View Single Post
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-08-2017 , 08:48   Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #1

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>

CDetourShootTimed2Detour;

DETOUR_DECL_MEMBER6(ShootTimed2CBaseEntity *, entvars_t *, pevOwnerVectorvecStartVectorvecVelocityfloattimeintiTeamunsigned shortusEvent)
{
    
CBaseEntity * Return = DETOUR_MEMBER_CALL(ShootTimed2)(pevOwnervecStartvecVelocitytimeiTeamusEvent);

    const 
void *pvPlayer reinterpret_cast<const void*>(Return);
    
SERVER_PRINT(UTIL_VarArgs("%i [%f %f %f] [%f %f %f] %f %i %i %i"pevOwnervecStart[0], vecStart[1], vecStart[2], vecVelocity[0], vecVelocity[1], vecVelocity[2], timeiTeamusEventpvPlayer));
    return Return;
}

void ActivateDetour()
{
    
voidfuncAddress Utils::FindAddressFromEntry(FUNC_SHOOTTIMED2);

    
ShootTimed2Detour DETOUR_CREATE_MEMBER_FIXED(ShootTimed2funcAddress);

    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?
__________________

Last edited by HamletEagle; 10-08-2017 at 08:51.
HamletEagle is offline