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 BepInEx;
using BepInEx.Logging;
using Colossal.IO.AssetDatabase;
using Colossal.Localization;
using Colossal.Serialization.Entities;
using Game;
using Game.Settings;
using Gooee;
using Gooee.Plugins;
using Gooee.Plugins.Attributes;
using HarmonyLib;
using HighwayNameRemover.Configuration;
using HighwayNameRemover.Localization;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HighwayNameRemover")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+0b2922b1761d03089b81e25ce9007a38be2cf6fe")]
[assembly: AssemblyProduct("HighwayNameRemover")]
[assembly: AssemblyTitle("HighwayNameRemover")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.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 HighwayNameRemover
{
public class HighwayNameRemoverController : Controller<HighwayNameRemoverModel>
{
private HighwayNameRemoverSettings _modSettings;
public static readonly HighwayNameRemoverConfig _config = ConfigBase.Load<HighwayNameRemoverConfig>();
public static HighwayNameRemoverModel _model;
public override HighwayNameRemoverModel Configure()
{
_model = new HighwayNameRemoverModel();
_model.HideHighwayNames = _config.HideHighwayNames;
_model.HideStreetNames = _config.HideStreetNames;
_model.HideAlleyNames = _config.HideAlleyNames;
_model.HideBridgeNames = _config.HideBridgeNames;
_model.HideDamNames = _config.HideDamNames;
return _model;
}
protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
((GameSystemBase)this).OnGameLoadingComplete(purpose, mode);
if ((int)mode == 2)
{
if ((base.Plugin as HighwayNameRemoverPlugin).Settings is HighwayNameRemoverSettings modSettings)
{
_modSettings = modSettings;
}
UpdateFromSettings();
}
}
private void UpdateFromSettings()
{
if (_modSettings != null)
{
if (_modSettings.HideHighwayNames != base.Model.HideHighwayNames)
{
base.Model.HideHighwayNames = _modSettings.HideHighwayNames;
base.TriggerUpdate();
}
if (_modSettings.HideStreetNames != base.Model.HideStreetNames)
{
base.Model.HideStreetNames = _modSettings.HideStreetNames;
base.TriggerUpdate();
}
if (_modSettings.HideAlleyNames != base.Model.HideAlleyNames)
{
base.Model.HideAlleyNames = _modSettings.HideAlleyNames;
base.TriggerUpdate();
}
if (_modSettings.HideBridgeNames != base.Model.HideBridgeNames)
{
base.Model.HideBridgeNames = _modSettings.HideBridgeNames;
base.TriggerUpdate();
}
if (_modSettings.HideDamNames != base.Model.HideDamNames)
{
base.Model.HideDamNames = _modSettings.HideDamNames;
base.TriggerUpdate();
}
}
}
protected override void OnModelUpdated()
{
if (base.Model.HideHighwayNames != _config.HideHighwayNames)
{
_config.HideHighwayNames = base.Model.HideHighwayNames;
_config.Save();
}
if (base.Model.HideStreetNames != _config.HideStreetNames)
{
_config.HideStreetNames = base.Model.HideStreetNames;
_config.Save();
}
if (base.Model.HideAlleyNames != _config.HideAlleyNames)
{
_config.HideAlleyNames = base.Model.HideAlleyNames;
_config.Save();
}
if (base.Model.HideBridgeNames != _config.HideBridgeNames)
{
_config.HideBridgeNames = base.Model.HideBridgeNames;
_config.Save();
}
if (base.Model.HideDamNames != _config.HideDamNames)
{
_config.HideDamNames = base.Model.HideDamNames;
_config.Save();
}
}
protected override void OnSettingsUpdated()
{
UpdateFromSettings();
}
}
public class HighwayNameRemoverModel : Model
{
public bool HideHighwayNames { get; set; } = true;
public bool HideStreetNames { get; set; } = true;
public bool HideAlleyNames { get; set; } = true;
public bool HideBridgeNames { get; set; } = true;
public bool HideDamNames { get; set; } = true;
}
[ControllerTypes(new Type[] { typeof(HighwayNameRemoverController) })]
[GooeeSettingsMenu(typeof(HighwayNameRemoverSettings))]
public class HighwayNameRemoverPlugin : IGooeePluginWithControllers, IGooeePlugin, IGooeeSettings, IGooeeLanguages
{
public string Name => "HighwayNameRemover";
public string ScriptResource => "HighwayNameRemover.Resources.ui.js";
public string LanguageResourceFolder => "HighwayNameRemover.Resources.lang";
public GooeeSettings Settings { get; set; }
public IController[] Controllers { get; set; }
}
public class HighwayNameRemoverSettings : GooeeSettings
{
[SettingsUISection("Toggles")]
public bool HideHighwayNames { get; set; } = true;
[SettingsUISection("Toggles")]
public bool HideStreetNames { get; set; } = true;
[SettingsUISection("Toggles")]
public bool HideAlleyNames { get; set; } = true;
[SettingsUISection("Toggles")]
public bool HideBridgeNames { get; set; } = true;
[SettingsUISection("Toggles")]
public bool HideDamNames { get; set; } = true;
protected override string UIResource => "HighwayNameRemover.Resources.settings.xml";
public override void SetDefaults()
{
HideHighwayNames = true;
HideStreetNames = false;
HideAlleyNames = false;
HideBridgeNames = false;
HideDamNames = false;
}
}
[BepInPlugin("HighwayNameRemover", "HighwayNameRemover", "2.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"[HighwayNameRemover]: Loading Harmony patches.");
MethodBase[] array = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "HighwayNameRemover_Cities2Harmony").GetPatchedMethods().ToArray();
Logger.LogInfo((object)("Plugin HighwayNameRemover made patches! Patched methods: " + array.Length));
MethodBase[] array2 = array;
foreach (MethodBase methodBase in array2)
{
Logger.LogInfo((object)("[HighwayNameRemover]: Patched method: " + methodBase.Module.Name + ":" + methodBase.Name));
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "HighwayNameRemover";
public const string PLUGIN_NAME = "HighwayNameRemover";
public const string PLUGIN_VERSION = "2.0.0";
}
}
namespace HighwayNameRemover.Patches
{
[HarmonyPatch(typeof(LocalizationManager), "AddLocale", new Type[] { typeof(LocaleAsset) })]
internal class LocalizationManager_AddLocale
{
private static void Prefix(LocaleAsset asset)
{
HighwayNameRemover.Localization.Localization.AddCustomLocal(asset);
}
}
}
namespace HighwayNameRemover.Localization
{
public class Localization
{
internal static void AddCustomLocal(LocaleAsset localeAsset)
{
List<string> list = new List<string>();
HighwayNameRemoverConfig config = HighwayNameRemoverController._config;
if (config.HideStreetNames)
{
list.Add("Assets.STREET_NAME:");
}
if (config.HideHighwayNames)
{
list.Add("Assets.HIGHWAY_NAME:");
}
if (config.HideAlleyNames)
{
list.Add("Assets.ALLEY_NAME:");
}
if (config.HideBridgeNames)
{
list.Add("Assets.BRIDGE_NAME:");
}
if (config.HideDamNames)
{
list.Add("Assets.DAM_NAME:");
}
List<string> list2 = new List<string>();
foreach (string key in localeAsset.data.entries.Keys)
{
if (Array.Exists(list.ToArray(), (string element) => key.Contains(element)))
{
list2.Add(key);
}
}
foreach (string item in list2)
{
localeAsset.data.entries[item] = " ";
}
}
}
}
namespace HighwayNameRemover.Configuration
{
public abstract class ConfigBase
{
public static readonly string MOD_PATH = Path.Combine(Application.persistentDataPath, "Mods", "HighwayNameRemover");
private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{
NullValueHandling = (NullValueHandling)1,
Formatting = (Formatting)1
};
public static Action OnUpdated;
protected abstract string ConfigFileName { get; }
public virtual void Save()
{
string contents = JsonConvert.SerializeObject((object)this, _serializerSettings);
Directory.CreateDirectory(MOD_PATH);
File.WriteAllText(Path.Combine(MOD_PATH, ConfigFileName), contents);
OnUpdated?.Invoke();
}
public static T Load<T>(bool useDefaultAsTemplate = true) where T : ConfigBase, new()
{
T val = new T();
Directory.CreateDirectory(MOD_PATH);
string path = Path.Combine(MOD_PATH, val.ConfigFileName);
string text = "";
if (File.Exists(path))
{
text = File.ReadAllText(path);
}
else
{
if (!useDefaultAsTemplate)
{
return new T();
}
text = LoadDefaultAndSave<T>();
}
return (T)JsonConvert.DeserializeObject(text, typeof(T), _serializerSettings);
}
public static T LoadDefault<T>() where T : ConfigBase, new()
{
return new T();
}
private static string LoadDefaultAndSave<T>() where T : ConfigBase, new()
{
T val = new T();
Directory.CreateDirectory(MOD_PATH);
string path = Path.Combine(MOD_PATH, val.ConfigFileName);
string text = JsonConvert.SerializeObject((object)val, _serializerSettings);
File.WriteAllText(path, text);
return text;
}
private static string UppercaseFirst(string s)
{
if (string.IsNullOrEmpty(s))
{
return string.Empty;
}
return char.ToUpper(s[0]) + s.Substring(1);
}
}
public class HighwayNameRemoverConfig : ConfigBase
{
protected override string ConfigFileName => "config.json";
public bool HideHighwayNames { get; set; }
public bool HideStreetNames { get; set; }
public bool HideAlleyNames { get; set; } = true;
public bool HideBridgeNames { get; set; } = true;
public bool HideDamNames { get; set; } = true;
}
}