Jump to content
Korean Random

Python C Api Hooking

Recommended Posts

Good day,

I am trying to hook a Python function (Vehicle.onHealthChanged) with Python C Api.

I create my hOnHealthChanged function like in the first codeblock.

the problem is, I am hooking the onHealthChanged class function and I can‘t seem to get the vehicle instance when my hook gets called.

Because I create the function with nullptr as the second parameter, „self“ will always be zero when called. When the original function gets called, the game has pass the vehicle instance as the first argument, to my understanding, but I can‘t get it. The first argument in args is newHealth.

Do I have to hook every instance when it gets created or is there a way to dynamically get the needed vehicle instance?

I am trying to make a simple hitmarker mod in C++


PyMethodDef hookedPlayerDef = { "onHealthChanged", hOnHealthChanged, 1, "hooked onHealthChanged"};

PyObject* hookedFunc = PyCFunction_New(&hookedPlayerDef, nullptr);

hOnHealthChanged gets correctly called when a vehicle ingame receives damage, but it fails to execute the original method, because „self“ argument is zero and it needs the vehicle instance. 4 other arguments are correct.

HMU if you got any idea

Share this post

Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...