Merge branch '1.15' of https://github.com/h1-mod/h1-mod into imgui

This commit is contained in:
mjkzy 2022-05-28 21:19:51 -05:00
commit 3d6fef94d0
6 changed files with 94 additions and 18 deletions

View File

@ -0,0 +1,46 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
namespace bullet
{
namespace
{
game::dvar_t* bg_surface_penetration = nullptr;
utils::hook::detour bg_get_surface_penetration_depth_hook;
float bg_get_surface_penetration_depth_stub(game::Weapon weapon, bool is_alternate, int surface_type)
{
if (bg_surface_penetration->current.value > 0.0f)
{
return bg_surface_penetration->current.value;
}
return bg_get_surface_penetration_depth_hook.invoke<float>(weapon, is_alternate, surface_type);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (game::environment::is_sp())
{
return;
}
bg_surface_penetration = dvars::register_float("bg_surfacePenetration", 0.0f,
0.0f, std::numeric_limits<float>::max(), game::DVAR_FLAG_SAVED,
"Set to a value greater than 0 to override the surface penetration depth");
bg_get_surface_penetration_depth_hook.create(0x2E1110_b, &bg_get_surface_penetration_depth_stub);
}
};
}
REGISTER_COMPONENT(bullet::component)

View File

@ -35,7 +35,6 @@ namespace dvars
struct dvar_vector3 : dvar_base
{
float x{};
float y{};
float z{};
@ -43,6 +42,12 @@ namespace dvars
float max{};
};
struct dvar_enum : dvar_base
{
const char* const* value_list{};
int default_index{};
};
struct dvar_int : dvar_base
{
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_vector2> register_vector2_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, float> set_float_overrides;
@ -210,6 +216,16 @@ namespace dvars
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)
{
set_bool_overrides[name] = value;
@ -245,6 +261,7 @@ namespace dvars
utils::hook::detour dvar_register_string_hook;
utils::hook::detour dvar_register_vector2_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_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);
}
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)
{
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_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_enum_hook.create(SELECT_VALUE(0x419500_b, 0x182700_b), &dvar_register_enum);
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_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_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_float(const std::string& name, float fl);

View File

@ -1,5 +1,8 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "dvars.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
@ -30,7 +33,6 @@ namespace renderer
void gfxdrawmethod()
{
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
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->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");
r_init_draw_method_hook.create(SELECT_VALUE(0x1404BD140, 0x1405C46E0), &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_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(0x583560_b, 0x6A78C0_b), &r_update_front_end_dvar_options_stub);
// use "saved" flags for "r_normalMap"
utils::hook::set<uint8_t>(SELECT_VALUE(0x1404CF5CA, 0x1405D460E), game::DVAR_FLAG_SAVED);
// use "saved" flags for "r_specularMap"
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);
// use "saved" flags
dvars::override::register_enum("r_normalMap", game::DVAR_FLAG_SAVED);
dvars::override::register_enum("r_specularMap", game::DVAR_FLAG_SAVED);
dvars::override::register_enum("r_specOccMap", game::DVAR_FLAG_SAVED);
}
};
}
//REGISTER_COMPONENT(renderer::component)
REGISTER_COMPONENT(renderer::component)

View File

@ -45,9 +45,9 @@ namespace slowmotion
return;
}
utils::hook::jump(0x140365480, scr_cmd_set_slow_motion);
utils::hook::jump(0x43D2E0_b, scr_cmd_set_slow_motion);
}
};
}
//REGISTER_COMPONENT(slowmotion::component)
REGISTER_COMPONENT(slowmotion::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<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<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};
@ -135,7 +135,7 @@ namespace game
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<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,
float y, float xScale, float yScale, float rotation, float* color,
int style, int cursor_pos, char cursor_char,
@ -249,7 +249,7 @@ namespace game
WEAK symbol<scrVmPub_t> scr_VmPub{0xC3F4E20, 0xB7AE3C0};
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<dvar_t> dvarPool{0xC90E560, 0x344DF20};