Skip to content

Commit

Permalink
[Fix] DLC not able to be removed from items.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwindalmir committed Feb 1, 2022
1 parent 7f6f8e6 commit 43a8ef6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
17 changes: 14 additions & 3 deletions WorkshopToolCommon/Uploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Uploader : IMod
{
readonly HashSet<string> m_ignoredExtensions = new HashSet<string>();
readonly HashSet<string> m_ignoredPaths = new HashSet<string>();
uint[] m_dlcs;
uint[] m_dlcs = null;
uint[] m_dlcsToAdd = null;
uint[] m_dlcsToRemove = null;
ulong[] m_deps;
ulong[] m_depsToAdd;
ulong[] m_depsToRemove;
Expand Down Expand Up @@ -337,6 +339,8 @@ public bool Publish()

// SE libraries don't support updating dependencies, so we have to do that separately
WorkshopHelper.PublishDependencies(m_modId, m_depsToAdd, m_depsToRemove);
// SE also doesn't support removing DLC items, so do that too
WorkshopHelper.PublishDLC(m_modId, m_dlcsToAdd, m_dlcsToRemove);
}
if (((IMod)this).ModId == 0 || !WorkshopHelper.PublishSuccess)
{
Expand Down Expand Up @@ -498,6 +502,7 @@ void ProcessDLCs(IEnumerable<uint> dlcs, IEnumerable<uint> add, IEnumerable<uint
{
// Remove ALL DLCS
depsToRemove.AddRange(existingDeps);
explicitDeps.Clear();
}
else if (existingDeps?.Count > 0)
{
Expand All @@ -507,11 +512,17 @@ void ProcessDLCs(IEnumerable<uint> dlcs, IEnumerable<uint> add, IEnumerable<uint
}
}

// Remove from add/remove list any dependencies that don't exist, or aren't configured to set
depsToAdd.RemoveAll(d => existingDeps.Contains(d) || explicitDeps?.Contains(d) == true);
// Remove from add list any that already exist
depsToAdd.RemoveAll(d => existingDeps.Contains(d));
// Remove from remove list any dependencies that don't exist, or aren't configured to set
depsToRemove.RemoveAll(d => !existingDeps.Contains(d) && !(explicitDeps?.Contains(d) == true));

// Add all explicit deps to the add list that don't already exist
depsToAdd.AddRange(explicitDeps.Except(existingDeps));

m_dlcs = existingDeps.Union(explicitDeps ?? new List<uint>()).Union(depsToAdd).Except(depsToRemove).Where(i => i != 0).Distinct().ToArray();
m_dlcsToAdd = depsToAdd.Distinct().ToArray();
m_dlcsToRemove = depsToRemove.Distinct().ToArray();
#endif
}

Expand Down
25 changes: 25 additions & 0 deletions WorkshopToolCommon/WorkshopHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static void PublishDependencies(ulong[] modId, ulong[] dependenciesToAdd,
dependenciesToAdd?.ForEach(id => Steamworks.SteamUGC.AddDependency((Steamworks.PublishedFileId_t)modId[0], (Steamworks.PublishedFileId_t)id));
}

public static void PublishDLC(ulong[] modId, uint[] dependenciesToAdd, uint[] dependenciesToRemove = null)
{
dependenciesToRemove?.ForEach(id => Steamworks.SteamUGC.RemoveAppDependency((Steamworks.PublishedFileId_t)modId[0], (Steamworks.AppId_t)id));
dependenciesToAdd?.ForEach(id => Steamworks.SteamUGC.AddAppDependency((Steamworks.PublishedFileId_t)modId[0], (Steamworks.AppId_t)id));
}
#if SE
public static void PublishDependencies(WorkshopId[] modId, ulong[] dependenciesToAdd, ulong[] dependenciesToRemove = null)
{
Expand All @@ -179,6 +184,26 @@ public static void PublishDependencies(WorkshopId[] modId, ulong[] dependenciesT
}
}
}

public static void PublishDLC(WorkshopId[] modId, uint[] dependenciesToAdd, uint[] dependenciesToRemove = null)
{
foreach (var item in modId)
{
if (item.ServiceName == "Steam")
{
dependenciesToRemove?.ForEach(id => Steamworks.SteamUGC.RemoveAppDependency((Steamworks.PublishedFileId_t)item.Id, (Steamworks.AppId_t)id));
dependenciesToAdd?.ForEach(id => Steamworks.SteamUGC.AddAppDependency((Steamworks.PublishedFileId_t)item.Id, (Steamworks.AppId_t)id));
}
else if (item.ServiceName == "mod.io")
{
throw new NotImplementedException("Setting mod DLC on mod.io is not implemented yet.");
}
else
{
throw new ArgumentOutOfRangeException(nameof(item.ServiceName), $"Unknown service: {item.ServiceName}");
}
}
}
#endif
#endregion Publishing

Expand Down

0 comments on commit 43a8ef6

Please sign in to comment.