Skip to content
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,32 @@ Update records:
- Initial organization of RawFileClass_Impl completed.
- Tested and confirmed to work correctly.

## Launch_Impl
#### 2025-10-16 IronHammer_Std
- 整理了CopyProtection部分的实现。

- Organized the implementation of CopyProtection.

## InitCheck_Impl
#### 2025-10-18 IronHammer_Std
- 整理了GetFreeDiskSpaceKB的实现。

- Organized the implementation of GetFreeDiskSpaceKB.

## Debug_Impl
#### 2025-10-17 IronHammer_Std
- 恢复了调试日志功能。

- Restored the debug logging functionality.
- Restored the debug logging functionality.
#### 2025-10-17 IronHammer_Std
- 更新文件操作为CRT的函数。

- Updated file operations to use CRT functions.

## WinMain_Impl
#### 2025-10-17 IronHammer_Std
- 替换为了WinMain_Aux以增强日志相关功能。
- 给出了WinMain的开头一小段的部分实现,并作为部分实现的样例。

- Replaced with WinMain_Aux to enhance logging-related features.
- Provided a small portion of the implementation at the beginning of WinMain as a sample of partial implementation.
32 changes: 29 additions & 3 deletions Patch/Debug.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#include "Debug.h"
#include <CRT.h>
#include <MessageListClass.h>
#include "../src/VanillaImpl.h"
#include "../src/Debug_Impl.h"

namespace Debug
{
void Log(const char* pFormat, ...)
{
JMP_STD(0x4068E0);
if constexpr (!UseVanillaImpl_Supplementary)
{
va_list args;
va_start(args, pFormat);
Debug_Impl::LogWithVArgs(pFormat, args);
va_end(args);
}
else
{
JMP_STD(0x4068E0);
}
}
void LogAndMessage(const char* pFormat, ...)
{
Expand All @@ -20,11 +32,25 @@ namespace Debug
}
void LogString(const char* pStr)
{
Log("%s", pStr);
if constexpr (!UseVanillaImpl_Supplementary)
{
Debug_Impl::LogString(pStr);
}
else
{
Log("%s", pStr);
}
}
void LogString(const std::string& Str)
{
Log("%s", Str.c_str());
if constexpr (!UseVanillaImpl_Supplementary)
{
Debug_Impl::LogString(Str.c_str());
}
else
{
Log("%s", Str.c_str());
}
}
void MessageString(const char* pStr)
{
Expand Down
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ YRDict 以函数为单位进行整理。
对单个类的实现,在YRpp当中记录下这个类的Type和具体内容,
同时,在实现当中以一个Type_Impl来容纳实现。

具体的书写方式,可以参照示例代码和src/ImplBase.h等。
函数的实现可以是完整的C++代码,也可以是IDA产出的伪代码。
无论如何,请确保最终的代码能够成功编译通过。
每个提交的函数按照ImplBase.h的约定标示是否可用。
例如(PENDING)_IMPLEMENT/(PENDING)_FUNCTION_IMPLEMENT等。
如果有任何不清楚的地方,欢迎提出Issue进行讨论。

YRDict is organized by functions. For each function,
its interface and memory address are documented in projects like YRpp.
Expand Down Expand Up @@ -66,6 +72,14 @@ For the implementation of a single class,
record the Type and specific content of this class in YRpp,
and at the same time, use a Type_Impl to contain the implementation.

Regarding the specific format, please see the example source files and src/ImplBase.h.
Implementations can be complete C++ code or IDA-generated pseudocode.
Anyway, make sure the final code can be built successfully.
Mark each function's status using the marker symbols defined in ImplBase.h
e.g., using (PENDING)_IMPLEMENT/(PENDING)_FUNCTION_IMPLEMENT.
For any questions, we welcome you to start a discussion by opening a new Issue.


## 使用/USAGE

把这个项目编译成DLL,或下载Release当中的DLL。
Expand All @@ -78,6 +92,7 @@ and at the same time, use a Type_Impl to contain the implementation.

当然,也可以仅仅拿来参考,或者用来作为自己扩展的基础。
这个项目的内容是开源的,遵循MIT许可证。
欢迎基于YRDict开发引擎扩展。


Compile this project into a DLL, or download the DLL from the Release page.
Expand All @@ -92,6 +107,7 @@ Loading it alongside other extensions may lead to unpredictable behavior.
Naturally, you are also free to use this project
solely for reference or as a foundation for your own extensions.
The content of this project is open source and follows the MIT license.
You are welcome to develop game engine extensions based on YRDict.

## 注意/NOTE

Expand All @@ -101,15 +117,17 @@ The content of this project is open source and follows the MIT license.

这个项目可以修正WW的原有BUG,但请注明WW原来是怎么写的。
如果有意愿的话,也可以标注出Ares/Phobos等钩了什么位置以及改变了什么。
不考虑提供任何的新增或增强逻辑。
允许也欢迎添加与调试等相关的辅助功能。
不考虑提供任何的新增玩法或增强的游戏内逻辑。
允许也欢迎添加与调试等相关的辅助功能和优化补丁。


所有源文件和说明文件应统一编码为 UTF8 带BOM格式。

所有人注意不要直接提交到main分支。
可以申请加入,并在dev分支上直接开发与提交;
也可以fork本项目,并在自己的分支当中添加内容。
以上两种方式都应通过Pull Request的方式合并到main分支。
注意只会合并通过所有自动检查的PR(如nightly build & changelog check)

Please note that this project does not aim to fully reverse engineer YR.
Instead, it focuses on documenting critical functions and implementations.
Expand All @@ -121,8 +139,10 @@ This project can fix the original bugs of WW,
but please indicate how WW was originally written.
If you are willing, you can also indicate what positions
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.
No new or enhanced in-game logic is considered.
Adding auxiliary features related to debugging and similar tasks
as well as simple optimization patches is allowed and encouraged.


All source files and documentation files
should be uniformly encoded in **UTF-8 with BOM** format.
Expand All @@ -131,6 +151,8 @@ 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.
Both methods should merge into the main branch via Pull Request.
Note that only PRs that pass all automated checks
(e.g., nightly build & changelog check) will be merged.

## 结语/CONCLUSION

Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 3 files
+4 −4 CCFileClass.h
+3 −1 CRT.h
+4 −0 Unsorted.h
52 changes: 44 additions & 8 deletions src/Debug_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "VanillaImpl.h"
#include <Debug.h>
#include <Unsorted.h>
#include <CRT.h>

namespace Debug_Impl
{
Expand Down Expand Up @@ -53,15 +54,15 @@ namespace Debug_Impl
MakeLogFile();
CloseLogFile(nullptr);

LogFile = _wfsopen(LogFilePath.c_str(), L"w", _SH_DENYWR);
LogFile = CRT::_fsopen(LogFilePath.string().c_str(), "w", _SH_DENYWR);
if (!LogFile) {
wchar_t msg[100] = L"\0";
LogFile = nullptr;
wsprintfW(msg, L"Log file failed to open. Error code = %X(%hs)", errno, strerror(errno));
MessageBoxW(Game::hWnd, LogFilePath.c_str(), msg, MB_OK | MB_ICONEXCLAMATION);
ExitProcess(1);
}
TempLogFile = _wfsopen(TempLogFilePath.c_str(), L"w", _SH_DENYWR);
TempLogFile = CRT::_fsopen(TempLogFilePath.string().c_str(), "w", _SH_DENYWR);
if (!TempLogFile) {
wchar_t msg[100] = L"\0";
TempLogFile = nullptr;
Expand All @@ -82,8 +83,8 @@ namespace Debug_Impl
Debug::LogString(CloseState);
else
Debug::LogString("YRDict : Closing Log File...\n");
fclose(LogFile);
fclose(TempLogFile);
CRT::fclose(LogFile);
CRT::fclose(TempLogFile);
LogFile = nullptr;
TempLogFile = nullptr;
}
Expand All @@ -96,8 +97,8 @@ namespace Debug_Impl
{
if (IsLogFileOpen())
{
fflush(LogFile);
fflush(TempLogFile);
CRT::fflush(LogFile);
CRT::fflush(TempLogFile);
}
}
}
Expand All @@ -106,8 +107,17 @@ namespace Debug_Impl
{
if constexpr (!UseVanillaImpl_Supplementary)
{
vfprintf(LogFile, pFormat, args);
vfprintf(TempLogFile, pFormat, args);
CRT::vfprintf(LogFile, pFormat, args);
CRT::vfprintf(TempLogFile, pFormat, args);
}
}

void LogUnflushed(const char* Str)
{
if constexpr (!UseVanillaImpl_Supplementary)
{
CRT::fprintf(LogFile, "%s", Str);
CRT::fprintf(TempLogFile, "%s", Str);
}
}

Expand All @@ -126,4 +136,30 @@ namespace Debug_Impl
FlushLogFile();
}
}

void LogWithVArgs(const char* pFormat, va_list args)
{
if constexpr (!UseVanillaImpl_Supplementary)
{
if (!IsLogFileOpen())
OpenLogFile();

LogWithVArgsUnflushed(pFormat, args);

FlushLogFile();
}
}

void LogString(const char* Str)
{
if constexpr (!UseVanillaImpl_Supplementary)
{
if (!IsLogFileOpen())
OpenLogFile();

LogUnflushed(Str);

FlushLogFile();
}
}
}
4 changes: 4 additions & 0 deletions src/Debug_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ namespace Debug_Impl
void CloseLogFile(const char* CloseState);
void FlushLogFile();
void LogWithVArgsUnflushed(const char* pFormat, va_list args);
void LogUnflushed(const char* Str);

void __cdecl Log(const char* pFormat, ...);
FUNCTION_IMPLEMENT(0x4A4AC0, Log);
FUNCTION_IMPLEMENT(0x4068E0, Log);

void LogWithVArgs(const char* pFormat, va_list args);
void LogString(const char* Str);
}
2 changes: 1 addition & 1 deletion src/FileClass_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ DEFINE_VIRTUAL_IMPL(RawFileClass, 0x7F0904u)
void Close();
DWORD GetFileTime();
bool SetFileTime(DWORD FileTime);
void CDCheck(DWORD ErrorCode, bool bUnk, const char* FileName) {}
void CDCheck(DWORD ErrorCode, bool canRetry, const char* FileName) {}

//Non-virtual Function Implements
void Bias(int offset = 0, int length = -1);
Expand Down
21 changes: 18 additions & 3 deletions src/ImplBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ See details in FileClass_Impl.h
#define DEFINE_IMPLEMENT \
inline static void Implement()

/*

什么也不会干,标记此处在完成实现之后应该换成IMPLEMENT
Does nothing; marks this location to be replaced with IMPLEMENT after the implementation is complete.

*/
#define PENDING_IMPLEMENT(Addr, Method)

/*

Expand Down Expand Up @@ -287,7 +294,7 @@ See details in FileClass_Impl.h

/*

为普通函数生成实现补丁,放在函数的实现后面。
为非成员函数生成实现补丁,放在函数的实现后面。
Generate Implementation Patch for Non-member Functions.
For use after the function's implementation.

Expand All @@ -300,8 +307,16 @@ See details in Launch_Impl.h

/*

为尚未实现的函数生成跳转到原函数的补丁,放在函数的声明后面。
Generate Jump-to-Original Patch for Not-Yet-Implemented Functions.
什么也不会干,标记此处在完成实现之后应该换成FUNCTION_IMPLEMENT
Does nothing; marks this location to be replaced with FUNCTION_IMPLEMENT after the implementation is complete.

*/
#define PENDING_FUNCTION_IMPLEMENT(Addr, Func)

/*

为尚未实现的非成员函数生成跳转到原函数的补丁,放在函数的声明后面。
Generate Jump-to-Original Patch for Not-Yet-Implemented Non-member Functions.
For use after the function's declaration.

详见示例 Launch_Impl.h
Expand Down
Loading
Loading