v0.10.5.1
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Formerly System.Web.HttpUtility, now it just vaguely resembles it
|
||||
//
|
||||
// Authors:
|
||||
// Patrik Torstensson (Patrik.Torstensson@labs2.com)
|
||||
// Wictor Wilén (decode/encode functions) (wictor@ibizkit.se)
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||||
//
|
||||
// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public sealed class HttpUtility
|
||||
{
|
||||
public static Dictionary<string, string> ParseQueryString(string query)
|
||||
{
|
||||
Dictionary<string, string> collection = new Dictionary<string, string>();
|
||||
var splitGet = query.Split('?');
|
||||
if (splitGet.Length > 1)
|
||||
{
|
||||
var get = splitGet[1];
|
||||
foreach (string kvp in get.Split('&'))
|
||||
{
|
||||
var splitKeyValue = kvp.Split('=');
|
||||
if (splitKeyValue.Length > 1)
|
||||
{
|
||||
collection.Add(splitKeyValue[0], splitKeyValue[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Barotrauma
|
||||
{
|
||||
public static class IPExtensions
|
||||
{
|
||||
//TODO: remove?
|
||||
//workaround for .NET Framework 4.5 bug; presumably fixed in later versions
|
||||
//see https://stackoverflow.com/questions/23608829/why-does-ipaddress-maptoipv4-throw-argumentoutofrangeexception
|
||||
public static IPAddress MapToIPv4NoThrow(this IPAddress address)
|
||||
|
||||
@@ -288,8 +288,13 @@ namespace Barotrauma
|
||||
return (r >= 0 && r <= 1) && (s >= 0 && s <= 1);
|
||||
}
|
||||
|
||||
// a1 is line1 start, a2 is line1 end, b1 is line2 start, b2 is line2 end
|
||||
public static bool GetLineIntersection(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2, out Vector2 intersection)
|
||||
{
|
||||
return GetLineIntersection(a1, a2, b1, b2, false, out intersection);
|
||||
}
|
||||
|
||||
// a1 is line1 start, a2 is line1 end, b1 is line2 start, b2 is line2 end
|
||||
public static bool GetLineIntersection(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2, bool ignoreSegments, out Vector2 intersection)
|
||||
{
|
||||
intersection = Vector2.Zero;
|
||||
|
||||
@@ -302,10 +307,10 @@ namespace Barotrauma
|
||||
|
||||
Vector2 c = b1 - a1;
|
||||
float t = (c.X * d.Y - c.Y * d.X) / bDotDPerp;
|
||||
if (t < 0 || t > 1) return false;
|
||||
if ((t < 0 || t > 1) && !ignoreSegments) return false;
|
||||
|
||||
float u = (c.X * b.Y - c.Y * b.X) / bDotDPerp;
|
||||
if (u < 0 || u > 1) return false;
|
||||
if ((u < 0 || u > 1) && !ignoreSegments) return false;
|
||||
|
||||
intersection = a1 + t * b;
|
||||
return true;
|
||||
@@ -532,6 +537,21 @@ namespace Barotrauma
|
||||
Math.Sqrt(xDiff * xDiff + yDiff * yDiff));
|
||||
}
|
||||
|
||||
public static float LineToPointDistanceSquared(Vector2 lineA, Vector2 lineB, Vector2 point)
|
||||
{
|
||||
float xDiff = lineB.X - lineA.X;
|
||||
float yDiff = lineB.Y - lineA.Y;
|
||||
|
||||
if (xDiff == 0 && yDiff == 0)
|
||||
{
|
||||
return Vector2.DistanceSquared(lineA, point);
|
||||
}
|
||||
|
||||
float numerator = xDiff * (lineA.Y - point.Y) - yDiff * (lineA.X - point.X);
|
||||
return (numerator*numerator) /
|
||||
(xDiff * xDiff + yDiff * yDiff);
|
||||
}
|
||||
|
||||
public static bool CircleIntersectsRectangle(Vector2 circlePos, float radius, Rectangle rect)
|
||||
{
|
||||
int halfWidth = rect.Width / 2;
|
||||
|
||||
@@ -41,7 +41,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (System.Threading.Thread.CurrentThread.ManagedThreadId != ThreadId)
|
||||
{
|
||||
#if DEBUG
|
||||
throw new Exception("Unauthorized multithreaded access to RandSync.Server");
|
||||
#else
|
||||
DebugConsole.ThrowError("Unauthorized multithreaded access to RandSync.Server\n" + Environment.StackTrace);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public static class ReadOnlyListExtensions
|
||||
{
|
||||
public static int IndexOf<T>(this IReadOnlyList<T> list, T elem)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (list[i].Equals(elem)) { return i; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static T Find<T>(this IReadOnlyList<T> list, Func<T, bool> predicate)
|
||||
{
|
||||
return list.FirstOrDefault(predicate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -8,7 +7,9 @@ namespace Barotrauma.IO
|
||||
{
|
||||
static readonly string[] unwritableDirs = new string[] { "Content", "Data/ContentPackages" };
|
||||
|
||||
public static bool CanWrite(string path, bool canWarn = true)
|
||||
public static bool DevException;
|
||||
|
||||
public static bool CanWrite(string path)
|
||||
{
|
||||
path = System.IO.Path.GetFullPath(path).CleanUpPath();
|
||||
|
||||
@@ -19,11 +20,7 @@ namespace Barotrauma.IO
|
||||
if (path.StartsWith(dir, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
#if DEBUG
|
||||
if (canWarn)
|
||||
{
|
||||
DebugConsole.NewMessage($"WARNING: writing to \"{path}\" is disallowed in Release builds!\n{Environment.StackTrace}", Color.Orange);
|
||||
}
|
||||
return true;
|
||||
return DevException;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@@ -46,6 +43,16 @@ namespace Barotrauma.IO
|
||||
doc.Save(path);
|
||||
}
|
||||
|
||||
public static void SaveSafe(this System.Xml.Linq.XElement element, string path)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot save XML element to \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
element.Save(path);
|
||||
}
|
||||
|
||||
public static void SaveSafe(this System.Xml.Linq.XDocument doc, XmlWriter writer)
|
||||
{
|
||||
doc.WriteTo(writer);
|
||||
@@ -297,7 +304,7 @@ namespace Barotrauma.IO
|
||||
break;
|
||||
}
|
||||
return new FileStream(path, System.IO.File.Open(path, mode,
|
||||
!Validation.CanWrite(path, false) ?
|
||||
!Validation.CanWrite(path) ?
|
||||
System.IO.FileAccess.Read :
|
||||
access));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Barotrauma
|
||||
public static string MultiplayerSaveFolder = Path.Combine(SaveFolder, "Multiplayer");
|
||||
|
||||
public static readonly string SubmarineDownloadFolder = Path.Combine("Submarines", "Downloaded");
|
||||
public static readonly string CampaignDownloadFolder = Path.Combine("Data", "Saves", "Multiplayer");
|
||||
public static readonly string CampaignDownloadFolder = Path.Combine("Data", "Saves", "Multiplayer_Downloaded");
|
||||
|
||||
public delegate void ProgressDelegate(string sMessage);
|
||||
|
||||
|
||||
@@ -18,20 +18,28 @@ namespace Barotrauma
|
||||
public object UserData;
|
||||
}
|
||||
|
||||
private static List<TaskAction> taskActions = new List<TaskAction>();
|
||||
private static readonly List<TaskAction> taskActions = new List<TaskAction>();
|
||||
|
||||
public static void ListTasks(string[] args)
|
||||
public static void ListTasks()
|
||||
{
|
||||
lock (taskActions)
|
||||
{
|
||||
DebugConsole.NewMessage($"Task count: {taskActions.Count}");
|
||||
for (int i=0;i<taskActions.Count;i++)
|
||||
for (int i = 0; i < taskActions.Count; i++)
|
||||
{
|
||||
DebugConsole.NewMessage($" -{i}: {taskActions[i].Name}, {taskActions[i].Task.Status}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsTaskRunning(string name)
|
||||
{
|
||||
lock (taskActions)
|
||||
{
|
||||
return taskActions.Any(t => t.Name == name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddInternal(string name, Task task, Action<Task, object> onCompletion, object userdata)
|
||||
{
|
||||
lock (taskActions)
|
||||
|
||||
@@ -212,15 +212,16 @@ namespace Barotrauma
|
||||
|
||||
return inputType;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns either a green [x] or a red [o]
|
||||
/// </summary>
|
||||
/// <param name="isFinished"></param>
|
||||
/// <param name="isRunning"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDebugSymbol(bool isFinished)
|
||||
public static string GetDebugSymbol(bool isFinished, bool isRunning = false)
|
||||
{
|
||||
return $"[‖color:{(isFinished ? "0,255,0‖x" : "255,0,0‖o")}‖color:end‖]";
|
||||
return isRunning ? "[‖color:243,162,50‖x‖color:end‖]" : $"[‖color:{(isFinished ? "0,255,0‖x" : "255,0,0‖o")}‖color:end‖]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user