I'm playing a bit with CDetour and trying to learn how it works. I've found this module by Arkshine:
https://forums.alliedmods.net/showpo...51&postcount=7 which I'm using as an example to hook
CGrenade::ShootTimed2.
PHP Code:
//
// AMX Mod X SetAnimation Forward
// Copyright (C) Vincent Herbet (Arkshine)
//
// This software is licensed under the GNU General Public License, version 2.
// For full license details, see LICENSE file.
//
#include "setanimation.h"
#include "gamedatas.h"
#include "utils.h"
#include <MemoryUtils.h>
#include <CDetour/detours.h>
CDetour* ShootTimed2Detour;
DETOUR_DECL_MEMBER6(ShootTimed2, CBaseEntity *, entvars_t *, pevOwner, Vector, vecStart, Vector, vecVelocity, float, time, int, iTeam, unsigned short, usEvent)
{
CBaseEntity * Return = DETOUR_MEMBER_CALL(ShootTimed2)(pevOwner, vecStart, vecVelocity, time, iTeam, usEvent);
const void *pvPlayer = reinterpret_cast<const void*>(Return);
SERVER_PRINT(UTIL_VarArgs("%i [%f %f %f] [%f %f %f] %f %i %i %i", pevOwner, vecStart[0], vecStart[1], vecStart[2], vecVelocity[0], vecVelocity[1], vecVelocity[2], time, iTeam, usEvent, pvPlayer));
return Return;
}
void ActivateDetour()
{
void* funcAddress = Utils::FindAddressFromEntry(FUNC_SHOOTTIMED2);
ShootTimed2Detour = DETOUR_CREATE_MEMBER_FIXED(ShootTimed2, funcAddress);
if (ShootTimed2Detour && funcAddress)
{
ShootTimed2Detour->EnableDetour();
}
else
{
if (!funcAddress)
{
SERVER_PRINT("[SETANIMATION] CGrenade::ShootTimed2 address could not be found.\n");
}
}
}
void DestroyDetour()
{
if (ShootTimed2Detour)
{
ShootTimed2Detour->Destroy();
}
}
Signature:
PHP Code:
#define FUNC_SHOOTTIMED2 "\\x83\\x2A\\x2A\\x56\\x57\\xFF\\x2A\\x2A\\x2A\\x2A\\x2A\\x85\\x2A\\x75\\x2A\\x33\\x2A\\xEB\\x2A\\x8D\\x2A\\x2A\\x2A\\x2A\\x2A\\x8B\\x2A\\x2A\\x2A\\x2A\\x2A\\x85\\x2A\\x74\\x2A\\x8B\\x2A\\x2A\\x85\\x2A\\x75\\x2A\\x68\\x2A\\x2A\\x2A\\x2A\\x50\\xFF\\x2A\\x2A\\x2A\\x2A\\x2A\\x8B"
When I throw a grenade I get the debug message with the right values, and right after that the server crashes with this error message:
Code:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
I've read a lot of threads about this error but I can't figure out what I did wrong. Any help?
__________________