From 8b60707edb44fcd7bb91f853950f04c343e27dff Mon Sep 17 00:00:00 2001 From: M-itch Date: Sat, 7 Mar 2015 15:42:50 +0100 Subject: [PATCH] added firetime/hitloc multiplier getter/setter --- gsc.cpp | 4 ++ gsc_utils.cpp | 164 +++++++++++++++++++++++++++++++++++--------------- gsc_utils.hpp | 4 ++ 3 files changed, 123 insertions(+), 49 deletions(-) diff --git a/gsc.cpp b/gsc.cpp index 2ee96f8..c86581c 100644 --- a/gsc.cpp +++ b/gsc.cpp @@ -264,6 +264,10 @@ Scr_Function scriptFunctions[] = { {"setweapondamage" , gsc_utils_setweapondamage , 0}, {"getweaponmeleedamage" , gsc_utils_getweaponmeleedamage , 0}, {"setweaponmeleedamage" , gsc_utils_setweaponmeleedamage , 0}, + {"getweaponfiretime" , gsc_utils_getweaponfiretime , 0}, + {"setweaponfiretime" , gsc_utils_setweaponfiretime , 0}, + {"getweaponhitlocmultiplier" , gsc_utils_getweaponhitlocmultiplier , 0}, + {"setweaponhitlocmultiplier" , gsc_utils_setweaponhitlocmultiplier , 0}, {"getloadedweapons" , gsc_utils_getloadedweapons , 0}, #endif diff --git a/gsc_utils.cpp b/gsc_utils.cpp index 40e9245..2cb97ee 100644 --- a/gsc_utils.cpp +++ b/gsc_utils.cpp @@ -816,15 +816,13 @@ void gsc_utils_setdefaultweapon() { return; } - if(strlen(weapon) > 31) - { + if(strlen(weapon) > 31) { printf("scriptengine> weapon name is too long: setdefaultweapon(weapon)\n"); stackPushUndefined(); return; } - if(strcmp(defaultweapon_mp, weapon) == 0) - { + if(strcmp(defaultweapon_mp, weapon) == 0) { stackPushInt(2); return; } @@ -881,11 +879,8 @@ int getWeapon(int index) bool isValidWeaponId(int id) { int weps = weaponCount(); - if(id >= weps || weps == 0) - { - stackPushInt(0); + if(id >= weps || id < 0 || weps == 0) return false; - } return true; } @@ -898,9 +893,9 @@ void gsc_utils_getweaponmaxammo() { return; } - if(!isValidWeaponId(id)) - { + if(!isValidWeaponId(id)) { printf("scriptengine> index out of bounds: getweaponmaxammo(id)\n"); + stackPushInt(0); return; } @@ -916,9 +911,9 @@ void gsc_utils_getweapondamage() { return; } - if(!isValidWeaponId(id)) - { + if(!isValidWeaponId(id)) { printf("scriptengine> index out of bounds: getweapondamage(id)\n"); + stackPushInt(0); return; } @@ -934,9 +929,9 @@ void gsc_utils_setweapondamage() { return; } - if(!isValidWeaponId(id)) - { + if(!isValidWeaponId(id)) { printf("scriptengine> index out of bounds: setweapondamage(id, dmg)\n"); + stackPushInt(0); return; } @@ -953,9 +948,9 @@ void gsc_utils_getweaponmeleedamage() { return; } - if(!isValidWeaponId(id)) - { + if(!isValidWeaponId(id)) { printf("scriptengine> index out of bounds: getweapondamagemelee(id)\n"); + stackPushInt(0); return; } @@ -971,9 +966,9 @@ void gsc_utils_setweaponmeleedamage() { return; } - if(!isValidWeaponId(id)) - { + if(!isValidWeaponId(id)) { printf("scriptengine> index out of bounds: setweapondamagemelee(id, dmg)\n"); + stackPushInt(0); return; } @@ -982,54 +977,125 @@ void gsc_utils_setweaponmeleedamage() { stackPushInt(1); } +void gsc_utils_getweaponfiretime() { + int id; + if ( ! stackGetParams("i", &id)) { + printf("scriptengine> wrongs args for: getweaponfiretime(id)\n"); + stackPushInt(0); + return; + } + + if(!isValidWeaponId(id)) { + printf("scriptengine> index out of bounds: getweaponfiretime(id)\n"); + stackPushInt(0); + return; + } + + int firetime = *(int*)(getWeapon(id) + 516); + stackPushInt(firetime); +} + +void gsc_utils_setweaponfiretime() { + int id, time; + if ( ! stackGetParams("ii", &id, &time)) { + printf("scriptengine> wrongs args for: setweaponfiretime(id, time)\n"); + stackPushInt(0); + return; + } + + if(!isValidWeaponId(id)) { + printf("scriptengine> index out of bounds: setweaponfiretime(id, time)\n"); + stackPushInt(0); + return; + } + + int* firetime = (int*)(getWeapon(id) + 516); // see 80EF58A + *firetime = time; + stackPushInt(1); +} + +char* hitlocs[] = {"none", "helmet", "head", "neck", "torso_upper", "torso_lower", "right_arm_upper", +"right_arm_lower", "right_hand", "left_arm_upper", "left_arm_lower", "left_hand", "right_leg_upper", +"right_leg_lower", "right_foot", "left_leg_upper", "left_leg_lower", "left_foot", "gun"}; + +int getHitLocOffset(char* hitloc) +{ + int offset = 0; // none + for (int i=0;i<19;i++) { // prevent out of bound + if(strcmp(hitlocs[i], hitloc) == 0) { + offset = i; + break; + } + } + return offset; +} + +void gsc_utils_getweaponhitlocmultiplier() { + int id; + char* hitloc; + if ( ! stackGetParams("is", &id, &hitloc)) { + printf("scriptengine> wrongs args for: getweaponhitlocmultiplier(id, hitloc)\n"); + stackPushInt(0); + return; + } + + if(!isValidWeaponId(id)) { + printf("scriptengine> index out of bounds: getweaponhitlocmultiplier(id, hitloc)\n"); + stackPushInt(0); + return; + } + + int offset = getHitLocOffset(hitloc); + float multiplier = *(float*)(getWeapon(id) + 4 * offset + 1456); + stackPushFloat(multiplier); +} + +void gsc_utils_setweaponhitlocmultiplier() { + int id; + float multiplier; + char* hitloc; + if ( ! stackGetParams("isf", &id, &hitloc, &multiplier)) { + printf("scriptengine> wrongs args for: getweaponhitlocmultiplier(id, hitloc, multiplier)\n"); + stackPushInt(0); + return; + } + + if(!isValidWeaponId(id)) { + printf("scriptengine> index out of bounds: getweaponhitlocmultiplier(id, hitloc, multiplier)\n"); + stackPushInt(0); + return; + } + + int offset = getHitLocOffset(hitloc); + float* multiPointer = (float*)(getWeapon(id) + 4 * offset + 1456); + *multiPointer = multiplier; + stackPushFloat(1); +} + void gsc_utils_getloadedweapons() { stackPushArray(); int weps = weaponCount(); if(weps == 0) return; - for(int i=0;i