public DebugEngine(LuaState ls) { this.ls = ls; this.debugHook = new LuaDebugHook(this.DebugHook); this.logCallback = new LuaCFunc(this.LogCallback); RegisterLogFunction(); ErrorHook.SetErrorHandler(ls.L, new ErrorHook.LuaErrorCaught(this.ErrorCaughtHook)); this.fireStateChangedEvent = new Action(FireStateChangedEvent); SetHook(); }
public static bool InstallHook() { ErrorHook.errorHandler = new LuaCFunc(ErrorHook.ErrorCatcher); ErrorHook.errorHandlerPtr = Marshal.GetFunctionPointerForDelegate(ErrorHook.errorHandler); ErrorHook.pcallHook = new LuaPcallHook(ErrorHook.FakePcall); IntPtr pcallHookPtr = Marshal.GetFunctionPointerForDelegate(ErrorHook.pcallHook); try { return(ImportPatcher.ReplaceIATEntry(GlobalState.LuaDll, "lua_pcall", pcallHookPtr)); } catch (Exception e) { Process p = Process.GetCurrentProcess(); string modules = ""; foreach (ProcessModule pm in p.Modules) { modules += pm.ModuleName + " (@ 0x" + pm.BaseAddress.ToString("X") + ") " + pm.FileName + "\n"; } MessageBox.Show("Patching the Import Table for lua_pcall failed!\nLua Errors won't be caught by the Debugger.\nProblem: " + e.Message + "\n\n" + modules.TrimEnd(), "Press Ctrl+C and send to yoq!"); return(false); } }