Skip to content

Commit 365f889

Browse files
committed
fix invalid chars in configs
1 parent 232f132 commit 365f889

File tree

6 files changed

+54
-42
lines changed

6 files changed

+54
-42
lines changed

UnboundLib/Cards/CustomCard.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static void BuildCard<T>(Action<CardInfo> callback) where T : CustomCard
158158
CardManager.activeCards.CollectionChanged += CardManager.CardsChanged;
159159
// Register card with the toggle menu
160160
CardManager.cards.Add(newCard.gameObject.name,
161-
new Card(customCard.GetModName().Sanitize(), Unbound.config.Bind("Cards: " + customCard.GetModName().Sanitize(), newCard.gameObject.name, true), newCardInfo));
161+
new Card(customCard.GetModName().Sanitize(), Unbound.BindConfig("Cards: " + customCard.GetModName().Sanitize(), newCard.gameObject.name, true), newCardInfo));
162162
}
163163

164164
// Post-creation clean up
@@ -188,7 +188,7 @@ public static void BuildUnityCard<T>(GameObject cardPrefab, Action<CardInfo> cal
188188

189189
if (customCard.GetEnabled())
190190
{
191-
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.config.Bind("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
191+
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.BindConfig("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
192192
}
193193

194194
customCard.Awake();
@@ -219,7 +219,7 @@ public void BuildUnityCard(Action<CardInfo> callback)
219219

220220
if (customCard.GetEnabled())
221221
{
222-
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.config.Bind("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
222+
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.BindConfig("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
223223
}
224224

225225
this.Awake();
@@ -241,7 +241,7 @@ public static void RegisterUnityCard<T>(GameObject cardPrefab, Action<CardInfo>
241241

242242
if (customCard.GetEnabled())
243243
{
244-
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.config.Bind("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
244+
CardManager.cards.Add(cardInfo.gameObject.name, new Card(customCard.GetModName().Sanitize(), Unbound.BindConfig("Cards: " + customCard.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
245245
}
246246

247247
Unbound.Instance.ExecuteAfterFrames(5, () =>
@@ -260,7 +260,7 @@ public static void RegisterUnityCard(GameObject cardPrefab, string modInitials,
260260

261261
if (enabled)
262262
{
263-
CardManager.cards.Add(cardInfo.gameObject.name, new Card(modInitials.Sanitize(), Unbound.config.Bind("Cards: " + cardname.Sanitize(), cardInfo.gameObject.name, true), cardInfo));
263+
CardManager.cards.Add(cardInfo.gameObject.name, new Card(modInitials.Sanitize(), Unbound.BindConfig("Cards: " + cardname.Sanitize(), cardInfo.gameObject.name, true), cardInfo));
264264
}
265265

266266
Unbound.Instance.ExecuteAfterFrames(5, () =>
@@ -279,7 +279,7 @@ public void RegisterUnityCard(Action<CardInfo> callback)
279279

280280
if (this.GetEnabled())
281281
{
282-
CardManager.cards.Add(cardInfo.gameObject.name, new Card(this.GetModName().Sanitize(), Unbound.config.Bind("Cards: " + this.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
282+
CardManager.cards.Add(cardInfo.gameObject.name, new Card(this.GetModName().Sanitize(), Unbound.BindConfig("Cards: " + this.GetModName().Sanitize(), cardInfo.gameObject.name, true), cardInfo));
283283
}
284284

285285
Unbound.Instance.ExecuteAfterFrames(5, () =>

UnboundLib/GameModes/GameModeManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public static class GameModeManager
2323
private static Dictionary<string, List<GameModeHooks.Hook>> hooks = new Dictionary<string, List<GameModeHooks.Hook>>();
2424
private static Dictionary<string, List<GameModeHooks.Hook>> onceHooks = new Dictionary<string, List<GameModeHooks.Hook>>();
2525

26-
private static bool firstTime = true;
27-
2826
// public properties that return deep copies of the handlers and gameModes dictionarys (the values in the dictionaries returned are shallow copies)
2927
public static ReadOnlyDictionary<string, IGameModeHandler> Handlers => new ReadOnlyDictionary<string, IGameModeHandler>(handlers.ToDictionary(kv => kv.Key, kv => kv.Value));
3028
public static ReadOnlyDictionary<string, Type> GameModes => new ReadOnlyDictionary<string, Type>(gameModes.ToDictionary(kv => kv.Key, kv => kv.Value));
@@ -117,10 +115,6 @@ internal static void SetupUI()
117115
group.Find("CREDITS")?.SetAsLastSibling();
118116
group.Find("Quit")?.SetAsLastSibling();
119117
});
120-
121-
firstTime = false;
122-
123-
124118
}
125119
var gameModeGo = GameObject.Find("/Game/UI/UI_MainMenu/Canvas/ListSelector/LOCAL");
126120
var onlineGo = GameObject.Find("/Game/UI/UI_MainMenu/Canvas/ListSelector/Online/Group");

UnboundLib/Unbound.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class Unbound : BaseUnityPlugin
2525
{
2626
private const string ModId = "com.willis.rounds.unbound";
2727
private const string ModName = "Rounds Unbound";
28-
public const string Version = "3.2.8";
28+
public const string Version = "3.2.9";
2929

3030
public static Unbound Instance { get; private set; }
31-
public static readonly ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, "UnboundLib.cfg"), true);
31+
private static readonly ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, "UnboundLib.cfg"), true);
3232

3333
private Canvas _canvas;
3434
public Canvas canvas
@@ -482,6 +482,24 @@ public static bool IsNotPlayingOrConnected()
482482
(PhotonNetwork.OfflineMode || !PhotonNetwork.IsConnected);
483483
}
484484

485+
internal static ConfigEntry<T> BindConfig<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
486+
{
487+
return config.Bind(EscapeConfigKey(section), EscapeConfigKey(key), defaultValue, configDescription);
488+
}
489+
490+
private static string EscapeConfigKey(string key)
491+
{
492+
return key
493+
.Replace("=", "&eq;")
494+
.Replace("\n", "&nl;")
495+
.Replace("\t", "&tab;")
496+
.Replace("\\", "&esc;")
497+
.Replace("\"", "&dquot;")
498+
.Replace("'", "&squot;")
499+
.Replace("[", "&lsq;")
500+
.Replace("]", "&rsq;");
501+
}
502+
485503
internal static readonly ModCredits modCredits = new ModCredits("UNBOUND", new[]
486504
{
487505
"Willis (Creation, design, networking, custom cards, custom maps, and more)",

UnboundLib/Utils/CardManager.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace UnboundLib.Utils
1515
public class CardManager : MonoBehaviour
1616
{
1717
public CardManager instance;
18-
18+
1919
// A string array of all cardInfos
2020
internal static CardInfo[] allCards
2121
{
@@ -28,32 +28,32 @@ internal static CardInfo[] allCards
2828
return _allCards.ToArray();
2929
}
3030
}
31-
31+
3232
internal static CardInfo[] defaultCards;
3333
internal static ObservableCollection<CardInfo> activeCards;
3434
//internal static ObservableCollection<CardInfo> previousActiveCards = new ObservableCollection<CardInfo>();
3535
internal static List<CardInfo> inactiveCards = new List<CardInfo>();
3636
//internal static List<CardInfo> previousInactiveCards = new List<CardInfo>();
37-
37+
3838
// List of all categories
3939
public static readonly List<string> categories = new List<string>();
4040
// Dictionary of category name against if it is enabled
4141
internal static readonly Dictionary<string, ConfigEntry<bool>> categoryBools = new Dictionary<string, ConfigEntry<bool>>();
42-
42+
4343
public static Dictionary<string, Card> cards = new Dictionary<string, Card>();
4444

4545
private static readonly List<Action<CardInfo[]>> FirstStartCallbacks = new List<Action<CardInfo[]>>();
4646

4747
public void Start()
4848
{
4949
instance = this;
50-
50+
5151
// store default cardInfos
5252
defaultCards = (CardInfo[]) CardChoice.instance.cards.Clone();
53-
53+
5454
// Make activeCardsCollection and add defaultCards to it
5555
activeCards = new ObservableCollection<CardInfo>(defaultCards);
56-
56+
5757
// Set activeCards CollectionChanged event
5858
activeCards.CollectionChanged += CardsChanged;
5959
}
@@ -62,7 +62,7 @@ public static void FirstTimeStart()
6262
{
6363
// Sort cardInfos
6464
cards = cards.Keys.OrderBy(k => k).ToDictionary(k => k, k => cards[k]);
65-
65+
6666
// Set categories
6767
foreach (var card in cards.Where(card => !categories.Contains(card.Value.category)))
6868
{
@@ -72,7 +72,7 @@ public static void FirstTimeStart()
7272
// Populate the categoryBools dictionary
7373
foreach (var category in categories)
7474
{
75-
categoryBools.Add(category, Unbound.config.Bind("Card categories", category, true));
75+
categoryBools.Add(category, Unbound.BindConfig("Card categories", category, true));
7676
}
7777

7878
foreach (Action<CardInfo[]> callback in FirstStartCallbacks)
@@ -101,7 +101,7 @@ public static void AddAllCardsCallback(Action<CardInfo[]> callback)
101101
{
102102
FirstStartCallbacks.Add(callback);
103103
}
104-
104+
105105
internal static void CardsChanged(object sender, NotifyCollectionChangedEventArgs args)
106106
{
107107
if (CardChoice.instance)
@@ -143,7 +143,7 @@ public static void EnableCard(CardInfo cardInfo, bool saved = true)
143143

144144
string cardName = cardInfo.gameObject.name;
145145
if (!cards.ContainsKey(cardName)) return;
146-
146+
147147
cards[cardName].enabled = true;
148148

149149
if (saved)
@@ -159,7 +159,7 @@ public static void DisableCards(CardInfo[] cardInfos, bool saved = true)
159159
DisableCard(card, saved);
160160
}
161161
}
162-
162+
163163
public static void DisableCard(CardInfo cardInfo, bool saved = true)
164164
{
165165
if (activeCards.Contains(cardInfo))
@@ -185,7 +185,7 @@ public static void DisableCard(CardInfo cardInfo, bool saved = true)
185185

186186
public static void EnableCategory(string categoryName)
187187
{
188-
if(categoryBools.ContainsKey(categoryName)) categoryBools[categoryName].Value = true;
188+
if (categoryBools.ContainsKey(categoryName)) categoryBools[categoryName].Value = true;
189189
foreach (string cardname in GetCardsInCategory(categoryName))
190190
{
191191
EnableCard(cards[cardname].cardInfo, true);
@@ -194,18 +194,18 @@ public static void EnableCategory(string categoryName)
194194

195195
public static void DisableCategory(string categoryName)
196196
{
197-
if(categoryBools.ContainsKey(categoryName)) categoryBools[categoryName].Value = false;
197+
if (categoryBools.ContainsKey(categoryName)) categoryBools[categoryName].Value = false;
198198
foreach (string cardname in GetCardsInCategory(categoryName))
199199
{
200200
DisableCard(cards[cardname].cardInfo, true);
201201
}
202202
}
203-
203+
204204
public static bool IsCardActive(CardInfo card)
205205
{
206206
return activeCards.Contains(card);
207207
}
208-
208+
209209
public static bool IsCategoryActive(string categoryName)
210210
{
211211
return categoryBools.ContainsKey(categoryName) && categoryBools[categoryName].Value;
@@ -236,7 +236,7 @@ public static void OnJoinedRoomAction()
236236
}
237237
});
238238
}
239-
239+
240240
// This gets executed only on master client
241241
[UnboundRPC]
242242
private static void RPC_CardHandshake(string[] cardsArray)
@@ -303,7 +303,7 @@ private static void RPC_HostCardHandshakeResponse(string[] cardsArray)
303303

304304
#endregion
305305
}
306-
306+
307307
public class Card
308308
{
309309
public bool enabled;

UnboundLib/Utils/LevelManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ private void Start()
8383
// Populate the categoryBools dictionary
8484
foreach (var category in categories)
8585
{
86-
categoryBools[category] = Unbound.config.Bind("Level categories", category, true);
86+
categoryBools[category] = Unbound.BindConfig("Level categories", category, true);
8787
}
8888

8989
// Disable all default levels that are disabled in config
9090
foreach (var level in allLevels)
9191
{
9292
levelPaths[GetVisualName(level)] = level;
93-
if (!Unbound.config.Bind("Levels: " + levels[level].category, GetVisualName(level), true).Value)
93+
if (!Unbound.BindConfig("Levels: " + levels[level].category, GetVisualName(level), true).Value)
9494
{
9595
DisableLevel(level);
9696
}
@@ -145,7 +145,7 @@ public static void EnableLevel(string levelName, bool saved = true)
145145

146146
if (!saved) return;
147147
levels[levelName].enabled = true;
148-
Unbound.config.Bind("Levels: " + levels[levelName].category, GetVisualName(levelName), true).Value = true;
148+
Unbound.BindConfig("Levels: " + levels[levelName].category, GetVisualName(levelName), true).Value = true;
149149
}
150150

151151
public static void DisableLevels(string[] levelNames, bool saved = true)
@@ -171,7 +171,7 @@ public static void DisableLevel(string levelName, bool saved = true)
171171

172172
if (!saved) return;
173173
levels[levelName].enabled = false;
174-
Unbound.config.Bind("Levels: " + levels[levelName].category, GetVisualName(levelName), true).Value = false;
174+
Unbound.BindConfig("Levels: " + levels[levelName].category, GetVisualName(levelName), true).Value = false;
175175
}
176176

177177

@@ -253,7 +253,7 @@ public static void RegisterMaps(IEnumerable<string> paths, string category = "Mo
253253
{
254254
RegisterNamedMaps(paths, new Dictionary<string, string>(), category);
255255
}
256-
public static void RegisterNamedMaps(IEnumerable<string> paths, IDictionary<string, string> mapNames , string category = "Modded")
256+
public static void RegisterNamedMaps(IEnumerable<string> paths, IDictionary<string, string> mapNames, string category = "Modded")
257257
{
258258
foreach (var path in paths.Distinct())
259259
{
@@ -286,9 +286,9 @@ private static void RegisterMap(string path, string name, string category)
286286
if (!categories.Contains(category))
287287
{
288288
categories.Add(category);
289-
categoryBools[category] = Unbound.config.Bind("Level categories", category, true);
289+
categoryBools[category] = Unbound.BindConfig("Level categories", category, true);
290290
}
291-
if (!Unbound.config.Bind("Levels: " + levels[path].category, GetVisualName(path), true).Value)
291+
if (!Unbound.BindConfig("Levels: " + levels[path].category, GetVisualName(path), true).Value)
292292
{
293293
DisableLevel(path);
294294
}

UnboundLib/Utils/UI/ToggleLevelMenuHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void Start()
248248

249249
lvlObjs.Add(mapObject);
250250
UpdateVisualsLevelObj(mapObject);
251-
if (!Unbound.config.Bind("Levels: " + level.Value.category, LevelManager.GetVisualName(level.Key), true).Value)
251+
if (!Unbound.BindConfig("Levels: " + level.Value.category, LevelManager.GetVisualName(level.Key), true).Value)
252252
{
253253
LevelManager.DisableLevel(level.Key);
254254
UpdateVisualsLevelObj(mapObject);
@@ -275,7 +275,7 @@ public void Start()
275275

276276
ScrollViews[category].GetComponent<ScrollRect>().normalizedPosition = new Vector2(0, 1);
277277
ScrollViews[category].gameObject.SetActive(true);
278-
278+
279279
viewingText.text = "Viewing: " + category;
280280
});
281281
var toggle = categoryObj.GetComponentInChildren<Toggle>();
@@ -440,7 +440,7 @@ private static void ChangeMapColumnAmountMenus(int amount)
440440
}
441441
}
442442
cellSize *= localScale;
443-
443+
444444
mapAmountText.text = "Maps Per Line: " + amount;
445445
foreach (GridLayoutGroup gridLayout in from category in LevelManager.categories select ScrollViews[category].Find("Viewport/Content") into categoryMenu where categoryMenu != null select categoryMenu.gameObject.GetComponent<GridLayoutGroup>())
446446
{

0 commit comments

Comments
 (0)