Merge pull request #241 from diamante0018/custom-bullet-features

Add user requested features
This commit is contained in:
Edo 2022-05-03 18:04:00 +01:00 committed by GitHub
commit d6c4159bdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 4 deletions

View File

@ -106,6 +106,7 @@ namespace Components
Loader::Register(new ClientCommand());
Loader::Register(new ScriptExtension());
Loader::Register(new RawMouse());
Loader::Register(new Bullet());
Loader::Pregame = false;
}

View File

@ -137,3 +137,4 @@ namespace Components
#include "Modules/Gamepad.hpp"
#include "Modules/ScriptExtension.hpp"
#include "Modules/RawMouse.hpp"
#include "Modules/Bullet.hpp"

View File

@ -0,0 +1,60 @@
#include <STDInclude.hpp>
namespace Components
{
Dvar::Var Bullet::BGSurfacePenetration;
Game::dvar_t* Bullet::BGBulletRange;
float Bullet::BG_GetSurfacePenetrationDepthStub(const Game::WeaponDef* weapDef, int surfaceType)
{
assert(weapDef != nullptr);
assert(weapDef->penetrateType != Game::PenetrateType::PENETRATE_TYPE_NONE);
assert(weapDef->penetrateType < Game::PenetrateType::PENETRATE_TYPE_COUNT);
assert(static_cast<size_t>(surfaceType) < Game::materialSurfType_t::SURF_TYPE_COUNT);
const auto penetrationDepth = BGSurfacePenetration.get<float>();
if (penetrationDepth > 0.0f)
{
// Custom depth
return penetrationDepth;
}
// Game's code
if (surfaceType != Game::materialSurfType_t::SURF_TYPE_DEFAULT)
{
return (*Game::penetrationDepthTable)[weapDef->penetrateType][surfaceType];
}
return 0.0f;
}
__declspec(naked) void Bullet::Bullet_FireStub()
{
__asm
{
push eax
mov eax, BGBulletRange
fld dword ptr [eax + 0x10] // dvar_t.current.value
pop eax
push 0x440346
retn
}
}
Bullet::Bullet()
{
Dvar::OnInit([]
{
BGSurfacePenetration = Dvar::Register<float>("bg_surfacePenetration", 0.0f,
0.0f, std::numeric_limits<float>::max(), Game::dvar_flag::DVAR_CODINFO,
"Set to a value greater than 0 to override the surface penetration depth");
BGBulletRange = Game::Dvar_RegisterFloat("bg_bulletRange", 8192.0f,
0.0f, std::numeric_limits<float>::max(), Game::dvar_flag::DVAR_CODINFO,
"Max range used when calculating the bullet end position");
});
Utils::Hook(0x4F6980, BG_GetSurfacePenetrationDepthStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x440340, Bullet_FireStub, HOOK_JUMP).install()->quick();
}
}

View File

@ -0,0 +1,19 @@
#pragma once
namespace Components
{
class Bullet : public Component
{
public:
Bullet();
private:
static Dvar::Var BGSurfacePenetration;
// Can't use Var class inside assembly stubs
static Game::dvar_t* BGBulletRange;
static float BG_GetSurfacePenetrationDepthStub(const Game::WeaponDef* weapDef, int surfaceType);
static void Bullet_FireStub();
};
}

View File

@ -193,7 +193,7 @@ namespace Game
Load_snd_alias_list_nameArray_t Load_snd_alias_list_nameArray = Load_snd_alias_list_nameArray_t(0x4499F0);
Menus_CloseAll_t Menus_CloseAll = Menus_CloseAll_t(0x4BA5B0);
Menus_CloseRequest_t Menus_CloseRequest = Menus_CloseRequest_t(0x430D50);
Menus_CloseRequest_t Menus_CloseRequest = Menus_CloseRequest_t(0x430D50);
Menus_OpenByName_t Menus_OpenByName = Menus_OpenByName_t(0x4CCE60);
Menus_FindByName_t Menus_FindByName = Menus_FindByName_t(0x487240);
Menu_IsVisible_t Menu_IsVisible = Menu_IsVisible_t(0x4D77D0);
@ -550,6 +550,8 @@ namespace Game
level_locals_t* level = reinterpret_cast<level_locals_t*>(0x1A831A8);
float(*penetrationDepthTable)[PENETRATE_TYPE_COUNT][SURF_TYPE_COUNT] = reinterpret_cast<float(*)[PENETRATE_TYPE_COUNT][SURF_TYPE_COUNT]>(0x7C4878);
WinMouseVars_t* s_wmv = reinterpret_cast<WinMouseVars_t*>(0x649D640);
int* window_center_x = reinterpret_cast<int*>(0x649D638);
@ -1593,7 +1595,7 @@ namespace Game
__declspec(naked) void AimAssist_UpdateAdsLerp(const AimInput* /*aimInput*/)
{
__asm
__asm
{
mov eax, [esp + 0x4]
mov ebx, 0x569AA0

View File

@ -477,8 +477,8 @@ namespace Game
typedef void(__cdecl * Menus_CloseAll_t)(UiContext* dc);
extern Menus_CloseAll_t Menus_CloseAll;
typedef void(__cdecl * Menus_CloseRequest_t)(UiContext *dc, menuDef_t* menu);
extern Menus_CloseRequest_t Menus_CloseRequest;
typedef void(__cdecl * Menus_CloseRequest_t)(UiContext* dc, menuDef_t* menu);
extern Menus_CloseRequest_t Menus_CloseRequest;
typedef int(__cdecl * Menus_OpenByName_t)(UiContext* dc, const char* p);
extern Menus_OpenByName_t Menus_OpenByName;
@ -1148,6 +1148,8 @@ namespace Game
extern level_locals_t* level;
extern float(*penetrationDepthTable)[PENETRATE_TYPE_COUNT][SURF_TYPE_COUNT];
extern WinMouseVars_t* s_wmv;
extern int* window_center_x;

View File

@ -96,6 +96,43 @@ namespace Game
ASSET_TYPE_INVALID = -1,
};
enum materialSurfType_t
{
SURF_TYPE_DEFAULT,
SURF_TYPE_BARK,
SURF_TYPE_BRICK,
SURF_TYPE_CARPET,
SURF_TYPE_CLOTH,
SURF_TYPE_CONCRETE,
SURF_TYPE_DIRT,
SURF_TYPE_FLESH,
SURF_TYPE_FOLIAGE,
SURF_TYPE_GLASS,
SURF_TYPE_GRASS,
SURF_TYPE_GRAVEL,
SURF_TYPE_ICE,
SURF_TYPE_METAL,
SURF_TYPE_MUD,
SURF_TYPE_PAPER,
SURF_TYPE_PLASTER,
SURF_TYPE_ROCK,
SURF_TYPE_SAND,
SURF_TYPE_SNOW,
SURF_TYPE_WATER,
SURF_TYPE_WOOD,
SURF_TYPE_ASPHALT,
SURF_TYPE_CERAMIC,
SURF_TYPE_PLASTIC,
SURF_TYPE_RUBBER,
SURF_TYPE_CUSHION,
SURF_TYPE_FRUIT,
SURF_TYPE_PAINTED_METAL,
SURF_TYPE_RIOT_SHIELD,
SURF_TYPE_SLUSH,
SURF_TYPE_COUNT
};
enum dvar_flag : unsigned __int16
{
DVAR_NONE = 0x0, // No flags