using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("Speedometer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a speedometer to the HUD while driving")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+83e729fd83e12cd3c1b3f91b16d0c9b0b4a5256d")]
[assembly: AssemblyProduct("Speedometer")]
[assembly: AssemblyTitle("Speedometer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 Speedometer
{
[BepInPlugin("Speedometer", "Speedometer", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal class SpeedoGauge
{
private Texture2D atlas;
private Texture2D needleOverlay;
private Texture2D clearTexture;
private Vector2Int dimensions;
private Vector2Int center;
private Vector2Int needleStart;
private Vector2Int needleEnd;
private float needleWidth = 1.3f;
public Vector2Int Dimensions => dimensions;
private static void SetPixel(Texture2D t, int x, int y, Color c)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
t.SetPixel(x, ((Texture)t).height - y, c);
}
private static Color GetPixel(Texture2D t, int x, int y)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
return t.GetPixel(x, ((Texture)t).height - y);
}
public SpeedoGauge(string atlasImage)
{
//IL_0036: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: 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_0188: 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_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: 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_0120: Unknown result type (might be due to invalid IL or missing references)
atlas = LoadImage(atlasImage);
dimensions = new Vector2Int(((Texture)atlas).width, ((Texture)atlas).height);
clearTexture = new Texture2D(((Vector2Int)(ref dimensions)).x, ((Vector2Int)(ref dimensions)).y);
for (int i = 0; i < ((Vector2Int)(ref dimensions)).x; i++)
{
for (int j = 0; j < ((Vector2Int)(ref dimensions)).y; j++)
{
SetPixel(clearTexture, i, j, Color.clear);
Color pixel = GetPixel(atlas, i, j);
if (pixel == Color.blue)
{
center = new Vector2Int(i, j);
SetPixel(atlas, i, j, Color.white);
}
else if (pixel == Color.green)
{
needleStart = new Vector2Int(i, j);
SetPixel(atlas, i, j, Color.white);
}
else if (pixel == Color.red)
{
needleEnd = new Vector2Int(i, j);
SetPixel(atlas, i, j, Color.white);
}
}
}
atlas.Apply();
needleStart -= center;
needleEnd -= center;
needleOverlay = new Texture2D(((Vector2Int)(ref dimensions)).x, ((Vector2Int)(ref dimensions)).y);
}
public void Draw(MiniRenderer R, Vector2Int position, float speedFactor)
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: 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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: 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_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
R.spr((Texture)(object)atlas, 0f, 0f, (float)((Vector2Int)(ref position)).x, (float)((Vector2Int)(ref position)).y, (float)((Vector2Int)(ref dimensions)).x, (float)((Vector2Int)(ref dimensions)).y, false, (float)((Vector2Int)(ref dimensions)).x, (float)((Vector2Int)(ref dimensions)).y);
Vector2 val = ClockwiseLerp(Vector2Int.op_Implicit(needleStart), Vector2Int.op_Implicit(needleEnd), speedFactor);
Vector2 w = Vector2Int.op_Implicit(center) + val * 0.8f;
needleOverlay.CopyPixels((Texture)(object)clearTexture);
for (int i = 0; i < ((Vector2Int)(ref dimensions)).x; i++)
{
for (int j = 0; j < ((Vector2Int)(ref dimensions)).y; j++)
{
float num = minimum_distance(Vector2Int.op_Implicit(center) - val * 0.2f, w, new Vector2((float)i, (float)j));
if (num < needleWidth)
{
SetPixel(needleOverlay, i, j, Color.white);
}
}
}
needleOverlay.Apply();
R.spr((Texture)(object)needleOverlay, 0f, 0f, (float)((Vector2Int)(ref position)).x, (float)((Vector2Int)(ref position)).y, (float)((Vector2Int)(ref dimensions)).x, (float)((Vector2Int)(ref dimensions)).y, false, (float)((Vector2Int)(ref dimensions)).x, (float)((Vector2Int)(ref dimensions)).y);
}
private static float minimum_distance(Vector2 v, Vector2 w, Vector2 p)
{
//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_0003: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
Vector2 val = w - v;
float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
if ((double)sqrMagnitude == 0.0)
{
return Vector2.Distance(p, v);
}
float num = Mathf.Max(0f, Mathf.Min(1f, Vector2.Dot(p - v, w - v) / sqrMagnitude));
Vector2 val2 = v + num * (w - v);
return Vector2.Distance(p, val2);
}
private static Vector2 ClockwiseLerp(Vector2 start, Vector2 end, float t)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Atan2(start.y, start.x);
float num2 = Mathf.Atan2(end.y, end.x);
if (num > num2)
{
num -= MathF.PI * 2f;
}
float num3 = num + (num2 - num) * t;
return new Vector2(Mathf.Cos(num3), Mathf.Sin(num3)) * Mathf.Lerp(((Vector2)(ref start)).magnitude, ((Vector2)(ref end)).magnitude, t);
}
}
internal static ManualLogSource Logger;
private static SpeedoGauge gauge;
private static bool digital = false;
private static bool useWheelSpeed = true;
private static bool centered = false;
public static bool Centered
{
get
{
return centered;
}
set
{
if (value)
{
CenterSpeedo();
}
else
{
SideSpeedo();
}
centered = value;
}
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
SideSpeedo();
}
private static Texture2D LoadImage(string name)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
using Stream stream = executingAssembly.GetManifestResourceStream("Speedometer.Assets." + name);
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
((Texture)val).wrapMode = (TextureWrapMode)1;
((Texture)val).filterMode = (FilterMode)0;
return val;
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)44))
{
Centered = !centered;
}
if (Input.GetKeyDown((KeyCode)46))
{
digital = !digital;
}
}
private static void SideSpeedo()
{
gauge = new SpeedoGauge("speedo_side.png");
}
private static void CenterSpeedo()
{
gauge = new SpeedoGauge("speedo_center.png");
}
[HarmonyPatch(typeof(sHUD), "RadioDisplay")]
[HarmonyPostfix]
private static void ShowSpeed(sHUD __instance)
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: 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_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: 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)
object? value = AccessTools.Field(typeof(sHUD), "R").GetValue(__instance);
MiniRenderer val = (MiniRenderer)((value is MiniRenderer) ? value : null);
sCarController val2 = Object.FindFirstObjectByType<sCarController>();
if (val2.GuyActive)
{
return;
}
bool flag = useWheelSpeed;
if (1 == 0)
{
}
float num;
if (flag)
{
num = Math.Max(Math.Abs(Mathf.FloorToInt(val2.wheels[0].viewRotationVelocity * 1.092f)) - 1, 0);
}
else
{
Vector3 linearVelocity = val2.rb.linearVelocity;
num = Mathf.Floor(((Vector3)(ref linearVelocity)).magnitude * 3.6f);
}
if (1 == 0)
{
}
float num2 = num;
if (digital)
{
string text = num2 + " km/h";
bool flag2 = centered;
if (1 == 0)
{
}
Vector2Int val3 = (flag2 ? new Vector2Int(val.width / 2 - 32, val.height - 54) : new Vector2Int(val.width - 68 - 8 * text.Length, val.height - 86));
if (1 == 0)
{
}
Vector2Int val4 = val3;
val.put(text, (float)((Vector2Int)(ref val4)).x, (float)((Vector2Int)(ref val4)).y);
}
else
{
bool flag3 = centered;
if (1 == 0)
{
}
Vector2Int val3 = (flag3 ? (new Vector2Int(val.width / 2, val.height - 58) - gauge.Dimensions / 2) : (new Vector2Int(val.width - 68, val.height - 74) - gauge.Dimensions));
if (1 == 0)
{
}
Vector2Int position = val3;
gauge.Draw(val, position, num2 / 120f);
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Speedometer";
public const string PLUGIN_NAME = "Speedometer";
public const string PLUGIN_VERSION = "1.0.0";
}
}