From 21976e265cb36f070f2ede57fa3ba0897b7a6423 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 24 Nov 2020 00:15:30 +0100 Subject: [PATCH] Remove Nett .Get<> methods from content. They could allow bypassing sandbox due to how the deserialization logic works. --- Content.Client/Parallax/ParallaxGenerator.cs | 65 ++++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/Content.Client/Parallax/ParallaxGenerator.cs b/Content.Client/Parallax/ParallaxGenerator.cs index ab358c2b41..d905c19dd9 100644 --- a/Content.Client/Parallax/ParallaxGenerator.cs +++ b/Content.Client/Parallax/ParallaxGenerator.cs @@ -44,18 +44,17 @@ namespace Content.Client.Parallax private void _loadConfig(TomlTable config) { - foreach (var layerArray in config.Get("layers").Items) + foreach (var layerArray in ((TomlTableArray)config.Get("layers")).Items) { - var layer = layerArray.Get(); - switch (layer.Get("type")) + switch (((TomlValue) layerArray.Get("type")).Value) { case "noise": - var layerNoise = new LayerNoise(layer); + var layerNoise = new LayerNoise(layerArray); Layers.Add(layerNoise); break; case "points": - var layerPoint = new LayerPoints(layer); + var layerPoint = new LayerPoints(layerArray); Layers.Add(layerPoint); break; @@ -89,62 +88,62 @@ namespace Content.Client.Parallax { if (table.TryGetValue("innercolor", out var tomlObject)) { - InnerColor = Color.FromHex(tomlObject.Get()); + InnerColor = Color.FromHex(((TomlValue) tomlObject).Value); } if (table.TryGetValue("outercolor", out tomlObject)) { - OuterColor = Color.FromHex(tomlObject.Get()); + OuterColor = Color.FromHex(((TomlValue) tomlObject).Value); } if (table.TryGetValue("seed", out tomlObject)) { - Seed = (uint) tomlObject.Get(); + Seed = (uint) ((TomlValue) tomlObject).Value; } if (table.TryGetValue("persistence", out tomlObject)) { - Persistence = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + Persistence = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("lacunarity", out tomlObject)) { - Lacunarity = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + Lacunarity = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("frequency", out tomlObject)) { - Frequency = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + Frequency = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("octaves", out tomlObject)) { - Octaves = (uint) tomlObject.Get(); + Octaves = (uint) ((TomlValue) tomlObject).Value; } if (table.TryGetValue("threshold", out tomlObject)) { - Threshold = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + Threshold = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("sourcefactor", out tomlObject)) { - SrcFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), tomlObject.Get()); + SrcFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), ((TomlValue) tomlObject).Value); } if (table.TryGetValue("destfactor", out tomlObject)) { - DstFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), tomlObject.Get()); + DstFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), ((TomlValue) tomlObject).Value); } if (table.TryGetValue("power", out tomlObject)) { - Power = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + Power = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("noise_type", out tomlObject)) { - switch (tomlObject.Get()) + switch (((TomlValue) tomlObject).Value) { case "fbm": NoiseType = NoiseGenerator.NoiseType.Fbm; @@ -226,78 +225,78 @@ namespace Content.Client.Parallax { if (table.TryGetValue("seed", out var tomlObject)) { - Seed = tomlObject.Get(); + Seed = ((TomlValue) tomlObject).Value; } if (table.TryGetValue("count", out tomlObject)) { - PointCount = tomlObject.Get(); + PointCount = ((TomlValue) tomlObject).Value; } if (table.TryGetValue("sourcefactor", out tomlObject)) { - SrcFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), tomlObject.Get()); + SrcFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), ((TomlValue) tomlObject).Value); } if (table.TryGetValue("destfactor", out tomlObject)) { - DstFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), tomlObject.Get()); + DstFactor = (Color.BlendFactor) Enum.Parse(typeof(Color.BlendFactor), ((TomlValue) tomlObject).Value); } if (table.TryGetValue("farcolor", out tomlObject)) { - FarColor = Color.FromHex(tomlObject.Get()); + FarColor = Color.FromHex(((TomlValue) tomlObject).Value); } if (table.TryGetValue("closecolor", out tomlObject)) { - CloseColor = Color.FromHex(tomlObject.Get()); + CloseColor = Color.FromHex(((TomlValue) tomlObject).Value); } if (table.TryGetValue("pointsize", out tomlObject)) { - PointSize = tomlObject.Get(); + PointSize = ((TomlValue) tomlObject).Value; } // Noise mask stuff. if (table.TryGetValue("mask", out tomlObject)) { - Masked = tomlObject.Get(); + Masked = ((TomlValue) tomlObject).Value; } if (table.TryGetValue("maskseed", out tomlObject)) { - MaskSeed = (uint) tomlObject.Get(); + MaskSeed = (uint) ((TomlValue) tomlObject).Value; } if (table.TryGetValue("maskpersistence", out tomlObject)) { - MaskPersistence = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + MaskPersistence = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("masklacunarity", out tomlObject)) { - MaskLacunarity = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + MaskLacunarity = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("maskfrequency", out tomlObject)) { - MaskFrequency = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + MaskFrequency = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("maskoctaves", out tomlObject)) { - MaskOctaves = (uint) tomlObject.Get(); + MaskOctaves = (uint) ((TomlValue) tomlObject).Value; } if (table.TryGetValue("maskthreshold", out tomlObject)) { - MaskThreshold = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + MaskThreshold = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } if (table.TryGetValue("masknoise_type", out tomlObject)) { - switch (tomlObject.Get()) + switch (((TomlValue) tomlObject).Value) { case "fbm": MaskNoiseType = NoiseGenerator.NoiseType.Fbm; @@ -312,7 +311,7 @@ namespace Content.Client.Parallax if (table.TryGetValue("maskpower", out tomlObject)) { - MaskPower = float.Parse(tomlObject.Get(), CultureInfo.InvariantCulture); + MaskPower = float.Parse(((TomlValue) tomlObject).Value, CultureInfo.InvariantCulture); } }