using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using JetBrains.Annotations;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MonklePack")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MonklePack")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A97A53E0-35CF-4DD0-8997-544706FAF0B3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MonklePack;
[BepInPlugin("Monkle.VariousMods", "MonklePack", "1.0.0.2")]
public class MonklePackModBase : BaseUnityPlugin
{
public const string ModGuid = "Monkle.VariousMods";
public const string ModName = "MonklePack";
public const string ModVersion = "1.0.0.2";
private readonly Harmony _harmony = new Harmony("Monkle.VariousMods");
[CanBeNull]
public static readonly List<AudioWeight> TomScreamClips = new List<AudioWeight>();
[CanBeNull]
public static AudioClip Pedro;
[CanBeNull]
private static MonklePackModBase _instance;
public static readonly Random Rnd = new Random();
private static ManualLogSource _monkleLogger;
private static AssetBundle _itemAssetBundle;
[CanBeNull]
public static AudioClip[] RadioTracks;
internal static MonkleConfig BoundConfig { get; private set; } = null;
private void Awake()
{
if ((Object)(object)_instance == (Object)null)
{
_instance = this;
}
string location = ((BaseUnityPlugin)_instance).Info.Location;
_monkleLogger = Logger.CreateLogSource("Monkle.VariousMods");
BoundConfig = new MonkleConfig(((BaseUnityPlugin)this).Config);
LogMessage("location " + location);
_itemAssetBundle = AssetBundle.LoadFromFile(location.TrimEnd("MonklePack.dll".ToCharArray()) + "monklepack");
AudioClip[] source = _itemAssetBundle.LoadAllAssets<AudioClip>();
RadioTracks = (from x in source
where Regex.IsMatch(((Object)x).name, "^\\d")
select x into _
orderby Guid.NewGuid()
select _).ToArray();
AudioClip[] radioTracks = RadioTracks;
for (int i = 0; i < radioTracks.Length; i++)
{
LogMessage(((Object)radioTracks[i]).name);
}
if (TomScreamClips != null)
{
TomScreamClips.Add(new AudioWeight
{
Sound = ((IEnumerable<AudioClip>)source).FirstOrDefault((Func<AudioClip, bool>)((AudioClip x) => ((Object)x).name == "TomScream")),
Weight = 50
});
TomScreamClips.Add(new AudioWeight
{
Sound = ((IEnumerable<AudioClip>)source).FirstOrDefault((Func<AudioClip, bool>)((AudioClip x) => ((Object)x).name == "TomScream2")),
Weight = 30
});
TomScreamClips.Add(new AudioWeight
{
Sound = ((IEnumerable<AudioClip>)source).FirstOrDefault((Func<AudioClip, bool>)((AudioClip x) => ((Object)x).name == "UghSound")),
Weight = 10
});
}
Pedro = ((IEnumerable<AudioClip>)source).FirstOrDefault((Func<AudioClip, bool>)((AudioClip x) => ((Object)x).name == "Pedro"));
_monkleLogger.LogMessage((object)"Monkle.VariousMods has loaded succesfully.");
LogMessage("has loaded succesfully.");
if (BoundConfig.EnableTomScream.Value)
{
_harmony.PatchAll(typeof(TomScreamMod));
}
if (BoundConfig.EnablePedro.Value)
{
_harmony.PatchAll(typeof(JesterPedroMod));
}
if (BoundConfig.EnableFear.Value)
{
_harmony.PatchAll(typeof(PlayerScaredMod));
}
if (BoundConfig.EnableCruiserTunes.Value)
{
_harmony.PatchAll(typeof(CruiserMod));
}
}
public static void LogMessage(string message)
{
_monkleLogger.LogMessage((object)("Monkle.VariousMods " + message));
}
}
internal class MonkleConfig
{
public readonly ConfigEntry<float> FearSpeedMultiplier;
public readonly ConfigEntry<bool> EnableTomScream;
public readonly ConfigEntry<bool> EnablePedro;
public readonly ConfigEntry<bool> EnableFear;
public readonly ConfigEntry<bool> EnableCruiserTunes;
public MonkleConfig(ConfigFile cfg)
{
cfg.SaveOnConfigSet = false;
FearSpeedMultiplier = cfg.Bind<float>("Sanity", "FearSpeedMultiplier", 1f, "How much should you be sped up by insanity");
EnableTomScream = cfg.Bind<bool>("General", "EnableTomScream", true, "Should dogs scream like Tom");
EnablePedro = cfg.Bind<bool>("General", "EnablePedro", true, "Should pedro come out of the box");
EnableFear = cfg.Bind<bool>("General", "EnableFear", false, "Should fear speed you up");
EnableCruiserTunes = cfg.Bind<bool>("General", "EnableCruiserTunes", true, "Want some tuneskies");
ClearOrphanedEntries(cfg);
cfg.Save();
cfg.SaveOnConfigSet = true;
}
private static void ClearOrphanedEntries(ConfigFile cfg)
{
((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(cfg)).Clear();
}
}
public class AudioWeight
{
public AudioClip Sound { get; set; }
public int Weight { get; set; }
}
[HarmonyPatch(typeof(MouthDogAI))]
[HarmonyPatch("Update")]
internal class TomScreamMod
{
private static AudioClip originalScream;
[HarmonyPostfix]
private static void Postfix(ref MouthDogAI __instance)
{
if (!((Object)(object)originalScream == (Object)null))
{
return;
}
originalScream = __instance.screamSFX;
MonklePackModBase.LogMessage("Loaded original scream.");
MonklePackModBase.TomScreamClips.Add(new AudioWeight
{
Sound = originalScream,
Weight = 100 - MonklePackModBase.TomScreamClips.Sum((AudioWeight x) => x.Weight)
});
int num = 0;
int num2 = MonklePackModBase.Rnd.Next(0, 100);
foreach (AudioWeight item in MonklePackModBase.TomScreamClips.OrderByDescending((AudioWeight x) => x.Weight))
{
num += item.Weight;
if (num2 - num < 0)
{
__instance.screamSFX = item.Sound;
return;
}
}
if (((EnemyAI)__instance).currentBehaviourStateIndex != 3)
{
return;
}
int num3 = MonklePackModBase.Rnd.Next(0, 100);
int num4 = 0;
foreach (AudioWeight item2 in MonklePackModBase.TomScreamClips.OrderByDescending((AudioWeight x) => x.Weight))
{
num4 += item2.Weight;
if (num3 - num4 < 0)
{
__instance.screamSFX = item2.Sound;
}
}
}
}
[HarmonyPatch(typeof(JesterAI))]
[HarmonyPatch("Update")]
internal class JesterPedroMod
{
[HarmonyPostfix]
private static void Postfix(ref JesterAI __instance)
{
if ((Object)(object)MonklePackModBase.Pedro != (Object)null)
{
__instance.screamingSFX = MonklePackModBase.Pedro;
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
[HarmonyPatch("Update")]
internal class PlayerScaredMod
{
private static float currentSanity = 0f;
private static float baseMovement = 0.5f;
private static float baseSprint = 1.125f;
private static float baseTargetFOV = 0.5f;
private static float baseDrunkness = 0.5f;
[HarmonyPostfix]
private static void Postfix(ref PlayerControllerB __instance)
{
if ((double)Math.Abs(currentSanity - __instance.insanityLevel) > 0.1)
{
currentSanity = __instance.insanityLevel;
float num = 1f + __instance.insanityLevel / 100f * MonklePackModBase.BoundConfig.FearSpeedMultiplier.Value;
if (__instance.isSprinting)
{
__instance.movementSpeed = baseSprint * num;
}
else
{
__instance.movementSpeed = baseMovement * num;
}
MonklePackModBase.LogMessage($"Sanity Changed: {__instance.movementSpeed}");
if (__instance.isSprinting)
{
__instance.targetFOV = 68f * num;
}
}
}
}
[HarmonyPatch(typeof(VehicleController))]
[HarmonyPatch("Start")]
internal class CruiserMod
{
[HarmonyPostfix]
private static void Postfix(ref VehicleController __instance)
{
__instance.radioClips = MonklePackModBase.RadioTracks;
}
}