diff --git a/Essentials/Essentials.csproj b/Essentials/Essentials.csproj
index 03108b2..6228666 100644
--- a/Essentials/Essentials.csproj
+++ b/Essentials/Essentials.csproj
@@ -2,7 +2,7 @@
netstandard2.1
latest
- 0.2.0-dev.7
+ 0.2.0-dev.8
Among Us modding essentials
CoMaNdO
@@ -14,7 +14,7 @@
true
1701;1702;
- $(AmongUs_2020-12-9)
+ $(AmongUs_2020-12-9s)
NuclearPowered/Mappings:0.1.3
2020.12.9s
@@ -24,6 +24,7 @@
true
1701;1702;
+ $(AmongUs_2021-3-5s)
NuclearPowered/Mappings:0.2.0
2021.3.5s
@@ -39,7 +40,7 @@
-
+
diff --git a/Essentials/Options/CustomOption.Button.cs b/Essentials/Options/CustomOption.Button.cs
new file mode 100644
index 0000000..fa1a47a
--- /dev/null
+++ b/Essentials/Options/CustomOption.Button.cs
@@ -0,0 +1,104 @@
+using Essentials.Extensions;
+using System;
+
+namespace Essentials.Options
+{
+ ///
+ /// A derivative of , handling "buttons" in the options menu.
+ ///
+ public class CustomOptionButton : CustomOption, IToggleOption
+ {
+ public override bool SendRpc { get { return false; } }
+
+ ///
+ /// Adds an option header.
+ ///
+ /// The title of the header
+ /// The button will be visible in the lobby options menu
+ /// The button title will appear in the HUD (option list) in the lobby
+ /// The button's initial (client sided) value, can be used to hide/show other options
+ public CustomOptionButton(string title, bool menu = true, bool hud = false, bool initialValue = false) : base(title, title, false, CustomOptionType.Toggle, initialValue)
+ {
+ HudStringFormat = (_, name, _) => name;
+
+ MenuVisible = menu;
+ HudVisible = hud;
+ }
+
+ protected override bool GameOptionCreated(OptionBehaviour o)
+ {
+ if (o is ToggleOption toggle)
+ {
+ toggle.TitleText.Text = GetFormattedName();
+
+ toggle.CheckMark.enabled = toggle.oldValue = false;
+
+ toggle.transform.FindChild("CheckBox")?.gameObject?.SetActive(false);
+
+ return true;
+ }
+ else if (o is StringOption str) // Display options in menu for non-host
+ {
+ str.TitleText.Text = GetFormattedName();
+
+ str.Value = str.oldValue = 0;
+
+ str.ValueText.Text = GetFormattedValue();
+
+ return true;
+ }
+
+ return false;
+ }
+
+ ///
+ /// Toggles the option value (called when the button is pressed).
+ ///
+ public virtual void Toggle()
+ {
+ SetValue(!GetValue());
+ }
+
+ ///
+ /// Sets a new value
+ ///
+ /// The new value
+ public virtual void SetValue(bool value)
+ {
+ SetValue(value, true);
+ }
+
+ /// The boolean-casted default value.
+ public virtual bool GetDefaultValue()
+ {
+ return GetDefaultValue();
+ }
+
+ /// The boolean-casted old value.
+ public virtual bool GetOldValue()
+ {
+ return GetOldValue();
+ }
+
+ /// The boolean-casted current value.
+ public virtual bool GetValue()
+ {
+ return GetValue();
+ }
+ }
+
+ public partial class CustomOption
+ {
+ ///
+ /// Adds a "button" in the options menu.
+ ///
+ /// The title of the button
+ /// The button will be visible in the lobby options menu
+ /// The button title will appear in the HUD (option list) in the lobby
+ /// The button's initial (client sided) value, can be used to hide/show other options
+ public static CustomOptionButton AddButton(string title, bool menu = true, bool hud = false, bool initialValue = false)
+ {
+ return new CustomOptionButton(title, menu, hud, initialValue);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Essentials/Options/CustomOption.Header.cs b/Essentials/Options/CustomOption.Header.cs
index 5b6377a..0e28483 100644
--- a/Essentials/Options/CustomOption.Header.cs
+++ b/Essentials/Options/CustomOption.Header.cs
@@ -1,41 +1,36 @@
namespace Essentials.Options
{
///
- /// A derivative of , handling option headers.
+ /// A derivative of , handling option headers.
///
- public class CustomOptionHeader : CustomOption
+ public class CustomOptionHeader : CustomOptionButton
{
- public override bool SendRpc { get { return false; } }
-
///
/// Adds an option header.
///
/// The title of the header
/// The header will be visible in the lobby options menu
- /// The header will appear in the option list in the lobby
- public CustomOptionHeader(string title, bool menu = true, bool hud = true) : base(title, title, false, CustomOptionType.Toggle, false)
+ /// The header will appear in the HUD (option list) in the lobby
+ /// The header's initial (client sided) value, can be used to hide/show other options
+ public CustomOptionHeader(string title, bool menu = true, bool hud = true, bool initialValue = false) : base(title, menu, hud, initialValue)
{
- OnValueChanged += (sender, args) =>
- {
- args.Cancel = true;
- };
-
- ToStringFormat = (_, name, _) => name;
-
- MenuVisible = menu;
- HudVisible = hud;
}
- protected override void GameOptionCreated(OptionBehaviour o)
+ protected override bool GameOptionCreated(OptionBehaviour o)
{
- if (o is not ToggleOption toggle) return;
+ if (!base.GameOptionCreated(o)) return false;
- toggle.TitleText.Text = GetFormattedName();
+ if (o is ToggleOption toggle) toggle.transform.FindChild("Background")?.gameObject?.SetActive(false);
- toggle.CheckMark.enabled = toggle.oldValue = false;
+ return true;
+ }
- toggle.transform.FindChild("Background")?.gameObject?.SetActive(false);
- toggle.transform.FindChild("CheckBox")?.gameObject?.SetActive(false);
+ ///
+ /// Toggles the option value (called when the header is pressed).
+ ///
+ public override void Toggle()
+ {
+ base.Toggle();
}
}
@@ -46,10 +41,11 @@ public partial class CustomOption
///
/// The title of the header
/// The header will be visible in the lobby options menu
- /// The header will appear in the option list in the lobby
- public static CustomOptionHeader AddHeader(string title, bool menu = true, bool hud = true)
+ /// The header will appear in the HUD (option list) in the lobby
+ /// The header's initial (client sided) value, can be used to hide/show other options
+ public static CustomOptionHeader AddHeader(string title, bool menu = true, bool hud = true, bool initialValue = false)
{
- return new CustomOptionHeader(title, menu, hud);
+ return new CustomOptionHeader(title, menu, hud, initialValue);
}
}
}
\ No newline at end of file
diff --git a/Essentials/Options/CustomOption.Number.cs b/Essentials/Options/CustomOption.Number.cs
index ed4750c..57237c5 100644
--- a/Essentials/Options/CustomOption.Number.cs
+++ b/Essentials/Options/CustomOption.Number.cs
@@ -70,7 +70,7 @@ public CustomNumberOption(string id, string name, bool saveValue, float value, f
ConfigEntry = saveValue ? EssentialsPlugin.Instance.Config.Bind(PluginID, ConfigID, GetDefaultValue()) : null;
SetValue(ConfigEntry == null ? GetDefaultValue() : ConfigEntry.Value, false);
- StringFormat = (sender, value) => value.ToString();
+ ValueStringFormat = (sender, value) => value.ToString();
}
protected override OptionOnValueChangedEventArgs OnValueChangedEventArgs(object value, object oldValue)
@@ -83,9 +83,9 @@ protected override OptionValueChangedEventArgs ValueChangedEventArgs(object valu
return new NumberOptionValueChangedEventArgs(value, Value);
}
- protected override void GameOptionCreated(OptionBehaviour o)
+ protected override bool GameOptionCreated(OptionBehaviour o)
{
- if (o is not NumberOption number) return;
+ if (o is not NumberOption number) return false;
number.TitleText.Text = GetFormattedName();
number.ValidRange = new FloatRange(Min, Max);
@@ -96,6 +96,8 @@ protected override void GameOptionCreated(OptionBehaviour o)
number.Value = number.Field_3 = GetValue();
#endif
number.ValueText.Text = GetFormattedValue();
+
+ return true;
}
///
diff --git a/Essentials/Options/CustomOption.Patches.cs b/Essentials/Options/CustomOption.Patches.cs
index ff2f42c..862fa0c 100644
--- a/Essentials/Options/CustomOption.Patches.cs
+++ b/Essentials/Options/CustomOption.Patches.cs
@@ -49,7 +49,12 @@ private static List GetGameOptions(float lowestY)
ToggleOption toggle = Object.Instantiate(toggleOption, toggleOption.transform.parent);//.DontDestroy();
- option.OnGameOptionCreated(toggle);
+ if (!option.OnGameOptionCreated(toggle))
+ {
+ toggle.Destroy();
+
+ continue;
+ }
options.Add(toggle);
@@ -61,7 +66,12 @@ private static List GetGameOptions(float lowestY)
NumberOption number = Object.Instantiate(numberOption, numberOption.transform.parent);//.DontDestroy();
- option.OnGameOptionCreated(number);
+ if (!option.OnGameOptionCreated(number))
+ {
+ number.Destroy();
+
+ continue;
+ }
options.Add(number);
@@ -94,7 +104,12 @@ private static List GetGameOptions(float lowestY)
StringOption str = Object.Instantiate(stringOption, stringOption.transform.parent);//.DontDestroy();
- option.OnGameOptionCreated(str);
+ if (!option.OnGameOptionCreated(str))
+ {
+ str.Destroy();
+
+ continue;
+ }
options.Add(str);
@@ -166,7 +181,7 @@ private static IEnumerable TargetMethods()
private static void Postfix(ref string __result)
{
int firstNewline = __result.IndexOf('\n');
- StringBuilder sb = new StringBuilder(ClearDefaultLobbyText ? __result.Substring(0, firstNewline + 1) : __result);
+ StringBuilder sb = new StringBuilder(ClearDefaultHudText ? __result.Substring(0, firstNewline + 1) : __result);
if (ShamelessPlug) sb.AppendLine("[FF1111FF]DorCoMaNdO on GitHub/Twitter/Twitch[]");
foreach (CustomOption option in Options) if (option.HudVisible) sb.AppendLine(option.ToString());
@@ -174,7 +189,7 @@ private static void Postfix(ref string __result)
__result = sb.ToString();
string insert = ":";
- if (LobbyTextScroller && (HudManager.Instance?.GameSettings?.Height).GetValueOrDefault() + 0.02F > HudPosition.Height) insert = " (Scroll for more):";
+ if (HudTextScroller && (HudManager.Instance?.GameSettings?.Height).GetValueOrDefault() + 0.02F > HudPosition.Height) insert = " (Scroll for more):";
__result = __result.Insert(firstNewline, insert);
// Remove last newline (for the scroller to not overscroll one line)
@@ -293,7 +308,8 @@ public static void Postfix()
if (AmongUsClient.Instance?.AmHost != true || PlayerControl.AllPlayerControls.Count < 2 || !PlayerControl.LocalPlayer) return;
//Rpc.Send(Options.Where(o => o.SendRpc).Select(o => ((string, CustomOptionType, object))o).ToArray());
- foreach (CustomOption option in Options) if (option.SendRpc) Rpc.Instance.Send(option);
+ foreach (CustomOption option in Options) if (option.SendRpc) Rpc.Instance.Send(option, true);
+ //Rpc.Instance.Send(Options.Where(o => o.SendRpc).Select(o => ((int, CustomOptionType, object))o).ToArray());
}
}
@@ -308,12 +324,12 @@ private static void UpdateScroller(object sender, EventArgs e)
if (hudManager?.GameSettings?.transform == null) return;
- hudManager.GameSettings.scale = LobbyTextScale;
+ hudManager.GameSettings.scale = HudTextScale;
const float XOffset = 0.066666F, YOffset = 0.1F;
// Scroller disabled
- if (!LobbyTextScroller)
+ if (!HudTextScroller)
{
// Remove scroller if disabled late
if (OptionsScroller != null)
diff --git a/Essentials/Options/CustomOption.Rpc.cs b/Essentials/Options/CustomOption.Rpc.cs
index cfcebb8..fc4d7f5 100644
--- a/Essentials/Options/CustomOption.Rpc.cs
+++ b/Essentials/Options/CustomOption.Rpc.cs
@@ -1,6 +1,5 @@
using Hazel;
using Reactor;
-using System;
using System.Linq;
namespace Essentials.Options
@@ -34,7 +33,7 @@ internal static void HandleRpc(PlayerControl sender, (string, CustomOptionType,
}*/
[RegisterCustomRpc]
- private protected class Rpc : PlayerCustomRpc
+ private protected class Rpc : PlayerCustomRpc
{
public static Rpc Instance { get { return Rpc.Instance; } }
@@ -44,7 +43,7 @@ public Rpc(EssentialsPlugin plugin) : base(plugin)
public override RpcLocalHandling LocalHandling { get { return RpcLocalHandling.None; } }
- public override void Write(MessageWriter writer, (string, CustomOptionType, object) option)
+ public override void Write(MessageWriter writer, (int, CustomOptionType, object) option)
{
writer.Write(option.Item1); // ID
writer.Write((int)option.Item2); // Type
@@ -53,9 +52,9 @@ public override void Write(MessageWriter writer, (string, CustomOptionType, obje
else if (option.Item2 == CustomOptionType.String) writer.Write((int)option.Item3);
}
- public override (string, CustomOptionType, object) Read(MessageReader reader)
+ public override (int, CustomOptionType, object) Read(MessageReader reader)
{
- string id = reader.ReadString();
+ int id = reader.ReadInt32();
CustomOptionType type = (CustomOptionType)reader.ReadInt32();
object value = null;
if (type == CustomOptionType.Toggle) value = reader.ReadBoolean();
@@ -65,34 +64,47 @@ public override (string, CustomOptionType, object) Read(MessageReader reader)
return (id, type, value);
}
- public override void Handle(PlayerControl sender, (string, CustomOptionType, object) option)
+ public override void Handle(PlayerControl sender, (int, CustomOptionType, object) option)
{
if (sender?.Data == null) return;
- string id = option.Item1;
+ int id = option.Item1;
CustomOptionType type = option.Item2;
- CustomOption customOption = Options.FirstOrDefault(o => o.Type == type && o.ID.Equals(id, StringComparison.Ordinal));
+ CustomOption customOption = Options.FirstOrDefault(o => o.Type == type && o.GetHashCode() == id);
if (customOption == null)
{
- EssentialsPlugin.Logger.LogWarning($"Received option that could not be found: \"{id}\" of type {type}.");
+ EssentialsPlugin.Logger.LogWarning($"Received option that could not be found, hashcode: {id}, type: {type}.");
return;
}
object value = option.Item3;
- if (Debug) EssentialsPlugin.Logger.LogInfo($"\"{id}\" type: {type}, value: {value}, current value: {customOption.Value}");
+ if (Debug) EssentialsPlugin.Logger.LogInfo($"\"{customOption.ID}\" type: {type}, value: {value}, current value: {customOption.Value}");
customOption.SetValue(value, true);
- if (Debug) EssentialsPlugin.Logger.LogInfo($"\"{id}\", set value: {customOption.Value}");
+ if (Debug) EssentialsPlugin.Logger.LogInfo($"\"{customOption.ID}\", set value: {customOption.Value}");
}
}
- public static implicit operator (string ID, CustomOptionType Type, object Value)(CustomOption option)
+ public static implicit operator (int ID, CustomOptionType Type, object Value)(CustomOption option)
{
- return (option.ID, option.Type, option.GetValue