Decompiled source of Info Loom v0.2.2

InfoLoom.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Colossal.Logging;
using Colossal.UI.Binding;
using Game;
using Game.Citizens;
using Game.Common;
using Game.Companies;
using Game.Economy;
using Game.Prefabs;
using Game.Simulation;
using Game.Tools;
using Game.UI;
using Game.UI.InGame;
using HarmonyLib;
using HookUILib.Core;
using Microsoft.CodeAnalysis;
using Unity.Burst;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using UnityEngine.Scripting;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("InfoLoom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Extra City information and demographics data (population, education and workforce structure).")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("InfoLoom")]
[assembly: AssemblyTitle("InfoLoom")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace InfoLoom
{
	[CompilerGenerated]
	public class BuildingDemandUISystem : UISystemBase
	{
		private SimulationSystem m_SimulationSystem;

		private ResidentialDemandSystem m_ResidentialDemandSystem;

		private CommercialDemandSystem m_CommercialDemandSystem;

		private IndustrialDemandSystem m_IndustrialDemandSystem;

		private RawValueBinding m_uiBuildingDemand;

		private NativeArray<int> m_BuildingDemand;

		[Preserve]
		protected override void OnCreate()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_006e: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			((UISystemBase)this).OnCreate();
			m_SimulationSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<SimulationSystem>();
			m_ResidentialDemandSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ResidentialDemandSystem>();
			m_CommercialDemandSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<CommercialDemandSystem>();
			m_IndustrialDemandSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<IndustrialDemandSystem>();
			RawValueBinding val = new RawValueBinding("cityInfo", "ilBuildingDemand", (Action<IJsonWriter>)delegate(IJsonWriter binder)
			{
				JsonWriterExtensions.ArrayBegin(binder, m_BuildingDemand.Length);
				for (int i = 0; i < m_BuildingDemand.Length; i++)
				{
					binder.Write(m_BuildingDemand[i]);
				}
				binder.ArrayEnd();
			});
			RawValueBinding val2 = val;
			m_uiBuildingDemand = val;
			((UISystemBase)this).AddBinding((IBinding)(object)val2);
			m_BuildingDemand = new NativeArray<int>(7, (Allocator)4, (NativeArrayOptions)1);
		}

		protected override void OnUpdate()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (m_SimulationSystem.frameIndex % 128 == 77)
			{
				((UISystemBase)this).OnUpdate();
				m_BuildingDemand[0] = m_ResidentialDemandSystem.buildingDemand.z;
				m_BuildingDemand[1] = m_ResidentialDemandSystem.buildingDemand.y;
				m_BuildingDemand[2] = m_ResidentialDemandSystem.buildingDemand.x;
				m_BuildingDemand[3] = m_CommercialDemandSystem.buildingDemand;
				m_BuildingDemand[4] = m_IndustrialDemandSystem.industrialBuildingDemand;
				m_BuildingDemand[5] = m_IndustrialDemandSystem.storageBuildingDemand;
				m_BuildingDemand[6] = m_IndustrialDemandSystem.officeBuildingDemand;
				m_uiBuildingDemand.Update();
			}
		}

		[Preserve]
		protected override void OnDestroy()
		{
			m_BuildingDemand.Dispose();
			((UISystemBase)this).OnDestroy();
		}
	}
	public static class Patcher
	{
		private const string HarmonyId = "InfoLoom_Cities2Harmony";

		private static bool patched = false;

		private static Dictionary<string, MethodBase> myPatches = new Dictionary<string, MethodBase>();

		public static void PatchAll()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (patched)
			{
				Plugin.Log("WARNING: Not patched!");
				return;
			}
			Harmony val = new Harmony("InfoLoom_Cities2Harmony");
			val.PatchAll();
			if (Harmony.HasAnyPatches("InfoLoom_Cities2Harmony"))
			{
				Plugin.Log("OK methods patched");
				patched = true;
				{
					foreach (MethodBase patchedMethod in val.GetPatchedMethods())
					{
						Plugin.Log($"...method {patchedMethod.DeclaringType}.{patchedMethod.Name}");
						myPatches[patchedMethod.DeclaringType?.ToString() + "." + patchedMethod.Name] = patchedMethod;
					}
					return;
				}
			}
			Plugin.Log("ERROR methods not patched.");
		}

		private static void RemoveConflictingPatches(MethodBase original, params string[] mods)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("InfoLoom_Cities2Harmony");
			Patches patchInfo = Harmony.GetPatchInfo(original);
			foreach (Patch transpiler in patchInfo.Transpilers)
			{
				if (transpiler.owner != "InfoLoom_Cities2Harmony")
				{
					Plugin.Log("REMOVING " + transpiler.PatchMethod.Name + " from " + transpiler.owner);
					val.Unpatch(original, (HarmonyPatchType)3, transpiler.owner);
				}
			}
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (prefix.owner != "InfoLoom_Cities2Harmony")
				{
					Plugin.Log("REMOVING " + prefix.PatchMethod.Name + " from " + prefix.owner);
					val.Unpatch(original, (HarmonyPatchType)1, prefix.owner);
				}
			}
		}

		private static void RemovePostfixPatch(MethodBase original, string plugin)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("InfoLoom_Cities2Harmony");
			foreach (Patch postfix in Harmony.GetPatchInfo(original).Postfixes)
			{
				if (postfix.owner != "InfoLoom_Cities2Harmony" && postfix.owner == plugin)
				{
					Plugin.Log("REMOVING " + postfix.PatchMethod.Name + " from " + postfix.owner);
					val.Unpatch(original, (HarmonyPatchType)2, postfix.owner);
				}
			}
		}

		public static void RemoveConflictingPatches()
		{
			RemoveConflictingPatches(myPatches["OutsideConnectionAI.StartConnectionTransferImpl"]);
			RemoveConflictingPatches(myPatches["Citizen.GetAgeGroup"]);
			RemoveConflictingPatches(myPatches["Citizen.GetAgePhase"]);
			RemovePostfixPatch(myPatches["Citizen.GetCitizenHomeBehaviour"], "com.github.algernon-A.csl.lifecyclerebalancerevisited");
			RemoveConflictingPatches(myPatches["HumanAI.FindVisitPlace"]);
			RemoveConflictingPatches(myPatches["ResidentAI.CanMakeBabies"]);
			RemoveConflictingPatches(myPatches["ResidentAI.UpdateAge"]);
			RemoveConflictingPatches(myPatches["ResidentAI.UpdateWorkplace"]);
		}

		public static void ListAllPatches()
		{
			foreach (MethodBase allPatchedMethod in Harmony.GetAllPatchedMethods())
			{
				bool flag = myPatches.ContainsKey(allPatchedMethod.DeclaringType?.ToString() + "." + allPatchedMethod.Name);
				Plugin.Log($"Method: {allPatchedMethod.DeclaringType}.{allPatchedMethod.Name}");
				Patches patchInfo = Harmony.GetPatchInfo(allPatchedMethod);
				foreach (Patch transpiler in patchInfo.Transpilers)
				{
					Plugin.Log($"  Transpiler {transpiler.index}: {transpiler.owner} {transpiler.PatchMethod.DeclaringType}.{transpiler.PatchMethod.Name}" + ((flag && transpiler.owner != "InfoLoom_Cities2Harmony") ? " potential CONFLICT" : ""));
				}
				foreach (Patch postfix in patchInfo.Postfixes)
				{
					Plugin.Log($"  Postfix {postfix.index}: {postfix.owner} {postfix.PatchMethod.DeclaringType}.{postfix.PatchMethod.Name}" + ((flag && postfix.owner != "InfoLoom_Cities2Harmony") ? " could be safe, but check for CONFLICT" : ""));
				}
				foreach (Patch prefix in patchInfo.Prefixes)
				{
					Plugin.Log($"  Prefix {prefix.index}: {prefix.owner} {prefix.PatchMethod.DeclaringType}.{prefix.PatchMethod.Name}" + ((flag && prefix.owner != "InfoLoom_Cities2Harmony") ? " potential CONFLICT" : ""));
				}
			}
		}

		public static void UnpatchAll()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!patched)
			{
				Plugin.Log("WARNING: Not patched!");
				return;
			}
			new Harmony("InfoLoom_Cities2Harmony").UnpatchSelf();
			Plugin.Log("OK methods unpatched.");
			patched = false;
		}
	}
	[HarmonyPatch]
	internal static class GamePatches
	{
		[HarmonyPatch(typeof(SystemOrder), "Initialize")]
		[HarmonyPostfix]
		public static void Initialize_Postfix(UpdateSystem updateSystem)
		{
			updateSystem.UpdateAt<BuildingDemandUISystem>((SystemUpdatePhase)22);
			updateSystem.UpdateAt<PopulationStructureUISystem>((SystemUpdatePhase)22);
		}

		[HarmonyPatch(typeof(CityInfoUISystem), "WriteDemandFactors")]
		[HarmonyPrefix]
		public static bool WriteDemandFactors_Prefix(CityInfoUISystem __instance, IJsonWriter writer, NativeArray<int> factors, JobHandle deps)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			((JobHandle)(ref deps)).Complete();
			NativeList<FactorInfo> val = FactorInfo.FromFactorArray(factors, (Allocator)2);
			NativeSortExtension.Sort<FactorInfo>(val);
			try
			{
				int length = val.Length;
				JsonWriterExtensions.ArrayBegin(writer, length);
				for (int i = 0; i < length; i++)
				{
					FactorInfo val2 = val[i];
					((FactorInfo)(ref val2)).WriteDemandFactor(writer);
				}
				writer.ArrayEnd();
			}
			finally
			{
				val.Dispose();
			}
			return false;
		}

		[HarmonyPatch(typeof(ProductionUISystem), "GetData")]
		[HarmonyPrefix]
		private static bool GetData(ref (int, int, int) __result, ProductionUISystem __instance, Entity entity, PrefabSystem ___m_PrefabSystem, NativeList<int> ___m_ProductionCache, NativeList<int> ___m_CommercialConsumptionCache, NativeList<int> ___m_IndustrialConsumptionCache)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			int resourceIndex = EconomyUtils.GetResourceIndex(EconomyUtils.GetResource(___m_PrefabSystem.GetPrefab<ResourcePrefab>(entity).m_Resource));
			__result = (___m_ProductionCache[resourceIndex], ___m_CommercialConsumptionCache[resourceIndex], ___m_IndustrialConsumptionCache[resourceIndex]);
			return false;
		}
	}
	[BepInPlugin("InfoLoom", "InfoLoom", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string HarmonyId = "InfoLoom_Cities2Harmony";

		internal static ManualLogSource Logger;

		private static ILog s_Log;

		public static ConfigEntry<bool> SeparateConsumption;

		public static void Log(string text, bool bMethod = false)
		{
			if (bMethod)
			{
				text = GetCallingMethod(2) + ": " + text;
			}
			Logger.LogInfo((object)text);
			s_Log.Info((object)text);
		}

		public static void LogStack(string text)
		{
			Logger.LogInfo((object)(text + " STACKTRACE"));
			s_Log.logStackTrace = true;
			s_Log.Info((object)(text + "STACKTRACE"));
			s_Log.logStackTrace = false;
		}

		public static string GetCallingMethod(int frame)
		{
			MethodBase method = new StackTrace().GetFrame(frame).GetMethod();
			return method.DeclaringType?.ToString() + "." + method.Name;
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			s_Log = LogManager.GetLogger("InfoLoom", true);
			Logger.LogInfo((object)"Plugin InfoLoom is loaded!");
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "InfoLoom_Cities2Harmony");
			MethodBase[] array = val.GetPatchedMethods().ToArray();
			Logger.LogInfo((object)("Plugin InfoLoom made patches! Patched methods: " + array.Length));
			MethodBase[] array2 = array;
			foreach (MethodBase methodBase in array2)
			{
				Logger.LogInfo((object)("Patched method: " + methodBase.Module.Name + ":" + methodBase.Name));
			}
			SeparateConsumption = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "SeparateConsumption", false, "Enables showing commercial and industrial consumption instead of surplus/deficit in the Production UI");
			if (!SeparateConsumption.Value)
			{
				MethodBase method = typeof(ProductionUISystem).GetMethod("GetData", BindingFlags.Instance | BindingFlags.NonPublic);
				if (method != null)
				{
					Log("REMOVING " + method.Name + " patch from InfoLoom_Cities2Harmony");
					val.Unpatch(method, (HarmonyPatchType)1, "InfoLoom_Cities2Harmony");
				}
				else
				{
					Log("WARNING: Cannot remove GetData patch.");
				}
			}
		}
	}
	public class InfoLoom_DemandFactors : UIExtension
	{
		public readonly string extensionID = "infoloom.demandfactors";

		public readonly string extensionContent;

		public readonly ExtensionType extensionType;

		public InfoLoom_DemandFactors()
		{
			extensionContent = ((UIExtension)this).LoadEmbeddedResource("InfoLoom.dist.demandfactors.js");
		}
	}
	[CompilerGenerated]
	public class PopulationStructureUISystem : UISystemBase
	{
		private struct PopulationAtAgeInfo
		{
			public int Age;

			public int Total;

			public int School1;

			public int School2;

			public int School3;

			public int School4;

			public int Work;

			public int Other;

			public PopulationAtAgeInfo(int _age)
			{
				Total = 0;
				School1 = 0;
				School2 = 0;
				School3 = 0;
				School4 = 0;
				Work = 0;
				Other = 0;
				Age = _age;
			}
		}

		[BurstCompile]
		private struct PopulationStructureJob : IJobChunk
		{
			[ReadOnly]
			public EntityTypeHandle m_EntityType;

			[ReadOnly]
			public ComponentTypeHandle<Citizen> m_CitizenType;

			[ReadOnly]
			public ComponentTypeHandle<Student> m_StudentType;

			[ReadOnly]
			public ComponentTypeHandle<Worker> m_WorkerType;

			[ReadOnly]
			public BufferTypeHandle<HouseholdCitizen> m_HouseholdCitizenHandle;

			[ReadOnly]
			public ComponentTypeHandle<Household> m_HouseholdType;

			[ReadOnly]
			public ComponentLookup<Worker> m_WorkerFromEntity;

			[ReadOnly]
			public ComponentLookup<HealthProblem> m_HealthProblems;

			[ReadOnly]
			public ComponentLookup<Citizen> m_Citizens;

			[ReadOnly]
			public ComponentLookup<Student> m_Students;

			public TimeData m_TimeData;

			public uint m_SimulationFrame;

			public NativeArray<int> m_Totals;

			public NativeArray<PopulationAtAgeInfo> m_Results;

			public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Invalid comparison between Unknown and I4
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Invalid comparison between Unknown and I4
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_0213: Unknown result type (might be due to invalid IL or missing references)
				NativeArray<Entity> nativeArray = ((ArchetypeChunk)(ref chunk)).GetNativeArray(m_EntityType);
				NativeArray<Citizen> nativeArray2 = ((ArchetypeChunk)(ref chunk)).GetNativeArray<Citizen>(ref m_CitizenType);
				NativeArray<Student> nativeArray3 = ((ArchetypeChunk)(ref chunk)).GetNativeArray<Student>(ref m_StudentType);
				((ArchetypeChunk)(ref chunk)).GetNativeArray<Worker>(ref m_WorkerType);
				bool flag = ((ArchetypeChunk)(ref chunk)).Has<Student>(ref m_StudentType);
				bool flag2 = ((ArchetypeChunk)(ref chunk)).Has<Worker>(ref m_WorkerType);
				int day = TimeSystem.GetDay(m_SimulationFrame, m_TimeData);
				if (!((ArchetypeChunk)(ref chunk)).Has<Citizen>(ref m_CitizenType))
				{
					Plugin.Log("NOCITIZENS in the chunk");
					return;
				}
				for (int i = 0; i < nativeArray.Length; i++)
				{
					_ = nativeArray[i];
					Citizen val = nativeArray2[i];
					bool flag3 = (val.m_State & 0x400) > 0;
					bool num = (val.m_State & 0x400) > 0;
					ref NativeArray<int> totals = ref m_Totals;
					int num2 = totals[0];
					totals[0] = num2 + 1;
					if (num)
					{
						ref NativeArray<int> totals2 = ref m_Totals;
						num2 = totals2[2];
						totals2[2] = num2 + 1;
					}
					else if (flag3)
					{
						ref NativeArray<int> totals3 = ref m_Totals;
						num2 = totals3[3];
						totals3[3] = num2 + 1;
					}
					else
					{
						ref NativeArray<int> totals4 = ref m_Totals;
						num2 = totals4[1];
						totals4[1] = num2 + 1;
					}
					if (num || flag3)
					{
						continue;
					}
					int num3 = day - val.m_BirthDay;
					if (num3 > m_Totals[6])
					{
						m_Totals[6] = num3;
					}
					num3 /= 10;
					PopulationAtAgeInfo populationAtAgeInfo = m_Results[num3];
					populationAtAgeInfo.Total++;
					if (flag)
					{
						ref NativeArray<int> totals5 = ref m_Totals;
						num2 = totals5[4];
						totals5[4] = num2 + 1;
						_ = nativeArray3[i];
						switch (nativeArray3[i].m_Level)
						{
						case 1:
							populationAtAgeInfo.School1++;
							break;
						case 2:
							populationAtAgeInfo.School2++;
							break;
						case 3:
							populationAtAgeInfo.School3++;
							break;
						case 4:
							populationAtAgeInfo.School4++;
							break;
						default:
							Plugin.Log($"WARNING: incorrect school level, {nativeArray3[i].m_Level}");
							break;
						}
					}
					if (flag2)
					{
						ref NativeArray<int> totals6 = ref m_Totals;
						num2 = totals6[5];
						totals6[5] = num2 + 1;
						populationAtAgeInfo.Work++;
					}
					if (!flag && !flag2)
					{
						populationAtAgeInfo.Other++;
					}
					m_Results[num3] = populationAtAgeInfo;
				}
			}

			public void Execute_Households(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: 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_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Expected I4, but got Unknown
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				BufferAccessor<HouseholdCitizen> bufferAccessor = ((ArchetypeChunk)(ref chunk)).GetBufferAccessor<HouseholdCitizen>(ref m_HouseholdCitizenHandle);
				NativeArray<Household> nativeArray = ((ArchetypeChunk)(ref chunk)).GetNativeArray<Household>(ref m_HouseholdType);
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				int num5 = 0;
				int num6 = 0;
				for (int i = 0; i < bufferAccessor.Length; i++)
				{
					DynamicBuffer<HouseholdCitizen> val = bufferAccessor[i];
					if ((nativeArray[i].m_Flags & 4) == 0)
					{
						continue;
					}
					for (int j = 0; j < val.Length; j++)
					{
						Entity citizen = val[j].m_Citizen;
						Citizen val2 = m_Citizens[citizen];
						if ((m_HealthProblems.HasComponent(citizen) && CitizenUtils.IsDead(m_HealthProblems[citizen])) || (val2.m_State & 0x600) != 0)
						{
							continue;
						}
						CitizenAge age = ((Citizen)(ref val2)).GetAge();
						switch ((int)age)
						{
						case 0:
							num++;
							break;
						case 1:
							num2++;
							if (m_Students.HasComponent(citizen))
							{
								num6++;
							}
							break;
						case 2:
							num3++;
							if (m_Students.HasComponent(citizen))
							{
								num6++;
							}
							break;
						case 3:
							num4++;
							break;
						}
						if (m_WorkerFromEntity.HasComponent(citizen))
						{
							num5++;
						}
					}
				}
				PopulationAtAgeInfo populationAtAgeInfo = m_Results[0];
				populationAtAgeInfo.School1 = num;
				populationAtAgeInfo.School2 = num2;
				populationAtAgeInfo.School3 = num3;
				populationAtAgeInfo.School4 = num4;
				m_Results[0] = populationAtAgeInfo;
			}

			void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				Execute(in chunk, unfilteredChunkIndex, useEnabledMask, in chunkEnabledMask);
			}
		}

		private struct TypeHandle
		{
			[ReadOnly]
			public EntityTypeHandle __Unity_Entities_Entity_TypeHandle;

			[ReadOnly]
			public ComponentTypeHandle<Citizen> __Game_Citizens_Citizen_RO_ComponentTypeHandle;

			[ReadOnly]
			public ComponentTypeHandle<Student> __Game_Citizens_Student_RO_ComponentTypeHandle;

			[ReadOnly]
			public ComponentTypeHandle<Worker> __Game_Citizens_Worker_RO_ComponentTypeHandle;

			public BufferTypeHandle<HouseholdCitizen> __Game_Citizens_HouseholdCitizen_RW_BufferTypeHandle;

			public ComponentTypeHandle<Household> __Game_Citizens_Household_RW_ComponentTypeHandle;

			[ReadOnly]
			public ComponentLookup<Worker> __Game_Citizens_Worker_RO_ComponentLookup;

			[ReadOnly]
			public ComponentLookup<Citizen> __Game_Citizens_Citizen_RO_ComponentLookup;

			[ReadOnly]
			public ComponentLookup<HealthProblem> __Game_Citizens_HealthProblem_RO_ComponentLookup;

			[ReadOnly]
			public ComponentLookup<Student> __Game_Citizens_Student_RO_ComponentLookup;

			[ReadOnly]
			public ComponentTypeHandle<WorkProvider> __Game_Companies_WorkProvider_RO_ComponentTypeHandle;

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public void __AssignHandles(ref SystemState state)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				__Unity_Entities_Entity_TypeHandle = ((SystemState)(ref state)).GetEntityTypeHandle();
				__Game_Citizens_Citizen_RO_ComponentTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<Citizen>(true);
				__Game_Citizens_Student_RO_ComponentTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<Student>(true);
				__Game_Citizens_Worker_RO_ComponentTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<Worker>(true);
				__Game_Citizens_HouseholdCitizen_RW_BufferTypeHandle = ((SystemState)(ref state)).GetBufferTypeHandle<HouseholdCitizen>(false);
				__Game_Citizens_Household_RW_ComponentTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<Household>(false);
				__Game_Citizens_Worker_RO_ComponentLookup = ((SystemState)(ref state)).GetComponentLookup<Worker>(true);
				__Game_Citizens_Citizen_RO_ComponentLookup = ((SystemState)(ref state)).GetComponentLookup<Citizen>(true);
				__Game_Citizens_HealthProblem_RO_ComponentLookup = ((SystemState)(ref state)).GetComponentLookup<HealthProblem>(true);
				__Game_Citizens_Student_RO_ComponentLookup = ((SystemState)(ref state)).GetComponentLookup<Student>(true);
				__Game_Companies_WorkProvider_RO_ComponentTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<WorkProvider>(true);
			}
		}

		private const string kGroup = "populationInfo";

		private CitySystem m_CitySystem;

		private SimulationSystem m_SimulationSystem;

		private RawValueBinding m_uiTotals;

		private RawValueBinding m_uiResults;

		private EntityQuery m_TimeDataQuery;

		private EntityQuery m_CitizenQuery;

		private NativeArray<int> m_Totals;

		private NativeArray<PopulationAtAgeInfo> m_Results;

		private TypeHandle __TypeHandle;

		private static bool dumped;

		private static void WriteData(IJsonWriter writer, PopulationAtAgeInfo info)
		{
			writer.TypeBegin("populationAtAgeInfo");
			writer.PropertyName("age");
			writer.Write(info.Age);
			writer.PropertyName("total");
			writer.Write(info.Total);
			writer.PropertyName("school1");
			writer.Write(info.School1);
			writer.PropertyName("school2");
			writer.Write(info.School2);
			writer.PropertyName("school3");
			writer.Write(info.School3);
			writer.PropertyName("school4");
			writer.Write(info.School4);
			writer.PropertyName("work");
			writer.Write(info.Work);
			writer.PropertyName("other");
			writer.Write(info.Other);
			writer.TypeEnd();
		}

		[Preserve]
		protected override void OnCreate()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//IL_00ce: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_00f8: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			((UISystemBase)this).OnCreate();
			m_CitySystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<CitySystem>();
			m_SimulationSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<SimulationSystem>();
			m_TimeDataQuery = ((ComponentSystemBase)this).GetEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<TimeData>() });
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<Citizen>() };
			val.None = (ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadOnly<Deleted>(),
				ComponentType.ReadOnly<Temp>()
			};
			array[0] = val;
			m_CitizenQuery = ((ComponentSystemBase)this).GetEntityQuery((EntityQueryDesc[])(object)array);
			((ComponentSystemBase)this).RequireForUpdate(m_CitizenQuery);
			RawValueBinding val2 = new RawValueBinding("populationInfo", "structureTotals", (Action<IJsonWriter>)delegate(IJsonWriter binder)
			{
				JsonWriterExtensions.ArrayBegin(binder, m_Totals.Length);
				for (int j = 0; j < m_Totals.Length; j++)
				{
					binder.Write(m_Totals[j]);
				}
				binder.ArrayEnd();
			});
			RawValueBinding val3 = val2;
			m_uiTotals = val2;
			((UISystemBase)this).AddBinding((IBinding)(object)val3);
			RawValueBinding val4 = new RawValueBinding("populationInfo", "structureDetails", (Action<IJsonWriter>)delegate(IJsonWriter binder)
			{
				JsonWriterExtensions.ArrayBegin(binder, m_Results.Length);
				for (int i = 0; i < m_Results.Length; i++)
				{
					WriteData(binder, m_Results[i]);
				}
				binder.ArrayEnd();
			});
			val3 = val4;
			m_uiResults = val4;
			((UISystemBase)this).AddBinding((IBinding)(object)val3);
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<int>("populationInfo", "oldest_citizen", (Func<int>)(() => m_Totals[6]), (IWriter<int>)null, (EqualityComparer<int>)null));
			m_Totals = new NativeArray<int>(7, (Allocator)4, (NativeArrayOptions)1);
			m_Results = new NativeArray<PopulationAtAgeInfo>(20, (Allocator)4, (NativeArrayOptions)1);
			Plugin.Log("ProductionStructureUISystem created.");
		}

		[Preserve]
		protected override void OnDestroy()
		{
			m_Totals.Dispose();
			m_Results.Dispose();
			((UISystemBase)this).OnDestroy();
		}

		protected override void OnUpdate()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			if (m_SimulationSystem.frameIndex % 128 == 77)
			{
				((UISystemBase)this).OnUpdate();
				ResetResults();
				((EntityTypeHandle)(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle)).Update(ref ((SystemBase)this).CheckedStateRef);
				__TypeHandle.__Game_Citizens_Citizen_RO_ComponentTypeHandle.Update(ref ((SystemBase)this).CheckedStateRef);
				__TypeHandle.__Game_Citizens_Student_RO_ComponentTypeHandle.Update(ref ((SystemBase)this).CheckedStateRef);
				__TypeHandle.__Game_Citizens_Worker_RO_ComponentTypeHandle.Update(ref ((SystemBase)this).CheckedStateRef);
				PopulationStructureJob populationStructureJob = default(PopulationStructureJob);
				populationStructureJob.m_EntityType = __TypeHandle.__Unity_Entities_Entity_TypeHandle;
				populationStructureJob.m_CitizenType = __TypeHandle.__Game_Citizens_Citizen_RO_ComponentTypeHandle;
				populationStructureJob.m_StudentType = __TypeHandle.__Game_Citizens_Student_RO_ComponentTypeHandle;
				populationStructureJob.m_WorkerType = __TypeHandle.__Game_Citizens_Worker_RO_ComponentTypeHandle;
				populationStructureJob.m_SimulationFrame = m_SimulationSystem.frameIndex;
				populationStructureJob.m_TimeData = ((EntityQuery)(ref m_TimeDataQuery)).GetSingleton<TimeData>();
				populationStructureJob.m_Totals = m_Totals;
				populationStructureJob.m_Results = m_Results;
				JobHandle val = JobChunkExtensions.Schedule<PopulationStructureJob>(populationStructureJob, m_CitizenQuery, ((SystemBase)this).Dependency);
				((JobHandle)(ref val)).Complete();
				m_uiTotals.Update();
				m_uiResults.Update();
			}
		}

		private void ResetResults()
		{
			for (int i = 0; i < m_Totals.Length; i++)
			{
				m_Totals[i] = 0;
			}
			for (int j = 0; j < m_Results.Length; j++)
			{
				m_Results[j] = new PopulationAtAgeInfo(j);
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private void __AssignQueries(ref SystemState state)
		{
		}

		protected override void OnCreateForCompiler()
		{
			((ComponentSystemBase)this).OnCreateForCompiler();
			__AssignQueries(ref ((SystemBase)this).CheckedStateRef);
			__TypeHandle.__AssignHandles(ref ((SystemBase)this).CheckedStateRef);
		}

		[Preserve]
		public PopulationStructureUISystem()
		{
		}

		public static void LogChunk(in ArchetypeChunk chunk)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			EntityArchetype archetype = ((ArchetypeChunk)(ref chunk)).Archetype;
			NativeArray<ComponentType> componentTypes = ((EntityArchetype)(ref archetype)).GetComponentTypes((Allocator)2);
			Plugin.Log(string.Format("chunk: {0}, {1}", ((ArchetypeChunk)(ref chunk)).Count, string.Join(", ", ((IEnumerable<ComponentType>)(object)componentTypes).Select((ComponentType ct) => ((object)ct).GetType().GetTypeInfo().FullName))));
		}

		public string[] ListEntityComponents(Entity entity)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_002d: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			new List<ComponentType>();
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			if (!((EntityManager)(ref entityManager)).Exists(entity))
			{
				throw new ArgumentException("Entity does not exist.");
			}
			entityManager = ((ComponentSystemBase)this).EntityManager;
			NativeArray<ComponentType> componentTypes = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2);
			string[] result = ((IEnumerable<ComponentType>)(object)componentTypes).Select((ComponentType T) => ((ComponentType)(ref T)).GetManagedType().Name).ToArray();
			componentTypes.Dispose();
			return result;
		}

		public void InspectComponentsInQuery(EntityQuery query)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			NativeArray<Entity> val = ((EntityQuery)(ref m_CitizenQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			for (int i = 0; i < val.Length; i++)
			{
				Entity entity = val[i];
				string[] array = ListEntityComponents(entity);
				foreach (string key in array)
				{
					if (dictionary.ContainsKey(key))
					{
						dictionary[key]++;
					}
					else
					{
						dictionary.Add(key, 1);
					}
				}
			}
			val.Dispose();
			Plugin.Log("=== Components in selected chunks ===");
			foreach (KeyValuePair<string, int> item in dictionary)
			{
				Plugin.Log($"{item.Key} {item.Value}");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "InfoLoom";

		public const string PLUGIN_NAME = "InfoLoom";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}