Hello there!
Im working on my inproc wrapper for all the LUA-stuff. Thus im creating an empty 0-sized frame which listens for events. Im also detouring FrameScript::InvalidPtrCheck to not get in trouble when a function is called that was previously registered using FrameScript::RegisterFunction.
The code i use is the following:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Framework.LUA
{
public class EventManager
{
public EventManager()
{
IntPtr origPtrCheck = new IntPtr(Memory.Native.ModuleBase.ToInt32() + (int)LUAOffsets.funInvalidPointerCheck);
PtrCheckNew = OnPointerCheck;
PointerCheckDetour = new Memory.Detour<InvalidFunctionPointerCheckDlg>(origPtrCheck, PtrCheckNew);
if (!PointerCheckDetour.Enable())
{
Console.WriteLine("Unable to enable detour!");
throw new InvalidOperationException("Unable to write detour!");
}
eventHandler = OnEvent;
tramp = LUAFunctions.CreateLuaTrampoline(eventHandler);
LUAFunctions.FrameScript_RegisterFunction("theEventHandler", tramp);
mEventScript.Lines.Add("local f = CreateFrame(\"FRAME\", \"EventFrame" + this.GetHashCode() + "\", UIParent);");
mEventScript.Lines.Add("f:SetWidth(0);");
mEventScript.Lines.Add("f:SetHeight(0);");
mEventScript.Lines.Add("f:RegisterEvent(\"TIME_PLAYED_MSG\");");
mEventScript.Lines.Add("f:RegisterEvent(\"CHAT_MSG_SAY\");");
mEventScript.Lines.Add("f:RegisterEvent(\"UNIT_SPELLCAST_SUCCEEDED\");");
mEventScript.Lines.Add("f:SetScript(\"OnEvent\", theEventHandler);");
mEventScript.Execute();
}
public int OnEvent(IntPtr state)
{
var luas = new LUAState(state);
for (int i = 1; i <= luas.NumArguments; ++i)
{
if (luas.ArgumentTypes[i] == LUATypes.String)
{
string str = luas.Get<string>(i);
Console.WriteLine("string arg{0} = {1}", i, str);
}
}
return 0;
}
private int OnPointerCheck(IntPtr function)
{
if (function == tramp)
return 1;
return (int)PointerCheckDetour.CallDetoured(function);
}
delegate int EventDelegate(IntPtr state);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int InvalidFunctionPointerCheckDlg(IntPtr function);
InvalidFunctionPointerCheckDlg PtrCheckNew;
EventDelegate eventHandler = null;
IntPtr tramp;
Memory.Detour<InvalidFunctionPointerCheckDlg> PointerCheckDetour;
LUAScript mEventScript = new LUAScript();
}
}
Now my question is:
Does anybody of the guys that studied warden know if it check if InvalidPtrCheck was changed? I must confess that im not that much into warden so far but from the name and the code InvalidPtrCheck is executing ive got the feeling that if id be blizzard id check that function.
Thanks for any thoughts or responses on that!
Greetings
Cromon