Skip to content
This repository was archived by the owner on Mar 11, 2023. It is now read-only.

Commit 41a8e7b

Browse files
committed
[Gardening] Fix up code smell, unused headers, and resolve warnings
1 parent 100c507 commit 41a8e7b

File tree

7 files changed

+45
-116
lines changed

7 files changed

+45
-116
lines changed

Client/.idea/workspace.xml

+2-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ClientInjector/include/macOS/injector.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ class MacOSInjector: public Injector {
1212
public:
1313

1414
MacOSInjector() = default;
15-
bool inject(argparse::ArgumentParser parser, int pid) final;
16-
int getLunarPID(argparse::ArgumentParser parser) final;
1715

18-
//private:
19-
// kern_return_t injectToTask(mach_port_t task, string dllpath);
20-
// kern_return_t getThreadPortForTask(mach_port_t task, mach_port_t *thread);
16+
bool inject(const argparse::ArgumentParser& parser, int pid) final;
17+
18+
int getLunarPID(const argparse::ArgumentParser& parser) final;
19+
2120
};
2221

2322
#endif //CEROCLIENT_MINJECTOR_H

ClientInjector/include/macOS/remoteExec/remoteExec.h

-33
This file was deleted.

ClientInjector/include/shared/injector.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212

1313
class Injector {
1414
public:
15-
virtual bool inject(argparse::ArgumentParser parser, int pid) = 0;
16-
virtual int getLunarPID(argparse::ArgumentParser parser) = 0;
17-
string getDLLPath(argparse::ArgumentParser parser);
15+
16+
Injector() = default;
17+
virtual ~Injector() = default;
18+
19+
virtual bool inject(const argparse::ArgumentParser& parser, int pid) = 0;
20+
21+
virtual int getLunarPID(const argparse::ArgumentParser& parser) = 0;
22+
23+
static string getDLLPath(const argparse::ArgumentParser& parser);
24+
1825
};
1926

2027
#endif //CEROCLIENT_INJECTOR_H

ClientInjector/include/windows/injector.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99

1010
class WindowsInjector: public Injector {
1111
public:
12+
1213
WindowsInjector() = default;
13-
bool inject(argparse::ArgumentParser parser, int pid) final;
14-
int getLunarPID(argparse::ArgumentParser parser) final;
14+
virtual ~WindowsInjector() = default;
15+
16+
bool inject(const argparse::ArgumentParser& parser, int pid) final;
17+
18+
int getLunarPID(const argparse::ArgumentParser& parser) final;
19+
1520
};
1621

1722
#endif //CEROCLIENT_WINJECTOR_H

ClientInjector/src/macOS/injector.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
#include <macOS/injector.h>
99
#include <macOS/mip-mini/inject.h>
10-
#include <macOS/remoteExec/remoteExec.h>
1110

1211
string exec(const string& cmd);
13-
vector<string> split(string phrase, const string& delimiter);
12+
vector<string> split(string phrase, string_view delimiter);
1413

15-
bool MacOSInjector::inject(argparse::ArgumentParser parser, int pid) {
14+
bool MacOSInjector::inject(const argparse::ArgumentParser& parser, int pid) {
1615

1716
string dllPath = getDLLPath(parser);
1817
mach_port_t task;
@@ -34,7 +33,7 @@ bool MacOSInjector::inject(argparse::ArgumentParser parser, int pid) {
3433
return !ret;
3534
}
3635

37-
int MacOSInjector::getLunarPID(argparse::ArgumentParser parser) {
36+
int MacOSInjector::getLunarPID(const argparse::ArgumentParser& parser) {
3837
string output = exec("ps aux | grep optifine");
3938
vector<string> newList;
4039
double versionIDX = 0.0;
@@ -81,16 +80,16 @@ string exec(const string& cmd) {
8180
array<char, 128> buffer {};
8281
string result;
8382
unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
84-
if (!pipe) {
83+
if (!pipe)
8584
throw std::runtime_error("popen() failed!");
86-
}
85+
8786
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
8887
result += buffer.data();
8988
}
9089
return result;
9190
}
9291

93-
vector<string> split(string phrase, const string& delimiter) {
92+
vector<string> split(string phrase, string_view delimiter) {
9493
vector<string> list;
9594
size_t pos = 0;
9695
string token;

ClientInjector/src/shared/Injector.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
//
44

55
#include <shared/injector.h>
6+
#include "macOS/injector.h"
67

7-
string Injector::getDLLPath(argparse::ArgumentParser parser) {
8+
9+
string Injector::getDLLPath(const argparse::ArgumentParser& parser) {
810

911
// The injector binary needs a couple resources to be in certain places.
1012
// This is what the local structure needs to look like:
@@ -21,40 +23,44 @@ string Injector::getDLLPath(argparse::ArgumentParser parser) {
2123
// Resources is copied to ~/.ceroclient/resources so that libClientLoader.dylib
2224
// knows where to look for Client.jar.
2325

24-
auto currentPath = (string)current_path();
26+
path currentPath = current_path();
2527

2628
// ensure ./Resources
27-
auto localResourcePath = currentPath + path_sep + HOMEDIR_RESOURCES_NAME;
29+
path localResourcePath = currentPath / HOMEDIR_RESOURCES_NAME;
2830
if (!exists(localResourcePath)) {
2931
cerr << "Resource path missing from current path." << endl << parser << endl;
3032
exit(1);
3133
}
3234

3335
// Ensure ./Resources/libClientLoader.ext
34-
auto libClientLoaderPath = localResourcePath + path_sep + RESOURCE_CLIENTLOADER_NAME + DYNAMIC_EXT;
35-
if (!exists(libClientLoaderPath)) {
36+
if (
37+
path libClientLoaderPath = localResourcePath / ((string)RESOURCE_CLIENTLOADER_NAME + DYNAMIC_EXT);
38+
!exists(libClientLoaderPath)
39+
) {
3640
cerr << "Missing libClientLoader." << endl << parser << endl;
3741
exit(1);
3842
}
3943

4044
// Ensure ./Resources/Client.jar
41-
auto clientPath = localResourcePath + path_sep + RESOURCE_CLIENTJAR_NAME + ".jar";
42-
if (!exists(clientPath)) {
45+
if (
46+
auto clientPath = localResourcePath / ((string)RESOURCE_CLIENTJAR_NAME + ".jar");
47+
!exists(clientPath)
48+
) {
4349
cerr << "Missing client jar." << endl << parser << endl;
4450
exit(1);
4551
}
4652

47-
auto homePath = getHomePath();
53+
filesystem::path homePath = getHomePath();
4854
Ensure(homePath);
4955
permissions(homePath, perms::all);
5056

5157
// NOTE: Only do this for debug builds
52-
auto homeResourcePath = homePath + path_sep + HOMEDIR_RESOURCES_NAME;
58+
auto homeResourcePath = homePath / HOMEDIR_RESOURCES_NAME;
5359

5460
using namespace filesystem;
5561
auto options = copy_options::overwrite_existing | copy_options::recursive;
5662
copy(localResourcePath.c_str(), homeResourcePath, options); // Weird build glitch when both paths are same type
5763
permissions(localResourcePath, perms::all);
58-
return homeResourcePath + path_sep + RESOURCE_CLIENTLOADER_NAME + DYNAMIC_EXT;
64+
return homeResourcePath / ((string)RESOURCE_CLIENTLOADER_NAME + DYNAMIC_EXT);
5965

6066
}

0 commit comments

Comments
 (0)