Server crash on @EntityPreHook

Please post any questions about developing your plugin here. Please use the search function before posting!
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Server crash on @EntityPreHook

Postby InvisibleSoldiers » Tue Jan 07, 2020 2:16 am

Syntax: Select all

from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
from memory import Convention
from memory import DataType

def make_function(pointer):
return pointer.make_virtual_function(290, Convention.THISCALL, (DataType.POINTER, ), DataType.POINTER)

@EntityPreHook(EntityCondition.is_human_player, lambda entity: make_function(entity.pointer))
def entity_pre_hook(stack_data):
print('test')


Tried to hook:

Syntax: Select all

Vector CBasePlayer::Weapon_ShootPosition( )
{
return EyePosition();
}

The hook is working and 'test' was printed, but it leaded to server crash.

Syntax: Select all

Checksum      : 3c0e4aa6746ee4cbdbfafbe80eb3c760
Date : 2020-01-07 02:17:50.173790
OS : Linux-5.3.0-7625-generic-x86_64-with-debian-buster-sid
Game : csgo
SP version : 694
Github commit : e65bf547b5f036b50a89dc9461af75efb24a3b1d
Server plugins:
00: Source.Python, (C) 2012-2019, Source.Python Team.
SP plugins:
00: combat
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Server crash on @EntityPreHook

Postby L'In20Cible » Tue Jan 07, 2020 10:14 am

For CS:GO, that function's prototype appears to be:

Syntax: Select all

Vector Weapon_ShootPosition(Vector &vecOut);
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: Server crash on @EntityPreHook

Postby InvisibleSoldiers » Tue Jan 07, 2020 11:52 am

L'In20Cible wrote:For CS:GO, that function's prototype appears to be:

Syntax: Select all

Vector Weapon_ShootPosition(Vector &vecOut);

Syntax: Select all

def make_function(pointer):
return pointer.make_virtual_function(290, Convention.THISCALL, (DataType.POINTER, DataType.POINTER), DataType.POINTER)

@EntityPreHook(EntityCondition.is_human_player, lambda entity: make_function(entity.pointer))
def entity_pre_hook(stack_data):
print('test')

Crash still happens.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Server crash on @EntityPreHook

Postby L'In20Cible » Tue Jan 07, 2020 2:37 pm

InvisibleSoldiers wrote:Crash still happens.

The following worked for me on Windows:

Syntax: Select all

from players.entity import Player
from mathlib import Vector
from memory import Convention
from memory import DataType

pl = Player(1)
fn = pl.make_virtual_function(289, Convention.THISCALL, (DataType.POINTER, DataType.POINTER), DataType.POINTER)

result = Vector()
fn(pl, result)
print(result)


Along with pre and post hooks. Must be using an unusual convention on Linux, or that slot points to a thunk (_ZThn* instead of _ZN* symbol). Try to grab a straight signature to the later, or restructure the convention.
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: Server crash on @EntityPreHook

Postby InvisibleSoldiers » Tue Jan 07, 2020 2:54 pm

L'In20Cible wrote:Along with pre and post hooks. Must be using an unusual convention on Linux, or that slot points to a thunk (_ZThn* instead of _ZN* symbol). Try to grab a straight signature to the later, or restructure the convention.

Tried CDECL, THISCALL but STDCALL and CUSTOM give the error.

Syntax: Select all

TypeError: 'Convention' object is not callable

And i don't know what do you mean about this:
L'In20Cible wrote:or that slot points to a thunk (_ZThn* instead of _ZN* symbol).
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Server crash on @EntityPreHook

Postby L'In20Cible » Thu Jan 09, 2020 2:39 am

InvisibleSoldiers wrote:Tried CDECL, THISCALL but STDCALL and CUSTOM give the error.

Syntax: Select all

TypeError: 'Convention' object is not callable

To use a custom convention, you must subclass CallingConvention telling it where to retrieve the arguments, etc. Ayuto provided some examples in the past: search.php?keywords=callingconvention

InvisibleSoldiers wrote:And i don't know what do you mean about this:
L'In20Cible wrote:or that slot points to a thunk (_ZThn* instead of _ZN* symbol).

A virtual thunk is basically a wrapper generated by the compiler used to resolve clashes for complex inheritance classes. I don't think this is the case here, but always a possibility which can point you in the right direction to solve your issue.
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: Server crash on @EntityPreHook

Postby InvisibleSoldiers » Sun Jan 12, 2020 1:59 pm

Original plugin uses only it, without any conventions: _hWeapon_ShootPosition = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_CBaseEntity);
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: Server crash on @EntityPreHook

Postby Sam » Mon Jan 13, 2020 12:34 pm

InvisibleSoldiers wrote:Original plugin uses only it, without any conventions: _hWeapon_ShootPosition = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_CBaseEntity);


SourceMod - DHooks (Dynamic Hooks - Dev Preview)
You can look at the source code and find out what is there. :P
Last edited by Sam on Mon Jan 13, 2020 12:34 pm, edited 1 time in total.
Reason: Original post version
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Server crash on @EntityPreHook

Postby Ayuto » Mon Jan 13, 2020 7:40 pm

InvisibleSoldiers wrote:Original plugin uses only it, without any conventions: _hWeapon_ShootPosition = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_CBaseEntity);

Since it creates a hook using an offset/index in the vtable, it probably assumes THISCALL internally. There is always a convention, because it defines which registers need to be saved/restored, where to grab the function arguments from and who is responsible for cleaning up the stack.

Unfortunately, I can't help you with the crash (currently), because I'm out of town.
Sam
Senior Member
Posts: 100
Joined: Tue Jul 03, 2018 3:00 pm
Location: *DELETED*
Contact:

Re: Server crash on @EntityPreHook

Postby Sam » Tue Jan 14, 2020 12:56 am

Ayuto wrote:
InvisibleSoldiers wrote:Original plugin uses only it, without any conventions: _hWeapon_ShootPosition = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_CBaseEntity);

Since it creates a hook using an offset/index in the vtable, it probably assumes THISCALL internally. There is always a convention, because it defines which registers need to be saved/restored, where to grab the function arguments from and who is responsible for cleaning up the stack.

Unfortunately, I can't help you with the crash (currently), because I'm out of town.


A similar situation with the city xD
Last edited by Sam on Tue Jan 14, 2020 12:56 am, edited 1 time in total.
Reason: Original post version
InvisibleSoldiers
Senior Member
Posts: 114
Joined: Fri Mar 15, 2019 6:08 am

Re: Server crash on @EntityPreHook

Postby InvisibleSoldiers » Thu Jan 30, 2020 3:55 pm

ааа
Jezza
Junior Member
Posts: 16
Joined: Tue Aug 28, 2012 5:52 pm

Re: Server crash on @EntityPreHook

Postby Jezza » Sun Sep 13, 2020 7:34 pm

A struct (Vector) is passed to the function as a hidden pointer, so callee has to clean up the stack for 4 bytes.
https://gcc.gnu.org/onlinedocs/gcc/x86- ... e_002c-x86

As L'In20Cible wrote, you can hook it by creating a custom calling convention.

There is also a pull request on Github that adds the default convention to CallingConvention.
https://github.com/Source-Python-Dev-Te ... n/pull/344

Syntax: Select all

# Source.Python Imports
# Memory
from memory import CallingConvention
from memory import Convention

class Pop4(CallingConvention):
def __init__(self, arg_types, return_type):
super().__init__(arg_types, return_type,
default_convention=Convention.CDECL)

def get_pop_size(self):
return 4

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 23 guests