1
- using System ;
2
- using HarmonyLib ;
3
- using KSP . Localization ;
4
- using System . Collections . Generic ;
1
+ using KSP . Localization ;
2
+ using System ;
5
3
using UnityEngine ;
6
4
7
5
namespace KSPCommunityFixes . Performance
@@ -12,32 +10,36 @@ internal class CollisionEnhancerFastUpdate : BasePatch
12
10
13
11
protected override void ApplyPatches ( )
14
12
{
15
- AddPatch ( PatchType . Prefix , typeof ( CollisionEnhancer ) , nameof ( CollisionEnhancer . FixedUpdate ) ) ;
13
+ AddPatch ( PatchType . Override , typeof ( CollisionEnhancer ) , nameof ( CollisionEnhancer . FixedUpdate ) ) ;
16
14
}
17
15
18
- private static bool CollisionEnhancer_FixedUpdate_Prefix ( CollisionEnhancer __instance )
16
+ private static void CollisionEnhancer_FixedUpdate_Override ( CollisionEnhancer __instance )
19
17
{
20
18
Part part = __instance . part ;
19
+
20
+ if ( part . IsNullOrDestroyed ( ) || part . partTransform . IsNullOrDestroyed ( ) )
21
+ return ;
22
+
21
23
Vector3 position = part . partTransform . position ;
22
24
23
25
if ( part . packed )
24
26
{
25
27
__instance . lastPos = position ;
26
28
__instance . wasPacked = true ;
27
- return false ;
29
+ return ;
28
30
}
29
31
30
32
if ( __instance . framesToSkip > 0 )
31
33
{
32
34
__instance . lastPos = position ;
33
35
__instance . framesToSkip -- ;
34
- return false ;
36
+ return ;
35
37
}
36
38
37
- if ( part . vessel . heightFromTerrain > 1000f )
39
+ if ( part . vessel . IsNullOrDestroyed ( ) || part . vessel . heightFromTerrain > 1000f )
38
40
{
39
41
__instance . lastPos = position ;
40
- return false ;
42
+ return ;
41
43
}
42
44
43
45
if ( ! __instance . wasPacked )
@@ -54,7 +56,7 @@ private static bool CollisionEnhancer_FixedUpdate_Prefix(CollisionEnhancer __ins
54
56
&& Physics . Linecast ( __instance . lastPos , position , out RaycastHit hit , 32768 , QueryTriggerInteraction . Ignore ) ) // linecast against the "LocalScenery" layer
55
57
{
56
58
Vector3 rbVelocity = __instance . rb . velocity ;
57
- Debug . Log ( "[F: " + Time . frameCount + " ]: [" + __instance . name + " ] Collision Enhancer Punch Through - vel: " + rbVelocity . magnitude , __instance . gameObject ) ;
59
+ Debug . Log ( $ "[F: { Time . frameCount } ]: [{ __instance . name } ] Collision Enhancer Punch Through - vel: { rbVelocity . magnitude } " ) ;
58
60
59
61
if ( mode == CollisionEnhancerBehaviour . EXPLODE
60
62
&& ! CheatOptions . NoCrashDamage
@@ -89,8 +91,6 @@ private static bool CollisionEnhancer_FixedUpdate_Prefix(CollisionEnhancer __ins
89
91
}
90
92
91
93
__instance . lastPos = position ;
92
-
93
- return false ;
94
94
}
95
95
}
96
96
}
0 commit comments