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 BepInEx;
using Colossal;
using Colossal.IO.AssetDatabase;
using Colossal.Localization;
using Colossal.Logging;
using Colossal.Serialization.Entities;
using Game;
using Game.Common;
using Game.Input;
using Game.Modding;
using Game.SceneFlow;
using Game.Settings;
using Game.Simulation;
using Game.UI.Localization;
using Game.UI.Widgets;
using HarmonyLib;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("algernon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2023 algernon (github.com/algernon-A). All rights reserved.")]
[assembly: AssemblyDescription("A Cities: Skylines 2 mod.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+9984f32cd3ba841c75fc16b77d56b6996a0a0a2e")]
[assembly: AssemblyProduct("Image Overlay Lite")]
[assembly: AssemblyTitle("Image Overlay Lite")]
[assembly: AssemblyVersion("1.1.1.0")]
namespace ImageOverlay;
[BepInPlugin("com.github.algernon-A.CS2.ImageOverlayLite", "Image Overlay Lite", "1.1.1")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "com.github.algernon-A.CS2.ImageOverlayLite";
private Mod _mod;
public void Awake()
{
_mod = new Mod();
_mod.OnLoad();
_mod.Log.Info((object)"Plugin.Awake");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.github.algernon-A.CS2.ImageOverlayLite");
}
[HarmonyPatch(typeof(SystemOrder), "Initialize")]
[HarmonyPostfix]
private static void InjectSystems(UpdateSystem updateSystem)
{
Mod.Instance.OnCreateWorld(updateSystem);
}
}
internal sealed class ImageOverlaySystem : GameSystemBase
{
private ILog _log;
private GameObject _overlayObject;
private Material _overlayMaterial;
private Texture2D _overlayTexture;
private Shader _overlayShader;
private bool _isVisible = false;
internal static ImageOverlaySystem Instance { get; private set; }
internal void UpdateOverlay()
{
if (Object.op_Implicit((Object)(object)_overlayObject))
{
UpdateOverlayTexture();
}
}
internal void SetAlpha(float alpha)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
_overlayObject.GetComponent<Renderer>().material.color = new Color(1f, 1f, 1f, 1f - alpha);
}
}
internal void SetSize(float size)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
float num = size / 10f;
_overlayObject.transform.localScale = new Vector3(num, 1f, num);
}
}
internal void SetPositionX(float posX)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
Vector3 position = _overlayObject.transform.position;
position.x = posX;
_overlayObject.transform.position = position;
}
}
internal void SetPositionZ(float posZ)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
Vector3 position = _overlayObject.transform.position;
position.z = posZ;
_overlayObject.transform.position = position;
}
}
protected override void OnCreate()
{
((GameSystemBase)this).OnCreate();
Instance = this;
_log = Mod.Instance.Log;
_log.Info((object)"OnCreate");
if (LoadShader())
{
InputBindingsManager.Ensure();
List<string> modifiers = new List<string> { "<Keyboard>/shift" };
List<string> modifiers2 = new List<string> { "<Keyboard>/ctrl" };
InputBindingsManager.Instance.AddAction("ImageOverlayToggle", "<Keyboard>/o", modifiers2, ToggleOverlay);
InputBindingsManager.Instance.AddAction("ImageOverlayUp", "<Keyboard>/pageup", modifiers2, delegate
{
ChangeHeight(5f);
});
InputBindingsManager.Instance.AddAction("ImageOverlayDown", "<Keyboard>/pagedown", modifiers2, delegate
{
ChangeHeight(-5f);
});
InputBindingsManager.Instance.AddAction("ImageOverlayNorth", "<Keyboard>/uparrow", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlayPosZ += 1f;
});
InputBindingsManager.Instance.AddAction("ImageOverlaySouth", "<Keyboard>/downarrow", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlayPosZ -= 1f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayEast", "<Keyboard>/rightarrow", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlayPosX += 1f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayWest", "<Keyboard>/leftarrow", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlayPosX -= 1f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayNorthLarge", "<Keyboard>/uparrow", modifiers, delegate
{
Mod.Instance.ActiveSettings.OverlayPosZ += 10f;
});
InputBindingsManager.Instance.AddAction("ImageOverlaySouthLarge", "<Keyboard>/downarrow", modifiers, delegate
{
Mod.Instance.ActiveSettings.OverlayPosZ -= 10f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayEastLarge", "<Keyboard>/rightarrow", modifiers, delegate
{
Mod.Instance.ActiveSettings.OverlayPosX += 10f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayWestLarge", "<Keyboard>/leftarrow", modifiers, delegate
{
Mod.Instance.ActiveSettings.OverlayPosX -= 10f;
});
InputBindingsManager.Instance.AddAction("ImageOverlayRotateRight", "<Keyboard>/period", modifiers2, delegate
{
Rotate(90f);
});
InputBindingsManager.Instance.AddAction("ImageOverlayRotateLeft", "<Keyboard>/comma", modifiers2, delegate
{
Rotate(-90f);
});
InputBindingsManager.Instance.AddAction("ImageOverlaySizeUp", "<Keyboard>/equals", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlaySize += 10f;
});
InputBindingsManager.Instance.AddAction("ImageOverlaySizeDown", "<Keyboard>/minus", modifiers2, delegate
{
Mod.Instance.ActiveSettings.OverlaySize -= 10f;
});
}
}
protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
((GameSystemBase)this).OnGameLoadingComplete(purpose, mode);
if ((mode & 6) > 0)
{
InputBindingsManager.Instance.EnableActions();
}
else
{
InputBindingsManager.Instance.DisableActions();
}
}
protected override void OnUpdate()
{
}
protected override void OnDestroy()
{
((GameSystemBase)this).OnDestroy();
DestroyObjects();
}
private void ToggleOverlay()
{
if (_isVisible)
{
_isVisible = false;
if (Object.op_Implicit((Object)(object)_overlayObject))
{
_overlayObject.SetActive(false);
}
return;
}
if (!Object.op_Implicit((Object)(object)_overlayObject) || !Object.op_Implicit((Object)(object)_overlayMaterial) || !Object.op_Implicit((Object)(object)_overlayTexture))
{
CreateOverlay();
}
if (Object.op_Implicit((Object)(object)_overlayObject))
{
_overlayObject.SetActive(true);
_isVisible = true;
}
}
private void ChangeHeight(float adjustment)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
Transform transform = _overlayObject.transform;
transform.position += new Vector3(0f, adjustment, 0f);
}
}
private void Rotate(float rotation)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_overlayObject))
{
_overlayObject.transform.Rotate(new Vector3(0f, rotation, 0f), (Space)1);
}
}
private void UpdateOverlayTexture()
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Expected O, but got Unknown
string selectedOverlay = Mod.Instance.ActiveSettings.SelectedOverlay;
if (string.IsNullOrEmpty(selectedOverlay))
{
_log.Info((object)"no overlay file set");
return;
}
if (!File.Exists(selectedOverlay))
{
_log.Info((object)("invalid overlay file " + selectedOverlay));
return;
}
_log.Info((object)("loading image file " + selectedOverlay));
if (_overlayTexture == null)
{
_overlayTexture = new Texture2D(1, 1, (TextureFormat)5, false);
}
ImageConversion.LoadImage(_overlayTexture, File.ReadAllBytes(selectedOverlay));
_overlayTexture.Apply();
if (_overlayMaterial == null)
{
_overlayMaterial = new Material(_overlayShader)
{
mainTexture = (Texture)(object)_overlayTexture
};
}
}
private void CreateOverlay()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
_log.Info((object)"creating overlay");
DestroyObjects();
try
{
UpdateOverlayTexture();
_overlayObject = GameObject.CreatePrimitive((PrimitiveType)4);
SetSize(Mod.Instance.ActiveSettings.OverlaySize);
Rotate(180f);
TerrainHeightData heightData = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<TerrainSystem>().GetHeightData(false);
JobHandle val = default(JobHandle);
WaterSurfaceData surfaceData = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<WaterSystem>().GetSurfaceData(ref val);
_overlayObject.transform.position = new Vector3(Mod.Instance.ActiveSettings.OverlayPosX, WaterUtils.SampleHeight(ref surfaceData, ref heightData, float3.zero) + 5f, Mod.Instance.ActiveSettings.OverlayPosZ);
_overlayObject.GetComponent<Renderer>().material = _overlayMaterial;
SetAlpha(Mod.Instance.ActiveSettings.Alpha);
}
catch (Exception ex)
{
_log.Error(ex, (object)"exception loading image overlay file");
}
}
private bool LoadShader()
{
try
{
_log.Info((object)"loading overlay shader");
using StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("ImageOverlayLite.Shader.shaderbundle"));
AssetBundle obj = AssetBundle.LoadFromStream(streamReader.BaseStream);
_overlayShader = ((obj != null) ? obj.LoadAsset<Shader>("UnlitTransparentAdditive.shader") : null);
if (_overlayShader != null)
{
return true;
}
_log.Critical((object)"Image Overlay: unable to load overlay shader from asset bundle; aborting operation.");
}
catch (Exception ex)
{
_log.Critical(ex, (object)"Image Overlay: exception loading overlay shader; aborting operation.");
}
return false;
}
private void DestroyObjects()
{
if (Object.op_Implicit((Object)(object)_overlayTexture))
{
_log.Info((object)"destroying existing overlay texture");
Object.DestroyImmediate((Object)(object)_overlayTexture);
_overlayTexture = null;
}
if (Object.op_Implicit((Object)(object)_overlayMaterial))
{
_log.Info((object)"destroying existing overlay material");
Object.DestroyImmediate((Object)(object)_overlayMaterial);
_overlayMaterial = null;
}
if (Object.op_Implicit((Object)(object)_overlayObject))
{
_log.Info((object)"destroying existing overlay object");
Object.DestroyImmediate((Object)(object)_overlayObject);
_overlayObject = null;
}
}
}
[DisplayStringFormat("{modifier1}+{modifier2}+{modifier3}+{button}")]
public class ButtonWithThreeModifiers : InputBindingComposite<float>
{
[InputControl(layout = "Button")]
public int modifier1;
[InputControl(layout = "Button")]
public int modifier2;
[InputControl(layout = "Button")]
public int modifier3;
[InputControl(layout = "Button")]
public int button;
private bool _timelessModifiers;
public override float ReadValue(ref InputBindingCompositeContext context)
{
if (AreModifiersPressed(ref context))
{
return ((InputBindingCompositeContext)(ref context)).ReadValue<float>(button);
}
return 0f;
}
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
{
return ((InputBindingComposite<float>)this).ReadValue(ref context);
}
protected override void FinishSetup(ref InputBindingCompositeContext context)
{
if (!_timelessModifiers)
{
_timelessModifiers = !InputSystem.settings.shortcutKeysConsumeInput;
}
}
private bool AreModifiersPressed(ref InputBindingCompositeContext context)
{
bool flag = ((InputBindingCompositeContext)(ref context)).ReadValueAsButton(modifier1) && ((InputBindingCompositeContext)(ref context)).ReadValueAsButton(modifier2) && ((InputBindingCompositeContext)(ref context)).ReadValueAsButton(modifier3);
if (flag && !_timelessModifiers)
{
double pressTime = ((InputBindingCompositeContext)(ref context)).GetPressTime(button);
if (((InputBindingCompositeContext)(ref context)).GetPressTime(modifier1) <= pressTime && ((InputBindingCompositeContext)(ref context)).GetPressTime(modifier2) <= pressTime)
{
return ((InputBindingCompositeContext)(ref context)).GetPressTime(modifier3) <= pressTime;
}
return false;
}
return flag;
}
}
[HarmonyPatch]
internal class InputBindingsManager
{
internal delegate void Callback();
private const string MapName = "Shortcuts";
private readonly ILog _log;
private readonly Dictionary<string, InputAction> _actions;
private readonly Dictionary<string, ProxyBinding> _bindings;
internal static InputBindingsManager Instance { get; private set; }
private InputBindingsManager()
{
_log = Mod.Instance.Log;
_actions = new Dictionary<string, InputAction>();
_bindings = new Dictionary<string, ProxyBinding>();
InputSystem.RegisterBindingComposite<ButtonWithThreeModifiers>((string)null);
}
internal static void Ensure()
{
if (Instance == null)
{
Instance = new InputBindingsManager();
}
}
[HarmonyPatch(typeof(InputManager), "SetBindingImpl")]
[HarmonyPrefix]
internal static bool SetBindingImplPrefix(ProxyBinding newBinding, ref ProxyBinding result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//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_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
if (newBinding.m_MapName.Equals("Shortcuts") && Instance != null && Instance._bindings.ContainsKey(newBinding.m_ActionName) && Instance._actions.TryGetValue(newBinding.m_ActionName, out var value))
{
Instance._log.Info((object)("updating binding for action " + newBinding.m_ActionName));
BindingSyntax val = InputActionSetupExtensions.ChangeBinding(value, 0);
((BindingSyntax)(ref val)).Erase();
CompositeSyntax val2;
switch (newBinding.m_Modifiers.Count)
{
default:
InputActionSetupExtensions.AddBinding(value, ((ProxyBinding)(ref newBinding)).path, (string)null, (string)null, (string)null);
break;
case 1:
val2 = InputActionSetupExtensions.AddCompositeBinding(value, "ButtonWithOneModifier", (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier", newBinding.m_Modifiers[0].m_Path, (string)null, (string)null);
((CompositeSyntax)(ref val2)).With("button", ((ProxyBinding)(ref newBinding)).path, (string)null, (string)null);
break;
case 2:
val2 = InputActionSetupExtensions.AddCompositeBinding(value, "ButtonWithTwoModifiers", (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier1", newBinding.m_Modifiers[0].m_Path, (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier2", newBinding.m_Modifiers[1].m_Path, (string)null, (string)null);
((CompositeSyntax)(ref val2)).With("button", ((ProxyBinding)(ref newBinding)).path, (string)null, (string)null);
break;
case 3:
val2 = InputActionSetupExtensions.AddCompositeBinding(value, "ButtonWithThreeModifiers", (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier1", newBinding.m_Modifiers[0].m_Path, (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier2", newBinding.m_Modifiers[1].m_Path, (string)null, (string)null);
val2 = ((CompositeSyntax)(ref val2)).With("modifier3", newBinding.m_Modifiers[2].m_Path, (string)null, (string)null);
((CompositeSyntax)(ref val2)).With("button", ((ProxyBinding)(ref newBinding)).path, (string)null, (string)null);
break;
}
Instance._bindings[newBinding.m_ActionName] = newBinding;
result = newBinding;
return false;
}
return true;
}
internal void AddAction(string actionName, string path, List<string> modifiers, Callback callback)
{
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(actionName))
{
_log.Error((object)"attempt to add null or empty action name");
return;
}
if (_actions.ContainsKey(actionName))
{
_log.Error((object)("attempt to add duplicate action key for " + actionName));
return;
}
_log.Info((object)("adding action key for " + actionName));
InputActionMap val = InputManager.instance.inputActions.FindActionMap("Shortcuts", false);
InputAction val2 = InputActionSetupExtensions.AddAction(val, actionName, (InputActionType)1, (string)null, (string)null, (string)null, (string)null, "Button");
if (callback != null)
{
val2.performed += delegate
{
callback();
};
}
CompositeSyntax val3;
switch (modifiers?.Count ?? 0)
{
default:
InputActionSetupExtensions.AddBinding(val2, path, (string)null, (string)null, (string)null);
break;
case 1:
val3 = InputActionSetupExtensions.AddCompositeBinding(val2, "ButtonWithOneModifier", (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier", modifiers[0], (string)null, (string)null);
((CompositeSyntax)(ref val3)).With("button", path, (string)null, (string)null);
break;
case 2:
val3 = InputActionSetupExtensions.AddCompositeBinding(val2, "ButtonWithTwoModifiers", (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier1", modifiers[0], (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier2", modifiers[1], (string)null, (string)null);
((CompositeSyntax)(ref val3)).With("button", path, (string)null, (string)null);
break;
case 3:
val3 = InputActionSetupExtensions.AddCompositeBinding(val2, "ButtonWithThreeModifiers", (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier1", modifiers[0], (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier2", modifiers[1], (string)null, (string)null);
val3 = ((CompositeSyntax)(ref val3)).With("modifier3", modifiers[2], (string)null, (string)null);
((CompositeSyntax)(ref val3)).With("button", path, (string)null, (string)null);
break;
}
_actions.Add(actionName, val2);
ProxyActionMap val4 = InputManager.instance.FindActionMap("Shortcuts");
List<ProxyModifier> list = new List<ProxyModifier>(modifiers.Count);
foreach (string modifier in modifiers)
{
list.Add(new ProxyModifier
{
m_Path = modifier
});
}
Dictionary<string, ProxyBinding> bindings = _bindings;
ProxyBinding value = new ProxyBinding
{
m_MapName = "Shortcuts",
m_ActionName = actionName,
m_CompositeName = "Keyboard",
m_Name = "binding",
m_IsRebindable = true,
m_AllowModifiers = true,
m_CanBeEmpty = true,
m_Usage = (BindingUsage)94,
m_Modifiers = list
};
((ProxyBinding)(ref value)).group = "Keyboard";
((ProxyBinding)(ref value)).path = path;
bindings.Add(actionName, value);
}
internal void EnableActions()
{
foreach (InputAction value in _actions.Values)
{
value.Enable();
}
}
internal void DisableActions()
{
foreach (InputAction value in _actions.Values)
{
value.Disable();
}
}
}
public static class Localization
{
public static void LoadTranslations(ModSetting settings, ILog log)
{
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Expected O, but got Unknown
try
{
using StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("ImageOverlayLite.l10n.csv"));
List<string> list = new List<string>();
while (!streamReader.EndOfStream)
{
list.Add(streamReader.ReadLine());
}
log.Debug((object)"parsing translation file");
IEnumerable<string[]> source = list.Select((string x) => x.Split(new char[1] { '\t' }));
string[] supportedLocales = GameManager.instance.localizationManager.GetSupportedLocales();
foreach (string text in supportedLocales)
{
try
{
int valueColumn = Array.IndexOf(source.First(), text);
if (valueColumn > 1)
{
log.Debug((object)("found translation for " + text));
MemorySource val = new MemorySource(source.Skip(1).ToDictionary((string[] x) => GenerateOptionsKey(x[0], x[1], settings), (string[] x) => x.ElementAtOrDefault(valueColumn)));
GameManager.instance.localizationManager.AddSource(text, (IDictionarySource)(object)val);
}
}
catch (Exception ex)
{
log.Error(ex, (object)("exception reading localization for locale " + text));
}
}
}
catch (Exception ex2)
{
log.Error(ex2, (object)"exception reading settings localization file");
}
}
private static string GenerateOptionsKey(string context, string key, ModSetting settings)
{
if (1 == 0)
{
}
string result = context switch
{
"Options.OPTION" => settings.GetOptionLabelLocaleID(key),
"Options.OPTION_DESCRIPTION" => settings.GetOptionDescLocaleID(key),
"Options.WARNING" => settings.GetOptionWarningLocaleID(key),
_ => settings.GetSettingsLocaleID(),
};
if (1 == 0)
{
}
return result;
}
}
public sealed class Mod : IMod
{
public const string ModName = "Image Overlay";
public static Mod Instance { get; private set; }
internal ILog Log { get; private set; }
internal ModSettings ActiveSettings { get; private set; }
public void OnLoad()
{
Instance = this;
Log = LogManager.GetLogger("Image Overlay", true);
Log.Info((object)"setting logging level to Debug");
Log.effectivenessLevel = Level.Debug;
Log.Info((object)string.Format("loading {0} version {1}", "Image Overlay", Assembly.GetExecutingAssembly().GetName().Version));
}
public void OnCreateWorld(UpdateSystem updateSystem)
{
Log.Info((object)"starting OnCreateWorld");
updateSystem.UpdateAt<ImageOverlaySystem>((SystemUpdatePhase)17);
ActiveSettings = new ModSettings((IMod)(object)this);
((ModSetting)ActiveSettings).RegisterInOptionsUI();
AssetDatabase.global.LoadSettings("ImageOverlaySettings", (object)ActiveSettings, (object)new ModSettings((IMod)(object)this));
Localization.LoadTranslations((ModSetting)(object)ActiveSettings, Log);
}
public void OnDispose()
{
Log.Info((object)"disposing");
}
}
[FileLocation("Image Overlay")]
public class ModSettings : ModSetting
{
private const string NoOverlayText = "None";
private const float VanillaMapSize = 14336f;
private readonly ILog _log;
private readonly string _directoryPath;
private string[] _fileList;
private string _selectedOverlay = string.Empty;
private int _fileListVersion = 0;
private float _overlaySize = 14336f;
private float _overlayPosX = 0f;
private float _overlayPosZ = 0f;
private float _alpha = 0f;
[SettingsUIDropdown(typeof(ModSettings), "GenerateFileSelectionItems")]
[SettingsUIValueVersion(typeof(ModSettings), "GetListVersion")]
[SettingsUISection("FileSelection")]
public string SelectedOverlay
{
get
{
if (_fileList == null || _fileList.Length == 0)
{
return string.Empty;
}
if (string.IsNullOrEmpty(_selectedOverlay) || !_fileList.Contains(_selectedOverlay))
{
_selectedOverlay = _fileList[0];
}
return _selectedOverlay;
}
set
{
if (_selectedOverlay != value)
{
_selectedOverlay = value;
ImageOverlaySystem.Instance?.UpdateOverlay();
}
}
}
[SettingsUIButton]
[SettingsUISection("FileSelection")]
public bool RefreshFileList
{
set
{
UpdateFileList();
}
}
[SettingsUISlider(min = 3584f, max = 57344f, step = 1f, scalarMultiplier = 1f)]
[SettingsUISection("OverlaySize")]
public float OverlaySize
{
get
{
return _overlaySize;
}
set
{
if (_overlaySize != value)
{
_overlaySize = value;
ImageOverlaySystem.Instance?.SetSize(value);
}
}
}
[SettingsUIButton]
[SettingsUISection("OverlaySize")]
public bool ResetToVanilla
{
set
{
OverlaySize = 14336f;
}
}
[SettingsUISlider(min = -7168f, max = 7168f, step = 1f, scalarMultiplier = 1f)]
[SettingsUISection("OverlayPosition")]
public float OverlayPosX
{
get
{
return _overlayPosX;
}
set
{
if (_overlayPosX != value)
{
_overlayPosX = value;
ImageOverlaySystem.Instance?.SetPositionX(value);
}
}
}
[SettingsUISlider(min = -7168f, max = 7168f, step = 1f, scalarMultiplier = 1f)]
[SettingsUISection("OverlayPosition")]
public float OverlayPosZ
{
get
{
return _overlayPosZ;
}
set
{
if (_overlayPosZ != value)
{
_overlayPosZ = value;
ImageOverlaySystem.Instance?.SetPositionZ(value);
}
}
}
[SettingsUIButton]
[SettingsUISection("OverlayPosition")]
public bool ResetPosition
{
set
{
OverlayPosX = 0f;
OverlayPosZ = 0f;
}
}
[SettingsUISlider(min = 0f, max = 95f, step = 5f, scalarMultiplier = 100f, unit = "percentage")]
[SettingsUISection("Alpha")]
public float Alpha
{
get
{
return _alpha;
}
set
{
if (_alpha != value)
{
_alpha = value;
ImageOverlaySystem.Instance?.SetAlpha(value);
}
}
}
public ModSettings(IMod mod)
: base(mod)
{
_log = Mod.Instance.Log;
_directoryPath = Path.Combine(Application.persistentDataPath, "Overlays");
UpdateFileList();
}
public DropdownItem<string>[] GenerateFileSelectionItems()
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
if (_fileList == null || _fileList.Length == 0)
{
return new DropdownItem<string>[1]
{
new DropdownItem<string>
{
value = string.Empty,
displayName = LocalizedString.op_Implicit("None")
}
};
}
DropdownItem<string>[] array = new DropdownItem<string>[_fileList.Length];
for (int i = 0; i < _fileList.Length; i++)
{
array[i] = new DropdownItem<string>
{
value = _fileList[i],
displayName = LocalizedString.op_Implicit(Path.GetFileNameWithoutExtension(_fileList[i]))
};
}
return array;
}
public int GetListVersion()
{
return _fileListVersion;
}
public override void SetDefaults()
{
_selectedOverlay = string.Empty;
OverlaySize = 14336f;
Alpha = 0f;
}
private void UpdateFileList()
{
if (!Directory.Exists(_directoryPath))
{
Directory.CreateDirectory(_directoryPath);
}
_log.Info((object)("refreshing overlay file list using directory " + _directoryPath));
_fileList = Directory.GetFiles(_directoryPath, "*.png", SearchOption.TopDirectoryOnly);
_log.Debug((object)_fileList.Length);
_fileListVersion++;
}
}