PatchMaster.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Harmony;
  2. using Il2Cpp;
  3. using MelonLoader;
  4. using UnityEngine;
  5. namespace AudioMgr
  6. {
  7. public static class PatchMaster
  8. {
  9. private static Dictionary<string, ReplacePatch> _replacePatches = new Dictionary<string, ReplacePatch>();
  10. private static List<string> _skipPatches = new List<string>();
  11. public enum ParameterType { Absolute, Percentage, Limitter };
  12. private static Dictionary<string, ParameterType> _parameterPatches = new Dictionary<string, ParameterType>();
  13. private static Dictionary<string, float> _parameterValues = new Dictionary<string, float>();
  14. public static void AddParameterPatch(string parameterID, float value, ParameterType type)
  15. {
  16. if (!_parameterPatches.ContainsKey(parameterID))
  17. {
  18. _parameterPatches.Add(parameterID, type);
  19. _parameterValues.Add(parameterID, value);
  20. }
  21. }
  22. public static void AddReplacePatch(string eventID, ClipManager clipManager, string clipString, AudioMaster.SourceType sourceType)
  23. {
  24. if (!_replacePatches.ContainsKey(eventID))
  25. {
  26. _replacePatches.Add(eventID, new ReplacePatch(eventID, clipManager, clipString, sourceType));
  27. }
  28. }
  29. public static void AddSkipPatch(string eventID)
  30. {
  31. if (!_skipPatches.Contains(eventID))
  32. {
  33. _skipPatches.Add(eventID);
  34. }
  35. }
  36. public static float ParameterAction(string parameterID, float originalValue)
  37. {
  38. if (_parameterPatches.ContainsKey(parameterID))
  39. {
  40. if (_parameterPatches[parameterID] == ParameterType.Absolute)
  41. {
  42. return _parameterValues[parameterID];
  43. }
  44. else if(_parameterPatches[parameterID] == ParameterType.Percentage)
  45. {
  46. return (originalValue / 100) * _parameterValues[parameterID];
  47. }
  48. else if (_parameterPatches[parameterID] == ParameterType.Limitter)
  49. {
  50. if(originalValue > _parameterValues[parameterID])
  51. {
  52. return _parameterValues[parameterID];
  53. }
  54. }
  55. }
  56. return originalValue;
  57. }
  58. public static bool PatchAction(string eventID, GameObject gameObject)
  59. {
  60. if(_skipPatches.Contains(eventID))
  61. {
  62. return true;
  63. }
  64. else if(_replacePatches.ContainsKey(eventID))
  65. {
  66. _replacePatches[eventID].PlayOneshot(gameObject);
  67. //_globalPatches[eventID].PlayQueue(gameObject);
  68. return true;
  69. }
  70. return false;
  71. }
  72. }
  73. }