Skip to content

Commit

Permalink
Fixes IPC crash (I'm an idiot c:)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyceri committed Jul 27, 2024
1 parent 914182b commit 7374020
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
30 changes: 23 additions & 7 deletions PetNicknames/PetNicknames/IPC/IpcProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -7,6 +9,7 @@
using PetRenamer.PetNicknames.Services;
using PetRenamer.PetNicknames.WritingAndParsing.DataParseResults;
using PetRenamer.PetNicknames.WritingAndParsing.Interfaces.IParseResults;
using System;

namespace PetRenamer;

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions PetNicknames/PetNicknames/WritingAndParsing/DataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

internal interface IClearParseResult : IDataParseResult
{
ulong ContentID { get; }
ushort Homeworld { get; }
string Name { get; }
}

0 comments on commit 7374020

Please sign in to comment.