[Misc]: Added 'console_menu_style' dvar.

This commit is contained in:
JerryALT 2024-03-29 19:57:50 +03:00
parent 1a301f65c3
commit 7050ef5e96
2 changed files with 153 additions and 71 deletions

View File

@ -2,14 +2,14 @@
namespace Components namespace Components
{ {
void sv_cheats_hook() void CommonPatch::SV_CheatsStub()
{ {
Dvars::Override::DvarBoolOverride("sv_cheats", Dvars::Override::DvarBoolOverride("sv_cheats",
Dvars::Functions::Dvar_FindVar("sv_allowCheats")->current.enabled ? true : false, Dvars::Functions::Dvar_FindVar("sv_allowCheats")->current.enabled ? true : false,
Dvars::Functions::Dvar_FindVar("sv_allowCheats")->current.enabled ? Game::none : Game::cheat_protected); Dvars::Functions::Dvar_FindVar("sv_allowCheats")->current.enabled ? Game::none : Game::cheat_protected);
} }
void DB_LoadCommonFastFiles() void CommonPatch::DB_LoadCommonFastFiles()
{ {
int i = 0; int i = 0;
Game::XZoneInfo XZoneInfoStack[6]; Game::XZoneInfo XZoneInfoStack[6];
@ -148,33 +148,19 @@ namespace Components
ServerCommand::Add("server_test_cmd", []() ServerCommand::Add("server_test_cmd", []()
{ {
Game::Com_Printf(0, "^8MY FIRST TEST SERVER COMMAND\n"); const char* arg1 = Command::Cmd_Argv(1);
Game::Com_Printf(0, "^1Custom server command with argument %s\n", arg1);
}); });
// Unlocked the developer_script flag from "write only" to "none" Command::Add("test_send_custom_server_cmd", [](Command::Params*)
Dvars::Functions::Dvar_FindVar("developer_script")->flags = Game::none; {
Dvars::Functions::Dvar_FindVar("r_ignorehwgamma")->flags = Game::saved; Game::SV_GameSendServerCommand(-1, Utils::String::VA("%s %d", "server_test_cmd", 5));
//Game::SV_GameSendServerCommand(-1, Utils::String::VA("%s", "function_not_exists"));
});
const float newDefault_con_inputBoxColor[4] = { 0.15f, 0.15f, 0.15f, 1.0f }; Dvars::Override::DvarBoolOverride("developer_script", Game::none);
const float newDefault_con_inputHintBoxColor[4] = { 0.1f, 0.1f, 0.1f, 1.0f }; Dvars::Override::DvarBoolOverride("r_ignorehwgamma", Game::saved);
const float newDefault_con_outputWindowColor[4] = { 0.1f, 0.1f, 0.1f, 0.75f };
const float newDefault_con_outputBarColor[4] = { 0.1f, 0.1f, 0.1f, 1.0f };
const float newDefault_con_outputSliderColor[4] = { 0.1f, 0.1f, 0.1f, 1.0f };
// I can't find more genius idea than this, but, anyway, this is works fine and correct for me!
// For save values from user config.
Dvars::Override::DvarVec4OverrideDefaultValue("con_inputBoxColor", newDefault_con_inputBoxColor);
Dvars::Override::DvarVec4Override("con_inputBoxColor", Dvars::Functions::Dvar_FindVar("con_inputBoxColor")->current.vector);
Dvars::Override::DvarVec4OverrideDefaultValue("con_inputHintBoxColor", newDefault_con_inputHintBoxColor);
Dvars::Override::DvarVec4Override("con_inputHintBoxColor", Dvars::Functions::Dvar_FindVar("con_inputHintBoxColor")->current.vector);
Dvars::Override::DvarVec4OverrideDefaultValue("con_outputWindowColor", newDefault_con_outputWindowColor);
Dvars::Override::DvarVec4Override("con_outputWindowColor", Dvars::Functions::Dvar_FindVar("con_outputWindowColor")->current.vector);
Dvars::Override::DvarVec4OverrideDefaultValue("con_outputBarColor", newDefault_con_outputBarColor);
Dvars::Override::DvarVec4Override("con_outputBarColor", Dvars::Functions::Dvar_FindVar("con_outputBarColor")->current.vector);
Dvars::Override::DvarVec4OverrideDefaultValue("con_outputSliderColor", newDefault_con_outputSliderColor);
Dvars::Override::DvarVec4Override("con_outputSliderColor", Dvars::Functions::Dvar_FindVar("con_outputSliderColor")->current.vector);
// Override existing localize entries.
LocalizedStrings::OverrideLocalizeStrings(); LocalizedStrings::OverrideLocalizeStrings();
if (Flags::HasFlag("dump")) if (Flags::HasFlag("dump"))
@ -257,18 +243,10 @@ namespace Components
}); });
} }
UIScript::Add("testUIScript", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) TextRenderer::UpdateGameFontsAndText();
{
Game::Com_Printf(0, "^2Game:: test uiscript\n");
});
UIScript::Add("VisitYT", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
{
Utils::OpenUrl("https://youtu.be/dQw4w9WgXcQ?t=85");
});
} }
void RunModStub() void CommonPatch::RunModStub()
{ {
char mod[260]; char mod[260];
@ -290,7 +268,7 @@ namespace Components
} }
} }
void ClearModStub() void CommonPatch::ClearModStub()
{ {
Dvars::Functions::Dvar_Reset(0, Dvars::Functions::Dvar_FindVar("fs_game")); Dvars::Functions::Dvar_Reset(0, Dvars::Functions::Dvar_FindVar("fs_game"));
Language::VideoSubtitlesStub(); Language::VideoSubtitlesStub();
@ -298,11 +276,16 @@ namespace Components
Config::CallExecFromCFG(false); Config::CallExecFromCFG(false);
} }
void R_Cinematic_BinkOpen_stub01(char* buffer, size_t size, const char* /*format*/, const char* directory, const char* fileName, const char* videoFormat) void CommonPatch::R_Cinematic_BinkOpenStub1(char* buffer, size_t size, const char* /*format*/, const char* directory, const char* fileName, const char* videoFormat)
{ {
const char* languageName = Game::SEH_GetLanguageName(Dvars::Functions::Dvar_FindVar("loc_language")->current.unsignedInt); const char* languageName = Game::SEH_GetLanguageName(Dvars::Functions::Dvar_FindVar("loc_language")->current.unsignedInt);
if (Utils::IO::FileExists(Utils::String::VA("%s\\main\\video\\%s.%s", directory, fileName, videoFormat))) if (Utils::IO::FileExists(Utils::String::VA("%s\\iw3sp_data\\video\\%s.%s", directory, fileName, videoFormat)))
{
_snprintf_s(buffer, size, _TRUNCATE, "%s\\iw3sp_data\\video\\%s.%s", directory, fileName, videoFormat);
return;
}
else if (Utils::IO::FileExists(Utils::String::VA("%s\\main\\video\\%s.%s", directory, fileName, videoFormat)))
{ {
_snprintf_s(buffer, size, _TRUNCATE, "%s\\main\\video\\%s.%s", directory, fileName, videoFormat); _snprintf_s(buffer, size, _TRUNCATE, "%s\\main\\video\\%s.%s", directory, fileName, videoFormat);
return; return;
@ -324,33 +307,17 @@ namespace Components
} }
} }
void R_Cinematic_BinkOpen_stub02(char* buffer, size_t size, const char* /*format*/, const char* directory, const char* fileName, const char* videoFormat) void CommonPatch::Com_Quit_f_Stub()
{
const char* languageName = Game::SEH_GetLanguageName(Dvars::Functions::Dvar_FindVar("loc_language")->current.unsignedInt);
if (Utils::IO::FileExists(Utils::String::VA("%s\\raw\\video\\%s.%s", directory, fileName, videoFormat)))
{
_snprintf_s(buffer, size, _TRUNCATE, "%s\\raw\\video\\%s.%s", directory, fileName, videoFormat);
return;
}
else
{
_snprintf_s(buffer, size, _TRUNCATE, "%s\\raw\\%s_video\\%s.%s", directory, languageName, fileName, videoFormat);
return;
}
}
void Com_Quit_f_stub()
{ {
Utils::Library::Terminate(); Utils::Library::Terminate();
} }
void LanguageSetValueConfig(int langIndex) void CommonPatch::LanguageSetValueConfig(int langIndex)
{ {
Config::Set<std::string>("language", Game::SEH_GetLanguageName(langIndex)); Config::Set<std::string>("language", Game::SEH_GetLanguageName(langIndex));
} }
void __declspec(naked) updateLanguageStub() void __declspec(naked) CommonPatch::UpdateLanguageStub()
{ {
const static uint32_t retn_addr = 0x5674FD; const static uint32_t retn_addr = 0x5674FD;
__asm __asm
@ -363,6 +330,103 @@ namespace Components
} }
} }
// It may need to be redone as 'Event' module, but i don't have much dvars with latched flag :<
int CommonPatch::R_RegisterSunDvarsStub()
{
Dvars::console_menu_style = Dvars::Register::Dvar_RegisterBool("console_menu_style", "Enable/Disable menu style from console version", false, Game::saved | Game::latched);
return Utils::Hook::Call<int()>(0x61D050)();
}
Game::dvar_s* CommonPatch::RegisterConColor(const char* dvarName, float r, float g, float b, float a, float min, float max, unsigned __int16 flags, const char* description)
{
static struct
{
const char* name;
float color[4];
} patchedColors[] =
{
{ "con_inputBoxColor", { 0.15f, 0.15f, 0.15f, 1.00f } },
{ "con_inputHintBoxColor", { 0.10f, 0.10f, 0.10f, 1.00f } },
{ "con_outputWindowColor", { 0.10f, 0.10f, 0.10f, 0.75f } },
{ "con_outputBarColor", { 0.10f, 0.10f, 0.10f, 1.00f } },
{ "con_outputSliderColor", { 0.10f, 0.10f, 0.10f, 1.00f } },
};
for (std::size_t i = 0; i < ARRAYSIZE(patchedColors); ++i)
{
if (std::strcmp(dvarName, patchedColors[i].name) == 0)
{
r = patchedColors[i].color[0];
g = patchedColors[i].color[1];
b = patchedColors[i].color[2];
a = patchedColors[i].color[3];
break;
}
}
return Dvars::Register::Dvar_RegisterVec4(dvarName, description, r, g, b, a, min, max, flags);
}
void __declspec(naked) CommonPatch::RegisterConColorStub1()
{
const static uint32_t retn_addr = 0x439948;
__asm
{
push edi;
call RegisterConColor;
add esp, 4;
jmp retn_addr;
}
}
void __declspec(naked) CommonPatch::RegisterConColorStub2()
{
const static uint32_t retn_addr = 0x43998B;
__asm
{
push edi;
call RegisterConColor;
add esp, 4;
jmp retn_addr;
}
}
void __declspec(naked) CommonPatch::RegisterConColorStub3()
{
const static uint32_t retn_addr = 0x4399CE;
__asm
{
push edi;
call RegisterConColor;
add esp, 4;
jmp retn_addr;
}
}
void __declspec(naked) CommonPatch::RegisterConColorStub4()
{
const static uint32_t retn_addr = 0x439A17;
__asm
{
push edi;
call RegisterConColor;
add esp, 4;
jmp retn_addr;
}
}
void __declspec(naked) CommonPatch::RegisterConColorStub5()
{
const static uint32_t retn_addr = 0x439A60;
__asm
{
push edi;
call RegisterConColor;
add esp, 4;
jmp retn_addr;
}
}
CommonPatch::CommonPatch() CommonPatch::CommonPatch()
{ {
Events::OnDvarInit([] Events::OnDvarInit([]
@ -402,10 +466,12 @@ namespace Components
Game::dvar_s* snd_hitsoundDisabled = Dvars::Register::Dvar_RegisterBool("snd_hitsoundDisabled", "Disable the hit indicator sound", true, Game::saved); Game::dvar_s* snd_hitsoundDisabled = Dvars::Register::Dvar_RegisterBool("snd_hitsoundDisabled", "Disable the hit indicator sound", true, Game::saved);
Game::dvar_s* sv_allowCheats = Dvars::Register::Dvar_RegisterBool("sv_allowCheats", "Enable/Disable the game cheats", false, Game::saved); Game::dvar_s* sv_allowCheats = Dvars::Register::Dvar_RegisterBool("sv_allowCheats", "Enable/Disable the game cheats", false, Game::saved);
Game::dvar_s* allowCompactFolderForMod = Dvars::Register::Dvar_RegisterBool("allowCompactFolderForMod", "Enable/Disable compact loading of the mod files.", true, Game::none); Game::dvar_s* allowCompactFolderForMod = Dvars::Register::Dvar_RegisterBool("allowCompactFolderForMod", "Enable/Disable compact loading of the mod files.", true, Game::none);
//Game::dvar_s* ui_console_menu_style = Dvars::Register::Dvar_RegisterBool("ui_console_menu_style", "Enable/Disable menu style from console version", false, Game::none);
}); });
Utils::Hook(0x4B83CF, sv_cheats_hook, HOOK_CALL).install()->quick(); // Hook for correct works the latched dvars
Utils::Hook(0x5F68DB, R_RegisterSunDvarsStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4B83CF, SV_CheatsStub, HOOK_CALL).install()->quick();
Utils::Hook::Nop(0x5899E8, 5); Utils::Hook::Nop(0x5899E8, 5);
Utils::Hook::Set<const char*>(0x445667, "iw3sp_mod.exe"); //-startSingleplayer Utils::Hook::Set<const char*>(0x445667, "iw3sp_mod.exe"); //-startSingleplayer
@ -418,9 +484,6 @@ namespace Components
if (Utils::IO::FileExists("iw3sp_data/assets/splash_logo.bmp")) if (Utils::IO::FileExists("iw3sp_data/assets/splash_logo.bmp"))
Utils::Hook::Set<const char*>(0x595EC4, "iw3sp_data/assets/splash_logo.bmp"); Utils::Hook::Set<const char*>(0x595EC4, "iw3sp_data/assets/splash_logo.bmp");
//Utils::Hook::Set<BYTE>(0x41D652, Game::saved);
//Utils::Hook::Set<BYTE>(0x41D653, 0x0);
// g_mem limit expansion. Thanks to Nikolai for offsets. // g_mem limit expansion. Thanks to Nikolai for offsets.
Utils::Hook::Set<DWORD>(0x534B3F, 0x20000000); //528mb Utils::Hook::Set<DWORD>(0x534B3F, 0x20000000); //528mb
Utils::Hook::Set<DWORD>(0x534B70, 0x20000000); //528mb Utils::Hook::Set<DWORD>(0x534B70, 0x20000000); //528mb
@ -445,13 +508,12 @@ namespace Components
Utils::Hook::Set<const char*>(0x567284, "vid_restart\n"); //for ClearMods Utils::Hook::Set<const char*>(0x567284, "vid_restart\n"); //for ClearMods
// Making the separate video folder // Making the separate video folder
Utils::Hook(0x5D70DA, R_Cinematic_BinkOpen_stub01, HOOK_CALL).install()->quick(); Utils::Hook(0x5D70DA, R_Cinematic_BinkOpenStub1, HOOK_CALL).install()->quick();
Utils::Hook(0x5D70FC, R_Cinematic_BinkOpen_stub02, HOOK_CALL).install()->quick();
Utils::Hook(0x5674F8, updateLanguageStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x5674F8, UpdateLanguageStub, HOOK_JUMP).install()->quick();
// Com_Quit_f_stub for auto-update. // Com_Quit_f_stub for auto-update.
Utils::Hook(0x595324, Com_Quit_f_stub, HOOK_CALL).install()->quick(); Utils::Hook(0x595324, Com_Quit_f_Stub, HOOK_CALL).install()->quick();
// Increase fps cap to 250 for menus. // Increase fps cap to 250 for menus.
Utils::Hook::Set<BYTE>(0x535881, 0xEB); Utils::Hook::Set<BYTE>(0x535881, 0xEB);
@ -480,8 +542,6 @@ namespace Components
Utils::Hook::Set<float*>(0x447661, BuildVersionColor); Utils::Hook::Set<float*>(0x447661, BuildVersionColor);
Utils::Hook::Set<float*>(0x43A8D2, BuildVersionColor); Utils::Hook::Set<float*>(0x43A8D2, BuildVersionColor);
// Changing the font in video cinematic from 'normalFont' to 'extraBigFont'.
Utils::Hook::Set<DWORD>(0x56502B, 0x6ABEC4);
Utils::Hook::Nop(0x4477A1, 4); Utils::Hook::Nop(0x4477A1, 4);
Utils::Hook::Nop(0x44045E, 5); // MAX_PACKET_USERCMDS\n Utils::Hook::Nop(0x44045E, 5); // MAX_PACKET_USERCMDS\n
@ -490,6 +550,13 @@ namespace Components
// ui_showList: changing the font. // ui_showList: changing the font.
Utils::Hook::Set<DWORD>(0x57164F, 0x129ADB8); Utils::Hook::Set<DWORD>(0x57164F, 0x129ADB8);
// Patch in-game console dvars
Utils::Hook(0x439943, RegisterConColorStub1, HOOK_JUMP).install()->quick();
Utils::Hook(0x439986, RegisterConColorStub2, HOOK_JUMP).install()->quick();
Utils::Hook(0x4399C9, RegisterConColorStub3, HOOK_JUMP).install()->quick();
Utils::Hook(0x439A12, RegisterConColorStub4, HOOK_JUMP).install()->quick();
Utils::Hook(0x439A5B, RegisterConColorStub5, HOOK_JUMP).install()->quick();
// Mouse fix // Mouse fix
Utils::Hook::Nop(0x59681C, 8); Utils::Hook::Nop(0x59681C, 8);
Scheduler::Loop([] Scheduler::Loop([]

View File

@ -9,5 +9,20 @@ namespace Components
inline static bool iw3sp_mod_ff_exists; inline static bool iw3sp_mod_ff_exists;
CommonPatch(); CommonPatch();
private: private:
static void SV_CheatsStub();
static void DB_LoadCommonFastFiles();
static void RunModStub();
static void ClearModStub();
static void R_Cinematic_BinkOpenStub1(char* buffer, size_t size, const char* /*format*/, const char* directory, const char* fileName, const char* videoFormat);
static void Com_Quit_f_Stub();
static void UpdateLanguageStub();
static int R_RegisterSunDvarsStub();
static Game::dvar_s* RegisterConColor(const char* dvarName, float r, float g, float b, float a, float min, float max, unsigned __int16 flags, const char* description);
static void RegisterConColorStub1();
static void RegisterConColorStub2();
static void RegisterConColorStub3();
static void RegisterConColorStub4();
static void RegisterConColorStub5();
static void LanguageSetValueConfig(int langIndex);
}; };
} }