using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FMOD.Studio;
using FMODUnity;
using HarmonyLib;
using ImGuiNET;
using Receiver2;
using Receiver2.SneakBot;
using Receiver2ModdingKit;
using Receiver2ModdingKit.CustomSounds;
using UnityEngine;
using UnityEngine.Events;
using Wolfire;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace StalkerChanBlabber;
[BepInPlugin("TCCrew.StalkerChanBlabber", "StalkerChanBlabber", "1.0.0")]
public class StalkerChanBlabberLoader : BaseUnityPlugin
{
internal static ConfigEntry<float> stalkerChanVolumeMultiplier;
public void Awake()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Expected O, but got Unknown
stalkerChanVolumeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("StalkerChanBlabber", "VolumePercentage", 0.4f, new ConfigDescription("Volume multiplier for Stalker-Chan. Note that this is the same option as the one in the settings menu", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
StalkerChanBlabberManager.volumeMultiplier = stalkerChanVolumeMultiplier.Value;
stalkerChanVolumeMultiplier.SettingChanged += delegate(object s, EventArgs e)
{
StalkerChanBlabberManager.volumeMultiplier = ((ConfigEntry<float>)s).Value;
};
BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(((object)this).GetType(), typeof(BepInPlugin));
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Plugin {val.Name} version {val.Version} is loaded!");
if (!Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<StalkerChanBlabberManager>()))
{
((Component)this).gameObject.AddComponent<StalkerChanBlabberManager>();
}
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
using (BinaryReader binaryReader = new BinaryReader(new FileStream(directoryName + "/StalkerChanBlabberBank.bank", FileMode.Open)))
{
byte[] array = new byte[binaryReader.BaseStream.Length];
binaryReader.Read(array, 0, array.Length);
Bank val2 = default(Bank);
((System)(ref ModAudioManager.mod_system)).loadBankMemory(array, (LOAD_BANK_FLAGS)4, ref val2);
Utility.IsError(((Bank)(ref val2)).loadSampleData(), "BlabberBank is fucked");
}
using (BinaryReader binaryReader2 = new BinaryReader(new FileStream(directoryName + "/StalkerChanBlabberBank.strings.bank", FileMode.Open)))
{
byte[] array2 = new byte[binaryReader2.BaseStream.Length];
binaryReader2.Read(array2, 0, array2.Length);
Bank val3 = default(Bank);
((System)(ref ModAudioManager.mod_system)).loadBankMemory(array2, (LOAD_BANK_FLAGS)4, ref val3);
Utility.IsError(((Bank)(ref val3)).loadSampleData(), "BlabberStrings is fucked");
}
ModdingKitEvents.AddTaskAtCoreStartup(new StartupAction(CreateSettings));
ReceiverEvents.StartListening((ReceiverEventTypeVoid)26, (UnityAction<ReceiverEventTypeVoid>)PlayerInitialized);
Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
}
private void CreateSettings()
{
SliderComponent component = SettingsMenuManager.CreateSettingsMenuOption<float>("Stalker-Chan Volume Multiplier", stalkerChanVolumeMultiplier, 8).control.GetComponent<SliderComponent>();
((UnityEvent<float>)(object)component.OnChange).AddListener((UnityAction<float>)delegate(float value)
{
stalkerChanVolumeMultiplier.Value = value;
});
component.format = "P0";
component.Value = stalkerChanVolumeMultiplier.Value;
}
private void PlayerInitialized(ReceiverEventTypeVoid ev)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
GameObject val = GameObject.Find("Weapon Storage Room");
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
Transform val2 = val.transform.Find("Statues");
if (Object.op_Implicit((Object)(object)val2))
{
Transform val3 = val2.Find("SneakBotStatue");
if (Object.op_Implicit((Object)(object)val3))
{
GameObject val4 = new GameObject("Easter Egg");
val4.transform.parent = ((Component)val3).transform;
val4.transform.localPosition = Vector234Extensions.SetY(Vector3.zero, 0.1f);
val4.layer = Layers.Interactable;
val4.AddComponent<SphereCollider>().radius = 1f;
PressableButton obj = val4.AddComponent<PressableButton>();
PressableButtonUnityEvent val5 = new PressableButtonUnityEvent();
((UnityEvent)val5).AddListener(new UnityAction(StalkerChanBlabberManager.Instance.PlayEasterEggBlabber));
obj.onPress = val5;
}
}
}
[HarmonyPatch(typeof(MenuManagerScript), "UpdateDeveloperMenu")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AddAudioDebug(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Expected O, but got Unknown
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, generator).MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
{
new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"Debug Text Window", (string)null),
new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"", (string)null),
new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ConfigFiles), "global"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Global), "display_debug_text_window"), (string)null),
new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "MenuItem", new Type[3]
{
typeof(string),
typeof(string),
typeof(bool)
}, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
});
if (!val.ReportFailure(__originalMethod, (Action<string>)Debug.LogError))
{
List<Label> collection = CodeInstructionExtensions.ExtractLabels(val.Instruction);
val.Insert((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StalkerChanBlabberManager), "OpenAudioDebug", (Type[])null, (Type[])null))
});
val.Labels.AddRange(collection);
}
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(SneakBotTape), "StartEvent")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SayTapeBlabber(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, generator).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(RuntimeTileLevelGenerator), "CreateSneakBot", (Type[])null, (Type[])null), (string)null)
});
if (!val.ReportFailure(__originalMethod, (Action<string>)Debug.LogError))
{
val.InsertAndAdvance((IEnumerable<CodeInstruction>)AccessTools.Method(typeof(StalkerChanBlabberLoader), "PlaySummonedByTape", (Type[])null, (Type[])null).ToCodeInstructionsClipLast(out var _));
}
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(RankingProgressionGameMode), "OnEntityDestroyed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SayPumpkingBlabber(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, generator).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(RuntimeTileLevelGenerator), "CreateSneakBot", (Type[])null, (Type[])null), (string)null)
});
if (!val.ReportFailure(__originalMethod, (Action<string>)Debug.LogError))
{
val.InsertAndAdvance((IEnumerable<CodeInstruction>)AccessTools.Method(typeof(StalkerChanBlabberLoader), "PlaySummonedByPumpkin", (Type[])null, (Type[])null).ToCodeInstructionsClipLast(out var _));
}
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(SneakBotSpawner), "TrySpawnSneakBotInstanced")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SayGongBlabber(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
CodeMatcher val = new CodeMatcher(instructions, generator).Start();
if (!val.ReportFailure(__originalMethod, (Action<string>)Debug.LogError))
{
val.InsertAndAdvance((IEnumerable<CodeInstruction>)AccessTools.Method(typeof(StalkerChanBlabberLoader), "PlaySummonedByGong", (Type[])null, (Type[])null).ToCodeInstructionsClipLast(out var extractedLabels)).AddLabels((IEnumerable<Label>)extractedLabels);
}
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(SneakBot), "OnHackProgress")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SayHackBlabber(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, generator).MatchStartForward((CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(SneakBot), "being_hacked"), (string)null)
});
if (!val.ReportFailure(__originalMethod, (Action<string>)Debug.LogError))
{
val.InsertAndAdvance((IEnumerable<CodeInstruction>)AccessTools.Method(typeof(StalkerChanBlabberLoader), "PlayEnterHack", (Type[])null, (Type[])null).ToCodeInstructionsClipLast(out var _));
}
return val.InstructionEnumeration();
}
private void PlaySummonedByPumpkin()
{
Debug.Log((object)"plumpkin!!!");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.SummonedByPumpkin);
}
private void PlaySummonedByTape()
{
Debug.Log((object)"Taep");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.SummonedByTape);
}
private void PlaySummonedByGong()
{
Debug.Log((object)"gnong?");
if (((Object)this).name == "Gong")
{
Debug.Log((object)"gnong!");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.SummonedByGong);
}
}
private void PlayEnterHack()
{
Debug.Log((object)"hack");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.Hacking);
}
[HarmonyPatch(typeof(SneakBotTeleportationScript), "TeleportStalk")]
[HarmonyPostfix]
private static void PlayStalkingBlabber(SneakBotTeleportationScript __instance)
{
Debug.Log((object)"stalk?");
if (Probability.Chance(0.5f))
{
Debug.Log((object)"stalk!");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.Stalking);
}
}
[HarmonyPatch(typeof(SneakBot), "PlayDeathSound")]
[HarmonyPostfix]
private static void PlayDeathBlabber()
{
Debug.Log((object)"death");
StalkerChanBlabberManager.Instance.PlayBlabber(BlabberState.Death);
}
}
public static class Extensions
{
public static List<CodeInstruction> ToCodeInstructionsClipLast(this MethodInfo methodInfo, out List<Label> extractedLabels, Dictionary<CodeInstruction, CodeInstruction> replaceInstructionWith = null)
{
List<CodeInstruction> originalInstructions = PatchProcessor.GetOriginalInstructions((MethodBase)methodInfo, (ILGenerator)null);
if (replaceInstructionWith != null)
{
for (int i = 0; i < originalInstructions.Count; i++)
{
if (replaceInstructionWith.TryGetValue(originalInstructions[i], out var value))
{
originalInstructions[i] = value;
}
}
}
extractedLabels = CodeInstructionExtensions.ExtractLabels(originalInstructions.Last());
originalInstructions.Remove(originalInstructions.Last());
return originalInstructions;
}
}
public class StalkerChanBlabberManager : MonoBehaviour
{
private const string kStalkerChanEvent = "event:/StalkerChan/";
private static bool debugWindowVisible;
internal static float volumeMultiplier = 0.4f;
public Dictionary<BlabberState, List<StalkerChanVoiceline>> voiceLineDictionnary = new Dictionary<BlabberState, List<StalkerChanVoiceline>>
{
{
BlabberState.SummonedByGong,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Prey"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Cocky"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Neighbours"
}
}
},
{
BlabberState.SummonedByTape,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/FoundYa"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/TheMan"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Ready"
}
}
},
{
BlabberState.SummonedByPumpkin,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Griddy"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Trick"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/EasyTarget"
}
}
},
{
BlabberState.Stalking,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/BehindYou"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/GunJam"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/PutDownGunAndGiveUp"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/GunOilAndFear"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/CuteWhenAfraid"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/GettingCloser"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/AraAraUrgh"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/CatAndMouse"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/JohnMosesBrowning"
}
}
},
{
BlabberState.Hacking,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/Bastard"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/DontTouch"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/LetGo"
}
}
},
{
BlabberState.Death,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/NondescriptDeath1"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/NondescriptDeath2"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/NondescriptDeath3"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/SpicyDeath1"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/SpicyDeath2"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/SpicyDeath3"
}
}
},
{
BlabberState.EasterEgg,
new List<StalkerChanVoiceline>
{
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/TheSigns"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/GetPB"
},
new StalkerChanVoiceline
{
eventName = "event:/StalkerChan/ReadCredits"
}
}
}
};
public static StalkerChanBlabberManager Instance { get; private set; }
public void Awake()
{
Instance = this;
}
public void Update()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (debugWindowVisible)
{
ImGui.SetNextWindowSize(new Vector2(440f, 550f), (ImGuiCond)4);
if (ImGui.Begin("StalkerChanBlabber", ref debugWindowVisible))
{
ImGui.SliderFloat("Audio Boost", ref volumeMultiplier, 0.01f, 100f);
}
ImGui.End();
}
}
public static void OpenAudioDebug()
{
if (ImGui.MenuItem("StalkerChanBlabber Audio Debug", "", debugWindowVisible))
{
debugWindowVisible = !debugWindowVisible;
}
}
public void PlayBlabber(BlabberState blabberState)
{
StalkerChanVoiceline random = IListExtensions.GetRandom<StalkerChanVoiceline>((IList<StalkerChanVoiceline>)voiceLineDictionnary[blabberState].Where((StalkerChanVoiceline voiceline) => !voiceline.playedLast).ToList());
foreach (StalkerChanVoiceline item in voiceLineDictionnary[blabberState])
{
if (item.playedLast)
{
item.playedLast = false;
}
}
random.playedLast = true;
ModAudioManager.PlayOneShotAttached(random.eventName, ((Component)LocalAimHandler.player_instance).gameObject, 1f * volumeMultiplier);
}
public void PlayEasterEggBlabber()
{
StalkerChanVoiceline random = IListExtensions.GetRandom<StalkerChanVoiceline>((IList<StalkerChanVoiceline>)voiceLineDictionnary[BlabberState.EasterEgg].Where((StalkerChanVoiceline voiceline) => !voiceline.playedLast).ToList());
foreach (StalkerChanVoiceline item in voiceLineDictionnary[BlabberState.EasterEgg])
{
if (item.playedLast)
{
item.playedLast = false;
}
}
random.playedLast = true;
GameObject val = GameObject.Find("Weapon Storage Room");
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
Transform val2 = val.transform.Find("Statues");
if (Object.op_Implicit((Object)(object)val2))
{
Transform val3 = val2.Find("SneakBotStatue");
if (Object.op_Implicit((Object)(object)val3))
{
ModAudioManager.PlayOneShotAttached(random.eventName, ((Component)val3).gameObject, 1f * volumeMultiplier);
}
}
}
}
public enum BlabberState
{
SummonedByGong,
SummonedByTape,
SummonedByPumpkin,
Stalking,
Death,
Hacking,
EasterEgg
}
public class StalkerChanVoiceline
{
[EventRef]
public string eventName;
public bool playedLast;
}