PDA

View Full Version : [LIBCOD] NO-CRASH "setanim"



maxdamage99
10th October 2017, 16:26
If send an non-existent or not registered animation to the server - the server crash. This function excludes server crash.
For: https://killtube.org/showthread.php?2225-player-setAnim(string)
Maybe it will be useful to someone.

#gsc_player.cpp#


int BG_AnimationCheckForBad(char *anim)
{
int i,v6,v8;

#if COD_VERSION == COD2_1_0
int _VAR_ = 0x855A4E4;
#elif COD_VERSION == COD2_1_2
int _VAR_ = 0x856E3A4;
#elif COD_VERSION == COD2_1_3
int _VAR_ = 0x860B424;
#endif

int (*ConverteStr)(int a1);
#if COD_VERSION == COD2_1_0
*(int *)&ConverteStr = 0x80D45C4;
#elif COD_VERSION == COD2_1_2
*(int *)&ConverteStr = 0x80D6B9C;
#elif COD_VERSION == COD2_1_3
*(int *)&ConverteStr = 0x80D6CE0;
#endif

signed int (*SACh)(char *a1, char *a2);
#if COD_VERSION == COD2_1_0
*(int *)&SACh = 0x80B5620;
#elif COD_VERSION == COD2_1_2
*(int *)&SACh = 0x80B7AB4;
#elif COD_VERSION == COD2_1_3
*(int *)&SACh = 0x80B7BF8;
#endif

v6 = ConverteStr((int)anim);
v8 = 0;

for ( i = *(int *)_VAR_; ; i += 96 )
{

if ( v8 >= *(long *)((*(int *)_VAR_) + 49152) )
{
printf("BG_AnimationIndexForString: unknown player animation '%s'\n", anim);
return 0;
}

if ( v6 == *(long *)(i + 76) && !SACh(anim, (char *)i) )
return v8;

++v8;

}
return 0;
}

void gsc_player_set_anim(int id)
{
char* animation;

if ( ! stackGetParams("s", &animation))
{
stackError("gsc_player_set_anim() argument is undefined or has a wrong type");
stackPushUndefined();
return;
}

int animationIndex = 0;
extern int custom_animation[64];

animationIndex=strcmp(animation, "none")?BG_AnimationCheckForBad(animation):0;

custom_animation[id] = (animationIndex);
}