File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,8 @@ class SetPartIconMaterialsPatch
34
34
static MethodInfo mInfo_FindOverrideIconShader =
35
35
AccessTools . Method ( typeof ( SetPartIconMaterialsPatch ) , nameof ( FindOverrideIconShader ) ) ;
36
36
37
- static Shader FindOverrideIconShader ( Material material )
38
- {
39
- if ( Shabby . iconShaders . TryGetValue ( material . shader . name , out var shader ) ) {
40
- Log . Debug ( $ "custom icon shader { material . shader . name } -> { shader . name } ") ;
41
- return shader ;
42
- }
43
-
44
- return Shabby . FindShader ( "KSP/ScreenSpaceMask" ) ;
45
- }
37
+ static Shader FindOverrideIconShader ( Material material ) =>
38
+ Shabby . TryFindIconShader ( material . shader . name ) ?? Shabby . FindShader ( "KSP/ScreenSpaceMask" ) ;
46
39
47
40
/// <summary>
48
41
/// The stock method iterates through every material in the icon prefab and replaces some
@@ -89,4 +82,19 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
89
82
return code ;
90
83
}
91
84
}
92
- }
85
+
86
+ [ HarmonyPatch ( TargetType , "GetIconShader" ) ]
87
+ class KSPCFGetIconShaderPatch
88
+ {
89
+ const string TargetType = "KSPCommunityFixes.Performance.PartParsingPerf" ;
90
+
91
+ static bool Prepare ( ) => AccessTools . TypeByName ( TargetType ) != null ;
92
+
93
+ static void Postfix ( string materialShaderName , ref Shader __result )
94
+ {
95
+ if ( __result . name != "KSP/ScreenSpaceMask" ) return ;
96
+ if ( Shabby . TryFindIconShader ( materialShaderName ) is not Shader iconShader ) return ;
97
+ __result = iconShader ;
98
+ }
99
+ }
100
+ }
Original file line number Diff line number Diff line change @@ -95,6 +95,13 @@ public static Shader FindShader(string shaderName)
95
95
return shader ;
96
96
}
97
97
98
+ public static Shader TryFindIconShader ( string shaderName )
99
+ {
100
+ if ( ! iconShaders . TryGetValue ( shaderName , out var iconShader ) ) return null ;
101
+ Log . Debug ( $ "custom icon shader { shaderName } -> { iconShader . name } ") ;
102
+ return iconShader ;
103
+ }
104
+
98
105
public static void MMPostLoadCallback ( )
99
106
{
100
107
var configNodes = GameDatabase . Instance . GetConfigNodes ( "SHABBY" ) ;
You can’t perform that action at this time.
0 commit comments