@@ -290,26 +290,31 @@ void CheckAndCreateModFolder() {
290290 }
291291}
292292
293- void GameEngine::LoadResourceFiles () {
294- #ifndef __SWITCH__
293+ static void SetupScriptLoader (std::shared_ptr<Ship::Context> context) {
294+ #ifdef __SWITCH__
295+ return ;
296+ #endif
295297 constexpr int codeVersion = 1 ;
296- std::unordered_map<std::string, std::string> defines = { { " VERSION_US" , " 1" }, { " ENABLE_RUMBLE" , " 1" },
297- { " F3D_OLD" , " 1" }, { " F3D_GBI" , " 1" },
298- { " GBI_FLOATS" , " 1" }, { " _LANGUAGE_C" , " 1" },
299- { " _USE_MATH_DEFINES" , " 1" }, { " AVOID_UB" , " 1" } };
298+ const std::unordered_map<std::string, std::string> defines = {
299+ { " VERSION_US" , " 1" }, { " ENABLE_RUMBLE" , " 1" }, { " F3D_OLD" , " 1" }, { " F3D_GBI" , " 1" },
300+ { " GBI_FLOATS" , " 1" }, { " _LANGUAGE_C" , " 1" }, { " _USE_MATH_DEFINES" , " 1" }, { " AVOID_UB" , " 1" },
301+ };
302+
300303#ifdef _WIN32
301304 const std::string tccBase = Ship::Context::GetAppBundlePath () + " /.tcc" ;
302- std::vector<std::string> includePaths = {
305+ const std::vector<std::string> includePaths = {
303306 tccBase + " /include" , tccBase + " /include/tcc" , tccBase + " /include/winapi" ,
304307 tccBase + " /include/sys" , tccBase + " /include/sec_api" ,
305308 };
306- std::vector<std::string> libraryPaths = { tccBase + " /lib" };
309+ const std::vector<std::string> libraryPaths = { tccBase + " /lib" };
307310 context->InitScriptLoader (defines, codeVersion, " -g -rdynamic" , includePaths, libraryPaths, { " Ghostship" });
308- context->GetScriptLoader ()->SetCacheDir (Ship::Context::GetPathRelativeToAppDirectory (" mods_cache" ));
309311#else
310- std::vector<std::string> includePaths = {
311- Ship::Context::GetPathRelativeToAppDirectory (" .tcc/include" ),
312- };
312+ std::string tccBase = Ship::Context::GetPathRelativeToAppDirectory (" .tcc" );
313+ if (!std::filesystem::exists (tccBase)) {
314+ tccBase = Ship::Context::GetAppBundlePath () + " /.tcc" ;
315+ }
316+
317+ std::vector<std::string> includePaths = { tccBase + " /include" };
313318
314319#ifdef __APPLE__
315320 {
@@ -328,14 +333,17 @@ void GameEngine::LoadResourceFiles() {
328333 }
329334#endif
330335
331- std::vector<std::string> libraryPaths = {
332- Ship::Context::GetPathRelativeToAppDirectory (" .tcc/lib" ),
333- };
336+ const std::vector<std::string> libraryPaths = { tccBase + " /lib" };
334337 context->InitScriptLoader (defines, codeVersion, " -g -rdynamic" , includePaths, libraryPaths, {});
335- context->GetScriptLoader ()->SetCacheDir (Ship::Context::GetPathRelativeToAppDirectory (" mods_cache" ));
336338#endif
337339
338- #endif // __SWITCH__
340+ context->GetScriptLoader ()->SetCacheDir (Ship::Context::GetPathRelativeToAppDirectory (" mods_cache" ));
341+ }
342+
343+ void GameEngine::LoadResourceFiles () {
344+ SetupScriptLoader (context);
345+
346+ #ifndef __SWITCH__
339347
340348 std::string romPath = Ship::Context::LocateFileAcrossAppDirs (" sm64.o2r" , " sm64" );
341349 if (std::filesystem::exists (romPath)) {
@@ -386,6 +394,7 @@ void GameEngine::LoadResourceFiles() {
386394 this ->totalScripts ++;
387395#endif
388396 }
397+ #endif // __SWITCH__
389398}
390399
391400void GameEngine::FinishInit () {
@@ -395,50 +404,7 @@ void GameEngine::FinishInit() {
395404
396405 context->InitFileDropMgr ();
397406 context->InitCrashHandler ();
398- #ifndef __SWITCH__
399- constexpr int codeVersion = 1 ;
400- std::unordered_map<std::string, std::string> defines = { { " VERSION_US" , " 1" }, { " ENABLE_RUMBLE" , " 1" },
401- { " F3D_OLD" , " 1" }, { " F3D_GBI" , " 1" },
402- { " GBI_FLOATS" , " 1" }, { " _LANGUAGE_C" , " 1" },
403- { " _USE_MATH_DEFINES" , " 1" }, { " AVOID_UB" , " 1" } };
404- #ifdef _WIN32
405- const std::string tccBase = Ship::Context::GetAppBundlePath () + " /.tcc" ;
406- std::vector<std::string> includePaths = {
407- tccBase + " /include" , tccBase + " /include/tcc" , tccBase + " /include/winapi" ,
408- tccBase + " /include/sys" , tccBase + " /include/sec_api" ,
409- };
410- std::vector<std::string> libraryPaths = { tccBase + " /lib" };
411- context->InitScriptLoader (defines, codeVersion, " -g -rdynamic" , includePaths, libraryPaths, { " Ghostship" });
412- context->GetScriptLoader ()->SetCacheDir (Ship::Context::GetPathRelativeToAppDirectory (" mods_cache" ));
413- #else
414- std::vector<std::string> includePaths = {
415- Ship::Context::GetPathRelativeToAppDirectory (" .tcc/include" ),
416- };
417-
418- #ifdef __APPLE__
419- {
420- FILE * fp = popen (" xcrun --show-sdk-path 2>/dev/null" , " r" );
421- if (fp) {
422- char buf[4096 ] = {};
423- if (fgets (buf, sizeof (buf), fp)) {
424- std::string sdkPath (buf);
425- sdkPath.erase (sdkPath.find_last_not_of (" \n\r \t " ) + 1 );
426- if (!sdkPath.empty ()) {
427- includePaths.push_back (sdkPath + " /usr/include" );
428- }
429- }
430- pclose (fp);
431- }
432- }
433- #endif
434-
435- std::vector<std::string> libraryPaths = {
436- Ship::Context::GetPathRelativeToAppDirectory (" .tcc/lib" ),
437- };
438- context->InitScriptLoader (defines, codeVersion, " -g -rdynamic" , includePaths, libraryPaths, {});
439- context->GetScriptLoader ()->SetCacheDir (Ship::Context::GetPathRelativeToAppDirectory (" mods_cache" ));
440- #endif
441- #endif // __SWITCH__
407+ SetupScriptLoader (context);
442408
443409 this ->context ->InitAudio ({ .SampleRate = 32000 , .SampleLength = 512 , .DesiredBuffered = 1100 });
444410
@@ -603,8 +569,7 @@ void GameEngine::RunExtract(int argc, char* argv[]) {
603569 while (true ) {
604570#ifndef __SWITCH__
605571 auto satellaPhase = Satella::Client::Instance ().GetPhase ();
606- bool satellaActive = satellaPhase == Satella::Phase::Connecting ||
607- satellaPhase == Satella::Phase::FetchingKeys;
572+ bool satellaActive = satellaPhase == Satella::Phase::Connecting || satellaPhase == Satella::Phase::FetchingKeys;
608573#else
609574 bool satellaActive = false ;
610575#endif
@@ -983,9 +948,8 @@ void GameEngine::RunExtract(int argc, char* argv[]) {
983948 ImGuiWindowFlags_NoSavedSettings)) {
984949#ifndef __SWITCH__
985950 if (satellaActive) {
986- const char * msg = satellaPhase == Satella::Phase::Connecting
987- ? " Connecting to Satella..."
988- : " Retrieving public keys..." ;
951+ const char * msg = satellaPhase == Satella::Phase::Connecting ? " Connecting to Satella..."
952+ : " Retrieving public keys..." ;
989953 ImGui::Text (" %s" , msg);
990954 ImGui::ProgressBar (-1 .0f * (float )ImGui::GetTime (), ImVec2 (600 .0f , 20 .0f ), " " );
991955 if (totalScripts > 0 ) {
0 commit comments