Skip to content

Commit a6ceee5

Browse files
committed
we don't need a singleton here
1 parent f2697cf commit a6ceee5

4 files changed

Lines changed: 29 additions & 41 deletions

File tree

app/src/main/cpp/base.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@
77

88
class DataPaths {
99
public:
10-
std::string original_data_path{};
11-
std::string data_path{};
12-
std::string load_symbols_from{};
10+
static std::string original_data_path;
11+
static std::string data_path;
1312

14-
bool patch_exceptions{};
15-
16-
static DataPaths& get_instance();
17-
18-
private:
19-
DataPaths() {}
13+
static bool patch_exceptions;
2014
};
2115

2216
// this is every function that i thought would be relevant

app/src/main/cpp/launcher-fix.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include "base.h"
55
#include "log.hpp"
66

7-
DataPaths& DataPaths::get_instance() {
8-
static auto paths_instance = DataPaths();
9-
return paths_instance;
10-
}
7+
std::string DataPaths::original_data_path{};
8+
std::string DataPaths::data_path{};
9+
10+
bool DataPaths::patch_exceptions{};
1111

1212
extern "C"
1313
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
@@ -18,25 +18,11 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setDataPath(
1818
auto is_copy = jboolean();
1919
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
2020

21-
DataPaths::get_instance().data_path = std::string(data_path_str);
21+
DataPaths::data_path = std::string(data_path_str);
2222

2323
env->ReleaseStringUTFChars(data_path, data_path_str);
2424
}
2525

26-
extern "C"
27-
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableCustomSymbolList(
28-
JNIEnv* env,
29-
jobject,
30-
jstring symbol_path
31-
) {
32-
auto is_copy = jboolean();
33-
auto symbol_path_str = env->GetStringUTFChars(symbol_path, &is_copy);
34-
35-
DataPaths::get_instance().load_symbols_from = std::string(symbol_path_str);
36-
37-
env->ReleaseStringUTFChars(symbol_path, symbol_path_str);
38-
}
39-
4026
extern "C"
4127
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
4228
JNIEnv *env,
@@ -46,14 +32,14 @@ JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_setOriginalDataPath(
4632
auto is_copy = jboolean();
4733
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
4834

49-
DataPaths::get_instance().original_data_path = std::string(data_path_str);
35+
DataPaths::original_data_path = std::string(data_path_str);
5036

5137
env->ReleaseStringUTFChars(data_path, data_path_str);
5238
}
5339

5440
extern "C"
5541
JNIEXPORT void JNICALL Java_com_geode_launcher_LauncherFix_enableExceptionsRenaming(JNIEnv*, jobject) {
56-
DataPaths::get_instance().patch_exceptions = true;
42+
DataPaths::patch_exceptions = true;
5743
}
5844

5945
// 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
6248
}
6349

6450
std::optional<std::string> redirect_path(const char* pathname) {
65-
std::string_view data_path = DataPaths::get_instance().data_path;
66-
std::string_view original_data_path = DataPaths::get_instance().original_data_path;
67-
68-
if (!data_path.empty() && !original_data_path.empty()) {
69-
// call this a c string optimization
70-
if (std::strncmp(pathname, original_data_path.data(), original_data_path.size()) == 0) {
71-
return std::format("{}{}", data_path, (pathname + original_data_path.size()));
72-
}
51+
std::string_view data_path = DataPaths::data_path;
52+
std::string_view original_data_path = DataPaths::original_data_path;
53+
54+
if (data_path.empty() || original_data_path.empty()) [[unlikely]] {
55+
return std::nullopt;
56+
}
57+
58+
// call this a c string optimization
59+
if (std::strncmp(pathname, original_data_path.data(), original_data_path.size()) == 0) {
60+
auto remaining_path = (pathname + original_data_path.size());
61+
auto remaining_len = strlen(remaining_path);
62+
63+
std::string x;
64+
x.reserve(data_path.size() + remaining_len);
65+
x.append(data_path);
66+
x.append(remaining_path, remaining_len);
67+
68+
return x;
7369
}
7470

7571
return std::nullopt;

app/src/main/cpp/patcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ int on_dl_iterate(dl_phdr_info* info, size_t size, void* data) {
277277
failed = true;
278278
}
279279

280-
if (DataPaths::get_instance().patch_exceptions) {
280+
if (DataPaths::patch_exceptions) {
281281
if (!perform_symbol_patches(info, state)) {
282282
failed = true;
283283
}

app/src/main/java/com/geode/launcher/LauncherFix.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ object LauncherFix {
1616
external fun enableExceptionsRenaming()
1717

1818
external fun performPatches()
19-
20-
external fun enableCustomSymbolList(symbolsPath: String)
2119
}

0 commit comments

Comments
 (0)