@@ -37,9 +37,11 @@ enum OSType
37
37
OSType gOSType ;
38
38
EngineVersion gEngineVersion ;
39
39
40
- #define CUSTOM_ASSERTION_FAILSTATE
41
- #define FAILSTATE_FUNC SetFailStateCustom
40
+ #define ASSERTUTILS_FAILSTATE_FUNC SetFailStateCustom
41
+ #define MEMUTILS_PLUGINENDCALL
42
42
#include "glib/memutils"
43
+ #undef MEMUTILS_PLUGINENDCALL
44
+
43
45
#include "momsurffix/utils.sp"
44
46
#include "momsurffix/baseplayer.sp"
45
47
#include "momsurffix/gametrace.sp"
@@ -50,22 +52,27 @@ ConVar gBounce;
50
52
float vec3_origin [3 ] = {0.0 , 0.0 , 0.0 };
51
53
bool gBasePlayerLoadedTooEarly ;
52
54
53
- PatchHandler gASMPatch ;
54
- Handle gStoreToAddressFast ;
55
- Address gTryPlayerMoveStart ;
56
-
57
55
#if defined DEBUG_PROFILE
58
56
#include "profiler"
59
- #define PROF_START() if (gProf ) gProf .Start ()
60
- #define PROF_STOP(% 1 )% 2 ; if (gProf )\
61
- {\
62
- gProf .Stop ();\
63
- Prof_Check (% 1 );\
64
- }
65
-
66
57
Profiler gProf ;
67
58
ArrayList gProfData ;
68
59
float gProfTime ;
60
+
61
+ void PROF_START ()
62
+ {
63
+ if (gProf )
64
+ gProf .Start ();
65
+ }
66
+
67
+ void PROF_STOP (int idx )
68
+ {
69
+ if (gProf )
70
+ {
71
+ gProf .Stop ();
72
+ Prof_Check (idx );
73
+ }
74
+ }
75
+
69
76
#else
70
77
#define PROF_START% 1 ;
71
78
#define PROF_STOP% 1 ;
@@ -100,7 +107,6 @@ public void OnPluginStart()
100
107
InitGameMovement (gd );
101
108
102
109
SetupDhooks (gd );
103
- SetupASMOptimizations (gd );
104
110
105
111
delete gd ;
106
112
}
@@ -190,48 +196,6 @@ public Action Prof_Check_Timer(Handle timer, int client)
190
196
}
191
197
#endif
192
198
193
- void SetupASMOptimizations (GameData gd )
194
- {
195
- //CGameMovement::TryPlayerMove_Start
196
- gTryPlayerMoveStart = gd .GetAddress (" CGameMovement::TryPlayerMove_Start" );
197
- ASSERT_MSG (gTryPlayerMoveStart , " Can't find start of the \" CGameMovement::TryPlayerMove\" function." );
198
-
199
- gASMPatch = PatchHandler (gTryPlayerMoveStart + ASM_START_OFFSET );
200
- gASMPatch .Save (ASM_PATCH_LEN );
201
-
202
- Address start = gASMPatch .Address ;
203
-
204
- /* StoreToAddressFast asm:
205
- * push ebp
206
- * mov ebp, esp
207
- *
208
- * mov eax, [ebp + 12]
209
- * mov ecx, [ebp + 8]
210
- * mov [ecx], eax
211
- *
212
- * mov esp, ebp
213
- * pop ebp
214
- * ret 8
215
- */
216
-
217
- StoreToAddress (start , 0x8B_EC_8B_55 , NumberType_Int32 );
218
- StoreToAddress (start + 4 , 0x4D_8B_0C_45 , NumberType_Int32 );
219
- StoreToAddress (start + 8 , 0x8B_01_89_08 , NumberType_Int32 );
220
- StoreToAddress (start + 12 , 0x08_C2_5D_E5 , NumberType_Int32 );
221
- StoreToAddress (start + 16 , 0x00 , NumberType_Int8 );
222
-
223
- //StoreToAddressFast
224
- StartPrepSDKCall (SDKCall_Static );
225
-
226
- PrepSDKCall_SetAddress (start );
227
- PrepSDKCall_AddParameter (SDKType_PlainOldData , SDKPass_Plain );
228
- PrepSDKCall_AddParameter (SDKType_PlainOldData , SDKPass_Plain );
229
- PrepSDKCall_SetReturnInfo (SDKType_PlainOldData , SDKPass_Plain );
230
-
231
- gStoreToAddressFast = EndPrepSDKCall ();
232
- ASSERT (gStoreToAddressFast );
233
- }
234
-
235
199
void ValidateGameAndOS (GameData gd )
236
200
{
237
201
gOSType = view_as <OSType >(gd .GetOffset (" OSType" ));
@@ -345,7 +309,13 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
345
309
VectorCopy (view_as <float >({0.0 , 0.0 , 0.0 }), valid_plane );
346
310
347
311
float offset [3 ], offset_mins [3 ], offset_maxs [3 ], buff [3 ];
348
- Ray_t ray = Ray_t ();
312
+ static Ray_t ray ;
313
+
314
+ // Keep this variable allocated only once
315
+ // since ray.Init should take care of removing any left garbage values
316
+ if (ray .Address == Address_Null )
317
+ ray = Ray_t ();
318
+
349
319
for (i = 0 ; i < 3 ; i ++ )
350
320
{
351
321
for (j = 0 ; j < 3 ; j ++ )
@@ -413,7 +383,6 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
413
383
}
414
384
}
415
385
}
416
- ray .Free ();
417
386
418
387
if (valid_planes != 0 && ! CloseEnough (valid_plane , view_as <float >({0.0 , 0.0 , 0.0 })))
419
388
{
@@ -669,12 +638,20 @@ stock bool CloseEnoughFloat(float a, float b, float eps = FLT_EPSILON)
669
638
670
639
public void SetFailStateCustom (const char [] fmt , any ...)
671
640
{
672
- char buff [ASSERT_FMT_STRING_LEN ];
641
+ char buff [512 ];
673
642
VFormat (buff , sizeof (buff ), fmt , 2 );
674
643
675
644
CleanUpUtils ();
676
645
677
- SetFailState (buff );
646
+ char ostype [32 ];
647
+ switch (gOSType )
648
+ {
649
+ case OSLinux : ostype = " LIN" ;
650
+ case OSWindows : ostype = " WIN" ;
651
+ default : ostype = " UNK" ;
652
+ }
653
+
654
+ SetFailState (" [%s | %i ] %s " , ostype , gEngineVersion , buff );
678
655
}
679
656
680
657
// 0-2 are axial planes
@@ -706,7 +683,7 @@ stock bool IsValidMovementTrace(CGameMovement pThis, CGameTrace tr)
706
683
707
684
CGameTrace stuck = CGameTrace ();
708
685
709
- TracePlayerBBox (pThis , tr .endpos , tr .endpos , MASK_PLAYERSOLID , COLLISION_GROUP_PLAYER_MOVEMENT , stuck )
686
+ TracePlayerBBox (pThis , tr .endpos , tr .endpos , MASK_PLAYERSOLID , COLLISION_GROUP_PLAYER_MOVEMENT , stuck );
710
687
if (stuck .startsolid || ! CloseEnoughFloat (stuck .fraction , 1.0 ))
711
688
{
712
689
stuck .Free ();
@@ -742,25 +719,4 @@ stock void UTIL_TraceRay(Ray_t ray, int mask, CGameMovement gm, int collisionGro
742
719
743
720
filter .Free ();
744
721
}
745
- }
746
-
747
- //Faster then native StoreToAddress by ~45 times.
748
- stock void StoreToAddressFast (Address addr , any data )
749
- {
750
- ASSERT (gStoreToAddressFast );
751
-
752
- int ret = SDKCall (gStoreToAddressFast , addr , data );
753
- ASSERT (ret == data );
754
- }
755
-
756
- stock void StoreToAddressCustom (Address addr , any data , NumberType type )
757
- {
758
- if (gStoreToAddressFast && type == NumberType_Int32 )
759
- {
760
- StoreToAddressFast (addr , data );
761
- }
762
- else
763
- {
764
- StoreToAddress (addr , view_as <int >(data ), type );
765
- }
766
722
}
0 commit comments