using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SoDEssentialShops")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1")]
[assembly: AssemblyProduct("SoDEssentialShops")]
[assembly: AssemblyTitle("SoDEssentialShops")]
[assembly: AssemblyVersion("0.2.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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;
}
}
[CompilerGenerated]
[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 SoDEssentialShops
{
[BepInPlugin("sm3gm.sod.essentialshops", "Essential Shops", "1.2.2")]
public sealed class Plugin : BasePlugin
{
public const string VER = "1.2.2";
internal static ManualLogSource L;
internal static ConfigEntry<string> Shops;
internal static ConfigEntry<int> MinimumPerCity;
internal static ConfigEntry<int> OneMorePerTiles;
internal static ConfigEntry<int> SpreadAddresses;
internal static ConfigEntry<int> MaxBlackMarkets;
internal static ConfigEntry<string> RequiredBuildings;
internal static ConfigEntry<string> OptionalInSmallCities;
internal static ConfigEntry<int> SmallCityTiles;
internal static ConfigEntry<string> SmallCityMustHave;
internal static ConfigEntry<bool> SwapIn;
internal static ConfigEntry<bool> AlwaysHotel;
internal static ConfigEntry<string> SwapOut;
public override void Load()
{
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0260: Expected O, but got Unknown
L = ((BasePlugin)this).Log;
Shops = ((BasePlugin)this).Config.Bind<string>("General", "ShopTypes", "SyncClinic,PawnShop,BlackmarketTrader:1,BlackmarketSyncClinic:1,WeaponsDealer:1", "Shop types every newly generated city gets. Internal names, comma separated. Name alone = the size-based number below; Name:count = exactly that many at least (one of each black market type is enough). Empty = off.");
MaxBlackMarkets = ((BasePlugin)this).Config.Bind<int>("General", "MaxBlackMarketsOfEachType", 1, "At most this many of each black market type (trader, black market Sync Clinic, weapons dealer) in a new city. The ones listed in ShopTypes are still always placed. 0 = no limit.");
if (Shops.Value == "SyncClinic,PawnShop,BlackmarketTrader:1")
{
Shops.Value = "SyncClinic,PawnShop,BlackmarketTrader:1,BlackmarketSyncClinic:1,WeaponsDealer:1";
((BasePlugin)this).Log.LogInfo((object)"ShopTypes updated to the 1.1.0 default (all three black market shops)");
}
MinimumPerCity = ((BasePlugin)this).Config.Bind<int>("General", "MinimumPerCity", 1, "Every new city gets at least this many of each listed shop type.");
OneMorePerTiles = ((BasePlugin)this).Config.Bind<int>("General", "OneMorePerTiles", 8, "One more of each shop type per this many city tiles (the largest vanilla city, 5x4, has 20 tiles, so 8 gives 1 + 2 = 3). Shops the game places by itself count too. 0 = only MinimumPerCity.");
SpreadAddresses = ((BasePlugin)this).Config.Bind<int>("General", "SpreadAddresses", 25, "After each shop, this many other addresses are filled before the next one is forced, so the shops spread out instead of lining up in one street. 0 = no spacing.");
RequiredBuildings = ((BasePlugin)this).Config.Bind<string>("Buildings", "RequiredInEveryCity", "", "Building types every new city must contain, as Name:count, comma separated (internal names are listed in the log when a city is generated). Without a building that has shop spaces, no shop can be placed at all.");
OptionalInSmallCities = ((BasePlugin)this).Config.Bind<string>("Buildings", "SmallCityLimits", "ChemicalPlant:0,BrandyNetherland:0,MixedIndustrial:0,Hotel:0,AmericanDiner:1", "Small cities have only a few building plots, and the game tends to fill the last one with a Chemical Plant or the Brandy Netherland, neither of which has shop spaces. In small cities these types get at most this many (Name:count, 0 = none). Everything else stays allowed, so every plot can still be filled. Empty = keep the game's rules.");
AlwaysHotel = ((BasePlugin)this).Config.Bind<bool>("Buildings", "AlwaysHotel", true, "Every new city gets a hotel, whatever its size (also when SmallCityLimits says Hotel:0). In a 2x2 city that means City Hall, a hotel, a diner and the office tower with the shops.");
SmallCityTiles = ((BasePlugin)this).Config.Bind<int>("Buildings", "SmallCityTiles", 4, "A city with this many tiles or fewer counts as small (a 2x2 city has 4 tiles, the same count as OneMorePerTiles).");
SmallCityMustHave = ((BasePlugin)this).Config.Bind<string>("Buildings", "SmallCityMustHave", "EdenTower,AmericanDiner", "Generation of a small city pauses right after the buildings are chosen (the way the city editor does) and the city is checked for these buildings. Empty = no check.");
SwapIn = ((BasePlugin)this).Config.Bind<bool>("Buildings", "SwapInEdenTower", false, "If a small city has no EdenTower (the commercial tower with offices and shop spaces), one of the buildings in SwapOut is replaced by it at that pause, the way the city editor changes a building type. Experimental, off by default: the building limits already give small cities an EdenTower.");
SwapOut = ((BasePlugin)this).Config.Bind<string>("Buildings", "SwapOut", "Townhouse,ShantyTown", "Buildings without shop spaces that may be replaced by the EdenTower in a small city.");
Spread.Bind(((BasePlugin)this).Config);
((BasePlugin)this).AddComponent<CityCheck>();
Harmony val = new Harmony("sm3gm.sod.essentialshops");
val.PatchAll(typeof(GeneratePatch));
val.PatchAll(typeof(LoadPatch));
val.PatchAll(typeof(StartPatch));
val.PatchAll(typeof(PlacedPatch));
val.PatchAll(typeof(VendingPickPatch));
val.PatchAll(typeof(VendingPlacedPatch));
ManualLogSource l = L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Essential Shops ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.2.2");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded");
}
l.LogInfo(val2);
}
}
internal static class Forcing
{
private sealed class Armed
{
internal AddressPreset Preset;
internal int Quota;
internal int Count;
internal int Pause;
internal bool Important;
internal bool ForcePick;
internal bool HardSize;
internal bool Waiting;
internal float MinLand;
internal float MaxLand;
internal int MaxInstances;
}
private static readonly Dictionary<string, Armed> armed = new Dictionary<string, Armed>();
private static readonly Dictionary<string, (AddressPreset preset, int max)> capped = new Dictionary<string, (AddressPreset, int)>();
internal static int Quota()
{
int num = CitySize.Tiles();
int value = Plugin.OneMorePerTiles.Value;
return Math.Max(1, Plugin.MinimumPerCity.Value) + ((value > 0) ? (num / value) : 0);
}
internal static void Arm()
{
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Expected O, but got Unknown
Disarm("a new city starts generating");
Dictionary<string, int> dictionary = new Dictionary<string, int>();
string[] array = (Plugin.Shops.Value ?? "").Split(',');
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split(':');
string text = array2[0].Trim();
if (text.Length != 0)
{
dictionary[text] = ((array2.Length > 1 && int.TryParse(array2[1], out var result)) ? result : 0);
}
}
Toolbox instance = Toolbox.Instance;
List<AddressPreset> val = ((instance != null) ? instance.allAddressPresets : null);
if (dictionary.Count == 0 || val == null)
{
return;
}
int num = Quota();
Buildings.Arm();
try
{
List<string> list = new List<string>();
for (int j = 0; j < val.Count; j++)
{
if ((SoCustomComparison)(object)val[j] != (SoCustomComparison)null && (SoCustomComparison)(object)val[j].company != (SoCustomComparison)null)
{
list.Add(((Object)val[j]).name);
}
}
Plugin.L.LogDebug((object)("Business types in the game: " + string.Join(", ", list.OrderBy((string n) => n))));
}
catch
{
}
for (int num2 = 0; num2 < val.Count; num2++)
{
AddressPreset val2 = val[num2];
if (!((SoCustomComparison)(object)val2 == (SoCustomComparison)null) && dictionary.ContainsKey(((Object)val2).name) && !armed.ContainsKey(((Object)val2).name))
{
int num3 = ((dictionary[((Object)val2).name] > 0) ? dictionary[((Object)val2).name] : num);
armed[((Object)val2).name] = new Armed
{
Preset = val2,
Quota = num3,
Important = val2.important,
ForcePick = val2.forcePick,
HardSize = val2.hardSizeLimits,
MinLand = val2.minimumLandValue,
MaxLand = val2.maximumLandValue,
MaxInstances = val2.maxInstances
};
val2.important = true;
val2.forcePick = true;
val2.hardSizeLimits = false;
val2.minimumLandValue = 0f;
val2.maximumLandValue = 1f;
if (val2.maxInstances < num3)
{
val2.maxInstances = num3;
}
}
}
CapBlackMarkets(val);
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(54, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("New city: making sure it gets ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(string.Join(", ", armed.Values.Select((Armed x) => x.Quota + " " + ((Object)x.Preset).name)));
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(armed.Count);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" of ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(dictionary.Count);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" shop types found)");
}
l.LogInfo(val3);
}
internal static bool IsBlackMarket(string n)
{
if (n.IndexOf("Blackmarket", StringComparison.OrdinalIgnoreCase) < 0)
{
return n == "WeaponsDealer";
}
return true;
}
private static void CapBlackMarkets(List<AddressPreset> all)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
int value = Plugin.MaxBlackMarkets.Value;
if (value <= 0)
{
return;
}
for (int i = 0; i < all.Count; i++)
{
AddressPreset val = all[i];
if (!((SoCustomComparison)(object)val == (SoCustomComparison)null) && !((SoCustomComparison)(object)val.company == (SoCustomComparison)null) && IsBlackMarket(((Object)val).name) && !capped.ContainsKey(((Object)val).name))
{
capped[((Object)val).name] = (val, val.maxInstances);
val.maxInstances = value;
if (armed.TryGetValue(((Object)val).name, out Armed value2) && value2.Quota > value)
{
value2.Quota = value;
}
}
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(36, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("At most ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(value);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" of each black market type: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(string.Join(", ", capped.Keys));
}
l.LogInfo(val2);
}
internal static void Placed(NewAddress address)
{
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
foreach (Armed value in armed.Values)
{
if (value.Pause > 0 && --value.Pause == 0 && !value.Waiting)
{
value.Preset.forcePick = true;
}
}
AddressPreset val = ((address != null) ? address.addressPreset : null);
if ((SoCustomComparison)(object)val == (SoCustomComparison)null || !armed.TryGetValue(((Object)val).name, out Armed st))
{
return;
}
st.Count++;
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(25, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Placed ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(st.Count);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" of ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(st.Quota);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" at ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)address).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (floor ");
BepInExInfoLogInterpolatedStringHandler obj = val2;
NewFloor floor = ((NewGameLocation)address).floor;
((BepInExLogInterpolatedStringHandler)obj).AppendFormatted<int?>((floor != null) ? new int?(floor.floor) : ((int?)null));
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
}
l.LogInfo(val2);
if (st.Count >= Minimum())
{
try
{
val.important = st.Important;
}
catch
{
}
}
if (st.Count >= st.Quota)
{
Restore(((Object)val).name);
}
else if (st.Count >= Minimum() && armed.Values.Any((Armed o) => o != st && o.Count < Minimum()))
{
val.forcePick = false;
st.Waiting = true;
st.Pause = 0;
ManualLogSource l2 = Plugin.L;
val2 = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" waits until every type has ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(Minimum());
}
l2.LogInfo(val2);
}
else if (Plugin.SpreadAddresses.Value > 0)
{
val.forcePick = false;
st.Pause = Plugin.SpreadAddresses.Value;
}
ReleaseWaiting();
}
private static int Minimum()
{
return Math.Max(1, Plugin.MinimumPerCity.Value);
}
private static void ReleaseWaiting()
{
if (armed.Values.Any((Armed o) => o.Count < Minimum()))
{
return;
}
foreach (Armed value in armed.Values)
{
if (value.Waiting)
{
value.Waiting = false;
value.Preset.forcePick = true;
}
}
}
internal static void Disarm(string why)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
Buildings.Restore();
bool flag = default(bool);
foreach (string item in Forcing.armed.Keys.ToList())
{
Armed armed = Forcing.armed[item];
ManualLogSource l = Plugin.L;
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(60, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Only ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(armed.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(armed.Quota);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" placed before ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(why);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; the game's own rules apply again.");
}
l.LogWarning(val);
Restore(item);
}
foreach (var value in capped.Values)
{
try
{
value.preset.maxInstances = value.max;
}
catch
{
}
}
capped.Clear();
}
private static void Restore(string name)
{
Armed armed = Forcing.armed[name];
Forcing.armed.Remove(name);
try
{
AddressPreset preset = armed.Preset;
preset.important = armed.Important;
preset.forcePick = armed.ForcePick;
preset.hardSizeLimits = armed.HardSize;
preset.minimumLandValue = armed.MinLand;
preset.maximumLandValue = armed.MaxLand;
if (!capped.ContainsKey(name))
{
preset.maxInstances = Math.Max(armed.MaxInstances, armed.Count);
}
}
catch
{
}
ReleaseWaiting();
}
}
internal static class CitySize
{
internal static int Tiles()
{
//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_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
int num = 0;
int num2 = 0;
try
{
Vector2 citySize = CityData.Instance.citySize;
num = (int)(Math.Max(0f, citySize.x - 2f) * Math.Max(0f, citySize.y - 2f));
}
catch
{
}
try
{
RestartSafeController instance = RestartSafeController.Instance;
if ((Object)(object)instance != (Object)null)
{
num2 = Math.Max(0, instance.cityX - 2) * Math.Max(0, instance.cityY - 2);
}
}
catch
{
}
int num3 = Math.Max(num, num2);
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(46, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("City size: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num3);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" playable tiles (city data ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", menu ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
l.LogInfo(val);
return num3;
}
}
[HarmonyPatch(typeof(CityConstructor), "GenerateNewCity")]
internal static class GeneratePatch
{
private static void Prefix()
{
try
{
Forcing.Arm();
}
catch (Exception ex)
{
Plugin.L.LogError((object)("Could not prepare the shops: " + ex.Message));
}
try
{
Spread.Start();
}
catch (Exception ex2)
{
Plugin.L.LogError((object)("Could not prepare the spreading: " + ex2.Message));
}
try
{
CityCheck.Arm();
}
catch (Exception ex3)
{
Plugin.L.LogError((object)("Could not set up the city check: " + ex3.Message));
}
}
}
[HarmonyPatch(typeof(CityConstructor), "LoadSaveGame")]
internal static class LoadPatch
{
private static void Prefix()
{
Forcing.Disarm("the city finished");
Spread.Stop("a saved city loads");
}
}
[HarmonyPatch(typeof(CityConstructor), "LoadCityStartNewGame")]
internal static class StartPatch
{
private static void Prefix()
{
Forcing.Disarm("the new game started");
}
}
[HarmonyPatch(typeof(NewAddress), "AssignPurpose")]
internal static class PlacedPatch
{
private static void Prefix(NewAddress __instance)
{
try
{
Spread.BeforeAssign(__instance);
}
catch
{
}
}
private static void Postfix(NewAddress __instance)
{
try
{
Spread.AfterAssign(__instance);
}
catch
{
}
try
{
Forcing.Placed(__instance);
}
catch
{
}
}
}
internal static class Buildings
{
private static readonly Dictionary<string, (BuildingPreset preset, int minimum, int importance)> raised = new Dictionary<string, (BuildingPreset, int, int)>();
private static readonly List<(BuildingPreset preset, int minimum, int importance, int limit)> changed = new List<(BuildingPreset, int, int, int)>();
private static readonly List<(BuildingPreset preset, bool all)> looseDistricts = new List<(BuildingPreset, bool)>();
private static readonly List<(BuildingPreset preset, Density dMin, Density dMax, LandValue lMin, LandValue lMax)> looseLimits = new List<(BuildingPreset, Density, Density, LandValue, LandValue)>();
internal static void Arm()
{
//IL_0427: Unknown result type (might be due to invalid IL or missing references)
//IL_042e: Expected O, but got Unknown
Restore();
Dictionary<string, int> dictionary = new Dictionary<string, int>();
string[] array = (Plugin.RequiredBuildings.Value ?? "").Split(',');
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split(':');
if (array2[0].Trim().Length != 0)
{
dictionary[array2[0].Trim()] = ((array2.Length <= 1 || !int.TryParse(array2[1], out var result)) ? 1 : result);
}
}
int num = 0;
num = CitySize.Tiles();
bool flag = num > 0 && num <= Plugin.SmallCityTiles.Value;
if (Plugin.AlwaysHotel.Value && (!dictionary.TryGetValue("Hotel", out var value) || value < 1))
{
dictionary["Hotel"] = 1;
}
if (!dictionary.ContainsKey("CityHall"))
{
dictionary["CityHall"] = 1;
}
if (Plugin.AlwaysHotel.Value && !dictionary.ContainsKey("AmericanDiner"))
{
dictionary["AmericanDiner"] = 1;
}
Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
array = (Plugin.OptionalInSmallCities.Value ?? "").Split(',');
for (int i = 0; i < array.Length; i++)
{
string[] array3 = array[i].Split(':');
if (array3[0].Trim().Length != 0)
{
dictionary2[array3[0].Trim()] = ((array3.Length <= 1 || !int.TryParse(array3[1], out var result2)) ? 1 : result2);
}
}
HashSet<string> optional = new HashSet<string>(dictionary2.Keys);
List<BuildingPreset> list = new List<BuildingPreset>();
foreach (Object item in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.Of<BuildingPreset>()))
{
BuildingPreset val = ((Il2CppObjectBase)item).TryCast<BuildingPreset>();
if ((SoCustomComparison)(object)val != (SoCustomComparison)null)
{
list.Add(val);
}
}
int top = ((list.Count != 0) ? list.Max((BuildingPreset val3) => val3.featureImportance) : 0);
List<string> list2 = new List<string>();
bool flag2 = default(bool);
foreach (BuildingPreset b in list)
{
list2.Add($"{((Object)b).name} (min {b.minimum}, limit {b.hardLimit}, importance {b.featureImportance})");
if (raised.ContainsKey(((Object)b).name))
{
if (((Il2CppObjectBase)raised[((Object)b).name].preset).Pointer != ((Il2CppObjectBase)b).Pointer)
{
Change(b, dictionary, optional, flag, top);
}
continue;
}
Change(b, dictionary, optional, flag, top);
if (flag && dictionary2.TryGetValue(((Object)b).name, out var value2) && b.hardLimit > value2 && !dictionary.ContainsKey(((Object)b).name))
{
if (!changed.Any<(BuildingPreset, int, int, int)>(((BuildingPreset preset, int minimum, int importance, int limit) c) => ((Il2CppObjectBase)c.preset).Pointer == ((Il2CppObjectBase)b).Pointer))
{
changed.Add((b, b.minimum, b.featureImportance, b.hardLimit));
}
b.minimum = Math.Min(b.minimum, value2);
b.hardLimit = value2;
ManualLogSource l = Plugin.L;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(21, 2, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Small city: at most ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(value2);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)b).name);
}
l.LogInfo(val2);
}
}
Plugin.L.LogDebug((object)("Building types in the game: " + string.Join(", ", list2.OrderBy((string x) => x))));
}
private static void Change(BuildingPreset b, Dictionary<string, int> wanted, HashSet<string> optional, bool small, int top)
{
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
if (wanted.TryGetValue(((Object)b).name, out var value))
{
changed.Add((b, b.minimum, b.featureImportance, b.hardLimit));
if (b.minimum < value)
{
b.minimum = value;
}
if (b.hardLimit < value)
{
b.hardLimit = value;
}
b.featureImportance = ((((Object)b).name == "EdenTower") ? (top + 3) : ((((Object)b).name == "CityHall") ? (top + 2) : (top + 1)));
raised[((Object)b).name] = (b, 0, 0);
if (!looseLimits.Any<(BuildingPreset, Density, Density, LandValue, LandValue)>(((BuildingPreset preset, Density dMin, Density dMax, LandValue lMin, LandValue lMax) tuple) => ((Il2CppObjectBase)tuple.preset).Pointer == ((Il2CppObjectBase)b).Pointer))
{
looseLimits.Add((b, b.densityMinimum, b.densityMaximum, b.landValueMinimum, b.landValueMaximum));
looseDistricts.Add((b, b.allowedInAllDistricts));
Density[] source = (Density[])Enum.GetValues(typeof(Density));
LandValue[] source2 = (LandValue[])Enum.GetValues(typeof(LandValue));
b.densityMinimum = source.Min();
b.densityMaximum = source.Max();
b.landValueMinimum = source2.Min();
b.landValueMaximum = source2.Max();
b.allowedInAllDistricts = true;
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("New city: at least ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)b).name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", placed first");
}
l.LogInfo(val);
}
}
internal static void Restore()
{
//IL_001c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
foreach (var looseLimit in looseLimits)
{
try
{
looseLimit.preset.densityMinimum = looseLimit.dMin;
looseLimit.preset.densityMaximum = looseLimit.dMax;
looseLimit.preset.landValueMinimum = looseLimit.lMin;
looseLimit.preset.landValueMaximum = looseLimit.lMax;
}
catch
{
}
}
looseLimits.Clear();
foreach (var looseDistrict in looseDistricts)
{
try
{
looseDistrict.preset.allowedInAllDistricts = looseDistrict.all;
}
catch
{
}
}
looseDistricts.Clear();
foreach (var item in changed)
{
try
{
item.preset.minimum = item.minimum;
item.preset.featureImportance = item.importance;
item.preset.hardLimit = item.limit;
}
catch
{
}
}
changed.Clear();
raised.Clear();
}
}
public class CityCheck : MonoBehaviour
{
private static bool pending;
private static float since;
private LoadState last = (LoadState)(-1);
public CityCheck(IntPtr ptr)
: base(ptr)
{
}//IL_0002: Unknown result type (might be due to invalid IL or missing references)
internal static void Arm()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Expected O, but got Unknown
pending = false;
CityConstructor instance = CityConstructor.Instance;
if ((Object)(object)instance == (Object)null || string.IsNullOrWhiteSpace(Plugin.SmallCityMustHave.Value))
{
return;
}
if (instance.IsUsingCityEditor())
{
Plugin.L.LogInfo((object)"City check: city editor in use, no check");
return;
}
int num = 0;
num = CitySize.Tiles();
if (num > 0 && num <= Plugin.SmallCityTiles.Value)
{
instance.StopCityConstructionAtEndOfLoadState((LoadState)5);
pending = true;
since = Time.unscaledTime;
string text = "?";
try
{
RestartSafeController instance2 = RestartSafeController.Instance;
text = ((instance2 != null) ? instance2.seed : null) ?? "?";
}
catch
{
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(50, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("City check: will pause after the buildings (seed ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
l.LogInfo(val);
}
}
private static void SwapInEden(List<NewBuilding> dir)
{
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Expected O, but got Unknown
try
{
BuildingPreset val = null;
List<BuildingPreset> buildingPresets = HighlanderSingleton<CityBuildings>.Instance.buildingPresets;
for (int i = 0; i < buildingPresets.Count; i++)
{
BuildingPreset obj = buildingPresets[i];
if (((obj != null) ? ((Object)obj).name : null) == "EdenTower")
{
val = buildingPresets[i];
break;
}
}
if ((SoCustomComparison)(object)val == (SoCustomComparison)null)
{
Plugin.L.LogInfo((object)"City check: no EdenTower preset found, no swap");
return;
}
List<string> list = (from x in Plugin.SwapOut.Value.Split(',')
select x.Trim() into x
where x.Length > 0
select x).ToList();
NewBuilding val2 = null;
foreach (string item in list)
{
for (int num = 0; num < dir.Count; num++)
{
if (!((Object)(object)val2 == (Object)null))
{
break;
}
NewBuilding obj2 = dir[num];
object obj3;
if (obj2 == null)
{
obj3 = null;
}
else
{
BuildingPreset preset = obj2.preset;
obj3 = ((preset != null) ? ((Object)preset).name : null);
}
if ((string?)obj3 == item)
{
val2 = dir[num];
}
}
if ((Object)(object)val2 != (Object)null)
{
break;
}
}
if ((Object)(object)val2 == (Object)null)
{
Plugin.L.LogInfo((object)"City check: nothing to swap out");
return;
}
CityTile cityTile = val2.cityTile;
int buildingID = val2.buildingID;
string name = ((Object)val2.preset).name;
val2.RemoveBuilding();
Object.Instantiate<GameObject>(HighlanderSingleton<CityBuildings>.Instance.buildingPrefab, ((Component)cityTile).transform).GetComponent<NewBuilding>().Setup(cityTile, val, false, buildingID);
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(46, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("City check: swapped ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(name);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" for EdenTower (building ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(buildingID);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(")");
}
l.LogInfo(val3);
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("City check: swap failed, city unchanged: " + ex));
}
}
private void Update()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0053: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Invalid comparison between Unknown and I4
//IL_0066: 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_00cb: Invalid comparison between Unknown and I4
Spread.Poll();
if (!pending)
{
return;
}
try
{
CityConstructor instance = CityConstructor.Instance;
if ((Object)(object)instance == (Object)null)
{
return;
}
if (instance.loadState != last)
{
last = instance.loadState;
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(36, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("City check: state ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<LoadState>(last);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", hold ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(instance.useCityConstructionHold);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", complete ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(instance.stateComplete);
}
l.LogDebug(val);
}
bool flag2 = instance.useCityConstructionHold && (int)instance.loadState == 5 && instance.stateComplete;
bool flag3 = (int)instance.loadState > 5;
if (!flag2 && !flag3 && Time.unscaledTime - since < 600f)
{
return;
}
Dictionary<string, int> got = new Dictionary<string, int>();
CityBuildings instance2 = HighlanderSingleton<CityBuildings>.Instance;
List<NewBuilding> val2 = ((instance2 != null) ? instance2.buildingDirectory : null);
int num = 0;
while (val2 != null && num < val2.Count)
{
NewBuilding obj = val2[num];
object obj2;
if (obj == null)
{
obj2 = null;
}
else
{
BuildingPreset preset = obj.preset;
obj2 = ((preset != null) ? ((Object)preset).name : null);
}
if (obj2 == null)
{
obj2 = "?";
}
string text = (string)obj2;
if (!text.StartsWith("Boundary"))
{
got[text] = ((!got.TryGetValue(text, out var value)) ? 1 : (value + 1));
}
num++;
}
List<string> list = (from x in (from x in Plugin.SmallCityMustHave.Value.Split(',')
select x.Trim() into x
where x.Length > 0
select x).ToList()
where !got.ContainsKey(x)
select x).ToList();
Plugin.L.LogInfo((object)("City check (" + (flag2 ? "paused" : (flag3 ? "already past the pause" : "timed out")) + "): " + string.Join(", ", got.Select<KeyValuePair<string, int>, string>((KeyValuePair<string, int> kv) => kv.Value + " " + kv.Key)) + ((list.Count == 0) ? " -> OK" : (" -> missing " + string.Join(", ", list)))));
if (flag2 && list.Contains("EdenTower") && Plugin.SwapIn.Value)
{
SwapInEden(val2);
}
pending = false;
instance.ClearCityConstructionHoldStatus();
}
catch (Exception ex)
{
pending = false;
Plugin.L.LogWarning((object)("City check failed, continuing: " + ex.Message));
try
{
CityConstructor.Instance.ClearCityConstructionHoldStatus();
}
catch
{
}
}
}
}
internal static class Spread
{
internal static ConfigEntry<int> ShopSpacing = null;
internal static ConfigEntry<int> VendingSpacing = null;
private const string OutdoorVending = "1x1VendingMachineOutdoor";
private const float GroupReach = 3.5f;
private const int MaxGroup = 4;
private static bool active;
private static readonly Dictionary<string, AddressPreset> shopTypes = new Dictionary<string, AddressPreset>();
private static readonly Dictionary<string, List<Vector2>> shops = new Dictionary<string, List<Vector2>>();
private static readonly List<(AddressPreset preset, int max)> held = new List<(AddressPreset, int)>();
private static readonly List<Vector2> machines = new List<Vector2>();
private static int heldBack;
private static int turnedDown;
private static int placedMachines;
internal static void Bind(ConfigFile c)
{
ShopSpacing = c.Bind<int>("Spread", "ShopSpacing", 12, "In a new city, a shop is not placed this close to another shop of the same type, in floor tiles (a city block is about 21). 0 = the game's own placing.");
VendingSpacing = c.Bind<int>("Spread", "VendingSpacing", 0, "In a new city, a group of street vending machines is not placed this close to another group, in floor tiles. Thins machines out rather than filling empty areas, so off by default. 0 = the game's own placing.");
}
internal static void Start()
{
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
active = true;
shopTypes.Clear();
shops.Clear();
held.Clear();
machines.Clear();
heldBack = (turnedDown = (placedMachines = 0));
Toolbox instance = Toolbox.Instance;
List<AddressPreset> val = ((instance != null) ? instance.allAddressPresets : null);
int num = 0;
while (val != null && num < val.Count)
{
AddressPreset val2 = val[num];
if (!((SoCustomComparison)(object)val2 == (SoCustomComparison)null) && !((SoCustomComparison)(object)val2.company == (SoCustomComparison)null) && val2.company.publicFacing && !Forcing.IsBlackMarket(((Object)val2).name))
{
shopTypes[((Object)val2).name] = val2;
}
num++;
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(95, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[SPREAD] new city: shops of a type at least ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(ShopSpacing.Value);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" tiles apart (");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(shopTypes.Count);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" types), street vending groups ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(VendingSpacing.Value);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" apart");
}
l.LogInfo(val3);
}
internal static void Stop(string why)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
if (active)
{
Release();
active = false;
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(141, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[SPREAD] ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(why);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(heldBack);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" times a shop type was kept away from a branch nearby; ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(placedMachines);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" street vending machines placed, ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(turnedDown);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" groups turned down for standing too close");
}
l.LogInfo(val);
}
}
internal static void Poll()
{
if (!active)
{
return;
}
try
{
if ((Object)(object)SessionData.Instance != (Object)null && SessionData.Instance.startedGame)
{
Stop("the city is done");
}
}
catch
{
}
}
private static bool Live()
{
if (!active)
{
return false;
}
try
{
if ((Object)(object)SessionData.Instance != (Object)null && SessionData.Instance.startedGame)
{
Stop("the game started");
return false;
}
}
catch
{
}
return true;
}
private static Vector2 Centre(NewGameLocation gl)
{
//IL_0022: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: 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)
List<NewNode> val = ((gl != null) ? gl.nodes : null);
if (val == null || val.Count == 0)
{
return new Vector2(float.NaN, float.NaN);
}
Vector2 val2 = Vector2.zero;
for (int i = 0; i < val.Count; i++)
{
Vector2 val3 = val2;
Vector3Int nodeCoord = val[i].nodeCoord;
float num = ((Vector3Int)(ref nodeCoord)).x;
nodeCoord = val[i].nodeCoord;
val2 = val3 + new Vector2(num, (float)((Vector3Int)(ref nodeCoord)).y);
}
return val2 / (float)val.Count;
}
internal static void BeforeAssign(NewAddress a)
{
//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_0025: 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_009a: 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)
if (!Live() || ShopSpacing.Value <= 0 || (Object)(object)a == (Object)null)
{
return;
}
Vector2 val = Centre((NewGameLocation)(object)a);
if (float.IsNaN(val.x))
{
return;
}
float num = (float)ShopSpacing.Value * (float)ShopSpacing.Value;
foreach (KeyValuePair<string, List<Vector2>> shop in shops)
{
if (!shopTypes.TryGetValue(shop.Key, out AddressPreset value) || (SoCustomComparison)(object)value == (SoCustomComparison)null)
{
continue;
}
foreach (Vector2 item in shop.Value)
{
Vector2 val2 = item - val;
if (((Vector2)(ref val2)).sqrMagnitude < num)
{
held.Add((value, value.maxInstances));
value.maxInstances = 0;
break;
}
}
}
}
private static void Release()
{
foreach (var (val, maxInstances) in held)
{
try
{
val.maxInstances = maxInstances;
}
catch
{
}
}
held.Clear();
}
internal static void AfterAssign(NewAddress a)
{
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
if (held.Count > 0)
{
object obj;
if (a == null)
{
obj = null;
}
else
{
AddressPreset addressPreset = a.addressPreset;
obj = ((addressPreset != null) ? ((Object)addressPreset).name : null);
}
string text = (string)obj;
foreach (var item in held)
{
if (((Object)item.preset).name != text)
{
heldBack++;
}
}
Release();
}
if (!active || (SoCustomComparison)(object)((a != null) ? a.addressPreset : null) == (SoCustomComparison)null || !shopTypes.ContainsKey(((Object)a.addressPreset).name))
{
return;
}
Vector2 val = Centre((NewGameLocation)(object)a);
if (!float.IsNaN(val.x))
{
if (!shops.TryGetValue(((Object)a.addressPreset).name, out List<Vector2> value))
{
value = (shops[((Object)a.addressPreset).name] = new List<Vector2>());
}
value.Add(val);
}
}
private static bool IsStreetVending(FurnitureCluster? c)
{
List<FurnitureClusterRule> val = ((c != null) ? c.clusterElements : null);
int num = 0;
while (val != null && num < val.Count)
{
FurnitureClusterRule obj = val[num];
FurnitureClass val2 = ((obj != null) ? obj.furnitureClass : null);
if ((SoCustomComparison)(object)val2 != (SoCustomComparison)null && ((Object)val2).name == "1x1VendingMachineOutdoor")
{
return true;
}
num++;
}
return false;
}
internal static bool VendingFits(FurnitureClusterLocation loc)
{
//IL_0039: 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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_0093: 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)
if (!Live() || VendingSpacing.Value <= 0 || ((loc != null) ? loc.anchorNode : null) == null || !IsStreetVending(loc.cluster))
{
return true;
}
Vector3Int nodeCoord = loc.anchorNode.nodeCoord;
float num = ((Vector3Int)(ref nodeCoord)).x;
nodeCoord = loc.anchorNode.nodeCoord;
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(num, (float)((Vector3Int)(ref nodeCoord)).y);
float num2 = (float)VendingSpacing.Value * (float)VendingSpacing.Value;
int num3 = 0;
int num4 = 0;
foreach (Vector2 machine in machines)
{
Vector2 val2 = machine - val;
float sqrMagnitude = ((Vector2)(ref val2)).sqrMagnitude;
if (!(sqrMagnitude >= num2))
{
num3++;
if (sqrMagnitude <= 12.25f)
{
num4++;
}
}
}
if (num3 == 0 || (num3 == num4 && num4 < 4))
{
return true;
}
turnedDown++;
return false;
}
internal static void VendingPlaced(FurnitureClusterLocation loc)
{
//IL_002e: 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)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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)
if (active && ((loc != null) ? loc.anchorNode : null) != null && IsStreetVending(loc.cluster))
{
List<Vector2> list = machines;
Vector3Int nodeCoord = loc.anchorNode.nodeCoord;
float num = ((Vector3Int)(ref nodeCoord)).x;
nodeCoord = loc.anchorNode.nodeCoord;
list.Add(new Vector2(num, (float)((Vector3Int)(ref nodeCoord)).y));
placedMachines++;
}
}
}
[HarmonyPatch(typeof(GenerationController), "GetBestFurnitureClusterLocation")]
internal static class VendingPickPatch
{
private static void Postfix(ref FurnitureClusterLocation __result)
{
try
{
if (__result != null && !Spread.VendingFits(__result))
{
__result = null;
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(NewRoom), "AddFurniture")]
internal static class VendingPlacedPatch
{
private static void Postfix(FurnitureClusterLocation newFurn)
{
try
{
Spread.VendingPlaced(newFurn);
}
catch
{
}
}
}
}