using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HungryThumper.Patches;
using HungryThumper.Utilities;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HungryThumper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HungryThumper")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("640815c5-0ee8-405b-8431-c1f6b1ba5b31")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HungryThumper
{
public class CustomAudioClip
{
public AudioClip clip;
public string source = string.Empty;
public bool canPlay = true;
private bool initialized = false;
public CustomAudioClip(AudioClip newClip, string newSource)
{
if (!initialized)
{
Initialize();
}
clip = newClip;
source = newSource;
}
private void Initialize()
{
initialized = true;
}
}
[BepInPlugin("Tonic.HungryThumper", "Hungry Thumper", "1.0.0")]
public class HungryThumperModBase : BaseUnityPlugin
{
private const string modGUID = "Tonic.HungryThumper";
private const string modName = "Hungry Thumper";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Tonic.HungryThumper");
public static HungryThumperModBase Instance;
internal ManualLogSource logger;
public static Dictionary<string, string> customAudioClipsMatrix { get; } = new Dictionary<string, string>
{
{ "ShortRoar1", "CustomShortRoar1" },
{ "HitCrawler", "CustomHitCrawler" },
{ "HitCrawler2", "CustomHitCrawler2" },
{ "StunCrawler", "CustomStunCrawler" },
{ "CrawlerDie", "CustomCrawlerDie" },
{ "LongRoar1", "CustomLongRoar1" },
{ "LongRoar2", "CustomLongRoar2" },
{ "LongRoar3", "CustomLongRoar3" },
{ "Stomp1", "CustomStomp1" },
{ "Stomp2", "CustomStomp2" },
{ "Stomp3", "CustomStomp3" },
{ "Ram1", "CustomRam1" },
{ "Ram2", "CustomRam2" },
{ "Ram3", "CustomRam3" },
{ "BitePlayer", "CustomBitePlayer" }
};
public static Dictionary<string, CustomAudioClip> replacedClips { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
replacedClips = new Dictionary<string, CustomAudioClip>();
logger = Logger.CreateLogSource("Tonic.HungryThumper");
harmony.PatchAll(typeof(HungryThumperModBase));
harmony.PatchAll(typeof(ThumperNoisePatch));
InitializeCustomAudioClips();
}
private void InitializeCustomAudioClips()
{
string path = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("HungryThumper.dll".ToCharArray());
string path2 = Path.Combine(path, "CustomSounds");
foreach (KeyValuePair<string, string> item in customAudioClipsMatrix)
{
string path3 = Path.Combine(path2, item.Value + ".mp3");
AudioClip newClip = AudioUtilities.LoadFromDiskToAudioClip(path3);
CustomAudioClip value = new CustomAudioClip(newClip, item.Key);
replacedClips.Add(item.Key, value);
}
}
}
}
namespace HungryThumper.Utilities
{
public static class AudioUtilities
{
public static AudioClip LoadFromDiskToAudioClip(string path)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
AudioClip val = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)13);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
HungryThumperModBase.Instance.logger.LogError((object)("Failed to load MP3 AudioClip from path: " + path + " Full error: " + audioClip.error));
}
else
{
HungryThumperModBase.Instance.logger.LogInfo((object)$"Uwr: {audioClip}");
val = DownloadHandlerAudioClip.GetContent(audioClip);
HungryThumperModBase.Instance.logger.LogInfo((object)("Successfully load MP3 AudioClip from path: " + path + ", with clip: " + ((Object)val).name));
}
}
catch (Exception ex)
{
HungryThumperModBase.Instance.logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
return val;
}
}
}
namespace HungryThumper.Patches
{
[HarmonyPatch(typeof(AudioSource))]
internal class ThumperNoisePatch
{
[HarmonyPatch("PlayOneShot", new Type[]
{
typeof(AudioClip),
typeof(float)
})]
[HarmonyPrefix]
private static void changeScreamSFX(ref AudioClip clip, float volumeScale)
{
if (!((Object)(object)clip == (Object)null))
{
clip = ReplaceClipWithNew(clip);
}
}
private static AudioClip ReplaceClipWithNew(AudioClip original, AudioSource source = null)
{
string name = ((Object)original).name;
if (HungryThumperModBase.replacedClips.ContainsKey(name) && !string.IsNullOrEmpty(HungryThumperModBase.replacedClips[name].source))
{
return HungryThumperModBase.replacedClips[name].clip;
}
return original;
}
}
}