Skip to content

Commit

Permalink
Merge pull request #475 from ow-mods/dev
Browse files Browse the repository at this point in the history
Dev -> master
  • Loading branch information
xen-42 authored Sep 18, 2022
2 parents 86de6f4 + 011d598 commit c7a0a2a
Show file tree
Hide file tree
Showing 32 changed files with 553 additions and 69 deletions.
2 changes: 1 addition & 1 deletion OWML.sln
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Global
{739D16FB-7848-4047-A173-500CE7C40399} = {C447A599-2700-44E1-BBFA-52880B7BFFBA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35;packages\Unity.2.1.505.0\lib\NET35
SolutionGuid = {0E767163-75F9-420A-80EB-320429543CAD}
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35;packages\Unity.2.1.505.0\lib\NET35
EndGlobalSection
EndGlobal
17 changes: 15 additions & 2 deletions schemas/manifest_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"minGameVersion": {
"type": "string",
"description": "The minimum version of the game that this mod is compatible with",
"pattern": "^\\d+\\.\\d+\\.\\d+$",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$",
"examples": [
"1.0.0",
"2.0.1",
Expand All @@ -101,13 +101,26 @@
"maxGameVersion": {
"type": "string",
"description": "The maximum version of the game that this mod is compatible with",
"pattern": "^\\d+\\.\\d+\\.\\d+$",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$",
"examples": [
"1.0.0",
"2.0.1",
"0.1.4"
]
},
"requireLatestVersion": {
"type": "boolean",
"description": "Whether this mod needs the very latest game version",
"default": false
},
"incompatibleVendors": {
"type": "array",
"description": "The vendors this mod does not work on",
"items": {
"type": "string",
"enum": ["Steam", "Epic", "Gamepass"]
}
},
"pathsToPreserve": {
"type": "array",
"description": "The paths to preserve when updating the mod",
Expand Down
2 changes: 2 additions & 0 deletions src/OWML.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class Constants
public const string ModDefaultConfigFileName = "default-config.json";

public const string ModManifestFileName = "manifest.json";

public const string GameVersionsFileName = "game-versions.json";
}
}
10 changes: 10 additions & 0 deletions src/OWML.Common/Enums/GameVendor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OWML.Common.Enums
{
public enum GameVendor
{
None,
Steam,
Epic,
Gamepass
}
}
17 changes: 17 additions & 0 deletions src/OWML.Common/GameVersions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;
using OWML.Common.Interfaces;

namespace OWML.Common
{
public class GameVersions : IGameVersions
{
[JsonProperty("steam")]
public string Steam { get; private set; }

[JsonProperty("epic")]
public string Epic { get; private set; }

[JsonProperty("gamepass")]
public string Gamepass { get; private set; }
}
}
9 changes: 9 additions & 0 deletions src/OWML.Common/Interfaces/IGameVendorGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OWML.Common.Enums;

namespace OWML.Common.Interfaces
{
public interface IGameVendorGetter
{
GameVendor GetGameVendor();
}
}
11 changes: 11 additions & 0 deletions src/OWML.Common/Interfaces/IGameVersions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OWML.Common.Interfaces
{
public interface IGameVersions
{
string Steam { get; }

string Epic { get; }

string Gamepass { get; }
}
}
8 changes: 7 additions & 1 deletion src/OWML.Common/Interfaces/IModManifest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace OWML.Common
using OWML.Common.Enums;

namespace OWML.Common
{
public interface IModManifest
{
Expand Down Expand Up @@ -29,5 +31,9 @@ public interface IModManifest
string MinGameVersion { get; }

string MaxGameVersion { get; }

bool RequireLatestVersion { get; }

GameVendor[] IncompatibleVendors { get; }
}
}
6 changes: 5 additions & 1 deletion src/OWML.Common/Interfaces/IModVersionChecker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace OWML.Common
using System;

namespace OWML.Common
{
public interface IModVersionChecker
{
bool CheckModVersion(IModData data);

bool CheckModGameVersion(IModData data, Version latestGameVersion);
}
}
7 changes: 7 additions & 0 deletions src/OWML.Common/ModManifest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OWML.Common.Enums;

namespace OWML.Common
{
Expand Down Expand Up @@ -45,5 +46,11 @@ public class ModManifest : IModManifest

[JsonProperty("maxGameVersion")]
public string MaxGameVersion { get; private set; } = "";

[JsonProperty("requireLatestVersion")]
public bool RequireLatestVersion { get; private set; }

[JsonProperty("incompatibleVendors")]
public GameVendor[] IncompatibleVendors { get; private set; } = { };
}
}
13 changes: 10 additions & 3 deletions src/OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void CopyGameFiles()
}
catch (Exception ex)
{
_writer.WriteLine($"Error while copying game file {fileName}: {ex.Message}");
_writer.WriteLine($"Error while copying game file {fileName}: {ex}");
}
}
_writer.WriteLine("Game files copied.");
Expand Down Expand Up @@ -153,7 +153,7 @@ private void ExecutePatcher(IModData modData)
}
catch (Exception ex)
{
_writer.WriteLine($"Cannot run patcher for mod {modData.Manifest.UniqueName} v{modData.Manifest.Version}: {ex.Message}", MessageType.Error);
_writer.WriteLine($"Cannot run patcher for mod {modData.Manifest.UniqueName} v{modData.Manifest.Version}: {ex}", MessageType.Error);
}
finally
{
Expand All @@ -172,6 +172,7 @@ void StartGameViaExe()

if (_owmlConfig.ForceExe)
{
_writer.WriteLine($"Launching game...");
StartGameViaExe();
return;
}
Expand Down Expand Up @@ -210,9 +211,15 @@ void StartGameViaExe()
StartGameViaExe();
}
}
catch (ReflectionTypeLoadException ex)
{
_writer.WriteLine($"ReflectionTypeLoadException while starting game: {ex}\n" +
"Top 5 LoaderExceptions:\n" +
$"* {string.Join("\n* ", ex.LoaderExceptions.Take(5).ToList().Select(e => e.ToString()).ToArray())}", MessageType.Error);
}
catch (Exception ex)
{
_writer.WriteLine($"Error while starting game: {ex.Message}", MessageType.Error);
_writer.WriteLine($"Error while starting game: {ex}", MessageType.Error);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/OWML.Launcher/OWML.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</ItemGroup>

<ItemGroup>
<None Update="game-versions.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="OWML.DefaultConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
3 changes: 2 additions & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "https://raw.githubusercontent.com/ow-mods/owml/dev/schemas/manifest_schema.json",
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "2.6.0",
"version": "2.7.0",
"minGameVersion": "1.1.10.47",
"maxGameVersion": "1.1.12.201"
}
2 changes: 1 addition & 1 deletion src/OWML.Launcher/SocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void ProcessMessage(byte[] bytes, int count)
catch (Exception ex)
{
ConsoleUtils.WriteByType(MessageType.Warning, $"Failed to process following message:{Separator}\n{json}{Separator}");
ConsoleUtils.WriteByType(MessageType.Warning, $"Reason: {ex.Message}");
ConsoleUtils.WriteByType(MessageType.Warning, $"Reason: {ex}");
continue;
}

Expand Down
5 changes: 5 additions & 0 deletions src/OWML.Launcher/game-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"steam": "1.1.12.201",
"epic": "1.1.12.168",
"gamepass": "1.1.12.181"
}
2 changes: 1 addition & 1 deletion src/OWML.Logging/ModSocketOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private string GetCallingType(StackTrace frame)
SenderName = Constants.OwmlTitle,
SenderType = nameof(ModSocketOutput),
Type = MessageType.Error,
Message = $"Error while getting calling type : {ex.Message}"
Message = $"Error while getting calling type : {ex}"
};
_socket.WriteToSocket(message);
return string.Empty;
Expand Down
9 changes: 2 additions & 7 deletions src/OWML.ModHelper.Menus/ModConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace OWML.ModHelper.Menus
{
public class ModConfigMenu : ModConfigMenuBase, IModConfigMenu
{
private const string EnabledTitle = "Enabled";

public IModData ModData { get; }

public IModBehaviour Mod { get; }
Expand All @@ -22,8 +20,7 @@ public ModConfigMenu(IModData modData, IModBehaviour mod, IModStorage storage, I

protected override void AddInputs()
{
var index = 2;
AddConfigInput(EnabledTitle, ModData.Config.Enabled, index++);
var index = 3;
foreach (var setting in ModData.Config.Settings)
{
AddConfigInput(setting.Key, setting.Value, index++);
Expand All @@ -34,7 +31,6 @@ protected override void AddInputs()

public override void UpdateUIValues()
{
GetToggleInput(EnabledTitle).Value = ModData.Config.Enabled;
foreach (var setting in ModData.Config.Settings)
{
SetInputValue(setting.Key, setting.Value);
Expand All @@ -43,7 +39,6 @@ public override void UpdateUIValues()

protected override void OnSave()
{
ModData.Config.Enabled = GetInputValue<bool>(EnabledTitle);
var keys = ModData.Config.Settings.Select(x => x.Key).ToList();
foreach (var key in keys)
{
Expand All @@ -62,7 +57,7 @@ protected override void OnSave()
}
catch (Exception e)
{
Console.WriteLine($"Exception thrown when changing settings for {Mod?.ModHelper?.Manifest?.UniqueName} : {e.Message}, {e.StackTrace}", MessageType.Error);
Console.WriteLine($"Exception thrown when changing settings for {Mod?.ModHelper?.Manifest?.UniqueName} : {e}", MessageType.Error);
}

Close();
Expand Down
1 change: 1 addition & 0 deletions src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ protected virtual void OnActivateMenu()
protected virtual void OnDeactivateMenu()
{
CommandListener.OnNewlyPressed -= OnButton;
OnSave();
}

protected virtual void OnButton(IInputCommands command)
Expand Down
48 changes: 38 additions & 10 deletions src/OWML.ModHelper.Menus/ModsMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using OWML.Common;
using OWML.Common.Menus;
Expand All @@ -16,6 +17,7 @@ public class ModsMenu : ModPopupMenu, IModsMenu

private readonly IModStorage _storage;
private readonly List<IModConfigMenu> _modConfigMenus = new();
private readonly List<IModData> _noConfigMods = new();
private readonly List<MenuOption> _menuOptions = new();
private IModMenus _menus;

Expand All @@ -31,7 +33,14 @@ public ModsMenu(

public void AddMod(IModData modData, IModBehaviour mod)
{
_modConfigMenus.Add(new ModConfigMenu(modData, mod, _storage, Console));
if (modData.Config.Settings.Count != 0)
{
_modConfigMenus.Add(new ModConfigMenu(modData, mod, _storage, Console));
}
else
{
_noConfigMods.Add(modData);
}
}

public IModConfigMenu GetModMenu(IModBehaviour modBehaviour)
Expand Down Expand Up @@ -64,6 +73,17 @@ public void Initialize(IModMenus menus, IModOWMenu owMenu)
OwmlMenu.OnClosed += modsMenu.Open;
}

private int CreateSeparator(IModTabbedMenu options, IModMenu menu, int index, string text)
{
var separator = new ModSeparator(menu)
{
Title = text
};
menu.AddSeparator(separator, index++);
separator.Element.transform.localScale = options.GameplayTab.Buttons.First().Button.transform.localScale;
return index;
}

private IModPopupMenu CreateModsMenu(IModTabbedMenu options)
{
_menuOptions.Clear();
Expand All @@ -76,9 +96,20 @@ private IModPopupMenu CreateModsMenu(IModTabbedMenu options)
owmlButton.OnClick += () => owmlTab.Open();

var enabledMods = _modConfigMenus.Where(modConfigMenu => modConfigMenu.ModData.Config.Enabled).ToList();
var index = CreateBlockOfButtons(options, modsTab, enabledMods, 1, "ENABLED MODS");
var index = CreateBlockOfButtons(options, modsTab, enabledMods, 1, "-- ENABLED MODS --");

foreach (var mod in _noConfigMods.Where(modData => modData.Config.Enabled))
{
index = CreateSeparator(options, modsTab, index, mod.Manifest.Name);
}

var disabledMods = _modConfigMenus.Except(enabledMods).ToList();
CreateBlockOfButtons(options, modsTab, disabledMods, index, "DISABLED MODS");
index = CreateBlockOfButtons(options, modsTab, disabledMods, index, "-- DISABLED MODS --");

foreach (var mod in _noConfigMods.Where(modData => !modData.Config.Enabled))
{
index = CreateSeparator(options, modsTab, index, mod.Manifest.Name);
}

modsTab.Menu.SetValue("_menuOptions", _menuOptions.ToArray());
return modsTab;
Expand All @@ -87,16 +118,13 @@ private IModPopupMenu CreateModsMenu(IModTabbedMenu options)
private int CreateBlockOfButtons(IModTabbedMenu options, IModTabMenu menu,
List<IModConfigMenu> configMenus, int index, string title)
{
index = CreateSeparator(options, menu, index, $"{Environment.NewLine}{title}{Environment.NewLine}");

if (configMenus.Count <= 0)
{
return index;
}
var separator = new ModSeparator(menu)
{
Title = title
};
menu.AddSeparator(separator, index++);
separator.Element.transform.localScale = options.GameplayTab.Buttons.First().Button.transform.localScale;

foreach (var modConfigMenu in configMenus)
{
var modButton = CreateButton(options, modConfigMenu.Manifest.Name);
Expand Down
Loading

0 comments on commit c7a0a2a

Please sign in to comment.