Skip to content

Commit

Permalink
Add support for Windows Store build (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
artumino authored Jan 6, 2022
1 parent d615a41 commit db68554
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.11.72" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.12.125" />
</ItemGroup>

</Project>
14 changes: 9 additions & 5 deletions src/OWML.Common/OwmlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json;

namespace OWML.Common
{
Expand All @@ -14,16 +15,19 @@ public class OwmlConfig : IOwmlConfig
public bool ForceExe { get; set; }

[JsonIgnore]
public string DataPath => $"{GamePath}/OuterWilds_Data";
public bool IsSpaced => Directory.Exists(Path.Combine(GamePath, "Outer Wilds_Data"));

[JsonIgnore]
public string ExePath => $"{GamePath}/OuterWilds.exe";
public string DataPath => Path.Combine(GamePath, IsSpaced ? "Outer Wilds_Data" : "OuterWilds_Data");

[JsonIgnore]
public string ManagedPath => $"{DataPath}/Managed";
public string ExePath => Path.Combine(GamePath, IsSpaced ? "Outer Wilds.exe" : "OuterWilds.exe");

[JsonIgnore]
public string PluginsPath => $"{DataPath}/Plugins";
public string ManagedPath => Path.Combine(DataPath, "Managed");

[JsonIgnore]
public string PluginsPath => Path.Combine(DataPath, "Plugins");

[JsonProperty("owmlPath")]
public string OWMLPath { get; set; }
Expand Down
15 changes: 12 additions & 3 deletions src/OWML.GameFinder/BaseFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace OWML.GameFinder
{
public abstract class BaseFinder
{
private const string ManagedPath = "OuterWilds_Data/Managed";
private readonly string ManagedPath = Path.Combine("OuterWilds_Data", "Managed");
private const string ExePath = "OuterWilds.exe";
private readonly string SpacedManagedPath = Path.Combine("Outer Wilds_Data", "Managed");
private const string SpacedExePath = "Outer Wilds.exe";

protected IOwmlConfig Config;
protected IModConsole Writer;
Expand All @@ -22,7 +24,14 @@ protected BaseFinder(IOwmlConfig config, IModConsole writer)
protected bool IsValidGamePath(string gamePath) =>
!string.IsNullOrEmpty(gamePath) &&
Directory.Exists(gamePath) &&
Directory.Exists($"{gamePath}/{ManagedPath}") &&
File.Exists($"{gamePath}/{ExePath}");
(HasGameFiles(gamePath) || HasSpacedGameFiles(gamePath));

private bool HasGameFiles(string gamePath) =>
Directory.Exists(Path.Combine(gamePath, ManagedPath)) &&
File.Exists(Path.Combine(gamePath, ExePath));

private bool HasSpacedGameFiles(string gamePath) =>
Directory.Exists(Path.Combine(gamePath, SpacedManagedPath)) &&
File.Exists(Path.Combine(gamePath, SpacedExePath));
}
}
1 change: 1 addition & 0 deletions src/OWML.GameFinder/PathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public string FindGamePath() =>
FindPathWith<CurrentPathFinder>() ??
FindPathWith<SteamGameFinder>() ??
FindPathWith<EpicGameFinder>() ??
FindPathWith<UWPGameFinder>() ??
FindPathWith<DefaultLocationFinder>() ??
FindPathWith<PromptGameFinder>();

Expand Down
42 changes: 42 additions & 0 deletions src/OWML.GameFinder/UWPGameFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Microsoft.Win32;
using OWML.Common;

namespace OWML.GameFinder
{
public class UWPGameFinder : BaseFinder
{
private const string RegistryPath = @"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages";

public UWPGameFinder(IOwmlConfig config, IModConsole writer)
: base(config, writer)
{
}

public override string FindGamePath()
{
var appPackages = Registry.CurrentUser.OpenSubKey(RegistryPath);

var gamePath = "";
foreach(var appPackageName in appPackages?.GetSubKeyNames())
{
var appPackageKey = appPackages.OpenSubKey(appPackageName);
var packageDisplayName = (string)appPackageKey.GetValue("DisplayName");

if(!String.IsNullOrEmpty(packageDisplayName) && packageDisplayName.Contains("Outer Wilds"))
{
gamePath = (string)appPackageKey.GetValue("PackageRootFolder");
break;
}
}

if (IsValidGamePath(gamePath))
{
return gamePath;
}

Writer.WriteLine("Game not found in UWP.");
return null;
}
}
}
4 changes: 2 additions & 2 deletions src/OWML.Patcher/OWPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void CopyFiles(string[] filesToCopy, string pathPrefix, string destinati
{
try
{
File.Copy($"{pathPrefix}{filename}", $"{destination}/{filename}", true);
File.Copy($"{pathPrefix}{filename}", Path.Combine(destination, filename), true);
}
catch
{
Expand All @@ -100,7 +100,7 @@ private void PatchAssembly()
{
_writer.WriteLine("Patching OW assembly...");

var patcher = new dnpatch.Patcher($"{_owmlConfig.ManagedPath}/Assembly-CSharp.dll");
var patcher = new dnpatch.Patcher(Path.Combine(_owmlConfig.ManagedPath, "Assembly-CSharp.dll"));

var target = new Target
{
Expand Down

0 comments on commit db68554

Please sign in to comment.