public static void RegisterProcessParams(string soundbank, string param1, string param2) { if (procParams.ContainsKey(soundbank)) { procParams[soundbank] = new ProcessParameters(param1, param2); } else { procParams.Add(soundbank, new ProcessParameters(param1, param2)); } }
public static bool Prefix(LoadedAudioBank __instance, ref AKRESULT __result, ref uint ___id) { RLog.M.TWL(0, "LoadedAudioBank.LoadBankExternal " + __instance.name); if (ModTek.soundBanks.ContainsKey(__instance.name) == false) { return(false); } var uri = new System.Uri(ModTek.soundBanks[__instance.name].filename).AbsoluteUri; RLog.M.WL(1, uri); WWW www = new WWW(uri); while (!www.isDone) { Thread.Sleep(25); } RLog.M.WL(1, "'" + uri + "' loaded"); ProcessParameters pparams = SoundBanksProcessHelper.GetRegistredProcParams(__instance.name); GCHandle? handle = null; uint dataLength = (uint)www.bytes.Length; if (pparams != null) { RLog.M.WL(1, "found post-process parameters " + pparams.param1 + " " + pparams.param2); Aes aes = Aes.Create(); aes.Mode = CipherMode.CBC; aes.KeySize = 256; aes.BlockSize = 128; aes.FeedbackSize = 128; aes.Padding = PaddingMode.PKCS7; aes.Key = Convert.FromBase64String(pparams.param1); aes.IV = Convert.FromBase64String(pparams.param2); ICryptoTransform encryptor = aes.CreateDecryptor(aes.Key, aes.IV); byte[] result = null; using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { csEncrypt.Write(www.bytes, 0, www.bytes.Length); } result = msEncrypt.ToArray(); } handle = GCHandle.Alloc((object)result, GCHandleType.Pinned); dataLength = (uint)result.Length; } else { handle = GCHandle.Alloc((object)www.bytes, GCHandleType.Pinned); dataLength = (uint)www.bytes.Length; } if (handle.HasValue == false) { return(false); } try { uint id = uint.MaxValue; __result = AkSoundEngine.LoadBank(handle.Value.AddrOfPinnedObject(), dataLength, out id); ___id = id; if (__result == AKRESULT.AK_Success) { ModTek.soundBanks[__instance.name].registerEvents(); ModTek.soundBanks[__instance.name].setVolume(); } ; } catch { __result = AKRESULT.AK_Fail; } RLog.M.WL(1, "Result:" + __result + " id:" + ___id + " length:" + dataLength); return(false); }