@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
19
19
using System ;
20
20
using System . IO ;
21
21
using System . Collections . Generic ;
22
+ using System . Linq ;
22
23
using System . Reflection ;
23
24
using System . Reflection . Emit ;
24
25
using System . Runtime . CompilerServices ;
@@ -120,14 +121,20 @@ public static void MMPostLoadCallback()
120
121
121
122
void Awake ( )
122
123
{
123
- Debug . Log ( "Test context (shibboleth)" , this ) ;
124
124
if ( loadedShaders == null ) {
125
125
loadedShaders = new Dictionary < string , Shader > ( ) ;
126
126
127
127
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
+ }
131
138
132
139
// Register as an explicit MM callback such that it is run before all reflected
133
140
// callbacks (as used by most mods), which may wish to access the MaterialDef library.
@@ -151,7 +158,7 @@ private void Start()
151
158
152
159
List < MethodBase > callSites = new List < MethodBase > ( ) ;
153
160
154
- Log . Debug ( "Beginning search for callsites" ) ;
161
+ Log . Debug ( "Beginning search for `Shader.Find` callsites" ) ;
155
162
156
163
// Don't use appdomain, we don't want to accidentally patch Unity itself and this avoid
157
164
// having to iterate on the BCL and Unity assemblies.
@@ -238,9 +245,9 @@ private void Start()
238
245
239
246
try {
240
247
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 } ") ;
242
249
} 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 } ") ;
244
251
}
245
252
}
246
253
}
@@ -256,4 +263,4 @@ static IEnumerable<CodeInstruction> CallSiteTranspiler(IEnumerable<CodeInstructi
256
263
}
257
264
}
258
265
}
259
- }
266
+ }
0 commit comments