Decompiled source of SacrificialStonesShifted v1.0.1

IronLabs.SacrificialStonesShifted.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using IronLabs.SharedLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("IronLabs.SacrificialStonesShifted")]
[assembly: AssemblyDescription("Moves Valheim's Sacrificial Stones away from the world center.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("IronLabs")]
[assembly: AssemblyProduct("IronLabs.SacrificialStonesShifted")]
[assembly: AssemblyCopyright("Copyright © 2026 End3rbyte")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("C698CE81-6F76-4320-A8C2-80E5273177E7")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.1.27463")]
namespace IronLabs.SacrificialStonesShifted
{
	[BepInPlugin("IronLabs.SacrificialStonesShifted", "IronLabs.SacrificialStonesShifted", "1.0.1")]
	public sealed class SacrificialStonesShiftedPlugin : IronLabsPlugin
	{
		private const string PluginGuid = "IronLabs.SacrificialStonesShifted";

		private const string PluginName = "IronLabs.SacrificialStonesShifted";

		private const string PluginVersion = "1.0.1";

		internal static ModLog Log { get; private set; }

		private void Awake()
		{
			Log = InitializePlugin("IronLabs.SacrificialStonesShifted");
			Log.LogInfo("IronLabs.SacrificialStonesShifted 1.0.1 is loaded.");
		}

		private void OnDestroy()
		{
			ShutdownPlugin();
			Log = null;
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "GenerateLocations")]
	internal static class ZoneSystemGenerateLocationsPatch
	{
		private const string StartTemplePrefabName = "StartTemple";

		private const float MinimumDistance = 1500f;

		private const float MaximumDistance = 1600f;

		private static void Prefix(ZoneSystem __instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			ZoneLocation val = FindStartTemple(__instance);
			if (val == null)
			{
				SacrificialStonesShiftedPlugin.Log.LogWarning("StartTemple was not found; its generation rules were not changed.");
				return;
			}
			val.m_biome = (Biome)1;
			val.m_minDistance = 1500f;
			val.m_maxDistance = 1600f;
			val.m_centerFirst = true;
			SacrificialStonesShiftedPlugin.Log.LogDebug($"StartTemple generation constrained to Meadows between {1500f} and {1600f} metres.");
		}

		private static ZoneLocation FindStartTemple(ZoneSystem zoneSystem)
		{
			foreach (ZoneLocation location in zoneSystem.m_locations)
			{
				if (location.m_prefabName == "StartTemple")
				{
					return location;
				}
			}
			return null;
		}
	}
}
namespace IronLabs.SharedLib
{
	public abstract class IronLabsPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private bool _patchesApplied;

		protected ModLog InitializePlugin(string pluginGuid)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			ModLog modLog = new ModLog(((BaseUnityPlugin)this).Logger);
			Version version = ((object)this).GetType().Assembly.GetName().Version;
			modLog.LogInfo($"AssemblyVersion: {version}.");
			_harmony = new Harmony(pluginGuid);
			PatchOwnNamespace(modLog);
			return modLog;
		}

		protected void PatchOwnNamespace(ModLog log)
		{
			if (_patchesApplied)
			{
				log.LogDebug("Harmony patches are already active; skipping registration.");
				return;
			}
			string text = ((object)this).GetType().Namespace;
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type.Namespace == text)
				{
					_harmony.CreateClassProcessor(type).Patch();
				}
			}
			_patchesApplied = true;
			log.LogDebug("Harmony patches were applied for the plugin namespace.");
		}

		protected void ShutdownPlugin()
		{
			if (_patchesApplied)
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
				_patchesApplied = false;
			}
		}
	}
	public sealed class ModLog
	{
		private readonly ManualLogSource _logger;

		public ModLog(ManualLogSource logger)
		{
			_logger = logger;
		}

		public void LogFatal(object message)
		{
			Write((LogLevel)1, message);
		}

		public void LogError(object message)
		{
			Write((LogLevel)2, message);
		}

		public void LogWarning(object message)
		{
			Write((LogLevel)4, message);
		}

		public void LogMessage(object message)
		{
			Write((LogLevel)8, message);
		}

		public void LogInfo(object message)
		{
			Write((LogLevel)16, message);
		}

		public void LogDebug(object message)
		{
			Write((LogLevel)32, message);
		}

		public void Log(LogLevel level, object message)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Write(level, message);
		}

		private void Write(LogLevel level, object message)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			string arg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
			_logger.Log(level, (object)$"[{arg}] {message}");
		}
	}
}