Add cg_drawfps + fixes

This commit is contained in:
Federico Cecchetto 2022-05-20 21:11:58 +02:00
parent 949a0821f8
commit 9d0f319c02
7 changed files with 193 additions and 185 deletions

View File

@ -93,6 +93,7 @@ function infoelement(data)
local value = LUI.UIText.new({ local value = LUI.UIText.new({
left = left + 5, left = left + 5,
top = textoffsety, top = textoffsety,
font = labelfont.Font,
height = textheight, height = textheight,
leftAnchor = true, leftAnchor = true,
topAnchor = true, topAnchor = true,
@ -156,3 +157,4 @@ LUI.onmenuopen("mp_hud", function(hud)
hud.static:addElement(infobar) hud.static:addElement(infobar)
end) end)

View File

@ -9,6 +9,10 @@ game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS", "Unlock all items")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS_DESC", game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS_DESC",
"Whether items should be locked based on the player's stats or always unlocked.") "Whether items should be locked based on the player's stats or always unlocked.")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT", "Unlock all loot")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT_DESC",
"Whether loot should be locked based on the player's stats or always unlocked.")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES", "Unlock all classes") game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES", "Unlock all classes")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES_DESC", game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES_DESC",
"Whether classes should be locked based on the player's stats or always unlocked.") "Whether classes should be locked based on the player's stats or always unlocked.")
@ -69,6 +73,15 @@ LUI.MenuBuilder.registerType("stats_menu", function(a1)
value = false value = false
}}, nil, nil) }}, nil, nil)
LUI.Options.CreateOptionButton(menu, "cg_unlockall_loot", "@LUA_MENU_UNLOCKALL_LOOT",
"@LUA_MENU_UNLOCKALL_LOOT_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
LUI.Options.CreateOptionButton(menu, "cg_unlockall_classes", "@LUA_MENU_UNLOCKALL_CLASSES", LUI.Options.CreateOptionButton(menu, "cg_unlockall_classes", "@LUA_MENU_UNLOCKALL_CLASSES",
"@LUA_MENU_UNLOCKALL_CLASSES_DESC", {{ "@LUA_MENU_UNLOCKALL_CLASSES_DESC", {{
text = "@LUA_MENU_ENABLED", text = "@LUA_MENU_ENABLED",
@ -82,63 +95,31 @@ LUI.MenuBuilder.registerType("stats_menu", function(a1)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0 local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0 local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local rank = luiglobals.Lobby.GetRankForXP(experience, prestige) local rank = Lobby.GetRankForXP(experience, prestige)
local saved = true
local prestigevalue = prestige
local rankvalue = rank
local rankbutton = nil
prestigeeditbutton(menu, function(value) prestigeeditbutton(menu, function(value)
prestigevalue = value Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "prestige", tonumber(value))
saved = false
end) end)
rankbutton = rankeditbutton(menu, function(value) rankeditbutton(menu, function(value)
rankvalue = value local rank = tonumber(value)
saved = false
end)
local savebutton = menu:AddButton("@LUA_MENU_SAVE", function()
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "prestige", tonumber(prestigevalue))
local rank = tonumber(rankvalue)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0 local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = rank == 0 and 0 or luiglobals.Rank.GetRankMaxXP(tonumber(rankvalue) - 1, prestige) local experience = rank == 0 and 0 or Rank.GetRankMaxXP(tonumber(value) - 1, prestige)
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "experience", experience) Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "experience", experience)
end)
saved = true
end, nil, nil, nil, {
desc_text = Engine.Localize("LUA_MENU_SAVE_DESC")
})
LUI.Options.InitScrollingList(menu.list, nil) LUI.Options.InitScrollingList(menu.list, nil)
LUI.Options.AddOptionTextInfo(menu) LUI.Options.AddOptionTextInfo(menu)
menu:AddBackButton(function() menu:AddBackButton()
if (saved) then
LUI.FlowManager.RequestLeaveMenu(menu)
return
end
LUI.yesnopopup({
title = Engine.Localize("@MENU_NOTICE"),
text = Engine.Localize("@LUA_MENU_UNSAVED_CHANGES"),
callback = function(result)
if (result) then
LUI.FlowManager.RequestLeaveMenu(menu)
end
end
})
end)
return menu return menu
end) end)
function prestigeeditbutton(menu, callback) function prestigeeditbutton(menu, callback)
local options = {} local options = {}
local max = luiglobals.Lobby.GetMaxPrestigeLevel() local max = Lobby.GetMaxPrestigeLevel()
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0 local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
for i = 0, max do for i = 0, max do
@ -161,9 +142,9 @@ function rankeditbutton(menu, callback)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0 local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0 local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local rank = luiglobals.Lobby.GetRankForXP(experience, prestige) local rank = Lobby.GetRankForXP(experience, prestige)
local max = luiglobals.Rank.GetMaxRank(prestige) local max = Rank.GetMaxRank(prestige)
local maxprestige = luiglobals.Lobby.GetMaxPrestigeLevel() local maxprestige = Lobby.GetMaxPrestigeLevel()
for i = 0, max do for i = 0, max do
game:addlocalizedstring("LUA_MENU_" .. i, i .. "") game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
@ -180,11 +161,20 @@ function rankeditbutton(menu, callback)
nil, callback) nil, callback)
end end
local isclasslocked = luiglobals.Cac.IsCustomClassLocked local isclasslocked = Cac.IsCustomClassLocked
luiglobals.Cac.IsCustomClassLocked = function(...) Cac.IsCustomClassLocked = function(...)
if (Engine.GetDvarBool("cg_unlockall_classes")) then if (Engine.GetDvarBool("cg_unlockall_classes")) then
return false return false
end end
return isclasslocked(table.unpack({...})) return isclasslocked(...)
end
local getlockstate = Engine.GetItemLockState
Engine.GetItemLockState = function(...)
local status, state, msg = getlockstate(...)
if (state == Cac.ItemLockStatus.NotInInventory and Engine.GetDvarBool("cg_unlockall_loot")) then
return "Unlocked", 0, ""
end
return status, state, msg
end end

View File

@ -5,6 +5,7 @@
#include "game/game.hpp" #include "game/game.hpp"
#include "game/dvars.hpp" #include "game/dvars.hpp"
#include "dvars.hpp"
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include <utils/string.hpp> #include <utils/string.hpp>
@ -87,8 +88,6 @@ namespace fps
cg_perf.previous_ms = cg_perf.current_ms; cg_perf.previous_ms = cg_perf.current_ms;
perf_calc_fps(&cg_perf, cg_perf.frame_ms); perf_calc_fps(&cg_perf, cg_perf.frame_ms);
utils::hook::invoke<void>(SELECT_VALUE(0x1405487A0, 0x1406575A0));
} }
void cg_draw_fps() void cg_draw_fps()
@ -98,16 +97,19 @@ namespace fps
const auto fps = fps::get_fps(); const auto fps = fps::get_fps();
const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25); const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25);
if (font)
{
const auto fps_string = utils::string::va("%i", fps); const auto fps_string = utils::string::va("%i", fps);
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) - game::R_TextWidth( const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) -
fps_string, 0x7FFFFFFF, font); game::R_TextWidth(fps_string, 0x7FFFFFFF, font);
const auto y = font->pixelHeight + 10.f; const auto y = font->pixelHeight + 10.f;
const auto fps_color = fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad); const auto fps_color = fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad);
game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, font, x, y, 1.f, 1.f, 0.0f, fps_color, 6); game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, font, x, y, 1.f, 1.f, 0.0f, fps_color, 6);
} }
} }
}
void cg_draw_ping() void cg_draw_ping()
{ {
@ -124,8 +126,7 @@ namespace fps
} }
} }
game::dvar_t* cg_draw_fps_register_stub(const char* name, const char** _enum, const int value, unsigned int /*flags*/, game::dvar_t* cg_draw_fps_register_stub()
const char* desc)
{ {
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second"); cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second");
return cg_drawfps; return cg_drawfps;
@ -151,22 +152,31 @@ namespace fps
// fps setup // fps setup
cg_perf.perf_start = std::chrono::high_resolution_clock::now(); cg_perf.perf_start = std::chrono::high_resolution_clock::now();
utils::hook::call(SELECT_VALUE(0x14018D261, 0x14025B747), &perf_update);
// change cg_drawfps flags to saved utils::hook::jump(SELECT_VALUE(0, 0x343847_b), utils::hook::assemble([](utils::hook::assembler& a)
utils::hook::call(SELECT_VALUE(0x140139F48, 0x140222A46), &cg_draw_fps_register_stub); {
a.pushad64();
a.call_aligned(perf_update);
a.popad64();
a.call(0x702250_b);
a.mov(edx, 3);
a.xor_(ecx, ecx);
a.jmp(0x343853_b);
}), true);
// Don't register cg_drawfps
utils::hook::nop(0x31D74F_b, 0x1C);
utils::hook::nop(0x31D76F_b, 0x7);
scheduler::loop(cg_draw_fps, scheduler::pipeline::renderer); scheduler::loop(cg_draw_fps, scheduler::pipeline::renderer);
if (game::environment::is_sp())
{
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second"); cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second");
}
if (game::environment::is_mp()) if (game::environment::is_mp())
{ {
// fix ping value // fix ping value
utils::hook::nop(0x14025AC41, 2); utils::hook::nop(0x342C6C_b, 2);
cg_drawping = dvars::register_int("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED, "Choose to draw ping"); cg_drawping = dvars::register_int("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED, "Choose to draw ping");
@ -179,4 +189,4 @@ namespace fps
}; };
} }
//REGISTER_COMPONENT(fps::component) REGISTER_COMPONENT(fps::component)

View File

@ -41,16 +41,6 @@ namespace stats
return is_item_unlocked_hook2.invoke<int>(a1, a2, a3, a4, a5, a6); return is_item_unlocked_hook2.invoke<int>(a1, a2, a3, a4, a5, a6);
} }
int is_item_unlocked_stub3(int a1)
{
if (cg_unlock_all_items->current.enabled)
{
return 0;
}
return is_item_unlocked_hook3.invoke<int>(a1);
}
int is_item_unlocked() int is_item_unlocked()
{ {
return 0; return 0;
@ -75,14 +65,15 @@ namespace stats
} }
else else
{ {
is_item_unlocked_hook.create(0x19E6E0_b, is_item_unlocked_stub);
is_item_unlocked_hook2.create(0x19E070_b, is_item_unlocked_stub2);
cg_unlock_all_items = dvars::register_bool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED, cg_unlock_all_items = dvars::register_bool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED,
"Whether items should be locked based on the player's stats or always unlocked."); "Whether items should be locked based on the player's stats or always unlocked.");
dvars::register_bool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED, dvars::register_bool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED,
"Whether classes should be locked based on the player's stats or always unlocked."); "Whether classes should be locked based on the player's stats or always unlocked.");
dvars::register_bool("cg_unlockall_loot", false, game::DVAR_FLAG_SAVED,
is_item_unlocked_hook.create(0x19E6E0_b, is_item_unlocked_stub); "Whether loot should be locked based on the player's stats or always unlocked.");
is_item_unlocked_hook2.create(0x19E070_b, is_item_unlocked_stub2);
is_item_unlocked_hook3.create(0x19D390_b, is_item_unlocked_stub3);
} }
} }
}; };

View File

@ -21,6 +21,7 @@
#include <utils/string.hpp> #include <utils/string.hpp>
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include <utils/io.hpp> #include <utils/io.hpp>
#include <utils/binary_resource.hpp>
namespace ui_scripting namespace ui_scripting
{ {
@ -35,6 +36,8 @@ namespace ui_scripting
utils::hook::detour hks_load_hook; utils::hook::detour hks_load_hook;
utils::hook::detour db_find_xasset_header_hook; utils::hook::detour db_find_xasset_header_hook;
const auto lui_common = utils::nt::load_resource(LUI_COMMON);
struct script struct script
{ {
std::string name; std::string name;
@ -185,7 +188,7 @@ namespace ui_scripting
game_type["getping"] = [](const game&) game_type["getping"] = [](const game&)
{ {
//return *::game::mp::ping; return *::game::mp::ping;
}; };
game_type["issingleplayer"] = [](const game&) game_type["issingleplayer"] = [](const game&)
@ -218,6 +221,8 @@ namespace ui_scripting
lua["table"]["unpack"] = lua["unpack"]; lua["table"]["unpack"] = lua["unpack"];
lua["luiglobals"] = lua; lua["luiglobals"] = lua;
load_script("lui_common", lui_common);
load_scripts("h1-mod/ui_scripts/"); load_scripts("h1-mod/ui_scripts/");
load_scripts("data/ui_scripts/"); load_scripts("data/ui_scripts/");
} }

View File

@ -252,7 +252,7 @@ namespace game
WEAK symbol<int> svs_numclients{0x0, 0x2DC338C}; WEAK symbol<int> svs_numclients{0x0, 0x2DC338C};
WEAK symbol<int> gameTime{0x0, 0x0}; WEAK symbol<int> gameTime{0x0, 0x0};
WEAK symbol<int> ping{0x0, 0x0}; WEAK symbol<int> ping{0x0, 0x2ECCF40};
WEAK symbol<int> sv_serverId_value{0x0, 0x0}; WEAK symbol<int> sv_serverId_value{0x0, 0x0};

View File

@ -1,6 +1,30 @@
menucallbacks = {} local menucallbacks = {}
originalmenus = {} local originalmenus = {}
stack = {} local stack = {}
function getchildren(element)
local children = {}
local first = element:getFirstChild()
while (first) do
table.insert(children, first)
first = first:getNextSibling()
end
return children
end
function printchildtree(element, indent, last)
indent = indent or ""
print(indent .. "+- " .. element.id .. " " .. (element:getText() or ""))
indent = indent .. (last and " " or "| ")
local children = getchildren(element)
for i = 1, #children do
printchildtree(children[i], indent, i == #children)
end
end
LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event) LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
local oncancel = stack.oncancel local oncancel = stack.oncancel
@ -14,9 +38,7 @@ LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
end end
}) })
local listchildren = popup:getChildById("LUIHorizontalList"):getchildren() popup.text = popup:getLastChild():getPreviousSibling():getPreviousSibling()
local children = listchildren[2]:getchildren()
popup.text = children[2]
stack = { stack = {
ret = popup ret = popup
@ -76,10 +98,10 @@ LUI.onmenuopen = function(name, callback)
originalmenus[name] = LUI.MenuBuilder.m_types_build[name] originalmenus[name] = LUI.MenuBuilder.m_types_build[name]
LUI.MenuBuilder.m_types_build[name] = function(...) LUI.MenuBuilder.m_types_build[name] = function(...)
local args = {...} local args = {...}
local menu = originalmenus[name](table.unpack(args)) local menu = originalmenus[name](unpack(args))
for k, v in luiglobals.next, menucallbacks[name] do for k, v in next, menucallbacks[name] do
v(menu, table.unpack(args)) v(menu, unpack(args))
end end
return menu return menu
@ -136,7 +158,7 @@ LUI.openpopupmenu = function(menu, args)
end end
LUI.yesnopopup = function(data) LUI.yesnopopup = function(data)
for k, v in luiglobals.next, data do for k, v in next, data do
stack[k] = v stack[k] = v
end end
LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_") LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_")
@ -144,21 +166,9 @@ LUI.yesnopopup = function(data)
end end
LUI.confirmationpopup = function(data) LUI.confirmationpopup = function(data)
for k, v in luiglobals.next, data do for k, v in next, data do
stack[k] = v stack[k] = v
end end
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_") LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
return stack.ret return stack.ret
end end
function userdata_:getchildren()
local children = {}
local first = self:getFirstChild()
while (first) do
table.insert(children, first)
first = first:getNextSibling()
end
return children
end