[HL2DM] GetPlayerMaxSpeed crashing

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 114
Joined: Thu Dec 18, 2014 2:41 am

[HL2DM] GetPlayerMaxSpeed crashing

Postby VinciT » Sat Oct 19, 2019 4:44 pm

I'm trying to hook CBasePlayer::GetPlayerMaxSpeed() and the server (Windows) keeps crashing the moment I load the plugin.

Here's my CBasePlayer.ini:

Syntax: Select all

[virtual_function]

[[get_player_max_speed]]
offset_linux = 438
offset_windows = 437
return_type = FLOAT
And the plugin code:

Syntax: Select all

# ../max_speed_test/max_speed_test.py

# Source.Python
from entities.hooks import EntityPreHook, EntityCondition
from memory import make_object
from memory.manager import TypeManager
from path import Path


manager = TypeManager()

CBasePlayer = manager.create_type_from_file(
'CBasePlayer', Path(__file__).parent / 'CBasePlayer.ini')


@EntityPreHook(
EntityCondition.is_player,
lambda entity: make_object(CBasePlayer, entity.pointer).get_player_max_speed)
def get_player_max_speed_pre(stack_data):
print('test')
return 0.0

Any idea why it's crashing? At first I thought it was cause I wasn't returning a float, but even after I added that, it still crashes.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1178
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2DM] GetPlayerMaxSpeed crashing

Postby L'In20Cible » Sun Oct 20, 2019 4:24 am

Seems like you found a bug. After some testing, seems like calling an hooked function that return a float or a double through the ST0 register is causing an access violation which causes a crash when the game itself is calling said function. I've tested multiple functions on different games and always got the same results. The shortest reproducible code:

Syntax: Select all

from memory import Convention, DataType, NULL, Pointer
from memory.hooks import PreHook
from players.entity import Player

pl = Player(1)
fn = pl.pointer.make_virtual_function(437, Convention.THISCALL, [DataType.POINTER,], DataType.FLOAT)

print(fn(pl))

@PreHook(fn)
def callback(stack):
print(stack)

print(fn(pl))

Which results into:

Syntax: Select all

190.0
Hooking function: type=PRE, addr=1505250672, conv=THISCALL, args=(_memory.DataType.POINTER,), rtype=FLOAT, callback=<function callback at 0x1EFB6348>

[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 194, in load
plugin._load()
File "..\addons\source-python\packages\source-python\plugins\instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "..\addons\source-python\plugins\testing\testing.py", line 14, in <module>
print(fn(pl))
File "<string>", line 1, in <lambda>

RuntimeError: Access violation while executing address '0'.


[SP] Plugin 'testing' was unable to be loaded.

Where the first print statement is working as intended and prints 190.0 then the second is causing the access violation. The game itself is not catching the exception, so it simply crashes. It is also not a conflict between dyncall and DynamicHooks because a straight call from a function exported by boost is also causing a crash after being hooked:

Syntax: Select all

from engines.server import engine_server
from memory import get_virtual_function
from memory.hooks import PreHook

print(engine_server.sentence_length(1))

@PreHook(get_virtual_function(engine_server, 'SentenceLength'))
def pre_sentence_lenght(stack_data):
pass

print(engine_server.sentence_length(1))

So yeah, there is definitely an issue somewhere when hooking a function that returns a float or a double. At least, THISCALL functions on Windows.
User avatar
L'In20Cible
Project Leader
Posts: 1178
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2DM] GetPlayerMaxSpeed crashing

Postby L'In20Cible » Tue Oct 22, 2019 1:45 am

I haven't made extensive testing yet but I believe the following build should works: ../hl2mp/addons/source-python/bin/core.dll. Please let me know if it works for you or if it is causing more issues.
User avatar
VinciT
Senior Member
Posts: 114
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2DM] GetPlayerMaxSpeed crashing

Postby VinciT » Tue Oct 22, 2019 2:18 am

I got a couple of warnings(?) during server start-up:

Code: Select all

Message type 5431 wasn't declared, but we registered job CClientJobRequestAuthList to handle it?
Message type 9900 wasn't declared, but we registered job ClientJobPeerChunkRequest to handle it?
Message type 9503 wasn't declared, but we registered job RemoteClientJobStartStream to handle it?
Message type 9505 wasn't declared, but we registered job RemoteClientJobPing to handle it?
Message type 9510 wasn't declared, but we registered job RemoteClientJobGetControllerConfig to handle it?
Message type 10100 wasn't declared, but we registered job ClientJobReceiveSiteInfo to handle it?
Message type 10101 wasn't declared, but we registered job ClientJobSiteLicenseCheckout to handle it?
Message type 10103 wasn't declared, but we registered job ClientJobSiteLicenseGetAvailableSeats to handle it?
Message type 10105 wasn't declared, but we registered job CClientJobSiteLicenseGetContentCacheInfo to handle it?
But it works! The server is no longer crashing when I load the plugin. Thanks L'In20Cible! :grin:
Image
User avatar
L'In20Cible
Project Leader
Posts: 1178
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2DM] GetPlayerMaxSpeed crashing

Postby L'In20Cible » Tue Oct 22, 2019 6:33 am

VinciT wrote:I got a couple of warnings(?) during server start-up:

Code: Select all

Message type 5431 wasn't declared, but we registered job CClientJobRequestAuthList to handle it?
Message type 9900 wasn't declared, but we registered job ClientJobPeerChunkRequest to handle it?
Message type 9503 wasn't declared, but we registered job RemoteClientJobStartStream to handle it?
Message type 9505 wasn't declared, but we registered job RemoteClientJobPing to handle it?
Message type 9510 wasn't declared, but we registered job RemoteClientJobGetControllerConfig to handle it?
Message type 10100 wasn't declared, but we registered job ClientJobReceiveSiteInfo to handle it?
Message type 10101 wasn't declared, but we registered job ClientJobSiteLicenseCheckout to handle it?
Message type 10103 wasn't declared, but we registered job ClientJobSiteLicenseGetAvailableSeats to handle it?
Message type 10105 wasn't declared, but we registered job CClientJobSiteLicenseGetContentCacheInfo to handle it?
Weird. I don't get these and cannot find any info searching for them. Their names tend to point as if they were trying to get a floating license or something. Anyways, don't tell anyone, but I was trying to steal your cat pictures. :wink:
VinciT wrote:But it works! The server is no longer crashing when I load the plugin. Thanks L'In20Cible! :grin:

Nice! All the testing I've made also seems to works fine in all cases. You can find the changes I made here.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests