Skip to content

Commit

Permalink
More code :p
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJJ committed Dec 30, 2023
1 parent 8d6d208 commit 6467314
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 80 deletions.
2 changes: 1 addition & 1 deletion AML_PrecompiledLibs
2 changes: 1 addition & 1 deletion ARMPatch
10 changes: 5 additions & 5 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ LOCAL_MODULE := substrate
LOCAL_SRC_FILES := obj/local/$(TARGET_ARCH_ABI)/libsubstrate.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := dobby
LOCAL_SRC_FILES := AML_PrecompiledLibs/$(TARGET_ARCH_ABI)/libdobby.a
include $(PREBUILT_STATIC_LIBRARY)
# include $(CLEAR_VARS)
# LOCAL_MODULE := dobby
# LOCAL_SRC_FILES := AML_PrecompiledLibs/$(TARGET_ARCH_ABI)/libdobby.a
# include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := gloss
Expand Down Expand Up @@ -56,7 +56,7 @@ include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cpp .cc
LOCAL_SHARED_LIBRARIES := armpatch substrate curl dobby gloss xUnwind
LOCAL_SHARED_LIBRARIES := armpatch substrate curl gloss xUnwind
LOCAL_MODULE := AML
LOCAL_SRC_FILES := main.cpp interface.cpp aml.cpp modpaks.cpp signal.cpp \
modslist.cpp icfg.cpp vtable_hooker.cpp alog.cpp mls.cpp \
Expand Down
2 changes: 1 addition & 1 deletion aml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void AML::ShowToast(bool longerDuration, const char* fmt, ...)
{
if(!fmt) return;

char txt[2048];
static char txt[512];
va_list args;
va_start(args, fmt);
vsnprintf(txt, sizeof(txt), fmt, args);
Expand Down
9 changes: 6 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <modslist.h>

bool g_bShowUpdatedToast, g_bShowUpdateFailedToast, g_bEnableFileDownloads;
bool g_bCrashAML, g_bNoMods, g_bSimplerCrashLog, g_bNoSPInLog, g_bNoModsInLog, g_bMLSOnlyManualSaves, g_bDumpAllThreads, g_bEHUnwind;
bool g_bCrashAML, g_bNoMods, g_bSimplerCrashLog, g_bNoSPInLog, g_bNoModsInLog, g_bMLSOnlyManualSaves, g_bDumpAllThreads, g_bEHUnwind, g_bMoreRegsInfo;
int g_nEnableNews, g_nDownloadTimeout;
ConfigEntry* g_pLastNewsId;
char g_szInternalStoragePath[256],
Expand Down Expand Up @@ -222,6 +222,7 @@ void LoadMods(const char* path)
}
}

extern ModDesc* pLastModProcessed;
void StartSignalHandler();
void HookALog();
extern bool bAndroidLog_OnlyImportant, bAndroidLog_NoAfter;
Expand Down Expand Up @@ -347,6 +348,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
g_bMLSOnlyManualSaves = cfg->GetBool("MLSOnlyManualSaves", false, "DevTools");
g_bDumpAllThreads = cfg->GetBool("CrashLogFromAllThreads", true, "DevTools");
g_bEHUnwind = cfg->GetBool("EHUnwindCrashLog", false, "DevTools");
g_bMoreRegsInfo = cfg->GetBool("MoreRegistersInfo", true, "DevTools");

if(g_nDownloadTimeout < 1) g_nDownloadTimeout = 1;
else if(g_nDownloadTimeout > 10) g_nDownloadTimeout = 10;
Expand All @@ -356,9 +358,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
if(cfg->GetBool("SignalHandler", true)) StartSignalHandler();

/* Catch another fish! */
if(cfg->GetBool("PrintLogsToFile", false)) HookALog();
bAndroidLog_OnlyImportant = !cfg->GetBool("PrintLogsToFile_Verbose", false);
bAndroidLog_NoAfter = cfg->GetBool("PrintLogsToFile_NoLogCat", false);
if(cfg->GetBool("PrintLogsToFile", false)) HookALog();

/* Mods? */
logger->Info("Working with mods...");
Expand Down Expand Up @@ -421,6 +423,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
modlist->OnAllModsLoaded();
logger->Info("Mods were launched!");
}
pLastModProcessed = NULL;

/* Fake crash for crash handler testing (does not work?) */
if(g_bCrashAML) __builtin_trap();
Expand All @@ -433,5 +436,5 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
{
/* Not sure if it'll work... */
/* It worked once, lol */
//modlist->ProcessUnloading();
modlist->ProcessUnloading();
}
8 changes: 7 additions & 1 deletion mod/iaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class IAML
virtual bool IsThumbAddr(uintptr_t addr);
virtual uintptr_t GetBranchDest(uintptr_t addr);



// Inlines (shortcuts for you!)
inline void Write(uintptr_t dest, const char* str, size_t size) { Write(dest, (uintptr_t)str, size); } // Inline
inline void Write(uintptr_t dest, const char* str) { Write(dest, (uintptr_t)str, strlen(str)); } // Inline
Expand Down Expand Up @@ -160,6 +162,10 @@ inline IAML* GetAMLInterface() { return aml; }
#define DECL_HOOKi(_name, ...) \
int (*_name)(__VA_ARGS__); \
int HookOf_##_name(__VA_ARGS__)
/* Just a hook declaration with return type = void* */
#define DECL_HOOKp(_name, ...) \
void* (*_name)(__VA_ARGS__); \
void* HookOf_##_name(__VA_ARGS__)

/* Just a hook of a function */
#define HOOK(_name, _fnAddr) \
Expand All @@ -183,4 +189,4 @@ inline IAML* GetAMLInterface() { return aml; }
#define HOOK_IL2CPP(_name, _methodInfo) \
aml->Hook((void*)_methodInfo->methodPointer, (void*)(&HookOf_##_name), (void**)(&_name))

#endif // _IAML
#endif // _IAML
11 changes: 9 additions & 2 deletions modslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <modpaks.h>
#include <mod/logger.h>
#include <mod/listitem.h>
//#include <dlfcn.h>

extern ModDesc* pLastModProcessed;

Mods* listMods = NULL;
LIST_START(Mods)
Expand Down Expand Up @@ -235,6 +235,7 @@ void ModsList::ProcessPreLoading()
if(handle != NULL)
{
desc = item->pModDesc;
pLastModProcessed = desc;

onModPreLoadFn = (OnModLoadFn)dlsym(handle, "OnModPreLoad");
//if(onModPreLoadFn == NULL) onModPreLoadFn = (OnModLoadFn)dlsym(handle, "_Z12OnModPreLoadv");
Expand Down Expand Up @@ -268,6 +269,7 @@ void ModsList::ProcessLoading()
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnOnModLoaded) desc->m_fnOnModLoaded();
}
logger->Info("Mods were loaded!");
Expand All @@ -279,6 +281,7 @@ void ModsList::ProcessUnloading()
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnOnModUnloaded) desc->m_fnOnModUnloaded();
}
}
Expand All @@ -289,6 +292,7 @@ void ModsList::ProcessUpdater()
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnRequestUpdaterURL)
{
const char* url = desc->m_fnRequestUpdaterURL();
Expand All @@ -311,6 +315,7 @@ void ModsList::ProcessCrash(const char* szLibName, int sig, int code, uintptr_t
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnGameCrashedCB) desc->m_fnGameCrashedCB(szLibName, sig, code, libaddr, mcontext);
}
}
Expand Down Expand Up @@ -342,6 +347,7 @@ void ModsList::OnInterfaceAdded(const char* name, const void* ptr)
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnInterfaceAddedCB) desc->m_fnInterfaceAddedCB(name, ptr);
}
}
Expand All @@ -352,10 +358,11 @@ void ModsList::OnAllModsLoaded()
LIST_FOR(listMods)
{
desc = item->pModDesc;
pLastModProcessed = desc;
if(desc->m_fnOnAllModsLoaded) desc->m_fnOnAllModsLoaded();
}
logger->Info("Mods were postloaded!");
}

static ModsList modlistLocal;
ModsList* modlist = &modlistLocal;
ModsList* modlist = &modlistLocal;
Loading

0 comments on commit 6467314

Please sign in to comment.