we don't need a singleton here

This commit is contained in:
Chloe committed 2026-02-25 23:41:27 -07:00
1 parent f2697cfb3b
commit a6ceee55d8
4 files changed
+28 -40

No files matched your search

+3 -9
View File
@@ -7,16 +7,10 @@
class DataPaths {
public:
std::string original_data_path{};
std::string data_path{};
std::string load_symbols_from{};
static std::string original_data_path;
static std::string data_path;
bool patch_exceptions{};
static DataPaths& get_instance();
private:
DataPaths() {}
static bool patch_exceptions;
};
// this is every function that i thought would be relevant
+24 -28
View File
@@ -4,10 +4,10 @@
#include "base.h"
#include "log.hpp"
DataPaths& DataPaths::get_instance() {
static auto paths_instance = DataPaths();
return paths_instance;
}
std::string DataPaths::original_data_path{};
std::string DataPaths::data_path{};
bool DataPaths::patch_exceptions{};
extern "C"
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
@@ -18,25 +18,11 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().data_path = std::string(data_path_str);
DataPaths::data_path = std::string(data_path_str);
env->ReleaseStringUTFChars(data_path, data_path_str);
}
extern "C"
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableCustomSymbolList(
JNIEnv* env,
jobject,
jstring symbol_path
) {
auto is_copy = jboolean();
auto symbol_path_str = env->GetStringUTFChars(symbol_path, &is_copy);
DataPaths::get_instance().load_symbols_from = std::string(symbol_path_str);
env->ReleaseStringUTFChars(symbol_path, symbol_path_str);
}
extern "C"
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
JNIEnv *env,
@@ -46,14 +32,14 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().original_data_path = std::string(data_path_str);
DataPaths::original_data_path = std::string(data_path_str);
env->ReleaseStringUTFChars(data_path, data_path_str);
}
extern "C"
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableExceptionsRenaming(JNIEnv*, jobject) {
DataPaths::get_instance().patch_exceptions = true;
DataPaths::patch_exceptions = true;
}
// this should be called after gd is loaded but before geode
@@ -62,14 +48,24 @@ extern "C" JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_performPat
}
std::optional<std::string> redirect_path(const char* pathname) {
std::string_view data_path = DataPaths::get_instance().data_path;
std::string_view original_data_path = DataPaths::get_instance().original_data_path;
std::string_view data_path = DataPaths::data_path;
std::string_view original_data_path = DataPaths::original_data_path;
if (!data_path.empty() && !original_data_path.empty()) {
// call this a c string optimization
if (std::strncmp(pathname, original_data_path.data(), original_data_path.size()) == 0) {
return std::format("{}{}", data_path, (pathname + original_data_path.size()));
}
if (data_path.empty() || original_data_path.empty()) [[unlikely]] {
return std::nullopt;
}
// call this a c string optimization
if (std::strncmp(pathname, original_data_path.data(), original_data_path.size()) == 0) {
auto remaining_path = (pathname + original_data_path.size());
auto remaining_len = strlen(remaining_path);
std::string x;
x.reserve(data_path.size() + remaining_len);
x.append(data_path);
x.append(remaining_path, remaining_len);
return x;
}
return std::nullopt;
+1 -1
View File
@@ -277,7 +277,7 @@ int on_dl_iterate(dl_phdr_info* info, size_t size, void* data) {
failed = true;
}
if (DataPaths::get_instance().patch_exceptions) {
if (DataPaths::patch_exceptions) {
if (!perform_symbol_patches(info, state)) {
failed = true;
}
@@ -16,6 +16,4 @@ object LauncherFix {
external fun enableExceptionsRenaming()
external fun performPatches()
external fun enableCustomSymbolList(symbolsPath: String)
}