using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CasperQOL;
using CasperQOL.Patches;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CasperQOL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CasperQOL")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("45f28435-2d1a-4991-a4b7-9c74eb723b5a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class ShowGUI
{
public static bool shouldShow;
private static GUIStyle guiStyleBox;
private static GUIStyle guiStyleButton;
private static GUIStyle guiStyleButtonSelected;
public static GUIStyle guiStyleLabel;
private static GUIStyle guiStyleBorder;
private static Texture2D lightestBackground;
private static Texture2D lightBackground;
private static Texture2D purpleBackground;
private static Texture2D orangeBorder;
static ShowGUI()
{
shouldShow = false;
InitializeStyles();
}
private static void InitializeStyles()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: 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_019b: 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_01ce: Expected O, but got Unknown
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_0350: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Expected O, but got Unknown
//IL_0369: Unknown result type (might be due to invalid IL or missing references)
lightestBackground = CreateColorTexture("#3A3A58");
lightBackground = CreateColorTexture("#303040");
purpleBackground = CreateColorTexture("#800080");
orangeBorder = CreateColorTexture("#FFA500");
guiStyleBorder = new GUIStyle(GUI.skin.box);
guiStyleBorder.normal.background = orangeBorder;
guiStyleBorder.border = new RectOffset(3, 3, 3, 3);
guiStyleBox = new GUIStyle(GUI.skin.box);
guiStyleBox.normal.background = lightestBackground;
guiStyleBox.normal.textColor = HexToColor("#FFA500");
guiStyleBox.fontSize = 16;
guiStyleBox.alignment = (TextAnchor)1;
guiStyleButton = new GUIStyle(GUI.skin.button);
guiStyleButton.normal.background = lightBackground;
guiStyleButton.normal.textColor = HexToColor("#FFA500");
guiStyleButton.hover.background = lightBackground;
guiStyleButton.hover.textColor = HexToColor("#E59400");
guiStyleButton.active.background = lightBackground;
guiStyleButton.active.textColor = HexToColor("#E59400");
guiStyleButton.focused.background = lightBackground;
guiStyleButton.focused.textColor = HexToColor("#FFA500");
guiStyleButton.fontSize = 14;
guiStyleButton.alignment = (TextAnchor)4;
guiStyleButtonSelected = new GUIStyle(guiStyleButton);
guiStyleButtonSelected.normal.background = purpleBackground;
guiStyleButtonSelected.normal.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.hover.background = purpleBackground;
guiStyleButtonSelected.hover.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.active.background = purpleBackground;
guiStyleButtonSelected.active.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.focused.background = purpleBackground;
guiStyleButtonSelected.focused.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.onNormal.background = purpleBackground;
guiStyleButtonSelected.onNormal.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.onHover.background = purpleBackground;
guiStyleButtonSelected.onHover.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.onActive.background = purpleBackground;
guiStyleButtonSelected.onActive.textColor = HexToColor("#FFA500");
guiStyleButtonSelected.onFocused.background = purpleBackground;
guiStyleButtonSelected.onFocused.textColor = HexToColor("#FFA500");
guiStyleLabel = new GUIStyle(GUI.skin.label);
guiStyleLabel.normal.textColor = HexToColor("#FFA500");
guiStyleLabel.fontSize = 16;
guiStyleLabel.alignment = (TextAnchor)4;
}
public static void DrawGUI()
{
//IL_0053: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: 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)
if (shouldShow)
{
float num = Screen.width / 2 - 100;
float num2 = Screen.height / 2 - 90;
int num3 = 200;
int num4 = 240;
int num5 = 3;
GUI.Box(new Rect(num - (float)num5, num2 - (float)num5, (float)(num3 + 2 * num5), (float)(num4 + 2 * num5)), GUIContent.none, guiStyleBorder);
GUI.Box(new Rect(num, num2, (float)num3, (float)num4), "Casper's QOL Menu", guiStyleBox);
SharedState.speedToggle = GUI.Toggle(new Rect(num + 10f, num2 + 30f, 180f, 30f), SharedState.speedToggle, "Concrete Speed", SharedState.speedToggle ? guiStyleButtonSelected : guiStyleButton);
if (GUI.changed)
{
Debug.Log((object)("Concrete Speed Toggle changed: " + SharedState.speedToggle));
}
SharedState.lightToggle = GUI.Toggle(new Rect(num + 10f, num2 + 70f, 180f, 30f), SharedState.lightToggle, "Headlight Toggle", SharedState.lightToggle ? guiStyleButtonSelected : guiStyleButton);
if (GUI.changed)
{
Debug.Log((object)("Headlight Toggle changed: " + SharedState.lightToggle));
}
GUI.Label(new Rect(num, num2 + 115f, (float)num3, 20f), "Cheats:", guiStyleLabel);
SharedState.oreProtect = GUI.Toggle(new Rect(num + 10f, num2 + 140f, 180f, 30f), SharedState.oreProtect, "Infinite Ore", SharedState.oreProtect ? guiStyleButtonSelected : guiStyleButton);
if (GUI.changed)
{
Debug.Log((object)("Infinite Ore Toggle changed: " + SharedState.oreProtect));
}
}
}
private static Color HexToColor(string hex)
{
//IL_0054: 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_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
hex = hex.Replace("#", "");
byte b = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
byte b2 = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
byte b3 = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
return Color32.op_Implicit(new Color32(b, b2, b3, byte.MaxValue));
}
private static Texture2D CreateColorTexture(string hex)
{
//IL_0002: 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_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
Color val = HexToColor(hex);
Texture2D val2 = new Texture2D(1, 1);
val2.SetPixel(0, 0, val);
val2.Apply();
return val2;
}
}
namespace CasperQOL
{
public static class SharedState
{
public static string stoodOn = "";
public static string lastZone = "";
public static bool speedToggle = false;
public static bool lightToggle = false;
public static bool protectToggle = false;
public static bool oreProtect = false;
public static ConfigEntry<KeyboardShortcut> toggleKey;
public static readonly HashSet<string> ValidResourceNames = new HashSet<string> { "Calycite Platform (1x1)", "Calycite Platform (3x3)", "Calycite Platform (5x5)" };
public static float CustomMaxRunSpeed { get; set; } = 11f;
public static float CustomMaxWalkSpeed { get; set; } = 8f;
public static float DefaultMaxRunSpeed { get; set; } = 8f;
public static float DefaultMaxWalkSpeed { get; set; } = 5f;
}
[BepInPlugin("com.casper.CasperQOL", "CasperQOL", "1.0.4")]
public class CasperQOL : BaseUnityPlugin
{
private const string MyGUID = "com.casper.CasperQOL";
private const string PluginName = "CasperQOL";
private const string VersionString = "1.0.4";
private static readonly Harmony Harmony = new Harmony("com.casper.CasperQOL");
public static ManualLogSource Log = new ManualLogSource("CasperQOL");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CasperQOL, VersionString: 1.0.4 is loading...");
Harmony.PatchAll();
CreateConfigEntries();
ApplyPatches();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CasperQOL, VersionString: 1.0.4 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = SharedState.toggleKey.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ShowGUI.shouldShow = !ShowGUI.shouldShow;
}
}
private void OnGUI()
{
ShowGUI.DrawGUI();
}
private void ApplyPatches()
{
Harmony.CreateAndPatchAll(typeof(PlayerFirstPersonControllerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(HeadlampUpdatePatch), (string)null);
Harmony.CreateAndPatchAll(typeof(VoxelModificationPatch), (string)null);
}
private void CreateConfigEntries()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut val = default(KeyboardShortcut);
((KeyboardShortcut)(ref val))..ctor((KeyCode)269, Array.Empty<KeyCode>());
SharedState.toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "GUI Key", val, "Key to toggle the GUI.");
}
}
[HarmonyPatch(typeof(PendingVoxelChanges), "TryDig")]
public static class VoxelModificationPatch
{
public static int MaxIntegrity = 10000;
[HarmonyPostfix]
public static void TryDigPostfix(PendingVoxelChanges __instance, Vector3Int coord, int digStrength, int miningTier, ref int numResourcesTaken, bool __result)
{
if (SharedState.oreProtect && !__result && numResourcesTaken > 0)
{
try
{
int x = ((Vector3Int)(ref coord)).x;
int y = ((Vector3Int)(ref coord)).y;
int z = ((Vector3Int)(ref coord)).z;
int chunkId = VoxelManager.GetChunkId(ref x, ref y, ref z);
int orCreateIndexForChunk = __instance.GetOrCreateIndexForChunk(ref chunkId);
ref ChunkPendingVoxelChanges reference = ref __instance.chunkData[orCreateIndexForChunk];
x = ((Vector3Int)(ref coord)).x;
y = ((Vector3Int)(ref coord)).y;
z = ((Vector3Int)(ref coord)).z;
int index = ((ChunkPendingVoxelChanges)(ref reference)).GetIndex(ref x, ref y, ref z);
ref ModifiedCoordData orAdd = ref ((ChunkPendingVoxelChanges)(ref reference)).GetOrAdd(index);
int num = Math.Min(numResourcesTaken, MaxIntegrity - orAdd.integrity);
orAdd.integrity += num;
}
catch (Exception ex)
{
Debug.LogError((object)("Error in TryDigPostfix: " + ex.Message));
}
}
}
}
}
namespace CasperQOL.Patches
{
[HarmonyPatch(typeof(Headlamp))]
[HarmonyPatch("Update")]
public class HeadlampUpdatePatch
{
private static bool previousToggleState = SharedState.lightToggle;
private static void Prefix(Headlamp __instance)
{
if (SharedState.lightToggle != previousToggleState)
{
__instance.ToggleLight();
previousToggleState = SharedState.lightToggle;
}
}
}
internal static class PlayerFirstPersonControllerPatch
{
[HarmonyPatch(typeof(PlayerFirstPersonController), "FixedUpdate")]
public static class SpeedModifierPatch
{
private static CapsuleCollider GetBodyCollider(PlayerFirstPersonController controller)
{
return AccessTools.FieldRefAccess<PlayerFirstPersonController, CapsuleCollider>(controller, "bodyCollider");
}
private static LayerMask GetGroundLayer(PlayerFirstPersonController controller)
{
//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)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
return AccessTools.FieldRefAccess<PlayerFirstPersonController, LayerMask>(controller, "groundLayer");
}
private static int GetStandingOnLayer(PlayerFirstPersonController controller)
{
return AccessTools.FieldRefAccess<PlayerFirstPersonController, int>(controller, "standingOnLayer");
}
private static void SetStandingOnLayer(PlayerFirstPersonController controller, int layer)
{
AccessTools.FieldRefAccess<PlayerFirstPersonController, int>(controller, "standingOnLayer") = layer;
}
private static float CalculateLegHeight(PlayerFirstPersonController controller)
{
//IL_0009: 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)
CapsuleCollider bodyCollider = GetBodyCollider(controller);
return bodyCollider.center.y * ((Component)controller).transform.lossyScale.y;
}
private static void Prefix(PlayerFirstPersonController __instance)
{
//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_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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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)
//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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_00c0: 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)
CapsuleCollider bodyCollider = GetBodyCollider(__instance);
LayerMask groundLayer = GetGroundLayer(__instance);
float num = CalculateLegHeight(__instance);
Vector3 position = ((Component)__instance).transform.position;
float num2 = 0.3f;
Vector3 val = position + Vector3.up * (num + 0.1f);
float num3 = num + num2;
RaycastHit val2 = default(RaycastHit);
if (Physics.SphereCast(val, bodyCollider.radius, Vector3.down, ref val2, num3, LayerMask.op_Implicit(groundLayer), (QueryTriggerInteraction)1))
{
SetStandingOnLayer(__instance, ((Component)((RaycastHit)(ref val2)).collider).gameObject.layer);
if (((Component)((RaycastHit)(ref val2)).collider).gameObject.CompareTag("IInteractable"))
{
IInteractable component = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<IInteractable>();
if (component != null)
{
GenericMachineInstanceRef myMachineRef = component.myMachineRef;
int resId = ((GenericMachineInstanceRef)(ref myMachineRef)).ResId;
string displayName = SaveState.GetResInfoFromId(resId).displayName;
SharedState.stoodOn = displayName;
Debug.Log((object)("Standing on interactable: " + SharedState.stoodOn));
}
}
else
{
SharedState.stoodOn = "";
}
}
else
{
SharedState.stoodOn = "";
Debug.Log((object)"Not standing on any interactable object.");
}
if (__instance.m_IsGrounded)
{
if (SharedState.ValidResourceNames.Contains(SharedState.stoodOn) && SharedState.speedToggle)
{
UpdateSpeed(__instance, SharedState.CustomMaxRunSpeed, SharedState.CustomMaxWalkSpeed);
}
else
{
UpdateSpeed(__instance, SharedState.DefaultMaxRunSpeed, SharedState.DefaultMaxWalkSpeed);
}
}
else
{
UpdateSpeed(__instance, SharedState.DefaultMaxRunSpeed, SharedState.DefaultMaxWalkSpeed);
}
}
private static void UpdateSpeed(PlayerFirstPersonController controller, float runSpeed, float walkSpeed)
{
if (controller.maxRunSpeed != runSpeed || controller.maxWalkSpeed != walkSpeed)
{
controller.maxRunSpeed = runSpeed;
controller.maxWalkSpeed = walkSpeed;
Debug.Log((object)$"Updated Speeds -> Walk: {walkSpeed}, Run: {runSpeed}");
}
}
}
}
}