Skip to content

Commit 73de7d7

Browse files
committed
[CONFIGURATION] Implement base support for save/load of user configuration settings
1 parent 7eda9f3 commit 73de7d7

File tree

9 files changed

+894
-47
lines changed

9 files changed

+894
-47
lines changed

COTLMP/Api/Configuration.cs

Lines changed: 475 additions & 0 deletions
Large diffs are not rendered by default.

COTLMP/Data/ModDataGlobals.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* PROJECT: Cult of the Lamb Multiplayer Mod
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Globals data of the mod
5+
* COPYRIGHT: Copyright 2025 GeoB99 <[email protected]>
6+
*/
7+
8+
/* IMPORTS ********************************************************************/
9+
10+
using COTLMP;
11+
12+
/* CLASSES & CODE *************************************************************/
13+
14+
/*
15+
* @brief
16+
* Contains global mod data.
17+
*
18+
* @class ModDataGlobals
19+
* Main class of which mod data is stored.
20+
*/
21+
namespace COTLMP.Data
22+
{
23+
internal class ModDataGlobals
24+
{
25+
/* Enable or Disable the execution of the mod */
26+
public bool EnableMod;
27+
28+
/* The current executing game-play mode */
29+
public string GameMode;
30+
31+
/* The name of the player in-game */
32+
public string PlayerName;
33+
34+
/* The name of the server */
35+
public string ServerName;
36+
37+
/* The maximum allowed number of players */
38+
public int MaxNumPlayers;
39+
40+
/* Enable or Disable voice chat */
41+
public bool EnableVoiceChat;
42+
43+
/******************************************************************************
44+
* THE FOLLOWING FIELDS ARE RESERVED INTERNALLY *
45+
* FOR THE MOD. CHANGE THESE VALUES WITH CAUTION!!! *
46+
******************************************************************************/
47+
48+
/* Enable or disable verbose debug output in the console */
49+
internal bool VerboseDebug = false;
50+
51+
/* The internal variable of maximum count of players per server. Used for validation purposes. */
52+
internal const int MaxPlayersPerServerInternal = 8;
53+
54+
public ModDataGlobals(bool Enable,
55+
string Mode,
56+
string PlName,
57+
string SvName,
58+
int PlNum,
59+
bool EnableVC)
60+
{
61+
EnableMod = Enable;
62+
GameMode = Mode;
63+
PlayerName = PlName;
64+
ServerName = SvName;
65+
MaxNumPlayers = PlNum;
66+
EnableVoiceChat = EnableVC;
67+
}
68+
}
69+
}
70+
71+
/* EOF */

COTLMP/Data/Resources.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ public static string MultiplayerSettings_VoiceChat
9292
return LocalizationManager.GetTranslation("Multiplayer/UI/Settings/VoiceChat");
9393
}
9494
}
95-
96-
public static string MultiplayerSettings_SayChat
97-
{
98-
get
99-
{
100-
return LocalizationManager.GetTranslation("Multiplayer/UI/Settings/SayChat");
101-
}
102-
}
10395
}
10496
}
10597
}

COTLMP/Debug/PrintLogger.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public enum DebugComponent
8080
INIT_COMPONENT = 0,
8181
UI_COMPONENT,
8282
NETWORK_STACK_COMPONENT,
83-
LOCALIZATION_COMPONENT
83+
LOCALIZATION_COMPONENT,
84+
CONFIGURATION_COMPONENT
8485
}
8586

8687
public class PrintLogger
@@ -128,6 +129,12 @@ private static string GetComponentName(DebugComponent Component)
128129
break;
129130
}
130131

132+
case DebugComponent.CONFIGURATION_COMPONENT:
133+
{
134+
Name = "CONFIGURATION_COMPONENT";
135+
break;
136+
}
137+
131138
default:
132139
{
133140
Name = null;

COTLMP/Game/Callbacks.cs

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
* PROJECT: Cult of the Lamb Multiplayer Mod
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Setting callbacks methods
5+
* COPYRIGHT: Copyright 2025 GeoB99 <[email protected]>
6+
*/
7+
8+
/* IMPORTS ********************************************************************/
9+
10+
using COTLMP;
11+
using COTLMP.Debug;
12+
using COTLMP.Api;
13+
using BepInEx;
14+
using BepInEx.Configuration;
15+
using HarmonyLib;
16+
using System;
17+
using UnityEngine;
18+
using UnityEngine.Assertions;
19+
20+
/* CLASSES & CODE *************************************************************/
21+
22+
/*
23+
* @brief
24+
* Contains the classes and code for the mod game related stuff.
25+
*
26+
* @class Callbacks
27+
* The callbacks class which contains callback methods for the
28+
* mod game settings.
29+
*/
30+
namespace COTLMP.Game
31+
{
32+
internal static class Callbacks
33+
{
34+
/*
35+
* @brief
36+
* A callback that gets called when the Toggle Mod
37+
* setting's value has changed.
38+
*
39+
* @param[in] Value
40+
* A boolean value representing the value of the setting
41+
* that has changed.
42+
*/
43+
public static void ModToggleCallback(bool Value)
44+
{
45+
string Section;
46+
ConfigDefinition Definition;
47+
ConfigEntry<bool> SettingEntry;
48+
49+
/* Retrieve the section name for the setting */
50+
Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ModSettings);
51+
52+
/* Get the Mod Toggle setting */
53+
Definition = new ConfigDefinition(Section, "Toggle Mod");
54+
SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<bool>(Definition);
55+
Assert.IsNotNull(SettingEntry);
56+
57+
/* Cache the new value to the globals store */
58+
Plugin.Globals.EnableMod = Value;
59+
60+
/* FIXME: Enable/Disable mod execution here */
61+
62+
/* Overwrite the current value of the setting and flush it */
63+
SettingEntry.BoxedValue = Value;
64+
COTLMP.Api.Configuration.FlushSettings();
65+
}
66+
67+
/*
68+
* @brief
69+
* A callback that gets called when the Game Mode
70+
* setting's value has changed.
71+
*
72+
* @param[in] Value
73+
* An integer value representing the value of the
74+
* setting that has changed.
75+
*/
76+
public static void GameModeCallback(int Value)
77+
{
78+
string Section;
79+
string GameMode;
80+
ConfigDefinition Definition;
81+
ConfigEntry<string> SettingEntry;
82+
83+
/* Retrieve the section name for the setting */
84+
Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings);
85+
86+
/* Get the Game Mode setting */
87+
Definition = new ConfigDefinition(Section, "Game Mode");
88+
SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<string>(Definition);
89+
Assert.IsNotNull(SettingEntry);
90+
91+
/* FIXME: This is a placeholder code, the game modes should be declared in a dedicated enum */
92+
switch (Value)
93+
{
94+
case 0:
95+
{
96+
GameMode = "Standard";
97+
break;
98+
}
99+
100+
case 1:
101+
{
102+
GameMode = "Boss Fight";
103+
break;
104+
}
105+
106+
case 2:
107+
{
108+
GameMode = "Deathmatch";
109+
break;
110+
}
111+
112+
case 3:
113+
{
114+
GameMode = "Zombies!";
115+
break;
116+
}
117+
118+
/* Always default the game mode to Standard on bogus values */
119+
default:
120+
{
121+
GameMode = "Standard";
122+
break;
123+
}
124+
}
125+
126+
/* Cache the new value to the globals store */
127+
Plugin.Globals.GameMode = GameMode;
128+
129+
/* Overwrite the current value of the setting and flush it */
130+
SettingEntry.BoxedValue = GameMode;
131+
COTLMP.Api.Configuration.FlushSettings();
132+
}
133+
134+
/*
135+
* @brief
136+
* A callback that gets called when the Max Players
137+
* Count setting's value has changed.
138+
*
139+
* @param[in] Value
140+
* An integer value representing the value of the
141+
* setting that has changed.
142+
*/
143+
public static void PlayerCountCallback(int Value)
144+
{
145+
string Section;
146+
ConfigDefinition Definition;
147+
ConfigEntry<int> SettingEntry;
148+
149+
/* Retrieve the section name for the setting */
150+
Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings);
151+
152+
/* Get the Max Players Count setting */
153+
Definition = new ConfigDefinition(Section, "Max Players");
154+
SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<int>(Definition);
155+
Assert.IsNotNull(SettingEntry);
156+
157+
/*
158+
* Cache the new value to the globals store.
159+
* The horizontal selector begins its first element at index of 0
160+
* which is which why we increment the value by one to make up the
161+
* real count of max number of players.
162+
*/
163+
Plugin.Globals.MaxNumPlayers = Value + 1;
164+
165+
/* Overwrite the current value of the setting and flush it */
166+
SettingEntry.BoxedValue = Value + 1;
167+
COTLMP.Api.Configuration.FlushSettings();
168+
}
169+
170+
/*
171+
* @brief
172+
* A callback that gets called when the Toggle Voice
173+
* Chat setting's value has changed.
174+
*
175+
* @param[in] Value
176+
* A boolean value representing the value of the
177+
* setting that has changed.
178+
*/
179+
public static void VoiceChatCallback(bool Value)
180+
{
181+
string Section;
182+
ConfigDefinition Definition;
183+
ConfigEntry<bool> SettingEntry;
184+
185+
/* Retrieve the section name for the setting */
186+
Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings);
187+
188+
/* Get the Voice Chat Toggle setting */
189+
Definition = new ConfigDefinition(Section, "Toggle Voice Chat");
190+
SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<bool>(Definition);
191+
Assert.IsNotNull(SettingEntry);
192+
193+
/* Cache the new value to the globals store */
194+
Plugin.Globals.EnableVoiceChat = Value;
195+
196+
/* FIXME: Enable/Disable the voice chat subsystem here */
197+
198+
/* Overwrite the current value of the setting and flush it */
199+
SettingEntry.BoxedValue = Value;
200+
COTLMP.Api.Configuration.FlushSettings();
201+
}
202+
}
203+
}
204+
205+
/* EOF */

COTLMP/Language/en-US.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class English
2727
new("Multiplayer/UI/Settings/GameMode", "Game Mode", false),
2828
new("Multiplayer/UI/Settings/PlayerCount", "Number of maximum players to join", false),
2929
new("Multiplayer/UI/Settings/VoiceChat", "Enable Voice Chat", false),
30-
new("Multiplayer/UI/Settings/SayChat", "Enable Say Chat", false),
3130
new("Multiplayer/Game/Join", "{0} has joined the server", false),
3231
new("Multiplayer/Game/Left", "{0} has left the server", false),
3332
new("Multiplayer/UI/WIP", "Multiplayer is currently not implemented yet", false)

0 commit comments

Comments
 (0)