I've been wanting to experiment with the FMOD audio library on the Switch. An official build is obviously not publicly available, so I had the idea of finding the relevant FMOD functions within the game code of Celeste and just using those. (I understand that this may not be possible depending on how the game was optimized or how the Switch library differs from the official PC/mobile versions of the library with public documentation, but I haven't gotten to the part where that matters yet.)
I found the offsets for the functions I am interested in with Ghidra and confirmed that they are correct by hooking them using an exlaunch mod. For example, I tried hooking FMOD_Studio_System_GetEvent and swapping around some music, and my changes were reflected when I launched the game.
However, it looks like I'm not able to run my own program or game code within the context of Celeste.
Directly linking libnx doesn't work: Attempting to use libnx functions results in linker errors like "dangerous relocation" and "recompile with -fPIE" (even though everything is already compiled with -fPIE). Recompiling libnx without switch_crt0.s and using that seemed to resolve the issue, and I assumed there wouldn't be any issues since exlaunch also has a crt0. However, even then, attempting to call printf() after consoleInit(NULL) appears to cause a crash.
I also tried using SDL2. While SDL2 appears to link successfully using the libnx without crt0, the mod crashes in __init_array before it even reaches exl_main. I tried skipping the function within the init array that causes the crash (obviously a bad idea) but even then, SDL_Init() causes a crash.
I tried putting the libnx/SDL code both before and after nnMain, but it didn't help.
1) Is my approach correct? I assumed that the easiest way to use a function within a game would be to inject my own code into that game. Would it be easier to perhaps load the game's code into my own homebrew instead?
2) Are there any existing working/complete projects that replace the entry point of a game? I found a project called SaltyLime by @XorTroll, but it seemed to be discontinued and I couldn't find any projects that used it.
3) Alternatively, are there any existing projects that use a game "as a library"?
I found the offsets for the functions I am interested in with Ghidra and confirmed that they are correct by hooking them using an exlaunch mod. For example, I tried hooking FMOD_Studio_System_GetEvent and swapping around some music, and my changes were reflected when I launched the game.
However, it looks like I'm not able to run my own program or game code within the context of Celeste.
Directly linking libnx doesn't work: Attempting to use libnx functions results in linker errors like "dangerous relocation" and "recompile with -fPIE" (even though everything is already compiled with -fPIE). Recompiling libnx without switch_crt0.s and using that seemed to resolve the issue, and I assumed there wouldn't be any issues since exlaunch also has a crt0. However, even then, attempting to call printf() after consoleInit(NULL) appears to cause a crash.
I also tried using SDL2. While SDL2 appears to link successfully using the libnx without crt0, the mod crashes in __init_array before it even reaches exl_main. I tried skipping the function within the init array that causes the crash (obviously a bad idea) but even then, SDL_Init() causes a crash.
I tried putting the libnx/SDL code both before and after nnMain, but it didn't help.
1) Is my approach correct? I assumed that the easiest way to use a function within a game would be to inject my own code into that game. Would it be easier to perhaps load the game's code into my own homebrew instead?
2) Are there any existing working/complete projects that replace the entry point of a game? I found a project called SaltyLime by @XorTroll, but it seemed to be discontinued and I couldn't find any projects that used it.
3) Alternatively, are there any existing projects that use a game "as a library"?






