Skip to content

Commit

Permalink
oxposing owml config (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingalek authored Jan 7, 2020
1 parent d73bf52 commit e3e4c36
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 40 deletions.
27 changes: 14 additions & 13 deletions OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ namespace OWML.Launcher
{
public class App
{
private const string Version = "0.3.15";
private const string Version = "0.3.16";

private readonly IOwmlConfig _config;
private readonly IOwmlConfig _owmlConfig;
private readonly IModConsole _writer;
private readonly IModFinder _modFinder;
private readonly OutputListener _listener;
private readonly PathFinder _pathFinder;
private readonly ModPatcher _patcher;

public App(IOwmlConfig config, IModConsole writer, IModFinder modFinder, OutputListener listener, PathFinder pathFinder)
public App(IOwmlConfig owmlConfig, IModConsole writer, IModFinder modFinder, OutputListener listener, PathFinder pathFinder, ModPatcher patcher)
{
_config = config;
_owmlConfig = owmlConfig;
_writer = writer;
_modFinder = modFinder;
_listener = listener;
_pathFinder = pathFinder;
_patcher = patcher;
}

public void Run()
Expand All @@ -51,16 +53,16 @@ private void LocateGamePath()
{
var gamePath = _pathFinder.FindGamePath();
_writer.WriteLine("Game found in " + gamePath);
if (gamePath != _config.GamePath)
if (gamePath != _owmlConfig.GamePath)
{
_config.GamePath = gamePath;
_owmlConfig.GamePath = gamePath;
SaveConfig();
}
}

private void SaveConfig()
{
var json = JsonConvert.SerializeObject(_config);
var json = JsonConvert.SerializeObject(_owmlConfig);
File.WriteAllText("OWML.Config.json", json);
}

Expand All @@ -69,7 +71,7 @@ private void CopyGameFiles()
var filesToCopy = new[] { "UnityEngine.CoreModule.dll", "Assembly-CSharp.dll" };
foreach (var fileName in filesToCopy)
{
File.Copy($"{_config.ManagedPath}/{fileName}", fileName, true);
File.Copy($"{_owmlConfig.ManagedPath}/{fileName}", fileName, true);
}
_writer.WriteLine("Game files copied.");
}
Expand Down Expand Up @@ -108,24 +110,23 @@ private void OnOutput(string s)

private void PatchGame()
{
var patcher = new ModPatcher(_config, _writer);
patcher.PatchGame();
_patcher.PatchGame();
var filesToCopy = new[] { "OWML.ModLoader.dll", "OWML.Common.dll", "OWML.ModHelper.dll",
"OWML.ModHelper.Events.dll", "OWML.ModHelper.Assets.dll", "OWML.ModHelper.Menus.dll",
"Newtonsoft.Json.dll", "System.Runtime.Serialization.dll", "0Harmony.dll", "NAudio-Unity.dll" };
foreach (var filename in filesToCopy)
{
File.Copy(filename, $"{_config.ManagedPath}/{filename}", true);
File.Copy(filename, $"{_owmlConfig.ManagedPath}/{filename}", true);
}
File.WriteAllText($"{_config.ManagedPath}/OWML.Config.json", JsonConvert.SerializeObject(_config));
File.WriteAllText($"{_owmlConfig.ManagedPath}/OWML.Config.json", JsonConvert.SerializeObject(_owmlConfig));
}

private void StartGame()
{
_writer.WriteLine("Starting game...");
try
{
Process.Start($"{_config.GamePath}/OuterWilds.exe");
Process.Start($"{_owmlConfig.GamePath}/OuterWilds.exe");
}
catch (Exception ex)
{
Expand Down
14 changes: 8 additions & 6 deletions OWML.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
using OWML.Common;
using OWML.ModHelper;
using OWML.ModLoader;
using OWML.Patcher;

namespace OWML.Launcher
{
public class Program
{
static void Main(string[] args)
{
var config = GetConfig();
var owmlConfig = GetOwmlConfig();
var writer = new OutputWriter();
var modFinder = new ModFinder(config, writer);
var outputListener = new OutputListener(config);
var pathFinder = new PathFinder(config, writer);
var app = new App(config, writer, modFinder, outputListener, pathFinder);
var modFinder = new ModFinder(owmlConfig, writer);
var outputListener = new OutputListener(owmlConfig);
var pathFinder = new PathFinder(owmlConfig, writer);
var patcher = new ModPatcher(owmlConfig, writer);
var app = new App(owmlConfig, writer, modFinder, outputListener, pathFinder, patcher);
app.Run();
}

private static IOwmlConfig GetConfig()
private static IOwmlConfig GetOwmlConfig()
{
var json = File.ReadAllText("OWML.Config.json")
.Replace("\\", "/");
Expand Down
4 changes: 3 additions & 1 deletion OWML.ModHelper/ModHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class ModHelper : IModHelper
public IModMenus Menus { get; }
public IModManifest Manifest { get; }
public IModConfig Config { get; }
public IOwmlConfig OwmlConfig { get; }

public ModHelper(IModLogger logger, IModConsole console, IHarmonyHelper harmonyHelper, IModEvents events,
IModAssets assets, IModStorage storage, IModMenus menus, IModManifest manifest, IModConfig config)
IModAssets assets, IModStorage storage, IModMenus menus, IModManifest manifest, IModConfig config, IOwmlConfig owmlConfig)
{
Logger = logger;
Console = console;
Expand All @@ -27,6 +28,7 @@ public ModHelper(IModLogger logger, IModConsole console, IHarmonyHelper harmonyH
Menus = menus;
Manifest = manifest;
Config = config;
OwmlConfig = owmlConfig;
}

}
Expand Down
14 changes: 7 additions & 7 deletions OWML.ModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public class ModLoader

public static void LoadMods()
{
var config = GetConfig();
if (config == null)
var owmlConfig = GetOwmlConfig();
if (owmlConfig == null)
{
return;
}
var logger = new ModLogger(config);
var logger = new ModLogger(owmlConfig);
logger.Log("Got config!");
var console = new ModConsole(config, logger);
var console = new ModConsole(owmlConfig, logger);
console.WriteLine("Mod loader has been initialized.");
var modFinder = new ModFinder(config, console);
var modFinder = new ModFinder(owmlConfig, console);
var menus = new ModMenus(logger, console);
var owo = new Owo(modFinder, logger, console, config, menus);
var owo = new Owo(modFinder, logger, console, owmlConfig, menus);
owo.LoadMods();
}

private static IOwmlConfig GetConfig()
private static IOwmlConfig GetOwmlConfig()
{
try
{
Expand Down
14 changes: 7 additions & 7 deletions OWML.ModLoader/Owo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ internal class Owo
private readonly IModFinder _modFinder;
private readonly IModLogger _logger;
private readonly IModConsole _console;
private readonly IOwmlConfig _config;
private readonly IOwmlConfig _owmlConfig;
private readonly IModMenus _menus;

public Owo(IModFinder modFinder, IModLogger logger, IModConsole console, IOwmlConfig config, IModMenus menus)
public Owo(IModFinder modFinder, IModLogger logger, IModConsole console, IOwmlConfig owmlConfig, IModMenus menus)
{
_modFinder = modFinder;
_logger = logger;
_console = console;
_config = config;
_owmlConfig = owmlConfig;
_menus = menus;
}

public void LoadMods()
{
if (_config.Verbose)
if (_owmlConfig.Verbose)
{
_console.WriteLine("Verbose mod is enabled");
Application.logMessageReceived += OnLogMessageReceived;
Expand Down Expand Up @@ -60,11 +60,11 @@ private IModHelper CreateModHelper(IModManifest manifest)
var storage = new ModStorage(_logger, _console, manifest);
var harmonyHelper = new HarmonyHelper(_logger, _console, manifest);
var events = new ModEvents(_logger, _console, harmonyHelper);
var config = GetConfig(storage);
return new ModHelper.ModHelper(_logger, _console, harmonyHelper, events, assets, storage, _menus, manifest, config);
var modConfig = GetModConfig(storage);
return new ModHelper.ModHelper(_logger, _console, harmonyHelper, events, assets, storage, _menus, manifest, modConfig, _owmlConfig);
}

private IModConfig GetConfig(IModStorage storage)
private IModConfig GetModConfig(IModStorage storage)
{
_logger.Log("Initializing config");
var config = storage.Load<ModConfig>("config.json") ?? new ModConfig();
Expand Down
8 changes: 4 additions & 4 deletions OWML.Patcher/ModPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OWML.Patcher
{
public class ModPatcher
{
private readonly IOwmlConfig _config;
private readonly IOwmlConfig _owmlConfig;
private readonly IModConsole _writer;

private const string PatchClass = "PermanentManager";
Expand All @@ -19,15 +19,15 @@ public class ModPatcher
{
};

public ModPatcher(IOwmlConfig config, IModConsole writer)
public ModPatcher(IOwmlConfig owmlConfig, IModConsole writer)
{
_config = config;
_owmlConfig = owmlConfig;
_writer = writer;
}

public void PatchGame()
{
var patcher = new dnpatch.Patcher($"{_config.ManagedPath}/Assembly-CSharp.dll");
var patcher = new dnpatch.Patcher($"{_owmlConfig.ManagedPath}/Assembly-CSharp.dll");

RemoveOldPatches(patcher);

Expand Down
2 changes: 1 addition & 1 deletion OWML.SampleMods/OWML.EnableDebugMode/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"name": "EnableDebugMode",
"uniqueName": "Alek.EnableDebugMode",
"version": "0.2",
"owmlVersion": "0.3.15",
"owmlVersion": "0.3.16",
"enabled": false
}
2 changes: 1 addition & 1 deletion OWML.SampleMods/OWML.LoadCustomAssets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"name": "LoadCustomAssets",
"uniqueName": "Alek.LoadCustomAssets",
"version": "0.4",
"owmlVersion": "0.3.15",
"owmlVersion": "0.3.16",
"enabled": false
}

0 comments on commit e3e4c36

Please sign in to comment.