new internal static BasePatch ParseFromJSON(JSON.Object obj, params object[] args) { var targetType = args[0] as Reflection.TypePatcher; var patch = new MethodPatch(); if (obj.ContainsKey("TargetMethodSigniture")) patch.TargetMethod = targetType.GetMethod(obj["TargetMethod"].Str, obj["TargetMethodSigniture"].Str); else patch.TargetMethod = targetType.GetMethod(obj["TargetMethod"].Str); MainClass.LogLine(" + " + patch.TargetMethod.methodDefinition.GetSigniture()); foreach (JSON.Value instru in obj["Instructions"].Array) { var instrupatch = MethodInstruction.ParseFromJSON(instru.Obj, patch); switch (instrupatch.OperandType) { case EOperandType.Instruction: instrupatch.Operand = patch.TargetMethod.IlProc.Body.Instructions[instrupatch.ParamOrVarOffset]; break; case EOperandType.Variable: instrupatch.Operand = patch.TargetMethod.IlProc.Body.Variables[instrupatch.ParamOrVarOffset]; break; case EOperandType.Parameter: instrupatch.Operand = patch.TargetMethod.IlProc.Body.Method.Parameters[instrupatch.ParamOrVarOffset]; break; } patch.Instructions.Add(instrupatch); } return patch; }
public static MethodInstruction ParseFromJSON(JSON.Object instru, MethodPatch targetMethod) { var patch = new MethodInstruction(); patch.InstructionType = (EInstructionType)Enum.Parse(typeof(EInstructionType), instru["InstructionType"].Str); switch (patch.InstructionType) { case EInstructionType.SetVisibility: patch.Public = instru.ContainsKey("Public") ? instru["Public"].Boolean : patch.Public; break; case EInstructionType.RemoveRange: patch.RemoveEnd = Int32.Parse(instru["RemoveEnd"].Str); goto case EInstructionType.RemoveAt; case EInstructionType.RemoveAt: patch.RemoveStart = Int32.Parse(instru["RemoveStart"].Str); goto case EInstructionType.Clear; case EInstructionType.Clear: return patch; case EInstructionType.InsertAfter: case EInstructionType.InsertBefore: patch.InsertOffset = Int32.Parse(instru["InsertOffset"].Str); break; } patch.Instruction = Instruction.Create(OpCodes.Ret); patch.OpCode = (OpCode)typeof(OpCodes).GetField(instru["OpCode"].Str).GetValue(typeof(OpCodes)); patch.OperandType = (EOperandType)Enum.Parse(typeof(EOperandType), instru["OperandType"].Str); switch (patch.OperandType) { case EOperandType.Type: patch.Operand = Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).typeDefinition; break; case EOperandType.Method: if (instru.ContainsKey("TargetMethodSigniture")) patch.Operand = targetMethod.TargetMethod.rootAssemblyPatcher.mainModule.Import(Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetMethod(instru["TargetMethod"].Str, instru["TargetMethodSigniture"].Str).methodDefinition); else patch.Operand = targetMethod.TargetMethod.rootAssemblyPatcher.mainModule.Import(Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetMethod(instru["TargetMethod"].Str).methodDefinition); break; case EOperandType.Field: patch.Operand = Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetField(instru["TargetField"].Str); break; case EOperandType.Parameter: case EOperandType.Variable: case EOperandType.Instruction: patch.ParamOrVarOffset = Int32.Parse(instru["ParamVarOffset"].Str); break; case EOperandType.SByte: patch.Operand = SByte.Parse(instru["Operand"].Str); break; case EOperandType.Byte: patch.Operand = Byte.Parse(instru["Operand"].Str); break; case EOperandType.Int: patch.Operand = Int32.Parse(instru["Operand"].Str); break; case EOperandType.Float: patch.Operand = Single.Parse(instru["Operand"].Str); break; case EOperandType.Long: patch.Operand = Int64.Parse(instru["Operand"].Str); break; case EOperandType.Double: patch.Operand = Double.Parse(instru["Operand"].Str); break; case EOperandType.String: patch.Operand = instru["Operand"].Str; break; } return patch; }