using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using COIExtended.Entities;
using COIExtended.Patches;
using COIExtended.Prototypes;
using COIExtended.Prototypes.Buildings;
using COIExtended.Prototypes.Decorations;
using COIExtended.Prototypes.Edicts;
using COIExtended.Prototypes.Fleets;
using COIExtended.Prototypes.Machines;
using COIExtended.Prototypes.Modifications;
using COIExtended.Prototypes.Products;
using COIExtended.Prototypes.Recipes;
using COIExtended.Prototypes.Research;
using COIExtended.Prototypes.SettlementModules;
using COIExtended.Prototypes.Storages;
using COIExtended.Prototypes.Surfaces;
using COIExtended.Prototypes.Transports;
using COIExtended.Prototypes.Vehicles;
using COIExtended.Prototypes.World;
using COIExtended.World;
using HarmonyLib;
using Mafi;
using Mafi.Collections;
using Mafi.Collections.ImmutableCollections;
using Mafi.Core;
using Mafi.Core.Game;
using Mafi.Core.Mods;
using Mafi.Core.Prototypes;
using Mafi.Core.SaveGame;
using Mafi.Core.Terrain.Generation;
using Mafi.Serialization;
using UnityEngine;
namespace COIExtended
{
public sealed class COIExtended : IMod, IModWithMaps
{
public string Name
{
get
{
return "COIExtended";
}
}
public int Version
{
get
{
return 71;
}
}
public bool IsUiOnly
{
get
{
return false;
}
}
public Option<IConfig> ModConfig { get; }
public IEnumerable<IWorldRegionMapPreviewData> GetMapPreviews(IFileSystemHelper fsHelper, ProtosDb protosDb, bool includeWip)
{
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(new string[]
{
folderPath,
"Captain of Industry",
"Mods",
"COIExtended",
"Maps"
});
MapSerializer mapLoader = new MapSerializer(ImmutableArray.Create<ISpecialSerializerFactory>(new ProtosSerializerFactory(protosDb)));
this.m_mapSerializer = mapLoader;
this.m_loadedMapPreviewsTmp.Clear();
int builtInMapsCount = 0;
HashSet<string> existingPreviewPaths = new HashSet<string>();
foreach (string text in Directory.EnumerateFiles(path, "*.map"))
{
IWorldRegionMapPreviewData worldRegionMapPreviewData;
Option<Exception> option;
if ((includeWip || !FileSystemHelperExtensions.IsWipMap(fsHelper, text)) && !existingPreviewPaths.Contains(text) && mapLoader.TryLoadPreviewMinimalFromFile(text, ref worldRegionMapPreviewData, ref option) && (includeWip || worldRegionMapPreviewData.IsPublished))
{
this.m_loadedMapPreviewsTmp.Add(Pair.Create<string, IWorldRegionMapPreviewData>(text, worldRegionMapPreviewData));
existingPreviewPaths.Add(text);
int num = builtInMapsCount;
builtInMapsCount = num + 1;
yield return worldRegionMapPreviewData;
}
}
IEnumerator<string> enumerator = null;
Debug.Log(string.Format("Loaded {0} mod provided maps.", builtInMapsCount));
yield break;
yield break;
}
public bool TryGetMapData(IWorldRegionMapPreviewData preview, IFileSystemHelper fsHelper, ProtosDb protosDb, out IWorldRegionMapAdditionalData fullData, out WorldRegionMapFactoryConfig factoryConfig)
{
fullData = null;
factoryConfig = null;
if (this.m_mapSerializer.IsNone)
{
Log.Error("No map serializer.");
return false;
}
int num = this.m_loadedMapPreviewsTmp.IndexOf<IWorldRegionMapPreviewData>(preview, (Pair<string, IWorldRegionMapPreviewData> x) => x.Second);
if (num < 0)
{
Log.Error("File path not found for given map: " + preview.Name);
return false;
}
string first = this.m_loadedMapPreviewsTmp[num].First;
bool result;
try
{
using (FileStream fileStream = File.OpenRead(first))
{
IWorldRegionMapPreviewData worldRegionMapPreviewData;
fullData = this.m_mapSerializer.Value.LoadPreviewFull(fileStream, true, ref worldRegionMapPreviewData);
factoryConfig = new WorldRegionMapFactoryConfig(typeof(FileWorldRegionMapFactory), new FileWorldRegionMapFactory.Config(first));
result = true;
}
}
catch (Exception ex)
{
Log.Exception(ex, "Failed to load map full data from file '" + first + "'.");
result = false;
}
return result;
}
public void ClearMapData()
{
this.m_loadedMapPreviewsTmp = default(LystStruct<Pair<string, IWorldRegionMapPreviewData>>);
this.m_mapSerializer = Option<MapSerializer>.None;
}
public COIExtended()
{
Debug.Log("[COIE]: Mod Loaded");
this.HarmonyInstance = new Harmony("COIE");
this.HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
Debug.Log("[COIE]: Applying Patches with Harmony");
}
public void EarlyInit(DependencyResolver resolver)
{
}
public void Initialize(DependencyResolver resolver, bool gameWasLoaded)
{
Debug.Log("[COIE]: Initializing.....");
this.InitializePatchers(resolver);
}
public void ChangeConfigs(Lyst<IConfig> configs)
{
Debug.Log("[COIE]: Changing configurations...");
}
public void RegisterPrototypes(ProtoRegistrator registrator)
{
Debug.Log("[COIE]: Registering new prototypes...");
registrator.RegisterAllProducts(null);
registrator.RegisterData<COIEPropertyData>(null);
registrator.RegisterData<Countable>(null);
registrator.RegisterData<Loose>(null);
registrator.RegisterData<Virtual>(null);
registrator.RegisterData<Fluid>(null);
registrator.RegisterData<Molten>(null);
registrator.RegisterData<TerrainData>(null);
registrator.RegisterData<DecalsData>(null);
registrator.RegisterData<SurfaceData>(null);
registrator.RegisterData<DiseaseData>(null);
registrator.RegisterData<SeawaterPump>(null);
registrator.RegisterData<Waterwell>(null);
registrator.RegisterData<SettlingTank>(null);
registrator.RegisterData<LiquidDumps>(null);
registrator.RegisterData<AirSeparator>(null);
registrator.RegisterData<StackerLong>(null);
registrator.RegisterData<StackerT2>(null);
registrator.RegisterData<DryDock>(null);
registrator.RegisterData<FluidStorage>(null);
registrator.RegisterData<StoragesT5>(null);
registrator.RegisterData<LiquidDump>(null);
registrator.RegisterData<AdvancedPumping>(null);
registrator.RegisterData<MegaStorage>(null);
registrator.RegisterData<Nitrogen>(null);
registrator.RegisterData<COIExtended.Prototypes.Recipes.Titanium>(null);
registrator.RegisterData<COIExtended.Prototypes.Research.Titanium>(null);
registrator.RegisterData<CargoShip>(null);
registrator.RegisterData<ChemicalPlant>(null);
registrator.RegisterData<ChemicalPlantT3>(null);
registrator.RegisterData<ScrubberT2>(null);
registrator.RegisterData<PhotoOxidation>(null);
registrator.RegisterData<COIFleetData>(null);
registrator.RegisterData<HardwareStoreModule>(null);
registrator.RegisterData<HardwareConsumptionEdict>(null);
registrator.RegisterData<HardwareStoreResearch>(null);
registrator.RegisterData<FishingDock>(null);
registrator.RegisterData<FishingDockResearch>(null);
registrator.RegisterData<ConstructionPartsV>(null);
registrator.RegisterData<COIExtended.Prototypes.Buildings.ResearchLab6>(null);
registrator.RegisterData<COIExtended.Prototypes.Research.ResearchLab6>(null);
registrator.RegisterData<COIETransportData>(null);
registrator.RegisterData<PipeT4>(null);
registrator.RegisterData<ConveyorBeltsT4>(null);
registrator.RegisterData<COIExtended.Prototypes.Machines.Assembler3>(null);
registrator.RegisterData<ShipArmor3>(null);
registrator.RegisterData<MarketModules>(null);
registrator.RegisterData<DataCenters>(null);
registrator.RegisterData<COIExtended.Prototypes.Research.Assembler3>(null);
registrator.RegisterData<COIExtended.Prototypes.Machines.CVDPlant>(null);
registrator.RegisterData<COIExtended.Prototypes.Research.CVDPlant>(null);
registrator.RegisterData<LithiumSalts>(null);
registrator.RegisterData<NanochipMachines>(null);
registrator.RegisterData<COIERocketData>(null);
registrator.RegisterData<GoldFurnaceT2>(null);
registrator.RegisterData<NanochipProduction>(null);
registrator.RegisterData<ServerT2>(null);
registrator.RegisterData<NewShredderData>(null);
registrator.RegisterData<BatteryEfficiencyEdict>(null);
registrator.RegisterData<PowerExchangerData>(null);
registrator.RegisterData<Batteries3>(null);
registrator.RegisterData<Batteries2>(null);
registrator.RegisterData<Batteries>(null);
registrator.RegisterData<TransportsResearch>(null);
registrator.RegisterData<SeawallsData>(null);
registrator.RegisterData<Seawalls>(null);
registrator.RegisterData<IndustrialMixer>(null);
registrator.RegisterData<NuclearReactorsData>(null);
registrator.RegisterData<TritiumEnrichment>(null);
registrator.RegisterData<COIExtended.Prototypes.Machines.DesalinatorT2>(null);
registrator.RegisterData<COIExtended.Prototypes.Research.DesalinatorT2>(null);
registrator.RegisterData<ChillerBoilerT2>(null);
registrator.RegisterData<ThermalEfficiency>(null);
registrator.RegisterData<PowerGeneratorsData>(null);
registrator.RegisterData<TurbineEfficiency>(null);
registrator.RegisterData<FusionReactor>(null);
registrator.RegisterData<DigesterT2>(null);
registrator.RegisterData<MixerT3>(null);
registrator.RegisterData<FertilizerT3>(null);
registrator.RegisterData<NanoDistillationData>(null);
registrator.RegisterData<NanoDistillation>(null);
registrator.RegisterData<PassiveTruckCapacity>(null);
registrator.RegisterData<PassiveTruckCapacityT1>(null);
registrator.RegisterData<MicrochipRetrofitting>(null);
registrator.RegisterData<OreSortingPlantData>(null);
registrator.RegisterData<OreSortingPlantResearch>(null);
registrator.RegisterData<Locations>(null);
registrator.RegisterData<TractorTrucksData>(null);
registrator.RegisterData<TractorTrucks>(null);
registrator.RegisterData<MoreVehicleRamps>(null);
cargoShipPatcher.runPatch();
areaSizePatcher.applyPatch();
}
public void RegisterDependencies(DependencyResolverBuilder depBuilder, ProtosDb protosDb, bool wasLoaded)
{
Debug.Log("[COIE]: Registering all dependencies...");
}
private void InitializePatchers(DependencyResolver resolver)
{
Debug.Log("[COIE]: Initializing patches...");
}
private LystStruct<Pair<string, IWorldRegionMapPreviewData>> m_loadedMapPreviewsTmp;
private Option<MapSerializer> m_mapSerializer;
public Harmony HarmonyInstance;
}
}