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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using Candide.ActionInProgress;
using Candide.GameModels;
using Candide.GameModels.Managers;
using Candide.GameModels.Models.Constructions;
using Candide.GameModels.Services;
using CandideServer.MessageModels.Constructions;
using CandideServer.ServerManagers;
using HarmonyLib;
using InstantConstruction.Features.Construction;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("InstantConstruction")]
[assembly: AssemblyDescription("Instant Construction for Romestead by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("InstantConstruction")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("D6FCA710-A361-4782-9A55-D7623153BB51")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace InstantConstruction
{
[BepInPlugin("IceBoxStudio.Romestead.InstantConstruction", "InstantConstruction", "1.0.1")]
public class InstantConstruction : BasePlugin
{
public static InstantConstruction _Instance;
private Harmony _harmony;
public static InstantConstruction Instance => _Instance;
internal static ManualLogSource Logger { get; private set; }
public override void Load()
{
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Expected O, but got Unknown
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
_Instance = this;
Logger = ((BasePlugin)this).Log;
bool flag = default(bool);
try
{
Logger.LogInfo((object)"=============================================");
ManualLogSource logger = Logger;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InstantConstruction");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initializing...");
}
logger.LogInfo(val);
ManualLogSource logger2 = Logger;
val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Author: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Ice Box Studio");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("https://steamcommunity.com/id/ibox666/");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
logger2.LogInfo(val);
_harmony = new Harmony("IceBoxStudio.Romestead.InstantConstruction");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
ManualLogSource logger3 = Logger;
val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InstantConstruction");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initialized.");
}
logger3.LogInfo(val);
Logger.LogInfo((object)"=============================================");
}
catch (Exception ex)
{
ManualLogSource logger4 = Logger;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(24, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("InstantConstruction");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" initialization error: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("\n");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
}
logger4.LogError(val2);
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "IceBoxStudio.Romestead.InstantConstruction";
public const string PLUGIN_NAME = "InstantConstruction";
public const string PLUGIN_VERSION = "1.0.1";
public const string PLUGIN_AUTHOR = "Ice Box Studio";
public const string PLUGIN_AUTHOR_URL = "https://steamcommunity.com/id/ibox666/";
}
}
namespace InstantConstruction.Patches.Construction
{
[HarmonyPatch(typeof(ConstructionSitesServerManager), "DoPlayerConstructActionInProgress")]
public static class ConstructionSitesServerManagerDoPlayerConstructActionInProgressPatch
{
[HarmonyPrefix]
public static void Prefix(ref float progress)
{
InstantConstructionController.CompleteProgress(ref progress);
}
}
[HarmonyPatch(typeof(StandardConstructActionInProgressController), "OnActionProgressDone")]
public static class StandardConstructActionInProgressControllerOnActionProgressDonePatch
{
[HarmonyPrefix]
public static bool Prefix(StandardConstructActionInProgressController __instance, bool critical)
{
return !InstantConstructionController.CompleteClientConstructionProgress(__instance, critical);
}
}
[HarmonyPatch(typeof(StandardConstructActionInProgressController), "OnActionStart")]
public static class StandardConstructActionInProgressControllerOnActionStartPatch
{
[HarmonyPostfix]
public static void Postfix(StandardConstructActionInProgressController __instance)
{
InstantConstructionController.CompleteConstructionAfterActionStart(__instance);
}
}
}
namespace InstantConstruction.Features.Construction
{
public static class InstantConstructionController
{
public const float CompletionProgress = 1000000f;
private static readonly FieldRef<StandardConstructActionInProgressController, ConstructionSite> ConstructionSiteRef = AccessTools.FieldRefAccess<StandardConstructActionInProgressController, ConstructionSite>("_constructionSite");
private static readonly HashSet<Guid> ExperienceAwardedConstructionSites = new HashSet<Guid>();
public static void CompleteConstructionAfterActionStart(StandardConstructActionInProgressController controller)
{
ConstructionSite constructionSite = GetConstructionSite(controller);
if (constructionSite != null)
{
TryAddConstructionExperience(controller, constructionSite);
SendCompletionProgress(constructionSite);
controller.CurrentProgress = Math.Max(controller.CurrentProgress, GetCompletionProgress(constructionSite));
}
}
public static bool CompleteClientConstructionProgress(StandardConstructActionInProgressController controller, bool critical)
{
ConstructionSite constructionSite = GetConstructionSite(controller);
if (constructionSite == null)
{
return false;
}
TryAddConstructionExperience(controller, constructionSite);
SendCompletionProgress(constructionSite);
controller.CurrentProgress = Math.Max(controller.CurrentProgress, GetCompletionProgress(constructionSite));
return true;
}
public static void CompleteProgress(ref float progress)
{
if (progress < 1000000f)
{
progress = 1000000f;
}
}
private static ConstructionSite GetConstructionSite(StandardConstructActionInProgressController controller)
{
return ConstructionSiteRef.Invoke(controller);
}
private static void TryAddConstructionExperience(StandardConstructActionInProgressController controller, ConstructionSite constructionSite)
{
if (controller.IsLocalPlayer && !(constructionSite.Id == Guid.Empty))
{
float constructionExperience = GetConstructionExperience(controller, constructionSite);
if (!(constructionExperience <= 0f) && ExperienceAwardedConstructionSites.Add(constructionSite.Id))
{
SkillsManager.AddExperienceToSkillType(GameState.LocalPlayer.Character.Character, "skill:construction", constructionExperience);
}
}
}
private static void SendCompletionProgress(ConstructionSite constructionSite)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
if (!(constructionSite.Id == Guid.Empty))
{
ConstructionSitesService.Send_ConstructActionInProgressDoProgress(new ConstructActionInProgressDoProgressMessage
{
ConstructionSiteId = constructionSite.Id,
Progress = GetCompletionProgress(constructionSite)
});
}
}
private static float GetCompletionProgress(ConstructionSite constructionSite)
{
return Math.Max(1000000f, constructionSite.RequiredConstructionProgress);
}
private static float GetConstructionExperience(StandardConstructActionInProgressController controller, ConstructionSite constructionSite)
{
float num = Math.Max(controller.CurrentProgress, constructionSite.CurrentConstructionProgress);
return Math.Max(0f, constructionSite.RequiredConstructionProgress - num);
}
}
}