Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PandoraVoicesAndFix v1.0.1
BepInEx/patchers/PandoraCompatPatcher/PandoraCompatPatcher.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using HarmonyLib; using Mono.Cecil; using Mono.Cecil.Cil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace PandoraCompatPatcher; public static class Patcher { public static IEnumerable<string> TargetDLLs { get { yield return "Assembly-CSharp.dll"; } } public static void Initialize() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown try { Harmony val = new Harmony("com.fer.pandoracompatpatcher"); HarmonyMethod val2 = new HarmonyMethod(typeof(Patcher).GetMethod("DisambiguatePrefix", BindingFlags.Static | BindingFlags.NonPublic)); MethodInfo method = typeof(AccessTools).GetMethod("DeclaredMethod", BindingFlags.Static | BindingFlags.Public, null, new Type[4] { typeof(Type), typeof(string), typeof(Type[]), typeof(Type[]) }, null); if (method != null) { val.Patch((MethodBase)method, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo method2 = typeof(AccessTools).GetMethod("Method", BindingFlags.Static | BindingFlags.Public, null, new Type[4] { typeof(Type), typeof(string), typeof(Type[]), typeof(Type[]) }, null); if (method2 != null) { val.Patch((MethodBase)method2, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } catch (Exception ex) { Console.WriteLine("[PandoraCompatPatcher] Warning in Initialize: " + ex); } } private static bool DisambiguatePrefix(Type type, string name, Type[] parameters, Type[] generics, ref MethodInfo __result) { if (parameters != null || type == null || name == null) { return true; } int num = -1; if (name == "EnableEnemyMesh" && type.FullName == "EnemyAI") { num = 3; } else if (name == "KillPlayer" && type.FullName == "GameNetcodeStuff.PlayerControllerB") { num = 6; } else if (name == "HasLineOfSightToPosition" && type.FullName == "GameNetcodeStuff.PlayerControllerB") { num = 5; } if (num < 0) { return true; } MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name == name && methodInfo.GetParameters().Length == num) { __result = methodInfo; return false; } } return true; } public static void Patch(AssemblyDefinition assembly) { ModuleDefinition mainModule = assembly.MainModule; TypeDefinition type = mainModule.GetType("EnemyAI"); if (type != null) { AddEnableEnemyMeshOverload(mainModule, type); } TypeDefinition type2 = mainModule.GetType("GameNetcodeStuff.PlayerControllerB"); if (type2 != null) { AddKillPlayerOverload(mainModule, type2); AddHasLineOfSightOverload(mainModule, type2); } } private static void AddEnableEnemyMeshOverload(ModuleDefinition mod, TypeDefinition enemyAI) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) if (!((IEnumerable<MethodDefinition>)enemyAI.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "EnableEnemyMesh" && ((MethodReference)m).Parameters.Count == 2)) { MethodDefinition val = ((IEnumerable<MethodDefinition>)enemyAI.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "EnableEnemyMesh" && ((MethodReference)m).Parameters.Count == 3)); if (val != null) { MethodDefinition val2 = new MethodDefinition("EnableEnemyMesh", (MethodAttributes)134, mod.TypeSystem.Void); ((MethodReference)val2).Parameters.Add(new ParameterDefinition("enable", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType)); ((MethodReference)val2).Parameters.Add(new ParameterDefinition("overrideDoNotSet", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[1]).ParameterType)); ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val); iLProcessor.Emit(OpCodes.Ret); enemyAI.Methods.Add(val2); } } } private static void AddKillPlayerOverload(ModuleDefinition mod, TypeDefinition pcb) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) if (((IEnumerable<MethodDefinition>)pcb.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "KillPlayer" && ((MethodReference)m).Parameters.Count == 5)) { return; } MethodDefinition val = ((IEnumerable<MethodDefinition>)pcb.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "KillPlayer" && ((MethodReference)m).Parameters.Count == 6)); if (val != null) { MethodDefinition val2 = new MethodDefinition("KillPlayer", (MethodAttributes)134, mod.TypeSystem.Void); for (int num = 0; num < 5; num++) { ((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType)); } ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Ldarg_3); iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]); iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[4]); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val); iLProcessor.Emit(OpCodes.Ret); pcb.Methods.Add(val2); } } private static void AddHasLineOfSightOverload(ModuleDefinition mod, TypeDefinition pcb) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) if (((IEnumerable<MethodDefinition>)pcb.Methods).Any((MethodDefinition m) => ((MemberReference)m).Name == "HasLineOfSightToPosition" && ((MethodReference)m).Parameters.Count == 4)) { return; } MethodDefinition val = ((IEnumerable<MethodDefinition>)pcb.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => ((MemberReference)m).Name == "HasLineOfSightToPosition" && ((MethodReference)m).Parameters.Count == 5)); if (val != null) { MethodDefinition val2 = new MethodDefinition("HasLineOfSightToPosition", (MethodAttributes)134, mod.TypeSystem.Boolean); for (int num = 0; num < 4; num++) { ((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[num]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[num]).ParameterType)); } ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Ldarg_3); iLProcessor.Emit(OpCodes.Ldarg_S, ((MethodReference)val2).Parameters[3]); iLProcessor.Emit(OpCodes.Ldc_I4_M1); iLProcessor.Emit(OpCodes.Callvirt, (MethodReference)(object)val); iLProcessor.Emit(OpCodes.Ret); pcb.Methods.Add(val2); } } }
BepInEx/plugins/PandoraVoices/PandoraVoices.dll
Decompiled an hour agousing System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace PandoraVoices; [BepInPlugin("com.fer.pandoravoices", "PandoraVoicesAndFix", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private class VoiceState { public AudioSource Source; public float NextAllowedTime; } private const float CooldownSeconds = 18f; internal static ManualLogSource Log; internal static readonly List<AudioClip> SpawnClips = new List<AudioClip>(); internal static readonly List<AudioClip> ChaseClips = new List<AudioClip>(); internal static readonly List<AudioClip> IdleClips = new List<AudioClip>(); internal static readonly List<AudioClip> AllClips = new List<AudioClip>(); private static readonly Random Rng = new Random(); private static MethodInfo _getOrCreatePlayerDataMethod; private static FieldInfo _inAnimationWithPandoraField; private static readonly ConditionalWeakTable<object, VoiceState> States = new ConditionalWeakTable<object, VoiceState>(); private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Harmony harmony = new Harmony("com.fer.pandoravoices"); TryRecoverPandoraStartup(harmony); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "voices"); LoadAllWavFiles(text); if (AllClips.Count == 0) { Log.LogWarning((object)("No se encontraron archivos .wav en: " + text)); return; } Type type = FindTypeSafe("PandoraEnemy.Content.Enemies.PandoraEnemyAI"); if (type == null) { Log.LogWarning((object)"PandoraEnemyAI no encontrado; asegurate de tener instalado Professor_Poof-PandoraEnemy."); return; } PatchIfPresent(harmony, type, "Start", "OnStart"); PatchIfPresent(harmony, type, "DoIdle", "OnIdle"); PatchIfPresent(harmony, type, "DoChasing", "OnChase"); PatchIfPresent(harmony, type, "ChooseNextAttack", "OnChase"); PatchIfPresent(harmony, type, "KillEnemy", "OnKill"); Log.LogInfo((object)("PandoraVoicesAndFix v1.0.1 cargado con " + AllClips.Count + " clips de voz.")); } private static Type FindTypeSafe(string fullName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { Type type = assembly.GetType(fullName, throwOnError: false); if (type != null) { return type; } } catch { } } return null; } private static void TryRecoverPandoraStartup(Harmony harmony) { //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Expected O, but got Unknown try { Type type = FindTypeSafe("PandoraEnemy.PandoraEnemy"); if (type == null) { return; } PropertyInfo propertyInfo = AccessTools.Property(type, "Mod"); object obj = ((propertyInfo != null) ? propertyInfo.GetValue(null, null) : null); if (obj == null) { return; } MethodInfo methodInfo = AccessTools.Method(obj.GetType(), "AllEnemies", (Type[])null, (Type[])null); if (methodInfo == null) { return; } IEnumerable enumerable = methodInfo.Invoke(obj, null) as IEnumerable; bool flag = false; if (enumerable != null) { IEnumerator enumerator = enumerable.GetEnumerator(); flag = enumerator.MoveNext(); if (enumerator is IDisposable disposable) { disposable.Dispose(); } } if (flag) { Log.LogInfo((object)"PandoraEnemy ya inicializo correctamente sus contenidos."); return; } Type type2 = FindTypeSafe("PandoraEnemy.PandoraAdditionalPlayerData"); if (type2 != null) { _getOrCreatePlayerDataMethod = AccessTools.Method(type2, "GetOrCreate", new Type[1] { typeof(PlayerControllerB) }, (Type[])null); _inAnimationWithPandoraField = AccessTools.Field(type2, "inAnimationWithPandora"); } MethodInfo method = typeof(EnemyAI).GetMethod("PlayerIsTargetable", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null && _getOrCreatePlayerDataMethod != null && _inAnimationWithPandoraField != null) { MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), "PlayerIsTargetablePostfix", (Type[])null, (Type[])null); harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } Type type3 = FindTypeSafe("PandoraEnemy.Patches.SpacebarMinigamePatches"); MethodInfo methodInfo3 = ((type3 != null) ? AccessTools.Method(type3, "Init", (Type[])null, (Type[])null) : null); if (methodInfo3 != null) { methodInfo3.Invoke(null, null); } MethodInfo methodInfo4 = AccessTools.Method(obj.GetType(), "RegisterContentHandlers", (Type[])null, (Type[])null); if (methodInfo4 != null) { methodInfo4.Invoke(obj, null); } Log.LogInfo((object)"Parche de compatibilidad aplicado: PandoraEnemy recuperado e inicializado correctamente."); } catch (Exception ex) { Log.LogError((object)("Error aplicando recuperacion de compatibilidad para PandoraEnemy: " + ex)); } } private static void PlayerIsTargetablePostfix(PlayerControllerB playerScript, ref bool __result) { if (!__result || (Object)(object)playerScript == (Object)null || _getOrCreatePlayerDataMethod == null || _inAnimationWithPandoraField == null) { return; } object obj = _getOrCreatePlayerDataMethod.Invoke(null, new object[1] { playerScript }); if (obj != null) { object? value = _inAnimationWithPandoraField.GetValue(obj); Object val = (Object)((value is Object) ? value : null); if (val != (Object)null) { __result = false; } } } private static void PatchIfPresent(Harmony harmony, Type targetType, string methodName, string postfix) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(targetType, methodName, (Type[])null, (Type[])null); if (methodInfo == null) { Log.LogWarning((object)("Metodo no encontrado: " + targetType.Name + "." + methodName)); return; } MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), postfix, (Type[])null, (Type[])null); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static void LoadAllWavFiles(string voicesDir) { if (!Directory.Exists(voicesDir)) { Directory.CreateDirectory(voicesDir); return; } string[] files = Directory.GetFiles(voicesDir, "*.wav", SearchOption.AllDirectories); foreach (string text in files) { try { AudioClip val = LoadWavFile(text); if (!((Object)(object)val == (Object)null)) { AllClips.Add(val); string text2 = text.ToLowerInvariant(); if (text2.Contains("spawn") || text2.Contains("voz_1")) { SpawnClips.Add(val); } else if (text2.Contains("chase") || text2.Contains("attack") || text2.Contains("voz_2")) { ChaseClips.Add(val); } else if (text2.Contains("idle") || text2.Contains("voz_3")) { IdleClips.Add(val); } } } catch (Exception ex) { Log.LogError((object)("Error cargando wav " + text + ": " + ex.Message)); } } } private static AudioClip LoadWavFile(string path) { byte[] array = File.ReadAllBytes(path); if (array.Length < 44) { return null; } if (array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70) { return null; } if (array[8] != 87 || array[9] != 65 || array[10] != 86 || array[11] != 69) { return null; } int num = 1; int num2 = 44100; int num3 = 16; int num4 = -1; int num5 = 0; int num6 = 12; while (num6 + 8 <= array.Length) { string text = Encoding.ASCII.GetString(array, num6, 4); int num7 = BitConverter.ToInt32(array, num6 + 4); num6 += 8; if (num6 + num7 > array.Length) { num7 = array.Length - num6; } if (text == "fmt " && num7 >= 16) { short num8 = BitConverter.ToInt16(array, num6); if (num8 != 1) { Log.LogWarning((object)("WAV no es PCM sin comprimir (" + path + ")")); return null; } num = BitConverter.ToInt16(array, num6 + 2); num2 = BitConverter.ToInt32(array, num6 + 4); num3 = BitConverter.ToInt16(array, num6 + 14); } else if (text == "data") { num4 = num6; num5 = num7; break; } num6 += num7; if ((num7 & 1) == 1) { num6++; } } if (num4 < 0 || num5 <= 0 || num3 != 16) { return null; } int num9 = num5 / 2; float[] array2 = new float[num9]; for (int i = 0; i < num9; i++) { short num10 = BitConverter.ToInt16(array, num4 + i * 2); array2[i] = (float)num10 / 32768f; } int num11 = num9 / num; AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num11, num, num2, false); val.SetData(array2, 0); return val; } private static VoiceState GetOrCreateState(EnemyAI enemy) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown if (!States.TryGetValue(enemy, out var value)) { GameObject val = new GameObject("PandoraVoiceAudio"); val.transform.SetParent(((Component)enemy).transform, false); AudioSource val2 = val.AddComponent<AudioSource>(); val2.spatialBlend = 1f; val2.rolloffMode = (AudioRolloffMode)0; val2.minDistance = 4f; val2.maxDistance = 35f; val2.volume = 1f; val2.playOnAwake = false; VoiceState voiceState = new VoiceState(); voiceState.Source = val2; voiceState.NextAllowedTime = Time.time + 1.5f; value = voiceState; States.Add(enemy, value); } return value; } private static void TryPlay(EnemyAI enemy, List<AudioClip> preferred, float minCooldown) { if ((Object)(object)enemy == (Object)null || enemy.isEnemyDead) { return; } VoiceState orCreateState = GetOrCreateState(enemy); if ((Object)(object)orCreateState.Source == (Object)null || orCreateState.Source.isPlaying || Time.time < orCreateState.NextAllowedTime) { return; } List<AudioClip> list = ((preferred != null && preferred.Count > 0) ? preferred : AllClips); if (list.Count != 0) { AudioClip val = list[Rng.Next(list.Count)]; if (!((Object)(object)val == (Object)null)) { orCreateState.Source.clip = val; orCreateState.Source.Play(); orCreateState.NextAllowedTime = Time.time + val.length + minCooldown; } } } private static void OnStart(EnemyAI __instance) { VoiceState orCreateState = GetOrCreateState(__instance); orCreateState.NextAllowedTime = 0f; TryPlay(__instance, SpawnClips, 12f); } private static void OnIdle(EnemyAI __instance) { TryPlay(__instance, IdleClips, 18f); } private static void OnChase(EnemyAI __instance) { TryPlay(__instance, ChaseClips, 18f); } private static void OnKill(EnemyAI __instance) { if ((Object)(object)__instance != (Object)null && States.TryGetValue(__instance, out var value) && (Object)(object)value.Source != (Object)null) { value.Source.Stop(); } } }