@@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
21
21
using System . Collections . Generic ;
22
22
using System . Reflection ;
23
23
using System . Reflection . Emit ;
24
+ using System . Runtime . CompilerServices ;
24
25
using UnityEngine ;
25
26
using HarmonyLib ;
26
27
using Mono . Cecil ;
@@ -63,7 +64,7 @@ static Shader FindLoadedShader(string shaderName)
63
64
{
64
65
Shader shader ;
65
66
if ( loadedShaders . TryGetValue ( shaderName , out shader ) ) {
66
- Debug . Log ( $ "[Shabby] custom shader: { shader . name } ") ;
67
+ Log ( $ "custom shader: { shader . name } ") ;
67
68
return shader ;
68
69
}
69
70
@@ -81,7 +82,7 @@ public static Shader FindShader(string shaderName)
81
82
shader = FindLoadedShader ( replacement . shader ) ;
82
83
83
84
if ( shader == null ) {
84
- Debug . LogError ( $ "[Shabby] failed to find shader { replacement . shader } to replace { shaderName } ") ;
85
+ LogError ( $ "failed to find shader { replacement . shader } to replace { shaderName } ") ;
85
86
}
86
87
}
87
88
@@ -106,7 +107,7 @@ public static void MMPostLoadCallback()
106
107
var iconShaderName = iconNode . GetValue ( "iconShader" ) ;
107
108
var iconShader = FindShader ( iconShaderName ?? "" ) ;
108
109
if ( string . IsNullOrEmpty ( shader ) || iconShader == null ) {
109
- Debug . LogError ( $ "[Shabby] invalid icon shader specification { shader } -> { iconShaderName } ") ;
110
+ LogError ( $ "invalid icon shader specification { shader } -> { iconShaderName } ") ;
110
111
} else {
111
112
iconShaders [ shader ] = iconShader ;
112
113
}
@@ -124,7 +125,7 @@ void Awake()
124
125
harmony = new Harmony ( "Shabby" ) ;
125
126
harmony . PatchAll ( Assembly . GetExecutingAssembly ( ) ) ;
126
127
127
- Debug . Log ( $ "[Shabby] hooked") ;
128
+ LogDebug ( " hooked") ;
128
129
129
130
// Register as an explicit MM callback such that it is run before all reflected
130
131
// callbacks (as used by most mods), which may wish to access the MaterialDef library.
@@ -148,7 +149,7 @@ private void Start()
148
149
149
150
List < MethodBase > callSites = new List < MethodBase > ( ) ;
150
151
151
- Debug . Log ( $ "[Shabby]: Beginning search for callsites") ;
152
+ LogDebug ( " Beginning search for callsites") ;
152
153
153
154
// Don't use appdomain, we don't want to accidentally patch Unity itself and this avoid
154
155
// having to iterate on the BCL and Unity assemblies.
@@ -174,7 +175,7 @@ private void Start()
174
175
}
175
176
}
176
177
} catch ( Exception ex ) {
177
- Debug . LogError ( $ "[Shabby] excpetion while patching { method . Name } : { ex } ") ;
178
+ LogError ( $ "exception while patching { method . Name } : { ex } ") ;
178
179
}
179
180
}
180
181
}
@@ -189,7 +190,7 @@ private void Start()
189
190
if ( assemblyDef == null )
190
191
throw new FileLoadException ( $ "Couldn't read assembly \" { kspAssembly . assembly . Location } \" ") ;
191
192
} catch ( Exception e ) {
192
- Debug . LogWarning ( $ "[Shabby] Replace failed for assembly { kspAssembly . name } \n { e } ") ;
193
+ LogWarning ( $ "Replace failed for assembly { kspAssembly . name } \n { e } ") ;
193
194
continue ;
194
195
}
195
196
@@ -210,8 +211,8 @@ private void Start()
210
211
if ( callSite == null )
211
212
throw new MemberAccessException ( ) ;
212
213
} catch {
213
- Debug . LogWarning (
214
- $ "[Shabby] Failed to patch method { assemblyDef . Name } ::{ typeDef . Name } .{ methodDef . Name } ") ;
214
+ LogWarning (
215
+ $ "Failed to patch method { assemblyDef . Name } ::{ typeDef . Name } .{ methodDef . Name } ") ;
215
216
break ;
216
217
}
217
218
@@ -233,8 +234,8 @@ private void Start()
233
234
if ( callSite == mInfo_ShaderFind_Replacement )
234
235
continue ;
235
236
236
- Debug . Log (
237
- $ "[Shabby] Patching call site : { callSite . DeclaringType . Assembly . GetName ( ) . Name } ::{ callSite . DeclaringType } .{ callSite . Name } ") ;
237
+ Log (
238
+ $ "Patching call site : { callSite . DeclaringType . Assembly . GetName ( ) . Name } ::{ callSite . DeclaringType } .{ callSite . Name } ") ;
238
239
harmony . Patch ( callSite , null , null , new HarmonyMethod ( callSiteTranspiler ) ) ;
239
240
}
240
241
}
@@ -249,5 +250,31 @@ static IEnumerable<CodeInstruction> CallSiteTranspiler(IEnumerable<CodeInstructi
249
250
yield return instruction ;
250
251
}
251
252
}
253
+
254
+ internal const string LogPrefix = "[Shabby] " ;
255
+
256
+ [ System . Diagnostics . Conditional ( "DEBUG" ) ]
257
+ internal static void LogDebug ( string message )
258
+ {
259
+ Debug . Log ( LogPrefix + message ) ;
260
+ }
261
+
262
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
263
+ internal static void Log ( string message )
264
+ {
265
+ Debug . Log ( LogPrefix + message ) ;
266
+ }
267
+
268
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
269
+ internal static void LogWarning ( string message )
270
+ {
271
+ Debug . LogWarning ( LogPrefix + message ) ;
272
+ }
273
+
274
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
275
+ internal static void LogError ( string message )
276
+ {
277
+ Debug . LogError ( LogPrefix + message ) ;
278
+ }
252
279
}
253
280
}
0 commit comments