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

Commit 78336b6

Browse files
committed
nSkinz advancedfx-v0.1.22
- Fixes #33
1 parent 78b8057 commit 78336b6

File tree

7 files changed

+151
-154
lines changed

7 files changed

+151
-154
lines changed

src/Hooks/Hooks.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace hooks
5656

5757
// NetVar Proxies
5858

59-
extern auto __cdecl modelindex_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
60-
extern auto __cdecl weapon_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
59+
//extern auto __cdecl modelindex_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
60+
//extern auto __cdecl weapon_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
6161
//extern auto __cdecl sequence_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void;
6262
}

src/Hooks/PostDataUpdate.cpp

Lines changed: 33 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -82,42 +82,6 @@ void hook_weapon_update_on_remove(sdk::C_BaseAttributableItem* thisptr) {
8282
}
8383
}
8484

85-
struct OrgModelData_s {
86-
int ModelIndex = -1;
87-
int Sequence = -1;
88-
int LastNewSequence = -1;
89-
};
90-
91-
std::map<sdk::C_BaseEntity*, OrgModelData_s> g_weapon_to_org;
92-
sdk::C_BaseEntity* g_lastviewmodel = nullptr;
93-
static std::map<void*, vmt_multi_hook*> C_BaseEntity_UpdateOnRemove_hooks;
94-
95-
vmt_multi_hook* Get_ViewModel_Hook(sdk::C_BaseViewModel* This) {
96-
return C_BaseEntity_UpdateOnRemove_hooks[*(void**)This];
97-
}
98-
99-
void __fastcall C_BaseEntity_UpdateOnRemove_Hook(sdk::C_BaseViewModel* This, void* Edx)
100-
{
101-
if (g_lastviewmodel == This) g_lastviewmodel = nullptr;
102-
g_weapon_to_org.erase(This);
103-
auto pHook = Get_ViewModel_Hook(This);
104-
auto org_fn = pHook->get_original_function<void(__fastcall*)(sdk::C_BaseEntity*, void*)>(127);
105-
org_fn(This, Edx);
106-
}
107-
108-
void hook_viewmodel(sdk::C_BaseViewModel* thisptr) {
109-
110-
if (C_BaseEntity_UpdateOnRemove_hooks.contains(*(void**)thisptr)) return;
111-
112-
vmt_multi_hook* pHook = new vmt_multi_hook();
113-
if (pHook->initialize_and_hook_instance(thisptr)) {
114-
pHook->hook_function(C_BaseEntity_UpdateOnRemove_Hook, 127);
115-
pHook->hook_function(&hooks::C_BaseViewModel_SetSequence::hooked, 219);
116-
C_BaseEntity_UpdateOnRemove_hooks[*(void**)thisptr] = pHook;
117-
}
118-
}
119-
120-
12185
void apply_config_on_attributable_item(sdk::C_BaseAttributableItem* item, item_setting* config, int xuid_lo, int xuid_hi, bool isGlove)
12286
{
12387
uint64_t xuid = (uint64_t)((uint32_t)xuid_lo) << 32 | (uint64_t)(uint32_t)xuid_hi;
@@ -242,59 +206,19 @@ bool GetPlayerIndexToViewModelHash(int index, fnv::hash & hash) {
242206
return true;
243207
}
244208

245-
int do_sequence_remapping(int org_definition_index, int nSequence, int definition_override_index);
246-
247-
void fixup_view_model(sdk::C_BaseViewModel* view_model) {
248-
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(view_model->GetWeapon());
209+
void patch_weapon(sdk::C_BaseAttributableItem* weapon) {
249210

250-
if (view_model_weapon) {
251-
auto item = (sdk::C_BaseAttributableItem*)view_model_weapon;
211+
auto& definition_index = weapon->GetItemDefinitionIndex();
252212

253-
auto& definition_index = view_model_weapon->GetItemDefinitionIndex();
254-
// All knives are terrorist knives.
255-
const auto active_conf = g_config.get_from_xuid_by_definition_index(item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), is_knife(definition_index) ? WEAPON_KNIFE : definition_index);
256-
if (active_conf && active_conf->definition_override_index) {
257-
hook_weapon_update_on_remove(view_model_weapon);
258-
auto emplace_result = g_weapon_to_orgindex.emplace(view_model_weapon, definition_index);
259-
view_model_weapon->GetItemDefinitionIndex() = active_conf->definition_override_index;
260-
const auto override_info = game_data::get_weapon_info(active_conf->definition_override_index);
261-
if (override_info) {
262-
263-
auto& org = g_weapon_to_org[view_model];
264-
265-
int oldModelIndex = view_model->GetModelIndex();
266-
int oldSequence = view_model->GetSequence();
267-
268-
bool bMapSequence = org.LastNewSequence == -1 || oldModelIndex != org.ModelIndex || oldSequence != org.Sequence;
269-
270-
org.ModelIndex = oldModelIndex;
271-
org.Sequence = oldSequence;
272-
273-
int newIndex = g_model_info->GetModelIndex(override_info->viewModel);
274-
view_model->GetModelIndex() = newIndex;
275-
276-
if (bMapSequence) {
277-
int orgIndex = definition_index;
278-
auto it = g_weapon_to_orgindex.find(view_model_weapon);
279-
if (it != g_weapon_to_orgindex.end())
280-
orgIndex = it->second;
281-
int newSequence = do_sequence_remapping(definition_index, oldSequence, active_conf->definition_override_index);
213+
// All knives are terrorist knives.
214+
if (const auto active_conf = g_config.get_from_xuid_by_definition_index(weapon->GetOriginalOwnerXuidLow(), weapon->GetOriginalOwnerXuidHigh(), is_knife(definition_index) ? WEAPON_KNIFE : definition_index))
215+
apply_config_on_attributable_item(weapon, active_conf, weapon->GetOriginalOwnerXuidLow(), weapon->GetOriginalOwnerXuidHigh(), false);
216+
else
217+
erase_override_if_exists_by_index(weapon->GetOriginalOwnerXuidLow(), weapon->GetOriginalOwnerXuidHigh(), definition_index);
218+
}
282219

283-
view_model->GetSequence() = newSequence;
284-
org.LastNewSequence = newSequence;
285-
//view_model->SetSequence(newSequence);
286-
}
287-
else {
288-
view_model->GetSequence() = org.LastNewSequence;
289-
}
290220

291-
hook_viewmodel(view_model);
292-
g_lastviewmodel = view_model;
293-
}
294-
}
295-
}
296-
view_model->ValidateModelIndex();
297-
}
221+
void hook_viewmodel(sdk::C_BaseViewModel* thisptr);
298222

299223
void On_FRAME_NET_UPDATE_POSTDATAUPDATE_START(sdk::C_BasePlayer* local)
300224
{
@@ -389,32 +313,34 @@ void On_FRAME_NET_UPDATE_POSTDATAUPDATE_START(sdk::C_BasePlayer* local)
389313
if (!weapon)
390314
continue;
391315

392-
auto item = (sdk::C_BaseAttributableItem*)weapon;
393-
394-
auto& definition_index = weapon->GetItemDefinitionIndex();
395-
396-
// All knives are terrorist knives.
397-
if (const auto active_conf = g_config.get_from_xuid_by_definition_index(item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), is_knife(definition_index) ? WEAPON_KNIFE : definition_index))
398-
apply_config_on_attributable_item(weapon, active_conf, item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), false);
399-
else
400-
erase_override_if_exists_by_index(item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), definition_index);
316+
patch_weapon(weapon);
401317
}
402318
}
403319

404-
const auto view_model = get_entity_from_handle<sdk::C_BaseViewModel>(local->GetViewModel());
405-
if (view_model) {
406-
fixup_view_model(view_model);
407-
}
408-
}
320+
auto view_model = get_entity_from_handle<sdk::C_BaseViewModel>(local->GetViewModel());
409321

410-
void BeginFixUpViewmodel(sdk::C_BaseViewModel* view_model) {
411-
fixup_view_model(view_model);
412-
}
322+
if (nullptr == view_model) return;
323+
324+
hook_viewmodel(view_model);
325+
326+
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(view_model->GetWeapon());
413327

414-
void EndFixUpViewmodel(sdk::C_BaseViewModel* view_model) {
415-
auto it = g_weapon_to_org.find(view_model);
416-
if (it != g_weapon_to_org.end()) {
417-
view_model->GetModelIndex() = it->second.ModelIndex;
418-
view_model->GetSequence() = it->second.Sequence;
328+
if (view_model_weapon) {
329+
patch_weapon(view_model_weapon);
330+
331+
auto item = (sdk::C_BaseAttributableItem*)view_model_weapon;
332+
333+
auto& definition_index = view_model_weapon->GetItemDefinitionIndex();
334+
// All knives are terrorist knives.
335+
const auto active_conf = g_config.get_from_xuid_by_definition_index(item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), is_knife(definition_index) ? WEAPON_KNIFE : definition_index);
336+
if (active_conf && active_conf->definition_override_index) {
337+
hook_weapon_update_on_remove(view_model_weapon);
338+
auto emplace_result = g_weapon_to_orgindex.emplace(view_model_weapon, definition_index);
339+
view_model_weapon->GetItemDefinitionIndex() = active_conf->definition_override_index;
340+
const auto override_info = game_data::get_weapon_info(active_conf->definition_override_index);
341+
if (override_info) {
342+
view_model->GetModelIndex() = g_model_info->GetModelIndex(override_info->viewModel);
343+
}
344+
}
419345
}
420346
}

src/Hooks/Sequence.cpp

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,46 @@ int do_sequence_remapping(int org_definition_index, int nSequence, int definitio
530530
}
531531

532532

533-
vmt_multi_hook* Get_ViewModel_Hook(sdk::C_BaseViewModel* This);
534533
void hook_weapon_update_on_remove(sdk::C_BaseAttributableItem* thisptr);
534+
vmt_multi_hook* Get_ViewModel_Hook(sdk::C_BaseViewModel* This);
535+
536+
struct OrgModelData_s {
537+
int LastSequence = -1;
538+
int LastNewSequence = -1;
539+
};
540+
541+
std::map<sdk::C_BaseEntity*, OrgModelData_s> g_weapon_to_org;
542+
static std::map<void*, vmt_multi_hook*> C_BaseEntity_UpdateOnRemove_hooks;
543+
544+
vmt_multi_hook* Get_ViewModel_Hook(sdk::C_BaseViewModel* This) {
545+
return C_BaseEntity_UpdateOnRemove_hooks[*(void**)This];
546+
}
547+
548+
void __fastcall C_BaseEntity_UpdateOnRemove_Hook(sdk::C_BaseViewModel* This, void* Edx)
549+
{
550+
g_weapon_to_org.erase(This);
551+
auto pHook = Get_ViewModel_Hook(This);
552+
auto org_fn = pHook->get_original_function<void(__fastcall*)(sdk::C_BaseEntity*, void*)>(127);
553+
org_fn(This, Edx);
554+
}
535555

536-
auto __fastcall hooks::C_BaseViewModel_SetSequence::hooked(sdk::C_BaseViewModel* This, void* Edx, int nSequence) -> void
556+
void hook_viewmodel(sdk::C_BaseViewModel* thisptr)
537557
{
538-
int newSequence = nSequence;
539-
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(This->GetWeapon());
558+
if (C_BaseEntity_UpdateOnRemove_hooks.contains(*(void**)thisptr)) return;
559+
560+
vmt_multi_hook* pHook = new vmt_multi_hook();
561+
if (pHook->initialize_and_hook_instance(thisptr)) {
562+
pHook->hook_function(C_BaseEntity_UpdateOnRemove_Hook, 127);
563+
//pHook->hook_function(&hooks::C_BaseViewModel_SetSequence::hooked, 219);
564+
C_BaseEntity_UpdateOnRemove_hooks[*(void**)thisptr] = pHook;
565+
}
566+
}
567+
568+
569+
void MapSequence(sdk::C_BaseViewModel* view_model) {
570+
hook_viewmodel(view_model);
571+
572+
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(view_model->GetWeapon());
540573
if (view_model_weapon) {
541574
const auto weapon_info = game_data::get_weapon_info(view_model_weapon->GetItemDefinitionIndex());
542575
if (weapon_info) {
@@ -547,41 +580,30 @@ auto __fastcall hooks::C_BaseViewModel_SetSequence::hooked(sdk::C_BaseViewModel*
547580
if (nullptr != active_conf && 0 != active_conf->definition_override_index) {
548581
auto it = g_weapon_to_orgindex.find(view_model_weapon);
549582
if (it != g_weapon_to_orgindex.end()) {
550-
newSequence = do_sequence_remapping(it->second, nSequence, active_conf->definition_override_index);
583+
int newSequence;
584+
int nSequence = view_model->GetSequence();
585+
586+
auto& entry = g_weapon_to_org[view_model];
587+
588+
int lastSequence = entry.LastSequence;
589+
entry.LastSequence = nSequence;
590+
if (lastSequence != nSequence || entry.LastNewSequence == -1)
591+
newSequence = do_sequence_remapping(it->second, nSequence, active_conf->definition_override_index);
592+
else
593+
newSequence = entry.LastNewSequence;
594+
595+
entry.LastNewSequence = newSequence;
596+
view_model->GetSequence() = newSequence;
551597
}
552598
}
553599
}
554600
}
555601
}
556-
557-
auto pHook = Get_ViewModel_Hook(This);
558-
pHook->get_original_function<void(__fastcall*)(sdk::C_BaseViewModel*, void*, int)>(219)(This, Edx, 0);
559-
}
560-
561-
void BeginFixUpViewmodel(sdk::C_BaseViewModel* ent);
562-
void EndFixUpViewmodel(sdk::C_BaseViewModel* ent);
563-
564-
auto __cdecl hooks::modelindex_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void
565-
{
566-
ensure_dynamic_hooks();
567-
EndFixUpViewmodel(static_cast<sdk::C_BaseViewModel*>(entity));
568-
569-
static auto original_fn = g_modelindex_hook->get_original_function();
570-
original_fn(proxy_data_const, entity, output);
571602
}
572603

573-
void hook_viewmodel(sdk::C_BaseViewModel* thisptr);
574-
575-
auto __cdecl hooks::weapon_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) -> void
576-
{
577-
const auto view_model = static_cast<sdk::C_BaseViewModel*>(entity);
578-
579-
ensure_dynamic_hooks();
580-
hook_viewmodel(view_model);
581-
582-
static auto original_fn = g_weapon_hook->get_original_function();
583-
584-
original_fn(proxy_data_const, entity, output);
585-
586-
BeginFixUpViewmodel(view_model);
604+
void UnmapSequence(sdk::C_BaseViewModel* view_model) {
605+
auto it = g_weapon_to_org.find(view_model);
606+
if(it != g_weapon_to_org.end()) {
607+
view_model->GetSequence() = it->second.LastSequence;
608+
}
587609
}

src/SDK/CBaseEntity.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ namespace sdk
9090
public:
9191
NETVAR(GetWeapon, "CBaseViewModel", "m_hWeapon", CBaseHandle);
9292
NETVAR(GetOwner, "CBaseViewModel", "m_hOwner", CBaseHandle);
93-
NETPROP(GetModelIndexProp, "CBaseViewModel", "m_nModelIndex");
94-
NETPROP(GetWeaponProp, "CBaseViewModel", "m_hWeapon");
93+
//NETPROP(GetModelIndexProp, "CBaseViewModel", "m_nModelIndex");
94+
//NETPROP(GetWeaponProp, "CBaseViewModel", "m_hWeapon");
9595
//NETPROP(GetSequenceProp, "CBaseViewModel", "m_nSequence");
9696

97-
void SetSequence(int nSequence)
98-
{
99-
get_vfunc<void(__thiscall*)(C_BaseViewModel*,int)>(this, 219)(this,nSequence);
100-
}
97+
//void SetSequence(int nSequence)
98+
//{
99+
// get_vfunc<void(__thiscall*)(C_BaseViewModel*,int)>(this, 219)(this,nSequence);
100+
//}
101101
};
102102

103103
class C_PlayerResource

src/SDK/declarations.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ namespace sdk
4242
using RecvVarProxyFn = void(__cdecl *)(const CRecvProxyData*, void*, void*);
4343
using Vector = std::array<float, 3>;
4444

45+
46+
constexpr static auto MAX_EDICT_BITS = 11;
47+
48+
constexpr static auto NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS = 10;
49+
constexpr static auto NUM_NETWORKED_EHANDLE_BITS = MAX_EDICT_BITS + NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS;
50+
constexpr static auto INVALID_NETWORKED_EHANDLE_VALUE = (1 << NUM_NETWORKED_EHANDLE_BITS) - 1;
51+
52+
constexpr static auto NUM_SERIAL_NUM_BITS = 16; // (32 - NUM_ENT_ENTRY_BITS)
53+
constexpr static auto NUM_SERIAL_NUM_SHIFT_BITS = 32 - NUM_SERIAL_NUM_BITS;
4554
constexpr static auto INVALID_EHANDLE_INDEX = 0xFFFFFFFF;
4655
constexpr static auto MAX_PLAYER_NAME_LENGTH = 128;
4756
constexpr static auto SIGNED_GUID_LEN = 32;

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.20)");
266+
ImGui::Text("nSkinz by namazso (advancedfx-v0.1.22)");
267267

268268
ImGui::End();
269269
}

0 commit comments

Comments
 (0)