Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SniperGER committed Apr 30, 2022
0 parents commit bfa8789
Show file tree
Hide file tree
Showing 60 changed files with 3,035 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs/
bin/
obj/
packages/
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
13 changes: 13 additions & 0 deletions Instructions/Add.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Adds two values and pushes the result onto the evaluation stack.
/// </summary>
public class Add : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.Add);
}
}
}
13 changes: 13 additions & 0 deletions Instructions/And.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Computes the bitwise AND of two values and pushes the result onto the evaluation stack.
/// </summary>
public class And : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.And);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Beq.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if two values are equal.
/// </summary>
public class Beq : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Beq, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Bge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if the first value is greater than or equal to the second value.
/// </summary>
public class Bge : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Bge, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Bgt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if the first value is greater than the second value.
/// </summary>
public class Bgt : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Bgt, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Ble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if the first value is less than or equal to the second value.
/// </summary>
public class Ble : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Ble, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Blt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if the first value is less than the second value.
/// </summary>
public class Blt : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Blt, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Bne_Un.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction when two unsigned integer values or unordered float values are not equal.
/// </summary>
public class Bne_Un : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Bne_Un, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Br.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Unconditionally transfers control to a target instruction.
/// </summary>
public class Br : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Br, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Brfalse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if value is false, a null reference, or zero.
/// </summary>
public class Brfalse : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Brfalse, targetInstruction);
}
}
}
22 changes: 22 additions & 0 deletions Instructions/Brtrue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Transfers control to a target instruction if value is true, not null, or non-zero.
/// </summary>
public class Brtrue : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.TargetIndex < 0)
return null;

Instruction targetInstruction = methodDef.Body.Instructions.ElementAt(patchInstruction.TargetIndex);

if (targetInstruction == null)
return null;

return processor.Create(OpCodes.Brtrue, targetInstruction);
}
}
}
46 changes: 46 additions & 0 deletions Instructions/Call.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Calls the method indicated by the passed method descriptor.
/// </summary>
public class Call : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.Type == null || patchInstruction.Method == null)
return null;

string typeName = patchInstruction.Type;
string methodName = patchInstruction.Method;

AssemblyDefinition _assemblyDef = assemblyDef;
if (patchInstruction.Assembly != null)
_assemblyDef = Patcher.ResolveAssembly(patchInstruction.Assembly);

if (_assemblyDef == null)
return null;

// Get Type
TypeDefinition typeDefinition = _assemblyDef.MainModule.GetType(typeName);

// Get Method
MethodDefinition methodDefinition = typeDefinition.Methods.FirstOrDefault(m => m.Name == methodName);
MethodReference methodReference = assemblyDef.MainModule.ImportReference(methodDefinition);

//if (patchInstruction.Parameters.Count > 0) {
// List<TypeReference> genericParameters = new List<TypeReference>();

// foreach (PatchInstructionParameter genericAssembly in patchInstruction.Parameters) {
// AssemblyDefinition genericAssemblyDef = Patcher.ResolveAssembly(genericAssembly.Assembly);
// TypeReference genericTypeRef = assemblyDef.MainModule.ImportReference(genericAssemblyDef.MainModule.GetType(genericAssembly.Type));

// methodReference.GenericParameters.Add(new GenericParameter(genericTypeRef.Name, methodDefinition));
// }
//}

// Return Instruction
return processor.Create(OpCodes.Call, methodReference);
}
}
}
46 changes: 46 additions & 0 deletions Instructions/Callvirt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Calls a late-bound method on an object, pushing the return value onto the evaluation stack.
/// </summary>
public class Callvirt : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
if (patchInstruction.Type == null || patchInstruction.Method == null)
return null;

string typeName = patchInstruction.Type;
string methodName = patchInstruction.Method;

AssemblyDefinition _assemblyDef = assemblyDef;
if (patchInstruction.Assembly != null)
_assemblyDef = Patcher.ResolveAssembly(patchInstruction.Assembly);

if (_assemblyDef == null)
return null;

// Get Type
TypeDefinition typeDefinition = _assemblyDef.MainModule.GetType(typeName);

// Get Method
MethodDefinition methodDefinition = typeDefinition.Methods.FirstOrDefault(m => m.Name == methodName);
MethodReference methodReference = assemblyDef.MainModule.ImportReference(methodDefinition);

//if (patchInstruction.Parameters.Count > 0) {
// List<TypeReference> genericParameters = new List<TypeReference>();

// foreach (PatchInstructionParameter genericAssembly in patchInstruction.Parameters) {
// AssemblyDefinition genericAssemblyDef = Patcher.ResolveAssembly(genericAssembly.Assembly);
// TypeReference genericTypeRef = assemblyDef.MainModule.ImportReference(genericAssemblyDef.MainModule.GetType(genericAssembly.Type));

// methodReference.GenericParameters.Add(new GenericParameter(genericTypeRef.Name, methodDefinition));
// }
//}

// Return Instruction
return processor.Create(OpCodes.Callvirt, methodReference);
}
}
}
13 changes: 13 additions & 0 deletions Instructions/Ceq.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Compares two values. If they are equal, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.
/// </summary>
public class Ceq : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.Ceq);
}
}
}
13 changes: 13 additions & 0 deletions Instructions/Cgt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Compares two values. If the first value is greater than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.
/// </summary>
public class Cgt : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.Cgt);
}
}
}
13 changes: 13 additions & 0 deletions Instructions/Clt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Compares two values. If the first value is less than the second, the integer value 1 (int32) is pushed onto the evaluation stack; otherwise 0 (int32) is pushed onto the evaluation stack.
/// </summary>
public class Clt : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.Clt);
}
}
}
13 changes: 13 additions & 0 deletions Instructions/Div.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace UniversalUnityPatcher.Instructions {
/// <summary>
/// Divides two values and pushes the result as a floating-point (type F) or quotient (type int32) onto the evaluation stack.
/// </summary>
public class Div : InstructionBase {
public override Instruction ParseInstruction(ILProcessor processor, AssemblyDefinition assemblyDef, TypeDefinition typeDef, MethodDefinition methodDef, PatchInstruction patchInstruction) {
return processor.Create(OpCodes.Div);
}
}
}
Loading

0 comments on commit bfa8789

Please sign in to comment.