API 9
This commit is contained in:
parent
d425fa4040
commit
59aa8c7dc7
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,4 +1,6 @@
|
|||||||
.vs/
|
/dist
|
||||||
obj/
|
/obj
|
||||||
dist/
|
/bin
|
||||||
*.user
|
/.idea
|
||||||
|
/.vs
|
||||||
|
*.user
|
||||||
|
@ -1,25 +1,9 @@
|
|||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Plugin;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace FishNotify
|
namespace FishNotify;
|
||||||
|
|
||||||
|
internal sealed class Configuration : IPluginConfiguration
|
||||||
{
|
{
|
||||||
internal class Configuration : IPluginConfiguration
|
public int Version { get; set; } = 0;
|
||||||
{
|
public bool ChatAlerts { get; set; } = false;
|
||||||
public int Version { get; set; } = 0;
|
|
||||||
public bool ChatAlerts { get; set; } = false;
|
|
||||||
|
|
||||||
[NonSerialized]
|
|
||||||
private DalamudPluginInterface pluginInterface = null!;
|
|
||||||
|
|
||||||
public void Initialize(DalamudPluginInterface pluginInterface)
|
|
||||||
{
|
|
||||||
this.pluginInterface = pluginInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Save()
|
|
||||||
{
|
|
||||||
this.pluginInterface.SavePluginConfig(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
330
FishNotify.cs
330
FishNotify.cs
@ -1,10 +1,7 @@
|
|||||||
using Dalamud.Data;
|
using Dalamud.Game.Network;
|
||||||
using Dalamud.Game.Gui;
|
|
||||||
using Dalamud.Game.Network;
|
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
using Dalamud.Logging;
|
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -13,197 +10,184 @@ using System.Collections.Generic;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
|
||||||
namespace FishNotify
|
namespace FishNotify;
|
||||||
|
|
||||||
|
public sealed class FishNotifyPlugin : IDalamudPlugin
|
||||||
{
|
{
|
||||||
public sealed class FishNotifyPlugin : IDalamudPlugin
|
[PluginService]
|
||||||
|
[RequiredVersion("1.0")]
|
||||||
|
private DalamudPluginInterface PluginInterface { get; set; } = null!;
|
||||||
|
|
||||||
|
[PluginService]
|
||||||
|
private IGameNetwork Network { get; set; } = null!;
|
||||||
|
|
||||||
|
[PluginService]
|
||||||
|
private IChatGui Chat { get; set; } = null!;
|
||||||
|
|
||||||
|
[PluginService]
|
||||||
|
private IPluginLog PluginLog { get; set; } = null!;
|
||||||
|
|
||||||
|
private readonly Configuration _configuration;
|
||||||
|
private bool _settingsVisible;
|
||||||
|
private int _expectedOpCode = -1;
|
||||||
|
private uint _fishCount;
|
||||||
|
|
||||||
|
public FishNotifyPlugin()
|
||||||
{
|
{
|
||||||
public string Name => "FishNotify";
|
_configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
|
|
||||||
[PluginService]
|
Network.NetworkMessage += OnNetworkMessage;
|
||||||
[RequiredVersion("1.0")]
|
PluginInterface.UiBuilder.Draw += OnDrawUI;
|
||||||
private DalamudPluginInterface PluginInterface { get; set; } = null!;
|
PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
|
||||||
|
|
||||||
[PluginService]
|
var client = new HttpClient();
|
||||||
private GameNetwork Network { get; set; } = null!;
|
client.GetStringAsync("https://raw.githubusercontent.com/karashiiro/FFXIVOpcodes/master/opcodes.min.json")
|
||||||
|
.ContinueWith(ExtractOpCode);
|
||||||
|
}
|
||||||
|
|
||||||
[PluginService]
|
public void Dispose()
|
||||||
public static ChatGui Chat { get; set; } = null!;
|
{
|
||||||
|
Network.NetworkMessage -= OnNetworkMessage;
|
||||||
|
PluginInterface.UiBuilder.Draw -= OnDrawUI;
|
||||||
|
PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
|
||||||
|
}
|
||||||
|
|
||||||
private Configuration configuration;
|
private void ExtractOpCode(Task<string> task)
|
||||||
private bool settingsVisible;
|
{
|
||||||
private int expectedOpCode = -1;
|
try
|
||||||
private uint fishCount = 0;
|
|
||||||
|
|
||||||
public FishNotifyPlugin()
|
|
||||||
{
|
{
|
||||||
configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
var regions = JsonConvert.DeserializeObject<List<OpcodeRegion>>(task.Result);
|
||||||
configuration.Initialize(PluginInterface);
|
if (regions == null)
|
||||||
|
|
||||||
Network.NetworkMessage += OnNetworkMessage;
|
|
||||||
PluginInterface.UiBuilder.Draw += OnDrawUI;
|
|
||||||
PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
|
|
||||||
|
|
||||||
var client = new HttpClient();
|
|
||||||
client.GetStringAsync("https://raw.githubusercontent.com/karashiiro/FFXIVOpcodes/master/opcodes.min.json")
|
|
||||||
.ContinueWith(ExtractOpCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Network.NetworkMessage -= OnNetworkMessage;
|
|
||||||
PluginInterface.UiBuilder.Draw -= OnDrawUI;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!region.Lists.TryGetValue("ServerZoneIpcType", out List<OpcodeList>? serverZoneIpcTypes) || serverZoneIpcTypes == null)
|
|
||||||
{
|
|
||||||
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 (!)
|
|
||||||
++fishCount;
|
|
||||||
Sounds.PlaySound(Resources.Info);
|
|
||||||
SendChatAlert("light");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x125:
|
|
||||||
// medium tug (!!)
|
|
||||||
++fishCount;
|
|
||||||
Sounds.PlaySound(Resources.Alert);
|
|
||||||
SendChatAlert("medium");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x126:
|
|
||||||
// heavy tug (!!!)
|
|
||||||
++fishCount;
|
|
||||||
Sounds.PlaySound(Resources.Alarm);
|
|
||||||
SendChatAlert("heavy");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Sounds.Stop();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendChatAlert(string size)
|
|
||||||
{
|
|
||||||
if (!configuration.ChatAlerts)
|
|
||||||
{
|
{
|
||||||
|
PluginLog.Warning("No regions found in opcode list");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SeString message = new SeStringBuilder()
|
var region = regions.Find(r => r.Region == "Global");
|
||||||
.AddUiForeground(514)
|
if (region == null || region.Lists == null)
|
||||||
.Append("[FishNotify]")
|
|
||||||
.AddUiForegroundOff()
|
|
||||||
.Append($" You hook a fish with a ")
|
|
||||||
.AddUiForeground(514)
|
|
||||||
.Append(size)
|
|
||||||
.AddUiForegroundOff()
|
|
||||||
.Append(" bite.")
|
|
||||||
.Build();
|
|
||||||
Chat.Print(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDrawUI()
|
|
||||||
{
|
|
||||||
if (!settingsVisible)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ImGui.Begin("FishNotify", ref this.settingsVisible, ImGuiWindowFlags.AlwaysAutoResize))
|
|
||||||
{
|
{
|
||||||
var chatAlerts = configuration.ChatAlerts;
|
PluginLog.Warning("No global region found in opcode list");
|
||||||
if (ImGui.Checkbox("Show chat message on hooking a fish", ref chatAlerts))
|
return;
|
||||||
{
|
|
||||||
configuration.ChatAlerts = chatAlerts;
|
|
||||||
configuration.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expectedOpCode > -1)
|
|
||||||
ImGui.TextColored(ImGuiColors.HealerGreen, $"Status: {(fishCount == 0 ? "Unknown (not triggered yet)" : $"OK ({fishCount} fish hooked)")}, opcode = {expectedOpCode:X}");
|
|
||||||
else
|
|
||||||
ImGui.TextColored(ImGuiColors.DalamudRed, "Status: No opcode :(");
|
|
||||||
}
|
}
|
||||||
ImGui.End();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnOpenConfigUi()
|
if (!region.Lists.TryGetValue("ServerZoneIpcType", out List<OpcodeList>? serverZoneIpcTypes) || serverZoneIpcTypes == null)
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
settingsVisible = !settingsVisible;
|
PluginLog.Error(e, "Could not download/extract opcodes: {}", e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OpcodeRegion
|
private void OnNetworkMessage(IntPtr dataPtr, ushort opCode, uint sourceActorId, uint targetActorId, NetworkMessageDirection direction)
|
||||||
{
|
{
|
||||||
public string? Version { get; set; }
|
if (direction != NetworkMessageDirection.ZoneDown || opCode != _expectedOpCode)
|
||||||
public string? Region { get; set; }
|
return;
|
||||||
public Dictionary<string, List<OpcodeList>>? Lists { get; set; }
|
|
||||||
|
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 (!)
|
||||||
|
++_fishCount;
|
||||||
|
Sounds.PlaySound(Resources.Info);
|
||||||
|
SendChatAlert("light");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x125:
|
||||||
|
// medium tug (!!)
|
||||||
|
++_fishCount;
|
||||||
|
Sounds.PlaySound(Resources.Alert);
|
||||||
|
SendChatAlert("medium");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x126:
|
||||||
|
// heavy tug (!!!)
|
||||||
|
++_fishCount;
|
||||||
|
Sounds.PlaySound(Resources.Alarm);
|
||||||
|
SendChatAlert("heavy");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Sounds.Stop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OpcodeList
|
private void SendChatAlert(string size)
|
||||||
{
|
{
|
||||||
public string? Name { get; set; }
|
if (!_configuration.ChatAlerts)
|
||||||
public ushort Opcode { get; set; }
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDrawUI()
|
||||||
|
{
|
||||||
|
if (!_settingsVisible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ImGui.Begin("FishNotify", ref _settingsVisible, ImGuiWindowFlags.AlwaysAutoResize))
|
||||||
|
{
|
||||||
|
var chatAlerts = _configuration.ChatAlerts;
|
||||||
|
if (ImGui.Checkbox("Show chat message on hooking a fish", ref chatAlerts))
|
||||||
|
{
|
||||||
|
_configuration.ChatAlerts = chatAlerts;
|
||||||
|
PluginInterface.SavePluginConfig(_configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_expectedOpCode > -1)
|
||||||
|
ImGui.TextColored(ImGuiColors.HealerGreen, $"Status: {(_fishCount == 0 ? "Unknown (not triggered yet)" : $"OK ({_fishCount} fish hooked)")}, opcode = {_expectedOpCode:X}");
|
||||||
|
else
|
||||||
|
ImGui.TextColored(ImGuiColors.DalamudRed, "Status: No opcode :(");
|
||||||
|
}
|
||||||
|
ImGui.End();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnOpenConfigUi()
|
||||||
|
{
|
||||||
|
_settingsVisible = !_settingsVisible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>5.0</Version>
|
<Version>6.0</Version>
|
||||||
<Description>Plays a sound effect when a fish bites</Description>
|
<Description>Plays a sound effect when a fish bites</Description>
|
||||||
<Copyright></Copyright>
|
<Copyright></Copyright>
|
||||||
<PackageProjectUrl>https://github.com/carvelli/Fish-Notify</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/carvelli/Fish-Notify</PackageProjectUrl>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DalamudPackager" Version="2.1.10" />
|
<PackageReference Include="DalamudPackager" Version="2.1.12" />
|
||||||
<PackageReference Include="System.Windows.Extensions" Version="7.0.0" />
|
<PackageReference Include="System.Windows.Extensions" Version="7.0.0" />
|
||||||
<Reference Include="FFXIVClientStructs">
|
<Reference Include="FFXIVClientStructs">
|
||||||
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
|
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
|
||||||
@ -55,10 +55,6 @@
|
|||||||
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
|
<HintPath>$(DalamudLibPath)ImGui.NET.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ImGuiScene">
|
|
||||||
<HintPath>$(DalamudLibPath)ImGuiScene.dll</HintPath>
|
|
||||||
<Private>false</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Lumina">
|
<Reference Include="Lumina">
|
||||||
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
|
<HintPath>$(DalamudLibPath)Lumina.dll</HintPath>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
|
7
OpcodeList.cs
Normal file
7
OpcodeList.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace FishNotify;
|
||||||
|
|
||||||
|
public class OpcodeList
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public ushort Opcode { get; set; }
|
||||||
|
}
|
10
OpcodeRegion.cs
Normal file
10
OpcodeRegion.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace FishNotify;
|
||||||
|
|
||||||
|
public class OpcodeRegion
|
||||||
|
{
|
||||||
|
public string? Version { get; set; }
|
||||||
|
public string? Region { get; set; }
|
||||||
|
public Dictionary<string, List<OpcodeList>>? Lists { get; set; }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user