翻译FusionFix菜单项

This commit is contained in:
ckeleshi committed 2024-06-09 18:14:05 +08:00
1 parent c9c94bf4b3
commit 42e50fbd1b
16 files changed
+242 -251

No files matched your search

+1 -8
View File
@@ -1,14 +1,7 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.28)
project(gta4_chs)
find_package(utf8cpp CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
add_subdirectory(plugin)
add_subdirectory(whm_io)
+8 -11
View File
@@ -2,9 +2,8 @@
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"name": "windows-x86-base",
"description": "面向具有 Visual Studio 开发环境的 Windows。",
"hidden": true,
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
@@ -24,22 +23,20 @@
"VCPKG_TARGET_TRIPLET": "x86-windows-static",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
}
],
"buildPresets": [
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
"configurePreset": "windows-x86-base",
"configuration": "Debug"
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "windows-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
"configurePreset": "windows-x86-base",
"configuration": "Release"
}
]
}
+3
View File
@@ -1,5 +1,8 @@
-----------todo-----------
json自定义翻译功能
91C777 call CFont::ProcessString
922BA4 call CFont::ProcessString
某些邮件回复时崩溃
*craplist.net邮件排版问题(最低优先)
+1
View File
@@ -31,6 +31,7 @@
#include "injector/calling.hpp"
#include "injector/hooking.hpp"
#include "injector/injector.hpp"
#include "injector/utility.hpp"
// vcpkg
#include <fmt/printf.h>
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.28)
project(plugin)
+30 -25
View File
@@ -11,21 +11,21 @@ static const float fTextureRowsCount = fTextureResolution / fSpriteHeight;
static const float fTextureColumnsCount = fTextureResolution / fSpriteWidth;
static const float fRatio = 4.0f;
void *CNFont;
void* CNFont;
void *__fastcall CFont::LoadTextureCB(void *pDictionary, int, uint hash)
void* __fastcall CFont::LoadTextureCB(void* pDictionary, int, uint hash)
{
auto result = plugin.game.Dictionary_grcTexturePC_GetElementByKey(pDictionary, hash);
CNFont = plugin.game.Dictionary_grcTexturePC_GetElementByKey(pDictionary,
plugin.game.Hash_HashStringFromSeediCase("font_chs"));
plugin.game.Hash_HashStringFromSeediCase("font_chs"));
return result;
}
const GTAChar *CFont::SkipWord_Prolog(std::uintptr_t address)
const GTAChar* CFont::SkipWord_Prolog(std::uintptr_t address)
{
auto ptr = reinterpret_cast<const GTAChar *>(address & 0x7FFFFFFF);
auto ptr = reinterpret_cast<const GTAChar*>(address & 0x7FFFFFFF);
if ((address & 0x80000000) == 0)
{
@@ -57,7 +57,7 @@ bool CFont::IsSpecialPunctuationMark(GTAChar chr)
#endif
}
void CFont::SkipSpecialPunctuationMarks(const GTAChar *&str)
void CFont::SkipSpecialPunctuationMarks(const GTAChar*& str)
{
while (IsSpecialPunctuationMark(*str))
{
@@ -65,7 +65,7 @@ void CFont::SkipSpecialPunctuationMarks(const GTAChar *&str)
}
}
void CFont::AddSpecialPunctuationMarksWidth(const GTAChar *&str, float *width)
void CFont::AddSpecialPunctuationMarksWidth(const GTAChar*& str, float* width)
{
while (IsSpecialPunctuationMark(*str))
{
@@ -74,7 +74,7 @@ void CFont::AddSpecialPunctuationMarksWidth(const GTAChar *&str, float *width)
}
}
const GTAChar *CFont::SkipWord(const GTAChar *str)
const GTAChar* CFont::SkipWord(const GTAChar* str)
{
if (str == nullptr)
{
@@ -113,7 +113,7 @@ const GTAChar *CFont::SkipWord(const GTAChar *str)
return current;
}
const GTAChar *CFont::SkipSpaces(const GTAChar *text)
const GTAChar* CFont::SkipSpaces(const GTAChar* text)
{
if (text == nullptr)
return text;
@@ -126,7 +126,7 @@ const GTAChar *CFont::SkipSpaces(const GTAChar *text)
return text;
}
float CFont::GetMaxWordWidth(const GTAChar *text)
float CFont::GetMaxWordWidth(const GTAChar* text)
{
if (text == nullptr)
return 0.0f;
@@ -146,12 +146,12 @@ float CFont::GetMaxWordWidth(const GTAChar *text)
return max_word_width;
}
float CFont::GetStringWidthRemake(const GTAChar *str, bool get_all)
float CFont::GetStringWidthRemake(const GTAChar* str, bool get_all)
{
float current_width = 0.0f, max_width = 0.0f;
bool had_word = false;
auto render_index = plugin.game.Font_GetRenderIndex();
auto &using_details = plugin.game.game_addr.pFont_Details[render_index];
auto& using_details = plugin.game.game_addr.pFont_Details[render_index];
TokenStruct token_data;
GTAChar token_string[64];
@@ -225,7 +225,7 @@ float CFont::GetStringWidthRemake(const GTAChar *str, bool get_all)
case 1: {
// 91BF26
current_width += plugin.game.game_addr.pFont_ButtonWidths[token_data.f0[token_index] - 255] *
using_details.fBlipScaleX;
using_details.fBlipScaleX;
had_word = true;
break;
@@ -305,17 +305,22 @@ float CFont::GetStringWidthRemake(const GTAChar *str, bool get_all)
return std::max(current_width, max_width);
}
void CFont::ProcessStringRoutine(float x, float y, const GTAChar* str, void* a4)
{
plugin.game.Font_ProcessString(x, y, plugin.string_table.GetString(str), a4);
}
float CFont::GetCHSCharacterSizeNormal()
{
auto render_index = plugin.game.Font_GetRenderIndex();
auto &using_details = plugin.game.game_addr.pFont_Details[render_index];
auto &using_font_data = plugin.game.game_addr.pFont_Datas[using_details.nFont];
auto& using_details = plugin.game.game_addr.pFont_Details[render_index];
auto& using_font_data = plugin.game.game_addr.pFont_Datas[using_details.nFont];
float extra_width = using_font_data.fWidthOfSpaceBetweenChars[using_details.nExtraWidthIndex];
return (((fChsWidth + fChsWidthFix + extra_width) / *plugin.game.game_addr.pFont_ResolutionX +
using_details.fEdgeSize2) *
using_details.fScaleX);
using_details.fEdgeSize2) *
using_details.fScaleX);
}
float CFont::GetCharacterSizeNormalDispatch(GTAChar chr)
@@ -335,7 +340,7 @@ float CFont::GetCHSCharacterSizeDrawing(bool use_extra_width)
float extra_width = 0.0f;
auto render_state = plugin.game.game_addr.pFont_RenderState;
auto &using_font_data = plugin.game.game_addr.pFont_Datas[render_state->nFont];
auto& using_font_data = plugin.game.game_addr.pFont_Datas[render_state->nFont];
if (use_extra_width)
{
@@ -343,8 +348,8 @@ float CFont::GetCHSCharacterSizeDrawing(bool use_extra_width)
}
return ((fChsWidth + fChsWidthFix + extra_width) / *plugin.game.game_addr.pFont_ResolutionX +
render_state->fEdgeSize) *
render_state->fScaleX;
render_state->fEdgeSize) *
render_state->fScaleX;
}
float CFont::GetCharacterSizeDrawingDispatch(GTAChar chr, bool use_extra_width)
@@ -406,23 +411,23 @@ void CFont::PrintCHSChar(float x, float y, GTAChar chr)
auto new_range = new_ub - new_lb;
return old_diff / old_range * new_range + new_lb;
};
};
// 将virtual_char_rect投影到old_screen_rect中,得到real_screen_rect
CRect real_screen_rect;
// 计算y的第二个参数越小,字的y长度越大
real_screen_rect.top_right.x = flt_proj(0.0f, 64.0f, relative_char_rect.top_right.x, old_screen_rect.bottom_left.x,
old_screen_rect.top_right.x);
old_screen_rect.top_right.x);
real_screen_rect.top_right.y = flt_proj(0.0f, 74.4912f, relative_char_rect.top_right.y, old_screen_rect.top_right.y,
old_screen_rect.bottom_left.y);
old_screen_rect.bottom_left.y);
real_screen_rect.bottom_left.x = flt_proj(0.0f, 64.0f, relative_char_rect.bottom_left.x,
old_screen_rect.bottom_left.x, old_screen_rect.top_right.x);
old_screen_rect.bottom_left.x, old_screen_rect.top_right.x);
real_screen_rect.bottom_left.y = flt_proj(0.0f, 74.4912f, relative_char_rect.bottom_left.y,
old_screen_rect.top_right.y, old_screen_rect.bottom_left.y);
old_screen_rect.top_right.y, old_screen_rect.bottom_left.y);
switch (render_state->nFont)
{
+16 -14
View File
@@ -12,7 +12,7 @@ enum eTextAlignment
class CFontDetails
{
public:
public:
uint field_0;
float fScaleX;
float fScaleY;
@@ -46,7 +46,7 @@ VALIDATE_SIZE(CFontDetails, 0x48);
class CFontInfo
{
public:
public:
uchar iPropValues[255];
uchar iTextureMap[255];
char pad1[2];
@@ -62,7 +62,7 @@ class CFontInfo
int iSubFont2End;
int iCommonFontStart;
int iCommonFontEnd;
void *pTexture;
void* pTexture;
float fTextureWidth;
float fTextureHeight;
float fSpriteSize;
@@ -73,7 +73,7 @@ VALIDATE_SIZE(CFontInfo, 0x258);
class CFontRenderState
{
public:
public:
uint magic;
float field_4;
float field_8;
@@ -99,7 +99,7 @@ VALIDATE_SIZE(CFontRenderState, 0x38);
class CFontBuffer
{
public:
public:
CFontRenderState render_state;
GTAChar buffer[996];
};
@@ -119,8 +119,8 @@ VALIDATE_SIZE(TokenStruct, 0x114);
class CFont
{
public:
static void *__fastcall LoadTextureCB(void *, int, uint);
public:
static void* __fastcall LoadTextureCB(void*, int, uint);
static float GetCharacterSizeNormalDispatch(GTAChar chr);
static float GetCHSCharacterSizeNormal();
@@ -134,14 +134,16 @@ class CFont
// 判断字符是否为不能放在行首的标点符号
static bool IsSpecialPunctuationMark(GTAChar chr);
// 将特殊字符看作单词的一部分
static void SkipSpecialPunctuationMarks(const GTAChar *&str);
static void AddSpecialPunctuationMarksWidth(const GTAChar *&str, float *width);
static void SkipSpecialPunctuationMarks(const GTAChar*& str);
static void AddSpecialPunctuationMarksWidth(const GTAChar*& str, float* width);
static const GTAChar *SkipWord(const GTAChar *str);
static const GTAChar *SkipWord_Prolog(std::uintptr_t address);
static const GTAChar *SkipSpaces(const GTAChar *text);
static const GTAChar* SkipWord(const GTAChar* str);
static const GTAChar* SkipWord_Prolog(std::uintptr_t address);
static const GTAChar* SkipSpaces(const GTAChar* text);
static float GetMaxWordWidth(const GTAChar *text);
static float GetMaxWordWidth(const GTAChar* text);
static float GetStringWidthRemake(const GTAChar *str, bool get_all);
static float GetStringWidthRemake(const GTAChar* str, bool get_all);
static void ProcessStringRoutine(float x, float y, const GTAChar* str, void* a4);
};
+18 -13
View File
@@ -1,9 +1,9 @@
#include "game.h"
#include "plugin.h"
void CGame::Graphics_SetRenderState(void *texture, int arg4)
void CGame::Graphics_SetRenderState(void* texture, int arg4)
{
injector::cstd<void(void *, int)>::call(game_addr.fnGraphics_SetRenderState, texture, arg4);
injector::cstd<void(void*, int)>::call(game_addr.fnGraphics_SetRenderState, texture, arg4);
}
void* CGame::Dictionary_grcTexturePC_GetElementByKey(void* dictionary, uint hash)
@@ -31,9 +31,9 @@ float CGame::Font_GetCharacterSizeDrawing(GTAChar chr, bool use_extra_width)
return injector::cstd<float(GTAChar, bool)>::call(game_addr.fnFont_GetCharacterSizeDrawing, chr, use_extra_width);
}
void CGame::Font_Render2DPrimitive(const CRect *screen_rect, const CRect *texture_rect, uint color, bool buffered)
void CGame::Font_Render2DPrimitive(const CRect* screen_rect, const CRect* texture_rect, uint color, bool buffered)
{
injector::cstd<void(const CRect *, const CRect *, uint, bool)>::call(game_addr.fnFont_Render2DPrimitive, screen_rect, texture_rect, color, buffered);
injector::cstd<void(const CRect*, const CRect*, uint, bool)>::call(game_addr.fnFont_Render2DPrimitive, screen_rect, texture_rect, color, buffered);
}
void CGame::Font_PrintChar(float posx, float posy, GTAChar chr, bool buffered)
@@ -41,26 +41,31 @@ void CGame::Font_PrintChar(float posx, float posy, GTAChar chr, bool buffered)
injector::cstd<void(float, float, GTAChar, bool)>::call(game_addr.fnFont_PrintChar, posx, posy, chr, buffered);
}
int CGame::Font_ParseToken(const GTAChar *text, GTAChar *text_to_show, TokenStruct *token_data)
void CGame::Font_ProcessString(float posx, float posy, const GTAChar* str, void* a4)
{
return injector::cstd<int(const GTAChar *, GTAChar *, TokenStruct *)>::call(
injector::cstd<void(float, float, const GTAChar*, void*)>::call(game_addr.fnFont_ProcessString, posx, posy, str, a4);
}
int CGame::Font_ParseToken(const GTAChar* text, GTAChar* text_to_show, TokenStruct* token_data)
{
return injector::cstd<int(const GTAChar*, GTAChar*, TokenStruct*)>::call(
game_addr.fnFont_ParseToken, text, text_to_show, token_data);
}
const GTAChar *CGame::Font_ProcessToken(const GTAChar *text, uint *color, bool get_color, uchar *color_code,
int *key_number, bool *is_new_line_token, GTAChar *text_to_show, TokenStruct *token_data)
const GTAChar* CGame::Font_ProcessToken(const GTAChar* text, uint* color, bool get_color, uchar* color_code,
int* key_number, bool* is_new_line_token, GTAChar* text_to_show, TokenStruct* token_data)
{
return injector::cstd<const GTAChar *(const GTAChar *, uint *, bool, uchar *, int *, bool *, GTAChar *, TokenStruct *)>::call(
return injector::cstd<const GTAChar * (const GTAChar*, uint*, bool, uchar*, int*, bool*, GTAChar*, TokenStruct*)>::call(
game_addr.fnFont_ProcessToken, text, color, get_color, color_code, key_number, is_new_line_token,
text_to_show, token_data);
}
void CGame::Font_AddTokenStringWidth(const GTAChar *text, float *width, int render_index)
void CGame::Font_AddTokenStringWidth(const GTAChar* text, float* width, int render_index)
{
return injector::cstd<void(const GTAChar *, float *, int)>::call(game_addr.fnFont_AddTokenStringWidth, text, width, render_index);
return injector::cstd<void(const GTAChar*, float*, int)>::call(game_addr.fnFont_AddTokenStringWidth, text, width, render_index);
}
void CGame::MailAppendByteString(int id, const uchar *str)
void CGame::MailAppendByteString(int id, const uchar* str)
{
injector::stdcall<void(int, const uchar *)>::call(game_addr.fnMailAppendByteString, id, str);
injector::stdcall<void(int, const uchar*)>::call(game_addr.fnMailAppendByteString, id, str);
}
+35 -33
View File
@@ -4,61 +4,63 @@
class CGame
{
public:
public:
struct
{
IDirect3DDevice9 **ppD3DDevice;
void *pTexturePCVirtualTable;
void *fnGraphics_SetRenderState;
void *fnDictionary_GetElementByKey;
void *fnHash_HashStringFromSeediCase;
int *pGameEpisodeID;
IDirect3DDevice9** ppD3DDevice;
void* pTexturePCVirtualTable;
void* fnGraphics_SetRenderState;
void* fnDictionary_GetElementByKey;
void* fnHash_HashStringFromSeediCase;
int* pGameEpisodeID;
CFontInfo *pFont_Datas;
CFontDetails *pFont_Details;
CFontRenderState *pFont_RenderState;
CFontInfo* pFont_Datas;
CFontDetails* pFont_Details;
CFontRenderState* pFont_RenderState;
float *pFont_BlipWidth;
float *pFont_ResolutionX;
float *pFont_ButtonWidths;
float* pFont_BlipWidth;
float* pFont_ResolutionX;
float* pFont_ButtonWidths;
void *fnFont_GetRenderIndex;
void *fnFont_PrintChar;
void *fnFont_GetCharacterSizeNormal;
void *fnFont_GetCharacterSizeDrawing;
void *fnFont_Render2DPrimitive;
void *fnFont_AddTokenStringWidth;
void *fnFont_ParseToken;
void *fnFont_ProcessToken;
void* fnFont_GetRenderIndex;
void* fnFont_PrintChar;
void* fnFont_GetCharacterSizeNormal;
void* fnFont_GetCharacterSizeDrawing;
void* fnFont_Render2DPrimitive;
void* fnFont_AddTokenStringWidth;
void* fnFont_ParseToken;
void* fnFont_ProcessToken;
void* fnFont_ProcessString;
void *fnMailAppendByteString;
char *pDLCTruncateBuffer;
void* fnMailAppendByteString;
char* pDLCTruncateBuffer;
} game_addr;
void Graphics_SetRenderState(void *texture, int = 1);
void Graphics_SetRenderState(void* texture, int = 1);
void *Dictionary_grcTexturePC_GetElementByKey(void *dictionary, uint hash);
void* Dictionary_grcTexturePC_GetElementByKey(void* dictionary, uint hash);
uint Hash_HashStringFromSeediCase(const char *str, uint hash = 0);
uint Hash_HashStringFromSeediCase(const char* str, uint hash = 0);
uchar Font_GetRenderIndex();
float Font_GetCharacterSizeNormal(GTAChar chr);
float Font_GetCharacterSizeDrawing(GTAChar chr, bool use_extra_width);
void Font_Render2DPrimitive(const CRect *screen_rect, const CRect *texture_rect, uint color, bool buffered);
void Font_Render2DPrimitive(const CRect* screen_rect, const CRect* texture_rect, uint color, bool buffered);
void Font_PrintChar(float posx, float posy, GTAChar chr, bool buffered);
void Font_ProcessString(float posx, float posy, const GTAChar* str, void* a4);
// ParseToken逻辑
// 1000+ BLIP
// 256-300 按键类
// 全部strcmp都不通过则当成单字符token,返回此字符
int Font_ParseToken(const GTAChar *text, GTAChar *text_to_show, TokenStruct *token_data);
int Font_ParseToken(const GTAChar* text, GTAChar* text_to_show, TokenStruct* token_data);
const GTAChar *Font_ProcessToken(const GTAChar *text, uint *color, bool get_color, uchar *color_code,
int *key_number, bool *is_new_line_token, GTAChar *text_to_show,
TokenStruct *token_data);
const GTAChar* Font_ProcessToken(const GTAChar* text, uint* color, bool get_color, uchar* color_code,
int* key_number, bool* is_new_line_token, GTAChar* text_to_show,
TokenStruct* token_data);
void Font_AddTokenStringWidth(const GTAChar *text, float *width, int render_index);
void Font_AddTokenStringWidth(const GTAChar* text, float* width, int render_index);
void MailAppendByteString(int id, const uchar *str);
void MailAppendByteString(int id, const uchar* str);
};
+102 -121
View File
@@ -4,148 +4,129 @@
namespace gta_font
{
static const char *__stdcall GetTextFileName(int)
{
return "chinese.gxt";
}
// 922095
__declspec(naked) void ProcessToken_Epilog()
{
__asm
// 922095
__declspec(naked) void ProcessToken_Epilog()
{
pop edi;
call plugin.game.game_addr.fnFont_ProcessToken;
or eax, 0x80000000;
jmp edi;
__asm
{
pop edi;
call plugin.game.game_addr.fnFont_ProcessToken;
or eax, 0x80000000;
jmp edi;
}
}
}
// 922120
__declspec(naked) void ProcessToken_Epilog2()
{
__asm
// 922120
__declspec(naked) void ProcessToken_Epilog2()
{
and edi,0x7FFFFFFF;
movzx eax,word ptr[edi-4];
sub edi,4;
ret;
__asm
{
and edi, 0x7FFFFFFF;
movzx eax, word ptr[edi - 4];
sub edi, 4;
ret;
}
}
}
// 922147
__declspec(naked) void ProcessToken_Epilog3()
{
__asm
// 922147
__declspec(naked) void ProcessToken_Epilog3()
{
and edi,0x7FFFFFFF;
mov [esp+0x16], cl;
test cl,cl;
ret;
__asm
{
and edi, 0x7FFFFFFF;
mov[esp + 0x16], cl;
test cl, cl;
ret;
}
}
}
static char *strncpy_for_datfile_section(char *dst, char *src, uint count)
{
return std::strncpy(dst, "content_chs.dat", count);
}
void register_patches(batch_matching& batch_matcher)
{
// 搜索"~%c~"找到CFont::ProcessString
void register_patches(batch_matching &batch_matcher)
{
// 搜索"~%c~"找到CFont::ProcessString
//储存CFont::ProcessString地址
batch_matcher.register_step("81 EC 8C 0A 00 00", 1, [](const byte_pattern::result_type& addresses) {
plugin.game.game_addr.fnFont_ProcessString = addresses[0].p();
});
// ProcessToken epilog
batch_matcher.register_step("89 AC 24 80 00 00 00 E8", 1, [](const byte_pattern::result_type &addresses) {
plugin.game.game_addr.fnFont_ProcessToken = injector::GetBranchDestination(addresses[0].i(7)).get();
injector::MakeCALL(addresses[0].i(7), ProcessToken_Epilog);
});
//劫持菜单项的CFont::ProcessString
batch_matcher.register_step("F3 0F 10 44 24 18 8B C1 50", 1, [](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(33), CFont::ProcessStringRoutine);
});
// ProcessString token branch2
batch_matcher.register_step("0F B7 47 FC 83 EF 04", 1, [](const std::vector<memory_pointer> &addresses) {
injector::MakeCALL(addresses[0].i(), ProcessToken_Epilog2);
injector::MakeNOP(addresses[0].i(5), 2);
});
// ProcessToken epilog
batch_matcher.register_step("89 AC 24 80 00 00 00 E8", 1, [](const byte_pattern::result_type& addresses) {
plugin.game.game_addr.fnFont_ProcessToken = injector::GetBranchDestination(addresses[0].i(7)).get();
injector::MakeCALL(addresses[0].i(7), ProcessToken_Epilog);
});
// ProcessString token branch3
batch_matcher.register_step("88 4C 24 12 84 C9", 1, [](const std::vector<memory_pointer> &addresses) {
injector::MakeCALL(addresses[0].i(), ProcessToken_Epilog3);
injector::MakeNOP(addresses[0].i(5), 1);
});
// ProcessString token branch2
batch_matcher.register_step("0F B7 47 FC 83 EF 04", 1, [](const std::vector<memory_pointer>& addresses) {
injector::MakeCALL(addresses[0].i(), ProcessToken_Epilog2);
injector::MakeNOP(addresses[0].i(5), 2);
});
// CFont::ProcessString使用了
// 跳过单词
batch_matcher.register_step("57 8B 7C 24 08 85 FF 75 04 33 C0 5F C3 56", 1,
[](const byte_pattern::result_type &addresses) {
injector::MakeJMP(addresses[0].i(), CFont::SkipWord_Prolog);
});
// ProcessString token branch3
batch_matcher.register_step("88 4C 24 12 84 C9", 1, [](const std::vector<memory_pointer>& addresses) {
injector::MakeCALL(addresses[0].i(), ProcessToken_Epilog3);
injector::MakeNOP(addresses[0].i(5), 1);
});
// ProcessString使用了
// 获取字符宽度
batch_matcher.register_step("83 C0 E0 50 E8 ? ? ? ? D9 5C 24", 2, [](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(4), CFont::GetCharacterSizeNormalDispatch);
injector::MakeCALL(addresses[1].i(4), CFont::GetCharacterSizeNormalDispatch);
});
// CFont::ProcessString使用了
// 跳过单词
batch_matcher.register_step("57 8B 7C 24 08 85 FF 75 04 33 C0 5F C3 56", 1,
[](const byte_pattern::result_type& addresses) {
injector::MakeJMP(addresses[0].i(), CFont::SkipWord_Prolog);
});
// 查找GetCharacterSizeNormal的引用获得
batch_matcher.register_step("6A 01 57 E8 ? ? ? ? D9 5C 24 30", 1, [](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(3), CFont::GetCharacterSizeDrawingDispatch);
});
// ProcessString使用了
// 获取字符宽度
batch_matcher.register_step("83 C0 E0 50 E8 ? ? ? ? D9 5C 24", 2, [](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(4), CFont::GetCharacterSizeNormalDispatch);
injector::MakeCALL(addresses[1].i(4), CFont::GetCharacterSizeNormalDispatch);
});
// 查找GetCharacterSizeNormal的引用获得
batch_matcher.register_step("EB 12 6A 01 57 E8 ? ? ? ? D9 5C 24 24", 1,
[](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(5), CFont::GetCharacterSizeDrawingDispatch);
});
// 查找GetCharacterSizeNormal的引用获得
batch_matcher.register_step("6A 01 57 E8 ? ? ? ? D9 5C 24 30", 1, [](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(3), CFont::GetCharacterSizeDrawingDispatch);
});
// RenderSingleBuffer使用了
// 绘制字符
batch_matcher.register_step("F3 0F 11 0C 24 E8 ? ? ? ? 8B 35", 1, [](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(5), CFont::PrintCharDispatch);
});
// 查找GetCharacterSizeNormal的引用获得
batch_matcher.register_step("EB 12 6A 01 57 E8 ? ? ? ? D9 5C 24 24", 1,
[](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(5), CFont::GetCharacterSizeDrawingDispatch);
});
// 另一个使用PrintChar的函数里面
batch_matcher.register_step("E8 ? ? ? ? 6A 01 57 E8 ? ? ? ? D9 5C 24 30", 1,
[](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(), CFont::PrintCharDispatch);
});
// RenderSingleBuffer使用了
// 绘制字符
batch_matcher.register_step("F3 0F 11 0C 24 E8 ? ? ? ? 8B 35", 1, [](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(5), CFont::PrintCharDispatch);
});
// 搜索"font3"
// 修改本体字体文件名为fonts_chs
batch_matcher.register_step("80 7C 24 13 00 0F 85 6E 01 00 00", 2, [](const byte_pattern::result_type &addresses) {
injector::WriteMemory(addresses[0].i(12), "platform:/textures/fonts_chs", true);
injector::WriteMemory(addresses[1].i(12), "platform:/textures/fonts_chs", true);
});
// 另一个使用PrintChar的函数里面
batch_matcher.register_step("E8 ? ? ? ? 6A 01 57 E8 ? ? ? ? D9 5C 24 30", 1,
[](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(), CFont::PrintCharDispatch);
});
// 修改资料片字体文件名
// 935093 修改setup2.xml解析<datfile>的结果为content_chs.dat,在content_chs.dat中指定FONTTXD
batch_matcher.register_step("6A 20 50 8D 44 24 6C 50 E8", 1, [](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(8), strncpy_for_datfile_section);
});
// 加载fonts.wtd中的font_chs
batch_matcher.register_step("8B CE 50 E8 ? ? ? ? 80 3D ? ? ? ? 6A", 2,
[](const byte_pattern::result_type& addresses) {
injector::MakeCALL(addresses[0].i(3), CFont::LoadTextureCB);
injector::MakeCALL(addresses[1].i(3), CFont::LoadTextureCB);
});
// 加载fonts_chs.wtd中的font_chs
batch_matcher.register_step("8B CE 50 E8 ? ? ? ? 80 3D ? ? ? ? 6A", 2,
[](const byte_pattern::result_type &addresses) {
injector::MakeCALL(addresses[0].i(3), CFont::LoadTextureCB);
injector::MakeCALL(addresses[1].i(3), CFont::LoadTextureCB);
});
// ProcessString使用了
// GetStringWidth
batch_matcher.register_step("B8 B4 10 00 00", 1, [](const std::vector<memory_pointer>& addresses) {
injector::MakeJMP(addresses[0].i(-6), CFont::GetStringWidthRemake);
});
// 搜索"american.gxt"
// 改变GXT的文件名
batch_matcher.register_step("80 7C 24 04 00 56 8B F1 74 07", 1, [](const byte_pattern::result_type &addresses) {
injector::MakeJMP(addresses[0].i(), GetTextFileName);
});
// ProcessString使用了
// GetStringWidth
batch_matcher.register_step("B8 B4 10 00 00", 1, [](const std::vector<memory_pointer> &addresses) {
injector::MakeJMP(addresses[0].i(-6), CFont::GetStringWidthRemake);
});
// 使用了GetStringWidth
// GetMaxWordWidth
batch_matcher.register_step("51 56 8B 74 24 0C 85 F6 75 05 D9 EE 5E 59 C3 66", 1,
[](const std::vector<memory_pointer> &addresses) {
injector::MakeJMP(addresses[0].i(), CFont::GetMaxWordWidth);
});
}
// 使用了GetStringWidth
// GetMaxWordWidth
batch_matcher.register_step("51 56 8B 74 24 0C 85 F6 75 05 D9 EE 5E 59 C3 66", 1,
[](const std::vector<memory_pointer>& addresses) {
injector::MakeJMP(addresses[0].i(), CFont::GetMaxWordWidth);
});
}
} // namespace gta_font
+6 -6
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "../common/stdinc.h"
#include "../common/common.h"
@@ -6,20 +6,20 @@ namespace gta_string
{
unsigned gtaWcslen(const GTAChar* str);
//存档标题
//存档标题
uchar* gtaTruncateString(uchar* dst, const GTAChar* src, unsigned size);
void gtaExpandString(const uchar* src, GTAChar* dst);
//显示存档覆盖提示时用于格式化的存档名称
//显示存档覆盖提示时用于格式化的存档名称
void gtaExpandString2(GTAChar* dst, const uchar* src, int a8);
//TBoGT重玩任务选择界面
//TBoGT重玩任务选择界面
void gtaExpandString3(GTAChar* dst, const uchar* src, int a8);
//邮件/网页
//邮件/网页
void gtaTruncateString2(const GTAChar* src, uchar* dst);
void gtaExpandStringGxt(const uchar* src, GTAChar* dst);
//接收宽字符串,但转换成utf8
//接收宽字符串,但转换成utf8
void __stdcall gtaMailAppendWideStringAsUtf8(int id, const GTAChar* str);
uchar* gtaUTF8strncpy(uchar* dest, const uchar* source, unsigned size);
+1
View File
@@ -71,6 +71,7 @@ bool CPlugin::Init(HMODULE module)
char_table.LoadTable(GetPluginAsset("char_table.dat"));
whm_table.LoadTable(GetPluginAsset("whm_table.dat"));
string_table.LoadTable(GetPluginAsset("custom_translations.json"));
return true;
}
+4 -2
View File
@@ -5,6 +5,7 @@
#include "char_table.h"
#include "whm_table.h"
#include "game.h"
#include "string_table.h"
#include "../common/module_path.h"
class CPlugin
@@ -14,16 +15,17 @@ public:
HANDLE GetGameModule() const;
HANDLE GetPluginModule() const;
std::filesystem::path GetGameRoot() const;
std::filesystem::path GetPluginAsset(const std::filesystem::path &rest_path) const;
std::filesystem::path GetPluginAsset(const std::filesystem::path& rest_path) const;
//保证进入构造函数之后这些对象已经初始化了
ModulePath game_module_path, plugin_module_path;
CCharTable char_table;
CWhmTable whm_table;
CStringTable string_table;
CGame game;
private:
static void RegisterPatchSteps(batch_matching &batch_matcher);
static void RegisterPatchSteps(batch_matching& batch_matcher);
};
extern CPlugin plugin;
+12 -11
View File
@@ -1,15 +1,10 @@
#include "string_table.h"
#include "../common/fnv_hash.h"
CStringTable& CStringTable::GetInstance()
{
static CStringTable instance;
return instance;
}
void CStringTable::LoadTable(const std::filesystem::path& filename)
{
auto logger = spdlog::get("gta4.chs");
std::ifstream ifs(filename);
if (!ifs)
@@ -25,7 +20,8 @@ void CStringTable::LoadTable(const std::filesystem::path& filename)
{
auto origin = it.key();
auto translated = it.value().get<std::string>();
std::vector<GTAChar> utf16;
std::vector<GTAChar> worigin;
std::vector<GTAChar> wtranslated;
if (translated.empty()) {
continue;
@@ -33,18 +29,23 @@ void CStringTable::LoadTable(const std::filesystem::path& filename)
try
{
utf8::utf8to16(translated.begin(), translated.end(), std::back_inserter(utf16));
utf16.push_back(0);
m_Table.emplace(fnv_hash::hash_string(origin.c_str(), false), std::move(utf16));
utf8::utf8to16(origin.begin(), origin.end(), std::back_inserter(worigin));
worigin.push_back(0);
utf8::utf8to16(translated.begin(), translated.end(), std::back_inserter(wtranslated));
wtranslated.push_back(0);
m_Table.emplace(fnv_hash::hash_string(worigin.data(), false), std::move(wtranslated));
}
catch (utf8::exception&)
{
logger->error("Utf8 convert failed.");
continue;
}
}
}
catch (nlohmann::json::exception&)
{
logger->error("Json processing failed.");
return;
}
}
+3 -5
View File
@@ -5,14 +5,12 @@
class CStringTable
{
public:
static CStringTable& GetInstance();
CStringTable() = default;
~CStringTable() = default;
void LoadTable(const std::filesystem::path& filename);
const GTAChar* GetString(const GTAChar* origin) const;
private:
CStringTable() = default;
~CStringTable() = default;
std::unordered_map<std::uint64_t, std::vector<GTAChar>> m_Table;
std::unordered_map<std::size_t, std::vector<GTAChar>> m_Table;
};
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.28)
project(whm_io)