Skip to content

Commit

Permalink
Merge pull request #214 from amazingalek/dev
Browse files Browse the repository at this point in the history
master < dev
  • Loading branch information
amazingalek authored Jul 26, 2020
2 parents e0f76eb + 0c9678f commit a6f88d3
Show file tree
Hide file tree
Showing 82 changed files with 1,262 additions and 480 deletions.
5 changes: 4 additions & 1 deletion OWML.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
{
public class Constants
{
public const string QuitKeyPhrase = "{RageAgainstTheDyingOfTheLight}";
public const string ConsolePortArgument = "consolePort";
public const string OwmlConfigFileName = "OWML.Config.json";
public const string OwmlDefaultConfigFileName = "OWML.DefaultConfig.json";
public const string OwmlManifestFileName = "OWML.Manifest.json";
public const string LocalAddress = "127.0.0.1";
public const string ModConfigFileName = "config.json";
public const string ModDefaultConfigFileName = "default-config.json";
public const string ModManifestFileName = "manifest.json";
}
}
1 change: 1 addition & 0 deletions OWML.Common/IModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace OWML.Common
public interface IModConfig
{
bool Enabled { get; set; }
[Obsolete("Use ModManifest.RequireVR instead")]
bool RequireVR { get; set; }
Dictionary<string, object> Settings { get; set; }

Expand Down
11 changes: 8 additions & 3 deletions OWML.Common/IModConsole.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace OWML.Common
using System;

namespace OWML.Common
{
public interface IModConsole
{
void WriteLine(string s);
void WriteLine(params object[] s);
[Obsolete("Use WriteLine(string) or WriteLine(string, MessageType) instead.")]
void WriteLine(params object[] objects);

void WriteLine(string line);
void WriteLine(string line, MessageType type);
}
}
5 changes: 5 additions & 0 deletions OWML.Common/IModData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ public interface IModData
IModManifest Manifest { get; }
IModConfig Config { get; }
IModConfig DefaultConfig { get; }
bool Enabled { get; }
bool RequireVR { get; }

void ResetConfigToDefaults();
bool FixConfigs();
}
}
3 changes: 3 additions & 0 deletions OWML.Common/IModEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace OWML.Common
{
public interface IModEvents
{
IModPlayerEvents Player { get; }
IModSceneEvents Scenes { get; }

Action<MonoBehaviour, Events> OnEvent { get; set; }

void Subscribe<T>(Events ev) where T : MonoBehaviour;
Expand Down
2 changes: 1 addition & 1 deletion OWML.Common/IModFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace OWML.Common
{
public interface IModFinder
{
IList<IModData> GetMods();
List<IModData> GetMods();
}
}
1 change: 1 addition & 0 deletions OWML.Common/IModManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public interface IModManifest
Dictionary<string, string> AppIds { get; }
string[] Dependencies { get; }
bool PriorityLoad { get; }
bool RequireVR { get; }
}
}
9 changes: 9 additions & 0 deletions OWML.Common/IModPlayerEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace OWML.Common
{
public interface IModPlayerEvents
{
event Action<PlayerBody> OnPlayerAwake;
}
}
10 changes: 10 additions & 0 deletions OWML.Common/IModSceneEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace OWML.Common
{
public interface IModSceneEvents
{
event Action<OWScene, OWScene> OnStartSceneChange;
event Action<OWScene, OWScene> OnCompleteSceneChange;
}
}
4 changes: 1 addition & 3 deletions OWML.Common/IOwmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public interface IOwmlConfig
string DataPath { get; }
string OWMLPath { get; set; }
string ModsPath { get; }
string OutputFilePath { get; }
string LogFilePath { get; }
bool Verbose { get; set; }
bool BlockInput { get; set; }
int SocketPort { get; set; }
}
}
3 changes: 2 additions & 1 deletion OWML.Common/Menus/IModConfigMenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public interface IModConfigMenuBase : IModPopupMenu
IModManifest Manifest { get; }

void Initialize(Menu modMenuCopy, IModToggleInput toggleTemplate, IModSliderInput sliderTemplate,
IModTextInput textInputTemplate, IModNumberInput numberInputTemplate, IModComboInput comboInputTemplate);
IModTextInput textInputTemplate, IModNumberInput numberInputTemplate,
IModComboInput comboInputTemplate, IModSelectorInput selectorTemplate);
}
}
10 changes: 10 additions & 0 deletions OWML.Common/Menus/IModMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public interface IModMenu
IModSliderInput AddSliderInput(IModSliderInput input);
IModSliderInput AddSliderInput(IModSliderInput input, int index);

List<IModSelectorInput> SelectorInputs { get; }
IModSelectorInput GetSelectorInput(string title);
IModSelectorInput AddSelectorInput(IModSelectorInput input);
IModSelectorInput AddSelectorInput(IModSelectorInput input, int index);

List<IModTextInput> TextInputs { get; }
IModTextInput GetTextInput(string title);
IModTextInput AddTextInput(IModTextInput input);
Expand All @@ -45,6 +50,11 @@ public interface IModMenu
IModNumberInput AddNumberInput(IModNumberInput input);
IModNumberInput AddNumberInput(IModNumberInput input, int index);

List<IModSeparator> Separators { get; }
IModSeparator AddSeparator(IModSeparator separator);
IModSeparator AddSeparator(IModSeparator separator, int index);
IModSeparator GetSeparator(string title);

object GetInputValue(string key);
void SetInputValue(string key, object value);

Expand Down
10 changes: 10 additions & 0 deletions OWML.Common/Menus/IModSelectorInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OWML.Common.Menus
{
public interface IModSelectorInput : IModInput<string>
{
int SelectedIndex { get; set; }
void Initialize(string option, string[] options);
IModSelectorInput Copy();
IModSelectorInput Copy(string title);
}
}
12 changes: 12 additions & 0 deletions OWML.Common/Menus/IModSeparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine.UI;

namespace OWML.Common.Menus
{
public interface IModSeparator : IModInputBase
{
LayoutElement LayoutElement { get; }

IModSeparator Copy();
IModSeparator Copy(string title);
}
}
1 change: 1 addition & 0 deletions OWML.Common/Menus/IModSliderInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public interface IModSliderInput : IModInput<float>
{
float Min { get; set; }
float Max { get; set; }
bool HasValueText { get; }

IModSliderInput Copy();
IModSliderInput Copy(string title);
Expand Down
12 changes: 12 additions & 0 deletions OWML.Common/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace OWML.Common
{
public enum MessageType
{
Message = 0,
Error = 1,
Warning = 2,
Info = 3,
Success = 4,
Quit = 5
}
}
5 changes: 5 additions & 0 deletions OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<Compile Include="IModInputTextures.cs" />
<Compile Include="IModInputHandler.cs" />
<Compile Include="IModInteraction.cs" />
<Compile Include="IModPlayerEvents.cs" />
<Compile Include="IModSceneEvents.cs" />
<Compile Include="Menus\IModSeparator.cs" />
<Compile Include="Menus\IModInputBase.cs" />
<Compile Include="Menus\IModFieldInput.cs" />
<Compile Include="Menus\IModMenuWithSelectables.cs" />
Expand All @@ -54,6 +57,7 @@
<Compile Include="Menus\IModComboInput.cs" />
<Compile Include="Menus\IModOWMenu.cs" />
<Compile Include="Menus\IModPromptButton.cs" />
<Compile Include="Menus\IModSelectorInput.cs" />
<Compile Include="Menus\InputType.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="IModConfig.cs" />
Expand Down Expand Up @@ -82,6 +86,7 @@
<Compile Include="Menus\IModNumberInput.cs" />
<Compile Include="Menus\IModTextInput.cs" />
<Compile Include="Menus\IModToggleInput.cs" />
<Compile Include="MessageType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion OWML.GameFinder/CurrentPathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override string FindGamePath()
{
return Config.GamePath;
}
Writer.WriteLine($"Current game path is not valid: {Config.GamePath}");
Writer.WriteLine($"Current game path is not valid: {Config.GamePath}", MessageType.Error);
return null;
}

Expand Down
63 changes: 23 additions & 40 deletions OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,32 @@ public class App
private readonly IModManifest _owmlManifest;
private readonly IModConsole _writer;
private readonly IModFinder _modFinder;
private readonly OutputListener _listener;
private readonly PathFinder _pathFinder;
private readonly OWPatcher _owPatcher;
private readonly VRPatcher _vrPatcher;

public App(IOwmlConfig owmlConfig, IModManifest owmlManifest, IModConsole writer, IModFinder modFinder,
OutputListener listener, PathFinder pathFinder, OWPatcher owPatcher, VRPatcher vrPatcher)
PathFinder pathFinder, OWPatcher owPatcher, VRPatcher vrPatcher)
{
_owmlConfig = owmlConfig;
_owmlManifest = owmlManifest;
_writer = writer;
_modFinder = modFinder;
_listener = listener;
_pathFinder = pathFinder;
_owPatcher = owPatcher;
_vrPatcher = vrPatcher;
}

public void Run(string[] args)
{
_writer.WriteLine($"Started OWML v{_owmlManifest.Version}");
_writer.WriteLine("For detailed log, see Logs/OWML.Log.txt");
_writer.WriteLine($"Started OWML v{_owmlManifest.Version}", MessageType.Info);

LocateGamePath();

CopyGameFiles();

CreateLogsDirectory();

var hasPortArgument = CommandLineArguments.HasArgument(Constants.ConsolePortArgument);
if (!hasPortArgument)
{
ListenForOutput();
}

var mods = _modFinder.GetMods();

ShowModList(mods);
Expand All @@ -59,6 +50,7 @@ public void Run(string[] args)

StartGame(args);

var hasPortArgument = CommandLineArguments.HasArgument(Constants.ConsolePortArgument);
if (hasPortArgument)
{
ExitConsole();
Expand Down Expand Up @@ -88,22 +80,23 @@ private void CopyGameFiles()
_writer.WriteLine("Game files copied.");
}

private void ShowModList(IList<IModData> mods)
private void ShowModList(List<IModData> mods)
{
if (!mods.Any())
{
_writer.WriteLine("Warning: found no mods.");
_writer.WriteLine("Warning - No mods found.", MessageType.Warning);
return;
}
_writer.WriteLine("Found mods:");
foreach (var modData in mods)
{
var stateText = modData.Config.Enabled ? "" : "(disabled)";
_writer.WriteLine($"* {modData.Manifest.UniqueName} v{modData.Manifest.Version} {stateText}");
var stateText = modData.Enabled ? "" : "(disabled)";
var type = modData.Enabled ? MessageType.Message : MessageType.Warning;
_writer.WriteLine($"* {modData.Manifest.UniqueName} v{modData.Manifest.Version} {stateText}", type);

if (!string.IsNullOrEmpty(modData.Manifest.OWMLVersion) && !IsMadeForSameOwmlMajorVersion(modData.Manifest))
{
_writer.WriteLine($" Warning: made for old version of OWML: v{modData.Manifest.OWMLVersion}");
_writer.WriteLine($" Warning - Made for old version of OWML: v{modData.Manifest.OWMLVersion}", MessageType.Warning);
}
}
}
Expand All @@ -117,34 +110,15 @@ private bool IsMadeForSameOwmlMajorVersion(IModManifest manifest)
owmlVersionSplit[1] == modVersionSplit[1];
}

private void ListenForOutput()
private bool HasVrMod(List<IModData> mods)
{
_listener.OnOutput += OnOutput;
_listener.Start();
}

private void OnOutput(string s)
{
var lines = s.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
_writer.WriteLine(line);
if (line.EndsWith(Constants.QuitKeyPhrase))
{
ExitConsole();
}
}
}

private bool HasVrMod(IList<IModData> mods)
{
var vrMod = mods.FirstOrDefault(x => x.Config.RequireVR && x.Config.Enabled);
var vrMod = mods.FirstOrDefault(x => x.RequireVR && x.Config.Enabled);
var hasVrMod = vrMod != null;
_writer.WriteLine(hasVrMod ? $"{vrMod.Manifest.UniqueName} requires VR." : "No mods require VR.");
return hasVrMod;
}

private void PatchGame(IList<IModData> mods)
private void PatchGame(List<IModData> mods)
{
_owPatcher.PatchGame();

Expand All @@ -155,20 +129,29 @@ private void PatchGame(IList<IModData> mods)
}
catch (Exception ex)
{
_writer.WriteLine($"Error while applying VR patch: {ex}");
_writer.WriteLine($"Error while applying VR patch: {ex}", MessageType.Error);
}
}

private void StartGame(string[] args)
{
_writer.WriteLine("Starting game...");

if (args.Contains("-consolePort"))
{
var index = Array.IndexOf(args, "-consolePort");
var list = new List<string>(args);
list.RemoveRange(index, 2);
args = list.ToArray();
}

try
{
Process.Start($"{_owmlConfig.GamePath}/OuterWilds.exe", string.Join(" ", args));
}
catch (Exception ex)
{
_writer.WriteLine("Error while starting game: " + ex.Message);
_writer.WriteLine($"Error while starting game: {ex.Message}", MessageType.Error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions OWML.Launcher/OWML.DefaultConfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gamePath": "C:/Program Files/Epic Games/OuterWilds",
"verbose": true,
"combinationsBlockInput": false
"combinationsBlockInput": false,
"socketPort": 0
}
2 changes: 1 addition & 1 deletion OWML.Launcher/OWML.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="OutputListener.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SocketListener.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
Loading

0 comments on commit a6f88d3

Please sign in to comment.