PDA

View Full Version : CodeCallback_FireGrenade



IzNoGoD
28th February 2016, 22:09
Heres a working version of CodeCallback_FireGrenade for cod2 1.3:

Possible uses: nade explosion timer and preventing people from changing team after throwing a grenade (prevent those filthy teamkills)

libcod.cpp:
after


int codecallback_playercommand = 0;
int codecallback_userinfochanged = 0;

add


int codecallback_fire_grenade = 0;

after


#else
codecallback_playercommand = codscript_load_function((char *)"maps/mp/gametypes/_callbacksetup", (char *)"CodeCallback_PlayerCommand", 0);
codecallback_userinfochanged = codscript_load_function((char *)"maps/mp/gametypes/_callbacksetup", (char *)"CodeCallback_UserInfoChanged", 0);
add


codecallback_fire_grenade = codscript_load_function((char *)"maps/mp/gametypes/_callbacksetup", (char *)"CodeCallback_FireGrenade", 0);
Below that function, add:


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 (*sig2)(int weapon);
*(int *)&sig2 = 0x80EB9A4; //cod2_1_3
int weaponname = sig2(weapon);
char *wname2 = *(char**)weaponname;
stackPushString(wname2);
stackPushEntity(grenade);
short ret = codscript_call_callback_entity(player, codecallback_fire_grenade, 2);
codscript_callback_finish(ret);
return grenade;
}


and in an appropriate spot (somewhere in class cCallOfDuty2Pro) add


hook_fire_grenade = new cHook(0x810E68E, (int) fire_grenade);
hook_fire_grenade->hook();

Values for other cod versions:
cod2_1_0:
hook_fire_grenade: 0x810C1F6
sig2:
0x80E9270

cod2_1_2:
hook_fire_grenade:
0x810E532
sig2:
0x80EB860


Inside your _callbacksetup add this:


CodeCallback_FireGrenade(grenade, name)
{
}

This function will be called when a player throws a nade, on the player that is throwing the nade. The grenade-var will be the entity of the grenade, and the name will be a string, like "frag_grenade_american_mp"


Have fun :)

IzNoGoD
28th February 2016, 22:19
Sidenote on a point that i havent explored yet myself: if the weaponname is exactly 32 chars long, the \0 might be missing, so it could be beneficial to strncpy it with a \0 at the end.