Merge pull request #73 from h1-mod/renderer

renderer + partial register enum overrides
This commit is contained in:
fed 2022-05-29 01:26:03 +00:00 committed by GitHub
commit c195921c53
4 changed files with 46 additions and 16 deletions

View File

@ -35,7 +35,6 @@ namespace dvars
struct dvar_vector3 : dvar_base struct dvar_vector3 : dvar_base
{ {
float x{}; float x{};
float y{}; float y{};
float z{}; float z{};
@ -43,6 +42,12 @@ namespace dvars
float max{}; float max{};
}; };
struct dvar_enum : dvar_base
{
const char* const* value_list{};
int default_index{};
};
struct dvar_int : dvar_base struct dvar_int : dvar_base
{ {
int value{}; int value{};
@ -139,6 +144,7 @@ namespace dvars
static std::unordered_map<std::string, dvar_string> register_string_overrides; static std::unordered_map<std::string, dvar_string> register_string_overrides;
static std::unordered_map<std::string, dvar_vector2> register_vector2_overrides; static std::unordered_map<std::string, dvar_vector2> register_vector2_overrides;
static std::unordered_map<std::string, dvar_vector3> register_vector3_overrides; static std::unordered_map<std::string, dvar_vector3> register_vector3_overrides;
static std::unordered_map<std::string, dvar_enum> register_enum_overrides;
static std::unordered_map<std::string, bool> set_bool_overrides; static std::unordered_map<std::string, bool> set_bool_overrides;
static std::unordered_map<std::string, float> set_float_overrides; static std::unordered_map<std::string, float> set_float_overrides;
@ -210,6 +216,16 @@ namespace dvars
register_vector3_overrides[name] = std::move(values); register_vector3_overrides[name] = std::move(values);
} }
void register_enum(const std::string& name, /*const char* const* value_list, int default_index,*/
const unsigned int flags)
{
dvar_enum values;
//values.value_list = value_list;
//values.default_index = default_index;
values.flags = flags;
register_enum_overrides[name] = std::move(values);
}
void set_bool(const std::string& name, const bool value) void set_bool(const std::string& name, const bool value)
{ {
set_bool_overrides[name] = value; set_bool_overrides[name] = value;
@ -245,6 +261,7 @@ namespace dvars
utils::hook::detour dvar_register_string_hook; utils::hook::detour dvar_register_string_hook;
utils::hook::detour dvar_register_vector2_hook; utils::hook::detour dvar_register_vector2_hook;
utils::hook::detour dvar_register_vector3_hook; utils::hook::detour dvar_register_vector3_hook;
utils::hook::detour dvar_register_enum_hook;
utils::hook::detour dvar_set_bool_hook; utils::hook::detour dvar_set_bool_hook;
utils::hook::detour dvar_set_float_hook; utils::hook::detour dvar_set_float_hook;
@ -377,6 +394,19 @@ namespace dvars
return dvar_register_vector3_hook.invoke<game::dvar_t*>(hash, name, x, y, z, min, max, flags); return dvar_register_vector3_hook.invoke<game::dvar_t*>(hash, name, x, y, z, min, max, flags);
} }
game::dvar_t* dvar_register_enum(const int hash, const char* name, const char* const value_list, int default_index, unsigned int flags)
{
auto* var = find_dvar(override::register_enum_overrides, hash);
if (var)
{
//value_list = var->value_list;
//default_index = var->default_index;
flags = var->flags;
}
return dvar_register_enum_hook.invoke<game::dvar_t*>(hash, name, value_list, default_index, flags);
}
void dvar_set_bool(game::dvar_t* dvar, bool boolean) void dvar_set_bool(game::dvar_t* dvar, bool boolean)
{ {
const auto disabled = find_dvar(disable::set_bool_disables, dvar->hash); const auto disabled = find_dvar(disable::set_bool_disables, dvar->hash);
@ -473,6 +503,7 @@ namespace dvars
dvar_register_string_hook.create(SELECT_VALUE(0x4197E0_b, 0x182BD0_b), &dvar_register_string); dvar_register_string_hook.create(SELECT_VALUE(0x4197E0_b, 0x182BD0_b), &dvar_register_string);
dvar_register_vector2_hook.create(SELECT_VALUE(0x4198C0_b, 0x182CB0_b), &dvar_register_vector2); dvar_register_vector2_hook.create(SELECT_VALUE(0x4198C0_b, 0x182CB0_b), &dvar_register_vector2);
dvar_register_vector3_hook.create(SELECT_VALUE(0x419A00_b, 0x182DB0_b), &dvar_register_vector3); dvar_register_vector3_hook.create(SELECT_VALUE(0x419A00_b, 0x182DB0_b), &dvar_register_vector3);
dvar_register_enum_hook.create(SELECT_VALUE(0x419500_b, 0x182700_b), &dvar_register_enum);
if (!game::environment::is_sp()) if (!game::environment::is_sp())
{ {

View File

@ -18,6 +18,7 @@ namespace dvars
void register_string(const std::string& name, const std::string& value, const unsigned int flags); void register_string(const std::string& name, const std::string& value, const unsigned int flags);
void register_vec2(const std::string& name, float x, float y, float min, float max, const unsigned int flags); void register_vec2(const std::string& name, float x, float y, float min, float max, const unsigned int flags);
void register_vec3(const std::string& name, float x, float y, float z, float min, float max, const unsigned int flags); void register_vec3(const std::string& name, float x, float y, float z, float min, float max, const unsigned int flags);
void register_enum(const std::string& name, /*const char* const* value_list, int default_index,*/ const unsigned int flags);
void set_bool(const std::string& name, bool boolean); void set_bool(const std::string& name, bool boolean);
void set_float(const std::string& name, float fl); void set_float(const std::string& name, float fl);

View File

@ -1,5 +1,8 @@
#include <std_include.hpp> #include <std_include.hpp>
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "dvars.hpp"
#include "game/game.hpp" #include "game/game.hpp"
#include "game/dvars.hpp" #include "game/dvars.hpp"
@ -30,7 +33,6 @@ namespace renderer
void gfxdrawmethod() void gfxdrawmethod()
{ {
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD; game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
game::gfxDrawMethod->baseTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_LIT; game::gfxDrawMethod->baseTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_LIT;
game::gfxDrawMethod->emissiveTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_EMISSIVE; game::gfxDrawMethod->emissiveTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_EMISSIVE;
game::gfxDrawMethod->forceTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : 242; game::gfxDrawMethod->forceTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : 242;
@ -67,19 +69,15 @@ namespace renderer
dvars::r_fullbright = dvars::register_int("r_fullbright", 0, 0, 4, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting"); dvars::r_fullbright = dvars::register_int("r_fullbright", 0, 0, 4, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting");
r_init_draw_method_hook.create(SELECT_VALUE(0x1404BD140, 0x1405C46E0), &r_init_draw_method_stub); r_init_draw_method_hook.create(SELECT_VALUE(0x5467E0_b, 0x669580_b), &r_init_draw_method_stub);
r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x1404F8870, 0x1405FF9E0), &r_update_front_end_dvar_options_stub); r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x583560_b, 0x6A78C0_b), &r_update_front_end_dvar_options_stub);
// use "saved" flags for "r_normalMap" // use "saved" flags
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF5CA, 0x1405D460E), game::DVAR_FLAG_SAVED); dvars::override::register_enum("r_normalMap", game::DVAR_FLAG_SAVED);
dvars::override::register_enum("r_specularMap", game::DVAR_FLAG_SAVED);
// use "saved" flags for "r_specularMap" dvars::override::register_enum("r_specOccMap", game::DVAR_FLAG_SAVED);
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF5F5, 0x1405D4639), game::DVAR_FLAG_SAVED);
// use "saved" flags for "r_specOccMap"
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF620, 0x1405D4664), game::DVAR_FLAG_SAVED);
} }
}; };
} }
//REGISTER_COMPONENT(renderer::component) REGISTER_COMPONENT(renderer::component)

View File

@ -71,7 +71,7 @@ namespace game
WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x41BAD0, 0x1857D0}; WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x41BAD0, 0x1857D0};
WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x41A600, 0x183EB0}; WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x41A600, 0x183EB0};
WEAK symbol<void(const dvar_t* dvar)> Dvar_ClearModified{0x0, 0x0}; WEAK symbol<void(const dvar_t* dvar)> Dvar_ClearModified{0x41A4F0, 0x183D50};
WEAK symbol<void(char* buffer, int index)> Dvar_GetCombinedString{0x3A7D60, 0x4EA020}; WEAK symbol<void(char* buffer, int index)> Dvar_GetCombinedString{0x3A7D60, 0x4EA020};
WEAK symbol<const char*(dvar_t* dvar, bool is_hashed, dvar_value value)> Dvar_ValueToString{0x41CE00, 0x187000}; WEAK symbol<const char*(dvar_t* dvar, bool is_hashed, dvar_value value)> Dvar_ValueToString{0x41CE00, 0x187000};
WEAK symbol<void(dvar_t* dvar, DvarSetSource source)> Dvar_Reset{0x41B5F0, 0x185390}; WEAK symbol<void(dvar_t* dvar, DvarSetSource source)> Dvar_Reset{0x41B5F0, 0x185390};
@ -135,7 +135,7 @@ namespace game
WEAK symbol<int(const char* text, int maxChars, Font_s* font)> R_TextWidth{0x55C7A0, 0x67F8F0}; WEAK symbol<int(const char* text, int maxChars, Font_s* font)> R_TextWidth{0x55C7A0, 0x67F8F0};
WEAK symbol<int(void* font)> R_GetFontHeight{0x55C5C0, 0x67F710}; WEAK symbol<int(void* font)> R_GetFontHeight{0x55C5C0, 0x67F710};
WEAK symbol<void*(int a1)> R_GetSomething{0x55BB90, 0x67ECE0}; WEAK symbol<void*(int a1)> R_GetSomething{0x55BB90, 0x67ECE0};
WEAK symbol<void()> R_SyncRenderThread{0x0, 0x0}; WEAK symbol<void()> R_SyncRenderThread{0x582F30, 0x6A78C0};
WEAK symbol<void*(const char* text, int maxChars, void* font, int fontHeight, float x, WEAK symbol<void*(const char* text, int maxChars, void* font, int fontHeight, float x,
float y, float xScale, float yScale, float rotation, float* color, float y, float xScale, float yScale, float rotation, float* color,
int style, int cursor_pos, char cursor_char, int style, int cursor_pos, char cursor_char,
@ -247,7 +247,7 @@ namespace game
WEAK symbol<scrVmPub_t> scr_VmPub{0xC3F4E20, 0xB7AE3C0}; WEAK symbol<scrVmPub_t> scr_VmPub{0xC3F4E20, 0xB7AE3C0};
WEAK symbol<function_stack_t> scr_function_stack{0xC4015C0, 0xB7B8940}; WEAK symbol<function_stack_t> scr_function_stack{0xC4015C0, 0xB7B8940};
WEAK symbol<GfxDrawMethod_s> gfxDrawMethod{0x0, 0x0}; WEAK symbol<GfxDrawMethod_s> gfxDrawMethod{0xF7530B0, 0xE9213F0};
WEAK symbol<int> dvarCount{0xC90E550, 0x2999C34}; WEAK symbol<int> dvarCount{0xC90E550, 0x2999C34};
WEAK symbol<dvar_t> dvarPool{0xC90E560, 0x344DF20}; WEAK symbol<dvar_t> dvarPool{0xC90E560, 0x344DF20};