Skip to content

Commit 479f67d

Browse files
committed
Fix to work with the latest Doorstop
1 parent b6cfdf9 commit 479f67d

File tree

9 files changed

+39
-74
lines changed

9 files changed

+39
-74
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018
3+
Copyright Geoffrey Horsington (c) 2018
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
> This software exists as an example of how to use [UnityDoorstop](https://github.com/NeighTools/UnityDoorstop)
66
> to preload managed code during Unity startup.
77
>
8-
> Use for testing purposes only!
8+
> Use for testing purposes only for **developers**!
99
> For a stable version, please use [BepInEx](https://github.com/bbepis/BepInEx) when a suitable loader exists.
1010
11-
This is a simple loader that loads and applies Sybaris-compatible patchers without editing the assembly files.
11+
This is a simple loader that loads and applies Sybaris-compatible patchers without editing the assembly files.
12+
The loader is works as a seamless replacement Sybaris 2.1.
1213

13-
## Requirements
14-
15-
* [UnityDoorstop 2.0](https://github.com/NeighTools/UnityDoorstop) or higher
14+
This tool uses [UnityDoorstop](https://github.com/NeighTools/UnityDoorstop) as its backbone and is packaged with it.
1615

1716
## Installation
1817

19-
1. Extract the contents of the archive into `UnityDoorstop` folder. Overwrite when asked.
18+
1. **Remove `opengl32.dll` and `Sybaris\Sybaris.Loader.dll`** if you have them
19+
2. Extract the contents of the archive into the game's root directory
20+
3. Configure the loader `Sybaris\SybariLoader.json` as you want.
21+
4. Launch the game
2022

2123
## Installing patchers
2224

23-
Put all Sybaris patchers into `<UnityDoorstop>\Sybaris\patches`.
25+
This is Sybaris 2.1 compatible loader. Thus put all your patchers into `Sybaris` folder.
2426

2527
## More information
2628

SybarisLoader/Configuration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using SimpleJSON;
55
using SybarisLoader.Util;
66

7-
namespace PatchLoader
7+
namespace SybarisLoader
88
{
99
public static class Configuration
1010
{
@@ -37,8 +37,9 @@ private static void InitDefaultConfig(string path)
3737

3838
Options["debug"]["logging"]["enabled"] = true;
3939
Options["debug"]["logging"]["redirectConsole"] = true;
40+
Options["debug"]["logging"]["outputDirectory"] = @"Sybaris\logs";
4041
Options["debug"]["outputAssemblies"]["enabled"] = false;
41-
Options["debug"]["outputAssemblies"]["outputDirectory"] = @"UnityPrePatcher\debug\assemblies";
42+
Options["debug"]["outputAssemblies"]["outputDirectory"] = @"Sybaris\patched_assemblies";
4243

4344
StringBuilder sb = new StringBuilder();
4445

SybarisLoader/SybarisLoader.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.IO;
44
using System.Reflection;
55
using Mono.Cecil;
6-
using PatchLoader;
76
using SybarisLoader.Util;
87

98
namespace SybarisLoader
@@ -25,7 +24,7 @@ public static void LoadPatchers()
2524

2625
Logger.Log(LogLevel.Info, "Loading patchers");
2726

28-
foreach (string dll in Directory.GetFiles(Utils.PatchesDir, "*.Patcher.dll"))
27+
foreach (string dll in Directory.GetFiles(Utils.SybarisDir, "*.Patcher.dll"))
2928
{
3029
Assembly assembly;
3130

@@ -46,8 +45,7 @@ public static void LoadPatchers()
4645
if (type.IsInterface)
4746
continue;
4847

49-
FieldInfo targetAssemblyNamesField =
50-
type.GetField("TargetAssemblyNames", BindingFlags.Static | BindingFlags.Public);
48+
FieldInfo targetAssemblyNamesField = type.GetField("TargetAssemblyNames", BindingFlags.Static | BindingFlags.Public);
5149

5250
if (targetAssemblyNamesField == null || targetAssemblyNamesField.FieldType != typeof(string[]))
5351
continue;
@@ -160,17 +158,23 @@ public static void Patch()
160158
}
161159

162160
/// <summary>
163-
/// The entry point of the loader
161+
/// The entry point of the loader
164162
/// </summary>
165163
public static void Main()
166164
{
167165
if (!Directory.Exists(Utils.SybarisDir))
168166
Directory.CreateDirectory(Utils.SybarisDir);
169-
if (!Directory.Exists(Utils.LogsDir))
170-
Directory.CreateDirectory(Utils.LogsDir);
171167

172168
Configuration.Init();
173169

170+
if (!Configuration.Options["debug"]["logging"]["outputDirectory"].IsString)
171+
Configuration.Options["debug"]["logging"]["enabled"] = false;
172+
else if (!Directory.Exists(Configuration.Options["debug"]["logging"]["outputDirectory"]))
173+
Directory.CreateDirectory(Configuration.Options["debug"]["logging"]["outputDirectory"]);
174+
175+
if (!Directory.Exists(Configuration.Options["debug"]["outputAssemblies"]["outputDirectory"]))
176+
Directory.CreateDirectory(Configuration.Options["debug"]["outputAssemblies"]["outputDirectory"]);
177+
174178
if (Configuration.Options["debug"]["logging"]["enabled"])
175179
Logger.Enabled = true;
176180
if (Configuration.Options["debug"]["logging"]["redirectConsole"])
@@ -179,17 +183,7 @@ public static void Main()
179183
Logger.Log("===Sybaris Loader===");
180184
Logger.Log($"Started on {DateTime.Now:R}");
181185
Logger.Log($"Game assembly directory: {Utils.GameAssembliesDir}");
182-
Logger.Log($"Doorstop directory: {Utils.RootDir}");
183-
184-
if (!Directory.Exists(Utils.PatchesDir))
185-
{
186-
Directory.CreateDirectory(Utils.PatchesDir);
187-
Logger.Log(LogLevel.Info, "No patches directory found! Created an empty one!");
188-
Logger.Dispose();
189-
return;
190-
}
191-
192-
Logger.Log(LogLevel.Info, "Adding ResolveAssembly Handler");
186+
Logger.Log($"Sybaris directory: {Utils.SybarisDir}");
193187

194188
// We add a custom assembly resolver
195189
// Since assemblies don't unload, this event handler will be called always there is an assembly to resolve
@@ -214,7 +208,7 @@ public static void Main()
214208
public static Assembly ResolvePatchers(object sender, ResolveEventArgs args)
215209
{
216210
// Try to resolve from patches directory
217-
if (Utils.TryResolveDllAssembly(args.Name, Utils.PatchesDir, out Assembly patchAssembly))
211+
if (Utils.TryResolveDllAssembly(args.Name, Utils.SybarisDir, out Assembly patchAssembly))
218212
return patchAssembly;
219213
return null;
220214
}
@@ -237,8 +231,7 @@ private static void SavePatchedAssembly(byte[] assembly, string name)
237231
}
238232
catch (Exception e)
239233
{
240-
Logger.Log(LogLevel.Warning,
241-
$"Failed to create patched assembly directory to {outDir}!\nReason: {e.Message}");
234+
Logger.Log(LogLevel.Warning, $"Failed to create patched assembly directory to {outDir}!\nReason: {e.Message}");
242235
return;
243236
}
244237

SybarisLoader/SybarisLoader.csproj

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
32+
<ItemGroup>
33+
<Compile Include="Configuration.cs" />
34+
<Compile Include="SybarisLoader.cs" />
35+
<Compile Include="Properties\AssemblyInfo.cs" />
36+
<Compile Include="Util\Logger.cs" />
37+
<Compile Include="Util\SimpleJSON.cs" />
38+
<Compile Include="Util\Stack.cs" />
39+
<Compile Include="Util\Utils.cs" />
40+
</ItemGroup>
3241
<ItemGroup>
3342
<Reference Include="Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
3443
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.dll</HintPath>
@@ -42,25 +51,9 @@
4251
<Reference Include="Mono.Cecil.Rocks, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
4352
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.Rocks.dll</HintPath>
4453
</Reference>
45-
<Reference Include="System" />
46-
<Reference Include="System.Core" />
47-
<Reference Include="System.Xml.Linq" />
48-
<Reference Include="System.Data.DataSetExtensions" />
49-
<Reference Include="System.Data" />
50-
<Reference Include="System.Xml" />
51-
</ItemGroup>
52-
<ItemGroup>
53-
<Compile Include="Configuration.cs" />
54-
<Compile Include="SybarisLoader.cs" />
55-
<Compile Include="Properties\AssemblyInfo.cs" />
56-
<Compile Include="Util\Logger.cs" />
57-
<Compile Include="Util\SimpleJSON.cs" />
58-
<Compile Include="Util\Stack.cs" />
59-
<Compile Include="Util\Utils.cs" />
6054
</ItemGroup>
6155
<ItemGroup>
6256
<None Include="packages.config" />
6357
</ItemGroup>
64-
<ItemGroup />
6558
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6659
</Project>

SybarisLoader/Util/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private static void Init()
9292
return;
9393

9494
StreamWriter writer =
95-
File.CreateText(Path.Combine(Utils.LogsDir,
95+
File.CreateText(Path.Combine(Configuration.Options["debug"]["logging"]["outputDirectory"],
9696
$"{DateTime.Now:yyyyMMdd_HHmmss_fff}_patcherloader.log"));
9797
writer.AutoFlush = true;
9898

SybarisLoader/Util/SimpleJSON.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
using System.Globalization;
124124
using System.Linq;
125125
using System.Text;
126+
using SybarisLoader.Util;
126127

127128
// ReSharper disable InconsistentNaming
128129
// ReSharper disable CheckNamespace

SybarisLoader/Util/Utils.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,14 @@ static Utils()
1414
//GameAssembliesDir = Path.Combine(GameRootDir, Path.Combine($"{GameName}_Data", "Managed"));
1515

1616
GameAssembliesDir = Path.GetDirectoryName(typeof(Assembly).Assembly.Location);
17-
BinariesDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
18-
RootDir = Path.Combine(BinariesDir, "..");
19-
SybarisDir = Path.Combine(RootDir, "Sybaris");
20-
LogsDir = Path.Combine(SybarisDir, "logs");
21-
PatchesDir = Path.Combine(SybarisDir, "patches");
17+
SybarisDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
2218
}
2319

24-
/// <summary>
25-
/// Binaries directory for UnityPrePatcher.
26-
/// </summary>
27-
public static string BinariesDir { get; }
28-
2920
/// <summary>
3021
/// Game's Managed directory. Takes in account game's executable name.
3122
/// </summary>
3223
public static string GameAssembliesDir { get; }
3324

34-
/// <summary>
35-
/// Logs directory for UnityPrePatcher.
36-
/// </summary>
37-
public static string LogsDir { get; }
38-
39-
/// <summary>
40-
/// Patches directory for UnityPrePatcher.
41-
/// </summary>
42-
public static string PatchesDir { get; }
43-
44-
/// <summary>
45-
/// Base UnityPrePatcher directory.
46-
/// </summary>
47-
public static string RootDir { get; }
48-
4925
/// <summary>
5026
/// Patches directory for UnityPrePatcher.
5127
/// </summary>

SybarisLoader/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
32
<packages>
43
<package id="Mono.Cecil" version="0.10.0" targetFramework="net35" />
54
</packages>

0 commit comments

Comments
 (0)