Skip to content

Commit

Permalink
Merge pull request #164 from chinosk6/main
Browse files Browse the repository at this point in the history
修复 12.14 更新 BUG
  • Loading branch information
ChihyuenWang authored Dec 20, 2023
2 parents 61afec3 + 4770942 commit 4c8212a
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 56 deletions.
190 changes: 161 additions & 29 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,48 @@ namespace
return replaceFont;
}

void* Text_set_font_orig;
void Text_set_font_hook(void* _this, void* font) {
return reinterpret_cast<decltype(Text_set_font_hook)*>(Text_set_font_orig)(_this, font);
}

bool settingSubText = false;

void* SubTextCommon_Setup_orig;
void SubTextCommon_Setup_hook(void* _this, int fontType, bool isChangeLine) {
settingSubText = true;
reinterpret_cast<decltype(SubTextCommon_Setup_hook)*>(SubTextCommon_Setup_orig)(_this, fontType, isChangeLine);
settingSubText = false;
}

void* TextCommon_UpdateBaseText_orig;
void TextCommon_UpdateBaseText_hook(void* _this, Il2CppString* value) {
settingSubText = true;
reinterpret_cast<decltype(TextCommon_UpdateBaseText_hook)*>(TextCommon_UpdateBaseText_orig)(_this, value);
settingSubText = false;
}

void* GetChineseFont_orig;
void* GetChineseFont_hook(void* _this) {
auto ret = getReplaceFont();
if (ret) return ret;
return reinterpret_cast<decltype(GetChineseFont_hook)*>(GetChineseFont_orig)(_this);
}

void* LoadResourcesFolderFont_orig;
void* LoadResourcesFolderFont_hook(void* _this, int fontType) {
if (settingSubText) {
switch (fontType) {
case 0x0: // Dynamic01
case 0x3: { // Chinese_Font01
auto ret = getReplaceFont();
if (ret) return ret;
}; break;
}
}
return reinterpret_cast<decltype(LoadResourcesFolderFont_hook)*>(LoadResourcesFolderFont_orig)(_this, fontType);
}

void* TextCommon_Awake_orig;
void TextCommon_Awake_hook(void* _this)
{
Expand Down Expand Up @@ -2637,7 +2679,6 @@ namespace
float(*get_Wiz)(void*);
float(*get_DeltaTime)();
bool(*get_IsStartDash)(void*);
int(*GetActivateSkillCount)(void*);
int(*get_FinishOrder)(void*);
// int(*CalcChallengeMatchPointTotal)(void*);
float(*get_MoveDistance)(void*);
Expand Down Expand Up @@ -2681,8 +2722,8 @@ namespace
convertPtrType(&GetHp, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "GetHp", 0));
convertPtrType(&GetMaxHp, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "GetMaxHp", 0));
convertPtrType(&GetHpPer, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "GetHpPer", 0));
convertPtrType(&get_NearHorseCount, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_NearHorseCount", 0));
convertPtrType(&get_CongestionTime, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_CongestionTime", 0));
// convertPtrType(&get_NearHorseCount, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_NearHorseCount", 0));
// convertPtrType(&get_CongestionTime, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_CongestionTime", 0));
convertPtrType(&get_RawSpeed, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_RawSpeed", 0));
convertPtrType(&get_BaseSpeed, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_BaseSpeed", 0));
convertPtrType(&get_Speed, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_Speed", 0));
Expand All @@ -2699,7 +2740,6 @@ namespace
convertPtrType(&get_BaseWiz, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_BaseWiz", 0));
convertPtrType(&get_Wiz, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_Wiz", 0));
convertPtrType(&get_IsStartDash, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_IsStartDash", 0));
convertPtrType(&GetActivateSkillCount, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "GetActivateSkillCount", 0));
convertPtrType(&get_MoveDistance, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "HorseRaceInfo", "get_MoveDistance", 0));
convertPtrType(&get_DeltaTime, il2cpp_resolve_icall("UnityEngine.Time::get_unscaledDeltaTime()"));

Expand All @@ -2717,6 +2757,7 @@ namespace

void* get_RunMotionSpeed_orig;
float get_RunMotionSpeed_hook(void* _this) {
// handle: 00007FF9C71B0000
raceStart = true;
auto ret = reinterpret_cast<decltype(get_RunMotionSpeed_hook)*>(get_RunMotionSpeed_orig)(_this);
if (enableRaceInfoTab || (g_race_free_camera && g_race_freecam_follow_umamusume)) {
Expand All @@ -2726,20 +2767,32 @@ namespace
bool isFinished = get_IsOverRun(_this);
iter->second.UpdateMotionData(ret, get_RunMotionRate(_this), get_RaceBaseSpeed(_this), get_MinSpeed(_this),
get_StartDashSpeedThreshold(_this), isFinished, GetHp(_this), GetMaxHp(_this), GetHpPer(_this),
get_NearHorseCount(_this), get_CongestionTime(_this), get_RawSpeed(_this),
0, //get_NearHorseCount(_this),
0, //get_CongestionTime(_this),

get_RawSpeed(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_baseSpeedAdjusted),
get_Speed(_this),
get_RawStamina(_this), il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_baseStaminaAdjusted),
get_Stamina(_this), get_RawPow(_this),
get_RawStamina(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_baseStaminaAdjusted),
get_Stamina(_this),
get_RawPow(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_basePowAdjusted),
get_Pow(_this), get_RawGuts(_this),
get_Pow(_this),
get_RawGuts(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_baseGutsAdjusted),
get_Guts(_this), get_RawWiz(_this),
get_Guts(_this),
get_RawWiz(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_baseWizAdjusted),
get_Wiz(_this), get_IsStartDash(_this), GetActivateSkillCount(_this),
get_Wiz(_this),
get_IsStartDash(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_lastSpeed),
get_MoveDistance(_this), il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_distance),
get_DeltaTime(), get_LastSpurtStartDistance(_this), get_IsLastSpurt(_this));
get_MoveDistance(_this),
il2cpp_symbols::read_field<float>(_this, HorseRaceInfo_distance),
get_DeltaTime(),
get_LastSpurtStartDistance(_this),
get_IsLastSpurt(_this)
);
if (isFinished) iter->second.setFinallyRank(get_FinishOrder(_this) + 1);

if (g_race_free_camera && g_race_freecam_follow_umamusume) {
Expand Down Expand Up @@ -2806,7 +2859,7 @@ namespace
bool isSkillManaInited = false;

void initSkillManager() {
if (isSkillManaInited)return;
if (isSkillManaInited) return;
isSkillManaInited = true;

skillManager_klass = il2cpp_symbols::get_class("umamusume.dll", "Gallop", "SkillManager");
Expand All @@ -2815,16 +2868,52 @@ namespace
convertPtrType(&GetSkillLevel, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillBase", "get_Level", 0));
convertPtrType(&GetSkilDetails, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillBase", "get_Details", 0));
convertPtrType(&get_SkillMaster, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillBase", "get_SkillMaster", 0));
convertPtrType(&getSkill_Abilities, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillDetail", "get_Abilities", 0));
convertPtrType(&get_SkillEffectName, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillDetail", "get_SkillEffectName", 0));
convertPtrType(&SkillActivate, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillDetail", "Activate", 0));
convertPtrType(&get_DefaultCoolDownTime, il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "SkillDetail", "get_DefaultCoolDownTime", 0));
convertPtrType(&getSkill_Abilities, il2cpp_symbols::get_method_pointer("umamusume.dll", "StandaloneSimulator", "SkillDetail", "get_Abilities", 0));
convertPtrType(&get_SkillEffectName, il2cpp_symbols::get_method_pointer("umamusume.dll", "StandaloneSimulator", "SkillDetail", "get_SkillEffectName", 0));
// convertPtrType(&SkillActivate, il2cpp_symbols::get_method_pointer("umamusume.dll", "StandaloneSimulator", "SkillDetail", "Activate", 0));
// convertPtrType(&get_DefaultCoolDownTime, il2cpp_symbols::get_method_pointer("umamusume.dll", "StandaloneSimulator", "SkillDetail", "get_DefaultCoolDownTime", 0));
}

struct MSkillAbility {
int AbilityType;
float AbilityValue;
int targetType;
float CooldownTime;
};

std::vector<MSkillAbility> getMSkillAbilitiesByMasterData(int skillId) {
static std::vector<std::string> abilityEnds = { "1_1", "1_2", "1_3", "2_1", "2_2", "2_3" };
std::vector<MSkillAbility> ret{};

if (auto iter = UmaDatabase::umaSkillInfo.find(skillId); iter != UmaDatabase::umaSkillInfo.end()) {
for (const auto& i : abilityEnds) {
const std::string AbilityTypeName = std::format("ability_type_{}", i);
const std::string AbilityValueName = std::format("float_ability_value_{}", i);
const std::string FloatCooldownTimeName = std::format("float_cooldown_time_{}", i[0]);
const std::string TargetTypeName = std::format("target_type_{}", i);

const auto AbilityType = iter->second[AbilityTypeName];
if (AbilityType <= 0) continue;
const auto AbilityValue = iter->second[AbilityValueName];
const auto FloatCooldownTime = iter->second[FloatCooldownTimeName];
const auto TargetType = iter->second[TargetTypeName];

MSkillAbility currRet{};
currRet.AbilityType = AbilityType;
currRet.AbilityValue = (float)AbilityValue / 10000.0f;
currRet.targetType = TargetType;
currRet.CooldownTime = (float)FloatCooldownTime / 10000.0f;
// printf("AbilityType: %d, AbilityValue: %f, CooldownTime: %f, TargetType: %d\n", currRet.AbilityType, currRet.AbilityValue, currRet.CooldownTime, TargetType);
ret.push_back(currRet);
}
}
// printf("\n");
return ret;
}

void* AddUsedSkillId_orig;
void AddUsedSkillId_hook(void* _this, int skillId) {
reinterpret_cast<decltype(AddUsedSkillId_hook)*>(AddUsedSkillId_orig)(_this, skillId);

if (enableRaceInfoTab) {
initSkillManager();
// Gallop.IHorseRaceInfo
Expand Down Expand Up @@ -2855,13 +2944,29 @@ namespace
skillData.SetSkillName(utility::conversions::to_utf8string(skillName->start_char));
}

bool updatedCool = false;
const auto mAbilities = getMSkillAbilitiesByMasterData(skillId);
for (const auto& skillAbility : mAbilities) {
const auto abilityType = skillAbility.AbilityType;
const auto effValue = skillAbility.AbilityValue;
if (!updatedCool) {
updatedCool = true;
skillData.updateCoolDownTime(skillAbility.CooldownTime);
}
UmaGUiShowData::SkillAbility mSkillability(abilityType, effValue);
mSkillability.setTargetType(skillAbility.targetType);
skillData.addSkillAbilities(mSkillability);
}

/*
il2cpp_symbols::iterate_list(skilDetails, [&](int32_t index, void* skillDetail) {
SkillActivate(skillDetail);
// SkillActivate(skillDetail);
auto abilities = getSkill_Abilities(skillDetail); // List`1<class Gallop.ISkillAbility>
auto defCooldownTime = get_DefaultCoolDownTime(skillDetail);
// auto defCooldownTime = get_DefaultCoolDownTime(skillDetail);
auto defCooldownTime = 1200.0f;
skillData.updateCoolDownTime(defCooldownTime);

il2cpp_symbols::iterate_list(abilities, [&](int32_t cIndex, void* skillAbility) {
int (*get_AbilityType)(void*);
float (*get_AbilityValueOnActivate)(void*);
Expand Down Expand Up @@ -2889,13 +2994,11 @@ namespace
// printf("abilityType: 0x%x, effValue: %f\n", abilityType, effValue);
skillData.addSkillAbilities(mSkillability);
});

});

*/
umaUsedSkillList.emplace_back(skillData);
}
}

}

void* AlterUpdate_CameraLayer_orig;
Expand Down Expand Up @@ -4298,11 +4401,29 @@ namespace
"AnGlobalData", "_GetFontFromCommon", 1
);

Text_set_font = reinterpret_cast<void(*)(void*, void*)>(
il2cpp_symbols::get_method_pointer(
auto Text_set_font_addr = il2cpp_symbols::get_method_pointer(
"UnityEngine.UI.dll", "UnityEngine.UI",
"Text", "set_font", 1)
);
"Text", "set_font", 1);

auto GetChineseFont_addr = il2cpp_symbols::get_method_pointer(
"umamusume.dll", "Gallop",
"TextFontManager", "GetChineseFont", 0);

auto SubTextCommon_Setup_addr = il2cpp_symbols::get_method_pointer(
"umamusume.dll", "Gallop",
"SubTextCommon", "Setup", 2);
auto TextCommon_UpdateBaseText_addr = il2cpp_symbols::get_method_pointer(
"umamusume.dll", "Gallop",
"TextCommon", "UpdateBaseText", 1);

auto LoadResourcesFolderFont_addr = il2cpp_symbols::find_method("umamusume.dll", "Gallop", "TextFontManager", [](const MethodInfo* method) {
if (strcmp(method->name, "LoadResourcesFolderFont") == 0) {
if (method->parameters->parameter_type->type == Il2CppTypeEnum::IL2CPP_TYPE_VALUETYPE) {
return true;
}
}
return false;
});

Text_set_horizontalOverflow = reinterpret_cast<void(*)(void*, int)>(
il2cpp_symbols::get_method_pointer(
Expand Down Expand Up @@ -4833,7 +4954,6 @@ namespace
ADD_HOOK(WWWRequest_Post, "WWWRequest_Post at %p\n");
}
#pragma endregion

// hook UnityEngine.TextGenerator::PopulateWithErrors to modify text
ADD_HOOK(populate_with_errors, "UnityEngine.TextGenerator::PopulateWithErrors at %p\n");

Expand Down Expand Up @@ -4948,6 +5068,12 @@ namespace
if (!std::holds_alternative<UseOriginalFont>(g_replace_font))
{
ADD_HOOK(TextCommon_Awake, "Gallop.TextCommon::Awake at %p\n");
ADD_HOOK(Text_set_font, "Text_set_font at %p\n");
ADD_HOOK(GetChineseFont, "GetChineseFont at %p\n");
ADD_HOOK(SubTextCommon_Setup, "SubTextCommon_Setup at %p\n");
ADD_HOOK(TextCommon_UpdateBaseText, "TextCommon_UpdateBaseText at %p\n");
ADD_HOOK(LoadResourcesFolderFont, "LoadResourcesFolderFont at %p\n");
Text_set_font = reinterpret_cast<void(*)(void*, void*)>(Text_set_font_orig);
ADD_HOOK(TextMeshProUguiCommon_Awake, "TextMeshProUguiCommon_Awake at %p\n");
ADD_HOOK(AnText_UpdateText, "AnText_UpdateText at %p\n");
ADD_HOOK(AnText_Destroy, "AnText_Destroy at %p\n");
Expand All @@ -4960,6 +5086,12 @@ namespace
AssetBundle_LoadAsset_orig = reinterpret_cast<void*>(AssetBundle_LoadAsset_addr);
}
}
else
{
Text_set_font = reinterpret_cast<void(*)(void*, void*)>(il2cpp_symbols::get_method_pointer(
"UnityEngine.UI.dll", "UnityEngine.UI",
"Text", "set_font", 1));
}

if (g_replace_assets)
{
Expand Down
8 changes: 8 additions & 0 deletions src/il2cpp/il2cpp_symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ namespace il2cpp_symbols
const char* klassName, const char* name, int argsCount)
{
auto assembly = il2cpp_domain_assembly_open(il2cpp_domain, assemblyName);
if (!assembly) {
printf("assembly: %s not found!\n", assemblyName);
return NULL;
}
auto image = il2cpp_assembly_get_image(assembly);
auto klass = il2cpp_class_from_name(image, namespaze, klassName);
if (!klass) {
printf("class %s::%s not found!\n", namespaze, klassName);
return NULL;
}
auto ret = il2cpp_class_get_method_from_name(klass, name, argsCount);
if (ret) {
return ret->methodPointer;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ int __stdcall DllMain(HINSTANCE dllModule, DWORD reason, LPVOID)
}

auto dicts = read_config();
UmaDatabase::executeQuerySkillData();

if (g_enable_console)
create_debug_console();
Expand Down
24 changes: 11 additions & 13 deletions src/mhotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <thread>
#include <format>
#include <functional>
#include <filesystem>

extern void (*testFunction)();

Expand Down Expand Up @@ -39,11 +40,6 @@ namespace MHotkey{
void SetKeyCallBack(std::function<void(int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD)> callbackfun) {
mKeyBoardCallBack = callbackfun;
}

bool check_file_exist(const std::string& name) {
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}

void fopenExternalPlugin(int tlgPort) {
std::thread([tlgPort](){
Expand All @@ -59,13 +55,15 @@ namespace MHotkey{
printf("\"externalPlugin\" not found\n");
return;
}

if (check_file_exist(file_check_name)) {
if (check_file_exist(extPluginPath)) {
remove(extPluginPath.c_str());
if (std::filesystem::exists(file_check_name)) {
try {
if (std::filesystem::exists(extPluginPath)) {
std::filesystem::remove(extPluginPath);
}
std::filesystem::rename(file_check_name, extPluginPath);
}
if (rename(file_check_name.c_str(), extPluginPath.c_str()) != 0) {
printf("update external plugin failed\n");
catch (std::exception& e) {
printf("update external plugin failed: %s\n", e.what());
}
}

Expand Down Expand Up @@ -94,8 +92,8 @@ namespace MHotkey{
}

void closeExternalPlugin() {
if (check_file_exist("dontcloseext.lock")) {
remove("dontcloseext.lock");
if (std::filesystem::exists("dontcloseext.lock")) {
std::filesystem::remove("dontcloseext.lock");
return;
}
if (openPluginSuccess && pluginPID != -1) {
Expand Down
Loading

0 comments on commit 4c8212a

Please sign in to comment.