Skip to content

Commit 474e0c2

Browse files
committed
more verbose Harmony logging
1 parent 5abf432 commit 474e0c2

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Source/IconMaterialPatch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
8181
code[i].opcode = OpCodes.Ldloc_S;
8282
code[i].operand = locMaterial;
8383
code[i + 1].operand = mInfo_FindOverrideIconShader;
84-
Log.Debug("patched part icon shader replacement");
8584
return code;
8685
}
8786
}

Source/Shabby.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
1919
using System;
2020
using System.IO;
2121
using System.Collections.Generic;
22+
using System.Linq;
2223
using System.Reflection;
2324
using System.Reflection.Emit;
2425
using System.Runtime.CompilerServices;
@@ -120,14 +121,20 @@ public static void MMPostLoadCallback()
120121

121122
void Awake()
122123
{
123-
Debug.Log("Test context (shibboleth)", this);
124124
if (loadedShaders == null) {
125125
loadedShaders = new Dictionary<string, Shader>();
126126

127127
harmony = new Harmony("Shabby");
128-
harmony.PatchAll(Assembly.GetExecutingAssembly());
129-
130-
Log.Debug("hooked");
128+
Log.Message("Harmony patching");
129+
foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) {
130+
PatchClassProcessor processor = new(harmony, type);
131+
if (processor.Patch() is not List<MethodInfo> patchedMethods) continue;
132+
if (patchedMethods.Count == 0) {
133+
Log.Message($"`{type.Name}` skipped");
134+
continue;
135+
}
136+
Log.Message($"`{type.Name}` patched methods {string.Join(", ", patchedMethods.Select(m => $"`{m.Name}`"))}");
137+
}
131138

132139
// Register as an explicit MM callback such that it is run before all reflected
133140
// callbacks (as used by most mods), which may wish to access the MaterialDef library.
@@ -151,7 +158,7 @@ private void Start()
151158

152159
List<MethodBase> callSites = new List<MethodBase>();
153160

154-
Log.Debug("Beginning search for callsites");
161+
Log.Debug("Beginning search for `Shader.Find` callsites");
155162

156163
// Don't use appdomain, we don't want to accidentally patch Unity itself and this avoid
157164
// having to iterate on the BCL and Unity assemblies.
@@ -238,9 +245,9 @@ private void Start()
238245

239246
try {
240247
harmony.Patch(callSite, null, null, new HarmonyMethod(callSiteTranspiler));
241-
Log.Debug($"Patching call site : {callSite.DeclaringType.Assembly.GetName().Name}::{callSite.DeclaringType}.{callSite.Name}");
248+
Log.Debug($"Patching call site: {callSite.DeclaringType.Assembly.GetName().Name}::{callSite.DeclaringType}.{callSite.Name}");
242249
} catch (Exception e) {
243-
Log.Warning($"Failed to patch call site : {callSite.DeclaringType.Assembly.GetName().Name}::{callSite.DeclaringType}.{callSite.Name}\n{e.Message}\n{e.StackTrace}");
250+
Log.Warning($"Failed to patch call site: {callSite.DeclaringType.Assembly.GetName().Name}::{callSite.DeclaringType}.{callSite.Name}\n{e.Message}\n{e.StackTrace}");
244251
}
245252
}
246253
}
@@ -256,4 +263,4 @@ static IEnumerable<CodeInstruction> CallSiteTranspiler(IEnumerable<CodeInstructi
256263
}
257264
}
258265
}
259-
}
266+
}

Source/Shabby.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<PropertyGroup>
1919
<TargetFramework>net48</TargetFramework>
20-
<LangVersion>7.3</LangVersion>
20+
<LangVersion>latest</LangVersion>
2121
<IsPackable>false</IsPackable>
2222
<PlatformTarget>x64</PlatformTarget>
2323
<NoWarn>1701;1702;CS0649;CS1591;</NoWarn>

0 commit comments

Comments
 (0)