2021-09-29 14:36:27 +00:00
|
|
|
|
using Dalamud.Data;
|
2022-04-14 17:38:52 +00:00
|
|
|
|
using Dalamud.Game.Gui;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
using Dalamud.Game.Network;
|
2022-04-14 17:38:52 +00:00
|
|
|
|
using Dalamud.Game.Text.SeStringHandling;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
using Dalamud.Interface.Colors;
|
|
|
|
|
using Dalamud.IoC;
|
|
|
|
|
using Dalamud.Logging;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using ImGuiNET;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FishNotify
|
|
|
|
|
{
|
|
|
|
|
public sealed class FishNotifyPlugin : IDalamudPlugin
|
|
|
|
|
{
|
|
|
|
|
public string Name => "FishNotify";
|
|
|
|
|
|
|
|
|
|
[PluginService]
|
|
|
|
|
[RequiredVersion("1.0")]
|
2022-04-14 17:38:52 +00:00
|
|
|
|
private DalamudPluginInterface PluginInterface { get; set; } = null!;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
|
|
|
|
|
[PluginService]
|
2022-04-14 17:38:52 +00:00
|
|
|
|
private GameNetwork Network { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[PluginService]
|
|
|
|
|
public static ChatGui Chat { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
private Configuration configuration;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
private bool settingsVisible;
|
|
|
|
|
private int expectedOpCode = -1;
|
2022-04-14 17:38:52 +00:00
|
|
|
|
private uint fishCount = 0;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
|
|
|
|
|
public FishNotifyPlugin()
|
|
|
|
|
{
|
2022-04-14 17:38:52 +00:00
|
|
|
|
configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
|
|
|
|
configuration.Initialize(PluginInterface);
|
|
|
|
|
|
|
|
|
|
Network.NetworkMessage += OnNetworkMessage;
|
|
|
|
|
PluginInterface.UiBuilder.Draw += OnDrawUI;
|
|
|
|
|
PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
client.GetStringAsync("https://raw.githubusercontent.com/karashiiro/FFXIVOpcodes/master/opcodes.min.json")
|
|
|
|
|
.ContinueWith(ExtractOpCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Network.NetworkMessage -= OnNetworkMessage;
|
2022-04-14 17:38:52 +00:00
|
|
|
|
PluginInterface.UiBuilder.Draw -= OnDrawUI;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExtractOpCode(Task<string> task)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var regions = JsonConvert.DeserializeObject<List<OpcodeRegion>>(task.Result);
|
|
|
|
|
if (regions == null)
|
|
|
|
|
{
|
|
|
|
|
PluginLog.Warning("No regions found in opcode list");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var region = regions.Find(r => r.Region == "Global");
|
|
|
|
|
if (region == null || region.Lists == null)
|
|
|
|
|
{
|
|
|
|
|
PluginLog.Warning("No global region found in opcode list");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 17:38:52 +00:00
|
|
|
|
if (!region.Lists.TryGetValue("ServerZoneIpcType", out List<OpcodeList>? serverZoneIpcTypes) || serverZoneIpcTypes == null)
|
2021-09-29 14:36:27 +00:00
|
|
|
|
{
|
|
|
|
|
PluginLog.Warning("No ServerZoneIpcType in opcode list");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var eventPlay = serverZoneIpcTypes.Find(opcode => opcode.Name == "EventPlay");
|
|
|
|
|
if (eventPlay == null)
|
|
|
|
|
{
|
|
|
|
|
PluginLog.Warning("No EventPlay opcode in ServerZoneIpcType");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedOpCode = eventPlay.Opcode;
|
|
|
|
|
PluginLog.Debug($"Found EventPlay opcode {expectedOpCode:X4}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
PluginLog.Error(e, "Could not download/extract opcodes: {}", e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnNetworkMessage(IntPtr dataPtr, ushort opCode, uint sourceActorId, uint targetActorId, NetworkMessageDirection direction)
|
|
|
|
|
{
|
|
|
|
|
if (direction != NetworkMessageDirection.ZoneDown || opCode != expectedOpCode)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var data = new byte[32];
|
|
|
|
|
Marshal.Copy(dataPtr, data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
int eventId = BitConverter.ToInt32(data, 8);
|
|
|
|
|
short scene = BitConverter.ToInt16(data, 12);
|
|
|
|
|
int param5 = BitConverter.ToInt32(data, 28);
|
|
|
|
|
|
|
|
|
|
// Fishing event?
|
|
|
|
|
if (eventId != 0x00150001)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Fish hooked?
|
|
|
|
|
if (scene != 5)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (param5)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case 0x124:
|
|
|
|
|
// light tug (!)
|
2022-04-14 17:38:52 +00:00
|
|
|
|
++fishCount;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
Sounds.PlaySound(Resources.Info);
|
2022-04-14 17:38:52 +00:00
|
|
|
|
SendChatAlert("light");
|
2021-09-29 14:36:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x125:
|
|
|
|
|
// medium tug (!!)
|
2022-04-14 17:38:52 +00:00
|
|
|
|
++fishCount;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
Sounds.PlaySound(Resources.Alert);
|
2022-04-14 17:38:52 +00:00
|
|
|
|
SendChatAlert("medium");
|
2021-09-29 14:36:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x126:
|
|
|
|
|
// heavy tug (!!!)
|
2022-04-14 17:38:52 +00:00
|
|
|
|
++fishCount;
|
2021-09-29 14:36:27 +00:00
|
|
|
|
Sounds.PlaySound(Resources.Alarm);
|
2022-04-14 17:38:52 +00:00
|
|
|
|
SendChatAlert("heavy");
|
2021-09-29 14:36:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Sounds.Stop();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 17:38:52 +00:00
|
|
|
|
private void SendChatAlert(string size)
|
|
|
|
|
{
|
|
|
|
|
if (!configuration.ChatAlerts)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeString message = new SeStringBuilder()
|
|
|
|
|
.AddUiForeground(514)
|
|
|
|
|
.Append("[FishNotify]")
|
|
|
|
|
.AddUiForegroundOff()
|
|
|
|
|
.Append($" You hook a fish with a ")
|
|
|
|
|
.AddUiForeground(514)
|
|
|
|
|
.Append(size)
|
|
|
|
|
.AddUiForegroundOff()
|
|
|
|
|
.Append(" bite.")
|
|
|
|
|
.Build();
|
|
|
|
|
Chat.Print(message);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 14:36:27 +00:00
|
|
|
|
private void OnDrawUI()
|
|
|
|
|
{
|
|
|
|
|
if (!settingsVisible)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (ImGui.Begin("FishNotify", ref this.settingsVisible, ImGuiWindowFlags.AlwaysAutoResize))
|
|
|
|
|
{
|
2022-04-14 17:38:52 +00:00
|
|
|
|
var chatAlerts = configuration.ChatAlerts;
|
|
|
|
|
if (ImGui.Checkbox("Show chat message on hooking a fish", ref chatAlerts))
|
|
|
|
|
{
|
|
|
|
|
configuration.ChatAlerts = chatAlerts;
|
|
|
|
|
configuration.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 14:36:27 +00:00
|
|
|
|
if (expectedOpCode > -1)
|
2022-04-14 17:38:52 +00:00
|
|
|
|
ImGui.TextColored(ImGuiColors.HealerGreen, $"Status: {(fishCount == 0 ? "Unknown (not triggered yet)" : $"OK ({fishCount} fish hooked)")}, opcode = {expectedOpCode:X}");
|
2021-09-29 14:36:27 +00:00
|
|
|
|
else
|
|
|
|
|
ImGui.TextColored(ImGuiColors.DalamudRed, "Status: No opcode :(");
|
|
|
|
|
}
|
|
|
|
|
ImGui.End();
|
|
|
|
|
}
|
2022-04-14 17:38:52 +00:00
|
|
|
|
|
2021-09-29 14:36:27 +00:00
|
|
|
|
private void OnOpenConfigUi()
|
|
|
|
|
{
|
|
|
|
|
settingsVisible = !settingsVisible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class OpcodeRegion
|
|
|
|
|
{
|
2022-04-14 17:38:52 +00:00
|
|
|
|
public string? Version { get; set; }
|
|
|
|
|
public string? Region { get; set; }
|
|
|
|
|
public Dictionary<string, List<OpcodeList>>? Lists { get; set; }
|
2021-09-29 14:36:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class OpcodeList
|
|
|
|
|
{
|
2022-04-14 17:38:52 +00:00
|
|
|
|
public string? Name { get; set; }
|
2021-09-29 14:36:27 +00:00
|
|
|
|
public ushort Opcode { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|