Skip to content

Commit

Permalink
chore: update to 0.11n support 0.16n game
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcating committed Jun 2, 2024
1 parent 31a119a commit 3f43413
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 127 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# GhTrTool 0.11w ~ [2024-05-29]
# GhTrTool 0.11x ~ [2024-06-02]
## 完整更新日志
### 特性
- 重构"允许创建Unbalanced难度存档"功能
### 更新
- 支持0.16n的游戏版本,取消对之前版本的支持
### 正在进行
- 地址常数化
- 地址数值常数化

![image](https://github.com/Xcating/GhTrTool/assets/82816129/0c7d40cd-d8d8-4367-838e-f3a12b841c3e)
![MainGUI](https://github.com/Xcating/GhTrTool/assets/82816129/42f63f91-314f-4457-a53a-e23779d1c7ca)

![image](https://github.com/Xcating/GhTrTool/assets/82816129/685daa33-4945-452a-8491-9440c166f619)
![GameTest](https://github.com/Xcating/GhTrTool/assets/82816129/6665c762-5e7b-44b7-b322-b0ea3b89d0e7)
10 changes: 5 additions & 5 deletions GhTrTool/Constant.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#pragma once
CONST DWORD GAME_BASE_OFFSET = 0x29CD20; //游戏LawnAPP* 实例偏移 [BaseAddress+GAME_BASE_OFFSET]
CONST DWORD GAME_BASE_OFFSET = 0x2A0DD0; //游戏LawnAPP* 实例偏移 [BaseAddress+GAME_BASE_OFFSET]
CONST DWORD GAME_BOARD_OFFSET = 0x708; //游戏Board*板 实例偏移 [[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]
CONST DWORD GAME_SUN_OFFSET = 0x384; //阳光 偏移 [[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_SUN_OFFSET]
CONST DWORD GAME_CARD_OFFSET = 0x14C; //卡槽 实例偏移 [[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_CARD_OFFSET]
CONST DWORD GAME_CARD_NUMBER_OFFSET = 0x24; //卡槽个数 偏移 [[[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_CARD_OFFSET]+GAME_CARD_NUMBER_OFFSET]
CONST DWORD GAME_CARD_ID_OFFSET = 0x2C; //卡槽ID 偏移 [[[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_CARD_OFFSET]+GAME_CARD_ID_OFFSET]
CONST DWORD GAME_CARD_SIZE = 0x38; //卡槽类大小
CONST DWORD GAME_CARD_ID_START_OFFSET = 0x1C; //卡槽ID特殊起始点 偏移 [!疑似多余] [[[[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_CARD_OFFSET]+GAME_CARD_ID_OFFSET]+GAME_CARD_ID_START_OFFSET]
CONST DWORD GAME_PLANT_SUB_SUN_OFFSET = 0x9C519; //种植植物阳光减少 偏移 [BaseAddress+GAME_PLANT_SUB_SUN_OFFSET]
CONST DWORD GAME_CARD_ID_START_OFFSET = 0x1C; //卡槽ID特殊起始点 偏移 [[[[[BaseAddress+GAME_BASE_OFFSET]+GAME_BOARD_OFFSET]+GAME_CARD_OFFSET]+GAME_CARD_ID_OFFSET]+GAME_CARD_ID_START_OFFSET]
CONST DWORD GAME_PLANT_SUB_SUN_OFFSET = 0x9C709;//种植植物阳光减少 偏移 [BaseAddress+GAME_PLANT_SUB_SUN_OFFSET]
CONST CHAR* GAME_PLANT_SUB_SUN_PATCH_OPCODE = "\x90\x90\x90\x90\x90\x90"; //种植植物阳光减少_阳光不减少 操作码
CONST CHAR* GAME_PLANT_SUB_SUN_ORIGINAL_OPCODE = "\x29\xBE\x84\x03\x00\x00"; //种植植物阳光减少_原码 操作码
CONST DWORD GAME_PLANT_NO_CD_OFFSET = 0xEBA99; //重新种植更新当前冷却 偏移 [BaseAddress+GAME_PLANT_NO_CD_OFFSET]
CONST DWORD GAME_PLANT_NO_CD_OFFSET = 0xEE299; //重新种植更新当前冷却 偏移 [BaseAddress+GAME_PLANT_NO_CD_OFFSET]
CONST CHAR* GAME_CARD_NO_CD_PATCH_OPCODE = "\xC7\x42\x24\x00\x00\x00\x00\x90\x90\x90"; //重新种植更新当前冷却_重置冷却设为0 操作码
CONST CHAR* GAME_CARD_NO_CD_ORIGINAL_OPCODE = "\x89\x42\x24\xC7\x42\x20\x00\x00\x00\x00"; //重新种植更新当前冷却_原码 操作码
CONST DWORD GAME_PLANT_IGNORE_CD_OFFSET = 0xEBD3D; //判断冷却是否结束 偏移 [BaseAddress+GAME_PLANT_IGNORE_CD_OFFSET]
CONST DWORD GAME_PLANT_IGNORE_CD_OFFSET = 0xEE53D; //判断冷却是否结束 偏移 [BaseAddress+GAME_PLANT_IGNORE_CD_OFFSET]
CONST CHAR* GAME_CARD_IGNORE_CD_PATCH_OPCODE = "\x90\x90"; //判断冷却是否结束_不判断 操作码
CONST CHAR* GAME_CARD_IGNORE_CD_ORIGINAL_OPCODE = "\x39\x08"; //判断冷却是否结束_原码 操作码
195 changes: 98 additions & 97 deletions GhTrTool/GhTr.cpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion GhTrTool/GhTr.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <filesystem>
#include "json.hpp"
#define GAME_NAME L"Plants Vs Zombies GhTr ~ Perfect Voyage ver.0.16m"
#define GAME_NAME L"Plants Vs Zombies GhTr ~ Perfect Voyage ver.0.16n"

class GhTrManager
{
Expand Down Expand Up @@ -126,9 +126,11 @@ class GhTrManager
void SwitchToRedStingerMode();
//Ub不碎档
void DisableUbSaveDestroy(bool isFeatureEnabled);
#ifdef _DEBUG
//解包grp
void UnpackGrpFile();
//打包grp
void PackGrpFile();
#endif
};

Binary file modified GhTrTool/GhTrTool.rc
Binary file not shown.
26 changes: 20 additions & 6 deletions GhTrTool/GhTrToolDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ BEGIN_MESSAGE_MAP(CGhTrToolDlg, CDialogEx)
ON_BN_CLICKED(IDC_BTN_MakePlantsInvincible, &CGhTrToolDlg::OnBnClickedBtnMakePlantsInvincible)
ON_BN_CLICKED(IDC_BTN_PreventItemDeterioration, &CGhTrToolDlg::OnBnClickedBtnPreventItemDeterioration)
ON_BN_CLICKED(IDC_BTN_DisableUbSaveDestroy, &CGhTrToolDlg::OnBnClickedBtnDisableUbSaveDestroy)
#ifdef _DEBUG
ON_BN_CLICKED(IDC_BTN_UnpackGrpFile, &CGhTrToolDlg::OnBnClickedBtnUnpackGrpFile)
ON_BN_CLICKED(IDC_BTN_PackGrpFile, &CGhTrToolDlg::OnBnClickedBtnPackGrpFile)
#else
ON_BN_CLICKED(IDC_BTN_UnpackGrpFile, &CGhTrToolDlg::DebugOnlyMessageBox)
ON_BN_CLICKED(IDC_BTN_PackGrpFile, &CGhTrToolDlg::DebugOnlyMessageBox)
#endif
ON_BN_CLICKED(IDC_BTN_EnableOpticaltropFrameDamage, &CGhTrToolDlg::OnBnClickedBtnEnableOpticaltropFrameDamage)
ON_BN_CLICKED(IDC_BTN_PlantWithoutSunCost, &CGhTrToolDlg::OnBnClickedBtnPlantWithoutSunCost)
ON_BN_CLICKED(IDC_BTN_CompleteLevelWithTrophy, &CGhTrToolDlg::OnBnClickedBtnCompleteLevelWithTrophy)
Expand Down Expand Up @@ -198,14 +203,15 @@ BOOL CGhTrToolDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
UpdateText();
GetDlgItem(IDC_BTN_UnpackGrpFile)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_PackGrpFile)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_PACK)->ShowWindow(SW_HIDE);
#ifdef _DEBUG
#ifdef _DEBUG
GetDlgItem(IDC_BTN_UnpackGrpFile)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BTN_PackGrpFile)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATIC_PACK)->ShowWindow(SW_SHOW);
#endif
#else
GetDlgItem(IDC_BTN_UnpackGrpFile)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BTN_PackGrpFile)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_PACK)->ShowWindow(SW_HIDE);
#endif
CMenu* pMenu = new CMenu();
pMenu->LoadMenu(IDR_MENU1); // 使用实际的菜单资源ID代替
SetMenu(pMenu);
Expand Down Expand Up @@ -285,6 +291,13 @@ HCURSOR CGhTrToolDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
#ifdef _DEBUG
#else
void CGhTrToolDlg::DebugOnlyMessageBox()
{
MessageBoxA(NULL, "该功能仅供DEBUG使用,RELEASE编译模式无法使用。", "提示", MB_OK | MB_ICONERROR);
}
#endif
void CGhTrToolDlg::ToggleFeature(UINT nID, void (GhTrManager::* featureFunc)(bool))
{
GhTrManager GhTr;
Expand Down Expand Up @@ -521,6 +534,7 @@ void CGhTrToolDlg::OnBnClickedBtnDisableUbSaveDestroy()
{
ToggleFeature(IDC_BTN_DisableUbSaveDestroy, &GhTrManager::DisableUbSaveDestroy);
}
#ifdef _DEBUG

void CGhTrToolDlg::OnBnClickedBtnUnpackGrpFile()
{
Expand All @@ -533,7 +547,7 @@ void CGhTrToolDlg::OnBnClickedBtnPackGrpFile()
GhTrManager GhTr = GhTrManager();
GhTr.PackGrpFile();
}

#endif
void CGhTrToolDlg::OnBnClickedBtnInstantSunGeneration()
{
ToggleFeature(IDC_BTN_InstantSunGeneration, &GhTrManager::InstantSunGeneration);
Expand Down
3 changes: 3 additions & 0 deletions GhTrTool/GhTrToolDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CGhTrToolDlg : public CDialogEx
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
void DebugOnlyMessageBox();
void ToggleFeature(UINT nID, void(GhTrManager::* featureFunc)(bool));
void PlantAtPositions(GhTrManager& GhTr, DWORD dwXP, DWORD dwYP, DWORD dwID);
DECLARE_MESSAGE_MAP()
Expand Down Expand Up @@ -78,8 +79,10 @@ class CGhTrToolDlg : public CDialogEx
afx_msg void OnBnClickedBtnMaintainMaximumPowerPlantSize();
afx_msg void OnBnClickedBtnPreventItemDeterioration();
afx_msg void OnBnClickedBtnDisableUbSaveDestroy();
#ifdef _DEBUG
afx_msg void OnBnClickedBtnUnpackGrpFile();
afx_msg void OnBnClickedBtnPackGrpFile();
#endif
afx_msg void OnBnClickedBtnInstantSunGeneration();
afx_msg void OnBnClickedBtnDeployFormationInstantly();
afx_msg void OnBnClickedBtnModifyEnableFrameDamageData();
Expand Down
7 changes: 5 additions & 2 deletions GhTrTool/InfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ BOOL InfoDialog::OnInitDialog()
{_T("苹果鼓瑟手"), _T("11")},
{_T("滇池牡丹"), _T("12")},
{_T("导藓"), _T("13")},
{_T("土豆地雷"), _T("14")},
{_T("淀粉海"), _T("15")},
{_T("淀粉海"), _T("14")},
{_T("伶初玫瑰"), _T("15")},
{_T("磁力菇"), _T("16")},
{_T("土豆地雷"), _T("17")},
};
// 插入列
m_List.InsertColumn(0, _T("植物名称"), LVCFMT_LEFT, 100);
Expand Down Expand Up @@ -92,6 +94,7 @@ BOOL InfoDialog::OnInitDialog()
{_T("迷蒙之沼"), _T("6")},
{_T("迷蒙神隐"), _T("7")},
{_T("绽凌原野"), _T("8")},
{_T("绽凌殿"), _T("9")},
};
// 插入列
m_List3.InsertColumn(0, _T("背景名称"), LVCFMT_LEFT, 100);
Expand Down
56 changes: 50 additions & 6 deletions GhTrTool/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ struct FileInfoNode {
}
};

const wchar_t* GAME_TITLE = L"Plants Vs Zombies GhTr ~ Perfect Voyage ver.0.16m";
const wchar_t* GAME_TITLE = L"Plants Vs Zombies GhTr ~ Perfect Voyage ver.0.16n";
const wchar_t* GAME_PROCESS_NAME_CAPITAL = L"PlantsVsZombies.exe";
const wchar_t* GAME_PROCESS_NAME_LOWER = L"plantsvszombies.exe";

constexpr auto MAGIC_NUM = 0xC04AC0BA;
constexpr auto VERSION_NUM = (0xFFFFFFFF ^ 0xFFFFFFFF);
constexpr auto XOR_KEY = (0xFFFFFFFF ^ 0x14141414);

/**
* 转码UTF8
*
* @param wstr 目标转换字符串
*/
std::string utf8_encode(const std::wstring& wstr)
{
if (wstr.empty())
Expand All @@ -28,7 +32,11 @@ std::string utf8_encode(const std::wstring& wstr)
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, nullptr, nullptr);
return str;
}

/**
* 解码UTF8
*
* @param str 目标转换字符串
*/
std::wstring utf8_decode(const std::string& str)
{
if (str.empty())
Expand All @@ -38,6 +46,14 @@ std::wstring utf8_decode(const std::string& str)
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size_needed);
return wstr;
}
/**
* 查找文件夹内所有文件并建表
*
* @param find_path 查找的目录
* @param files_name 文件名数组
* @param files_size 文件大小数组
* @param files_time 文件修改时间数组
*/
void find_files(const std::wstring find_path,
std::vector<std::wstring>& files_name,
std::vector<int>& files_size,
Expand Down Expand Up @@ -80,6 +96,11 @@ void find_files(const std::wstring find_path,
FindClose(hf);
}
}
/**
* 创建目标解包路径文件夹
*
* @param path 要创建的目录地址
*/
bool create_path(const std::wstring& path)
{
if (path == L"")
Expand All @@ -94,7 +115,10 @@ bool create_path(const std::wstring& path)
return false;
return CreateDirectoryW(path.c_str(), nullptr);
}

/**
* 弹出选择文件夹对话框
*
*/
std::filesystem::path SelectFolder()
{
CFolderPickerDialog folderPickerDialog(NULL, OFN_ENABLESIZING | OFN_OVERWRITEPROMPT, NULL, 0);
Expand All @@ -105,9 +129,19 @@ std::filesystem::path SelectFolder()
}
return resultPath;
}
/**
* 交换字节顺序
*
* @param x 要交换的字节
*/
unsigned char swapNibbles(unsigned char x) {
return (x << 4) | (x >> 4);
}
/**
* 交换DWORD所有字节的顺序
*
* @param val 要交换的DWORD变量
*/
unsigned long swapBytesInLong(unsigned long val) {
unsigned long result = 0;
result |= (unsigned long)swapNibbles((unsigned char)(val & 0xFF)) << 24;
Expand All @@ -116,10 +150,20 @@ unsigned long swapBytesInLong(unsigned long val) {
result |= (unsigned long)swapNibbles((unsigned char)((val >> 24) & 0xFF));
return result;
}
void OpenFolder(const CString& unpackFolderName)
/**
* 打开一个文件夹
*
* @param FolderName 要打开的文件夹地址
*/
void OpenFolder(const CString& FolderName)
{
ShellExecute(NULL, _T("open"), LPCTSTR(unpackFolderName), NULL, NULL, SW_SHOWDEFAULT);
ShellExecute(NULL, _T("open"), LPCTSTR(FolderName), NULL, NULL, SW_SHOWDEFAULT);
}
/**
* 打开一个文件夹并选中文件
*
* @param itemName 要选中的文件地址
*/
void OpenFolderAndSelectItem(const std::wstring& itemName)
{
wchar_t buffer[MAX_PATH];
Expand Down
Binary file modified GhTrTool/resource.h
Binary file not shown.
Binary file modified Image/AboutGUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Image/GameTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Image/InfoGUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Image/MainGUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ PlantsVsZombies ~ GhTr *PersonGames Tools*

[+]what *functions* r needed, pls click [here](https://github.com/Xcating/GhTrTool/issues) propose and **TRY** todo it as well as ***possible***
### [#]修改 Modified
[+]修改了偏移,适配于GhTr.0.16m版本
[+]修改了偏移,适配于GhTr.0.16n版本

[+]Modify offset handling to support GhTr 0.16m version
[+]Modify offset handling to support GhTr 0.16n version
### [#]工具截图 Screenshot
[+]工具版本:0.11w
[+]工具版本:0.11x

[+]Tools Version: 0.11w
[+]Tools Version: 0.11x
![MainGUI](/Image/MainGUI.png "MainGUI")
![GameTest](/Image/GameTest.png "GameTest")

Expand Down

0 comments on commit 3f43413

Please sign in to comment.