-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,752 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
public class HookAttribute : Attribute | ||
{ | ||
private string _fullName; | ||
public HookAttribute(string fullName, bool end = false) | ||
{ | ||
_fullName = fullName; | ||
} | ||
using System; | ||
|
||
|
||
public class HookAttribute : Attribute | ||
{ | ||
private string _fullName; | ||
public HookAttribute(string fullName, bool end = false) { | ||
_fullName = fullName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+28.5 KB
(620%)
HookAttribute/obj/Debug/HookAttribute.csprojResolveAssemblyReference.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
HookAttribute/obj/Release/HookAttribute.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
6f051f3773f28dd737e06e6fa081d55ae6f23112 | ||
da346672aca068797a3a3ea91e844556111b0f4a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+84.3 KB
(390%)
HookAttribute/obj/Release/HookAttribute.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,91 @@ | ||
using Mono.Cecil; | ||
using Mono.Cecil.Inject; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace HooksInjector | ||
{ | ||
class Injector | ||
{ | ||
private string _pluginPath; | ||
private AssemblyDefinition _gameAssembly; | ||
private AssemblyDefinition _pluginAssembly; | ||
public Injector(AssemblyDefinition gameAssembly, AssemblyDefinition pluginAssembly, string pluginPath) | ||
{ | ||
_pluginPath = pluginPath; | ||
_gameAssembly = gameAssembly; | ||
_pluginAssembly = pluginAssembly; | ||
} | ||
|
||
public void InjectHook(ScriptsParser.ParsedHook hook) | ||
{ | ||
var nameSplit = hook.fullName.Split('.'); | ||
var className = nameSplit[0]; | ||
var methodName = nameSplit[1]; | ||
|
||
var classType = _gameAssembly.MainModule.GetType(className); | ||
if(classType == null) | ||
{ | ||
Console.WriteLine(className + " class not found in game assembly!"); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
|
||
var method = classType.GetMethod(methodName); | ||
|
||
if (method == null) | ||
{ | ||
Console.WriteLine(methodName + " method not found in " + className + "!"); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
|
||
TypeDefinition pluginClassType = null; | ||
foreach(var type in _pluginAssembly.MainModule.GetTypes()) | ||
{ | ||
if(type.Name.EndsWith("Plugin")) | ||
{ | ||
pluginClassType = type; | ||
} | ||
} | ||
|
||
if(pluginClassType == null) | ||
{ | ||
Console.WriteLine("No plugin class ending with \"Plugin\" found in " + _pluginPath + "!"); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
|
||
var rawMethodName = hook.fullName.Split('.').Last(); | ||
var hookMethod = pluginClassType.GetMethod(rawMethodName); | ||
|
||
if (hookMethod == null) | ||
{ | ||
Console.WriteLine(pluginClassType.Name + " doesn't contain method: " + rawMethodName); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
|
||
InjectionDefinition injector; | ||
|
||
try | ||
{ | ||
if (hook.canBlock) | ||
{ | ||
if(method.Parameters.Count > 0) | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.PassParametersRef | InjectFlags.ModifyReturn); | ||
else | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.ModifyReturn); | ||
} | ||
else | ||
{ | ||
if (method.Parameters.Count > 0) | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.PassParametersRef); | ||
else | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance); | ||
} | ||
|
||
if (hook.hookEnd) | ||
{ | ||
injector.Inject(-1, null, InjectDirection.Before); | ||
} | ||
else | ||
injector.Inject(); | ||
|
||
Console.WriteLine(rawMethodName + " hooked!"); | ||
} | ||
catch(Exception e) | ||
{ | ||
Console.WriteLine("Hook definition is wrong!"); | ||
Console.WriteLine(e.ToString()); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
using Mono.Cecil; | ||
using Mono.Cecil.Inject; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace HooksInjector | ||
{ | ||
class Injector | ||
{ | ||
string pluginPath; | ||
AssemblyDefinition gameAssembly; | ||
AssemblyDefinition pluginAssembly; | ||
public Injector(AssemblyDefinition _gameAssembly, AssemblyDefinition _pluginAssembly, string _pluginPath) { | ||
pluginPath = _pluginPath; | ||
gameAssembly = _gameAssembly; | ||
pluginAssembly = _pluginAssembly; | ||
|
||
} | ||
public void InjectHook(ScriptsParser.ParsedHook hook) { | ||
var nameSplit = hook.fullName.Split('.'); | ||
var className = nameSplit[0]; | ||
var methodName = nameSplit[1]; | ||
|
||
var methodClassType = gameAssembly.MainModule.GetType(className); | ||
if (methodClassType == null) { | ||
Console.WriteLine("HooksInjector: ERROR: Class " + className + " Was not found in game assembly. Please check the spelling of the class."); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
|
||
var method = methodClassType.GetMethod(methodName); | ||
|
||
if (method == null) { | ||
Console.WriteLine("HooksInjector: ERROR: Method " + methodName + " could not be found in class: " + className + ". Please check the spelling of the method."); | ||
Console.Read(); | ||
return; | ||
|
||
} | ||
TypeDefinition classType = null; | ||
foreach (var type in pluginAssembly.MainModule.GetTypes()) { | ||
if (type.Name.EndsWith("Plugin", StringComparison.CurrentCulture)) { | ||
classType = type; | ||
} | ||
} | ||
if (classType == null) { | ||
Console.WriteLine("HooksInjector: ERROR: No class ending with \"Plugin\" found in " + pluginPath); | ||
Console.Read(); | ||
return; | ||
} | ||
var rawmethodName = hook.fullName.Split('.').Last(); | ||
var hookMethod = classType.GetMethod(methodName); | ||
|
||
if (hookMethod == null) { | ||
Console.WriteLine("HooksInjector: ERROR: Method " + rawmethodName + " Not found in class " + className); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
InjectionDefinition injector; | ||
|
||
try { | ||
if (hook.canBlock) { | ||
if (method.Parameters.Count > 0) | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.PassParametersRef | InjectFlags.ModifyReturn); | ||
else | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.ModifyReturn); | ||
} | ||
else { | ||
if (method.Parameters.Count > 0) | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance | InjectFlags.PassParametersRef); | ||
else | ||
injector = new InjectionDefinition(method, hookMethod, InjectFlags.PassInvokingInstance); | ||
} | ||
|
||
if (hook.hookEnd) { | ||
injector.Inject(-1, null, InjectDirection.Before); | ||
} | ||
else | ||
injector.Inject(); | ||
Console.WriteLine("HooksInjector: Hooked " + rawmethodName + "."); | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine("HooksInjector: ERROR: " + e.ToString() + " Hook definition is probably wrong."); | ||
Console.ReadLine(); | ||
return; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.