Raised This Month: $12 Target: $400
 3% 

Run-Time Check Failure #0 - The value of ESP was not properly saved


Post New Thread Reply   
 
Thread Tools Display Modes
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
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-08-2017 , 09:04   Re: Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #2

Because this function is static: https://github.com/s1lentq/ReGameDLL...weapons.h#L187

Meaning, there is no object involved, you have to hook it as a normal (static) function, without forgetting the first argument is the grenade.
__________________

Last edited by Arkshine; 10-08-2017 at 09:05.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-08-2017 , 10:43   Re: Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #3

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_STATIC7(ShootTimed2CBaseEntity *, CBaseEntity *, grenadeEntityentvars_t *, pevOwnerVectorvecStartVectorvecVelocityfloattimeintiTeamunsigned shortusEvent)
{
    
CBaseEntity * Return = DETOUR_STATIC_CALL(ShootTimed2)(grenadeEntitypevOwnervecStartvecVelocitytimeiTeamusEvent);
    
SERVER_PRINT(UTIL_VarArgs("Debug: %i %i [%f %f %f] [%f %f %f] %f %i %i"grenadeEntitypevOwnervecStart[0], vecStart[1], vecStart[2], vecVelocity[0], vecVelocity[1], vecVelocity[2], timeiTeamusEvent));
    return Return;
}

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

    
ShootTimed2Detour DETOUR_CREATE_STATIC_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();
    }

Thanks, it's no longer crashing. But I am not sure how to add the grenade argument. If I simply put it and use DETOUR_DECL_STATIC7 instead of DETOUR_DECL_STATIC6 all parameters have wrong values, which means I'm doing something wrong. How do I do that?
__________________

Last edited by HamletEagle; 10-08-2017 at 10:46.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-08-2017 , 11:09   Re: Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #4

Maybe I said bullshits, try 6 params then. Also, you should use %p if you output pointers.
__________________
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-08-2017 , 11:20   Re: Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #5

With 6 parameters it works fine. I have some other questions:
-About pre/post: pre would be before DETOUR_STATIC_CALL and post after?
-I saw there's something called CHooker(tried it and it worked). What's the difference between CDetour and CHooker? Can CHooker/CDetour be used to modify global variables or directly change memory?
-Why this part of code is needed under linux?
PHP Code:
asm volatile
(
    
"movl %%edx, %0;"
    "movl %%eax, %1;"
    
"=d" (playerAnim), "=a" (pvPlayer) : :
);
#endif 
__________________

Last edited by HamletEagle; 10-08-2017 at 11:21.
HamletEagle is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 10-10-2017 , 15:00   Re: Run-Time Check Failure #0 - The value of ESP was not properly saved
Reply With Quote #6

I think it's a problem between GCC and asm insertions, and maybe that's why you should put it first on function. If I'm right you are retrieving data and set into variables.

Just saying I'm not pretty sure.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 10-10-2017 at 15:13.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode