diff --git a/NuGet.Config b/NuGet.Config
new file mode 100644
index 0000000..1864ded
--- /dev/null
+++ b/NuGet.Config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ScriptLoader/ScriptLoader.cs b/ScriptLoader/ScriptLoader.cs
index ad6a637..4452b85 100644
--- a/ScriptLoader/ScriptLoader.cs
+++ b/ScriptLoader/ScriptLoader.cs
@@ -6,25 +6,29 @@
using System.Security.Cryptography;
using System.Text;
using BepInEx;
+using BepInEx.IL2CPP;
using BepInEx.Logging;
namespace ScriptLoader
{
- [BepInPlugin("horse.coder.tools.scriptloader", "C# Script Loader", "1.2.4")]
- public class ScriptLoader : BaseUnityPlugin
+ [BepInPlugin("horse.coder.tools.scriptloader", "C# Script Loader", "1.3.0")]
+ public class ScriptLoader : BasePlugin
{
private readonly string scriptsPath = Path.Combine(Paths.GameRootPath, "scripts");
private Dictionary availableScripts = new Dictionary();
private FileSystemWatcher fileSystemWatcher;
private Assembly lastCompilationAssembly;
private string lastCompilationHash;
- private LoggerTextWriter loggerTextWriter;
- private bool shouldRecompile;
-
- private void Awake()
+ private LogTextWriter LogTextWriter;
+ public override bool Unload()
+ {
+ fileSystemWatcher.EnableRaisingEvents = false;
+ fileSystemWatcher.Dispose();
+ return base.Unload();
+ }
+ public override void Load()
{
- DontDestroyOnLoad(this);
- loggerTextWriter = new LoggerTextWriter(Logger);
+ LogTextWriter = new LogTextWriter(Log);
CompileScripts();
fileSystemWatcher = new FileSystemWatcher(scriptsPath);
@@ -32,41 +36,27 @@ private void Awake()
fileSystemWatcher.Filter = "*.cs";
fileSystemWatcher.Changed += (sender, args) =>
{
- Logger.LogInfo($"File {Path.GetFileName(args.Name)} changed. Recompiling...");
- shouldRecompile = true;
+ Log.LogInfo("File " + Path.GetFileName(args.Name) + " changed. Recompiling...");
+ CompileScripts();
};
fileSystemWatcher.Deleted += (sender, args) =>
{
- Logger.LogInfo($"File {Path.GetFileName(args.Name)} removed. Recompiling...");
- shouldRecompile = true;
+ Log.LogInfo("File " + Path.GetFileName(args.Name) + " removed. Recompiling...");
+ CompileScripts();
};
fileSystemWatcher.Created += (sender, args) =>
{
- Logger.LogInfo($"File {Path.GetFileName(args.Name)} created. Recompiling...");
- shouldRecompile = true;
+ Log.LogInfo("File " + Path.GetFileName(args.Name) + " created. Recompiling...");
+ CompileScripts();
};
fileSystemWatcher.Renamed += (sender, args) =>
{
- Logger.LogInfo($"File {Path.GetFileName(args.Name)} renamed. Recompiling...");
- shouldRecompile = true;
+ Log.LogInfo("File " + Path.GetFileName(args.Name) + " renamed. Recompiling...");
+ CompileScripts();
};
fileSystemWatcher.EnableRaisingEvents = true;
}
- private void OnDestroy()
- {
- fileSystemWatcher.EnableRaisingEvents = false;
- fileSystemWatcher.Dispose();
- }
-
- private void Update()
- {
- if (!shouldRecompile)
- return;
- CompileScripts();
- shouldRecompile = false;
- }
-
private void CompileScripts()
{
if (!Directory.Exists(scriptsPath))
@@ -97,7 +87,7 @@ bool UsesHarmonyWrapper(string scriptFile)
var text = File.ReadAllText(scriptFile);
if (text.Contains("HarmonyWrapper") || text.Contains("BepInEx.Harmony"))
{
- Logger.LogError($"Skipping loading `{scriptFile}` because it references outdated HarmonyWrapper and BepInEx.Harmony. To fix this, refer to github.com/denikson/BepInEx.ScriptLoader#upgrading-to-1240");
+ Log.LogError("Skipping loading `" + scriptFile + "` because it references outdated HarmonyWrapper and BepInEx.Harmony. To fix this, refer to github.com/denikson/BepInEx.ScriptLoader#upgrading-to-1240");
return true;
}
return false;
@@ -106,8 +96,8 @@ bool UsesHarmonyWrapper(string scriptFile)
var ignores = new HashSet(File.ReadAllLines(ignoresPath).Select(s => s.Trim()));
var scriptsToCompile = files.Where(f => !UsesHarmonyWrapper(f) && IsValidProcess(f) && !ignores.Contains(Path.GetFileName(f))).ToList();
- Logger.LogInfo(
- $"Found {files.Length} scripts to compile, skipping {files.Length - scriptsToCompile.Count} scripts because of `scriptignores` or process filters");
+ Log.LogInfo(
+ "Found " + files.Length + " scripts to compile, skipping " + (files.Length - scriptsToCompile.Count) + " scripts because of `scriptignores` or process filters");
var md5 = MD5.Create();
var scriptDict = new Dictionary();
@@ -123,7 +113,7 @@ bool UsesHarmonyWrapper(string scriptFile)
if (hash == lastCompilationHash)
{
- Logger.LogInfo("No changes detected! Skipping compilation!");
+ Log.LogInfo("No changes detected! Skipping compilation!");
return;
}
@@ -134,11 +124,11 @@ bool UsesHarmonyWrapper(string scriptFile)
Assembly.LoadFile(infoReference);
}
- var ass = MonoCompiler.Compile(scriptDict, loggerTextWriter);
+ var ass = MonoCompiler.Compile(scriptDict, LogTextWriter);
if (ass == null)
{
- Logger.LogError("Skipping loading scripts because of errors above.");
+ Log.LogError("Skipping loading scripts because of errors above.");
return;
}
@@ -151,7 +141,7 @@ bool UsesHarmonyWrapper(string scriptFile)
if (method == null)
continue;
- Logger.Log(LogLevel.Info, $"Unloading {type.Name}");
+ Log.Log(LogLevel.Info, "Unloading " + type.Name);
method.Invoke(null, new object[0]);
}
@@ -166,20 +156,20 @@ bool UsesHarmonyWrapper(string scriptFile)
if (method == null)
continue;
- Logger.Log(LogLevel.Info, $"Running {type.Name}");
+ Log.Log(LogLevel.Info, "Running " + type.Name);
method.Invoke(null, new object[0]);
}
}
}
- internal class LoggerTextWriter : TextWriter
+ internal class LogTextWriter : TextWriter
{
- private readonly ManualLogSource logger;
+ private readonly ManualLogSource Log;
private readonly StringBuilder sb = new StringBuilder();
- public LoggerTextWriter(ManualLogSource logger)
+ public LogTextWriter(ManualLogSource Log)
{
- this.logger = logger;
+ this.Log = Log;
}
public override Encoding Encoding { get; } = Encoding.UTF8;
@@ -188,7 +178,7 @@ public override void Write(char value)
{
if (value == '\n')
{
- logger.Log(LogLevel.Info, sb.ToString());
+ Log.Log(LogLevel.Info, sb.ToString());
sb.Length = 0;
return;
}
diff --git a/ScriptLoader/ScriptLoader.csproj b/ScriptLoader/ScriptLoader.csproj
index ef09927..ab3be9d 100644
--- a/ScriptLoader/ScriptLoader.csproj
+++ b/ScriptLoader/ScriptLoader.csproj
@@ -9,10 +9,11 @@
Properties
ScriptLoader
ScriptLoader
- v3.5
+ v4.8
512
+
true
@@ -22,6 +23,7 @@
DEBUG;TRACE
prompt
4
+ false
pdbonly
@@ -30,11 +32,16 @@
TRACE
prompt
4
+ false
-
- ..\lib\BepInEx.dll
- False
+
+ False
+ ..\lib\BepInEx.Core.dll
+
+
+ False
+ ..\lib\BepInEx.IL2CPP.dll
..\lib\mcs.dll
diff --git a/ScriptLoader/packages.config b/ScriptLoader/packages.config
index 1311b38..622af0e 100644
--- a/ScriptLoader/packages.config
+++ b/ScriptLoader/packages.config
@@ -1,5 +1,4 @@
-
\ No newline at end of file
diff --git a/lib/BepInEx.Core.dll b/lib/BepInEx.Core.dll
new file mode 100644
index 0000000..f9cf6fa
Binary files /dev/null and b/lib/BepInEx.Core.dll differ
diff --git a/lib/BepInEx.IL2CPP.dll b/lib/BepInEx.IL2CPP.dll
new file mode 100644
index 0000000..9732b32
Binary files /dev/null and b/lib/BepInEx.IL2CPP.dll differ