Skip to content

Commit

Permalink
add proper flashlight (attached to weapon)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Feb 16, 2024
1 parent d2c37e1 commit 5a9c0c8
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/components/modules/rtx/rtx_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ namespace components
{
on_edit = ImGui::DragFloat3("Direction", rtx_lights::rtx_debug_lights[i].dir, 0.05f) ? true : on_edit;

if (rtx_lights::rtx_debug_lights[i].attach)
if (rtx_lights::rtx_debug_lights[i].attach_to_head)
{
on_edit = ImGui::DragFloat3("Direction Offset", rtx_lights::rtx_debug_lights[i].dir_offset, 0.05f) ? true : on_edit;
}
Expand All @@ -317,7 +317,16 @@ namespace components

if (rtx_lights::rtx_debug_lights[i].type != D3DLIGHT_DIRECTIONAL)
{
ImGui::Checkbox("Attach light to head", &rtx_lights::rtx_debug_lights[i].attach);
if (ImGui::Checkbox("Attach light to head", &rtx_lights::rtx_debug_lights[i].attach_to_head))
{
rtx_lights::rtx_debug_lights[i].attach_to_weapon = false;
}

ImGui::SameLine(0, 20.0f);
if (ImGui::Checkbox("Attach light to weapon", &rtx_lights::rtx_debug_lights[i].attach_to_weapon))
{
rtx_lights::rtx_debug_lights[i].attach_to_head = false;
}

if (ImGui::Button("Move light to player"))
{
Expand Down Expand Up @@ -401,7 +410,6 @@ namespace components
if (game::cm->materials[num].material[0])
{
map_materials += std::to_string(num) + ": " + std::string(game::cm->materials[num].material) + "\n";
//map_materials.emplace_back(game::cm->materials[num].material);
}
}
}
Expand Down
79 changes: 71 additions & 8 deletions src/components/modules/rtx/rtx_lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,90 @@ namespace components
ff_light->Theta = utils::vector::deg_to_rad(setting->inner_angle); // 3.14f / 8.0f;
}

if (setting->attach && setting->enable)

// #
// attach light to head / weapon (tag_flash)

if (setting->attach_to_head && setting->enable)
{
game::vec3_t fwd, rt, up = {};
utils::vector::angle_vectors(game::cgs->predictedPlayerState.viewangles, fwd, rt, up);

setting->origin[0] = game::cgs->predictedPlayerState.origin[0] + (utils::vector::dot3(fwd, setting->dir_offset));
setting->origin[1] = game::cgs->predictedPlayerState.origin[1] + (utils::vector::dot3(rt, setting->dir_offset));
setting->origin[2] = game::cgs->predictedPlayerState.origin[2] + game::cgs->predictedPlayerState.viewHeightCurrent + (utils::vector::dot3(up, setting->dir_offset));

utils::vector::copy(setting->origin, &ff_light->Position.x, 3);

ff_light->Direction.x = fwd[0];
ff_light->Direction.y = fwd[1];
ff_light->Direction.z = fwd[2];
setting->dir[0] = fwd[0];
setting->dir[1] = fwd[1];
setting->dir[2] = fwd[2];
utils::vector::copy(setting->dir, &ff_light->Direction.x, 3);
}
else if (setting->attach_to_weapon && setting->enable)
{
game::vec3_t forward_vec = {};
game::orientation_t orient = {};
std::uint8_t bone = 254;

// we need to handle view and world separately
// ignore thirdperson if thirdperson-hack is enabled

// update gui settings
utils::vector::copy(fwd, setting->dir, 3);
if (game::cgs->renderingThirdPerson && !flags::has_flag("thirdperson"))
{
auto obj = game::objBuf[game::clientObjMap[game::cgs->predictedPlayerEntity.nextState.number]];
if (game::DObjGetBoneIndex(&obj, game::scr_const->tag_flash, &bone))
{
// get orientation of tag_flash
game::CG_DObjGetWorldBoneMatrix(&game::cgs->viewModelPose, bone, orient.axis[0], &obj, orient.origin);

setting->origin[0] = orient.origin[0];
setting->origin[1] = orient.origin[1];
setting->origin[2] = orient.origin[2];
utils::vector::copy(setting->origin, &ff_light->Position.x, 3);

game::AxisToAngles(setting->dir, orient.axis);
utils::vector::angle_vectors(setting->dir, forward_vec, nullptr, nullptr);

ff_light->Direction.x = forward_vec[0];
ff_light->Direction.y = forward_vec[1];
ff_light->Direction.z = forward_vec[2];
utils::vector::copy(forward_vec, setting->dir, 3);
}
}
else // viewweapon (if not thirdperson)
{
std::uint32_t weapon_num = game::cgs->predictedPlayerState.offHandIndex;
if ((game::cgs->predictedPlayerState.weapFlags & 2) == 0)
{
weapon_num = game::cgs->predictedPlayerState.weapon;
}

if (weapon_num > 0)
{
const auto obj = game::cg_weaponsArray[weapon_num].viewModelDObj;
if (game::DObjGetBoneIndex(obj, game::scr_const->tag_flash, &bone))
{
// get orientation of tag_flash
game::CG_DObjGetWorldBoneMatrix(&game::cgs->viewModelPose, bone, orient.axis[0], obj, orient.origin);

setting->origin[0] = orient.origin[0];
setting->origin[1] = orient.origin[1];
setting->origin[2] = orient.origin[2];
utils::vector::copy(setting->origin, &ff_light->Position.x, 3);

game::AxisToAngles(setting->dir, orient.axis);
utils::vector::angle_vectors(setting->dir, forward_vec, nullptr, nullptr);

ff_light->Direction.x = forward_vec[0];
ff_light->Direction.y = forward_vec[1];
ff_light->Direction.z = forward_vec[2];
utils::vector::copy(forward_vec, setting->dir, 3);
}
}
}
}
};


for (auto i = 0; i < RTX_DEBUGLIGHT_AMOUNT; i++)
{
if (rtx_debug_lights[i].enable)
Expand Down
3 changes: 2 additions & 1 deletion src/components/modules/rtx/rtx_lights.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace components
struct rtx_debug_light
{
bool enable = false;
bool attach = false;
bool attach_to_head = false;
bool attach_to_weapon = false;
bool virgin = true;
int disable_hack = 10;

Expand Down
82 changes: 80 additions & 2 deletions src/game/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace game
game::ComWorld* com = reinterpret_cast<game::ComWorld*>(0x1435CB8);
game::GfxWorld* gfx_world = reinterpret_cast<game::GfxWorld*>(0xD0701E0);

game::DObj_s* objBuf = reinterpret_cast<game::DObj_s*>(0x1477F30);
std::uint16_t* clientObjMap = reinterpret_cast<std::uint16_t*>(0x14A9F30);
game::centity_s* cg_entitiesArray = reinterpret_cast<game::centity_s*>(0x84F2D8);
game::weaponInfo_s* cg_weaponsArray = reinterpret_cast<game::weaponInfo_s*>(0x748658);

int* com_frameTime = reinterpret_cast<int*>(0x1476EFC);
float* com_timescaleValue = reinterpret_cast<float*>(0x1435D68);

Expand Down Expand Up @@ -747,6 +752,79 @@ namespace game
}
}

int GetTagPos(std::uint16_t tag, game::centity_s* ent, float* origin_out)
{
const static uint32_t func_addr = 0x4024B0;
int return_val = 0;

__asm
{
push origin_out;
movzx esi, tag;
mov ecx, ent;
movzx eax, byte ptr[ecx + 4];
call func_addr;
add esp, 4;
mov return_val, eax;
}

return return_val;
}

int DObjGetBoneIndex(DObj_s* obj /*ecx*/, int tag_name, BYTE* bone_index)
{
const static uint32_t func_addr = 0x57F2B0;
int result = 0;
__asm
{
push bone_index;
push tag_name;
mov ecx, obj;
call func_addr;
add esp, 8;
mov result, eax;
}

return result;
}

int CG_GetBoneIndex(int local_client_num /*eax*/, int tag_name /*edx*/, int nextstate_num, char* bone)
{
const static uint32_t func_addr = 0x435A50;
int result = 0;
__asm
{
push bone;
push nextstate_num;
mov edx, tag_name;
mov eax, local_client_num;
call func_addr;
add esp, 8;
mov result, eax;
}

return result;
}

int CG_DObjGetWorldBoneMatrix(cpose_t* pose /*eax*/, int bone_index /*ecx*/, float* axis /*esi*/, DObj_s* obj, float* origin)
{
const static uint32_t func_addr = 0x433F00;
int result = 0;
__asm
{
push origin;
push obj;
mov esi, axis;
mov ecx, bone_index;
mov eax, pose;
call func_addr;
add esp, 8;
mov result, eax;
}

return result;
}

int is_button_pressed(int button, int button_data)
{
int tmp, i = 0;
Expand Down Expand Up @@ -798,8 +876,8 @@ namespace game

game::WeaponDef** BG_WeaponNames = reinterpret_cast<game::WeaponDef**>(0x736DB8);

int* g_entities = reinterpret_cast<int*>(0x12885C4);
int* g_clients = reinterpret_cast<int*>(0x13255A8);
game::gentity_s* g_entities = reinterpret_cast<game::gentity_s*>(0x12885C4);
game::gclient_s* g_clients = reinterpret_cast<game::gclient_s*>(0x13255A8);

bool Jump_Check(game::pmove_t* pm /*eax*/, game::pml_t* pml)
{
Expand Down
17 changes: 13 additions & 4 deletions src/game/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ namespace game
extern game::ComWorld* com;
extern game::GfxWorld* gfx_world;

extern game::DObj_s* objBuf;
extern std::uint16_t* clientObjMap;
extern game::centity_s* cg_entitiesArray;
extern game::weaponInfo_s* cg_weaponsArray;

extern int* com_frameTime;
extern float* com_timescaleValue;

Expand Down Expand Up @@ -293,6 +298,10 @@ namespace game
void Scr_AddVector(float* out /*esi*/); // ASM
float Scr_GetFloat(unsigned int arg_index /*eax*/); // ASM

int GetTagPos(std::uint16_t tag, game::centity_s* ent, float* origin_out); // ASM
int DObjGetBoneIndex(DObj_s* obj /*ecx*/, int tag_name, BYTE* bone_index); // ASM
int CG_GetBoneIndex(int local_client_num /*eax*/, int tag_name /*edx*/, int nextstate_num, char* bone); // ASM
int CG_DObjGetWorldBoneMatrix(cpose_t* pose /*eax*/, int bone_index /*ecx*/, float* axis /*esi*/, DObj_s* obj, float* origin); // ASM
int is_button_pressed(int button, int button_data);


Expand All @@ -301,8 +310,8 @@ namespace game

extern game::WeaponDef** BG_WeaponNames;

extern int* g_entities;
extern int* g_clients;
extern game::gentity_s* g_entities;
extern game::gclient_s* g_clients;

static utils::function<void(game::pmove_t* pm)> PmoveSingle = 0x4143A0;
static utils::function<void(game::pmove_t* pm)> PM_UpdateSprint = 0x40E6A0;
Expand Down Expand Up @@ -399,10 +408,10 @@ namespace game
}

// using RegisterNew - ENUM (04)
static utils::function<dvar_s* (const char *dvar_name, DvarType type_enum, std::uint16_t flags, const char *description, std::int32_t default_index, std::int32_t null1, std::int32_t null2, std::int32_t null3, std::int32_t enumSize, const char** enum_data)>
static utils::function<dvar_s* (const char *dvar_name, DvarType type_enum, std::uint16_t flags, const char *description, std::uint32_t default_index, std::int32_t null1, std::int32_t null2, std::int32_t null3, std::uint32_t enumSize, const char** enum_data)>
Dvar_RegisterEnum_r = 0x56C130;

inline dvar_s* Dvar_RegisterEnum(const char* dvar_name, const char* description, std::int32_t default_value, std::int32_t enum_size, const char** enum_data, std::uint16_t flags) {
inline dvar_s* Dvar_RegisterEnum(const char* dvar_name, const char* description, std::uint32_t default_value, std::uint32_t enum_size, const char** enum_data, std::uint16_t flags) {
return Dvar_RegisterEnum_r(dvar_name, DvarType::DVAR_TYPE_ENUM, flags, description, default_value, 0, 0, 0, enum_size, enum_data);
}

Expand Down
34 changes: 34 additions & 0 deletions src/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,12 @@ namespace game
float absmax[3];
};

struct orientation_t
{
float origin[3];
float axis[3][3];
};

struct dmaterial_t
{
char material[64];
Expand Down Expand Up @@ -7436,6 +7442,34 @@ namespace game
const char** argv[8];
};

enum itemType_t
{
IT_BAD = 0x0,
IT_WEAPON = 0x1,
};

struct gitem_s
{
itemType_t giType;
};

struct weaponInfo_s
{
DObj_s* viewModelDObj;
XModel* handModel;
XModel* gogglesModel;
XModel* rocketModel;
XModel* knifeModel;
char weapModelIdx;
unsigned int partBits[4];
int iPrevAnim;
XAnimTree_s* tree;
int registered;
gitem_s* item;
const char* translatedDisplayName;
const char* translatedModename;
const char* translatedAIOverlayDescription;
};

struct dynBrush_t
{
Expand Down

0 comments on commit 5a9c0c8

Please sign in to comment.