Decompiled source of Vagons v1.0.5

VagonsJVL.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
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("BrynServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BrynServer")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("492f36ab-5fce-4f82-9ea0-4941a3b9138d")]
[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 VagonsJVL;

[BepInPlugin("JVLVagons", "VagonsJVL", "1.0.5")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class vagonsJVL : BaseUnityPlugin
{
	public const string PluginGUID = "JVLVagons";

	public const string PluginName = "VagonsJVL";

	public const string PluginVersion = "1.0.5";

	internal static ManualLogSource Log;

	private CustomLocalization Localization;

	public AssetBundle WagonAssets;

	public ConfigEntry<bool> AddWagonsEnable;

	public GameObject WagonCrate1;

	public void CreateConfigurationValues()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		AddWagonsEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Wagons", "Enable", true, new ConfigDescription("Adds Wagons.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		SynchronizationManager.OnConfigurationSynchronized += delegate(object obj, ConfigurationSynchronizationEventArgs attr)
		{
			if (attr.InitialSynchronization)
			{
				Logger.LogMessage((object)"Initial Config sync event received for DoDSoloExperience");
			}
			else
			{
				Logger.LogMessage((object)"Config sync event received for DoDSoloExperience");
			}
		};
	}

	private void Awake()
	{
		try
		{
			Log = ((BaseUnityPlugin)this).Logger;
			CreateConfigurationValues();
			LoadBundle();
			AddLocalizations();
			AddWagons();
			PrefabManager.OnVanillaPrefabsAvailable += FixWagonAudio;
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while executing Vagons awake: {arg}");
		}
	}

	private void AddLocalizations()
	{
		try
		{
			Localization = LocalizationManager.Instance.GetLocalization();
			CustomLocalization localization = Localization;
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "prop_cargo_hw", "Crate" },
				{ "war_wagon3p_hw", "Battle Wagon" },
				{ "war_wagon3p_desc_hw", "Four wheeled Battle Wagon for 3 people" },
				{ "tool_wagon_hw", "Iron Wagon" },
				{ "tool_wagon_desc_hw", "Four wheeled Wagon with medium storage" },
				{ "tool_wagonmed_hw", "Blackmetal Wagon" },
				{ "tool_wagonmed_desc_hw", "Four wheeled Wagon with large storage" }
			});
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while adding Localication for Vagons: {arg}");
		}
	}

	public void LoadBundle()
	{
		try
		{
			WagonAssets = AssetUtils.LoadAssetBundleFromResources("wagons", Assembly.GetExecutingAssembly());
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while loading Vagon bundle: {arg}");
		}
	}

	private void AddWagons()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Expected O, but got Unknown
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Expected O, but got Unknown
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Expected O, but got Unknown
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Expected O, but got Unknown
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Expected O, but got Unknown
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Expected O, but got Unknown
		try
		{
			GameObject val = WagonAssets.LoadAsset<GameObject>("Wagon_HW");
			if ((Object)(object)val != (Object)null)
			{
				if (AddWagonsEnable.Value)
				{
					WagonCrate1 = WagonAssets.LoadAsset<GameObject>("WagonCrate_HW");
					GameObject prefab = PrefabManager.Instance.GetPrefab("WagonCrate_HW");
					if ((Object)(object)prefab != (Object)null)
					{
						((BaseUnityPlugin)this).Logger.LogMessage((object)"Vagon Crate already added.");
					}
					else
					{
						GameObject wagonCrate = WagonCrate1;
						CustomPrefab val2 = new CustomPrefab(wagonCrate, true);
						PrefabManager.Instance.AddPrefab(val2);
					}
					PieceConfig val3 = new PieceConfig();
					val3.PieceTable = "_HammerPieceTable";
					val3.Category = "Misc";
					val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[4]
					{
						new RequirementConfig
						{
							Item = "Resin",
							Amount = 15,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "Wood",
							Amount = 15,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "FineWood",
							Amount = 10,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "Iron",
							Amount = 5,
							Recover = true
						}
					};
					CustomPiece val4 = new CustomPiece(val, true, val3);
					PieceManager.Instance.AddPiece(val4);
					GameObject val5 = WagonAssets.LoadAsset<GameObject>("WagonMedium_HW");
					val3 = new PieceConfig();
					val3.PieceTable = "_HammerPieceTable";
					val3.Category = "Misc";
					val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[4]
					{
						new RequirementConfig
						{
							Item = "Resin",
							Amount = 15,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "Wood",
							Amount = 25,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "FineWood",
							Amount = 20,
							Recover = true
						},
						new RequirementConfig
						{
							Item = "BlackMetal",
							Amount = 5,
							Recover = true
						}
					};
					CustomPiece val6 = new CustomPiece(val5, true, val3);
					PieceManager.Instance.AddPiece(val6);
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogMessage((object)"Vagons disabled");
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogMessage((object)"Vagons not found");
			}
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while adding Vagons: {arg}");
		}
		finally
		{
			WagonAssets.Unload(false);
		}
	}

	private void FixWagonAudio()
	{
		try
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("Wagon_HW");
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("WagonMedium_HW");
			if ((Object)(object)prefab != (Object)null)
			{
				prefab.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer;
				prefab2.GetComponentInChildren<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer;
			}
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)$"Exception caught while adding AudioMixer to Vagons: {arg}");
		}
		finally
		{
			PrefabManager.OnVanillaPrefabsAvailable -= FixWagonAudio;
		}
	}
}