Skip to content

Commit

Permalink
Merge pull request #549 from ow-mods/dev
Browse files Browse the repository at this point in the history
2.9.5
  • Loading branch information
misternebula authored Jul 29, 2023
2 parents 5d59545 + 7daa973 commit fad21f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "2.9.3",
"version": "2.9.4",
"minGameVersion": "1.1.13.393",
"maxGameVersion": "1.1.13.456"
}
22 changes: 21 additions & 1 deletion src/OWML.ModHelper.Interaction/InterfaceProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,27 @@ bool AreTypesMatching(Type targetType, Type proxyType, bool parameter)
if (typeA.IsGenericParameter != typeB.IsGenericParameter)
return false;

return typeA.IsGenericParameter ? typeA.GenericParameterPosition == typeB.GenericParameterPosition : typeA.IsAssignableFrom(typeB);
if (typeA.IsGenericParameter)
{
return typeA.GenericParameterPosition == typeB.GenericParameterPosition;
}

if (typeA.IsAssignableFrom(typeB))
return true;

if (!typeA.IsGenericType)
return false;

if (typeA.GetGenericArguments().Length != typeB.GetGenericArguments().Length)
return false;

for (var i = 0; i < typeA.GetGenericArguments().Length; i++)
{
if (typeA.GetGenericArguments()[i].GenericParameterPosition != typeB.GetGenericArguments()[i].GenericParameterPosition)
return false;
}

return true;
}

foreach (var proxyMethod in interfaceType.GetMethods())
Expand Down
4 changes: 2 additions & 2 deletions src/OWML.ModHelper/OWML.ModHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>9.0</LangVersion>
<PackageVersion>2.9.3</PackageVersion>
<PackageVersion>2.9.4</PackageVersion>
<PackageId>OWML</PackageId>
<Title>OWML</Title>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<Authors>Alek, Nebula, Raicuparta, TAImatem</Authors>
<Description>Mod loader and mod framework for Outer Wilds</Description>
<PackageTags>Outer Wilds</PackageTags>
Expand Down
17 changes: 7 additions & 10 deletions src/OWML.ModLoader/ModSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public IList<IModData> SortMods(IList<IModData> mods)
{
// #541 When detecting a cyclic mod dependency we give up on sorting mods at all
// When this happens because of a disabled mod it will potentially break the rest of the mods for no reason
var enabledMods = mods.Where(x => x.Enabled).ToList();
var enabledMods = mods.Where(x => x.Enabled).OrderBy(x => x.Manifest.UniqueName).ToList();

var modDict = new Dictionary<string, IModData>();
var set = new HashSet<Edge>();
var set = new List<Edge>();
var modList = enabledMods.Select(mod => mod.Manifest.UniqueName).ToList();

foreach (var mod in enabledMods)
Expand All @@ -30,7 +30,7 @@ public IList<IModData> SortMods(IList<IModData> mods)
}
modDict.Add(mod.Manifest.UniqueName, mod);

foreach (var dependency in mod.Manifest.Dependencies)
foreach (var dependency in mod.Manifest.Dependencies.OrderBy(x => x))
{
if (mod.Manifest.PriorityLoad && !modList.Contains(dependency))
{
Expand All @@ -45,10 +45,7 @@ public IList<IModData> SortMods(IList<IModData> mods)
}
}

var sortedList = TopologicalSort(
new HashSet<string>(modList),
new HashSet<Edge>(set)
);
var sortedList = TopologicalSort(modList, set);

if (sortedList == null)
{
Expand All @@ -61,15 +58,15 @@ public IList<IModData> SortMods(IList<IModData> mods)
var sortedModData = sortedList.Where(modDict.ContainsKey).Select(mod => modDict[mod]).ToList();

// Include the disabled mods at the end of the list
return sortedModData.Union(mods.Where(x => !x.Enabled)).ToList();
return sortedModData.Union(mods.Where(x => !x.Enabled).OrderBy(x => x.Manifest.UniqueName)).ToList();
}

// Thanks to https://gist.github.com/Sup3rc4l1fr4g1l1571c3xp14l1d0c10u5/3341dba6a53d7171fe3397d13d00ee3f
private static List<string> TopologicalSort(HashSet<string> nodes, HashSet<Edge> edges)
private static List<string> TopologicalSort(List<string> nodes, List<Edge> edges)
{
var sortedList = new List<string>();

var nodesWithNoEdges = new HashSet<string>(nodes.Where(node => edges.All(edge => edge.Second.Equals(node) == false)));
var nodesWithNoEdges = nodes.Where(node => edges.All(edge => edge.Second.Equals(node) == false)).ToList();

while (nodesWithNoEdges.Any())
{
Expand Down

0 comments on commit fad21f0

Please sign in to comment.