diff --git a/Custom Commands and Macro Macros/GameFunctions.cs b/Custom Commands and Macro Macros/GameFunctions.cs index 2f37e9a..f4e9864 100644 --- a/Custom Commands and Macro Macros/GameFunctions.cs +++ b/Custom Commands and Macro Macros/GameFunctions.cs @@ -9,41 +9,38 @@ namespace CCMM { private delegate IntPtr GetUIBaseDelegate(); private delegate IntPtr GetUIModuleDelegate(IntPtr basePtr); - private delegate void ProcessChatBoxDelegate(IntPtr raptureModule, IntPtr message, IntPtr uiModule); + private delegate void EasierProcessChatBoxDelegate(IntPtr uiModule, IntPtr message, IntPtr unused, byte a4); - private readonly GetUIBaseDelegate GetUIBase; private readonly GetUIModuleDelegate GetUIModule; - private readonly ProcessChatBoxDelegate _ProcessChatBox; + private readonly EasierProcessChatBoxDelegate _EasierProcessChatBox; + + private readonly IntPtr uiModulePtr; public GameFunctions(CCMMPlugin plugin) { - this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "CCMMPlugin cannot be null"); + this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "Plugin cannot be null"); - IntPtr getUIBasePtr = this.plugin.Interface.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 41 b8 01 00 00 00 48 8d 15 ?? ?? ?? ?? 48 8b 48 20 e8 ?? ?? ?? ?? 48 8b cf"); IntPtr getUIModulePtr = this.plugin.Interface.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 48 83 7F ?? 00 48 8B F0"); - IntPtr processChatBoxPtr = this.plugin.Interface.TargetModuleScanner.ScanText("40 53 56 57 48 83 EC 70 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 44 24 ?? 48 8B 02"); + IntPtr easierProcessChatBoxPtr = this.plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9"); + this.uiModulePtr = this.plugin.Interface.TargetModuleScanner.GetStaticAddressFromSig("48 8B 0D ?? ?? ?? ?? 48 8D 54 24 ?? 48 83 C1 10 E8 ?? ?? ?? ??"); - if (getUIBasePtr == IntPtr.Zero || getUIModulePtr == IntPtr.Zero || processChatBoxPtr == IntPtr.Zero) { - PluginLog.Log($"getUIBasePtr: {getUIBasePtr.ToInt64():x}"); + if (getUIModulePtr == IntPtr.Zero || easierProcessChatBoxPtr == IntPtr.Zero || this.uiModulePtr == IntPtr.Zero) { PluginLog.Log($"getUIModulePtr: {getUIModulePtr.ToInt64():x}"); - PluginLog.Log($"processChatBoxPtr: {processChatBoxPtr.ToInt64():x}"); + PluginLog.Log($"easierProcessChatBoxPtr: {easierProcessChatBoxPtr.ToInt64():x}"); + PluginLog.Log($"this.uiModulePtr: {this.uiModulePtr.ToInt64():x}"); throw new ApplicationException("Got null pointers for game signature(s)"); } - this.GetUIBase = Marshal.GetDelegateForFunctionPointer(getUIBasePtr); this.GetUIModule = Marshal.GetDelegateForFunctionPointer(getUIModulePtr); - this._ProcessChatBox = Marshal.GetDelegateForFunctionPointer(processChatBoxPtr); + this._EasierProcessChatBox = Marshal.GetDelegateForFunctionPointer(easierProcessChatBoxPtr); } public void ProcessChatBox(string message) { - IntPtr uiBase = this.GetUIBase(); - IntPtr uiModule = this.GetUIModule(Marshal.ReadIntPtr(this.plugin.Interface.TargetModuleScanner.Module.BaseAddress + 0x1ce80b8)); + IntPtr uiModule = this.GetUIModule(Marshal.ReadIntPtr(this.uiModulePtr)); - if (uiBase == IntPtr.Zero || uiModule == IntPtr.Zero) { - throw new ApplicationException("uiBase or uiModule was null"); + if (uiModule == IntPtr.Zero) { + throw new ApplicationException("uiModule was null"); } - IntPtr raptureModule = uiModule + 0xA4D00; - byte[] bytes = Encoding.UTF8.GetBytes(message); IntPtr mem1 = Marshal.AllocHGlobal(400); @@ -56,12 +53,7 @@ namespace CCMM { Marshal.WriteInt64(mem1 + 8 + 8, bytes.Length + 1); Marshal.WriteInt64(mem1 + 8 + 8 + 8, 0); - Marshal.WriteByte(uiModule + 675757, 1); - Marshal.WriteInt16(uiModule + 169921, 0); - - this._ProcessChatBox(raptureModule, mem1, uiModule); - - Marshal.WriteByte(uiModule + 675757, 0); + this._EasierProcessChatBox(uiModule, mem1, IntPtr.Zero, 0); Marshal.FreeHGlobal(mem1); Marshal.FreeHGlobal(mem2);