This commit is contained in:
ClansChen committed 2024-06-03 17:19:22 +08:00
1 parent b7f40a2e60
commit adc2577fd0
20 files changed
+253 -147

No files matched your search

+1 -2
View File
@@ -2,7 +2,6 @@ build/
.cache/
.vscode/
.xmake/
CMakeSettings.json
CMakePresets.json
CMakeUserPresets.json
.vs/
out/
-15
View File
@@ -1,17 +1,7 @@
cmake_minimum_required(VERSION 3.24)
set(CMAKE_CXX_STANDARD 20)
project(gta4_chs)
add_definitions(-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
include("VC-LTL helper for cmake.cmake")
file(GLOB common_sources "common/*.cpp")
find_package(utf8cpp CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
@@ -22,8 +12,3 @@ find_package(ZLIB REQUIRED)
add_subdirectory(plugin)
add_subdirectory(whm_io)
target_precompile_headers(GTA4.CHS PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/common/stdinc.h")
target_precompile_headers(whm_io PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/common/stdinc.h")
target_link_libraries(GTA4.CHS PRIVATE utf8::cpp range-v3 range-v3-meta range-v3::meta range-v3-concepts fmt::fmt-header-only spdlog::spdlog_header_only)
target_link_libraries(whm_io PRIVATE range-v3 range-v3-meta range-v3::meta range-v3-concepts ZLIB::ZLIB fmt::fmt-header-only rapidjson)
+45
View File
@@ -0,0 +1,45 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"description": "面向具有 Visual Studio 开发环境的 Windows。",
"hidden": true,
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_CXX_STANDARD": "20",
"VCPKG_TARGET_TRIPLET": "x86-windows-static",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "windows-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
+3 -2
View File
@@ -1,6 +1,7 @@
-----------todo-----------
自己创建的grcTexture在DeviceReset时的流程
研究第二次启动游戏时汉化失效的问题
json自定义翻译功能
某些邮件回复时崩溃
*craplist.net邮件排版问题(最低优先)
-----------issue list-----------
+1 -2
View File
@@ -1,9 +1,8 @@
适用于GTA4三合一版本(1.2.0.43)的汉化程序<br/><br/>
[汉化项目网站](https://b9348.gitee.io)<br/><br/>
[汉化项目网站](https://b9348.pages.dev/)<br/><br/>
依赖库<br/>
[VC-LTL](https://github.com/Chuyu-Team/VC-LTL5)<br/><br/>
[Vcpkg](https://github.com/microsoft/vcpkg)<br/>
[range-v3(Vcpkg)](https://github.com/ericniebler/range-v3)<br/>
[zlib(Vcpkg)](https://github.com/madler/zlib)<br/>
[utfcpp(Vcpkg)](https://github.com/nemtrif/utfcpp)<br/>
[fmt(Vcpkg)](https://github.com/fmtlib/fmt)<br/>
+12 -11
View File
@@ -6,12 +6,12 @@ namespace fnv_hash
{
template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::size_t>
hash_seq(std::span<const T> seq, bool path_mode)
hash_seq(std::span<const T> seq, bool path_mode)
{
static constexpr uint64 fnv_prime = 16777619ull;
auto real_seq = std::span(reinterpret_cast<const uchar *>(seq.data()),
seq.size() * sizeof(T));
auto real_seq = std::span(reinterpret_cast<const uchar*>(seq.data()),
seq.size() * sizeof(T));
std::size_t result = 2166136261u;
@@ -39,7 +39,7 @@ namespace fnv_hash
template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::span<const T>>
get_string_span(const T *str)
get_string_span(const T* str)
{
std::size_t size = 0;
@@ -54,22 +54,23 @@ namespace fnv_hash
}
}
return {str, size};
return { str, size };
}
template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::vector<T>>
get_string_vector(const T *str)
get_string_vector(const T* str)
{
auto result = ranges::to_vector(get_string_span(str));
auto sp = get_string_span(str);
auto result = std::vector(sp.begin(), sp.end());
result.push_back(0);
return result;
}
//字符串哈希函数
std::size_t hash_string(const std::string &str, bool path_mode);
std::size_t hash_string(const char *str, bool path_mode);
std::size_t hash_string(const uchar *str, bool path_mode);
std::size_t hash_string(const GTAChar *str, bool path_mode);
std::size_t hash_string(const std::string& str, bool path_mode);
std::size_t hash_string(const char* str, bool path_mode);
std::size_t hash_string(const uchar* str, bool path_mode);
std::size_t hash_string(const GTAChar* str, bool path_mode);
} // namespace fnv_hash
-1
View File
@@ -1 +0,0 @@
#include "stdinc.h"
+1 -3
View File
@@ -11,6 +11,7 @@
#include <cstdio>
#include <cstring>
#include <d3d9.h>
#include <ranges>
#include <filesystem>
#include <fstream>
#include <functional>
@@ -33,7 +34,6 @@
// vcpkg
#include <fmt/printf.h>
#include <range/v3/all.hpp>
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/reader.h>
@@ -53,5 +53,3 @@ typedef unsigned int uint32;
typedef unsigned long long ulonglong;
typedef unsigned long long uint64;
typedef std::filesystem::path tPath;
struct grcTexturePC;
+56 -4
View File
@@ -1,9 +1,61 @@
cmake_minimum_required(VERSION 3.24)
project(GTA4.CHS)
project(plugin)
file(GLOB sources "*.cpp")
find_package(utf8cpp CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
add_library(GTA4.CHS SHARED ${sources} ${common_sources})
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_target_properties(GTA4.CHS PROPERTIES SUFFIX ".asi")
include("VC-LTL helper for cmake.cmake")
add_library(plugin SHARED
${CMAKE_SOURCE_DIR}/common/common.cpp
${CMAKE_SOURCE_DIR}/common/fnv_hash.cpp
${CMAKE_SOURCE_DIR}/common/module_path.cpp
batch_matching.cpp
batch_matching.h
byte_pattern.cpp
byte_pattern.h
char_table.cpp
char_table.h
class_pointer.hpp
dllmain.cpp
font.cpp
font.h
game.cpp
game.h
gta_benchmark.cpp
gta_benchmark.h
gta_font.cpp
gta_font.h
gta_game.cpp
gta_game.h
gta_html.cpp
gta_html.h
gta_mail_reply.cpp
gta_mail_reply.h
gta_menu.cpp
gta_menu.h
gta_phone.cpp
gta_phone.h
gta_save.cpp
gta_save.h
gta_string.cpp
gta_string.h
gta_whm.cpp
gta_whm.h
plugin.cpp
plugin.h
whm_table.cpp
whm_table.h
)
target_compile_definitions(plugin PRIVATE NOMINMAX _CRT_SECURE_NO_WARNINGS)
target_precompile_headers(plugin PRIVATE "${CMAKE_SOURCE_DIR}/common/stdinc.h")
target_link_libraries(plugin PRIVATE utf8::cpp utf8cpp::utf8cpp spdlog::spdlog_header_only)
set_target_properties(plugin PROPERTIES OUTPUT_NAME "GTA4.CHS")
set_target_properties(plugin PROPERTIES SUFFIX ".asi")
@@ -1,88 +1,88 @@
cmake_minimum_required(VERSION 3.5.2)
#
# VC-LTL自动化加载配置,建议你将此文件单独复制到你的工程再使用,该文件能自动识别当前环境是否存在VC-LTL,并且自动应用。
#
# 使用方法:
# 1. 在“CMakeLists.txt” 添加 “include("VC-LTL helper for cmake.cmake")”。
#
# VC-LTL默认搜索顺序
# 1. “VC-LTL helper for cmake.cmake”所在根目录,即 ${CMAKE_CURRENT_LIST_DIR}
# 2. 当前CMake根目录,即 ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL
# 3. 当前项目根目录,即 ${PROJECT_SOURCE_DIR}/VC-LTL
# 4. 当前CMake父目录,即 ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL
# 5. 当前项目根目录,即 ${PROJECT_SOURCE_DIR}/../VC-LTL
# 6. 注册表HKEY_CURRENT_USER\Code\VC-LTL@Root
#
# 把VC-LTL放在其中一个位置即可,VC-LTL就能被自动引用。
#
# 如果你对默认搜索顺序不满,你可以修改此文件。你也可以直接指定${VC_LTL_Root}宏更加任性的去加载VC-LTL。
#
#####################################################################VC-LTL设置#####################################################################
#控制TargetPlatform版本,目前可用版本为5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
#set(WindowsTargetPlatformMinVersion "10.0.10240.0")
#启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
#set(CleanImport "true")
####################################################################################################################################################
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_LIST_DIR})
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${PROJECT_SOURCE_DIR}/VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${PROJECT_SOURCE_DIR}/VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${PROJECT_SOURCE_DIR}/../VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${PROJECT_SOURCE_DIR}/../VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
EXECUTE_PROCESS(COMMAND reg query "HKEY_CURRENT_USER\\Code\\VC-LTL" -v "Root"
OUTPUT_VARIABLE FOUND_FILE
ERROR_VARIABLE ERROR_INFO
)
string(REGEX MATCH "[a-zA-Z]:\\\\.+\\\\"
FOUND_LTL
${FOUND_FILE})
if (NOT ${FOUND_LTL} STREQUAL "")
set(VC_LTL_Root ${FOUND_LTL})
endif()
if(NOT DEFINED VC_LTL_Root)
string(REGEX MATCH "\\\\\\\\.+\\\\" FOUND_LTL ${FOUND_FILE})
if (NOT ${FOUND_LTL} STREQUAL "")
set(VC_LTL_Root ${FOUND_LTL})
endif()
endif()
endif()
if(VC_LTL_Root)
include("${VC_LTL_Root}\\config\\config.cmake")
endif()
cmake_minimum_required(VERSION 3.5.2)
#
# VC-LTL自动化加载配置,建议你将此文件单独复制到你的工程再使用,该文件能自动识别当前环境是否存在VC-LTL,并且自动应用。
#
# 使用方法:
# 1. 在“CMakeLists.txt” 添加 “include("VC-LTL helper for cmake.cmake")”。
#
# VC-LTL默认搜索顺序
# 1. “VC-LTL helper for cmake.cmake”所在根目录,即 ${CMAKE_CURRENT_LIST_DIR}
# 2. 当前CMake根目录,即 ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL
# 3. 当前项目根目录,即 ${PROJECT_SOURCE_DIR}/VC-LTL
# 4. 当前CMake父目录,即 ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL
# 5. 当前项目根目录,即 ${PROJECT_SOURCE_DIR}/../VC-LTL
# 6. 注册表HKEY_CURRENT_USER\Code\VC-LTL@Root
#
# 把VC-LTL放在其中一个位置即可,VC-LTL就能被自动引用。
#
# 如果你对默认搜索顺序不满,你可以修改此文件。你也可以直接指定${VC_LTL_Root}宏更加任性的去加载VC-LTL。
#
#####################################################################VC-LTL设置#####################################################################
#控制TargetPlatform版本,目前可用版本为5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
#set(WindowsTargetPlatformMinVersion "10.0.10240.0")
#启用干净的导入表,消除 ucrt apiset(如:api-ms-win-crt-time-l1-1-0.dll),满足强迫症患者。
#set(CleanImport "true")
####################################################################################################################################################
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_LIST_DIR})
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_SOURCE_DIR}/VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${PROJECT_SOURCE_DIR}/VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${PROJECT_SOURCE_DIR}/VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${CMAKE_CURRENT_SOURCE_DIR}/../VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
if(EXISTS ${PROJECT_SOURCE_DIR}/../VC-LTL/_msvcrt.h)
set(VC_LTL_Root ${PROJECT_SOURCE_DIR}/../VC-LTL)
endif()
endif()
if(NOT VC_LTL_Root)
EXECUTE_PROCESS(COMMAND reg query "HKEY_CURRENT_USER\\Code\\VC-LTL" -v "Root"
OUTPUT_VARIABLE FOUND_FILE
ERROR_VARIABLE ERROR_INFO
)
string(REGEX MATCH "[a-zA-Z]:\\\\.+\\\\"
FOUND_LTL
${FOUND_FILE})
if (NOT ${FOUND_LTL} STREQUAL "")
set(VC_LTL_Root ${FOUND_LTL})
endif()
if(NOT DEFINED VC_LTL_Root)
string(REGEX MATCH "\\\\\\\\.+\\\\" FOUND_LTL ${FOUND_FILE})
if (NOT ${FOUND_LTL} STREQUAL "")
set(VC_LTL_Root ${FOUND_LTL})
endif()
endif()
endif()
if(VC_LTL_Root)
include("${VC_LTL_Root}\\config\\config.cmake")
endif()
+1 -1
View File
@@ -41,7 +41,7 @@ bool batch_matching::perform_search()
bool batch_matching::is_all_succeed() const
{
return ranges::all_of(_steps, [](const std::pair<std::string, match_step> &step) {
return std::ranges::all_of(_steps, [](const std::pair<std::string, match_step> &step) {
return step.second.expected_size == step.second.result.size();
});
}
+1 -1
View File
@@ -6,7 +6,7 @@ void CCharTable::LoadTable(const std::filesystem::path &filename) {
}
std::pair<uint, uint> CCharTable::GetCharPos(GTAChar chr) const {
auto char_it = ranges::lower_bound(m_Chars, chr);
auto char_it = std::ranges::lower_bound(m_Chars, chr);
if (char_it != m_Chars.end() && *char_it == chr) {
auto diff = char_it - m_Chars.begin();
+2 -2
View File
@@ -11,9 +11,9 @@ static const float fTextureRowsCount = fTextureResolution / fSpriteHeight;
static const float fTextureColumnsCount = fTextureResolution / fSpriteWidth;
static const float fRatio = 4.0f;
struct grcTexturePC *CNFont;
void *CNFont;
grcTexturePC *__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);
+1 -1
View File
@@ -120,7 +120,7 @@ VALIDATE_SIZE(TokenStruct, 0x114);
class CFont
{
public:
static grcTexturePC *__fastcall LoadTextureCB(void *, int, uint);
static void *__fastcall LoadTextureCB(void *, int, uint);
static float GetCharacterSizeNormalDispatch(GTAChar chr);
static float GetCHSCharacterSizeNormal();
+4 -4
View File
@@ -1,14 +1,14 @@
#include "game.h"
#include "plugin.h"
void CGame::Graphics_SetRenderState(grcTexturePC *texture, int arg4)
void CGame::Graphics_SetRenderState(void *texture, int arg4)
{
injector::cstd<void(grcTexturePC *, int)>::call(game_addr.fnGraphics_SetRenderState, texture, arg4);
injector::cstd<void(void *, int)>::call(game_addr.fnGraphics_SetRenderState, texture, arg4);
}
grcTexturePC* CGame::Dictionary_grcTexturePC_GetElementByKey(void* dictionary, uint hash)
void* CGame::Dictionary_grcTexturePC_GetElementByKey(void* dictionary, uint hash)
{
return injector::thiscall<grcTexturePC* (void*, uint)>::call(game_addr.fnDictionary_GetElementByKey, dictionary, hash);
return injector::thiscall<void* (void*, uint)>::call(game_addr.fnDictionary_GetElementByKey, dictionary, hash);
}
uint CGame::Hash_HashStringFromSeediCase(const char* str, uint hash)
+2 -2
View File
@@ -36,9 +36,9 @@ class CGame
} game_addr;
void Graphics_SetRenderState(grcTexturePC *texture, int = 1);
void Graphics_SetRenderState(void *texture, int = 1);
grcTexturePC *Dictionary_grcTexturePC_GetElementByKey(void *dictionary, uint hash);
void *Dictionary_grcTexturePC_GetElementByKey(void *dictionary, uint hash);
uint Hash_HashStringFromSeediCase(const char *str, uint hash = 0);
+3 -3
View File
@@ -70,11 +70,11 @@ namespace gta_string
if (wide_string_it != truncated_text_map.end())
{
ranges::copy(wide_string_it->second, dst);
std::ranges::copy(wide_string_it->second, dst);
}
else
{
*ranges::copy(src_span, dst).out = 0;
*std::ranges::copy(src_span, dst).out = 0;
}
}
@@ -118,7 +118,7 @@ namespace gta_string
else
{
//遇到无效的utf8序列(如网页中未翻译的FIGS字符),则直接扩展成utf16
*ranges::copy(src_span, dst).out = 0;
*std::ranges::copy(src_span, dst).out = 0;
}
}
+14
View File
@@ -0,0 +1,14 @@
{
"table": {
"translations": [
{
"origin": "This is English",
"translated": "这是中文"
},
{
"origin": "Another English",
"translated": "另一个中文"
}
]
}
}
+14 -1
View File
@@ -2,11 +2,24 @@ cmake_minimum_required(VERSION 3.24)
project(whm_io)
find_package(fmt CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
add_executable(whm_io
${CMAKE_SOURCE_DIR}/common/common.cpp
${CMAKE_SOURCE_DIR}/common/fnv_hash.cpp
${CMAKE_SOURCE_DIR}/common/module_path.cpp
HTMLDocument.h
HtmlTextExport.h
HtmlTextExport.cpp
pgBase.h
rsc_header.h
main.cpp
${common_sources})
)
target_compile_definitions(whm_io PRIVATE NOMINMAX)
target_precompile_headers(whm_io PRIVATE "${CMAKE_SOURCE_DIR}/common/stdinc.h")
target_link_libraries(whm_io PRIVATE ZLIB::ZLIB fmt::fmt-header-only rapidjson)
+4 -4
View File
@@ -63,7 +63,7 @@ void CHtmlTextExport::GenerateDataBase(const path_type &input_folder, const path
bin_entry.hash = entry.hash;
bin_entry.offset = text_data.size();
ranges::copy(entry.str, std::back_inserter(text_data));
std::ranges::copy(entry.str, std::back_inserter(text_data));
text_data.push_back(0);
text_table.push_back(bin_entry);
@@ -146,7 +146,7 @@ void CHtmlTextExport::ExportJson(const std::filesystem::path &filename,
bool CHtmlTextExport::IsBlankText(const std::string &str)
{
return ranges::all_of(str, [](char chr) {
return std::ranges::all_of(str, [](char chr) {
// TODO: 全角空格之类更加特殊的字符判断
return chr == ' ' || chr == '\t';
});
@@ -367,7 +367,7 @@ void CHtmlTextExport::TryAppendString(std::vector<exported_text_entry> &containe
//判断字符串是否为url
auto validate_url = [validate_url_char](std::string_view view) {
auto validate_char_result = ranges::all_of(view, validate_url_char);
auto validate_char_result = std::ranges::all_of(view, validate_url_char);
auto first_dot_pos = view.find('.');
auto last_dot_pos = view.find_last_of('.');
@@ -380,7 +380,7 @@ void CHtmlTextExport::TryAppendString(std::vector<exported_text_entry> &containe
auto validate_string = [validate_efigs_char, validate_url](std::string_view view) {
//包含EFIGS字母且不是网址
return ranges::any_of(view, validate_efigs_char) && !validate_url(view);
return std::ranges::any_of(view, validate_efigs_char) && !validate_url(view);
};
if (ptr == nullptr)