Add cg_drawfps + fixes
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
#include "dvars.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -87,8 +88,6 @@ namespace fps
|
||||
cg_perf.previous_ms = cg_perf.current_ms;
|
||||
|
||||
perf_calc_fps(&cg_perf, cg_perf.frame_ms);
|
||||
|
||||
utils::hook::invoke<void>(SELECT_VALUE(0x1405487A0, 0x1406575A0));
|
||||
}
|
||||
|
||||
void cg_draw_fps()
|
||||
@ -98,14 +97,17 @@ namespace fps
|
||||
const auto fps = fps::get_fps();
|
||||
|
||||
const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25);
|
||||
const auto fps_string = utils::string::va("%i", fps);
|
||||
if (font)
|
||||
{
|
||||
const auto fps_string = utils::string::va("%i", fps);
|
||||
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) - game::R_TextWidth(
|
||||
fps_string, 0x7FFFFFFF, font);
|
||||
const auto y = font->pixelHeight + 10.f;
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 15.0f) -
|
||||
game::R_TextWidth(fps_string, 0x7FFFFFFF, font);
|
||||
const auto y = font->pixelHeight + 10.f;
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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*/,
|
||||
const char* desc)
|
||||
game::dvar_t* cg_draw_fps_register_stub()
|
||||
{
|
||||
cg_drawfps = dvars::register_int("cg_drawFps", 0, 0, 2, game::DVAR_FLAG_SAVED, "Draw frames per second");
|
||||
return cg_drawfps;
|
||||
@ -151,22 +152,31 @@ namespace fps
|
||||
|
||||
// fps setup
|
||||
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::call(SELECT_VALUE(0x140139F48, 0x140222A46), &cg_draw_fps_register_stub);
|
||||
utils::hook::jump(SELECT_VALUE(0, 0x343847_b), utils::hook::assemble([](utils::hook::assembler& a)
|
||||
{
|
||||
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);
|
||||
|
||||
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())
|
||||
{
|
||||
// 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");
|
||||
|
||||
@ -179,4 +189,4 @@ namespace fps
|
||||
};
|
||||
}
|
||||
|
||||
//REGISTER_COMPONENT(fps::component)
|
||||
REGISTER_COMPONENT(fps::component)
|
||||
|
@ -41,16 +41,6 @@ namespace stats
|
||||
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()
|
||||
{
|
||||
return 0;
|
||||
@ -75,14 +65,15 @@ namespace stats
|
||||
}
|
||||
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,
|
||||
"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,
|
||||
"Whether classes should be locked based on the player's stats or always unlocked.");
|
||||
|
||||
is_item_unlocked_hook.create(0x19E6E0_b, is_item_unlocked_stub);
|
||||
is_item_unlocked_hook2.create(0x19E070_b, is_item_unlocked_stub2);
|
||||
is_item_unlocked_hook3.create(0x19D390_b, is_item_unlocked_stub3);
|
||||
dvars::register_bool("cg_unlockall_loot", false, game::DVAR_FLAG_SAVED,
|
||||
"Whether loot should be locked based on the player's stats or always unlocked.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/binary_resource.hpp>
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
@ -35,6 +36,8 @@ namespace ui_scripting
|
||||
utils::hook::detour hks_load_hook;
|
||||
utils::hook::detour db_find_xasset_header_hook;
|
||||
|
||||
const auto lui_common = utils::nt::load_resource(LUI_COMMON);
|
||||
|
||||
struct script
|
||||
{
|
||||
std::string name;
|
||||
@ -185,7 +188,7 @@ namespace ui_scripting
|
||||
|
||||
game_type["getping"] = [](const game&)
|
||||
{
|
||||
//return *::game::mp::ping;
|
||||
return *::game::mp::ping;
|
||||
};
|
||||
|
||||
game_type["issingleplayer"] = [](const game&)
|
||||
@ -218,6 +221,8 @@ namespace ui_scripting
|
||||
lua["table"]["unpack"] = lua["unpack"];
|
||||
lua["luiglobals"] = lua;
|
||||
|
||||
load_script("lui_common", lui_common);
|
||||
|
||||
load_scripts("h1-mod/ui_scripts/");
|
||||
load_scripts("data/ui_scripts/");
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ namespace game
|
||||
WEAK symbol<int> svs_numclients{0x0, 0x2DC338C};
|
||||
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};
|
||||
|
||||
|
@ -1,6 +1,30 @@
|
||||
menucallbacks = {}
|
||||
originalmenus = {}
|
||||
stack = {}
|
||||
local menucallbacks = {}
|
||||
local originalmenus = {}
|
||||
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)
|
||||
local oncancel = stack.oncancel
|
||||
@ -14,9 +38,7 @@ LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
|
||||
end
|
||||
})
|
||||
|
||||
local listchildren = popup:getChildById("LUIHorizontalList"):getchildren()
|
||||
local children = listchildren[2]:getchildren()
|
||||
popup.text = children[2]
|
||||
popup.text = popup:getLastChild():getPreviousSibling():getPreviousSibling()
|
||||
|
||||
stack = {
|
||||
ret = popup
|
||||
@ -76,10 +98,10 @@ LUI.onmenuopen = function(name, callback)
|
||||
originalmenus[name] = LUI.MenuBuilder.m_types_build[name]
|
||||
LUI.MenuBuilder.m_types_build[name] = function(...)
|
||||
local args = {...}
|
||||
local menu = originalmenus[name](table.unpack(args))
|
||||
local menu = originalmenus[name](unpack(args))
|
||||
|
||||
for k, v in luiglobals.next, menucallbacks[name] do
|
||||
v(menu, table.unpack(args))
|
||||
for k, v in next, menucallbacks[name] do
|
||||
v(menu, unpack(args))
|
||||
end
|
||||
|
||||
return menu
|
||||
@ -136,7 +158,7 @@ LUI.openpopupmenu = function(menu, args)
|
||||
end
|
||||
|
||||
LUI.yesnopopup = function(data)
|
||||
for k, v in luiglobals.next, data do
|
||||
for k, v in next, data do
|
||||
stack[k] = v
|
||||
end
|
||||
LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_")
|
||||
@ -144,21 +166,9 @@ LUI.yesnopopup = function(data)
|
||||
end
|
||||
|
||||
LUI.confirmationpopup = function(data)
|
||||
for k, v in luiglobals.next, data do
|
||||
for k, v in next, data do
|
||||
stack[k] = v
|
||||
end
|
||||
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
|
||||
return stack.ret
|
||||
end
|
||||
|
||||
function userdata_:getchildren()
|
||||
local children = {}
|
||||
local first = self:getFirstChild()
|
||||
|
||||
while (first) do
|
||||
table.insert(children, first)
|
||||
first = first:getNextSibling()
|
||||
end
|
||||
|
||||
return children
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user