From 725f2992474eb0e31e387e8e851da6d636961de0 Mon Sep 17 00:00:00 2001
From: twix <91138333+whichtwix@users.noreply.github.com>
Date: Mon, 20 Mar 2023 22:46:45 +0600
Subject: [PATCH 1/5] try loading existing settings after defaults
---
source/Patches/CustomOption/Generate.cs | 7 ++---
source/Patches/CustomOption/Import.cs | 37 +++++++++++++++++++------
2 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/source/Patches/CustomOption/Generate.cs b/source/Patches/CustomOption/Generate.cs
index b10dae4b9..f1f4d0e0e 100644
--- a/source/Patches/CustomOption/Generate.cs
+++ b/source/Patches/CustomOption/Generate.cs
@@ -435,10 +435,6 @@ public static void GenerateAll()
{
var num = 0;
- Patches.ExportButton = new Export(num++);
- Patches.ImportButton = new Import(num++);
-
-
CrewInvestigativeRoles = new CustomHeaderOption(num++, MultiMenu.crewmate, "Crewmate Investigative Roles");
DetectiveOn = new CustomNumberOption(num++, MultiMenu.crewmate, "Detective", 0f, 0f, 100f, 10f,
PercentFormat);
@@ -1109,6 +1105,9 @@ public static void GenerateAll()
Underdog = new CustomHeaderOption(num++, MultiMenu.modifiers, "Underdog");
UnderdogKillBonus = new CustomNumberOption(num++, MultiMenu.modifiers, "Kill Cooldown Bonus", 5f, 2.5f, 10f, 2.5f, CooldownFormat);
UnderdogIncreasedKC = new CustomToggleOption(num++, MultiMenu.modifiers, "Increased Kill Cooldown When 2+ Imps", true);
+
+ Patches.ExportButton = new Export(num++);
+ Patches.ImportButton = new Import(num++);
}
}
}
\ No newline at end of file
diff --git a/source/Patches/CustomOption/Import.cs b/source/Patches/CustomOption/Import.cs
index 52685e030..c7fd4cd55 100644
--- a/source/Patches/CustomOption/Import.cs
+++ b/source/Patches/CustomOption/Import.cs
@@ -21,6 +21,7 @@ public class Import : CustomButtonOption
protected internal Import(int id) : base(id, MultiMenu.main, "Load Custom Settings")
{
Do = ToDo;
+ TryLoadExistingFile();
}
@@ -29,11 +30,9 @@ private List CreateOptions()
var options = new List();
var togglePrefab = Object.FindObjectOfType();
- var numberPrefab = Object.FindObjectOfType();
- var stringPrefab = Object.FindObjectOfType();
-
foreach (var button in SlotButtons)
+ {
if (button.Setting != null)
{
button.Setting.gameObject.SetActive(true);
@@ -49,13 +48,15 @@ private List CreateOptions()
button.OptionCreated();
options.Add(toggle);
}
+ }
return options;
}
- protected internal void Cancel(Func flashCoro)
+ protected internal Action Cancel(Func flashCoro)
{
Coroutines.Start(CancelCoro(flashCoro));
+ return null;
}
protected internal IEnumerator CancelCoro(Func flashCoro)
@@ -111,7 +112,7 @@ protected internal void ToDo()
__instance.Children = new Il2CppReferenceArray(options.ToArray());
}
- private void ImportSlot(int slotId)
+ private void ImportSlot(int slotId, bool DoAction = true)
{
System.Console.WriteLine(slotId);
@@ -124,18 +125,17 @@ private void ImportSlot(int slotId)
}
catch
{
- Cancel(FlashRed);
+ if (DoAction) Cancel(FlashRed);
return;
}
-
var splitText = text.Split("\n").ToList();
while (splitText.Count > 0)
{
var name = splitText[0].Trim();
splitText.RemoveAt(0);
- var option = AllOptions.FirstOrDefault(o => o.Name.Equals(name, StringComparison.Ordinal));
+ var option = AllOptions.Find(o => o.Name.Equals(name, StringComparison.Ordinal));
if (option == null)
{
try
@@ -165,11 +165,30 @@ private void ImportSlot(int slotId)
}
}
+ if (DoAction)
+ {
+ Rpc.SendRpc();
Rpc.SendRpc();
- Cancel(FlashGreen);
+ Rpc.SendRpc();
+
+ Cancel(FlashGreen);
+ }
+
+ return;
}
+ private void TryLoadExistingFile()
+ {
+ for (int i = 1; i < 6; i++)
+ {
+ if (File.Exists(Application.persistentDataPath + $"\\GameSettings-Slot{i}"))
+ {
+ ImportSlot(i, false);
+ return;
+ }
+ }
+ }
private IEnumerator FlashGreen()
{
From 05ea3a869859e709a7783249ded33fa5e4e36652 Mon Sep 17 00:00:00 2001
From: twix <91138333+whichtwix@users.noreply.github.com>
Date: Mon, 20 Mar 2023 22:50:24 +0600
Subject: [PATCH 2/5] not sure where extra sendrpc calls came from
---
source/Patches/CustomOption/Import.cs | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/source/Patches/CustomOption/Import.cs b/source/Patches/CustomOption/Import.cs
index c7fd4cd55..f26ee7ce7 100644
--- a/source/Patches/CustomOption/Import.cs
+++ b/source/Patches/CustomOption/Import.cs
@@ -53,10 +53,9 @@ private List CreateOptions()
return options;
}
- protected internal Action Cancel(Func flashCoro)
+ protected internal void Cancel(Func flashCoro)
{
Coroutines.Start(CancelCoro(flashCoro));
- return null;
}
protected internal IEnumerator CancelCoro(Func flashCoro)
@@ -167,11 +166,7 @@ private void ImportSlot(int slotId, bool DoAction = true)
if (DoAction)
{
- Rpc.SendRpc();
- Rpc.SendRpc();
-
Rpc.SendRpc();
-
Cancel(FlashGreen);
}
From 864b320bf90441f2e82f7dec39c960d9ecd0b7da Mon Sep 17 00:00:00 2001
From: twix <91138333+whichtwix@users.noreply.github.com>
Date: Sun, 26 Mar 2023 20:09:44 +0600
Subject: [PATCH 3/5] add config setting
---
source/Patches/CustomOption/Import.cs | 6 ++++++
source/TownOfUs.cs | 30 +++++----------------------
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/source/Patches/CustomOption/Import.cs b/source/Patches/CustomOption/Import.cs
index f26ee7ce7..6ed994ab2 100644
--- a/source/Patches/CustomOption/Import.cs
+++ b/source/Patches/CustomOption/Import.cs
@@ -175,6 +175,12 @@ private void ImportSlot(int slotId, bool DoAction = true)
private void TryLoadExistingFile()
{
+ if (File.Exists(Application.persistentDataPath + $"\\GameSettings-Slot{TownOfUs.PreferredFile.Value}"))
+ {
+ ImportSlot(TownOfUs.PreferredFile.Value, false);
+ return;
+ }
+
for (int i = 1; i < 6; i++)
{
if (File.Exists(Application.persistentDataPath + $"\\GameSettings-Slot{i}"))
diff --git a/source/TownOfUs.cs b/source/TownOfUs.cs
index 3b2a9cdac..3a816461a 100644
--- a/source/TownOfUs.cs
+++ b/source/TownOfUs.cs
@@ -1,7 +1,4 @@
using System;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
@@ -30,8 +27,8 @@ public class TownOfUs : BasePlugin
{
public const string Id = "com.slushiegoose.townofus";
public const string VersionString = "4.0.3";
- public static System.Version Version = System.Version.Parse(VersionString);
-
+ public static Version Version = Version.Parse(VersionString);
+
public static Sprite JanitorClean;
public static Sprite EngineerFix;
public static Sprite SwapperSwitch;
@@ -99,18 +96,16 @@ public class TownOfUs : BasePlugin
private static DLoadImage _iCallLoadImage;
-
private Harmony _harmony;
- public ConfigEntry Ip { get; set; }
-
- public ConfigEntry Port { get; set; }
+ public static ConfigEntry PreferredFile { get; set; }
public override void Load()
{
System.Console.WriteLine("000.000.000.000/000000000000000000");
_harmony = new Harmony("com.slushiegoose.townofus");
+ PreferredFile = Config.Bind("Loading mod settings", "Preferred slot", 1, "which slot(1 - 5) is preferred to be loaded at game start");
Generate.GenerateAll();
@@ -183,22 +178,7 @@ public override void Load()
// RegisterInIl2CppAttribute.Register();
- Ip = Config.Bind("Custom", "Ipv4 or Hostname", "127.0.0.1");
- Port = Config.Bind("Custom", "Port", (ushort) 22023);
- var defaultRegions = ServerManager.DefaultRegions.ToList();
- var ip = Ip.Value;
- if (Uri.CheckHostName(Ip.Value).ToString() == "Dns")
- foreach (var address in Dns.GetHostAddresses(Ip.Value))
- {
- if (address.AddressFamily != AddressFamily.InterNetwork)
- continue;
- ip = address.ToString();
- break;
- }
-
- ServerManager.DefaultRegions = defaultRegions.ToArray();
-
- SceneManager.add_sceneLoaded((Action) ((scene, loadSceneMode) =>
+ SceneManager.add_sceneLoaded((Action) ((_, __) =>
{
try { ModManager.Instance.ShowModStamp(); }
catch { }
From aa741fa9834ad4df4c6c2663edaa9ba144ae0431 Mon Sep 17 00:00:00 2001
From: twix <91138333+whichtwix@users.noreply.github.com>
Date: Mon, 27 Mar 2023 11:56:00 +0600
Subject: [PATCH 4/5] stop logging twice that a setting was changed
---
source/Patches/CustomOption/Rpc.cs | 2 --
1 file changed, 2 deletions(-)
diff --git a/source/Patches/CustomOption/Rpc.cs b/source/Patches/CustomOption/Rpc.cs
index 6f48c26db..dd859ad10 100644
--- a/source/Patches/CustomOption/Rpc.cs
+++ b/source/Patches/CustomOption/Rpc.cs
@@ -49,8 +49,6 @@ public static void ReceiveRpc(MessageReader reader)
else if (type == CustomOptionType.String) value = reader.ReadInt32();
customOption?.Set(value);
-
- PluginSingleton.Instance.Log.LogInfo($"{customOption?.Name} : {customOption}:");
}
}
}
From cebee0702a97cbca6255dc9c522be5c875820294 Mon Sep 17 00:00:00 2001
From: twix <91138333+whichtwix@users.noreply.github.com>
Date: Mon, 17 Apr 2023 12:22:48 +0600
Subject: [PATCH 5/5] merge conflict
---
source/TownOfUs.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source/TownOfUs.cs b/source/TownOfUs.cs
index ce77d495a..c6442e2fe 100644
--- a/source/TownOfUs.cs
+++ b/source/TownOfUs.cs
@@ -26,7 +26,7 @@ namespace TownOfUs
public class TownOfUs : BasePlugin
{
public const string Id = "com.slushiegoose.townofus";
- public const string VersionString = "4.0.4;
+ public const string VersionString = "4.0.4";
public static Version Version = Version.Parse(VersionString);
public static Sprite JanitorClean;