Skip to content

Commit

Permalink
Fix to work with the latest Doorstop
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorsington committed May 5, 2018
1 parent b6cfdf9 commit 479f67d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 74 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018
Copyright Geoffrey Horsington (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
> This software exists as an example of how to use [UnityDoorstop](https://github.com/NeighTools/UnityDoorstop)
> to preload managed code during Unity startup.
>
> Use for testing purposes only!
> Use for testing purposes only for **developers**!
> For a stable version, please use [BepInEx](https://github.com/bbepis/BepInEx) when a suitable loader exists.
This is a simple loader that loads and applies Sybaris-compatible patchers without editing the assembly files.
This is a simple loader that loads and applies Sybaris-compatible patchers without editing the assembly files.
The loader is works as a seamless replacement Sybaris 2.1.

## Requirements

* [UnityDoorstop 2.0](https://github.com/NeighTools/UnityDoorstop) or higher
This tool uses [UnityDoorstop](https://github.com/NeighTools/UnityDoorstop) as its backbone and is packaged with it.

## Installation

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

## Installing patchers

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

## More information

Expand Down
5 changes: 3 additions & 2 deletions SybarisLoader/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using SimpleJSON;
using SybarisLoader.Util;

namespace PatchLoader
namespace SybarisLoader
{
public static class Configuration
{
Expand Down Expand Up @@ -37,8 +37,9 @@ private static void InitDefaultConfig(string path)

Options["debug"]["logging"]["enabled"] = true;
Options["debug"]["logging"]["redirectConsole"] = true;
Options["debug"]["logging"]["outputDirectory"] = @"Sybaris\logs";
Options["debug"]["outputAssemblies"]["enabled"] = false;
Options["debug"]["outputAssemblies"]["outputDirectory"] = @"UnityPrePatcher\debug\assemblies";
Options["debug"]["outputAssemblies"]["outputDirectory"] = @"Sybaris\patched_assemblies";

StringBuilder sb = new StringBuilder();

Expand Down
35 changes: 14 additions & 21 deletions SybarisLoader/SybarisLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Reflection;
using Mono.Cecil;
using PatchLoader;
using SybarisLoader.Util;

namespace SybarisLoader
Expand All @@ -25,7 +24,7 @@ public static void LoadPatchers()

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

foreach (string dll in Directory.GetFiles(Utils.PatchesDir, "*.Patcher.dll"))
foreach (string dll in Directory.GetFiles(Utils.SybarisDir, "*.Patcher.dll"))
{
Assembly assembly;

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

FieldInfo targetAssemblyNamesField =
type.GetField("TargetAssemblyNames", BindingFlags.Static | BindingFlags.Public);
FieldInfo targetAssemblyNamesField = type.GetField("TargetAssemblyNames", BindingFlags.Static | BindingFlags.Public);

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

/// <summary>
/// The entry point of the loader
/// The entry point of the loader
/// </summary>
public static void Main()
{
if (!Directory.Exists(Utils.SybarisDir))
Directory.CreateDirectory(Utils.SybarisDir);
if (!Directory.Exists(Utils.LogsDir))
Directory.CreateDirectory(Utils.LogsDir);

Configuration.Init();

if (!Configuration.Options["debug"]["logging"]["outputDirectory"].IsString)
Configuration.Options["debug"]["logging"]["enabled"] = false;
else if (!Directory.Exists(Configuration.Options["debug"]["logging"]["outputDirectory"]))
Directory.CreateDirectory(Configuration.Options["debug"]["logging"]["outputDirectory"]);

if (!Directory.Exists(Configuration.Options["debug"]["outputAssemblies"]["outputDirectory"]))
Directory.CreateDirectory(Configuration.Options["debug"]["outputAssemblies"]["outputDirectory"]);

if (Configuration.Options["debug"]["logging"]["enabled"])
Logger.Enabled = true;
if (Configuration.Options["debug"]["logging"]["redirectConsole"])
Expand All @@ -179,17 +183,7 @@ public static void Main()
Logger.Log("===Sybaris Loader===");
Logger.Log($"Started on {DateTime.Now:R}");
Logger.Log($"Game assembly directory: {Utils.GameAssembliesDir}");
Logger.Log($"Doorstop directory: {Utils.RootDir}");

if (!Directory.Exists(Utils.PatchesDir))
{
Directory.CreateDirectory(Utils.PatchesDir);
Logger.Log(LogLevel.Info, "No patches directory found! Created an empty one!");
Logger.Dispose();
return;
}

Logger.Log(LogLevel.Info, "Adding ResolveAssembly Handler");
Logger.Log($"Sybaris directory: {Utils.SybarisDir}");

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

Expand Down
25 changes: 9 additions & 16 deletions SybarisLoader/SybarisLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="SybarisLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\Logger.cs" />
<Compile Include="Util\SimpleJSON.cs" />
<Compile Include="Util\Stack.cs" />
<Compile Include="Util\Utils.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.dll</HintPath>
Expand All @@ -42,25 +51,9 @@
<Reference Include="Mono.Cecil.Rocks, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net35\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="SybarisLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\Logger.cs" />
<Compile Include="Util\SimpleJSON.cs" />
<Compile Include="Util\Stack.cs" />
<Compile Include="Util\Utils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion SybarisLoader/Util/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void Init()
return;

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

Expand Down
1 change: 1 addition & 0 deletions SybarisLoader/Util/SimpleJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using SybarisLoader.Util;

// ReSharper disable InconsistentNaming
// ReSharper disable CheckNamespace
Expand Down
26 changes: 1 addition & 25 deletions SybarisLoader/Util/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,14 @@ static Utils()
//GameAssembliesDir = Path.Combine(GameRootDir, Path.Combine($"{GameName}_Data", "Managed"));

GameAssembliesDir = Path.GetDirectoryName(typeof(Assembly).Assembly.Location);
BinariesDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
RootDir = Path.Combine(BinariesDir, "..");
SybarisDir = Path.Combine(RootDir, "Sybaris");
LogsDir = Path.Combine(SybarisDir, "logs");
PatchesDir = Path.Combine(SybarisDir, "patches");
SybarisDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

/// <summary>
/// Binaries directory for UnityPrePatcher.
/// </summary>
public static string BinariesDir { get; }

/// <summary>
/// Game's Managed directory. Takes in account game's executable name.
/// </summary>
public static string GameAssembliesDir { get; }

/// <summary>
/// Logs directory for UnityPrePatcher.
/// </summary>
public static string LogsDir { get; }

/// <summary>
/// Patches directory for UnityPrePatcher.
/// </summary>
public static string PatchesDir { get; }

/// <summary>
/// Base UnityPrePatcher directory.
/// </summary>
public static string RootDir { get; }

/// <summary>
/// Patches directory for UnityPrePatcher.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion SybarisLoader/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="Mono.Cecil" version="0.10.0" targetFramework="net35" />
</packages>

0 comments on commit 479f67d

Please sign in to comment.