Skip to content

Commit

Permalink
Publish v2.2 source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrapivin committed Apr 2, 2021
1 parent 673d4c7 commit 285c48d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 8 deletions.
3 changes: 3 additions & 0 deletions libLassebq/GMAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -94,4 +96,5 @@
#define AllocNewVarSlot_Addr (0x023C5310u)
#define MenuVersionString_Addr (0x000020C0u)
#define DispatchAsync_Addr (0x0248E970u)
#define New_Room_Addr (0x02C4698Cu)
#endif
5 changes: 5 additions & 0 deletions libLassebq/GMLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -442,6 +443,10 @@ void InitGMLuaConfig(void)
{
wait = true;
}
else if (line == "enableBeforeEvents")
{
g_EnableBeforeEvents = true;
}
}
cfg.close();

Expand Down
3 changes: 2 additions & 1 deletion libLassebq/GMLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
extern bool g_AddScripts;
extern bool g_EnableBeforeEvents;
1 change: 1 addition & 0 deletions libLassebq/Room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

CRoom** g_RunRoom = nullptr; // this variable was only used to find instances, it is not used anymore!
CHash<CInstance>* g_CInstanceHashList = nullptr;
int* g_New_Room = nullptr;

const int FLAG_deactivated = 1;

Expand Down
1 change: 1 addition & 0 deletions libLassebq/Room.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@ class CRoom {
};

extern CRoom** g_RunRoom;
extern int* g_New_Room;
extern CHash<CInstance>* g_CInstanceHashList;
CInstance* lass_find_CInstance_QUICK(int obj_index);
Binary file modified libLassebq/libLassebq.aps
Binary file not shown.
40 changes: 33 additions & 7 deletions libLassebq/libLassebq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void ALT_DispatchAsync(int _map, int _eventnum)
DispatchAsyncInternal(_map, _eventnum);
}

void lassebq_doLua(CInstance* _pSelf, CInstance* _pOther, const char* _pLFName) // pointerLuaFunctionName
bool lassebq_doLua(CInstance* _pSelf, CInstance* _pOther, const char* _pLFName) // pointerLuaFunctionName
{
int r = LUA_OK; const char* errmsg = nullptr; int type = LUA_TNONE; int a = -1;
for (const std::string& script : Lscripts)
Expand Down Expand Up @@ -210,6 +210,8 @@ void lassebq_doLua(CInstance* _pSelf, CInstance* _pOther, const char* _pLFName)
}
}
}

return false;
}

unsigned long long lassebq_evKey(int etype, int esubtype)
Expand Down Expand Up @@ -290,6 +292,13 @@ void lassebq_luaPatch_GMLRoutine(CInstance* _pSelf, CInstance* _pOther)

GML_ObjectEvent origptr = reinterpret_cast<GML_ObjectEvent>
(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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -643,6 +653,7 @@ void lassebq_initYYC()
}

g_RunRoom = reinterpret_cast<CRoom**>(exeAsUint + Run_Room_Addr);
g_New_Room = reinterpret_cast<int*>(exeAsUint + New_Room_Addr);
g_CInstanceHashList = reinterpret_cast<CHash<CInstance>*>(exeAsUint + CInstanceHash_Addr);
g_RFunctionTableLen = reinterpret_cast<int*>(exeAsUint + RFunctionTableL_Addr);
g_RFunctionTable = reinterpret_cast<RFunction**>(exeAsUint + RFunctionTable_Addr);
Expand Down Expand Up @@ -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)
Expand Down
Binary file modified libLassebq/libLassebq.rc
Binary file not shown.

0 comments on commit 285c48d

Please sign in to comment.