Skip to content

Commit 0b71c3c

Browse files
authored
Add new launch flag ("binary-dir") & Change the path for loading mods (#1439)
* change loading libraries to use getBinaryPath & add new launch flag * move to LoaderImpl
1 parent 26c612f commit 0b71c3c

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

loader/src/loader/LoaderImpl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ Result<> Loader::Impl::setup() {
9999
}
100100
}
101101

102+
if (auto value = this->getLaunchArgument("binary-dir")) {
103+
log::info("Using custom binary directory: {}", value.value());
104+
m_binaryPath = value.value();
105+
}
106+
102107
if (this->getLaunchFlag("enable-tulip-hook-logs")) {
103108
log::info("Enabling TulipHook logs");
104109
tulip::hook::setLogCallback([](std::string_view msg) {
@@ -1299,4 +1304,8 @@ bool Loader::Impl::isRestartRequired() const {
12991304

13001305
bool Loader::Impl::isPatchless() const {
13011306
return m_isPatchless;
1302-
}
1307+
}
1308+
1309+
std::optional<std::string> Loader::Impl::getBinaryPath() const {
1310+
return m_binaryPath;
1311+
}

loader/src/loader/LoaderImpl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace geode {
7171
std::unordered_map<void*, std::pair<tulip::hook::HandlerHandle, size_t>> m_handlerHandles;
7272

7373
bool m_isPatchless = false;
74+
std::optional<std::string> m_binaryPath;
7475

7576
Result<tulip::hook::HandlerHandle> getHandler(void* address);
7677
Result<tulip::hook::HandlerHandle> getOrCreateHandler(void* address, tulip::hook::HandlerMetadata const& metadata);
@@ -156,6 +157,7 @@ namespace geode {
156157
bool isRestartRequired() const;
157158

158159
bool isPatchless() const;
160+
std::optional<std::string> getBinaryPath() const;
159161
};
160162

161163
class LoaderImpl : public Loader::Impl {

loader/src/loader/ModImpl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ std::filesystem::path Mod::Impl::getTempDir() const {
133133
}
134134

135135
std::filesystem::path Mod::Impl::getBinaryPath() const {
136+
if (auto value = LoaderImpl::get()->getBinaryPath()) {
137+
return std::filesystem::path(value.value()) / m_metadata.getBinaryName();
138+
}
136139
return m_tempDirName / m_metadata.getBinaryName();
137140
}
138141

loader/src/platform/android/ModImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ T findSymbolOrMangled(void* so, char const* name, char const* mangled) {
1616

1717
Result<> Mod::Impl::loadPlatformBinary() {
1818
auto so =
19-
dlopen((m_tempDirName / m_metadata.getBinaryName()).string().c_str(), RTLD_LAZY);
19+
dlopen(this->getBinaryPath().string().c_str(), RTLD_LAZY);
2020
if (so) {
2121
if (m_platformInfo) {
2222
delete m_platformInfo;

loader/src/platform/ios/ModImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ T findSymbolOrMangled(void* dylib, char const* name, char const* mangled) {
1717

1818
Result<> Mod::Impl::loadPlatformBinary() {
1919
auto dylib =
20-
dlopen((m_tempDirName / m_metadata.getBinaryName()).string().c_str(), RTLD_LAZY);
20+
dlopen(this->getBinaryPath().string().c_str(), RTLD_LAZY);
2121
if (dylib) {
2222
if (m_platformInfo) {
2323
delete m_platformInfo;

loader/src/platform/mac/ModImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ T findSymbolOrMangled(void* dylib, char const* name, char const* mangled) {
1717

1818
Result<> Mod::Impl::loadPlatformBinary() {
1919
auto dylib =
20-
dlopen((m_tempDirName / m_metadata.getBinaryName()).string().c_str(), RTLD_LAZY);
20+
dlopen(this->getBinaryPath().string().c_str(), RTLD_LAZY);
2121
if (dylib) {
2222
if (m_platformInfo) {
2323
delete m_platformInfo;

loader/src/platform/windows/ModImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::string getLastWinError() {
5454
}
5555

5656
Result<> Mod::Impl::loadPlatformBinary() {
57-
auto load = LoadLibraryW((m_tempDirName / m_metadata.getBinaryName()).wstring().c_str());
57+
auto load = LoadLibraryW(this->getBinaryPath().wstring().c_str());
5858
if (load) {
5959
if (m_platformInfo) {
6060
delete m_platformInfo;

0 commit comments

Comments
 (0)