Skip to content

Commit

Permalink
EXPERIMENTAL: Ditch iwd verefication
Browse files Browse the repository at this point in the history
I don't know, this apparantly only causes more cons than pros, looks like there is some possibility to abuse it and make the server lag. Tried to modify referenced iwd's with this and still was unable to join so idk. Also fixed grenade and vid restart callbacks. Also added possiblity to force client download.
  • Loading branch information
voron00 committed Oct 22, 2017
1 parent 471dc76 commit 8829e43
Showing 1 changed file with 62 additions and 41 deletions.
103 changes: 62 additions & 41 deletions libcod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ cvar_t *sv_pure;
cvar_t *developer;
cvar_t *rcon_password;
cvar_t *con_coloredPrints;
cvar_t *cl_allowDownload;

#if COD_VERSION == COD2_1_2 || COD_VERSION == COD2_1_3
cvar_t *sv_wwwDownload;
cvar_t *cl_wwwDownload;
#endif

void hook_sv_init(char *format, ...)
Expand Down Expand Up @@ -114,48 +116,25 @@ cHook *hook_fire_grenade;
int fire_grenade(int player, int a2, int a3, int weapon, int a5)
{
hook_fire_grenade->unhook();

int (*sig)(int player, int a2, int a3, int a4, int a5);
*(int *)&sig = hook_fire_grenade->from;
int grenade = sig(player, a2, a3, weapon, a5);
hook_fire_grenade->hook();
int weapondef = BG_WeaponDefs(weapon);
char *weaponname = *(char**)weapondef;
stackPushString(weaponname);
stackPushEntity(grenade);
short ret = Scr_ExecEntThread(player, codecallback_fire_grenade, 2);
Scr_FreeThread(ret);
return grenade;
}

void hook_vid_restart(char *format, ...)
{
char s[COD2_MAX_STRINGLENGTH];
va_list va;

va_start(va, format);
vsnprintf(s, sizeof(s), format, va);
va_end(va);
int grenade = sig(player, a2, a3, weapon, a5);

Com_DPrintf("%s", s);
hook_fire_grenade->hook();

if (strncmp(&s[strlen(s) - 4], "vdr", 3) == 0)
if (codecallback_fire_grenade)
{
char *name = &s[24];
name[strlen(name) - 6] = '\0';

for (int i = 0; i < sv_maxclients->integer; i++)
{
if (CLIENTSTATE(i) == CS_ACTIVE)
{
if (strcmp(name, (char*)(PLAYERBASE(i) + 134216)) == 0)
{
stackPushInt(i);
short ret = Scr_ExecEntThread(G_ENTITY(i), codecallback_vid_restart, 1);
Scr_FreeThread(ret);
}
}
}
int weapondef = BG_WeaponDefs(weapon);
char *weaponname = *(char**)weapondef;
stackPushString(weaponname);
stackPushEntity(grenade);
short ret = Scr_ExecEntThread(player, codecallback_fire_grenade, 2);
Scr_FreeThread(ret);
}

return grenade;
}

void hook_ClientCommand(int clientNum)
Expand Down Expand Up @@ -472,6 +451,41 @@ char *custom_va(char *format, ...)
return s;
}

void hook_SV_VerifyIwds_f(int cl)
{
#if COD_VERSION == COD2_1_0
int pureauthentic_offset = 452016;
#elif COD_VERSION == COD2_1_2
int pureauthentic_offset = 452288;
#elif COD_VERSION == COD2_1_3
int pureauthentic_offset = 452288;
#endif

if (sv_pure->boolean)
*(int *)(cl + pureauthentic_offset) = 1;
}

void hook_SV_ResetPureClient_f(int cl)
{
#if COD_VERSION == COD2_1_0
int pureauthentic_offset = 452016;
#elif COD_VERSION == COD2_1_2
int pureauthentic_offset = 452288;
#elif COD_VERSION == COD2_1_3
int pureauthentic_offset = 452288;
#endif

*(int *)(cl + pureauthentic_offset) = 0;

if (codecallback_vid_restart)
{
int client_id = PLAYERBASE_ID(cl);
stackPushInt(client_id);
short ret = Scr_ExecEntThread(G_ENTITY(client_id), codecallback_vid_restart, 1);
Scr_FreeThread(ret);
}
}

void hook_scriptError(int a1, int a2, int a3, void *a4)
{
if (developer->integer == 2)
Expand Down Expand Up @@ -1058,8 +1072,6 @@ class cCallOfDuty2Pro
cracking_hook_call(0x0808E18F, (int)hook_gamestate_info);
#endif

cracking_hook_call(0x0808F412, (int)hook_vid_restart);

#if COMPILE_PLAYER == 1
cracking_hook_call(0x080DFF66, (int)hook_player_setmovespeed);
cracking_hook_call(0x080F50AB, (int)hook_player_g_speed);
Expand Down Expand Up @@ -1095,6 +1107,8 @@ class cCallOfDuty2Pro
cracking_hook_function(0x080E97F0, (int)hook_BG_IsWeaponValid);
cracking_hook_function(0x0808E544, (int)custom_SV_WriteDownloadToClient);
cracking_hook_function(0x080B59CE, (int)custom_va);
cracking_hook_function(0x0808EC66, (int)hook_SV_VerifyIwds_f);
cracking_hook_function(0x0808EEEC, (int)hook_SV_ResetPureClient_f);

#if COMPILE_RATELIMITER == 1
cracking_hook_call(0x08094081, (int)hook_SVC_Info);
Expand All @@ -1117,8 +1131,6 @@ class cCallOfDuty2Pro
cracking_hook_call(0x0808F533, (int)hook_gamestate_info);
#endif

cracking_hook_call(0x08090CA2, (int)hook_vid_restart);

#if COMPILE_PLAYER == 1
cracking_hook_call(0x080E2546, (int)hook_player_setmovespeed);
cracking_hook_call(0x080F76BF, (int)hook_player_g_speed);
Expand Down Expand Up @@ -1154,6 +1166,8 @@ class cCallOfDuty2Pro
cracking_hook_function(0x080EBDE0, (int)hook_BG_IsWeaponValid);
cracking_hook_function(0x0808FD2E, (int)custom_SV_WriteDownloadToClient);
cracking_hook_function(0x080B7E62, (int)custom_va);
cracking_hook_function(0x080904A0, (int)hook_SV_VerifyIwds_f);
cracking_hook_function(0x08090726, (int)hook_SV_ResetPureClient_f);

#if COMPILE_RATELIMITER == 1
cracking_hook_call(0x08095B8E, (int)hook_SVC_Info);
Expand All @@ -1176,8 +1190,6 @@ class cCallOfDuty2Pro
cracking_hook_call(0x0808F5C7, (int)hook_gamestate_info);
#endif

cracking_hook_call(0x08090D36, (int)hook_vid_restart);

#if COMPILE_PLAYER == 1
cracking_hook_call(0x080E268A, (int)hook_player_setmovespeed);
cracking_hook_call(0x080F7803, (int)hook_player_g_speed);
Expand Down Expand Up @@ -1213,6 +1225,8 @@ class cCallOfDuty2Pro
cracking_hook_function(0x080EBF24, (int)hook_BG_IsWeaponValid);
cracking_hook_function(0x0808FDC2, (int)custom_SV_WriteDownloadToClient);
cracking_hook_function(0x080B7FA6, (int)custom_va);
cracking_hook_function(0x08090534, (int)hook_SV_VerifyIwds_f);
cracking_hook_function(0x080907BA, (int)hook_SV_ResetPureClient_f);

#if COMPILE_RATELIMITER == 1
cracking_hook_call(0x08095C48, (int)hook_SVC_Info);
Expand All @@ -1233,6 +1247,13 @@ class cCallOfDuty2Pro
fs_library = Cvar_RegisterString("fs_library", "", CVAR_ARCHIVE);
sv_downloadMessage = Cvar_RegisterString("sv_downloadMessage", "", CVAR_ARCHIVE);

// Force download on clients
cl_allowDownload = Cvar_RegisterBool("cl_allowDownload", 1, CVAR_ARCHIVE | CVAR_SYSTEMINFO);

#if COD_VERSION == COD2_1_2 || COD_VERSION == COD2_1_3
cl_wwwDownload = Cvar_RegisterBool("cl_wwwDownload", 1, CVAR_ARCHIVE | CVAR_SYSTEMINFO);
#endif

setenv("LD_PRELOAD", "", 1); // dont inherit lib of parent
printf("> [PLUGIN LOADED]\n");
}
Expand Down

0 comments on commit 8829e43

Please sign in to comment.