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 BrandonLeeBracken.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BrandonLeeBracken")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BrandonLeeBracken")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("24652358-91da-4ae1-a6bd-bb916fdbfb36")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BrandonLeeBracken
{
[BepInPlugin("frare.brandonleebracken", "Brandon Lee Bracken", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BrandonLeeBrackenBase : BaseUnityPlugin
{
internal const string modGUID = "frare.brandonleebracken";
internal const string modName = "Brandon Lee Bracken";
internal const string modVersion = "1.0.0";
internal static BrandonLeeBrackenBase Instance;
private readonly Harmony harmony = new Harmony("frare.brandonleebracken");
internal ManualLogSource logger;
public static AssetBundle CustomTextures;
public static AssetBundle CustomAudio;
internal Texture2D relaxedTexture;
internal Texture2D fleeingTexture;
internal Texture2D angryTexture;
internal Material creatureMaterial;
internal List<AudioClip> fleeingClips = new List<AudioClip>();
internal List<AudioClip> killClips = new List<AudioClip>();
internal AudioClip fleeingClipRare;
internal AudioClip angryClip;
internal AudioClip scanClip;
internal AudioClip memeClip;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("frare.brandonleebracken");
logger.LogInfo((object)"Mod started! :)");
LoadCustomTextures();
LoadCustomAudioClips();
CreateMaterial();
harmony.PatchAll(typeof(FlowerManPatch));
}
private void Start()
{
SoundTool.ReplaceAudioClip("Scan", scanClip, 0.995f);
SoundTool.ReplaceAudioClip("Scan", memeClip, 0.005f);
foreach (AudioClip fleeingClip in Instance.fleeingClips)
{
SoundTool.ReplaceAudioClip("Found1", fleeingClip, 1f / (float)Instance.fleeingClips.Count);
SoundTool.ReplaceAudioClip("FlowermanStun", fleeingClip, 1f / (float)Instance.fleeingClips.Count);
}
foreach (AudioClip killClip in Instance.killClips)
{
SoundTool.ReplaceAudioClip("CrackNeck", killClip, 1f / (float)Instance.killClips.Count);
}
SoundTool.ReplaceAudioClip("Angered", Instance.angryClip, 1f);
}
private void LoadCustomTextures()
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
CustomTextures = AssetBundle.LoadFromFile(Path.Combine(directoryName, "modtextures"));
if ((Object)(object)CustomTextures == (Object)null)
{
logger.LogError((object)"Failed to load custom textures");
return;
}
string[] allAssetNames = CustomTextures.GetAllAssetNames();
foreach (string text in allAssetNames)
{
logger.LogDebug((object)("Found asset: " + text));
Texture2D val = CustomTextures.LoadAsset<Texture2D>(text);
if (text.Contains("relaxed"))
{
relaxedTexture = val;
}
else if (text.Contains("fleeing"))
{
fleeingTexture = val;
}
else if (text.Contains("angry"))
{
angryTexture = val;
}
else
{
logger.LogWarning((object)"Found an asset in texture bundle that does not match any category");
}
}
if ((Object)(object)relaxedTexture == (Object)null || (Object)(object)fleeingTexture == (Object)null || (Object)(object)angryTexture == (Object)null)
{
logger.LogError((object)"Failed to load custom textures");
}
else
{
logger.LogDebug((object)"Custom textures loaded!");
}
}
private void LoadCustomAudioClips()
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
CustomAudio = AssetBundle.LoadFromFile(Path.Combine(directoryName, "modaudio"));
if ((Object)(object)CustomAudio == (Object)null)
{
logger.LogError((object)"Failed to load custom audio");
return;
}
string[] allAssetNames = CustomAudio.GetAllAssetNames();
foreach (string text in allAssetNames)
{
logger.LogDebug((object)("Found asset: " + text));
if (text.Contains("fleeing-rare"))
{
fleeingClipRare = CustomAudio.LoadAsset<AudioClip>(text);
}
else if (text.Contains("fleeing"))
{
fleeingClips.Add(CustomAudio.LoadAsset<AudioClip>(text));
}
else if (text.Contains("kill"))
{
killClips.Add(CustomAudio.LoadAsset<AudioClip>(text));
}
else if (text.Contains("angry"))
{
angryClip = CustomAudio.LoadAsset<AudioClip>(text);
}
else if (text.Contains("scan"))
{
scanClip = CustomAudio.LoadAsset<AudioClip>(text);
}
else if (text.Contains("meme"))
{
memeClip = CustomAudio.LoadAsset<AudioClip>(text);
}
else
{
logger.LogWarning((object)"Found an asset in audio bundle that does not match any category");
}
}
if (fleeingClips.Count == 0 || killClips.Count == 0 || (Object)(object)angryClip == (Object)null)
{
logger.LogError((object)"Failed to load custom audio");
}
else
{
logger.LogDebug((object)"Custom audio loaded!");
}
}
private void CreateMaterial()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
creatureMaterial = new Material(Shader.Find("HDRP/Lit"));
creatureMaterial.SetFloat("_Smoothness", 0f);
creatureMaterial.SetFloat("_DoubleSidedEnable", 1f);
creatureMaterial.SetFloat("_CullMode", 0f);
creatureMaterial.SetFloat("_DoubleSidedNormalMode", 0f);
creatureMaterial.EnableKeyword("DOUBLESIDED_ON");
}
public AudioClip GetRandomFleeingAudioClip()
{
if (Random.Range(1f, 100f) < 5f)
{
return fleeingClipRare;
}
return fleeingClips[Random.Range(0, Instance.fleeingClips.Count)];
}
public static void LogMessage(string message, LogLevel logLevel = 32)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Instance.logger.Log(logLevel, (object)message);
}
}
}
namespace BrandonLeeBracken.Patches
{
[HarmonyPatch(typeof(FlowermanAI))]
internal static class FlowerManPatch
{
private class VariableContainer
{
public MeshRenderer meshRenderer;
}
private static readonly ConditionalWeakTable<FlowermanAI, VariableContainer> Variables = new ConditionalWeakTable<FlowermanAI, VariableContainer>();
[HarmonyPatch("Start")]
[HarmonyPostfix]
internal static void StartPostfix(ref FlowermanAI __instance)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
BrandonLeeBrackenBase.LogMessage("Patching \"FlowermanAI Start\"... for gameObject " + ((Object)((Component)__instance).gameObject).name, (LogLevel)32);
((Behaviour)((Component)__instance).GetComponentInChildren<Animator>()).enabled = false;
CollectionExtensions.Do<Renderer>((IEnumerable<Renderer>)((Component)__instance).GetComponentsInChildren<Renderer>(), (Action<Renderer>)delegate(Renderer renderer)
{
renderer.enabled = false;
});
GameObject val = GameObject.CreatePrimitive((PrimitiveType)4);
val.GetComponent<Collider>().enabled = false;
val.transform.SetParent(((Component)__instance).transform);
val.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
val.transform.localScale = new Vector3(0.15f, 0.15f, 0.4f);
val.transform.localPosition = new Vector3(0f, 2f, 0f);
MeshRenderer component = val.GetComponent<MeshRenderer>();
((Renderer)component).material = BrandonLeeBrackenBase.Instance.creatureMaterial;
__instance.SetMeshRenderer(component);
AudioSource creatureSFX = ((EnemyAI)__instance).creatureSFX;
creatureSFX.minDistance *= 2f;
AudioSource creatureSFX2 = ((EnemyAI)__instance).creatureSFX;
creatureSFX2.maxDistance *= 2f;
BrandonLeeBrackenBase.LogMessage("Done!", (LogLevel)32);
}
[HarmonyPatch(typeof(EnemyAI), "SwitchToBehaviourStateOnLocalClient")]
[HarmonyPostfix]
internal static void SwitchToStatePostfix(ref EnemyAI __instance, int stateIndex)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected O, but got Unknown
FlowermanAI val = (FlowermanAI)__instance;
if (!((Object)(object)val == (Object)null))
{
switch (stateIndex)
{
case 0:
((Renderer)val.GetMeshRenderer()).material.mainTexture = (Texture)(object)BrandonLeeBrackenBase.Instance.relaxedTexture;
break;
case 1:
((Renderer)val.GetMeshRenderer()).material.mainTexture = (Texture)(object)BrandonLeeBrackenBase.Instance.fleeingTexture;
((EnemyAI)val).creatureSFX.PlayOneShot(BrandonLeeBrackenBase.Instance.GetRandomFleeingAudioClip(), 2f);
break;
case 2:
((Renderer)val.GetMeshRenderer()).material.mainTexture = (Texture)(object)BrandonLeeBrackenBase.Instance.angryTexture;
break;
}
}
}
public static MeshRenderer GetMeshRenderer(this FlowermanAI instance)
{
return Variables.GetOrCreateValue(instance).meshRenderer;
}
public static void SetMeshRenderer(this FlowermanAI instance, MeshRenderer value)
{
Variables.GetOrCreateValue(instance).meshRenderer = value;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private static InputAction keyPressAction;
[HarmonyPatch("Awake")]
[HarmonyPostfix]
internal static void AwakePostFix(ref PlayerControllerB __instance)
{
if (((NetworkBehaviour)__instance).IsOwner)
{
BrandonLeeBrackenBase.LogMessage("PlayerControllerB Awake", (LogLevel)32);
}
}
private static void OnKeyPress(CallbackContext context)
{
BrandonLeeBrackenBase.LogMessage("F5 pressed", (LogLevel)32);
}
}
}