Skip to content

Commit

Permalink
Revert to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
tjone270 committed Jun 16, 2024
1 parent 530d250 commit 9b46a39
Show file tree
Hide file tree
Showing 13 changed files with 430 additions and 1,082 deletions.
26 changes: 13 additions & 13 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void __cdecl Slay(void) {
Com_Printf("Slaying player...\n");
SV_SendServerCommand(NULL, "print \"%s^7 was slain!\n\"\n", svs->clients[i].name);
DebugPrint("Slaying '%s'!\n", svs->clients[i].name);
g_entities[i].health = -40;
G_AddEvent(&g_entities[i], EV_GIB_PLAYER, g_entities[i].s.number);
g_entities[i].health = -40;
G_AddEvent(&g_entities[i], EV_GIB_PLAYER, g_entities[i].s.number);
}
else
Com_Printf("The player is currently not active.\n");
Expand All @@ -89,24 +89,24 @@ void __cdecl PyRcon(void) {
}

void __cdecl PyCommand(void) {
if (!custom_command_handler) {
return; // No registered handler.
}
PyGILState_STATE gstate = PyGILState_Ensure();
if (!custom_command_handler) {
return; // No registered handler.
}
PyGILState_STATE gstate = PyGILState_Ensure();

PyObject* result = PyObject_CallFunction(custom_command_handler, "s", Cmd_Args());
if (result == Py_False) {
Com_Printf("The command failed to be executed. pyminqlxtended found no handler.\n");
}
PyObject* result = PyObject_CallFunction(custom_command_handler, "s", Cmd_Args());
if (result == Py_False) {
Com_Printf("The command failed to be executed. pyminqlxtended found no handler.\n");
}

Py_XDECREF(result);
PyGILState_Release(gstate);
Py_XDECREF(result);
PyGILState_Release(gstate);
}

void __cdecl RestartPython(void) {
Com_Printf("Restarting Python...\n");
if (PyMinqlx_IsInitialized())
PyMinqlx_Finalize();
PyMinqlx_Finalize();
PyMinqlx_Initialize();
// minqlxtended initializes after the first new game starts, but since the game already
// start, we manually trigger the event to make it initialize properly.
Expand Down
9 changes: 1 addition & 8 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Cvar_Set2_ptr Cvar_Set2;
SV_SendServerCommand_ptr SV_SendServerCommand;
SV_ExecuteClientCommand_ptr SV_ExecuteClientCommand;
SV_ClientEnterWorld_ptr SV_ClientEnterWorld;
SV_ClientThink_ptr SV_ClientThink;
SV_Shutdown_ptr SV_Shutdown;
SV_Map_f_ptr SV_Map_f;
SV_SetConfigstring_ptr SV_SetConfigstring;
Expand All @@ -62,9 +61,6 @@ G_InitGame_ptr G_InitGame;
CheckPrivileges_ptr CheckPrivileges;
ClientConnect_ptr ClientConnect;
ClientSpawn_ptr ClientSpawn;
ClientUserinfoChanged_ptr ClientUserinfoChanged;
ClientBegin_ptr ClientBegin;
ClientEndFrame_ptr ClientEndFrame;
G_Damage_ptr G_Damage;
Touch_Item_ptr Touch_Item;
LaunchItem_ptr LaunchItem;
Expand Down Expand Up @@ -128,7 +124,6 @@ static void SearchFunctions(void) {
STATIC_SEARCH(SV_Shutdown, PTRN_SV_SHUTDOWN, MASK_SV_SHUTDOWN);
STATIC_SEARCH(SV_Map_f, PTRN_SV_MAP_F, MASK_SV_MAP_F);
STATIC_SEARCH(SV_ClientEnterWorld, PTRN_SV_CLIENTENTERWORLD, MASK_SV_CLIENTENTERWORLD);
STATIC_SEARCH(SV_ClientThink, PTRN_SV_CLIENTTHINK, MASK_SV_CLIENTTHINK);
STATIC_SEARCH(SV_SetConfigstring, PTRN_SV_SETCONFIGSTRING, MASK_SV_SETCONFIGSTRING);
STATIC_SEARCH(SV_GetConfigstring, PTRN_SV_GETCONFIGSTRING, MASK_SV_GETCONFIGSTRING);
STATIC_SEARCH(SV_DropClient, PTRN_SV_DROPCLIENT, MASK_SV_DROPCLIENT);
Expand Down Expand Up @@ -210,8 +205,7 @@ void InitializeStatic(void) {
// Initialize VM stuff. Needs to be called whenever Sys_SetModuleOffset is called,
// after qagame pointer has been initialized.
void InitializeVm(void) {
DebugPrint("Initializing VM pointers... ");

DebugPrint("Initializing VM pointers...\n");
#if defined(__x86_64__) || defined(_M_X64)
g_entities = (gentity_t*)(*(int32_t*)OFFSET_RELP_G_ENTITIES + OFFSET_RELP_G_ENTITIES + 4);
level = (level_locals_t*)(*(int32_t*)OFFSET_RELP_LEVEL + OFFSET_RELP_LEVEL + 4);
Expand All @@ -221,7 +215,6 @@ void InitializeVm(void) {
level = (level_locals_t*)(*(int32_t*)OFFSET_RELP_LEVEL + 0xCEFF4 + (pint)qagame);
bg_itemlist = (gitem_t*)*(int32_t*)((*(int32_t*)OFFSET_RELP_BG_ITEMLIST + 0xCEFF4 + (pint)qagame));
#endif

for (bg_numItems = 1; bg_itemlist[ bg_numItems ].classname; bg_numItems++);
}

Expand Down
194 changes: 1 addition & 193 deletions hooks.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#define _GNU_SOURCE
#define __STDC_FORMAT_MACROS

#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -61,63 +60,6 @@ void __cdecl My_Sys_SetModuleOffset(char* moduleName, void* offset) {
}
}

typedef void (__cdecl *race_point_touch_ptr)(gentity_t *a1, gentity_t *a2);
race_point_touch_ptr race_point_touch;

void __cdecl My_race_point_touch( gentity_t *ent, gentity_t *activator ) {
if (activator->client) {
if ( ent->spawnflags && activator->client->race.startTime && !ent->targetname )
return; //no more tr
}

activator->client->pers.teamState.flagruntime = level->time - activator->client->race.startTime;
race_point_touch(ent, activator);
}

void __cdecl My_race_point_touch_old( gentity_t *ent, gentity_t *activator ) {
if (activator->client) {
if (ent->message)
if ( !strncmp(ent->message, "notr", 4) && activator->client->race.startTime && !ent->targetname )
return; //no more tr
}

activator->client->pers.teamState.flagruntime = level->time - activator->client->race.startTime;
race_point_touch(ent, activator);
}

void __cdecl My_target_init_touch( gentity_t *ent, gentity_t *activator ) {
if (activator->client) {
//KEEPARMOR
if ( !(ent->spawnflags & 1) )
activator->client->ps.stats[STAT_ARMOR] = 0;

//KEEPHEALTH
if ( !(ent->spawnflags & 2) )
activator->health = 100;

//KEEPWEAPONS
if ( !(ent->spawnflags & 4) ) {
activator->client->ps.stats[STAT_WEAPONS] = 2<<(WP_MACHINEGUN-1);
memset( activator->client->ps.ammo, 0, sizeof( activator->client->ps.ammo ) );
activator->client->ps.ammo[WP_MACHINEGUN] = 100;
activator->client->ps.weapon = WP_MACHINEGUN;
}

//KEEPPOWERUPS
if ( !(ent->spawnflags & 8) )
memset( activator->client->ps.powerups, 0, sizeof( activator->client->ps.powerups ) );

//KEEPHOLDABLE
if ( !(ent->spawnflags & 16) )
activator->client->ps.stats[STAT_HOLDABLE_ITEM] = 0;

//REMOVEMACHINEGUN
if ( ent->spawnflags & 32 && activator->client->ps.stats[STAT_WEAPONS] & (2<<(WP_MACHINEGUN-1)) )
activator->client->ps.stats[STAT_WEAPONS] -= 2<<(WP_MACHINEGUN-1);
}
}


void __cdecl My_G_InitGame(int levelTime, int randomSeed, int restart) {
G_InitGame(levelTime, randomSeed, restart);

Expand All @@ -130,28 +72,6 @@ void __cdecl My_G_InitGame(int levelTime, int randomSeed, int restart) {
if (restart)
NewGameDispatcher(restart);
#endif

race_point_touch = (race_point_touch_ptr)qagame_dllentry + 0xEE60;

gentity_t *z1;
int j1;
for ( j1=1, z1=g_entities+j1 ; j1 < level->num_entities ; j1++,z1++ ) {
if (!z1->classname) continue;

if (z1->inuse) {
if (strncmp(z1->classname, "trigger_multiple", 16) == 0 && z1->message) {
if (strncmp(z1->message, "race_point", 10) == 0 && (z1->target || z1->targetname)) {
z1->touch = My_race_point_touch;
} else if (strncmp(z1->message, "target_init", 11) == 0) {
z1->touch = My_target_init_touch;
}
}
}

if (strncmp(z1->classname, "race_point", 10) == 0) {
z1->touch = My_race_point_touch_old;
}
}
}

// USED FOR PYTHON
Expand All @@ -177,7 +97,6 @@ void __cdecl My_SV_SendServerCommand(client_t* cl, char* fmt, ...) {
va_end(argptr);

char* res = buffer;
DebugPrint("SSC: %s\n", res);
if (cl && cl->gentity)
res = ServerCommandDispatcher(cl - svs->clients, buffer);
else if (cl == NULL)
Expand All @@ -201,59 +120,6 @@ void __cdecl My_SV_ClientEnterWorld(client_t* client, usercmd_t* cmd) {
}
}

void __cdecl My_SV_ClientThink(client_t *client, usercmd_t *cmd)
{
// Debug client dict
/*
int i = sizeof(client_t);
// 158328 on linux
DebugPrint(" ----\nsizeof c: %d\n", i);
DebugPrint("\n");
DebugPrint(" dl: %s, offset: %d\n", client->downloadName, (char*)&client->downloadName - (char*)client);
DebugPrint(" ds: %d, offset: %d\n", client->downloadSize, (char*)&client->downloadSize - (char*)client);
DebugPrint(" dc: %d, offset: %d\n", client->downloadCount, (char*)&client->downloadCount - (char*)client);
DebugPrint(" dcb: %d, offset: %d\n", client->downloadClientBlock, (char*)&client->downloadClientBlock - (char*)client);
DebugPrint(" dcrb: %d, offset: %d\n", client->downloadCurrentBlock, (char*)&client->downloadCurrentBlock - (char*)client);
DebugPrint(" dxb: %d, offset: %d\n", client->downloadXmitBlock, (char*)&client->downloadXmitBlock - (char*)client);
DebugPrint(" deof: %d, offset: %d\n", client->downloadEOF, (char*)&client->downloadEOF - (char*)client);
DebugPrint(" dst: %d, offset: %d\n", client->downloadSendTime, (char*)&client->downloadSendTime - (char*)client);
DebugPrint("\n");
DebugPrint(" uk0: %d, offset: %d\n", client->_unknown0, (char*)&client->_unknown0 - (char*)client);
DebugPrint(" uk1: %d, offset: %d\n", client->_unknown1, (char*)&client->_unknown1 - (char*)client);
DebugPrint(" ukt: %d, offset: %d\n", client->_unknownTime, (char*)&client->_unknownTime - (char*)client);
DebugPrint("\n");
DebugPrint(" dm: %d, offset: %d\n", client->deltaMessage, (char*)&client->deltaMessage - (char*)client);
DebugPrint(" nrt: %d, offset: %d\n", client->nextReliableTime, (char*)&client->nextReliableTime - (char*)client);
DebugPrint(" uk3: %d, offset: %d\n", client->_unknown3, (char*)&client->_unknown3 - (char*)client);
DebugPrint("\n");
DebugPrint(" lpt: %d, offset: %d\n", client->lastPacketTime, (char*)&client->lastPacketTime - (char*)client);
DebugPrint(" lct: %d, offset: %d\n", client->lastConnectTime, (char*)&client->lastConnectTime - (char*)client);
DebugPrint(" nst: %d, offset: %d\n", client->nextSnapshotTime, (char*)&client->nextSnapshotTime - (char*)client);
DebugPrint(" rd: %d, offset: %d\n", client->rateDelayed, (char*)&client->rateDelayed - (char*)client);
DebugPrint(" toc: %d, offset: %d\n", client->timeoutCount, (char*)&client->timeoutCount - (char*)client);
DebugPrint("\n");
DebugPrint(" ping: %d, offset: %d\n", client->ping, (char*)&client->ping - (char*)client);
DebugPrint(" rate: %d, offset: %d\n", client->rate, (char*)&client->rate - (char*)client);
DebugPrint(" snms: %d, offset: %d\n", client->snapshotMsec, (char*)&client->snapshotMsec - (char*)client);
DebugPrint(" pure: %d, offset: %d\n", client->pureAuthentic, (char*)&client->pureAuthentic - (char*)client);
DebugPrint("\n");
DebugPrint(" steamid: %" PRId64 ", offset: %d\n", client->steam_id, (char*)&client->steam_id - (char*)client);
// for (size_t i = 0; i < sizeof(client_t) - 3; i++)
// {
// int val = *(int*)((char*)client + i);
// if (val != 0)
// DebugPrint(" byte offset %d as int: %d\n", i, val);
// }
*/

ClientThinkDispatcher(client - svs->clients, cmd);
SV_ClientThink(client, cmd);
}


void __cdecl My_SV_SetConfigstring(int index, char* value) {
// Indices 16 and 66X are spammed a ton every frame for some reason,
// so we add some exceptions for those. I don't think we should have any
Expand Down Expand Up @@ -331,12 +197,6 @@ void __cdecl My_ClientSpawn(gentity_t* ent) {
ClientSpawnDispatcher(ent - g_entities);
}

gentity_t* __cdecl My_LaunchItem( gitem_t *item, vec3_t origin, vec3_t velocity ) {
gentity_t* r = LaunchItem(item, origin, velocity);
LaunchItemDispatcher(item, origin, velocity);
return r;
}

void __cdecl My_G_StartKamikaze(gentity_t* ent) {
int client_id, is_used_on_demand;

Expand All @@ -363,36 +223,6 @@ 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 - g_entities;

attacker_id = attacker - g_entities;

DamageDispatcher(target_id, attacker_id, damage, dflags, mod);
}
#endif

// Hook static functions. Can be done before program even runs.
Expand Down Expand Up @@ -427,12 +257,6 @@ void HookStatic(void) {
failed = 1;
}

res = Hook((void*)SV_ClientThink, My_SV_ClientThink, (void*)&SV_ClientThink);
if (res) {
DebugPrint("ERROR: Failed to hook SV_ClientThink: %d\n", res);
failed = 1;
}

res = Hook((void*)SV_SendServerCommand, My_SV_SendServerCommand, (void*)&SV_SendServerCommand);
if (res) {
DebugPrint("ERROR: Failed to hook SV_SendServerCommand: %d\n", res);
Expand Down Expand Up @@ -494,8 +318,6 @@ void HookVm(void) {
*(void**)(vm_call_table + RELOFFSET_VM_CALL_INITGAME) = My_G_InitGame;

G_RunFrame = *(G_RunFrame_ptr*)(vm_call_table + RELOFFSET_VM_CALL_RUNFRAME);
ClientUserinfoChanged = *(ClientUserinfoChanged_ptr*)(vm_call_table + RELOFFSET_VM_CALL_CLIENTUSERINFOCHANGED);
ClientBegin = *(ClientBegin_ptr*)(vm_call_table + RELOFFSET_VM_CALL_CLIENTBEGIN);

#ifndef NOPY
*(void**)(vm_call_table + RELOFFSET_VM_CALL_RUNFRAME) = My_G_RunFrame;
Expand All @@ -506,7 +328,7 @@ void HookVm(void) {
DebugPrint("ERROR: Failed to hook ClientConnect: %d\n", res);
failed = 1;
}
count++;
count++;

res = Hook((void*)G_StartKamikaze, My_G_StartKamikaze, (void*)&G_StartKamikaze);
if (res) {
Expand All @@ -515,25 +337,11 @@ void HookVm(void) {
}
count++;

res = Hook((void*)LaunchItem, My_LaunchItem, (void*)&LaunchItem);
if (res) {
DebugPrint("ERROR: Failed to hook LaunchItem: %d\n", res);
failed = 1;
}
count++;

res = Hook((void*)ClientSpawn, My_ClientSpawn, (void*)&ClientSpawn);
if (res) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ void vote_clientkick_fix(void) {

void patch_vm(void) {
vote_clientkick_fix();
}
}
2 changes: 1 addition & 1 deletion patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ void patch_vm(void);
#define PTRN_VOTE_CLIENTKICK_FIX "\x69\xc8\xd0\x0b\x0\x0\x01\xca\x90\x0\x44\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x6c\x90\x90\x90\x90\x90\x90\x90\x90"
#define MASK_VOTE_CLIENTKICK_FIX "XXXXXXXXX-X------------XXXXXXXXX"

#endif
#endif
2 changes: 1 addition & 1 deletion patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@



#endif /* PATTERNS_H */
#endif /* PATTERNS_H */
Loading

0 comments on commit 9b46a39

Please sign in to comment.