Member
|
10-31-2014
, 10:57
Re: Hooking BaseEntity Functions in CSGO
|
#20
|
Unhandled exception at 0x1707E1BF (dbi.sqlite.ext.dll) in srcds.exe: Fatal program exit requested.
extension.h
PHP Code:
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
/**
* @file extension.h
* @brief Sample extension code header.
*/
#include "smsdk_ext.h"
#include "CDetour/detours.h"
#define DETOUR_DECL_STATIC10(name, ret, p1type, p1name, p2type, p2name, p3type, p3name, p4type, p4name, p5type, p5name, p6type, p6name, p7type, p7name, p8type, p8name, p9type, p9name, p10type, p10name) \
ret (*name##_Actual)(p1type, p2type, p3type, p4type, p5type, p6type, p7type, p8type, p9type, p10type) = NULL; \
ret name(p1type p1name, p2type p2name, p3type p3name, p4type p4name, p5type p5name, p6type p6name, p7type p7name, p8type p8name, p9type p9name, p10type p10name)
bool CreateFXFireBulletsDetour();
/**
* @brief Sample implementation of the SDK Extension.
* Note: Uncomment one of the pre-defined virtual functions in order to use it.
*/
class Sample : public SDKExtension, public IPluginsListener
{
public:
/**
* @brief This is called after the initial loading sequence has been processed.
*
* @param error Error message buffer.
* @param maxlength Size of error message buffer.
* @param late Whether or not the module was loaded after map load.
* @return True to succeed loading, false to fail.
*/
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
/**
* @brief This is called right before the extension is unloaded.
*/
virtual void SDK_OnUnload();
/**
* @brief This is called once all known extensions have been loaded.
* Note: It is is a good idea to add natives here, if any are provided.
*/
//virtual void SDK_OnAllLoaded();
/**
* @brief Called when the pause state is changed.
*/
//virtual void SDK_OnPauseChange(bool paused);
/**
* @brief this is called when Core wants to know if your extension is working.
*
* @param error Error message buffer.
* @param maxlength Size of error message buffer.
* @return True if working, false otherwise.
*/
//virtual bool QueryRunning(char *error, size_t maxlength);
public:
#if defined SMEXT_CONF_METAMOD
/**
* @brief Called when Metamod is attached, before the extension version is called.
*
* @param error Error buffer.
* @param maxlength Maximum size of error buffer.
* @param late Whether or not Metamod considers this a late load.
* @return True to succeed, false to fail.
*/
//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
/**
* @brief Called when Metamod is detaching, after the extension version is called.
* NOTE: By default this is blocked unless sent from SourceMod.
*
* @param error Error buffer.
* @param maxlength Maximum size of error buffer.
* @return True to succeed, false to fail.
*/
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
/**
* @brief Called when Metamod's pause state is changing.
* NOTE: By default this is blocked unless sent from SourceMod.
*
* @param paused Pause state being set.
* @param error Error buffer.
* @param maxlength Maximum size of error buffer.
* @return True to succeed, false to fail.
*/
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
#endif
void OnPluginLoaded(IPlugin *plugin);
void OnPluginUnloaded(IPlugin *plugin);
private:
bool m_FXFireBulletsDetourEnabled;
};
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
extension.cpp
PHP Code:
#include "extension.h"
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
Sample g_Sample; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_Sample);
IGameConfig *g_pGameConf = NULL;
CDetour *DFXFireBullets = NULL;
IForward *g_pFireBullet = NULL;
DETOUR_DECL_STATIC10(DetourFXFireBullets, void, Vector const&, vOrigin, QAngle const&, vAngles, int, weaponId, int, mode, int, seed, float, flSpread, float, a9, float, a10, float, a11, int, a12)
{
int iPlayerId;
__asm mov iPlayerId, ecx
int definitionIndex;
__asm mov definitionIndex, edx
// Trick the compiler into thinking that we're using ESI(to preserve it - just to be sure).
__asm mov esi, esi;
/*cell_t result = Pl_Continue;
g_pFireBullet->PushCell(iPlayerId);
g_pFireBullet->Execute(&result);
printf("playerID: %d\n", iPlayerId);
printf("definitionIndex: %d\n", definitionIndex);
printf("wpnId: %d\n", weaponId);
printf("mode: %d\n", mode);
printf("seed: %d\n", seed);
printf("spread: %f\n", flSpread);*/
/*Vector *ptr3;
ptr3 = (Vector*)( &vOrigin );
*ptr3 = Vector(vOrigin.x, vOrigin.y, vOrigin.z);
QAngle *ptr4;
ptr4 = (QAngle*)( &vAngles );
*ptr4 = QAngle(vAngles.x, vAngles.y, vAngles.z);*/
/* Call original function.
* I had to manually 'construct' this call because the compiler was destroying register content while pushing the args. */
void *addr = DETOUR_STATIC_CALL(DetourFXFireBullets);
__asm {
push a12
push a11
push a10
push a9
push flSpread
push seed
push mode
push weaponId
push vAngles
push vOrigin
mov edx, definitionIndex
mov ecx, iPlayerId
call addr
add esp, 0x28
}
}
bool Sample::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
char conf_error[255];
if (!gameconfs->LoadGameConfigFile("sample.games", &g_pGameConf, conf_error, sizeof(conf_error)))
{
if (error)
{
snprintf(error, maxlength, "Could not read sample.games.txt: %s", conf_error);
}
return false;
}
sharesys->RegisterLibrary(myself, "sample");
plsys->AddPluginsListener(this);
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
m_FXFireBulletsDetourEnabled = false;
g_pFireBullet = forwards->CreateForward("OnFireBullet", ET_Event, 1, NULL, Param_Cell);
return true;
}
void Sample::SDK_OnUnload()
{
gameconfs->CloseGameConfigFile(g_pGameConf);
plsys->RemovePluginsListener(this);
forwards->ReleaseForward(g_pFireBullet);
}
void Sample::OnPluginLoaded(IPlugin *plugin)
{
if(!m_FXFireBulletsDetourEnabled)
{
m_FXFireBulletsDetourEnabled = CreateFXFireBulletsDetour();
}
}
void Sample::OnPluginUnloaded(IPlugin *plugin)
{
if(m_FXFireBulletsDetourEnabled)
{
if(DFXFireBullets != NULL)
{
DFXFireBullets->Destroy();
DFXFireBullets = NULL;
}
m_FXFireBulletsDetourEnabled = false;
}
}
bool CreateFXFireBulletsDetour()
{
DFXFireBullets = DETOUR_CREATE_STATIC(DetourFXFireBullets, "FX_FireBullets");
if(DFXFireBullets != NULL)
{
DFXFireBullets->EnableDetour();
return true;
}
g_pSM->LogError(myself, "FX_FireBullets detour could not be initialized");
return false;
}
PHP Code:
1707E15C push dword ptr [ebp+10h]
1707E15F push 0
1707E161 push dword ptr [ebp+8]
1707E164 call 1707DEB0
1707E169 push dword ptr [ebp+18h]
1707E16C push dword ptr [ebp+14h]
1707E16F call 1708489C
1707E174 pop ecx
1707E175 pop ecx
1707E176 pop ebp
1707E177 ret
1707E178 push ebp
1707E179 mov ebp,esp
1707E17B mov edx,dword ptr [ebp+0Ch]
1707E17E mov eax,dword ptr ds:[1709C2B0h]
1707E183 not edx
1707E185 mov ecx,dword ptr [ebp+8]
1707E188 and edx,eax
1707E18A and ecx,dword ptr [ebp+0Ch]
1707E18D or edx,ecx
1707E18F mov dword ptr ds:[1709C2B0h],edx
1707E195 pop ebp
1707E196 ret
1707E197 call 1708503F
1707E19C test eax,eax
1707E19E je 1707E1A8
1707E1A0 push 16h
1707E1A2 call 17085068
1707E1A7 pop ecx
1707E1A8 test byte ptr ds:[1709C2B0h],2
1707E1AF je 1707E1D2
1707E1B1 push 17h
1707E1B3 call 1708B1B8
1707E1B8 test eax,eax
1707E1BA je 1707E1C1
1707E1BC push 7
1707E1BE pop ecx
1707E1BF int 29h
1707E1C1 push 1
1707E1C3 push 40000015h
1707E1C8 push 3
1707E1CA call 1707E1E7
1707E1CF add esp,0Ch
1707E1D2 push 3
1707E1D4 call 1708087B
1707E1D9 int 3
1707E1DA push ebp
1707E1DB mov ebp,esp
1707E1DD mov eax,dword ptr [ebp+8]
1707E1E0 mov dword ptr ds:[1709DD68h],eax
1707E1E5 pop ebp
1707E1E6 ret
|
|