diff --git a/bin-vc14/FLHook.dll b/bin-vc14/FLHook.dll index 05aacd5ec..503e8e49a 100644 Binary files a/bin-vc14/FLHook.dll and b/bin-vc14/FLHook.dll differ diff --git a/bin-vc14/FLHook.pdb b/bin-vc14/FLHook.pdb index ed0021281..85a589410 100644 Binary files a/bin-vc14/FLHook.pdb and b/bin-vc14/FLHook.pdb differ diff --git a/bin-vc14/flhook_plugins/ahookext.dll b/bin-vc14/flhook_plugins/ahookext.dll index 79b12b7ce..934a86cb3 100644 Binary files a/bin-vc14/flhook_plugins/ahookext.dll and b/bin-vc14/flhook_plugins/ahookext.dll differ diff --git a/bin-vc14/flhook_plugins/ahookext.pdb b/bin-vc14/flhook_plugins/ahookext.pdb index 7f4d41cdd..6b992c03a 100644 Binary files a/bin-vc14/flhook_plugins/ahookext.pdb and b/bin-vc14/flhook_plugins/ahookext.pdb differ diff --git a/bin-vc14/flhook_plugins/base.dll b/bin-vc14/flhook_plugins/base.dll index aa52ae137..6b2ba11ed 100644 Binary files a/bin-vc14/flhook_plugins/base.dll and b/bin-vc14/flhook_plugins/base.dll differ diff --git a/bin-vc14/flhook_plugins/base.pdb b/bin-vc14/flhook_plugins/base.pdb index 7da222384..116fae844 100644 Binary files a/bin-vc14/flhook_plugins/base.pdb and b/bin-vc14/flhook_plugins/base.pdb differ diff --git a/bin-vc14/flhook_plugins/cloak.dll b/bin-vc14/flhook_plugins/cloak.dll index 3c07ced0f..40c6fa8ee 100644 Binary files a/bin-vc14/flhook_plugins/cloak.dll and b/bin-vc14/flhook_plugins/cloak.dll differ diff --git a/bin-vc14/flhook_plugins/cloak.pdb b/bin-vc14/flhook_plugins/cloak.pdb index ace4fc94c..25d14c868 100644 Binary files a/bin-vc14/flhook_plugins/cloak.pdb and b/bin-vc14/flhook_plugins/cloak.pdb differ diff --git a/bin-vc14/flhook_plugins/condata.dll b/bin-vc14/flhook_plugins/condata.dll index 2d07aadea..abe091191 100644 Binary files a/bin-vc14/flhook_plugins/condata.dll and b/bin-vc14/flhook_plugins/condata.dll differ diff --git a/bin-vc14/flhook_plugins/condata.pdb b/bin-vc14/flhook_plugins/condata.pdb index 6909936c7..0f7d4886c 100644 Binary files a/bin-vc14/flhook_plugins/condata.pdb and b/bin-vc14/flhook_plugins/condata.pdb differ diff --git a/bin-vc14/flhook_plugins/conn.dll b/bin-vc14/flhook_plugins/conn.dll index 6268bb00a..f23a2e679 100644 Binary files a/bin-vc14/flhook_plugins/conn.dll and b/bin-vc14/flhook_plugins/conn.dll differ diff --git a/bin-vc14/flhook_plugins/conn.pdb b/bin-vc14/flhook_plugins/conn.pdb index fc933543b..83afc7c9d 100644 Binary files a/bin-vc14/flhook_plugins/conn.pdb and b/bin-vc14/flhook_plugins/conn.pdb differ diff --git a/bin-vc14/flhook_plugins/event.dll b/bin-vc14/flhook_plugins/event.dll index d1907ae25..afe312625 100644 Binary files a/bin-vc14/flhook_plugins/event.dll and b/bin-vc14/flhook_plugins/event.dll differ diff --git a/bin-vc14/flhook_plugins/event.pdb b/bin-vc14/flhook_plugins/event.pdb index 562b25f0d..360b3a79b 100644 Binary files a/bin-vc14/flhook_plugins/event.pdb and b/bin-vc14/flhook_plugins/event.pdb differ diff --git a/bin-vc14/flhook_plugins/minecontrol.dll b/bin-vc14/flhook_plugins/minecontrol.dll index da32745a8..6bbae42c0 100644 Binary files a/bin-vc14/flhook_plugins/minecontrol.dll and b/bin-vc14/flhook_plugins/minecontrol.dll differ diff --git a/bin-vc14/flhook_plugins/minecontrol.pdb b/bin-vc14/flhook_plugins/minecontrol.pdb index 992aee7cf..3703a6b01 100644 Binary files a/bin-vc14/flhook_plugins/minecontrol.pdb and b/bin-vc14/flhook_plugins/minecontrol.pdb differ diff --git a/bin-vc14/flhook_plugins/mobiledock.dll b/bin-vc14/flhook_plugins/mobiledock.dll index 3061c1091..7cd3f1d15 100644 Binary files a/bin-vc14/flhook_plugins/mobiledock.dll and b/bin-vc14/flhook_plugins/mobiledock.dll differ diff --git a/bin-vc14/flhook_plugins/mobiledock.pdb b/bin-vc14/flhook_plugins/mobiledock.pdb index 87a4b59ae..a777ef0cd 100644 Binary files a/bin-vc14/flhook_plugins/mobiledock.pdb and b/bin-vc14/flhook_plugins/mobiledock.pdb differ diff --git a/bin-vc14/flhook_plugins/playercntl.dll b/bin-vc14/flhook_plugins/playercntl.dll index 14882bcd7..7b61807db 100644 Binary files a/bin-vc14/flhook_plugins/playercntl.dll and b/bin-vc14/flhook_plugins/playercntl.dll differ diff --git a/bin-vc14/flhook_plugins/playercntl.pdb b/bin-vc14/flhook_plugins/playercntl.pdb index c6e33aa16..3161d69e3 100644 Binary files a/bin-vc14/flhook_plugins/playercntl.pdb and b/bin-vc14/flhook_plugins/playercntl.pdb differ diff --git a/bin-vc14/flhook_plugins/tempban.dll b/bin-vc14/flhook_plugins/tempban.dll index d69bfffb2..da1efe1d7 100644 Binary files a/bin-vc14/flhook_plugins/tempban.dll and b/bin-vc14/flhook_plugins/tempban.dll differ diff --git a/bin-vc14/flhook_plugins/tempban.pdb b/bin-vc14/flhook_plugins/tempban.pdb index b9f2f5954..975a95679 100644 Binary files a/bin-vc14/flhook_plugins/tempban.pdb and b/bin-vc14/flhook_plugins/tempban.pdb differ diff --git a/plugins/flhookplugin_sdk/libs/FLHook-vc14.lib b/plugins/flhookplugin_sdk/libs/FLHook-vc14.lib index 4e91cca52..3fc9a0629 100644 Binary files a/plugins/flhookplugin_sdk/libs/FLHook-vc14.lib and b/plugins/flhookplugin_sdk/libs/FLHook-vc14.lib differ diff --git a/plugins/playercntl_plugin/src/PluginUtilities.h b/plugins/playercntl_plugin/src/PluginUtilities.h index 216bb62fb..f2ea669f2 100644 --- a/plugins/playercntl_plugin/src/PluginUtilities.h +++ b/plugins/playercntl_plugin/src/PluginUtilities.h @@ -77,7 +77,7 @@ void HkLoadStringDLLs(); void HkUnloadStringDLLs(); wstring HkGetWStringFromIDS(uint iIDS); -void AddExceptionInfoLog(LPEXCEPTION_POINTERS pep); +void AddExceptionInfoLog(struct SEHException* pep); #define LOG_EXCEPTION { AddLog("ERROR Exception in %s", __FUNCTION__); AddExceptionInfoLog(0); } CAccount* HkGetAccountByClientID(uint iClientID); diff --git a/project-vc14/FLHook.vcxproj b/project-vc14/FLHook.vcxproj index 73bd7a77d..aadc4b1c4 100644 --- a/project-vc14/FLHook.vcxproj +++ b/project-vc14/FLHook.vcxproj @@ -116,7 +116,7 @@ copy /Y $(OutDir)$(TargetName).lib ..\plugins\flhookplugin_sdk\libs\$(TargetNa ProgramDatabase - Ws2_32.lib;psapi.lib;%(AdditionalDependencies) + Ws2_32.lib;psapi.lib;dbghelp.lib;%(AdditionalDependencies) true Windows true @@ -127,7 +127,8 @@ copy /Y $(OutDir)$(TargetName).lib ..\plugins\flhookplugin_sdk\libs\$(TargetNa MachineX86 - + copy /Y $(OutDir)$(TargetName).dll C:\FWDev\Freeworlds-public\exe\ +copy /Y $(OutDir)$(TargetName).pdb C:\FWDev\Freeworlds-public\exe\ diff --git a/source/FLHook.cpp b/source/FLHook.cpp index 41193a0d1..18d2d31c4 100644 --- a/source/FLHook.cpp +++ b/source/FLHook.cpp @@ -113,7 +113,8 @@ BYTE oldSetUnhandledExceptionFilter[5]; LONG WINAPI FLHookTopLevelFilter(struct _EXCEPTION_POINTERS *pExceptionInfo) { AddLog("!!TOP LEVEL EXCEPTION!!"); - WriteMiniDump(pExceptionInfo); + SEHException ex(0, pExceptionInfo); + WriteMiniDump(&ex); return EXCEPTION_EXECUTE_HANDLER; // EXCEPTION_CONTINUE_SEARCH; } @@ -643,7 +644,7 @@ struct timeval tv = {0, 0}; void ProcessPendingCommands() { - try { + TRY_HOOK { // check for new console commands EnterCriticalSection(&cs); while(lstConsoleCmds.size()) @@ -852,8 +853,5 @@ void ProcessPendingCommands() } lstDelete.clear(); - } catch(...) { - LOG_EXCEPTION - throw "exception"; - } + } CATCH_HOOK({}) } \ No newline at end of file diff --git a/source/HkCbChat.cpp b/source/HkCbChat.cpp index 72ce93d02..0706d1b78 100644 --- a/source/HkCbChat.cpp +++ b/source/HkCbChat.cpp @@ -12,7 +12,7 @@ void __stdcall HkCb_SendChat(uint iClientID, uint iTo, uint iSize, void *pRDL) CALL_PLUGINS_V(PLUGIN_HkCb_SendChat,__stdcall,(uint,uint,uint,void*),(iClientID,iTo,iSize,pRDL)); - try { + TRY_HOOK { if(HkIServerImpl::g_bInSubmitChat && (iTo != 0x10004)) { wchar_t wszBuf[1024] = L""; // extract text from rdlReader @@ -120,5 +120,5 @@ void __stdcall HkCb_SendChat(uint iClientID, uint iTo, uint iSize, void *pRDL) popad } } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } diff --git a/source/HkCbDamage.cpp b/source/HkCbDamage.cpp index d7f25723c..24f7bfca3 100644 --- a/source/HkCbDamage.cpp +++ b/source/HkCbDamage.cpp @@ -20,7 +20,7 @@ int __stdcall HkCB_MissileTorpHit(char *ECX, char *p1, DamageList *dmg) CALL_PLUGINS(PLUGIN_HkCB_MissileTorpHit,int,__stdcall,(char*,char*,DamageList*),(ECX,p1,dmg)); - try { + TRY_HOOK { // get client id char *szP; memcpy(&szP, ECX + 0x10, 4); @@ -48,7 +48,7 @@ int __stdcall HkCB_MissileTorpHit(char *ECX, char *p1, DamageList *dmg) dmg->set_cause((enum DamageCause)0xC0); // change to sth else, so client won't recognize it as a disruptor } } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) return 0; } @@ -119,7 +119,7 @@ void __stdcall HkCb_AddDmgEntry(DamageList *dmgList, unsigned short p1, float p2 else dmgList->add_damage_entry(p1, p2, p3); - try { + TRY_HOOK { LastDmgList = *dmgList; // save // float fHealth,fMaxHealth;32 256 @@ -141,7 +141,7 @@ void __stdcall HkCb_AddDmgEntry(DamageList *dmgList, unsigned short p1, float p2 } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkCb_AddDmgEntry_AFTER,__stdcall,(DamageList *,unsigned short,float, DamageEntry::SubObjFate),(dmgList,p1,p2,p3)); @@ -175,7 +175,7 @@ void __stdcall HkCb_GeneralDmg(char *szECX) CALL_PLUGINS_V(PLUGIN_HkCb_GeneralDmg,__stdcall,(char*),(szECX)); - try { + TRY_HOOK { char *szP; memcpy(&szP, szECX + 0x10, 4); uint iClientID; @@ -185,8 +185,7 @@ void __stdcall HkCb_GeneralDmg(char *szECX) iDmgTo = iClientID; iDmgToSpaceID = iSpaceID; - } - catch (...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } __declspec(naked) void _HkCb_GeneralDmg() diff --git a/source/HkCbDeath.cpp b/source/HkCbDeath.cpp index 92853a49a..304325dac 100644 --- a/source/HkCbDeath.cpp +++ b/source/HkCbDeath.cpp @@ -116,7 +116,7 @@ void __stdcall ShipDestroyed(DamageList *_dmg, DWORD *ecx, uint iKill) CALL_PLUGINS_V(PLUGIN_ShipDestroyed,__stdcall,(DamageList *_dmg, DWORD *ecx, uint iKill),(_dmg,ecx,iKill)); - try { + TRY_HOOK { if(iKill==1) { CShip *cship = (CShip*)ecx[4]; @@ -252,7 +252,7 @@ void __stdcall ShipDestroyed(DamageList *_dmg, DWORD *ecx, uint iKill) ClientInfo[iClientID].iShipOld = ClientInfo[iClientID].iShip; ClientInfo[iClientID].iShip = 0; } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } FARPROC fpOldShipDestroyed; diff --git a/source/HkCbDisconnect.cpp b/source/HkCbDisconnect.cpp index 2ce6bfb59..6377c5e36 100644 --- a/source/HkCbDisconnect.cpp +++ b/source/HkCbDisconnect.cpp @@ -4,7 +4,7 @@ int __stdcall DisconnectPacketSent(uint iClientID) { - try { + TRY_HOOK { uint iShip = 0; pub::Player::GetShip(iClientID, iShip); if(set_iDisconnectDelay && iShip) @@ -12,7 +12,7 @@ int __stdcall DisconnectPacketSent(uint iClientID) ClientInfo[iClientID].tmF1TimeDisconnect = timeInMS() + set_iDisconnectDelay; return 0; // don't pass on } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) return 1; // pass on } diff --git a/source/HkCbIEngine.cpp b/source/HkCbIEngine.cpp index 6538d3588..5151e65ef 100644 --- a/source/HkCbIEngine.cpp +++ b/source/HkCbIEngine.cpp @@ -132,9 +132,9 @@ int __cdecl Dock_Call(unsigned int const &uShipID,unsigned int const &uSpaceID,i CALL_PLUGINS(PLUGIN_HkCb_Dock_Call,int,,(unsigned int const &,unsigned int const &,int,DOCK_HOST_RESPONSE),(uShipID,uSpaceID,p3,p4)); - try { + TRY_HOOK { return pub::SpaceObj::Dock(uShipID,uSpaceID,p3,p4); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS(PLUGIN_HkCb_Dock_Call_AFTER, int, , (unsigned int const &, unsigned int const &, int, DOCK_HOST_RESPONSE), (uShipID, uSpaceID, p3, p4)); diff --git a/source/HkCbIServerImpl.cpp b/source/HkCbIServerImpl.cpp index 1b58bc9a5..d833a2017 100644 --- a/source/HkCbIServerImpl.cpp +++ b/source/HkCbIServerImpl.cpp @@ -17,9 +17,9 @@ { \ static CTimer timer(__FUNCTION__,set_iTimerThreshold); \ timer.start(); \ - try { \ + TRY_HOOK { \ args; \ - } catch(...) { AddLog("ERROR: Exception in " __FUNCTION__ " on server call"); LOG_EXCEPTION; } \ + } CATCH_HOOK( { AddLog("ERROR: Exception in " __FUNCTION__ " on server call"); } ) \ timer.stop(); \ } @@ -108,7 +108,7 @@ void __stdcall SubmitChat(struct CHAT_ID cId, unsigned long lP1, void const *rdl CALL_PLUGINS_V(PLUGIN_HkIServerImpl_SubmitChat,__stdcall,(struct CHAT_ID cId, unsigned long lP1, void const *rdlReader, struct CHAT_ID cIdTo, int iP2),(cId,lP1,rdlReader,cIdTo,iP2)); - try { + TRY_HOOK { // Group join/leave commands if(cIdTo.iID == 0x10004) @@ -258,7 +258,7 @@ void __stdcall SubmitChat(struct CHAT_ID cId, unsigned long lP1, void const *rdl if((ToLower(wscBuf)).find(ToLower(*i)) == 0) return; } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) // send g_bInSubmitChat = true; @@ -280,7 +280,7 @@ void __stdcall PlayerLaunch(unsigned int iShip, unsigned int iClientID) CHECK_FOR_DISCONNECT - try { + TRY_HOOK { ClientInfo[iClientID].iShip = iShip; ClientInfo[iClientID].iKillsInARow = 0; ClientInfo[iClientID].bCruiseActivated = false; @@ -299,13 +299,13 @@ void __stdcall PlayerLaunch(unsigned int iShip, unsigned int iClientID) break; } } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_PlayerLaunch,__stdcall,(unsigned int iShip, unsigned int iClientID),(iShip,iClientID)); EXECUTE_SERVER_CALL(Server.PlayerLaunch(iShip, iClientID)); - try { + TRY_HOOK { if(!ClientInfo[iClientID].iLastExitedBaseID) { ClientInfo[iClientID].iLastExitedBaseID = 1; @@ -316,7 +316,7 @@ void __stdcall PlayerLaunch(unsigned int iShip, unsigned int iClientID) iClientID, HkGetPlayerSystem(iClientID).c_str()); } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_PlayerLaunch_AFTER,__stdcall,(unsigned int iShip, unsigned int iClientID),(iShip,iClientID)); } @@ -354,10 +354,9 @@ void __stdcall SPMunitionCollision(struct SSPMunitionCollisionInfo const & ci, u CHECK_FOR_DISCONNECT - try { + TRY_HOOK { iClientIDTarget = HkGetClientIDByShip(ci.dwTargetShip); - - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) iDmgTo = iClientIDTarget; @@ -438,7 +437,7 @@ void __stdcall LaunchComplete(unsigned int iBaseID, unsigned int iShip) ISERVER_LOGARG_UI(iBaseID); ISERVER_LOGARG_UI(iShip); - try { + TRY_HOOK { uint iClientID = HkGetClientIDByShip(iShip); if(iClientID) { ClientInfo[iClientID].tmSpawnTime = timeInMS(); // save for anti-dockkill @@ -455,7 +454,7 @@ void __stdcall LaunchComplete(unsigned int iBaseID, unsigned int iShip) iClientID, HkGetBaseNickByID(ClientInfo[iClientID].iLastExitedBaseID).c_str(), HkGetPlayerSystem(iClientID).c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_LaunchComplete,__stdcall,(unsigned int iBaseID, unsigned int iShip),(iBaseID, iShip)); @@ -491,7 +490,7 @@ void __stdcall CharacterSelect(struct CHARACTER_ID const & cId, unsigned int iCl return; } - try { + TRY_HOOK { wstring wscCharname = (wchar_t*)Players.GetActiveCharacterName(iClientID); if(wscCharBefore.compare(wscCharname) != 0) { @@ -531,7 +530,7 @@ void __stdcall CharacterSelect(struct CHARACTER_ID const & cId, unsigned int iCl iClientID, pi.wscIP.c_str()); } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_CharacterSelect_AFTER,__stdcall,(struct CHARACTER_ID const & cId, unsigned int iClientID),(cId,iClientID)); } @@ -550,15 +549,15 @@ void __stdcall BaseEnter(unsigned int iBaseID, unsigned int iClientID) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_BaseEnter,__stdcall,(unsigned int iBaseID, unsigned int iClientID),(iBaseID,iClientID)); - try { + TRY_HOOK { // autobuy if(set_bAutoBuy) HkPlayerAutoBuy(iClientID, iBaseID); - } catch(...) { AddLog("Exception in " __FUNCTION__ " on autobuy"); LOG_EXCEPTION } + } CATCH_HOOK( { AddLog("Exception in " __FUNCTION__ " on autobuy"); } ) EXECUTE_SERVER_CALL(Server.BaseEnter(iBaseID, iClientID)); - try { + TRY_HOOK { // adjust cash, this is necessary when cash was added while use was in charmenu/had other char selected wstring wscCharname = ToLower((wchar_t*)Players.GetActiveCharacterName(iClientID)); foreach(ClientInfo[iClientID].lstMoneyFix, MONEY_FIX, i) @@ -580,7 +579,7 @@ void __stdcall BaseEnter(unsigned int iBaseID, unsigned int iClientID) iClientID, HkGetBaseNickByID(iBaseID).c_str(), HkGetPlayerSystem(iClientID).c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_BaseEnter_AFTER,__stdcall,(unsigned int iBaseID, unsigned int iClientID),(iBaseID,iClientID)); } @@ -597,16 +596,16 @@ void __stdcall BaseExit(unsigned int iBaseID, unsigned int iClientID) CHECK_FOR_DISCONNECT - try { + TRY_HOOK { ClientInfo[iClientID].iBaseEnterTime = 0; ClientInfo[iClientID].iLastExitedBaseID = iBaseID; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_BaseExit,__stdcall,(unsigned int iBaseID, unsigned int iClientID),(iBaseID,iClientID)); EXECUTE_SERVER_CALL(Server.BaseExit(iBaseID, iClientID)); - try { + TRY_HOOK { const wchar_t *wszCharname = (wchar_t*)Players.GetActiveCharacterName(iClientID); // event @@ -615,7 +614,7 @@ void __stdcall BaseExit(unsigned int iBaseID, unsigned int iClientID) iClientID, HkGetBaseNickByID(iBaseID).c_str(), HkGetPlayerSystem(iClientID).c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_BaseExit_AFTER,__stdcall,(unsigned int iBaseID, unsigned int iClientID),(iBaseID,iClientID)); } @@ -628,7 +627,7 @@ void __stdcall OnConnect(unsigned int iClientID) ISERVER_LOG(); ISERVER_LOGARG_UI(iClientID); - try { + TRY_HOOK { // If ID is too high due to disconnect buffer time then manually drop the connection. if(iClientID > MAX_CLIENT_ID) { @@ -653,21 +652,21 @@ void __stdcall OnConnect(unsigned int iClientID) ClientInfo[iClientID].iConnects++; ClearClientInfo(iClientID); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_OnConnect,__stdcall,(unsigned int iClientID),(iClientID)); EXECUTE_SERVER_CALL(Server.OnConnect(iClientID)); - try { + TRY_HOOK { // event wstring wscIP; HkGetPlayerIP(iClientID, wscIP); ProcessEvent(L"connect id=%d ip=%s", iClientID, wscIP.c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_OnConnect_AFTER,__stdcall,(unsigned int iClientID),(iClientID)); } @@ -683,7 +682,7 @@ void __stdcall DisConnect(unsigned int iClientID, enum EFLConnection p2) ISERVER_LOGARG_UI(p2); wstring wscCharname; - try + TRY_HOOK { if(!ClientInfo[iClientID].bDisconnected) { @@ -702,11 +701,7 @@ void __stdcall DisConnect(unsigned int iClientID, enum EFLConnection p2) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_DisConnect_AFTER,__stdcall,(unsigned int iClientID, enum EFLConnection p2),(iClientID,p2)); } } - catch (...) - { - AddLog("ERROR: Exception in " __FUNCTION__ "@loc2 charname=%s iClientID=%u", wstos(wscCharname).c_str(), iClientID); - LOG_EXCEPTION; - } + CATCH_HOOK({ AddLog("ERROR: Exception in " __FUNCTION__ "@loc2 charname=%s iClientID=%u", wstos(wscCharname).c_str(), iClientID); }) } /************************************************************************************************************** @@ -725,7 +720,7 @@ void __stdcall TerminateTrade(unsigned int iClientID, int iAccepted) EXECUTE_SERVER_CALL(Server.TerminateTrade(iClientID, iAccepted)); - try { + TRY_HOOK { if(iAccepted) { // save both chars to prevent cheating in case of server crash HkSaveChar(ARG_CLIENTID(iClientID)); @@ -737,7 +732,7 @@ void __stdcall TerminateTrade(unsigned int iClientID, int iAccepted) ClientInfo[ClientInfo[iClientID].iTradePartner].iTradePartner = 0; ClientInfo[iClientID].iTradePartner = 0; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_TerminateTrade_AFTER,__stdcall,(unsigned int iClientID, int iAccepted),(iClientID,iAccepted)); } @@ -752,11 +747,11 @@ void __stdcall InitiateTrade(unsigned int iClientID1, unsigned int iClientID2) ISERVER_LOGARG_UI(iClientID1); ISERVER_LOGARG_UI(iClientID2); - try { + TRY_HOOK { // save traders client-ids ClientInfo[iClientID1].iTradePartner = iClientID2; ClientInfo[iClientID2].iTradePartner = iClientID1; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_InitiateTrade,__stdcall,(unsigned int iClientID1, unsigned int iClientID2),(iClientID1,iClientID2)); @@ -776,7 +771,7 @@ void __stdcall ActivateEquip(unsigned int iClientID, struct XActivateEquip const CHECK_FOR_DISCONNECT - try { + TRY_HOOK { list lstCargo; int iRem; @@ -796,7 +791,7 @@ void __stdcall ActivateEquip(unsigned int iClientID, struct XActivateEquip const } } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_ActivateEquip,__stdcall,(unsigned int iClientID, struct XActivateEquip const &aq),(iClientID,aq)); @@ -816,9 +811,9 @@ void __stdcall ActivateCruise(unsigned int iClientID, struct XActivateCruise con CHECK_FOR_DISCONNECT - try { + TRY_HOOK { ClientInfo[iClientID].bCruiseActivated = ac.bActivate; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_ActivateCruise,__stdcall,(unsigned int iClientID, struct XActivateCruise const &ac),(iClientID,ac)); @@ -838,9 +833,9 @@ void __stdcall ActivateThrusters(unsigned int iClientID, struct XActivateThruste CHECK_FOR_DISCONNECT - try { + TRY_HOOK { ClientInfo[iClientID].bThrusterActivated = at.bActivate; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_ActivateThrusters,__stdcall,(unsigned int iClientID, struct XActivateThrusters const &at),(iClientID,at)); @@ -861,7 +856,7 @@ void __stdcall GFGoodSell(struct SGFGoodSellInfo const &gsi, unsigned int iClien CHECK_FOR_DISCONNECT - try { + TRY_HOOK { // anti-cheat check list lstCargo; int iHold; @@ -902,7 +897,7 @@ void __stdcall GFGoodSell(struct SGFGoodSellInfo const &gsi, unsigned int iClien //HkKick(ARG_CLIENTID(iClientID)); return; } - } catch(...) { AddLog("Exception in %s (iClientID=%u (%x))", __FUNCTION__, iClientID, Players.GetActiveCharacterName(iClientID)); } + } CATCH_HOOK({ AddLog("Exception in %s (iClientID=%u (%x))", __FUNCTION__, iClientID, Players.GetActiveCharacterName(iClientID)); }) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_GFGoodSell,__stdcall,(struct SGFGoodSellInfo const &gsi, unsigned int iClientID),(gsi,iClientID)); @@ -962,7 +957,7 @@ void __stdcall JumpInComplete(unsigned int iSystemID, unsigned int iShip) EXECUTE_SERVER_CALL(Server.JumpInComplete(iSystemID, iShip)); - try { + TRY_HOOK { uint iClientID = HkGetClientIDByShip(iShip); if(!iClientID) return; @@ -972,7 +967,7 @@ void __stdcall JumpInComplete(unsigned int iSystemID, unsigned int iShip) (wchar_t*)Players.GetActiveCharacterName(iClientID), iClientID, HkGetSystemNickByID(iSystemID).c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_JumpInComplete_AFTER,__stdcall,(unsigned int iSystemID, unsigned int iShip),(iSystemID,iShip)); } @@ -995,13 +990,13 @@ void __stdcall SystemSwitchOutComplete(unsigned int iShip, unsigned int iClientI EXECUTE_SERVER_CALL(Server.SystemSwitchOutComplete(iShip, iClientID)); - try { + TRY_HOOK { // event ProcessEvent(L"switchout char=%s id=%d system=%s", (wchar_t*)Players.GetActiveCharacterName(iClientID), iClientID, wscSystem.c_str()); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_SystemSwitchOutComplete_AFTER,__stdcall,(unsigned int iShip, unsigned int iClientID),(iShip,iClientID)); } @@ -1016,7 +1011,7 @@ void __stdcall Login(struct SLoginInfo const &li, unsigned int iClientID) ISERVER_LOGARG_WS(&li); ISERVER_LOGARG_UI(iClientID); - try { + TRY_HOOK { CALL_PLUGINS_V(PLUGIN_HkIServerImpl_Login_BEFORE, __stdcall, (struct SLoginInfo const &li, unsigned int iClientID), (li, iClientID)); Server.Login(li, iClientID); @@ -1092,15 +1087,13 @@ void __stdcall Login(struct SLoginInfo const &li, unsigned int iClientID) HkAddConnectLog(iClientID, wscIP); } - catch(...) - { - LOG_EXCEPTION + CATCH_HOOK({ CAccount *acc = Players.FindAccountFromClientID(iClientID); if (acc) { acc->ForceLogout(); } - } + }) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_Login_AFTER,__stdcall,(struct SLoginInfo const &li, unsigned int iClientID),(li,iClientID)); } @@ -1136,23 +1129,22 @@ void __stdcall GoTradelane(unsigned int iClientID, struct XGoTradelane const > ISERVER_LOG(); ISERVER_LOGARG_UI(iClientID); - try { + TRY_HOOK { ClientInfo[iClientID].bTradelane = true; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_GoTradelane,__stdcall,(unsigned int iClientID, struct XGoTradelane const >l),(iClientID,gtl)); - try + TRY_HOOK { Server.GoTradelane(iClientID, gtl); } - catch (...) - { + CATCH_HOOK({ uint iSystem; pub::Player::GetSystem(iClientID, iSystem); AddLog("ERROR: Exception in HkIServerImpl::GoTradelane charname=%s sys=%08x arch=%08x arch2=%08x", wstos((const wchar_t*)Players.GetActiveCharacterName(iClientID)).c_str(), iSystem, gtl.iTradelaneSpaceObj1, gtl.iTradelaneSpaceObj2); - } + }) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_GoTradelane_AFTER,__stdcall,(unsigned int iClientID, struct XGoTradelane const >l),(iClientID,gtl)); } @@ -1168,9 +1160,9 @@ void __stdcall StopTradelane(unsigned int iClientID, unsigned int p2, unsigned i ISERVER_LOGARG_UI(p3); ISERVER_LOGARG_UI(p4); - try { + TRY_HOOK { ClientInfo[iClientID].bTradelane = false; - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) CALL_PLUGINS_V(PLUGIN_HkIServerImpl_StopTradelane,__stdcall,(unsigned int iClientID, unsigned int p2, unsigned int p3, unsigned int p4),(iClientID,p2,p3,p4)); diff --git a/source/HkTimers.cpp b/source/HkTimers.cpp index 59f0187f8..ecfedfa81 100644 --- a/source/HkTimers.cpp +++ b/source/HkTimers.cpp @@ -46,7 +46,7 @@ void HkTimerCheckKick() CALL_PLUGINS_V(PLUGIN_HkTimerCheckKick,,(),()); - try { + TRY_HOOK { // for all players struct PlayerData *pPD = 0; while(pPD = Players.traverse_active(pPD)) @@ -96,7 +96,7 @@ void HkTimerCheckKick() } } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } /************************************************************************************************************** @@ -107,7 +107,7 @@ void HkTimerNPCAndF1Check() { CALL_PLUGINS_V(PLUGIN_HkTimerNPCAndF1Check,,(),()); - try { + TRY_HOOK { struct PlayerData *pPD = 0; while(pPD = Players.traverse_active(pPD)) { @@ -141,7 +141,7 @@ void HkTimerNPCAndF1Check() HkChangeNPCSpawn(true); // serverload too high, disable npcs else HkChangeNPCSpawn(false); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } /************************************************************************************************************** @@ -154,7 +154,7 @@ HANDLE hThreadResolver; void HkThreadResolver() { - try { + TRY_HOOK { while(1) { EnterCriticalSection(&csIPResolve); @@ -180,7 +180,7 @@ void HkThreadResolver() Sleep(50); } - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } /************************************************************************************************************** @@ -188,7 +188,7 @@ void HkThreadResolver() void HkTimerCheckResolveResults() { - try { + TRY_HOOK { EnterCriticalSection(&csIPResolve); foreach(g_lstResolveIPsResult, RESOLVE_IP, it) { @@ -211,7 +211,7 @@ void HkTimerCheckResolveResults() g_lstResolveIPsResult.clear(); LeaveCriticalSection(&csIPResolve); - } catch(...) { LOG_EXCEPTION } + } CATCH_HOOK({}) } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/Hook.h b/source/Hook.h index 7d73c728e..477929f79 100644 --- a/source/Hook.h +++ b/source/Hook.h @@ -87,11 +87,34 @@ #define EXTENDED_EXCEPTION_LOGGING #ifdef EXTENDED_EXCEPTION_LOGGING -EXPORT extern void WriteMiniDump(LPEXCEPTION_POINTERS pep); -EXPORT extern void AddExceptionInfoLog(LPEXCEPTION_POINTERS pep); -#define LOG_EXCEPTION { AddLog("ERROR: Exception in %s", __FUNCTION__); AddExceptionInfoLog(0); } + +struct SEHException +{ + SEHException(uint code, EXCEPTION_POINTERS* ep) + : code(code), record(*ep->ExceptionRecord), context(*ep->ContextRecord) + { } + + uint code; + EXCEPTION_RECORD record; + CONTEXT context; + + static void Translator(uint code, EXCEPTION_POINTERS* ep) + { + throw SEHException(code, ep); + } +}; + +EXPORT extern void WriteMiniDump(SEHException* ex); +EXPORT extern void AddExceptionInfoLog(SEHException* ex); +//#define LOG_EXCEPTION { AddLog("ERROR: Exception in %s", __FUNCTION__); AddExceptionInfoLog(0); } +#define TRY_HOOK try { _set_se_translator(SEHException::Translator); +#define CATCH_HOOK(e) } \ +catch(SEHException& ex) { e; AddBothLog("ERROR: SEH Exception in %s on line %d; minidump may contain more information.", __FUNCTION__, __LINE__); AddExceptionInfoLog(&ex); } \ +catch(std::exception& ex) { e; AddBothLog("ERROR: STL Exception in %s on line %d: %s.", __FUNCTION__, __LINE__, ex.what()); AddExceptionInfoLog(0); } \ +catch (...) { e; AddBothLog("ERROR: Exception in %s on line %d.", __FUNCTION__, __LINE__); AddExceptionInfoLog(0); } #else -#define LOG_EXCEPTION { AddLog("ERROR: Exception in %s", __FUNCTION__); } +#define TRY_HOOK try +#define CATCH_HOOK(e) catch(...) { e; AddLog("ERROR: Exception in %s", __FUNCTION__); } #endif @@ -153,16 +176,16 @@ struct PLUGIN_SORTCRIT { ret_type vPluginRet; \ bool bPluginReturn = false; \ g_bPlugin_nofunctioncall = false; \ - try { \ + TRY_HOOK { \ foreach(pPluginHooks[(int)callback_id],PLUGIN_HOOKDATA, itplugin) { \ if(itplugin->bPaused) \ continue; \ if(itplugin->pFunc) { \ CTimer timer(itplugin->sPluginFunction,set_iTimerThreshold); \ timer.start(); \ - try { \ + TRY_HOOK { \ vPluginRet = ((ret_type (calling_convention*) arg_types )itplugin->pFunc) args; \ - } catch(...) { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); } ) \ timer.stop(); \ } else \ AddLog("ERROR: Plugin '%s' does not export %s [%s]", itplugin->sName.c_str(), __FUNCTION__, __FUNCDNAME__); \ @@ -175,7 +198,7 @@ struct PLUGIN_SORTCRIT { } else if(*itplugin->ePluginReturnCode == SKIPPLUGINS) \ break; \ } \ - } catch(...) { AddLog("ERROR: Exception %s", __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception %s", __FUNCTION__); } ) \ if(bPluginReturn) \ return vPluginRet; \ } \ @@ -185,16 +208,16 @@ struct PLUGIN_SORTCRIT { { \ bool bPluginReturn = false; \ g_bPlugin_nofunctioncall = false; \ - try { \ + TRY_HOOK { \ foreach(pPluginHooks[(int)callback_id],PLUGIN_HOOKDATA, itplugin) { \ if(itplugin->bPaused) \ continue; \ if(itplugin->pFunc) { \ CTimer timer(itplugin->sPluginFunction,set_iTimerThreshold); \ timer.start(); \ - try { \ + TRY_HOOK { \ ((void (calling_convention*) arg_types )itplugin->pFunc) args; \ - } catch(...) { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); } ) \ timer.stop(); \ } else \ AddLog("ERROR: Plugin '%s' does not export %s [%s]", itplugin->sName.c_str(), __FUNCTION__, __FUNCDNAME__); \ @@ -207,7 +230,7 @@ struct PLUGIN_SORTCRIT { } else if(*itplugin->ePluginReturnCode == SKIPPLUGINS) \ break; \ } \ - } catch(...) { AddLog("ERROR: Exception %s", __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception %s", __FUNCTION__); } ) \ if(bPluginReturn) \ return; \ } \ @@ -216,16 +239,16 @@ struct PLUGIN_SORTCRIT { #define CALL_PLUGINS_NORET(callback_id,calling_convention,arg_types,args) \ { \ g_bPlugin_nofunctioncall = false; \ - try { \ + TRY_HOOK { \ foreach(pPluginHooks[(int)callback_id],PLUGIN_HOOKDATA, itplugin) { \ if(itplugin->bPaused) \ continue; \ if(itplugin->pFunc) { \ CTimer timer(itplugin->sPluginFunction,set_iTimerThreshold); \ timer.start(); \ - try { \ + TRY_HOOK { \ ((void (calling_convention*) arg_types )itplugin->pFunc) args; \ - } catch(...) { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception in plugin '%s' in %s", itplugin->sName.c_str(), __FUNCTION__); } ) \ timer.stop(); \ } else \ AddLog("ERROR: Plugin '%s' does not export %s [%s]", itplugin->sName.c_str(), __FUNCTION__, __FUNCDNAME__); \ @@ -238,7 +261,7 @@ struct PLUGIN_SORTCRIT { } else if(*itplugin->ePluginReturnCode == SKIPPLUGINS) \ break; \ } \ - } catch(...) { AddLog("ERROR: Exception %s", __FUNCTION__); LOG_EXCEPTION } \ + } CATCH_HOOK( { AddLog("ERROR: Exception %s", __FUNCTION__); } ) \ } \ typedef PLUGIN_RETURNCODE (*PLUGIN_Get_PluginReturnCode)(); @@ -637,6 +660,7 @@ EXPORT HK_ERROR HkReadCharFile(const wstring &wscCharname, list &lstOut EXPORT HK_ERROR HkWriteCharFile(const wstring &wscCharname, wstring wscData); // HkFuncLog +#define AddBothLog(s, ...) { AddLog(s, __VA_ARGS__); AddDebugLog(s, __VA_ARGS__); } EXPORT void AddDebugLog(const char *szString, ...); EXPORT void AddLog(const char *szString, ...); EXPORT void HkHandleCheater(uint iClientID, bool bBan, wstring wscReason, ...); diff --git a/source/Tools.cpp b/source/Tools.cpp index f18afff4b..00db3ae51 100644 --- a/source/Tools.cpp +++ b/source/Tools.cpp @@ -390,10 +390,9 @@ typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hF CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam ); -void WriteMiniDump(struct _EXCEPTION_POINTERS *pExceptionInfo) +void WriteMiniDump(SEHException* ex) { - AddLog("Attempting to write minidump..."); - AddDebugLog("Attempting to write minidump..."); + AddBothLog("Attempting to write minidump..."); HMODULE hDll = ::LoadLibrary( "DBGHELP.DLL" ); if (hDll) { @@ -423,10 +422,13 @@ void WriteMiniDump(struct _EXCEPTION_POINTERS *pExceptionInfo) { _MINIDUMP_EXCEPTION_INFORMATION ExInfo; - if (pExceptionInfo) + if (ex) { ExInfo.ThreadId = ::GetCurrentThreadId(); - ExInfo.ExceptionPointers = pExceptionInfo; + EXCEPTION_POINTERS ep; + ep.ContextRecord = &ex->context; + ep.ExceptionRecord = &ex->record; + ExInfo.ExceptionPointers = &ep; ExInfo.ClientPointers = NULL; pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL ); } @@ -436,22 +438,22 @@ void WriteMiniDump(struct _EXCEPTION_POINTERS *pExceptionInfo) } ::CloseHandle(hFile); - AddLog("Minidump '%s' written.", szDumpPath); + AddBothLog("Minidump '%s' written.", szDumpPath); } } } } -void AddExceptionInfoLog(LPEXCEPTION_POINTERS pep) +void AddExceptionInfoLog(SEHException* ex) { try { - _EXCEPTION_RECORD *exception = NULL; - _CONTEXT *reg = NULL; - if (pep) + EXCEPTION_RECORD *exception = NULL; + CONTEXT *context = NULL; + if (ex) { - exception = pep->ExceptionRecord; - reg = pep->ContextRecord; + exception = &ex->record; + context = &ex->context; } if (exception) @@ -466,26 +468,26 @@ void AddExceptionInfoLog(LPEXCEPTION_POINTERS pep) iOffset = iAddr - (uint)hModExc; GetModuleFileName(hModExc, szModName, sizeof(szModName)); } - AddLog("Code=%x Offset=%x Module=\"%s\"", iCode, iOffset, szModName); + AddBothLog("Code=%x Offset=%x Module=\"%s\"", iCode, iOffset, szModName); } else { - AddLog("No exception information available"); + AddBothLog("No exception information available"); } - if (reg) + if (context) { - AddLog("eax=%x ebx=%x ecx=%x edx=%x edi=%x esi=%x ebp=%x eip=%x esp=%x", - reg->Eax, reg->Ebx, reg->Ecx, reg->Edx, reg->Edi, reg->Esi, reg->Ebp, reg->Eip, reg->Esp); + AddBothLog("eax=%x ebx=%x ecx=%x edx=%x edi=%x esi=%x ebp=%x eip=%x esp=%x", + context->Eax, context->Ebx, context->Ecx, context->Edx, context->Edi, context->Esi, context->Ebp, context->Eip, context->Esp); } else { - AddLog("No register information available"); + AddBothLog("No register information available"); } - WriteMiniDump(pep); + WriteMiniDump(ex); - } catch(...) { AddLog("Exception in AddExceptionInfoLog!"); } + } catch(...) { AddBothLog("Exception in AddExceptionInfoLog (minidump/exception)!"); } } #endif