-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawModel.cpp
762 lines (641 loc) · 27.4 KB
/
DrawModel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#include "precompiled.h"
#include "CreateMove.h"
#include "CSGO_HX.h"
#include "Targetting.h"
#include "AutoWall.h"
#include "ThirdPerson.h"
#include "LocalPlayer.h"
#include "FarESP.h"
#include "ServerSide.h"
#include "CPlayerrecord.h"
#include "ServerSide.h"
#include "worldsize.h"
#include "Adriel/stdafx.hpp"
struct RenderableInfo_t
{
IClientRenderable* m_pRenderable;
void* m_pAlphaProperty;
int m_EnumCount;
int m_nRenderFrame;
unsigned short m_FirstShadow;
unsigned short m_LeafList;
short m_Area;
uint16_t m_Flags; // 0x0016
uint16_t m_Flags2; // 0x0018
Vector m_vecBloatedAbsMins;
Vector m_vecBloatedAbsMaxs;
Vector m_vecAbsMins;
Vector m_vecAbsMaxs;
int pad;
};
const Vector coord_mins = Vector(MIN_COORD_FLOAT, MIN_COORD_FLOAT, MIN_COORD_FLOAT);
const Vector coord_maxs = Vector(MAX_COORD_FLOAT, MAX_COORD_FLOAT, MAX_COORD_FLOAT);
DrawModelFn oDrawModel;
ListLeavesInBox oListLeavesInBox;
void ForceMaterial(bool ignoreZ, Color clr, IMaterial* material)
{
if (!material)
return;
if (ignoreZ)
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, true);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, true);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, true);
}
else
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, false);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, false);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, false);
}
material->AlphaModulate((float)clr.a() / 255.f);
material->ColorModulate((float)clr.r() / 255.f, (float)clr.g() / 255.f, (float)clr.b() / 255.f);
Interfaces::StudioRender->ForcedMaterialOverride(material);
}
void ForceMaterial(bool ignoreZ, int r, int g, int b, int a, IMaterial* material)
{
if (!material)
return;
if (ignoreZ)
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, true);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, true);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, true);
}
else
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, false);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, false);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, false);
}
material->AlphaModulate((float)a / 255.f);
material->ColorModulate((float)r / 255.f, (float)g / 255.f, (float)b / 255.f);
Interfaces::StudioRender->ForcedMaterialOverride(material);
}
void ForceMaterialAlpha(bool ignoreZ, float a, IMaterial* material)
{
if (!material)
return;
if (ignoreZ)
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, true);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, true);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, true);
}
else
{
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, false);
material->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, false);
material->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, false);
}
material->AlphaModulate((float)a / 255.f);
Interfaces::StudioRender->ForcedMaterialOverride(material);
}
void ForceMaterialAlpha(int alpha, IMaterial* material)
{
if (!material)
return;
material->AlphaModulate(clamp((float)alpha / 255.f, 0.1f, 1.f));
Interfaces::StudioRender->ForcedMaterialOverride(material);
}
void ForceMaterial(IMaterial *mat, ImColor color, bool z_flag)
{
if (!mat)
return;
mat->SetMaterialVarFlag(MATERIAL_VAR_ZNEARER, z_flag);
mat->SetMaterialVarFlag(MATERIAL_VAR_NOFOG, z_flag);
mat->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, z_flag);
mat->ColorModulate(color.Value.x, color.Value.y, color.Value.z);
mat->AlphaModulate(color.Value.w);
Interfaces::StudioRender->ForcedMaterialOverride(mat);
}
int serverticksallowed;
int clientticksallowed;
void __fastcall Hooks::DrawModel(void* ecx, void* edx, void* pResults, const DrawModelInfo_t& info, matrix3x4a_t *pBoneToWorld, float *pFlexWeights, float *pFlexDelayedWeights, Vector &modelOrigin, int flags)
{
START_PROFILING
LocalPlayer.Get(&LocalPlayer);
if (!Interfaces::EngineClient->IsInGame() || !LocalPlayer.Entity || !info.m_pClientEntity || !variable::get().visuals.b_enabled)
{
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
END_PROFILING
return;
}
if (!LocalPlayer.IsFakeLaggingOnPeek
&& info.m_StudioHdr->name[0] == 'p' // NOTE: player\\contactshadow\\contactshadow_leftfoot.mdl player\\contactshadow\\contactshadow_rightfoot.mdl
&& info.m_StudioHdr->name[7] == 'c'
&& info.m_StudioHdr->name[14] == 's'
&& info.m_StudioHdr->name[19] == 'w'
&& info.m_StudioHdr->name[21] == 'c')
{
LocalPlayer.NetvarMutex.Lock();
Vector footpos = LocalPlayer.Entity->GetBonePositionCachedOnly(info.m_StudioHdr->name[35] == 'l' ? HITBOX_LEFT_FOOT : HITBOX_RIGHT_FOOT, (matrix3x4_t*)LocalPlayer.Entity->GetCachedBoneData()->Base());
float len = (modelOrigin - footpos).Length();
if (len < 10.0f)
{
//This is our foot shadow, fix its position
Vector delta = modelOrigin - LocalPlayer.LastAnimatedOrigin;
pBoneToWorld->SetOrigin(LocalPlayer.Entity->GetAbsOriginDirect() + delta);
}
LocalPlayer.NetvarMutex.Unlock();
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
END_PROFILING
return;
}
// release render context
auto pRenderContext = Interfaces::MatSystem->GetRenderContext();
ITexture* texture = pRenderContext->GetRenderTarget();
pRenderContext->Release();
// don't draw over _rt_fullframefb
if (texture)
{
const char* name = texture->GetName();
if (name[4] == 'f' && name[10] == 'a')
{
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexWeights, pFlexDelayedWeights, modelOrigin, flags);
END_PROFILING;
return;
}
}
bool drawn = false;
matrix3x4_t* final_matrix_follow_entities = nullptr;
enum : int
{
MODELTYPE_INVALID,
MODELTYPE_PLAYER,
MODELTYPE_WEAPON,
MODELTYPE_ARMS,
MODELTYPE_VIEWWEAPON,
MODELTYPE_BOMB,
MODELTYPE_PROJ,
};
auto get_model_info = [](const DrawModelInfo_t& info) -> int
{
if (!info.m_StudioHdr || !info.m_pClientEntity)
return MODELTYPE_INVALID;
auto entity = (CBaseEntity*)((DWORD)info.m_pClientEntity - 0x4);
if (entity && entity->IsProjectile())
return MODELTYPE_PROJ;
std::string name = info.m_StudioHdr->name;
//if (name.find(XorStrCT("play")) != std::string::npos)
if (IntFromChars(name, 14) == 'yalp')
return MODELTYPE_PLAYER;
//if (name.find(XorStrCT("arms")) != std::string::npos)
if(IntFromChars(name, 17) == 'smra')
return MODELTYPE_ARMS;
//if (name.find(XorStrCT("weap")) != std::string::npos)
if(IntFromChars(name, 0) == 'paew')
{
if (name[8] == 'v')
return MODELTYPE_VIEWWEAPON;
else if (IntFromChars(name, 10) == '_dei')
return MODELTYPE_BOMB;
return MODELTYPE_WEAPON;
}
return MODELTYPE_INVALID;
};
const auto model_type = get_model_info(info);
if (model_type == MODELTYPE_INVALID)
{
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexWeights, pFlexDelayedWeights, modelOrigin, flags);
END_PROFILING
return;
}
// get renderable entity
auto entity = (CBaseEntity*)((DWORD)info.m_pClientEntity - 0x4);
// check if the player exists (less CPU)
if (model_type == MODELTYPE_PLAYER)
{
if (!entity /*|| !Interfaces::ClientEntList->PlayerExists(entity)*/)
{
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexWeights, pFlexDelayedWeights, modelOrigin, flags);
END_PROFILING
return;
}
}
bool enemy = entity->IsEnemy(LocalPlayer.Entity);
// thirdperson local player aesthetics
if (Interfaces::Input->CAM_IsThirdPerson())
{
if (!entity->IsLocalPlayer() && entity->GetMoveParent()->IsLocalPlayer())
{
if (!LocalPlayer.IsFakeLaggingOnPeek)
{
LocalPlayer.NetvarMutex.Lock();
// this must be a following entity such as the player foot shadow or view model
// fix it by matching the position to the player position
auto parent = entity->GetMoveParent();
matrix3x4_t OriginalMatrixInverted, EndMatrix;
auto cache = entity->GetCachedBoneData();
int numbones = cache->Count();
//Transform the old matrix to the current player position for aesthetic reasons
MatrixInvert(entity->EntityToWorldTransform(), OriginalMatrixInverted);
MatrixCopy(entity->EntityToWorldTransform(), EndMatrix);
//Get relative position from parent position
Vector relative_position = entity->GetAbsOriginDirect() - LocalPlayer.LastAnimatedOrigin;
//Get a positional matrix from the current position of the parent + the relative position of the following entity
PositionMatrix(parent->GetAbsOriginDirect() + relative_position, EndMatrix);
//Get a relative transform
matrix3x4_t TransformedMatrix;
ConcatTransforms(EndMatrix, OriginalMatrixInverted, TransformedMatrix);
final_matrix_follow_entities = new matrix3x4_t[MAXSTUDIOBONES];
for (int i = 0; i < numbones; i++)
{
//Now concat the original matrix with the rotated one
ConcatTransforms(TransformedMatrix, pBoneToWorld[i], final_matrix_follow_entities[i]);
//old matrix dest new matrix
}
//Draw the newly transformed matrix
pBoneToWorld = (matrix3x4a_t*)final_matrix_follow_entities;
LocalPlayer.NetvarMutex.Unlock();
}
}
}
/*auto p_renderable_info = (RenderableInfo_t*)entity->GetClientRenderable();
if (!p_renderable_info->m_pRenderable)
return oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexWeights, pFlexDelayedWeights, modelOrigin, flags);*/
// deal with rendering specific model types
if (model_type == MODELTYPE_PLAYER)
{
bool alive = static_cast<bool>(entity->GetAlive());
int index = entity->entindex();
matrix3x4_t* final_matrix_Real = nullptr;
matrix3x4_t* final_matrix_Fake = nullptr;
if (alive)
{
// local player check
if (entity->IsLocalPlayer())
{
LocalPlayer.NetvarMutex.Lock();
// draw real angle model
matrix3x4_t * original_matrix_Real = LocalPlayer.RealAngleMatrix;
matrix3x4_t * original_matrix_Fake = LocalPlayer.FakeAngleMatrix;
matrix3x4_t OriginalMatrixInverted_Real, EndMatrix_Real;
matrix3x4_t OriginalMatrixInverted_Fake, EndMatrix_Fake;
final_matrix_Real = new matrix3x4_t[MAXSTUDIOBONES];
final_matrix_Fake = new matrix3x4_t[MAXSTUDIOBONES];
auto cache = entity->GetCachedBoneData();
int numbones = cache->Count();
//Transform the old matrix to the current player position for aesthetic reasons
MatrixInvert(LocalPlayer.RealAngleEntityToWorldTransform, OriginalMatrixInverted_Real);
MatrixInvert(LocalPlayer.FakeAngleEntityToWorldTransform, OriginalMatrixInverted_Fake);
MatrixCopy(LocalPlayer.RealAngleEntityToWorldTransform, EndMatrix_Real);
MatrixCopy(LocalPlayer.FakeAngleEntityToWorldTransform, EndMatrix_Fake);
//Set the angles for the new matrix
//AngleMatrix(QAngle(0.0f, LocalPlayer.LowerBodyYaw, 0.0f), EndMatrix);
//Get a positional matrix from the current position
PositionMatrix(entity->GetAbsOriginDirect(), EndMatrix_Real);
PositionMatrix(entity->GetAbsOriginDirect(), EndMatrix_Fake);
//Get a relative transform
matrix3x4_t TransformedMatrix_Real, TransformedMatrix_Fake;
ConcatTransforms(EndMatrix_Real, OriginalMatrixInverted_Real, TransformedMatrix_Real);
ConcatTransforms(EndMatrix_Fake, OriginalMatrixInverted_Fake, TransformedMatrix_Fake);
for (int i = 0; i < numbones; i++)
{
//Now concat the original matrix with the rotated one
ConcatTransforms(TransformedMatrix_Real, original_matrix_Real[i], final_matrix_Real[i]);
ConcatTransforms(TransformedMatrix_Fake, original_matrix_Fake[i], final_matrix_Fake[i]);
}
//Draw the newly transformed matrix
if (!LocalPlayer.IsFakeLaggingOnPeek)
pBoneToWorld = (matrix3x4a_t*)final_matrix_Real;
else
pBoneToWorld = (matrix3x4a_t*)original_matrix_Real;
#ifdef USE_SERVER_SIDE
CSGOPacket* packet = nullptr;
if (pServerSide.IsSocketCreated())
{
auto record = g_LagCompensation.GetPlayerrecord(entity);
if (record)
{
bool found = false;
//sometimes we receive a newer simulation time from the serverside plugin faster than the actual game server sends
for (int i = 0; i < 2 && !found; ++i)
{
record->serversidemutex.lock();
if (i == 0)
packet = record->GetServerSidePacket();
else
packet = record->ServerSidePackets.size() > 1 ? &record->ServerSidePackets.at(1) : nullptr;
if (packet)
{
float flTargetTime = packet->flSimulationTime;
if (LocalPlayer.m_RealMatrixBackups.buffersize)
{
for (BackupMatrixStruct* pk = LocalPlayer.m_RealMatrixBackups.rbegin<BackupMatrixStruct>(); pk != LocalPlayer.m_RealMatrixBackups.rend<BackupMatrixStruct>(); --pk)
{
if (pk->m_SimulationTime == flTargetTime)
{
modelOrigin = packet->absorigin;
pBoneToWorld = (matrix3x4a_t*)pk->m_Matrix;
serverticksallowed = packet->ticksallowedforprocessing;
clientticksallowed = pk->m_TicksAllowedForProcessing;
//Interfaces::DebugOverlay->AddTextOverlay(modelOrigin, TICKS_TO_TIME(2), "Server: %i Client: %i", packet->ticksallowedforprocessing, (*pk)->m_TicksAllowedForProcessing);
found = true;
break;
}
}
}
}
record->serversidemutex.unlock();
}
}
}
#endif
if (LocalPlayer.Config_IsFakelagging() || LocalPlayer.Config_IsDesyncing())
{
// draw fake model
if (variable::get().visuals.b_fake && variable::get().visuals.b_enabled)
{
matrix3x4a_t *dest = !LocalPlayer.IsFakeLaggingOnPeek ? (matrix3x4a_t*)final_matrix_Fake : (matrix3x4a_t*)original_matrix_Fake;
#ifdef USE_SERVER_SIDE
if (pServerSide.IsSocketCreated() && packet)
{
auto record = g_LagCompensation.GetPlayerrecord(entity);
if (record)
{
record->serversidemutex.lock();
float flTargetTime = packet->flSimulationTime;
if (LocalPlayer.m_FakeMatrixBackups.buffersize)
{
for (BackupMatrixStruct* pk = LocalPlayer.m_FakeMatrixBackups.rbegin<BackupMatrixStruct>(); pk != LocalPlayer.m_FakeMatrixBackups.rend<BackupMatrixStruct>(); --pk)
{
if (pk->m_SimulationTime == flTargetTime)
{
modelOrigin = packet->absorigin;
dest = (matrix3x4a_t*)pk->m_Matrix;
break;
}
}
}
record->serversidemutex.unlock();
}
}
#endif
ImColor color = variable::get().visuals.col_fake.color().ToImGUI();
// blend scope check
if (entity->IsScoped())
{
color.Value.w = variable::get().visuals.f_blend_scope * 0.01f;
}
ForceMaterial(g_Visuals.MutinyMaterials[variable::get().visuals.pf_local_player.vf_main.chams.i_mat_desync_type], color, false);
oDrawModel(ecx, pResults, info, dest, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
Interfaces::ModelRender->ForcedMaterialOverride(nullptr);
if (variable::get().visuals.pf_local_player.vf_main.b_enabled && variable::get().visuals.pf_local_player.vf_main.chams.b_enabled)
{
ImColor color = variable::get().visuals.pf_local_player.vf_main.chams.col_visible.color().ToImGUI();
// blend scope check
if (entity->IsScoped())
{
color.Value.w = variable::get().visuals.f_blend_scope * 0.01f;
}
ForceMaterial(g_Visuals.MutinyMaterials[variable::get().visuals.pf_local_player.vf_main.chams.i_mat_visible], color, true);
}
// draw real model
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
drawn = true;
if (final_matrix_Real)
delete[]final_matrix_Real;
if (final_matrix_Fake)
delete[]final_matrix_Fake;
LocalPlayer.NetvarMutex.Unlock();
}
// other players
else if (index >= 0 && index <= MAX_PLAYERS)
{
//uncomment this when testing multipoint
//ForceMaterial(false, Color(255, 255, 255, 50), g_Info.LitMaterial);
// get playerrecord
auto _playerRecord = &m_PlayerRecords[index];
LocalPlayer.NetvarMutex.Lock();
// get current record
CTickrecord *currentrecord = nullptr;
for (const auto& tick : _playerRecord->m_Tickrecords)
{
if (tick->m_bCachedBones)
{
currentrecord = tick;
break;
}
}
if (currentrecord)
{
// set bonematrix
pBoneToWorld = reinterpret_cast<matrix3x4a_t*>(currentrecord->m_PlayerBackup.CachedBoneMatrices);
// get render origin
Vector _RenderOrigin = currentrecord ? currentrecord->m_AbsOrigin : entity->GetAbsOriginDirect();
bool cham = false, xqz = false, backtrack = false;
ImColor vis_color = Color::White().ToImGUI();
ImColor invis_color = Color::White().ToImGUI();
ImColor backtrack_color = Color::White().ToImGUI();
int vis_mat = 0, invis_mat = 0;
if (alive)
{
if (enemy)
{
cham = (variable::get().visuals.pf_enemy.vf_main.b_enabled && variable::get().visuals.pf_enemy.vf_main.chams.b_enabled && variable::get().visuals.pf_enemy.vf_main.b_render);
xqz = (cham && variable::get().visuals.pf_enemy.vf_main.chams.b_xqz);
backtrack = (cham && variable::get().visuals.pf_enemy.b_backtrack);
invis_color = variable::get().visuals.pf_enemy.vf_main.chams.col_invisible.color().ToImGUI();
vis_color = variable::get().visuals.pf_enemy.vf_main.chams.col_visible.color().ToImGUI();
backtrack_color = variable::get().visuals.pf_enemy.col_backtrack.color().ToImGUI();
vis_mat = variable::get().visuals.pf_enemy.vf_main.chams.i_mat_visible;
invis_mat = variable::get().visuals.pf_enemy.vf_main.chams.i_mat_invisible;
}
else
{
cham = (variable::get().visuals.pf_teammate.vf_main.b_enabled && variable::get().visuals.pf_teammate.vf_main.chams.b_enabled && variable::get().visuals.pf_teammate.vf_main.b_render);
xqz = (cham && variable::get().visuals.pf_teammate.vf_main.chams.b_xqz);
backtrack = (cham && variable::get().visuals.pf_teammate.b_backtrack);
invis_color = variable::get().visuals.pf_teammate.vf_main.chams.col_invisible.color().ToImGUI();
vis_color = variable::get().visuals.pf_teammate.vf_main.chams.col_visible.color().ToImGUI();
backtrack_color = variable::get().visuals.pf_teammate.col_backtrack.color().ToImGUI();
vis_mat = variable::get().visuals.pf_teammate.vf_main.chams.i_mat_visible;
invis_mat = variable::get().visuals.pf_teammate.vf_main.chams.i_mat_invisible;
}
}
else
{
cham = (variable::get().visuals.vf_ragdolls.b_enabled && variable::get().visuals.vf_ragdolls.chams.b_enabled && variable::get().visuals.vf_ragdolls.b_render);
xqz = (cham && variable::get().visuals.vf_ragdolls.chams.b_xqz);
backtrack = false;
invis_color = variable::get().visuals.vf_ragdolls.chams.col_invisible.color().ToImGUI();
vis_color = variable::get().visuals.vf_ragdolls.chams.col_visible.color().ToImGUI();
vis_mat = variable::get().visuals.vf_ragdolls.chams.i_mat_visible;
invis_mat = variable::get().visuals.vf_ragdolls.chams.i_mat_invisible;
}
// xqz
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
// regular
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
// backtrack
if (backtrack)
{
// get oldest record if it's not the same as the one cached in createmove
auto _record = _playerRecord->GetOldestValidRecord();
// origin changed
if (_record && _record->m_AbsOrigin != _RenderOrigin)
{
// no bones cached
if (!_record->m_bCachedBones)
{
// cache bones
PlayerBackup_t *backupstate = new PlayerBackup_t(entity);
_playerRecord->CM_RestoreAnimations(_record);
_playerRecord->CM_RestoreNetvars(_record);
AllowSetupBonesToUpdateAttachments = false;
_playerRecord->CacheBones(Interfaces::Globals->curtime, false, _record);
backupstate->RestoreData();
delete backupstate;
}
// set bonematrix
pBoneToWorld = reinterpret_cast<matrix3x4a_t*>(_record->m_PlayerBackup.CachedBoneMatrices);
// draw backtrack model
ForceMaterial(g_Visuals.MutinyMaterials[FLAT], backtrack_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
}
LocalPlayer.NetvarMutex.Unlock();
}
}
}
// todo: nit; DrawModel only draws on skinned weapons and not base models. We need to convert these chams to SceneEnd eventually.
else if (model_type == MODELTYPE_VIEWWEAPON)
{
bool cham = variable::get().visuals.vf_viewweapon.b_enabled && variable::get().visuals.vf_viewweapon.chams.b_enabled && variable::get().visuals.vf_viewweapon.b_render;
bool xqz = cham && variable::get().visuals.vf_viewweapon.chams.b_xqz;
ImColor vis_color = variable::get().visuals.vf_viewweapon.chams.col_visible.color().ToImGUI();
ImColor invis_color = variable::get().visuals.vf_viewweapon.chams.col_invisible.color().ToImGUI();
int vis_mat = variable::get().visuals.vf_viewweapon.chams.i_mat_visible;
int invis_mat = variable::get().visuals.vf_viewweapon.chams.i_mat_invisible;
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
else if (model_type == MODELTYPE_WEAPON)
{
bool cham = variable::get().visuals.vf_weapon.b_enabled && variable::get().visuals.vf_weapon.chams.b_enabled && variable::get().visuals.vf_weapon.b_render;
bool xqz = cham && variable::get().visuals.vf_weapon.chams.b_xqz;
ImColor vis_color = variable::get().visuals.vf_weapon.chams.col_visible.color().ToImGUI();
ImColor invis_color = variable::get().visuals.vf_weapon.chams.col_invisible.color().ToImGUI();
int vis_mat = variable::get().visuals.vf_weapon.chams.i_mat_visible;
int invis_mat = variable::get().visuals.vf_weapon.chams.i_mat_invisible;
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
else if (model_type == MODELTYPE_BOMB)
{
bool cham = variable::get().visuals.vf_bomb.b_enabled && variable::get().visuals.vf_bomb.chams.b_enabled && variable::get().visuals.vf_bomb.b_render;
bool xqz = cham && variable::get().visuals.vf_bomb.chams.b_xqz;
ImColor vis_color = variable::get().visuals.vf_bomb.chams.col_visible.color().ToImGUI();
ImColor invis_color = variable::get().visuals.vf_bomb.chams.col_invisible.color().ToImGUI();
int vis_mat = variable::get().visuals.vf_bomb.chams.i_mat_visible;
int invis_mat = variable::get().visuals.vf_bomb.chams.i_mat_invisible;
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
else if (model_type == MODELTYPE_ARMS)
{
bool cham = variable::get().visuals.vf_arms.b_enabled && variable::get().visuals.vf_arms.chams.b_enabled && variable::get().visuals.vf_weapon.b_render;
bool xqz = cham && variable::get().visuals.vf_arms.chams.b_xqz;
ImColor vis_color = variable::get().visuals.vf_arms.chams.col_visible.color().ToImGUI();
ImColor invis_color = variable::get().visuals.vf_arms.chams.col_invisible.color().ToImGUI();
int vis_mat = variable::get().visuals.vf_arms.chams.i_mat_visible;
int invis_mat = variable::get().visuals.vf_arms.chams.i_mat_invisible;
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
else if (model_type == MODELTYPE_PROJ)
{
bool cham = variable::get().visuals.vf_projectile.b_enabled && variable::get().visuals.vf_projectile.chams.b_enabled && variable::get().visuals.vf_projectile.b_render;
bool xqz = cham && variable::get().visuals.vf_projectile.chams.b_xqz;
ImColor vis_color = variable::get().visuals.vf_projectile.chams.col_visible.color().ToImGUI();
ImColor invis_color = variable::get().visuals.vf_projectile.chams.col_invisible.color().ToImGUI();
int vis_mat = variable::get().visuals.vf_projectile.chams.i_mat_visible;
int invis_mat = variable::get().visuals.vf_projectile.chams.i_mat_invisible;
if (xqz)
{
ForceMaterial(g_Visuals.MutinyMaterials[invis_mat], invis_color, true);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
if (cham)
{
ForceMaterial(g_Visuals.MutinyMaterials[vis_mat], vis_color, false);
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
}
if (!drawn)
{
// apply material
oDrawModel(ecx, pResults, info, pBoneToWorld, pFlexDelayedWeights, pFlexDelayedWeights, modelOrigin, flags);
}
// reset wireframe
if (g_Info.LitMaterial)
g_Info.LitMaterial->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, false);
Interfaces::ModelRender->ForcedMaterialOverride(nullptr);
if (final_matrix_follow_entities)
delete[]final_matrix_follow_entities;
END_PROFILING
}
int __fastcall Hooks::ListLeavesInBox(void* ecx, void* edx, Vector& mins, Vector& maxs, unsigned short* list, int list_max)
{
auto& var = variable::get();
if (!LocalPlayer.Entity || !var.visuals.b_enabled || *(uint32_t*)_ReturnAddress() != StaticOffsets.GetOffsetValue(_ListLeavesInBox_ReturnAddrBytes))
return oListLeavesInBox(ecx, mins, maxs, list, list_max);
auto info = *(RenderableInfo_t**)((uintptr_t)_AddressOfReturnAddress() + 0x14); // todo: nit; make a sig for this address of return addr offset | ?
if (!info || !info->m_pRenderable)
return oListLeavesInBox(ecx, mins, maxs, list, list_max);
auto base_entity = info->m_pRenderable->GetIClientUnknown()->GetBaseEntity();
if(!base_entity || base_entity->IsLocalPlayer() || !base_entity->IsPlayer())
return oListLeavesInBox(ecx, mins, maxs, list, list_max);
const bool is_enemy = base_entity->IsEnemy(LocalPlayer.Entity);
if(is_enemy && !var.visuals.pf_enemy.vf_main.b_render || !var.visuals.pf_enemy.vf_main.b_enabled && !var.visuals.pf_enemy.vf_main.chams.b_enabled && !var.visuals.pf_enemy.vf_main.chams.b_xqz)
return oListLeavesInBox(ecx, mins, maxs, list, list_max);
if(!is_enemy && !var.visuals.pf_teammate.vf_main.b_render || !var.visuals.pf_teammate.vf_main.b_enabled && !var.visuals.pf_teammate.vf_main.chams.b_enabled && !var.visuals.pf_teammate.vf_main.chams.b_xqz)
return oListLeavesInBox(ecx, mins, maxs, list, list_max);
info->m_Flags &= ~0x100;
info->m_Flags2 |= 0xC0;
return oListLeavesInBox(ecx, coord_mins, coord_maxs, list, list_max);
}