Skip to content

Commit

Permalink
Vr patch (#55)
Browse files Browse the repository at this point in the history
* VR patch
* only patching/enabling VR if at least one mod requires it
* checksum
  • Loading branch information
amazingalek authored Jan 10, 2020
1 parent 5d32578 commit a20c244
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 81 deletions.
1 change: 1 addition & 0 deletions OWML.Common/IModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace OWML.Common
{
public interface IModConfig
{
bool RequireVR { get; }
Dictionary<string, object> Settings { get; }
T GetSetting<T>(string key);
}
Expand Down
2 changes: 1 addition & 1 deletion OWML.Common/IModManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IModManifest
string OWMLVersion { get; }
string AssemblyPath { get; }
string UniqueName { get; }
string FolderPath { get; set; }
string ModFolderPath { get; set; }
bool Enabled { get; }
}
}
2 changes: 2 additions & 0 deletions OWML.Common/IOwmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public interface IOwmlConfig
{
string GamePath { get; set; }
string ManagedPath { get; }
string PluginsPath { get; }
string DataPath { get; }
string OWMLPath { get; }
string ModsPath { get; }
string OutputFilePath { get; }
Expand Down
51 changes: 35 additions & 16 deletions OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using OWML.Common;
using OWML.ModHelper;
using OWML.Patcher;
using OWML.Update;

namespace OWML.Launcher
{
public class App
{
private const string Version = "0.3.20";
private const string Version = "0.3.21";

private readonly IOwmlConfig _owmlConfig;
private readonly IModConsole _writer;
private readonly IModFinder _modFinder;
private readonly OutputListener _listener;
private readonly PathFinder _pathFinder;
private readonly ModPatcher _patcher;
private readonly OWPatcher _owPatcher;
private readonly VRPatcher _vrPatcher;
private readonly ModUpdate _update;

public App(IOwmlConfig owmlConfig, IModConsole writer, IModFinder modFinder,
OutputListener listener, PathFinder pathFinder, ModPatcher patcher, ModUpdate update)
OutputListener listener, PathFinder pathFinder, OWPatcher owPatcher, VRPatcher vrPatcher, ModUpdate update)
{
_owmlConfig = owmlConfig;
_writer = writer;
_modFinder = modFinder;
_listener = listener;
_pathFinder = pathFinder;
_patcher = patcher;
_owPatcher = owPatcher;
_vrPatcher = vrPatcher;
_update = update;
}

Expand All @@ -46,9 +50,11 @@ public void Run()

ListenForOutput();

ShowModList();
var manifests = _modFinder.GetManifests();

ShowModList(manifests);

PatchGame();
PatchGame(manifests);

StartGame();

Expand Down Expand Up @@ -98,9 +104,8 @@ private void CopyGameFiles()
_writer.WriteLine("Game files copied.");
}

private void ShowModList()
private void ShowModList(IList<IModManifest> manifests)
{
var manifests = _modFinder.GetManifests();
if (!manifests.Any())
{
_writer.WriteLine("Warning: found no mods.");
Expand Down Expand Up @@ -130,17 +135,31 @@ private void OnOutput(string s)
}
}

private void PatchGame()
private void PatchGame(IList<IModManifest> manifests)
{
_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)
var enableVR = IsVRRequired(manifests);
_owPatcher.PatchGame();
_vrPatcher.PatchVR(enableVR);
}

private bool IsVRRequired(IList<IModManifest> manifests)
{
foreach (var manifest in manifests)
{
File.Copy(filename, $"{_owmlConfig.ManagedPath}/{filename}", true);
var configPath = manifest.ModFolderPath + "config.json";
if (manifest.Enabled && File.Exists(configPath))
{
var json = File.ReadAllText(configPath);
var config = JsonConvert.DeserializeObject<ModConfig>(json);
if (config.RequireVR)
{
_writer.WriteLine($"{manifest.UniqueName} requires VR.");
return true;
}
}
}
File.WriteAllText($"{_owmlConfig.ManagedPath}/OWML.Config.json", JsonConvert.SerializeObject(_owmlConfig));
_writer.WriteLine("No mod requires VR.");
return false;
}

private void StartGame()
Expand Down
5 changes: 3 additions & 2 deletions OWML.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ static void Main(string[] args)
var modFinder = new ModFinder(owmlConfig, writer);
var outputListener = new OutputListener(owmlConfig);
var pathFinder = new PathFinder(owmlConfig, writer);
var patcher = new ModPatcher(owmlConfig, writer);
var owPatcher = new OWPatcher(owmlConfig, writer);
var vrPatcher = new VRPatcher(owmlConfig, writer);
var update = new ModUpdate(writer);
var app = new App(owmlConfig, writer, modFinder, outputListener, pathFinder, patcher, update);
var app = new App(owmlConfig, writer, modFinder, outputListener, pathFinder, owPatcher, vrPatcher, update);
app.Run();
}

Expand Down
12 changes: 6 additions & 6 deletions OWML.ModHelper.Assets/ModAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ModAssets(IModConsole console, IModManifest manifest)

public AssetBundle LoadBundle(string filename)
{
var path = _manifest.FolderPath + filename;
var path = _manifest.ModFolderPath + filename;
_console.WriteLine("Loading asset bundle from " + path);
var bundle = AssetBundle.LoadFromFile(path);
if (bundle == null)
Expand All @@ -32,8 +32,8 @@ public AssetBundle LoadBundle(string filename)

public IModAsset<GameObject> Load3DObject(string objectFilename, string imageFilename)
{
var objectPath = _manifest.FolderPath + objectFilename;
var imagePath = _manifest.FolderPath + imageFilename;
var objectPath = _manifest.ModFolderPath + objectFilename;
var imagePath = _manifest.ModFolderPath + imageFilename;
_console.WriteLine("Loading object from " + objectPath);

var go = new GameObject();
Expand All @@ -47,7 +47,7 @@ public IModAsset<GameObject> Load3DObject(string objectFilename, string imageFil

public IModAsset<MeshFilter> LoadMesh(string objectFilename)
{
var objectPath = _manifest.FolderPath + objectFilename;
var objectPath = _manifest.ModFolderPath + objectFilename;
_console.WriteLine("Loading mesh from " + objectPath);

var go = new GameObject();
Expand All @@ -60,7 +60,7 @@ public IModAsset<MeshFilter> LoadMesh(string objectFilename)

public IModAsset<MeshRenderer> LoadTexture(string imageFilename)
{
var imagePath = _manifest.FolderPath + imageFilename;
var imagePath = _manifest.ModFolderPath + imageFilename;
_console.WriteLine("Loading texture from " + imagePath);

var go = new GameObject();
Expand All @@ -73,7 +73,7 @@ public IModAsset<MeshRenderer> LoadTexture(string imageFilename)

public IModAsset<AudioSource> LoadAudio(string audioFilename)
{
var audioPath = _manifest.FolderPath + audioFilename;
var audioPath = _manifest.ModFolderPath + audioFilename;
_console.WriteLine("Loading audio from " + audioPath);

var go = new GameObject();
Expand Down
3 changes: 3 additions & 0 deletions OWML.ModHelper/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace OWML.ModHelper
{
public class ModConfig : IModConfig
{
[JsonProperty("requireVR")]
public bool RequireVR { get; set; }

[JsonProperty("settings")]
public Dictionary<string, object> Settings { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions OWML.ModHelper/ModManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class ModManifest : IModManifest
public bool Enabled { get; private set; }

[JsonIgnore]
public string FolderPath { get; set; }
public string ModFolderPath { get; set; }

[JsonIgnore]
public string AssemblyPath => FolderPath + Filename;
public string AssemblyPath => ModFolderPath + Filename;
}
}
4 changes: 2 additions & 2 deletions OWML.ModHelper/ModStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ModStorage(IModLogger logger, IModConsole console, IModManifest manifest)

public T Load<T>(string filename)
{
var path = _manifest.FolderPath + filename;
var path = _manifest.ModFolderPath + filename;
_logger.Log($"Loading {path}...");
if (!File.Exists(path))
{
Expand All @@ -41,7 +41,7 @@ public T Load<T>(string filename)

public void Save<T>(T obj, string filename)
{
var path = _manifest.FolderPath + filename;
var path = _manifest.ModFolderPath + filename;
_logger.Log($"Saving {path}...");
try
{
Expand Down
8 changes: 7 additions & 1 deletion OWML.ModHelper/OwmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ public class OwmlConfig : IOwmlConfig
public bool Verbose { get; private set; }

[JsonIgnore]
public string ManagedPath => $"{GamePath}/OuterWilds_Data/Managed";
public string DataPath => $"{GamePath}/OuterWilds_Data";

[JsonIgnore]
public string ManagedPath => $"{DataPath}/Managed";

[JsonIgnore]
public string PluginsPath => $"{DataPath}/Plugins";

[JsonProperty("owmlPath")]
public string OWMLPath { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion OWML.ModLoader/ModFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IList<IModManifest> GetManifests()
{
var json = File.ReadAllText(manifestFilename);
var manifest = JsonConvert.DeserializeObject<ModManifest>(json);
manifest.FolderPath = manifestFilename.Substring(0, manifestFilename.IndexOf("manifest.json"));
manifest.ModFolderPath = manifestFilename.Substring(0, manifestFilename.IndexOf("manifest.json"));
manifests.Add(manifest);
}
return manifests;
Expand Down
22 changes: 19 additions & 3 deletions OWML.Patcher/OWML.Patcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,32 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="dnlib, Version=3.3.0.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL">
<Reference Include="BsPatch, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>VR\BsPatch.dll</HintPath>
</Reference>
<Reference Include="dnlib, Version=1.6.0.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dnpatch\dnlib.dll</HintPath>
</Reference>
<Reference Include="dnpatch">
<Reference Include="dnpatch, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dnpatch\dnpatch.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>VR\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="ModPatcher.cs" />
<Compile Include="OWPatcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VRPatcher.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OWML.Common\OWML.Common.csproj">
Expand All @@ -58,5 +71,8 @@
<Name>OWML.ModLoader</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit a20c244

Please sign in to comment.