using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using MinorTweaks.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MinorTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MinorTweaks")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("72d79f23-dad1-4fea-ad13-acd9a2f9fee7")]
[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")]
namespace MinorTweaks
{
[BepInPlugin("ironbean.MinorTweaks", "Minor Tweaks", "1.4.0")]
public class MinorTweaks : BaseUnityPlugin
{
private const string modGUID = "ironbean.MinorTweaks";
private const string modName = "Minor Tweaks";
private const string modVersion = "1.4.0";
private readonly Harmony harmony = new Harmony("ironbean.MinorTweaks");
internal static MinorTweaks Instance;
internal static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("ironbean.MinorTweaks");
mls.LogInfo((object)" hello! o/");
harmony.PatchAll(typeof(MinorTweaks));
harmony.PatchAll(typeof(LandmineCollision));
harmony.PatchAll(typeof(TVRemote));
harmony.PatchAll(typeof(WolfKiller));
harmony.PatchAll(typeof(WeedRemover));
harmony.PatchAll(typeof(InverseCooldownRemover));
harmony.PatchAll(typeof(TerminalHotSwitcher));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(CruiserVolume));
}
}
}
namespace MinorTweaks.Patches
{
[HarmonyPatch(typeof(TimeOfDay))]
internal class MeteorChance
{
private static int daysWithoutMeteor;
[HarmonyPatch("DecideRandomDayEvents")]
[HarmonyPostfix]
public static void OverwriteMeteorChance(TimeOfDay __instance)
{
if (((NetworkBehaviour)__instance).IsServer)
{
Random random = new Random(StartOfRound.Instance.randomMapSeed + 28);
float num = -0.4f + (float)Math.Pow(0.85, -daysWithoutMeteor);
if ((float)random.Next(0, 100) < num)
{
daysWithoutMeteor = 0;
__instance.meteorShowerAtTime = (float)random.Next(5, 80) / 100f;
}
else
{
daysWithoutMeteor++;
__instance.meteorShowerAtTime = -1f;
}
}
}
}
[HarmonyPatch(typeof(VehicleController))]
internal class CruiserVolume
{
private static float lastTimeValue = -1f;
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void CruiserUpdate(VehicleController __instance, ref bool ___radioOn)
{
__instance.radioAudio.volume = 0.2f;
if (!((NetworkBehaviour)__instance).IsServer)
{
return;
}
if (__instance.carDestroyed || !__instance.ignitionStarted)
{
if (___radioOn)
{
__instance.SwitchRadio();
}
return;
}
if (lastTimeValue > __instance.radioAudio.time && ___radioOn)
{
__instance.ChangeRadioStation();
}
lastTimeValue = __instance.radioAudio.time;
}
}
[HarmonyPatch(typeof(ShipTeleporter))]
internal class InverseCooldownRemover
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void SetCooldown(ref float ___cooldownAmount)
{
___cooldownAmount = 10f;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void DropItemButton(PlayerControllerB __instance)
{
if (!((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)__instance) && !__instance.isTypingChat && !__instance.inTerminalMenu && !__instance.quickMenuManager.isMenuOpen && !__instance.isGrabbingObjectAnimation && ((ButtonControl)Keyboard.current[(Key)22]).wasPressedThisFrame)
{
__instance.DropAllHeldItemsAndSync();
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalHotSwitcher
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void Switch(Terminal __instance)
{
if (!(GameNetworkManager.Instance?.localPlayerController?.inTerminalMenu).GetValueOrDefault())
{
return;
}
bool wasPressedThisFrame = ((ButtonControl)Keyboard.current[(Key)63]).wasPressedThisFrame;
bool wasPressedThisFrame2 = ((ButtonControl)Keyboard.current[(Key)62]).wasPressedThisFrame;
bool wasPressedThisFrame3 = ((ButtonControl)Keyboard.current[(Key)64]).wasPressedThisFrame;
bool wasPressedThisFrame4 = ((ButtonControl)Keyboard.current[(Key)61]).wasPressedThisFrame;
if (!(wasPressedThisFrame4 || wasPressedThisFrame2))
{
return;
}
ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
int targetTransformIndex = mapScreen.targetTransformIndex;
int num = targetTransformIndex;
PlayerControllerB component;
do
{
num += ((!wasPressedThisFrame4) ? 1 : (-1));
if (num < 0)
{
num = mapScreen.radarTargets.Count - 1;
}
else if (num >= mapScreen.radarTargets.Count)
{
num = 0;
}
component = ((Component)mapScreen.radarTargets[num].transform).gameObject.GetComponent<PlayerControllerB>();
}
while ((Object)(object)component != (Object)null && !component.isPlayerControlled && !component.isPlayerDead && (Object)(object)component.redirectToEnemy == (Object)null && num != targetTransformIndex);
if (num != targetTransformIndex)
{
mapScreen.SwitchRadarTargetAndSync(num);
__instance.LoadNewNode(__instance.terminalNodes.specialNodes[20]);
}
}
}
[HarmonyPatch(typeof(MoldSpreadManager))]
internal class WeedRemover
{
[HarmonyPatch("GenerateMold")]
[HarmonyPostfix]
private static void ICalledTheWeedMan(MoldSpreadManager __instance)
{
__instance.RemoveAllMold();
}
}
[HarmonyPatch(typeof(BushWolfEnemy))]
internal class WolfKiller
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void KillThem(BushWolfEnemy __instance)
{
((EnemyAI)__instance).KillEnemy(true);
}
}
[HarmonyPatch(typeof(WhoopieCushionItem))]
internal class UsableWhoopieCushion
{
[HarmonyPatch("ItemInteractLeftRightOnClient")]
[HarmonyPostfix]
private static void UseWhoopieCushion(ref WhoopieCushionItem __instance)
{
__instance.Fart();
}
}
[HarmonyPatch(typeof(Landmine))]
internal class LandmineCollision
{
[HarmonyPatch("ExplodeMineClientRpc")]
[HarmonyPostfix]
private static void disableLandmineCollision(Landmine __instance)
{
SphereCollider componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<SphereCollider>();
if (!((Object)(object)componentInChildren == (Object)null) && __instance.hasExploded)
{
((Collider)componentInChildren).enabled = false;
}
}
}
[HarmonyPatch(typeof(RemoteProp))]
internal class TVRemote
{
[HarmonyPatch("ItemActivate")]
[HarmonyPostfix]
private static void ToggleTV(ref RemoteProp __instance)
{
((GrabbableObject)__instance).useCooldown = 0.2f;
Object.FindObjectOfType<ShipLights>().ToggleShipLightsOnLocalClientOnly();
if (((NetworkBehaviour)__instance).IsServer)
{
TVScript val = Object.FindObjectOfType<TVScript>();
if (!((Object)(object)val == (Object)null))
{
val.SwitchTVLocalClient();
}
}
}
}
}