mirror of
https://github.com/wangdage12/genshin-fps-unlock.git
synced 2026-02-17 09:22:08 +08:00
Update main.cpp
fix hide attribute
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
std::string GamePath{};
|
std::string GamePath{};
|
||||||
int FpsValue = FPS_TARGET;
|
int FpsValue = FPS_TARGET;
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
// 特征搜索 - 不是我写的 - 忘了在哪拷的
|
||||||
uintptr_t PatternScan(void* module, const char* signature)
|
uintptr_t PatternScan(void* module, const char* signature)
|
||||||
{
|
{
|
||||||
static auto pattern_to_byte = [](const char* pattern) {
|
static auto pattern_to_byte = [](const char* pattern) {
|
||||||
@@ -73,7 +73,7 @@ std::string GetLastErrorAsString(DWORD code)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ȡĿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DLL<EFBFBD><EFBFBD>Ϣ
|
// 获取目标进程DLL信息
|
||||||
bool GetModule(DWORD pid, std::string ModuleName, PMODULEENTRY32 pEntry)
|
bool GetModule(DWORD pid, std::string ModuleName, PMODULEENTRY32 pEntry)
|
||||||
{
|
{
|
||||||
if (!pEntry)
|
if (!pEntry)
|
||||||
@@ -98,7 +98,7 @@ bool GetModule(DWORD pid, std::string ModuleName, PMODULEENTRY32 pEntry)
|
|||||||
return pEntry->modBaseAddr;
|
return pEntry->modBaseAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
|
// 通过进程名搜索进程ID
|
||||||
DWORD GetPID(std::string ProcessName)
|
DWORD GetPID(std::string ProcessName)
|
||||||
{
|
{
|
||||||
DWORD pid = 0;
|
DWORD pid = 0;
|
||||||
@@ -119,7 +119,7 @@ DWORD GetPID(std::string ProcessName)
|
|||||||
|
|
||||||
bool WriteConfig(std::string GamePath, int fps)
|
bool WriteConfig(std::string GamePath, int fps)
|
||||||
{
|
{
|
||||||
HANDLE hFile = CreateFileA("fps_config.ini", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
HANDLE hFile = CreateFileA("fps_config.ini", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_HIDDEN, nullptr);
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DWORD code = GetLastError();
|
DWORD code = GetLastError();
|
||||||
@@ -145,16 +145,16 @@ void LoadConfig()
|
|||||||
INIReader reader("fps_config.ini");
|
INIReader reader("fps_config.ini");
|
||||||
if (reader.ParseError() != 0)
|
if (reader.ParseError() != 0)
|
||||||
{
|
{
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n<EFBFBD>벻Ҫ<EFBFBD>رմ˽<EFBFBD><EFBFBD><EFBFBD> - Ȼ<><C8BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ\n<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> - <20><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><C8A1>Ϸ·<CFB7><C2B7>\n");
|
printf("配置不存在\n请不要关闭此进程 - 然后手动开启游戏\n这只需要进行一次 - 用于获取游戏路经\n");
|
||||||
printf("\n<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\n");
|
printf("\n等待游戏启动...\n");
|
||||||
|
|
||||||
DWORD pid = 0;
|
DWORD pid = 0;
|
||||||
while (!(pid = GetPID("YuanShen.exe")) && !(pid = GetPID("GenshinImpact.exe")))
|
while (!(pid = GetPID("YuanShen.exe")) && !(pid = GetPID("GenshinImpact.exe")))
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>̾<EFBFBD><EFBFBD><EFBFBD> - <20><>Ȩ<EFBFBD>ܵ͵<DCB5><CDB5><EFBFBD> - <20><>Ӧ<EFBFBD>û<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
// 获取进程句柄 - 这权限很低的了 - 不应该获取不了
|
||||||
// PROCESS_QUERY_LIMITED_INFORMATION - <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD> (K32GetModuleFileNameExA)
|
// PROCESS_QUERY_LIMITED_INFORMATION - 用于查询进程路经 (K32GetModuleFileNameExA)
|
||||||
// SYNCHRONIZE - <EFBFBD><EFBFBD><EFBFBD>ڵȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD> (WaitForSingleObject)
|
// SYNCHRONIZE - 用于等待进程结束 (WaitForSingleObject)
|
||||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, pid);
|
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, pid);
|
||||||
if (!hProcess)
|
if (!hProcess)
|
||||||
{
|
{
|
||||||
@@ -195,13 +195,13 @@ void LoadConfig()
|
|||||||
|
|
||||||
if (GetFileAttributesA(GamePath.c_str()) == INVALID_FILE_ATTRIBUTES)
|
if (GetFileAttributesA(GamePath.c_str()) == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ·<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD> - <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
printf("配置里的游戏路经改变了 - 开始重新配置\n");
|
||||||
DeleteFileA("config.ini");
|
DeleteFileA("config.ini");
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD>ȼ<EFBFBD><EFBFBD>߳<EFBFBD>
|
// 热键线程
|
||||||
DWORD __stdcall Thread1(LPVOID p)
|
DWORD __stdcall Thread1(LPVOID p)
|
||||||
{
|
{
|
||||||
if (!p)
|
if (!p)
|
||||||
@@ -251,7 +251,7 @@ int main(int argc, char** argv)
|
|||||||
CommandLine += argv[i] + std::string(" ");
|
CommandLine += argv[i] + std::string(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 读取配置
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
int TargetFPS = FpsValue;
|
int TargetFPS = FpsValue;
|
||||||
std::string ProcessPath = GamePath;
|
std::string ProcessPath = GamePath;
|
||||||
@@ -260,16 +260,16 @@ int main(int argc, char** argv)
|
|||||||
if (ProcessPath.length() < 8)
|
if (ProcessPath.length() < 8)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
printf("FPS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> v1.4.2\n");
|
printf("FPS 解锁器 v1.4.2\n");
|
||||||
printf("<EFBFBD><EFBFBD>Ϸ·<EFBFBD><EFBFBD>: %s\n\n", ProcessPath.c_str());
|
printf("游戏路经: %s\n\n", ProcessPath.c_str());
|
||||||
ProcessDir = ProcessPath.substr(0, ProcessPath.find_last_of("\\"));
|
ProcessDir = ProcessPath.substr(0, ProcessPath.find_last_of("\\"));
|
||||||
|
|
||||||
DWORD pid = GetPID(ProcessPath.substr(ProcessPath.find_last_of("\\") + 1));
|
DWORD pid = GetPID(ProcessPath.substr(ProcessPath.find_last_of("\\") + 1));
|
||||||
if (pid)
|
if (pid)
|
||||||
{
|
{
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>\n");
|
printf("检测到游戏已在运行!\n");
|
||||||
printf("<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>ᵼ<EFBFBD><EFBFBD>ʧЧ<EFBFBD><EFBFBD>\n");
|
printf("手动启动游戏会导致失效的\n");
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>Ϸ - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ\n");
|
printf("请手动关闭游戏 - 解锁器会自动启动游戏\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ int main(int argc, char** argv)
|
|||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
printf("PID: %d\n", pi.dwProcessId);
|
printf("PID: %d\n", pi.dwProcessId);
|
||||||
|
|
||||||
// <EFBFBD>ȴ<EFBFBD>UnityPlayer.dll<EFBFBD><EFBFBD><EFBFBD>غͻ<EFBFBD>ȡDLL<EFBFBD><EFBFBD>Ϣ
|
// 等待UnityPlayer.dll加载和获取DLL信息
|
||||||
MODULEENTRY32 hUnityPlayer{};
|
MODULEENTRY32 hUnityPlayer{};
|
||||||
MODULEENTRY32 hUserAssembly{};
|
MODULEENTRY32 hUserAssembly{};
|
||||||
while (!GetModule(pi.dwProcessId, "UnityPlayer.dll", &hUnityPlayer))
|
while (!GetModule(pi.dwProcessId, "UnityPlayer.dll", &hUnityPlayer))
|
||||||
@@ -296,7 +296,7 @@ int main(int argc, char** argv)
|
|||||||
printf("UnityPlayer: %X%X\n", (uintptr_t)hUnityPlayer.modBaseAddr >> 32 & -1, hUnityPlayer.modBaseAddr);
|
printf("UnityPlayer: %X%X\n", (uintptr_t)hUnityPlayer.modBaseAddr >> 32 & -1, hUnityPlayer.modBaseAddr);
|
||||||
printf("UserAssembly: %X%X\n", (uintptr_t)hUnityPlayer.modBaseAddr >> 32 & -1, hUserAssembly.modBaseAddr);
|
printf("UserAssembly: %X%X\n", (uintptr_t)hUnityPlayer.modBaseAddr >> 32 & -1, hUserAssembly.modBaseAddr);
|
||||||
|
|
||||||
// <EFBFBD>ڱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UnityPlayer.dll<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 在本进程内申请UnityPlayer.dll大小的内存 - 用于特征搜索
|
||||||
//LPVOID mem = VirtualAlloc(nullptr, hUnityPlayer.modBaseSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
//LPVOID mem = VirtualAlloc(nullptr, hUnityPlayer.modBaseSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||||
LPVOID up = VirtualAlloc(nullptr, hUnityPlayer.modBaseSize + hUserAssembly.modBaseSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
LPVOID up = VirtualAlloc(nullptr, hUnityPlayer.modBaseSize + hUserAssembly.modBaseSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||||
if (!up)
|
if (!up)
|
||||||
@@ -306,7 +306,7 @@ int main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// 把整个模块读出来
|
||||||
ReadProcessMemory(pi.hProcess, hUnityPlayer.modBaseAddr, up, hUnityPlayer.modBaseSize, nullptr);
|
ReadProcessMemory(pi.hProcess, hUnityPlayer.modBaseAddr, up, hUnityPlayer.modBaseSize, nullptr);
|
||||||
LPVOID ua = (LPVOID)((uintptr_t)up + hUnityPlayer.modBaseSize);
|
LPVOID ua = (LPVOID)((uintptr_t)up + hUnityPlayer.modBaseSize);
|
||||||
ReadProcessMemory(pi.hProcess, hUserAssembly.modBaseAddr, ua, hUserAssembly.modBaseSize, nullptr);
|
ReadProcessMemory(pi.hProcess, hUserAssembly.modBaseAddr, ua, hUserAssembly.modBaseSize, nullptr);
|
||||||
@@ -322,7 +322,7 @@ int main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>ַ (FPS)
|
// 计算相对地址 (FPS)
|
||||||
uintptr_t pfps = 0;
|
uintptr_t pfps = 0;
|
||||||
{
|
{
|
||||||
uintptr_t rip = address;
|
uintptr_t rip = address;
|
||||||
@@ -344,7 +344,7 @@ int main(int argc, char** argv)
|
|||||||
pfps = (uintptr_t)hUnityPlayer.modBaseAddr + pfps;
|
pfps = (uintptr_t)hUnityPlayer.modBaseAddr + pfps;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>ַ (<28><>ֱͬ<D6B1><CDAC>)
|
// 计算相对地址 (垂直同步)
|
||||||
address = PatternScan(up, "E8 ? ? ? ? 8B E8 49 8B 1E");
|
address = PatternScan(up, "E8 ? ? ? ? 8B E8 49 8B 1E");
|
||||||
uintptr_t pvsync = 0;
|
uintptr_t pvsync = 0;
|
||||||
if (address)
|
if (address)
|
||||||
@@ -373,13 +373,13 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
VirtualFree(up, 0, MEM_RELEASE);
|
VirtualFree(up, 0, MEM_RELEASE);
|
||||||
printf("Done\n\n");
|
printf("Done\n\n");
|
||||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ctrl + <EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
|
printf("用右ctrl + 箭头键更改限制:\n");
|
||||||
printf(" <EFBFBD><EFBFBD>ctrl + <EFBFBD><EFBFBD>: +20\n");
|
printf(" 右ctrl + 上: +20\n");
|
||||||
printf(" <EFBFBD><EFBFBD>ctrl + <EFBFBD><EFBFBD>: -20\n");
|
printf(" 右ctrl + 下: -20\n");
|
||||||
printf(" <EFBFBD><EFBFBD>ctrl + <EFBFBD><EFBFBD>: -2\n");
|
printf(" 右ctrl + 左: -2\n");
|
||||||
printf(" <EFBFBD><EFBFBD>ctrl + <EFBFBD><EFBFBD>: +2\n\n");
|
printf(" 右ctrl + 右: +2\n\n");
|
||||||
|
|
||||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD>߳<EFBFBD>
|
// 创建热键线程
|
||||||
HANDLE hThread = CreateThread(nullptr, 0, Thread1, &TargetFPS, 0, nullptr);
|
HANDLE hThread = CreateThread(nullptr, 0, Thread1, &TargetFPS, 0, nullptr);
|
||||||
if (hThread)
|
if (hThread)
|
||||||
CloseHandle(hThread);
|
CloseHandle(hThread);
|
||||||
@@ -389,7 +389,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
||||||
|
|
||||||
// ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
// 每两秒检查一次
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
int fps = 0;
|
int fps = 0;
|
||||||
ReadProcessMemory(pi.hProcess, (LPVOID)pfps, &fps, sizeof(fps), nullptr);
|
ReadProcessMemory(pi.hProcess, (LPVOID)pfps, &fps, sizeof(fps), nullptr);
|
||||||
@@ -403,7 +403,7 @@ int main(int argc, char** argv)
|
|||||||
if (vsync)
|
if (vsync)
|
||||||
{
|
{
|
||||||
vsync = 0;
|
vsync = 0;
|
||||||
// <EFBFBD>رմ<EFBFBD>ֱͬ<EFBFBD><EFBFBD>
|
// 关闭垂直同步
|
||||||
WriteProcessMemory(pi.hProcess, (LPVOID)pvsync, &vsync, sizeof(vsync), nullptr);
|
WriteProcessMemory(pi.hProcess, (LPVOID)pvsync, &vsync, sizeof(vsync), nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user