Got some news about the source of the segfault.
Kungs code didn't worked, cause if statement is not causing server to crash..
I've added few more prints:
PHP Code:
int hook_BG_IsWeaponValid(int a1, int a2) {
printf("hook_BG_IsWeaponValid -- Begin\n");
printf("hook_BG_IsWeaponValid -- 1 a1 : %i, a2 : %i \n", a1, a2);
int v3;
char v4;
signed int (*sub_80E9758)(int a1);
*(int *)&sub_80E9758 = 0x80E9758;
printf("hook_BG_IsWeaponValid -- 2 a1 : %i \n", a1);
int (*sub_80D9E84)(int a1, signed int a2);
*(int *)&sub_80D9E84 = 0x80D9E84;
printf("hook_BG_IsWeaponValid -- 3 a1 : %i, a2 : %i \n", a1, a2);
int (*sub_80E9270)(int a1);
*(int *)&sub_80E9270 = 0x80E9270;
printf("hook_BG_IsWeaponValid -- 4 a1 : %i \n", a1);
v4 = 1;
if ( !(unsigned int8_t)sub_80E9758(a2) )
v4 = 0;
printf("hook_BG_IsWeaponValid -- 5 a2 : %i \n", a2);
if ( !(unsigned int8_t)sub_80D9E84(a1 + 1348, a2) )
v4 = 0;
printf("hook_BG_IsWeaponValid -- 6 a2 : %i \n", a2);
v3 = sub_80E9270(a2);
printf("hook_BG_IsWeaponValid -- Last weapon used: %s\n", *(char**)(v3 + 0));
if ((long *)(v3 + 132) == NULL)
{
printf("this would later crash 1\n");
return 0;
}
if ((char *)(a1 + 1365) == NULL)
{
printf("this would later crash 2\n");
return 0;
}
if ((char *)(a1 + 1366) == NULL)
{
printf("this would later crash 3\n");
return 0;
}
if ((long *)(v3 + 876) == NULL)
{
printf("this would later crash 4\n");
return 0;
}
printf("hook_BG_IsWeaponValid -- After Kungs IF statements \n");
if ( !*(long *)(v3 + 132) && *(char *)(a1 + 1365) != a2 && *(char *)(a1 + 1366) != a2 && *(long *)(v3 + 876) != a2 )
v4 = 0;
printf("hook_BG_IsWeaponValid -- After IF statement \n");
// printf("Testcall\n");
return (unsigned int8_t)v4;
}
Log's of two last segfaults:
Code:
hook_BG_IsWeaponValid -- 6 a2 : 0
hook_BG_IsWeaponValid -- Last weapon used: none
hook_BG_IsWeaponValid -- After Kungs IF statements
hook_BG_IsWeaponValid -- After IF statement
hook_BG_IsWeaponValid -- Begin
hook_BG_IsWeaponValid -- 1 a1 : 141507876, a2 : 111
hook_BG_IsWeaponValid -- 2 a1 : 141507876
hook_BG_IsWeaponValid -- 3 a1 : 141507876, a2 : 111
hook_BG_IsWeaponValid -- 4 a1 : 141507876
hook_BG_IsWeaponValid -- 5 a2 : 111
hook_BG_IsWeaponValid -- 6 a2 : 111
Segmentation fault (core dumped)
Code:
hook_BG_IsWeaponValid -- After Kungs IF statements
hook_BG_IsWeaponValid -- After IF statement
hook_BG_IsWeaponValid -- Begin
hook_BG_IsWeaponValid -- 1 a1 : 141559896, a2 : 211
hook_BG_IsWeaponValid -- 2 a1 : 141559896
hook_BG_IsWeaponValid -- 3 a1 : 141559896, a2 : 211
hook_BG_IsWeaponValid -- 4 a1 : 141559896
hook_BG_IsWeaponValid -- 5 a2 : 211
hook_BG_IsWeaponValid -- 6 a2 : 211
Segmentation fault (core dumped)
As we can see it ends at v3 = sub_80E9270(a2); which is:
PHP Code:
int __cdecl sub_80E9270(int a1)
{
return dword_8576160[a1];
}
According to this thread https://killtube.org/showthread.php?2067-Server-Crash&p=11792&viewfull=1#post11792 I'll have to pay more attention to weapon functions. Let you know if I found anything.