using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using DiceKingdoms.Game;
using DiceModders.ModCore;
using DiceModders.ModCore.Tools;
using DiceModders.UiKit;
using DiceModders.UiKit.Native;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Unity.Mathematics;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DiceModders")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Performance options for Dice Kingdoms: lighter battles, cheaper graphics, faster first loads on hard disks.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DiceModders.Optimization")]
[assembly: AssemblyTitle("DiceModders.Optimization")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace DiceModders.Optimization
{
internal static class AiPlacement
{
private const int Margin = 8;
private const int NormalSide = 49;
private static PatchSwitch _turn;
private static PatchSwitch _somewhere;
private static PatchSwitch _spiral;
private static int _town;
private static int _coast;
private static int _limit;
private static readonly Dictionary<IntPtr, int> CoastRing = new Dictionary<IntPtr, int>();
private static readonly Dictionary<IntPtr, bool> WaterTypes = new Dictionary<IntPtr, bool>();
internal static int CurrentLimit => _limit;
internal static void Install(Patcher patcher)
{
_turn = patcher.Switch("AIPlay", "BuildAndClean", typeof(AiPlacement), "TurnPrefix", "TurnPostfix");
_somewhere = patcher.Switch("AIPlay", "PlaceBuildingSomewhere", typeof(AiPlacement), "SomewherePrefix", "SomewherePostfix");
_spiral = patcher.Switch("SpiralGrid", "Enumerate", typeof(AiPlacement), "EnumeratePrefix", (string)null);
Options.AiSearchNearTown.SettingChanged += delegate
{
Refresh();
};
Match.Ended += CoastRing.Clear;
Match.Reset += CoastRing.Clear;
}
internal static void Refresh()
{
bool flag = Plugin.On && Options.AiSearchNearTown.Value;
_turn.On = flag;
_somewhere.On = flag;
_spiral.On = flag;
_town = (_limit = 0);
}
internal static bool TurnPrefix(BuildData data)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
if (!HasHammer(data))
{
return false;
}
_town = (_coast = (_limit = 0));
try
{
object obj;
if (data == null)
{
obj = null;
}
else
{
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)data).Island;
obj = ((island != null) ? island.grid : null);
}
IslandGrid val = (IslandGrid)obj;
if ((Object)(object)val == (Object)null)
{
return true;
}
int x = val.size.x;
if (x <= 49)
{
return true;
}
int num = (x - 1) / 2;
int num2 = 0;
Enumerator<Id, Building> enumerator = val.Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
if (!NeedsWater(current.type))
{
int2 position = current.transform.position;
num2 = Math.Max(num2, Math.Max(Math.Abs(position.x - num), Math.Abs(position.y - num)));
}
}
int num3 = Math.Max(49, 2 * (num2 + 8) + 1);
int num4 = Math.Max(num3, 2 * (NearestWater(val, num) + 8) + 1);
_town = ((num3 < x) ? num3 : 0);
_coast = ((num4 < x) ? num4 : 0);
_limit = _town;
}
catch (Exception ex)
{
_town = (_coast = (_limit = 0));
Plugin.L.LogWarning((object)("[ai] search area: " + ex.Message));
}
return true;
}
private static bool HasHammer(BuildData data)
{
//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)
try
{
object obj;
if (data == null)
{
obj = null;
}
else
{
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)data).Island;
obj = ((island != null) ? island.statistics : null);
}
return (Object)obj == (Object)null || ((PhaseData<BuildData, BuildIslandState>)(object)data).Island.statistics.Storage.stored.hammer >= 1;
}
catch (Exception)
{
return true;
}
}
internal static void TurnPostfix()
{
_town = (_coast = (_limit = 0));
}
private static int NearestWater(IslandGrid grid, int c)
{
if (CoastRing.TryGetValue(((Il2CppObjectBase)grid).Pointer, out var value))
{
return value;
}
value = c;
for (int i = 1; i <= c; i++)
{
if (value != c)
{
break;
}
for (int j = -i; j <= i; j++)
{
if (value != c)
{
break;
}
if (IsWater(grid, c + j, c - i) || IsWater(grid, c + j, c + i) || IsWater(grid, c - i, c + j) || IsWater(grid, c + i, c + j))
{
value = i;
}
}
}
CoastRing[((Il2CppObjectBase)grid).Pointer] = value;
return value;
}
private static bool IsWater(IslandGrid grid, int x, int y)
{
//IL_0003: 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_000e: Invalid comparison between Unknown and I4
return (int)grid.Ground(new int2(x, y)) == 0;
}
internal static void SomewherePrefix(BuildingType buildingType)
{
try
{
_limit = (NeedsWater(buildingType) ? _coast : _town);
}
catch (Exception)
{
_limit = 0;
}
}
private static bool NeedsWater(BuildingType type)
{
if (type == null)
{
return false;
}
if (WaterTypes.TryGetValue(((Il2CppObjectBase)type).Pointer, out var value))
{
return value;
}
Il2CppStructArray<int2> localPositionsInWater = type.localPositionsInWater;
value = localPositionsInWater != null && ((Il2CppArrayBase<int2>)(object)localPositionsInWater).Length > 0;
WaterTypes[((Il2CppObjectBase)type).Pointer] = value;
return value;
}
internal static void SomewherePostfix(bool __result)
{
_limit = _town;
}
internal static void EnumeratePrefix(ref int size)
{
if (_limit > 0 && size > _limit)
{
size = _limit;
}
}
}
internal static class AiSearch
{
private struct Layer
{
public unsafe byte* Items;
public int Width;
public int Height;
public int Stride;
public unsafe static Layer Of(byte* grid, int offset, int stride)
{
Layer result = new Layer
{
Stride = stride
};
IntPtr intPtr = *(IntPtr*)(grid + offset);
if (intPtr == IntPtr.Zero)
{
return result;
}
IntPtr intPtr2 = *(IntPtr*)((byte*)(void*)intPtr + 16);
result.Width = ((int*)(void*)intPtr)[6];
result.Height = ((int*)(void*)intPtr)[7];
if (intPtr2 != IntPtr.Zero)
{
result.Items = (byte*)(void*)intPtr2 + 32;
}
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe byte* At(int x, int y)
{
if (Items != null && x >= 0 && y >= 0 && x < Width && y < Height)
{
return Items + (y * Width + x) * Stride;
}
return null;
}
}
private sealed class Context
{
public unsafe byte* Grid;
public int Side;
public string TypeName = "?";
private Layer _ground;
private Layer _buildings;
private Layer _remains;
private Layer _nature;
private IntPtr _type;
private IntPtr _amplified;
private int[] _local;
private int[] _water;
private bool _anchorInWater;
private bool _hasProx;
private bool _isWonder;
private int _proxKind;
private int _proxNature;
private int _walls;
private int _minDist;
private int _health;
private int _bulk;
private int _sizeX;
private int _sizeY;
private int[] _typeCost = new int[8];
private int[] _tool = new int[8];
private int[] _wallCost = new int[8];
private HashSet<long> _reserved;
private Dictionary<int, IntPtr> _buildingTypes;
private static readonly HashSet<string> Said = new HashSet<string>();
private static readonly int[] Cos = new int[4] { 1, 0, -1, 0 };
private static readonly int[] Sin = new int[4] { 0, 1, 0, -1 };
private readonly List<long> _foot = new List<long>();
private readonly List<long> _ring = new List<long>();
private readonly HashSet<long> _footSet = new HashSet<long>();
private readonly HashSet<long> _ringSet = new HashSet<long>();
private readonly HashSet<long> _proxSet = new HashSet<long>();
private readonly int[] _cost = new int[8];
private readonly int[] _bestCost = new int[8];
public unsafe bool Init(IntPtr self, IntPtr data, IntPtr type, IntPtr wonder)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Expected O, but got Unknown
//IL_001e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0407: Expected I4, but got Unknown
//IL_0459: Unknown result type (might be due to invalid IL or missing references)
//IL_045e: Unknown result type (might be due to invalid IL or missing references)
//IL_0466: Unknown result type (might be due to invalid IL or missing references)
//IL_046d: Unknown result type (might be due to invalid IL or missing references)
//IL_0392: Unknown result type (might be due to invalid IL or missing references)
//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
AIPlay val = new AIPlay(self);
BuildingType val2 = new BuildingType(type);
BuildingTypes buildingTypes = val.buildingTypes;
_type = type;
TypeName = ((object)val2.name/*cast due to .constrained prefix*/).ToString();
_isWonder = ((Il2CppObjectBase)val2).TryCast<BuildingTypeWonder>() != null;
if (!_isWonder)
{
GameState gameState = ((PhaseData<BuildData, BuildIslandState>)new BuildData(data)).GameState;
if ((Object)(object)gameState == (Object)null)
{
return No("no game state");
}
int turnCounter = gameState.TurnCounter;
int turnCountLimit = val.configuration.turnCountLimit;
if (turnCounter <= turnCountLimit)
{
return No("turn " + turnCounter + " <= disease turn limit " + turnCountLimit);
}
}
IntPtr intPtr = *(IntPtr*)((byte*)(void*)data + 160);
if (intPtr == IntPtr.Zero)
{
return No("no island");
}
Grid = *(byte**)((byte*)(void*)intPtr + 152);
if (Grid == null)
{
return No("no grid");
}
_sizeX = ((int*)Grid)[60];
_sizeY = ((int*)(Grid + 240))[1];
_ground = Layer.Of(Grid, 312, 4);
_buildings = Layer.Of(Grid, 264, 8);
_remains = Layer.Of(Grid, 280, 8);
_nature = Layer.Of(Grid, 296, 8);
if (_ground.Items == null || _buildings.Items == null || _remains.Items == null || _nature.Items == null)
{
return No("a tile layer is missing");
}
_local = Positions(*(IntPtr*)((byte*)(void*)type + 24));
_water = Positions(*(IntPtr*)((byte*)(void*)type + 32));
if (_local.Length == 0)
{
return No("no footprint");
}
for (int i = 0; i < _water.Length; i += 2)
{
if (_water[i] == 0 && _water[i + 1] == 0)
{
_anchorInWater = true;
}
}
for (int j = 0; j < 8; j++)
{
_typeCost[j] = *(int*)((byte*)(void*)type + 88 + 4 * j);
_tool[j] = *(int*)((byte*)(void*)data + 184 + 4 * j);
}
_health = ((int*)(void*)type)[32];
BuildingType wall = buildingTypes.wall;
for (int k = 0; k < 8; k++)
{
_wallCost[k] = *(int*)((byte*)(void*)((Il2CppObjectBase)wall).Pointer + 88 + 4 * k);
}
_bulk = Math.Max(1, ((int*)(void*)((Il2CppObjectBase)wall).Pointer)[31]);
_walls = val.GetWallsThickness(val2);
_hasProx = val.HasProximity(val2);
_minDist = ((buildingTypes.farm != null && ((Il2CppObjectBase)buildingTypes.farm).Pointer == type) ? 15 : 0);
if (_hasProx)
{
if (((Il2CppObjectBase)val2).TryCast<BuildingTypeLandExtension>() != null)
{
_proxKind = 0;
}
else
{
BuildingTypeProducerAmplifier val3 = ((Il2CppObjectBase)val2).TryCast<BuildingTypeProducerAmplifier>();
if (val3 != null)
{
_proxKind = 1;
BuildingType amplifiedBuildingType = val3.AmplifiedBuildingType;
_amplified = ((amplifiedBuildingType != null) ? ((Il2CppObjectBase)amplifiedBuildingType).Pointer : IntPtr.Zero);
_buildingTypes = new Dictionary<int, IntPtr>();
Enumerator<Id, Building> enumerator = new IslandGrid((IntPtr)Grid).Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
Dictionary<int, IntPtr> buildingTypes2 = _buildingTypes;
int value = current.id.value;
BuildingType type2 = current.type;
buildingTypes2[value] = ((type2 != null) ? ((Il2CppObjectBase)type2).Pointer : IntPtr.Zero);
}
}
else
{
BuildingTypeProducerNature val4 = ((Il2CppObjectBase)val2).TryCast<BuildingTypeProducerNature>();
if (val4 == null)
{
return No("unknown neighbour-counting type " + TypeName);
}
_proxKind = 2;
_proxNature = (int)val4.natureTile;
}
}
}
if (wonder != IntPtr.Zero)
{
HashSet<int2> val5 = new HashSet<int2>(wonder);
if (val5.Count > 0)
{
_reserved = new HashSet<long>();
Enumerator<int2> enumerator2 = val5.GetEnumerator();
while (enumerator2.MoveNext())
{
int2 current2 = enumerator2.Current;
_reserved.Add(Key(current2.x, current2.y));
}
}
}
Side = Math.Max(_sizeX, _sizeY);
int currentLimit = AiPlacement.CurrentLimit;
if (currentLimit > 0 && currentLimit < Side)
{
Side = currentLimit;
}
return true;
}
private bool No(string why)
{
if (Said.Add(why))
{
Plugin.L.LogInfo((object)("[ai] game's search used: " + why));
}
return false;
}
private unsafe static int[] Positions(IntPtr array)
{
if (array == IntPtr.Zero)
{
return Array.Empty<int>();
}
int num = ((int*)(void*)array)[6];
int[] array2 = new int[num * 2];
int* ptr = (int*)(void*)array + 8;
for (int i = 0; i < num * 2; i++)
{
array2[i] = ptr[i];
}
return array2;
}
private static long Key(int x, int y)
{
return ((long)x << 32) | (uint)y;
}
private unsafe int Ground(int x, int y)
{
byte* ptr = _ground.At(x, y);
if (ptr != null)
{
return *(int*)ptr;
}
return 0;
}
private unsafe bool HasBuilding(int x, int y)
{
byte* ptr = _buildings.At(x, y);
if (ptr != null)
{
return *ptr != 0;
}
return false;
}
private unsafe int BuildingId(int x, int y)
{
byte* ptr = _buildings.At(x, y);
if (ptr == null || *ptr == 0)
{
return -1;
}
return ((int*)ptr)[1];
}
private unsafe bool HasRemains(int x, int y)
{
byte* ptr = _remains.At(x, y);
if (ptr != null)
{
return *ptr != 0;
}
return false;
}
private unsafe int Nature(int x, int y)
{
byte* ptr = _nature.At(x, y);
if (ptr == null || *ptr == 0)
{
return -1;
}
return ((int*)ptr)[1];
}
public unsafe void Run(byte* ret)
{
uint* ptr = (uint*)Grid + 63;
int num2;
int num = (num2 = (Math.Max(_sizeX, _sizeY) - 1) / 2);
bool flag = false;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
int num7 = num;
int num8 = num2;
int num9 = 1;
int num10 = 0;
int num11 = 0;
int num12 = 0;
bool flag2 = true;
while (true)
{
if (flag2)
{
flag2 = false;
}
else
{
if (num9 >= Side)
{
break;
}
num7 += num11 switch
{
2 => -1,
0 => 1,
_ => 0,
};
num8 += num11 switch
{
3 => -1,
1 => 1,
_ => 0,
};
if (++num12 >= num9)
{
num12 = 0;
num11 = (num11 + 1) & 3;
if (++num10 >= ((num9 == Side - 1) ? 3 : 2))
{
num9++;
num10 = 0;
}
}
}
int num13 = Ground(num7, num8);
bool num14;
if (!_anchorInWater)
{
if (num13 == 2)
{
goto IL_00ee;
}
num14 = num13 != 6;
}
else
{
num14 = num13 != 0;
}
if (num14)
{
continue;
}
goto IL_00ee;
IL_00ee:
uint num15 = *ptr;
int num16 = (int)((long)num15 * 4L >>> 32);
num15 ^= num15 << 13;
num15 ^= num15 >> 17;
num15 ^= num15 << 5;
*ptr = num15;
int num17 = 0;
while (num17 < 4)
{
if (Math.Abs(num7 - _sizeX / 2) + Math.Abs(num8 - _sizeY / 2) >= _minDist && TotalCost(num7, num8, num16))
{
int num18 = (_hasProx ? Proximity() : 0);
if (!flag || num18 > num3 || (num18 == num3 && Total(_cost) < Total(_bestCost)))
{
flag = true;
num3 = num18;
num4 = num7;
num5 = num8;
num6 = num16;
Array.Copy(_cost, _bestCost, 8);
}
if (!_hasProx && Same(_cost, _typeCost))
{
break;
}
}
num17++;
num16 = (num16 + 1) & 3;
}
}
for (int i = 0; i < 80; i++)
{
ret[i] = 0;
}
if (flag && (!_hasProx || num3 != 0))
{
*ret = 1;
*(IntPtr*)(ret + 8) = _type;
((int*)ret)[4] = num4;
((int*)ret)[5] = num5;
((int*)ret)[6] = num6;
((int*)ret)[7] = 0;
*(IntPtr*)(ret + 32) = IntPtr.Zero;
((int*)ret)[10] = _health;
((int*)ret)[11] = 0;
for (int j = 0; j < 8; j++)
{
*(int*)(ret + 48 + 4 * j) = _bestCost[j];
}
}
}
private static int Total(int[] c)
{
int num = 0;
for (int i = 0; i < 8; i++)
{
num += c[i];
}
return num;
}
private static bool Same(int[] a, int[] b)
{
for (int i = 0; i < 8; i++)
{
if (a[i] != b[i])
{
return false;
}
}
return true;
}
private bool TotalCost(int px, int py, int o)
{
_foot.Clear();
_footSet.Clear();
int num = Cos[o];
int num2 = Sin[o];
for (int i = 0; i < _local.Length; i += 2)
{
int num3 = _local[i];
int num4 = _local[i + 1];
long item = Key(px + num3 * num - num4 * num2, py + num3 * num2 + num4 * num);
if (_footSet.Add(item))
{
_foot.Add(item);
}
}
for (int j = 0; j < 8; j++)
{
_cost[j] = 0;
}
foreach (long item3 in _foot)
{
int num5 = (int)(item3 >> 32);
int num6 = (int)item3;
if (HasBuilding(num5, num6))
{
return false;
}
int num7 = Ground(num5, num6);
bool flag = false;
for (int k = 0; k < _water.Length; k += 2)
{
if (flag)
{
break;
}
int num8 = _water[k];
int num9 = _water[k + 1];
flag = px + num8 * num - num9 * num2 == num5 && py + num8 * num2 + num9 * num == num6;
}
bool num10;
if (!flag)
{
if (num7 == 2)
{
goto IL_016e;
}
num10 = num7 != 6;
}
else
{
num10 = num7 != 0;
}
if (num10)
{
return false;
}
goto IL_016e;
IL_016e:
if (!_isWonder && _reserved != null && _reserved.Contains(item3))
{
return false;
}
int num11 = Nature(num5, num6);
bool flag2 = false;
if (num11 >= 0 && num11 != 4)
{
if (num11 > 3)
{
return false;
}
flag2 = true;
}
if (HasRemains(num5, num6) || flag2)
{
for (int l = 0; l < 8; l++)
{
_cost[l] += _tool[l];
}
}
}
if (_walls > 0)
{
_ring.Clear();
_ringSet.Clear();
foreach (long item4 in _foot)
{
int num12 = (int)(item4 >> 32);
int num13 = (int)item4;
for (int m = -_walls; m <= _walls; m++)
{
for (int n = -_walls; n <= _walls; n++)
{
int x = num12 + n;
int y = num13 + m;
long item2 = Key(x, y);
if (_ringSet.Contains(item2) || _footSet.Contains(item2) || HasBuilding(x, y))
{
continue;
}
switch (Ground(x, y))
{
default:
return false;
case 2:
case 6:
{
int num14 = Nature(x, y);
if ((num14 >= 0 && num14 != 4) || HasRemains(x, y))
{
for (int num15 = 0; num15 < 8; num15++)
{
_cost[num15] += _tool[num15];
}
}
_ringSet.Add(item2);
_ring.Add(item2);
break;
}
case 1:
case 4:
break;
}
}
}
}
}
for (int num16 = 0; num16 < 8; num16++)
{
_cost[num16] += _typeCost[num16];
}
int num17 = ((_walls > 0) ? _ring.Count : 0);
int num18 = ((num17 >= 1) ? ((num17 - 1) / _bulk + 1) : 0);
for (int num19 = 0; num19 < 8; num19++)
{
_cost[num19] += _wallCost[num19] * num18;
}
return true;
}
private int Proximity()
{
_proxSet.Clear();
int num = 0;
foreach (long item2 in _foot)
{
int num2 = (int)(item2 >> 32);
int num3 = (int)item2;
for (int i = 0; i < 4; i++)
{
int x = num2 + i switch
{
2 => -1,
0 => 1,
_ => 0,
};
int y = num3 + i switch
{
3 => -1,
1 => 1,
_ => 0,
};
long item = Key(x, y);
if (!_footSet.Contains(item) && _proxSet.Add(item))
{
bool flag;
switch (_proxKind)
{
case 0:
{
int num5 = Ground(x, y);
bool flag2 = (uint)num5 <= 1u;
flag = flag2;
break;
}
case 1:
{
int num4 = BuildingId(x, y);
flag = num4 >= 0 && _buildingTypes.TryGetValue(num4, out var value) && value == _amplified && value != IntPtr.Zero;
break;
}
default:
flag = Nature(x, y) == _proxNature;
break;
}
if (flag)
{
num++;
}
}
}
}
return num;
}
}
private const int BuildDataIsland = 160;
private const int IslandGrid = 152;
private const int GridSize = 240;
private const int GridRandom = 252;
private const int GridBuildings = 264;
private const int GridRemains = 280;
private const int GridNature = 296;
private const int GridGround = 312;
private const int TypeLocal = 24;
private const int TypeLocalWater = 32;
private const int TypeCost = 88;
private const int TypeBulk = 124;
private const int TypeHealth = 128;
private const int DataToolCost = 184;
private const int NatureFlower = 4;
private static IntPtr _function;
private static readonly byte[] Original = new byte[12];
private static bool _patched;
internal static bool Verify;
internal static int Searches;
internal static int Fallbacks;
internal static int Mismatches;
private unsafe static delegate* unmanaged<IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> OriginalFn => (delegate* unmanaged<IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr>)(void*)_function;
internal static void Refresh()
{
bool flag = Plugin.On && Options.AiFastSearch.Value;
Verify = Options.AiFastSearchVerify.Value;
try
{
if (flag && !_patched)
{
Patch();
Plugin.L.LogInfo((object)("[ai] fast building search on" + (Verify ? " (verify mode: both searches run, the game's result is used)" : "")));
}
else if (!flag && _patched)
{
Unpatch();
}
}
catch (Exception ex)
{
Plugin.L.LogError((object)("[ai] fast search: " + ex.Message));
}
}
private unsafe static void Patch()
{
if (_function == IntPtr.Zero)
{
FieldInfo? field = typeof(AIPlay).GetField(Array.Find(typeof(AIPlay).GetFields(BindingFlags.Static | BindingFlags.NonPublic), (FieldInfo f) => f.Name.StartsWith("NativeMethodInfoPtr_WhereToPlaceBuilding_", StringComparison.Ordinal))?.Name ?? "", BindingFlags.Static | BindingFlags.NonPublic);
if (field == null)
{
throw new InvalidOperationException("WhereToPlaceBuilding not found in the interop");
}
_function = *(IntPtr*)(void*)(IntPtr)field.GetValue(null);
if (_function == IntPtr.Zero)
{
throw new InvalidOperationException("no native code for WhereToPlaceBuilding");
}
Marshal.Copy(_function, Original, 0, Original.Length);
}
byte[] array = new byte[12]
{
72, 184, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
};
BitConverter.GetBytes((long)(IntPtr)(delegate*<IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr>)(&Search)).CopyTo(array, 2);
array[10] = byte.MaxValue;
array[11] = 224;
Write(array);
_patched = true;
}
private static void Unpatch()
{
Write(Original);
_patched = false;
Plugin.L.LogInfo((object)"[ai] fast building search off");
}
private static void Write(byte[] code)
{
if (!VirtualProtect(_function, (UIntPtr)(ulong)code.Length, 64u, out var old))
{
throw new InvalidOperationException("VirtualProtect failed");
}
Marshal.Copy(code, 0, _function, code.Length);
VirtualProtect(_function, (UIntPtr)(ulong)code.Length, old, out var _);
FlushInstructionCache(GetCurrentProcess(), _function, (UIntPtr)(ulong)code.Length);
}
private unsafe static IntPtr CallOriginal(IntPtr ret, IntPtr self, IntPtr data, IntPtr type, IntPtr wonder, IntPtr method)
{
Write(Original);
try
{
return OriginalFn(ret, self, data, type, wonder, method);
}
finally
{
Patch();
}
}
[UnmanagedCallersOnly]
private unsafe static IntPtr Search(IntPtr ret, IntPtr self, IntPtr data, IntPtr type, IntPtr wonder, IntPtr method)
{
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
try
{
Searches++;
Context context = new Context();
if (!context.Init(self, data, type, wonder))
{
Fallbacks++;
return CallOriginal(ret, self, data, type, wonder, method);
}
if (!Verify)
{
context.Run((byte*)(void*)ret);
return ret;
}
uint* ptr = (uint*)context.Grid + 63;
uint num = *ptr;
byte* ptr2 = stackalloc byte[80];
context.Run(ptr2);
uint num2 = *ptr;
*ptr = num;
CallOriginal(ret, self, data, type, wonder, method);
bool flag = num2 == *ptr;
for (int i = 0; i < 80 && flag; i++)
{
if (ptr2[i] != ((byte*)(void*)ret)[i])
{
flag = false;
}
}
if (!flag)
{
Mismatches++;
ManualLogSource l = Plugin.L;
bool flag2 = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(60, 6, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ai-verify] DIFFERENT for ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(context.TypeName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (square ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(context.Side);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): fast ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Describe(ptr2));
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" rng ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(num2, "X8");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", game ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Describe((byte*)(void*)ret));
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" rng ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(*ptr, "X8");
}
l.LogWarning(val);
}
return ret;
}
catch (Exception ex)
{
Fallbacks++;
Plugin.L.LogWarning((object)("[ai] fast search failed, the game's search is used: " + ex.Message));
return CallOriginal(ret, self, data, type, wonder, method);
}
}
private unsafe static string Describe(byte* r)
{
if (*r != 0)
{
return $"({((int*)r)[4]},{((int*)r)[5]}) rot {((int*)r)[6]} cost {((int*)r)[12]}/{((int*)r)[13]}/{((int*)r)[14]}/{((int*)r)[15]}/{((int*)r)[16]}";
}
return "none";
}
[DllImport("kernel32.dll")]
private static extern bool VirtualProtect(IntPtr address, UIntPtr size, uint protect, out uint old);
[DllImport("kernel32.dll")]
private static extern bool FlushInstructionCache(IntPtr process, IntPtr address, UIntPtr size);
[DllImport("kernel32.dll")]
private static extern IntPtr GetCurrentProcess();
}
internal static class CombatEffects
{
private static PatchSwitch _particles;
private static PatchSwitch _update;
internal static void Install(Patcher patcher)
{
_particles = patcher.Switch("UnitVisual", "SpawnParticles", typeof(CombatEffects), "SpawnParticlesPrefix", (string)null);
_update = patcher.Switch("UnitVisual", "Update", typeof(CombatEffects), "UnitUpdatePrefix", (string)null);
Options.NoParticles.SettingChanged += delegate
{
Refresh();
};
Options.UnitUpdateEvery.SettingChanged += delegate
{
Refresh();
};
}
internal static void Refresh()
{
_particles.On = Plugin.On && Options.NoParticles.Value;
_update.On = Plugin.On && Options.UnitUpdateEvery.Value > 1;
}
internal static bool SpawnParticlesPrefix()
{
return false;
}
internal static bool UnitUpdatePrefix(object __instance)
{
int value = Options.UnitUpdateEvery.Value;
int num = (int)((long)Mem.PtrOf(__instance) >> 5);
return (Time.frameCount + num) % value == 0;
}
}
internal static class DiskWarmup
{
private struct MemoryStatus
{
public uint Length;
public uint Load;
public ulong TotalPhys;
public ulong AvailPhys;
public ulong TotalPage;
public ulong AvailPage;
public ulong TotalVirtual;
public ulong AvailVirtual;
public ulong AvailExtended;
}
private const long Chunk = 4194304L;
private const double FastDriveMBps = 400.0;
[DllImport("kernel32.dll")]
private static extern bool GlobalMemoryStatusEx(ref MemoryStatus status);
internal static void Install()
{
Civilizations.WhenGameDataLoaded((Action)Start);
}
private static void Start()
{
if (!Plugin.On || !Options.WarmUpFiles.Value)
{
return;
}
string data = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) ?? "", "Dice-Kingdoms_Data");
if (Directory.Exists(data))
{
Thread thread = new Thread((ThreadStart)delegate
{
Run(data);
});
thread.IsBackground = true;
thread.Priority = ThreadPriority.Lowest;
thread.Name = "Optimization warm-up";
thread.Start();
}
}
private static void Run(string data)
{
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Expected O, but got Unknown
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Expected O, but got Unknown
try
{
List<FileInfo> list = (from f in Directory.GetFiles(data, "*", SearchOption.AllDirectories)
select new FileInfo(f)).OrderByDescending(delegate(FileInfo f)
{
string extension = f.Extension;
return (extension == ".resS" || extension == ".resource") ? true : false;
}).ThenByDescending((FileInfo f) => f.Length).ToList();
long num = list.Sum((FileInfo f) => f.Length);
MemoryStatus status = new MemoryStatus
{
Length = (uint)Marshal.SizeOf<MemoryStatus>()
};
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val;
if (GlobalMemoryStatusEx(ref status) && (long)status.AvailPhys < num * 2)
{
ManualLogSource l = Plugin.L;
val = new BepInExInfoLogInterpolatedStringHandler(57, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("warm-up skipped: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(status.AvailPhys >> 20);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" MB free memory, the game files need ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(num >> 20);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" MB");
}
l.LogInfo(val);
return;
}
Stopwatch stopwatch = Stopwatch.StartNew();
byte[] array = new byte[4194304];
long num2 = 0L;
bool flag2 = false;
foreach (FileInfo item in list)
{
if (!Plugin.On || !Options.WarmUpFiles.Value)
{
return;
}
using FileStream fileStream = new FileStream(item.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 1, FileOptions.SequentialScan);
int num3;
while ((num3 = fileStream.Read(array, 0, array.Length)) > 0)
{
num2 += num3;
if (flag2 || num2 < 67108864)
{
continue;
}
flag2 = true;
double num4 = (double)num2 / 1048576.0 / Math.Max(0.001, stopwatch.Elapsed.TotalSeconds);
if (num4 > 400.0)
{
ManualLogSource l2 = Plugin.L;
val = new BepInExInfoLogInterpolatedStringHandler(52, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("warm-up stopped: fast drive (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(num4, "0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" MB/s), nothing to gain");
}
l2.LogInfo(val);
return;
}
}
}
ManualLogSource l3 = Plugin.L;
val = new BepInExInfoLogInterpolatedStringHandler(77, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("warm-up: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(num2 >> 20);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" MB of game files read in ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(stopwatch.Elapsed.TotalSeconds, "0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" s; the first match loads them from memory");
}
l3.LogInfo(val);
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("warm-up stopped: " + ex.Message));
}
}
}
internal static class Options
{
internal static ConfigEntry<bool> NoParticles;
internal static ConfigEntry<bool> WarmUpFiles;
internal static ConfigEntry<bool> AiSearchNearTown;
internal static ConfigEntry<bool> FastPlayerList;
internal static ConfigEntry<bool> AiFastSearch;
internal static ConfigEntry<bool> AiFastSearchVerify;
internal static ConfigEntry<int> UnitUpdateEvery;
internal static void Bind(ConfigFile config)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
NoParticles = config.Bind<bool>("Battles", "NoParticles", false, "Skip the parry / death / conversion particle effects of units.");
UnitUpdateEvery = config.Bind<int>("Battles", "UnitUpdateEveryNFrames", 1, new ConfigDescription("Update each unit's animation only every N-th frame (1 = every frame, the game's behaviour). Units still stand where the simulation puts them.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), Array.Empty<object>()));
AiSearchNearTown = config.Bind<bool>("Computer players", "SearchNearTown", false, "On islands bigger than the game's, computer players look for building spots around their town first and only search the whole island when nothing fits there. Without it the end of a build phase can freeze the game for a long time on big islands. Host only; normal islands are unchanged.");
AiFastSearch = config.Bind<bool>("Computer players", "FastBuildingSearch", false, "Computer players find their building spots with a faster search that follows the game's rules exactly (same spots, same order). Removes most of the pause at the end of every build phase with many computer players. Host only.");
AiFastSearchVerify = config.Bind<bool>("Computer players", "VerifyFastBuildingSearch", false, "Testing: run the fast search AND the game's search for every building and log any difference (the game's result is used). Slower.");
FastPlayerList = config.Bind<bool>("Interface", "FastPlayerList", false, "The player list on the left recomputes each player's attack, defence and population a few times a second instead of in every frame (the numbers can be up to a quarter of a second late). Saves several percent of frame time with many players on big islands.");
WarmUpFiles = config.Bind<bool>("Loading", "WarmUpGameFiles", false, "At the main menu, read the game's data files once in the background (lowest priority) so the first match loads from memory instead of a hard disk. Stops by itself on a fast drive (SSD) or when there is not enough free memory.");
}
}
[BepInPlugin("org.dicemodders.dicekingdoms.optimization", "DiceKingdoms Optimization", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Dice-Kingdoms.exe")]
public sealed class Plugin : BasePlugin
{
public const string Guid = "org.dicemodders.dicekingdoms.optimization";
public const string Name = "DiceKingdoms Optimization";
public const string Version = "1.0.0";
internal static ManualLogSource L;
internal static bool On;
public override void Load()
{
//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_0031: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
Tx.Load();
L = ((BasePlugin)this).Log;
Options.Bind(((BasePlugin)this).Config);
Patcher val = new Patcher("org.dicemodders.dicekingdoms.optimization", ((BasePlugin)this).Log);
CombatEffects.Install(val);
AiPlacement.Install(val);
SummaryCache.Install(val);
val.Summary();
Options.FastPlayerList.SettingChanged += delegate
{
SummaryCache.Refresh();
};
Options.AiFastSearch.SettingChanged += delegate
{
AiSearch.Refresh();
};
Options.AiFastSearchVerify.SettingChanged += delegate
{
AiSearch.Refresh();
};
DiskWarmup.Install();
Mods.Switch(((BasePlugin)this).Config, false, false, "Turns every option of this mod on or off at once.").WhenOn((Action)delegate
{
On = true;
Refresh();
}, (Action)delegate
{
On = false;
Refresh();
});
VideoSettings.Install(UiKit.CreateScope("org.dicemodders.dicekingdoms.optimization"));
}
private static void Refresh()
{
CombatEffects.Refresh();
AiPlacement.Refresh();
SummaryCache.Refresh();
AiSearch.Refresh();
}
}
internal static class SummaryCache
{
private const double MaxAge = 0.25;
private static PatchSwitch _row;
private static PatchSwitch _attack;
private static PatchSwitch _defense;
private static PatchSwitch _population;
private static bool _inRow;
private static readonly Dictionary<IntPtr, (double at, float value)> Attack = new Dictionary<IntPtr, (double, float)>();
private static readonly Dictionary<IntPtr, (double at, float value)> Defense = new Dictionary<IntPtr, (double, float)>();
private static readonly Dictionary<IntPtr, (double at, int value)> Population = new Dictionary<IntPtr, (double, int)>();
private static readonly Stopwatch Clock = Stopwatch.StartNew();
private static double Now => Clock.Elapsed.TotalSeconds;
internal static void Install(Patcher patcher)
{
_row = patcher.Switch("PlayerSummary", "Update", typeof(SummaryCache), "RowPrefix", "RowPostfix");
_attack = patcher.Switch("PowerConstants", "AttackPower", typeof(SummaryCache), "AttackPrefix", "AttackPostfix");
_defense = patcher.Switch("PowerConstants", "DefensePower", typeof(SummaryCache), "DefensePrefix", "DefensePostfix");
_population = patcher.Switch("IslandGrid", "get_Population", typeof(SummaryCache), "PopulationPrefix", "PopulationPostfix");
Match.PhaseEntered += delegate
{
Clear();
};
Match.PhaseSynced += delegate
{
Clear();
};
Match.Ended += Clear;
Match.Reset += Clear;
}
internal static void Refresh()
{
bool flag = Plugin.On && Options.FastPlayerList.Value;
PatchSwitch row = _row;
PatchSwitch attack = _attack;
PatchSwitch defense = _defense;
bool flag2 = (_population.On = flag);
bool flag4 = (defense.On = flag2);
bool flag6 = (attack.On = flag4);
row.On = flag6;
Clear();
}
private static void Clear()
{
Attack.Clear();
Defense.Clear();
Population.Clear();
}
private static bool Fresh(double at, IntPtr key)
{
return Now - at < 0.25 * (0.75 + 0.5 * (double)((key.ToInt64() >> 4) & 7) / 7.0);
}
internal static void RowPrefix()
{
_inRow = true;
}
internal static void RowPostfix()
{
_inRow = false;
}
internal static bool AttackPrefix(Island island, ref float __result)
{
return Use(Attack, island, ref __result);
}
internal static void AttackPostfix(Island island, float __result)
{
Store(Attack, island, __result);
}
internal static bool DefensePrefix(Island island, ref float __result)
{
return Use(Defense, island, ref __result);
}
internal static void DefensePostfix(Island island, float __result)
{
Store(Defense, island, __result);
}
internal static bool PopulationPrefix(IslandGrid __instance, ref int __result)
{
if (!_inRow || (Object)(object)__instance == (Object)null)
{
return true;
}
if (Population.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out (double, int) value) && Fresh(value.Item1, ((Il2CppObjectBase)__instance).Pointer))
{
__result = value.Item2;
return false;
}
return true;
}
internal static void PopulationPostfix(IslandGrid __instance, int __result)
{
if (_inRow && (Object)(object)__instance != (Object)null)
{
Population[((Il2CppObjectBase)__instance).Pointer] = (Now, __result);
}
}
private static bool Use(Dictionary<IntPtr, (double at, float value)> map, Island island, ref float result)
{
if (!_inRow || (Object)(object)island == (Object)null)
{
return true;
}
if (map.TryGetValue(((Il2CppObjectBase)island).Pointer, out (double, float) value) && Fresh(value.Item1, ((Il2CppObjectBase)island).Pointer))
{
result = value.Item2;
return false;
}
return true;
}
private static void Store(Dictionary<IntPtr, (double at, float value)> map, Island island, float result)
{
if (_inRow && (Object)(object)island != (Object)null)
{
map[((Il2CppObjectBase)island).Pointer] = (Now, result);
}
}
}
internal static class Tx
{
internal static TextSet Set;
internal static void Load()
{
Set = Texts.Load("texts.json", (string)null);
}
internal static string T(string key)
{
TextSet set = Set;
return ((set != null) ? set.Get(key) : null) ?? key;
}
internal static string T(string key, params object[] values)
{
TextSet set = Set;
return ((set != null) ? set.Get(key, values) : null) ?? key;
}
internal static SettingsBlockHandle Block(UiScope ui, Func<SettingsBlockSpec> spec)
{
if (ui == null)
{
return null;
}
SettingsBlockHandle handle = ui.Native.Settings.AddBlock(spec());
Texts.LanguageChanged += delegate
{
SettingsBlockHandle obj = handle;
if (obj != null)
{
((NativeHandle)obj).Dispose();
}
handle = ui.Native.Settings.AddBlock(spec());
};
return handle;
}
}
internal static class VideoSettings
{
internal static void Install(UiScope ui)
{
Tx.Block(ui, delegate
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
SettingsBlockSpec val = new SettingsBlockSpec();
val.set_Id("org.dicemodders.dicekingdoms.optimization.settings");
val.set_Page((SettingsPage)0);
val.set_Title(Tx.T("block.title"));
val.set_Order(10);
val.set_Build((Action<SettingsBlockHandle>)delegate(SettingsBlockHandle block)
{
Toggle(block, Tx.T("noParticles"), Options.NoParticles);
ConfigEntry<int> every = Options.UnitUpdateEvery;
SettingsRowHandle row = block.AddSlider(Tx.T("unitEvery"), 1f, 4f, (float)every.Value, (Action<float>)delegate(float v)
{
every.Value = (int)v;
}, "0", true);
if (row != null)
{
every.SettingChanged += delegate
{
row.SetValue(every.Value);
};
}
Toggle(block, Tx.T("warmUp"), Options.WarmUpFiles);
Toggle(block, Tx.T("fastPlayerList"), Options.FastPlayerList);
Toggle(block, Tx.T("aiNearTown"), Options.AiSearchNearTown);
Toggle(block, Tx.T("aiFast"), Options.AiFastSearch);
block.AddInfo(Tx.T("info"));
});
return val;
});
}
private static void Toggle(SettingsBlockHandle block, string label, ConfigEntry<bool> entry)
{
SettingsRowHandle row = block.AddToggle(label, entry.Value, (Action<bool>)delegate(bool v)
{
entry.Value = v;
});
if (row != null)
{
entry.SettingChanged += delegate
{
row.SetValue(entry.Value);
};
}
}
}
}