Skip to content

Commit 6d4763a

Browse files
committed
Skip loading scripts that use HarmonyWrapper
1 parent 8c44227 commit 6d4763a

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ Currently the following special folders are available:
8181

8282
At this moment the compilation errors are simply written to the BepInEx console.
8383

84-
## TODO
84+
### Upgrading to 1.2.4.0
8585

86-
* [x] Script reloading
87-
* [x] Specifying script metadata (name, description, DLL dependencies)
88-
* [ ] Maybe a UI?
89-
* [ ] Optionally an ability to locate and use `csc` to compile scripts when mcs cannot be used
86+
Starting 1.2.4.0, you might see the following error when loading a script:
87+
88+
```
89+
Skipping loading `...` because it references outdated HarmonyWrapper and BepInEx.Harmony. To fix this, refer to github.com/denikson/BepInEx.ScriptLoader#upgrading-to-1240.
90+
```
91+
92+
This error happens when using older ScriptLoader scripts with ScriptLoader 1.2.4.0 or newer.
93+
94+
In most cases, you can fix the script yourself. Open the script specified in the error into Notepad or some other text editor and do the following changes:
95+
96+
* Remove `using BepInEx.Harmony;` line
97+
* Replace `HarmonyWrapper.PatchAll` with `Harmony.CreateAndPatchAll`
98+
99+
Then try to run the game again. If the error persists or you get some other error, the script is too complex to fix by this guide. In that case please conact the developer of the script and ask them to fix it.

ScriptLoader/ScriptLoader.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,19 @@ bool IsValidProcess(string scriptFile)
9292
StringComparison.InvariantCultureIgnoreCase));
9393
}
9494

95+
bool UsesHarmonyWrapper(string scriptFile)
96+
{
97+
var text = File.ReadAllText(scriptFile);
98+
if (text.Contains("HarmonyWrapper") || text.Contains("BepInEx.Harmony"))
99+
{
100+
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");
101+
return true;
102+
}
103+
return false;
104+
}
105+
95106
var ignores = new HashSet<string>(File.ReadAllLines(ignoresPath).Select(s => s.Trim()));
96-
var scriptsToCompile = files.Where(f => IsValidProcess(f) && !ignores.Contains(Path.GetFileName(f))).ToList();
107+
var scriptsToCompile = files.Where(f => !UsesHarmonyWrapper(f) && IsValidProcess(f) && !ignores.Contains(Path.GetFileName(f))).ToList();
97108

98109
Logger.LogInfo(
99110
$"Found {files.Length} scripts to compile, skipping {files.Length - scriptsToCompile.Count} scripts because of `scriptignores` or process filters");

0 commit comments

Comments
 (0)