From 285c48dda1aff6ef014fcbe26031071aaf5c7949 Mon Sep 17 00:00:00 2001 From: Nikita Krapivin Date: Fri, 2 Apr 2021 22:39:16 +0500 Subject: [PATCH] Publish v2.2 source code. --- libLassebq/GMAddresses.h | 3 +++ libLassebq/GMLua.cpp | 5 +++++ libLassebq/GMLua.h | 3 ++- libLassebq/Room.cpp | 1 + libLassebq/Room.h | 1 + libLassebq/libLassebq.aps | Bin 3456 -> 3456 bytes libLassebq/libLassebq.cpp | 40 +++++++++++++++++++++++++++++++------- libLassebq/libLassebq.rc | Bin 5730 -> 5728 bytes 8 files changed, 45 insertions(+), 8 deletions(-) diff --git a/libLassebq/GMAddresses.h b/libLassebq/GMAddresses.h index 2af1b02..f6c8364 100644 --- a/libLassebq/GMAddresses.h +++ b/libLassebq/GMAddresses.h @@ -34,6 +34,7 @@ #define AllocNewVarSlot_Addr (0x01525840u) #define MenuVersionString_Addr (0x01233C16u) #define DispatchAsync_Addr (0x00000000u) +#define New_Room_Addr (0x01CF8904u) #endif #ifdef KZ_105_GOG /* Katana ZERO v1.0.5 Windows GOG */ @@ -64,6 +65,7 @@ #define AllocNewVarSlot_Addr (0x015244C0u) #define MenuVersionString_Addr (0x01232846u) #define DispatchAsync_Addr (0x00000000u) +#define New_Room_Addr (0x01CF7894u) #endif #ifdef DITTO_WIN_STEAM /* The Swords of Ditto 1.17.05-205 STM Windows Steam */ @@ -94,4 +96,5 @@ #define AllocNewVarSlot_Addr (0x023C5310u) #define MenuVersionString_Addr (0x000020C0u) #define DispatchAsync_Addr (0x0248E970u) +#define New_Room_Addr (0x02C4698Cu) #endif diff --git a/libLassebq/GMLua.cpp b/libLassebq/GMLua.cpp index 68d7f0a..0d47740 100644 --- a/libLassebq/GMLua.cpp +++ b/libLassebq/GMLua.cpp @@ -14,6 +14,7 @@ bool g_ThrowErrors = true; bool g_NoConsole = false; bool g_IgnoreArgc = false; bool g_AddScripts = false; +bool g_EnableBeforeEvents = false; /* * Why: @@ -442,6 +443,10 @@ void InitGMLuaConfig(void) { wait = true; } + else if (line == "enableBeforeEvents") + { + g_EnableBeforeEvents = true; + } } cfg.close(); diff --git a/libLassebq/GMLua.h b/libLassebq/GMLua.h index 13a365a..52aa4e4 100644 --- a/libLassebq/GMLua.h +++ b/libLassebq/GMLua.h @@ -50,4 +50,5 @@ void RenewGlobal(lua_State* _pL); extern bool g_ThrowErrors; extern bool g_NoConsole; extern bool g_AddCollisionEvents; -extern bool g_AddScripts; \ No newline at end of file +extern bool g_AddScripts; +extern bool g_EnableBeforeEvents; \ No newline at end of file diff --git a/libLassebq/Room.cpp b/libLassebq/Room.cpp index 173f851..62ece0e 100644 --- a/libLassebq/Room.cpp +++ b/libLassebq/Room.cpp @@ -3,6 +3,7 @@ CRoom** g_RunRoom = nullptr; // this variable was only used to find instances, it is not used anymore! CHash* g_CInstanceHashList = nullptr; +int* g_New_Room = nullptr; const int FLAG_deactivated = 1; diff --git a/libLassebq/Room.h b/libLassebq/Room.h index 55f9391..555b454 100644 --- a/libLassebq/Room.h +++ b/libLassebq/Room.h @@ -183,5 +183,6 @@ class CRoom { }; extern CRoom** g_RunRoom; +extern int* g_New_Room; extern CHash* g_CInstanceHashList; CInstance* lass_find_CInstance_QUICK(int obj_index); \ No newline at end of file diff --git a/libLassebq/libLassebq.aps b/libLassebq/libLassebq.aps index 661a12012cb408e80d109f0dcad61ebb36b57416..db268c573514c784713d1d3ffa1a5b8ef5d2282d 100644 GIT binary patch delta 163 zcmZpWZjjz!z{bhMz{CIoOq(s)!WkKjHcw=a2U3$iauhRnF&IvM&!(Cv&tk#i#NxxE zz+lB<$Kt|b3S`*=S?)kFKOkF|L4g6pGi9*_tFmWt0O|m#wFdG*D)oRW6oIr6P>mCd kGgy}qizAR{1C(Q!{FYN4Xy-(B@68EZA|O|ka&t2Q00&+hbN~PV delta 138 zcmZpWZjjz!z{bhQz{CIojGHal!WkJ2H&0}b2U3$iauhT7Fc?jK&!%c2$YQ}_$YKp7 z?O2>xOj)d03|JHxOn@T(K-vZ (EventPatchMap[_pSelf->m_pObject->m_ID][evKey]); + + if (g_EnableBeforeEvents) + { + std::string nn("Before" + mapOfEvents[evKey]); + lassebq_doLua(_pSelf, _pOther, nn.c_str()); + } + origptr(_pSelf, _pOther); // Execute the lua function. @@ -595,6 +604,7 @@ void lassebq_initYYC() if (!g_ThrowErrors) std::cout << "Will ignore Lua errors, this is VERY evil and unstable!" << std::endl; if (g_AddCollisionEvents) std::cout << "Collision event name generation enabled, loading times will be WAY slower." << std::endl; if (g_AddScripts) std::cout << "GML script hooking enabled, loading times will be slowed down." << std::endl; + if (g_EnableBeforeEvents) std::cout << "Execution of `Before` object events is enabled." << std::endl; } exeBase = GetModuleHandleW(nullptr); @@ -643,6 +653,7 @@ void lassebq_initYYC() } g_RunRoom = reinterpret_cast(exeAsUint + Run_Room_Addr); + g_New_Room = reinterpret_cast(exeAsUint + New_Room_Addr); g_CInstanceHashList = reinterpret_cast*>(exeAsUint + CInstanceHash_Addr); g_RFunctionTableLen = reinterpret_cast(exeAsUint + RFunctionTableL_Addr); g_RFunctionTable = reinterpret_cast(exeAsUint + RFunctionTable_Addr); @@ -731,14 +742,29 @@ funcR lassebq_init() return 1.0; } +const int REASON_game_end = -100; +const int REASON_game_restart = -200; +const int REASON_game_load = -300; +const int REASON_game_end2 = -400; + funcR lassebq_shutdown() { - // TODO: do something more complicated than this? - lua_close(lS); - FreeConsole(); - //sch_end(); - SH_quitDetours(); - return 1.0; + int r = *g_New_Room; + if (r != REASON_game_end && r != REASON_game_end2) + { + // wrong end reason? :p + std::cout << "A friendly reminder, game_restart is evil, do not use this piece of shit please." << std::endl; + return 0.0; + } + else + { + // TODO: do something more complicated than this? + lua_close(lS); + FreeConsole(); + //sch_end(); + SH_quitDetours(); + return 1.0; + } } funcV RegisterCallbacks(char* p1, char* p2, char* p3, char* p4) diff --git a/libLassebq/libLassebq.rc b/libLassebq/libLassebq.rc index 6535969bfa3e178b1ae15ebdc6e7a602e0d656e7..b17b734c25582a6b1916484edf34bd4e4d2c73e8 100644 GIT binary patch delta 164 zcmaE)^FU`q6$hiyMx)JZIV_ohod5h+H}ByIVg!ot^Vu`T%d=RpII;M!C@@&D z*s-{WuI`3$!d(7ONpnoK|k@bei?mJ{aMoFep(830e!Ax!`P delta 161 zcmaE$^GIhy6$hi?M#If(IV_oh9DY9e$rpIVHp}pQVg!ov^Vu_62(nnP7_wLc zNjnxN7E=~076TRq1{0u&KajQoikblBT!0uP;|8QHf#Oyylk>RcxGh+WSsZ}EHY|FR pKXRE)KEo}Aux7Fh&w|aD1VVsT0c|#%EF;V{IY5YGbC%FIW&jc7BU=Cf