Skip to content

Commit 5798c6a

Browse files
Merge pull request #5 from Everything-Compatible/dev
Dev
2 parents df751b1 + c0c3608 commit 5798c6a

19 files changed

+906
-55
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ Update records:
4040
- 经测试能够正常工作。
4141

4242
- Initial organization of RawFileClass_Impl completed.
43-
- Tested and confirmed to work correctly.
43+
- Tested and confirmed to work correctly.
44+
45+
## Debug_Impl
46+
#### 2025-10-17 IronHammer_Std
47+
- 恢复了调试日志功能。
48+
49+
- Restored the debug logging functionality.

Patch/Debug.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Windows.h>
33
#include <string>
44
#include <format>
5+
#include <string_view>
56

67
namespace Debug
78
{
@@ -14,27 +15,30 @@ namespace Debug
1415
void LogAndMessageString(const char* pStr);
1516
void LogAndMessageString(const std::string& Str);
1617

17-
void LogFormat(const std::string& fmt, auto&&... args) {
18-
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
18+
template <class... _Types>
19+
inline void LogFormat(const std::format_string<_Types...> fmt, _Types&&... args) {
20+
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
1921
LogString(msg);
2022
}
21-
void LogVFormat(const std::string& fmt, std::format_args args) {
23+
inline void LogVFormat(std::string_view fmt, std::format_args args) {
2224
std::string msg = std::vformat(fmt, args);
2325
LogString(msg);
2426
}
25-
void MessageFormat(const std::string& fmt, auto&&... args) {
26-
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
27+
template <class... _Types>
28+
inline void MessageFormat(const std::format_string<_Types...> fmt, _Types&&... args) {
29+
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
2730
MessageString(msg);
2831
}
29-
void MessageVFormat(const std::string& fmt, std::format_args args) {
32+
inline void MessageVFormat(const std::string& fmt, std::format_args args) {
3033
std::string msg = std::vformat(fmt, args);
3134
MessageString(msg);
3235
}
33-
void LogFormatAndMessage(const std::string& fmt, auto&&... args) {
34-
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
36+
template <class... _Types>
37+
inline void LogFormatAndMessage(const std::format_string<_Types...> fmt, _Types&&... args) {
38+
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
3539
LogAndMessageString(msg);
3640
}
37-
void LogVFormatAndMessage(const std::string& fmt, std::format_args args) {
41+
inline void LogVFormatAndMessage(const std::string& fmt, std::format_args args) {
3842
std::string msg = std::vformat(fmt, args);
3943
LogAndMessageString(msg);
4044
}

Patch/DynamicPatch.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "DynamicPatch.h"
1+
#include "DynamicPatch.h"
22
#include <imagehlp.h>
33
#include <cstring>
44

55
#pragma comment(lib, "imagehlp.lib")
66

7-
// 节区扫描工具
7+
// 节区扫描工具
88
bool LocateExecutableSection(const char* sectionName, SectionInfo* result)
99
{
1010
HMODULE moduleBase = GetModuleHandle(nullptr);
@@ -44,7 +44,7 @@ bool LocateExecutableSection(const char* sectionName, SectionInfo* result)
4444
return false;
4545
}
4646

47-
// 执行所有存储的补丁
47+
// 执行所有存储的补丁
4848
void CodeModifier::ExecuteAllStored()
4949
{
5050
SectionInfo section;
@@ -59,22 +59,22 @@ void CodeModifier::ExecuteAllStored()
5959
{
6060
const CodeModifier* modifier = reinterpret_cast<const CodeModifier*>(current);
6161

62-
// 终止条件:空偏移量
62+
// 终止条件:空偏移量
6363
if (modifier->m_targetOffset == 0) {
6464
break;
6565
}
6666

67-
// 验证数据有效性
67+
// 验证数据有效性
6868
if (modifier->m_dataSize > 0 && modifier->m_patchData != nullptr) {
6969
modifier->Execute();
7070
}
7171

72-
// 移动到下一个补丁
72+
// 移动到下一个补丁
7373
current += sizeof(CodeModifier);
7474
}
7575
}
7676

77-
// 跳转和调用补丁实现
77+
// 跳转和调用补丁实现
7878
void CodeModifier::InsertFarJump(DWORD offset, DWORD target)
7979
{
8080
FarJumpInstruction instruction(offset, target);

Patch/DynamicPatch.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#pragma once
1+
#pragma once
22
#include <windows.h>
33
#include <initializer_list>
44
#include <cstring>
55
#include <memory>
66

7-
// 使用更独特的节区名称,避免冲突
7+
// 使用更独特的节区名称,避免冲突
88
#define CODE_PATCH_SECTION ".codepatch"
99
#pragma section(CODE_PATCH_SECTION, read, execute)
1010

11-
// 指令结构体
11+
// 指令结构体
1212
#pragma pack(push, 1)
1313
struct FarJumpInstruction
1414
{
1515
BYTE opcode; // 0xE9 for near jump, 0xEA for far jump
16-
DWORD offset; // 跳转偏移量
16+
DWORD offset; // 跳转偏移量
1717

1818
FarJumpInstruction(DWORD from, DWORD to)
1919
{
@@ -25,7 +25,7 @@ struct FarJumpInstruction
2525
struct NearCallInstruction
2626
{
2727
BYTE opcode; // 0xE8
28-
DWORD offset; // 调用偏移量
28+
DWORD offset; // 调用偏移量
2929

3030
NearCallInstruction(DWORD from, DWORD to)
3131
{
@@ -36,18 +36,18 @@ struct NearCallInstruction
3636

3737
struct ExtendedCallInstruction
3838
{
39-
WORD prefix; // 特殊调用前缀
40-
DWORD offset; // 调用偏移量
39+
WORD prefix; // 特殊调用前缀
40+
DWORD offset; // 调用偏移量
4141

4242
ExtendedCallInstruction(DWORD from, DWORD to)
4343
{
44-
prefix = 0x15FF; // FF15 操作码
44+
prefix = 0x15FF; // FF15 操作码
4545
offset = to;
4646
}
4747
};
4848
#pragma pack(pop)
4949

50-
// 内存保护封装类
50+
// 内存保护封装类
5151
class MemoryGuard
5252
{
5353
private:
@@ -73,19 +73,19 @@ class MemoryGuard
7373
}
7474
}
7575

76-
// 禁用复制
76+
// 禁用复制
7777
MemoryGuard(const MemoryGuard&) = delete;
7878
MemoryGuard& operator=(const MemoryGuard&) = delete;
7979
};
8080

81-
// 节区信息结构
81+
// 节区信息结构
8282
struct SectionInfo
8383
{
8484
void* virtualAddress;
8585
size_t virtualSize;
8686
};
8787

88-
// 主补丁类
88+
// 主补丁类
8989
#pragma pack(push, 1)
9090
class CodeModifier
9191
{
@@ -95,14 +95,14 @@ class CodeModifier
9595
const BYTE* m_patchData;
9696

9797
public:
98-
// 默认构造函数
98+
// 默认构造函数
9999
CodeModifier() : m_targetOffset(0), m_dataSize(0), m_patchData(nullptr) {}
100100

101-
// 参数化构造函数
101+
// 参数化构造函数
102102
CodeModifier(DWORD offset, DWORD size, const BYTE* data)
103103
: m_targetOffset(offset), m_dataSize(size), m_patchData(data) {}
104104

105-
// 应用补丁到内存
105+
// 应用补丁到内存
106106
void Execute() const
107107
{
108108
if (m_targetOffset == 0 || m_dataSize == 0 || m_patchData == nullptr) {
@@ -111,17 +111,17 @@ class CodeModifier
111111

112112
void* targetAddress = reinterpret_cast<void*>(m_targetOffset);
113113

114-
// 使用RAII模式管理内存保护
114+
// 使用RAII模式管理内存保护
115115
MemoryGuard guard(targetAddress, m_dataSize);
116116

117-
// 安全地复制数据
117+
// 安全地复制数据
118118
std::memcpy(targetAddress, m_patchData, m_dataSize);
119119
}
120120

121-
// 静态方法集
121+
// 静态方法集
122122
static void ExecuteAllStored();
123123

124-
// 类型化数据补丁
124+
// 类型化数据补丁
125125
template <typename DataType>
126126
static void ModifyWithData(DWORD offset, std::initializer_list<DataType> dataPattern)
127127
{
@@ -133,49 +133,49 @@ class CodeModifier
133133
modifier.Execute();
134134
}
135135

136-
// 原始字节补丁(数组版本)
136+
// 原始字节补丁(数组版本)
137137
template <size_t ArraySize>
138138
static void ModifyRawBytes(DWORD offset, const BYTE(&byteArray)[ArraySize])
139139
{
140140
CodeModifier modifier(offset, static_cast<DWORD>(ArraySize), byteArray);
141141
modifier.Execute();
142142
}
143143

144-
// 原始字节补丁(初始化列表版本)
144+
// 原始字节补丁(初始化列表版本)
145145
static void ModifyRawBytes(DWORD offset, std::initializer_list<BYTE> byteData)
146146
{
147147
ModifyWithData<BYTE>(offset, byteData);
148148
}
149149

150-
// 原始字节补丁(指针+长度版本)
150+
// 原始字节补丁(指针+长度版本)
151151
static void ModifyRawBytes(DWORD offset, const BYTE* dataPtr, size_t dataLength)
152152
{
153153
CodeModifier modifier(offset, static_cast<DWORD>(dataLength), dataPtr);
154154
modifier.Execute();
155155
}
156156

157-
// 远跳转补丁
157+
// 远跳转补丁
158158
static void InsertFarJump(DWORD offset, DWORD jumpTarget);
159159
static void InsertFarJump(DWORD offset, void* jumpTarget)
160160
{
161161
InsertFarJump(offset, reinterpret_cast<DWORD>(jumpTarget));
162162
}
163163

164-
// 近调用补丁
164+
// 近调用补丁
165165
static void InsertNearCall(DWORD offset, DWORD callTarget);
166166
static void InsertNearCall(DWORD offset, void* callTarget)
167167
{
168168
InsertNearCall(offset, reinterpret_cast<DWORD>(callTarget));
169169
}
170170

171-
// 6字节调用补丁(特殊格式)
171+
// 6字节调用补丁(特殊格式)
172172
static void InsertExtendedCall(DWORD offset, DWORD callTarget);
173173
static void InsertExtendedCall(DWORD offset, void* callTarget)
174174
{
175175
InsertExtendedCall(offset, reinterpret_cast<DWORD>(callTarget));
176176
}
177177

178-
// 虚函数表修补
178+
// 虚函数表修补
179179
static void UpdateVTableEntry(DWORD vtableOffset, DWORD newFunction);
180180
static void UpdateVTableEntry(DWORD vtableOffset, void* newFunction)
181181
{
@@ -200,7 +200,7 @@ class CodeModifier
200200
UpdateVTableEntry(vtableOffset, GetMemberFunctionAddress(memberFunc));
201201
}
202202

203-
// 偏移量修补(别名)
203+
// 偏移量修补(别名)
204204
static void ModifyPointer(DWORD offset, DWORD newValue)
205205
{
206206
UpdateVTableEntry(offset, newValue);
@@ -212,5 +212,5 @@ class CodeModifier
212212
};
213213
#pragma pack(pop)
214214

215-
// 节区扫描函数声明
215+
// 节区扫描函数声明
216216
bool LocateExecutableSection(const char* sectionName, SectionInfo* result);

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ The content of this project is open source and follows the MIT license.
104104
不考虑提供任何的新增或增强逻辑。
105105
允许也欢迎添加与调试等相关的辅助功能。
106106

107+
所有源文件和说明文件应统一编码为 UTF8 带BOM格式。
108+
107109
所有人注意不要直接提交到main分支。
108110
可以申请加入,并在dev分支上直接开发与提交;
109111
也可以fork本项目,并在自己的分支当中添加内容。
110112
以上两种方式都应通过Pull Request的方式合并到main分支。
111113

112-
113114
Please note that this project does not aim to fully reverse engineer YR.
114115
Instead, it focuses on documenting critical functions and implementations.
115116
If you are interested, you can try to supplement more functions.
@@ -123,6 +124,9 @@ Ares/Phobos, etc. hooked and what changes they made.
123124
No new or enhanced logic is considered.
124125
Adding auxiliary features related to debugging and similar tasks is allowed and encouraged.
125126

127+
All source files and documentation files
128+
should be uniformly encoded in **UTF-8 with BOM** format.
129+
126130
Everyone, please avoid committing directly to the main branch.
127131
You can apply to join and develop and commit directly on the dev branch;
128132
or you can fork this project and add content in your own branch.

YRDict.vcxproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@
8989
<ItemGroup>
9090
<ClInclude Include="Patch\Debug.h" />
9191
<ClInclude Include="Patch\DynamicPatch.h" />
92+
<ClInclude Include="src\Debug_Impl.h" />
9293
<ClInclude Include="src\FileClass_Impl.h" />
9394
<ClInclude Include="src\ImplBase.h" />
95+
<ClInclude Include="src\InitBase.h" />
96+
<ClInclude Include="src\Launch_Impl.h" />
97+
<ClInclude Include="src\VanillaImpl.h" />
9498
<ClInclude Include="src\Version.h" />
99+
<ClInclude Include="src\WinMain_Impl.h" />
95100
<ClInclude Include="YRpp\AbstractClass.h" />
96101
<ClInclude Include="YRpp\AbstractTypeClass.h" />
97102
<ClInclude Include="YRpp\AircraftClass.h" />
@@ -230,6 +235,7 @@
230235
<ClInclude Include="YRpp\ControlClass.h" />
231236
<ClInclude Include="YRpp\Conversions.h" />
232237
<ClInclude Include="YRpp\ConvertClass.h" />
238+
<ClInclude Include="YRpp\CopyProtection.h" />
233239
<ClInclude Include="YRpp\CRC.h" />
234240
<ClInclude Include="YRpp\CRT.h" />
235241
<ClInclude Include="YRpp\Dir.h" />
@@ -364,6 +370,7 @@
364370
<ClInclude Include="YRpp\Surface.h" />
365371
<ClInclude Include="YRpp\SwizzleManagerClass.h" />
366372
<ClInclude Include="YRpp\Syringe.h" />
373+
<ClInclude Include="YRpp\SystemData.h" />
367374
<ClInclude Include="YRpp\TacticalClass.h" />
368375
<ClInclude Include="YRpp\TActionClass.h" />
369376
<ClInclude Include="YRpp\TagClass.h" />
@@ -399,6 +406,7 @@
399406
<ClInclude Include="YRpp\Unsorted.h" />
400407
<ClInclude Include="YRpp\Vault.h" />
401408
<ClInclude Include="YRpp\VeinholeMonsterClass.h" />
409+
<ClInclude Include="YRpp\VersionClass.h" />
402410
<ClInclude Include="YRpp\VocClass.h" />
403411
<ClInclude Include="YRpp\VoxClass.h" />
404412
<ClInclude Include="YRpp\VoxelAnimClass.h" />
@@ -424,10 +432,13 @@
424432
<ClCompile Include="dllmain.cpp" />
425433
<ClCompile Include="Patch\Debug.cpp" />
426434
<ClCompile Include="Patch\DynamicPatch.cpp" />
435+
<ClCompile Include="src\Debug_Impl.cpp" />
427436
<ClCompile Include="src\FileClass_Impl.cpp" />
428437
<ClCompile Include="src\CopyProtection.cpp" />
438+
<ClCompile Include="src\Launch_Impl.cpp" />
429439
<ClCompile Include="src\RawFileClass_Impl.cpp" />
430440
<ClCompile Include="src\VersionMark.cpp" />
441+
<ClCompile Include="src\WinMain_Impl.cpp" />
431442
<ClCompile Include="YRpp\StaticInits.cpp" />
432443
</ItemGroup>
433444
<ItemGroup>

0 commit comments

Comments
 (0)