diff --git a/PetNicknames/PetNicknames/IPC/IpcProvider.cs b/PetNicknames/PetNicknames/IPC/IpcProvider.cs index c4cfa3d..0bdf2c4 100644 --- a/PetNicknames/PetNicknames/IPC/IpcProvider.cs +++ b/PetNicknames/PetNicknames/IPC/IpcProvider.cs @@ -1,4 +1,6 @@ -using Dalamud.Plugin; +using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Plugin; using Dalamud.Plugin.Ipc; using FFXIVClientStructs.FFXIV.Client.Game.Character; using PetRenamer.PetNicknames.IPC.Interfaces; @@ -7,6 +9,7 @@ using PetRenamer.PetNicknames.Services; using PetRenamer.PetNicknames.WritingAndParsing.DataParseResults; using PetRenamer.PetNicknames.WritingAndParsing.Interfaces.IParseResults; +using System; namespace PetRenamer; @@ -129,8 +132,18 @@ void RegisterFunctions() // Actions public void SetPlayerDataDetour(string data) { - IDataParseResult result = DataReader.ParseData(data); - DalamudServices.Framework.Run(() => DataReader.ApplyParseData(result, true)); + try + { + DalamudServices.Framework.Run(() => + { + IDataParseResult result = DataReader.ParseData(data); + DataReader.ApplyParseData(result, true); + }); + } + catch (Exception e) + { + DalamudServices.PluginLog.Error(e, "Error in Set Player Data"); + } } public unsafe void ClearIPCDataDetour(ushort objectIndex) @@ -139,13 +152,16 @@ public unsafe void ClearIPCDataDetour(ushort objectIndex) { DalamudServices.Framework.Run(() => { - BattleChara* bChara = (BattleChara*)DalamudServices.ObjectTable.GetObjectAddress(objectIndex); - if (bChara == null) return; + if (DalamudServices.ObjectTable.Length <= objectIndex) return; + if (DalamudServices.ObjectTable[objectIndex] is not IPlayerCharacter pc) return; - DataReader.ApplyParseData(new ClearParseResult(bChara->ContentId), true); + DataReader.ApplyParseData(new ClearParseResult(pc.Name.TextValue, (ushort)pc.HomeWorld.Id), true); }); } - catch { } + catch(Exception e) + { + DalamudServices.PluginLog.Error(e, "Error in clear IPC"); + } } // Functions diff --git a/PetNicknames/PetNicknames/WritingAndParsing/DataParseResults/ClearParseResult.cs b/PetNicknames/PetNicknames/WritingAndParsing/DataParseResults/ClearParseResult.cs index d7afb84..78148da 100644 --- a/PetNicknames/PetNicknames/WritingAndParsing/DataParseResults/ClearParseResult.cs +++ b/PetNicknames/PetNicknames/WritingAndParsing/DataParseResults/ClearParseResult.cs @@ -4,10 +4,12 @@ namespace PetRenamer.PetNicknames.WritingAndParsing.DataParseResults; internal class ClearParseResult : IClearParseResult { - public ulong ContentID { get; } + public string Name { get; } + public ushort Homeworld { get; } - public ClearParseResult(ulong contentID) + public ClearParseResult(string name, ushort homeworld) { - ContentID = contentID; + Name = name; + Homeworld = homeworld; } } diff --git a/PetNicknames/PetNicknames/WritingAndParsing/DataParser.cs b/PetNicknames/PetNicknames/WritingAndParsing/DataParser.cs index a6ca961..fcff8ce 100644 --- a/PetNicknames/PetNicknames/WritingAndParsing/DataParser.cs +++ b/PetNicknames/PetNicknames/WritingAndParsing/DataParser.cs @@ -46,9 +46,9 @@ public unsafe bool ApplyParseData(IDataParseResult result, bool isFromIPC) if (result is IClearParseResult clearParseResult) { - if (clearParseResult.ContentID == 0) return false; + if (clearParseResult.Name.IsNullOrWhitespace() || clearParseResult.Homeworld == 0) return false; - Database.GetEntry(clearParseResult.ContentID).Clear(false); + Database.GetEntry(clearParseResult.Name, clearParseResult.Homeworld, false)?.Clear(false); return true; } diff --git a/PetNicknames/PetNicknames/WritingAndParsing/Interfaces/IParseResults/IClearParseResult.cs b/PetNicknames/PetNicknames/WritingAndParsing/Interfaces/IParseResults/IClearParseResult.cs index 4cfd461..b780371 100644 --- a/PetNicknames/PetNicknames/WritingAndParsing/Interfaces/IParseResults/IClearParseResult.cs +++ b/PetNicknames/PetNicknames/WritingAndParsing/Interfaces/IParseResults/IClearParseResult.cs @@ -2,5 +2,6 @@ internal interface IClearParseResult : IDataParseResult { - ulong ContentID { get; } + ushort Homeworld { get; } + string Name { get; } }