mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-22 12:39:51 +00:00
rework patches
This commit is contained in:
parent
bc41702ac2
commit
222c4047a5
@ -35,15 +35,15 @@ namespace QSB.Patches
|
|||||||
_patchedMethods.Add(method);
|
_patchedMethods.Add(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Prefix(string patchName)
|
public void Prefix(string patchName, params Type[] args)
|
||||||
=> DoPrefixPostfix(true, patchName);
|
=> DoPrefixPostfix(true, patchName, args);
|
||||||
|
|
||||||
public void Postfix(string patchName)
|
public void Postfix(string patchName, params Type[] args)
|
||||||
=> DoPrefixPostfix(false, patchName);
|
=> DoPrefixPostfix(false, patchName, args);
|
||||||
|
|
||||||
private void DoPrefixPostfix(bool isPrefix, string patchName)
|
private void DoPrefixPostfix(bool isPrefix, string patchName, params Type[] args)
|
||||||
{
|
{
|
||||||
var method = GetMethodInfo(patchName);
|
var method = GetMethodInfo(patchName, args);
|
||||||
|
|
||||||
if (method != null)
|
if (method != null)
|
||||||
{
|
{
|
||||||
@ -62,7 +62,7 @@ namespace QSB.Patches
|
|||||||
//DebugLog.DebugWrite($"{(isPrefix ? "[Prefix]" : "[Postfix]")} {patchName}", method == null ? MessageType.Error : MessageType.Success);
|
//DebugLog.DebugWrite($"{(isPrefix ? "[Prefix]" : "[Postfix]")} {patchName}", method == null ? MessageType.Error : MessageType.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodInfo GetMethodInfo(string patchName)
|
private MethodInfo GetMethodInfo(string patchName, params Type[] args)
|
||||||
{
|
{
|
||||||
var splitName = patchName.Split('_');
|
var splitName = patchName.Split('_');
|
||||||
var typeName = splitName[0];
|
var typeName = splitName[0];
|
||||||
@ -75,14 +75,41 @@ namespace QSB.Patches
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var method = type.GetAnyMethod(methodName);
|
var allMethodsOfName = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Where(x => x.Name == methodName);
|
||||||
if (method == null)
|
|
||||||
|
if (allMethodsOfName.Count() == 0)
|
||||||
{
|
{
|
||||||
DebugLog.ToConsole($"Error - Couldn't find method for patch name {patchName}!", MessageType.Error);
|
DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName}.", MessageType.Error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return method;
|
if (allMethodsOfName.Count() == 1)
|
||||||
|
{
|
||||||
|
return allMethodsOfName.First();
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLog.DebugWrite($"More than one method found with name {methodName} in type {typeName}");
|
||||||
|
|
||||||
|
foreach (var method in allMethodsOfName)
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"checking {method.Name}");
|
||||||
|
var paramList = method.GetParameters().Select(x => x.ParameterType);
|
||||||
|
if (Enumerable.SequenceEqual(args, paramList))
|
||||||
|
{
|
||||||
|
DebugLog.DebugWrite($"match!");
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLog.DebugWrite($"nothing found");
|
||||||
|
|
||||||
|
DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName} with parameter list of {string.Join(", ", args.Select(x => x.FullName).ToArray())}", MessageType.Error);
|
||||||
|
foreach (var method in allMethodsOfName)
|
||||||
|
{
|
||||||
|
var paramList = method.GetParameters().Select(x => x.ParameterType);
|
||||||
|
DebugLog.ToConsole($"- Found {method.Name}, but with params {string.Join(", ", paramList.Select(x => x.FullName).ToArray())}", MessageType.Error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetFirstTypeByName(string typeName)
|
private Type GetFirstTypeByName(string typeName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user