Decompiled source of Map Texture Replacer v2.0.2

MapTextureReplacer.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
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 BepInEx;
using Colossal;
using Colossal.IO.AssetDatabase;
using Colossal.Serialization.Entities;
using Colossal.UI.Binding;
using Game;
using Game.Assets;
using Game.Audio;
using Game.Common;
using Game.Modding;
using Game.SceneFlow;
using Game.Settings;
using Game.UI;
using HarmonyLib;
using HookUILib.Core;
using MapTextureReplacer.Helpers;
using MapTextureReplacer.Locale;
using MapTextureReplacer.Systems;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Unity.Entities;
using UnityEngine;
using cohtml.Net;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MapTextureReplacer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that I made for Cities: Skylines 2")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("MapTextureReplacer")]
[assembly: AssemblyTitle("MapTextureReplacer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 MapTextureReplacer
{
	[FileLocation("MapTextureReplacer")]
	public class MapTextureReplacerOptions : ModSetting
	{
		private MapTextureReplacerSystem m_MapTextureReplacerSystem;

		[SettingsUIButton]
		[SettingsUIConfirmation(null, null)]
		public bool ResetModSettings
		{
			set
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				MakeSureSave = new Random().Next();
				TextureSelectData = "[{\"Key\":\"Default\",\"Value\":\"none\"},{\"Key\":\"Default\",\"Value\":\"none\"},{\"Key\":\"Default\",\"Value\":\"none\"},{\"Key\":\"Default\",\"Value\":\"none\"},{\"Key\":\"Default\",\"Value\":\"none\"},{\"Key\":\"Default\",\"Value\":\"none\"}]";
				ActiveDropdown = "none";
				CurrentTilingVector = Vector4.zero;
				World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
				m_MapTextureReplacerSystem = ((defaultGameObjectInjectionWorld != null) ? defaultGameObjectInjectionWorld.GetOrCreateSystemManaged<MapTextureReplacerSystem>() : null);
				m_MapTextureReplacerSystem.ChangePack("none");
			}
		}

		[SettingsUIHidden]
		public string ActiveDropdown { get; set; }

		[SettingsUIHidden]
		public string TextureSelectData { get; set; }

		[SettingsUIHidden]
		public Vector4 CurrentTilingVector { get; set; }

		[SettingsUIHidden]
		public int MakeSureSave { get; set; }

		public MapTextureReplacerOptions(IMod mod)
			: base(mod)
		{
			((Setting)this).SetDefaults();
		}

		public override void SetDefaults()
		{
			MakeSureSave = 0;
		}
	}
	public class MapTextureReplacerMod : IMod
	{
		public static MapTextureReplacerOptions Options { get; set; }

		public static MapTextureReplacerMod Instance { get; private set; }

		public void OnDisable()
		{
		}

		public void OnDispose()
		{
		}

		public void OnEnable()
		{
		}

		public void OnLoad()
		{
			Instance = this;
		}

		public void OnCreateWorld(UpdateSystem updateSystem)
		{
			Options = new MapTextureReplacerOptions((IMod)(object)this);
			((ModSetting)Options).RegisterInOptionsUI();
			AssetDatabase.global.LoadSettings("MapTextureOptions", (object)Options, (object)new MapTextureReplacerOptions((IMod)(object)this));
			string[] supportedLocales = GameManager.instance.localizationManager.GetSupportedLocales();
			foreach (string text in supportedLocales)
			{
				GameManager.instance.localizationManager.AddSource(text, (IDictionarySource)(object)new LocaleEN(Options));
			}
			AssetDatabase.global.SaveSettingsNow();
		}
	}
	[BepInPlugin("MapTextureReplacer", "MapTextureReplacer", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static MapTextureReplacerMod _mod;

		private void Awake()
		{
			_mod = new MapTextureReplacerMod();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MapTextureReplacer is loaded!");
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "MapTextureReplacer_Cities2Harmony");
			MethodBase[] array = val.GetPatchedMethods().ToArray();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin MapTextureReplacer made patches! Patched methods: " + array.Length));
			MethodBase[] array2 = array;
			foreach (MethodBase methodBase in array2)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched method: " + methodBase.Module.Name + ":" + methodBase.Name));
			}
			_mod.OnLoad();
		}
	}
	public class MapTextureReplacerUI : UIExtension
	{
		public readonly string extensionID = "example.map_texture";

		public readonly string extensionContent;

		public readonly ExtensionType extensionType = (ExtensionType)0;

		public MapTextureReplacerUI()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			extensionContent = ((UIExtension)this).LoadEmbeddedResource("MapTextureReplacer.dist.bundle.js");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MapTextureReplacer";

		public const string PLUGIN_NAME = "MapTextureReplacer";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace MapTextureReplacer.Systems
{
	public class MapTextureReplacerEditorUISystem : GameSystemBase
	{
		private View m_UIView;

		protected override void OnCreate()
		{
			((GameSystemBase)this).OnCreate();
		}

		public void CreateAssetEditorButton()
		{
			Debug.Log((object)"CreateAssetEditorButton() Loaded!");
			m_UIView = GameManager.instance.userInterface.view.View;
			m_UIView.ExecuteScript("document.querySelector(\".maptexturereplacer_custom_container\")?.parentNode?.removeChild(document.querySelector(\".maptexturereplacer_custom_container\"));");
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MapTextureReplacer.dist.game_editor.compiled.js");
			using StreamReader streamReader = new StreamReader(stream);
			m_UIView.ExecuteScript(streamReader.ReadToEnd());
		}

		protected override void OnUpdate()
		{
		}
	}
	public class MapTextureReplacerInGameLoadedSystem : GameSystemBase
	{
		private MapTextureReplacerSystem m_mapTextureReplacerSystem;

		protected override void OnCreate()
		{
		}

		public void RunAction()
		{
			m_mapTextureReplacerSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<MapTextureReplacerSystem>();
			((GameSystemBase)this).OnCreate();
			StaticCoroutine.Start(ReapplyTexture(m_mapTextureReplacerSystem));
		}

		private static IEnumerator ReapplyTexture(MapTextureReplacerSystem m_mapTextureReplacerSystem)
		{
			yield return (object)new WaitForEndOfFrame();
			yield return (object)new WaitForEndOfFrame();
			List<string> textureTypeKeys = new List<string>(m_mapTextureReplacerSystem.textureTypes.Keys);
			for (int i = 0; i < textureTypeKeys.Count; i++)
			{
				if (m_mapTextureReplacerSystem.textureSelectData[i].Value != "none")
				{
					m_mapTextureReplacerSystem.OpenImage(textureTypeKeys[i], m_mapTextureReplacerSystem.textureSelectData[i].Value);
				}
			}
			if (MapTextureReplacerMod.Options.CurrentTilingVector != Vector4.zeroVector)
			{
				Shader.SetGlobalVector(Shader.PropertyToID("colossal_TerrainTextureTiling"), MapTextureReplacerMod.Options.CurrentTilingVector);
			}
		}

		protected override void OnUpdate()
		{
		}
	}
	public class MapTextureReplacerSystem : GameSystemBase
	{
		public string PackImportedText = "";

		private Dictionary<string, string> importedPacks = new Dictionary<string, string>();

		public string importedPacksJsonString;

		public string textureSelectDataJsonString;

		public List<KeyValuePair<string, string>> textureSelectData = new List<KeyValuePair<string, string>>
		{
			new KeyValuePair<string, string>("Default", "none"),
			new KeyValuePair<string, string>("Default", "none"),
			new KeyValuePair<string, string>("Default", "none"),
			new KeyValuePair<string, string>("Default", "none"),
			new KeyValuePair<string, string>("Default", "none"),
			new KeyValuePair<string, string>("Default", "none")
		};

		private static Dictionary<string, Texture> mapTextureCache = new Dictionary<string, Texture>();

		private static bool isOver;

		public readonly Dictionary<string, string> textureTypes = new Dictionary<string, string>
		{
			{ "colossal_TerrainGrassDiffuse", "Grass_BaseColor.png" },
			{ "colossal_TerrainGrassNormal", "Grass_Normal.png" },
			{ "colossal_TerrainDirtDiffuse", "Dirt_BaseColor.png" },
			{ "colossal_TerrainDirtNormal", "Dirt_Normal.png" },
			{ "colossal_TerrainRockDiffuse", "Cliff_BaseColor.png" },
			{ "colossal_TerrainRockNormal", "Cliff_Normal.png" }
		};

		protected override void OnCreate()
		{
			((GameSystemBase)this).OnCreate();
			if (MapTextureReplacerMod.Options.TextureSelectData == null)
			{
				MapTextureReplacerMod.Options.ActiveDropdown = "none";
				SetTextureSelectDataJson();
			}
			else
			{
				textureSelectData = JsonConvert.DeserializeObject<List<KeyValuePair<string, string>>>(MapTextureReplacerMod.Options.TextureSelectData);
			}
			foreach (KeyValuePair<string, string> textureType in textureTypes)
			{
				CacheExistingTexture(textureType.Key);
			}
			List<string> list = new List<string>();
			DirectoryInfo parent = Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
			string[] files = Directory.GetFiles(parent.FullName, "*.json", SearchOption.AllDirectories);
			foreach (string path in files)
			{
				string fileName = Path.GetFileName(path);
				if (fileName == "maptextureconfig.json")
				{
					list.Add(Directory.GetParent(path).FullName);
				}
			}
			foreach (string item in list)
			{
				string[] files2 = Directory.GetFiles(item);
				foreach (string text in files2)
				{
					string fileName2 = Path.GetFileName(text);
					if (fileName2 == "maptextureconfig.json")
					{
						MapTextureConfig mapTextureConfig = JsonConvert.DeserializeObject<MapTextureConfig>(File.ReadAllText(text));
						importedPacks.Add(text, mapTextureConfig.pack_name);
					}
				}
			}
			importedPacksJsonString = JsonConvert.SerializeObject((object)importedPacks);
			textureSelectDataJsonString = JsonConvert.SerializeObject((object)textureSelectData);
		}

		protected override void OnUpdate()
		{
		}

		public void ChangePack(string current)
		{
			if (current == "none")
			{
				foreach (KeyValuePair<string, string> textureType in textureTypes)
				{
					ResetTexture(textureType.Key);
				}
				SetTilingValueDefault();
			}
			else if (current.EndsWith(".zip"))
			{
				OpenTextureZip(current.Split(',')[1]);
				SetSelectImageAllText(current.Split(',')[0], current);
			}
			else
			{
				if (!current.EndsWith(".json"))
				{
					return;
				}
				string directoryName = Path.GetDirectoryName(current);
				string[] files = Directory.GetFiles(directoryName);
				foreach (string filePath in files)
				{
					foreach (KeyValuePair<string, string> textureType2 in textureTypes)
					{
						LoadImageFile(filePath, textureType2.Value, textureType2.Key);
					}
				}
				MapTextureConfig mapTextureConfig = JsonConvert.DeserializeObject<MapTextureConfig>(File.ReadAllText(current));
				SetTilingValues(mapTextureConfig.far_tiling, mapTextureConfig.close_tiling, mapTextureConfig.close_dirt_tiling);
				SetSelectImageAllText(mapTextureConfig.pack_name, current);
			}
		}

		private void SetSelectImageAllText(string key, string path)
		{
			for (int i = 0; i < textureSelectData.Count; i++)
			{
				textureSelectData[i] = new KeyValuePair<string, string>(key, path);
			}
			SetTextureSelectDataJson();
		}

		private void SetTextureSelectDataJson()
		{
			textureSelectDataJsonString = JsonConvert.SerializeObject((object)textureSelectData);
			MapTextureReplacerMod.Options.TextureSelectData = textureSelectDataJsonString;
			AssetDatabase.global.SaveSettingsNow();
		}

		public void SetTilingValues(string far, string close, string dirtClose)
		{
			TileVectorChange("colossal_TerrainTextureTiling", 0, int.Parse(far));
			TileVectorChange("colossal_TerrainTextureTiling", 1, int.Parse(close));
			TileVectorChange("colossal_TerrainTextureTiling", 2, int.Parse(dirtClose));
		}

		public void SetTilingValueDefault()
		{
			TileVectorChange("colossal_TerrainTextureTiling", 0, 160);
			TileVectorChange("colossal_TerrainTextureTiling", 1, 1600);
			TileVectorChange("colossal_TerrainTextureTiling", 2, 2400);
		}

		private static void LoadImageFile(string filePath, string textureFile, string shaderProperty)
		{
			if (Path.GetFileName(filePath) == textureFile)
			{
				byte[] fileData = File.ReadAllBytes(filePath);
				LoadTextureInGame(shaderProperty, fileData);
			}
		}

		public void OpenImage(string shaderProperty, string packPath)
		{
			string text = "";
			foreach (KeyValuePair<string, string> textureType in textureTypes)
			{
				if (textureType.Key == shaderProperty)
				{
					text = textureType.Value;
				}
			}
			if (packPath == "")
			{
				string text2 = OpenFileDialog.ShowDialog("Image files\0*.jpg;*.png\0");
				if (!string.IsNullOrEmpty(text2))
				{
					byte[] fileData = File.ReadAllBytes(text2);
					LoadTextureInGame(shaderProperty, fileData);
					int index = textureTypes.Keys.ToList().IndexOf(shaderProperty);
					string key = ShortenDisplayedFilename(text2);
					textureSelectData[index] = new KeyValuePair<string, string>(key, text2);
					SetTextureSelectDataJson();
				}
				return;
			}
			if (packPath.EndsWith(".zip"))
			{
				int index2 = textureTypes.Keys.ToList().IndexOf(shaderProperty);
				textureSelectData[index2] = new KeyValuePair<string, string>(packPath.Split(',')[0], packPath);
				SetTextureSelectDataJson();
				using ZipArchive archive = ZipFile.Open(packPath.Split(',')[1], ZipArchiveMode.Read);
				ExtractEntry(archive, text, shaderProperty);
				return;
			}
			int index3 = textureTypes.Keys.ToList().IndexOf(shaderProperty);
			string value;
			string key2 = (importedPacks.TryGetValue(packPath, out value) ? value : ShortenDisplayedFilename(Path.GetFileName(packPath)));
			textureSelectData[index3] = new KeyValuePair<string, string>(key2, packPath);
			SetTextureSelectDataJson();
			if (packPath.EndsWith(".json"))
			{
				string directoryName = Path.GetDirectoryName(packPath);
				string[] files = Directory.GetFiles(directoryName);
				foreach (string filePath in files)
				{
					LoadImageFile(filePath, text, shaderProperty);
				}
			}
			else
			{
				byte[] fileData2 = File.ReadAllBytes(packPath);
				LoadTextureInGame(shaderProperty, fileData2);
			}
		}

		private static string ShortenDisplayedFilename(string file)
		{
			string text = Path.GetFileName(file);
			if (text.Length > 15)
			{
				text = text.Substring(0, 15);
			}
			return text;
		}

		public void GetTextureZip()
		{
			string text = OpenFileDialog.ShowDialog("Zip archives\0*.zip\0");
			PackImportedText = Path.GetFileNameWithoutExtension(text) + "," + text;
		}

		public void OpenTextureZip(string zipFilePath)
		{
			if (string.IsNullOrEmpty(zipFilePath))
			{
				return;
			}
			using ZipArchive archive = ZipFile.Open(zipFilePath, ZipArchiveMode.Read);
			List<string> list = new List<string>();
			if (!ExtractEntry(archive, "Grass_BaseColor.png", "colossal_TerrainGrassDiffuse"))
			{
				list.Add("Grass_BaseColor.png");
			}
			if (!ExtractEntry(archive, "Grass_Normal.png", "colossal_TerrainGrassNormal"))
			{
				list.Add("Grass_Normal.png");
			}
			if (!ExtractEntry(archive, "Dirt_BaseColor.png", "colossal_TerrainDirtDiffuse"))
			{
				list.Add("Dirt_BaseColor.png");
			}
			if (!ExtractEntry(archive, "Dirt_Normal.png", "colossal_TerrainDirtNormal"))
			{
				list.Add("Dirt_Normal.png");
			}
			if (!ExtractEntry(archive, "Cliff_BaseColor.png", "colossal_TerrainRockDiffuse"))
			{
				list.Add("Cliff_BaseColor.png");
			}
			if (!ExtractEntry(archive, "Cliff_Normal.png", "colossal_TerrainRockNormal"))
			{
				list.Add("Cliff_Normal.png");
			}
			if (list.Count <= 0)
			{
				return;
			}
			string text = "Files not found in .zip file:\n";
			foreach (string item in list)
			{
				text = text + "\n" + item;
			}
			throw new Exception(text + "\n\n");
		}

		private static void CacheExistingTexture(string shaderProperty)
		{
			Texture globalTexture = Shader.GetGlobalTexture(Shader.PropertyToID(shaderProperty));
			if (!mapTextureCache.ContainsKey(shaderProperty))
			{
				mapTextureCache.Add(shaderProperty, globalTexture);
			}
		}

		private static void LoadTextureInGame(string shaderProperty, byte[] fileData)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Texture2D val = new Texture2D(4096, 4096);
			ImageConversion.LoadImage(val, fileData);
			Shader.SetGlobalTexture(Shader.PropertyToID(shaderProperty), (Texture)(object)val);
			Debug.Log((object)("Replaced " + shaderProperty + " ingame"));
		}

		public void ResetTexture(string shaderProperty)
		{
			mapTextureCache.TryGetValue(shaderProperty, out var value);
			if ((Object)(object)value != (Object)null)
			{
				Shader.SetGlobalTexture(Shader.PropertyToID(shaderProperty), value);
			}
			int index = textureTypes.Keys.ToList().IndexOf(shaderProperty);
			textureSelectData[index] = new KeyValuePair<string, string>("Default", "none");
			SetTextureSelectDataJson();
		}

		private static bool ExtractEntry(ZipArchive archive, string entryName, string shaderProperty)
		{
			ZipArchiveEntry entry = archive.GetEntry(entryName);
			if (entry != null)
			{
				using (Stream stream = entry.Open())
				{
					byte[] array = new byte[entry.Length];
					stream.Read(array, 0, array.Length);
					LoadTextureInGame(shaderProperty, array);
				}
				return true;
			}
			return false;
		}

		public void SetTile(int v)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Shader.SetGlobalVector(Shader.PropertyToID("colossal_TerrainTextureTiling"), new Vector4((float)new Random().Next(0, 10000), (float)new Random().Next(0, 10000), (float)new Random().Next(0, 10000), 1f));
		}

		public void ResetTextureSelectData()
		{
			textureSelectData = new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("Default", "none"),
				new KeyValuePair<string, string>("Default", "none"),
				new KeyValuePair<string, string>("Default", "none"),
				new KeyValuePair<string, string>("Default", "none"),
				new KeyValuePair<string, string>("Default", "none"),
				new KeyValuePair<string, string>("Default", "none")
			};
			SetTextureSelectDataJson();
		}

		public void SetTexturesGameLoad()
		{
			List<string> list = new List<string>(textureTypes.Keys);
			for (int i = 0; i < list.Count; i++)
			{
				OpenImage(list[i], textureSelectData[i].Value);
			}
		}

		public void SetActivePackDropdown(string data)
		{
			try
			{
				MapTextureReplacerMod.Options.ActiveDropdown = data;
				AssetDatabase.global.SaveSettingsNow();
			}
			catch
			{
				Debug.Log((object)"ActivePackDropdown Call Cancelled");
			}
		}

		public string GetActivePackDropdown()
		{
			return MapTextureReplacerMod.Options.ActiveDropdown;
		}

		public void TileVectorChange(string shaderProperty, int vectorIndex, int tileValue)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			int num = Shader.PropertyToID(shaderProperty);
			Vector4 globalVector = Shader.GetGlobalVector(num);
			((Vector4)(ref globalVector))[vectorIndex] = tileValue;
			Shader.SetGlobalVector(num, globalVector);
			MapTextureReplacerMod.Options.CurrentTilingVector = globalVector;
			if (!isOver)
			{
				StaticCoroutine.Start(SaveSettingsOnceAfterDelay());
			}
			isOver = true;
		}

		private static IEnumerator SaveSettingsOnceAfterDelay()
		{
			yield return (object)new WaitForSeconds(2f);
			AssetDatabase.global.SaveSettingsNow();
			isOver = false;
		}
	}
	public class MapTextureReplacerUISystem : UISystemBase
	{
		public int current_vehicle_count = 0;

		public MapTextureReplacerSystem systemManaged;

		private Dictionary<string, Action<int>> handlers = new Dictionary<string, Action<int>>();

		protected override void OnCreate()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Expected O, but got Unknown
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Expected O, but got Unknown
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			systemManaged = ((ComponentSystemBase)this).World.GetExistingSystemManaged<MapTextureReplacerSystem>();
			((UISystemBase)this).OnCreate();
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<string>("map_texture", "texture_pack", (Func<string>)(() => systemManaged.PackImportedText), (IWriter<string>)null, (EqualityComparer<string>)null));
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<string>("map_texture", "get_detected_packs", (Func<string>)(() => systemManaged.importedPacksJsonString), (IWriter<string>)null, (EqualityComparer<string>)null));
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<string>("map_texture", "get_texture_select_data", (Func<string>)(() => systemManaged.textureSelectDataJsonString), (IWriter<string>)null, (EqualityComparer<string>)null));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_select_data", (Action)systemManaged.ResetTextureSelectData));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "open_texture_zip", (Action)systemManaged.GetTextureZip));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "change_pack", (Action<string>)systemManaged.ChangePack, (IReader<string>)null));
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<string>("map_texture", "get_active_pack_dropdown", (Func<string>)(() => systemManaged.GetActivePackDropdown()), (IWriter<string>)null, (EqualityComparer<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "set_active_pack_dropdown", (Action<string>)systemManaged.SetActivePackDropdown, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_gd", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainGrassDiffuse", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_gn", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainGrassNormal", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_dd", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainDirtDiffuse", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_dn", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainDirtNormal", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_cd", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainRockDiffuse", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<string>("map_texture", "open_image_cn", (Action<string>)delegate(string imageFile)
			{
				systemManaged.OpenImage("colossal_TerrainRockNormal", imageFile);
			}, (IReader<string>)null));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_gd", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainGrassDiffuse");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_gn", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainGrassNormal");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_dd", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainDirtDiffuse");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_dn", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainDirtNormal");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_cd", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainRockDiffuse");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_texture_cn", (Action)delegate
			{
				systemManaged.ResetTexture("colossal_TerrainRockNormal");
			}));
			((UISystemBase)this).AddBinding((IBinding)new TriggerBinding("map_texture", "reset_tiling", (Action)systemManaged.SetTilingValueDefault));
			AddSlider("slider1", "colossal_TerrainTextureTiling", 0);
			AddSlider("slider2", "colossal_TerrainTextureTiling", 1);
			AddSlider("slider3", "colossal_TerrainTextureTiling", 2);
		}

		private void AddSlider(string sliderName, string shaderProperty, int vectorIndex)
		{
			((UISystemBase)this).AddUpdateBinding((IUpdateBinding)(object)new GetterValueBinding<int>("map_texture", sliderName + "_Pos", (Func<int>)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Vector4 globalVector = Shader.GetGlobalVector(Shader.PropertyToID(shaderProperty));
				return (int)((Vector4)(ref globalVector))[vectorIndex];
			}, (IWriter<int>)null, (EqualityComparer<int>)null));
			((UISystemBase)this).AddBinding((IBinding)(object)new TriggerBinding<int>("map_texture", sliderName + "_UpdatedValue", (Action<int>)delegate(int tileValue)
			{
				systemManaged.TileVectorChange(shaderProperty, vectorIndex, tileValue);
			}, (IReader<int>)null));
		}
	}
}
namespace MapTextureReplacer.Patches
{
	[HarmonyPatch(typeof(SystemOrder), "Initialize")]
	internal class InjectSystemsPatch
	{
		[HarmonyBefore(new string[] { "Gooee_Cities2Harmony" })]
		private static void Postfix(UpdateSystem updateSystem)
		{
			MapTextureReplacerMod.Instance.OnCreateWorld(updateSystem);
			updateSystem.UpdateAt<MapTextureReplacerSystem>((SystemUpdatePhase)11);
			updateSystem.UpdateAt<MapTextureReplacerUISystem>((SystemUpdatePhase)22);
		}
	}
	[HarmonyPatch(typeof(AudioManager), "OnGameLoadingComplete")]
	internal class AudioManager_OnGameLoadingComplete
	{
		private static void Postfix(AudioManager __instance, Purpose purpose, GameMode mode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!GameModeExtensions.IsGameOrEditor(mode))
			{
				return;
			}
			World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
			if (defaultGameObjectInjectionWorld != null)
			{
				defaultGameObjectInjectionWorld.GetOrCreateSystemManaged<MapTextureReplacerInGameLoadedSystem>().RunAction();
			}
			if (GameModeExtensions.IsEditor(mode))
			{
				World defaultGameObjectInjectionWorld2 = World.DefaultGameObjectInjectionWorld;
				if (defaultGameObjectInjectionWorld2 != null)
				{
					defaultGameObjectInjectionWorld2.GetOrCreateSystemManaged<MapTextureReplacerEditorUISystem>().CreateAssetEditorButton();
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameManager))]
	public static class SavePatch
	{
		private static Texture[] setTexturesCache;

		private static readonly string[] propertyNames;

		[HarmonyPatch("Save", new Type[]
		{
			typeof(string),
			typeof(SaveInfo),
			typeof(ILocalAssetDatabase),
			typeof(Texture)
		})]
		[HarmonyPrefix]
		public static void Prefix()
		{
			for (int i = 0; i < setTexturesCache.Length; i++)
			{
				setTexturesCache[i] = Shader.GetGlobalTexture(Shader.PropertyToID(propertyNames[i]));
			}
		}

		[HarmonyPatch("Save", new Type[]
		{
			typeof(string),
			typeof(SaveInfo),
			typeof(ILocalAssetDatabase),
			typeof(Texture)
		})]
		[HarmonyPostfix]
		public static void Postfix()
		{
			StaticCoroutine.Start(ReapplyTexture());
		}

		private static IEnumerator ReapplyTexture()
		{
			yield return (object)new WaitForEndOfFrame();
			for (int i = 0; i < setTexturesCache.Length; i++)
			{
				Shader.SetGlobalTexture(Shader.PropertyToID(propertyNames[i]), setTexturesCache[i]);
				Debug.Log((object)"Map Textures Reapplied After Save");
			}
		}

		static SavePatch()
		{
			Texture[] array = (Texture[])(object)new Texture2D[6];
			setTexturesCache = array;
			propertyNames = new string[6] { "colossal_TerrainGrassDiffuse", "colossal_TerrainGrassNormal", "colossal_TerrainDirtDiffuse", "colossal_TerrainDirtNormal", "colossal_TerrainRockDiffuse", "colossal_TerrainRockNormal" };
		}
	}
}
namespace MapTextureReplacer.Locale
{
	public class LocaleEN : IDictionarySource
	{
		private readonly MapTextureReplacerOptions m_Setting;

		public LocaleEN(MapTextureReplacerOptions options)
		{
			m_Setting = options;
		}

		public IEnumerable<KeyValuePair<string, string>> ReadEntries(IList<IDictionaryEntryError> errors, Dictionary<string, int> indexCounts)
		{
			return new Dictionary<string, string>
			{
				{
					((ModSetting)m_Setting).GetSettingsLocaleID(),
					"Map Texture Replacer"
				},
				{
					((ModSetting)m_Setting).GetOptionLabelLocaleID("ResetModSettings"),
					"Reset All Settings"
				},
				{
					((ModSetting)m_Setting).GetOptionDescLocaleID("ResetModSettings"),
					"Reset Mod Settings to Default Values"
				},
				{
					((ModSetting)m_Setting).GetOptionWarningLocaleID("ResetModSettings"),
					"Are you sure you want to reset all mod settings?"
				}
			};
		}

		public void Unload()
		{
		}
	}
}
namespace MapTextureReplacer.Helpers
{
	public class MapTextureConfig
	{
		public string pack_name { get; set; }

		public string far_tiling { get; set; }

		public string close_tiling { get; set; }

		public string close_dirt_tiling { get; set; }
	}
	public class OpenFileDialog
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		private class OpenFileName
		{
			public int structSize = 0;

			public IntPtr dlgOwner = IntPtr.Zero;

			public IntPtr instance = IntPtr.Zero;

			public string filter = null;

			public string customFilter = null;

			public int maxCustFilter = 0;

			public int filterIndex = 0;

			public string file = null;

			public int maxFile = 0;

			public string fileTitle = null;

			public int maxFileTitle = 0;

			public string initialDir = null;

			public string title = null;

			public int flags = 0;

			public short fileOffset = 0;

			public short fileExtension = 0;

			public string defExt = null;

			public IntPtr custData = IntPtr.Zero;

			public IntPtr hook = IntPtr.Zero;

			public string templateName = null;

			public IntPtr reservedPtr = IntPtr.Zero;

			public int reservedInt = 0;

			public int flagsEx = 0;
		}

		[DllImport("comdlg32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		private static extern bool GetOpenFileName([In][Out] OpenFileName ofn);

		public static string ShowDialog(string filter = "All Files\0*.*\0", string defaultExt = "")
		{
			OpenFileName openFileName = new OpenFileName();
			openFileName.structSize = Marshal.SizeOf(openFileName);
			openFileName.filter = filter;
			openFileName.file = new string(new char[256]);
			openFileName.maxFile = openFileName.file.Length;
			openFileName.fileTitle = new string(new char[64]);
			openFileName.maxFileTitle = openFileName.fileTitle.Length;
			openFileName.initialDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			openFileName.title = "Open File";
			openFileName.defExt = defaultExt;
			if (GetOpenFileName(openFileName))
			{
				return openFileName.file;
			}
			return null;
		}
	}
	public class StaticCoroutine : MonoBehaviour
	{
		public static StaticCoroutine m_instance;

		private void OnDestroy()
		{
			((MonoBehaviour)m_instance).StopAllCoroutines();
		}

		private void OnApplicationQuit()
		{
			((MonoBehaviour)m_instance).StopAllCoroutines();
		}

		private static StaticCoroutine Build()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			if ((Object)(object)m_instance != (Object)null)
			{
				return m_instance;
			}
			m_instance = (StaticCoroutine)(object)Object.FindObjectOfType(typeof(StaticCoroutine));
			if ((Object)(object)m_instance != (Object)null)
			{
				return m_instance;
			}
			GameObject val = new GameObject("StaticCoroutine");
			val.AddComponent<StaticCoroutine>();
			m_instance = val.GetComponent<StaticCoroutine>();
			if ((Object)(object)m_instance != (Object)null)
			{
				return m_instance;
			}
			Debug.LogError((object)"Build did not generate a replacement instance. Method Failed!");
			return null;
		}

		public static void Start(string methodName)
		{
			((MonoBehaviour)Build()).StartCoroutine(methodName);
		}

		public static void Start(string methodName, object value)
		{
			((MonoBehaviour)Build()).StartCoroutine(methodName, value);
		}

		public static void Start(IEnumerator routine)
		{
			((MonoBehaviour)Build()).StartCoroutine(routine);
		}
	}
}