using Harmony; using Il2Cpp; using Il2CppAK.Wwise; using MelonLoader; using UnityEngine; namespace AudioMgr { public static class PatchMaster { private static Dictionary _replacePatches = new Dictionary(); private static List _skipPatches = new List(); public enum ParameterType { Absolute, Percentage, Limitter }; private static Dictionary _parameterPatches = new Dictionary(); private static Dictionary _parameterValues = new Dictionary(); public static void AddParameterPatch(string parameterID, float value, ParameterType type) { if (!_parameterPatches.ContainsKey(parameterID)) { _parameterPatches.Add(parameterID, type); _parameterValues.Add(parameterID, value); } } public static void AddReplacePatch(string eventID, ClipManager clipManager, string clipString, AudioMaster.SourceType sourceType) { if (!_replacePatches.ContainsKey(eventID)) { _replacePatches.Add(eventID, new ReplacePatch(eventID, clipManager, clipString, sourceType)); } } public static void AddSkipPatch(string eventID) { if (!_skipPatches.Contains(eventID)) { _skipPatches.Add(eventID); } } public static float ParameterAction(string parameterID, float originalValue) { if (_parameterPatches.ContainsKey(parameterID)) { if (AudioMain._debug) MelonLogger.Msg("ParameterAction in Action now " + parameterID + "; " + originalValue); if (_parameterPatches[parameterID] == ParameterType.Absolute) { if (AudioMain._debug) MelonLogger.Msg("Limit to " + _parameterPatches[parameterID]); return _parameterValues[parameterID]; } else if(_parameterPatches[parameterID] == ParameterType.Percentage) { if (AudioMain._debug) MelonLogger.Msg("Limit to " + _parameterPatches[parameterID]); return (originalValue / 100) * _parameterValues[parameterID]; } else if (_parameterPatches[parameterID] == ParameterType.Limitter) { if (AudioMain._debug) MelonLogger.Msg("Limit to " + _parameterValues[parameterID]); if (originalValue > _parameterValues[parameterID]) { return _parameterValues[parameterID]; } } } return originalValue; } public static bool PatchAction(string eventID, GameObject gameObject) { if(_skipPatches.Contains(eventID)) { return true; } else if(_replacePatches.ContainsKey(eventID)) { _replacePatches[eventID].PlayOneshot(gameObject); //_globalPatches[eventID].PlayQueue(gameObject); return true; } return false; } } }