using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using SquishCompany.Extensions;
using SquishCompany.MonoBehaviours;
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SquishCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SquishCompany")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("99e2ca9a-1171-425b-9108-d36eacb2cf69")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SquishCompany
{
public class SquishConfig
{
private const float DEFAULT_VOLUME = 50f;
public static void LoadVolumeFrom(ConfigFile config, List<CustomItemData> itemDatas)
{
foreach (CustomItemData itemData in itemDatas)
{
ConfigEntry<float> val = ConfigBindVolume(config, itemData);
SetAllAudioSourcesToValue(itemData.Prefab, val.Value);
}
}
public static void SetAllAudioSourcesToValue(GameObject prefab, float value)
{
AudioSource[] componentsInChildren = prefab.GetComponentsInChildren<AudioSource>();
if (componentsInChildren.Length != 0)
{
AudioSource[] array = componentsInChildren;
foreach (AudioSource val in array)
{
val.volume *= value / 100f;
}
}
}
public static ConfigEntry<float> ConfigBindVolume(ConfigFile config, CustomItemData itemData)
{
return config.Bind<float>(itemData.GetVolumeConfigDefinition(), 50f, itemData.GetVolumeConfigDescription());
}
}
public class CustomItemData
{
public string name;
public string itemPath;
public string infoPath;
public int scrapValue;
public int scrapRarity;
public LevelTypes scrapLevelFlags;
public int buyValue;
public Type monoBehaviour;
public bool Enabled { get; private set; }
public bool IsBuyable { get; private set; }
public bool IsScrap { get; private set; }
public Item ItemAsset { get; private set; }
public GameObject Prefab => ItemAsset.spawnPrefab;
public CustomItemData(string name_)
{
name = name_;
itemPath = Path.Combine("Assets", "Custom", "SquishCompany", "Items", name, name + ".asset");
scrapValue = 0;
scrapRarity = 0;
IsScrap = false;
IsBuyable = false;
Enabled = true;
}
private void SetEnabled(bool enabled_)
{
Enabled = enabled_;
}
private void MakeScrap(int itemPrice_, int rarity_, LevelTypes scrapLevelFlags_ = -1)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
IsScrap = true;
scrapValue = itemPrice_;
scrapRarity = rarity_;
scrapLevelFlags = scrapLevelFlags_;
}
private void MakeBuyable(int itemPrice_)
{
IsBuyable = true;
buyValue = itemPrice_;
}
public CustomItemData SetMonoBehaviour<T>() where T : MonoBehaviour
{
monoBehaviour = typeof(T);
return this;
}
public CustomItemData Bind<T>(ConfigFile config, string key, string description, ref T configValue)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_0032: Expected O, but got Unknown
configValue = (T)((ConfigEntryBase)config.Bind<T>(new ConfigDefinition("Scrap", name + key), configValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()))).BoxedValue;
return this;
}
public CustomItemData BindEnabled(ConfigFile config, bool enabled)
{
Bind(config, "Enabled", "Is " + name + " Enabled?", ref enabled);
SetEnabled(enabled);
return this;
}
public CustomItemData BindScrap(ConfigFile config, int price, int rarity)
{
Bind(config, "Price", "How much is " + name + " valued?", ref price);
Bind(config, "Rarity", "How much does " + name + " spawn, higher = more common?", ref rarity);
MakeScrap(price, rarity, (LevelTypes)(-1));
return this;
}
public CustomItemData BindBuyable(ConfigFile config, int price)
{
Bind(config, "Price", "How much is " + name + " valued?", ref price);
MakeBuyable(price);
return this;
}
public ConfigDefinition GetVolumeConfigDefinition()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
return new ConfigDefinition("Volume", name ?? "");
}
public ConfigDescription GetVolumeConfigDescription()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
return new ConfigDescription("Audio volume for " + name + " (0 - 100)", (AcceptableValueBase)null, Array.Empty<object>());
}
public void LoadAssetFrom(AssetBundle mainAssets)
{
Plugin.logger.LogInfo((object)("Attempting to load " + name + " at " + itemPath));
if (mainAssets == null)
{
Plugin.logger.LogError((object)"Main Assets is null!");
}
if (!mainAssets.Contains(itemPath))
{
Plugin.logger.LogError((object)("Main Assets does not contain item path " + itemPath + "!"));
}
ItemAsset = mainAssets.LoadAsset<Item>(itemPath);
if (ItemAsset == null)
{
Plugin.logger.LogError((object)("Failed to load item " + itemPath + " from asset!!"));
Plugin.DEBUG_ASSETBUNDLE();
}
if (Prefab == null)
{
Plugin.logger.LogError((object)"Items spawnPrefab is null!");
}
Prefab.EnsureNetworkTransform();
Prefab.OverridePhysicsPropWith(monoBehaviour);
Utilities.FixMixerGroups(Prefab);
NetworkPrefabs.RegisterNetworkPrefab(Prefab);
}
public void Register()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
if (ItemAsset == null)
{
Plugin.logger.LogError((object)"Registering failed! Item Asset is null");
}
else if (!IsBuyable)
{
if (IsScrap)
{
Plugin.logger.LogInfo((object)("Registering scrap item " + name));
Items.RegisterScrap(ItemAsset, scrapRarity, scrapLevelFlags);
}
else
{
Plugin.logger.LogInfo((object)("Registering item " + name));
Items.RegisterItem(ItemAsset);
}
}
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("ByCubed7.SquishCompany", "SquishCompany", "0.0.1")]
public class Plugin : BaseUnityPlugin
{
public const string modGUID = "ByCubed7.SquishCompany";
public const string modName = "SquishCompany";
public const string modVersion = "0.0.1";
private readonly Harmony harmony = new Harmony("ByCubed7.SquishCompany");
internal static ManualLogSource logger;
private static Plugin Instance;
public static ConfigFile GeneralConfig;
public static ConfigFile VolumeConfig;
public static List<CustomItemData> CustomItems = new List<CustomItemData>();
public static Dictionary<string, CustomItemData> CustomItemDatas = new Dictionary<string, CustomItemData>();
public static AssetBundle MainAssets { get; private set; }
private void Awake()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
if ((Object)(object)Instance != (Object)null)
{
throw new Exception("SquishCompanyBase already has an instance! Is this mod added twice?");
}
Instance = this;
logger = Logger.CreateLogSource("ByCubed7.SquishCompany");
logger.LogInfo((object)"Loading general configs.");
GeneralConfig = new ConfigFile(Paths.ConfigPath + "\\SquishCompany.cfg", true);
VolumeConfig = new ConfigFile(Paths.ConfigPath + "\\SquishCompany.AudioVolume.cfg", true);
MainAssets = LoadAssetBundle();
InitCustomItems();
LoadAndRegisterAllItems();
logger.LogInfo((object)"Loading volume configs.");
SquishConfig.LoadVolumeFrom(VolumeConfig, CustomItems);
harmony.PatchAll(typeof(Plugin));
}
public static AssetBundle LoadAssetBundle()
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string text = Path.Combine(directoryName, "SquishCompany".ToLower());
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
logger.LogError((object)"Failed to load custom assets.");
}
return val;
}
public static void DEBUG_ASSETBUNDLE()
{
logger.LogInfo((object)"All assets:");
string[] allAssetNames = MainAssets.GetAllAssetNames();
foreach (string text in allAssetNames)
{
logger.LogInfo((object)(" - " + text));
}
}
public static void InitCustomItems()
{
CustomItems = new List<CustomItemData> { new CustomItemData("SquishMellow").SetMonoBehaviour<SquishMellow>().BindEnabled(GeneralConfig, enabled: true).BindScrap(GeneralConfig, 15, 40) };
logger.LogInfo((object)"Custom items initialized!");
}
public static void LoadAndRegisterAllItems()
{
foreach (CustomItemData customItem in CustomItems)
{
if (customItem.Enabled)
{
customItem.LoadAssetFrom(MainAssets);
customItem.Register();
CustomItemDatas.Add(customItem.name, customItem);
}
}
}
}
}
namespace SquishCompany.MonoBehaviours
{
public class CustomPhysicsProp : PhysicsProp
{
public static void BroadcastAudioSource(AudioSource audiosource, bool isInShipRoom = false)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Sqrt(audiosource.maxDistance * audiosource.volume) * 2f;
RoundManager.Instance.PlayAudibleNoise(((Component)audiosource).transform.position, num, 0.5f, 0, isInShipRoom, 0);
}
public virtual void DEBUG_PRINT_STATE()
{
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"");
Debug.Log((object)"#### ############### ####");
Debug.Log((object)"#### GrabbableObject ####");
Debug.Log((object)$"- grabbable {((GrabbableObject)this).grabbable}");
Debug.Log((object)$"- isHeld {((GrabbableObject)this).isHeld}");
Debug.Log((object)$"- isHeldByEnemy {((GrabbableObject)this).isHeldByEnemy}");
Debug.Log((object)$"- deactivated {((GrabbableObject)this).deactivated}");
Debug.Log((object)$"- parentObject {((GrabbableObject)this).parentObject}");
Debug.Log((object)$"- targetFloorPosition {((GrabbableObject)this).targetFloorPosition}");
Debug.Log((object)$"- startFallingPosition {((GrabbableObject)this).startFallingPosition}");
Debug.Log((object)$"- floorYRot {((GrabbableObject)this).floorYRot}");
Debug.Log((object)$"- fallTime {((GrabbableObject)this).fallTime}");
Debug.Log((object)$"- hasHitGround {((GrabbableObject)this).hasHitGround}");
Debug.Log((object)$"- scrapValue {((GrabbableObject)this).scrapValue}");
Debug.Log((object)$"- itemUsedUp {((GrabbableObject)this).itemUsedUp}");
Debug.Log((object)$"- playerHeldBy {((GrabbableObject)this).playerHeldBy}");
Debug.Log((object)$"- isPocketed {((GrabbableObject)this).isPocketed}");
Debug.Log((object)$"- isBeingUsed {((GrabbableObject)this).isBeingUsed}");
Debug.Log((object)$"- isInElevator {((GrabbableObject)this).isInElevator}");
Debug.Log((object)$"- isInShipRoom {((GrabbableObject)this).isInShipRoom}");
Debug.Log((object)$"- isInFactory {((GrabbableObject)this).isInFactory}");
Debug.Log((object)$"- useCooldown {((GrabbableObject)this).useCooldown}");
Debug.Log((object)$"- currentUseCooldown {((GrabbableObject)this).currentUseCooldown}");
Debug.Log((object)$"- itemProperties {((GrabbableObject)this).itemProperties}");
Debug.Log((object)$"- insertedBattery {((GrabbableObject)this).insertedBattery}");
Debug.Log((object)("- customGrabTooltip " + ((GrabbableObject)this).customGrabTooltip));
Debug.Log((object)$"- propBody {((GrabbableObject)this).propBody}");
Debug.Log((object)$"- propColliders {((GrabbableObject)this).propColliders}");
Debug.Log((object)$"- originalScale {((GrabbableObject)this).originalScale}");
Debug.Log((object)$"- wasOwnerLastFrame {((GrabbableObject)this).wasOwnerLastFrame}");
Debug.Log((object)$"- mainObjectRenderer {((GrabbableObject)this).mainObjectRenderer}");
Debug.Log((object)$"- scrapPersistedThroughRounds {((GrabbableObject)this).scrapPersistedThroughRounds}");
Debug.Log((object)$"- heldByPlayerOnServer {((GrabbableObject)this).heldByPlayerOnServer}");
Debug.Log((object)$"- radarIcon {((GrabbableObject)this).radarIcon}");
Debug.Log((object)$"- reachedFloorTarget {((GrabbableObject)this).reachedFloorTarget}");
Debug.Log((object)$"- grabbableToEnemies {((GrabbableObject)this).grabbableToEnemies}");
}
}
public class SquishMellow : CustomPhysicsProp
{
public AudioSource noiseAudio;
public AudioSource noiseAudioFar;
public AudioSource musicAudio;
public AudioSource musicAudioFar;
public AudioClip[] noiseSFX;
public AudioClip[] noiseSFXFar;
private Random noisemakerRandom;
private float noiseInterval = 1f;
public NetworkVariable<bool> isPlayingMusic = new NetworkVariable<bool>(true, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)1);
public override void Start()
{
((GrabbableObject)this).Start();
noisemakerRandom = new Random(StartOfRound.Instance.randomMapSeed + 85);
noiseAudio = ((Component)((Component)this).transform.Find("Noise Near")).GetComponent<AudioSource>();
musicAudio = ((Component)((Component)this).transform.Find("Music Near")).GetComponent<AudioSource>();
noiseAudioFar = ((Component)((Component)noiseAudio).transform.Find("Noise Far")).GetComponent<AudioSource>();
musicAudioFar = ((Component)((Component)musicAudio).transform.Find("Music Far")).GetComponent<AudioSource>();
noiseSFX = null;
noiseSFXFar = null;
}
public override void OnNetworkSpawn()
{
((NetworkBehaviour)this).OnNetworkSpawn();
if (((NetworkBehaviour)this).IsOwner)
{
isPlayingMusic.Value = true;
}
}
public override void ItemActivate(bool used, bool buttonDown = true)
{
((GrabbableObject)this).ItemActivate(used, buttonDown);
if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
{
}
}
public override void DiscardItem()
{
if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
{
((GrabbableObject)this).playerHeldBy.equippedUsableItemQE = false;
}
((GrabbableObject)this).isBeingUsed = false;
((GrabbableObject)this).DiscardItem();
}
public override void EquipItem()
{
((PhysicsProp)this).EquipItem();
((GrabbableObject)this).playerHeldBy.equippedUsableItemQE = true;
}
public override void ItemInteractLeftRight(bool right)
{
((GrabbableObject)this).ItemInteractLeftRight(right);
Debug.Log((object)"ItemInteractLeftRight");
if (!right && ((NetworkBehaviour)this).IsOwner)
{
Debug.Log((object)"Running");
isPlayingMusic.Value = !isPlayingMusic.Value;
}
}
public override void InteractItem()
{
((GrabbableObject)this).InteractItem();
}
public override void Update()
{
((GrabbableObject)this).Update();
if (isPlayingMusic.Value)
{
if (!musicAudio.isPlaying)
{
musicAudio.Play();
}
if (noiseInterval <= 0f)
{
noiseInterval = 3f;
CustomPhysicsProp.BroadcastAudioSource(noiseAudio, ((GrabbableObject)this).isInShipRoom);
}
else
{
noiseInterval -= Time.deltaTime;
}
}
else if (musicAudio.isPlaying)
{
musicAudio.Pause();
}
}
public override void DEBUG_PRINT_STATE()
{
base.DEBUG_PRINT_STATE();
Debug.Log((object)"");
Debug.Log((object)"#### ############ ####");
Debug.Log((object)"#### SquishMellow ####");
Debug.Log((object)$"- noiseAudio {noiseAudio}");
Debug.Log((object)$"- noiseAudioFar {noiseAudioFar}");
Debug.Log((object)$"- musicAudio {musicAudio}");
Debug.Log((object)$"- musicAudioFar {musicAudioFar}");
Debug.Log((object)$"- noiseSFX {noiseSFX}");
Debug.Log((object)$"- noiseSFXFar {noiseSFXFar}");
Debug.Log((object)$"- noisemakerRandom {noisemakerRandom}");
Debug.Log((object)$"- noiseInterval {noiseInterval}");
Debug.Log((object)$"- isPlayingMusic {isPlayingMusic}");
Debug.Log((object)"");
}
}
}
namespace SquishCompany.Extensions
{
public static class Extensions
{
public static bool EnsureNetworkTransform(this GameObject gameObject)
{
if (!gameObject.EnsureComponent<NetworkTransform>())
{
return false;
}
NetworkTransform component = gameObject.GetComponent<NetworkTransform>();
component.SlerpPosition = false;
component.Interpolate = false;
component.SyncPositionX = false;
component.SyncPositionY = false;
component.SyncPositionZ = false;
component.SyncScaleX = false;
component.SyncScaleY = false;
component.SyncScaleZ = false;
component.UseHalfFloatPrecision = true;
return true;
}
public static bool EnsureComponent<T>(this GameObject gameObject) where T : Component
{
if ((Object)(object)gameObject.GetComponent<T>() != (Object)null)
{
return false;
}
Plugin.logger.LogInfo((object)("Item has no " + typeof(T).Name + "! Adding it."));
gameObject.AddComponent<T>();
return true;
}
public static void OverridePhysicsPropWith<T>(this GameObject gameObject) where T : PhysicsProp
{
gameObject.OverridePhysicsPropWith(typeof(T));
}
public static void OverridePhysicsPropWith(this GameObject gameObject, Type type)
{
PhysicsProp component = gameObject.GetComponent<PhysicsProp>();
Component obj = gameObject.AddComponent(type);
PhysicsProp destination = (PhysicsProp)(object)((obj is PhysicsProp) ? obj : null);
component.CopyTo<PhysicsProp, PhysicsProp>(destination);
Object.Destroy((Object)(object)component);
}
public static T1 CopyTo<T1, T2>(this T1 source, T2 destination) where T1 : class where T2 : T1
{
PropertyInfo[] properties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
PropertyInfo[] properties2 = destination.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
PropertyInfo[] array = properties;
foreach (PropertyInfo property in array)
{
PropertyInfo propertyInfo = properties2.FirstOrDefault((PropertyInfo x) => x.Name == property.Name);
if (propertyInfo.CanWrite)
{
propertyInfo.SetValue(destination, property.GetValue(source));
}
}
FieldInfo[] fields = source.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField);
FieldInfo[] fields2 = destination.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField);
FieldInfo[] array2 = fields;
foreach (FieldInfo property2 in array2)
{
FieldInfo fieldInfo = fields2.FirstOrDefault((FieldInfo x) => x.Name == property2.Name);
fieldInfo.SetValue(destination, property2.GetValue(source));
}
return source;
}
}
}