@@ -18,14 +18,14 @@ public class PatchesTranspilerTest
18
18
[ typeof ( AttackCyclops_OnCollisionEnter_Patch ) , - 17 ] ,
19
19
[ typeof ( AttackCyclops_UpdateAggression_Patch ) , - 23 ] ,
20
20
[ typeof ( Bullet_Update_Patch ) , 3 ] ,
21
- [ typeof ( BaseDeconstructable_Deconstruct_Patch ) , BaseDeconstructable_Deconstruct_Patch . InstructionsToAdd ( true ) . Count ( ) * 2 ] ,
21
+ [ typeof ( BaseDeconstructable_Deconstruct_Patch ) , 10 ] ,
22
22
[ typeof ( BaseHullStrength_CrushDamageUpdate_Patch ) , 3 ] ,
23
23
[ typeof ( BreakableResource_SpawnResourceFromPrefab_Patch ) , 2 ] ,
24
- [ typeof ( Builder_TryPlace_Patch ) , Builder_TryPlace_Patch . InstructionsToAdd1 . Count + Builder_TryPlace_Patch . InstructionsToAdd2 . Count ] ,
24
+ [ typeof ( Builder_TryPlace_Patch ) , 4 ] ,
25
25
[ typeof ( CellManager_TryLoadCacheBatchCells_Patch ) , 4 ] ,
26
- [ typeof ( Constructable_Construct_Patch ) , Constructable_Construct_Patch . InstructionsToAdd . Count ] ,
27
- [ typeof ( Constructable_DeconstructAsync_Patch ) , Constructable_DeconstructAsync_Patch . InstructionsToAdd . Count ] ,
28
- [ typeof ( ConstructableBase_SetState_Patch ) , ConstructableBase_SetState_Patch . InstructionsToAdd . Count ] ,
26
+ [ typeof ( Constructable_Construct_Patch ) , 3 ] ,
27
+ [ typeof ( Constructable_DeconstructAsync_Patch ) , 3 ] ,
28
+ [ typeof ( ConstructableBase_SetState_Patch ) , 2 ] ,
29
29
[ typeof ( ConstructorInput_OnCraftingBegin_Patch ) , 7 ] ,
30
30
[ typeof ( CrafterLogic_TryPickupSingleAsync_Patch ) , 4 ] ,
31
31
[ typeof ( CrashHome_Spawn_Patch ) , 2 ] ,
@@ -90,7 +90,7 @@ public class PatchesTranspilerTest
90
90
[ TestMethod ]
91
91
public void AllTranspilerPatchesHaveSanityTest ( )
92
92
{
93
- Type [ ] allPatchesWithTranspiler = typeof ( NitroxPatcher . Main ) . Assembly . GetTypes ( ) . Where ( p => typeof ( NitroxPatch ) . IsAssignableFrom ( p ) && p . IsClass ) . Where ( x => x . GetMethod ( "Transpiler" ) != null ) . ToArray ( ) ;
93
+ Type [ ] allPatchesWithTranspiler = typeof ( NitroxPatcher . Main ) . Assembly . GetTypes ( ) . Where ( p => typeof ( INitroxPatch ) . IsAssignableFrom ( p ) && p . IsClass ) . Where ( x => x . GetMethod ( "Transpiler" ) != null ) . ToArray ( ) ;
94
94
95
95
foreach ( Type patch in allPatchesWithTranspiler )
96
96
{
@@ -146,7 +146,14 @@ public void AllPatchesTranspilerSanity(Type patchClassType, int ilDifference, bo
146
146
147
147
if ( logInstructions )
148
148
{
149
+ Console . WriteLine ( "~~~~~~~~~~~~~~~~~~~~~~" ) ;
150
+ Console . WriteLine ( "~~~ TRANSFORMED IL ~~~" ) ;
151
+ Console . WriteLine ( "~~~~~~~~~~~~~~~~~~~~~~" ) ;
149
152
Console . WriteLine ( transformedIl . ToPrettyString ( ) ) ;
153
+ Console . WriteLine ( "~~~~~~~~~~~~~~~~~~~~~~" ) ;
154
+ Console . WriteLine ( "~~~ ORIGINAL IL ~~~" ) ;
155
+ Console . WriteLine ( "~~~~~~~~~~~~~~~~~~~~~~" ) ;
156
+ Console . WriteLine ( originalIlCopy . ToPrettyString ( ) ) ;
150
157
}
151
158
152
159
if ( transformedIl == null || transformedIl . Count == 0 )
@@ -155,7 +162,14 @@ public void AllPatchesTranspilerSanity(Type patchClassType, int ilDifference, bo
155
162
}
156
163
157
164
originalIlCopy . Count . Should ( ) . Be ( transformedIl . Count - ilDifference ) ;
158
- Assert . IsFalse ( originalIlCopy . SequenceEqual ( transformedIl , new CodeInstructionComparer ( ) ) , $ "The transpiler patch of { patchClassType . Name } did not change the IL") ;
165
+ if ( originalIlCopy . Count == transformedIl . Count )
166
+ {
167
+ string originalIlPrettyString = originalIlCopy . ToPrettyString ( ) ;
168
+ if ( originalIlPrettyString == transformedIl . ToPrettyString ( ) )
169
+ {
170
+ Assert . Fail ( $ "The transpiler patch of { patchClassType . Name } did not change the IL:{ Environment . NewLine } { originalIlPrettyString } ") ;
171
+ }
172
+ }
159
173
}
160
174
161
175
private static readonly ModuleBuilder patchTestModule ;
@@ -177,35 +191,3 @@ private static ILGenerator GetILGenerator(MethodInfo method, Type generatingType
177
191
return myTypeBld . DefineMethod ( method . Name , MethodAttributes . Public , method . ReturnType , method . GetParameters ( ) . Types ( ) ) . GetILGenerator ( ) ;
178
192
}
179
193
}
180
-
181
- public class CodeInstructionComparer : IEqualityComparer < CodeInstruction >
182
- {
183
- public bool Equals ( CodeInstruction x , CodeInstruction y )
184
- {
185
- if ( ReferenceEquals ( x , y ) )
186
- {
187
- return true ;
188
- }
189
- if ( x is null )
190
- {
191
- return false ;
192
- }
193
- if ( y is null )
194
- {
195
- return false ;
196
- }
197
- if ( x . GetType ( ) != y . GetType ( ) )
198
- {
199
- return false ;
200
- }
201
- return x . opcode . Equals ( y . opcode ) && Equals ( x . operand , y . operand ) ;
202
- }
203
-
204
- public int GetHashCode ( CodeInstruction obj )
205
- {
206
- unchecked
207
- {
208
- return ( obj . opcode . GetHashCode ( ) * 397 ) ^ ( obj . operand != null ? obj . operand . GetHashCode ( ) : 0 ) ;
209
- }
210
- }
211
- }
0 commit comments