Skip to content

Commit

Permalink
fix: Use SetValue for FlyText string arrays (#1532)
Browse files Browse the repository at this point in the history
- Might fix a bug causing crashes with certain FlyText use cases, maybe.
- Also allows building Dalamud under .NET 8 local envs.
  • Loading branch information
KazWolfe committed Nov 18, 2023
1 parent 48e8462 commit 93f08a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
44 changes: 19 additions & 25 deletions Dalamud/Game/Gui/FlyText/FlyTextGui.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

Expand Down Expand Up @@ -113,32 +112,26 @@ public unsafe void AddFlyText(FlyTextKind kind, uint actorIndex, uint val1, uint
numArray->IntArray[numOffset + 2] = unchecked((int)val1);
numArray->IntArray[numOffset + 3] = unchecked((int)val2);
numArray->IntArray[numOffset + 4] = unchecked((int)damageTypeIcon); // Icons for damage type
numArray->IntArray[numOffset + 5] = 5; // Unknown
numArray->IntArray[numOffset + 5] = 5; // Unknown
numArray->IntArray[numOffset + 6] = unchecked((int)color);
numArray->IntArray[numOffset + 7] = unchecked((int)icon);
numArray->IntArray[numOffset + 8] = 0; // Unknown
numArray->IntArray[numOffset + 9] = 0; // Unknown, has something to do with yOffset

fixed (byte* pText1 = text1.Encode())
{
fixed (byte* pText2 = text2.Encode())
{
strArray->StringArray[strOffset + 0] = pText1;
strArray->StringArray[strOffset + 1] = pText2;

this.addFlyTextNative(
flytext,
actorIndex,
1,
(IntPtr)numArray,
numOffset,
10,
(IntPtr)strArray,
strOffset,
2,
0);
}
}
strArray->SetValue((int)strOffset + 0, text1.Encode(), false, true, false);
strArray->SetValue((int)strOffset + 1, text2.Encode(), false, true, false);

this.addFlyTextNative(
flytext,
actorIndex,
1,
(IntPtr)numArray,
numOffset,
10,
(IntPtr)strArray,
strOffset,
2,
0);
}

private static byte[] Terminate(byte[] source)
Expand Down Expand Up @@ -230,7 +223,8 @@ private IntPtr CreateFlyTextDetour(
if (!dirty)
{
Log.Verbose("[FlyText] Calling flytext with original args.");
return this.createFlyTextHook.Original(addonFlyText, kind, val1, val2, text2, color, icon, damageTypeIcon, text1, yOffset);
return this.createFlyTextHook.Original(addonFlyText, kind, val1, val2, text2, color, icon,
damageTypeIcon, text1, yOffset);
}

var terminated1 = Terminate(tmpText1.Encode());
Expand Down Expand Up @@ -299,10 +293,10 @@ internal FlyTextGuiPluginScoped()
{
this.flyTextGuiService.FlyTextCreated += this.FlyTextCreatedForward;
}

/// <inheritdoc/>
public event IFlyTextGui.OnFlyTextCreatedDelegate? FlyTextCreated;

/// <inheritdoc/>
public void Dispose()
{
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "7.0.0",
"rollForward": "latestMinor",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
}

0 comments on commit 93f08a4

Please sign in to comment.