Decompiled source of PavedRoadNoLevel v1.0.5

plugins/PavedRoadNoLevel.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn;
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("PavedRoadNoLevel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PavedRoadNoLevel")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace PavedRoadNoLevel;

[BepInPlugin("DeathWizsh.PavedRoadNoLevel", "Paved Road No Level", "1.0.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class PavedRoadNoLevel : BaseUnityPlugin
{
	public const string PluginGUID = "DeathWizsh.PavedRoadNoLevel";

	public const string PluginName = "Paved Road No Level";

	public const string PluginVersion = "1.0.5";

	private static string configFileName = "DeathWizsh.PavedRoadNoLevel.cfg";

	private static string configFileFullPath;

	private ConfigEntry<bool> configEnable;

	private ConfigEntry<bool> configRequireStoncutter;

	private CraftingStation stonecutterPiece;

	private bool firstPatch = true;

	private void Awake()
	{
		InitConfig();
		if (configEnable.Value)
		{
			PrefabManager.OnVanillaPrefabsAvailable += PatchOriginal;
		}
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
	}

	private void PatchOriginal()
	{
		try
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("paved_road_v2");
			Piece component = prefab.GetComponent<Piece>();
			component.m_allowAltGroundPlacement = false;
			if (firstPatch)
			{
				stonecutterPiece = component.m_craftingStation;
				firstPatch = false;
			}
			if (!configRequireStoncutter.Value)
			{
				component.m_craftingStation = null;
			}
			else if ((Object)(object)component.m_craftingStation == (Object)null)
			{
				component.m_craftingStation = stonecutterPiece;
			}
			TerrainOp component2 = prefab.GetComponent<TerrainOp>();
			component2.m_settings.m_smooth = false;
			Logger.LogInfo((object)"Successfully patched Paved Road, enjoy!");
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Could not patch original: " + ex));
		}
	}

	private void UnpatchOriginal()
	{
		try
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("paved_road_v2");
			Piece component = prefab.GetComponent<Piece>();
			component.m_allowAltGroundPlacement = true;
			if ((Object)(object)component.m_craftingStation == (Object)null)
			{
				component.m_craftingStation = stonecutterPiece;
			}
			TerrainOp component2 = prefab.GetComponent<TerrainOp>();
			component2.m_settings.m_smooth = true;
			Logger.LogInfo((object)"Successfully unpatched Paved Road, Why u do this?!");
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Could not unpatch original: " + ex));
		}
	}

	private void ApplyConfigChanges()
	{
		if (configEnable.Value)
		{
			PatchOriginal();
		}
		else
		{
			UnpatchOriginal();
		}
	}

	private void InitConfig()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_004c: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Expected O, but got Unknown
		//IL_00b3: Expected O, but got Unknown
		try
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			configEnable = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Enable"), true, new ConfigDescription("Enable this mod", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			configEnable.SettingChanged += delegate
			{
				ApplyConfigChanges();
			};
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			configRequireStoncutter = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Stonecutter requirement"), true, new ConfigDescription("Enable the Stonecutter as a requirement (to pave roads)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			configRequireStoncutter.SettingChanged += delegate
			{
				ApplyConfigChanges();
			};
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, configFileName);
			fileSystemWatcher.Changed += OnConfigFileChange;
			fileSystemWatcher.Created += OnConfigFileChange;
			fileSystemWatcher.Renamed += OnConfigFileChange;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Could not initialise the config & events: " + ex));
		}
	}

	private void OnConfigFileChange(object sender, FileSystemEventArgs e)
	{
		if (!File.Exists(configFileFullPath))
		{
			return;
		}
		try
		{
			((BaseUnityPlugin)this).Config.Reload();
		}
		catch (Exception ex)
		{
			Logger.LogError((object)("Something went wrong while reloading the config, please check if the file exists and the entries are valid! " + ex));
		}
	}

	static PavedRoadNoLevel()
	{
		string configPath = Paths.ConfigPath;
		char directorySeparatorChar = Path.DirectorySeparatorChar;
		configFileFullPath = configPath + directorySeparatorChar + configFileName;
	}
}