mirror: 上游快照导入

This commit is contained in:
gitea committed 2026-11-30 09:52:42 +08:00
commit ffa771803e
2 files changed
+603

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
# Widescreen Patch for [BlackMythWuKong]
## Overview
This project provides a widescreen patch for [BlackMythWuKong], allowing players to enjoy the game in a 32:9 aspect ratio. The original idea for this patch comes from the Bilibili content creator [conglin3](https://space.bilibili.com/543249142)
## Features
- Uses memory patching to modify the game process, eliminating the need for file modifications.
- No impact on normal game operation.
- Automatically launches and adjusts the game to widescreen mode.
- Precisely locates the data that needs to be modified for widescreen, requiring only a single memory modification.
## How to Use
1. Run the program directly. It will launch the game and attempt to adjust it to widescreen mode.
2. If the game doesn't switch to widescreen immediately, go to the in-game settings -> Display and change the aspect ratio to 21:9. (It will comes 32:9)
3. Currently, the program can automatically launch games from Steam. For games from other sources:
- Run the program first.
- When prompted that the game cannot be found, manually launch the game yourself, then the program will modify the game process shortly
## Note
This program currently supports automatic launching only for Steam-sourced games. For games from other platforms or standalone installations, manual game launch is required after running this patcher.
## Credits
Original idea by [conglin3](https://space.bilibili.com/543249142) on Bilibili.
Program and in memory patcher : MJ0011 of Kunlun Lab
## Disclaimer
This software is for educational purposes only. Please ensure you have the right to modify and use the game in this manner. The authors are not responsible for any misuse or potential violations of terms of service.
## Contributing
Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.
## License
This project is licensed under the MIT License
# 黑神话:悟空 超宽屏补丁
## 概述
本项目为《黑神话:悟空》提供了一个超宽屏补丁,让玩家能够以 32:9 的宽高比享受游戏。这个补丁的原始想法来自哔哩哔哩UP主 [conglin3](https://space.bilibili.com/543249142)。
## 特点
- 使用内存补丁修改游戏进程,无需修改文件。
- 对正常游戏运行无影响。
- 自动启动游戏并调整为超宽屏模式。
- 精确定位需要修改的超宽屏数据,仅需进行一次内存修改。
## 使用方法
1. 直接运行程序。它将启动游戏并尝试调整为超宽屏模式。
2. 如果游戏没有立即切换到超宽屏,请进入游戏内设置 -> 显示,并将宽高比更改为 21:9。(实际效果将会是 32:9)
3. 目前,程序可以自动启动 Steam 来源的游戏。对于其他来源的游戏:
- 首先运行程序。
- 当提示找不到游戏时,手动启动游戏,然后程序将很快修改游戏进程。
## 注意
本程序目前仅支持自动启动 Steam 来源的游戏。对于其他平台或独立安装的游戏,需要在运行此补丁程序后手动启动游戏。
## 致谢
原始想法来自哔哩哔哩UP主 [conglin3](https://space.bilibili.com/543249142)。
程序和内存补丁:昆仑实验室的 MJ0011
## 免责声明
本软件仅用于教育目的。请确保您有权以这种方式修改和使用游戏。作者不对任何滥用或可能违反服务条款的行为负责。
## 贡献
欢迎贡献、提出问题和功能请求。如果您想贡献,请查看 [问题页面]
## 许可证
本项目采用 MIT 许可证+
+519
View File
@@ -0,0 +1,519 @@
#include <iostream>
#include "windows.h"
#include "shlwapi.h"
#include "tlhelp32.h"
#pragma comment(lib ,"shlwapi.lib")
#include <string>
#include <psapi.h>
// Windows内部结构定义
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, * PUNICODE_STRING;
typedef struct _PEB_LDR_DATA {
ULONG Length;
BOOLEAN Initialized;
HANDLE SsHandle;
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
PVOID EntryInProgress;
} PEB_LDR_DATA, * PPEB_LDR_DATA;
typedef struct _LDR_DATA_TABLE_ENTRY {
LIST_ENTRY InLoadOrderLinks;
LIST_ENTRY InMemoryOrderLinks;
LIST_ENTRY InInitializationOrderLinks;
PVOID DllBase;
PVOID EntryPoint;
ULONG SizeOfImage;
UNICODE_STRING FullDllName;
UNICODE_STRING BaseDllName;
} LDR_DATA_TABLE_ENTRY, * PLDR_DATA_TABLE_ENTRY;
#ifdef _WIN64
typedef struct _PEB {
BYTE Reserved1[2];
BYTE BeingDebugged;
BYTE Reserved2[21];
PPEB_LDR_DATA Ldr;
} PEB, * PPEB;
#else
typedef struct _PEB {
BYTE Reserved1[2];
BYTE BeingDebugged;
BYTE Reserved2[1];
PVOID Reserved3[2];
PPEB_LDR_DATA Ldr;
} PEB, * PPEB;
#endif
typedef struct _PROCESS_BASIC_INFORMATION {
PVOID Reserved1;
PPEB PebBaseAddress;
PVOID Reserved2[2];
ULONG_PTR UniqueProcessId;
PVOID Reserved3;
} PROCESS_BASIC_INFORMATION, * PPROCESS_BASIC_INFORMATION;
// 定义NtQueryInformationProcess函数的类型
typedef NTSTATUS(NTAPI* pNtQueryInformationProcess)(
HANDLE ProcessHandle,
ULONG ProcessInformationClass,
PVOID ProcessInformation,
ULONG ProcessInformationLength,
PULONG ReturnLength
);
// 安全地读取进程内存
BOOL SafeReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead) {
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQueryEx(hProcess, lpBaseAddress, &mbi, sizeof(mbi)) == 0) {
return FALSE;
}
if ((mbi.Protect & (PAGE_READONLY | PAGE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) == 0 ||
mbi.State != MEM_COMMIT) {
return FALSE;
}
return ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead);
}
std::wstring GetProcessPath(DWORD processId) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
if (hProcess == NULL) return L"";
WCHAR path[MAX_PATH];
DWORD size = MAX_PATH;
if (QueryFullProcessImageNameW(hProcess, 0, path, &size)) {
CloseHandle(hProcess);
return std::wstring(path);
}
CloseHandle(hProcess);
return L"";
}
DWORD GetProcessIdByName(const std::wstring& processName) {
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(snapshot, &entry)) {
do {
if (entry.th32ParentProcessID != GetCurrentProcessId() &&
processName == entry.szExeFile &&
entry.cntThreads != 0)
{
CloseHandle(snapshot);
return entry.th32ProcessID;
}
} while (Process32Next(snapshot, &entry));
}
CloseHandle(snapshot);
return 0;
}
// 手动遍历PEB模块列表
BOOL FindModuleInPEB(HANDLE hProcess, PPEB pebAddress, const wchar_t* targetDllName, PLDR_DATA_TABLE_ENTRY* ppFoundEntry) {
// 读取PEB
PEB peb;
SIZE_T bytesRead;
if (!SafeReadProcessMemory(hProcess, pebAddress, &peb, sizeof(PEB), &bytesRead)) {
return FALSE;
}
// 读取PEB_LDR_DATA
PEB_LDR_DATA ldrData;
if (!SafeReadProcessMemory(hProcess, peb.Ldr, &ldrData, sizeof(PEB_LDR_DATA), &bytesRead)) {
return FALSE;
}
// 计算第一个条目的地址
PLIST_ENTRY currentLink = ldrData.InInitializationOrderModuleList.Flink;
PLIST_ENTRY firstLink = &(peb.Ldr->InInitializationOrderModuleList);
// 遍历模块列表
while (currentLink != firstLink) {
// 计算当前LDR_DATA_TABLE_ENTRY的地址
PLDR_DATA_TABLE_ENTRY entry = CONTAINING_RECORD(currentLink, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
// 读取整个条目
LDR_DATA_TABLE_ENTRY currentEntry;
if (!SafeReadProcessMemory(hProcess, entry, &currentEntry, sizeof(LDR_DATA_TABLE_ENTRY), &bytesRead)) {
// 尝试只读取下一个链接地址
LIST_ENTRY linkEntry;
if (!SafeReadProcessMemory(hProcess, currentLink, &linkEntry, sizeof(LIST_ENTRY), &bytesRead)) {
return FALSE;
}
currentLink = linkEntry.Flink;
continue;
}
// 读取DLL名称
if (currentEntry.BaseDllName.Length > 0 && currentEntry.BaseDllName.Buffer != NULL) {
WCHAR dllName[MAX_PATH] = { 0 };
SIZE_T nameLength = min(currentEntry.BaseDllName.Length, (MAX_PATH - 1) * sizeof(WCHAR));
if (SafeReadProcessMemory(hProcess, currentEntry.BaseDllName.Buffer, dllName, nameLength, &bytesRead)) {
// 确保字符串以null结尾
dllName[nameLength / sizeof(WCHAR)] = L'\0';
// 检查是否是我们要找的DLL
if (_wcsicmp(dllName, targetDllName) == 0) {
printf("Found: %ls, Base=%p, Entry=%p\n", dllName, currentEntry.DllBase, currentEntry.EntryPoint);
*ppFoundEntry = entry;
return TRUE;
}
}
}
// 移动到下一个条目
currentLink = currentEntry.InInitializationOrderLinks.Flink;
}
return FALSE;
}
int RemoveSteamClient(DWORD processId)
{
HANDLE hProcess = OpenProcess(
PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ |
PROCESS_VM_WRITE |
PROCESS_VM_OPERATION,
FALSE, processId);
if (hProcess == NULL) {
printf("Can't open process: %u\n", GetLastError());
return 1;
}
// 获取NtQueryInformationProcess函数
HMODULE hNtdll = GetModuleHandleW(L"ntdll.dll");
pNtQueryInformationProcess NtQueryInformationProcess = (pNtQueryInformationProcess)GetProcAddress(hNtdll, "NtQueryInformationProcess");
if (!NtQueryInformationProcess) {
printf("No NtQueryInformationProcess??\n");
CloseHandle(hProcess);
return 1;
}
// 获取进程的PEB地址
PROCESS_BASIC_INFORMATION pbi;
ULONG returnLength;
NTSTATUS status = NtQueryInformationProcess(hProcess, 0, &pbi, sizeof(pbi), &returnLength);
if (status != 0) {
printf("NtQueryInformationProcess failed, status: %lx\n", status);
CloseHandle(hProcess);
return 1;
}
// 查找steamclient64.dll
PLDR_DATA_TABLE_ENTRY foundEntry = NULL;
if (FindModuleInPEB(hProcess, pbi.PebBaseAddress, L"steamclient64.dll", &foundEntry)) {
// 计算EntryPoint的地址
SIZE_T entryPointOffset = FIELD_OFFSET(LDR_DATA_TABLE_ENTRY, EntryPoint);
PVOID entryPointAddress = (BYTE*)foundEntry + entryPointOffset;
// 将EntryPoint清零
PVOID nullPtr = NULL;
if (WriteProcessMemory(hProcess, entryPointAddress, &nullPtr, sizeof(PVOID), NULL)) {
printf("Removed Entry of steamclient64.dll!\n");
}
else {
printf("Write Memory failed: %u\n", GetLastError());
}
}
else {
printf("Module steamclient64.dll not found\n");
}
CloseHandle(hProcess);
return 0;
}
PROCESS_INFORMATION pi;
#define SEARCH_CHUNK_SIZE 4096
BOOL SearchAndModifyRemoteData(HANDLE hProcess, DWORD_PTR moduleBase, const char* sectionName,
const BYTE* searchPattern, DWORD patternSize,
const BYTE* newData, DWORD newDataSize) {
IMAGE_DOS_HEADER dosHeader;
IMAGE_NT_HEADERS ntHeaders;
// 读取 DOS 头
if (!ReadProcessMemory(hProcess, (LPCVOID)moduleBase, &dosHeader, sizeof(dosHeader), NULL)) {
printf("Failed to read DOS header. Error %u \n", GetLastError());
return FALSE;
}
// 读取 NT 头
if (!ReadProcessMemory(hProcess, (LPCVOID)(moduleBase + dosHeader.e_lfanew), &ntHeaders, sizeof(ntHeaders), NULL)) {
printf("Failed to read NT headers.\n");
return FALSE;
}
// 读取节表
DWORD sectionTableOffset = dosHeader.e_lfanew + sizeof(IMAGE_NT_HEADERS);
IMAGE_SECTION_HEADER sectionHeader;
BOOL sectionFound = FALSE;
for (int i = 0; i < ntHeaders.FileHeader.NumberOfSections; i++) {
if (!ReadProcessMemory(hProcess, (LPCVOID)(moduleBase + sectionTableOffset + i * sizeof(IMAGE_SECTION_HEADER)),
&sectionHeader, sizeof(sectionHeader), NULL)) {
printf("Failed to read section header.\n");
return FALSE;
}
if (strncmp((char*)sectionHeader.Name, sectionName, 8) == 0) {
sectionFound = TRUE;
break;
}
}
if (!sectionFound) {
printf("Section %s not found.\n", sectionName);
return FALSE;
}
// 搜索段中的数据
DWORD_PTR sectionStart = moduleBase + sectionHeader.VirtualAddress;
DWORD_PTR sectionEnd = sectionStart + sectionHeader.Misc.VirtualSize;
BYTE* buffer = (BYTE*)malloc(SEARCH_CHUNK_SIZE);
if (!buffer) {
printf("Failed to allocate memory.\n");
return FALSE;
}
for (DWORD_PTR currentAddress = sectionStart; currentAddress < sectionEnd; currentAddress += SEARCH_CHUNK_SIZE - patternSize + 1) {
SIZE_T bytesRead;
if (!ReadProcessMemory(hProcess, (LPCVOID)currentAddress, buffer, SEARCH_CHUNK_SIZE, &bytesRead)) {
printf("Failed to read memory at 0x%p\n", (void*)currentAddress);
free(buffer);
return FALSE;
}
for (SIZE_T i = 0; i < bytesRead - patternSize + 1; i++) {
if (memcmp(buffer + i, searchPattern, patternSize) == 0) {
// 找到匹配的模式
DWORD_PTR matchAddress = currentAddress + i;
printf("Pattern found at address: 0x%p\n", (void*)matchAddress);
// 修改内存保护
DWORD oldProtect;
if (!VirtualProtectEx(hProcess, (LPVOID)matchAddress, newDataSize, PAGE_EXECUTE_READWRITE, &oldProtect)) {
printf("Failed to change memory protection. Error: %d\n", GetLastError());
free(buffer);
return FALSE;
}
// 修改数据
if (!WriteProcessMemory(hProcess, (LPVOID)matchAddress, newData, newDataSize, NULL)) {
printf("Failed to write new data.Error %u\n", GetLastError());
free(buffer);
return FALSE;
}
printf("Data successfully modified.\n");
free(buffer);
return TRUE;
}
}
}
printf("Pattern not found in section %s.\n", sectionName);
free(buffer);
return FALSE;
}
int main()
{
DWORD dwret;
HKEY hkey;
WCHAR FinalPath[MAX_PATH];
WCHAR InstallPath[MAX_PATH];
ULONG dwcb = sizeof(InstallPath);
BOOL bFoundPath = FALSE;
printf("BlackMythWuKong WideScreen Modifier v0.1\nby MJ0011\n");
dwret = RegOpenKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 2358720", &hkey);
if (dwret != ERROR_SUCCESS)
{
printf("Can not locate BlackMythWuKong...You can just start the game manually\n");
goto waitgame;
}
bFoundPath = TRUE;
DWORD RegType;
dwret = RegQueryValueEx(hkey, L"InstallLocation", 0, &RegType, (LPBYTE)InstallPath, &dwcb);
if (dwret != ERROR_SUCCESS)
{
printf("Query InstallLocation failed %u\n", dwret);
RegCloseKey(hkey);
return 0;
}
RegCloseKey(hkey);
PathCombine(FinalPath, InstallPath, L"b1\\Binaries\\Win64\\b1-Win64-Shipping.exe");
if (PathFileExists(FinalPath) == FALSE)
{
printf("Can not find BlackMythWuKong file...Make sure you have installed it\n");
return 0;
}
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
memset(&pi, 0, sizeof(pi));
printf("Starting BlackMythWuKong...\n");
if (CreateProcess(FinalPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == FALSE)
{
printf("Can not start BlackMythWuKong, failed %u\n", GetLastError());
return 0;
}
waitgame:
std::wstring targetProcessName = L"b1-Win64-Shipping.exe";
DWORD processId = 0;
HANDLE hProcess = NULL;
HMODULE hlib;
while (true) {
processId = GetProcessIdByName(targetProcessName);
if (processId != 0) {
std::wcout << L"Process found! Process ID: " << processId << std::endl;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (hProcess != NULL) {
if (bFoundPath)
{
//No ASLR in current version but we still locate it for futher versions
hlib = LoadLibraryEx(FinalPath, 0, DONT_RESOLVE_DLL_REFERENCES);
FreeLibrary(hlib);
}
else
{
hlib = LoadLibraryEx(GetProcessPath(processId).c_str(), 0, DONT_RESOLVE_DLL_REFERENCES);
FreeLibrary(hlib);
}
std::wcout << L"Process handle opened successfully." << std::endl;
// 要搜索的模式(4个字节)
BYTE searchPattern[] = { 0x8e, 0xe3, 0x18, 0x40 };
// 要写入的新数据(4个字节)
BYTE newData[] = { 0x39, 0x8e, 0x63, 0x40 };
while (true)
{
//在 .sdata 段中搜索并修改数据
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".xpdata", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.21
printf("Data in .xpdata section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".xdata", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.20
printf("Data in .xdata section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".xcode", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.16
printf("Data in .xcode section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".tls$", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.14
printf("Data in .tls$ section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".rsrc", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.13
printf("Data in .rsrc section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".shared", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.9
printf("Data in .shared section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".rdata", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //version 1.0.8
printf("Data in .rdata section has been modified.\n");
break;
}
if (SearchAndModifyRemoteData(hProcess, (DWORD_PTR)hlib, ".sdata", searchPattern, sizeof(searchPattern), newData, sizeof(newData))) { //versions before 1.0.8
printf("Data in .sdata section has been modified.\n");
break;
}
printf("Failed to modify to widescreen, exit\n");
return 0;
}
break; // 找到并打开进程后退出循环
}
else {
std::wcout << L"Failed to open process handle. Error code: " << GetLastError() << std::endl;
}
}
Sleep(1000); // 每秒检查一次
}
printf("\nSuccessfully changed it to widescreen, WuKong will start in seconds...\n");
if (processId != 0)
{
Sleep(3000);
RemoveSteamClient(processId);
}
return 0;
}