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.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using Expedition;
using GTFO.API;
using GTFR.Genetic;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using Prelude;
using SNetwork;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GTFRevolution")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyProduct("GTFRevolution")]
[assembly: AssemblyTitle("GTFRevolution")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
namespace Prelude
{
public abstract record Maybe<T>;
public record Nothing<T> : Maybe<T>;
public record Just<T>(T a) : Maybe<T>();
}
namespace FakeClosure
{
public class Env
{
}
public class FakeClosure<T>
{
private readonly MethodInfo methodInfo;
public FakeClosure(string methodName)
{
methodInfo = typeof(T).GetMethod(methodName) ?? throw new FakeClosureException("T", methodName);
}
}
public class FakeClosureException : Exception
{
public string TypeName { get; private set; }
public string MethodName { get; private set; }
public FakeClosureException(string typeName, string methodName)
{
TypeName = typeName;
MethodName = methodName;
}
}
}
namespace GTFR
{
internal struct BioScan
{
public uint id;
public int numScans;
public float difficulty;
public BioScan(uint id, int numScans, float diff)
{
this.id = id;
this.numScans = numScans;
difficulty = diff;
}
public BioScan(ChainedPuzzleDataBlock puzzle)
{
id = ((GameDataBlockBase<ChainedPuzzleDataBlock>)(object)puzzle).persistentID;
numScans = puzzle.ChainedPuzzle.Count;
difficulty = PuzzleDifficulty(puzzle);
}
public static float ScanDifficulty(uint scanType)
{
if (1 == 0)
{
}
float result;
switch (scanType)
{
case 3u:
result = -0.5f;
break;
case 5u:
case 8u:
case 14u:
result = 0.25f;
break;
case 6u:
case 20u:
result = 0.5f;
break;
case 25u:
case 26u:
case 27u:
case 28u:
case 29u:
result = 0.75f;
break;
case 13u:
case 16u:
case 32u:
result = 1f;
break;
case 15u:
result = 1.5f;
break;
case 33u:
case 34u:
case 35u:
case 36u:
case 37u:
result = 2f;
break;
case 17u:
case 18u:
result = 2f;
break;
case 40u:
case 44u:
result = 2f;
break;
default:
result = 0f;
break;
}
if (1 == 0)
{
}
return result;
}
public static float PuzzleDifficulty(ChainedPuzzleDataBlock puzzle)
{
float num = 0f;
Enumerator<ChainedPuzzleComponent> enumerator = puzzle.ChainedPuzzle.GetEnumerator();
while (enumerator.MoveNext())
{
ChainedPuzzleComponent current = enumerator.Current;
num += ScanDifficulty(current.PuzzleType);
}
return num;
}
public static bool IsInvalid(ChainedPuzzleDataBlock puzzle)
{
Enumerator<ChainedPuzzleComponent> enumerator = puzzle.ChainedPuzzle.GetEnumerator();
while (enumerator.MoveNext())
{
ChainedPuzzleComponent current = enumerator.Current;
bool flag;
switch (current.PuzzleType)
{
case 10u:
case 11u:
case 12u:
case 21u:
case 22u:
case 24u:
case 31u:
case 38u:
flag = true;
break;
default:
flag = false;
break;
}
if (flag)
{
return true;
}
}
return false;
}
}
internal class SortedBioScans
{
private readonly List<BioScan>[] bioscans;
private readonly Dictionary<uint, int> scanCounts;
private readonly Dictionary<uint, BioScan> scansById;
public SortedBioScans(ChainedPuzzleDataBlock[] scans)
{
bioscans = new List<BioScan>[15];
for (int i = 0; i < bioscans.Length; i++)
{
bioscans[i] = new List<BioScan>();
}
scanCounts = new Dictionary<uint, int>();
scansById = new Dictionary<uint, BioScan>();
bioscans[0].Add(new BioScan(0u, 1, 0f));
foreach (ChainedPuzzleDataBlock puzzle in scans)
{
if (!BioScan.IsInvalid(puzzle))
{
BioScan bioScan = new BioScan(puzzle);
bioscans[bioScan.numScans].Add(bioScan);
scanCounts[bioScan.id] = bioScan.numScans;
scansById[bioScan.id] = bioScan;
}
}
}
public float CreateScanInZone(Random random, ExpeditionZoneData zone, ExpeditionZoneData original)
{
uint chainedPuzzleToEnter = original.ChainedPuzzleToEnter;
float num2;
int num;
try
{
num = scanCounts[chainedPuzzleToEnter];
num2 = scansById[chainedPuzzleToEnter].difficulty;
}
catch (Exception)
{
num = 0;
num2 = 0f;
}
num = Math.Clamp(num + random.Next(5) - 2, 0, 14);
while (bioscans[num].Count == 0)
{
num--;
}
int index = random.Next(bioscans[num].Count);
BioScan bioScan = bioscans[num][index];
zone.ChainedPuzzleToEnter = bioScan.id;
return bioScan.difficulty - num2;
}
}
public class Configuration
{
public const string configSource = "GTFR.cfg";
public Configuration()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
string text = Path.Combine(Paths.ConfigPath, "GTFR.cfg");
ConfigFile val = new ConfigFile(text, true);
}
}
internal class DangerGraph
{
private static readonly float[] factors = new float[7] { 0f, 2f, 3f, 5f, 8f, 13f, 21f };
public readonly float[] graph;
private static readonly float[][] presets = new float[2][]
{
new float[6] { 2f, 5f, 11f, 3f, 8f, 11f },
new float[6] { 5f, 5f, 5f, 5f, 5f, 5f }
};
public DangerGraph(Random random, int numZones)
{
graph = new float[numZones];
float num = 0f;
for (int i = 0; i < numZones; i++)
{
float num2 = factors[random.Next(factors.Length)];
num += num2;
graph[i] = num2;
}
for (int j = 0; j < numZones; j++)
{
graph[j] /= factors[factors.Length - 1];
}
}
public override string ToString()
{
return string.Join(" ", graph);
}
}
internal class SortedEnemies
{
private struct Sample
{
public EnemyGroupDataBlock[] groups;
public float danger;
public Sample(Random random, int numGroups, List<EnemyGroupDataBlock> groups, float[,,] scoresByKind)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected I4, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected I4, but got Unknown
//IL_005f: 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_007a: Expected I4, but got Unknown
this.groups = (EnemyGroupDataBlock[])(object)new EnemyGroupDataBlock[numGroups];
danger = 0f;
for (int i = 0; i < numGroups; i++)
{
EnemyGroupDataBlock val = groups[random.Next(groups.Count)];
Enumerator<EnemyGroupCompositionData> enumerator = val.Roles.GetEnumerator();
while (enumerator.MoveNext())
{
EnemyGroupCompositionData current = enumerator.Current;
int num = (int)current.Role;
int num2 = (int)val.Difficulty;
danger += DistributionFactor(current.Distribution) * scoresByKind[(int)val.Type, num, num2];
}
this.groups[i] = val;
}
}
}
private const int numSamplesPerArea = 15;
private const int numGroupsPerArea = 5;
private const float maxAreaScore = 12f;
private const int numGroupTypes = 7;
private const int numRoleTypes = 11;
private const int numDifficultyTypes = 8;
private readonly List<EnemyGroupDataBlock> sleeperGroups;
private readonly List<EnemyGroupDataBlock> hunterGroups;
private readonly List<uint> canSpawnBigScary;
private readonly List<uint> canSpawnScout;
private readonly List<uint> canSpawnUltraBoss;
private readonly float[,,] scoresByKind;
public SortedEnemies(Il2CppArrayBase<EnemyDataBlock> enemyData, EnemyPopulationDataBlock populationData, Il2CppArrayBase<EnemyGroupDataBlock> groupData)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Expected I4, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected I4, but got Unknown
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Expected I4, but got Unknown
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Expected I4, but got Unknown
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_0315: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Invalid comparison between Unknown and I4
//IL_0322: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Invalid comparison between Unknown and I4
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Expected I4, but got Unknown
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
List<EnemyRoleData>[,] array = new List<EnemyRoleData>[11, 8];
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 8; j++)
{
array[i, j] = new List<EnemyRoleData>();
}
}
Enumerator<EnemyRoleData> enumerator = populationData.RoleDatas.GetEnumerator();
while (enumerator.MoveNext())
{
EnemyRoleData current = enumerator.Current;
if (current != null)
{
int num = (int)current.Role;
int num2 = (int)current.Difficulty;
array[num, num2].Add(current);
}
}
sleeperGroups = new List<EnemyGroupDataBlock>();
hunterGroups = new List<EnemyGroupDataBlock>();
scoresByKind = new float[7, 11, 8];
canSpawnBigScary = new List<uint>();
canSpawnScout = new List<uint>();
canSpawnUltraBoss = new List<uint>();
foreach (EnemyGroupDataBlock groupDatum in groupData)
{
uint persistentID = ((GameDataBlockBase<EnemyGroupDataBlock>)(object)groupDatum).persistentID;
if ((persistentID == 41 || persistentID == 69) ? true : false)
{
continue;
}
int num3 = 0;
Enumerator<EnemyGroupCompositionData> enumerator3 = groupDatum.Roles.GetEnumerator();
while (enumerator3.MoveNext())
{
EnemyGroupCompositionData current3 = enumerator3.Current;
int num4 = (int)current3.Role;
int num5 = (int)groupDatum.Difficulty;
List<EnemyRoleData> list = array[num4, num5];
if (list.Count == 0)
{
continue;
}
float num6 = 0f;
foreach (EnemyRoleData item in list)
{
switch (item.Enemy)
{
case 20u:
case 40u:
case 41u:
case 54u:
case 56u:
canSpawnScout.Add(((GameDataBlockBase<EnemyGroupDataBlock>)(object)groupDatum).persistentID);
break;
case 36u:
case 37u:
canSpawnBigScary.Add(((GameDataBlockBase<EnemyGroupDataBlock>)(object)groupDatum).persistentID);
break;
case 29u:
canSpawnBigScary.Add(((GameDataBlockBase<EnemyGroupDataBlock>)(object)groupDatum).persistentID);
break;
case 47u:
canSpawnUltraBoss.Add(((GameDataBlockBase<EnemyGroupDataBlock>)(object)groupDatum).persistentID);
break;
}
float num7 = groupDatum.MaxScore / item.Cost;
EnemyDataBlock block = GameDataBlockBase<EnemyDataBlock>.GetBlock(item.Enemy);
EnemyBalancingDataBlock block2 = GameDataBlockBase<EnemyBalancingDataBlock>.GetBlock(block.BalancingDataId);
float num8 = block2.Health.HealthMax / block2.Health.WeakspotDamageMulti;
float num9 = num8 * num7 * DistributionFactor(current3.Distribution);
num6 += num9;
}
scoresByKind[(int)groupDatum.Type, num4, num5] = (float)Math.Sqrt(num6 / (float)list.Count());
num3++;
}
if (num3 == 0)
{
continue;
}
eEnemyGroupType type = groupDatum.Type;
eEnemyGroupType val = type;
if (val - 4 > 1)
{
if ((int)val == 6)
{
hunterGroups.Add(groupDatum);
}
else
{
sleeperGroups.Add(groupDatum);
}
}
}
}
private static float DistributionFactor(eEnemyRoleDistribution distrib)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected I4, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
if (1 == 0)
{
}
float result = (int)distrib switch
{
0 => 0f,
1 => 1f,
8 => 0.05f,
7 => 0.1f,
6 => 0.15f,
2 => 0.25f,
3 => 0.5f,
4 => 0.75f,
5 => 1f,
_ => throw new Exception($"Got invalid relative distribution: {distrib}"),
};
if (1 == 0)
{
}
return result;
}
public float SpawnEnemiesInZone(ManualLogSource log, Random random, float factor, ExpeditionZoneData zone)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Expected O, but got Unknown
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: 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_01be: Expected O, but got Unknown
if (factor == 0f)
{
zone.EnemySpawningInZone = null;
return 0f;
}
int num = (int)zone.CoverageMinMax.x / 8;
float num2 = (float)num * 12f;
float target = factor * num2;
int num3 = 15 * num;
Sample[] array = new Sample[num3];
int num4 = 1;
int num5 = 5 * num;
for (int i = 0; i < num3; i++)
{
array[i] = new Sample(random, num4, sleeperGroups, scoresByKind);
num4 %= num5;
num4++;
}
List<Sample> list = array.OrderBy((Sample sample) => Math.Abs(sample.danger - target)).ToList();
Sample sample2 = list[random.Next(5)];
List<EnemySpawningData> val = new List<EnemySpawningData>();
EnemyGroupDataBlock[] groups = sample2.groups;
foreach (EnemyGroupDataBlock val2 in groups)
{
EnemySpawningData val3 = new EnemySpawningData();
val3.Difficulty = val2.Difficulty;
val3.GroupType = val2.Type;
if (canSpawnBigScary.Contains(((GameDataBlockBase<EnemyGroupDataBlock>)(object)val2).persistentID))
{
val3.Distribution = (eEnemyZoneDistribution)1;
val3.DistributionValue = 1f;
}
else if (canSpawnScout.Contains(((GameDataBlockBase<EnemyGroupDataBlock>)(object)val2).persistentID))
{
val3.Distribution = (eEnemyZoneDistribution)1;
val3.DistributionValue = 1f;
}
else
{
val3.Distribution = (eEnemyZoneDistribution)2;
val3.DistributionValue = (float)Math.Sqrt(factor);
}
val.Add(val3);
}
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(16, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Zone ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(zone.AliasOverride);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": danger: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>((int)(100f * sample2.danger / num2));
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("%");
}
log.LogInfo(val4);
zone.EnemySpawningInZone = val;
return sample2.danger / (0.2f * num2);
}
public void CreateBloodDoorInZone(Random random, ExpeditionZoneData zone)
{
}
}
internal class FunnyResources : MonoBehaviour
{
private delegate void GiveAmmoEvent(PlayerAmmoStorage playerStorage, ref AmmoType ammoType);
private delegate void UpdateAmmoPackEvent(ref int bulletCount);
private static event GiveAmmoEvent OnGiveAmmo;
private static event UpdateAmmoPackEvent OnUpdateAmmoPack;
public static void CallOnGiveAmmo(PlayerAmmoStorage __instance, ref AmmoType ammoType, ref int bulletCount)
{
FunnyResources.OnGiveAmmo(__instance, ref ammoType);
}
public static void CallOnUpdateAmmoPack(PlayerAmmoStorage __instance, ref AmmoType ammoType, ref int bulletCount, ref float __result)
{
FunnyResources.OnUpdateAmmoPack(ref bulletCount);
}
public static void UncapResourcePacks()
{
ExpeditionBalanceDataBlock block = GameDataBlockBase<ExpeditionBalanceDataBlock>.GetBlock(1u);
List<float> resourcePackSizes = block.ResourcePackSizes;
resourcePackSizes[0] = resourcePackSizes[0] * 2f;
resourcePackSizes = block.ResourcePackSizes;
resourcePackSizes[1] = resourcePackSizes[1] * 2f;
resourcePackSizes = block.ResourcePackSizes;
resourcePackSizes[2] = resourcePackSizes[2] * 2f;
block.ResourcePackSizes.Add(2.4f);
block.ResourcePackSizes.Add(3f);
block.ResourcePackSizes.Add(3.2f);
block.ResourcePackSizes.Add(4f);
OnGiveAmmo += delegate(PlayerAmmoStorage playerStorage, ref AmmoType ammoType)
{
InventorySlotAmmo ammoPack = ((Il2CppArrayBase<InventorySlotAmmo>)(object)playerStorage.m_ammoStorage)[(int)ammoType];
float current = ammoPack.AmmoInPack;
FunnyResources.OnUpdateAmmoPack = delegate(ref int bulletCount)
{
float num = (float)bulletCount * ammoPack.CostOfBullet;
ammoPack.AmmoInPack = current + num;
playerStorage.UpdateAllAmmoUI();
};
};
}
public static void FakeClosurePatch(Harmony harmony)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
ClassInjector.RegisterTypeInIl2Cpp<FunnyResources>();
harmony.Patch((MethodBase)typeof(PlayerAmmoStorage).GetMethod("UpdateBulletsInPack"), new HarmonyMethod(typeof(FunnyResources).GetMethod("CallOnGiveAmmo")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)typeof(PlayerAmmoStorage).GetMethod("UpdateBulletsInPack"), (HarmonyMethod)null, new HarmonyMethod(typeof(FunnyResources).GetMethod("CallOnUpdateAmmoPack")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
static FunnyResources()
{
FunnyResources.OnGiveAmmo = delegate
{
};
FunnyResources.OnUpdateAmmoPack = delegate
{
};
}
}
internal class FunnyRundown : MonoBehaviour
{
private static readonly float[] coverages;
private static event Action OnStartLevelBuild;
public static void CallOnStartLevelBuild()
{
FunnyRundown.OnStartLevelBuild();
}
internal static void CreateFunnyRundown(ManualLogSource log, VanillaLevels vanilla, SortedBioScans bioscans)
{
OnStartLevelBuild += delegate
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Expected I4, but got Unknown
ExpeditionInTierData activeExpedition = RundownManager.ActiveExpedition;
Random random = new Random(activeExpedition.SessionSeed);
LevelLayoutDataBlock block = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition.LevelLayoutData);
List<ExpeditionZoneData> zones = vanilla.OriginalLayoutOf(((GameDataBlockBase<LevelLayoutDataBlock>)(object)block).name).Zones;
List<ExpeditionZoneData> zones2 = block.Zones;
uint complexResourceData = activeExpedition.Expedition.ComplexResourceData;
ComplexResourceSetDataBlock block2 = GameDataBlockBase<ComplexResourceSetDataBlock>.GetBlock(complexResourceData);
Geomorphs geomorphs = new Geomorphs(block2);
DangerGraph dangerGraph = new DangerGraph(random, zones2.Count);
ManualLogSource val = log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Danger Graph: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(dangerGraph.ToString());
}
val.LogInfo(val2);
DesignFloorPlan(log, random, zones2);
InteriorDecorating(log, random, geomorphs, zones2, zones);
Enumerator<ExpeditionZoneData> enumerator = zones2.GetEnumerator();
while (enumerator.MoveNext())
{
ExpeditionZoneData current = enumerator.Current;
current.AliasOverride = block.ZoneAliasStart + current.LocalIndex;
}
Il2CppArrayBase<EnemyDataBlock> allBlocks = GameDataBlockBase<EnemyDataBlock>.GetAllBlocks();
EnemyPopulationDataBlock block3 = GameDataBlockBase<EnemyPopulationDataBlock>.GetBlock(1u);
Il2CppArrayBase<EnemyGroupDataBlock> allBlocks2 = GameDataBlockBase<EnemyGroupDataBlock>.GetAllBlocks();
SortedEnemies enemies = new SortedEnemies(allBlocks, block3, allBlocks2);
float num = 0f;
float allowedTotalCost = EnemyCostManager.AllowedTotalCost;
num += InviteGuests(log, random, enemies, dangerGraph, zones2);
num += PlanActivities(log, random, enemies, bioscans, zones2, zones);
num += 3f * (EnemyCostManager.AllowedTotalCost - allowedTotalCost) / 100f;
num /= (float)zones.Count;
DistributeSnacks(num, zones2, zones);
log.LogInfo((object)"A funny rundown awaits you!");
};
}
private static void DesignFloorPlan(ManualLogSource log, Random random, List<ExpeditionZoneData> zones)
{
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
log.LogInfo((object)"Designing floor plan");
List<int> list = new List<int>();
Enumerator<ExpeditionZoneData> enumerator = zones.GetEnumerator();
while (enumerator.MoveNext())
{
ExpeditionZoneData current = enumerator.Current;
list.Add(0);
}
for (int i = 0; i < zones.Count - 1; i++)
{
int num = ((i >= 3) ? random.Next(i - 2, i) : random.Next(i));
if (list[num] < 2)
{
list[num]++;
zones[i].BuildFromLocalIndex = (eLocalZoneIndex)num;
float num2 = coverages[random.Next(coverages.Length)];
zones[i].CoverageMinMax = new Vector2(num2, num2);
}
}
}
private static void InteriorDecorating(ManualLogSource log, Random random, Geomorphs geomorphs, List<ExpeditionZoneData> zones, List<ExpeditionZoneData> originalZones)
{
log.LogInfo((object)"Interior decorating");
for (int i = 0; i < zones.Count - 1; i++)
{
zones[i].CustomGeomorph = geomorphs.RandomGeomorph(random, originalZones[i]);
zones[i].SubComplex = (SubComplex)5;
}
}
private static float InviteGuests(ManualLogSource log, Random random, SortedEnemies enemies, DangerGraph dangerGraph, List<ExpeditionZoneData> zones)
{
log.LogInfo((object)"Inviting guests");
float num = 0f;
for (int i = 0; i < zones.Count; i++)
{
num += enemies.SpawnEnemiesInZone(log, random, dangerGraph.graph[i], zones[i]);
}
return num;
}
private static float PlanActivities(ManualLogSource log, Random random, SortedEnemies enemies, SortedBioScans bioscans, List<ExpeditionZoneData> zones, List<ExpeditionZoneData> originals)
{
log.LogInfo((object)"Planning activities");
float num = 0f;
for (int i = 0; i < zones.Count - 1; i++)
{
if (i > 0)
{
num += bioscans.CreateScanInZone(random, zones[i], originals[i]);
}
}
return num / 2f;
}
private static void DistributeSnacks(float danger, List<ExpeditionZoneData> zones, List<ExpeditionZoneData> originals)
{
for (int i = 0; i < zones.Count; i++)
{
zones[i].ToolAmmoMulti = danger * originals[i].ToolAmmoMulti;
zones[i].WeaponAmmoMulti = danger * originals[i].WeaponAmmoMulti;
zones[i].HealthMulti = danger * originals[i].HealthMulti;
zones[i].DisinfectionMulti = danger * originals[i].DisinfectionMulti;
}
}
public static void FakeClosurePatch(Harmony harmony)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
ClassInjector.RegisterTypeInIl2Cpp<FunnyRundown>();
harmony.Patch((MethodBase)typeof(Builder).GetMethod("Build"), new HarmonyMethod(typeof(FunnyRundown).GetMethod("CallOnStartLevelBuild")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
static FunnyRundown()
{
FunnyRundown.OnStartLevelBuild = delegate
{
};
coverages = new float[7] { 8f, 16f, 24f, 32f, 40f, 48f, 64f };
}
}
public class GeneticEnemies
{
public record Phenotype(double penalty, double score, eEnemyGroupType group, eEnemyRoleDifficulty role, eEnemyZoneDistribution distribution, float distributionValue)
{
[CompilerGenerated]
protected virtual bool PrintMembers(StringBuilder builder)
{
//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_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_00af: 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)
RuntimeHelpers.EnsureSufficientExecutionStack();
builder.Append("penalty = ");
builder.Append(penalty.ToString());
builder.Append(", score = ");
builder.Append(score.ToString());
builder.Append(", group = ");
eEnemyGroupType val = group;
builder.Append(((object)(eEnemyGroupType)(ref val)).ToString());
builder.Append(", role = ");
eEnemyRoleDifficulty val2 = role;
builder.Append(((object)(eEnemyRoleDifficulty)(ref val2)).ToString());
builder.Append(", distribution = ");
eEnemyZoneDistribution val3 = distribution;
builder.Append(((object)(eEnemyZoneDistribution)(ref val3)).ToString());
builder.Append(", distributionValue = ");
builder.Append(distributionValue.ToString());
return true;
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyGroupType group, out eEnemyRoleDifficulty role, out eEnemyZoneDistribution distribution, out float distributionValue)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected I4, but got Unknown
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected I4, but got Unknown
penalty = this.penalty;
score = this.score;
group = (eEnemyGroupType)(int)this.group;
role = (eEnemyRoleDifficulty)(int)this.role;
distribution = (eEnemyZoneDistribution)(int)this.distribution;
distributionValue = this.distributionValue;
}
}
public record Hunter : Phenotype
{
public int persistentID { get; init; }
public Hunter(double penalty, double score, int persistentID, eEnemyRoleDifficulty role)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
this.persistentID = persistentID;
base..ctor(penalty, score, (eEnemyGroupType)6, role, (eEnemyZoneDistribution)1, 1f);
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out int persistentID, out eEnemyRoleDifficulty role)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
persistentID = this.persistentID;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record Sleeper : Phenotype
{
public Sleeper(double penalty, double score, eEnemyRoleDifficulty role)
: base(penalty, score, (eEnemyGroupType)0, role, (eEnemyZoneDistribution)2, 1f)
{
}//IL_0004: Unknown result type (might be due to invalid IL or missing references)
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyRoleDifficulty role)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record Scout : Phenotype
{
public Scout(double penalty, double score, eEnemyRoleDifficulty role)
: base(penalty, score, (eEnemyGroupType)3, role, (eEnemyZoneDistribution)1, 1f)
{
}//IL_0004: Unknown result type (might be due to invalid IL or missing references)
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyRoleDifficulty role)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record Hybrid : Phenotype
{
public Hybrid(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)1, (eEnemyRoleDifficulty)6, (eEnemyZoneDistribution)2, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record Charger : Phenotype
{
public Charger(double penalty, double score, eEnemyRoleDifficulty role)
: base(penalty, score, (eEnemyGroupType)2, role, (eEnemyZoneDistribution)2, 1f)
{
}//IL_0004: Unknown result type (might be due to invalid IL or missing references)
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyRoleDifficulty role)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record ChargerScout : Phenotype
{
public ChargerScout(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)3, (eEnemyRoleDifficulty)3, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record Shadow : Phenotype
{
public Shadow(double penalty, double score, eEnemyRoleDifficulty role)
: base(penalty, score, (eEnemyGroupType)0, role, (eEnemyZoneDistribution)2, 1f)
{
}//IL_0004: Unknown result type (might be due to invalid IL or missing references)
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyRoleDifficulty role)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record ShadowScout : Phenotype
{
public ShadowScout(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)3, (eEnemyRoleDifficulty)4, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record Nightmare : Phenotype
{
public Nightmare(double penalty, double score, eEnemyRoleDifficulty role)
: base(penalty, score, (eEnemyGroupType)2, role, (eEnemyZoneDistribution)2, 1f)
{
}//IL_0004: Unknown result type (might be due to invalid IL or missing references)
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score, out eEnemyRoleDifficulty role)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected I4, but got Unknown
penalty = base.penalty;
score = base.score;
role = (eEnemyRoleDifficulty)(int)base.role;
}
}
private record NightmareScout : Phenotype
{
public NightmareScout(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)3, (eEnemyRoleDifficulty)7, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record Tank : Phenotype
{
public Tank(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)1, (eEnemyRoleDifficulty)5, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record Mother : Phenotype
{
public Mother(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)1, (eEnemyRoleDifficulty)2, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
private record PMother : Phenotype
{
public PMother(double penalty, double score)
: base(penalty, score, (eEnemyGroupType)1, (eEnemyRoleDifficulty)3, (eEnemyZoneDistribution)1, 1f)
{
}
[CompilerGenerated]
public void Deconstruct(out double penalty, out double score)
{
penalty = base.penalty;
score = base.score;
}
}
public static void NextEnemy(ChromosomeReader reader, GeneticZone zone)
{
(string, Phenotype)[] array = new(string, Phenotype)[35]
{
("Sleepers Easy", new Sleeper(1.05, 0.0, (eEnemyRoleDifficulty)0)),
("Sleepers Medium", new Sleeper(1.05, 0.0, (eEnemyRoleDifficulty)1)),
("Sleepers Hard", new Sleeper(1.08, 0.0, (eEnemyRoleDifficulty)2)),
("Hybrids", new Hybrid(1.1, 0.0)),
("Scouts Easy", new Scout(1.08, 0.0, (eEnemyRoleDifficulty)0)),
("Scouts Medium", new Scout(1.07, 0.0, (eEnemyRoleDifficulty)1)),
("Scouts Hard", new Scout(1.1, 0.0, (eEnemyRoleDifficulty)2)),
("Chargers Easy", new Charger(1.05, 0.0, (eEnemyRoleDifficulty)0)),
("Chargers Medium", new Charger(1.06, 0.0, (eEnemyRoleDifficulty)1)),
("Charger Giant", new Charger(1.1, 0.0, (eEnemyRoleDifficulty)2)),
("Charger Scout", new ChargerScout(1.08, 0.0)),
("Shadows", new Shadow(1.08, 0.0, (eEnemyRoleDifficulty)6)),
("Shadow Giants", new Shadow(1.1, 0.0, (eEnemyRoleDifficulty)7)),
("Shadow Scout", new ShadowScout(1.1, 0.0)),
("Nightmare Strikers", new Nightmare(1.05, 0.0, (eEnemyRoleDifficulty)6)),
("Nightmare Shooters", new Nightmare(1.06, 0.0, (eEnemyRoleDifficulty)7)),
("Nightmare Scout", new NightmareScout(1.17, 0.0)),
("Tank", new Tank(1.25, 0.0)),
("Mother", new Mother(1.2, 0.0)),
("P-Mother", new PMother(1.3, 0.0)),
("BD Easy", new Hunter(1.1, 0.0, 30, (eEnemyRoleDifficulty)0)),
("BD Easy", new Hunter(1.1, 0.0, 76, (eEnemyRoleDifficulty)0)),
("BD Giant", new Hunter(1.12, 0.0, 74, (eEnemyRoleDifficulty)7)),
("BD Hybrid Easy", new Hunter(1.13, 0.0, 31, (eEnemyRoleDifficulty)0)),
("BD Hybrid Easy", new Hunter(1.13, 0.0, 51, (eEnemyRoleDifficulty)0)),
("BD Hybrid Medium", new Hunter(1.14, 0.0, 33, (eEnemyRoleDifficulty)0)),
("BD Chargers Easy", new Hunter(1.12, 0.0, 32, (eEnemyRoleDifficulty)0)),
("BD Chargers Easy", new Hunter(1.12, 0.0, 72, (eEnemyRoleDifficulty)0)),
("BD Shadows Easy", new Hunter(1.13, 0.0, 77, (eEnemyRoleDifficulty)0)),
("BD Shadows Medium", new Hunter(1.15, 0.0, 35, (eEnemyRoleDifficulty)0)),
("BD Shadows Medium", new Hunter(1.15, 0.0, 78, (eEnemyRoleDifficulty)0)),
("BD Mother", new Hunter(1.2, 0.0, 36, (eEnemyRoleDifficulty)2)),
("BD Mother", new Hunter(1.2, 0.0, 49, (eEnemyRoleDifficulty)2)),
("BD P-Mother", new Hunter(1.3, 0.0, 47, (eEnemyRoleDifficulty)3)),
("BD Tank", new Hunter(1.25, 0.0, 46, (eEnemyRoleDifficulty)5))
};
Maybe<(string, Phenotype)> maybe = reader.Match(new(string, (string, Phenotype))[33]
{
("00000", array[0]),
("00001", array[1]),
("00010", array[2]),
("00011", array[3]),
("00100", array[4]),
("00101", array[5]),
("00110", array[6]),
("00111", array[7]),
("01000", array[8]),
("01001", array[9]),
("01010", array[10]),
("01011", array[11]),
("01100", array[12]),
("01101", array[13]),
("01110", array[14]),
("01111", array[15]),
("10001", array[17]),
("10010", array[18]),
("10011", array[19]),
("110000", array[20]),
("110001", array[21]),
("110010", array[22]),
("110011", array[23]),
("110100", array[24]),
("110101", array[25]),
("110110", array[26]),
("110111", array[27]),
("111000", array[28]),
("111001", array[29]),
("111010", array[30]),
("111011", array[31]),
("111100", array[32]),
("111101", array[33])
});
if (!(maybe is Just<(string, Phenotype)> just))
{
return;
}
just.Deconstruct(out var a);
if (1 == 0)
{
return;
}
var (item, phenotype) = a;
if (phenotype is Hunter item2)
{
if (zone.bloodDoors.Count < 2)
{
zone.bloodDoors.Add((item, item2));
}
}
else
{
zone.enemies.Add(a);
}
}
}
public class GeneticRundown : MonoBehaviour
{
private delegate bool TryStartLevel_t(ref bool __result);
private enum BuildState
{
NeedRebuild,
Evolving,
WaitingForChromosome,
ReadyToDrop
}
public class Fitness : IFitness
{
private int numZones;
public Fitness(int numZones)
{
this.numZones = numZones;
}
public double Evaluate(Chromosome chromosome)
{
double num = 1.0;
double num2 = 0.0;
List<GeneticZone> list = FromChromosome(chromosome, numZones);
for (int i = 0; i < Math.Min(numZones, list.Count); i++)
{
if (list[i].enemies.Count > 0)
{
num *= 1.0;
}
num2 += list[i].Evaluate();
}
return num * num2;
}
}
public class Termination : ITermination
{
private float Threshold;
private IFitness fitness;
public Termination(float threshold, IFitness fitness)
{
Threshold = threshold;
this.fitness = fitness;
}
public bool IsGoodEnough(IList<Chromosome> chromosomes)
{
return fitness.Evaluate(chromosomes[0]) > (double)Threshold;
}
}
private struct pChromosome
{
public Il2CppStructArray<bool> genes;
public pChromosome(Chromosome chromosome)
{
genes = Il2CppStructArray<bool>.op_Implicit(chromosome.Genes);
}
}
public enum Allele
{
Nothing,
Command,
Enemy
}
private static TryStartLevel_t OnTryStartLevel;
private static Action OnStartLevelBuild;
private static Action<CM_PageLoadout> OnUpdateReadyState;
public static bool CallOnTryStartLevel(ref bool __result)
{
return OnTryStartLevel(ref __result);
}
public static void CallOnStartLevelBuild()
{
OnStartLevelBuild();
}
public static void CallOnUpdateReadyState(CM_PageLoadout __instance)
{
OnUpdateReadyState(__instance);
}
static GeneticRundown()
{
OnTryStartLevel = delegate(ref bool __result)
{
__result = false;
return false;
};
OnStartLevelBuild = delegate
{
};
OnUpdateReadyState = delegate
{
};
}
public static void FakeClosurePatch(Harmony harmony)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
ClassInjector.RegisterTypeInIl2Cpp<GeneticRundown>();
harmony.Patch((MethodBase)typeof(GS_Lobby).GetMethod("TryStartLevelTrigger"), new HarmonyMethod(typeof(GeneticRundown), "CallOnTryStartLevel", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)typeof(CM_PageLoadout).GetMethod("UpdateReadyState"), (HarmonyMethod)null, new HarmonyMethod(typeof(GeneticRundown), "CallOnUpdateReadyState", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)typeof(Builder).GetMethod("Build"), new HarmonyMethod(typeof(GeneticRundown), "CallOnStartLevelBuild", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public static void CreateGeneticRundown(ManualLogSource log)
{
Chromosome chromosome = null;
ChromosomeTransfer transfer = new ChromosomeTransfer();
BuildState state = BuildState.NeedRebuild;
OnTryStartLevel = delegate(ref bool __result)
{
__result = false;
if (state == BuildState.ReadyToDrop)
{
state = BuildState.NeedRebuild;
return true;
}
if (state == BuildState.NeedRebuild)
{
if (SNet.IsMaster)
{
state = BuildState.Evolving;
Task.Run((Action)buildLevel);
}
else
{
state = BuildState.WaitingForChromosome;
Task.Run((Action)awaitLevel);
}
}
return false;
};
OnUpdateReadyState = delegate(CM_PageLoadout page)
{
BuildState buildState = state;
if ((uint)(buildState - 1) <= 1u)
{
((Component)page.m_dropButton).gameObject.SetActive(false);
((Component)page.m_changeLoadoutButton).gameObject.SetActive(false);
((Component)page.m_readyButton).gameObject.SetActive(false);
}
if (state == BuildState.ReadyToDrop)
{
GameStateManager.CurrentState.TryStartLevelTrigger();
}
};
OnStartLevelBuild = delegate
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
ExpeditionInTierData activeExpedition3 = RundownManager.ActiveExpedition;
LevelLayoutDataBlock block3 = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition3.LevelLayoutData);
List<GeneticZone> list = FromChromosome(chromosome, block3.Zones.Count);
bool flag = default(bool);
for (int i = 0; i < Math.Min(block3.Zones.Count, list.Count); i++)
{
ManualLogSource val = log;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(7, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Zone ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(i);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(list[i].Show());
}
val.LogInfo(val2);
list[i].SetupZone(log, block3.Zones[i]);
}
};
void awaitLevel()
{
ExpeditionInTierData activeExpedition = RundownManager.ActiveExpedition;
LevelLayoutDataBlock block = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition.LevelLayoutData);
transfer.Reset();
log.LogInfo((object)"Waiting for level chromosome...");
transfer.Wait();
log.LogInfo((object)"Chromosome received!");
chromosome = transfer.Result;
state = BuildState.ReadyToDrop;
}
void buildLevel()
{
ExpeditionInTierData activeExpedition2 = RundownManager.ActiveExpedition;
LevelLayoutDataBlock block2 = GameDataBlockBase<LevelLayoutDataBlock>.GetBlock(activeExpedition2.LevelLayoutData);
Random random = new Random(activeExpedition2.SessionSeed);
NetworkAPI.InvokeFreeSizedEvent("awaitDNA", (chromosome = RunGenetic(log, random, block2.Zones.Count)).ToBytes(), (SNet_ChannelType)2);
state = BuildState.ReadyToDrop;
}
}
public static Chromosome RunGenetic(ManualLogSource log, Random random, int numZones)
{
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Expected O, but got Unknown
OnePointCrossover crossover = new OnePointCrossover(0.75f);
MultiMutation mutation = new MultiMutation(new IMutation[2]
{
new FlipMutation(0.09f),
new CopyMutation(0.05f)
});
Fitness fitness = new Fitness(numZones);
Termination termination = new Termination(0.875f * (float)numZones, fitness);
Algorithm algorithm = new Algorithm(16384, 64, 1024, fitness, crossover, mutation, termination);
List<Chromosome> list = new List<Chromosome>(16384);
for (int i = 0; i < 16384; i++)
{
list.Add(Chromosome.MakeRandom(random, 8, 32));
}
List<Chromosome> list2 = algorithm.Run(random, list).OrderByDescending(fitness.Evaluate).ToList();
Chromosome chromosome = list2[0];
log.LogInfo((object)"");
log.LogInfo((object)("\n" + chromosome.Show()));
log.LogInfo((object)"");
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Max final fitness: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(fitness.Evaluate(chromosome));
}
log.LogInfo(val);
return chromosome;
}
public static Maybe<Allele> NextAllele(ChromosomeReader reader)
{
Maybe<string> maybe = reader.Next(1);
if (1 == 0)
{
}
Maybe<Allele> result;
if (!(maybe is Nothing<string>))
{
if (!(maybe is Just<string> just))
{
goto IL_005d;
}
just.Deconstruct(out var a);
if (!(a == "0"))
{
if (!(a == "1"))
{
goto IL_005d;
}
result = new Just<Allele>(Allele.Enemy);
}
else
{
result = new Just<Allele>(Allele.Command);
}
}
else
{
result = new Nothing<Allele>();
}
goto IL_0066;
IL_0066:
if (1 == 0)
{
}
return result;
IL_005d:
result = new Just<Allele>(Allele.Nothing);
goto IL_0066;
}
public static List<GeneticZone> FromChromosome(Chromosome chromosome, int numZones)
{
ChromosomeReader reader = new ChromosomeReader(chromosome);
GeneticZone[] array = new GeneticZone[numZones];
for (int i = 0; i < numZones; i++)
{
array[i] = new GeneticZone();
}
int num = 0;
while (NextAllele(reader) is Just<Allele> just)
{
just.Deconstruct(out var a);
if (1 == 0)
{
break;
}
switch (a)
{
case Allele.Command:
if (numZones <= ++num)
{
return array.ToList();
}
break;
case Allele.Enemy:
GeneticEnemies.NextEnemy(reader, array[num]);
break;
}
}
return array.ToList();
}
}
public class Geomorphs
{
private readonly List<string> geomorphs;
private readonly List<string> reactors;
private static readonly string[] whitelist = new string[173]
{
"geo_64x64_tech_node_transition", "geo_64x64_tech_node_transition_02_JG", "geo_64x64_tech_node_transition_03_JG", "geo_64x64_tech_node_transition_04_JG", "geo_64x64_tech_node_transition_05_JG", "geo_64x64_tech_node_transition_06_JG", "geo_64x64_tech_lab_hub_HA_04", "geo_64x64_tech_lab_hub_LF_01", "geo_64x64_tech_lab_hub_HA_01_R3D1", "geo_64x64_tech_lab_hub_SF_02",
"geo_64x64_tech_lab_hub_HA_01", "geo_64x64_tech_destroyed_HA_01", "geo_64x64_tech_destroyed_HA_02", "geo_64x64_tech_data_center_hub_SF_ConduitVersion", "geo_64x64_tech_data_center_hub_SF_01", "geo_64x64_tech_data_center_hub_JG_01", "geo_64x64_lab_I_HA_01", "geo_64x64_lab_I_HA_03", "geo_64x64_lab_reactor_HA_01", "geo_64x64_lab_reactor_HA_02",
"geo_64x64_tech_data_center_hub_SF_02_CreativeDesign", "geo_64x64_tech_data_center_HA_09_v2_R5B2", "geo_64x64_tech_data_center_HA_09", "geo_64x64_tech_data_center_HA_08", "geo_64x64_tech_data_center_HA_07_v2_R5B2", "geo_64x64_tech_data_center_HA_07", "geo_64x64_tech_data_center_HA_06", "geo_64x64_tech_data_center_HA_05_v3_R5B2", "geo_64x64_tech_data_center_HA_05_v2_R5B2", "geo_64x64_tech_data_center_HA_05",
"geo_64x64_tech_data_center_HA_04_V2_R5B2", "geo_64x64_tech_data_center_HA_04", "geo_64x64_tech_data_center_HA_03", "geo_64x64_tech_data_center_HA_02", "geo_64x64_tech_data_center_HA_01_v2_R5B2", "geo_64x64_tech_data_center_HA_01", "geo_64x64_tech_data_center_dead_end_HA_01", "geo_64x64_service_floodways_VS_01", "geo_64x64_service_floodways_SF_01", "geo_64x64_service_floodways_I_HA_02",
"geo_64x64_service_floodways_I_HA_01_R7D1", "geo_64x64_service_floodways_I_HA_01", "geo_64x64_service_floodways_hub_SF_02", "geo_64x64_service_floodways_hub_SF_01", "geo_64x64_service_floodways_hub_HA_03", "geo_64x64_service_floodways_hub_HA_02", "geo_64x64_service_floodways_hub_HA_01_R7D1", "geo_64x64_service_floodways_hub_HA_01", "geo_64x64_service_floodways_hub_AW_01_V2", "geo_64x64_service_floodways_hub_AW_01",
"geo_64x64_service_floodways_HA_09", "geo_64x64_service_floodways_HA_08", "geo_64x64_service_floodways_HA_07", "geo_64x64_service_floodways_HA_06_R5A1_2", "geo_64x64_service_floodways_HA_06_R5A1_1", "geo_64x64_service_floodways_HA_06", "geo_64x64_service_floodways_HA_05_R5A1_2", "geo_64x64_service_floodways_HA_05_R5A1_1", "geo_64x64_service_floodways_HA_05", "geo_64x64_service_floodways_HA_04",
"geo_64x64_service_floodways_HA_03_R5A1_3", "geo_64x64_service_floodways_HA_03_R5A1_2", "geo_64x64_service_floodways_HA_03_R5A1_1", "geo_64x64_service_floodways_HA_03", "geo_64x64_lab_I_HA_01", "geo_64x64_lab_I_HA_03", "geo_64x64_lab_reactor_HA_01", "geo_64x64_lab_reactor_HA_02", "geo_64x64_mining_challenge_01", "geo_64x64_mining_dig_site_AS_01",
"geo_64x64_mining_dig_site_AS_02", "geo_64x64_mining_dig_site_AS_02_v2", "geo_64x64_mining_dig_site_AS_04", "geo_64x64_mining_dig_site_AS_04_v2", "geo_64x64_mining_dig_site_HA_01", "geo_64x64_mining_dig_site_HA_01_v2", "geo_64x64_mining_dig_site_HA_02", "geo_64x64_mining_dig_site_HA_02_R2A1", "geo_64x64_mining_dig_site_HA_02_v2", "geo_64x64_mining_dig_site_HA_02_v3",
"geo_64x64_mining_dig_site_HA_02_v4", "geo_64x64_mining_dig_site_HA_03", "geo_64x64_mining_dig_site_HA_03_v2", "geo_64x64_mining_dig_site_HA_03_v3", "geo_64x64_mining_dig_site_HA_04", "geo_64x64_mining_dig_site_HA_04_v2", "geo_64x64_mining_dig_site_HA_05", "geo_64x64_mining_dig_site_HA_05_v2", "geo_64x64_mining_dig_site_HA_06", "geo_64x64_mining_dig_site_HA_06_v2",
"geo_64x64_mining_dig_site_HA_07", "geo_64x64_mining_dig_site_HA_07_v2", "geo_64x64_mining_dig_site_HA_07_v3", "geo_64x64_mining_dig_site_hub_HA_01", "geo_64x64_mining_dig_site_hub_HA_01.R4E1", "geo_64x64_mining_dig_site_hub_HA_02", "geo_64x64_mining_dig_site_hub_HA_03", "geo_64x64_mining_dig_site_hub_SF_01", "geo_64x64_mining_dig_site_hub_SF_02", "geo_64x64_mining_dig_site_I_HA_01",
"geo_64x64_mining_dig_site_reactor_tunnel_I_HA_01", "geo_64x64_mining_exit_01", "geo_64x64_mining_exit_01_tutorial", "geo_64x64_mining_exit_02", "geo_64x64_mining_portal_HA_01", "geo_64x64_mining_HSU_exit_01", "geo_64x64_mining_reactor_open_HA_01", "geo_64x64_mining_refinery_dead_end_HA_01", "geo_64x64_mining_refinery_HA_01", "geo_64x64_mining_refinery_HA_02",
"geo_64x64_mining_refinery_HA_03", "geo_64x64_mining_refinery_HA_04", "geo_64x64_mining_refinery_HA_04_v2", "geo_64x64_mining_refinery_HA_05", "geo_64x64_mining_refinery_HA_05_v2", "geo_64x64_mining_refinery_HA_06", "geo_64x64_mining_refinery_HA_06_v2", "geo_64x64_mining_refinery_HA_07", "geo_64x64_mining_refinery_HA_08", "geo_64x64_mining_refinery_I_HA_01",
"geo_64x64_mining_refinery_I_HA_01_v2", "geo_64x64_mining_refinery_I_HA_02", "geo_64x64_mining_refinery_I_HA_03", "geo_64x64_mining_refinery_I_HA_04", "geo_64x64_mining_refinery_I_HA_05", "geo_64x64_mining_refinery_I_HA_06", "geo_64x64_mining_refinery_JG_01", "geo_64x64_mining_refinery_JG_02", "geo_64x64_mining_refinery_L_HA_01", "geo_64x64_mining_refinery_X_HA_01",
"geo_64x64_mining_refinery_X_HA_02", "geo_64x64_mining_refinery_X_HA_03", "geo_64x64_mining_refinery_X_HA_04", "geo_64x64_mining_refinery_X_HA_05", "geo_64x64_mining_refinery_X_HA_06", "geo_64x64_mining_refinery_X_HA_06_R3B2", "geo_64x64_mining_refinery_X_HA_06_v2", "geo_64x64_mining_refinery_X_HA_07", "geo_64x64_mining_refinery_X_VS_01", "geo_64x64_mining_refinery_X_VS_01_v2",
"geo_64x64_mining_storage_HA_01", "geo_64x64_mining_storage_HA_02", "geo_64x64_mining_storage_HA_03", "geo_64x64_mining_storage_HA_04", "geo_64x64_mining_storage_HA_05", "geo_64x64_mining_storage_HA_06", "geo_64x64_mining_storage_HA_06b", "geo_64x64_mining_storage_HA_07", "geo_64x64_mining_storage_HA_08", "geo_64x64_mining_storage_hub_HA_01",
"geo_64x64_mining_storage_hub_HA_02", "geo_64x64_mining_storage_hub_HA_03", "geo_64x64_mining_storage_hub_HA_04", "geo_64x64_mining_storage_hub_HA_04_R3B1", "geo_64x64_mining_storage_hub_HA_05", "geo_64x64_mining_storage_hub_VS_01", "geo_64x64_mining_storage_I_HA_01", "geo_64x64_mining_storage_I_HA_01_tutorial", "geo_64x64_mining_storage_tutorial_VS_01", "geo_64x64_mining_storage_tutorial_VS_02",
"geo_64x64_mining_storage_tutorial_VS_03", "geo_64x64_mining_storage_tutorial_VS_04", "geo_64x64_mining_storage_vault_HA_01", "geo_64x64_mining_storage_vault_v2_HA_01", "geo_64x64_mining_storage_vault_v3_HA_01", "geo_64x64_service_floodways_dead_end_HA_01", "geo_64x64_service_floodways_dead_end_HA_01_R7D1", "geo_64x64_service_floodways_HA_01", "geo_64x64_service_floodways_HA_01_R5A1_1", "geo_64x64_service_floodways_HA_01_R5A1_2",
"geo_64x64_service_floodways_HA_01_R5A1_3", "geo_64x64_service_floodways_HA_01_R5A1_4", "geo_64x64_service_floodways_HA_02"
};
private static readonly string[] blacklist = new string[12]
{
"Mainframe", "dead_end", "reactor", "geo_64x64_Lab_dead_end_room", "geo_64x64_mining_refinery_X", "geo_64x64_mining_reactor_HA_02", "portal", "exit", "geo_64x64_tech_lab_hub_HA_02", "geo_64x64_service_gardens_Lab_HSU_Prep_TestingFunc",
"geo_64x64_service_gardens_X_01", "geo_64x64_service_gardens_I_01"
};
public Geomorphs(ComplexResourceSetDataBlock complex)
{
geomorphs = new List<string>();
reactors = new List<string>();
Enumerator<ResourceData> enumerator = complex.CustomGeomorphs_Objective_1x1.GetEnumerator();
while (enumerator.MoveNext())
{
ResourceData current = enumerator.Current;
string prefab = current.Prefab;
if (prefab.Contains("reactor") && !prefab.Contains("tunnel"))
{
reactors.Add(prefab);
}
if (CheckWhitelist(prefab))
{
geomorphs.Add(prefab);
}
}
}
public string? RandomGeomorph(Random random, ExpeditionZoneData zone)
{
string customGeomorph = zone.CustomGeomorph;
if ((customGeomorph == null || customGeomorph == "") ? true : false)
{
return zone.CustomGeomorph;
}
if (CheckBlacklist(zone.CustomGeomorph))
{
return zone.CustomGeomorph;
}
if (zone.CustomGeomorph.Contains("reactor") && reactors.Count > 0)
{
return reactors[random.Next(reactors.Count)];
}
if (geomorphs.Count > 0)
{
return geomorphs[random.Next(geomorphs.Count)];
}
return zone.CustomGeomorph;
}
public static bool CheckWhitelist(string geo)
{
return whitelist.Any((string e) => geo.Contains(e));
}
public static bool CheckBlacklist(string geo)
{
return blacklist.Any((string e) => geo.Contains(e));
}
}
[BepInPlugin("GTFRevolution", "GTFRevolution", "1.1.3")]
public class Main : BasePlugin
{
public override void Load()
{
HahaInternal.HahaFunny(((BasePlugin)this).Log);
}
}
internal class HahaInternal : MonoBehaviour
{
private static event Action OnStartGame;
public static void HahaFunny(ManualLogSource log)
{
log.LogInfo((object)"Haha Funny Main >:3");
FakeClosurePatch(log);
HahaSerious(log);
}
public static void CallOnStartGame()
{
HahaInternal.OnStartGame();
}
private static void HahaSerious(ManualLogSource log)
{
OnStartGame += delegate
{
Configuration configuration = new Configuration();
log.LogInfo((object)"Haha Serious Main >:(");
GeneticRundown.CreateGeneticRundown(log);
};
}
public static void CallOnSetActiveExpedition(ref pActiveExpedition expPackage, ref ExpeditionInTierData expTierData)
{
Random random = new Random(expPackage.sessionSeed);
expTierData.Seeds.BuildSeed = random.Next(100000000, int.MaxValue);
}
public static void FakeClosurePatch(ManualLogSource log)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
ClassInjector.RegisterTypeInIl2Cpp<HahaInternal>();
Harmony val = new Harmony("gtfr:e");
val.Patch((MethodBase)typeof(StartMainGame).GetMethod("Start"), (HarmonyMethod)null, new HarmonyMethod(typeof(HahaInternal).GetMethod("CallOnStartGame")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)typeof(RundownManager).GetMethod("SetActiveExpedition"), new HarmonyMethod(typeof(HahaInternal).GetMethod("CallOnSetActiveExpedition")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
GeneticRundown.FakeClosurePatch(val);
}
static HahaInternal()
{
HahaInternal.OnStartGame = delegate
{
};
}
}
public class VanillaLevels
{
private readonly LevelLayoutDataBlock[] layouts;
public VanillaLevels(LevelLayoutDataBlock[] ingame)
{
LevelLayoutDataBlock[] array = (LevelLayoutDataBlock[])(object)new LevelLayoutDataBlock[ingame.Length];
for (int i = 0; i < ingame.Length; i++)
{
LevelLayoutDataBlock val = ingame[i];
try
{
LevelLayoutDataBlock val2 = GameDataBlockBase<LevelLayoutDataBlock>.CreateNewCopy(val);
((GameDataBlockBase<LevelLayoutDataBlock>)(object)val2).name = ((GameDataBlockBase<LevelLayoutDataBlock>)(object)val).name;
array[i] = val2;
}
catch (Exception)
{
}
}
layouts = array;
}
public LevelLayoutDataBlock OriginalLayoutOf(string name)
{
LevelLayoutDataBlock[] array = layouts;
foreach (LevelLayoutDataBlock val in array)
{
if (val != null && ((GameDataBlockBase<LevelLayoutDataBlock>)(object)val).name.Contains(name))
{
return val;
}
}
throw new ArgumentException("Could not find original layout for level " + name);
}
}
}
namespace GTFR.Genetic
{
public sealed class Algorithm
{
private readonly int MinPopulation;
private readonly int MaxIterations;
private readonly int NumElite;
private readonly IFitness fitness;
private readonly ICrossover crossover;
private readonly IMutation mutation;
private readonly ITermination termination;
public Algorithm(int minPopulation, int maxIterations, int numElite, IFitness fitness, ICrossover crossover, IMutation mutation, ITermination termination)
{
MinPopulation = minPopulation;
MaxIterations = maxIterations;
NumElite = numElite;
this.fitness = fitness;
this.crossover = crossover;
this.mutation = mutation;
this.termination = termination;
}
public IList<Chromosome> Run(Random random, List<Chromosome> initial)
{
List<Chromosome> list = new List<Chromosome>(MinPopulation);
foreach (Chromosome item in initial)
{
list.Add(item);
}
for (int i = 0; i < MaxIterations; i++)
{
list = RunOnce(random, list).ToList();
if (termination.IsGoodEnough(list))
{
return list;
}
}
return list;
}
public IList<Chromosome> RunOnce(Random random, IList<Chromosome> progenitors)
{
IList<Chromosome> progenitors2 = Shuffle(random, progenitors);
IList<Chromosome> list = Crossovers(random, progenitors2);
Mutations(random, list);
return Reinsertions(random, list, progenitors);
}
private IList<Chromosome> Crossovers(Random random, IEnumerable<Chromosome> progenitors)
{
List<Chromosome> list = new List<Chromosome>(MinPopulation);
while (progenitors.Any())
{
(IEnumerable<Chromosome>, IEnumerable<Chromosome>) tuple = crossover.Cross(random, progenitors);
IEnumerable<Chromosome> item = tuple.Item1;
IEnumerable<Chromosome> item2 = tuple.Item2;
progenitors = item2;
list.AddRange(item);
}
return list;
}
private void Mutations(Random random, IList<Chromosome> chromosomes)
{
foreach (Chromosome chromosome in chromosomes)
{
mutation.Mutate(random, chromosome);
}
}
private IList<Chromosome> Reinsertions(Random random, IList<Chromosome> offspring, IList<Chromosome> progenitors)
{
IEnumerable<Chromosome> second = progenitors.Take(NumElite);
IOrderedEnumerable<Chromosome> source = offspring.Concat(second).OrderByDescending(fitness.Evaluate);
return source.Take(MinPopulation).ToList();
}
private IList<Chromosome> Shuffle(Random random, IList<Chromosome> xs)
{
List<Chromosome> list = new List<Chromosome>(xs);
for (int i = 0; i < list.Count; i++)
{
int index = random.Next(0, list.Count);
Chromosome value = list[i];
list[i] = list[index];
list[index] = value;
}
return list;
}
}
public class Chromosome
{
private bool[] genes;
public bool this[int index] => genes[index];
public bool[] Genes => genes;
public int Length => genes.Length;
public Chromosome(int length)
{
genes = new bool[length];
}
public Chromosome(bool[] genes)
{
this.genes = new bool[genes.Length];
Array.Copy(this.genes, genes, genes.Length);
}
public Chromosome(Chromosome other)
{
genes = new bool[other.Length];
Array.Copy(genes, other.genes, other.Length);
}
public static Chromosome MakeRandom(Random random, int minLength, int maxLength)
{
int num = random.Next(minLength, maxLength);
bool[] array = new bool[num];
for (int i = 0; i < num; i++)
{
array[i] = random.Next(0, 2) > 0;
}
return new Chromosome(array);
}
public string Show()
{
float num = (float)genes.Length / 8f;
int num2 = 0;
while (num > 1024f)
{
num2++;
num /= 1024f;
}
if (1 == 0)
{
}
string text = num2 switch
{
0 => "B",
1 => "KiB",
2 => "MiB",
3 => "GiB",
4 => "TiB",
_ => "",
};
if (1 == 0)
{
}
string text2 = text;
string text3 = "";
text3 += "--- BEGIN CHROMOSOME ---\n";
text3 = text3 + "(" + num.ToString("N2") + " " + text2 + ")\n";
for (int i = 0; i < genes.Length; i += 256)
{
for (int j = 0; j < 256 && i + j < genes.Length; j++)
{
text3 += (genes[i + j] ? '1' : '0');
}
text3 += "\n";
}
return text3 + "--- END CHROMOSOME ---";
}
public void Overwrite(Chromosome other)
{
genes = other.genes;
}
public Chromosome Concat(Chromosome other)
{
Chromosome chromosome = new Chromosome(Length + other.Length);
Array.Copy(genes, chromosome.genes, Length);
Array.Copy(other.genes, 0, chromosome.genes, Length, other.Length);
return chromosome;
}
public Chromosome Slice(float p, float q)
{
int start = (int)Math.Round(p * (float)Length);
int end = (int)Math.Round(q * (float)Length);
return Slice(start, end);
}
public Chromosome Slice(int start, int end)
{
if (end < start)
{
throw new Exception("invalid slice");
}
return SliceN(start, end - start);
}
public Chromosome SliceN(int start, int length)
{
Chromosome chromosome = new Chromosome(length);
Array.Copy(genes, start, chromosome.genes, 0, length);
return chromosome;
}
public byte[] ToBytes()
{
byte[] array = new byte[genes.Length];
for (int i = 0; i < genes.Length; i++)
{
array[i] = (byte)(genes[i] ? 255u : 0u);
}
return array;
}
public static Chromosome FromBytes(byte[] bytes)
{
bool[] array = new bool[bytes.Length];
for (int i = 0; i < bytes.Length; i++)
{
array[i] = bytes[i] > 0;
}
return new Chromosome(array);
}
}
public class ChromosomeReader
{
private readonly Chromosome chromosome;
private int i;
public ChromosomeReader(Chromosome chromosome)
{
this.chromosome = chromosome;
i = 0;
}
public bool IsDone()
{
return !HasRemaining();
}
public bool HasRemaining()
{
return HasRemaining(0);
}
public bool HasRemaining(int n)
{
return i + n < chromosome.Length;
}
public Maybe<string> Next(int n)
{
if (!HasRemaining(n))
{
return new Nothing<string>();
}
string text = "";
for (int i = 0; i < n; i++)
{
text += (chromosome[this.i++] ? '1' : '0');
}
return new Just<string>(text);
}
public Maybe<T> Match<T>(IEnumerable<(string, T)> alts)
{
string a = "";
Func<(string, T), bool> predicate = delegate((string, T) x)
{
if (1 == 0)
{
}
string item = x.Item1;
bool result = item.StartsWith(a);
if (1 == 0)
{
}
return result;
};
while (true)
{
if (!HasRemaining())
{
return new Nothing<T>();
}
a += (chromosome[i++] ? '1' : '0');
IEnumerable<(string, T)> enumerable = alts.Where(predicate);
if (!enumerable.Any())
{
break;
}
foreach (var (text, a2) in enumerable)
{
if (text == a)
{
return new Just<T>(a2);
}
}
}
return new Nothing<T>();
}
}
public class ChromosomeTransfer
{
private class TransferImpl
{
public TaskCompletionSource<Chromosome> transferTask;
public TransferImpl()
{
transferTask = new TaskCompletionSource<Chromosome>();
}
}
private TransferImpl transferImpl;
private Action<ulong, byte[]> await;
public Chromosome Result => transferImpl.transferTask.Task.Result;
public ChromosomeTransfer()
{
transferImpl = new TransferImpl();
await = delegate(ulong _, byte[] data)
{
transferImpl.transferTask.SetResult(Chromosome.FromBytes(data));
};
NetworkAPI.RegisterFreeSizedEvent("awaitDNA", await);
}
public void Wait()
{
transferImpl.transferTask.Task.Wait();
}
public void Reset()
{
transferImpl.transferTask = new TaskCompletionSource<Chromosome>();
}
}
public class CutAndSplice : ICrossover
{
private readonly float probability;
public CutAndSplice(float probability)
{
this.probability = probability;
}
public (IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors)
{
if (random.NextDouble() > (double)probability)
{
return (new List<Chromosome>(), progenitors.Skip(2));
}
List<Chromosome> list = progenitors.Take(2).ToList();
Chromosome chromosome = list[0];
Chromosome chromosome2 = list[1];
int num = random.Next(1, chromosome.Length) + 1;
int num2 = random.Next(1, chromosome2.Length) + 1;
Chromosome item = CreateOffspring(chromosome, num, chromosome2, num2);
Chromosome item2 = CreateOffspring(chromosome2, num2, chromosome, num);
return (new List<Chromosome> { item, item2 }, progenitors.Skip(2));
}
private static Chromosome CreateOffspring(Chromosome p1, int m, Chromosome p2, int n)
{
return p1.Slice(0, m).Concat(p2.Slice(n, p2.Length));
}
}
public interface ICrossover
{
(IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors);
}
public class NoCrossover : ICrossover
{
public (IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors)
{
return (progenitors, new List<Chromosome>());
}
}
public class OnePointCrossover : ICrossover
{
private readonly float probability;
public OnePointCrossover(float probability)
{
this.probability = probability;
}
public (IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors)
{
if ((double)probability < random.NextDouble())
{
return (new List<Chromosome>(), progenitors.Skip(2));
}
List<Chromosome> list = progenitors.Take(2).ToList();
Chromosome chromosome = list[0];
Chromosome chromosome2 = list[1];
int m = random.Next(0, Math.Min(chromosome.Length, chromosome2.Length));
Chromosome item = CreateOffspring(chromosome, m, chromosome2);
Chromosome item2 = CreateOffspring(chromosome2, m, chromosome);
return (new List<Chromosome> { item, item2 }, progenitors.Skip(2));
}
private Chromosome CreateOffspring(Chromosome p1, int m, Chromosome p2)
{
return p1.Slice(0, m).Concat(p2.Slice(m, p2.Length));
}
}
public class TwoPointCrossover : ICrossover
{
private readonly float probability;
public TwoPointCrossover(float probability)
{
this.probability = probability;
}
public (IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors)
{
if ((double)probability < random.NextDouble())
{
return (new List<Chromosome>(), progenitors.Skip(2));
}
List<Chromosome> list = progenitors.Take(2).ToList();
Chromosome chromosome = list[0];
Chromosome chromosome2 = list[1];
int num = random.Next(0, chromosome.Length);
int num2 = random.Next(0, chromosome2.Length);
Chromosome item = CreateOffspring(chromosome, num, chromosome2, num2);
Chromosome item2 = CreateOffspring(chromosome2, num2, chromosome, num);
return (new List<Chromosome> { item, item2 }, progenitors.Skip(2));
}
private Chromosome CreateOffspring(Chromosome p1, int m, Chromosome p2, int n)
{
return p1.Slice(0, m).Concat(p2.Slice(m, n)).Concat(p1.Slice(m + n, p1.Length));
}
}
public class UniformCrossover : ICrossover
{
private readonly float probability;
public UniformCrossover(float probability)
{
this.probability = probability;
}
public (IEnumerable<Chromosome>, IEnumerable<Chromosome>) Cross(Random random, IEnumerable<Chromosome> progenitors)
{
if ((double)probability < random.NextDouble())
{
return (new List<Chromosome>(), progenitors.Skip(2));
}
List<Chromosome> list = progenitors.Take(2).ToList();
Chromosome chromosome = list[0];
Chromosome chromosome2 = list[1];
Chromosome chromosome3 = new Chromosome(chromosome);
Chromosome chromosome4 = new Chromosome(chromosome2);
for (int i = 0; i < Math.Min(chromosome.Length, chromosome2.Length); i++)
{
bool flag2;
bool flag3;
if (random.Next(0, 2) <= 0)
{
bool num = chromosome[i];
bool flag = chromosome2[i];
flag2 = flag;
flag3 = num;
}
else
{
bool num2 = chromosome2[i];
bool flag = chromosome[i];
flag2 = flag;
flag3 = num2;
}
chromosome3.Genes[i] = flag3;
chromosome4.Genes[i] = flag2;
}
return (new List<Chromosome> { chromosome3, chromosome4 }, progenitors.Skip(2));
}
}
public class Fitness : IFitness
{
private readonly Func<Chromosome, double> func;
public Fitness(Func<Chromosome, double> func)
{
this.func = func;
}
public double Evaluate(Chromosome chromosome)
{
return func(chromosome);
}
}
public interface IFitness
{
double Evaluate(Chromosome chromosome);
}
public class CopyMutation : IMutation
{
private float probability;
public CopyMutation(float probability)
{
this.probability = probability;
}
public void Mutate(Random random, Chromosome chromosome)
{
if (!((double)probability < random.NextDouble()))
{
int num = random.Next(0, chromosome.Length - 2);
int num2 = random.Next(num, chromosome.Length - 1);
Chromosome chromosome2 = chromosome.Slice(0, num);
Chromosome other = chromosome.Slice(num, num2);
Chromosome other2 = chromosome.Slice(num2, chromosome.Length);
chromosome.Overwrite(chromosome2.Concat(other).Concat(other).Concat(other2));
}
}
}
public class Displacement : IMutation
{
private float probability;
public Displacement(float probability)
{
this.probability = probability;
}
public void Mutate(Random random, Chromosome chromosome)
{
if (!((double)probability < random.NextDouble()))
{
int num = random.Next(0, chromosome.Length - 2);
int num2 = random.Next(num, chromosome.Length - 1);
Chromosome chromosome2 = chromosome.Slice(0, num);
Chromosome other = chromosome.Slice(num, num2);
Chromosome other2 = chromosome.Slice(num2, chromosome.Length);
Chromosome chromosome3 = chromosome2.Concat(other2);
int num3 = random.Next(0, chromosome3.Length);
Chromosome chromosome4 = chromosome3.Slice(0, num3);
Chromosome other3 = chromosome3.Slice(num3, chromosome3.Length);
chromosome.Overwrite(chromosome4.Concat(other).Concat(other3));
}
}
}
public class FlipMutation : IMutation
{
private float probability;
public FlipMutation(float probability)
{
this.probability = probability;
}
public void Mutate(Random random, Chromosome chromosome)
{
if (!((double)probability < random.NextDouble()))
{
int num = random.Next(0, chromosome.Length - 2);
int num2 = random.Next(num, chromosome.Length - 1);
for (int i = num; i < num2; i++)
{
ref bool reference = ref chromosome.Genes[i];
reference = !reference;
}
}
}
}
public interface IMutation
{
void Mutate(Random random, Chromosome chromosome);
}
public class MultiMutation : IMutation
{
private IEnumerable<IMutation> mutations;
public MultiMutation(IEnumerable<IMutation> mutations)
{
this.mutations = mutations;
}
public void Mutate(Random random, Chromosome chromosome)
{
foreach (IMutation mutation in mutations)
{
mutation.Mutate(random, chromosome);
}
}
}
public class NoMutation : IMutation
{
public void Mutate(Random random, Chromosome chromosome)
{
}
}
public interface ITermination
{
bool IsGoodEnough(IList<Chromosome> chromosomes);
}
public class GeneticZone
{
public List<(string name, GeneticEnemies.Phenotype)> enemies;
public List<(string name, GeneticEnemies.Hunter)> bloodDoors;
public GeneticZone()
{
enemies = new List<(string, GeneticEnemies.Phenotype)>();
bloodDoors = new List<(string, GeneticEnemies.Hunter)>();
}
public string Show()
{
List<string> list = new List<string>();
list.AddRange(enemies.Select(((string name, GeneticEnemies.Phenotype) x) => x.name));
list.AddRange(bloodDoors.Select(((string name, GeneticEnemies.Hunter) x) => x.name));
return "[" + string.Join(", ", list) + "]";
}
public double Evaluate()
{
return EvalEnemies();
}
public double EvalEnemies()
{
double num = 1.0;
double num2 = 0.0;
foreach (var enemy in enemies)
{
GeneticEnemies.Phenotype item = enemy.Item2;
num2 += item.score;
num *= item.penalty;
}
foreach (var bloodDoor in bloodDoors)
{
GeneticEnemies.Hunter item2 = bloodDoor.Item2;
num2 += item2.score;
num *= item2.penalty;
}
return 1.0 / (1.0 + Math.Exp(0.0 - num));
}
public void SetupZone(ManualLogSource log, ExpeditionZoneData zone)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
List<EnemySpawningData> val = new List<EnemySpawningData>();
foreach (var enemy in enemies)
{
GeneticEnemies.Phenotype item = enemy.Item2;
EnemySpawningData val2 = new EnemySpawningData();
val2.GroupType = item.group;
val2.Difficulty = item.role;
val2.Distribution = item.distribution;
val2.DistributionValue = item.distributionValue;
val.Add(val2);
}
zone.EnemySpawningInZone = val;
if (bloodDoors.Count > 1)
{
GeneticEnemies.Hunter item2 = bloodDoors[0].Item2;
zone.ActiveEnemyWave.HasActiveEnemyWave = true;
zone.ActiveEnemyWave.EnemyGroupInfrontOfDoor = (uint)item2.persistentID;
}
if (bloodDoors.Count > 2)
{
GeneticEnemies.Hunter item3 = bloodDoors[1].Item2;
zone.ActiveEnemyWave.EnemyGroupInArea = (uint)item3.persistentID;
zone.ActiveEnemyWave.EnemyGroupsInArea = 2;
}
}
}
}