Compare commits

..

3 Commits
4.3.1 ... 4.3.2

Author SHA1 Message Date
a80cef4c1d Bump version 2021-09-07 19:11:58 +10:00
450bb77f2e Use Harmony's FullDescription for hook parameter types 2021-09-07 19:11:19 +10:00
0479102db6 Cleanup toggle Enabled logic 2021-09-07 18:06:38 +10:00
2 changed files with 17 additions and 7 deletions

View File

@ -20,7 +20,7 @@ namespace UnityExplorer
public static class ExplorerCore public static class ExplorerCore
{ {
public const string NAME = "UnityExplorer"; public const string NAME = "UnityExplorer";
public const string VERSION = "4.3.1"; public const string VERSION = "4.3.2";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer"; public const string GUID = "com.sinai.unityexplorer";

View File

@ -17,6 +17,14 @@ namespace UnityExplorer.Hooks
private static readonly StringBuilder evalOutput = new StringBuilder(); private static readonly StringBuilder evalOutput = new StringBuilder();
private static readonly ScriptEvaluator scriptEvaluator = new ScriptEvaluator(new StringWriter(evalOutput)); private static readonly ScriptEvaluator scriptEvaluator = new ScriptEvaluator(new StringWriter(evalOutput));
static HookInstance()
{
scriptEvaluator.Run("using System;");
scriptEvaluator.Run("using System.Reflection;");
scriptEvaluator.Run("using System.Collections;");
scriptEvaluator.Run("using System.Collections.Generic;");
}
// Instance // Instance
public bool Enabled; public bool Enabled;
@ -117,13 +125,12 @@ namespace UnityExplorer.Hooks
if (targetMethod.ReturnType != typeof(void)) if (targetMethod.ReturnType != typeof(void))
codeBuilder.Append($", {targetMethod.ReturnType.FullName} __result"); codeBuilder.Append($", {targetMethod.ReturnType.FullName} __result");
int paramIdx = 0;
var parameters = targetMethod.GetParameters(); var parameters = targetMethod.GetParameters();
int paramIdx = 0;
foreach (var param in parameters) foreach (var param in parameters)
{ {
Type pType = param.ParameterType; codeBuilder.Append($", {param.ParameterType.FullDescription().Replace("&", "")} __{paramIdx}");
if (pType.IsByRef) pType = pType.GetElementType();
codeBuilder.Append($", {pType.FullName} __{paramIdx}");
paramIdx++; paramIdx++;
} }
@ -177,13 +184,14 @@ namespace UnityExplorer.Hooks
codeBuilder.AppendLine("}"); codeBuilder.AppendLine("}");
//ExplorerCore.Log(codeBuilder.ToString());
return PatchSourceCode = codeBuilder.ToString(); return PatchSourceCode = codeBuilder.ToString();
} }
public void TogglePatch() public void TogglePatch()
{ {
Enabled = !Enabled; if (!Enabled)
if (Enabled)
Patch(); Patch();
else else
Unpatch(); Unpatch();
@ -194,6 +202,7 @@ namespace UnityExplorer.Hooks
try try
{ {
patchProcessor.Patch(); patchProcessor.Patch();
Enabled = true; Enabled = true;
} }
catch (Exception ex) catch (Exception ex)
@ -214,6 +223,7 @@ namespace UnityExplorer.Hooks
patchProcessor.Unpatch(finalizer); patchProcessor.Unpatch(finalizer);
if (transpiler != null) if (transpiler != null)
patchProcessor.Unpatch(transpiler); patchProcessor.Unpatch(transpiler);
Enabled = false; Enabled = false;
} }
catch (Exception ex) catch (Exception ex)