Unstable v0.19.5.0

This commit is contained in:
Juan Pablo Arce
2022-09-14 12:47:17 -03:00
parent 3f2c843247
commit 1fd2a51bbb
158 changed files with 5702 additions and 4813 deletions
@@ -40,7 +40,9 @@ namespace Barotrauma
}
catch
{
prefab.Dispose(); //clean up before rethrowing, since some prefab types might lock resources
//clean up before rethrowing, since some prefab types might lock resources
prefab.Dispose();
Prefabs.Remove(prefab);
throw;
}
}
@@ -29,25 +29,25 @@ namespace Barotrauma
public readonly ImmutableArray<string> AltNames;
public readonly string Path;
public string Dir => Barotrauma.IO.Path.GetDirectoryName(Path) ?? "";
public readonly UInt64 SteamWorkshopId;
public readonly Option<ContentPackageId> UgcId;
public readonly Version GameVersion;
public readonly string ModVersion;
public Md5Hash Hash { get; private set; }
public readonly DateTime? InstallTime;
public readonly Option<DateTime> InstallTime;
public ImmutableArray<ContentFile> Files { get; private set; }
public ImmutableArray<ContentFile.LoadError> Errors { get; private set; }
public async Task<bool> IsUpToDate()
{
if (SteamWorkshopId != 0 && InstallTime.HasValue)
{
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(SteamWorkshopId);
if (item is null) { return true; }
return item.Value.LatestUpdateTime <= InstallTime;
}
return true;
if (!UgcId.TryUnwrap(out var ugcId)) { return true; }
if (!(ugcId is SteamWorkshopId steamWorkshopId)) { return true; }
if (!InstallTime.TryUnwrap(out var installTime)) { return true; }
Steamworks.Ugc.Item? item = await SteamManager.Workshop.GetItem(steamWorkshopId.Value);
if (item is null) { return true; }
return item.Value.LatestUpdateTime <= installTime;
}
public int Index => ContentPackageManager.EnabledPackages.IndexOf(this);
@@ -66,18 +66,19 @@ namespace Barotrauma
AltNames = rootElement.GetAttributeStringArray("altnames", Array.Empty<string>())
.Select(n => n.Trim()).ToImmutableArray();
AssertCondition(!string.IsNullOrEmpty(Name), "Name is null or empty");
SteamWorkshopId = rootElement.GetAttributeUInt64("steamworkshopid", 0);
UInt64 steamWorkshopId = rootElement.GetAttributeUInt64("steamworkshopid", 0);
UgcId = steamWorkshopId != 0
? Option<ContentPackageId>.Some(new SteamWorkshopId(steamWorkshopId))
: Option<ContentPackageId>.None();
GameVersion = rootElement.GetAttributeVersion("gameversion", GameMain.Version);
ModVersion = rootElement.GetAttributeString("modversion", DefaultModVersion);
if (rootElement.Attribute("installtime") != null)
{
InstallTime = ToolBox.Epoch.ToDateTime(rootElement.GetAttributeUInt("installtime", 0));
}
else
{
InstallTime = null;
}
UInt64 installTimeUnix = rootElement.GetAttributeUInt64("installtime", 0);
InstallTime = installTimeUnix != 0
? Option<DateTime>.Some(ToolBox.Epoch.ToDateTime(installTimeUnix))
: Option<DateTime>.None();
var fileResults = rootElement.Elements()
.Select(e => ContentFile.CreateFromXElement(this, e))
@@ -0,0 +1,19 @@
#nullable enable
namespace Barotrauma
{
public abstract class ContentPackageId
{
public abstract string StringRepresentation { get; }
public override string ToString()
=> StringRepresentation;
public abstract override bool Equals(object? obj);
public abstract override int GetHashCode();
public static Option<ContentPackageId> Parse(string s)
=> ReflectionUtils.ParseDerived<ContentPackageId, string>(s);
}
}
@@ -0,0 +1,32 @@
#nullable enable
using System;
using System.Globalization;
namespace Barotrauma
{
sealed class SteamWorkshopId : ContentPackageId
{
public readonly UInt64 Value;
public SteamWorkshopId(UInt64 value)
{
Value = value;
}
private const string Prefix = "STEAM_WORKSHOP_";
public override string StringRepresentation => Value.ToString(CultureInfo.InvariantCulture);
public override bool Equals(object? obj)
=> obj is SteamWorkshopId otherWorkshopId && otherWorkshopId.Value == Value;
public override int GetHashCode() => Value.GetHashCode();
public new static Option<SteamWorkshopId> Parse(string s)
{
if (s.StartsWith(Prefix)) { s = s[Prefix.Length..]; }
if (!UInt64.TryParse(s, out var id) || id == 0) { return Option<SteamWorkshopId>.None(); }
return Option<SteamWorkshopId>.Some(new SteamWorkshopId(id));
}
}
}
@@ -181,7 +181,7 @@ namespace Barotrauma
{
if (Core != null && !ContentPackageManager.CorePackages.Contains(Core))
{
SetCore(ContentPackageManager.WorkshopPackages.Core.FirstOrDefault(p => p.SteamWorkshopId == Core.SteamWorkshopId) ??
SetCore(ContentPackageManager.WorkshopPackages.Core.FirstOrDefault(p => p.UgcId == Core.UgcId) ??
ContentPackageManager.CorePackages.First());
}
@@ -193,7 +193,7 @@ namespace Barotrauma
newRegular.Add(p);
}
else if (ContentPackageManager.WorkshopPackages.Regular.FirstOrDefault(p2
=> p2.SteamWorkshopId == p.SteamWorkshopId) is { } newP)
=> p2.UgcId == p.UgcId) is { } newP)
{
newRegular.Add(newP);
}
@@ -43,10 +43,10 @@ namespace Barotrauma
cachedValue = cachedValue
.Replace(ModDirStr, modPath, StringComparison.OrdinalIgnoreCase)
.Replace(string.Format(OtherModDirFmt, ContentPackage.Name), modPath, StringComparison.OrdinalIgnoreCase);
if (ContentPackage.SteamWorkshopId != 0)
if (ContentPackage.UgcId.TryUnwrap(out var ugcId))
{
cachedValue = cachedValue
.Replace(string.Format(OtherModDirFmt, ContentPackage.SteamWorkshopId.ToString(CultureInfo.InvariantCulture)), modPath, StringComparison.OrdinalIgnoreCase);
.Replace(string.Format(OtherModDirFmt, ugcId.StringRepresentation), modPath, StringComparison.OrdinalIgnoreCase);
}
}
var allPackages = ContentPackageManager.AllPackages;
@@ -55,9 +55,9 @@ namespace Barotrauma
#endif
foreach (Identifier otherModName in otherMods)
{
if (!UInt64.TryParse(otherModName.Value, out UInt64 workshopId)) { workshopId = 0; }
Option<ContentPackageId> ugcId = ContentPackageId.Parse(otherModName.Value);
ContentPackage? otherMod =
allPackages.FirstOrDefault(p => workshopId != 0 && p.SteamWorkshopId != 0 && workshopId == p.SteamWorkshopId)
allPackages.FirstOrDefault(p => ugcId == p.UgcId)
?? allPackages.FirstOrDefault(p => p.Name == otherModName)
?? allPackages.FirstOrDefault(p => p.NameMatches(otherModName))
?? throw new MissingContentPackageException(ContentPackage, otherModName.Value);