From c474b27cd8a359ed76143da696f9d442997c8285 Mon Sep 17 00:00:00 2001
From: Kittenji <41535779+ChrisFeline@users.noreply.github.com>
Date: Thu, 17 Oct 2024 20:15:44 -0400
Subject: [PATCH] Implement ToN_HostChange OSC param.
---
Models/AppSettings.cs | 10 ++++++++++
Utils/LilOSC.cs | 44 +++++++++++++++++++++++++++++++++++++++----
Windows/MainWindow.cs | 8 ++++++++
3 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/Models/AppSettings.cs b/Models/AppSettings.cs
index a6e5ed1..beb1623 100644
--- a/Models/AppSettings.cs
+++ b/Models/AppSettings.cs
@@ -169,6 +169,16 @@ public int GetDeathID (string id) {
return Array.IndexOf(OSCDeathIDs, id) + 1;
}
+
+ ///
+ /// OSC Master Changed event for OSC.
+ ///
+ public bool OSCMasterChange { get; set; } = true;
+ ///
+ /// OSC Master Change event interval.
+ ///
+ public int OSCMasterChangeInterval { get; set; } = 200;
+
///
/// Enables OSC chatbox messages.
///
diff --git a/Utils/LilOSC.cs b/Utils/LilOSC.cs
index a2415dc..aca7705 100644
--- a/Utils/LilOSC.cs
+++ b/Utils/LilOSC.cs
@@ -45,13 +45,14 @@ internal static class LilOSC {
const string ParamDeath = "ToN_DeathID";
const string ParamPages = "ToN_Pages";
const string ParamItemStatus = "ToN_ItemStatus";
+ const string ParamMaster = "ToN_MasterChange";
static readonly string[] ParamAll = [
ParamRoundType, ParamTerror1, ParamTerror2, ParamTerror3, ParamTPhase1, ParamTPhase2, ParamTPhase3,
ParamOptedIn, ParamSaboteur, ParamMap, ParamEncounter,
ParamTerrorColorH, ParamTerrorColorS, ParamTerrorColorV, ParamTerrorColorL,
ParamTerrorColorR, ParamTerrorColorG, ParamTerrorColorB,
- ParamAlive, ParamReborn, ParamDamaged, ParamDeath, ParamPages, ParamItemStatus
+ ParamAlive, ParamReborn, ParamDamaged, ParamMaster, ParamDeath, ParamPages, ParamItemStatus
];
const string ParameterFileName = "osc_parameters.txt";
internal static void Initialize() {
@@ -186,6 +187,36 @@ private static void DeathTimer_Tick(object? sender, EventArgs e) {
}
#endregion
+ #region Host Change
+ private static Timer? HostTimer;
+ private static bool LastHost = false;
+ internal static void SendHostChange() {
+ if (LastHost || !MainWindow.Started || !Settings.Get.OSCMasterChange || !Settings.Get.OSCEnabled) return;
+
+ if (HostTimer == null) {
+ HostTimer = new Timer();
+ HostTimer.Tick += HostTimer_Tick;
+ HostTimer.Interval = Settings.Get.OSCMasterChangeInterval;
+ }
+
+ LastHost = true;
+ SendParam(ParamMaster, LastHost);
+
+ HostTimer.Stop();
+ if (Settings.Get.OSCMasterChangeInterval > 0) {
+ HostTimer.Interval = Settings.Get.OSCMasterChangeInterval;
+ HostTimer.Start();
+ } else LastHost = false;
+ }
+
+ private static void HostTimer_Tick(object? sender, EventArgs e) {
+ HostTimer?.Stop();
+
+ LastHost = false;
+ SendParam(ParamMaster, LastHost);
+ }
+ #endregion
+
private static Timer? DamageTimer;
private static int LastDamage = 0;
internal static void SetDamage(int damage) {
@@ -198,11 +229,16 @@ internal static void SetDamage(int damage) {
}
if (LastDamage != damage) {
- DamageTimer.Stop();
- DamageTimer.Start();
-
LastDamage = damage;
SendParam(ParamDamaged, damage); // change param to a const
+
+ DamageTimer.Stop();
+ if (Settings.Get.OSCDamagedInterval > 0) {
+ DamageTimer.Interval = Settings.Get.OSCDamagedInterval;
+ DamageTimer.Start();
+ } else {
+ LastDamage = 0;
+ }
}
}
diff --git a/Windows/MainWindow.cs b/Windows/MainWindow.cs
index 45f7ff4..330201e 100644
--- a/Windows/MainWindow.cs
+++ b/Windows/MainWindow.cs
@@ -872,6 +872,9 @@ private bool HandleTerrorIndex(string line, DateTime timestamp, ToNLogContext co
const string STAT_STUN_LANDED = " landed a stun!";
const string STAT_STUN_TARGET = " was stunned.";
const string STAT_HIT = "Hit - ";
+
+ const string EVENT_MASTER_CHANGE = "[Behaviour] OnMasterClientSwitched";
+
private bool HandleStatCollection(string line, DateTime timestamp, ToNLogContext context) {
if (!context.IsRecent) return false;
@@ -893,6 +896,11 @@ private bool HandleStatCollection(string line, DateTime timestamp, ToNLogContext
}
if (Settings.Get.OSCEnabled) {
+ if (Settings.Get.OSCMasterChange && line.StartsWith(EVENT_MASTER_CHANGE)) {
+ LilOSC.SendHostChange();
+ return true;
+ }
+
bool isActivated = line.StartsWith("[UNSTABLE COIL] Activated!") || line.StartsWith("[EMERALD COIL] Activated!") || line.StartsWith("[CORKSCREW COIL] Activated!");
bool isDeactivated = line.StartsWith("[UNSTABLE COIL] Deactivated!") || line.StartsWith("[EMERALD COIL] Deactivated!") || line.StartsWith("[CORKSCREW COIL] Deactivated!");
if (isActivated || isDeactivated) {