Skip to content

Commit

Permalink
Added my version of filthy_freak_'s disablePickup as disableItemPickup.
Browse files Browse the repository at this point in the history
Usage: self disableItemPickup(1); (= pickup disabled)
       self disableItemPickup(0); (= pickup enabled)
  • Loading branch information
M-itch committed Jun 30, 2015
1 parent f89b31f commit 0dc04f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
5 changes: 2 additions & 3 deletions gsc.cpp
Expand Up @@ -340,7 +340,7 @@ void gsc_player_printf(int id) {

Scr_Method scriptMethods[] = {
{"printf", gsc_player_printf, 0}, // rather use sprintf() to re-use iprintlnbold() etc.?

#if COMPILE_PLAYER == 1
{"getStance" , gsc_player_stance_get , 0},
{"setVelocity" , gsc_player_velocity_set , 0},
Expand Down Expand Up @@ -374,6 +374,7 @@ Scr_Method scriptMethods[] = {
{"setg_speed" , gsc_player_setg_speed , 0},
{"setg_gravity" , gsc_player_setg_gravity , 0},
{"setweaponfiremeleedelay", gsc_player_setweaponfiremeleedelay, 0},
{"disableitempickup" , gsc_player_disable_item_pickup, 0},
#if COD_VERSION < COD4_1_7
{"setmovespeedscale" , gsc_player_setmovespeedscale , 0},
{"ismantling" , gsc_player_ismantling , 0},
Expand Down Expand Up @@ -402,8 +403,6 @@ Scr_MethodCall Scr_GetCustomMethod(const char **fname, int *fdev) {
return NULL;
}



/*
In CoD2 this address can be found in every get-param-function
In CoD1 its a bit harder, search for: "cannot cast %s to int" and go the function upwards:
Expand Down
36 changes: 34 additions & 2 deletions gsc_player.cpp
Expand Up @@ -95,8 +95,8 @@ int clientaddress_to_num(int address) {
return (address - playerStates) / sizeOfPlayer;
}

int gentityaddress_to_num(int client) {
return (client - gentities) / gentities_size;
int gentityaddress_to_num(int address) {
return (address - gentities) / gentities_size;
}

void gsc_player_velocity_set(int id) {
Expand Down Expand Up @@ -707,6 +707,38 @@ void gsc_player_setweaponfiremeleedelay(int id) {
*(int *)(state + 216) = 11;
}

int disable_player_item_pickup[64] = {0};

int hook_pickup_item(int weapon, int player, int message) {
int clientNum = gentityaddress_to_num(player);
if(disable_player_item_pickup[clientNum] != 1) {
typedef int (*Touch_Item_Auto_t)(int a1, int a2, int a3);
#if COD_VERSION == COD2_1_0
Touch_Item_Auto_t Touch_Item_Auto = (Touch_Item_Auto_t)0x081037F0;
#elif COD_VERSION == COD2_1_2
Touch_Item_Auto_t Touch_Item_Auto = (Touch_Item_Auto_t)0x08105B24;
#elif COD_VERSION == COD2_1_3
Touch_Item_Auto_t Touch_Item_Auto = (Touch_Item_Auto_t)0x08105C80;
#else
Touch_Item_Auto_t Touch_Item_Auto = (Touch_Item_Auto_t)NULL;
#endif
return Touch_Item_Auto(weapon, player, message);
}

return 1;
}

void gsc_player_disable_item_pickup(int id) {
int disabled;
if (!stackGetParams("i", &disabled)) {
printf("scriptengine> ERROR: gsc_player_disable_item_pickup(): param \"disabled\"[1] has to be an integer!\n");
stackPushUndefined();
return;
}

disable_player_item_pickup[id] = disabled;
}

// entity functions (could be in own file, but atm not many pure entity functions)

void gsc_entity_setalive(int id) { // as in isAlive?
Expand Down
3 changes: 3 additions & 0 deletions gsc_player.hpp
Expand Up @@ -14,6 +14,7 @@ extern "C" {
#include "gsc.hpp"

int clientaddress_to_num(int address);
int gentityaddress_to_num(int address);

void gsc_player_velocity_set(int id);
void gsc_player_velocity_add(int id);
Expand Down Expand Up @@ -58,6 +59,8 @@ void gsc_player_setmovespeedscale(int id);
void gsc_player_setg_speed(int id);
void gsc_player_setg_gravity(int id);
void gsc_player_setweaponfiremeleedelay(int id);
int hook_pickup_item(int weapon, int player, int message);
void gsc_player_disable_item_pickup(int id);

// entity functions
void gsc_entity_setalive(int id);
Expand Down
18 changes: 13 additions & 5 deletions libcod.cpp
Expand Up @@ -2146,11 +2146,6 @@ int cmd_map()
return ret;
}

int hook_dummytrue(const char *src)
{
return 1;
}

#define TOSTRING2(str) #str
#define TOSTRING1(str) TOSTRING2(str) // else there is written "__LINE__"
class cCallOfDuty2Pro
Expand Down Expand Up @@ -2252,6 +2247,19 @@ class cCallOfDuty2Pro
printf("> [INFO] value of closer=%.8x\n", *addressToCloserPointer);
*addressToCloserPointer = (int) cdecl_injected_closer/*_stack_debug*/;
//printf("after\n");

#if COD_VERSION == COD2_1_0
int *addressToPickUpItemPointer = (int *)0x08167B34;
#elif COD_VERSION == COD2_1_2
int *addressToPickUpItemPointer = (int *)0x08186F94;
#elif COD_VERSION == COD2_1_3
int *addressToPickUpItemPointer = (int *)0x08187FB4;
#else
#warning int *addressToPickUpItemPointer = NULL;
int *addressToPickUpItemPointer = NULL;
#endif

*addressToPickUpItemPointer = (int)hook_pickup_item;

/*
printf("> [INFO] recvfrom=%08x\n", dlsym(NULL, "recvfrom"));
Expand Down

0 comments on commit 0dc04f7

Please sign in to comment.