mirror of
https://github.com/wangdage12/genshin-fps-unlock.git
synced 2026-03-28 00:42:21 +08:00
Update main.cpp
fix hide attribute
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
std::string GamePath{};
|
||||
int FpsValue = FPS_TARGET;
|
||||
|
||||
// 特征搜索 - 不是我写的 - 忘了在哪拷的
|
||||
// 特征搜索 - 不是我写的 - 忘了在哪拷的
|
||||
uintptr_t PatternScan(void* module, const char* signature)
|
||||
{
|
||||
static auto pattern_to_byte = [](const char* pattern) {
|
||||
@@ -73,7 +73,7 @@ std::string GetLastErrorAsString(DWORD code)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 获取目标进程DLL信息
|
||||
// 获取目标进程DLL信息
|
||||
bool GetModule(DWORD pid, std::string ModuleName, PMODULEENTRY32 pEntry)
|
||||
{
|
||||
if (!pEntry)
|
||||
@@ -98,7 +98,7 @@ bool GetModule(DWORD pid, std::string ModuleName, PMODULEENTRY32 pEntry)
|
||||
return pEntry->modBaseAddr;
|
||||
}
|
||||
|
||||
// 通过进程名搜索进程ID
|
||||
// 通过进程名搜索进程ID
|
||||
DWORD GetPID(std::string ProcessName)
|
||||
{
|
||||
DWORD pid = 0;
|
||||
@@ -119,7 +119,7 @@ DWORD GetPID(std::string ProcessName)
|
||||
|
||||
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)
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
@@ -145,16 +145,16 @@ void LoadConfig()
|
||||
INIReader reader("fps_config.ini");
|
||||
if (reader.ParseError() != 0)
|
||||
{
|
||||
printf("配置不存在\n请不要关闭此进程 - 然后手动开启游戏\n这只需要进行一次 - 用于获取游戏路经\n");
|
||||
printf("\n等待游戏启动...\n");
|
||||
printf("配置不存在\n请不要关闭此进程 - 然后手动开启游戏\n这只需要进行一次 - 用于获取游戏路经\n");
|
||||
printf("\n等待游戏启动...\n");
|
||||
|
||||
DWORD pid = 0;
|
||||
while (!(pid = GetPID("YuanShen.exe")) && !(pid = GetPID("GenshinImpact.exe")))
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
||||
// 获取进程句柄 - 这权限很低的了 - 不应该获取不了
|
||||
// PROCESS_QUERY_LIMITED_INFORMATION - 用于查询进程路经 (K32GetModuleFileNameExA)
|
||||
// SYNCHRONIZE - 用于等待进程结束 (WaitForSingleObject)
|
||||
// 获取进程句柄 - 这权限很低的了 - 不应该获取不了
|
||||
// PROCESS_QUERY_LIMITED_INFORMATION - 用于查询进程路经 (K32GetModuleFileNameExA)
|
||||
// SYNCHRONIZE - 用于等待进程结束 (WaitForSingleObject)
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE, pid);
|
||||
if (!hProcess)
|
||||
{
|
||||
@@ -195,13 +195,13 @@ void LoadConfig()
|
||||
|
||||
if (GetFileAttributesA(GamePath.c_str()) == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
printf("配置里的游戏路经改变了 - 开始重新配置\n");
|
||||
printf("配置里的游戏路经改变了 - 开始重新配置\n");
|
||||
DeleteFileA("config.ini");
|
||||
LoadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
// 热键线程
|
||||
// 热键线程
|
||||
DWORD __stdcall Thread1(LPVOID p)
|
||||
{
|
||||
if (!p)
|
||||
@@ -251,7 +251,7 @@ int main(int argc, char** argv)
|
||||
CommandLine += argv[i] + std::string(" ");
|
||||
}
|
||||
|
||||
// 读取配置
|
||||
// 读取配置
|
||||
LoadConfig();
|
||||
int TargetFPS = FpsValue;
|
||||
std::string ProcessPath = GamePath;
|
||||
@@ -260,16 +260,16 @@ int main(int argc, char** argv)
|
||||
if (ProcessPath.length() < 8)
|
||||
return 0;
|
||||
|
||||
printf("FPS 解锁器 v1.4.2\n");
|
||||
printf("游戏路经: %s\n\n", ProcessPath.c_str());
|
||||
printf("FPS 解锁器 v1.4.2\n");
|
||||
printf("游戏路经: %s\n\n", ProcessPath.c_str());
|
||||
ProcessDir = ProcessPath.substr(0, ProcessPath.find_last_of("\\"));
|
||||
|
||||
DWORD pid = GetPID(ProcessPath.substr(ProcessPath.find_last_of("\\") + 1));
|
||||
if (pid)
|
||||
{
|
||||
printf("检测到游戏已在运行!\n");
|
||||
printf("手动启动游戏会导致失效的\n");
|
||||
printf("请手动关闭游戏 - 解锁器会自动启动游戏\n");
|
||||
printf("检测到游戏已在运行!\n");
|
||||
printf("手动启动游戏会导致失效的\n");
|
||||
printf("请手动关闭游戏 - 解锁器会自动启动游戏\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ int main(int argc, char** argv)
|
||||
CloseHandle(pi.hThread);
|
||||
printf("PID: %d\n", pi.dwProcessId);
|
||||
|
||||
// 等待UnityPlayer.dll加载和获取DLL信息
|
||||
// 等待UnityPlayer.dll加载和获取DLL信息
|
||||
MODULEENTRY32 hUnityPlayer{};
|
||||
MODULEENTRY32 hUserAssembly{};
|
||||
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("UserAssembly: %X%X\n", (uintptr_t)hUnityPlayer.modBaseAddr >> 32 & -1, hUserAssembly.modBaseAddr);
|
||||
|
||||
// 在本进程内申请UnityPlayer.dll大小的内存 - 用于特征搜索
|
||||
// 在本进程内申请UnityPlayer.dll大小的内存 - 用于特征搜索
|
||||
//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);
|
||||
if (!up)
|
||||
@@ -306,7 +306,7 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 把整个模块读出来
|
||||
// 把整个模块读出来
|
||||
ReadProcessMemory(pi.hProcess, hUnityPlayer.modBaseAddr, up, hUnityPlayer.modBaseSize, nullptr);
|
||||
LPVOID ua = (LPVOID)((uintptr_t)up + hUnityPlayer.modBaseSize);
|
||||
ReadProcessMemory(pi.hProcess, hUserAssembly.modBaseAddr, ua, hUserAssembly.modBaseSize, nullptr);
|
||||
@@ -322,7 +322,7 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 计算相对地址 (FPS)
|
||||
// 计算相对地址 (FPS)
|
||||
uintptr_t pfps = 0;
|
||||
{
|
||||
uintptr_t rip = address;
|
||||
@@ -344,7 +344,7 @@ int main(int argc, char** argv)
|
||||
pfps = (uintptr_t)hUnityPlayer.modBaseAddr + pfps;
|
||||
}
|
||||
|
||||
// 计算相对地址 (垂直同步)
|
||||
// 计算相对地址 (垂直同步)
|
||||
address = PatternScan(up, "E8 ? ? ? ? 8B E8 49 8B 1E");
|
||||
uintptr_t pvsync = 0;
|
||||
if (address)
|
||||
@@ -373,13 +373,13 @@ int main(int argc, char** argv)
|
||||
|
||||
VirtualFree(up, 0, MEM_RELEASE);
|
||||
printf("Done\n\n");
|
||||
printf("用右ctrl + 箭头键更改限制:\n");
|
||||
printf(" 右ctrl + 上: +20\n");
|
||||
printf(" 右ctrl + 下: -20\n");
|
||||
printf(" 右ctrl + 左: -2\n");
|
||||
printf(" 右ctrl + 右: +2\n\n");
|
||||
printf("用右ctrl + 箭头键更改限制:\n");
|
||||
printf(" 右ctrl + 上: +20\n");
|
||||
printf(" 右ctrl + 下: -20\n");
|
||||
printf(" 右ctrl + 左: -2\n");
|
||||
printf(" 右ctrl + 右: +2\n\n");
|
||||
|
||||
// 创建热键线程
|
||||
// 创建热键线程
|
||||
HANDLE hThread = CreateThread(nullptr, 0, Thread1, &TargetFPS, 0, nullptr);
|
||||
if (hThread)
|
||||
CloseHandle(hThread);
|
||||
@@ -389,7 +389,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
||||
|
||||
// 每两秒检查一次
|
||||
// 每两秒检查一次
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
int fps = 0;
|
||||
ReadProcessMemory(pi.hProcess, (LPVOID)pfps, &fps, sizeof(fps), nullptr);
|
||||
@@ -403,7 +403,7 @@ int main(int argc, char** argv)
|
||||
if (vsync)
|
||||
{
|
||||
vsync = 0;
|
||||
// 关闭垂直同步
|
||||
// 关闭垂直同步
|
||||
WriteProcessMemory(pi.hProcess, (LPVOID)pvsync, &vsync, sizeof(vsync), nullptr);
|
||||
}
|
||||
}
|
||||
@@ -412,4 +412,4 @@ int main(int argc, char** argv)
|
||||
TerminateProcess((HANDLE)-1, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user