-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added new hook, handler and dispatcher for any damage events happening #120
base: master
Are you sure you want to change the base?
Changes from 9 commits
60dc507
f8ae6e7
96268f0
b3881ba
31a6342
8b05871
e5ecd85
a80144e
3112eb0
292ffa3
3d84b2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,38 @@ void __cdecl My_G_StartKamikaze(gentity_t* ent) { | |
if (client_id != -1) | ||
KamikazeExplodeDispatcher(client_id, is_used_on_demand); | ||
} | ||
|
||
void __cdecl My_G_Damage( | ||
gentity_t* target, // entity that is being damaged | ||
gentity_t* inflictor, // entity that is causing the damage | ||
gentity_t* attacker, // entity that caused the inflictor to damage targ | ||
vec3_t dir, // direction of the attack for knockback | ||
vec3_t point, // point at which the damage is being inflicted, used for headshots | ||
int damage, // amount of damage being inflicted | ||
int dflags, // these flags are used to control how T_Damage works | ||
int mod // means_of_death indicator | ||
) { | ||
int target_id; | ||
int attacker_id = -1; | ||
|
||
G_Damage(target, inflictor, attacker, dir, point, damage, dflags, mod); | ||
|
||
if (!target) { | ||
return; | ||
} | ||
|
||
if (!target->client) { | ||
return; | ||
} | ||
|
||
target_id = target->client->ps.clientNum; | ||
|
||
if (attacker && attacker->client) { | ||
attacker_id = attacker->client->ps.clientNum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
|
||
DamageDispatcher(target_id, attacker_id, damage, dflags, mod); | ||
} | ||
#endif | ||
|
||
// Hook static functions. Can be done before program even runs. | ||
|
@@ -342,6 +374,13 @@ void HookVm(void) { | |
DebugPrint("ERROR: Failed to hook ClientSpawn: %d\n", res); | ||
failed = 1; | ||
} | ||
count++; | ||
|
||
res = Hook((void*)G_Damage, My_G_Damage, (void*)&G_Damage); | ||
if (res) { | ||
DebugPrint("ERROR: Failed to hook G_Damage: %d\n", res); | ||
failed = 1; | ||
} | ||
count++; | ||
|
||
if (failed) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,18 @@ def handle_kamikaze_explode(client_id, is_used_on_demand): | |
minqlx.log_exception() | ||
return True | ||
|
||
def handle_damage(target_id, attacker_id, damage, dflags, mod): | ||
target_player = minqlx.Player(target_id) if target_id in range(0, 64) else None | ||
inflictor_player = minqlx.Player(attacker_id) if attacker_id is not None and attacker_id in range(0, 64) else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need check validity of target_id and attacker_id. My_G_Damage is expected to pass valid ids |
||
# noinspection PyBroadException | ||
try: | ||
minqlx.EVENT_DISPATCHERS["damage"].dispatch( | ||
target_player, inflictor_player, damage, dflags, mod | ||
) | ||
except: # noqa: E722 | ||
minqlx.log_exception() | ||
return True | ||
|
||
def handle_console_print(text): | ||
"""Called whenever the server prints something to the console and when rcon is used.""" | ||
try: | ||
|
@@ -510,3 +522,4 @@ def register_handlers(): | |
|
||
minqlx.register_handler("kamikaze_use", handle_kamikaze_use) | ||
minqlx.register_handler("kamikaze_explode", handle_kamikaze_explode) | ||
minqlx.register_handler("damage", handle_damage) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ PyObject* client_spawn_handler = NULL; | |
PyObject* kamikaze_use_handler = NULL; | ||
PyObject* kamikaze_explode_handler = NULL; | ||
|
||
PyObject* damage_handler = NULL; | ||
|
||
static PyThreadState* mainstate; | ||
static int initialized = 0; | ||
|
||
|
@@ -71,6 +73,8 @@ static handler_t handlers[] = { | |
{"kamikaze_use", &kamikaze_use_handler}, | ||
{"kamikaze_explode", &kamikaze_explode_handler}, | ||
|
||
{"damage", &damage_handler}, | ||
|
||
{NULL, NULL} | ||
}; | ||
|
||
|
@@ -117,6 +121,7 @@ static PyStructSequence_Field player_state_fields[] = { | |
{"powerups", "The player's powerups."}, | ||
{"holdable", "The player's holdable item."}, | ||
{"flight", "A struct sequence with flight parameters."}, | ||
{"is_chatting", "Whether the player is currently chatting."}, | ||
{"is_frozen", "Whether the player is frozen(freezetag)."}, | ||
{NULL} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is from other PR |
||
|
@@ -757,7 +762,8 @@ static PyObject* PyMinqlx_PlayerState(PyObject* self, PyObject* args) { | |
PyLong_FromLongLong(g_entities[client_id].client->ps.stats[STAT_FLIGHT_REFUEL])); | ||
PyStructSequence_SetItem(state, 11, flight); | ||
|
||
PyStructSequence_SetItem(state, 12, PyBool_FromLong(g_entities[client_id].client->ps.pm_type == 4)); | ||
PyStructSequence_SetItem(state, 12, PyBool_FromLong(g_entities[client_id].client->ps.eFlags & EF_TALK != 0)); | ||
PyStructSequence_SetItem(state, 13, PyBool_FromLong(g_entities[client_id].client->ps.pm_type == 4)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is from other PR |
||
|
||
return state; | ||
} | ||
|
@@ -1499,7 +1505,11 @@ void replace_item_core(gentity_t* ent, int item_id) { | |
static PyObject* PyMinqlx_ReplaceItems(PyObject* self, PyObject* args) { | ||
PyObject *arg1, *arg2 ; | ||
int entity_id = 0, item_id = 0; | ||
#if PY_VERSION_HEX < ((3 << 24) | (7 << 16)) | ||
char *entity_classname = NULL, *item_classname = NULL; | ||
#else | ||
const char *entity_classname = NULL, *item_classname = NULL; | ||
#endif | ||
gentity_t* ent; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already merged |
||
|
||
|
||
|
@@ -1873,6 +1883,13 @@ static PyObject* PyMinqlx_InitModule(void) { | |
PyModule_AddIntMacro(module, MOD_HMG); | ||
PyModule_AddIntMacro(module, MOD_RAILGUN_HEADSHOT); | ||
|
||
// damage flags | ||
PyModule_AddIntMacro(module, DAMAGE_RADIUS); | ||
PyModule_AddIntMacro(module, DAMAGE_NO_ARMOR); | ||
PyModule_AddIntMacro(module, DAMAGE_NO_KNOCKBACK); | ||
PyModule_AddIntMacro(module, DAMAGE_NO_PROTECTION); | ||
PyModule_AddIntMacro(module, DAMAGE_NO_TEAM_PROTECTION); | ||
|
||
// Initialize struct sequence types. | ||
PyStructSequence_InitType(&player_info_type, &player_info_desc); | ||
PyStructSequence_InitType(&player_state_type, &player_state_desc); | ||
|
@@ -1914,7 +1931,9 @@ PyMinqlx_InitStatus_t PyMinqlx_Initialize(void) { | |
Py_SetProgramName(PYTHON_FILENAME); | ||
PyImport_AppendInittab("_minqlx", &PyMinqlx_InitModule); | ||
Py_Initialize(); | ||
#if PY_VERSION_HEX < ((3 << 24) | (7 << 16)) | ||
PyEval_InitThreads(); | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already merged |
||
|
||
// Add the main module. | ||
PyObject* main_module = PyImport_AddModule("__main__"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if target->client is spectating, ps.clientNum is the player who is being spectated.