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

Commit 872c3cb

Browse files
committed
nSkinz advancedfx-v0.1.30
- Fixes #51 view model inspect-reload wiggling. - Other fix(es).
1 parent 9f4274b commit 872c3cb

File tree

7 files changed

+68
-60
lines changed

7 files changed

+68
-60
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ Although written from scratch, nSkinz was heavily influenced by [chameleon-ng](h
3131

3232
## Requirements for compiling
3333

34-
* Tested under: [Microsoft Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/community/)
35-
* Latest [Git](https://git-scm.com/downloads)
34+
* Tested under: Microsoft Visual Studio Community 2022
35+
* [DirectX SDK](https://www.microsoft.com/en-ca/download/details.aspx?id=6812)
3636

3737
## Usage
3838

3939
Currently only Windows is supported, however this may change ~~in the future~~ if you submit a PR because I'm lazy.
4040

4141
* Clone the source with:
42-
```git clone --recurse-submodules https://github.com/advancedfx/nSkinz.git```
43-
* Compile into a x86 library using your preferred compiler
42+
```git clone --recursive https://github.com/advancedfx/nSkinz.git```
43+
* Compile using your preferred compiler
4444
* Inject the resulting library into the game
4545
* Press <kbd>Insert</kbd> to bring up the menu.
4646
* Setup weapon configuration(s)

src/Hooks/Hooks.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ 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-
//};
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+
};
4949

5050
struct C_BaseAttributableItem_UpdateOnRemove
5151
{
@@ -58,5 +58,5 @@ namespace hooks
5858

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

src/Hooks/PostDataUpdate.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -345,30 +345,3 @@ void On_FRAME_NET_UPDATE_POSTDATAUPDATE_START(sdk::C_BasePlayer* local)
345345
}
346346
}*/
347347
}
348-
349-
void patch_view_model(sdk::C_BaseViewModel * view_model) {
350-
if (nullptr == view_model) return;
351-
352-
hook_viewmodel(view_model);
353-
354-
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(view_model->GetWeapon());
355-
356-
if (view_model_weapon) {
357-
patch_weapon(view_model_weapon);
358-
359-
auto item = (sdk::C_BaseAttributableItem*)view_model_weapon;
360-
361-
auto& definition_index = view_model_weapon->GetItemDefinitionIndex();
362-
// All knives are terrorist knives.
363-
const auto active_conf = g_config.get_from_xuid_by_definition_index(item->GetOriginalOwnerXuidLow(), item->GetOriginalOwnerXuidHigh(), is_knife(definition_index) ? WEAPON_KNIFE : definition_index);
364-
if (active_conf && active_conf->definition_override_index) {
365-
hook_weapon_update_on_remove(view_model_weapon);
366-
auto emplace_result = g_weapon_to_orgindex.emplace(view_model_weapon, definition_index);
367-
view_model_weapon->GetItemDefinitionIndex() = active_conf->definition_override_index;
368-
const auto override_info = game_data::get_weapon_info(active_conf->definition_override_index);
369-
if (override_info) {
370-
view_model->GetModelIndex() = g_model_info->GetModelIndex(override_info->viewModel);
371-
}
372-
}
373-
}
374-
}

src/Hooks/Sequence.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,21 +566,23 @@ void hook_viewmodel(sdk::C_BaseViewModel* thisptr)
566566
}
567567
}
568568

569+
void patch_weapon(sdk::C_BaseAttributableItem* weapon);
569570

570-
void MapSequence(sdk::C_BaseViewModel* view_model) {
571+
void MapViewModel(sdk::C_BaseViewModel* view_model) {
571572
hook_viewmodel(view_model);
572573

573574
int nSequence = view_model->GetSequence();
574575
int newSequence = nSequence;
575576
auto& entry = g_weapon_to_org[view_model];
576577
int lastSequence = entry.LastSequence;
577578
entry.LastSequence = nSequence;
578-
int newModelIndex = view_model->GetModelIndex();
579+
int modelIndex = view_model->GetModelIndex();
579580
int lastModelIndex = entry.LastModelIndex;
580-
entry.LastModelIndex = newModelIndex;
581+
entry.LastModelIndex = modelIndex;
581582

582583
const auto view_model_weapon = get_entity_from_handle<sdk::C_BaseAttributableItem>(view_model->GetWeapon());
583584
if (view_model_weapon) {
585+
patch_weapon(view_model_weapon);
584586
const auto weapon_info = game_data::get_weapon_info(view_model_weapon->GetItemDefinitionIndex());
585587
if (weapon_info) {
586588
const auto definition_index = view_model_weapon->GetItemDefinitionIndex();
@@ -590,8 +592,14 @@ void MapSequence(sdk::C_BaseViewModel* view_model) {
590592
if (nullptr != active_conf && 0 != active_conf->definition_override_index) {
591593
auto it = g_weapon_to_orgindex.find(view_model_weapon);
592594
if (it != g_weapon_to_orgindex.end()) {
595+
hook_weapon_update_on_remove(view_model_weapon);
596+
auto emplace_result = g_weapon_to_orgindex.emplace(view_model_weapon, definition_index);
597+
const auto override_info = game_data::get_weapon_info(active_conf->definition_override_index);
598+
if (override_info) {
599+
view_model->GetModelIndex() = g_model_info->GetModelIndex(override_info->viewModel);
600+
}
593601

594-
if (lastSequence != nSequence || entry.LastNewSequence == -1 || newModelIndex != lastModelIndex)
602+
if (lastSequence != nSequence || entry.LastNewSequence == -1 || modelIndex != lastModelIndex)
595603
newSequence = do_sequence_remapping(it->second, nSequence, active_conf->definition_override_index);
596604
else
597605
newSequence = entry.LastNewSequence;
@@ -605,9 +613,10 @@ void MapSequence(sdk::C_BaseViewModel* view_model) {
605613
view_model->GetSequence() = newSequence;
606614
}
607615

608-
void UnmapSequence(sdk::C_BaseViewModel* view_model) {
616+
void UnmapViewModel(sdk::C_BaseViewModel* view_model) {
609617
auto it = g_weapon_to_org.find(view_model);
610618
if(it != g_weapon_to_org.end()) {
611619
view_model->GetSequence() = it->second.LastSequence;
620+
view_model->GetModelIndex() = it->second.LastModelIndex;
612621
}
613622
}

src/SDK/CBaseEntity.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace sdk
9292
NETVAR(GetOwner, "CBaseViewModel", "m_hOwner", CBaseHandle);
9393
//NETPROP(GetModelIndexProp, "CBaseViewModel", "m_nModelIndex");
9494
//NETPROP(GetWeaponProp, "CBaseViewModel", "m_hWeapon");
95-
NETPROP(GetSequenceProp, "CBaseViewModel", "m_nSequence");
95+
//NETPROP(GetSequenceProp, "CBaseViewModel", "m_nSequence");
9696

9797
//void SetSequence(int nSequence)
9898
//{

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

268268
ImGui::End();
269269
}

src/nSkinz.cpp

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ sdk::C_CS_PlayerResource** g_player_resource;
4343
//vmt_smart_hook* g_client_hook;
4444
//vmt_smart_hook* g_game_event_manager_hook;
4545

46-
//recv_prop_hook* g_modelindex_hook;
47-
//recv_prop_hook* g_weapon_hook;
46+
recv_prop_hook* g_modelindex_hook;
47+
recv_prop_hook* g_weapon_hook;
4848
recv_prop_hook* g_sequence_hook;
4949

5050
auto ensure_dynamic_hooks() -> void
@@ -81,10 +81,9 @@ void On_FRAME_NET_UPDATE_POSTDATAUPDATE_START(sdk::C_BasePlayer* local);
8181

8282
hooks::IBaseClientDLL_FrameStageNotify::Fn* hooks::IBaseClientDLL_FrameStageNotify::m_original;
8383

84-
void MapSequence(sdk::C_BaseViewModel*view_model);
85-
void UnmapSequence(sdk::C_BaseViewModel* view_model);
84+
void MapViewModel(sdk::C_BaseViewModel* view_model);
85+
void UnmapViewModel(sdk::C_BaseViewModel* view_model);
8686
void patch_weapon(sdk::C_BaseAttributableItem* weapon);
87-
void patch_view_model(sdk::C_BaseViewModel* view_model);
8887

8988
auto __fastcall hooks::IBaseClientDLL_FrameStageNotify::hooked(sdk::IBaseClientDLL* thisptr, void*, sdk::ClientFrameStage_t curStage) -> void
9089
{
@@ -119,6 +118,42 @@ auto __fastcall hooks::IBaseClientDLL_FrameStageNotify::hooked(sdk::IBaseClientD
119118
}
120119
}
121120
}
121+
} break;
122+
case sdk::FRAME_NET_UPDATE_END:
123+
{
124+
for (int idx = 0; idx <= g_entity_list->GetMaxEntities(); ++idx)
125+
{
126+
if (auto ent = g_entity_list->GetClientEntity(idx))
127+
{
128+
if (auto bent = ent->GetBaseEntity())
129+
{
130+
const char* className = bent->GetClassname();
131+
132+
if (0 == strcmp("predicted_viewmodel", className))
133+
{
134+
auto view_model = static_cast<sdk::C_BaseViewModel*>(bent);
135+
MapViewModel(view_model);
136+
}
137+
}
138+
}
139+
}
140+
m_original(thisptr, nullptr, curStage);
141+
} break;
142+
case sdk::FRAME_NET_UPDATE_START:
143+
{
144+
for (int idx = 0; idx <= g_entity_list->GetMaxEntities(); ++idx)
145+
{
146+
if (auto ent = g_entity_list->GetClientEntity(idx))
147+
{
148+
if (auto bent = ent->GetBaseEntity())
149+
{
150+
if (0 == strcmp("predicted_viewmodel", bent->GetClassname()))
151+
{
152+
UnmapViewModel(static_cast<sdk::C_BaseViewModel*>(bent));
153+
}
154+
}
155+
}
156+
}
122157
m_original(thisptr, nullptr, curStage);
123158
} break;
124159
default:
@@ -127,15 +162,6 @@ auto __fastcall hooks::IBaseClientDLL_FrameStageNotify::hooked(sdk::IBaseClientD
127162

128163
}
129164

130-
131-
void __cdecl hooks::sequence_proxy_fn(const sdk::CRecvProxyData* proxy_data_const, void* entity, void* output) {
132-
auto view_model = static_cast<sdk::C_BaseViewModel*>(entity);
133-
patch_view_model(view_model);
134-
UnmapSequence(view_model);
135-
g_sequence_hook->get_original_function()(proxy_data_const, entity, output);
136-
MapSequence(view_model);
137-
}
138-
139165
auto initialize(void* instance) -> void
140166
{
141167
g_client = get_interface<sdk::IBaseClientDLL>(get_client_name(), CLIENT_DLL_INTERFACE_VERSION);
@@ -169,8 +195,8 @@ auto initialize(void* instance) -> void
169195
//const auto weapon_prop = sdk::C_BaseViewModel::GetWeaponProp();
170196
//g_weapon_hook = new recv_prop_hook(weapon_prop, &hooks::weapon_proxy_fn);
171197

172-
const auto squence_prop = sdk::C_BaseViewModel::GetSequenceProp();
173-
g_sequence_hook = new recv_prop_hook(squence_prop, &hooks::sequence_proxy_fn);
198+
//const auto squence_prop = sdk::C_BaseViewModel::GetSequenceProp();
199+
//g_sequence_hook = new recv_prop_hook(squence_prop, &hooks::sequence_proxy_fn);
174200

175201
const auto team_arr_prop = sdk::C_CS_PlayerResource::GetTeamProp();
176202
const auto team_prop = team_arr_prop->m_pDataTable->m_pProps;

0 commit comments

Comments
 (0)