/// <summary> /// Get Localized Text for command aka. read a lua variable /// </summary> /// <param name="command">lua command to run</param> /// <param name="variable">variable to read</param> /// <returns> /// Localized text for the executed functions /// return value, variable content or whatever /// you want to read. /// </returns> public static string GetLocalizedText(string command, string variable) { if (command.Length > 0 && variable.Length > 0) { // allocate memory for our command uint argCCCommand = BlackMagic.AllocateMemory(Encoding.UTF8.GetBytes(command).Length + 1); BlackMagic.WriteBytes(argCCCommand, Encoding.UTF8.GetBytes(command)); string[] asmDoString = new string[] { $"MOV EAX, {(argCCCommand) }", "PUSH 0", "PUSH EAX", "PUSH EAX", $"CALL {(Offsets.luaDoString)}", "ADD ESP, 0xC", "RETN", }; // allocate memory for our variable uint argCC = BlackMagic.AllocateMemory(Encoding.UTF8.GetBytes(variable).Length + 1); BlackMagic.WriteBytes(argCC, Encoding.UTF8.GetBytes(variable)); string[] asmLocalText = new string[] { $"CALL {(Offsets.clientObjectManagerGetActivePlayerObject)}", "MOV ECX, EAX", "PUSH -1", $"PUSH {(argCC)}", $"CALL {(Offsets.luaGetLocalizedText)}", "RETN", }; HookJob hookJobLocaltext = new HookJob(asmLocalText, true); ReturnHookJob hookJobDoString = new ReturnHookJob(asmDoString, false, hookJobLocaltext); // add our hook-job to be executed AmeisenHook.AddHookJob(ref hookJobDoString); // wait for our hook-job to return while (!hookJobDoString.IsFinished) { Thread.Sleep(1); } // parse the result bytes to a readable string string result = Encoding.UTF8.GetString((byte[])hookJobDoString.ReturnValue); AmeisenLogger.Instance.Log(LogLevel.VERBOSE, "DoString(" + command + "); => " + variable + " = " + result, "AmeisenCore"); // free our memory BlackMagic.FreeMemory(argCCCommand); BlackMagic.FreeMemory(argCC); return(result); } return(""); }
/// <summary> /// Get Localized Text for command /// </summary> /// <param name="command">lua command to run</param> /// <param name="variable">variable to read</param> /// <returns>localized text for the executed functions return value</returns> public static string GetLocalizedText(string command, string variable) { if (command.Length > 0 && variable.Length > 0) { uint argCCCommand = BlackMagic.AllocateMemory(Encoding.UTF8.GetBytes(command).Length + 1); BlackMagic.WriteBytes(argCCCommand, Encoding.UTF8.GetBytes(command)); string[] asmDoString = new string[] { $"MOV EAX, {(argCCCommand) }", "PUSH 0", "PUSH EAX", "PUSH EAX", $"CALL {(Offsets.luaDoString)}", "ADD ESP, 0xC", "RETN", }; uint argCC = BlackMagic.AllocateMemory(Encoding.UTF8.GetBytes(variable).Length + 1); BlackMagic.WriteBytes(argCC, Encoding.UTF8.GetBytes(variable)); uint playerBase = BlackMagic.ReadUInt(Offsets.playerBase); playerBase = BlackMagic.ReadUInt(playerBase + 0x34); playerBase = BlackMagic.ReadUInt(playerBase + 0x24); string[] asmLocalText = new string[] { $"CALL {(Offsets.clientObjectManagerGetActivePlayerObject)}", "MOV ECX, EAX", "PUSH -1", $"PUSH {(argCC)}", $"CALL {(Offsets.luaGetLocalizedText)}", "RETN", }; HookJob hookJobLocaltext = new HookJob(asmLocalText, true); ReturnHookJob hookJobDoString = new ReturnHookJob(asmDoString, false, hookJobLocaltext); AmeisenHook.AddHookJob(ref hookJobDoString); while (!hookJobDoString.IsFinished || !hookJobDoString.IsFinished) { Thread.Sleep(5); } string result = Encoding.UTF8.GetString((byte[])hookJobDoString.ReturnValue); AmeisenLogger.Instance.Log(LogLevel.VERBOSE, "DoString(" + command + "); => " + variable + " = " + result, "AmeisenCore"); BlackMagic.FreeMemory(argCCCommand); BlackMagic.FreeMemory(argCC); return(result); } return(""); }
public void AddHookJob(ref ReturnHookJob hookJob) { hookJobs.Enqueue(hookJob); }