summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalkierian <malkierian@gmail.com>2025-10-09 16:51:04 -0700
committerGitHub <noreply@github.com>2025-10-09 16:51:04 -0700
commit52a8f6c2810df518dc853edefdacb829cf1863dd (patch)
treea4c1327eccceb8eac9bd4efed0777a8c436240dd
parent57c368aa2c7ecb2c7d85f1f52ea7c0ea7d5c2d69 (diff)
Program Execution Argument Extraction (#5807)
* Add function to be able to feed specific path into to process programmatically, and setup drag and drop functionality. * Encapsulate dropped file functionality from Switch and Wii U. * Fix dropped file detection, and fix ShowYesNowBox return checking.
-rw-r--r--soh/soh/Extractor/Extract.cpp28
-rw-r--r--soh/soh/Extractor/Extract.h1
-rw-r--r--soh/soh/GbiWrap.cpp2
-rw-r--r--soh/soh/OTRGlobals.cpp27
-rw-r--r--soh/soh/OTRGlobals.h2
-rw-r--r--soh/src/code/main.c7
6 files changed, 60 insertions, 7 deletions
diff --git a/soh/soh/Extractor/Extract.cpp b/soh/soh/Extractor/Extract.cpp
index fecf9b741..558a3f74d 100644
--- a/soh/soh/Extractor/Extract.cpp
+++ b/soh/soh/Extractor/Extract.cpp
@@ -453,6 +453,34 @@ bool Extractor::ManuallySearchForRomMatchingType(RomSearchMode searchMode) {
return true;
}
+bool Extractor::RunFileStandalone(std::string rom) {
+ if (std::filesystem::is_directory(rom)) {
+ return false;
+ }
+ auto file = std::filesystem::path(rom);
+ if ((file.extension() != ".n64") && (file.extension() != ".z64") && (file.extension() != ".v64")) {
+ return false;
+ }
+ SetRomInfo(rom);
+
+ if (!ValidateRomSize()) {
+ return false;
+ }
+ std::ifstream inFile;
+
+ inFile.open(rom, std::ios::in | std::ios::binary);
+ inFile.read((char*)mRomData.get(), mCurRomSize);
+ inFile.clear();
+ inFile.close();
+ BitConverter::RomToBigEndian(mRomData.get(), mCurRomSize);
+
+ if (!ValidateRom(true)) {
+ return false;
+ }
+
+ return true;
+}
+
bool Extractor::Run(std::string searchPath, RomSearchMode searchMode) {
std::vector<std::string> roms;
std::ifstream inFile;
diff --git a/soh/soh/Extractor/Extract.h b/soh/soh/Extractor/Extract.h
index ae4fa740a..691233aba 100644
--- a/soh/soh/Extractor/Extract.h
+++ b/soh/soh/Extractor/Extract.h
@@ -59,6 +59,7 @@ class Extractor {
static void ShowErrorBox(const char* title, const char* text);
bool IsMasterQuest() const;
+ bool RunFileStandalone(std::string file);
bool Run(std::string searchPath, RomSearchMode searchMode = RomSearchMode::Both);
bool CallZapd(std::string installPath, std::string exportdir);
const char* GetZapdStr();
diff --git a/soh/soh/GbiWrap.cpp b/soh/soh/GbiWrap.cpp
index 0a26e9b18..1773c69c5 100644
--- a/soh/soh/GbiWrap.cpp
+++ b/soh/soh/GbiWrap.cpp
@@ -3,7 +3,7 @@
// OTRTODO - this is awful
extern "C" {
-void InitOTR();
+void InitOTR(int argc, char* argv[]);
void Graph_ProcessFrame(void (*run_one_game_iter)(void));
void Graph_StartFrame();
void Graph_ProcessGfxCommands(Gfx* commands);
diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp
index 3358d8585..342808e89 100644
--- a/soh/soh/OTRGlobals.cpp
+++ b/soh/soh/OTRGlobals.cpp
@@ -1121,7 +1121,32 @@ void CheckAndCreateModFolder() {
}
}
-extern "C" void InitOTR() {
+extern "C" void InitOTR(int argc, char* argv[]) {
+#if !defined(__SWITCH__) && !defined(__WIIU__)
+ if (argc > 1) {
+ for (int i = 1; i < argc; i++) {
+ std::string installPath = Ship::Context::GetAppBundlePath();
+ Extractor extract;
+ if (extract.RunFileStandalone(argv[i])) {
+ bool doExtract = true;
+ std::string archive = (extract.IsMasterQuest() ? "oot-mq.o2r" : "oot.o2r");
+ if (std::filesystem::exists(Ship::Context::GetAppBundlePath() + "/" + archive)) {
+ std::string msg = "Archive for current ROM, " + archive + ", already exists. Extract again?";
+ doExtract = extract.ShowYesNoBox("Confirm Re-extract", msg.c_str()) == IDYES;
+ }
+ if (doExtract) {
+ extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName));
+ }
+ } else {
+ std::string msg = "File " + std::string(argv[i]) + " is not a ROM or does not match supported ROMs.";
+ extract.ShowErrorBox("Incompatible File", msg.c_str());
+ }
+ }
+ if (Extractor::ShowYesNoBox("Run Ship of Harkinian", "All files have been processed. Run SoH?") != IDYES) {
+ exit(0);
+ }
+ }
+#endif
OTRGlobals::Instance = new OTRGlobals();
#ifdef __SWITCH__
Ship::Switch::Init(Ship::PreInitPhase);
diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h
index b653e9edf..c7c5702a0 100644
--- a/soh/soh/OTRGlobals.h
+++ b/soh/soh/OTRGlobals.h
@@ -87,7 +87,7 @@ class OTRGlobals {
#endif
#ifndef __cplusplus
-void InitOTR(void);
+void InitOTR(int argc, char* argv[]);
void DeinitOTR(void);
void VanillaItemTable_Init();
void OTRAudio_Init();
diff --git a/soh/src/code/main.c b/soh/src/code/main.c
index 769ecc026..558b30d2f 100644
--- a/soh/src/code/main.c
+++ b/soh/src/code/main.c
@@ -45,7 +45,7 @@ void Main_LogSystemHeap(void) {
}
#ifdef _WIN32
-int SDL_main(int argc, char** argv) {
+int SDL_main(int argc, char* argv[]) {
AllocConsole();
(void)freopen("CONIN$", "r", stdin);
(void)freopen("CONOUT$", "w", stdout);
@@ -57,11 +57,10 @@ int SDL_main(int argc, char** argv) {
setlocale(LC_ALL, ".UTF8");
#else //_WIN32
-int main(int argc, char** argv) {
+int main(int argc, char* argv[]) {
#endif
-
GameConsole_Init();
- InitOTR();
+ InitOTR(argc, argv);
// TODO: Was moved to below InitOTR because it requires window to be setup. But will be late to catch crashes.
CrashHandlerRegisterCallback(CrashHandler_PrintSohData);
BootCommands_Init();