-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzmod_exe.cpp
100 lines (85 loc) · 2.66 KB
/
zmod_exe.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <Windows.h>
#include <map>
#include <filesystem>
#include <fstream>
#include "detours.h"
#include "zmod_common.cpp"
std::string get_appid(std::filesystem::path dir)
{
std::map<std::wstring, std::string> appids = {
{L"steamapps\\common\\Dynasty Warriors 8", "278080"},
{L"steamapps\\common\\WARRIORS OROCHI 4", "831560"},
};
auto d = dir.wstring();
for (const auto &[installdir, appid] : appids)
{
if (d.find(installdir) != std::string::npos)
{
return appid;
}
}
return "";
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
zmod::ini ini = {{{L"zmod", L"target"}, L"Launch.exe"}}; // default values
auto app_path = zmod::get_module_path(NULL);
auto ini_path = app_path.replace_filename(L"zmod.ini");
auto dll_32_path = app_path.replace_filename(L"zmod_32.dll");
auto dll_64_path = app_path.replace_filename(L"zmod_64.dll");
auto dll_default = dll_32_path;
if (!(zmod::file_exists(dll_32_path)))
{
dll_default = dll_64_path;
if (!(zmod::file_exists(dll_64_path)))
{
MessageBoxW(NULL, (std::wstring(L"Missing file: ") + dll_32_path.wstring()).c_str(), L"zmod", MB_OK);
MessageBoxW(NULL, (std::wstring(L"Missing file: ") + dll_64_path.wstring()).c_str(), L"zmod", MB_OK);
return 1;
}
}
if (zmod::file_exists(ini_path))
{
zmod::read_ini_file(ini_path, ini);
}
else
{
zmod::write_ini_file(ini_path, ini);
}
auto target = std::filesystem::current_path() / ini[{L"zmod", L"target"}];
if (!(zmod::file_exists(target)))
{
MessageBoxW(NULL, (std::wstring(L"Missing file: ") + target.wstring()).c_str(), L"zmod", MB_OK);
return 1;
}
auto steam_appid = target.parent_path() / L"steam_appid.txt";
if (!(zmod::file_exists(steam_appid)))
{
auto appid = get_appid(target.parent_path());
if (!(appid.empty()))
{
std::ofstream(steam_appid) << appid;
}
}
STARTUPINFOW si{.cb = sizeof(si)};
PROCESS_INFORMATION pi{};
auto result = DetourCreateProcessWithDllExW(
target.wstring().c_str(),
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
target.parent_path().wstring().c_str(),
&si,
&pi,
dll_default.string().c_str(),
NULL);
if (!(result))
{
MessageBoxW(NULL, L"Failed to launch target!", L"zmod", MB_OK);
return 1;
}
return 0;
}