Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -36,26 +36,15 @@ using System.Configuration;
using System.Globalization;
using Barotrauma.IO;
using System.Text;
#if NET_4_0
using System.Web.Configuration;
#endif
namespace RestSharp.Contrib
{
#if NET_4_0
public
#endif
class HttpEncoder
{
static char[] hexChars = "0123456789abcdef".ToCharArray();
static object entitiesLock = new object();
static SortedDictionary<string, char> entities;
#if NET_4_0
static Lazy <HttpEncoder> defaultEncoder;
static Lazy <HttpEncoder> currentEncoderLazy;
#else
static HttpEncoder defaultEncoder;
#endif
static HttpEncoder currentEncoder;
static IDictionary<string, char> Entities
@@ -76,53 +65,29 @@ namespace RestSharp.Contrib
{
get
{
#if NET_4_0
if (currentEncoder == null)
currentEncoder = currentEncoderLazy.Value;
#endif
return currentEncoder;
}
#if NET_4_0
set {
if (value == null)
throw new ArgumentNullException ("value");
currentEncoder = value;
}
#endif
}
public static HttpEncoder Default
{
get
{
#if NET_4_0
return defaultEncoder.Value;
#else
return defaultEncoder;
#endif
}
}
static HttpEncoder()
{
#if NET_4_0
defaultEncoder = new Lazy <HttpEncoder> (() => new HttpEncoder ());
currentEncoderLazy = new Lazy <HttpEncoder> (new Func <HttpEncoder> (GetCustomEncoderFromConfig));
#else
defaultEncoder = new HttpEncoder();
currentEncoder = defaultEncoder;
#endif
}
public HttpEncoder()
{
}
#if NET_4_0
protected internal virtual
#else
internal static
#endif
void HeaderNameValueEncode(string headerName, string headerValue, out string encodedHeaderName, out string encodedHeaderValue)
internal static void HeaderNameValueEncode(string headerName, string headerValue, out string encodedHeaderName, out string encodedHeaderValue)
{
if (String.IsNullOrEmpty(headerName))
encodedHeaderName = headerName;
@@ -161,66 +126,8 @@ namespace RestSharp.Contrib
return input;
}
#if NET_4_0
protected internal virtual void HtmlAttributeEncode (string value, TextWriter output)
{
if (output == null)
throw new ArgumentNullException ("output");
if (String.IsNullOrEmpty (value))
return;
output.Write (HtmlAttributeEncode (value));
}
protected internal virtual void HtmlDecode (string value, TextWriter output)
{
if (output == null)
throw new ArgumentNullException ("output");
output.Write (HtmlDecode (value));
}
protected internal virtual void HtmlEncode (string value, TextWriter output)
{
if (output == null)
throw new ArgumentNullException ("output");
output.Write (HtmlEncode (value));
}
protected internal virtual byte[] UrlEncode (byte[] bytes, int offset, int count)
{
return UrlEncodeToBytes (bytes, offset, count);
}
static HttpEncoder GetCustomEncoderFromConfig ()
{
var cfg = WebConfigurationManager.GetSection ("system.web/httpRuntime") as HttpRuntimeSection;
string typeName = cfg.EncoderType;
if (String.Compare (typeName, "System.Web.Util.HttpEncoder", StringComparison.OrdinalIgnoreCase) == 0)
return Default;
Type t = Type.GetType (typeName, false);
if (t == null)
throw new ConfigurationErrorsException (String.Format ("Could not load type '{0}'.", typeName));
if (!typeof (HttpEncoder).IsAssignableFrom (t))
throw new ConfigurationErrorsException (
String.Format ("'{0}' is not allowed here because it does not extend class 'System.Web.Util.HttpEncoder'.", typeName)
);
return Activator.CreateInstance (t, false) as HttpEncoder;
}
#endif
#if NET_4_0
protected internal virtual
#else
internal static
#endif
string UrlPathEncode(string value)
internal static string UrlPathEncode(string value)
{
if (String.IsNullOrEmpty(value))
return value;
@@ -240,7 +147,7 @@ namespace RestSharp.Contrib
int blen = bytes.Length;
if (blen == 0)
return new byte[0];
return Array.Empty<byte>();
if (offset < 0 || offset >= blen)
throw new ArgumentOutOfRangeException("offset");
@@ -268,11 +175,7 @@ namespace RestSharp.Contrib
for (int i = 0; i < s.Length; i++)
{
char c = s[i];
if (c == '&' || c == '"' || c == '<' || c == '>' || c > 159
#if NET_4_0
|| c == '\''
#endif
)
if (c == '&' || c == '"' || c == '<' || c == '>' || c > 159)
{
needEncode = true;
break;
@@ -302,11 +205,6 @@ namespace RestSharp.Contrib
case '"':
output.Append("&quot;");
break;
#if NET_4_0
case '\'':
output.Append ("&#39;");
break;
#endif
case '\uff1c':
output.Append("&#65308;");
break;
@@ -334,25 +232,17 @@ namespace RestSharp.Contrib
internal static string HtmlAttributeEncode(string s)
{
#if NET_4_0
if (String.IsNullOrEmpty (s))
return String.Empty;
#else
if (s == null)
return null;
if (s.Length == 0)
return String.Empty;
#endif
bool needEncode = false;
for (int i = 0; i < s.Length; i++)
{
char c = s[i];
if (c == '&' || c == '"' || c == '<'
#if NET_4_0
|| c == '\''
#endif
)
if (c == '&' || c == '"' || c == '<')
{
needEncode = true;
break;
@@ -376,11 +266,6 @@ namespace RestSharp.Contrib
case '<':
output.Append("&lt;");
break;
#if NET_4_0
case '\'':
output.Append ("&#39;");
break;
#endif
default:
output.Append(s[i]);
break;
@@ -399,9 +284,7 @@ namespace RestSharp.Contrib
if (s.IndexOf('&') == -1)
return s;
#if NET_4_0
StringBuilder rawEntity = new StringBuilder ();
#endif
StringBuilder entity = new StringBuilder();
StringBuilder output = new StringBuilder();
int len = s.Length;
@@ -422,9 +305,6 @@ namespace RestSharp.Contrib
if (c == '&')
{
entity.Append(c);
#if NET_4_0
rawEntity.Append (c);
#endif
state = 1;
}
else
@@ -471,9 +351,6 @@ namespace RestSharp.Contrib
state = 3;
}
entity.Append(c);
#if NET_4_0
rawEntity.Append (c);
#endif
}
}
else if (state == 2)
@@ -488,20 +365,12 @@ namespace RestSharp.Contrib
output.Append(key);
state = 0;
entity.Length = 0;
#if NET_4_0
rawEntity.Length = 0;
#endif
}
}
else if (state == 3)
{
if (c == ';')
{
#if NET_4_0
if (number == 0)
output.Append (rawEntity.ToString () + ";");
else
#endif
if (number > 65535)
{
output.Append("&#");
@@ -514,33 +383,21 @@ namespace RestSharp.Contrib
}
state = 0;
entity.Length = 0;
#if NET_4_0
rawEntity.Length = 0;
#endif
have_trailing_digits = false;
}
else if (is_hex_value && Uri.IsHexDigit(c))
{
number = number * 16 + Uri.FromHex(c);
have_trailing_digits = true;
#if NET_4_0
rawEntity.Append (c);
#endif
}
else if (Char.IsDigit(c))
{
number = number * 10 + ((int)c - '0');
have_trailing_digits = true;
#if NET_4_0
rawEntity.Append (c);
#endif
}
else if (number == 0 && (c == 'x' || c == 'X'))
{
is_hex_value = true;
#if NET_4_0
rawEntity.Append (c);
#endif
}
else
{
@@ -568,11 +425,7 @@ namespace RestSharp.Contrib
internal static bool NotEncoded(char c)
{
return (c == '!' || c == '(' || c == ')' || c == '*' || c == '-' || c == '.' || c == '_'
#if !NET_4_0
|| c == '\''
#endif
);
return (c == '!' || c == '(' || c == ')' || c == '*' || c == '-' || c == '.' || c == '_');
}
internal static void UrlEncodeChar(char c, System.IO.Stream result, bool isUnicode)
@@ -26,7 +26,7 @@ namespace Barotrauma
public static void Convert()
{
if (TextManager.Language != "English")
if (GameSettings.CurrentConfig.Language != TextManager.DefaultLanguage)
{
DebugConsole.ThrowError("Use the english localization when converting .csv to allow copying values");
return;
@@ -123,8 +123,10 @@ namespace Barotrauma
private static List<string> ConvertInfoTextToXML(string[] csvContent, string language)
{
List<string> xmlContent = new List<string>();
xmlContent.Add(xmlHeader);
List<string> xmlContent = new List<string>
{
xmlHeader
};
string translatedName = GetTranslatedName(language);
bool nowhitespace = TextManager.IsCJK(translatedName);
@@ -151,6 +153,7 @@ namespace Barotrauma
split[1] = split[2];
split[2] = string.Empty;
}
split[1] = split[1].Replace(" & ", " &amp; ");
xmlContent.Add($"<{split[0]}>{split[1]}</{split[0]}>");
}
else if (split[0].Contains(".") && !split[0].Any(char.IsUpper)) // An empty field
@@ -220,15 +223,16 @@ namespace Barotrauma
}
//DebugConsole.NewMessage("Count: " + NPCPersonalityTrait.List.Count);
for (int i = 0; i < NPCPersonalityTrait.List.Count; i++) // Traits
var traits = NPCPersonalityTrait.GetAll(language.ToLanguageIdentifier()).ToArray();
for (int i = 0; i < traits.Length; i++) // Traits
{
//string[] split = SplitCSV(csvContent[traitStart + i].Trim(separator));
string[] split = csvContent[traitStart + i].Split(separator);
xmlContent.Add(
$"<PersonalityTrait " +
$"{GetVariable("name", split[1])}" +
$"{GetVariable("alloweddialogtags", string.Join(",", NPCPersonalityTrait.List[i].AllowedDialogTags))}" +
$"{GetVariable("commonness", NPCPersonalityTrait.List[i].Commonness.ToString(CultureInfo.InvariantCulture))}/>");
$"{GetVariable("alloweddialogtags", string.Join(",", traits[i].AllowedDialogTags))}" +
$"{GetVariable("commonness", traits[i].Commonness.ToString(CultureInfo.InvariantCulture))}/>");
}
xmlContent.Add(string.Empty);
@@ -53,7 +53,7 @@ namespace Barotrauma
private static XElement ParseRecipe(ItemPrefab prefab)
{
FabricationRecipe? recipe = prefab.FabricationRecipes.FirstOrDefault();
FabricationRecipe? recipe = prefab.FabricationRecipes.Values.FirstOrDefault();
List<ItemPrefab> ingredients = recipe?.RequiredItems.SelectMany(ri => ri.ItemPrefabs).Distinct().ToList() ?? new List<ItemPrefab>();
Skill? skill = recipe?.RequiredSkills.FirstOrDefault();
@@ -61,7 +61,7 @@ namespace Barotrauma
return new XElement("Recipe",
new XAttribute("amount", recipe?.Amount ?? 0),
new XAttribute("time", recipe?.RequiredTime ?? 0),
new XAttribute("skillname", skill?.Identifier ?? ""),
new XAttribute("skillname", skill?.Identifier.Value ?? ""),
new XAttribute("skillamount", (int?) skill?.Level ?? 0),
new XAttribute("ingredients", FormatArray(ingredients.Select(ip => ip.Name))),
new XAttribute("values", FormatArray(ingredients.Select(ip => ip.DefaultPrice?.Price ?? 0)))
@@ -80,15 +80,15 @@ namespace Barotrauma
private static XElement ParseMedical(ItemPrefab prefab)
{
XElement? itemMeleeWeapon = prefab.ConfigElement.GetChildElement(nameof(MeleeWeapon));
ContentXElement? itemMeleeWeapon = prefab.ConfigElement.GetChildElement(nameof(MeleeWeapon));
// affliction, amount, duration
List<Tuple<string, float, float>> onSuccessAfflictions = new List<Tuple<string, float, float>>();
List<Tuple<string, float, float>> onFailureAfflictions = new List<Tuple<string, float, float>>();
List<(LocalizedString Name, float Amount, float Duration)> onSuccessAfflictions = new List<(LocalizedString Name, float Amount, float Duration)>();
List<(LocalizedString Name, float Amount, float Duration)> onFailureAfflictions = new List<(LocalizedString Name, float Amount, float Duration)>();
int medicalRequiredSkill = 0;
if (itemMeleeWeapon != null)
{
List<StatusEffect> statusEffects = new List<StatusEffect>();
foreach (XElement subElement in itemMeleeWeapon.Elements())
foreach (var subElement in itemMeleeWeapon.Elements())
{
string name = subElement.Name.ToString();
if (name.Equals(nameof(StatusEffect), StringComparison.OrdinalIgnoreCase))
@@ -110,15 +110,15 @@ namespace Barotrauma
foreach (StatusEffect statusEffect in successEffects)
{
float duration = statusEffect.Duration;
onSuccessAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration)));
onSuccessAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
onSuccessAfflictions.AddRange(statusEffect.ReduceAffliction.Select(ra => (GetAfflictionName(ra.AfflictionIdentifier), -ra.ReduceAmount, duration)));
onSuccessAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => (affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
}
foreach (StatusEffect statusEffect in failureEffects)
{
float duration = statusEffect.Duration;
onFailureAfflictions.AddRange(statusEffect.ReduceAffliction.Select(pair => Tuple.Create(GetAfflictionName(pair.affliction), -pair.amount, duration)));
onFailureAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
onFailureAfflictions.AddRange(statusEffect.ReduceAffliction.Select(ra => (GetAfflictionName(ra.AfflictionIdentifier), -ra.ReduceAmount, duration)));
onFailureAfflictions.AddRange(statusEffect.Afflictions.Select(affliction => (affliction.Prefab.Name, affliction.NonClampedStrength, duration)));
}
}
@@ -141,15 +141,15 @@ namespace Barotrauma
int skillRequirement = 0;
// affliction, amount
List<Tuple<string, float>> damages = new List<Tuple<string, float>>();
List<(LocalizedString Name, float Amount)> damages = new List<(LocalizedString Name, float Amount)>();
string[] validNames = { nameof(Projectile), nameof(MeleeWeapon), nameof(RepairTool), nameof(ItemComponent), nameof(RangedWeapon) };
foreach (XElement icElement in prefab.ConfigElement.Elements())
foreach (var icElement in prefab.ConfigElement.Elements())
{
string icName = icElement.Name.ToString();
if (!validNames.Any(name => icName.Equals(name, StringComparison.OrdinalIgnoreCase))) { continue; }
foreach (XElement icChildElement in icElement.Elements())
foreach (var icChildElement in icElement.Elements())
{
string name = icChildElement.Name.ToString();
if (IsRequiredSkill(icChildElement, out Skill? skill) && skill != null)
@@ -208,7 +208,7 @@ namespace Barotrauma
continue;
}
damages.Add(Tuple.Create(affliction.Prefab.Name, affliction.NonClampedStrength));
damages.Add((affliction.Prefab.Name, affliction.NonClampedStrength));
}
}
}
@@ -224,9 +224,9 @@ namespace Barotrauma
);
}
private static string GetAfflictionName(string identifier)
private static LocalizedString GetAfflictionName(Identifier identifier)
{
return AfflictionPrefab.Prefabs.Find(prefab => prefab.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase))?.Name ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(identifier.ToLower());
return AfflictionPrefab.Prefabs.Find(prefab => prefab.Identifier == identifier)?.Name ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(identifier.Value!.ToLower());
}
private static string FormatFloat(float value)
@@ -239,7 +239,7 @@ namespace Barotrauma
return string.Join(separator, array);
}
private static bool IsRequiredSkill(XElement element, out Skill? skill)
private static bool IsRequiredSkill(ContentXElement element, out Skill? skill)
{
string name = element.Name.ToString();
bool isSkill = name.Equals("RequiredSkill", StringComparison.OrdinalIgnoreCase) ||
@@ -247,7 +247,7 @@ namespace Barotrauma
if (isSkill)
{
string identifier = element.GetAttributeString(nameof(Skill.Identifier).ToLowerInvariant(), string.Empty);
Identifier identifier = element.GetAttributeIdentifier(nameof(Skill.Identifier), Identifier.Empty);
float level = element.GetAttributeFloat(nameof(Skill.Level).ToLowerInvariant(), 0f);
skill = new Skill(identifier, level);
}
@@ -283,7 +283,7 @@ namespace Barotrauma
indexBuffer?.Dispose();
indexBuffer = new IndexBuffer(gfxDevice, IndexElementSize.SixteenBits, requiredIndexCount * 2, BufferUsage.WriteOnly);
ushort[] indices = new ushort[requiredIndexCount * 2];
for (int i=0;i<indices.Length;i+=6)
for (int i = 0; i < indices.Length; i += 6)
{
indices[i + 0] = (ushort)((i / 6) * 4 + 1);
indices[i + 1] = (ushort)((i / 6) * 4 + 0);
@@ -296,7 +296,7 @@ namespace Barotrauma
}
gfxDevice.Indices = indexBuffer;
for (int i=0;i<recordedBuffers.Count;i++)
for (int i = 0; i < recordedBuffers.Count; i++)
{
gfxDevice.SetVertexBuffer(recordedBuffers[i].VertexBuffer);
BasicEffect.Texture = recordedBuffers[i].Texture;
@@ -205,7 +205,7 @@ namespace Barotrauma
textureData = Texture2D.TextureDataFromStream(stream, out int width, out int height, out int channels);
SurfaceFormat format = SurfaceFormat.Color;
if (GameMain.Config.TextureCompressionEnabled && compress)
if (GameSettings.CurrentConfig.Graphics.CompressTextures && compress)
{
if (((width & 0x03) == 0) && ((height & 0x03) == 0))
{
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Color = Microsoft.Xna.Framework.Color;
@@ -394,6 +395,14 @@ namespace Barotrauma
sourceColor.A - color.A);
}
public static LocalizedString LimitString(LocalizedString str, GUIFont font, int maxWidth)
{
return new LimitLString(str, font, maxWidth);
}
public static LocalizedString LimitString(string str, GUIFont font, int maxWidth)
=> LimitString((LocalizedString)str, font, maxWidth);
public static string LimitString(string str, ScalableFont font, int maxWidth)
{
if (maxWidth <= 0 || string.IsNullOrWhiteSpace(str)) return "";
@@ -434,6 +443,11 @@ namespace Barotrauma
return Color.Lerp(gradient[(int)scaledT], gradient[(int)Math.Min(scaledT + 1, gradient.Length - 1)], (scaledT - (int)scaledT));
}
public static LocalizedString WrapText(LocalizedString text, float lineLength, GUIFont font, float textScale = 1.0f)
{
return new WrappedLString(text, lineLength, font, textScale);
}
public static string WrapText(string text, float lineLength, ScalableFont font, float textScale = 1.0f)
=> font.WrapText(text, lineLength / textScale);
@@ -464,5 +478,15 @@ namespace Barotrauma
if (b.Build < a.Build) { return false; }
return false;
}
public static void OpenFileWithShell(string filename)
{
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = filename,
UseShellExecute = true
};
Process.Start(startInfo);
}
}
}