using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SettingsMenu.Components;
using SettingsMenu.Models;
using TMPro;
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("BetterSpeedometer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterSpeedometer")]
[assembly: AssemblyTitle("BetterSpeedometer")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
}
}
[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 BetterSpeedometer
{
[BepInPlugin("com.10-days-till-xmas.betterspeedometer", "BetterSpeedometer", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin com.10-days-till-xmas.betterspeedometer is loaded!");
((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
new Harmony("com.10-days-till-xmas.betterspeedometer").PatchAll();
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.10-days-till-xmas.betterspeedometer";
public const string PLUGIN_NAME = "BetterSpeedometer";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace BetterSpeedometer.Patchers
{
[HarmonyPatch(typeof(SettingsItemBuilder))]
public static class SettingsItemBuilderPatcher
{
public const int SPEEDOMETER_ITEM_INDEX = 4;
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void AwakePostfix(SettingsItemBuilder __instance)
{
if (((Object)__instance).name == "Speedometer")
{
Plugin.Logger.LogDebug((object)"Patching Speedometer settings item");
__instance.asset.dropdownList = CollectionExtensions.AddToArray<string>(__instance.asset.dropdownList, "All");
}
}
[HarmonyPrefix]
[HarmonyPatch("ConfigureFrom")]
public static void ConfigureFromPrefix(SettingsItemBuilder __instance, SettingsItem item)
{
if (((Object)item).name == "Speedometer")
{
Plugin.Logger.LogDebug((object)"Patching Speedometer settings item!!");
item.dropdownList = CollectionExtensions.AddToArray<string>(item.dropdownList, "FULL SPEEDOMETER");
item.dropdownList[1] = "SPEED ONLY";
}
}
}
[HarmonyPatch(typeof(Speedometer))]
public static class SpeedometerPatcher
{
private static readonly FieldInfo f_Speedometer_type = AccessTools.Field(typeof(Speedometer), "type");
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void AwakePostfix(Speedometer __instance, bool ___classicVersion, int ___type)
{
ResizeSpeedometer(__instance, ___classicVersion, ___type);
}
[HarmonyPostfix]
[HarmonyPatch("OnEnable")]
public static void OnEnablePostfix(Speedometer __instance, bool ___classicVersion, int ___type)
{
ResizeSpeedometer(__instance, ___classicVersion, ___type);
}
[HarmonyPostfix]
[HarmonyPatch("OnPrefChanged")]
public static void OnPrefChangedPostfix(Speedometer __instance, string id, object value, int ___type, bool ___classicVersion)
{
if (!(id != "speedometer") && value is int)
{
ResizeSpeedometer(__instance, ___classicVersion, ___type);
}
}
[HarmonyTranspiler]
[HarmonyPatch("FixedUpdate")]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Expected O, but got Unknown
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.Start().MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"{0:0}", (string)null)
}).ThrowIfInvalid("Could not find the first format string in Speedometer.FixedUpdate")
.RemoveInstruction()
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4]
{
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)f_Speedometer_type),
CodeInstruction.Call((Expression<Action>)(() => GetStringClassic(0f, 0)))
})
.RemoveInstructions(3)
.MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"SPEED: {0:0.00} {1}/s", (string)null)
})
.ThrowIfInvalid("Could not find the second format string in Speedometer.FixedUpdate")
.RemoveInstruction()
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
{
new CodeInstruction(OpCodes.Ldloc_0, (object)null),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)f_Speedometer_type),
new CodeInstruction(OpCodes.Ldloc_1, (object)null),
CodeInstruction.Call((Expression<Action>)(() => GetStringStandard(0f, 0, "")))
})
.RemoveInstructions(4);
return val.InstructionEnumeration();
}
private static string GetStringClassic(float num, int type)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_0022: 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)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (type != 4)
{
return $"{num:0}";
}
Vector3 playerVelocity = MonoSingleton<PlayerTracker>.Instance.GetPlayerVelocity(true);
Vector3 val = Vector3.ProjectOnPlane(playerVelocity, Vector3.up);
float magnitude = ((Vector3)(ref val)).magnitude;
float y = playerVelocity.y;
float magnitude2 = ((Vector3)(ref playerVelocity)).magnitude;
return $"({magnitude:0}, {y:0})\n{magnitude2:0}";
}
private static string GetStringStandard(float num, int type, string unit)
{
//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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_0037: Unknown result type (might be due to invalid IL or missing references)
if (type != 4)
{
return $"SPEED: {num:0.00} {unit}/s";
}
Vector3 playerVelocity = MonoSingleton<PlayerTracker>.Instance.GetPlayerVelocity(true);
Vector3 val = Vector3.ProjectOnPlane(playerVelocity, Vector3.up);
float magnitude = ((Vector3)(ref val)).magnitude;
float y = playerVelocity.y;
float magnitude2 = ((Vector3)(ref playerVelocity)).magnitude;
return $"SPEED: ({magnitude:0.00}, {y:0.00})\n{magnitude2:0.00} u/s";
}
private static void ResizeSpeedometer(Speedometer sm, bool classicVersion, int type)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: 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)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: 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_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
Plugin.Logger.LogInfo((object)"Resizing speedometer");
RectTransform component = ((Component)sm).gameObject.GetComponent<RectTransform>();
TextMeshProUGUI textMesh = sm.textMesh;
((TMP_Text)textMesh).enableWordWrapping = type != 4;
if (classicVersion)
{
if (type == 4)
{
Vector2 sizeDelta = component.sizeDelta;
sizeDelta.x = 100f;
component.sizeDelta = sizeDelta;
((TMP_Text)textMesh).fontSize = 18f;
((TMP_Text)textMesh).fontSizeMax = 18f;
((TMP_Text)textMesh).fontSizeMin = 10f;
sizeDelta = component.pivot;
sizeDelta.x = 0.615f;
component.pivot = sizeDelta;
}
else
{
Vector2 sizeDelta = component.sizeDelta;
sizeDelta.x = 77.5f;
component.sizeDelta = sizeDelta;
((TMP_Text)textMesh).fontSize = 22f;
((TMP_Text)textMesh).fontSizeMax = 36f;
((TMP_Text)textMesh).fontSizeMin = 18f;
sizeDelta = component.pivot;
sizeDelta.x = 0.5f;
component.pivot = sizeDelta;
}
}
else if (type == 4)
{
Vector2 sizeDelta = component.sizeDelta;
sizeDelta.y = 40f;
component.sizeDelta = sizeDelta;
((TMP_Text)textMesh).fontSize = 14f;
((TMP_Text)textMesh).fontSizeMax = 20f;
((TMP_Text)textMesh).fontSizeMin = 10f;
}
else
{
Vector2 sizeDelta = component.sizeDelta;
sizeDelta.y = 25f;
component.sizeDelta = sizeDelta;
((TMP_Text)textMesh).fontSizeMin = 16f;
((TMP_Text)textMesh).fontSizeMax = 72f;
((TMP_Text)textMesh).fontSize = 18f;
}
}
}
}