Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 475f6a9

Browse files
committed
nskinz advancedfx-v0.1.18
- Try Fix quickswitch animation (advncedfx/nSkinz#31)
1 parent 85b41aa commit 475f6a9

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

src/Hooks/Hooks.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ namespace hooks
4141
static Fn* m_original;
4242
};
4343

44+
struct C_BaseViewModel_SetSequence {
45+
using Fn = void __fastcall(sdk::C_BaseViewModel* thisptr, void*, int nSequence);
46+
static Fn hooked;
47+
static Fn* m_original;
48+
};
49+
4450
struct C_BaseAttributableItem_UpdateOnRemove
4551
{
4652
using Fn = void __fastcall(sdk::C_BaseAttributableItem* thisptr, void*);
@@ -52,5 +58,4 @@ namespace hooks
5258

5359
extern auto __cdecl modelindex_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
5460
extern auto __cdecl weapon_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
55-
extern auto __cdecl sequence_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
5661
}

src/Hooks/PostDataUpdate.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ std::map<sdk::C_BaseAttributableItem*, int> g_weapon_to_orgindex;
6363

6464
hooks::C_BaseAttributableItem_UpdateOnRemove::Fn* hooks::C_BaseAttributableItem_UpdateOnRemove::m_original;
6565

66-
auto __fastcall hooks::C_BaseAttributableItem_UpdateOnRemove::hooked(sdk::C_BaseAttributableItem* thisptr, void*) -> void
66+
auto __fastcall hooks::C_BaseAttributableItem_UpdateOnRemove::hooked(sdk::C_BaseAttributableItem* This, void* Edx) -> void
6767
{
68-
g_weapon_to_orgindex.erase(thisptr);
68+
g_weapon_to_orgindex.erase(This);
69+
hooks::C_BaseAttributableItem_UpdateOnRemove::m_original(This, Edx);
6970
}
7071

7172
void hook_weapon_update_on_remove(sdk::C_BaseAttributableItem* thisptr) {
7273
static bool firstRun = true;
7374
if (firstRun) {
7475
firstRun = false;
75-
vmt_multi_hook weapon_update_on_remove_hook;
76+
static vmt_multi_hook weapon_update_on_remove_hook;
7677
if (weapon_update_on_remove_hook.initialize_and_hook_instance(thisptr))
7778
weapon_update_on_remove_hook.apply_hook<hooks::C_BaseAttributableItem_UpdateOnRemove>(127);
7879
}

src/Hooks/Sequence.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -523,62 +523,61 @@ class SequenceMap {
523523

524524
extern std::map<sdk::C_BaseAttributableItem*, int> g_weapon_to_orgindex;
525525

526-
static auto do_sequence_remapping(sdk::CRecvProxyData* data, sdk::C_BaseViewModel* entity) -> void
526+
static auto do_sequence_remapping(sdk::C_BaseViewModel* entity, int nSequence) -> int
527527
{
528528
const auto owner = get_entity_from_handle<sdk::C_BasePlayer>(entity->GetOwner());
529529

530530
if (!(owner && owner->IsPlayer() && static_cast<sdk::C_BasePlayer*>(owner)->GetLifeState() == sdk::LifeState::ALIVE))
531-
return;
531+
return nSequence;
532532

533533
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(entity->GetWeapon());
534534

535535
if(!view_model_weapon)
536-
return;
536+
return nSequence;
537537

538538
const auto weapon_info = game_data::get_weapon_info(view_model_weapon->GetItemDefinitionIndex());
539539

540540
if(!weapon_info)
541-
return;
541+
return nSequence;
542542

543543
const auto definition_index = view_model_weapon->GetItemDefinitionIndex();
544544

545545
if (!is_knife(definition_index))
546-
return;
546+
return nSequence;
547547

548548
sdk::player_info_t player_info;
549549
if (!g_engine->GetPlayerInfo(owner->GetIndex(), &player_info))
550-
return;
550+
return nSequence;
551551

552552
const auto active_conf = g_config.get_by_definition_index(player_info.userid, WEAPON_KNIFE);
553553
if (nullptr == active_conf || 0 == active_conf->definition_override_index)
554-
return;
554+
return nSequence;
555555

556-
auto& sequence = data->m_Value.m_Int;
557556
int orgIndex = definition_index;
558557
auto it = g_weapon_to_orgindex.find(view_model_weapon);
559558
if (it != g_weapon_to_orgindex.end())
560559
orgIndex = it->second;
561-
sequence = g_SequenceMap.MapSequence(orgIndex, sequence, active_conf->definition_override_index);
560+
return g_SequenceMap.MapSequence(orgIndex, nSequence, active_conf->definition_override_index);
562561
}
563562

564-
// Replacement function that will be called when the view model animation sequence changes.
565-
auto __cdecl hooks::sequence_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void
566-
{
567-
const auto view_model = static_cast<sdk::C_BaseViewModel*>(entity);
568563

569-
// Ensure our other dynamic object hooks are in place.
570-
// Must do this from a game thread.
571-
ensure_dynamic_hooks();
564+
static std::map<void*,vmt_multi_hook *> C_BaseViewModel_SetSequence_hooks;
572565

573-
static auto original_fn = g_sequence_hook->get_original_function();
566+
auto __fastcall hooks::C_BaseViewModel_SetSequence::hooked(sdk::C_BaseViewModel* This, void* Edx, int nSequence) -> void
567+
{
568+
auto &pHook = C_BaseViewModel_SetSequence_hooks[*(void**)This];
569+
pHook->get_original_function<void (__fastcall *)(sdk::C_BaseViewModel*, void*, int)>(219)(This, Edx, do_sequence_remapping(This, nSequence));
570+
}
574571

575-
// Remove the constness from the proxy data allowing us to make changes.
576-
const auto proxy_data = const_cast<sdk::CRecvProxyData*>(proxy_data_const);
572+
void hook_C_BaseViewModel_SetSequence(sdk::C_BaseViewModel* thisptr) {
577573

578-
do_sequence_remapping(proxy_data, view_model);
574+
if (C_BaseViewModel_SetSequence_hooks.contains(*(void**)thisptr)) return;
579575

580-
// Call the original function with our edited data.
581-
original_fn(proxy_data_const, entity, output);
576+
vmt_multi_hook* pHook = new vmt_multi_hook();
577+
if (pHook->initialize_and_hook_instance(thisptr)) {
578+
pHook->hook_function(&hooks::C_BaseViewModel_SetSequence::hooked, 219);
579+
C_BaseViewModel_SetSequence_hooks[*(void**)thisptr] = pHook;
580+
}
582581
}
583582

584583
bool get_fixup_view_model_index(sdk::C_BaseViewModel* view_model, int& outNewIndex, int& outOrgIndex);
@@ -601,6 +600,8 @@ auto __cdecl hooks::weapon_proxy_fn(const sdk::CRecvProxyData* proxy_data_const,
601600
const auto view_model = static_cast<sdk::C_BaseViewModel*>(entity);
602601

603602
ensure_dynamic_hooks();
603+
hook_C_BaseViewModel_SetSequence(view_model);
604+
604605
static auto original_fn = g_weapon_hook->get_original_function();
605606

606607
original_fn(proxy_data_const, entity, output);

src/SDK/CBaseEntity.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ namespace sdk
8181
NETVAR(GetOwner, "CBaseViewModel", "m_hOwner", CBaseHandle);
8282
NETPROP(GetModelIndexProp, "CBaseViewModel", "m_nModelIndex");
8383
NETPROP(GetWeaponProp, "CBaseViewModel", "m_hWeapon");
84-
NETPROP(GetSequenceProp, "CBaseViewModel", "m_nSequence");
8584
};
8685

8786
class C_PlayerResource

src/gui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void draw_gui()
263263
ImGui::PopItemWidth();
264264
ImGui::Columns(1);
265265

266-
ImGui::Text("nSkinz by namazso (advancedfx-v0.1.17)");
266+
ImGui::Text("nSkinz by namazso (advancedfx-v0.1.18)");
267267

268268
ImGui::End();
269269
}

src/nSkinz.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ auto initialize(void* instance) -> void
136136
const auto weapon_prop = sdk::C_BaseViewModel::GetWeaponProp();
137137
g_weapon_hook = new recv_prop_hook(weapon_prop, &hooks::weapon_proxy_fn);
138138

139-
const auto sequence_prop = sdk::C_BaseViewModel::GetSequenceProp();
140-
g_sequence_hook = new recv_prop_hook(sequence_prop, &hooks::sequence_proxy_fn);
141-
142139
const auto team_arr_prop = sdk::C_CS_PlayerResource::GetTeamProp();
143140
const auto team_prop = team_arr_prop->m_pDataTable->m_pProps;
144141
const auto proxy_addr = std::uintptr_t(team_prop->m_ProxyFn);

0 commit comments

Comments
 (0)