using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ServerSync;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Architecting")]
[assembly: AssemblyDescription("Minimal rip from blaxxun's Building")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Architecting")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9BF5432D-9518-4D36-A6C2-A8C62D36B921")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace Architecting
{
[BepInPlugin("Jacobo.Architecting", "Architecting", "0.1.0")]
public class Architecting : BaseUnityPlugin
{
private enum Toggle
{
On = 1,
Off = 0
}
[HarmonyPatch(typeof(WearNTear), "OnPlaced")]
public class AddZDOBuilding
{
public static bool forFree;
private static void Postfix(WearNTear __instance)
{
__instance.m_health *= 1f + ((Component)__instance).GetComponent<ZNetView>().GetZDO().GetFloat("Crafting Level", 0f) * (healthFactor.Value - 1f);
if (freeBuildLevelRequirement.Value > 0)
{
forFree = Random.Range((float)freeBuildLevelRequirement.Value / 100f, 5.5f) <= ((Character)Player.m_localPlayer).GetSkillFactor((SkillType)107);
}
((Component)__instance).GetComponent<ZNetView>().GetZDO().Set("Building FreeBuild", forFree);
}
}
[HarmonyPatch(typeof(WearNTear), "Awake")]
private class IncreaseHealth
{
private static void Postfix(WearNTear __instance)
{
if (__instance.m_nview.GetZDO() != null)
{
Player localPlayer = Player.m_localPlayer;
float num = ((localPlayer != null) ? ((Character)localPlayer).GetSkillFactor((SkillType)107) : 0f);
((Component)__instance).GetComponent<ZNetView>().GetZDO().Set("Crafting Level", num);
__instance.m_health *= 1f + ((Component)__instance).GetComponent<ZNetView>().GetZDO().GetFloat("Crafting Level", 0f) * (healthFactor.Value - 1f);
}
}
}
[HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")]
private class BuildHigher
{
private static void Postfix(WearNTear __instance, ref float maxSupport, ref float minSupport, ref float horizontalLoss, ref float verticalLoss)
{
ZNetView nview = __instance.m_nview;
float? obj;
if (nview == null)
{
obj = null;
}
else
{
ZDO zDO = nview.GetZDO();
obj = ((zDO != null) ? new float?(zDO.GetFloat("Crafting Level", 0f)) : null);
}
float? num = obj;
float num2;
if (!num.HasValue)
{
Player localPlayer = Player.m_localPlayer;
num2 = ((localPlayer != null) ? ((Character)localPlayer).GetSkillFactor((SkillType)107) : 0f);
}
else
{
num2 = num.GetValueOrDefault();
}
float num3 = num2;
maxSupport *= 1f + num3 * (maximumSupportFactor.Value - 1f);
horizontalLoss *= 1f - num3 * (1f - supportLossFactor.Value);
verticalLoss *= 1f - num3 * (1f - supportLossFactor.Value);
}
}
[HarmonyPatch(typeof(Player), "UpdatePlacement")]
private class ResetFlag
{
private static void Finalizer()
{
AddZDOBuilding.forFree = false;
}
}
[HarmonyPatch(typeof(Player), "ConsumeResources")]
private class BuildingIsFree
{
private class SkipConsumeResourcesException : Exception
{
}
[HarmonyPriority(800)]
private static void Prefix()
{
if (AddZDOBuilding.forFree)
{
throw new SkipConsumeResourcesException();
}
}
private static Exception? Finalizer(Exception __exception)
{
if (!(__exception is SkipConsumeResourcesException))
{
return __exception;
}
return null;
}
}
[HarmonyPatch(typeof(Piece), "DropResources")]
private class RecoverResources
{
private static bool Prefix(Piece __instance)
{
return !((Component)__instance).GetComponent<ZNetView>().GetZDO().GetBool("Building FreeBuild", false);
}
}
private const string ModName = "Architecting";
private const string ModVersion = "0.1.0";
private const string ModGUID = "Jacobo.Architecting";
private static readonly ConfigSync configSync = new ConfigSync("Jacobo.Architecting")
{
DisplayName = "Architecting",
CurrentVersion = "0.1.0",
MinimumRequiredVersion = "0.1.0"
};
private static ConfigEntry<Toggle> serverConfigLocked = null;
private static ConfigEntry<float> maximumSupportFactor = null;
private static ConfigEntry<float> supportLossFactor = null;
private static ConfigEntry<float> healthFactor = null;
private static ConfigEntry<int> freeBuildLevelRequirement = null;
private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
{
ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description);
((OwnConfigEntryBase)configSync.AddConfigEntry<T>(val)).SynchronizedConfig = synchronizedSetting;
return val;
}
private ConfigEntry<T> config<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
}
public void Awake()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Expected O, but got Unknown
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only.");
configSync.AddLockingConfigEntry<Toggle>(serverConfigLocked);
maximumSupportFactor = config("2 - Building", "Maximum Support Factor", 1.5f, new ConfigDescription("Maximum support factor for building pieces at skill level 100.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
supportLossFactor = config("2 - Building", "Support Loss Factor", 0.75f, new ConfigDescription("Support loss factor for vertical and horizontal building at skill level 100.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 1f), Array.Empty<object>()));
healthFactor = config("2 - Building", "Health Factor", 3f, new ConfigDescription("Health factor for building pieces at skill level 100.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
freeBuildLevelRequirement = config("2 - Building", "Free Build Level Requirement", 50, new ConfigDescription("Minimum required skill level to be able to receive free building pieces. 0 is disabled.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
Assembly executingAssembly = Assembly.GetExecutingAssembly();
new Harmony("Jacobo.Architecting").PatchAll(executingAssembly);
}
}
}