Open Kor-Angar opened 2 years ago
старый код
namespace NAMESPACE
{
std::unordered_map<string, string> fontBindings;
int __cdecl Hlp_BindFont()
{
string source, target;
ZARGS(source, target);
source.Upper();
target.Upper();
if (source != target)
{
fontBindings.erase(target);
fontBindings[source] = target;
}
return false;
}
// func void Hlp_BindFont(var string source, var string target)
ZEXTERNAL(Hlp_BindFont, void, string, string);
bool inSetFont;
extern Hook<void(__thiscall*)(zCView*, zSTRING const&)> Ivk_zCView_SetFont;
void __fastcall Hook_zCView_SetFont_Ptr(zCView*, void*, zCFont*);
Hook<void(__thiscall*)(zCView*, zCFont*)> Ivk_zCView_SetFont_Ptr(ZENFOR(0x006FFD60, 0x0073A360, 0x00749DF0, 0x007A98F0), &Hook_zCView_SetFont_Ptr, HookMode::Patch);
void __fastcall Hook_zCView_SetFont_Ptr(zCView* _this, void* vtable, zCFont* a0)
{
if (inSetFont || !a0)
return Ivk_zCView_SetFont_Ptr(_this, a0);
auto scope = AssignTemp(inSetFont, true);
string upperName{ a0->name };
upperName.Upper();
auto it = fontBindings.find(upperName);
if (it != fontBindings.end())
return Ivk_zCView_SetFont(_this, it->second);
Ivk_zCView_SetFont_Ptr(_this, a0);
}
void __fastcall Hook_zCView_SetFont(zCView*, void*, zSTRING const&);
Hook<void(__thiscall*)(zCView*, zSTRING const&)> Ivk_zCView_SetFont(ZENFOR(0x006FFD90, 0x0073A390, 0x00749E20, 0x007A9920), &Hook_zCView_SetFont, HookMode::Patch);
void __fastcall Hook_zCView_SetFont(zCView* _this, void* vtable, zSTRING const& a0)
{
if (inSetFont)
return Ivk_zCView_SetFont(_this, a0);
auto scope = AssignTemp(inSetFont, true);
string upperName{ a0 };
upperName.Upper();
auto it = fontBindings.find(upperName);
if (it != fontBindings.end())
return Ivk_zCView_SetFont(_this, it->second);
Ivk_zCView_SetFont(_this, a0);
}
Sub changeFonts(ZSUB(GameEvent::PreLoop, GameEvent::MenuLoop), []
{
if (!screen)
return;
std::vector<zCView*> stack;
stack.reserve(64u);
if (ogame->GetTextView() && !ogame->GetTextView()->owner)
stack += ogame->GetTextView();
for (int i = 0; i < oCGame::GAME_VIEW_MAX; i++)
if (ogame->array_view[i] && !ogame->array_view[i]->owner)
stack += ogame->array_view[i];
stack += screen;
while (!stack.empty())
{
zCView* const view = stack.back();
stack.pop_back();
for (zCView* child = view->childs.root; child; child = child->next)
stack += child;
if (!view->font)
continue;
auto it = fontBindings.find(string{ view->font->name }.Upper());
if (it == fontBindings.end())
continue;
Ivk_zCView_SetFont(view, it->second);
}
});
int __fastcall Hook_zCFont_LoadFontData(zCFont*, void*);
Hook<int(__thiscall*)(zCFont*)> Ivk_zCFont_LoadFontData(ZENFOR(0x006DFC50, 0x007181A0, 0x007294E0, 0x00788F20), &Hook_zCFont_LoadFontData, HookMode::Patch);
int __fastcall Hook_zCFont_LoadFontData(zCFont* _this, void* vtable)
{
VarScope<zSTRING> scope{ _this->name };
return Ivk_zCFont_LoadFontData(_this);
}
}
плагин zBindFont.zip
...
zBindFont.zip