mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
cleanup, disable sfx by default, adjust volume
Cleaned up code & disabled SFX by default. Also adjusted the preceived volume of the sfx clips in audacity to hopefully be equal to the existing UI sounds.
This commit is contained in:
parent
e2121e4535
commit
01a336d881
5 changed files with 64 additions and 76 deletions
|
@ -2,7 +2,6 @@
|
||||||
using ABI_RC.Core.AudioEffects;
|
using ABI_RC.Core.AudioEffects;
|
||||||
using ABI_RC.Core.Networking;
|
using ABI_RC.Core.Networking;
|
||||||
using ABI_RC.Core.Savior;
|
using ABI_RC.Core.Savior;
|
||||||
using ABI_RC.Core.UI;
|
|
||||||
using ABI_RC.Core.Util;
|
using ABI_RC.Core.Util;
|
||||||
using DarkRift;
|
using DarkRift;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
|
@ -24,7 +23,7 @@ public class PropUndoButton : MelonMod
|
||||||
Category.CreateEntry("Enabled", true, description: "Toggle Undo Prop Button.");
|
Category.CreateEntry("Enabled", true, description: "Toggle Undo Prop Button.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<bool> EntryUseSFX =
|
public static readonly MelonPreferences_Entry<bool> EntryUseSFX =
|
||||||
Category.CreateEntry("Use SFX", true, description: "Enable or disable undo SFX.");
|
Category.CreateEntry("Use SFX", false, description: "Toggle audio queues for prop spawn, undo, redo, or warning.");
|
||||||
|
|
||||||
// audio clip names, InterfaceAudio adds "PropUndo_" prefix
|
// audio clip names, InterfaceAudio adds "PropUndo_" prefix
|
||||||
public const string sfx_spawn = "PropUndo_sfx_spawn";
|
public const string sfx_spawn = "PropUndo_sfx_spawn";
|
||||||
|
@ -57,6 +56,7 @@ public class PropUndoButton : MelonMod
|
||||||
typeof(CVRWorld).GetMethod(nameof(CVRWorld.ConfigureWorld)),
|
typeof(CVRWorld).GetMethod(nameof(CVRWorld.ConfigureWorld)),
|
||||||
postfix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnWorldLoad), BindingFlags.NonPublic | BindingFlags.Static))
|
postfix: new HarmonyLib.HarmonyMethod(typeof(PropUndoButton).GetMethod(nameof(OnWorldLoad), BindingFlags.NonPublic | BindingFlags.Static))
|
||||||
);
|
);
|
||||||
|
|
||||||
SetupDefaultAudioClips();
|
SetupDefaultAudioClips();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +97,12 @@ public class PropUndoButton : MelonMod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void OnWorldLoad() => deletedProps.Clear();
|
||||||
|
|
||||||
private static void OnUpdateInput()
|
private static void OnUpdateInput()
|
||||||
{
|
{
|
||||||
|
if (!EntryEnabled.Value) return;
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.LeftControl))
|
if (Input.GetKey(KeyCode.LeftControl))
|
||||||
{
|
{
|
||||||
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Z))
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Z))
|
||||||
|
@ -116,16 +120,7 @@ public class PropUndoButton : MelonMod
|
||||||
{
|
{
|
||||||
if (!EntryEnabled.Value) return;
|
if (!EntryEnabled.Value) return;
|
||||||
|
|
||||||
if (!MetaPort.Instance.worldAllowProps
|
if (!IsPropSpawnAllowed() || IsAtPropLimit())
|
||||||
|| !MetaPort.Instance.settings.GetSettingsBool("ContentFilterPropsEnabled", false)
|
|
||||||
|| NetworkManager.Instance.GameNetwork.ConnectionState != ConnectionState.Connected)
|
|
||||||
{
|
|
||||||
PlayAudioModule(sfx_warn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// might need to touch
|
|
||||||
if (IsAtPropLimit())
|
|
||||||
{
|
{
|
||||||
PlayAudioModule(sfx_warn);
|
PlayAudioModule(sfx_warn);
|
||||||
return;
|
return;
|
||||||
|
@ -136,29 +131,30 @@ public class PropUndoButton : MelonMod
|
||||||
|
|
||||||
private static void OnDeletePropByInstanceId(string instanceId)
|
private static void OnDeletePropByInstanceId(string instanceId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(instanceId)) return;
|
if (!EntryEnabled.Value || string.IsNullOrEmpty(instanceId)) return;
|
||||||
|
|
||||||
CVRSyncHelper.PropData propData = GetPropByInstanceId(instanceId);
|
var propData = GetPropByInstanceIdAndOwnerId(instanceId);
|
||||||
if (propData == null) return;
|
if (propData == null) return;
|
||||||
|
|
||||||
// Add the spawned prop to the history of deleted props
|
AddDeletedProp(propData);
|
||||||
if (deletedProps.Count >= redoHistoryLimit) deletedProps.RemoveAt(0); // Remove the oldest item
|
|
||||||
|
|
||||||
DeletedProp deletedProp = new DeletedProp(propData);
|
|
||||||
deletedProps.Add(deletedProp);
|
|
||||||
|
|
||||||
PlayAudioModule(sfx_undo);
|
PlayAudioModule(sfx_undo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnWorldLoad()
|
private static void AddDeletedProp(CVRSyncHelper.PropData propData)
|
||||||
{
|
{
|
||||||
deletedProps.Clear();
|
if (deletedProps.Count >= redoHistoryLimit)
|
||||||
|
deletedProps.RemoveAt(0);
|
||||||
|
|
||||||
|
DeletedProp deletedProp = new DeletedProp(propData);
|
||||||
|
deletedProps.Add(deletedProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete in reverse order for undo to work as expected
|
// delete in reverse order for undo to work as expected
|
||||||
private static bool OnDeleteMyProps()
|
private static bool OnDeleteMyProps()
|
||||||
{
|
{
|
||||||
List<CVRSyncHelper.PropData> propsList = GetAllProps();
|
if (!EntryEnabled.Value) return true;
|
||||||
|
|
||||||
|
List<CVRSyncHelper.PropData> propsList = GetAllPropsByOwnerId();
|
||||||
|
|
||||||
for (int i = propsList.Count - 1; i >= 0; i--)
|
for (int i = propsList.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
@ -178,9 +174,7 @@ public class PropUndoButton : MelonMod
|
||||||
|
|
||||||
private static void UndoProp()
|
private static void UndoProp()
|
||||||
{
|
{
|
||||||
if (!EntryEnabled.Value) return;
|
var propData = GetLatestPropByOwnerId();
|
||||||
|
|
||||||
var propData = GetLatestProp();
|
|
||||||
if (propData == null)
|
if (propData == null)
|
||||||
{
|
{
|
||||||
PlayAudioModule(sfx_warn);
|
PlayAudioModule(sfx_warn);
|
||||||
|
@ -190,7 +184,6 @@ public class PropUndoButton : MelonMod
|
||||||
if (propData.Spawnable == null)
|
if (propData.Spawnable == null)
|
||||||
{
|
{
|
||||||
propData.Recycle();
|
propData.Recycle();
|
||||||
// what should i do here?
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +199,9 @@ public class PropUndoButton : MelonMod
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only allow redo of prop spawned in last minute
|
||||||
DeletedProp deletedProp = deletedProps[index];
|
DeletedProp deletedProp = deletedProps[index];
|
||||||
if (Time.time - deletedProp.timeDeleted <= redoTimeoutLimit) // only allow redo of prop spawned in last minute
|
if (Time.time - deletedProp.timeDeleted <= redoTimeoutLimit)
|
||||||
{
|
{
|
||||||
if (AttemptRedoProp(deletedProp.propGuid, deletedProp.position, deletedProp.rotation))
|
if (AttemptRedoProp(deletedProp.propGuid, deletedProp.position, deletedProp.rotation))
|
||||||
{
|
{
|
||||||
|
@ -221,21 +215,19 @@ public class PropUndoButton : MelonMod
|
||||||
}
|
}
|
||||||
|
|
||||||
// original spawn prop method does not let you specify rotation
|
// original spawn prop method does not let you specify rotation
|
||||||
public static bool AttemptRedoProp(string propGuid, Vector3 position, Quaternion quaternion)
|
public static bool AttemptRedoProp(string propGuid, Vector3 position, Vector3 rotation)
|
||||||
{
|
|
||||||
if (MetaPort.Instance.worldAllowProps
|
|
||||||
&& MetaPort.Instance.settings.GetSettingsBool("ContentFilterPropsEnabled", false)
|
|
||||||
&& NetworkManager.Instance.GameNetwork.ConnectionState == ConnectionState.Connected)
|
|
||||||
{
|
{
|
||||||
|
if (!IsPropSpawnAllowed()) return false;
|
||||||
|
|
||||||
using (DarkRiftWriter darkRiftWriter = DarkRiftWriter.Create())
|
using (DarkRiftWriter darkRiftWriter = DarkRiftWriter.Create())
|
||||||
{
|
{
|
||||||
darkRiftWriter.Write(propGuid);
|
darkRiftWriter.Write(propGuid);
|
||||||
darkRiftWriter.Write(position.x);
|
darkRiftWriter.Write(position.x);
|
||||||
darkRiftWriter.Write(position.y);
|
darkRiftWriter.Write(position.y);
|
||||||
darkRiftWriter.Write(position.z);
|
darkRiftWriter.Write(position.z);
|
||||||
darkRiftWriter.Write(0f);
|
darkRiftWriter.Write(rotation.x);
|
||||||
darkRiftWriter.Write(quaternion.eulerAngles.y);
|
darkRiftWriter.Write(rotation.y);
|
||||||
darkRiftWriter.Write(0f);
|
darkRiftWriter.Write(rotation.z);
|
||||||
darkRiftWriter.Write(1f);
|
darkRiftWriter.Write(1f);
|
||||||
darkRiftWriter.Write(1f);
|
darkRiftWriter.Write(1f);
|
||||||
darkRiftWriter.Write(1f);
|
darkRiftWriter.Write(1f);
|
||||||
|
@ -244,54 +236,50 @@ public class PropUndoButton : MelonMod
|
||||||
{
|
{
|
||||||
NetworkManager.Instance.GameNetwork.SendMessage(message, SendMode.Reliable);
|
NetworkManager.Instance.GameNetwork.SendMessage(message, SendMode.Reliable);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!MetaPort.Instance.worldAllowProps)
|
|
||||||
{
|
|
||||||
CohtmlHud.Instance.ViewDropText("Props are not allowed in this world", "");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void PlayAudioModule(string module)
|
public static void PlayAudioModule(string module)
|
||||||
{
|
{
|
||||||
if (!EntryUseSFX.Value) return;
|
if (EntryUseSFX.Value)
|
||||||
|
{
|
||||||
InterfaceAudio.PlayModule(module);
|
InterfaceAudio.PlayModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsAtPropLimit()
|
|
||||||
{
|
|
||||||
// might need rework
|
|
||||||
return GetAllProps().Count >= 20;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CVRSyncHelper.PropData GetPropByInstanceId(string instanceId)
|
private static bool IsPropSpawnAllowed()
|
||||||
{
|
{
|
||||||
// find prop by instance id and if it is ours
|
return MetaPort.Instance.worldAllowProps
|
||||||
return CVRSyncHelper.Props.Find((CVRSyncHelper.PropData match) => (match.InstanceId == instanceId && match.SpawnedBy == MetaPort.Instance.ownerId));
|
&& MetaPort.Instance.settings.GetSettingsBool("ContentFilterPropsEnabled", false)
|
||||||
|
&& NetworkManager.Instance.GameNetwork.ConnectionState == ConnectionState.Connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CVRSyncHelper.PropData GetLatestProp()
|
public static bool IsAtPropLimit(int limit = 20)
|
||||||
{
|
{
|
||||||
// should already be sorted by spawn order
|
return GetAllPropsByOwnerId().Count >= limit;
|
||||||
return CVRSyncHelper.Props.LastOrDefault((CVRSyncHelper.PropData match) => match.SpawnedBy == MetaPort.Instance.ownerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<CVRSyncHelper.PropData> GetAllProps()
|
private static CVRSyncHelper.PropData GetPropByInstanceIdAndOwnerId(string instanceId)
|
||||||
{
|
{
|
||||||
// im not storing the count because there is good chance itll desync from server
|
return CVRSyncHelper.Props.Find(propData => propData.InstanceId == instanceId && propData.SpawnedBy == MetaPort.Instance.ownerId);
|
||||||
return CVRSyncHelper.Props.FindAll((CVRSyncHelper.PropData match) => match.SpawnedBy == MetaPort.Instance.ownerId);
|
}
|
||||||
|
|
||||||
|
private static CVRSyncHelper.PropData GetLatestPropByOwnerId()
|
||||||
|
{
|
||||||
|
return CVRSyncHelper.Props.LastOrDefault(propData => propData.SpawnedBy == MetaPort.Instance.ownerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<CVRSyncHelper.PropData> GetAllPropsByOwnerId()
|
||||||
|
{
|
||||||
|
return CVRSyncHelper.Props.FindAll(propData => propData.SpawnedBy == MetaPort.Instance.ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeletedProp
|
public class DeletedProp
|
||||||
{
|
{
|
||||||
public string propGuid;
|
public string propGuid;
|
||||||
public Vector3 position;
|
public Vector3 position;
|
||||||
public Quaternion rotation;
|
public Vector3 rotation;
|
||||||
public float timeDeleted;
|
public float timeDeleted;
|
||||||
|
|
||||||
public DeletedProp(CVRSyncHelper.PropData propData)
|
public DeletedProp(CVRSyncHelper.PropData propData)
|
||||||
|
@ -301,10 +289,10 @@ public class PropUndoButton : MelonMod
|
||||||
Vector3 position = spawnable.position;
|
Vector3 position = spawnable.position;
|
||||||
position.y -= propData.Spawnable.spawnHeight;
|
position.y -= propData.Spawnable.spawnHeight;
|
||||||
|
|
||||||
propGuid = propData.ObjectId;
|
this.propGuid = propData.ObjectId;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
rotation = spawnable.rotation;
|
this.rotation = spawnable.rotation.eulerAngles;
|
||||||
timeDeleted = Time.time;
|
this.timeDeleted = Time.time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue