74086415fc
commit e08c5e722fdff38d408428d138919bb8ea90321b Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 11:13:25 2019 +0200 Changed default radio chat keybind to T. OemTilde works as an apostrophe on some keyboard layouts, making it difficult to type in chat messages without deselecting the chatbox. Closes #1044 commit e0ca9ffebe06b3f711b28a3ccfd486d84c47f9b0 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Tue Feb 5 11:03:14 2019 +0200 Fixed content package compatibility check. Closes #1059 commit f54bc180e8aef383cf9c893cd44c103840c066ac Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 10:48:03 2019 +0200 Remove the spacing from the crew selection listbox and disable focusing from the background. An alternative fix for #1039. commit d037815054ecc8269b0af3297700d2b98e1e5bc5 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Tue Feb 5 10:40:52 2019 +0200 Enforce vsync during the splash screen. Should fix the crashes due to insufficient memory mentioned in #1060. Does not fix the issue on releasing the used video resources. commit 90f1d8fe168356ba3c797c0c58fadea2aff57458 Author: ezjamsen <ezjames.fi@gmail.com> Date: Mon Feb 4 23:05:54 2019 +0200 small updates to subs commit 56dbdf6ea6e8e14035f943eb232eed7aa250f8f6 Author: ezjamsen <ezjames.fi@gmail.com> Date: Mon Feb 4 23:05:26 2019 +0200 adjusted default deterioration values on prefabs commit eaa4818cb63d52e1af519c8ca5c4f01f20143cb2 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 21:59:03 2019 +0200 Fixed servers occasionally starting the round multiple times when automatically starting the game via autorestart or clients being ready. Happened because "initiatedStartGame" (which prevents starting the round again) was not set until the InitiateStartGame coroutine is run for the first time, causing the automatic restart logic to run one extra time. Closes #1056 commit afd83b6ef40333a95e5eeec400d5f981cbdb1889 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 21:36:35 2019 +0200 Fixed some typos in affliction & mission descriptions. Closes #1057 commit feb97628582a9a22f0660a8ab2798f8e03fe8fc9 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 18:29:40 2019 +0200 Fixes to Level.TryGetInterestingPosition. Should fix monsters spawning very close to the sub in some levels (see #1054). - Ignore outposts when determining which positions are far enough from the sub. - If no position far enough from the sub is found, use the furthest one instead of choosing randomly. commit 62e5d7b229f334a5cf15cedf22e6795f18d637b9 Merge: 6ffc90da6 73f3dd060 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Mon Feb 4 18:03:44 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 6ffc90da69d9a5db146435054fdbb2cb18d855be Author: itchyOwl <lauri.harkanen@gmail.com> Date: Mon Feb 4 18:03:26 2019 +0200 Allow to focus on the crew selection listbox to enable scrolling when the mouse cursor is not over a content element, but is inside the listbox. Another option would be to remove the spacing from the listbox. Fixes #1039. commit 73f3dd060ef208199941cb74a72dcda6a7c15f41 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 18:00:57 2019 +0200 Fixed compiler error in GameServer.ClientWriteIngame commit 131263490c7093dd526a84757f4edd096a213a74 Merge: 637668488 9753e46a5 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 17:55:39 2019 +0200 Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev commit 637668488b27954afa0a8485eeaa3b23cf9461c5 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 17:55:01 2019 +0200 Changed character culling logic a bit. The characters need to be 22,000 units away from the players to be disabled, and won't be re-enabled until they're within 20,000 units. Using 20,000 as the threshold for both caused characters to be constantly toggled on/off when they're around the maximum distance, which caused ContactManager to constantly have to update contacts. commit 9753e46a5694b7b3c2bd0c4c006e2c1856c6eddb Author: itchyOwl <lauri.harkanen@gmail.com> Date: Mon Feb 4 17:54:35 2019 +0200 Add a debug command for adding more money in the compaign mode. commit f8a7179d6f8cb7c834b91b942722b1ae05417316 Author: itchyOwl <lauri.harkanen@gmail.com> Date: Mon Feb 4 17:53:03 2019 +0200 Always disallow zooming when the cursor is over a gui element. commit eefd956c50650be906acbd10662e24507e48cb83 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Feb 4 17:47:18 2019 +0200 Don't display outpost markers on the sonar (the ending and starting positions of the level are displayed, no need to show an additional marker on the "outpost submarine"). commit c7883bafc634e0ac2603bc96a87433da0c3481df Author: ezjamsen <ezjames.fi@gmail.com> Date: Mon Feb 4 17:21:50 2019 +0200 removed references to medical syringes
467 lines
15 KiB
C#
467 lines
15 KiB
C#
using Facepunch.Steamworks;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
public enum ContentType
|
|
{
|
|
None,
|
|
Submarine,
|
|
Jobs,
|
|
Item,
|
|
ItemAssembly,
|
|
Character,
|
|
Structure,
|
|
Outpost,
|
|
Text,
|
|
Executable,
|
|
ServerExecutable,
|
|
LocationTypes,
|
|
MapGenerationParameters,
|
|
LevelGenerationParameters,
|
|
LevelObjectPrefabs,
|
|
RandomEvents,
|
|
Missions,
|
|
BackgroundCreaturePrefabs,
|
|
Sounds,
|
|
RuinConfig,
|
|
Particles,
|
|
Decals,
|
|
NPCConversations,
|
|
Afflictions,
|
|
Tutorials,
|
|
UIStyle
|
|
}
|
|
|
|
public class ContentPackage
|
|
{
|
|
public static string Folder = "Data/ContentPackages/";
|
|
|
|
public static List<ContentPackage> List = new List<ContentPackage>();
|
|
|
|
//these types of files are included in the MD5 hash calculation,
|
|
//meaning that the players must have the exact same files to play together
|
|
private static HashSet<ContentType> multiplayerIncompatibleContent = new HashSet<ContentType>
|
|
{
|
|
ContentType.Jobs,
|
|
ContentType.Item,
|
|
ContentType.Character,
|
|
ContentType.Structure,
|
|
ContentType.LocationTypes,
|
|
ContentType.MapGenerationParameters,
|
|
ContentType.LevelGenerationParameters,
|
|
ContentType.Missions,
|
|
ContentType.LevelObjectPrefabs,
|
|
ContentType.RuinConfig,
|
|
ContentType.Outpost,
|
|
ContentType.Afflictions
|
|
};
|
|
|
|
//at least one file of each these types is required in core content packages
|
|
private static HashSet<ContentType> corePackageRequiredFiles = new HashSet<ContentType>
|
|
{
|
|
ContentType.Jobs,
|
|
ContentType.Item,
|
|
ContentType.Character,
|
|
ContentType.Structure,
|
|
ContentType.Outpost,
|
|
ContentType.Text,
|
|
ContentType.Executable,
|
|
ContentType.ServerExecutable,
|
|
ContentType.LocationTypes,
|
|
ContentType.MapGenerationParameters,
|
|
ContentType.LevelGenerationParameters,
|
|
ContentType.RandomEvents,
|
|
ContentType.Missions,
|
|
ContentType.BackgroundCreaturePrefabs,
|
|
ContentType.RuinConfig,
|
|
ContentType.NPCConversations,
|
|
ContentType.Afflictions,
|
|
ContentType.UIStyle
|
|
};
|
|
|
|
public static IEnumerable<ContentType> CorePackageRequiredFiles
|
|
{
|
|
get { return corePackageRequiredFiles; }
|
|
}
|
|
|
|
public string Name { get; set; }
|
|
|
|
public string Path
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public string SteamWorkshopUrl;
|
|
|
|
public bool HideInWorkshopMenu
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
private Md5Hash md5Hash;
|
|
public Md5Hash MD5hash
|
|
{
|
|
get
|
|
{
|
|
if (md5Hash == null) CalculateHash();
|
|
return md5Hash;
|
|
}
|
|
}
|
|
|
|
//core packages are content packages that are required for the game to work
|
|
//e.g. they include the executable, some location types, level generation params and other files the game won't work without
|
|
//one (and only one) core package must always be selected
|
|
public bool CorePackage
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
public Version GameVersion
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public List<ContentFile> Files;
|
|
|
|
public bool HasMultiplayerIncompatibleContent
|
|
{
|
|
get { return Files.Any(f => multiplayerIncompatibleContent.Contains(f.Type)); }
|
|
}
|
|
|
|
private ContentPackage()
|
|
{
|
|
Files = new List<ContentFile>();
|
|
}
|
|
|
|
public ContentPackage(string filePath, string setPath = "")
|
|
: this()
|
|
{
|
|
XDocument doc = XMLExtensions.TryLoadXml(filePath);
|
|
|
|
Path = setPath == string.Empty ? filePath : setPath;
|
|
|
|
if (doc?.Root == null)
|
|
{
|
|
DebugConsole.ThrowError("Couldn't load content package \"" + filePath + "\"!");
|
|
return;
|
|
}
|
|
|
|
Name = doc.Root.GetAttributeString("name", "");
|
|
HideInWorkshopMenu = doc.Root.GetAttributeBool("hideinworkshopmenu", false);
|
|
CorePackage = doc.Root.GetAttributeBool("corepackage", false);
|
|
SteamWorkshopUrl = doc.Root.GetAttributeString("steamworkshopurl", "");
|
|
GameVersion = new Version(doc.Root.GetAttributeString("gameversion", "0.0.0.0"));
|
|
|
|
List<string> errorMsgs = new List<string>();
|
|
foreach (XElement subElement in doc.Root.Elements())
|
|
{
|
|
if (!Enum.TryParse(subElement.Name.ToString(), true, out ContentType type))
|
|
{
|
|
errorMsgs.Add("Error in content package \"" + Name + "\" - \"" + subElement.Name.ToString() + "\" is not a valid content type.");
|
|
type = ContentType.None;
|
|
}
|
|
Files.Add(new ContentFile(subElement.GetAttributeString("file", ""), type));
|
|
}
|
|
|
|
bool compatible = IsCompatible();
|
|
//If we know that the package is not compatible, don't display error messages.
|
|
if (compatible)
|
|
{
|
|
foreach (string errorMsg in errorMsgs)
|
|
{
|
|
DebugConsole.ThrowError(errorMsg);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return Name;
|
|
}
|
|
|
|
public bool IsCompatible()
|
|
{
|
|
if (Files.All(f => f.Type == ContentType.Submarine))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//content package compatibility checks were added in 0.8.9.1
|
|
//v0.8.9.1 is not compatible with older content packages
|
|
if (GameVersion < new Version(0, 8, 9, 1))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//do additional checks here if later versions add changes that break compatibility
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool ContainsRequiredCorePackageFiles()
|
|
{
|
|
return corePackageRequiredFiles.All(fileType => Files.Any(file => file.Type == fileType));
|
|
}
|
|
public bool ContainsRequiredCorePackageFiles(out List<ContentType> missingContentTypes)
|
|
{
|
|
missingContentTypes = new List<ContentType>();
|
|
foreach (ContentType contentType in corePackageRequiredFiles)
|
|
{
|
|
if (!Files.Any(file => file.Type == contentType))
|
|
{
|
|
missingContentTypes.Add(contentType);
|
|
}
|
|
}
|
|
return missingContentTypes.Count == 0;
|
|
}
|
|
|
|
public static ContentPackage CreatePackage(string name, string path, bool corePackage)
|
|
{
|
|
ContentPackage newPackage = new ContentPackage()
|
|
{
|
|
Name = name,
|
|
Path = path,
|
|
CorePackage = corePackage,
|
|
GameVersion = GameMain.Version
|
|
};
|
|
|
|
return newPackage;
|
|
}
|
|
|
|
public ContentFile AddFile(string path, ContentType type)
|
|
{
|
|
if (Files.Find(file => file.Path == path && file.Type == type) != null) return null;
|
|
|
|
ContentFile cf = new ContentFile(path, type);
|
|
Files.Add(cf);
|
|
|
|
return cf;
|
|
}
|
|
|
|
public void RemoveFile(ContentFile file)
|
|
{
|
|
Files.Remove(file);
|
|
}
|
|
|
|
public void Save(string filePath)
|
|
{
|
|
XDocument doc = new XDocument();
|
|
doc.Add(new XElement("contentpackage",
|
|
new XAttribute("name", Name),
|
|
new XAttribute("path", Path),
|
|
new XAttribute("corepackage", CorePackage)));
|
|
|
|
|
|
doc.Root.Add(new XAttribute("gameversion", GameVersion.ToString()));
|
|
|
|
if (!string.IsNullOrEmpty(SteamWorkshopUrl))
|
|
{
|
|
doc.Root.Add(new XAttribute("steamworkshopurl", SteamWorkshopUrl));
|
|
}
|
|
|
|
foreach (ContentFile file in Files)
|
|
{
|
|
doc.Root.Add(new XElement(file.Type.ToString(), new XAttribute("file", file.Path)));
|
|
}
|
|
|
|
doc.Save(filePath);
|
|
}
|
|
|
|
public void CalculateHash(bool logging = false)
|
|
{
|
|
List<byte[]> hashes = new List<byte[]>();
|
|
|
|
if (logging)
|
|
{
|
|
DebugConsole.NewMessage("****************************** Calculating cp hash " + Name);
|
|
}
|
|
|
|
foreach (ContentFile file in Files)
|
|
{
|
|
if (!multiplayerIncompatibleContent.Contains(file.Type)) continue;
|
|
|
|
try
|
|
{
|
|
var hash = CalculateFileHash(file);
|
|
if (logging)
|
|
{
|
|
var fileMd5 = new Md5Hash(hash);
|
|
DebugConsole.NewMessage(" " + file.Path + ": " + fileMd5.ShortHash);
|
|
}
|
|
hashes.Add(hash);
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
DebugConsole.ThrowError("Error while calculating content package hash: ", e);
|
|
}
|
|
}
|
|
|
|
byte[] bytes = new byte[hashes.Count * 16];
|
|
for (int i = 0; i < hashes.Count; i++)
|
|
{
|
|
hashes[i].CopyTo(bytes, i * 16);
|
|
}
|
|
|
|
md5Hash = new Md5Hash(bytes);
|
|
if (logging)
|
|
{
|
|
DebugConsole.NewMessage("****************************** Package hash: " + md5Hash.ShortHash);
|
|
}
|
|
}
|
|
|
|
private byte[] CalculateFileHash(ContentFile file)
|
|
{
|
|
var md5 = MD5.Create();
|
|
|
|
List<string> filePaths = new List<string> { file.Path };
|
|
List<byte> data = new List<byte>();
|
|
|
|
switch (file.Type)
|
|
{
|
|
case ContentType.Character:
|
|
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
|
|
string speciesName = doc.Root.GetAttributeString("name", "");
|
|
filePaths.Add(RagdollParams.GetDefaultFile(speciesName));
|
|
foreach (AnimationType animationType in Enum.GetValues(typeof(AnimationType)))
|
|
{
|
|
filePaths.Add(AnimationParams.GetDefaultFile(speciesName, animationType));
|
|
}
|
|
break;
|
|
}
|
|
|
|
foreach (string filePath in filePaths)
|
|
{
|
|
if (!File.Exists(filePath)) continue;
|
|
using (var stream = File.OpenRead(filePath))
|
|
{
|
|
byte[] fileData = new byte[stream.Length];
|
|
stream.Read(fileData, 0, (int)stream.Length);
|
|
if (filePath.EndsWith(".xml", true, System.Globalization.CultureInfo.InvariantCulture))
|
|
{
|
|
string text = System.Text.Encoding.UTF8.GetString(fileData);
|
|
text = text.Replace("\n", "").Replace("\r", "");
|
|
fileData = System.Text.Encoding.UTF8.GetBytes(text);
|
|
}
|
|
data.AddRange(fileData);
|
|
}
|
|
}
|
|
return md5.ComputeHash(data.ToArray());
|
|
}
|
|
|
|
public static string GetFileExtension(ContentType contentType)
|
|
{
|
|
switch (contentType)
|
|
{
|
|
case ContentType.Executable:
|
|
case ContentType.ServerExecutable:
|
|
return ".exe";
|
|
default:
|
|
return ".xml";
|
|
}
|
|
}
|
|
|
|
public static bool IsModFilePathAllowed(ContentFile contentFile)
|
|
{
|
|
string path = contentFile.Path;
|
|
while (true)
|
|
{
|
|
string temp = System.IO.Path.GetDirectoryName(path);
|
|
if (string.IsNullOrEmpty(temp)) { break; }
|
|
path = temp;
|
|
}
|
|
switch (contentFile.Type)
|
|
{
|
|
case ContentType.Submarine:
|
|
return path == "Submarines";
|
|
default:
|
|
return path == "Mods";
|
|
}
|
|
}
|
|
public static bool IsModFilePathAllowed(string path)
|
|
{
|
|
while (true)
|
|
{
|
|
string temp = System.IO.Path.GetDirectoryName(path);
|
|
if (string.IsNullOrEmpty(temp)) { break; }
|
|
path = temp;
|
|
}
|
|
return path == "Mods";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all xml files.
|
|
/// </summary>
|
|
public static IEnumerable<string> GetAllContentFiles(IEnumerable<ContentPackage> contentPackages)
|
|
{
|
|
return contentPackages.SelectMany(f => f.Files).Select(f => f.Path).Where(p => p.EndsWith(".xml"));
|
|
}
|
|
|
|
public static IEnumerable<string> GetFilesOfType(IEnumerable<ContentPackage> contentPackages, ContentType type)
|
|
{
|
|
return contentPackages.SelectMany(f => f.Files).Where(f => f.Type == type).Select(f => f.Path);
|
|
}
|
|
|
|
public IEnumerable<string> GetFilesOfType(ContentType type)
|
|
{
|
|
return Files.Where(f => f.Type == type).Select(f => f.Path);
|
|
}
|
|
|
|
public static void LoadAll(string folder)
|
|
{
|
|
if (!Directory.Exists(folder))
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(folder);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
DebugConsole.ThrowError("Failed to create directory \"" + folder + "\"", e);
|
|
return;
|
|
}
|
|
}
|
|
|
|
string[] files = Directory.GetFiles(folder, "*.xml");
|
|
|
|
List.Clear();
|
|
|
|
foreach (string filePath in files)
|
|
{
|
|
ContentPackage package = new ContentPackage(filePath);
|
|
List.Add(package);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ContentFile
|
|
{
|
|
public readonly string Path;
|
|
public ContentType Type;
|
|
|
|
public Workshop.Item WorkShopItem;
|
|
|
|
public ContentFile(string path, ContentType type, Workshop.Item workShopItem = null)
|
|
{
|
|
Path = path;
|
|
Type = type;
|
|
WorkShopItem = workShopItem;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return Path;
|
|
}
|
|
}
|
|
|
|
}
|