1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-20 17:30:13 +00:00
UltimateTrainingModpack/source/main.cpp

115 lines
2.8 KiB
C++
Raw Normal View History

2019-07-25 20:00:13 +00:00
#include <switch_min.h>
2019-05-17 16:24:04 +00:00
#include <dirent.h>
#include <stdio.h>
#include <string.h>
2019-07-25 20:00:13 +00:00
#include <switch_min/kernel/ipc.h>
#include <sys/iosupport.h>
#include <sys/reent.h>
#include "useful/useful.h"
#include "saltysd/saltysd_core.h"
#include "saltysd/saltysd_dynamic.h"
#include "saltysd/saltysd_ipc.h"
2019-07-25 20:00:13 +00:00
#include "saltysd/saltysd_helper.h"
2019-05-19 04:16:48 +00:00
#include "hitbox_visualizer.hpp"
#include "training_mods.hpp"
2019-05-17 16:24:04 +00:00
extern "C" {
extern u32 __start__;
static char g_heap[0x8000];
void __libnx_init(void* ctx, Handle main_thread, void* saved_lr);
void __attribute__((weak)) NORETURN __libnx_exit(int rc);
void __nx_exit(int, void*);
void __libc_fini_array(void);
void __libc_init_array(void);
2019-05-17 16:24:04 +00:00
}
u32 __nx_applet_type = AppletType_None;
Handle orig_main_thread;
2019-05-17 16:24:04 +00:00
void* orig_ctx;
void* orig_saved_lr;
void __libnx_init(void* ctx, Handle main_thread, void* saved_lr) {
extern char* fake_heap_start;
extern char* fake_heap_end;
fake_heap_start = &g_heap[0];
fake_heap_end = &g_heap[sizeof g_heap];
orig_ctx = ctx;
orig_main_thread = main_thread;
orig_saved_lr = saved_lr;
// Call constructors.
// void __libc_init_array(void);
__libc_init_array();
2019-05-17 16:24:04 +00:00
}
void __attribute__((weak)) NORETURN __libnx_exit(int rc) {
// Call destructors.
// void __libc_fini_array(void);
__libc_fini_array();
2019-05-17 16:24:04 +00:00
SaltySD_printf("SaltySD Plugin: jumping to %p\n", orig_saved_lr);
2019-05-17 16:24:04 +00:00
__nx_exit(0, orig_saved_lr);
while (true)
;
2019-05-17 16:24:04 +00:00
}
extern int sprintf(char* s, const char* format, ...) LINKABLE;
int sprintf_intercept(char* s, const char* format, ...) {
if (strcmp(format, "Ver. %d.%d.%d") == 0 || strcmp(format, "Salty v%d%d%d") == 0)
format = "Training Mods v1.4";
va_list vl;
va_start(vl,format);
int ret = vsprintf(s, format, vl);
va_end(vl);
return ret;
}
int main(int argc, char* argv[]) {
SaltySD_printf("SaltySD Plugin: alive\n");
// Get anchor for imports
// do not remove if you plan on using IMPORT
ANCHOR_ABS = SaltySDCore_getCodeStart();
/*
Example of string replacement:
replaces the title screen's version number with the string
below.
*/
const char* ver = "Ver. %d.%d.%d";
u64 version_string = SaltySDCore_findCode((u8*)ver, strlen(ver));
if (version_string) {
SaltySD_Memcpy(version_string, (u64) "Salty v%d%d%d", 13);
}
SaltySDCore_ReplaceImport("sprintf", (void*)sprintf_intercept);
// Add function replacements here
hitbox_vis_main();
training_mods_main();
2019-10-26 21:09:18 +00:00
FILE* f = SaltySDCore_fopen("sdmc:/SaltySD/training_modpack.log", "w");
if (f) {
SaltySD_printf("Writing training_modpack.log...\n");
char buffer[20];
snprintf(buffer, 20, "%lx", (u64)&menu);
SaltySDCore_fwrite(buffer, strlen(buffer), 1, f);
SaltySDCore_fclose(f);
}
__libnx_exit(0);
}