1
0

PatchMaster.cs 3.5 KB

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