From 849706cfd6e45638819626e549085c05e87274a6 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 17 Dec 2023 18:38:30 +0300 Subject: [PATCH 01/23] Json build optimisation. Added ability to send UI to the list of players. --- src/RustCui.cs | 519 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 513 insertions(+), 6 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index ece193210..56575e284 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -6,6 +6,8 @@ using References::Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.IO; +using System.Text; using UnityEngine; using UnityEngine.UI; @@ -15,12 +17,28 @@ public static class CuiHelper { public static string ToJson(List elements, bool format = false) { - return JsonConvert.SerializeObject(elements, format ? Formatting.Indented : Formatting.None, new JsonSerializerSettings + StringBuilder stringBuilder = new StringBuilder(); + using (StringWriter stringWriter = new StringWriter(stringBuilder)) { - DefaultValueHandling = DefaultValueHandling.Ignore - }).Replace("\\n", "\n"); + using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter)) + { + jsonWriter.Formatting = Formatting.None; + + if (elements.Count > 0) + { + jsonWriter.WriteStartArray(); + foreach (var element in elements) + { + element.WriteJson(jsonWriter); + } + jsonWriter.WriteEndArray(); + } + } + } + return stringBuilder.ToString().Replace("\\n", "\n"); } + public static List FromJson(string json) => JsonConvert.DeserializeObject>(json); public static string GetGuid() => Guid.NewGuid().ToString().Replace("-", string.Empty); @@ -38,6 +56,29 @@ public static bool AddUi(BasePlayer player, string json) return false; } + public static bool AddUi(List playerList, List elements) + { + CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(playerList), null, "AddUI", ToJson(elements)); + return true; + } + + public static bool AddUi(List playerList, string json) + { + List connections = new List(); + foreach (var player in playerList) + { + if (player?.net != null) + { + connections.Add(player.net.connection); + } + } + + CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(connections), null, "AddUI", json); + return true; + } + + public static bool AddUi(List playerList, List elements) => AddUi(playerList, ToJson(elements)); + public static bool DestroyUi(BasePlayer player, string elem) { if (player?.net != null) @@ -196,7 +237,7 @@ public class CuiElement [JsonProperty("parent")] public string Parent { get; set; } - [JsonProperty("destroyUi", NullValueHandling=NullValueHandling.Ignore)] + [JsonProperty("destroyUi", NullValueHandling = NullValueHandling.Ignore)] public string DestroyUi { get; set; } [JsonProperty("components")] @@ -204,9 +245,59 @@ public class CuiElement [JsonProperty("fadeOut")] public float FadeOut { get; set; } - + [JsonProperty("update", NullValueHandling = NullValueHandling.Ignore)] - public bool Update { get; set; } + public bool Update { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + if (!string.IsNullOrEmpty(Name)) + { + jsonWriter.WritePropertyName("name"); + jsonWriter.WriteValue(Name); + } + + if (!string.IsNullOrEmpty(Parent)) + { + jsonWriter.WritePropertyName("parent"); + jsonWriter.WriteValue(Parent); + } + + if (!string.IsNullOrEmpty(DestroyUi)) + { + jsonWriter.WritePropertyName("destroyUi"); + jsonWriter.WriteValue(DestroyUi); + } + + if (FadeOut != 0f) + { + jsonWriter.WritePropertyName("fadeOut"); + jsonWriter.WriteValue(FadeOut); + } + + if (Update) + { + jsonWriter.WritePropertyName("update"); + jsonWriter.WriteValue(Update); + } + + if (Components.Count > 0) + { + jsonWriter.WritePropertyName("components"); + jsonWriter.WriteStartArray(); + + foreach (var component in Components) + { + component.WriteJson(jsonWriter); + } + + jsonWriter.WriteEndArray(); + } + + jsonWriter.WriteEndObject(); + } } [JsonConverter(typeof(ComponentConverter))] @@ -214,6 +305,7 @@ public interface ICuiComponent { [JsonProperty("type")] string Type { get; } + void WriteJson(JsonWriter jsonWriter); } public interface ICuiColor @@ -251,6 +343,58 @@ public class CuiTextComponent : ICuiComponent, ICuiColor [JsonProperty("fadeIn")] public float FadeIn { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.Text"); + + if (!string.IsNullOrEmpty(Text)) + { + jsonWriter.WritePropertyName("text"); + jsonWriter.WriteValue(Text); + } + + if (!string.IsNullOrEmpty(Font) && Font != "robotocondensed-bold.ttf") + { + jsonWriter.WritePropertyName("font"); + jsonWriter.WriteValue(Font); + } + + if (FontSize != 14 && FontSize != 0) + { + jsonWriter.WritePropertyName("fontSize"); + jsonWriter.WriteValue(FontSize); + } + + if (Align != TextAnchor.UpperLeft) + { + jsonWriter.WritePropertyName("align"); + jsonWriter.WriteValue(Align.ToString()); + } + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (VerticalOverflow != VerticalWrapMode.Truncate) + { + jsonWriter.WritePropertyName("verticalOverflow"); + jsonWriter.WriteValue(VerticalOverflow.ToString()); + } + + if (FadeIn > 0f) + { + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); + } + + jsonWriter.WriteEndObject(); + } } public class CuiImageComponent : ICuiComponent, ICuiColor @@ -280,6 +424,64 @@ public class CuiImageComponent : ICuiComponent, ICuiColor [JsonProperty("skinid")] public ulong SkinId { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.Image"); + + if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + { + jsonWriter.WritePropertyName("sprite"); + jsonWriter.WriteValue(Sprite); + } + + if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + { + jsonWriter.WritePropertyName("material"); + jsonWriter.WriteValue(Material); + } + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (ImageType != default(Image.Type)) + { + jsonWriter.WritePropertyName("imagetype"); + jsonWriter.WriteValue(ImageType.ToString()); + } + + if (!string.IsNullOrEmpty(Png)) + { + jsonWriter.WritePropertyName("png"); + jsonWriter.WriteValue(Png); + } + + if (FadeIn > 0f) + { + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); + } + + if (ItemId != 0) + { + jsonWriter.WritePropertyName("itemid"); + jsonWriter.WriteValue(ItemId); + } + + if (SkinId != 0) + { + jsonWriter.WritePropertyName("skinid"); + jsonWriter.WriteValue(SkinId); + } + + jsonWriter.WriteEndObject(); + } } public class CuiRawImageComponent : ICuiComponent, ICuiColor @@ -302,6 +504,52 @@ public class CuiRawImageComponent : ICuiComponent, ICuiColor [JsonProperty("fadeIn")] public float FadeIn { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.RawImage"); + + if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + { + jsonWriter.WritePropertyName("sprite"); + jsonWriter.WriteValue(Sprite); + } + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + { + jsonWriter.WritePropertyName("material"); + jsonWriter.WriteValue(Material); + } + + if (!string.IsNullOrEmpty(Url)) + { + jsonWriter.WritePropertyName("url"); + jsonWriter.WriteValue(Url); + } + + if (!string.IsNullOrEmpty(Png)) + { + jsonWriter.WritePropertyName("png"); + jsonWriter.WriteValue(Png); + } + + if (FadeIn > 0f) + { + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); + } + + jsonWriter.WriteEndObject(); + } } public class CuiButtonComponent : ICuiComponent, ICuiColor @@ -331,6 +579,58 @@ public class CuiButtonComponent : ICuiComponent, ICuiColor [JsonProperty("fadeIn")] public float FadeIn { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.Button"); + + if (!string.IsNullOrEmpty(Command)) + { + jsonWriter.WritePropertyName("command"); + jsonWriter.WriteValue(Command); + } + + if (!string.IsNullOrEmpty(Close)) + { + jsonWriter.WritePropertyName("close"); + jsonWriter.WriteValue(Close); + } + + if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + { + jsonWriter.WritePropertyName("sprite"); + jsonWriter.WriteValue(Sprite); + } + + if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + { + jsonWriter.WritePropertyName("material"); + jsonWriter.WriteValue(Material); + } + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (ImageType != default(Image.Type)) + { + jsonWriter.WritePropertyName("imagetype"); + jsonWriter.WriteValue(ImageType.ToString()); + } + + if (FadeIn > 0f) + { + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); + } + + jsonWriter.WriteEndObject(); + } } public class CuiOutlineComponent : ICuiComponent, ICuiColor @@ -347,6 +647,34 @@ public class CuiOutlineComponent : ICuiComponent, ICuiColor // Should the shadow inherit the alpha from the graphic [JsonProperty("useGraphicAlpha")] public bool UseGraphicAlpha { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.Outline"); + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (!string.IsNullOrEmpty(Distance)) + { + jsonWriter.WritePropertyName("distance"); + jsonWriter.WriteValue(Distance); + } + + if (UseGraphicAlpha) + { + jsonWriter.WritePropertyName("useGraphicAlpha"); + jsonWriter.WriteValue(UseGraphicAlpha); + } + + jsonWriter.WriteEndObject(); + } } public class CuiInputFieldComponent : ICuiComponent, ICuiColor @@ -396,6 +724,94 @@ public class CuiInputFieldComponent : ICuiComponent, ICuiColor [JsonProperty("hudMenuInput")] public bool HudMenuInput { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("UnityEngine.UI.InputField"); + + if (!string.IsNullOrEmpty(Text)) + { + jsonWriter.WritePropertyName("text"); + jsonWriter.WriteValue(Text); + } + + if (FontSize != 14 && FontSize != 0) + { + jsonWriter.WritePropertyName("fontSize"); + jsonWriter.WriteValue(FontSize); + } + + if (!string.IsNullOrEmpty(Font) && Font != "robotocondensed-bold.ttf") + { + jsonWriter.WritePropertyName("font"); + jsonWriter.WriteValue(Font); + } + + if (Align != TextAnchor.UpperLeft) + { + jsonWriter.WritePropertyName("align"); + jsonWriter.WriteValue(Align.ToString()); + } + + if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + { + jsonWriter.WritePropertyName("color"); + jsonWriter.WriteValue(Color); + } + + if (CharsLimit != 0) + { + jsonWriter.WritePropertyName("characterLimit"); + jsonWriter.WriteValue(CharsLimit); + } + + if (!string.IsNullOrEmpty(Command)) + { + jsonWriter.WritePropertyName("command"); + jsonWriter.WriteValue(Command); + } + + if (IsPassword) + { + jsonWriter.WritePropertyName("password"); + jsonWriter.WriteValue(IsPassword); + } + + if (ReadOnly) + { + jsonWriter.WritePropertyName("readOnly"); + jsonWriter.WriteValue(ReadOnly); + } + + if (NeedsKeyboard) + { + jsonWriter.WritePropertyName("needsKeyboard"); + jsonWriter.WriteValue(NeedsKeyboard); + } + + if (LineType != default(InputField.LineType)) + { + jsonWriter.WritePropertyName("lineType"); + jsonWriter.WriteValue(LineType.ToString()); + } + + if (Autofocus) + { + jsonWriter.WritePropertyName("autofocus"); + jsonWriter.WriteValue(Autofocus); + } + + if (HudMenuInput) + { + jsonWriter.WritePropertyName("hudMenuInput"); + jsonWriter.WriteValue(HudMenuInput); + } + + jsonWriter.WriteEndObject(); + } } public class CuiCountdownComponent : ICuiComponent @@ -416,16 +832,74 @@ public class CuiCountdownComponent : ICuiComponent [JsonProperty("fadeIn")] public float FadeIn { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("Countdown"); + + if (EndTime != 0) + { + jsonWriter.WritePropertyName("endTime"); + jsonWriter.WriteValue(EndTime); + } + + if (StartTime != 0) + { + jsonWriter.WritePropertyName("startTime"); + jsonWriter.WriteValue(StartTime); + } + + if (Step != 1) + { + jsonWriter.WritePropertyName("step"); + jsonWriter.WriteValue(Step); + } + + if (!string.IsNullOrEmpty(Command)) + { + jsonWriter.WritePropertyName("command"); + jsonWriter.WriteValue(Command); + } + + if (FadeIn > 0f) + { + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); + } + + jsonWriter.WriteEndObject(); + } } public class CuiNeedsCursorComponent : ICuiComponent { public string Type => "NeedsCursor"; + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("NeedsCursor"); + + jsonWriter.WriteEndObject(); + } } public class CuiNeedsKeyboardComponent : ICuiComponent { public string Type => "NeedsKeyboard"; + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("NeedsKeyboard"); + + jsonWriter.WriteEndObject(); + } } public class CuiRectTransformComponent : ICuiComponent @@ -447,6 +921,39 @@ public class CuiRectTransformComponent : ICuiComponent // The offset of the upper right corner of the rectangle relative to the upper right anchor [JsonProperty("offsetmax")] public string OffsetMax { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("RectTransform"); + + if (!string.IsNullOrEmpty(AnchorMin) && AnchorMin != "0 0") + { + jsonWriter.WritePropertyName("anchormin"); + jsonWriter.WriteValue(AnchorMin); + } + + if (!string.IsNullOrEmpty(AnchorMax) && AnchorMax != "1 1") + { + jsonWriter.WritePropertyName("anchormax"); + jsonWriter.WriteValue(AnchorMax); + } + + if (!string.IsNullOrEmpty(OffsetMin) && OffsetMin != "0 0") + { + jsonWriter.WritePropertyName("offsetmin"); + jsonWriter.WriteValue(OffsetMin); + } + + if (!string.IsNullOrEmpty(OffsetMax) && OffsetMax != "1 1") + { + jsonWriter.WritePropertyName("offsetmax"); + jsonWriter.WriteValue(OffsetMax); + } + + jsonWriter.WriteEndObject(); + } } public class ComponentConverter : JsonConverter From e6a52ec5689534e9589d153f5edf87d9c6a724c5 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Wed, 27 Dec 2023 03:20:59 +0300 Subject: [PATCH 02/23] fix --- src/RustCui.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 56575e284..892e7f9aa 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -35,7 +35,7 @@ public static string ToJson(List elements, bool format = false) } } } - return stringBuilder.ToString().Replace("\\n", "\n"); + return stringBuilder.Replace("\\n", "\n").ToString(); } From 9ff778819d6c51074b9809fe4c7601a25222b476 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Jan 2024 01:29:02 +0300 Subject: [PATCH 03/23] Removed ignoring default values --- src/RustCui.cs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 892e7f9aa..6e7e7cb95 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -357,25 +357,25 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Text); } - if (!string.IsNullOrEmpty(Font) && Font != "robotocondensed-bold.ttf") + if (!string.IsNullOrEmpty(Font)) { jsonWriter.WritePropertyName("font"); jsonWriter.WriteValue(Font); } - if (FontSize != 14 && FontSize != 0) + if (FontSize != 0) { jsonWriter.WritePropertyName("fontSize"); jsonWriter.WriteValue(FontSize); } - if (Align != TextAnchor.UpperLeft) + if (Align != default(TextAnchor)) { jsonWriter.WritePropertyName("align"); jsonWriter.WriteValue(Align.ToString()); } - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -432,19 +432,19 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Image"); - if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + if (!string.IsNullOrEmpty(Sprite)) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + if (!string.IsNullOrEmpty(Material)) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); } - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -512,19 +512,19 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.RawImage"); - if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + if (!string.IsNullOrEmpty(Sprite)) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); } - if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + if (!string.IsNullOrEmpty(Material)) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); @@ -599,19 +599,19 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Close); } - if (!string.IsNullOrEmpty(Sprite) && Sprite != "assets/content/ui/ui.background.tile.psd") + if (!string.IsNullOrEmpty(Sprite)) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Material) && Material != "assets/icons/iconmaterial.mat") + if (!string.IsNullOrEmpty(Material)) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); } - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -655,7 +655,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Outline"); - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -738,25 +738,25 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Text); } - if (FontSize != 14 && FontSize != 0) + if (FontSize != 0) { jsonWriter.WritePropertyName("fontSize"); jsonWriter.WriteValue(FontSize); } - if (!string.IsNullOrEmpty(Font) && Font != "robotocondensed-bold.ttf") + if (!string.IsNullOrEmpty(Font)) { jsonWriter.WritePropertyName("font"); jsonWriter.WriteValue(Font); } - if (Align != TextAnchor.UpperLeft) + if (Align != default(TextAnchor)) { jsonWriter.WritePropertyName("align"); jsonWriter.WriteValue(Align.ToString()); } - if (!string.IsNullOrEmpty(Color) && Color != "1 1 1 1") + if (!string.IsNullOrEmpty(Color)) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -928,25 +928,25 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("RectTransform"); - if (!string.IsNullOrEmpty(AnchorMin) && AnchorMin != "0 0") + if (!string.IsNullOrEmpty(AnchorMin)) { jsonWriter.WritePropertyName("anchormin"); jsonWriter.WriteValue(AnchorMin); } - if (!string.IsNullOrEmpty(AnchorMax) && AnchorMax != "1 1") + if (!string.IsNullOrEmpty(AnchorMax)) { jsonWriter.WritePropertyName("anchormax"); jsonWriter.WriteValue(AnchorMax); } - if (!string.IsNullOrEmpty(OffsetMin) && OffsetMin != "0 0") + if (!string.IsNullOrEmpty(OffsetMin)) { jsonWriter.WritePropertyName("offsetmin"); jsonWriter.WriteValue(OffsetMin); } - if (!string.IsNullOrEmpty(OffsetMax) && OffsetMax != "1 1") + if (!string.IsNullOrEmpty(OffsetMax)) { jsonWriter.WritePropertyName("offsetmax"); jsonWriter.WriteValue(OffsetMax); From 6f68a368b1964e272e5b0331548caff28a61e24b Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:42:13 +0300 Subject: [PATCH 04/23] Allow empty strings. --- src/RustCui.cs | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 6e7e7cb95..6c34de654 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -253,19 +253,19 @@ public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); - if (!string.IsNullOrEmpty(Name)) + if (Name != null) { jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(Name); } - if (!string.IsNullOrEmpty(Parent)) + if (Parent != null) { jsonWriter.WritePropertyName("parent"); jsonWriter.WriteValue(Parent); } - if (!string.IsNullOrEmpty(DestroyUi)) + if (DestroyUi != null) { jsonWriter.WritePropertyName("destroyUi"); jsonWriter.WriteValue(DestroyUi); @@ -351,13 +351,13 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Text"); - if (!string.IsNullOrEmpty(Text)) + if (Text != null) { jsonWriter.WritePropertyName("text"); jsonWriter.WriteValue(Text); } - if (!string.IsNullOrEmpty(Font)) + if (Font != null) { jsonWriter.WritePropertyName("font"); jsonWriter.WriteValue(Font); @@ -375,7 +375,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Align.ToString()); } - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -432,19 +432,19 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Image"); - if (!string.IsNullOrEmpty(Sprite)) + if (Sprite != null) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Material)) + if (Material != null) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); } - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -456,7 +456,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(ImageType.ToString()); } - if (!string.IsNullOrEmpty(Png)) + if (Png != null) { jsonWriter.WritePropertyName("png"); jsonWriter.WriteValue(Png); @@ -512,31 +512,31 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.RawImage"); - if (!string.IsNullOrEmpty(Sprite)) + if (Sprite != null) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); } - if (!string.IsNullOrEmpty(Material)) + if (Material != null) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); } - if (!string.IsNullOrEmpty(Url)) + if (Url != null) { jsonWriter.WritePropertyName("url"); jsonWriter.WriteValue(Url); } - if (!string.IsNullOrEmpty(Png)) + if (Png != null) { jsonWriter.WritePropertyName("png"); jsonWriter.WriteValue(Png); @@ -587,31 +587,31 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Button"); - if (!string.IsNullOrEmpty(Command)) + if (Command != null) { jsonWriter.WritePropertyName("command"); jsonWriter.WriteValue(Command); } - if (!string.IsNullOrEmpty(Close)) + if (Close != null) { jsonWriter.WritePropertyName("close"); jsonWriter.WriteValue(Close); } - if (!string.IsNullOrEmpty(Sprite)) + if (Sprite != null) { jsonWriter.WritePropertyName("sprite"); jsonWriter.WriteValue(Sprite); } - if (!string.IsNullOrEmpty(Material)) + if (Material != null) { jsonWriter.WritePropertyName("material"); jsonWriter.WriteValue(Material); } - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -655,13 +655,13 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.Outline"); - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); } - if (!string.IsNullOrEmpty(Distance)) + if (Distance != null) { jsonWriter.WritePropertyName("distance"); jsonWriter.WriteValue(Distance); @@ -732,7 +732,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("UnityEngine.UI.InputField"); - if (!string.IsNullOrEmpty(Text)) + if (Text != null) { jsonWriter.WritePropertyName("text"); jsonWriter.WriteValue(Text); @@ -744,7 +744,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(FontSize); } - if (!string.IsNullOrEmpty(Font)) + if (Font != null) { jsonWriter.WritePropertyName("font"); jsonWriter.WriteValue(Font); @@ -756,7 +756,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Align.ToString()); } - if (!string.IsNullOrEmpty(Color)) + if (Color != null) { jsonWriter.WritePropertyName("color"); jsonWriter.WriteValue(Color); @@ -768,7 +768,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(CharsLimit); } - if (!string.IsNullOrEmpty(Command)) + if (Command != null) { jsonWriter.WritePropertyName("command"); jsonWriter.WriteValue(Command); @@ -858,7 +858,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Step); } - if (!string.IsNullOrEmpty(Command)) + if (Command != null) { jsonWriter.WritePropertyName("command"); jsonWriter.WriteValue(Command); @@ -928,25 +928,25 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("RectTransform"); - if (!string.IsNullOrEmpty(AnchorMin)) + if (AnchorMin != null) { jsonWriter.WritePropertyName("anchormin"); jsonWriter.WriteValue(AnchorMin); } - if (!string.IsNullOrEmpty(AnchorMax)) + if (AnchorMax != null) { jsonWriter.WritePropertyName("anchormax"); jsonWriter.WriteValue(AnchorMax); } - if (!string.IsNullOrEmpty(OffsetMin)) + if (OffsetMin != null) { jsonWriter.WritePropertyName("offsetmin"); jsonWriter.WriteValue(OffsetMin); } - if (!string.IsNullOrEmpty(OffsetMax)) + if (OffsetMax != null) { jsonWriter.WritePropertyName("offsetmax"); jsonWriter.WriteValue(OffsetMax); From e46242eb50485bc628eb282a1599bb31bdb8f350 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 03:56:37 +0300 Subject: [PATCH 05/23] update for latest changes --- src/RustCui.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 6c34de654..5bbf782a1 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using TinyJSON; using UnityEngine; using UnityEngine.UI; @@ -49,7 +50,7 @@ public static bool AddUi(BasePlayer player, string json) { if (player?.net != null && Interface.CallHook("CanUseUI", player, json) == null) { - CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", json); + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Player("AddUI", player.net.connection), json); return true; } @@ -58,7 +59,7 @@ public static bool AddUi(BasePlayer player, string json) public static bool AddUi(List playerList, List elements) { - CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(playerList), null, "AddUI", ToJson(elements)); + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("AddUI", playerList), ToJson(elements)); return true; } @@ -73,7 +74,7 @@ public static bool AddUi(List playerList, string json) } } - CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo(connections), null, "AddUI", json); + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("AddUI", connections), json); return true; } @@ -84,7 +85,7 @@ public static bool DestroyUi(BasePlayer player, string elem) if (player?.net != null) { Interface.CallHook("OnDestroyUI", player, elem); - CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", elem); + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Player("DestroyUI", player.net.connection), elem); return true; } From 67289c08fd95f0b1eed108d528d7ebbfbf8e76fc Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 03:57:52 +0300 Subject: [PATCH 06/23] remove this --- src/RustCui.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 5bbf782a1..cdfe3f7cd 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using System.IO; using System.Text; -using TinyJSON; using UnityEngine; using UnityEngine.UI; From 0ee6ac1bd372833c6db9074d2c469512555188d0 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 04:30:16 +0300 Subject: [PATCH 07/23] add ScrollView (not tested) --- src/RustCui.cs | 216 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 210 insertions(+), 6 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index cdfe3f7cd..99ab1dd54 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -902,22 +902,54 @@ public void WriteJson(JsonWriter jsonWriter) } } - public class CuiRectTransformComponent : ICuiComponent + public class CuiRectTransformComponent : CuiRectTransform, ICuiComponent { public string Type => "RectTransform"; + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue("RectTransform"); + + if (AnchorMin != null) + { + jsonWriter.WritePropertyName("anchormin"); + jsonWriter.WriteValue(AnchorMin); + } + + if (AnchorMax != null) + { + jsonWriter.WritePropertyName("anchormax"); + jsonWriter.WriteValue(AnchorMax); + } + + if (OffsetMin != null) + { + jsonWriter.WritePropertyName("offsetmin"); + jsonWriter.WriteValue(OffsetMin); + } + + if (OffsetMax != null) + { + jsonWriter.WritePropertyName("offsetmax"); + jsonWriter.WriteValue(OffsetMax); + } + + jsonWriter.WriteEndObject(); + } + } + public class CuiRectTransform + { // The normalized position in the parent RectTransform that the lower left corner is anchored to [JsonProperty("anchormin")] public string AnchorMin { get; set; } - // The normalized position in the parent RectTransform that the upper right corner is anchored to [JsonProperty("anchormax")] public string AnchorMax { get; set; } - // The offset of the lower left corner of the rectangle relative to the lower left anchor [JsonProperty("offsetmin")] public string OffsetMin { get; set; } - // The offset of the upper right corner of the rectangle relative to the upper right anchor [JsonProperty("offsetmax")] public string OffsetMax { get; set; } @@ -925,8 +957,6 @@ public class CuiRectTransformComponent : ICuiComponent public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); - jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("RectTransform"); if (AnchorMin != null) { @@ -956,6 +986,176 @@ public void WriteJson(JsonWriter jsonWriter) } } + public class CuiScrollViewComponent : ICuiComponent + { + public string Type => "UnityEngine.UI.ScrollView"; + + [JsonProperty("contentTransform")] + public CuiRectTransform ContentTransform { get; set; } + + [JsonProperty("horizontal")] + public bool Horizontal { get; set; } + + [JsonProperty("vertical")] + public bool Vertical { get; set; } + + [JsonProperty("movementType")] + [JsonConverter(typeof(StringEnumConverter))] + public ScrollRect.MovementType MovementType { get; set; } + + [JsonProperty("elasticity")] + public float Elasticity { get; set; } + + [JsonProperty("inertia")] + public bool Inertia { get; set; } + + [JsonProperty("decelerationRate")] + public float DecelerationRate { get; set; } + + [JsonProperty("scrollSensitivity")] + public float ScrollSensitivity { get; set; } + + [JsonProperty("horizontalScrollbar")] + public CuiScrollbar HorizontalScrollbar { get; set; } + + [JsonProperty("verticalScrollbar")] + public CuiScrollbar VerticalScrollbar { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + if (Type != null) + { + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue(Type); + } + + jsonWriter.WritePropertyName("horizontal"); + jsonWriter.WriteValue(Horizontal); + + jsonWriter.WritePropertyName("vertical"); + jsonWriter.WriteValue(Vertical); + + jsonWriter.WritePropertyName("movementType"); + jsonWriter.WriteValue(MovementType.ToString()); + + jsonWriter.WritePropertyName("elasticity"); + jsonWriter.WriteValue(Elasticity); + + jsonWriter.WritePropertyName("inertia"); + jsonWriter.WriteValue(Inertia); + + jsonWriter.WritePropertyName("decelerationRate"); + jsonWriter.WriteValue(DecelerationRate); + + jsonWriter.WritePropertyName("scrollSensitivity"); + jsonWriter.WriteValue(ScrollSensitivity); + + if (ContentTransform != null) + { + jsonWriter.WritePropertyName("contentTransform"); + ContentTransform.WriteJson(jsonWriter); + } + + if (HorizontalScrollbar != null) + { + jsonWriter.WritePropertyName("horizontalScrollbar"); + HorizontalScrollbar.WriteJson(jsonWriter); + } + + if (VerticalScrollbar != null) + { + jsonWriter.WritePropertyName("verticalScrollbar"); + VerticalScrollbar.WriteJson(jsonWriter); + } + + jsonWriter.WriteEndObject(); + } + } + + public class CuiScrollbar + { + [JsonProperty("invert")] + public bool Invert { get; set; } + + [JsonProperty("autoHide")] + public bool AutoHide { get; set; } + + [JsonProperty("handleSprite")] + public string HandleSprite { get; set; } + + [JsonProperty("size")] + public float Size { get; set; } + + [JsonProperty("handleColor")] + public string HandleColor { get; set; } + + [JsonProperty("highlightColor")] + public string HighlightColor { get; set; } + + [JsonProperty("pressedColor")] + public string PressedColor { get; set; } + + [JsonProperty("trackSprite")] + public string TrackSprite { get; set; } + + [JsonProperty("trackColor")] + public string TrackColor { get; set; } + + public void WriteJson(JsonWriter jsonWriter) + { + jsonWriter.WriteStartObject(); + + jsonWriter.WritePropertyName("invert"); + jsonWriter.WriteValue(Invert); + + jsonWriter.WritePropertyName("autoHide"); + jsonWriter.WriteValue(AutoHide); + + if (HandleSprite != null) + { + jsonWriter.WritePropertyName("handleSprite"); + jsonWriter.WriteValue(HandleSprite); + } + + jsonWriter.WritePropertyName("size"); + jsonWriter.WriteValue(Size); + + if (HandleColor != null) + { + jsonWriter.WritePropertyName("handleColor"); + jsonWriter.WriteValue(HandleColor); + } + + if (HighlightColor != null) + { + jsonWriter.WritePropertyName("highlightColor"); + jsonWriter.WriteValue(HighlightColor); + } + + if (PressedColor != null) + { + jsonWriter.WritePropertyName("pressedColor"); + jsonWriter.WriteValue(PressedColor); + } + + if (TrackSprite != null) + { + jsonWriter.WritePropertyName("trackSprite"); + jsonWriter.WriteValue(TrackSprite); + } + + if (TrackColor != null) + { + jsonWriter.WritePropertyName("trackColor"); + jsonWriter.WriteValue(TrackColor); + } + + jsonWriter.WriteEndObject(); + } + } + public class ComponentConverter : JsonConverter { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) @@ -1011,6 +1211,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist type = typeof(CuiRectTransformComponent); break; + case "UnityEngine.UI.ScrollView": + type = typeof(CuiScrollViewComponent); + break; + default: return null; } From 3cc3dbf3ec4a01033d34dceabbb548b619dd8e32 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 04:38:56 +0300 Subject: [PATCH 08/23] Fixes for the ability to update the interfaces with default values. --- src/RustCui.cs | 184 ++++++++++++++----------------------------------- 1 file changed, 53 insertions(+), 131 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 99ab1dd54..90dfc36d5 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -271,11 +271,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(DestroyUi); } - if (FadeOut != 0f) - { - jsonWriter.WritePropertyName("fadeOut"); - jsonWriter.WriteValue(FadeOut); - } + jsonWriter.WritePropertyName("fadeOut"); + jsonWriter.WriteValue(FadeOut); if (Update) { @@ -363,17 +360,11 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Font); } - if (FontSize != 0) - { - jsonWriter.WritePropertyName("fontSize"); - jsonWriter.WriteValue(FontSize); - } + jsonWriter.WritePropertyName("fontSize"); + jsonWriter.WriteValue(FontSize); - if (Align != default(TextAnchor)) - { - jsonWriter.WritePropertyName("align"); - jsonWriter.WriteValue(Align.ToString()); - } + jsonWriter.WritePropertyName("align"); + jsonWriter.WriteValue(Align.ToString()); if (Color != null) { @@ -381,17 +372,11 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Color); } - if (VerticalOverflow != VerticalWrapMode.Truncate) - { - jsonWriter.WritePropertyName("verticalOverflow"); - jsonWriter.WriteValue(VerticalOverflow.ToString()); - } + jsonWriter.WritePropertyName("verticalOverflow"); + jsonWriter.WriteValue(VerticalOverflow.ToString()); - if (FadeIn > 0f) - { - jsonWriter.WritePropertyName("fadeIn"); - jsonWriter.WriteValue(FadeIn); - } + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); jsonWriter.WriteEndObject(); } @@ -450,11 +435,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Color); } - if (ImageType != default(Image.Type)) - { - jsonWriter.WritePropertyName("imagetype"); - jsonWriter.WriteValue(ImageType.ToString()); - } + jsonWriter.WritePropertyName("imagetype"); + jsonWriter.WriteValue(ImageType.ToString()); if (Png != null) { @@ -462,23 +444,14 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Png); } - if (FadeIn > 0f) - { - jsonWriter.WritePropertyName("fadeIn"); - jsonWriter.WriteValue(FadeIn); - } + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); - if (ItemId != 0) - { - jsonWriter.WritePropertyName("itemid"); - jsonWriter.WriteValue(ItemId); - } + jsonWriter.WritePropertyName("itemid"); + jsonWriter.WriteValue(ItemId); - if (SkinId != 0) - { - jsonWriter.WritePropertyName("skinid"); - jsonWriter.WriteValue(SkinId); - } + jsonWriter.WritePropertyName("skinid"); + jsonWriter.WriteValue(SkinId); jsonWriter.WriteEndObject(); } @@ -542,11 +515,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Png); } - if (FadeIn > 0f) - { - jsonWriter.WritePropertyName("fadeIn"); - jsonWriter.WriteValue(FadeIn); - } + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); jsonWriter.WriteEndObject(); } @@ -617,17 +587,11 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Color); } - if (ImageType != default(Image.Type)) - { - jsonWriter.WritePropertyName("imagetype"); - jsonWriter.WriteValue(ImageType.ToString()); - } + jsonWriter.WritePropertyName("imagetype"); + jsonWriter.WriteValue(ImageType.ToString()); - if (FadeIn > 0f) - { - jsonWriter.WritePropertyName("fadeIn"); - jsonWriter.WriteValue(FadeIn); - } + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); jsonWriter.WriteEndObject(); } @@ -667,11 +631,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Distance); } - if (UseGraphicAlpha) - { - jsonWriter.WritePropertyName("useGraphicAlpha"); - jsonWriter.WriteValue(UseGraphicAlpha); - } + jsonWriter.WritePropertyName("useGraphicAlpha"); + jsonWriter.WriteValue(UseGraphicAlpha); jsonWriter.WriteEndObject(); } @@ -738,11 +699,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Text); } - if (FontSize != 0) - { - jsonWriter.WritePropertyName("fontSize"); - jsonWriter.WriteValue(FontSize); - } + jsonWriter.WritePropertyName("fontSize"); + jsonWriter.WriteValue(FontSize); if (Font != null) { @@ -750,11 +708,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Font); } - if (Align != default(TextAnchor)) - { - jsonWriter.WritePropertyName("align"); - jsonWriter.WriteValue(Align.ToString()); - } + jsonWriter.WritePropertyName("align"); + jsonWriter.WriteValue(Align.ToString()); if (Color != null) { @@ -762,11 +717,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Color); } - if (CharsLimit != 0) - { - jsonWriter.WritePropertyName("characterLimit"); - jsonWriter.WriteValue(CharsLimit); - } + jsonWriter.WritePropertyName("characterLimit"); + jsonWriter.WriteValue(CharsLimit); if (Command != null) { @@ -774,41 +726,23 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Command); } - if (IsPassword) - { - jsonWriter.WritePropertyName("password"); - jsonWriter.WriteValue(IsPassword); - } + jsonWriter.WritePropertyName("password"); + jsonWriter.WriteValue(IsPassword); - if (ReadOnly) - { - jsonWriter.WritePropertyName("readOnly"); - jsonWriter.WriteValue(ReadOnly); - } + jsonWriter.WritePropertyName("readOnly"); + jsonWriter.WriteValue(ReadOnly); - if (NeedsKeyboard) - { - jsonWriter.WritePropertyName("needsKeyboard"); - jsonWriter.WriteValue(NeedsKeyboard); - } + jsonWriter.WritePropertyName("needsKeyboard"); + jsonWriter.WriteValue(NeedsKeyboard); - if (LineType != default(InputField.LineType)) - { - jsonWriter.WritePropertyName("lineType"); - jsonWriter.WriteValue(LineType.ToString()); - } + jsonWriter.WritePropertyName("lineType"); + jsonWriter.WriteValue(LineType.ToString()); - if (Autofocus) - { - jsonWriter.WritePropertyName("autofocus"); - jsonWriter.WriteValue(Autofocus); - } + jsonWriter.WritePropertyName("autofocus"); + jsonWriter.WriteValue(Autofocus); - if (HudMenuInput) - { - jsonWriter.WritePropertyName("hudMenuInput"); - jsonWriter.WriteValue(HudMenuInput); - } + jsonWriter.WritePropertyName("hudMenuInput"); + jsonWriter.WriteValue(HudMenuInput); jsonWriter.WriteEndObject(); } @@ -840,23 +774,14 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue("Countdown"); - if (EndTime != 0) - { - jsonWriter.WritePropertyName("endTime"); - jsonWriter.WriteValue(EndTime); - } + jsonWriter.WritePropertyName("endTime"); + jsonWriter.WriteValue(EndTime); - if (StartTime != 0) - { - jsonWriter.WritePropertyName("startTime"); - jsonWriter.WriteValue(StartTime); - } + jsonWriter.WritePropertyName("startTime"); + jsonWriter.WriteValue(StartTime); - if (Step != 1) - { - jsonWriter.WritePropertyName("step"); - jsonWriter.WriteValue(Step); - } + jsonWriter.WritePropertyName("step"); + jsonWriter.WriteValue(Step); if (Command != null) { @@ -864,11 +789,8 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteValue(Command); } - if (FadeIn > 0f) - { - jsonWriter.WritePropertyName("fadeIn"); - jsonWriter.WriteValue(FadeIn); - } + jsonWriter.WritePropertyName("fadeIn"); + jsonWriter.WriteValue(FadeIn); jsonWriter.WriteEndObject(); } @@ -905,7 +827,7 @@ public void WriteJson(JsonWriter jsonWriter) public class CuiRectTransformComponent : CuiRectTransform, ICuiComponent { public string Type => "RectTransform"; - public void WriteJson(JsonWriter jsonWriter) + public new void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); From 845c44636f31f5805832e9e32e692fa258aa726a Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 05:10:21 +0300 Subject: [PATCH 09/23] fix --- src/RustCui.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 90dfc36d5..d07050053 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -947,11 +947,8 @@ public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); - if (Type != null) - { - jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue(Type); - } + jsonWriter.WritePropertyName("type"); + jsonWriter.WriteValue(Type); jsonWriter.WritePropertyName("horizontal"); jsonWriter.WriteValue(Horizontal); From 5af0886e5cd31be31c898dc0c50c9f8e9e555657 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 05:12:54 +0300 Subject: [PATCH 10/23] fix --- src/RustCui.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index d07050053..96394a4eb 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -346,7 +346,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.Text"); + jsonWriter.WriteValue(Type); if (Text != null) { @@ -415,7 +415,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.Image"); + jsonWriter.WriteValue(Type); if (Sprite != null) { @@ -483,7 +483,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.RawImage"); + jsonWriter.WriteValue(Type); if (Sprite != null) { @@ -555,7 +555,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.Button"); + jsonWriter.WriteValue(Type); if (Command != null) { @@ -617,7 +617,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.Outline"); + jsonWriter.WriteValue(Type); if (Color != null) { @@ -691,7 +691,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("UnityEngine.UI.InputField"); + jsonWriter.WriteValue(Type); if (Text != null) { @@ -772,7 +772,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("Countdown"); + jsonWriter.WriteValue(Type); jsonWriter.WritePropertyName("endTime"); jsonWriter.WriteValue(EndTime); @@ -804,7 +804,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("NeedsCursor"); + jsonWriter.WriteValue(Type); jsonWriter.WriteEndObject(); } @@ -818,7 +818,7 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("NeedsKeyboard"); + jsonWriter.WriteValue(Type); jsonWriter.WriteEndObject(); } @@ -831,7 +831,7 @@ public class CuiRectTransformComponent : CuiRectTransform, ICuiComponent { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); - jsonWriter.WriteValue("RectTransform"); + jsonWriter.WriteValue(Type); if (AnchorMin != null) { From 05c6e90c1b3d9f37641a3e325b8c4eb6b1aef0bb Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Tue, 30 Apr 2024 05:17:33 +0300 Subject: [PATCH 11/23] add pooling --- src/RustCui.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 96394a4eb..c5fa7eb28 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -64,7 +64,7 @@ public static bool AddUi(List playerList, List e public static bool AddUi(List playerList, string json) { - List connections = new List(); + List connections = Facepunch.Pool.GetList(); foreach (var player in playerList) { if (player?.net != null) @@ -73,7 +73,14 @@ public static bool AddUi(List playerList, string json) } } + if(connections.Count == 0) + { + Facepunch.Pool.FreeList(ref connections); + return false; + } + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("AddUI", connections), json); + Facepunch.Pool.FreeList(ref connections); return true; } From 078e9b81456ba5be3d29b6ec616fc72852551ca4 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:06:37 +0300 Subject: [PATCH 12/23] Improved Countdown support to CuiHelper #529 --- src/RustCui.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index c5fa7eb28..e8c64a344 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -760,13 +760,26 @@ public class CuiCountdownComponent : ICuiComponent public string Type => "Countdown"; [JsonProperty("endTime")] - public int EndTime { get; set; } + public float EndTime { get; set; } [JsonProperty("startTime")] - public int StartTime { get; set; } + public float StartTime { get; set; } [JsonProperty("step")] - public int Step { get; set; } + public float Step { get; set; } + + [JsonProperty("interval")] + public float Interval { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + [JsonProperty("timerFormat")] + public TimerFormatEnum TimerFormat { get; set; } + + [JsonProperty("numberFormat")] + public string NumberFormat { get; set; } + + [JsonProperty("destroyIfDone")] + public bool DestroyIfDone { get; set; } [JsonProperty("command")] public string Command { get; set; } @@ -774,6 +787,16 @@ public class CuiCountdownComponent : ICuiComponent [JsonProperty("fadeIn")] public float FadeIn { get; set; } + public enum TimerFormatEnum + { + None, + SecondsHundreth, + MinutesSeconds, + MinutesSecondsHundreth, + HoursMinutes, + HoursMinutesSeconds + } + public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); From f63ee57a6999f7450f76bd75436d13361e434352 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:08:30 +0300 Subject: [PATCH 13/23] fix --- src/RustCui.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/RustCui.cs b/src/RustCui.cs index e8c64a344..0197e7b2c 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -813,6 +813,22 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("step"); jsonWriter.WriteValue(Step); + jsonWriter.WritePropertyName("interval"); + jsonWriter.WriteValue(Interval); + + jsonWriter.WritePropertyName("timerFormat"); + jsonWriter.WriteValue(TimerFormat.ToString()); + + if (NumberFormat != null) + { + jsonWriter.WritePropertyName("numberFormat"); + jsonWriter.WriteValue(NumberFormat); + } + + jsonWriter.WritePropertyName("destroyIfDone"); + jsonWriter.WriteValue(DestroyIfDone); + + if (Command != null) { jsonWriter.WritePropertyName("command"); From 12b66fd001a1c5664a70cb56a8ffea179c86d2b1 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Fri, 26 Jul 2024 22:09:48 +0300 Subject: [PATCH 14/23] destroy for list --- src/RustCui.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/RustCui.cs b/src/RustCui.cs index 0197e7b2c..8010d9c96 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -98,6 +98,34 @@ public static bool DestroyUi(BasePlayer player, string elem) return false; } + public static bool DestroyUi(List playerList, string elem) + { + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("DestroyUI", playerList), elem); + return true; + } + + public static bool DestroyUi(List playerList, string elem) + { + List connections = Facepunch.Pool.GetList(); + foreach (var player in playerList) + { + if (player?.net != null) + { + connections.Add(player.net.connection); + } + } + + if (connections.Count == 0) + { + Facepunch.Pool.FreeList(ref connections); + return false; + } + + CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("DestroyUI", connections), elem); + Facepunch.Pool.FreeList(ref connections); + return true; + } + public static void SetColor(this ICuiColor elem, Color color) { elem.Color = $"{color.r} {color.g} {color.b} {color.a}"; From b2e5b90b313a8f31986f2cd3cc73df0653619a2d Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:47:02 +0300 Subject: [PATCH 15/23] fix --- src/RustCui.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 8010d9c96..d27bf86e6 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -801,7 +801,7 @@ public class CuiCountdownComponent : ICuiComponent [JsonConverter(typeof(StringEnumConverter))] [JsonProperty("timerFormat")] - public TimerFormatEnum TimerFormat { get; set; } + public TimerFormat TimerFormat { get; set; } [JsonProperty("numberFormat")] public string NumberFormat { get; set; } @@ -815,16 +815,6 @@ public class CuiCountdownComponent : ICuiComponent [JsonProperty("fadeIn")] public float FadeIn { get; set; } - public enum TimerFormatEnum - { - None, - SecondsHundreth, - MinutesSeconds, - MinutesSecondsHundreth, - HoursMinutes, - HoursMinutesSeconds - } - public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); @@ -870,6 +860,16 @@ public void WriteJson(JsonWriter jsonWriter) } } + public enum TimerFormat + { + None, + SecondsHundreth, + MinutesSeconds, + MinutesSecondsHundreth, + HoursMinutes, + HoursMinutesSeconds + } + public class CuiNeedsCursorComponent : ICuiComponent { public string Type => "NeedsCursor"; From 4c391e3a2f41637b7f9f68e524055e768d1d6efa Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Fri, 1 Nov 2024 04:25:39 +0300 Subject: [PATCH 16/23] update --- src/RustCui.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index d27bf86e6..3b45447d2 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -41,7 +41,7 @@ public static string ToJson(List elements, bool format = false) public static List FromJson(string json) => JsonConvert.DeserializeObject>(json); - public static string GetGuid() => Guid.NewGuid().ToString().Replace("-", string.Empty); + public static string GetGuid() => Guid.NewGuid().ToString("N"); public static bool AddUi(BasePlayer player, List elements) => AddUi(player, ToJson(elements)); @@ -445,6 +445,9 @@ public class CuiImageComponent : ICuiComponent, ICuiColor [JsonProperty("skinid")] public ulong SkinId { get; set; } + [JsonProperty("steamid")] + public ulong SteamId { get; set; } // Community PR #61 + public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); @@ -488,6 +491,9 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("skinid"); jsonWriter.WriteValue(SkinId); + jsonWriter.WritePropertyName("steamid"); + jsonWriter.WriteValue(SteamId); + jsonWriter.WriteEndObject(); } } From c8e494602b996fab0b39fff797a4fd80e0b937c5 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:52:55 +0300 Subject: [PATCH 17/23] update --- src/RustCui.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 3b45447d2..7bb9bc2e7 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -873,7 +873,12 @@ public enum TimerFormat MinutesSeconds, MinutesSecondsHundreth, HoursMinutes, - HoursMinutesSeconds + HoursMinutesSeconds, + HoursMinutesSecondsMilliseconds, + HoursMinutesSecondsTenths, + DaysHoursMinutes, + DaysHoursMinutesSeconds, + Custom } public class CuiNeedsCursorComponent : ICuiComponent From 85260f743322df556398511abfe1f19877082963 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:08:17 +0300 Subject: [PATCH 18/23] fix --- src/RustCui.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 7bb9bc2e7..76980732c 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -446,7 +446,7 @@ public class CuiImageComponent : ICuiComponent, ICuiColor public ulong SkinId { get; set; } [JsonProperty("steamid")] - public ulong SteamId { get; set; } // Community PR #61 + public string SteamId { get; set; } // Community PR #61 public void WriteJson(JsonWriter jsonWriter) { From 8f3776d0631b322ecb18e3198f1741a87e8013b2 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:14:15 +0300 Subject: [PATCH 19/23] fix --- src/RustCui.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 76980732c..04ddbf980 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -4,6 +4,7 @@ using References::Newtonsoft.Json; using References::Newtonsoft.Json.Converters; using References::Newtonsoft.Json.Linq; +using Steamworks; using System; using System.Collections.Generic; using System.IO; @@ -445,9 +446,6 @@ public class CuiImageComponent : ICuiComponent, ICuiColor [JsonProperty("skinid")] public ulong SkinId { get; set; } - [JsonProperty("steamid")] - public string SteamId { get; set; } // Community PR #61 - public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); @@ -491,9 +489,6 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("skinid"); jsonWriter.WriteValue(SkinId); - jsonWriter.WritePropertyName("steamid"); - jsonWriter.WriteValue(SteamId); - jsonWriter.WriteEndObject(); } } @@ -519,6 +514,9 @@ public class CuiRawImageComponent : ICuiComponent, ICuiColor [JsonProperty("fadeIn")] public float FadeIn { get; set; } + [JsonProperty("steamid")] + public string SteamId { get; set; } // Community PR #61 + public void WriteJson(JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); @@ -559,6 +557,9 @@ public void WriteJson(JsonWriter jsonWriter) jsonWriter.WritePropertyName("fadeIn"); jsonWriter.WriteValue(FadeIn); + jsonWriter.WritePropertyName("steamid"); + jsonWriter.WriteValue(SteamId); + jsonWriter.WriteEndObject(); } } From b9f5b0297b678af6b73d0fde3bd8fe3a48d94913 Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:14:34 +0300 Subject: [PATCH 20/23] fixed fix --- src/RustCui.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 04ddbf980..92a1f1e4d 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -4,7 +4,6 @@ using References::Newtonsoft.Json; using References::Newtonsoft.Json.Converters; using References::Newtonsoft.Json.Linq; -using Steamworks; using System; using System.Collections.Generic; using System.IO; From 151762d18c9d288b5eb224b68eb2a46ed9ac7d0f Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:22:39 +0300 Subject: [PATCH 21/23] pooling --- src/RustCui.cs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 92a1f1e4d..9a314ded5 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -17,25 +17,33 @@ public static class CuiHelper { public static string ToJson(List elements, bool format = false) { - StringBuilder stringBuilder = new StringBuilder(); - using (StringWriter stringWriter = new StringWriter(stringBuilder)) + StringBuilder stringBuilder = Facepunch.Pool.Get(); + stringBuilder.Clear(); // As far as I remember the stringbuilder in the pool is not cleared. + try { - using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter)) + using (StringWriter stringWriter = new StringWriter(stringBuilder)) { - jsonWriter.Formatting = Formatting.None; - - if (elements.Count > 0) + using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter)) { - jsonWriter.WriteStartArray(); - foreach (var element in elements) + jsonWriter.Formatting = Formatting.None; + + if (elements.Count > 0) { - element.WriteJson(jsonWriter); + jsonWriter.WriteStartArray(); + foreach (var element in elements) + { + element.WriteJson(jsonWriter); + } + jsonWriter.WriteEndArray(); } - jsonWriter.WriteEndArray(); } } + return stringBuilder.Replace("\\n", "\n").ToString(); + } + finally + { + Facepunch.Pool.FreeUnmanaged(ref stringBuilder); } - return stringBuilder.Replace("\\n", "\n").ToString(); } From f861b829465f41fb21a4e1a67c7a0a6743a79cec Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:23:54 +0300 Subject: [PATCH 22/23] fix --- src/RustCui.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index f780c7276..9a314ded5 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -889,21 +889,6 @@ public enum TimerFormat Custom } - public enum TimerFormat - { - None, - SecondsHundreth, - MinutesSeconds, - MinutesSecondsHundreth, - HoursMinutes, - HoursMinutesSeconds, - HoursMinutesSecondsMilliseconds, - HoursMinutesSecondsTenths, - DaysHoursMinutes, - DaysHoursMinutesSeconds, - Custom - } - public class CuiNeedsCursorComponent : ICuiComponent { public string Type => "NeedsCursor"; From fd4e03f19d0f2e7dff4282df5edb167476405f3a Mon Sep 17 00:00:00 2001 From: SkiTee3000 <39069192+SkiTee3000@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:25:50 +0300 Subject: [PATCH 23/23] update --- src/RustCui.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RustCui.cs b/src/RustCui.cs index 9a314ded5..829afa735 100644 --- a/src/RustCui.cs +++ b/src/RustCui.cs @@ -72,7 +72,7 @@ public static bool AddUi(List playerList, List e public static bool AddUi(List playerList, string json) { - List connections = Facepunch.Pool.GetList(); + List connections = Facepunch.Pool.Get>(); foreach (var player in playerList) { if (player?.net != null) @@ -83,12 +83,12 @@ public static bool AddUi(List playerList, string json) if(connections.Count == 0) { - Facepunch.Pool.FreeList(ref connections); + Facepunch.Pool.FreeUnmanaged(ref connections); return false; } CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("AddUI", connections), json); - Facepunch.Pool.FreeList(ref connections); + Facepunch.Pool.FreeUnmanaged(ref connections); return true; } @@ -114,7 +114,7 @@ public static bool DestroyUi(List playerList, string elem) public static bool DestroyUi(List playerList, string elem) { - List connections = Facepunch.Pool.GetList(); + List connections = Facepunch.Pool.Get>(); foreach (var player in playerList) { if (player?.net != null) @@ -125,12 +125,12 @@ public static bool DestroyUi(List playerList, string elem) if (connections.Count == 0) { - Facepunch.Pool.FreeList(ref connections); + Facepunch.Pool.FreeUnmanaged(ref connections); return false; } CommunityEntity.ServerInstance.ClientRPC(RpcTarget.Players("DestroyUI", connections), elem); - Facepunch.Pool.FreeList(ref connections); + Facepunch.Pool.FreeUnmanaged(ref connections); return true; }