Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: fixed some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 5, 2023
1 parent 3fa1753 commit fb9053d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
14 changes: 5 additions & 9 deletions FakeName.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeName", "FakeName\FakeName.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeName", "FakeName\FakeName.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|Any CPU
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|Any CPU
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64
{13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|x64.ActiveCfg = Debug|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Debug|x64.Build.0 = Debug|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|x64.ActiveCfg = Release|x64
{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion FakeName/FakeName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<AssemblyVersion>1.0.0.5</AssemblyVersion>
<TargetFramework>net7.0-windows</TargetFramework>
<Platforms>x64</Platforms>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions FakeName/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Plugin : IDalamudPlugin
{
public string Name => "FakeName";

internal Hooker AtkTextNodeSetText { get; }
internal Hooker Hooker { get; }

internal WindowManager WindowManager { get; }

Expand All @@ -19,7 +19,7 @@ public Plugin(DalamudPluginInterface pluginInterface, CommandManager commandMana

WindowManager = new WindowManager();

AtkTextNodeSetText = new Hooker();
Hooker = new Hooker();

Service.CommandManager.AddHandler("/fakename", new CommandInfo(OnCommand)
{
Expand All @@ -31,7 +31,7 @@ public void Dispose()
{
Service.CommandManager.RemoveHandler("/fakename");

AtkTextNodeSetText.Dispose();
Hooker.Dispose();
WindowManager.Dispose();
}

Expand Down
46 changes: 21 additions & 25 deletions FakeName/Replacer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Game.Libc;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Logging;
using System;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -11,38 +12,33 @@ internal static class Replacer
{
public static IntPtr ChangeName(IntPtr seStringPtr)
{
var str = SeStringFromPtr(seStringPtr);
if(ChangeSeString(ref str))
if (seStringPtr == IntPtr.Zero) return seStringPtr;

try
{
FreePtr(seStringPtr);
return SeStringToPtr(str);
var str = SeString.Parse(StdString.ReadFromPointer(seStringPtr).RawData);
if (ChangeSeString(ref str))
{
var bytes = str.Encode();
var pointer = Marshal.AllocHGlobal(bytes.Length + 1);
Marshal.Copy(bytes, 0, pointer, bytes.Length);
Marshal.WriteByte(pointer, bytes.Length, 0);

return pointer;
}
else
{
return seStringPtr;
}
}
else
catch (Exception ex)
{
PluginLog.Error(ex, "Something wrong with change name!");
return seStringPtr;
}
}

static SeString SeStringFromPtr(IntPtr seStringPtr)
{
return SeString.Parse(StdString.ReadFromPointer(seStringPtr).RawData);
}

public static IntPtr SeStringToPtr(SeString seString)
{
var bytes = seString.Encode();
var pointer = Marshal.AllocHGlobal(bytes.Length + 1);
Marshal.Copy(bytes, 0, pointer, bytes.Length);
Marshal.WriteByte(pointer, bytes.Length, 0);

return pointer;
}

public static void FreePtr(IntPtr seStringPtr)
{
Marshal.FreeHGlobal(seStringPtr);
}

public static bool ChangeSeString(ref SeString seString)
{
if (!Service.Config.Enabled) return false;
Expand Down

0 comments on commit fb9053d

Please sign in to comment.