Skip to content

Commit

Permalink
HRtoVRChat | v1.5.1
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
200Tigersbloxed committed Feb 25, 2022
1 parent c31e879 commit 71eb7e7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 46 deletions.
96 changes: 52 additions & 44 deletions HRtoVRChat/HRtoVRChat/MainMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MainMod : MelonMod
private bool isRestarting = false;

public static Action<int, int, int, int, bool, bool> OnHRValuesUpdated = (ones, tens, hundreds, HR, isConnected, isActive) => { };
public static Action<bool, bool> OnHeartBeatUpdate = (isHeartBeat, shouldStart) => { };
public static Action<bool> OnHeartBeatUpdate = isHeartBeat => { };
public static bool isHeartBeat { get; private set; } = false;

private bool isAppClosing = false;
Expand Down Expand Up @@ -77,7 +77,7 @@ public override void OnApplicationLateStart()
}
//VRChatUtilityKit.Utilities.NetworkEvents.OnAvatarInstantiated += NetworkEvents_OnAvatarInstantiated;
EasyAvatarHook.OnAvatarInstantiated += OnAvatarInstantiatedListener;
OnHeartBeatUpdate += (hrb, restart) => { if(restart) MelonCoroutines.Start(WaitStartHeartBeat()); };
//OnHeartBeatUpdate += (hrb, restart) => { if(restart) MelonCoroutines.Start(WaitStartHeartBeat()); };
// Start everything else
Start();
// based, red-pilled
Expand Down Expand Up @@ -126,7 +126,9 @@ private void Start()
{
StartHRListener();
// Start Coroutine
RunBoopUwU = true;
MelonCoroutines.Start(BoopUwU());
RunHeartBeat = true;
MelonCoroutines.Start(HeartBeat());
}

Expand All @@ -138,11 +140,14 @@ private void Stop()
if(activeHRManager != null)
try
{
RunBoopUwU = false;
MelonCoroutines.Stop(BoopUwU()!);
RunHeartBeat = false;
MelonCoroutines.Stop(HeartBeat()!);
}
catch (Exception)
{
LogHelper.Warn("MainMod", "FunnyName Coroutine is null, you can probably ignore this.");
LogHelper.Warn("MainMod", "FunnyName or HeartBeat Coroutine is null, you can probably ignore this.");
}
// Stop HR Listener
StopHRListener();
Expand Down Expand Up @@ -248,64 +253,67 @@ private static void StopHRListener()
}

// why did i name the ienumerator this and why haven't i changed it
private static bool RunBoopUwU;
IEnumerator BoopUwU()
{
currentHRSplit chs = new currentHRSplit();
if (activeHRManager != null)
while (RunBoopUwU)
{
int HR = activeHRManager.GetHR();
bool isOpen = activeHRManager.IsOpen();
bool isActive = activeHRManager.IsActive();
// Cast to currentHRSplit
chs = intToHRSplit(HR);
OnHRValuesUpdated.Invoke(chs.ones, chs.tens, chs.hundreds, HR, isOpen, isActive);
currentHRSplit chs = new currentHRSplit();
if (activeHRManager != null)
{
int HR = activeHRManager.GetHR();
bool isOpen = activeHRManager.IsOpen();
bool isActive = activeHRManager.IsActive();
// Cast to currentHRSplit
chs = intToHRSplit(HR);
OnHRValuesUpdated.Invoke(chs.ones, chs.tens, chs.hundreds, HR, isOpen, isActive);
}
else
OnHRValuesUpdated.Invoke(0, 0, 0, 0, false, false);
yield return new WaitForSeconds(1);
}
yield return new WaitForSeconds(1);
if (UpdateIENum) MelonCoroutines.Start(BoopUwU());
}

static IEnumerator WaitStartHeartBeat()
{
yield return new WaitForSeconds(0.2f);
MelonCoroutines.Start(HeartBeat());
}

private static bool RunHeartBeat;
static IEnumerator HeartBeat()
{
if(activeHRManager != null)
while (RunHeartBeat)
{
bool io = activeHRManager.IsOpen();
// This should be started by the Melon Update void
if (io)
bool didRunProperly = false;
if(activeHRManager != null)
{
isHeartBeat = false;
// Get HR
float HR = activeHRManager.GetHR();
if (HR != 0)
bool io = activeHRManager.IsOpen();
// This should be started by the Melon Update void
if (io)
{
isHeartBeat = false;
OnHeartBeatUpdate.Invoke(isHeartBeat, false);
// Calculate wait interval
float waitTime = default(float);
// When lowering the HR significantly, this will cause issues with the beat bool
// Dubbed the "Breathing Excersise" bug
// There's a 'temp' fix for it right now, but I'm not sure how it'll hold up
try { waitTime = (1 / ((HR - 0.2f) / 60)); } catch (Exception) { /*Just a Divide by Zero Exception*/ }
yield return new WaitForSeconds(waitTime);
isHeartBeat = true;
OnHeartBeatUpdate.Invoke(isHeartBeat, false);
// Get HR
float HR = activeHRManager.GetHR();
if (HR != 0)
{
didRunProperly = true;
isHeartBeat = false;
OnHeartBeatUpdate.Invoke(isHeartBeat);
// Calculate wait interval
float waitTime = default(float);
// When lowering the HR significantly, this will cause issues with the beat bool
// Dubbed the "Breathing Excersise" bug
// There's a 'temp' fix for it right now, but I'm not sure how it'll hold up
try { waitTime = (1 / ((HR - 0.2f) / 60)); } catch (Exception) { /*Just a Divide by Zero Exception*/ }
yield return new WaitForSeconds(waitTime);
isHeartBeat = true;
OnHeartBeatUpdate.Invoke(isHeartBeat);
yield return new WaitForSeconds(waitTime);
}
}
}
else
if (!didRunProperly)
{
ParamsManager.HRParameter foundParam = ParamsManager.Parameters.Find(x => x.GetParamName() == "isHRBeat");
if (foundParam.GetParamValue() >= 1f)
{
isHeartBeat = false;
}
isHeartBeat = false;
yield return new WaitForSeconds(0.02f);
}
OnHeartBeatUpdate.Invoke(isHeartBeat);
}
OnHeartBeatUpdate.Invoke(isHeartBeat, true);
}

private currentHRSplit intToHRSplit(int hr)
Expand Down
2 changes: 1 addition & 1 deletion HRtoVRChat/HRtoVRChat/ParamsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public BoolParameter(BoolCheckType bct, string parameterName) : base(paramName:
{
SetParamName = parameterName;
LogHelper.Debug("ParamsManager", $"BoolParameter with ParameterName: {parameterName} and BoolCheckType of: {bct}, has been created!");
MainMod.OnHeartBeatUpdate += (isHeartBeat, shouldRestart) =>
MainMod.OnHeartBeatUpdate += isHeartBeat =>
{
switch (bct)
{
Expand Down
2 changes: 1 addition & 1 deletion HRtoVRChat/HRtoVRChat/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

[assembly: Guid("e60e13d3-e714-4d88-af0d-7df285f13178")]

[assembly: MelonInfo(typeof(MainMod), "HRtoVRChat", "1.5.0", "200Tigersbloxed")]
[assembly: MelonInfo(typeof(MainMod), "HRtoVRChat", "1.5.1", "200Tigersbloxed")]
[assembly: MelonGame("VRChat", "VRChat")]
[assembly: MelonOptionalDependencies(new string[] { "UIExpansionKit", "ActionMenuApi" })]

0 comments on commit 71eb7e7

Please sign in to comment.