using System;
using System.Collections;
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.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MonsterSoda.Components;
using MonsterSoda.Components.TextureUpdaters;
using MonsterSoda.FunctionOverrides;
using MonsterSoda.PatchFunctions;
using MonsterSoda.Utils.ModUtil;
using MonsterSoda.Utils.ReflectionUtil;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MonsterSoda")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("This mod changes the soda can to a Monsti Energy can")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MonsterSoda")]
[assembly: AssemblyTitle("MonsterSoda")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace MonsterSoda
{
[BepInPlugin("LegaliseLeek.mods.LethalCompany.Monsti_Energy", "Monsti_Energy", "1.0.0")]
[BepInProcess("Lethal Company.exe")]
public class MonsterSodaPlugin : BaseUnityPlugin
{
public const string GUID = "LegaliseLeek.mods.LethalCompany.Monsti_Energy";
public const string PLUGIN_NAME = "Monsti_Energy";
public const string PLUGIN_VERSION = "1.0.0";
public const string DEPENDENCY_STRING = "LegaliseLeek-Monsti_Energy-1.0.0";
private void Awake()
{
ConfigUtil.Initialize(((BaseUnityPlugin)this).Config);
LoggerUtil.Initialize(ConfigUtil.LoggingLevel, ((BaseUnityPlugin)this).Logger);
LoggerUtil.Log((LogLevel)16, "Plugin LegaliseLeek-Monsti_Energy-1.0.0 is loaded!");
PatchUtil.PatchFunctions();
}
}
internal static class Patches
{
[HarmonyPatch(typeof(GrabbableObject), "Start")]
[HarmonyPostfix]
internal static void GrabbableObjectStartPatch(GrabbableObject __instance)
{
if (((Object)__instance).name.ToLower().Contains("soda"))
{
((Component)__instance).gameObject.AddComponent<SodaCanTextureUpdater>();
((Component)__instance).gameObject.AddComponent<ObjectNameSetter>().SetName("Monsti Energy");
}
if (!((Object)__instance).name.ToLower().Contains("robot"))
{
return;
}
AnimatedItem val = (AnimatedItem)(object)((__instance is AnimatedItem) ? __instance : null);
if (val != null)
{
RobotToyFunctions.Start(val, isPrefab: false);
if (!RobotToyFunctions.DidSetPrefab)
{
RobotToyFunctions.SetPrefab(((GrabbableObject)val).itemProperties.spawnPrefab);
}
}
}
[HarmonyPatch(typeof(AnimatedItem), "EquipItem")]
[HarmonyPrefix]
internal static bool AnimatedItemEquipItemPatch(AnimatedItem __instance)
{
if (((Object)__instance).name.ToLower().Contains("robot"))
{
AnimatedItemRobotToyOverrides.EquipItem(__instance);
return false;
}
return true;
}
[HarmonyPatch(typeof(AnimatedItem), "DiscardItem")]
[HarmonyPostfix]
internal static void AnimatedItemDiscardItemPatch(AnimatedItem __instance)
{
if (((Object)__instance).name.ToLower().Contains("robot"))
{
RobotToyFunctions.Discarditem(__instance);
}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
[HarmonyPriority(0)]
internal static void StartOfRoundStartpatch(StartOfRound __instance)
{
((MonoBehaviour)__instance).StartCoroutine(ChangePosters());
IEnumerator ChangePosters()
{
yield return null;
for (int i = 0; i < 24; i++)
{
yield return null;
}
ulong currentSteamID = __instance.localPlayerController.playerSteamId;
if (currentSteamID == 76561199153768459L || currentSteamID == 76561198129133083L)
{
GameObject posters = GameObject.Find("Plane.001");
if (posters == null)
{
LoggerUtil.LogError("No posters found");
}
else
{
posters.AddComponent<PostersTextureUpdater>();
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MonsterSoda";
public const string PLUGIN_NAME = "MonsterSoda";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace MonsterSoda.Utils.ReflectionUtil
{
public static class DynamicMethodCreator
{
public static DynamicMethod GetDynamicMethod(MethodInfo methodInfo, string functionName)
{
DynamicMethod dynamicMethod = new DynamicMethod(functionName, methodInfo.ReturnType, new Type[1] { methodInfo.DeclaringType }, methodInfo.DeclaringType);
ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
iLGenerator.Emit(OpCodes.Ldarg_0);
iLGenerator.EmitCall(OpCodes.Call, methodInfo, null);
iLGenerator.Emit(OpCodes.Ret);
return dynamicMethod;
}
}
}
namespace MonsterSoda.Utils.ModUtil
{
public static class AssetBundleUtil
{
private static readonly string assemblyDirectory;
private static readonly Dictionary<string, AssetBundle> assetBundles;
static AssetBundleUtil()
{
assetBundles = new Dictionary<string, AssetBundle>();
assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
public static bool TryLoadAsset<TAssetType>(string bundleName, string assetPath, out TAssetType asset) where TAssetType : Object
{
if (!TryGetAssetBundle(bundleName, out var assetBundle))
{
asset = default(TAssetType);
return false;
}
asset = assetBundle.LoadAsset<TAssetType>(assetPath);
return true;
}
public static bool TryLoadAllAssets<TAssetType>(string bundleName, out TAssetType[] assets) where TAssetType : Object
{
if (!TryGetAssetBundle(bundleName, out var assetBundle))
{
assets = null;
return false;
}
assets = assetBundle.LoadAllAssets<TAssetType>();
return assets.Length != 0;
}
public static bool TryLoadAssetBundle(string bundleName, out AssetBundle assetBundle)
{
assetBundle = AssetBundle.LoadFromFile(GetPath(bundleName));
if (assetBundle == null)
{
return false;
}
assetBundles.Add(bundleName, assetBundle);
return true;
}
public static bool TryUnloadAssetBundle(string bundleName, bool unloadAllLoadedObjects)
{
if (assetBundles.TryGetValue(bundleName, out var value))
{
value.Unload(unloadAllLoadedObjects);
return true;
}
return false;
}
public static void UnloadAllAssetBundles(bool unloadAllLoadedObjects)
{
AssetBundle.UnloadAllAssetBundles(unloadAllLoadedObjects);
}
private static bool TryGetAssetBundle(string bundleName, out AssetBundle assetBundle)
{
if (assetBundles.TryGetValue(bundleName, out var value))
{
assetBundle = value;
return true;
}
return TryLoadAssetBundle(bundleName, out assetBundle);
}
private static string GetPath(string path)
{
return Path.Combine(assemblyDirectory, path);
}
}
public static class ConfigUtil
{
public static ConfigEntry<LogLevel> LoggingLevel;
private static ConfigFile config;
internal static void Initialize(ConfigFile configFile)
{
config = configFile;
}
public static void ReadConfig()
{
LoggingLevel = config.Bind<LogLevel>("0. General", "logLevel", (LogLevel)63, "What should be logged?\nYou can seperate the options by a ',' to enable multiple\nValid options:\nNone, Fatal, Error, Warning, Message, Info, Debug, All");
}
}
public static class LoggerUtil
{
private static ManualLogSource logger;
private static ConfigEntry<LogLevel> configLoggingLevel;
public static bool IsLoggerEnabled => true;
internal static void Initialize(ConfigEntry<LogLevel> loggingLevelEntry, ManualLogSource logSource)
{
configLoggingLevel = loggingLevelEntry;
logger = logSource;
}
internal static void Log(LogLevel logLevel, object data)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (IsLoggerEnabled)
{
logger.Log(logLevel, data);
}
}
internal static void LogMessage(object data)
{
Log((LogLevel)8, data);
}
internal static void LogInfo(object data)
{
Log((LogLevel)16, data);
}
internal static void LogDebug(object data)
{
Log((LogLevel)32, data);
}
internal static void LogError(object data)
{
Log((LogLevel)2, data);
}
internal static void LogWarning(object data)
{
Log((LogLevel)4, data);
}
internal static void LogFatal(object data)
{
Log((LogLevel)1, data);
}
}
public static class PatchUtil
{
public static void PatchFunctions()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("LegaliseLeek.mods.LethalCompany.Monsti_Energy");
LoggerUtil.LogInfo("Attempting to patch with Harmony!");
try
{
val.PatchAll(typeof(Patches));
LoggerUtil.Log((LogLevel)16, "Patching success!");
}
catch (Exception ex)
{
LoggerUtil.Log((LogLevel)2, "Failed to patch: " + ex);
}
}
}
}
namespace MonsterSoda.PatchFunctions
{
public static class RobotToyFunctions
{
private static readonly Texture2D normalTexture;
private static readonly Texture2D sadTexture;
private static readonly AudioClip grabAudio;
private static readonly AudioClip dropAudio;
private static readonly AudioClip grabSFX;
private static readonly AudioClip pocketSFX;
private static readonly Mesh normalMesh;
private static readonly Mesh heldMesh;
public static bool DidSetPrefab { get; private set; }
static RobotToyFunctions()
{
DidSetPrefab = false;
AssetBundleUtil.TryLoadAsset<Texture2D>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Textures/SqueezyTexture.png", out normalTexture);
AssetBundleUtil.TryLoadAsset<Texture2D>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Textures/SqueezySadTexture.png", out sadTexture);
AssetBundleUtil.TryLoadAsset<AudioClip>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Audio/SqueezyLoop.wav", out grabAudio);
AssetBundleUtil.TryLoadAsset<AudioClip>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Audio/SqueezyDrop.wav", out dropAudio);
AssetBundleUtil.TryLoadAsset<AudioClip>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Audio/SqueezyPickUp.wav", out grabSFX);
AssetBundleUtil.TryLoadAsset<AudioClip>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Audio/SqueezySwitch.wav", out pocketSFX);
AssetBundleUtil.TryLoadAsset<Mesh>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Models/Squeezy.obj", out normalMesh);
AssetBundleUtil.TryLoadAsset<Mesh>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Models/SqueezyHeld.obj", out heldMesh);
}
public static void SetPrefab(GameObject prefab)
{
DidSetPrefab = true;
AnimatedItem component = prefab.GetComponent<AnimatedItem>();
if (Object.op_Implicit((Object)(object)component))
{
Start(component, isPrefab: true);
}
}
public static void Start(AnimatedItem robotToy, bool isPrefab)
{
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
robotToy.grabAudio = grabAudio;
robotToy.dropAudio = dropAudio;
((GrabbableObject)robotToy).itemProperties.grabSFX = grabSFX;
((GrabbableObject)robotToy).itemProperties.dropSFX = dropAudio;
((GrabbableObject)robotToy).itemProperties.pocketSFX = pocketSFX;
robotToy.normalMesh = normalMesh;
robotToy.alternateMesh = normalMesh;
if (isPrefab)
{
SetHeldMesh(robotToy);
}
else
{
SetNormalMesh(robotToy);
}
SetNormalTexture((Component)(object)robotToy);
ObjectNameSetter objectNameSetter = ((Component)robotToy).gameObject.AddComponent<ObjectNameSetter>();
objectNameSetter.SetName("Squeezy");
foreach (Transform item in ((Component)robotToy).transform)
{
Transform val = item;
if (((Object)val).name.ToLower().Contains("arm"))
{
((Component)val).GetComponent<Renderer>().forceRenderingOff = true;
((Component)val).gameObject.SetActive(false);
}
}
}
public static void Discarditem(AnimatedItem robotToy)
{
SetNormalMesh(robotToy);
SetNormalTexture((Component)(object)robotToy);
}
public static void SetNormalTexture(Component robotToy)
{
SetTexture(robotToy, (Texture)(object)normalTexture);
}
public static void SetSadTexture(Component robotToy)
{
SetTexture(robotToy, (Texture)(object)sadTexture);
}
public static void SetNormalMesh(AnimatedItem robotToy)
{
SetMesh((Component)(object)robotToy, normalMesh);
}
public static void SetHeldMesh(AnimatedItem robotToy)
{
SetMesh((Component)(object)robotToy, heldMesh);
}
private static void SetTexture(Component robotToy, Texture newTexture)
{
robotToy.gameObject.GetComponent<Renderer>().material.SetTexture(AbstractTextureUpdater.BaseColorMap, newTexture);
}
private static void SetMesh(Component robotToy, Mesh newMesh)
{
robotToy.gameObject.GetComponent<MeshFilter>().mesh = newMesh;
}
}
}
namespace MonsterSoda.FunctionOverrides
{
public static class AnimatedItemRobotToyOverrides
{
private static readonly DynamicMethod baseEquipItem;
static AnimatedItemRobotToyOverrides()
{
MethodInfo method = typeof(GrabbableObject).GetMethod("EquipItem", BindingFlags.Instance | BindingFlags.Public);
baseEquipItem = DynamicMethodCreator.GetDynamicMethod(method, "EquipItem");
}
public static void EquipItem(AnimatedItem robotToy)
{
baseEquipItem.Invoke(null, new object[1] { robotToy });
RobotToyFunctions.SetHeldMesh(robotToy);
if ((Object)(object)robotToy.itemAudioLowPassFilter != (Object)null)
{
robotToy.itemAudioLowPassFilter.cutoffFrequency = 20000f;
}
robotToy.itemAudio.volume = 1f;
if (robotToy.chanceToTriggerAlternateMesh > 0 && robotToy.itemRandomChance.Next(0, 100) < robotToy.chanceToTriggerAlternateMesh)
{
RobotToyFunctions.SetSadTexture((Component)(object)robotToy);
robotToy.itemAudio.Stop();
return;
}
if (!robotToy.wasInPocket)
{
if (robotToy.itemRandomChance.Next(0, 100) > robotToy.chanceToTriggerAnimation)
{
RobotToyFunctions.SetSadTexture((Component)(object)robotToy);
robotToy.itemAudio.Stop();
return;
}
}
else
{
robotToy.wasInPocket = false;
}
RobotToyFunctions.SetNormalTexture((Component)(object)robotToy);
if ((Object)(object)robotToy.itemAnimator != (Object)null)
{
robotToy.itemAnimator.SetBool(robotToy.grabItemBoolString, true);
}
if ((Object)(object)robotToy.itemAudio != (Object)null)
{
robotToy.itemAudio.clip = robotToy.grabAudio;
robotToy.itemAudio.loop = robotToy.loopGrabAudio;
robotToy.itemAudio.Play();
}
}
}
}
namespace MonsterSoda.Constants
{
public static class SteamUserIDs
{
public const ulong EASTER_EGG = 76561199153768459uL;
public const ulong LEEK_ID = 76561198129133083uL;
}
}
namespace MonsterSoda.Components
{
public class ObjectNameSetter : MonoBehaviour
{
private ScanNodeProperties scanNodeProperties;
private GrabbableObject grabbableObject;
private void Awake()
{
scanNodeProperties = ((Component)this).GetComponentInChildren<ScanNodeProperties>();
grabbableObject = ((Component)this).GetComponentInChildren<GrabbableObject>();
}
public void SetName(string newName)
{
if ((Object)(object)scanNodeProperties == (Object)null)
{
Awake();
}
if (Object.op_Implicit((Object)(object)scanNodeProperties))
{
scanNodeProperties.headerText = newName;
}
grabbableObject.itemProperties.itemName = newName;
}
}
}
namespace MonsterSoda.Components.TextureUpdaters
{
public abstract class AbstractTextureUpdater : MonoBehaviour
{
public static readonly int BaseColorMap = Shader.PropertyToID("_BaseColorMap");
public static readonly int MainTex = Shader.PropertyToID("_MainTex");
protected Renderer rendererComponent;
private void Awake()
{
rendererComponent = ((Component)this).GetComponent<Renderer>();
}
private void Start()
{
if (ShouldUpdateTexture())
{
SwapTextures();
}
}
protected abstract bool ShouldUpdateTexture();
protected abstract void SwapTextures();
}
public class PostersTextureUpdater : AbstractTextureUpdater
{
private static bool shouldUpdateTexture = true;
protected override bool ShouldUpdateTexture()
{
return shouldUpdateTexture;
}
protected override void SwapTextures()
{
shouldUpdateTexture = false;
List<Material> list = rendererComponent.materials.ToList();
Material val = list[0];
if (AssetBundleUtil.TryLoadAsset<Texture2D>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Textures/AllPosters.png", out Texture2D asset))
{
val.SetTexture(AbstractTextureUpdater.BaseColorMap, (Texture)(object)asset);
val.SetTexture(AbstractTextureUpdater.MainTex, (Texture)(object)asset);
}
Material val2 = list[1];
if (AssetBundleUtil.TryLoadAsset<Texture2D>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Textures/BigPosterTexture.png", out asset))
{
val2.SetTexture(AbstractTextureUpdater.BaseColorMap, (Texture)(object)asset);
val2.SetTexture(AbstractTextureUpdater.MainTex, (Texture)(object)asset);
}
rendererComponent.SetSharedMaterials(list);
}
}
public class SodaCanTextureUpdater : AbstractTextureUpdater
{
private static bool shouldUpdateTexture = true;
protected override bool ShouldUpdateTexture()
{
return shouldUpdateTexture;
}
protected override void SwapTextures()
{
shouldUpdateTexture = false;
Material sharedMaterial = rendererComponent.sharedMaterial;
if (AssetBundleUtil.TryLoadAsset<Texture2D>("monstienergy.lem", "Assets/Mods/MonstiEnergy/Textures/MonstiTexture.png", out Texture2D asset))
{
sharedMaterial.SetTexture(AbstractTextureUpdater.BaseColorMap, (Texture)(object)asset);
sharedMaterial.SetTexture(AbstractTextureUpdater.MainTex, (Texture)(object)asset);
}
}
}
}