Skip to content

Commit

Permalink
OnGameCrash callback!
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJJ committed Aug 24, 2023
1 parent e400729 commit ce6b3e0
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 66 deletions.
4 changes: 4 additions & 0 deletions include/modslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef void (*OnInterfaceAddedFn)(const char*, const void*);
typedef const char* (*GetUpdaterURLFn)();
typedef void (*OnModLoadFn)();
typedef ModInfoDependency* (*GetDependenciesListFn)();
typedef void (*OnGameCrashedFn)(const char*, int, int, uintptr_t, mcontext_t*);
struct ModDesc
{
ModInfo* m_pInfo;
Expand All @@ -19,6 +20,7 @@ struct ModDesc
OnModLoadFn m_fnOnAllModsLoaded;
GetUpdaterURLFn m_fnRequestUpdaterURL;
OnInterfaceAddedFn m_fnInterfaceAddedCB;
OnGameCrashedFn m_fnGameCrashedCB;

ModDesc()
{
Expand All @@ -28,6 +30,7 @@ struct ModDesc
m_fnOnAllModsLoaded = NULL;
m_fnRequestUpdaterURL = NULL;
m_fnInterfaceAddedCB = NULL;
m_fnGameCrashedCB = NULL;
}
};

Expand All @@ -46,6 +49,7 @@ class ModsList
void ProcessLoading();
void ProcessUnloading();
void ProcessUpdater();
void ProcessCrash(const char* szLibName, int sig, int code, uintptr_t libaddr, mcontext_t* mcontext);
inline int GetModsNum() { return m_vecModInfo.size(); }

// Callbacks
Expand Down
5 changes: 4 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
modlist->ProcessLoading();
modlist->OnAllModsLoaded();
logger->Info("Mods were launched!");

/* Fake crash for crash handler testing */
//__builtin_trap();

/* Return the value it needs */
return JNI_VERSION_1_6;
Expand All @@ -362,4 +365,4 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
/* Not sure if it'll work... */
/* It worked once, lol */
//modlist->ProcessUnloading();
}
}
1 change: 1 addition & 0 deletions mod/amlmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include <cstring>
#include <stdlib.h>
#include <signal.h>

#ifdef __arm__
#define AML32
Expand Down
27 changes: 21 additions & 6 deletions modslist.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <modslist.h>
#include <modpaks.h>
#include <mod/logger.h>
#include <mod/listitem.h>
#include <dlfcn.h>

bool ModsList::AddMod(ModInfo* modinfo, void* modhandle, const char* path)
Expand Down Expand Up @@ -219,22 +218,26 @@ void ModsList::ProcessPreLoading()
if(handle != 0)
{
onModPreLoadFn = (OnModLoadFn)dlsym(handle, "OnModPreLoad");
if(onModPreLoadFn == NULL) onModPreLoadFn = (OnModLoadFn)dlsym(handle, "_Z12OnModPreLoadv");
//if(onModPreLoadFn == NULL) onModPreLoadFn = (OnModLoadFn)dlsym(handle, "_Z12OnModPreLoadv");
if(onModPreLoadFn != NULL) onModPreLoadFn();

desc->m_fnOnModLoaded = (OnModLoadFn)dlsym(handle, "OnModLoad");
if(desc->m_fnOnModLoaded == NULL) desc->m_fnOnModLoaded = (OnModLoadFn)dlsym(handle, "_Z9OnModLoadv");
//if(desc->m_fnOnModLoaded == NULL) desc->m_fnOnModLoaded = (OnModLoadFn)dlsym(handle, "_Z9OnModLoadv");

desc->m_fnOnModUnloaded = (OnModLoadFn)dlsym(handle, "OnModUnload");
if(desc->m_fnOnModUnloaded == NULL) desc->m_fnOnModUnloaded = (OnModLoadFn)dlsym(handle, "_Z11OnModUnloadv");
//if(desc->m_fnOnModUnloaded == NULL) desc->m_fnOnModUnloaded = (OnModLoadFn)dlsym(handle, "_Z11OnModUnloadv");

desc->m_fnRequestUpdaterURL = (GetUpdaterURLFn)dlsym(handle, "OnUpdaterURLRequested");
//if(desc->m_fnRequestUpdaterURL == NULL) desc->m_fnRequestUpdaterURL = (GetUpdaterURLFn)dlsym(handle, "_Z21OnUpdaterURLRequestedv");

desc->m_fnInterfaceAddedCB = (OnInterfaceAddedFn)dlsym(handle, "OnInterfaceAdded");
if(desc->m_fnInterfaceAddedCB == NULL) desc->m_fnInterfaceAddedCB = (OnInterfaceAddedFn)dlsym(handle, "_Z16OnInterfaceAddedPKcPKv");
//if(desc->m_fnInterfaceAddedCB == NULL) desc->m_fnInterfaceAddedCB = (OnInterfaceAddedFn)dlsym(handle, "_Z16OnInterfaceAddedPKcPKv");

desc->m_fnOnAllModsLoaded = (OnModLoadFn)dlsym(handle, "OnAllModsLoaded");
if(desc->m_fnOnAllModsLoaded == NULL) desc->m_fnOnAllModsLoaded = (OnModLoadFn)dlsym(handle, "_Z15OnAllModsLoadedv");
//if(desc->m_fnOnAllModsLoaded == NULL) desc->m_fnOnAllModsLoaded = (OnModLoadFn)dlsym(handle, "_Z15OnAllModsLoadedv");

desc->m_fnGameCrashedCB = (OnGameCrashedFn)dlsym(handle, "OnGameCrash");
//if(desc->m_fnGameCrashedCB == NULL) desc->m_fnGameCrashedCB = (OnGameCrashedFn)dlsym(handle, "_Z11OnGameCrashv");
}
}
logger->Info("Mods were preloaded!");
Expand Down Expand Up @@ -288,6 +291,18 @@ void ModsList::ProcessUpdater()
++it;
}
}
void ModsList::ProcessCrash(const char* szLibName, int sig, int code, uintptr_t libaddr, mcontext_t* mcontext)
{
auto it = modlist->m_vecModInfo.begin();
auto end = modlist->m_vecModInfo.end();
ModDesc* desc = NULL;
while( it != end )
{
desc = *it;
if(desc->m_fnGameCrashedCB != NULL) desc->m_fnGameCrashedCB(szLibName, sig, code, libaddr, mcontext);
++it;
}
}
void ModsList::OnInterfaceAdded(const char* name, const void* ptr)
{
auto it = modlist->m_vecModInfo.begin();
Expand Down
Loading

0 comments on commit ce6b3e0

Please sign in to comment.