Advertisement
captmicro

executecmdstring hook

Aug 8th, 2012
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. /* ExecuteCmdString Hook */
  2. typedef void (__cdecl *_ExecuteCmdString)(byte*, bool, int);
  3. _ExecuteCmdString rlExecuteCmdString = 0;
  4. void __cdecl hkExecuteCmdString(byte *inCmd, bool bUnknown, int iUnknown)
  5. {
  6.     char *cmdstr = (char*)(inCmd + 8);
  7.  
  8.     ILuaInterface *li = STATES[MENUSTATE];
  9.     ILuaObject *fn = li->GetGlobal("GABV9K_CallHook");
  10.     if (fn->isFunction())
  11.     {
  12.         li->Push(fn);
  13.         li->Push("ExecuteCmdString");
  14.         li->Push(cmdstr);
  15.         li->Call(2, 1);
  16.         ILuaObject *ret = li->GetReturn(0);
  17.         bool block_cmd = (!ret->isNil() && (ret->GetBool() == false));
  18.         ret->UnReference();
  19.         if (block_cmd) return;
  20.     }
  21.     fn->UnReference();
  22.  
  23.     rlExecuteCmdString(inCmd, bUnknown, iUnknown);
  24. }
  25. LUA_FUNCTION(lua_HookExecuteCmdString)
  26. {
  27.     Lua()->CheckType(1, GLua::TYPE_LIGHTUSERDATA);
  28.     BYTE *ECS = (BYTE*)Lua()->GetLightUserData(1);
  29.     if (ECS == 0) { Lua()->Msg("[GABV9K] Invalid Pointer!"); return 0; }
  30.     rlExecuteCmdString = (_ExecuteCmdString)ECS;
  31.     DetourTransactionBegin();
  32.     DetourUpdateThread(GetCurrentThread());
  33.     DetourAttach(&(void*&)rlExecuteCmdString, (void*)hkExecuteCmdString);
  34.     DetourTransactionCommit();
  35.     return 0;
  36. }
  37. LUA_FUNCTION(lua_UnHookExecuteCmdString)
  38. {
  39.     if (rlExecuteCmdString == 0) { Lua()->Msg("[GABV9K] Invalid Pointer!"); return 0; }
  40.     DetourTransactionBegin();
  41.     DetourUpdateThread(GetCurrentThread());
  42.     DetourDetach(&(void*&)rlExecuteCmdString, (void*)hkExecuteCmdString);
  43.     DetourTransactionCommit();
  44.     return 0;
  45. }
  46. /* ExecuteCmdString Hook */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement