Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ Update records:
- 缁忔祴璇曡兘澶熸甯稿伐浣溿��

- Initial organization of RawFileClass_Impl completed.
- Tested and confirmed to work correctly.
- Tested and confirmed to work correctly.

## Debug_Impl
#### 2025-10-17 IronHammer_Std
- 鎭㈠浜嗚皟璇曟棩蹇楀姛鑳姐��

- Restored the debug logging functionality.
22 changes: 13 additions & 9 deletions Patch/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Windows.h>
#include <string>
#include <format>
#include <string_view>

namespace Debug
{
Expand All @@ -14,27 +15,30 @@ namespace Debug
void LogAndMessageString(const char* pStr);
void LogAndMessageString(const std::string& Str);

void LogFormat(const std::string& fmt, auto&&... args) {
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
template <class... _Types>
inline void LogFormat(const std::format_string<_Types...> fmt, _Types&&... args) {
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
LogString(msg);
}
void LogVFormat(const std::string& fmt, std::format_args args) {
inline void LogVFormat(std::string_view fmt, std::format_args args) {
std::string msg = std::vformat(fmt, args);
LogString(msg);
}
void MessageFormat(const std::string& fmt, auto&&... args) {
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
template <class... _Types>
inline void MessageFormat(const std::format_string<_Types...> fmt, _Types&&... args) {
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
MessageString(msg);
}
void MessageVFormat(const std::string& fmt, std::format_args args) {
inline void MessageVFormat(const std::string& fmt, std::format_args args) {
std::string msg = std::vformat(fmt, args);
MessageString(msg);
}
void LogFormatAndMessage(const std::string& fmt, auto&&... args) {
std::string msg = std::format(fmt, std::forward<decltype(args)>(args)...);
template <class... _Types>
inline void LogFormatAndMessage(const std::format_string<_Types...> fmt, _Types&&... args) {
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
LogAndMessageString(msg);
}
void LogVFormatAndMessage(const std::string& fmt, std::format_args args) {
inline void LogVFormatAndMessage(const std::string& fmt, std::format_args args) {
std::string msg = std::vformat(fmt, args);
LogAndMessageString(msg);
}
Expand Down
14 changes: 7 additions & 7 deletions Patch/DynamicPatch.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "DynamicPatch.h"
锘�#include "DynamicPatch.h"
#include <imagehlp.h>
#include <cstring>

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

// 节区扫描工具
// 鑺傚尯鎵弿宸ュ叿
bool LocateExecutableSection(const char* sectionName, SectionInfo* result)
{
HMODULE moduleBase = GetModuleHandle(nullptr);
Expand Down Expand Up @@ -44,7 +44,7 @@ bool LocateExecutableSection(const char* sectionName, SectionInfo* result)
return false;
}

// 执行所有存储的补丁
// 鎵ц鎵�鏈夊瓨鍌ㄧ殑琛ヤ竵
void CodeModifier::ExecuteAllStored()
{
SectionInfo section;
Expand All @@ -59,22 +59,22 @@ void CodeModifier::ExecuteAllStored()
{
const CodeModifier* modifier = reinterpret_cast<const CodeModifier*>(current);

// 终止条件:空偏移量
// 缁堟鏉′欢锛氱┖鍋忕Щ閲�
if (modifier->m_targetOffset == 0) {
break;
}

// 验证数据有效性
// 楠岃瘉鏁版嵁鏈夋晥鎬�
if (modifier->m_dataSize > 0 && modifier->m_patchData != nullptr) {
modifier->Execute();
}

// 移动到下一个补丁
// 绉诲姩鍒颁笅涓�涓ˉ涓�
current += sizeof(CodeModifier);
}
}

// 跳转和调用补丁实现
// 璺宠浆鍜岃皟鐢ㄨˉ涓佸疄鐜�
void CodeModifier::InsertFarJump(DWORD offset, DWORD target)
{
FarJumpInstruction instruction(offset, target);
Expand Down
56 changes: 28 additions & 28 deletions Patch/DynamicPatch.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once
锘�#pragma once
#include <windows.h>
#include <initializer_list>
#include <cstring>
#include <memory>

// 使用更独特的节区名称,避免冲突
// 浣跨敤鏇寸嫭鐗圭殑鑺傚尯鍚嶇О锛岄伩鍏嶅啿绐�
#define CODE_PATCH_SECTION ".codepatch"
#pragma section(CODE_PATCH_SECTION, read, execute)

// 指令结构体
// 鎸囦护缁撴瀯浣�
#pragma pack(push, 1)
struct FarJumpInstruction
{
BYTE opcode; // 0xE9 for near jump, 0xEA for far jump
DWORD offset; // 跳转偏移量
DWORD offset; // 璺宠浆鍋忕Щ閲�

FarJumpInstruction(DWORD from, DWORD to)
{
Expand All @@ -25,7 +25,7 @@ struct FarJumpInstruction
struct NearCallInstruction
{
BYTE opcode; // 0xE8
DWORD offset; // 调用偏移量
DWORD offset; // 璋冪敤鍋忕Щ閲�

NearCallInstruction(DWORD from, DWORD to)
{
Expand All @@ -36,18 +36,18 @@ struct NearCallInstruction

struct ExtendedCallInstruction
{
WORD prefix; // 特殊调用前缀
DWORD offset; // 调用偏移量
WORD prefix; // 鐗规畩璋冪敤鍓嶇紑
DWORD offset; // 璋冪敤鍋忕Щ閲�

ExtendedCallInstruction(DWORD from, DWORD to)
{
prefix = 0x15FF; // FF15 操作码
prefix = 0x15FF; // FF15 鎿嶄綔鐮�
offset = to;
}
};
#pragma pack(pop)

// 内存保护封装类
// 鍐呭瓨淇濇姢灏佽绫�
class MemoryGuard
{
private:
Expand All @@ -73,19 +73,19 @@ class MemoryGuard
}
}

// 禁用复制
// 绂佺敤澶嶅埗
MemoryGuard(const MemoryGuard&) = delete;
MemoryGuard& operator=(const MemoryGuard&) = delete;
};

// 节区信息结构
// 鑺傚尯淇℃伅缁撴瀯
struct SectionInfo
{
void* virtualAddress;
size_t virtualSize;
};

// 主补丁类
// 涓昏ˉ涓佺被
#pragma pack(push, 1)
class CodeModifier
{
Expand All @@ -95,14 +95,14 @@ class CodeModifier
const BYTE* m_patchData;

public:
// 默认构造函数
// 榛樿鏋勯�犲嚱鏁�
CodeModifier() : m_targetOffset(0), m_dataSize(0), m_patchData(nullptr) {}

// 参数化构造函数
// 鍙傛暟鍖栨瀯閫犲嚱鏁�
CodeModifier(DWORD offset, DWORD size, const BYTE* data)
: m_targetOffset(offset), m_dataSize(size), m_patchData(data) {}

// 应用补丁到内存
// 搴旂敤琛ヤ竵鍒板唴瀛�
void Execute() const
{
if (m_targetOffset == 0 || m_dataSize == 0 || m_patchData == nullptr) {
Expand All @@ -111,17 +111,17 @@ class CodeModifier

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

// 使用RAII模式管理内存保护
// 浣跨敤RAII妯″紡绠$悊鍐呭瓨淇濇姢
MemoryGuard guard(targetAddress, m_dataSize);

// 安全地复制数据
// 瀹夊叏鍦板鍒舵暟鎹�
std::memcpy(targetAddress, m_patchData, m_dataSize);
}

// 静态方法集
// 闈欐�佹柟娉曢泦
static void ExecuteAllStored();

// 类型化数据补丁
// 绫诲瀷鍖栨暟鎹ˉ涓�
template <typename DataType>
static void ModifyWithData(DWORD offset, std::initializer_list<DataType> dataPattern)
{
Expand All @@ -133,49 +133,49 @@ class CodeModifier
modifier.Execute();
}

// 原始字节补丁(数组版本)
// 鍘熷瀛楄妭琛ヤ竵锛堟暟缁勭増鏈級
template <size_t ArraySize>
static void ModifyRawBytes(DWORD offset, const BYTE(&byteArray)[ArraySize])
{
CodeModifier modifier(offset, static_cast<DWORD>(ArraySize), byteArray);
modifier.Execute();
}

// 原始字节补丁(初始化列表版本)
// 鍘熷瀛楄妭琛ヤ竵锛堝垵濮嬪寲鍒楄〃鐗堟湰锛�
static void ModifyRawBytes(DWORD offset, std::initializer_list<BYTE> byteData)
{
ModifyWithData<BYTE>(offset, byteData);
}

// 原始字节补丁(指针+长度版本)
// 鍘熷瀛楄妭琛ヤ竵锛堟寚閽�+闀垮害鐗堟湰锛�
static void ModifyRawBytes(DWORD offset, const BYTE* dataPtr, size_t dataLength)
{
CodeModifier modifier(offset, static_cast<DWORD>(dataLength), dataPtr);
modifier.Execute();
}

// 远跳转补丁
// 杩滆烦杞ˉ涓�
static void InsertFarJump(DWORD offset, DWORD jumpTarget);
static void InsertFarJump(DWORD offset, void* jumpTarget)
{
InsertFarJump(offset, reinterpret_cast<DWORD>(jumpTarget));
}

// 近调用补丁
// 杩戣皟鐢ㄨˉ涓�
static void InsertNearCall(DWORD offset, DWORD callTarget);
static void InsertNearCall(DWORD offset, void* callTarget)
{
InsertNearCall(offset, reinterpret_cast<DWORD>(callTarget));
}

// 6字节调用补丁(特殊格式)
// 6瀛楄妭璋冪敤琛ヤ竵锛堢壒娈婃牸寮忥級
static void InsertExtendedCall(DWORD offset, DWORD callTarget);
static void InsertExtendedCall(DWORD offset, void* callTarget)
{
InsertExtendedCall(offset, reinterpret_cast<DWORD>(callTarget));
}

// 虚函数表修补
// 铏氬嚱鏁拌〃淇ˉ
static void UpdateVTableEntry(DWORD vtableOffset, DWORD newFunction);
static void UpdateVTableEntry(DWORD vtableOffset, void* newFunction)
{
Expand All @@ -200,7 +200,7 @@ class CodeModifier
UpdateVTableEntry(vtableOffset, GetMemberFunctionAddress(memberFunc));
}

// 偏移量修补(别名)
// 鍋忕Щ閲忎慨琛ワ紙鍒悕锛�
static void ModifyPointer(DWORD offset, DWORD newValue)
{
UpdateVTableEntry(offset, newValue);
Expand All @@ -212,5 +212,5 @@ class CodeModifier
};
#pragma pack(pop)

// 节区扫描函数声明
// 鑺傚尯鎵弿鍑芥暟澹版槑
bool LocateExecutableSection(const char* sectionName, SectionInfo* result);
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ The content of this project is open source and follows the MIT license.
涓嶈�冭檻鎻愪緵浠讳綍鐨勬柊澧炴垨澧炲己閫昏緫銆�
鍏佽涔熸杩庢坊鍔犱笌璋冭瘯绛夌浉鍏崇殑杈呭姪鍔熻兘銆�

鎵�鏈夋簮鏂囦欢鍜岃鏄庢枃浠跺簲缁熶竴缂栫爜涓� UTF8 甯OM鏍煎紡銆�

鎵�鏈変汉娉ㄦ剰涓嶈鐩存帴鎻愪氦鍒癿ain鍒嗘敮銆�
鍙互鐢宠鍔犲叆锛屽苟鍦╠ev鍒嗘敮涓婄洿鎺ュ紑鍙戜笌鎻愪氦锛�
涔熷彲浠ork鏈」鐩紝骞跺湪鑷繁鐨勫垎鏀綋涓坊鍔犲唴瀹广��
浠ヤ笂涓ょ鏂瑰紡閮藉簲閫氳繃Pull Request鐨勬柟寮忓悎骞跺埌main鍒嗘敮銆�


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

All source files and documentation files
should be uniformly encoded in **UTF-8 with BOM** format.

Everyone, please avoid committing directly to the main branch.
You can apply to join and develop and commit directly on the dev branch;
or you can fork this project and add content in your own branch.
Expand Down
11 changes: 11 additions & 0 deletions YRDict.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@
<ItemGroup>
<ClInclude Include="Patch\Debug.h" />
<ClInclude Include="Patch\DynamicPatch.h" />
<ClInclude Include="src\Debug_Impl.h" />
<ClInclude Include="src\FileClass_Impl.h" />
<ClInclude Include="src\ImplBase.h" />
<ClInclude Include="src\InitBase.h" />
<ClInclude Include="src\Launch_Impl.h" />
<ClInclude Include="src\VanillaImpl.h" />
<ClInclude Include="src\Version.h" />
<ClInclude Include="src\WinMain_Impl.h" />
<ClInclude Include="YRpp\AbstractClass.h" />
<ClInclude Include="YRpp\AbstractTypeClass.h" />
<ClInclude Include="YRpp\AircraftClass.h" />
Expand Down Expand Up @@ -230,6 +235,7 @@
<ClInclude Include="YRpp\ControlClass.h" />
<ClInclude Include="YRpp\Conversions.h" />
<ClInclude Include="YRpp\ConvertClass.h" />
<ClInclude Include="YRpp\CopyProtection.h" />
<ClInclude Include="YRpp\CRC.h" />
<ClInclude Include="YRpp\CRT.h" />
<ClInclude Include="YRpp\Dir.h" />
Expand Down Expand Up @@ -364,6 +370,7 @@
<ClInclude Include="YRpp\Surface.h" />
<ClInclude Include="YRpp\SwizzleManagerClass.h" />
<ClInclude Include="YRpp\Syringe.h" />
<ClInclude Include="YRpp\SystemData.h" />
<ClInclude Include="YRpp\TacticalClass.h" />
<ClInclude Include="YRpp\TActionClass.h" />
<ClInclude Include="YRpp\TagClass.h" />
Expand Down Expand Up @@ -399,6 +406,7 @@
<ClInclude Include="YRpp\Unsorted.h" />
<ClInclude Include="YRpp\Vault.h" />
<ClInclude Include="YRpp\VeinholeMonsterClass.h" />
<ClInclude Include="YRpp\VersionClass.h" />
<ClInclude Include="YRpp\VocClass.h" />
<ClInclude Include="YRpp\VoxClass.h" />
<ClInclude Include="YRpp\VoxelAnimClass.h" />
Expand All @@ -424,10 +432,13 @@
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="Patch\Debug.cpp" />
<ClCompile Include="Patch\DynamicPatch.cpp" />
<ClCompile Include="src\Debug_Impl.cpp" />
<ClCompile Include="src\FileClass_Impl.cpp" />
<ClCompile Include="src\CopyProtection.cpp" />
<ClCompile Include="src\Launch_Impl.cpp" />
<ClCompile Include="src\RawFileClass_Impl.cpp" />
<ClCompile Include="src\VersionMark.cpp" />
<ClCompile Include="src\WinMain_Impl.cpp" />
<ClCompile Include="YRpp\StaticInits.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 5 files
+10 −2 CRT.h
+22 −0 CopyProtection.h
+3 −3 SessionClass.h
+33 −0 SystemData.h
+155 −0 VersionClass.h
Loading
Loading