Decompiled source of WellLogistics v1.0.0

BepInEx\plugins\WellLogistics\WellLogistics.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using CandideServer;
using CandideServer.Buildings.BuildingControllers;
using CandideServer.Data.DataModels;
using CandideServer.Database;
using CandideServer.MessageModels.InternalResourceStorage;
using CandideServer.Models;
using CandideServer.Models.Citizen;
using CandideServer.ServerControllers;
using CandideServer.ServerManagers;
using CandideServer.ServerServices;
using CandideServer.SimulationModels;
using HarmonyLib;
using Shared.Data;
using Shared.Models.Buildings;
using Shared.Text;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("WellLogistics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WellLogistics")]
[assembly: AssemblyTitle("WellLogistics")]
[assembly: RequiresPreviewFeatures]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace WellLogistics;

[HarmonyPatch(typeof(BuildingTypeDataBase), "AddBuildingTypes")]
internal static class Patch_AddBuildingTypes
{
	private static void Postfix()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		if (!BuildingTypeDataBase.DataMap.ContainsKey("well"))
		{
			BuildingTypeDataBase.DataMap["well"] = new BuildingTypeData
			{
				Id = "well",
				Name = StringId.op_Implicit("Well"),
				CreateController = (BuildingSimulationModel b) => (AbstractBuildingController)(object)new WellBuildingController(b)
			};
		}
		if (BuildingDataBase.BuildingDataMap.TryGetValue("building:well:0", out var value))
		{
			value.Output = BuildingLogisticsConfig.ResourceProducingDefaultOutput;
		}
	}
}
[HarmonyPatch(typeof(BuildingsSController), "AfterWorldGameStateLoaded")]
internal static class Patch_AfterWorldGameStateLoaded
{
	private static void Prefix()
	{
		foreach (BuildingSimulationModel value in ServerGameState.Buildings.Values)
		{
			if (!(value.InstanceModel.BuildingTypeId != "well") && !(value.Controller is WellBuildingController))
			{
				value.SetupController();
			}
		}
	}
}
[BepInPlugin("local.romestead.well-logistics", "Well Logistics", "1.0.0")]
public class Plugin : BasePlugin
{
	public const string PluginGuid = "local.romestead.well-logistics";

	public const string PluginName = "Well Logistics";

	public const string PluginVersion = "1.0.0";

	public static ManualLogSource Logger;

	private Harmony _harmony;

	public override void Load()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		Logger = ((BasePlugin)this).Log;
		_harmony = new Harmony("local.romestead.well-logistics");
		_harmony.PatchAll();
		ManualLogSource logger = Logger;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Well Logistics");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
		}
		logger.LogInfo(val);
	}

	public override bool Unload()
	{
		_harmony.UnpatchSelf();
		return true;
	}
}
public class WellBuildingController : AbstractBuildingController
{
	public const string WaterResourceId = "resource:water";

	public const int MaxWaterStorage = 10;

	private const float ProductionInterval = 10f;

	private float _productionTimer;

	public WellBuildingController(BuildingSimulationModel building)
		: base(building, false)
	{
		base.JobTickRate = 10f;
	}

	public override void OnNewlyCreated()
	{
		CreateOutputStorage();
	}

	public override void OnLoaded()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (!base.Building.InstanceModel.Output.HasValue)
		{
			base.Building.InstanceModel.Output = BuildingLogisticsConfig.ResourceProducingDefaultOutput;
		}
		if (!base.Building.InstanceModel.OutputResourceStorageId.HasValue)
		{
			CreateOutputStorage();
		}
	}

	public override void Update(float dt)
	{
		_productionTimer += dt;
		if (!(_productionTimer < 10f))
		{
			_productionTimer -= 10f;
			TryProduceWater();
		}
	}

	public override CitizenPositionData GetSpawnPositionForCitizen(CitizenModel citizen, CitizenSlotModel slot)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return default(CitizenPositionData);
	}

	protected override void OnTickJob(CitizenModel citizen, JobModel job)
	{
	}

	private void CreateOutputStorage()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		BuildingsServerManager.CreateInternalResourceStorageForBuilding(base.Building.InstanceModel, new CreateNewInternalResourceStorageMessage
		{
			NewId = Guid.NewGuid(),
			ResourceAmounts = new Dictionary<string, int> { { "resource:water", 0 } },
			MaximumResourceAmounts = new Dictionary<string, int> { { "resource:water", 10 } }
		}, (IOStorageCreationType)1);
	}

	private void TryProduceWater()
	{
		InternalResourceStorageModel val = default(InternalResourceStorageModel);
		if (base.Building.InstanceModel.OutputResourceStorageId.HasValue && ServerGameState.TryGetInternalResourceStorage(base.Building.InstanceModel.OutputResourceStorageId.Value, ref val))
		{
			UpdateInternalResourceStorageChangedMessage val2 = InternalResourceStorageSController.TryAddToStorage(val, "resource:water", 1);
			if (val2 != null)
			{
				InternalResourceStorageServerService.Send_OneInternalResourceStorageChanged(val2);
			}
		}
	}
}