Unstable v0.19.5.0
This commit is contained in:
@@ -70,7 +70,9 @@ namespace Barotrauma.Steam
|
||||
(ContentPackage Package, bool IsUpToDate)[] outOfDatePackages = await Task.WhenAll(determiningTasks);
|
||||
|
||||
return (await Task.WhenAll(outOfDatePackages.Where(p => !p.IsUpToDate)
|
||||
.Select(async p => await SteamManager.Workshop.GetItem(p.Package.SteamWorkshopId))))
|
||||
.Select(p => p.Package.UgcId)
|
||||
.OfType<SteamWorkshopId>()
|
||||
.Select(async id => await SteamManager.Workshop.GetItem(id.Value))))
|
||||
.Where(p => p.HasValue).Select(p => p ?? default).ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -102,7 +100,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
currentLobby?.SetData("contentpackage", string.Join(",", contentPackages.Select(cp => cp.Name)));
|
||||
currentLobby?.SetData("contentpackagehash", string.Join(",", contentPackages.Select(cp => cp.Hash.StringRepresentation)));
|
||||
currentLobby?.SetData("contentpackageid", string.Join(",", contentPackages.Select(cp => cp.SteamWorkshopId)));
|
||||
currentLobby?.SetData("contentpackageid", string.Join(",", contentPackages.Select(cp => cp.UgcId)));
|
||||
currentLobby?.SetData("modeselectionmode", serverSettings.ModeSelectionMode.ToString());
|
||||
currentLobby?.SetData("subselectionmode", serverSettings.SubSelectionMode.ToString());
|
||||
currentLobby?.SetData("voicechatenabled", serverSettings.VoiceChatEnabled.ToString());
|
||||
@@ -152,275 +150,5 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static bool GetServers(Action<ServerInfo> addToServerList, Action serverQueryFinished)
|
||||
{
|
||||
if (!IsInitialized) { return false; }
|
||||
|
||||
int doneTasks = 0;
|
||||
void taskDone()
|
||||
{
|
||||
doneTasks++;
|
||||
if (doneTasks >= 2)
|
||||
{
|
||||
serverQueryFinished?.Invoke();
|
||||
serverQueryFinished = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Steamworks.Dispatch.OnDebugCallback = (callbackType, contents, isServer) =>
|
||||
{
|
||||
DebugConsole.NewMessage($"{callbackType}: " + contents, Color.Yellow);
|
||||
};
|
||||
|
||||
TaskPool.Add("LobbyQueryRequest", LobbyQueryRequest(),
|
||||
(t) =>
|
||||
{
|
||||
Steamworks.Dispatch.OnDebugCallback = null;
|
||||
if (t.Status == TaskStatus.Faulted)
|
||||
{
|
||||
TaskPool.PrintTaskExceptions(t, "Failed to retrieve SteamP2P lobbies");
|
||||
taskDone();
|
||||
return;
|
||||
}
|
||||
var lobbies = ((Task<List<Steamworks.Data.Lobby>>)t).Result;
|
||||
if (lobbies != null)
|
||||
{
|
||||
foreach (var lobby in lobbies)
|
||||
{
|
||||
if (string.IsNullOrEmpty(lobby.GetData("name"))) { continue; }
|
||||
|
||||
ServerInfo serverInfo = new ServerInfo
|
||||
{
|
||||
ServerName = lobby.GetData("name"),
|
||||
Endpoint = new SteamP2PEndpoint(SteamId.Parse(lobby.GetData("lobbyowner")).Fallback(default(SteamId))),
|
||||
LobbyID = lobby.Id,
|
||||
RespondedToSteamQuery = true
|
||||
};
|
||||
bool.TryParse(lobby.GetData("haspassword"), out serverInfo.HasPassword);
|
||||
serverInfo.PlayerCount = int.TryParse(lobby.GetData("playercount"), out int playerCount) ? playerCount : 0;
|
||||
serverInfo.MaxPlayers = int.TryParse(lobby.GetData("maxplayernum"), out int maxPlayers) ? maxPlayers : 1;
|
||||
|
||||
AssignLobbyDataToServerInfo(lobby, serverInfo);
|
||||
|
||||
addToServerList(serverInfo);
|
||||
}
|
||||
}
|
||||
taskDone();
|
||||
});
|
||||
|
||||
Steamworks.ServerList.Internet serverQuery = new Steamworks.ServerList.Internet();
|
||||
void onServer(Steamworks.Data.ServerInfo info, bool responsive)
|
||||
{
|
||||
if (string.IsNullOrEmpty(info.Name)) { return; }
|
||||
|
||||
ServerInfo serverInfo = new ServerInfo
|
||||
{
|
||||
ServerName = info.Name,
|
||||
HasPassword = info.Passworded,
|
||||
Endpoint = new LidgrenEndpoint(info.Address, info.ConnectionPort),
|
||||
PlayerCount = info.Players,
|
||||
MaxPlayers = info.MaxPlayers,
|
||||
RespondedToSteamQuery = responsive
|
||||
};
|
||||
|
||||
if (responsive)
|
||||
{
|
||||
TaskPool.Add($"QueryServerRules (GetServers, {info.Name}, {info.Address})", info.QueryRulesAsync(),
|
||||
(t) =>
|
||||
{
|
||||
if (t.Status == TaskStatus.Faulted)
|
||||
{
|
||||
TaskPool.PrintTaskExceptions(t, "Failed to retrieve rules for " + info.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
var rules = ((Task<Dictionary<string, string>>)t).Result;
|
||||
AssignServerRulesToServerInfo(rules, serverInfo);
|
||||
|
||||
CrossThread.RequestExecutionOnMainThread(() =>
|
||||
{
|
||||
addToServerList(serverInfo);
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CrossThread.RequestExecutionOnMainThread(() =>
|
||||
{
|
||||
addToServerList(serverInfo);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
serverQuery.OnResponsiveServer += (info) => onServer(info, true);
|
||||
serverQuery.OnUnresponsiveServer += (info) => onServer(info, false);
|
||||
|
||||
TaskPool.Add("RunServerQuery", serverQuery.RunQueryAsync(),
|
||||
(t) =>
|
||||
{
|
||||
serverQuery.Dispose();
|
||||
taskDone();
|
||||
if (t.Status == TaskStatus.Faulted)
|
||||
{
|
||||
TaskPool.PrintTaskExceptions(t, "Failed to retrieve servers");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<List<Steamworks.Data.Lobby>> LobbyQueryRequest()
|
||||
{
|
||||
List<Steamworks.Data.Lobby> allLobbies = new List<Steamworks.Data.Lobby>();
|
||||
Steamworks.Data.LobbyQuery lobbyQuery = Steamworks.SteamMatchmaking.CreateLobbyQuery()
|
||||
.FilterDistanceWorldwide()
|
||||
.WithMaxResults(50);
|
||||
//steamworks seems to unable to retrieve more than 50
|
||||
//lobbies per request; to work around this, we'll make
|
||||
//up to 10 requests, asking to ignore all previous results
|
||||
//in each subsequent request
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Steamworks.Data.Lobby[] lobbies = await lobbyQuery.RequestAsync();
|
||||
if (lobbies == null) { break; }
|
||||
foreach (var l in lobbies)
|
||||
{
|
||||
lobbyQuery = lobbyQuery
|
||||
.WithoutKeyValue("lobbyowner", l.GetData("lobbyowner"));
|
||||
}
|
||||
allLobbies.AddRange(lobbies);
|
||||
}
|
||||
|
||||
//make sure all returned lobbies are distinct, don't want any duplicates here
|
||||
return allLobbies.Select(l => l.Id).Distinct().Select(i => allLobbies.Find(l => l.Id == i)).ToList();
|
||||
}
|
||||
|
||||
public static void AssignLobbyDataToServerInfo(Steamworks.Data.Lobby lobby, ServerInfo serverInfo)
|
||||
{
|
||||
serverInfo.OwnerVerified = true;
|
||||
|
||||
serverInfo.ServerMessage = lobby.GetData("message");
|
||||
serverInfo.GameVersion = lobby.GetData("version");
|
||||
|
||||
serverInfo.ContentPackageNames.AddRange(lobby.GetData("contentpackage").Split(','));
|
||||
serverInfo.ContentPackageHashes.AddRange(lobby.GetData("contentpackagehash").Split(','));
|
||||
|
||||
string workshopIdData = lobby.GetData("contentpackageid");
|
||||
if (!string.IsNullOrEmpty(workshopIdData))
|
||||
{
|
||||
serverInfo.ContentPackageWorkshopIds.AddRange(ParseWorkshopIds(workshopIdData));
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] workshopUrls = lobby.GetData("contentpackageurl").Split(',');
|
||||
serverInfo.ContentPackageWorkshopIds.AddRange(WorkshopUrlsToIds(workshopUrls));
|
||||
}
|
||||
|
||||
if (Enum.TryParse(lobby.GetData("modeselectionmode"), out SelectionMode selectionMode)) { serverInfo.ModeSelectionMode = selectionMode; }
|
||||
if (Enum.TryParse(lobby.GetData("subselectionmode"), out selectionMode)) { serverInfo.SubSelectionMode = selectionMode; }
|
||||
|
||||
serverInfo.AllowSpectating = getLobbyBool("allowspectating");
|
||||
serverInfo.AllowRespawn = getLobbyBool("allowrespawn");
|
||||
serverInfo.VoipEnabled = getLobbyBool("voicechatenabled");
|
||||
serverInfo.KarmaEnabled = getLobbyBool("karmaenabled");
|
||||
serverInfo.FriendlyFireEnabled = getLobbyBool("friendlyfireenabled");
|
||||
if (Enum.TryParse(lobby.GetData("traitors"), out YesNoMaybe traitorsEnabled)) { serverInfo.TraitorsEnabled = traitorsEnabled; }
|
||||
|
||||
serverInfo.GameStarted = lobby.GetData("gamestarted") == "True";
|
||||
serverInfo.GameMode = (lobby.GetData("gamemode") ?? "").ToIdentifier();
|
||||
if (Enum.TryParse(lobby.GetData("playstyle"), out PlayStyle playStyle)) serverInfo.PlayStyle = playStyle;
|
||||
|
||||
if (serverInfo.ContentPackageNames.Count != serverInfo.ContentPackageHashes.Count ||
|
||||
serverInfo.ContentPackageHashes.Count != serverInfo.ContentPackageWorkshopIds.Count)
|
||||
{
|
||||
//invalid contentpackage info
|
||||
serverInfo.ContentPackageNames.Clear();
|
||||
serverInfo.ContentPackageHashes.Clear();
|
||||
serverInfo.ContentPackageWorkshopIds.Clear();
|
||||
}
|
||||
|
||||
string pingLocation = lobby.GetData("pinglocation");
|
||||
if (!string.IsNullOrEmpty(pingLocation))
|
||||
{
|
||||
serverInfo.PingLocation = Steamworks.Data.NetPingLocation.TryParseFromString(pingLocation);
|
||||
}
|
||||
|
||||
bool? getLobbyBool(string key)
|
||||
{
|
||||
string data = lobby.GetData(key);
|
||||
if (string.IsNullOrEmpty(data)) { return null; }
|
||||
return data == "True" || data == "true";
|
||||
}
|
||||
}
|
||||
|
||||
public static void AssignServerRulesToServerInfo(Dictionary<string, string> rules, ServerInfo serverInfo)
|
||||
{
|
||||
serverInfo.OwnerVerified = true;
|
||||
|
||||
if (rules == null) { return; }
|
||||
|
||||
if (rules.ContainsKey("message")) { serverInfo.ServerMessage = rules["message"]; }
|
||||
if (rules.ContainsKey("version")) { serverInfo.GameVersion = rules["version"]; }
|
||||
|
||||
if (rules.ContainsKey("playercount"))
|
||||
{
|
||||
if (int.TryParse(rules["playercount"], out int playerCount)) { serverInfo.PlayerCount = playerCount; }
|
||||
}
|
||||
|
||||
serverInfo.ContentPackageNames.Clear();
|
||||
serverInfo.ContentPackageHashes.Clear();
|
||||
serverInfo.ContentPackageWorkshopIds.Clear();
|
||||
if (rules.ContainsKey("contentpackage")) { serverInfo.ContentPackageNames.AddRange(rules["contentpackage"].Split(',')); }
|
||||
if (rules.ContainsKey("contentpackagehash")) { serverInfo.ContentPackageHashes.AddRange(rules["contentpackagehash"].Split(',')); }
|
||||
if (rules.ContainsKey("contentpackageid"))
|
||||
{
|
||||
serverInfo.ContentPackageWorkshopIds.AddRange(ParseWorkshopIds(rules["contentpackageid"]));
|
||||
}
|
||||
else if (rules.ContainsKey("contentpackageurl"))
|
||||
{
|
||||
string[] workshopUrls = rules["contentpackageurl"].Split(',');
|
||||
serverInfo.ContentPackageWorkshopIds.AddRange(WorkshopUrlsToIds(workshopUrls));
|
||||
}
|
||||
|
||||
if (rules.ContainsKey("modeselectionmode"))
|
||||
{
|
||||
if (Enum.TryParse(rules["modeselectionmode"], out SelectionMode selectionMode)) { serverInfo.ModeSelectionMode = selectionMode; }
|
||||
}
|
||||
if (rules.ContainsKey("subselectionmode"))
|
||||
{
|
||||
if (Enum.TryParse(rules["subselectionmode"], out SelectionMode selectionMode)) { serverInfo.SubSelectionMode = selectionMode; }
|
||||
}
|
||||
if (rules.ContainsKey("allowspectating")) { serverInfo.AllowSpectating = rules["allowspectating"] == "True"; }
|
||||
if (rules.ContainsKey("allowrespawn")) { serverInfo.AllowRespawn = rules["allowrespawn"] == "True"; }
|
||||
if (rules.ContainsKey("voicechatenabled")) { serverInfo.VoipEnabled = rules["voicechatenabled"] == "True"; }
|
||||
if (rules.ContainsKey("friendlyfireenabled")) { serverInfo.FriendlyFireEnabled = rules["friendlyfireenabled"] == "True"; }
|
||||
if (rules.ContainsKey("karmaenabled")) { serverInfo.KarmaEnabled = rules["karmaenabled"] == "True"; }
|
||||
if (rules.ContainsKey("traitors"))
|
||||
{
|
||||
if (Enum.TryParse(rules["traitors"], out YesNoMaybe traitorsEnabled)) { serverInfo.TraitorsEnabled = traitorsEnabled; }
|
||||
}
|
||||
|
||||
if (rules.ContainsKey("gamestarted")) { serverInfo.GameStarted = rules["gamestarted"] == "True"; }
|
||||
if (rules.ContainsKey("gamemode"))
|
||||
{
|
||||
serverInfo.GameMode = rules["gamemode"].ToIdentifier();
|
||||
}
|
||||
if (rules.ContainsKey("playstyle") && Enum.TryParse(rules["playstyle"], out PlayStyle playStyle))
|
||||
{
|
||||
serverInfo.PlayStyle = playStyle;
|
||||
}
|
||||
|
||||
if (serverInfo.ContentPackageNames.Count != serverInfo.ContentPackageHashes.Count ||
|
||||
serverInfo.ContentPackageHashes.Count != serverInfo.ContentPackageWorkshopIds.Count)
|
||||
{
|
||||
//invalid contentpackage info
|
||||
serverInfo.ContentPackageNames.Clear();
|
||||
serverInfo.ContentPackageHashes.Clear();
|
||||
serverInfo.ContentPackageWorkshopIds.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace Barotrauma.Steam
|
||||
throw new Exception("Expected Workshop package");
|
||||
}
|
||||
|
||||
if (contentPackage.SteamWorkshopId == 0)
|
||||
if (!contentPackage.UgcId.TryUnwrap(out var ugcId) || !(ugcId is SteamWorkshopId workshopId))
|
||||
{
|
||||
throw new Exception($"Steam Workshop ID not set for {contentPackage.Name}");
|
||||
}
|
||||
@@ -210,7 +210,7 @@ namespace Barotrauma.Steam
|
||||
string newPath = $"{ContentPackage.LocalModsDir}/{sanitizedName}";
|
||||
if (File.Exists(newPath) || Directory.Exists(newPath))
|
||||
{
|
||||
newPath += $"_{contentPackage.SteamWorkshopId}";
|
||||
newPath += $"_{workshopId.Value}";
|
||||
}
|
||||
|
||||
if (File.Exists(newPath) || Directory.Exists(newPath))
|
||||
@@ -226,7 +226,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
RefreshLocalMods();
|
||||
|
||||
return ContentPackageManager.LocalPackages.FirstOrDefault(p => p.SteamWorkshopId == contentPackage.SteamWorkshopId);
|
||||
return ContentPackageManager.LocalPackages.FirstOrDefault(p => p.UgcId == contentPackage.UgcId);
|
||||
}
|
||||
|
||||
private struct InstallWaiter
|
||||
@@ -266,7 +266,10 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
NukeDownload(workshopItem);
|
||||
var toUninstall
|
||||
= ContentPackageManager.WorkshopPackages.Where(p => p.SteamWorkshopId == workshopItem.Id)
|
||||
= ContentPackageManager.WorkshopPackages.Where(p =>
|
||||
p.UgcId.TryUnwrap(out var ugcId)
|
||||
&& ugcId is SteamWorkshopId workshopId
|
||||
&& workshopId.Value == workshopItem.Id)
|
||||
.ToHashSet();
|
||||
toUninstall.Select(p => p.Dir).ForEach(d => Directory.Delete(d));
|
||||
CrossThread.RequestExecutionOnMainThread(() => ContentPackageManager.WorkshopPackages.Refresh());
|
||||
@@ -296,7 +299,10 @@ namespace Barotrauma.Steam
|
||||
return;
|
||||
}
|
||||
else if (CanBeInstalled(id)
|
||||
&& !ContentPackageManager.WorkshopPackages.Any(p => p.SteamWorkshopId == id)
|
||||
&& !ContentPackageManager.WorkshopPackages.Any(p =>
|
||||
p.UgcId.TryUnwrap(out var ugcId)
|
||||
&& ugcId is SteamWorkshopId workshopId
|
||||
&& workshopId.Value == id)
|
||||
&& !InstallTaskCounter.IsInstalling(id))
|
||||
{
|
||||
TaskPool.Add($"InstallItem{id}", InstallMod(id), t => InstallWaiter.StopWaiting(id));
|
||||
|
||||
+20
-6
@@ -35,7 +35,12 @@ namespace Barotrauma.Steam
|
||||
memSubscribedModCount = numSubscribedMods;
|
||||
|
||||
var subscribedIds = SteamManager.GetSubscribedItems().ToHashSet();
|
||||
var installedIds = ContentPackageManager.WorkshopPackages.Select(p => p.SteamWorkshopId).ToHashSet();
|
||||
var installedIds = ContentPackageManager.WorkshopPackages
|
||||
.Select(p => p.UgcId)
|
||||
.NotNone()
|
||||
.OfType<SteamWorkshopId>()
|
||||
.Select(id => id.Value)
|
||||
.ToHashSet();
|
||||
foreach (var id in subscribedIds.Where(id2 => !installedIds.Contains(id2)))
|
||||
{
|
||||
Steamworks.Ugc.Item item = new Steamworks.Ugc.Item(id);
|
||||
@@ -514,7 +519,9 @@ namespace Barotrauma.Steam
|
||||
|
||||
private void PrepareToShowModInfo(ContentPackage mod)
|
||||
{
|
||||
TaskPool.Add($"PrepareToShow{mod.SteamWorkshopId}Info", SteamManager.Workshop.GetItem(mod.SteamWorkshopId),
|
||||
if (!mod.UgcId.TryUnwrap(out var ugcId)
|
||||
|| !(ugcId is SteamWorkshopId workshopId)) { return; }
|
||||
TaskPool.Add($"PrepareToShow{mod.UgcId}Info", SteamManager.Workshop.GetItem(workshopId.Value),
|
||||
t =>
|
||||
{
|
||||
if (!t.TryGetResult(out Steamworks.Ugc.Item? item)) { return; }
|
||||
@@ -592,7 +599,12 @@ namespace Barotrauma.Steam
|
||||
isEnabled: true,
|
||||
onSelected: () =>
|
||||
{
|
||||
TaskPool.AddIfNotFound($"UnsubFromSelected", Task.WhenAll(selectedMods.Select(m => SteamManager.Workshop.GetItem(m.SteamWorkshopId))),
|
||||
var workshopIds = selectedMods
|
||||
.Select(m => m.UgcId)
|
||||
.NotNone()
|
||||
.OfType<SteamWorkshopId>()
|
||||
.Select(id => id.Value);
|
||||
TaskPool.AddIfNotFound($"UnsubFromSelected", Task.WhenAll(workshopIds.Select(SteamManager.Workshop.GetItem)),
|
||||
t =>
|
||||
{
|
||||
if (!t.TryGetResult(out Steamworks.Ugc.Item?[] items)) { return; }
|
||||
@@ -672,7 +684,7 @@ namespace Barotrauma.Steam
|
||||
infoButton.Enabled = false;
|
||||
}
|
||||
TaskPool.AddIfNotFound(
|
||||
$"DetermineUpdateRequired{mod.SteamWorkshopId}",
|
||||
$"DetermineUpdateRequired{mod.UgcId}",
|
||||
mod.IsUpToDate(),
|
||||
t =>
|
||||
{
|
||||
@@ -725,6 +737,8 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
var mod = child.UserData as RegularPackage;
|
||||
if (mod is null || !ContentPackageManager.WorkshopPackages.Contains(mod)) { continue; }
|
||||
if (!mod.UgcId.TryUnwrap(out var ugcId)) { continue; }
|
||||
if (!(ugcId is SteamWorkshopId workshopId)) { continue; }
|
||||
|
||||
var btn = child.GetChild<GUILayoutGroup>()?.GetAllChildren<GUIButton>().Last();
|
||||
if (btn is null) { continue; }
|
||||
@@ -732,11 +746,11 @@ namespace Barotrauma.Steam
|
||||
|
||||
btn.ApplyStyle(
|
||||
GUIStyle.GetComponentStyle(
|
||||
ids.Contains(mod.SteamWorkshopId)
|
||||
ids.Contains(workshopId.Value)
|
||||
? "WorkshopMenu.PublishedIcon"
|
||||
: "WorkshopMenu.DownloadedIcon"));
|
||||
btn.ToolTip = TextManager.Get(
|
||||
ids.Contains(mod.SteamWorkshopId)
|
||||
ids.Contains(workshopId.Value)
|
||||
? "PublishedWorkshopMod"
|
||||
: "DownloadedWorkshopMod");
|
||||
btn.HoverCursor = CursorState.Default;
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Barotrauma.Steam
|
||||
(Steamworks.Ugc.Item WorkshopItem, ContentPackage? LocalPackage)[] publishedItems = workshopItems
|
||||
.Select(item => (item,
|
||||
(ContentPackage?)ContentPackageManager.LocalPackages.FirstOrDefault(p
|
||||
=> p.SteamWorkshopId != 0 && p.SteamWorkshopId == item.Id)))
|
||||
=> p.TryExtractSteamWorkshopId(out var workshopId) && workshopId.Value == item.Id)))
|
||||
//Sort the pairs by last local edit time if available
|
||||
.OrderBy(t => t.Item2 == null)
|
||||
.ThenByDescending(t => t.Item2 is { } p ? getEditTime(p) : t.Item1.LatestUpdateTime)
|
||||
@@ -241,7 +241,9 @@ namespace Barotrauma.Steam
|
||||
|
||||
//Get mods that haven't been published and add them to the list
|
||||
var unpublishedMods = ContentPackageManager.LocalPackages
|
||||
.Where(p => p.SteamWorkshopId == 0 || !publishedItems.Any(item => item.WorkshopItem.Id == p.SteamWorkshopId))
|
||||
.Where(p =>
|
||||
!p.TryExtractSteamWorkshopId(out var workshopId)
|
||||
|| !publishedItems.Any(item => item.WorkshopItem.Id == workshopId.Value))
|
||||
.OrderByDescending(getEditTime).ToArray();
|
||||
|
||||
if (unpublishedMods.Any())
|
||||
@@ -556,7 +558,9 @@ namespace Barotrauma.Steam
|
||||
taskCancelSrc = taskCancelSrc.IsCancellationRequested ? new CancellationTokenSource() : taskCancelSrc;
|
||||
|
||||
var contentPackage
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(p =>
|
||||
p.TryExtractSteamWorkshopId(out var workshopId)
|
||||
&& workshopId.Value == workshopItem.Id);
|
||||
|
||||
var verticalLayout = new GUILayoutGroup(new RectTransform(Vector2.One, parentFrame.RectTransform));
|
||||
|
||||
@@ -619,7 +623,7 @@ namespace Barotrauma.Steam
|
||||
if (contentPackage != null)
|
||||
{
|
||||
TaskPool.AddIfNotFound(
|
||||
$"DetermineUpdateRequired{contentPackage.SteamWorkshopId}",
|
||||
$"DetermineUpdateRequired{contentPackage.UgcId}",
|
||||
contentPackage.IsUpToDate(),
|
||||
t =>
|
||||
{
|
||||
@@ -652,7 +656,9 @@ namespace Barotrauma.Steam
|
||||
|
||||
if (contentPackage != null
|
||||
&& !ContentPackageManager.WorkshopPackages.Contains(contentPackage)
|
||||
&& ContentPackageManager.WorkshopPackages.Any(p => p.SteamWorkshopId == workshopItem.Id))
|
||||
&& ContentPackageManager.WorkshopPackages.Any(p =>
|
||||
p.TryExtractSteamWorkshopId(out var workshopId)
|
||||
&& workshopId.Value == workshopItem.Id))
|
||||
{
|
||||
updateButton.Visible = false;
|
||||
}
|
||||
|
||||
+8
-10
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Steam;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -49,21 +50,18 @@ namespace Barotrauma
|
||||
case ModType.Workshop:
|
||||
{
|
||||
var id = element.GetAttributeUInt64("id", 0);
|
||||
var pkg = ContentPackageManager.WorkshopPackages.FirstOrDefault(p => p.SteamWorkshopId == id);
|
||||
if (id != 0 && pkg != null)
|
||||
{
|
||||
addPkg(pkg);
|
||||
}
|
||||
if (id == 0) { continue; }
|
||||
var pkg = ContentPackageManager.WorkshopPackages.FirstOrDefault(p =>
|
||||
p.TryExtractSteamWorkshopId(out var workshopId) && workshopId.Value == id);
|
||||
if (pkg != null) { addPkg(pkg); }
|
||||
}
|
||||
break;
|
||||
case ModType.Local:
|
||||
{
|
||||
var name = element.GetAttributeString("name", "");
|
||||
if (name.IsNullOrEmpty()) { continue; }
|
||||
var pkg = ContentPackageManager.LocalPackages.FirstOrDefault(p => p.NameMatches(name));
|
||||
if (!name.IsNullOrEmpty() && pkg != null)
|
||||
{
|
||||
addPkg(pkg);
|
||||
}
|
||||
if (pkg != null) { addPkg(pkg); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -115,7 +113,7 @@ namespace Barotrauma
|
||||
{
|
||||
case ModType.Workshop:
|
||||
pkgElem.SetAttributeValue("name", pkg.Name);
|
||||
pkgElem.SetAttributeValue("id", pkg.SteamWorkshopId.ToString());
|
||||
pkgElem.SetAttributeValue("id", pkg.UgcId.ToString());
|
||||
break;
|
||||
case ModType.Local:
|
||||
pkgElem.SetAttributeValue("name", pkg.Name);
|
||||
|
||||
@@ -95,6 +95,9 @@ namespace Barotrauma.Steam
|
||||
SelectTab(Tab.Publish);
|
||||
}
|
||||
|
||||
private static bool PackageMatchesItem(ContentPackage p, Steamworks.Ugc.Item workshopItem)
|
||||
=> p.TryExtractSteamWorkshopId(out var workshopId) && workshopId.Value == workshopItem.Id;
|
||||
|
||||
private void PopulatePublishTab(ItemOrPackage itemOrPackage, GUIFrame parentFrame)
|
||||
{
|
||||
ContentPackageManager.LocalPackages.Refresh();
|
||||
@@ -105,18 +108,19 @@ namespace Barotrauma.Steam
|
||||
childAnchor: Anchor.TopCenter);
|
||||
|
||||
Steamworks.Ugc.Item workshopItem = itemOrPackage.TryGet(out Steamworks.Ugc.Item item) ? item : default;
|
||||
|
||||
ContentPackage? localPackage = itemOrPackage.TryGet(out ContentPackage package)
|
||||
? package
|
||||
: ContentPackageManager.LocalPackages.FirstOrDefault(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
: ContentPackageManager.LocalPackages.FirstOrDefault(p => PackageMatchesItem(p, workshopItem));
|
||||
ContentPackage? workshopPackage
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(p => PackageMatchesItem(p, workshopItem));
|
||||
if (localPackage is null)
|
||||
{
|
||||
new GUIFrame(new RectTransform((1.0f, 0.15f), mainLayout.RectTransform), style: null);
|
||||
|
||||
//Local copy does not exist; check for Workshop copy
|
||||
bool workshopCopyExists =
|
||||
ContentPackageManager.WorkshopPackages.Any(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
ContentPackageManager.WorkshopPackages.Any(p => PackageMatchesItem(p, workshopItem));
|
||||
|
||||
new GUITextBlock(new RectTransform((0.7f, 0.4f), mainLayout.RectTransform),
|
||||
TextManager.Get(workshopCopyExists ? "LocalCopyRequired" : "ItemInstallRequired"),
|
||||
@@ -403,7 +407,7 @@ namespace Barotrauma.Steam
|
||||
private IEnumerable<CoroutineStatus> CreateLocalCopy(GUITextBlock currentStepText, Steamworks.Ugc.Item workshopItem, GUIFrame parentFrame)
|
||||
{
|
||||
ContentPackage? workshopCopy =
|
||||
ContentPackageManager.WorkshopPackages.FirstOrDefault(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
ContentPackageManager.WorkshopPackages.FirstOrDefault(p => PackageMatchesItem(p, workshopItem));
|
||||
if (workshopCopy is null)
|
||||
{
|
||||
if (!SteamManager.Workshop.CanBeInstalled(workshopItem))
|
||||
@@ -417,7 +421,7 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
ContentPackageManager.WorkshopPackages.Refresh();
|
||||
});
|
||||
while (!ContentPackageManager.WorkshopPackages.Any(p => p.SteamWorkshopId == workshopItem.Id))
|
||||
while (!ContentPackageManager.WorkshopPackages.Any(p => PackageMatchesItem(p, workshopItem)))
|
||||
{
|
||||
currentStepText.Text = SteamManager.Workshop.CanBeInstalled(workshopItem)
|
||||
? TextManager.Get("PublishPopupInstall")
|
||||
@@ -426,7 +430,7 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
|
||||
workshopCopy =
|
||||
ContentPackageManager.WorkshopPackages.First(p => p.SteamWorkshopId == workshopItem.Id);
|
||||
ContentPackageManager.WorkshopPackages.First(p => PackageMatchesItem(p, workshopItem));
|
||||
}
|
||||
|
||||
bool localCopyMade = false;
|
||||
@@ -480,7 +484,7 @@ namespace Barotrauma.Steam
|
||||
messageBox.Buttons[0].Enabled = false;
|
||||
Steamworks.Ugc.PublishResult? result = null;
|
||||
Exception? resultException = null;
|
||||
TaskPool.Add($"Publishing {localPackage.Name} ({localPackage.SteamWorkshopId})",
|
||||
TaskPool.Add($"Publishing {localPackage.Name} ({localPackage.UgcId})",
|
||||
editor.SubmitAsync(),
|
||||
t =>
|
||||
{
|
||||
@@ -496,6 +500,8 @@ namespace Barotrauma.Steam
|
||||
if (result is { Success: true })
|
||||
{
|
||||
var resultId = result.Value.FileId;
|
||||
bool packageMatchesResult(ContentPackage p)
|
||||
=> p.TryExtractSteamWorkshopId(out var workshopId) && workshopId.Value == resultId;
|
||||
Steamworks.Ugc.Item resultItem = new Steamworks.Ugc.Item(resultId);
|
||||
Task downloadTask = SteamManager.Workshop.ForceRedownload(resultItem);
|
||||
while (!resultItem.IsInstalled && !downloadTask.IsCompleted)
|
||||
@@ -511,7 +517,7 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
|
||||
ContentPackage? pkgToNuke
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(p => p.SteamWorkshopId == resultId);
|
||||
= ContentPackageManager.WorkshopPackages.FirstOrDefault(packageMatchesResult);
|
||||
if (pkgToNuke != null)
|
||||
{
|
||||
Directory.Delete(pkgToNuke.Dir, recursive: true);
|
||||
@@ -537,7 +543,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
var localModProject = new ModProject(localPackage)
|
||||
{
|
||||
SteamWorkshopId = resultId
|
||||
UgcId = Option<ContentPackageId>.Some(new SteamWorkshopId(resultId))
|
||||
};
|
||||
localModProject.DiscardHashAndInstallTime();
|
||||
localModProject.Save(localPackage.Path);
|
||||
|
||||
Reference in New Issue
Block a user