@@ -15,77 +15,6 @@ namespace OTAPI.UnifiedServerProcess.Core.Patching
1515{
1616 public static class PatchingCommon
1717 {
18- public static Mono . Cecil . Cil . MethodBody ? Clone ( this Mono . Cecil . Cil . MethodBody ? bo , MethodDefinition m ) {
19- Mono . Cecil . Cil . MethodBody bo2 = bo ;
20- Helpers . ThrowIfArgumentNull ( m , "m" ) ;
21- if ( bo2 == null ) {
22- return null ;
23- }
24- Mono . Cecil . Cil . MethodBody bc = new Mono . Cecil . Cil . MethodBody ( m ) ;
25- bc . MaxStackSize = bo2 . MaxStackSize ;
26- bc . InitLocals = bo2 . InitLocals ;
27- bc . LocalVarToken = bo2 . LocalVarToken ;
28- bc . Instructions . AddRange ( bo2 . Instructions . Select ( delegate ( Instruction o ) {
29- Instruction instruction = Instruction . Create ( Mono . Cecil . Cil . OpCodes . Nop ) ;
30- instruction . OpCode = o . OpCode ;
31- instruction . Operand = o . Operand ;
32- instruction . Offset = o . Offset ;
33- return instruction ;
34- } ) ) ;
35- bc . ExceptionHandlers . AddRange ( bo2 . ExceptionHandlers . Select ( ( ExceptionHandler o ) => new ExceptionHandler ( o . HandlerType ) {
36- TryStart = ( ( o . TryStart == null ) ? null : bc . Instructions [ bo2 . Instructions . IndexOf ( o . TryStart ) ] ) ,
37- TryEnd = ( ( o . TryEnd == null ) ? null : bc . Instructions [ bo2 . Instructions . IndexOf ( o . TryEnd ) ] ) ,
38- FilterStart = ( ( o . FilterStart == null ) ? null : bc . Instructions [ bo2 . Instructions . IndexOf ( o . FilterStart ) ] ) ,
39- HandlerStart = ( ( o . HandlerStart == null ) ? null : bc . Instructions [ bo2 . Instructions . IndexOf ( o . HandlerStart ) ] ) ,
40- HandlerEnd = ( ( o . HandlerEnd == null ) ? null : bc . Instructions [ bo2 . Instructions . IndexOf ( o . HandlerEnd ) ] ) ,
41- CatchType = o . CatchType
42- } ) ) ;
43- bc . Variables . AddRange ( bo2 . Variables . Select ( ( VariableDefinition o ) => new VariableDefinition ( o . VariableType ) ) ) ;
44- m . CustomDebugInformations . AddRange ( bo2 . Method . CustomDebugInformations . Select ( delegate ( CustomDebugInformation o ) {
45- if ( o is AsyncMethodBodyDebugInformation asyncMethodBodyDebugInformation ) {
46- AsyncMethodBodyDebugInformation asyncMethodBodyDebugInformation2 = new AsyncMethodBodyDebugInformation ( ) ;
47- if ( asyncMethodBodyDebugInformation . CatchHandler . Offset >= 0 ) {
48- asyncMethodBodyDebugInformation2 . CatchHandler = ( asyncMethodBodyDebugInformation . CatchHandler . IsEndOfMethod ? default ( InstructionOffset ) : new InstructionOffset ( ResolveInstrOff ( asyncMethodBodyDebugInformation . CatchHandler . Offset ) ) ) ;
49- }
50- asyncMethodBodyDebugInformation2 . Yields . AddRange ( asyncMethodBodyDebugInformation . Yields . Select ( ( InstructionOffset off ) => ( ! off . IsEndOfMethod ) ? new InstructionOffset ( ResolveInstrOff ( off . Offset ) ) : default ( InstructionOffset ) ) ) ;
51- asyncMethodBodyDebugInformation2 . Resumes . AddRange ( asyncMethodBodyDebugInformation . Resumes . Select ( ( InstructionOffset off ) => ( ! off . IsEndOfMethod ) ? new InstructionOffset ( ResolveInstrOff ( off . Offset ) ) : default ( InstructionOffset ) ) ) ;
52- asyncMethodBodyDebugInformation2 . ResumeMethods . AddRange ( asyncMethodBodyDebugInformation . ResumeMethods ) ;
53- return asyncMethodBodyDebugInformation2 ;
54- }
55- if ( o is StateMachineScopeDebugInformation stateMachineScopeDebugInformation ) {
56- StateMachineScopeDebugInformation stateMachineScopeDebugInformation2 = new StateMachineScopeDebugInformation ( ) ;
57- stateMachineScopeDebugInformation2 . Scopes . AddRange ( stateMachineScopeDebugInformation . Scopes . Select ( ( StateMachineScope s ) => new StateMachineScope ( ResolveInstrOff ( s . Start . Offset ) , s . End . IsEndOfMethod ? null : ResolveInstrOff ( s . End . Offset ) ) ) ) ;
58- return stateMachineScopeDebugInformation2 ;
59- }
60- return o ;
61- } ) ) ;
62- m . DebugInformation . SequencePoints . AddRange ( bo2 . Method . DebugInformation . SequencePoints . Select ( ( SequencePoint o ) => new SequencePoint ( ResolveInstrOff ( o . Offset ) , o . Document ) {
63- StartLine = o . StartLine ,
64- StartColumn = o . StartColumn ,
65- EndLine = o . EndLine ,
66- EndColumn = o . EndColumn
67- } ) ) ;
68- foreach ( Instruction instruction2 in bc . Instructions ) {
69- if ( instruction2 . Operand is Instruction item ) {
70- instruction2 . Operand = bc . Instructions [ bo2 . Instructions . IndexOf ( item ) ] ;
71- }
72- else if ( instruction2 . Operand is Instruction [ ] source ) {
73- instruction2 . Operand = source . Select ( ( Instruction i ) => bc . Instructions [ bo2 . Instructions . IndexOf ( i ) ] ) . ToArray ( ) ;
74- }
75- else if ( instruction2 . Operand is VariableDefinition variableDefinition ) {
76- instruction2 . Operand = bc . Variables [ variableDefinition . Index ] ;
77- }
78- }
79- return bc ;
80- Instruction ResolveInstrOff ( int off ) {
81- for ( int j = 0 ; j < bo2 . Instructions . Count ; j ++ ) {
82- if ( bo2 . Instructions [ j ] . Offset == off ) {
83- return bc . Instructions [ j ] ;
84- }
85- }
86- throw new ArgumentException ( $ "Invalid instruction offset { off } ") ;
87- }
88- }
8918 public static MethodDefinition CreateInstanceConvdMethod ( MethodDefinition staticMethod , ContextTypeData instanceConvdType , ImmutableDictionary < string , FieldDefinition > instanceConvdFieldOrgiMap ) {
9019 if ( ! staticMethod . IsStatic ) {
9120 throw new ArgumentException ( "Method must be static" , nameof ( staticMethod ) ) ;
0 commit comments