Skip to content

Commit

Permalink
v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed May 5, 2024
1 parent 21f1a39 commit a6a2b75
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.12.0] - 2024-05-05

### Changed

- Added diving bell settings
- Updated sync

## [1.11.0] - 2024-05-02

### Changed
Expand Down
2 changes: 1 addition & 1 deletion ConfigurableWarning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>ConfigurableWarning</AssemblyName>
<Description>Makes the game configurable!</Description>
<Version>1.11.0</Version>
<Version>1.12.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);CS0436</NoWarn>
Expand Down
66 changes: 66 additions & 0 deletions Source/Patches/DivingBellPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using HarmonyLib;

namespace ConfigurableWarning.Patches {
[HarmonyPatch]
internal class DivingBellPatch {
[HarmonyPostfix]
[HarmonyPatch(typeof(DivingBellDoor), nameof(DivingBellDoor.IsFullyClosed))]
internal static void IsFullyClosed(DivingBellDoor __instance, ref bool __result) {
__result = __result || !Plugin.State.requireDiveBellDoorClosed;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(DiveBellPlayerDetector), nameof(DiveBellPlayerDetector.CheckForPlayers))]
internal static void CheckForPlayers(DiveBellPlayerDetector __instance, ref ICollection<Player> __result) {
if (!Plugin.State.requireAllPlayersInDiveBell) {
__result = PlayerHandler.instance.players;
}
}

[HarmonyPostfix]
[HarmonyPatch(typeof(DivingBell), nameof(DivingBell.Update))]
internal static void Update(DivingBell __instance) {
var recharging = __instance.onSurface && TimeOfDayHandler.TimeOfDay == TimeOfDay.Evening;

if (recharging) {
__instance.StateMachine.SwitchState<DivingBellRechargingState>();
return;
}

var allInside = true;
var playersFoundInBell = __instance.playerDetector.CheckForPlayers();
var players = PlayerHandler.instance.players;

foreach (Player player in players) {
if (!playersFoundInBell.Contains(player)) {
allInside = false;
break;
}
}

var notClosed = !__instance.door.IsFullyClosed() && Plugin.State.requireDiveBellDoorClosed;
var notAllInside = !allInside && Plugin.State.requireAllPlayersInDiveBell;

if (!notClosed) {
__instance.opened = false;
}

if (__instance.onSurface) {
if (notAllInside) {
__instance.StateMachine.SwitchState<DivingBellNotReadyMissingPlayersState>();
} else if (notClosed) {
__instance.StateMachine.SwitchState<DivingBellNotReadyDoorOpenState>();
} else {
__instance.StateMachine.SwitchState<DivingBellReadyState>();
}
} else {
if (notClosed) {
__instance.StateMachine.SwitchState<DivingBellNotReadyDoorOpenState>();
} else {
__instance.StateMachine.SwitchState<DivingBellReadyState>();
}
}
}
}
}
8 changes: 8 additions & 0 deletions Source/Patches/PlayerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ internal class PlayerPatch {
[HarmonyPrefix]
[HarmonyPatch(typeof(Player), nameof(Player.CheckOxygen))]
internal static bool CheckOxygen(Player __instance) {
if (Plugin.State.infiniteOxygen) {
__instance.data.remainingOxygen = Plugin.State.maxOxygen;
return false;
}

var isSurface = SceneManager.GetActiveScene().name == "SurfaceScene";
var flag = isSurface && !Plugin.State.useOxygenOnSurface;

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

__instance.maxOxygen = Plugin.State.maxOxygen;

// We want to override this functionality with our own code, but
// preserve the rest of the method.
__instance.usingOxygen = false;

return true;
Expand Down
8 changes: 0 additions & 8 deletions Source/Patches/UIPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,5 @@ internal class UIPatches {
internal static void UpdateHealth(UI_Health __instance) {
__instance.fill.fillAmount = Player.localPlayer.data.health / Plugin.State.maxHealth;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(UI_DaysLeft), nameof(UI_DaysLeft.Update))]
internal static void UpdateDaysLeft(UI_DaysLeft __instance) {
int num = Plugin.State.daysPerQuota - SurfaceNetworkHandler.RoomStats.CurrentQuotaDay + 1;

__instance.text.text = (num == 1) ? __instance.m_LastDayText : __instance.m_DaysLeftText.Replace("{0}", num.ToString());
}
}
}
14 changes: 14 additions & 0 deletions Source/Settings/PackedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class PackedSettings {
[SerializeField] private bool useOxygenOnSurface;
[SerializeField] private bool refillOxygenOnSurface;
[SerializeField] private float oxygenRefillRate;
[SerializeField] private bool requireAllPlayersInDiveBell;
[SerializeField] private bool requireDiveBellDoorClosed;
[SerializeField] private bool infiniteOxygen;

public static PackedSettings Collect() {
var me = new PackedSettings {
Expand All @@ -24,6 +27,9 @@ public static PackedSettings Collect() {
useOxygenOnSurface = Plugin.State.useOxygenOnSurface,
refillOxygenOnSurface = Plugin.State.refillOxygenOnSurface,
oxygenRefillRate = Plugin.State.oxygenRefillRate,
requireAllPlayersInDiveBell = Plugin.State.requireAllPlayersInDiveBell,
requireDiveBellDoorClosed = Plugin.State.requireDiveBellDoorClosed,
infiniteOxygen = Plugin.State.infiniteOxygen,
};

return me;
Expand All @@ -45,6 +51,9 @@ public static PackedSettings Unpack(string data) {
SettingsUtil.SetValue(ref Plugin.PluginSettings.useOxygenOnSurface, me.useOxygenOnSurface);
SettingsUtil.SetValue(ref Plugin.PluginSettings.refillOxygenOnSurface, me.refillOxygenOnSurface);
SettingsUtil.SetValue(ref Plugin.PluginSettings.oxygenRefillRate, me.oxygenRefillRate);
SettingsUtil.SetValue(ref Plugin.PluginSettings.requireAllPlayersInDiveBell, me.requireAllPlayersInDiveBell);
SettingsUtil.SetValue(ref Plugin.PluginSettings.requireDiveBellDoorClosed, me.requireDiveBellDoorClosed);
SettingsUtil.SetValue(ref Plugin.PluginSettings.infiniteOxygen, me.infiniteOxygen);

Plugin.State.maxOxygen = me.maxOxygen;
Plugin.State.maxHealth = me.maxHealth;
Expand All @@ -55,6 +64,11 @@ public static PackedSettings Unpack(string data) {
Plugin.State.useOxygenOnSurface = me.useOxygenOnSurface;
Plugin.State.refillOxygenOnSurface = me.refillOxygenOnSurface;
Plugin.State.oxygenRefillRate = me.oxygenRefillRate;
Plugin.State.requireAllPlayersInDiveBell = me.requireAllPlayersInDiveBell;
Plugin.State.requireDiveBellDoorClosed = me.requireDiveBellDoorClosed;
Plugin.State.infiniteOxygen = me.infiniteOxygen;

SettingsUtil.UpdateQuotaDays();

return me;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ public class PluginSettings {
public UseOxygenOnSurface useOxygenOnSurface;
public RefillOxygenOnSurface refillOxygenOnSurface;
public OxygenRefillRate oxygenRefillRate;
public RequireAllPlayersInDiveBell requireAllPlayersInDiveBell;
public RequireDiveBellDoorClosed requireDiveBellDoorClosed;
public InfiniteOxygen infiniteOxygen;

public PluginSettings() {
// -------------------- General -------------------- //

privateHost = new PrivateHost();
daysPerQuota = new DaysPerQuota();
requireAllPlayersInDiveBell = new RequireAllPlayersInDiveBell();
requireDiveBellDoorClosed = new RequireDiveBellDoorClosed();

// -------------------- Player -------------------- //

Expand All @@ -33,6 +38,7 @@ public PluginSettings() {
refillOxygenInDiveBell = new RefillOxygenInDiveBell();
useOxygenOnSurface = new UseOxygenOnSurface();
refillOxygenOnSurface = new RefillOxygenOnSurface();
infiniteOxygen = new InfiniteOxygen();
}
}
}
37 changes: 36 additions & 1 deletion Source/Settings/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ContentSettings.API.Attributes;
using BepInEx;
using ContentSettings.API.Attributes;
using ContentSettings.API.Settings;
using Unity.Mathematics;
using Zorro.Settings;
Expand All @@ -24,13 +25,36 @@ public class DaysPerQuota : IntSetting, ICustomSetting {
public override void ApplyValue() {
Plugin.State.daysPerQuota = Value;
Plugin.Sync.SyncSettings();
SettingsUtil.UpdateQuotaDays();
}

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

[SettingRegister("GAMEPLAY", "GENERAL")]
public class RequireAllPlayersInDiveBell : BoolSetting, ICustomSetting {
public override void ApplyValue() {
Plugin.State.requireAllPlayersInDiveBell = Value;
Plugin.Sync.SyncSettings();
}

public string GetDisplayName() => "Require All Players in Dive Bell";
public override bool GetDefaultValue() => true;
}

[SettingRegister("GAMEPLAY", "GENERAL")]
public class RequireDiveBellDoorClosed : BoolSetting, ICustomSetting {
public override void ApplyValue() {
Plugin.State.requireDiveBellDoorClosed = Value;
Plugin.Sync.SyncSettings();
}

public string GetDisplayName() => "Require Dive Bell Door Closed";
public override bool GetDefaultValue() => true;
}

// -------------------- Player -------------------- //

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

[SettingRegister("GAMEPLAY", "OXYGEN")]
public class InfiniteOxygen : BoolSetting, ICustomSetting {
public override void ApplyValue() {
Plugin.State.infiniteOxygen = Value;
Plugin.Sync.SyncSettings();
}

public string GetDisplayName() => "Enable Infinite Oxygen";
public override bool GetDefaultValue() => false;
}

[SettingRegister("GAMEPLAY", "OXYGEN")]
public class OxygenUsageMultiplier : FloatSetting, ICustomSetting {
public override void ApplyValue() {
Expand Down
12 changes: 9 additions & 3 deletions Source/Settings/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class SettingsState {
public bool useOxygenOnSurface;
public bool refillOxygenOnSurface;
public float oxygenRefillRate;
public bool requireAllPlayersInDiveBell;
public bool requireDiveBellDoorClosed;
public bool infiniteOxygen;

public SettingsState() {
privateHost = true;
Expand All @@ -19,11 +22,14 @@ public SettingsState() {
daysPerQuota = 3;
sprintUsage = 1.0f;
oxygenUsage = 1.0f;
useOxygenInDiveBell = true;
refillOxygenInDiveBell = true;
useOxygenOnSurface = true;
useOxygenInDiveBell = false;
refillOxygenInDiveBell = false;
useOxygenOnSurface = false;
refillOxygenOnSurface = true;
oxygenRefillRate = 1.0f;
requireAllPlayersInDiveBell = true;
requireDiveBellDoorClosed = true;
infiniteOxygen = false;
}
}
}
11 changes: 8 additions & 3 deletions Source/Settings/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

namespace ConfigurableWarning.Settings {
public class SettingsUtil {
public static void SetValue<T>(ref T setting, float value) where T: FloatSetting {
public static void SetValue<T>(ref T setting, float value) where T : FloatSetting {
setting.Value = setting.Clamp(value);
GameHandler.Instance.SettingsHandler.SaveSetting(setting);
}

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

public static void SetValue<T>(ref T setting, bool value) where T: BoolSetting {
public static void SetValue<T>(ref T setting, bool value) where T : BoolSetting {
setting.Value = value;
GameHandler.Instance.SettingsHandler.SaveSetting(setting);
}

public static void UpdateQuotaDays() {
if (SurfaceNetworkHandler.RoomStats != null)
SurfaceNetworkHandler.RoomStats.DaysPerQutoa = Plugin.State.daysPerQuota;
}
}
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.100"
"version": "8.0.204"
}
}

0 comments on commit a6a2b75

Please sign in to comment.