Skip to content

Commit a6a2b75

Browse files
v1.12.0
1 parent 21f1a39 commit a6a2b75

11 files changed

Lines changed: 156 additions & 17 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.12.0] - 2024-05-05
9+
10+
### Changed
11+
12+
- Added diving bell settings
13+
- Updated sync
14+
815
## [1.11.0] - 2024-05-02
916

1017
### Changed

ConfigurableWarning.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<AssemblyName>ConfigurableWarning</AssemblyName>
66
<Description>Makes the game configurable!</Description>
7-
<Version>1.11.0</Version>
7+
<Version>1.12.0</Version>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<LangVersion>latest</LangVersion>
1010
<NoWarn>$(NoWarn);CS0436</NoWarn>

Source/Patches/DivingBellPatch.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Collections.Generic;
2+
using HarmonyLib;
3+
4+
namespace ConfigurableWarning.Patches {
5+
[HarmonyPatch]
6+
internal class DivingBellPatch {
7+
[HarmonyPostfix]
8+
[HarmonyPatch(typeof(DivingBellDoor), nameof(DivingBellDoor.IsFullyClosed))]
9+
internal static void IsFullyClosed(DivingBellDoor __instance, ref bool __result) {
10+
__result = __result || !Plugin.State.requireDiveBellDoorClosed;
11+
}
12+
13+
[HarmonyPostfix]
14+
[HarmonyPatch(typeof(DiveBellPlayerDetector), nameof(DiveBellPlayerDetector.CheckForPlayers))]
15+
internal static void CheckForPlayers(DiveBellPlayerDetector __instance, ref ICollection<Player> __result) {
16+
if (!Plugin.State.requireAllPlayersInDiveBell) {
17+
__result = PlayerHandler.instance.players;
18+
}
19+
}
20+
21+
[HarmonyPostfix]
22+
[HarmonyPatch(typeof(DivingBell), nameof(DivingBell.Update))]
23+
internal static void Update(DivingBell __instance) {
24+
var recharging = __instance.onSurface && TimeOfDayHandler.TimeOfDay == TimeOfDay.Evening;
25+
26+
if (recharging) {
27+
__instance.StateMachine.SwitchState<DivingBellRechargingState>();
28+
return;
29+
}
30+
31+
var allInside = true;
32+
var playersFoundInBell = __instance.playerDetector.CheckForPlayers();
33+
var players = PlayerHandler.instance.players;
34+
35+
foreach (Player player in players) {
36+
if (!playersFoundInBell.Contains(player)) {
37+
allInside = false;
38+
break;
39+
}
40+
}
41+
42+
var notClosed = !__instance.door.IsFullyClosed() && Plugin.State.requireDiveBellDoorClosed;
43+
var notAllInside = !allInside && Plugin.State.requireAllPlayersInDiveBell;
44+
45+
if (!notClosed) {
46+
__instance.opened = false;
47+
}
48+
49+
if (__instance.onSurface) {
50+
if (notAllInside) {
51+
__instance.StateMachine.SwitchState<DivingBellNotReadyMissingPlayersState>();
52+
} else if (notClosed) {
53+
__instance.StateMachine.SwitchState<DivingBellNotReadyDoorOpenState>();
54+
} else {
55+
__instance.StateMachine.SwitchState<DivingBellReadyState>();
56+
}
57+
} else {
58+
if (notClosed) {
59+
__instance.StateMachine.SwitchState<DivingBellNotReadyDoorOpenState>();
60+
} else {
61+
__instance.StateMachine.SwitchState<DivingBellReadyState>();
62+
}
63+
}
64+
}
65+
}
66+
}

Source/Patches/PlayerPatch.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ internal class PlayerPatch {
1414
[HarmonyPrefix]
1515
[HarmonyPatch(typeof(Player), nameof(Player.CheckOxygen))]
1616
internal static bool CheckOxygen(Player __instance) {
17+
if (Plugin.State.infiniteOxygen) {
18+
__instance.data.remainingOxygen = Plugin.State.maxOxygen;
19+
return false;
20+
}
21+
1722
var isSurface = SceneManager.GetActiveScene().name == "SurfaceScene";
1823
var flag = isSurface && !Plugin.State.useOxygenOnSurface;
1924

@@ -47,6 +52,9 @@ internal static bool UpdateValuesPre(Player.PlayerData __instance) {
4752
Player.PlayerData.maxHealth = Plugin.State.maxHealth;
4853

4954
__instance.maxOxygen = Plugin.State.maxOxygen;
55+
56+
// We want to override this functionality with our own code, but
57+
// preserve the rest of the method.
5058
__instance.usingOxygen = false;
5159

5260
return true;

Source/Patches/UIPatches.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,5 @@ internal class UIPatches {
88
internal static void UpdateHealth(UI_Health __instance) {
99
__instance.fill.fillAmount = Player.localPlayer.data.health / Plugin.State.maxHealth;
1010
}
11-
12-
[HarmonyPostfix]
13-
[HarmonyPatch(typeof(UI_DaysLeft), nameof(UI_DaysLeft.Update))]
14-
internal static void UpdateDaysLeft(UI_DaysLeft __instance) {
15-
int num = Plugin.State.daysPerQuota - SurfaceNetworkHandler.RoomStats.CurrentQuotaDay + 1;
16-
17-
__instance.text.text = (num == 1) ? __instance.m_LastDayText : __instance.m_DaysLeftText.Replace("{0}", num.ToString());
18-
}
1911
}
2012
}

Source/Settings/PackedSettings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class PackedSettings {
1212
[SerializeField] private bool useOxygenOnSurface;
1313
[SerializeField] private bool refillOxygenOnSurface;
1414
[SerializeField] private float oxygenRefillRate;
15+
[SerializeField] private bool requireAllPlayersInDiveBell;
16+
[SerializeField] private bool requireDiveBellDoorClosed;
17+
[SerializeField] private bool infiniteOxygen;
1518

1619
public static PackedSettings Collect() {
1720
var me = new PackedSettings {
@@ -24,6 +27,9 @@ public static PackedSettings Collect() {
2427
useOxygenOnSurface = Plugin.State.useOxygenOnSurface,
2528
refillOxygenOnSurface = Plugin.State.refillOxygenOnSurface,
2629
oxygenRefillRate = Plugin.State.oxygenRefillRate,
30+
requireAllPlayersInDiveBell = Plugin.State.requireAllPlayersInDiveBell,
31+
requireDiveBellDoorClosed = Plugin.State.requireDiveBellDoorClosed,
32+
infiniteOxygen = Plugin.State.infiniteOxygen,
2733
};
2834

2935
return me;
@@ -45,6 +51,9 @@ public static PackedSettings Unpack(string data) {
4551
SettingsUtil.SetValue(ref Plugin.PluginSettings.useOxygenOnSurface, me.useOxygenOnSurface);
4652
SettingsUtil.SetValue(ref Plugin.PluginSettings.refillOxygenOnSurface, me.refillOxygenOnSurface);
4753
SettingsUtil.SetValue(ref Plugin.PluginSettings.oxygenRefillRate, me.oxygenRefillRate);
54+
SettingsUtil.SetValue(ref Plugin.PluginSettings.requireAllPlayersInDiveBell, me.requireAllPlayersInDiveBell);
55+
SettingsUtil.SetValue(ref Plugin.PluginSettings.requireDiveBellDoorClosed, me.requireDiveBellDoorClosed);
56+
SettingsUtil.SetValue(ref Plugin.PluginSettings.infiniteOxygen, me.infiniteOxygen);
4857

4958
Plugin.State.maxOxygen = me.maxOxygen;
5059
Plugin.State.maxHealth = me.maxHealth;
@@ -55,6 +64,11 @@ public static PackedSettings Unpack(string data) {
5564
Plugin.State.useOxygenOnSurface = me.useOxygenOnSurface;
5665
Plugin.State.refillOxygenOnSurface = me.refillOxygenOnSurface;
5766
Plugin.State.oxygenRefillRate = me.oxygenRefillRate;
67+
Plugin.State.requireAllPlayersInDiveBell = me.requireAllPlayersInDiveBell;
68+
Plugin.State.requireDiveBellDoorClosed = me.requireDiveBellDoorClosed;
69+
Plugin.State.infiniteOxygen = me.infiniteOxygen;
70+
71+
SettingsUtil.UpdateQuotaDays();
5872

5973
return me;
6074
}

Source/Settings/PluginSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ public class PluginSettings {
1111
public UseOxygenOnSurface useOxygenOnSurface;
1212
public RefillOxygenOnSurface refillOxygenOnSurface;
1313
public OxygenRefillRate oxygenRefillRate;
14+
public RequireAllPlayersInDiveBell requireAllPlayersInDiveBell;
15+
public RequireDiveBellDoorClosed requireDiveBellDoorClosed;
16+
public InfiniteOxygen infiniteOxygen;
1417

1518
public PluginSettings() {
1619
// -------------------- General -------------------- //
1720

1821
privateHost = new PrivateHost();
1922
daysPerQuota = new DaysPerQuota();
23+
requireAllPlayersInDiveBell = new RequireAllPlayersInDiveBell();
24+
requireDiveBellDoorClosed = new RequireDiveBellDoorClosed();
2025

2126
// -------------------- Player -------------------- //
2227

@@ -33,6 +38,7 @@ public PluginSettings() {
3338
refillOxygenInDiveBell = new RefillOxygenInDiveBell();
3439
useOxygenOnSurface = new UseOxygenOnSurface();
3540
refillOxygenOnSurface = new RefillOxygenOnSurface();
41+
infiniteOxygen = new InfiniteOxygen();
3642
}
3743
}
3844
}

Source/Settings/Settings.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ContentSettings.API.Attributes;
1+
using BepInEx;
2+
using ContentSettings.API.Attributes;
23
using ContentSettings.API.Settings;
34
using Unity.Mathematics;
45
using Zorro.Settings;
@@ -24,13 +25,36 @@ public class DaysPerQuota : IntSetting, ICustomSetting {
2425
public override void ApplyValue() {
2526
Plugin.State.daysPerQuota = Value;
2627
Plugin.Sync.SyncSettings();
28+
SettingsUtil.UpdateQuotaDays();
2729
}
2830

2931
public string GetDisplayName() => "Days Per Quota";
3032
public override int GetDefaultValue() => 3;
3133
public override (int, int) GetMinMaxValue() => (0, 30);
3234
}
3335

36+
[SettingRegister("GAMEPLAY", "GENERAL")]
37+
public class RequireAllPlayersInDiveBell : BoolSetting, ICustomSetting {
38+
public override void ApplyValue() {
39+
Plugin.State.requireAllPlayersInDiveBell = Value;
40+
Plugin.Sync.SyncSettings();
41+
}
42+
43+
public string GetDisplayName() => "Require All Players in Dive Bell";
44+
public override bool GetDefaultValue() => true;
45+
}
46+
47+
[SettingRegister("GAMEPLAY", "GENERAL")]
48+
public class RequireDiveBellDoorClosed : BoolSetting, ICustomSetting {
49+
public override void ApplyValue() {
50+
Plugin.State.requireDiveBellDoorClosed = Value;
51+
Plugin.Sync.SyncSettings();
52+
}
53+
54+
public string GetDisplayName() => "Require Dive Bell Door Closed";
55+
public override bool GetDefaultValue() => true;
56+
}
57+
3458
// -------------------- Player -------------------- //
3559

3660
[SettingRegister("GAMEPLAY", "PLAYER")]
@@ -59,6 +83,17 @@ public override void ApplyValue() {
5983
public override float2 GetMinMaxValue() => new(0f, 2000f);
6084
}
6185

86+
[SettingRegister("GAMEPLAY", "OXYGEN")]
87+
public class InfiniteOxygen : BoolSetting, ICustomSetting {
88+
public override void ApplyValue() {
89+
Plugin.State.infiniteOxygen = Value;
90+
Plugin.Sync.SyncSettings();
91+
}
92+
93+
public string GetDisplayName() => "Enable Infinite Oxygen";
94+
public override bool GetDefaultValue() => false;
95+
}
96+
6297
[SettingRegister("GAMEPLAY", "OXYGEN")]
6398
public class OxygenUsageMultiplier : FloatSetting, ICustomSetting {
6499
public override void ApplyValue() {

Source/Settings/State.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class SettingsState {
1111
public bool useOxygenOnSurface;
1212
public bool refillOxygenOnSurface;
1313
public float oxygenRefillRate;
14+
public bool requireAllPlayersInDiveBell;
15+
public bool requireDiveBellDoorClosed;
16+
public bool infiniteOxygen;
1417

1518
public SettingsState() {
1619
privateHost = true;
@@ -19,11 +22,14 @@ public SettingsState() {
1922
daysPerQuota = 3;
2023
sprintUsage = 1.0f;
2124
oxygenUsage = 1.0f;
22-
useOxygenInDiveBell = true;
23-
refillOxygenInDiveBell = true;
24-
useOxygenOnSurface = true;
25+
useOxygenInDiveBell = false;
26+
refillOxygenInDiveBell = false;
27+
useOxygenOnSurface = false;
2528
refillOxygenOnSurface = true;
2629
oxygenRefillRate = 1.0f;
30+
requireAllPlayersInDiveBell = true;
31+
requireDiveBellDoorClosed = true;
32+
infiniteOxygen = false;
2733
}
2834
}
2935
}

Source/Settings/Util.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@
55

66
namespace ConfigurableWarning.Settings {
77
public class SettingsUtil {
8-
public static void SetValue<T>(ref T setting, float value) where T: FloatSetting {
8+
public static void SetValue<T>(ref T setting, float value) where T : FloatSetting {
99
setting.Value = setting.Clamp(value);
1010
GameHandler.Instance.SettingsHandler.SaveSetting(setting);
1111
}
1212

13-
public static void SetValue<T>(ref T setting, int value) where T: IntSetting {
13+
public static void SetValue<T>(ref T setting, int value) where T : IntSetting {
1414
setting.Value = setting.Clamp(value);
1515
GameHandler.Instance.SettingsHandler.SaveSetting(setting);
1616
}
1717

18-
public static void SetValue<T>(ref T setting, bool value) where T: BoolSetting {
18+
public static void SetValue<T>(ref T setting, bool value) where T : BoolSetting {
1919
setting.Value = value;
2020
GameHandler.Instance.SettingsHandler.SaveSetting(setting);
2121
}
22+
23+
public static void UpdateQuotaDays() {
24+
if (SurfaceNetworkHandler.RoomStats != null)
25+
SurfaceNetworkHandler.RoomStats.DaysPerQutoa = Plugin.State.daysPerQuota;
26+
}
2227
}
2328
}

0 commit comments

Comments
 (0)