using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RadFixes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("raddude")]
[assembly: AssemblyProduct("RadFixes")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("56796b16-fa96-4077-8440-cc4ba31a62f5")]
[assembly: AssemblyFileVersion("1.1.7.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.7.0")]
[module: UnverifiableCode]
namespace RadFixes;
internal static class Extensions
{
public static T GetPrivateField<T>(this object obj, string field)
{
return (T)Traverse.Create(obj).Field(field).GetValue();
}
public static void SetPrivateField(this object obj, string field, object value)
{
Traverse.Create(obj).Field(field).SetValue(value);
}
public static void SetPrivateField<T>(string field, object value)
{
Traverse.Create(typeof(T)).Field(field).SetValue(value);
}
public static object InvokePrivateMethod(this object obj, string method, params object[] parameters)
{
return AccessTools.Method(obj.GetType(), method, (Type[])null, (Type[])null).Invoke(obj, parameters);
}
}
internal class Patches
{
[HarmonyPatch(typeof(ShipItemFishingRod))]
private class ShipItemFishingRodPatches
{
[HarmonyPostfix]
[HarmonyPatch("OnLoad")]
public static void OnLoadSetReverseSpinner(ref float ___spinnerSpeed)
{
if (RF_Plugin.enableFishingReelFix.Value)
{
___spinnerSpeed = -40f;
}
}
[HarmonyPostfix]
[HarmonyPatch("OnBuy")]
public static void OnBuySetReverseSpinner(ref float ___spinnerSpeed)
{
if (RF_Plugin.enableFishingReelFix.Value)
{
___spinnerSpeed = -40f;
}
}
}
[HarmonyPatch(typeof(StartMenu))]
private class StartMenuPatches
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void DestroyDeco(GameObject ___settingsUI)
{
Transform val = ((IEnumerable<Transform>)___settingsUI.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform k) => ((Object)k).name == "deco (1)"));
Object.Destroy((Object)(object)((Component)val).gameObject);
}
[HarmonyPrefix]
[HarmonyPatch("GameToSettings")]
public static void PauseSound()
{
AudioListener.pause = true;
}
[HarmonyPrefix]
[HarmonyPatch("SettingsToGame")]
public static void UnPauseSound()
{
AudioListener.pause = false;
}
[HarmonyPrefix]
[HarmonyPatch("ButtonClick", new Type[] { typeof(StartMenuButtonType) })]
public static void ContinueLoadSlotMenuPre(StartMenuButtonType button, ref int __state)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
__state = SaveSlots.activeSlotsCount;
if ((int)button == 1)
{
SaveSlots.activeSlotsCount++;
}
}
[HarmonyPostfix]
[HarmonyPatch("ButtonClick", new Type[] { typeof(StartMenuButtonType) })]
public static void ContinueLoadSlotMenuPost(StartMenuButtonType button, int __state)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
if ((int)button == 1)
{
SaveSlots.activeSlotsCount = __state;
}
}
[HarmonyPrefix]
[HarmonyPatch("EnableSettingsMenu")]
public static bool BoatCameraNoMenu(GameObject ___logo)
{
if (BoatCamera.on && !Object.op_Implicit((Object)(object)GameState.currentShipyard) && RF_Plugin.boatCameraMenuZoom.Value.Equals("DisableMenu"))
{
___logo.SetActive(false);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("LateUpdate")]
public static bool BoatCameraNoMenuSettingsToGame(StartMenu __instance)
{
if ((Input.GetKeyDown("escape") || Input.GetKeyDown("f10") || Input.GetKeyDown((KeyCode)336)) && GameState.playing && !GameState.currentlyLoading && !Object.op_Implicit((Object)(object)GameState.currentShipyard) && BoatCamera.on && GameState.wasInSettingsMenu && RF_Plugin.boatCameraMenuZoom.Value.Equals("DisableMenu"))
{
__instance.InvokePrivateMethod("SettingsToGame");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(BackupSavesListUI))]
private class BackupSavesListUIPatches
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void SetShowingListFor(ref int ___showingListFor)
{
___showingListFor = -1;
}
}
[HarmonyPatch(typeof(MouseButtonPointer))]
private class MouseButtonPointerPatches
{
[HarmonyPrefix]
[HarmonyPatch("LateUpdate")]
public static bool DisableMouseInputLostFocus()
{
if (!Application.isFocused)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(BoatCamera))]
private class BoatCameraPatches
{
[HarmonyPrefix]
[HarmonyPatch("Update")]
public static bool BoatCameraSettingsMenu(bool ___on)
{
if (GameState.playing && !GameState.currentlyLoading && !Object.op_Implicit((Object)(object)GameState.currentShipyard) && GameState.wasInSettingsMenu && !___on && GameInput.GetKeyDown((InputName)16))
{
return false;
}
if (GameState.wasInSettingsMenu && !Object.op_Implicit((Object)(object)GameState.currentShipyard) && ___on && RF_Plugin.boatCameraMenuZoom.Value.Equals("DisableZoom"))
{
return false;
}
if (GameState.wasInSettingsMenu && !Object.op_Implicit((Object)(object)GameState.currentShipyard) && ___on && GameInput.GetKeyDown((InputName)16) && RF_Plugin.boatCameraMenuZoom.Value.Equals("DisableMenu"))
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(GoPointer))]
private static class GoPointerPatches
{
[HarmonyPrefix]
[HarmonyPatch("DoRaycast")]
public static bool DisableRaycastSpyglass(GoPointer __instance)
{
if (GameState.playing && !GameState.currentlyLoading)
{
PickupableItem heldItem = __instance.GetHeldItem();
if ((Object)(object)heldItem != (Object)null && ((Component)heldItem).GetComponent<ShipItem>()?.name == "spyglass" && ((PickupableItem)((Component)heldItem).GetComponent<ShipItemSpyglass>()).heldRotationOffset != -22f)
{
((Component)__instance.lookUI).gameObject.SetActive(false);
return false;
}
((Component)__instance.lookUI).gameObject.SetActive(true);
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("LateUpdate")]
public static bool DisableAltActivatePlacing(GoPointer __instance, PickupableItem ___heldItem, GoPointerButton ___pointedAtButton)
{
if (GameState.playing && !GameState.currentlyLoading && (Object)(object)___heldItem != (Object)null && ((Component)___heldItem).GetComponent<ShipItem>()?.name == "spyglass" && Object.op_Implicit((Object)(object)___pointedAtButton) && ___pointedAtButton.allowPlacingItems && __instance.AltButtonDown())
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(ShipItemChipLog))]
private class ShipItemChipLogPatches
{
[HarmonyPrefix]
[HarmonyPatch("OnBuy")]
public static bool ChipLogOnBuy(ShipItemChipLog __instance, ref Rigidbody ___bobberBody, ConfigurableJoint ___bobberJoint, ref Vector3 ___initialBobberPos, ref SimpleFloatingObject ___bobberFloater)
{
//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)
___bobberBody = ((Component)___bobberJoint).GetComponent<Rigidbody>();
((Component)___bobberJoint).transform.parent = Refs.shiftingWorld;
___initialBobberPos = ((Joint)___bobberJoint).connectedAnchor;
___bobberFloater = ((Component)___bobberBody).GetComponent<SimpleFloatingObject>();
_ = ((ShipItem)__instance).sold;
return false;
}
}
[HarmonyPatch(typeof(CargoCarrier))]
private class CargoCarrierPatches
{
[HarmonyPrefix]
[HarmonyPatch("Awake")]
public static bool SunspireFixHelper(CargoCarrier __instance)
{
if (__instance.portIndex == 0)
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(EconomyUI))]
private class EconomyUIPatches
{
[HarmonyPostfix]
[HarmonyPatch("OpenUI")]
public static void FirstPagePatch(EconomyUI __instance, EconomyUIButton[] ___goodsListButtons, ref TextMesh ___textPageNumber)
{
int num = Mathf.CeilToInt((float)__instance.goodCount / (float)___goodsListButtons.Length);
___textPageNumber.text = "1 / " + num;
}
[HarmonyPrefix]
[HarmonyPatch("RefreshGoodsList")]
public static bool RefreshGoodsListPatch(EconomyUI __instance, EconomyUIButton[] ___goodsListButtons, int ___currentGoodsListPage, EconomyUIGoodsOrder ___goodsOrder, Material[] ___buttonMaterials, IslandMarket ___currentIsland)
{
int num = ___goodsListButtons.Length;
for (int i = 0; i < num; i++)
{
int num2 = num * ___currentGoodsListPage + i + 1;
if (num2 >= ___goodsOrder.goods.Length)
{
((Component)___goodsListButtons[i]).gameObject.SetActive(false);
continue;
}
ShipItem goodAt = ___goodsOrder.GetGoodAt(num2);
int goodIndex = ___goodsOrder.GetGoodIndex(num2);
if (Object.op_Implicit((Object)(object)goodAt) && goodIndex != 51)
{
___goodsListButtons[i].SetButtonText(goodAt.name);
}
else
{
___goodsListButtons[i].SetButtonText("---");
}
if (!Object.op_Implicit((Object)(object)goodAt))
{
___goodsListButtons[i].SetButtonMaterial(___buttonMaterials[1]);
}
else if (__instance.currentSelectedGood == goodIndex)
{
___goodsListButtons[i].SetButtonMaterial(___buttonMaterials[2]);
}
else if (___currentIsland.HasGood(goodIndex))
{
___goodsListButtons[i].SetButtonMaterial(___buttonMaterials[0]);
}
else
{
___goodsListButtons[i].SetButtonMaterial(___buttonMaterials[1]);
}
___goodsListButtons[i].SetButtonIndex(goodIndex);
((Component)___goodsListButtons[i]).gameObject.SetActive(true);
}
return false;
}
}
}
[BepInPlugin("com.raddude82.radfixes", "RadFixes", "1.1.7")]
public class RF_Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "com.raddude82.radfixes";
public const string PLUGIN_NAME = "RadFixes";
public const string PLUGIN_VERSION = "1.1.7";
internal static ConfigEntry<bool> enableFishingReelFix;
internal static ConfigEntry<string> boatCameraMenuZoom;
internal static RF_Plugin Instance;
internal static ManualLogSource logger;
private void Awake()
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
return;
}
Instance = this;
logger = ((BaseUnityPlugin)this).Logger;
enableFishingReelFix = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Enable reel fix", true, "If enabled will rotate the fishing rod reel in the direction it should.");
boatCameraMenuZoom = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Boat camera settings menu zoom fix", "DisableZoom", new ConfigDescription("While paused in boat camera mode: DisableZoom will disable zooming in and out, DisableMenu will disable the menu, None will leave it as it is.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "DisableZoom", "DisableMenu", "None" }), Array.Empty<object>()));
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.raddude82.radfixes");
SceneManager.sceneLoaded += SceneLoaded;
}
private static void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if (((Scene)(ref scene)).name == "island 1 A Gold Rock")
{
SceneFixes.GoldRockCity();
}
if (((Scene)(ref scene)).name == "island 13 E (Sage Hills)")
{
SceneFixes.SageHills();
}
if (((Scene)(ref scene)).name == "island 16 M (Sunspire)")
{
SceneFixes.Sunspire();
}
if (((Scene)(ref scene)).name == "island 18 M (Oasis)")
{
SceneFixes.HappyBay();
}
if (((Scene)(ref scene)).name == "island 19 M (Eastwind)")
{
SceneFixes.Eastwind();
}
if (((Scene)(ref scene)).name == "island 25 (chronos)")
{
SceneFixes.Chronos();
}
if (((Scene)(ref scene)).name == "island 35 M (valley)")
{
SceneFixes.FeyValley();
}
}
}
internal class SceneFixes
{
internal static void GoldRockCity()
{
GameObject islandScenery = GameObject.Find("island 1 A (gold rock) scenery");
SetShopkeeper(islandScenery, "shop (3)", "shopkeeper (5)");
SetShopkeeper(islandScenery, "shop (7)", "shopkeeper (9)");
}
private static void SetShopkeeper(GameObject islandScenery, string shopName, string shopkeeperName)
{
ShopArea val = ((islandScenery != null) ? ((IEnumerable<ShopArea>)islandScenery.GetComponentsInChildren<ShopArea>()).FirstOrDefault((Func<ShopArea, bool>)((ShopArea k) => ((Object)k).name == shopName)) : null);
Shopkeeper val2 = ((islandScenery != null) ? ((IEnumerable<Shopkeeper>)islandScenery.GetComponentsInChildren<Shopkeeper>()).FirstOrDefault((Func<Shopkeeper, bool>)((Shopkeeper k) => ((Object)k).name == shopkeeperName)) : null);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
{
val.SetPrivateField("keeper", val2);
val2.SetPrivateField("shop", val);
}
}
internal static void SageHills()
{
GameObject val = GameObject.Find("island 13 E (sage hills) scenery");
ShopArea val2 = ((val != null) ? ((IEnumerable<ShopArea>)val.GetComponentsInChildren<ShopArea>()).FirstOrDefault((Func<ShopArea, bool>)((ShopArea k) => ((Object)k).name == "shop area (2)")) : null);
if (!((Object)(object)val2 == (Object)null))
{
val2.openAtNight = true;
}
}
internal static void HappyBay()
{
GameObject val = GameObject.Find("island 18 M (Oasis) scenery");
Shopkeeper val2 = ((val != null) ? ((IEnumerable<Shopkeeper>)val.GetComponentsInChildren<Shopkeeper>()).FirstOrDefault((Func<Shopkeeper, bool>)((Shopkeeper k) => ((Object)k).name == "shopkeeper")) : null);
if (!((Object)(object)val2 == (Object)null))
{
val.gameObject.AddComponent<RF_NPCSchedule>();
val.gameObject.GetComponent<RF_NPCSchedule>().SetPrivateField("keeper", val2);
}
}
internal static void Eastwind()
{
GameObject val = GameObject.Find("island 19 M (Eastwind) scenery");
IEnumerable<Shopkeeper> enumerable = ((val != null) ? (from k in val.GetComponentsInChildren<Shopkeeper>()
where ((Object)k).name == "shopkeeper (1)"
select k) : null);
Shopkeeper val2 = null;
foreach (Shopkeeper item in enumerable)
{
val2 = item;
if ((Object)(object)item.GetPrivateField<ShopArea>("shop") == (Object)null)
{
((Object)item).name = "shopkeeper (3)";
break;
}
}
ShopArea val3 = ((val != null) ? ((IEnumerable<ShopArea>)val.GetComponentsInChildren<ShopArea>()).FirstOrDefault((Func<ShopArea, bool>)((ShopArea k) => ((Object)k).name == "shop area (2)")) : null);
if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val2 == (Object)null))
{
val3.SetPrivateField("keeper", val2);
val2.SetPrivateField("shop", val3);
}
}
internal static void Chronos()
{
GameObject val = GameObject.Find("island 25 (chronos) scenery");
IEnumerable<ShopArea> enumerable = ((val != null) ? (from k in val.GetComponentsInChildren<ShopArea>()
where ((Object)k).name == "shop area"
select k) : null);
ShopArea val2 = null;
ShopArea val3 = null;
foreach (ShopArea item in enumerable)
{
if (item.itemsForSale.Count > 0 && item.itemsForSale[0].name == "bun")
{
val2 = item;
}
if (item.itemsForSale.Count > 0 && item.itemsForSale[0].name == "trout")
{
val3 = item;
}
}
Shopkeeper val4 = ((val != null) ? ((IEnumerable<Shopkeeper>)val.GetComponentsInChildren<Shopkeeper>()).FirstOrDefault((Func<Shopkeeper, bool>)((Shopkeeper k) => ((Object)k).name == "shopkeeper (3)")) : null);
Shopkeeper val5 = ((val != null) ? ((IEnumerable<Shopkeeper>)val.GetComponentsInChildren<Shopkeeper>()).FirstOrDefault((Func<Shopkeeper, bool>)((Shopkeeper k) => ((Object)k).name == "shopkeeper (4)")) : null);
if ((Object)(object)val3 != (Object)null && (Object)(object)val5 != (Object)null)
{
val3.SetPrivateField("keeper", val5);
val5.SetPrivateField("shop", val3);
}
if ((Object)(object)val2 != (Object)null && (Object)(object)val4 != (Object)null)
{
val2.SetPrivateField("keeper", val4);
val4.SetPrivateField("shop", val2);
}
}
internal static void FeyValley()
{
GameObject val = GameObject.Find("scenery");
CargoTransportDude val2 = ((val != null) ? ((IEnumerable<CargoTransportDude>)val.GetComponentsInChildren<CargoTransportDude>()).FirstOrDefault((Func<CargoTransportDude, bool>)((CargoTransportDude k) => ((Object)k).name == "transport dude")) : null);
if (!((Object)(object)val2 == (Object)null))
{
val2.carrierIndex = 35;
}
}
internal static void Sunspire()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
if ((Object)(object)CargoCarrier.carriers[16] == (Object)null)
{
Transform val = ((IEnumerable<Transform>)((Component)Refs.observerMirror).gameObject.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform k) => ((Object)k).name == "cargo carriers"));
CargoCarrier val2 = ((Component)val).gameObject.AddComponent<CargoCarrier>();
val2.portIndex = 16;
val2.currency = (Currency)2;
val2.transportPriceMult = 2f;
val2.storagePriceMult = 1f;
val2.cargo = new List<ShipItem>();
Sun.OnNewDay += new NewDay(val2.RegisterDayPassed);
CargoCarrier.carriers[16] = val2;
}
}
}
public class RF_NPCSchedule : MonoBehaviour
{
[SerializeField]
private Shopkeeper keeper;
private void Awake()
{
keeper = null;
}
public void Update()
{
if (!Object.op_Implicit((Object)(object)keeper))
{
return;
}
if (Sun.sun.localTime >= 18f || Sun.sun.localTime < 7f)
{
if (((Component)keeper).gameObject.activeInHierarchy)
{
((Component)keeper).gameObject.SetActive(false);
}
}
else if (!((Component)keeper).gameObject.activeInHierarchy)
{
((Component)keeper).gameObject.SetActive(true);
}
}
}