Author Topic: Greater SCORES_MAX in fonline.h  (Read 2718 times)

Greater SCORES_MAX in fonline.h
« on: March 02, 2018, 11:09:30 am »
Hey,

I'm working on rev 412. In fonline.h I wanted to expand SCORES_MAX from 50 to 70. The compiler obviously attached me to

Code: [Select]
STATIC_ASSERT( offsetof( Critter, RefCounter )             == 9388 );
STATIC_ASSERT( offsetof( Client, LanguageMsg )             == 9548 );
STATIC_ASSERT( offsetof( Npc, Reserved )                   == 9408 );

I increased the values for comparison by 80 (bcs 20 additional indexes x 4 bytes for int or uint types of data), that is:
Code: [Select]
STATIC_ASSERT( offsetof( Critter, RefCounter )             == 9468 );
STATIC_ASSERT( offsetof( Client, LanguageMsg )             == 9628 );
STATIC_ASSERT( offsetof( Npc, Reserved )                   == 9488 );

DLLs were compiled without any problems, but the server itself, when generating the first location, crashed with message:
Utils.dll@Critter_ClearExtEvents : This nullptr

Of course, I looked there, and in fact, if the critter will be wrong, then something like this is supposed to happen.
Code: [Select]
EXPORT void Critter_ClearExtEvents(Critter* cr)
{
    if( cr->IsNotValid )
{
        LOG_ERROR("This nullptr.");
return;
}
for(int i=0;i<CRITTER_EVENT_EXT_MAX;i++)
*GetEventPtr(cr,i) = 0;
}

Only what does this have to do with STATIC_ASSERT itself? Did I count something wrong?

Dump from server crash:
Code: [Select]
Application
Name        FOnlineServer
Version     0520
OS          6.1.7601 (Service Pack 1)
Timestamp   2018.03.01 20:59:51

Exception
Code      EXCEPTION_ACCESS_VIOLATION
Address   0x5DBE173B
Flags     0x0
Info      Attempted to read to an 0x00000044

Thread 'Main' (4988, current)
parameters, getParam_MaxAp + 27, parameters.cpp (278)
FOnlineServer, unsigned __int64 __cdecl CallCDeclFunction32(unsigned int const *,unsigned int,unsigned int) + 35
FOnlineServer, bool __cdecl Script::RunPrepared(void) + 609
FOnlineServer, public: int __thiscall Critter::GetParam(unsigned int) + 91
FOnlineServer, public: static int __cdecl FOServer::SScriptFunc::DataVal_Index(class Critter * &,unsigned int) + 246
FOnlineServer, unsigned __int64 __cdecl CallCDeclFunctionObjFirst(void const *,unsigned long const *,int,void (__cdecl*)(void)) + 38
FOnlineServer, unsigned __int64 __cdecl CallSystemFunctionNative(class asCContext *,class asCScriptFunction *,void *,unsigned long *,void *,unsigned __int64 &) + 858
FOnlineServer, int __cdecl CallSystemFunction(int,class asCContext *,void *) + 294
FOnlineServer, public: void __thiscall asCContext::ExecuteNext(void) + 2325
FOnlineServer, public: virtual int __thiscall asCContext::Execute(void) + 521
FOnlineServer, bool __cdecl Script::RunPrepared(void) + 217
FOnlineServer, public: class Npc * __thiscall CritterManager::CreateNpc(unsigned short,unsigned int,int *,unsigned int,int *,char const *,class Map *,unsigned short,unsigned short,unsigned char,bool) + 800
FOnlineServer, public: bool __thiscall Map::Generate(void) + 700
FOnlineServer, public: class Location * __thiscall MapManager::CreateLocation(unsigned short,unsigned short,unsigned short,unsigned int) + 570
FOnlineServer, public: bool __thiscall MapManager::GenerateWorld(char const *,int) + 447
FOnlineServer, public: static bool __cdecl FOServer::NewWorld(void) + 27
FOnlineServer, public: static bool __cdecl FOServer::InitReal(void) + 1084
FOnlineServer, public: static bool __cdecl FOServer::Init(void) + 22
FOnlineServer, void __cdecl GameLoopThread(void *) + 10
FOnlineServer, void * __cdecl ThreadBeginExecution(void *) + 44
FOnlineServer, _ptw32_threadStart@4 + 97
FOnlineServer, __endthreadex + 58
FOnlineServer, __endthreadex + 196
kernel32, BaseThreadInitThunk + 18
ntdll, RtlInitializeExceptionChain + 99
ntdll, RtlInitializeExceptionChain + 54

Thread 'GUI' (2532)
ntdll, NtWaitForMultipleObjects + 21
kernel32, WaitForMultipleObjectsEx + 142
USER32, PeekMessageW + 688
USER32, MsgWaitForMultipleObjects + 31
FOnlineServer, int __cdecl fl_wait(double) + 665
FOnlineServer, public: static double __cdecl Fl::wait(double) + 23
FOnlineServer, public: static int __cdecl Fl::wait(void) + 33
FOnlineServer, _main + 1169
FOnlineServer, _WinMain@16 + 402
FOnlineServer, __tan_default + 552
kernel32, BaseThreadInitThunk + 18
ntdll, RtlInitializeExceptionChain + 99
ntdll, RtlInitializeExceptionChain + 54

Thread 'GUIUpdate' (4156)
ntdll, NtDelayExecution + 21
KERNELBASE, Sleep + 15
FOnlineServer, public: static void __cdecl Thread::Sleep(unsigned int) + 13
FOnlineServer, void __cdecl GUIUpdate(void *) + 17
FOnlineServer, void * __cdecl ThreadBeginExecution(void *) + 44
FOnlineServer, _ptw32_threadStart@4 + 97
FOnlineServer, __endthreadex + 58
FOnlineServer, __endthreadex + 196
kernel32, BaseThreadInitThunk + 18
ntdll, RtlInitializeExceptionChain + 99
ntdll, RtlInitializeExceptionChain + 54

Thread 'ScriptTimeout' (1056)
ntdll, NtDelayExecution + 21
KERNELBASE, Sleep + 15
FOnlineServer, public: static void __cdecl Thread::Sleep(unsigned int) + 13
FOnlineServer, void __cdecl RunTimeout(void *) + 963
FOnlineServer, void * __cdecl ThreadBeginExecution(void *) + 44
FOnlineServer, _ptw32_threadStart@4 + 97
FOnlineServer, __endthreadex + 58
FOnlineServer, __endthreadex + 196
kernel32, BaseThreadInitThunk + 18
ntdll, RtlInitializeExceptionChain + 99
ntdll, RtlInitializeExceptionChain + 54

Thread 'Unknown' (5768)
ntdll, NtWaitForMultipleObjects + 21
kernel32, BaseThreadInitThunk + 18
ntdll, RtlInitializeExceptionChain + 99
ntdll, RtlInitializeExceptionChain + 54

Loaded modules
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\FOnlineServer.exe (00400000)
C:\Windows\SysWOW64\ntdll.dll (77790000)
C:\Windows\syswow64\kernel32.dll (770C0000)
C:\Windows\syswow64\KERNELBASE.dll (75230000)
C:\Windows\syswow64\USER32.dll (75590000)
C:\Windows\syswow64\GDI32.dll (75100000)
C:\Windows\syswow64\LPK.dll (76EE0000)
C:\Windows\syswow64\USP10.dll (75190000)
C:\Windows\syswow64\msvcrt.dll (758D0000)
C:\Windows\syswow64\ADVAPI32.dll (754E0000)
C:\Windows\SysWOW64\sechost.dll (76920000)
C:\Windows\syswow64\RPCRT4.dll (76BB0000)
C:\Windows\syswow64\SspiCli.dll (75030000)
C:\Windows\syswow64\CRYPTBASE.dll (75020000)
C:\Windows\syswow64\WS2_32.dll (76F00000)
C:\Windows\syswow64\NSI.dll (76EF0000)
C:\Windows\system32\dbghelp.dll (73790000)
C:\Windows\syswow64\PSAPI.DLL (750E0000)
C:\Windows\system32\WINMM.dll (71C90000)
C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18837_none_ec86b8d6858ec0bc\COMCTL32.dll (71BE0000)
C:\Windows\syswow64\SHELL32.dll (759E0000)
C:\Windows\syswow64\SHLWAPI.dll (75980000)
C:\Windows\syswow64\ole32.dll (75380000)
C:\Windows\system32\IMM32.DLL (752E0000)
C:\Windows\syswow64\MSCTF.dll (76950000)
C:\Windows\syswow64\CLBCatQ.DLL (77300000)
C:\Windows\syswow64\OLEAUT32.dll (76CA0000)
C:\Windows\system32\msimtf.dll (5DC30000)
C:\Windows\system32\VERSION.dll (74F50000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\scripts\parameters.dll (5DBE0000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\scripts\backend.dll (5DB20000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\LIBMYSQL.dll (10000000)
C:\Windows\system32\WSOCK32.dll (71C80000)
C:\Windows\system32\NLAapi.dll (73A20000)
C:\Windows\system32\napinsp.dll (73A10000)
C:\Windows\system32\pnrpnsp.dll (739B0000)
C:\Windows\System32\mswsock.dll (71B40000)
C:\Windows\system32\DNSAPI.dll (71720000)
C:\Windows\System32\winrnr.dll (739F0000)
C:\Windows\system32\rasadhlp.dll (71AE0000)
C:\Windows\System32\wshtcpip.dll (71B30000)
C:\Windows\system32\IPHLPAPI.DLL (72540000)
C:\Windows\system32\WINNSI.DLL (72530000)
C:\Windows\System32\fwpuclnt.dll (71390000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\scripts\utils.dll (5DAD0000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\scripts\check_look.dll (5DA80000)
G:\fonlinedev\fonline_sdk\FAT_serverbeforeshutdown20170714_wosaves_fixed_FPS_2\Server412_2\scripts\online_stats.dll (5DA30000)

Thank you for help
rem

Offline Ghosthack

  • Rotator
  • Bytecruncher
Re: Greater SCORES_MAX in fonline.h
« Reply #1 on: March 03, 2018, 01:55:36 pm »
fonline.h is a dump reflecting the engine structures, so changing anything here will only change what gets compiled in the DLL, you haven't changed the structure in the server executable. That's why it crashes, the offsets are wrong when working with engine's version of Critter.

Not impossible to fix, but without source you need to grab a disassembler and then find the
Code: [Select]
const int Scores[ SCORES_MAX ]; declaration, and then hunt down every reference that uses 50 and change to 70.