(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -9,6 +9,7 @@ namespace Barotrauma.Networking
struct TempClient
{
public string Name;
public UInt16 NameID;
public UInt64 SteamID;
public byte ID;
public UInt16 CharacterID;
@@ -18,6 +18,22 @@ namespace Barotrauma.Networking
get { return true; }
}
private string name;
private UInt16 nameId = 0;
public string Name
{
get { return name; }
}
public void SetName(string value)
{
if (string.IsNullOrEmpty(value)) { return; }
name = value.Replace(":", "").Replace(";", "");
nameId++;
}
private ClientPeer clientPeer;
public ClientPeer ClientPeer { get { return clientPeer; } }
@@ -213,7 +229,7 @@ namespace Barotrauma.Networking
Hull.EditFire = false;
Hull.EditWater = false;
Name = newName;
SetName(newName);
entityEventManager = new ClientEntityEventManager(this);
@@ -221,7 +237,7 @@ namespace Barotrauma.Networking
fileReceiver.OnFinished += OnFileReceived;
fileReceiver.OnTransferFailed += OnTransferFailed;
characterInfo = new CharacterInfo(Character.HumanConfigFile, name, null)
characterInfo = new CharacterInfo(Character.HumanSpeciesName, name, null)
{
Job = null
};
@@ -311,6 +327,7 @@ namespace Barotrauma.Networking
translatedEndpoint = endpoint;
}
clientPeer.OnDisconnect = OnDisconnect;
clientPeer.OnDisconnectMessageReceived = HandleDisconnectMessage;
clientPeer.OnInitializationComplete = () =>
{
if (SteamManager.IsInitialized)
@@ -323,6 +340,8 @@ namespace Barotrauma.Networking
canStart = true;
connected = true;
VoipClient = new VoipClient(this, clientPeer);
if (Screen.Selected != GameMain.GameScreen)
{
GameMain.NetLobbyScreen.Select();
@@ -591,13 +610,17 @@ namespace Barotrauma.Networking
respawnManager.Update(deltaTime);
}
if (updateTimer > DateTime.Now) { return; }
SendIngameUpdate();
if (updateTimer <= DateTime.Now)
{
SendIngameUpdate();
}
}
else
{
if (updateTimer > DateTime.Now) { return; }
SendLobbyUpdate();
if (updateTimer <= DateTime.Now)
{
SendLobbyUpdate();
}
}
if (serverSettings.VoiceChatEnabled)
@@ -615,8 +638,11 @@ namespace Barotrauma.Networking
}
}
// Update current time
updateTimer = DateTime.Now + updateInterval;
if (updateTimer <= DateTime.Now)
{
// Update current time
updateTimer = DateTime.Now + updateInterval;
}
}
private CoroutineHandle startGameCoroutine;
@@ -641,6 +667,9 @@ namespace Barotrauma.Networking
{
errorMsg += "\nInner exception: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace;
}
#if DEBUG
DebugConsole.ThrowError("Error while reading an ingame update message from server.", e);
#endif
GameAnalyticsManager.AddErrorEventOnce("GameClient.ReadDataMessage:ReadIngameUpdate", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
throw;
}
@@ -671,10 +700,21 @@ namespace Barotrauma.Networking
IWriteMessage readyToStartMsg = new WriteOnlyMessage();
readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME);
MultiPlayerCampaign campaign = GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ?
GameMain.GameSession?.GameMode as MultiPlayerCampaign : null;
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
bool readyToStart =
GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) &&
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
bool readyToStart;
if (campaign == null)
{
readyToStart = GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) &&
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
}
else
{
readyToStart = !fileReceiver.ActiveTransfers.Any(c => c.FileType == FileTransferType.CampaignSave) &&
(campaign.LastSaveID == campaign.PendingSaveID);
}
readyToStartMsg.Write(readyToStart);
WriteCharacterInfo(readyToStartMsg);
@@ -741,18 +781,16 @@ namespace Barotrauma.Networking
}
}
private void OnDisconnect(string disconnectMsg)
{
HandleDisconnectMessage(disconnectMsg);
}
private void HandleDisconnectMessage(string disconnectMsg)
private void OnDisconnect()
{
if (SteamManager.IsInitialized)
{
SteamManager.Instance.User.ClearRichPresence();
}
}
private void HandleDisconnectMessage(string disconnectMsg)
{
disconnectMsg = disconnectMsg ?? "";
string[] splitMsg = disconnectMsg.Split('/');
@@ -910,9 +948,13 @@ namespace Barotrauma.Networking
private void ReadTraitorMessage(IReadMessage inc)
{
TraitorMessageType messageType = (TraitorMessageType)inc.ReadByte();
string missionIdentifier = inc.ReadString();
string message = inc.ReadString();
message = TextManager.GetServerMessage(message);
var missionPrefab = TraitorMissionPrefab.List.Find(t => t.Identifier == missionIdentifier);
Sprite icon = missionPrefab?.Icon;
switch(messageType) {
case TraitorMessageType.Objective:
var isTraitor = !string.IsNullOrEmpty(message);
@@ -932,7 +974,11 @@ namespace Barotrauma.Networking
DebugConsole.NewMessage(message);
break;
case TraitorMessageType.ServerMessageBox:
new GUIMessageBox("", message);
var msgBox = new GUIMessageBox("", message, new string[0], type: GUIMessageBox.Type.InGame, icon: icon);
if (msgBox.Icon != null)
{
msgBox.IconColor = missionPrefab.IconColor;
}
break;
case TraitorMessageType.Server:
default:
@@ -1137,6 +1183,12 @@ namespace Barotrauma.Networking
mirrorLevel: campaign.Map.CurrentLocation != campaign.Map.SelectedConnection.Locations[0]);
}
if (GameMain.GameSession.Submarine.IsFileCorrupted)
{
DebugConsole.ThrowError($"Failed to start a round. Could not load the submarine \"{GameMain.GameSession.Submarine.Name}\".");
yield return CoroutineStatus.Failure;
}
for (int i = 0; i < Submarine.MainSubs.Length; i++)
{
if (!loadSecondSub && i > 0) { break; }
@@ -1221,7 +1273,6 @@ namespace Barotrauma.Networking
private void ReadInitialUpdate(IReadMessage inc)
{
myID = inc.ReadByte();
VoipClient = new VoipClient(this, clientPeer);
UInt16 subListCount = inc.ReadUInt16();
serverSubmarines.Clear();
@@ -1229,16 +1280,14 @@ namespace Barotrauma.Networking
{
string subName = inc.ReadString();
string subHash = inc.ReadString();
bool requiredContentPackagesInstalled = inc.ReadBoolean();
var matchingSub = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash);
if (matchingSub != null)
{
serverSubmarines.Add(matchingSub);
}
else
{
serverSubmarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName) + ".sub", subHash, false));
}
var matchingSub =
Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash) ??
new Submarine(Path.Combine(Submarine.SavePath, subName) + ".sub", subHash, false);
matchingSub.RequiredContentPackagesInstalled = requiredContentPackagesInstalled;
serverSubmarines.Add(matchingSub);
}
GameMain.NetLobbyScreen.UpdateSubList(GameMain.NetLobbyScreen.SubList, serverSubmarines);
@@ -1265,6 +1314,7 @@ namespace Barotrauma.Networking
{
byte id = inc.ReadByte();
UInt64 steamId = inc.ReadUInt64();
UInt16 nameId = inc.ReadUInt16();
string name = inc.ReadString();
UInt16 characterID = inc.ReadUInt16();
bool muted = inc.ReadBoolean();
@@ -1274,6 +1324,7 @@ namespace Barotrauma.Networking
tempClients.Add(new TempClient
{
ID = id,
NameID = nameId,
SteamID = steamId,
Name = name,
CharacterID = characterID,
@@ -1301,6 +1352,7 @@ namespace Barotrauma.Networking
ConnectedClients.Add(existingClient);
GameMain.NetLobbyScreen.AddPlayer(existingClient);
}
existingClient.NameID = tc.NameID;
existingClient.Character = null;
existingClient.Muted = tc.Muted;
existingClient.AllowKicking = tc.AllowKicking;
@@ -1315,7 +1367,11 @@ namespace Barotrauma.Networking
if (existingClient.ID == myID)
{
existingClient.SetPermissions(permissions, permittedConsoleCommands);
name = tc.Name;
if (!NetIdUtils.IdMoreRecent(nameId, tc.NameID))
{
name = tc.Name;
nameId = tc.NameID;
}
if (GameMain.NetLobbyScreen.CharacterNameBox != null &&
!GameMain.NetLobbyScreen.CharacterNameBox.Selected)
{
@@ -1591,6 +1647,7 @@ namespace Barotrauma.Networking
outmsg.Write(GameMain.NetLobbyScreen.LastUpdateID);
outmsg.Write(ChatMessage.LastID);
outmsg.Write(LastClientListUpdateID);
outmsg.Write(nameId);
outmsg.Write(name);
var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
@@ -1795,6 +1852,7 @@ namespace Barotrauma.Networking
}
SaveUtil.LoadGame(GameMain.GameSession.SavePath, GameMain.GameSession);
GameMain.GameSession?.Submarine?.CheckSubsLeftBehind();
campaign.LastSaveID = campaign.PendingSaveID;
DebugConsole.Log("Campaign save received, save ID " + campaign.LastSaveID);
@@ -2123,7 +2181,15 @@ namespace Barotrauma.Networking
public bool SpectateClicked(GUIButton button, object userData)
{
if (button != null) button.Enabled = false;
MultiPlayerCampaign campaign =
GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ?
GameMain.GameSession?.GameMode as MultiPlayerCampaign : null;
if (campaign != null && campaign.LastSaveID < campaign.PendingSaveID)
{
new GUIMessageBox("", TextManager.Get("campaignfiletransferinprogress"));
return false;
}
if (button != null) { button.Enabled = false; }
IWriteMessage readyToStartMsg = new WriteOnlyMessage();
readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME);
@@ -7,12 +7,14 @@ namespace Barotrauma.Networking
abstract class ClientPeer
{
public delegate void MessageCallback(IReadMessage message);
public delegate void DisconnectCallback(string msg);
public delegate void DisconnectCallback();
public delegate void DisconnectMessageCallback(string message);
public delegate void PasswordCallback(int salt, int retries);
public delegate void InitializationCompleteCallback();
public MessageCallback OnMessageReceived;
public DisconnectCallback OnDisconnect;
public DisconnectMessageCallback OnDisconnectMessageReceived;
public PasswordCallback OnRequestPassword;
public InitializationCompleteCallback OnInitializationComplete;
@@ -136,6 +136,7 @@ namespace Barotrauma.Networking
case NetConnectionStatus.Disconnected:
string disconnectMsg = inc.ReadString();
Close(disconnectMsg);
OnDisconnectMessageReceived?.Invoke(disconnectMsg);
break;
}
}
@@ -227,7 +228,7 @@ namespace Barotrauma.Networking
netClient.Shutdown(msg ?? TextManager.Get("Disconnecting"));
netClient = null;
steamAuthTicket?.Cancel(); steamAuthTicket = null;
OnDisconnect?.Invoke(msg);
OnDisconnect?.Invoke();
}
public override void Send(IWriteMessage msg, DeliveryMethod deliveryMethod)
@@ -248,6 +249,13 @@ namespace Barotrauma.Networking
break;
}
#if DEBUG
netPeerConfiguration.SimulatedDuplicatesChance = GameMain.Client.SimulatedDuplicatesChance;
netPeerConfiguration.SimulatedMinimumLatency = GameMain.Client.SimulatedMinimumLatency;
netPeerConfiguration.SimulatedRandomLatency = GameMain.Client.SimulatedRandomLatency;
netPeerConfiguration.SimulatedLoss = GameMain.Client.SimulatedLoss;
#endif
NetOutgoingMessage lidgrenMsg = netClient.CreateMessage();
byte[] msgData = new byte[msg.LengthBytes];
msg.PrepareForSending(ref msgData, out bool isCompressed, out int length);
@@ -116,6 +116,7 @@ namespace Barotrauma.Networking
IReadMessage inc = new ReadOnlyMessage(data, false, 1, dataLength - 1, ServerConnection);
string msg = inc.ReadString();
Close(msg);
OnDisconnectMessageReceived?.Invoke(msg);
}
else
{
@@ -270,8 +271,27 @@ namespace Barotrauma.Networking
}
heartbeatTimer = 5.0;
bool successSend = SteamManager.Instance.Networking.SendP2PPacket(hostSteamId, buf, length + 4, sendType);
#if DEBUG
CoroutineManager.InvokeAfter(() =>
{
if (Rand.Range(0.0f, 1.0f) < GameMain.Client.SimulatedLoss && sendType != Facepunch.Steamworks.Networking.SendType.Reliable) { return; }
int count = Rand.Range(0.0f, 1.0f) < GameMain.Client.SimulatedDuplicatesChance ? 2 : 1;
for (int i = 0; i < count; i++)
{
Send(buf, length + 4, sendType);
}
},
GameMain.Client.SimulatedMinimumLatency + Rand.Range(0.0f, GameMain.Client.SimulatedRandomLatency));
#else
Send(buf, length + 4, sendType);
#endif
}
private void Send(byte[] buf, int length, Facepunch.Steamworks.Networking.SendType sendType)
{
bool successSend = SteamManager.Instance.Networking.SendP2PPacket(hostSteamId, buf, length + 4, sendType);
if (!successSend)
{
if (sendType != Facepunch.Steamworks.Networking.SendType.Reliable)
@@ -332,7 +352,7 @@ namespace Barotrauma.Networking
steamAuthTicket?.Cancel(); steamAuthTicket = null;
hostSteamId = 0;
OnDisconnect?.Invoke(msg);
OnDisconnect?.Invoke();
}
}
}
@@ -414,6 +414,7 @@ namespace Barotrauma.Networking
case NetConnectionStatus.Disconnected:
string disconnectMsg = inc.ReadString();
Close(disconnectMsg);
OnDisconnectMessageReceived?.Invoke(disconnectMsg);
break;
}
}
@@ -429,7 +430,7 @@ namespace Barotrauma.Networking
isActive = false;
for (int i=remotePeers.Count-1;i>=0;i--)
for (int i = remotePeers.Count - 1; i >= 0; i--)
{
DisconnectPeer(remotePeers[i], msg ?? DisconnectReason.ServerShutdown.ToString());
}
@@ -444,7 +445,7 @@ namespace Barotrauma.Networking
netClient.Shutdown(msg ?? TextManager.Get("Disconnecting"));
netClient = null;
OnDisconnect?.Invoke(msg);
OnDisconnect?.Invoke();
Steam.SteamManager.Instance.Networking.OnIncomingConnection = null;
Steam.SteamManager.Instance.Networking.OnP2PData = null;
@@ -478,6 +479,12 @@ namespace Barotrauma.Networking
lidgrenMsg.Write((UInt16)length);
lidgrenMsg.Write(msgData, 0, length);
#if DEBUG
netPeerConfiguration.SimulatedDuplicatesChance = GameMain.Client.SimulatedDuplicatesChance;
netPeerConfiguration.SimulatedMinimumLatency = GameMain.Client.SimulatedMinimumLatency;
netPeerConfiguration.SimulatedRandomLatency = GameMain.Client.SimulatedRandomLatency;
netPeerConfiguration.SimulatedLoss = GameMain.Client.SimulatedLoss;
#endif
NetSendResult result = netClient.SendMessage(lidgrenMsg, lidgrenDeliveryMethod);
if (result != NetSendResult.Queued && result != NetSendResult.Sent)
{
@@ -758,8 +758,14 @@ namespace Barotrauma.Networking
karmaSettingsBlocker = new GUIFrame(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform, Anchor.CenterLeft) { MaxSize = new Point(karmaSettingsList.Content.Rect.Width, int.MaxValue) },
style: "InnerFrame");
karmaPresetDD.SelectItem(KarmaPreset);
karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom";
GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content);
karmaPresetDD.OnSelected = (selected, obj) =>
{
string newKarmaPreset = obj as string;
if (newKarmaPreset == KarmaPreset) { return true; }
List<NetPropertyData> properties = netProperties.Values.ToList();
List<object> prevValues = new List<object>();
foreach (NetPropertyData prop in netProperties.Values)
@@ -772,7 +778,7 @@ namespace Barotrauma.Networking
GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset();
GameMain.NetworkMember?.KarmaManager?.Save();
}
KarmaPreset = obj as string;
KarmaPreset = newKarmaPreset;
GameMain.NetworkMember.KarmaManager.SelectPreset(KarmaPreset);
karmaSettingsList.Content.ClearChildren();
karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom";
@@ -783,7 +789,6 @@ namespace Barotrauma.Networking
}
return true;
};
karmaPresetDD.SelectItem(KarmaPreset);
AssignGUIComponent("KarmaPreset", karmaPresetDD);
karmaBox.OnSelected = (tb) =>
{
@@ -836,16 +841,16 @@ namespace Barotrauma.Networking
public bool ToggleSettingsFrame(GUIButton button, object obj)
{
if (settingsFrame == null)
{
CreateSettingsFrame();
}
else
{
if (KarmaPreset == "custom")
{
GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset();
GameMain.NetworkMember?.KarmaManager?.Save();
}
CreateSettingsFrame();
}
else
{
ClientAdminWrite(NetFlags.Properties);
foreach (NetPropertyData prop in netProperties.Values)
{
@@ -736,14 +736,14 @@ namespace Barotrauma.Steam
/// <summary>
/// Creates a copy of the specified workshop item in the staging folder and an editor that can be used to edit and update the item
/// </summary>
public static void CreateWorkshopItemStaging(Workshop.Item existingItem, out Workshop.Editor itemEditor, out ContentPackage contentPackage)
public static bool CreateWorkshopItemStaging(Workshop.Item existingItem, out Workshop.Editor itemEditor, out ContentPackage contentPackage)
{
if (!existingItem.Installed)
{
itemEditor = null;
contentPackage = null;
DebugConsole.ThrowError("Cannot edit the workshop item \"" + existingItem.Title + "\" because it has not been installed.");
return;
return false;
}
itemEditor = instance.client.Workshop.EditItem(existingItem.Id);
@@ -763,7 +763,7 @@ namespace Barotrauma.Steam
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { existingItem.Title, errorMsg }));
itemEditor = null;
contentPackage = null;
return;
return false;
}
}
@@ -773,7 +773,7 @@ namespace Barotrauma.Steam
if (contentPackage == null && tempContentPackage.GameVersion <= new Version(0, 9, 1, 0))
{
//try finding the content package in the lega
//try finding the content package from the non-legacy path
installedContentPackagePath = Path.GetFullPath(GetWorkshopItemContentPackagePath(tempContentPackage, legacy: false));
contentPackage = ContentPackage.List.Find(cp => Path.GetFullPath(cp.Path) == installedContentPackagePath);
}
@@ -792,8 +792,11 @@ namespace Barotrauma.Steam
contentPackage.Path = newPath;
itemEditor.Folder = newDir;
if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); }
if (File.Exists(newPath)) { File.Delete(newPath); }
File.Move(installedContentPackagePath, newPath);
if (Path.GetFullPath(newPath) != installedContentPackagePath)
{
if (File.Exists(newPath)) { File.Delete(newPath); }
File.Move(installedContentPackagePath, newPath);
}
//move all files inside the Mods folder
foreach (ContentFile cf in contentPackage.Files)
{
@@ -815,7 +818,7 @@ namespace Barotrauma.Steam
string errorMsg = TextManager.GetWithVariable("WorkshopErrorOnEnable", "[itemname]", TextManager.EnsureUTF8(existingItem.Title));
new GUIMessageBox(TextManager.Get("Error"), errorMsg);
DebugConsole.ThrowError(errorMsg, e);
return;
return false;
}
}
@@ -846,6 +849,7 @@ namespace Barotrauma.Steam
GameAnalyticsManager.AddErrorEventOnce("SteamManager.CreateWorkshopItemStaging:WriteAllBytesFailed" + previewImagePath,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg + "\n" + e.Message);
}
return true;
}
public static void StartPublishItem(ContentPackage contentPackage, Workshop.Editor item)
@@ -865,11 +869,9 @@ namespace Barotrauma.Steam
contentPackage.GameVersion = GameMain.Version;
contentPackage.Save(contentPackage.Path);
if (File.Exists(PreviewImageName)) { File.Delete(PreviewImageName); }
//move the preview image out of the staging folder, it does not need to be included in the folder sent to Workshop
File.Move(Path.GetFullPath(Path.Combine(item.Folder, PreviewImageName)), PreviewImageName);
item.PreviewImage = Path.GetFullPath(PreviewImageName);
string previewImagePath = Path.GetFullPath(Path.Combine(item.Folder, PreviewImageName));
item.PreviewImage = File.Exists(previewImagePath) ? previewImagePath : null;
CoroutineManager.StartCoroutine(PublishItem(item));
}
@@ -904,7 +906,7 @@ namespace Barotrauma.Steam
/// <summary>
/// Enables a workshop item by moving it to the game folder.
/// </summary>
public static bool EnableWorkShopItem(Workshop.Item item, bool allowFileOverwrite, out string errorMsg)
public static bool EnableWorkShopItem(Workshop.Item item, bool allowFileOverwrite, out string errorMsg, bool selectContentPackage = true)
{
if (!item.Installed)
{
@@ -959,19 +961,24 @@ namespace Barotrauma.Steam
}
newPackage.Save(newContentPackagePath);
ContentPackage.List.Add(newPackage);
if (newPackage.CorePackage)
if (selectContentPackage)
{
//if enabling a core package, disable all other core packages
GameMain.Config.SelectedContentPackages.RemoveWhere(cp => cp.CorePackage);
if (newPackage.CorePackage)
{
//if enabling a core package, disable all other core packages
GameMain.Config.SelectedContentPackages.RemoveAll(cp => cp.CorePackage);
}
GameMain.Config.SelectContentPackage(newPackage);
GameMain.Config.SaveNewPlayerConfig();
foreach (ContentFile cf in newPackage.Files)
{
if (cf.Type == ContentType.Submarine)
{
Submarine.RefreshSavedSub(cf.Path);
}
}
}
GameMain.Config.SelectedContentPackages.Add(newPackage);
GameMain.Config.SaveNewPlayerConfig();
if (newPackage.Files.Any(f => f.Type == ContentType.Submarine))
{
Submarine.RefreshSavedSubs();
}
errorMsg = "";
return true;
}
@@ -1166,7 +1173,8 @@ namespace Barotrauma.Steam
}
ContentPackage.List.RemoveAll(cp => System.IO.Path.GetFullPath(cp.Path) == System.IO.Path.GetFullPath(installedContentPackagePath));
GameMain.Config.SelectedContentPackages.RemoveWhere(cp => !ContentPackage.List.Contains(cp));
GameMain.Config.SelectedContentPackages.RemoveAll(cp => !ContentPackage.List.Contains(cp));
ContentPackage.SortContentPackages();
GameMain.Config.SaveNewPlayerConfig();
}
catch (Exception e)
@@ -1218,7 +1226,7 @@ namespace Barotrauma.Steam
{
metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
}
catch (ArgumentException e)
catch (ArgumentException)
{
string errorMessage = "Metadata file for the Workshop item \"" + item.Title +
"\" not found. Could not combine path (" + (item.Directory.FullName ?? "directory name empty") + ").";
@@ -1255,7 +1263,7 @@ namespace Barotrauma.Steam
public static bool CheckWorkshopItemUpToDate(Workshop.Item item)
{
if (!item.Installed) return false;
if (!item.Installed) { return false; }
string metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
if (!File.Exists(metaDataPath))
@@ -1274,6 +1282,22 @@ namespace Barotrauma.Steam
return item.Modified <= myPackage.InstallTime.Value;
}
public static bool CheckWorkshopItemSelected(Workshop.Item item)
{
if (!item.Installed) { return false; }
string metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
if (!File.Exists(metaDataPath))
{
DebugConsole.ThrowError("Metadata file for the Workshop item \"" + item.Title + "\" not found. The file may be corrupted.");
return false;
}
ContentPackage steamPackage = new ContentPackage(metaDataPath);
return GameMain.Config.SelectedContentPackages.Any(cp => cp.Name == steamPackage.Name);
}
public static bool AutoUpdateWorkshopItems()
{
if (instance == null || !instance.isInitialized) { return false; }
@@ -1290,8 +1314,9 @@ namespace Barotrauma.Steam
itemsUpdated = false;
foreach (var item in q.Items)
{
if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item))
try
{
if (!item.Installed || !CheckWorkshopItemEnabled(item) || CheckWorkshopItemUpToDate(item)) { continue; }
if (!UpdateWorkshopItem(item, out string errorMsg))
{
DebugConsole.ThrowError(errorMsg);
@@ -1305,6 +1330,16 @@ namespace Barotrauma.Steam
itemsUpdated = true;
}
}
catch (Exception e)
{
new GUIMessageBox(
TextManager.Get("Error"),
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, e.Message + ", " + e.TargetSite }));
GameAnalyticsManager.AddErrorEventOnce(
"SteamManager.AutoUpdateWorkshopItems:" + e.Message,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Failed to autoupdate workshop item \"" + item.Title + "\". " + e.Message + "\n" + e.StackTrace);
}
}
};
@@ -1328,8 +1363,9 @@ namespace Barotrauma.Steam
{
errorMsg = "";
if (!item.Installed) { return false; }
bool wasSelected = CheckWorkshopItemSelected(item);
if (!DisableWorkShopItem(item, out errorMsg)) { return false; }
if (!EnableWorkShopItem(item, allowFileOverwrite: false, errorMsg: out errorMsg)) { return false; }
if (!EnableWorkShopItem(item, allowFileOverwrite: false, errorMsg: out errorMsg, selectContentPackage: wasSelected)) { return false; }
return true;
}