-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
comvars.ixx
1243 lines (1066 loc) · 39.1 KB
/
comvars.ixx
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module;
#include <common.hxx>
#include <D3D9Types.h>
export module comvars;
import common;
#define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, "Invalid structure size of " #struc)
enum GameLanguage
{
eLANG_AMERICAN,
eLANG_FRENCH,
eLANG_GERMAN,
eLANG_ITALIAN,
eLANG_SPANISH,
eLANG_RUSSIAN,
eLANG_JAPANESE,
};
export unsigned int hashStringLowercaseFromSeed(const char* str, unsigned int seed)
{
auto hash = seed;
auto currentChar = str;
if (*str == '"')
currentChar = str + 1;
while (*currentChar)
{
char character = *currentChar;
if (*str == '"' && character == '"')
break;
++currentChar;
if ((uint8_t)(character - 'A') <= 25)
{
character += 32; // Convert uppercase to lowercase
}
else if (character == '\\')
{
character = '/';
}
hash = (1025 * (hash + character) >> 6) ^ 1025 * (hash + character);
}
return 32769 * (9 * hash ^ (9 * hash >> 11));
}
export class CBaseDC
{
public:
uint32_t field_1;
public:
static inline void* AppendAddr;
void Append()
{
reinterpret_cast<void(__thiscall*)(CBaseDC*)>(AppendAddr)(this);
}
static inline void* operator_newAddr;
void* operator new(std::size_t size)
{
return reinterpret_cast<void* (__cdecl*)(std::size_t, int32_t)>(operator_newAddr)(size, 0);
}
virtual ~CBaseDC() {}
virtual void DrawCommand() {}
virtual int32_t GetSize() { return sizeof(CBaseDC); }
};
export class T_CB_Generic_NoArgs : public CBaseDC
{
public:
void (*cb)();
public:
T_CB_Generic_NoArgs(void (*c)()) : CBaseDC()
{
cb = c;
}
void DrawCommand() override
{
cb();
}
int32_t GetSize() override
{
return sizeof(T_CB_Generic_NoArgs);
}
};
export namespace rage
{
struct Vector3
{
float x, y, z;
};
struct Vector4
{
float x, y, z, w;
};
enum grcTextureFormat : uint8_t
{
GRCFMT_UNKNOWN,
GRCFMT_R5G6B5,
GRCFMT_A8R8G8B8,
GRCFMT_R16F,
GRCFMT_R32F,
GRCFMT_A2R10G10B10,
GRCFMT_A16B16G16R16F,
GRCFMT_G16R16,
GRCFMT_G16R16F,
GRCFMT_A32B32G32R32F,
GRCFMT_A16B16G16R16F2,
GRCFMT_A16B16G16R16,
GRCFMT_L8,
GRCFMT_D24S8 = 0xE,
GRCFMT_X8R8G8B8 = 0x10,
};
inline std::vector<std::pair<grcTextureFormat, D3DFORMAT>> m_Formats
{
{ GRCFMT_UNKNOWN, D3DFMT_UNKNOWN },
{ GRCFMT_R5G6B5, D3DFMT_R5G6B5 },
{ GRCFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
{ GRCFMT_R16F, D3DFMT_R16F },
{ GRCFMT_R32F, D3DFMT_R32F },
{ GRCFMT_A2R10G10B10, D3DFMT_A2R10G10B10 },
{ GRCFMT_A16B16G16R16F, D3DFMT_A16B16G16R16F },
{ GRCFMT_G16R16, D3DFMT_G16R16 },
{ GRCFMT_G16R16F, D3DFMT_G16R16F },
{ GRCFMT_A32B32G32R32F, D3DFMT_A32B32G32R32F },
{ GRCFMT_A16B16G16R16F2, D3DFMT_A16B16G16R16F },
{ GRCFMT_A16B16G16R16, D3DFMT_A16B16G16R16 },
{ GRCFMT_L8, D3DFMT_L8 },
{ GRCFMT_D24S8, D3DFMT_D24S8 },
{ GRCFMT_X8R8G8B8, D3DFMT_X8R8G8B8 },
};
inline grcTextureFormat getEngineTextureFormat(D3DFORMAT format)
{
for (auto& pair : m_Formats)
{
if (pair.second == format)
return pair.first;
}
return GRCFMT_UNKNOWN;
}
inline D3DFORMAT getD3DTextureFormat(grcTextureFormat format)
{
for (auto& pair : m_Formats)
{
if (pair.first == format)
return pair.second;
}
return D3DFMT_UNKNOWN;
}
struct grcViewportWindow
{
float X;
float Y;
float Width;
float Height;
float MinZ;
float MaxZ;
};
class grcViewport
{
public:
float mWorldMatrix44[4][4];
float mCameraMatrix[4][4];
float mWorldMatrix[4][4];
float mWorldViewMatrix[4][4];
float mWorldViewProjMatrix[4][4];
float mViewInverseMatrix[4][4];
float mViewMatrix[4][4];
float mProjectionMatrix[4][4];
float mMatrix_200[4][4];//FrustumLRTB?
float mMatrix_240[4][4];//FrustumNFNF?
grcViewportWindow mGrcViewportWindow1;
grcViewportWindow mGrcViewportWindow2;//UnclippedWindow?
int mWidth;
int mHeight;
float mFov;
float mAspect;
float mNearClip;
float mFarClip;
float field_2C8;
float field_2CC;
float mScaleX;
float mScaleY;
float field_2D8;
float field_2DC;
Vector4 field_2E0;
bool mIsPerspective;
char gap_2f1[3];
int field_2F4;
int field_2F8;
int field_2FC;
Vector4 mFrustumClipPlanes[6];
int field_360;
int field_364;
int field_368;
int field_36C;
int field_370;
int field_374;
int field_378;
int field_37C;
int field_380;
int field_384;
int field_388;
int field_38C;
int field_390;
int field_394;
int field_398;
int field_39C;
int field_3A0;
int field_3A4;
int field_3A8;
int field_3AC;
int field_3B0;
int field_3B4;
int field_3B8;
int field_3BC;
int field_3C0;
int field_3C4;
int field_3C8;
int field_3CC;
int field_3D0;
int field_3D4;
int field_3D8;
int field_3DC;
bool mInvertZInProjectionMatrix;
char field_3E1[3];
int field_3E4;
int field_3E8;
int field_3EC;
};
grcViewport** pCurrentViewport = nullptr;
grcViewport* GetCurrentViewport()
{
return *pCurrentViewport;
}
VALIDATE_SIZE(grcViewport, 0x3F0);
struct grcImage
{
uint16_t mWidth;
uint16_t mHeight;
int32_t mFormat;
int32_t mType;
uint16_t mStride;
uint16_t mDepth;
void* mPixelData;
int32_t* field_14;
grcImage* mNextLevel;
grcImage* mNextSlice;
uint32_t mRefCount;
uint8_t gap24[8];
int field_2C;
float field_30[3];
int32_t field_3C;
float field_40[3];
int field_4C;
};
VALIDATE_SIZE(grcImage, 0x50);
class datBase
{
protected:
uint32_t* _vft;
};
class pgBase : public datBase
{
uint32_t mBlockMap;
};
VALIDATE_SIZE(pgBase, 0x8);
class grcRenderTargetPC;
struct grcRenderTargetDesc
{
grcRenderTargetDesc()
: field_0(0)
, mMultisampleCount(0)
, field_8(1)
, mLevels(1)
, field_10(1)
, field_11(1)
, field_1C(1)
, field_24(1)
, field_26(1)
, field_28(1)
, field_12(0)
, mDepthRT(0)
, field_18(0)
, field_20(0)
, field_25(0)
, field_27(0)
, field_29(0)
, field_2A(0)
, mFormat(GRCFMT_UNKNOWN)
{}
char field_0;
int mMultisampleCount;
char field_8;
int mLevels;
char field_10;
char field_11;
char field_12;
grcRenderTargetPC* mDepthRT;
char field_18;
int field_1C;
int field_20;
bool field_24;
char field_25;
char field_26;
char field_27;
char field_28;
char field_29;
char field_2A;
alignas(4) grcTextureFormat mFormat;
};
class grcRenderTarget : public pgBase
{
public:
uint8_t field_8;
uint8_t field_9;
int16_t field_A;
int32_t field_C;
int32_t field_10;
uint32_t mType;
int32_t* field_18;
int16_t field_1C;
int16_t field_1E;
int32_t field_20;
int16_t field_24;
int16_t field_26;
int32_t field_28;
uint16_t field_2C;
uint16_t field_2E;
};
VALIDATE_SIZE(grcRenderTargetDesc, 0x30);
class grcRenderTargetPC : public grcRenderTarget
{
public:
char* mName;
IDirect3DTexture9* mD3DTexture;
IDirect3DSurface9* mD3DSurface;
uint16_t mWidth;
uint16_t mHeight;
grcTextureFormat mFormat;
uint8_t mIndex;
uint8_t mBitsPerPixel;
uint8_t mMultisampleCount;
bool field_44;
uint8_t gap45[2];
uint8_t field_47;
uint32_t mLevels;
bool field_4C;
bool field_4D;
uint8_t field_4E;
void Destroy(uint8_t a2 = 1)
{
auto func = (void(__thiscall*)(grcRenderTargetPC*, uint8_t))(_vft[0]);
func(this, a2);
}
};
VALIDATE_SIZE(grcRenderTargetPC, 0x50);
class grcTexturePC : pgBase
{
public:
uint8_t field_8;
uint8_t mDepth;
uint16_t mRefCount;
int32_t field_C;
int32_t field_10;
char* mName;
IDirect3DTexture9* mD3DTexture;
uint16_t mWidth;
uint16_t mHeight;
int32_t mFormat;
uint16_t mStride;
uint8_t mTextureType;
uint8_t mMipCount;
D3DVECTOR field_28;
D3DVECTOR field_34;
grcTexturePC* mPrevious;
grcTexturePC* mNext;
void* mPixelData;
uint8_t field_4C;
uint8_t field_4D;
uint8_t field_4E;
uint8_t field_4F;
bool Init()
{
auto func = (grcTexturePC * (__thiscall*)(grcTexturePC*))(_vft[4]);
return func(this);
}
};
VALIDATE_SIZE(grcTexturePC, 0x50);
struct grcTextureReferenceBase : public pgBase
{
char field_8;
char field_9;
int16_t m_wUsageCount;
int field_C;
};
struct grcTextureReference : public grcTextureReferenceBase
{
int field_10;
const char* m_pszName;
grcTexturePC* m_pTexture;
};
namespace grcDevice
{
struct grcResolveFlags
{
grcResolveFlags()
: Depth(1.0f)
, BlurKernelSize(1.0f)
, Color(0)
, Stencil(0)
, ColorExpBias(0)
, ClearColor(false)
, ClearDepthStencil(false)
, BlurResult(false)
, NeedResolve(true)
, MipMap(true)
{}
float Depth;
float BlurKernelSize;
uint32_t Color;
uint32_t Stencil;
int ColorExpBias;
bool ClearColor;
bool ClearDepthStencil;
bool BlurResult;
bool NeedResolve;
bool MipMap;
};
IDirect3DDevice9** ms_pD3DDevice = nullptr;
int32_t* ms_nActiveWidth = nullptr;
int32_t* ms_nActiveHeight = nullptr;
bool* ms_bNoBlockOnLostFocus = nullptr;
IDirect3DDevice9* GetD3DDevice()
{
return *ms_pD3DDevice;
}
void* SetCallbackAddr;
class FunctorBase
{
public:
FunctorBase()
{
memset(mMemFunc, 0xAA, 8);
mCallee = 0;
}
FunctorBase(void* callee, void(__fastcall* function)(), void* mf, uint32_t size)
{
auto SetCallback = (void(__thiscall*)(FunctorBase*, void*, void(__fastcall*)(), void*, uint32_t))SetCallbackAddr;
SetCallback(this, callee, function, mf, size);
}
union
{
void(__fastcall* mFunction)();
uint8_t mMemFunc[8];
};
uint32_t mCallee;
};
class Functor0 : public FunctorBase
{
public:
Functor0(void* callee, void(__fastcall* function)(), void* mf, uint32_t size)
: FunctorBase(callee, function, mf, size)
{
mThunk = Translator;
}
private:
void(__cdecl* mThunk)(FunctorBase*);
static void Translator(FunctorBase* functor)
{
functor->mFunction();
}
};
VALIDATE_SIZE(Functor0, 0x10);
void(__cdecl* RegisterDeviceCallbacks)(Functor0 onLost, Functor0 onReset);
}
class grcTextureFactoryPC;
class grcTextureFactory
{
protected:
uint32_t* _vft;
public:
bool field_4;
char _gap5[3];
static inline grcTextureFactoryPC** g_pTextureFactory = nullptr;
static grcTextureFactoryPC* GetInstance()
{
return *g_pTextureFactory;
}
};
class grcTextureFactoryPC : public grcTextureFactory
{
public:
IDirect3DSurface9* mPrevRenderTargets[3];
int32_t field_14;
int32_t field_18;
int32_t field_1C;
int32_t field_20;
int32_t field_24;
IDirect3DSurface9* mD3D9Surfaces[4];
uint8_t gap38[4];
int32_t field_3C;
int32_t field_40;
int32_t field_44;
IDirect3DSurface9* field_48;
IDirect3DSurface9* mDepthStencilSurface;
IDirect3DSurface9* field_50;
grcRenderTargetPC* field_54;
int32_t field_58;
int32_t field_5C;
int32_t field_60;
int32_t field_64;
int32_t field_68;
int32_t field_6C;
int32_t field_70;
//virtuals
grcTexturePC* Create(grcImage* image, void* arg2)
{
auto func = (grcTexturePC * (__stdcall*)(grcImage*, void*))(_vft[2]);
return func(image, arg2);
}
grcRenderTargetPC* __stdcall CreateRenderTarget(const char* name, int32_t a2, uint32_t width, uint32_t height, uint32_t bitsPerPixel, grcRenderTargetDesc* desc)
{
auto func = (grcRenderTargetPC * (__stdcall*)(const char*, int32_t, uint32_t, uint32_t, uint32_t, grcRenderTargetDesc*))(_vft[14]);
return func(name, a2, width, height, bitsPerPixel, desc);
}
void LockRenderTarget(uint32_t index, grcRenderTargetPC* color, grcRenderTargetPC* depth, uint32_t a5 = 0, bool a6 = 1, uint32_t mip = 0)
{
auto func = (void(__thiscall*)(grcTextureFactory*, uint32_t, grcRenderTargetPC*, grcRenderTargetPC*, uint32_t, bool, uint32_t))(_vft[15]);
func(this, index, color, depth, a5, a6, mip);
}
void UnlockRenderTarget(uint32_t index, grcDevice::grcResolveFlags* resolveFlags, int32_t unused = -1)
{
auto func = (void(__thiscall*)(grcTextureFactory*, uint32_t, grcDevice::grcResolveFlags*, int32_t))(_vft[16]);
func(this, index, resolveFlags, unused);
}
static inline std::unordered_map<std::string, grcTexturePC*> TextureCache;
static inline std::unordered_map<std::string, grcRenderTargetPC*> RTCache;
static inline SafetyHookInline shCreateTexture{};
static grcTexturePC* __fastcall CreateTexture(grcTextureFactoryPC* _this, void* edx, const char* name, void* a3)
{
auto ret = shCreateTexture.fastcall<grcTexturePC*>(_this, edx, name, a3);
TextureCache[name] = ret;
return ret;
}
static inline SafetyHookInline shCreateRT{};
static grcRenderTargetPC* __stdcall CreateRT(const char* name, int32_t a2, uint32_t width, uint32_t height, uint32_t bitsPerPixel, grcRenderTargetDesc* desc)
{
// Scale phone screen/phone camera rendertarget resolution with game resolution.
if (std::string_view(name) == "PHONE_SCREEN" || std::string_view(name) == "PHOTO")
{
auto res = (int32_t)(std::ceil((float)*rage::grcDevice::ms_nActiveHeight / 720.0f) * 256.0f);
width = res;
height = res;
}
else if (std::string_view(name) == "WATER_SURFACE0_COLOUR" || std::string_view(name) == "WATER_SURFACE1_COLOUR")
{
// Force water surface rendertarget resolution to always be 256x256. This matches the water tiling on the console version.
width = 256;
height = 256;
}
auto ret = shCreateRT.stdcall<grcRenderTargetPC*>(name, a2, width, height, bitsPerPixel, desc);
// if(strcmp("WATER_REFLECTION_COLOUR", name) == 0) { ret->mMultisampleCount=1; }
//else if(strcmp("WATER_REFLECTION_DEPTH" , name) == 0) { ret->mMultisampleCount=1; }
//else if(strcmp("REFLECTION_MAP_COLOUR" , name) == 0) { ret->mMultisampleCount=1; }
//else if(strcmp("REFLECTION_MAP_DEPTH" , name) == 0) { ret->mMultisampleCount=1; }
RTCache[name] = ret;
return ret;
}
static grcTexturePC* GetTextureByName(const char* name)
{
if (TextureCache.contains(name))
return TextureCache[name];
return nullptr;
}
static grcRenderTargetPC* GetRTByName(const char* name)
{
if (RTCache.contains(name))
return RTCache[name];
return nullptr;
}
static grcTexturePC* FindTextureByRawPointer(IDirect3DTexture9* ptr)
{
for (auto& [name, tex] : TextureCache)
{
if (tex->mD3DTexture == ptr)
return tex;
}
return nullptr;
}
static grcRenderTargetPC* FindRTByRawPointer(IDirect3DTexture9* ptr)
{
for (auto& [name, rt] : RTCache)
{
if (rt->mD3DTexture == ptr)
return rt;
}
return nullptr;
}
};
VALIDATE_SIZE(grcTextureFactoryPC, 0x74);
enum eLightType
{
LT_POINT = 0x0,
LT_DIR = 0x1,
LT_SPOT = 0x2,
LT_AO = 0x3,
LT_CLAMPED = 0x4,
};
class CLightSource
{
public:
Vector3 mDirection;
int32_t field_C;
Vector3 mTangent;
int32_t field_1C;
Vector3 mPosition;
int32_t field_2C;
Vector4 mColor;
float mIntensity;
eLightType mType;
int32_t mFlags;
int32_t mTxdId;
int32_t field_50;
float mRadius;
float mInnerConeAngle;
float mOuterConeAngle;
int32_t field_60;
int32_t field_64;
int32_t field_68;
int32_t field_6C;
float mVolumeSize;
float mVolumeScale;
uint8_t gap78[8];
};
VALIDATE_SIZE(CLightSource, 0x80);
namespace scrEngine
{
uint32_t* ms_dwNativeTableSize;
uint32_t** ms_pNatives;
}
namespace scrProgram
{
uintptr_t** ms_pGlobals;
uint32_t* ms_pGlobalsSize;
}
namespace grcWindow
{
bool* ms_bWindowed;
bool* ms_bOnTop;
bool* ms_bFocusLost;
}
struct grmShaderInfo_Parameter
{
char nbType;
char nbCount;
char nbValueLength;
char nbAnnotationsCount;
const char* pszName;
const char* pszDescription;
int dwNameHash;
int dwDescriptionHash;
int pAnnotations;
void* pValue;
int16_t m_wVertexFragmentRegister;
int16_t m_wPixelFragmentRegister;
int pdwParameterHashes;
int field_24;
int field_28;
int field_2C;
};
VALIDATE_SIZE(grmShaderInfo_Parameter, 0x30);
struct sysArray
{
int pData;
int16_t wCount;
int16_t wSize;
};
struct grmShaderInfo_Values
{
int ppValues;
int pOwner;
int dwSize;
int dwTotalDataSize;
int pnbArraySizes;
int dwEffectHash;
int field_18;
int field_1C;
int field_20;
};
class grmShaderInfo
{
sysArray m_techniques;
sysArray m_parameters;
sysArray m_vsFragments;
sysArray m_psFragments;
const char* m_pszShaderPath;
int m_dwEffectHash;
int m_dwFileTimeLow;
int m_dwFileTimeHigh;
grmShaderInfo_Values m_values;
int m_pNext;
public:
static inline std::unordered_map<int, std::vector<uint8_t>> GlobalParams;
static inline std::map<unsigned int, std::map<int, std::vector<uint8_t>>> ShaderInfoParams;
static inline std::map<unsigned int, std::pair<int, int>> ShaderInfoParamHashes;
static inline void* pfngetParamIndex = nullptr;
static int getParamIndex(grmShaderInfo* instance, const char* name, int a3)
{
auto func = (int(__thiscall*)(grmShaderInfo* instance, const char* name, int a3))pfngetParamIndex;
return func(instance, name, a3);
}
static int getParamIndex(unsigned int shader_hash, unsigned int name_hash, int a3)
{
auto j = 1;
for (auto i = (int*)(ShaderInfoParamHashes[shader_hash].first + 0xC); j < ShaderInfoParamHashes[shader_hash].second; i += 0xC, ++j)
{
if (i[0] == name_hash || i[1] == name_hash)
return j;
}
return 0;
}
static inline SafetyHookInline shsub_436D70{};
static void __fastcall setShaderParam(grmShaderInfo* _this, void* edx, void* a2, int index, void* in, int a5, int a6, int a7)
{
size_t j = 1;
if (_this->m_parameters.wCount)
{
auto sv = std::string_view(_this->m_pszShaderPath);
auto shader_name = sv.substr(sv.find_last_of('/') + 1);
auto hash = hashStringLowercaseFromSeed(shader_name.data(), 0);
ShaderInfoParamHashes[hash] = { _this->m_parameters.pData, _this->m_parameters.wSize };
ShaderInfoParams[hash][index].assign((uint8_t*)in, (uint8_t*)in + a5);
}
return shsub_436D70.fastcall(_this, edx, a2, index, in, a5, a6, a7);
}
static inline SafetyHookInline shsetGlobalParam{};
static void __cdecl setGlobalParam(int index, void* data, int a3)
{
GlobalParams[index].assign((uint8_t*)data, (uint8_t*)data + 16); //assuming 4x4, maybe needs fixing
return shsetGlobalParam.ccall(index, data, a3);
}
static inline grmShaderInfo_Parameter* globalShaderParameters = nullptr;
static inline uint32_t* dwGlobalShaderParameterCount = nullptr;
static grmShaderInfo_Parameter* getGlobalShaderInfoParam(const char* name)
{
for (uint32_t i = 0; i < *dwGlobalShaderParameterCount; i++)
{
if (std::string_view(name) == std::string_view(globalShaderParameters[i].pszName))
return &globalShaderParameters[i];
}
return nullptr;
}
static inline int(__cdecl* getGlobalParameterIndexByName)(const char* a1) = nullptr;
static float* getGlobalParam(const char* name)
{
auto i = getGlobalParameterIndexByName(name);
if (GlobalParams.contains(i))
return reinterpret_cast<float*>(GlobalParams[i].data());
else
{
auto it = getGlobalShaderInfoParam(name);
return it && it->pValue ? reinterpret_cast<float*>(it->pValue) : nullptr;
}
return nullptr;
}
static float* getParam(const char* shaderName, const char* paramName)
{
auto hash = hashStringLowercaseFromSeed(paramName, 0);
for (auto& it : ShaderInfoParams)
{
if (it.first == hashStringLowercaseFromSeed(shaderName, 0))
{
auto i = getParamIndex(it.first, hash, 1);
if (i)
return reinterpret_cast<float*>(it.second[i].data());
else
break;
}
}
return nullptr;
}
};
}
export namespace CViewport3DScene
{
rage::grcRenderTargetPC** pGBufferRTs = nullptr;
rage::grcRenderTargetPC** pStencilRT = nullptr;
rage::grcRenderTargetPC* GetDiffuseRT()
{
return pGBufferRTs[0];
}
rage::grcRenderTargetPC* GetNormalRT()
{
return pGBufferRTs[1];
}
rage::grcRenderTargetPC* GetSpecularAoRT()
{
return pGBufferRTs[2];
}
rage::grcRenderTargetPC* GetDepthRT()
{
return pGBufferRTs[3];
}
rage::grcRenderTargetPC* GetStencilRT()
{
return *pStencilRT;
}
}
export namespace CMenuManager
{
bool* m_MenuActive = nullptr;
uint8_t* bLoadscreenShown = nullptr;
}
export namespace CCutscenes
{
uint32_t* m_dwCutsceneState;
bool(*hasCutsceneFinished)();
}
export namespace CCamera
{
bool(*isWidescreenBordersActive)();
}
export namespace CTimer
{
float* fTimeStep;
uint8_t* m_UserPause = nullptr;
uint8_t* m_CodePause = nullptr;
int32_t* m_snTimeInMilliseconds = nullptr;
}
export namespace CTimeCycle
{
void(__cdecl* Initialise)() = nullptr;
}
export namespace CWeather
{
enum eWeatherType : uint32_t
{
EXTRASUNNY,
SUNNY,
SUNNY_WINDY,
CLOUDY,
RAIN,
DRIZZLE,
FOGGY,
LIGHTNING
};
float* Rain = nullptr;
eWeatherType* CurrentWeather = nullptr;
eWeatherType* NextWeather = nullptr;
float* NextWeatherPercentage = nullptr;
}
export namespace RageDirect3DDevice9
{
enum eTexture : uint32_t
{
unk,
unk2,
HDRTex,
};
IDirect3DDevice9** m_pRealDevice = nullptr;
IDirect3DTexture9** g_TexturesBySampler = nullptr;
IDirect3DTexture9* GetTexture(uint32_t index)
{
if (index < 272)
return g_TexturesBySampler[index];
return nullptr;
}
}
export class CRenderPhaseDeferredLighting_LightsToScreen
{
public:
static FusionFix::Event<>& OnBuildRenderList() {
static FusionFix::Event<> BuildRenderListEvent;
return BuildRenderListEvent;
}
static FusionFix::Event<rage::CLightSource*>& OnAfterCopyLight() {
static FusionFix::Event<rage::CLightSource*> AfterCopyLightEvent;
return AfterCopyLightEvent;
}
static inline SafetyHookInline shBuildRenderList{};
static inline SafetyHookInline shCopyLight{};
static void __fastcall BuildRenderList(CBaseDC* _this, void* edx)
{
OnBuildRenderList().executeAll();
return shBuildRenderList.fastcall(_this, edx);
}