Decompiled source of BuildEverywhere v1.0.0

BuildNoLimits.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using FishNet.Connection;
using HarmonyLib;
using MelonLoader;
using S2;
using ScheduleOne.Building;
using ScheduleOne.DevUtilities;
using ScheduleOne.EntityFramework;
using ScheduleOne.ItemFramework;
using ScheduleOne.PlayerScripts;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::S2.S2), "Build_debug", "1.0", "Estonia", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyTitle("StackSizes")]
[assembly: AssemblyDescription("Increases Stack Sizes")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Estonia")]
[assembly: AssemblyProduct("StackSizes")]
[assembly: AssemblyCopyright("Copyright © Estonia 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3506c5d7-811e-4046-9fe7-9e963df141bd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace S2;

public class S2 : MelonMod
{
	[HarmonyPatch(typeof(BuildUpdate_Grid), "LateUpdate")]
	public class BuildUpdateGridPatch
	{
		private static void Postfix(BuildUpdate_Grid __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKey((KeyCode)304))
			{
				PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
				float holdDistance = ((BuildableItem)__instance.BuildableItemClass).HoldDistance;
				__instance.GhostModel.transform.position = ((Component)instance).transform.position + ((Component)instance).transform.forward * holdDistance;
				Material ghostMaterial_White = Singleton<BuildManager>.Instance.ghostMaterial_White;
				Singleton<BuildManager>.Instance.ApplyMaterial(__instance.GhostModel, ghostMaterial_White, true);
			}
		}
	}

	[HarmonyPatch(typeof(BuildUpdate_Grid), "Place")]
	public class BuildUpdateGridPlacePatch
	{
		private static bool Prefix(BuildUpdate_Grid __instance)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			MelonLogger.Msg("BuildUpdate_Grid.Place Prefix called");
			if (Input.GetKey((KeyCode)304))
			{
				MelonLogger.Msg("LeftShift is held down");
				GameObject ghostModel = __instance.GhostModel;
				ItemInstance itemInstance = __instance.ItemInstance;
				BuildManager instance = Singleton<BuildManager>.Instance;
				ItemDefinition definition = itemInstance.Definition;
				BuildableItemDefinition val = (BuildableItemDefinition)(object)((definition is BuildableItemDefinition) ? definition : null);
				if ((Object)(object)val == (Object)null)
				{
					MelonLogger.Msg("itemDef is null");
					return false;
				}
				if ((Object)(object)val.BuiltItem == (Object)null || (Object)(object)((Component)val.BuiltItem).gameObject == (Object)null)
				{
					MelonLogger.Msg("BuiltItem or its gameObject is null");
					return false;
				}
				Vector3 position = ghostModel.transform.position;
				string? text = ((object)(Vector3)(ref position)).ToString();
				Quaternion rotation = ghostModel.transform.rotation;
				MelonLogger.Msg("Instantiating item at position: " + text + " with rotation: " + ((object)(Quaternion)(ref rotation)).ToString());
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val.BuiltItem).gameObject, ghostModel.transform.position, ghostModel.transform.rotation);
				MelonLogger.Msg("Item instantiated: " + ((Object)(object)val2 != (Object)null));
				GridItem component = val2.GetComponent<GridItem>();
				if ((Object)(object)component != (Object)null)
				{
					MelonLogger.Msg("Setting locally built");
					((BuildableItem)component).SetLocallyBuilt();
					PropertyInfo property = ((object)component).GetType().GetProperty("grid");
					if (property != null)
					{
						property.SetValue(component, null);
						MelonLogger.Msg("Grid association removed for GridItem");
					}
					else
					{
						MelonLogger.Msg("GridItem does not have a 'grid' property");
					}
				}
				else
				{
					MelonLogger.Msg("GridItem component not found on instantiated object");
				}
				MelonLogger.Msg("Spawning item on network");
				instance.networkObject.Spawn(val2, (NetworkConnection)null, default(Scene));
				MelonLogger.Msg("Changing inventory quantity");
				((ItemSlot)PlayerSingleton<PlayerInventory>.Instance.equippedSlot).ChangeQuantity(-1, false);
				MelonLogger.Msg("Playing build sound");
				instance.PlayBuildSound(val.BuildSoundType, ghostModel.transform.position);
				return false;
			}
			MelonLogger.Msg("LeftShift not held, proceeding with original logic");
			return true;
		}
	}

	[HarmonyPatch(typeof(BuildUpdate_ProceduralGrid), "LateUpdate")]
	public class BuildUpdateProceduralGridPatch
	{
		private static void Postfix(BuildUpdate_ProceduralGrid __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKey((KeyCode)304))
			{
				PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
				float holdDistance = ((BuildableItem)__instance.ItemClass).HoldDistance;
				__instance.GhostModel.transform.position = ((Component)instance).transform.position + ((Component)instance).transform.forward * holdDistance;
				Material ghostMaterial_White = Singleton<BuildManager>.Instance.ghostMaterial_White;
				Singleton<BuildManager>.Instance.ApplyMaterial(__instance.GhostModel, ghostMaterial_White, true);
			}
		}
	}

	[HarmonyPatch(typeof(BuildUpdate_ProceduralGrid), "Place")]
	public class BuildUpdateProceduralGridPlacePatch
	{
		private static bool Prefix(BuildUpdate_ProceduralGrid __instance)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			MelonLogger.Msg("BuildUpdate_ProceduralGrid.Place Prefix called");
			if (Input.GetKey((KeyCode)304))
			{
				MelonLogger.Msg("LeftShift is held down");
				GameObject ghostModel = __instance.GhostModel;
				ItemInstance itemInstance = __instance.ItemInstance;
				BuildManager instance = Singleton<BuildManager>.Instance;
				ItemDefinition definition = itemInstance.Definition;
				BuildableItemDefinition val = (BuildableItemDefinition)(object)((definition is BuildableItemDefinition) ? definition : null);
				if ((Object)(object)val == (Object)null)
				{
					MelonLogger.Msg("itemDef is null");
					return false;
				}
				if ((Object)(object)val.BuiltItem == (Object)null || (Object)(object)((Component)val.BuiltItem).gameObject == (Object)null)
				{
					MelonLogger.Msg("BuiltItem or its gameObject is null");
					return false;
				}
				Vector3 position = ghostModel.transform.position;
				string? text = ((object)(Vector3)(ref position)).ToString();
				Quaternion rotation = ghostModel.transform.rotation;
				MelonLogger.Msg("Instantiating item at position: " + text + " with rotation: " + ((object)(Quaternion)(ref rotation)).ToString());
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val.BuiltItem).gameObject, ghostModel.transform.position, ghostModel.transform.rotation);
				MelonLogger.Msg("Item instantiated: " + ((Object)(object)val2 != (Object)null));
				ProceduralGridItem component = val2.GetComponent<ProceduralGridItem>();
				if ((Object)(object)component != (Object)null)
				{
					MelonLogger.Msg("Setting locally built");
					((BuildableItem)component).SetLocallyBuilt();
					PropertyInfo property = ((object)component).GetType().GetProperty("grid");
					if (property != null)
					{
						property.SetValue(component, null);
						MelonLogger.Msg("Grid association removed for ProceduralGridItem");
					}
					else
					{
						MelonLogger.Msg("ProceduralGridItem does not have a 'grid' property");
					}
				}
				else
				{
					MelonLogger.Msg("ProceduralGridItem component not found on instantiated object");
				}
				MelonLogger.Msg("Spawning item on network");
				instance.networkObject.Spawn(val2, (NetworkConnection)null, default(Scene));
				MelonLogger.Msg("Changing inventory quantity");
				((ItemSlot)PlayerSingleton<PlayerInventory>.Instance.equippedSlot).ChangeQuantity(-1, false);
				MelonLogger.Msg("Playing build sound");
				instance.PlayBuildSound(val.BuildSoundType, ghostModel.transform.position);
				return false;
			}
			MelonLogger.Msg("LeftShift not held, proceeding with original logic");
			return true;
		}
	}

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("Ultimate Mod initialized - Build anywhere with LeftShift!");
		((MelonBase)this).HarmonyInstance.PatchAll();
	}
}