1
1
#include < shobjidl.h>
2
2
#include < fstream>
3
+ #include < sstream>
4
+ #include < spdlog/spdlog.h>
3
5
4
6
#include " patcher.h"
5
7
#include " utils.h"
6
- #include " logger.h"
7
8
8
- constexpr unsigned int FAIL_CANNOT_OPEN_FILE = 0x1001 ;
9
- constexpr unsigned int FAIL_CANNOT_READ_FILE = 0x1002 ;
10
- constexpr unsigned int FAIL_CANNOT_FIND_BYTE = 0x1003 ;
11
- constexpr unsigned int FAIL_CURRENT_PLATFORM_NO_PATCH = 0x1004 ;
12
- constexpr unsigned int FAIL_BACKUP = 0x1005 ;
9
+ constexpr unsigned int FAIL_CANNOT_OPEN_FILE = ( 0x1001 ) ;
10
+ constexpr unsigned int FAIL_CANNOT_READ_FILE = ( 0x1002 ) ;
11
+ constexpr unsigned int FAIL_CANNOT_FIND_BYTE = ( 0x1003 ) ;
12
+ constexpr unsigned int FAIL_CURRENT_PLATFORM_NO_PATCH = ( 0x1004 ) ;
13
+ constexpr unsigned int FAIL_BACKUP = ( 0x1005 ) ;
13
14
14
- #define VERSION " 1.1 .0"
15
+ #define VERSION " 1.2 .0"
15
16
16
17
int main (int argc, char *argv[]) {
17
18
18
19
// Welcome message.
19
20
20
- Info (" MCPatcher v{} OpenSource: github.com/Redbeanw44602/MCPatcher [MIT]" ,VERSION);
21
+ spdlog::set_pattern (" [%H:%M:%S.%e] [%^%l%$] %v" );
22
+ spdlog::info (" MCPatcher v{}, Repository: github.com/Redbeanw44602/MCPatcher [MIT]" , VERSION);
21
23
22
- // Add known patches ;
24
+ // Add known patch(es) ;
23
25
24
26
MCPatcher patcher;
25
27
26
- // PatchName *from* [PV(preview)|FM(formal)|BT(beta)][VERSION][-][FUNCTION ADDRESS]
27
-
28
- patcher.registerPatch (
29
- Platform::Win10,
30
- " PV1193025-1403A4F20" ,
31
- {
32
- {
33
- { 0x10 , 0x84 , 0xC0 , 0x74 , 0x15 , 0xB0 , /* O*/ 0x01 , 0x48 , 0x8B , 0x4C , 0x24 , 0x30 , 0x48 , 0x33 , 0xCC },
34
- { 0x10 , 0x84 , 0xC0 , 0x74 , 0x15 , 0xB0 , /* N*/ 0x00 , 0x48 , 0x8B , 0x4C , 0x24 , 0x30 , 0x48 , 0x33 , 0xCC }
35
- },
36
- {
37
- { 0x48 , 0x83 , 0xC3 , 0x10 , 0x48 , 0x3B , 0xDF , 0x75 , 0xEA , 0xB0 , /* O*/ 0x01 , 0x48 , 0x8B , 0x7C , 0x24 },
38
- { 0x48 , 0x83 , 0xC3 , 0x10 , 0x48 , 0x3B , 0xDF , 0x75 , 0xEA , 0xB0 , /* N*/ 0x00 , 0x48 , 0x8B , 0x7C , 0x24 }
39
- }
40
- }
41
- );
42
-
43
- patcher.registerPatch (
44
- Platform::Win10,
45
- " PV1198020-14124C910" ,
46
- {
47
- {
48
- { 0x0D , 0xB8 , 0x00 , 0xEB , 0x04 , 0x0F , 0xB6 , 0x42 , 0x10 , 0x84 , 0xC0 , 0x74 , 0x26 , 0xB0 , /* O*/ 0x01 , 0x48 },
49
- { 0x0D , 0xB8 , 0x00 , 0xEB , 0x04 , 0x0F , 0xB6 , 0x42 , 0x10 , 0x84 , 0xC0 , 0x74 , 0x26 , 0xB0 , /* N*/ 0x00 , 0x48 }
50
- }
51
- }
52
- );
28
+ auto generalPatch = MCPatcher::compile (
29
+ " 48 8B 42 08 48 8B 88 80 01 00 00 48 85 C9 74 07 E8 ?? ?? ?? 00 "
30
+ " EB 04 0F B6 42 10 84 C0 74 ?? B0 01(00) 48 8B 4C 24 ?? 48 33 CC" );
31
+
32
+ patcher.registerPatch (Platform::Win10, " General_Patch_V2" , generalPatch);
53
33
54
34
// Ask for binary file;
55
35
56
36
string strpath;
57
- if (argc == 1 )
58
- {
37
+ if (argc == 1 ) {
59
38
HRESULT result = CoInitializeEx (nullptr , COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
60
- if (SUCCEEDED (result))
61
- {
62
- Info (" Please open an executable for minecraft. (Minecraft.Windows.exe)" );
39
+ if (SUCCEEDED (result)) {
40
+ spdlog::info (" Please open an executable for minecraft. (Minecraft.Windows.exe)" );
63
41
IFileOpenDialog *openFile;
64
42
CoCreateInstance (CLSID_FileOpenDialog, nullptr , CLSCTX_ALL,
65
43
IID_IFileOpenDialog, reinterpret_cast <void **>(&openFile));
@@ -71,53 +49,40 @@ int main(int argc, char *argv[]) {
71
49
openFile->Show (nullptr );
72
50
IShellItem *pItem;
73
51
result = openFile->GetResult (&pItem);
74
- if (SUCCEEDED (result))
75
- {
52
+ if (SUCCEEDED (result)) {
76
53
PWSTR pPath;
77
54
pItem->GetDisplayName (SIGDN_FILESYSPATH, &pPath);
78
55
std::wstringstream path;
79
56
path << pPath;
80
57
strpath = wchar2string (path.str ().c_str ());
81
- Info (" Selected {}." ,strpath);
58
+ spdlog::info (" Selected {}." ,strpath);
82
59
pItem->Release ();
83
- }
84
- else
85
- {
86
- Error (" Open file failed!" );
60
+ } else {
61
+ spdlog::error (" Open file failed!" );
87
62
}
88
63
openFile->Release ();
89
64
CoUninitialize ();
90
65
}
91
66
if (strpath.empty ())
92
67
return FAIL_CANNOT_OPEN_FILE;
93
- }
94
- else if (argc == 2 )
95
- {
68
+ } else if (argc == 2 ) {
96
69
strpath = argv[1 ];
97
- }
98
- else
99
- {
100
- Error (" Wrong parameter!" );
70
+ } else {
71
+ spdlog::error (" Wrong parameter!" );
101
72
}
102
73
103
74
// Open file;
104
75
105
- if (!patcher.target (strpath))
106
- {
107
- Error (" Can't read executable file!" );
76
+ if (!patcher.target (strpath)) {
77
+ spdlog::error (" Can't read executable file!" );
108
78
return FAIL_CANNOT_READ_FILE;
109
- }
110
- else
111
- {
79
+ } else {
112
80
std::ofstream ofs (strpath + " .bak" , std::ios::binary);
113
81
ofs << patcher.getImage ().rdbuf ();
114
- if (ofs.good ())
115
- {
116
- Info (" Backup created to: {}.bak" ,strpath);
117
- }
118
- else
119
- {
120
- Error (" Fail to create backup!" );
82
+ if (ofs.good ()) {
83
+ spdlog::info (" Backup created to: {}.bak" ,strpath);
84
+ } else {
85
+ spdlog::error (" Fail to create backup!" );
121
86
return FAIL_BACKUP;
122
87
}
123
88
ofs.close ();
@@ -127,22 +92,18 @@ int main(int argc, char *argv[]) {
127
92
128
93
auto platform = Platform::Win10;
129
94
auto patches = patcher.getPatches (platform);
130
- if (patches.empty ())
131
- {
132
- Error (" There are no patches available for the current platform." );
95
+ if (patches.empty ()) {
96
+ spdlog::error (" There are no patches available for the current platform." );
133
97
return FAIL_CURRENT_PLATFORM_NO_PATCH;
134
98
}
135
99
136
100
// Do patch;
137
101
138
- Info (" Looking for bytes..." );
139
- if (patcher.apply (platform))
140
- {
141
- Info (" Patch successfully." );
142
- }
143
- else
144
- {
145
- Error (" Failed, if it is the latest version, please send issue." );
102
+ spdlog::info (" Looking for bytes..." );
103
+ if (patcher.apply (platform)) {
104
+ spdlog::info (" Patch successfully." );
105
+ } else {
106
+ spdlog::error (" Failed, if it is the latest version, please send issue." );
146
107
return FAIL_CANNOT_FIND_BYTE;
147
108
}
148
109
0 commit comments