Decompiled source of Castle Freedom v1.0.0
CastleFreedom.dll
Decompiled 20 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem.Collections.Generic; using Microsoft.CodeAnalysis; using ProjectM; using ProjectM.CastleBuilding; using ProjectM.Network; using ProjectM.Shared; using ProjectM.UI; using Stunlock.Core; using Stunlock.Localization; using Stunlock.Network; using Unity.Collections; using Unity.Entities; using Unity.Mathematics; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(/*Could not decode attribute arguments.*/)] [assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : System.Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(/*Could not decode attribute arguments.*/)] internal sealed class RefSafetyRulesAttribute : System.Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CastleFreedom { [BepInPlugin("com.zeeCameLsnake.CastleFreedom", "CastleFreedom", "1.0.0")] public class CastleFreedomPlugin : BasePlugin { public const string PluginGUID = "com.zeeCameLsnake.CastleFreedom"; public const string PluginName = "CastleFreedom"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static bool IsServer; private Harmony _harmony; public override void Load() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown Log = ((BasePlugin)this).Log; IsServer = Application.productName == "VRisingServer"; _harmony = new Harmony("com.zeeCameLsnake.CastleFreedom"); if (IsServer) { ServerPart.Load(); _harmony.PatchAll(typeof(ServerPatches)); return; } CastleFreedomConfig.Bind(((BasePlugin)this).Config); _harmony.PatchAll(typeof(ClientPatches)); ManualLogSource log = Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(64, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CastleFreedom"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded (client part: Gale live-reload sync & bonus tooltips)."); } log.LogInfo(val); } public override bool Unload() { if (!IsServer) { try { ClientUiTooltips.RestoreAll(); } catch (System.Exception ex) { Util.LogExceptionOnce("Client.RestoreOnUnload", ex); } } Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } return true; } } [HarmonyPatch] internal static class ClientPatches { [HarmonyPatch(typeof(GameplayInputSystem), "OnUpdate")] [HarmonyPrefix] private static void InputPrefix(GameplayInputSystem __instance) { try { CastleFreedomConfig.PollLiveReload(); } catch (System.Exception ex) { Util.LogExceptionOnce("Client.LiveReload", ex); } try { ClientLink.Tick(((ComponentSystemBase)__instance).World); } catch (System.Exception ex2) { Util.LogExceptionOnce("Client.LinkTick", ex2); } try { ClientUiTooltips.Tick(((ComponentSystemBase)__instance).World); } catch (System.Exception ex3) { Util.LogExceptionOnce("Client.TooltipsTick", ex3); } } [HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")] [HarmonyPrefix] private static void ChatPrefix(ClientChatSystem __instance) { try { ClientLink.ReadServerMessages(__instance); } catch (System.Exception ex) { Util.LogExceptionOnce("Client.ReadChat", ex); } } } internal static class CastleFreedomConfig { private const string SectionGeneral = "1. General"; private const string SectionFloorBonuses = "2. Matching Floor Bonuses"; private const string SectionSpeedBonus = "3. Speed Bonus Without Roof"; private const string SectionClientUi = "4. Client UI"; private const string SectionDebug = "5. Debug"; internal static ConfigFile File; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> LiveReload; internal static ConfigEntry<bool> AllowPartialFloorMatch; internal static ConfigEntry<bool> EnableStationFloorBonusWithoutWalls; internal static ConfigEntry<bool> EnableTreasuryWithoutWalls; internal static ConfigEntry<bool> EnableSpeedBonusWithoutRoof; internal static ConfigEntry<bool> RequireBuildingACastleQuest; internal static ConfigEntry<SpeedFloorMode> SpeedBonusFloorRequirement; internal static ConfigEntry<bool> UpdateBonusTooltips; internal static ConfigEntry<bool> LogDiagnostics; private const float PollSeconds = 0.5f; private static float _nextPoll; private static System.DateTime _loadedWriteTime; private static System.DateTime _pendingWriteTime; private static bool _reloadErrorLogged; internal static void Bind(ConfigFile cfg) { File = cfg; Enabled = cfg.Bind<bool>("1. General", "Enabled", true, "Master switch for Castle Freedom. Off immediately restores vanilla enclosed-room requirements for all stations and containers (in Solo / Host play)."); LiveReload = cfg.Bind<bool>("1. General", "LiveReload", true, "Re-reads this config file automatically about 0.5 s after saving and syncs changes live to the local server without restarting. If turned off, use the .cf reload chat command to reload manually (and pick up turning LiveReload back on)."); AllowPartialFloorMatch = cfg.Bind<bool>("1. General", "AllowPartialFloorMatch", true, "Applies to all floor checks (stations, Treasury chests, and floor-based speed modes). On (default): only part of the station or chest needs to touch the required floor tiles, so chests and stations can sit edge-to-edge across floor borders. Off: the entire footprint must rest on the required floor tiles."); EnableStationFloorBonusWithoutWalls = cfg.Bind<bool>("2. Matching Floor Bonuses", "EnableStationFloorBonusWithoutWalls", true, "Stations (crafting, refining, forges, paper presses, prison, servant coffins, etc.) receive their Matching Floor bonus on matching floor tiles (no walls or roof needed)."); EnableTreasuryWithoutWalls = cfg.Bind<bool>("2. Matching Floor Bonuses", "EnableTreasuryWithoutWalls", true, "Storage containers (CastleSharedInventory) receive the Treasury shared-inventory perk on Treasury floor tiles (no walls or roof needed)."); EnableSpeedBonusWithoutRoof = cfg.Bind<bool>("3. Speed Bonus Without Roof", "EnableSpeedBonusWithoutRoof", true, "Stations receive the Confined Room (+25% speed) bonus without walls or a roof once unlocked. Real roofs and daytime sunlight stay unchanged."); RequireBuildingACastleQuest = cfg.Bind<bool>("3. Speed Bonus Without Roof", "Require Building a Castle Quest", true, "Requires the castle owner to have built an enclosed, roofed room at least once (journal quest \"Building a Castle\") before their castle stations gain the roof-free speed bonus. Off unlocks it immediately."); SpeedBonusFloorRequirement = cfg.Bind<SpeedFloorMode>("3. Speed Bonus Without Roof", "SpeedBonusFloorRequirement", SpeedFloorMode.None, "Floor required under an unwalled station for the roof-free speed bonus.\n(Stations inside a real enclosed room always keep their vanilla +25% speed bonus.)\n\n- None (default): Anywhere inside castle territory, even on bare ground.\n- AnyCastleFloor: Requires any castle floor tiles.\n- MatchingFloorOnly [STRICTER THAN VANILLA]: Optional balance tradeoff. Requires matching floor tiles (or any castle floor if the station has none).\n\nRespects AllowPartialFloorMatch."); UpdateBonusTooltips = cfg.Bind<bool>("4. Client UI", "UpdateBonusTooltips", true, "Updates station and container bonus tooltip requirement texts to reflect Castle Freedom's active rules (always matching the server's active settings)."); LogDiagnostics = cfg.Bind<bool>("5. Debug", "LogDiagnostics", false, "Writes diagnostic lines (handshakes, config sync, tooltip updates, and in Solo play server evaluation logs) to the BepInEx log."); _loadedWriteTime = WriteTime(); _pendingWriteTime = _loadedWriteTime; } internal static RuleSettings CurrentRules() { return new RuleSettings { Enabled = Enabled.Value, EnableStationFloorBonusWithoutWalls = EnableStationFloorBonusWithoutWalls.Value, EnableTreasuryWithoutWalls = EnableTreasuryWithoutWalls.Value, AllowPartialFloorMatch = AllowPartialFloorMatch.Value, EnableSpeedBonusWithoutRoof = EnableSpeedBonusWithoutRoof.Value, RequireBuildingACastleQuest = RequireBuildingACastleQuest.Value, SpeedBonusFloorRequirement = SpeedBonusFloorRequirement.Value, LiveReload = LiveReload.Value, LogDiagnostics = LogDiagnostics.Value }; } internal static void Diag(string text) { if (LogDiagnostics != null && LogDiagnostics.Value) { Util.Log.LogInfo((object)("[Diag] " + text)); } } internal static bool ForceReload() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown if (File == null) { return false; } bool saveOnConfigSet = File.SaveOnConfigSet; File.SaveOnConfigSet = false; try { File.Reload(); _loadedWriteTime = WriteTime(); _pendingWriteTime = _loadedWriteTime; _nextPoll = Time.unscaledTime + 0.5f; _reloadErrorLogged = false; ClientUiTooltips.MarkDirty(); ManualLogSource log = Util.Log; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(56, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Client config reloaded (manual .cf reload, LiveReload="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(LiveReload.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")."); } log.LogInfo(val); return true; } catch (System.Exception ex) { Util.Log.LogWarning((object)("Manual client config reload failed: " + ex.Message)); return false; } finally { File.SaveOnConfigSet = saveOnConfigSet; } } internal static void PollLiveReload() { if (File == null || !LiveReload.Value) { return; } float unscaledTime = Time.unscaledTime; if (unscaledTime < _nextPoll) { return; } _nextPoll = unscaledTime + 0.5f; System.DateTime dateTime = WriteTime(); if (dateTime == System.DateTime.MinValue || dateTime == _loadedWriteTime) { return; } if (dateTime != _pendingWriteTime) { _pendingWriteTime = dateTime; return; } bool saveOnConfigSet = File.SaveOnConfigSet; File.SaveOnConfigSet = false; try { File.Reload(); _loadedWriteTime = WriteTime(); _pendingWriteTime = _loadedWriteTime; _reloadErrorLogged = false; ClientUiTooltips.MarkDirty(); Util.Log.LogInfo((object)"Client config changed, reloaded (LiveReload)."); } catch (System.Exception ex) { if (!_reloadErrorLogged) { _reloadErrorLogged = true; Util.Log.LogWarning((object)("Config reload failed, trying again: " + ex.Message)); } } finally { File.SaveOnConfigSet = saveOnConfigSet; } } private static System.DateTime WriteTime() { try { string configFilePath = File.ConfigFilePath; return File.Exists(configFilePath) ? File.GetLastWriteTimeUtc(configFilePath) : System.DateTime.MinValue; } catch (System.Exception) { return System.DateTime.MinValue; } } } public enum SpeedFloorMode { None, AnyCastleFloor, MatchingFloorOnly } internal struct RuleSettings { public bool Enabled; public bool EnableStationFloorBonusWithoutWalls; public bool EnableTreasuryWithoutWalls; public bool AllowPartialFloorMatch; public bool EnableSpeedBonusWithoutRoof; public bool RequireBuildingACastleQuest; public SpeedFloorMode SpeedBonusFloorRequirement; public bool LiveReload; public bool LogDiagnostics; public bool GameplayEquals(RuleSettings other) { return Enabled == other.Enabled && EnableStationFloorBonusWithoutWalls == other.EnableStationFloorBonusWithoutWalls && EnableTreasuryWithoutWalls == other.EnableTreasuryWithoutWalls && AllowPartialFloorMatch == other.AllowPartialFloorMatch && EnableSpeedBonusWithoutRoof == other.EnableSpeedBonusWithoutRoof && RequireBuildingACastleQuest == other.RequireBuildingACastleQuest && SpeedBonusFloorRequirement == other.SpeedBonusFloorRequirement; } public string Describe() { return $"Enabled={Enabled}, LiveReload={LiveReload}, PartialFloor={AllowPartialFloorMatch}, StationFloor={EnableStationFloorBonusWithoutWalls}, Treasury={EnableTreasuryWithoutWalls}, SpeedNoRoof={EnableSpeedBonusWithoutRoof}, QuestGate={RequireBuildingACastleQuest}, SpeedFloor={SpeedBonusFloorRequirement}, Diag={LogDiagnostics}"; } } internal static class Protocol { internal const int Version = 1; internal const string Marker = "[[CastleFreedom]] "; internal const string Hello = "[CastleFreedom] "; internal const string ReloadWire = "reload"; internal static string BuildGreeting(RuleSettings r) { string text = FormatFlags(r); return r.Enabled ? $"{"[CastleFreedom] "}Castle bonuses without walls or roofs are active. (v={1} {text})" : $"{"[CastleFreedom] "}Installed on this server (currently disabled). (v={1} {text})"; } internal static bool TryParseGreeting(string text, out RuleSettings rules) { rules = default(RuleSettings); string text2 = $"(v={1} "; int num = text.LastIndexOf(text2, (StringComparison)4); if (num < 0) { return false; } int num2 = num + text2.Length; int num3 = text.IndexOf(')', num2); if (num3 <= num2) { return false; } string[] parts = text.Substring(num2, num3 - num2).Split(new char[1] { ' ' }, (StringSplitOptions)1); return TryParseCore(parts, 0, out rules); } internal static string RulesWire(RuleSettings r, bool serverOnly) { return $"rules {1} {FormatFlags(r)} {(serverOnly ? 1 : 0)}"; } internal static bool TryParseRules(string[] parts, out RuleSettings rules, out bool serverOnly) { rules = default(RuleSettings); serverOnly = false; if (parts == null || parts.Length < 10 || parts[0] != "rules" || parts[1] != 1.ToString((IFormatProvider)(object)CultureInfo.InvariantCulture)) { return false; } if (!TryParseCore(parts, 2, out rules)) { return false; } serverOnly = parts[9] == "1"; return true; } internal static string ClientSetWire(RuleSettings r) { return $"set {1} {FormatFlags(r)} {(r.LogDiagnostics ? 1 : 0)} {(r.LiveReload ? 1 : 0)}"; } internal static bool TryParseClientSet(string[] parts, out RuleSettings rules) { rules = default(RuleSettings); if (parts == null || parts.Length < 11 || parts[0] != "set" || parts[1] != 1.ToString((IFormatProvider)(object)CultureInfo.InvariantCulture)) { return false; } if (!TryParseCore(parts, 2, out rules)) { return false; } rules.LogDiagnostics = parts[9] == "1"; rules.LiveReload = parts[10] == "1"; return true; } private static string FormatFlags(RuleSettings r) { return string.Format((IFormatProvider)(object)CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5} {6}", new object[7] { r.Enabled ? 1 : 0, r.EnableStationFloorBonusWithoutWalls ? 1 : 0, r.EnableTreasuryWithoutWalls ? 1 : 0, r.AllowPartialFloorMatch ? 1 : 0, r.EnableSpeedBonusWithoutRoof ? 1 : 0, r.RequireBuildingACastleQuest ? 1 : 0, (int)r.SpeedBonusFloorRequirement }); } private static bool TryParseCore(string[] parts, int offset, out RuleSettings rules) { rules = default(RuleSettings); if (parts == null || parts.Length < offset + 7) { return false; } int num = default(int); if (!int.TryParse(parts[offset + 6], (NumberStyles)7, (IFormatProvider)(object)CultureInfo.InvariantCulture, ref num)) { return false; } if (num < 0 || num > 2) { num = 0; } rules.Enabled = parts[offset] == "1"; rules.EnableStationFloorBonusWithoutWalls = parts[offset + 1] == "1"; rules.EnableTreasuryWithoutWalls = parts[offset + 2] == "1"; rules.AllowPartialFloorMatch = parts[offset + 3] == "1"; rules.EnableSpeedBonusWithoutRoof = parts[offset + 4] == "1"; rules.RequireBuildingACastleQuest = parts[offset + 5] == "1"; rules.SpeedBonusFloorRequirement = (SpeedFloorMode)num; return true; } } internal static class Util { private static readonly HashSet<string> LoggedExceptions = new HashSet<string>(); private static readonly Dictionary<int, string> PrefabNames = new Dictionary<int, string>(); internal static ManualLogSource Log => CastleFreedomPlugin.Log; internal static void LogExceptionOnce(string where, System.Exception ex) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown string text = string.Concat(new string[5] { where, ":", ((MemberInfo)ex.GetType()).Name, ":", ex.Message }); if (LoggedExceptions.Add(text)) { ManualLogSource log = Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(3, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<System.Exception>(ex); } log.LogError(val); } } internal static bool IsNull(Entity e) { //IL_0000: 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 e.Index == 0 && e.Version == 0; } internal static bool Same(Entity a, Entity b) { //IL_0000: 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_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) return a.Index == b.Index && a.Version == b.Version; } internal static long Key(Entity e) { //IL_0000: 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) return ((long)e.Index << 32) | (uint)e.Version; } internal static string Id(Entity e) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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) return IsNull(e) ? "null" : $"{e.Index}:{e.Version}"; } internal unsafe static string PrefabName(World world, PrefabGUID guid) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //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_0068: Unknown result type (might be due to invalid IL or missing references) int guidHash = ((PrefabGUID)(ref guid)).GuidHash; if (guidHash == 0) { return "none(0)"; } string result = default(string); if (PrefabNames.TryGetValue(guidHash, ref result)) { return result; } string text = "?"; try { PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>(); if (existingSystemManaged != null) { FixedString128Bytes val = default(FixedString128Bytes); PrefabLookupMap prefabLookupMap = existingSystemManaged._PrefabLookupMap; if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetFixedName(guid, ref val)) { text = ((object)(*(FixedString128Bytes*)(&val))/*cast due to .constrained prefix*/).ToString(); } } } catch (System.Exception ex) { LogExceptionOnce("PrefabName", ex); } string text2 = $"{text}({guidHash})"; PrefabNames[guidHash] = text2; return text2; } internal static string Describe(World world, EntityManager em, Entity e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (IsNull(e)) { return "null"; } if (!((EntityManager)(ref em)).Exists(e)) { return Id(e) + "(gone)"; } if (!((EntityManager)(ref em)).HasComponent<PrefabGUID>(e)) { return Id(e) + "(noPrefab)"; } return Id(e) + " " + PrefabName(world, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(e)); } } internal struct FootprintResult { public bool AllHaveFloor; public bool AnyHasFloor; public bool AllMatchFloor; public bool AnyMatchFloor; } internal static class FloorFootprintChecker { internal static FootprintResult Evaluate(EntityManager em, CastleBlockSystem cbs, BoundsMinMax tb, byte heightLevel, CastleFloorTypes targetMatchType) { //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_002f: 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) //IL_003b: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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_0072: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0082: 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_008d: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_017e: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Invalid comparison between Unknown and I4 //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Invalid comparison between Unknown and I4 //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Invalid comparison between Unknown and I4 FootprintResult result = default(FootprintResult); if (cbs == null || !cbs._Floors.IsCreated) { return result; } int x = tb.Min.x; int y = tb.Min.y; int num = Math.Max(x, tb.Max.x - 1); int num2 = Math.Max(y, tb.Max.y - 1); CastleFloorBlock floorBlock = CastleFloorBlock.GetFloorBlock(new int2(x, y), heightLevel); CastleFloorBlock floorBlock2 = CastleFloorBlock.GetFloorBlock(new int2(num, num2), heightLevel); bool flag = true; bool anyHasFloor = false; bool flag2 = true; bool flag3 = false; CastleFloorBlock val = default(CastleFloorBlock); Entity val2 = default(Entity); for (int i = floorBlock.Value.x; i <= floorBlock2.Value.x; i++) { for (int j = floorBlock.Value.z; j <= floorBlock2.Value.z; j++) { ((CastleFloorBlock)(ref val))..ctor(i, j, heightLevel); if (!cbs._Floors.TryGetValue(val, ref val2) || !((EntityManager)(ref em)).Exists(val2) || !((EntityManager)(ref em)).HasComponent<CastleFloor>(val2)) { flag = false; flag2 = false; continue; } anyHasFloor = true; CastleFloorTypes floorType = ((EntityManager)(ref em)).GetComponentData<CastleFloor>(val2).FloorType; if ((int)targetMatchType > 0) { if (floorType == targetMatchType) { flag3 = true; } else if ((int)floorType != 13) { flag2 = false; } } } } result.AllHaveFloor = flag; result.AnyHasFloor = anyHasFloor; result.AnyMatchFloor = (int)targetMatchType > 0 && flag3; result.AllMatchFloor = result.AnyMatchFloor && flag && flag2; return result; } } internal static class QuestGate { private static readonly PrefabGUID JournalCompleteARoom = new PrefabGUID(334973636); private static readonly PrefabGUID JournalSubTaskCompleteARoom = new PrefabGUID(-1280890101); private static readonly PrefabGUID[] FallbackQuests = (PrefabGUID[])(object)new PrefabGUID[3] { new PrefabGUID(134993992), new PrefabGUID(606418711), new PrefabGUID(149111189) }; private static readonly Dictionary<long, bool> OwnerUnlocked = new Dictionary<long, bool>(); private static readonly Dictionary<long, Entity> LockedOwners = new Dictionary<long, Entity>(); internal static void Reset() { OwnerUnlocked.Clear(); LockedOwners.Clear(); } internal static bool IsCastleUnlocked(EntityManager em, Entity heartEntity, bool requireQuest) { //IL_0013: 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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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) if (!requireQuest) { return true; } Entity val = ResolveCastleOwner(em, heartEntity); if (Util.IsNull(val)) { return false; } long num = Util.Key(val); bool flag = default(bool); if (OwnerUnlocked.TryGetValue(num, ref flag)) { if (!flag && !LockedOwners.ContainsKey(num)) { LockedOwners[num] = val; } return flag; } bool flag2 = HasCompletedBuildingACastle(em, val); OwnerUnlocked[num] = flag2; if (!flag2) { LockedOwners[num] = val; } return flag2; } internal unsafe static bool CheckForNewUnlocks(EntityManager em, Action<string> diag) { //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_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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_0083: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) if (LockedOwners.Count == 0) { return false; } List<long> val = null; List<long> val2 = null; Enumerator<long, Entity> enumerator = LockedOwners.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair<long, Entity> current = enumerator.Current; Entity value = current.Value; if (!((EntityManager)(ref em)).Exists(value) || !((EntityManager)(ref em)).HasComponent<User>(value)) { if (val2 == null) { val2 = new List<long>(); } val2.Add(current.Key); } else if (HasCompletedBuildingACastle(em, value)) { if (val == null) { val = new List<long>(); } val.Add(current.Key); User componentData = ((EntityManager)(ref em)).GetComponentData<User>(value); string text = ((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString(); diag.Invoke("Owner '" + text + "' completed 'Building a Castle' -> unlocking outdoor speed bonuses for their castle(s)."); } } } finally { ((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } if (val2 != null) { for (int i = 0; i < val2.Count; i++) { LockedOwners.Remove(val2[i]); OwnerUnlocked.Remove(val2[i]); } } if (val == null) { return false; } for (int j = 0; j < val.Count; j++) { long num = val[j]; LockedOwners.Remove(num); OwnerUnlocked[num] = true; } return true; } private static Entity ResolveCastleOwner(EntityManager em, Entity heartEntity) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_002b: 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_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_004b: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_004a: 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_005f: 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_0081: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) if (Util.IsNull(heartEntity) || !((EntityManager)(ref em)).Exists(heartEntity)) { return Entity.Null; } Entity val = Entity.Null; if (((EntityManager)(ref em)).HasComponent<UserOwner>(heartEntity)) { val = ((EntityManager)(ref em)).GetComponentData<UserOwner>(heartEntity).Owner._Entity; } if ((Util.IsNull(val) || !((EntityManager)(ref em)).Exists(val)) && ((EntityManager)(ref em)).HasComponent<CastleHeart>(heartEntity)) { val = ((EntityManager)(ref em)).GetComponentData<CastleHeart>(heartEntity).LastUserOwner._Entity; } if (Util.IsNull(val) || !((EntityManager)(ref em)).Exists(val) || !((EntityManager)(ref em)).HasComponent<User>(val)) { return Entity.Null; } return val; } private static bool HasCompletedBuildingACastle(EntityManager em, Entity ownerUser) { //IL_0003: 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_001a: 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_0029: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) //IL_0066: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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) //IL_012a: 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_00a5: Unknown result type (might be due to invalid IL or missing references) if (!((EntityManager)(ref em)).HasComponent<AchievementOwner>(ownerUser)) { return false; } Entity entity = ((EntityManager)(ref em)).GetComponentData<AchievementOwner>(ownerUser).Entity._Entity; if (Util.IsNull(entity) || !((EntityManager)(ref em)).Exists(entity)) { return false; } if (((EntityManager)(ref em)).HasComponent<AchievementClaimedElement>(entity)) { DynamicBuffer<AchievementClaimedElement> buffer = ((EntityManager)(ref em)).GetBuffer<AchievementClaimedElement>(entity, true); for (int i = 0; i < buffer.Length; i++) { PrefabGUID achievementPrefabGuid = buffer[i].AchievementPrefabGuid; if (achievementPrefabGuid == JournalCompleteARoom) { return true; } for (int j = 0; j < FallbackQuests.Length; j++) { if (achievementPrefabGuid == FallbackQuests[j]) { return true; } } } } if (((EntityManager)(ref em)).HasComponent<AchievementInProgressElement>(entity)) { DynamicBuffer<AchievementInProgressElement> buffer2 = ((EntityManager)(ref em)).GetBuffer<AchievementInProgressElement>(entity, true); for (int k = 0; k < buffer2.Length; k++) { if (buffer2[k].AchievementPrefabGuid == JournalSubTaskCompleteARoom && buffer2[k].CompletedAmount >= 1) { return true; } } } return false; } } internal static class WorkstationEvaluator { private static ComponentType[] _levelModEventTypes; internal static bool IsEligibleWorkstation(EntityManager em, Entity e) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_003a: 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_004d: 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_0058: 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_005e: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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) if (!((EntityManager)(ref em)).Exists(e) || !((EntityManager)(ref em)).HasComponent<CastleWorkstation>(e) || !((EntityManager)(ref em)).HasComponent<TilePosition>(e) || !((EntityManager)(ref em)).HasComponent<TileBounds>(e)) { return false; } if (!((EntityManager)(ref em)).HasComponent<CastleHeartConnection>(e)) { return false; } Entity entity = ((EntityManager)(ref em)).GetComponentData<CastleHeartConnection>(e).CastleHeartEntity._Entity; if (Util.IsNull(entity) || !((EntityManager)(ref em)).Exists(entity) || !((EntityManager)(ref em)).HasComponent<CastleHeart>(entity)) { return false; } if (((EntityManager)(ref em)).HasComponent<CastleSharedInventory>(e)) { return true; } if (((EntityManager)(ref em)).HasComponent<StationBonusBuffer>(e) && ((EntityManager)(ref em)).GetBuffer<StationBonusBuffer>(e, true).Length > 0) { return true; } return false; } internal static WorkstationLevel ComputeVanillaLevel(EntityManager em, Entity e, CastleWorkstation cw) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0009: 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_0023: 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_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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_001a: 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_0183: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_007b: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017b: 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_0118: 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) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Invalid comparison between Unknown and I4 WorkstationLevel val = (WorkstationLevel)(cw.WorkstationLevel & 4); if (!((EntityManager)(ref em)).HasComponent<CastleRoomConnection>(e)) { return val; } Entity entity = ((EntityManager)(ref em)).GetComponentData<CastleRoomConnection>(e).RoomEntity._Entity; if (Util.IsNull(entity) || !((EntityManager)(ref em)).Exists(entity) || !((EntityManager)(ref em)).HasComponent<CastleRoom>(entity)) { return val; } CastleRoom componentData = ((EntityManager)(ref em)).GetComponentData<CastleRoom>(entity); if (!((CastleRoom)(ref componentData)).IsEnclosedRoom) { return val; } val = (WorkstationLevel)(val | 1); if ((int)cw.MatchingFloorType != 0 && ((EntityManager)(ref em)).HasComponent<CastleRoomFloorsBuffer>(entity)) { DynamicBuffer<CastleRoomFloorsBuffer> buffer = ((EntityManager)(ref em)).GetBuffer<CastleRoomFloorsBuffer>(entity, true); if (buffer.Length > 0) { bool flag = true; bool flag2 = false; for (int i = 0; i < buffer.Length; i++) { Entity entity2 = buffer[i].FloorEntity._Entity; if (Util.IsNull(entity2) || !((EntityManager)(ref em)).Exists(entity2) || !((EntityManager)(ref em)).HasComponent<CastleFloor>(entity2)) { flag = false; break; } CastleFloorTypes floorType = ((EntityManager)(ref em)).GetComponentData<CastleFloor>(entity2).FloorType; if (floorType == cw.MatchingFloorType) { flag2 = true; } else if ((int)floorType != 13) { flag = false; break; } } if (flag && flag2) { val = (WorkstationLevel)(val | 2); } } } return val; } internal static bool EvaluateEntity(World world, EntityManager em, CastleBlockSystem cbs, Entity e, RuleSettings rules, string reason, Action<string> diag) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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_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_0022: 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_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_002a: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0054: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Expected I4, but got Unknown //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Expected I4, but got Unknown //IL_0281: 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_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Invalid comparison between Unknown and I4 //IL_00c1: 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_00c8: Invalid comparison between Unknown and I4 //IL_00fc: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) if (!IsEligibleWorkstation(em, e)) { return false; } CastleWorkstation componentData = ((EntityManager)(ref em)).GetComponentData<CastleWorkstation>(e); WorkstationLevel val = ComputeVanillaLevel(em, e, componentData); WorkstationLevel val2 = val; if (rules.Enabled) { bool flag = ((EntityManager)(ref em)).HasComponent<CastleSharedInventory>(e); TilePosition componentData2 = ((EntityManager)(ref em)).GetComponentData<TilePosition>(e); BoundsMinMax value = ((EntityManager)(ref em)).GetComponentData<TileBounds>(e).Value; FootprintResult footprintResult = FloorFootprintChecker.Evaluate(em, cbs, value, ((TilePosition)(ref componentData2)).HeightLevel, componentData.MatchingFloorType); bool hasFloor = (rules.AllowPartialFloorMatch ? footprintResult.AnyHasFloor : footprintResult.AllHaveFloor); bool flag2 = (rules.AllowPartialFloorMatch ? footprintResult.AnyMatchFloor : footprintResult.AllMatchFloor); if (flag) { if (rules.EnableTreasuryWithoutWalls && (int)componentData.MatchingFloorType > 0 && flag2) { val2 = (WorkstationLevel)(val2 | 2); } } else { if (rules.EnableStationFloorBonusWithoutWalls && (int)componentData.MatchingFloorType > 0 && flag2) { val2 = (WorkstationLevel)(val2 | 2); } if (rules.EnableSpeedBonusWithoutRoof) { Entity entity = ((EntityManager)(ref em)).GetComponentData<CastleHeartConnection>(e).CastleHeartEntity._Entity; if (QuestGate.IsCastleUnlocked(em, entity, rules.RequireBuildingACastleQuest) && SatisfiesSpeedFloorRequirement(rules.SpeedBonusFloorRequirement, componentData.MatchingFloorType, hasFloor, flag2)) { val2 = (WorkstationLevel)(val2 | 1); } } } } if (val2 == componentData.WorkstationLevel) { return false; } WorkstationLevel workstationLevel = componentData.WorkstationLevel; componentData.WorkstationLevel = val2; ((EntityManager)(ref em)).SetComponentData<CastleWorkstation>(e, componentData); if (_levelModEventTypes == null) { _levelModEventTypes = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadWrite<CastleWorkstationLevelModified>() }; } Entity val3 = ((EntityManager)(ref em)).CreateEntity(_levelModEventTypes); ((EntityManager)(ref em)).SetComponentData<CastleWorkstationLevelModified>(val3, new CastleWorkstationLevelModified { Workstation = e }); diag.Invoke($"[{reason}] {Util.Describe(world, em, e)}: {workstationLevel}({(int)workstationLevel}) -> {val2}({(int)val2}) (vanilla={val})"); return true; } private static bool SatisfiesSpeedFloorRequirement(SpeedFloorMode mode, CastleFloorTypes matchFloorType, bool hasFloor, bool matchFloor) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) return mode switch { SpeedFloorMode.AnyCastleFloor => hasFloor, SpeedFloorMode.MatchingFloorOnly => ((int)matchFloorType != 0) ? matchFloor : hasFloor, _ => true, }; } } internal static class ServerPart { private const string ServerConfigFileName = "com.zeeCameLsnake.CastleFreedom.Server.cfg"; private const float PollSeconds = 0.5f; private const int StreamPollIntervalFrames = 30; internal static ConfigFile ServerConfigFile; internal static ConfigEntry<bool> UseServerConfigOnly; internal static ConfigEntry<bool> LiveReload; internal static ConfigEntry<bool> ServerEnabled; internal static ConfigEntry<bool> ServerAllowPartialFloorMatch; internal static ConfigEntry<bool> ServerStationFloorBonusWithoutWalls; internal static ConfigEntry<bool> ServerTreasuryWithoutWalls; internal static ConfigEntry<bool> ServerSpeedBonusWithoutRoof; internal static ConfigEntry<bool> ServerRequireBuildingACastleQuest; internal static ConfigEntry<SpeedFloorMode> ServerSpeedBonusFloorRequirement; internal static ConfigEntry<bool> ServerLogDiagnostics; private static bool _isLocalHostedServer; private static ulong _localHostPlatformId; private static RuleSettings _serverRules; private static RuleSettings _activeRules; private static RuleSettings _lastAuthorizedClientRules; private static bool _hasAuthorizedClientRules; private static bool _hostClientOverrideActive; private static bool _clientDiagnostics; private static float _nextConfigPoll; private static System.DateTime _loadedWriteTime; private static System.DateTime _pendingWriteTime; private static bool _reloadErrorLogged; private static World _world; private static EntityQuery _activeWorkstationQuery; private static EntityQuery _allWorkstationQuery; private static EntityQuery _userQuery; private static bool _floorsDirty; private static bool _workstationsPreDirty; private static bool _initialEvalDone; private static int _nextStreamPollFrame; private static readonly HashSet<long> SeenActiveWorkstations = new HashSet<long>(); private static readonly HashSet<ulong> ModdedUsers = new HashSet<ulong>(); private static readonly HashSet<ulong> PendingReloadFeedback = new HashSet<ulong>(); private static readonly Dictionary<ulong, bool> ClientDiagByPlayer = new Dictionary<ulong, bool>(); private static readonly Dictionary<ulong, bool> ClientLiveReloadByPlayer = new Dictionary<ulong, bool>(); private static bool DiagEnabled => (ServerLogDiagnostics != null && ServerLogDiagnostics.Value) || (_isLocalHostedServer && _clientDiagnostics); internal static void Load() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown _isLocalHostedServer = Paths.ConfigPath.IndexOf("BepInEx_Server", (StringComparison)5) >= 0; BepInPlugin val = new BepInPlugin("com.zeeCameLsnake.CastleFreedom", "CastleFreedom", "1.0.0"); ServerConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.zeeCameLsnake.CastleFreedom.Server.cfg"), true, val); UseServerConfigOnly = ServerConfigFile.Bind<bool>("Server 1. Who decides", "UseServerConfigOnly", false, "Off (default): in Solo / Self-Hosted play (and for Server Admins), settings from the host/admin's client config sync live to the server; non-admin players can never override server rules. On: ignores all client configs (even from admins) and always uses section Server 2 below."); LiveReload = ServerConfigFile.Bind<bool>("Server 1. Who decides", "LiveReload", true, "Re-reads this server config file automatically about 0.5 s after saving and re-evaluates castle stations and containers live. If turned off, use .cf reload in chat (as admin or Solo host) to reload manually."); ServerEnabled = ServerConfigFile.Bind<bool>("Server 2. Server settings", "Enabled", true, "Master switch for Castle Freedom on this server. Off immediately restores vanilla enclosed-room requirements."); ServerAllowPartialFloorMatch = ServerConfigFile.Bind<bool>("Server 2. Server settings", "AllowPartialFloorMatch", true, "Applies to all floor checks (stations, Treasury chests, and floor-based speed modes). On (default): touching at least one matching floor tile counts. Off: the entire footprint must rest on the required floor tiles."); ServerStationFloorBonusWithoutWalls = ServerConfigFile.Bind<bool>("Server 2. Server settings", "EnableStationFloorBonusWithoutWalls", true, "Stations receive their Matching Floor bonus on matching floor tiles (no walls or roof needed)."); ServerTreasuryWithoutWalls = ServerConfigFile.Bind<bool>("Server 2. Server settings", "EnableTreasuryWithoutWalls", true, "Storage containers (CastleSharedInventory) receive the Treasury shared-inventory perk on Treasury floor tiles (no walls or roof needed)."); ServerSpeedBonusWithoutRoof = ServerConfigFile.Bind<bool>("Server 2. Server settings", "EnableSpeedBonusWithoutRoof", true, "Stations receive the Confined Room (+25% speed) bonus without walls or a roof once unlocked."); ServerRequireBuildingACastleQuest = ServerConfigFile.Bind<bool>("Server 2. Server settings", "Require Building a Castle Quest", true, "Requires the castle owner to have built an enclosed, roofed room at least once (\"Building a Castle\") before their castle stations gain the roof-free speed bonus."); ServerSpeedBonusFloorRequirement = ServerConfigFile.Bind<SpeedFloorMode>("Server 2. Server settings", "SpeedBonusFloorRequirement", SpeedFloorMode.None, "Floor required under an unwalled station for the roof-free speed bonus.\n(Stations inside a real enclosed room always keep their vanilla +25% speed bonus.)\n\n- None (default): Anywhere inside castle territory, even on bare ground.\n- AnyCastleFloor: Requires any castle floor tiles.\n- MatchingFloorOnly [STRICTER THAN VANILLA]: Optional balance tradeoff. Requires matching floor tiles (or any castle floor if the station has none).\n\nRespects AllowPartialFloorMatch."); ServerLogDiagnostics = ServerConfigFile.Bind<bool>("Server 3. Debug", "LogDiagnostics", false, "Logs station/container floor checks, quest unlock checks, WorkstationLevel updates, and Shared Inventory triggers to BepInEx_Server/LogOutput.log."); _serverRules = ReadServerConfigRules(); _activeRules = _serverRules; _loadedWriteTime = WriteTime(); _pendingWriteTime = _loadedWriteTime; Util.Log.LogInfo((object)("CastleFreedom v1.0.0 loaded (server part, " + (_isLocalHostedServer ? "local solo/hosted" : "dedicated") + $", UseServerConfigOnly={UseServerConfigOnly.Value}, {_activeRules.Describe()}).")); } private static RuleSettings ReadServerConfigRules() { return new RuleSettings { Enabled = ServerEnabled.Value, EnableStationFloorBonusWithoutWalls = ServerStationFloorBonusWithoutWalls.Value, EnableTreasuryWithoutWalls = ServerTreasuryWithoutWalls.Value, AllowPartialFloorMatch = ServerAllowPartialFloorMatch.Value, EnableSpeedBonusWithoutRoof = ServerSpeedBonusWithoutRoof.Value, RequireBuildingACastleQuest = ServerRequireBuildingACastleQuest.Value, SpeedBonusFloorRequirement = ServerSpeedBonusFloorRequirement.Value, LiveReload = LiveReload.Value, LogDiagnostics = ServerLogDiagnostics.Value }; } internal static void Diag(string text) { if (DiagEnabled) { Util.Log.LogInfo((object)("[Diag] " + text)); } } private static void EnsureQueries(World world) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0059: 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_006d: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a6: 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) if (_world != world) { _world = world; EntityManager entityManager = world.EntityManager; ComponentType[] array = (ComponentType[])(object)new ComponentType[4] { ComponentType.ReadOnly<CastleWorkstation>(), ComponentType.ReadOnly<CastleHeartConnection>(), ComponentType.ReadOnly<TilePosition>(), ComponentType.ReadOnly<TileBounds>() }; _activeWorkstationQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(array); _allWorkstationQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { new EntityQueryDesc { All = Il2CppStructArray<ComponentType>.op_Implicit(array), Options = (EntityQueryOptions)2 } }); _userQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() }); _floorsDirty = false; _workstationsPreDirty = false; _initialEvalDone = false; _nextStreamPollFrame = 0; _localHostPlatformId = 0uL; SeenActiveWorkstations.Clear(); ModdedUsers.Clear(); PendingReloadFeedback.Clear(); ClientDiagByPlayer.Clear(); ClientLiveReloadByPlayer.Clear(); QuestGate.Reset(); } } internal static void OnUserConnected(ServerBootstrapSystem sys, NetConnectionId connection) { //IL_0026: 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_0036: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_009b: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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) EnsureQueries(((ComponentSystemBase)sys).World); int num = sys._NetEndPointToApprovedUserIndex[connection]; Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)sys._ApprovedUsersLookup)[num].UserEntity; EntityManager entityManager = ((ComponentSystemBase)sys).EntityManager; User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity); if (_isLocalHostedServer && _localHostPlatformId == 0) { _localHostPlatformId = componentData.PlatformId; } FixedString512Bytes val = default(FixedString512Bytes); ((FixedString512Bytes)(ref val))..ctor(Protocol.BuildGreeting(_activeRules)); ServerChatUtils.SendSystemMessageToClient(((ComponentSystemBase)sys).EntityManager, componentData, ref val); Diag($"Greeted '{componentData.CharacterName}' (PlatformId={componentData.PlatformId}, Admin={componentData.IsAdmin}, LocalHost={componentData.PlatformId == _localHostPlatformId})."); } internal static void OnClientMessage(World world, EntityManager em, FromCharacter from, string body) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_001a: 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_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_0042: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) EnsureQueries(world); if (!((EntityManager)(ref em)).Exists(from.User) || !((EntityManager)(ref em)).HasComponent<User>(from.User)) { return; } User componentData = ((EntityManager)(ref em)).GetComponentData<User>(from.User); ModdedUsers.Add(componentData.PlatformId); if (_isLocalHostedServer && _localHostPlatformId == 0) { _localHostPlatformId = componentData.PlatformId; } string[] parts = body.Split(new char[1] { ' ' }, (StringSplitOptions)1); bool flag = default(bool); if (!Protocol.TryParseClientSet(parts, out var rules)) { ManualLogSource log = Util.Log; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Malformed client message from '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<FixedString64Bytes>(componentData.CharacterName); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(body); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); } log.LogWarning(val); return; } ClientDiagByPlayer[componentData.PlatformId] = rules.LogDiagnostics; ClientLiveReloadByPlayer[componentData.PlatformId] = rules.LiveReload; RecomputeClientDiagnosticsFlag(); bool flag2 = IsAuthorizedClient(componentData); bool flag3 = PendingReloadFeedback.Remove(componentData.PlatformId); if (!flag2) { Diag($"Ignored gameplay settings from non-admin/server-locked '{componentData.CharacterName}'; sending active server rules."); SendRulesToUser(em, componentData, _activeRules, serverOnly: true); if (flag3) { SendChatLine(em, componentData, "[CastleFreedom] <color=#55FF55>Client config reloaded</color> (server rules active; use " + Cyan(".cf status") + ")."); } return; } _lastAuthorizedClientRules = rules; _hasAuthorizedClientRules = true; _hostClientOverrideActive = true; bool flag4 = !_activeRules.GameplayEquals(rules); _activeRules = rules; ManualLogSource log2 = Util.Log; BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(18, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Settings from '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<FixedString64Bytes>(componentData.CharacterName); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(_activeRules.Describe()); } log2.LogInfo(val2); if (flag4) { EvaluateAll(world, em, includeDisabled: true, "clientSync"); BroadcastRulesToModdedClients(em, _activeRules, serverOnly: false); } else { SendRulesToUser(em, componentData, _activeRules, serverOnly: false); } if (flag3) { SendChatLine(em, componentData, _activeRules.Enabled ? ("[CastleFreedom] <color=#55FF55>Config reloaded.</color> Use " + Cyan(".cf status") + " to view active rules.") : ("[CastleFreedom] <color=#55FF55>Config reloaded</color> (Mod: " + OnOff(value: false) + ").")); } } private static bool IsAuthorizedClient(User user) { //IL_000d: 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) return !UseServerConfigOnly.Value && (user.IsAdmin || (_isLocalHostedServer && user.PlatformId == _localHostPlatformId)); } private static void RecomputeClientDiagnosticsFlag() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) bool clientDiagnostics = false; Enumerator<ulong, bool> enumerator = ClientDiagByPlayer.Values.GetEnumerator(); try { while (enumerator.MoveNext()) { if (enumerator.Current) { clientDiagnostics = true; break; } } } finally { ((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } _clientDiagnostics = clientDiagnostics; } private static string OnOff(bool value) { return value ? "<color=#55FF55>On</color>" : "<color=#FF5555>Off</color>"; } private static string Cyan(string text) { return "<color=#82C9D9>" + text + "</color>"; } private static void SendChatLine(EntityManager em, User user, string text) { //IL_0028: 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) if (text.Length > 500) { text = text.Substring(0, 500); } FixedString512Bytes val = default(FixedString512Bytes); ((FixedString512Bytes)(ref val))..ctor(text); ServerChatUtils.SendSystemMessageToClient(em, user, ref val); } private static void SendRulesToUser(EntityManager em, User user, RuleSettings rules, bool serverOnly) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) SendChatLine(em, user, "[[CastleFreedom]] " + Protocol.RulesWire(rules, serverOnly)); } private static void BroadcastRulesToModdedClients(EntityManager em, RuleSettings rules, bool serverOnly) { //IL_001a: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_003b: 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_0061: 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) if (ModdedUsers.Count == 0) { return; } NativeArray<Entity> val = ((EntityQuery)(ref _userQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { for (int i = 0; i < val.Length; i++) { User componentData = ((EntityManager)(ref em)).GetComponentData<User>(val[i]); if (componentData.IsConnected && ModdedUsers.Contains(componentData.PlatformId)) { SendRulesToUser(em, componentData, rules, serverOnly); } } } finally { val.Dispose(); } } private static void PollServerLiveReload(World world) { if (ServerConfigFile == null || !LiveReload.Value) { return; } float unscaledTime = Time.unscaledTime; if (unscaledTime < _nextConfigPoll) { return; } _nextConfigPoll = unscaledTime + 0.5f; System.DateTime dateTime = WriteTime(); if (!(dateTime == System.DateTime.MinValue) && !(dateTime == _loadedWriteTime)) { if (dateTime != _pendingWriteTime) { _pendingWriteTime = dateTime; } else { ReloadServerConfigFile(world, broadcast: true, "LiveReload"); } } } private static bool ReloadServerConfigFile(World world, bool broadcast, string sourceLabel) { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) if (ServerConfigFile == null) { return false; } bool value = UseServerConfigOnly.Value; RuleSettings serverRules = _serverRules; bool saveOnConfigSet = ServerConfigFile.SaveOnConfigSet; ServerConfigFile.SaveOnConfigSet = false; try { ServerConfigFile.Reload(); _loadedWriteTime = WriteTime(); _pendingWriteTime = _loadedWriteTime; _nextConfigPoll = Time.unscaledTime + 0.5f; _reloadErrorLogged = false; } catch (System.Exception ex) { if (!_reloadErrorLogged) { _reloadErrorLogged = true; Util.Log.LogWarning((object)("Server config reload failed: " + ex.Message)); } return false; } finally { ServerConfigFile.SaveOnConfigSet = saveOnConfigSet; } _serverRules = ReadServerConfigRules(); bool flag = UseServerConfigOnly.Value != value; bool flag2 = !_serverRules.GameplayEquals(serverRules); ManualLogSource log = Util.Log; bool flag3 = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(62, 4, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Server config reloaded ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(sourceLabel); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): UseServerConfigOnly="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(UseServerConfigOnly.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", LiveReload="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(LiveReload.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_serverRules.Describe()); } log.LogInfo(val); RuleSettings ruleSettings = _activeRules; bool value2 = UseServerConfigOnly.Value; if (UseServerConfigOnly.Value) { ruleSettings = _serverRules; } else if (flag && _hasAuthorizedClientRules) { ruleSettings = _lastAuthorizedClientRules; } else if (!_hostClientOverrideActive || flag2) { ruleSettings = _serverRules; } if (!_activeRules.GameplayEquals(ruleSettings) || flag) { _activeRules = ruleSettings; EvaluateAll(world, world.EntityManager, includeDisabled: true, "serverConfigReload"); if (broadcast) { BroadcastRulesToModdedClients(world.EntityManager, _activeRules, value2); } } return true; } internal static void HandleChatCommand(World world, EntityManager em, FromCharacter from, string rawText) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0445: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_0436: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017a: 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_0132: Unknown result type (might be due to invalid IL or missing references) EnsureQueries(world); if (!((EntityManager)(ref em)).Exists(from.User) || !((EntityManager)(ref em)).HasComponent<User>(from.User)) { return; } User componentData = ((EntityManager)(ref em)).GetComponentData<User>(from.User); if (_isLocalHostedServer && _localHostPlatformId == 0) { _localHostPlatformId = componentData.PlatformId; } string[] array = rawText.Split(new char[1] { ' ' }, (StringSplitOptions)1); string text = ((array.Length > 1) ? array[1].ToLowerInvariant() : "help"); if (text == "reload") { bool flag = ModdedUsers.Contains(componentData.PlatformId); bool flag2 = componentData.IsAdmin || (_isLocalHostedServer && componentData.PlatformId == _localHostPlatformId); if (flag2) { ReloadServerConfigFile(world, !flag || UseServerConfigOnly.Value, "manual .cf reload"); } if (flag) { PendingReloadFeedback.Add(componentData.PlatformId); SendChatLine(em, componentData, "[[CastleFreedom]] reload"); } else if (flag2) { SendChatLine(em, componentData, _activeRules.Enabled ? ("[CastleFreedom] <color=#55FF55>Server config reloaded.</color> Use " + Cyan(".cf status") + " to view active rules.") : ("[CastleFreedom] <color=#55FF55>Server config reloaded</color> (Mod: " + OnOff(value: false) + ").")); } else { SendChatLine(em, componentData, "[CastleFreedom] <color=#FF5555>Only server admins can reload the server config.</color>"); } } else if (text == "status") { CountUnwalledState(em, out var eligible, out var unwalledMatch, out var unwalledTreasury, out var unwalledSpeed); string text2 = (UseServerConfigOnly.Value ? "Server config" : (_hostClientOverrideActive ? "Client synced" : "Server defaults")); bool flag3 = default(bool); bool value = ((!UseServerConfigOnly.Value && _hostClientOverrideActive && ClientLiveReloadByPlayer.TryGetValue(componentData.PlatformId, ref flag3)) ? flag3 : LiveReload.Value); string text3 = $"{"[CastleFreedom] "}<color=#FFD479>Status</color> ({text2})\nMod: {OnOff(_activeRules.Enabled)} | Live Reload: {OnOff(value)} | Partial Floor: {OnOff(_activeRules.AllowPartialFloorMatch)}\nStation Floor: {OnOff(_activeRules.EnableStationFloorBonusWithoutWalls)} | Treasury: {OnOff(_activeRules.EnableTreasuryWithoutWalls)}\nSpeed (no roof): {OnOff(_activeRules.EnableSpeedBonusWithoutRoof)} (Quest: {OnOff(_activeRules.RequireBuildingACastleQuest)}, Floor: {Cyan(((object)_activeRules.SpeedBonusFloorRequirement/*cast due to .constrained prefix*/).ToString())})\nUnwalled: {Cyan($"{unwalledMatch} Station, {unwalledTreasury} Treasury, {unwalledSpeed} Speed")} ({eligible} total)"; SendChatLine(em, componentData, text3); } else { SendChatLine(em, componentData, $"{"[CastleFreedom] "}<color=#FFD479>Commands:</color>\n{Cyan(".cf status")}: Show active rules and unwalled station counts\n{Cyan(".cf reload")}: Reload config now (even if LiveReload is Off)\n{Cyan(".cf help")}: Show this command list"); } } private static void CountUnwalledState(EntityManager em, out int eligible, out int unwalledMatch, out int unwalledTreasury, out int unwalledSpeed) { //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_001e: 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) //IL_0031: 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: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Invalid comparison between Unknown and I4 //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Invalid comparison between Unknown and I4 //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_00a0: Unknown result type (might be due to invalid IL or missing references) eligible = 0; unwalledMatch = 0; unwalledTreasury = 0; unwalledSpeed = 0; NativeArray<Entity> val = ((EntityQuery)(ref _allWorkstationQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { for (int i = 0; i < val.Length; i++) { Entity val2 = val[i]; if (!WorkstationEvaluator.IsEligibleWorkstation(em, val2)) { continue; } eligible++; bool flag = false; if (((EntityManager)(ref em)).HasComponent<CastleRoomConnection>(val2)) { Entity entity = ((EntityManager)(ref em)).GetComponentData<CastleRoomConnection>(val2).RoomEntity._Entity; if (!Util.IsNull(entity) && ((EntityManager)(ref em)).Exists(entity) && ((EntityManager)(ref em)).HasComponent<CastleRoom>(entity)) { CastleRoom componentData = ((EntityManager)(ref em)).GetComponentData<CastleRoom>(entity); flag = ((CastleRoom)(ref componentData)).IsEnclosedRoom; } } if (flag) { continue; } WorkstationLevel workstationLevel = ((EntityManager)(ref em)).GetComponentData<CastleWorkstation>(val2).WorkstationLevel; bool flag2 = ((EntityManager)(ref em)).HasComponent<CastleSharedInventory>(val2); if ((workstationLevel & 2) > 0) { if (flag2) { unwalledTreasury++; } else { unwalledMatch++; } } if (!flag2 && (workstationLevel & 1) > 0) { unwalledSpeed++; } } } finally { val.Dispose(); } } private static System.DateTime WriteTime() { try { string configFilePath = ServerConfigFile.ConfigFilePath; return File.Exists(configFilePath) ? File.GetLastWriteTimeUtc(configFilePath) : System.DateTime.MinValue; } catch (System.Exception) { return System.DateTime.MinValue; } } internal static void OnCastleBlockPre(CastleBlockSystem sys) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_0035: 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) EnsureQueries(((ComponentSystemBase)sys).World); EventQueries floorQueries = sys._FloorQueries; int num = ((EntityQuery)(ref floorQueries.AddedQuery)).CalculateEntityCount(); floorQueries = sys._FloorQueries; int num2 = num + ((EntityQuery)(ref floorQueries.RemovedQuery)).CalculateEntityCount(); floorQueries = sys._FloorQueries; int num3 = num2 + ((EntityQuery)(ref floorQueries.UpdatedQuery)).CalculateEntityCount(); if (num3 > 0) { _floorsDirty = true; Diag($"Floor change detected (delta={num3})."); } } internal static void OnWorkstationsPre(CastleBuildingWorkstationsSystem sys) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_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) //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_0049: 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_0058: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) EnsureQueries(((ComponentSystemBase)sys).World); EntityQuery val = sys._AddedFloorsQuery; int num = ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._MovedFloorsQuery; int num2 = num + ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._AddedWorkstationsQuery; int num3 = num2 + ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._MovedWorkstationsQuery; int num4 = num3 + ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._RemovedWorkstationsQuery; int num5 = num4 + ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._HandleRoomEventsQuery; int num6 = num5 + ((EntityQuery)(ref val)).CalculateEntityCount(); val = sys._RecalculateWorkstationLevelQuery; int num7 = num6 + ((EntityQuery)(ref val)).CalculateEntityCount(); _workstationsPreDirty = num7 > 0; } internal static void OnWorkstationsPost(CastleBuildingWorkstationsSystem sys) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) EnsureQueries(((ComponentSystemBase)sys).World); if (_floorsDirty || _workstationsPreDirty) { bool includeDisabled = !_initialEvalDone; string reason = (_floorsDirty ? "floorChange" : "workstationSys"); _floorsDirty = false; _workstationsPreDirty = false; EvaluateAll(((ComponentSystemBase)sys).World, ((ComponentSystemBase)sys).EntityManager, includeDisabled, reason); } } internal static void OnAchievementActivity(World world, EntityManager em) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (world != null) { EnsureQueries(world); if (_activeRules.Enabled && _activeRules.EnableSpeedBonusWithoutRoof && _activeRules.RequireBuildingACastleQuest && QuestGate.CheckForNewUnlocks(em, Diag)) { EvaluateAll(world, em, includeDisabled: true, "questUnlock"); } } } internal static void Tick(World world) { //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_00c2: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_0090: Unknown result type (might be due to invalid IL or missing references) if (world == null) { return; } EnsureQueries(world); try { PollServerLiveReload(world); } catch (System.Exception ex) { Util.LogExceptionOnce("Server.LiveReload", ex); } EntityManager entityManager = world.EntityManager; if (!_initialEvalDone) { CastleBlockSystem existingSystemManaged = world.GetExistingSystemManaged<CastleBlockSystem>(); if (existingSystemManaged != null && existingSystemManaged._Floors.IsCreated && (existingSystemManaged._Floors.Count() > 0 || ((EntityQuery)(ref _activeWorkstationQuery)).CalculateEntityCount() > 0)) { EvaluateAll(world, entityManager, includeDisabled: true, "startupInit"); } } if (Time.frameCount >= _nextStreamPollFrame) { _nextStreamPollFrame = Time.frameCount + 30; PollNewlyActiveWorkstations(world, entityManager); } } private static void PollNewlyActiveWorkstations(World world, EntityManager em) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0033: 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_004a: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) CastleBlockSystem existingSystemManaged = world.GetExistingSystemManaged<CastleBlockSystem>(); if (existingSystemManaged == null || !existingSystemManaged._Floors.IsCreated) { return; } NativeArray<Entity> val = ((EntityQuery)(ref _activeWorkstationQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { int num = 0; int num2 = 0; for (int i = 0; i < val.Length; i++) { Entity e = val[i]; if (SeenActiveWorkstations.Add(Util.Key(e))) { num++; if (WorkstationEvaluator.EvaluateEntity(world, em, existingSystemManaged, e, _activeRules, "streamIn", Diag)) { num2++; } } } if (num2 > 0) { Diag($"Chunk stream-in evaluated {num} new active workstation(s), updated={num2}."); } } finally { val.Dispose(); } } private static void EvaluateAll(World world, EntityManager em, bool includeDisabled, string reason) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result