Decompiled source of StarTrekValuables v1.0.3

StarTrekValuables.dll

Decompiled a day ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using REPOLib.Modules;
using StarTrekValuables.Scripts;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[CompilerGenerated]
[EditorBrowsable(EditorBrowsableState.Never)]
[GeneratedCode("Unity.MonoScriptGenerator.MonoScriptInfoGenerator", null)]
internal class UnitySourceGeneratedAssemblyMonoScriptTypes_v1
{
	private struct MonoScriptData
	{
		public byte[] FilePathsData;

		public byte[] TypesData;

		public int TotalTypes;

		public int TotalFiles;

		public bool IsEditorOnly;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private static MonoScriptData Get()
	{
		MonoScriptData result = default(MonoScriptData);
		result.FilePathsData = new byte[325]
		{
			0, 0, 0, 1, 0, 0, 0, 39, 92, 65,
			115, 115, 101, 116, 115, 92, 83, 99, 114, 105,
			112, 116, 115, 92, 66, 101, 112, 105, 110, 101,
			120, 80, 108, 117, 103, 105, 110, 92, 65, 115,
			115, 101, 116, 115, 46, 99, 115, 0, 0, 0,
			1, 0, 0, 0, 46, 92, 65, 115, 115, 101,
			116, 115, 92, 83, 99, 114, 105, 112, 116, 115,
			92, 66, 101, 112, 105, 110, 101, 120, 80, 108,
			117, 103, 105, 110, 92, 67, 111, 110, 102, 105,
			103, 77, 97, 110, 97, 103, 101, 114, 46, 99,
			115, 0, 0, 0, 1, 0, 0, 0, 45, 92,
			65, 115, 115, 101, 116, 115, 92, 83, 99, 114,
			105, 112, 116, 115, 92, 66, 101, 112, 105, 110,
			101, 120, 80, 108, 117, 103, 105, 110, 92, 77,
			121, 80, 108, 117, 103, 105, 110, 73, 110, 102,
			111, 46, 99, 115, 0, 0, 0, 1, 0, 0,
			0, 68, 92, 65, 115, 115, 101, 116, 115, 92,
			83, 99, 114, 105, 112, 116, 115, 92, 66, 101,
			112, 105, 110, 101, 120, 80, 108, 117, 103, 105,
			110, 92, 80, 97, 116, 99, 104, 101, 115, 92,
			86, 97, 108, 117, 97, 98, 108, 101, 79, 98,
			106, 101, 99, 116, 68, 105, 115, 99, 111, 118,
			101, 114, 80, 97, 116, 99, 104, 46, 99, 115,
			0, 0, 0, 1, 0, 0, 0, 39, 92, 65,
			115, 115, 101, 116, 115, 92, 83, 99, 114, 105,
			112, 116, 115, 92, 66, 101, 112, 105, 110, 101,
			120, 80, 108, 117, 103, 105, 110, 92, 80, 108,
			117, 103, 105, 110, 46, 99, 115, 0, 0, 0,
			1, 0, 0, 0, 40, 92, 65, 115, 115, 101,
			116, 115, 92, 83, 99, 114, 105, 112, 116, 115,
			92, 77, 111, 110, 111, 66, 101, 104, 97, 118,
			105, 111, 117, 114, 115, 92, 68, 97, 120, 77,
			117, 103, 46, 99, 115
		};
		result.TypesData = new byte[216]
		{
			0, 0, 0, 0, 24, 83, 116, 97, 114, 84,
			114, 101, 107, 86, 97, 108, 117, 97, 98, 108,
			101, 115, 124, 65, 115, 115, 101, 116, 115, 0,
			0, 0, 0, 31, 83, 116, 97, 114, 84, 114,
			101, 107, 86, 97, 108, 117, 97, 98, 108, 101,
			115, 124, 67, 111, 110, 102, 105, 103, 77, 97,
			110, 97, 103, 101, 114, 0, 0, 0, 0, 30,
			83, 116, 97, 114, 84, 114, 101, 107, 86, 97,
			108, 117, 97, 98, 108, 101, 115, 124, 77, 121,
			80, 108, 117, 103, 105, 110, 73, 110, 102, 111,
			0, 0, 0, 0, 45, 83, 116, 97, 114, 84,
			114, 101, 107, 86, 97, 108, 117, 97, 98, 108,
			101, 115, 124, 86, 97, 108, 117, 97, 98, 108,
			101, 79, 98, 106, 101, 99, 116, 68, 105, 115,
			99, 111, 118, 101, 114, 80, 97, 116, 99, 104,
			0, 0, 0, 0, 24, 83, 116, 97, 114, 84,
			114, 101, 107, 86, 97, 108, 117, 97, 98, 108,
			101, 115, 124, 80, 108, 117, 103, 105, 110, 0,
			0, 0, 0, 32, 83, 116, 97, 114, 84, 114,
			101, 107, 86, 97, 108, 117, 97, 98, 108, 101,
			115, 46, 83, 99, 114, 105, 112, 116, 115, 124,
			68, 97, 120, 77, 117, 103
		};
		result.TotalFiles = 6;
		result.TotalTypes = 6;
		result.IsEditorOnly = false;
		return result;
	}
}
namespace StarTrekValuables
{
	internal static class Assets
	{
		public static List<GameObject> ValuablesPrefabs { get; private set; } = new List<GameObject>();


		public static List<string> ValuablesPrefabNames { get; private set; } = new List<string>();


		public static Dictionary<string, Object> NonPrefabAssets { get; private set; } = new Dictionary<string, Object>();


		public static AssetBundle AssetBundle { get; private set; }

		public static void Load()
		{
			LoadAssetsFromAssetBundle();
		}

		private static void LoadAssetsFromAssetBundle()
		{
			AssetBundle val2 = (AssetBundle = LoadAssetBundle("startrekvaluables_assets"));
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			string[] allAssetNames = val2.GetAllAssetNames();
			foreach (string text in allAssetNames)
			{
				if (text.EndsWith(".prefab"))
				{
					Plugin.Logger.LogInfo((object)("Loading prefab \"" + text + "\" from AssetBundle \"" + ((Object)val2).name + "\""));
					GameObject val3 = Assets.LoadAssetFromAssetBundle<GameObject>(text, val2);
					ValuablesPrefabs.Add(val3);
					ValuablesPrefabNames.Add(((Object)val3).name);
				}
				else
				{
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
					Plugin.Logger.LogInfo((object)("Loading asset \"" + fileNameWithoutExtension + "\" (path: \"" + text + "\") from AssetBundle \"" + ((Object)val2).name + "\""));
					NonPrefabAssets.Add(fileNameWithoutExtension, Assets.LoadAssetFromAssetBundle<Object>(text, val2));
				}
			}
			Plugin.Logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
		}

		private static AssetBundle LoadAssetBundle(string fileName)
		{
			try
			{
				return AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location), fileName));
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Failed to load AssetBundle \"{fileName}\". {arg}");
			}
			return null;
		}

		public static T LoadAssetFromAssetBundle<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" from AssetBundle. Name is null or whitespace."));
				return default(T);
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. AssetBundle is null"));
				return default(T);
			}
			T val = assetBundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. No asset found with that type and name."));
				return default(T);
			}
			return val;
		}
	}
	internal static class ConfigManager
	{
		internal static Dictionary<string, List<string>> _valuableLevelSpawnsDefaults = new Dictionary<string, List<string>>
		{
			{
				"Valuable Antimatter Pod",
				new List<string> { "Valuables - Arctic" }
			},
			{
				"Valuable Blue Barrel",
				new List<string> { "Valuables - Arctic" }
			},
			{
				"Valuable Clock",
				new List<string> { "Valuables - Wizard" }
			},
			{
				"Valuable Exocomp",
				new List<string> { "Valuables - Arctic" }
			},
			{
				"Valuable Horgahn",
				new List<string> { "Valuables - Manor", "Valuables - Wizard" }
			},
			{
				"Valuable Metal Pipe",
				new List<string> { "Valuables - Manor", "Valuables - Arctic" }
			},
			{
				"Valuable Mug",
				new List<string> { "Valuables - Manor", "Valuables - Arctic" }
			},
			{
				"Valuable Odos Bucket",
				new List<string> { "Valuables - Manor", "Valuables - Wizard" }
			},
			{
				"Valuable Pyramid Game",
				new List<string> { "Valuables - Arctic" }
			},
			{
				"Valuable Strange Rock",
				new List<string> { "Valuables - Manor", "Valuables - Arctic" }
			},
			{
				"Valuable Widedoc Plush",
				new List<string> { "Valuables - Manor", "Valuables - Arctic" }
			},
			{
				"Valuable Worfs Chair",
				new List<string> { "Valuables - Manor" }
			}
		};

		public static ConfigFile ConfigFile { get; private set; }

		public static Dictionary<string, List<string>> ValuableLevelSpawns { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			ValuableLevelSpawns = new Dictionary<string, List<string>>();
			BindConfigs();
		}

		private static void BindConfigs()
		{
			foreach (string valuablesPrefabName in Assets.ValuablesPrefabNames)
			{
				if (!_valuableLevelSpawnsDefaults.TryGetValue(valuablesPrefabName, out var value))
				{
					value = new List<string> { "Valuables - Generic" };
				}
				ValuableLevelSpawns[valuablesPrefabName] = ConfigFile.Bind<string>("Valuable Spawns", valuablesPrefabName, (value != null) ? string.Join(",", value) : "Valuables - Generic", (ConfigDescription)null).Value.Split(",").ToList();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "StarTrekValuables";

		public const string PLUGIN_NAME = "StarTrekValuables";

		public const string PLUGIN_VERSION = "1.0.3";
	}
	[HarmonyPatch(typeof(ValuableObject), "Discover")]
	internal static class ValuableObjectDiscoverPatch
	{
		private static bool Prefix(ValuableObject __instance, State _state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)_state == 2)
			{
				return true;
			}
			DaxMug daxMug = default(DaxMug);
			if (((Component)__instance).TryGetComponent<DaxMug>(ref daxMug))
			{
				Plugin.Logger.LogInfo((object)"DaxMug discovered. Running patch.");
				daxMug.DiscoverScare();
				__instance.Discover((State)2);
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("StarTrekValuables", "StarTrekValuables", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static Harmony harmony;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = Logger.CreateLogSource("StarTrekValuables");
			Logger.LogInfo((object)"Plugin StarTrekValuables awake!");
			harmony = new Harmony("StarTrekValuables");
			harmony.PatchAll();
			Assets.Load();
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			RegisterValuables();
		}

		private void RegisterValuables()
		{
			foreach (GameObject valuablesPrefab in Assets.ValuablesPrefabs)
			{
				Valuables.RegisterValuable(valuablesPrefab, ConfigManager.ValuableLevelSpawns[((Object)valuablesPrefab).name]);
			}
			Logger.LogInfo((object)$"Registered {Assets.ValuablesPrefabs.Count} valuables!");
		}
	}
}
namespace StarTrekValuables.Scripts
{
	public class DaxMug : MonoBehaviour
	{
		private bool localSeen;

		private bool localSeenEffect;

		private float localSeenEffectTimer = 2f;

		public AudioClip seenSound;

		private PhysGrabObject physGrabObject;

		private void Start()
		{
			Debug.Log((object)"Dax is awake.");
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		}

		private void Update()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (localSeenEffect)
			{
				localSeenEffectTimer -= Time.deltaTime;
				CameraZoom.Instance.OverrideZoomSet(75f, 0.1f, 0.25f, 0.25f, ((Component)this).gameObject, 150);
				PostProcessing.Instance.VignetteOverride(Color.black, 0.4f, 1f, 1f, 0.5f, 0.1f, ((Component)this).gameObject);
				PostProcessing.Instance.SaturationOverride(-50f, 1f, 0.5f, 0.1f, ((Component)this).gameObject);
				PostProcessing.Instance.ContrastOverride(5f, 1f, 0.5f, 0.1f, ((Component)this).gameObject);
				GameDirector.instance.CameraImpact.Shake(10f * Time.deltaTime, 0.1f);
				GameDirector.instance.CameraShake.Shake(10f * Time.deltaTime, 1f);
				if (localSeenEffectTimer <= 0f)
				{
					localSeenEffect = false;
				}
			}
		}

		public void DiscoverScare()
		{
			Plugin.Logger.LogInfo((object)"Doing DaxMug scare");
			localSeenEffect = true;
			CameraGlitch.Instance.PlayLong();
			GameDirector.instance.CameraImpact.Shake(2f, 0.5f);
			GameDirector.instance.CameraShake.Shake(2f, 1f);
			localSeen = true;
			Plugin.Logger.LogInfo((object)$"Playing audio scare \"{seenSound}\"");
			AudioScare.instance.PlayCustom(seenSound, 0.3f, 60f);
		}
	}
}