Skip to content

Commit

Permalink
feat: a magic update.
Browse files Browse the repository at this point in the history
- bump version
  • Loading branch information
Xcating committed Apr 29, 2024
1 parent 7a1ff33 commit 9fd4ef2
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 10 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# GhTrTool 0.11u ~ [2024-04-14]
# GhTrTool 0.11v ~ [2024-04-29]
## 完整更新日志
### 更新
- 对GhTr ~ Perfect Voyage 0.16m版本提供支持,停止支持之前的版本
### 特性
- 重构代码,提升可读性和可维护性
- 增加一键允许创建ub存档
- 完善存档标记
### 正在进行
- 地址常数化

![image](https://github.com/Xcating/GhTrTool/assets/82816129/bf18c318-a437-4fd1-ba5e-9e3d37f36f00)
![image](https://github.com/Xcating/GhTrTool/assets/82816129/a2077550-108f-4334-9cf5-c5c4b29e4379)
Binary file modified GhTrTool/GhTrTool.rc
Binary file not shown.
9 changes: 9 additions & 0 deletions GhTrTool/GhTrToolDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ BEGIN_MESSAGE_MAP(CGhTrToolDlg, CDialogEx)
ON_BN_CLICKED(IDC_BTN_ClearZombie, &CGhTrToolDlg::OnBnClickedBtnClearZombie)
ON_BN_CLICKED(IDC_BTN_FixCrashBug, &CGhTrToolDlg::OnBnClickedBtnFixCrashBug)
ON_BN_CLICKED(IDC_BTN_ToDaoXiangJi, &CGhTrToolDlg::OnBnClickedBtnToDaoXiangJi)
ON_BN_CLICKED(IDC_BTN_ArrUb, &CGhTrToolDlg::OnBnClickedBtnArrUb)
ON_BN_CLICKED(IDC_BTN_ToHongZhen, &CGhTrToolDlg::OnBnClickedBtnToHongZhen)
ON_BN_CLICKED(IDC_BTN_ClearPlant, &CGhTrToolDlg::OnBnClickedBtnClearPlant)
ON_BN_CLICKED(IDC_BTN_ClearBullet, &CGhTrToolDlg::OnBnClickedBtnClearBullet)
Expand Down Expand Up @@ -172,6 +173,7 @@ void CGhTrToolDlg::OnClickMenuShowSaveFunction()
GetDlgItem(IDC_BTN_DifficultySwitcher)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_EDIT_Diff)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BTN_ToDaoXiangJi)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BTN_ArrUb)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BTN_ToHongZhen)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BTN_NoUbBroken)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATIC_DiffID)->ShowWindow(SW_SHOW);
Expand All @@ -183,6 +185,7 @@ void CGhTrToolDlg::OnClickMenuShowSaveFunction()
GetDlgItem(IDC_BTN_DifficultySwitcher)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDIT_Diff)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_ToDaoXiangJi)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_ArrUb)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_ToHongZhen)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_NoUbBroken)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_DiffID)->ShowWindow(SW_HIDE);
Expand Down Expand Up @@ -539,6 +542,12 @@ void CGhTrToolDlg::OnBnClickedBtnToDaoXiangJi()
pvz.ToDaoXiangJi();
}

void CGhTrToolDlg::OnBnClickedBtnArrUb()
{
GhTrManager pvz = GhTrManager();
pvz.ArrUb();
}

void CGhTrToolDlg::OnBnClickedBtnToHongZhen()
{
GhTrManager pvz = GhTrManager(); pvz.WriteConfig();
Expand Down
1 change: 1 addition & 0 deletions GhTrTool/GhTrToolDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CGhTrToolDlg : public CDialogEx
afx_msg void OnBnClickedBtnFixCrashBug();
afx_msg void OnBnClickedBtnToHongZhen();
afx_msg void OnBnClickedBtnToDaoXiangJi();
afx_msg void OnBnClickedBtnArrUb();
afx_msg void UpdateText();
afx_msg void OnBnClickedBtnPlantIDList();
void OnTimer(UINT_PTR nIDEvent);
Expand Down
79 changes: 75 additions & 4 deletions GhTrTool/Pvz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ bool GhTrManager::CheckGamePid(DWORD dw_pid, bool is_message) {
* @return bool 枚举是否继续
*/
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM l_param) {

DWORD dw_pid;
GetWindowThreadProcessId(hwnd, &dw_pid);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dw_pid);
DWORD base_address = GetGamebase_address(hProcess);
DWORD target_address = base_address + GAME_BASE_OFFSET;
DWORD dwNum = 0;
ReadProcessMemory(hProcess, (LPCVOID)target_address, &dwNum, sizeof(DWORD), NULL);
ReadProcessMemory(hProcess, (LPCVOID)(dwNum + 0x80C), &dwNum, sizeof(DWORD), NULL);
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
Expand All @@ -219,8 +226,8 @@ BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM l_param) {
#else
std::wstring wstr =
(std::wstringstream() << L"Plants Vs Zombies GhTr ~ Perfect Voyage "
<< L"ver.0.16m - [已被GhTrTool修改] [ver.0.11u] ["
<< millis << L"]")
<< L"ver.0.16m - [已被GhTrTool修改] [ver.0.11v] ["
<< millis << L"]" << L" [Save" << dwNum<<L"]")
.str();
#endif
if (dw_pid == l_param) {
Expand Down Expand Up @@ -639,7 +646,11 @@ void GhTrManager::WriteConfig()
CloseHandle(hProcess);
return;
}

DWORD base_address = GetGamebase_address(hProcess);
DWORD target_address = base_address + GAME_BASE_OFFSET;
DWORD dwNum = 0;
ReadProcessMemory(hProcess, (LPCVOID)target_address, &dwNum, sizeof(DWORD), NULL);
ReadProcessMemory(hProcess, (LPCVOID)(dwNum + 0x80C), &dwNum, sizeof(DWORD), NULL);
std::filesystem::path exe_path(sz_exe_path);
std::filesystem::path config_path = exe_path.parent_path() / "definition" / "config.json";

Expand All @@ -651,9 +662,35 @@ void GhTrManager::WriteConfig()
config_file_out << config_json.dump(4);
config_file_out.close();
}

EnumWindows(EnumWindowsProc, dw_pid);
CloseHandle(hProcess);
if (dwNum == 0)
return;
std::ostringstream file_path_stream;
file_path_stream << "C:\\ProgramData\\PerfectVoyage\\userdata\\save" << dwNum << "\\SaveInfor.ghtr";
std::string file_path = file_path_stream.str();
// 读取JSON文件
nlohmann::json j;
std::ifstream input_file(file_path);
if (input_file.is_open()) {
input_file >> j;
input_file.close();
}
// 修改Cheat为true,如果不存在则创建
j["Cheat"] = true;
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
j["LastCheatTime"] = millis;
// 写入修改后的JSON到文件
std::ofstream output_file(file_path);
if (output_file.is_open()) {
output_file << j.dump(4); // 以漂亮打印的格式写入文件(缩进为4个空格)
output_file.close();
}
else {
MessageBoxA(NULL, "无法打开文件进行写入!请检查你的GhTr是否能正确的存档", "警告", MB_OK);
}
}
/**
* 修改游戏中的阳光数量
Expand Down Expand Up @@ -1516,6 +1553,40 @@ void GhTrManager::ShowDiffBox(DWORD dwDiff)
break;
}
}
/**
* 切换是否可以创建Ub存档的变量
*/
void GhTrManager::ArrUb()
{
// 定义JSON对象
nlohmann::json j;
// 读取JSON文件
std::ifstream input_file("C:\\ProgramData\\PerfectVoyage\\allusers.ghtr");
if (input_file.is_open()) {
input_file >> j;
input_file.close();
}
// 修改UbOpen为true,如果不存在则创建
if (j["UbOpen"])
{
j["UbOpen"] = false;
MessageBoxA(NULL, "成功[禁止]Unbalanced存档的创建,再次点击则允许", "提示", MB_OK);
}
else
{
j["UbOpen"] = true;
MessageBoxA(NULL, "成功[允许]Unbalanced存档的创建,再次点击则禁止", "提示", MB_OK);
}
// 写入修改后的JSON到文件
std::ofstream output_file("C:\\ProgramData\\PerfectVoyage\\allusers.ghtr");
if (output_file.is_open()) {
output_file << j.dump(4); // 以漂亮打印的格式写入文件(缩进为4个空格)
output_file.close();
}
else {
MessageBoxA(NULL, "无法打开文件进行写入!请检查你的GhTr是否能正确的存档", "警告", MB_OK);
}
}
/**
* 切换当前存档难度
*
Expand Down
2 changes: 2 additions & 0 deletions GhTrTool/Pvz.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class GhTrManager
void FixCrashBug();
//切换至导向线
void ToDaoXiangJi();
//切换是否可以创建Ub存档
void ArrUb();
//显示难度提示信息
void ShowDiffBox(DWORD dwDiff);
//切换至红针线
Expand Down
Binary file modified GhTrTool/resource.h
Binary file not shown.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# GhTrTool
#### If you are not Chinese? pls Use ***[English Version](https://github.com/Xcating/GhTrTool/releases/tag/0.11c-en-us)***

植物大战僵尸GhTr同人游戏工具,娱乐学习
PlantsVsZombies ~ GhTr *PersonGames Tools*
Expand Down

0 comments on commit 9fd4ef2

Please sign in to comment.