using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SmartFishing")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SmartFishing")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5adf077a-740b-4e39-8ede-7f719ad19c53")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BetterFishing;
[BepInPlugin("kam1goroshi.BetterFishing", "BetterFishing", "1.2.2")]
[BepInProcess("valheim.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class BetterFishing : BaseUnityPlugin
{
[HarmonyPatch(typeof(FishingFloat), "Awake")]
private class FishingFixedUpdatePatch
{
private static void Postfix(ref float ___m_fishingSkillImproveHookedMultiplier)
{
___m_fishingSkillImproveHookedMultiplier = hookExpMultiplier.Value;
}
}
[HarmonyPatch(typeof(Fish), "OnHooked")]
private class fishLevelBoostPatch
{
private static void Postfix(Fish __instance, FishingFloat ff)
{
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
ItemDrop itemDrop = __instance.m_itemDrop;
string value;
if ((Object)(object)itemDrop == (Object)null || itemDrop.m_itemData == null)
{
logger.LogError((object)"Called boost patch on fish that had no itemDrop on it");
}
else if (itemDrop.m_itemData.m_customData.ContainsKey("FishHadBeenCaught"))
{
logger.LogMessage((object)"Fish has been marked as caught. Won't boost attempt");
}
else if ((Object)(object)ff != (Object)null)
{
float skillLevel = ((Character)Player.m_localPlayer).GetSkillLevel((SkillType)104);
if (skillLevel >= (float)fishingBoosterStartLevel.Value && !itemDrop.m_itemData.m_customData.ContainsKey("BoostedByFishingLevel"))
{
float num = skillLevel / 100f;
float num2 = fishingBoosterMaxChance.Value * num;
int num3 = 0;
float num4 = Random.Range(0f, 1f);
logger.LogMessage((object)$"Boosting success rate: {num2 * 100f:f2}% and rolled {num4 * 100f:F2}%");
if (num2 > num4)
{
itemDrop.SetQuality(Mathf.Clamp(itemDrop.m_itemData.m_quality + 1, minFishLevel, maxFishLevel));
num3++;
}
if (num3 > 0)
{
ff.GetOwner().Message((MessageType)2, $"Fish Level raised by {num3}!", 0, (Sprite)null);
itemDrop.m_itemData.m_customData.Add("BoostedByFishingLevel", $"{num3}");
Object.Instantiate<GameObject>(myAssetBundle.LoadAsset<GameObject>("kam_LevelUpEffect"), ((Component)__instance).transform.position, ((Component)__instance).transform.rotation);
itemDrop.Save();
}
}
}
else if (itemDrop.m_itemData.m_customData.TryGetValue("BoostedByFishingLevel", out value))
{
logger.LogMessage((object)"In OnHooked(null) with fish that was not already caught");
int num5 = int.Parse(value);
itemDrop.SetQuality(Mathf.Clamp(itemDrop.m_itemData.m_quality - num5, minFishLevel, maxFishLevel));
itemDrop.m_itemData.m_customData.Remove("BoostedByFishingLevel");
itemDrop.Save();
((Character)Player.m_localPlayer).Message((MessageType)2, "Failed to catch, fish level unboosted..", 0, (Sprite)null);
}
}
}
[HarmonyPatch(typeof(FishingFloat), "Catch")]
private class FishCatchPatch
{
private static void Prefix(Fish fish, Character owner)
{
if ((Object)(object)fish != (Object)null)
{
ItemDrop component = ((Component)fish).gameObject.GetComponent<ItemDrop>();
string name = ((Object)((Humanoid)Player.m_localPlayer).GetAmmoItem().m_dropPrefab).name;
float expGainOnCatch = getExpGainOnCatch(component.m_itemData.m_quality, name);
((Character)Player.m_localPlayer).RaiseSkill((SkillType)104, expGainOnCatch);
if (!component.m_itemData.m_customData.ContainsKey("FishHadBeenCaught"))
{
component.m_itemData.m_customData.Add("FishHadBeenCaught", "");
component.Save();
}
}
else
{
logger.LogError((object)"null fish in FishCatchPatch");
}
}
}
[HarmonyPatch(typeof(Fish), "Pickup")]
private class FishPickupPatch
{
private static void Prefix(Fish __instance)
{
ItemDrop component = ((Component)__instance).GetComponent<ItemDrop>();
if ((Object)(object)component != (Object)null)
{
if (__instance.IsHooked())
{
string name = ((Object)((Humanoid)Player.m_localPlayer).GetAmmoItem().m_dropPrefab).name;
float expGainOnCatch = getExpGainOnCatch(component.m_itemData.m_quality, name);
((Character)Player.m_localPlayer).RaiseSkill((SkillType)104, expGainOnCatch);
if (!component.m_itemData.m_customData.ContainsKey("FishHadBeenCaught"))
{
component.m_itemData.m_customData.Add("FishHadBeenCaught", "");
component.Save();
}
}
}
else
{
logger.LogError((object)"null fish in FishPickupPatch");
}
}
}
private const string GUID = "kam1goroshi.BetterFishing";
private const string readableName = "BetterFishing";
private const string version = "1.2.2";
private static AssetBundle myAssetBundle;
private static string ConfigFileName = "kam1goroshi.BetterFishing.cfg";
private static string configFilePath = Paths.ConfigPath;
private static string ConfigFileFullPath;
private static readonly int maxFishLevel;
private static readonly int minFishLevel;
private static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("kam1goroshi.BetterFishing");
private static Dictionary<string, float> baitBonusExpMap;
private static ConfigEntry<float> hookExpMultiplier;
private static ConfigEntry<float> stepsForCatch;
private static ConfigEntry<float> bonusPerFishLevel;
private static ConfigEntry<float> fishingBaitBonus;
private static ConfigEntry<float> fishingBaitForestBonus;
private static ConfigEntry<float> fishingBaitSwampBonus;
private static ConfigEntry<float> fishingBaitCaveBonus;
private static ConfigEntry<float> fishingBaitPlainsBonus;
private static ConfigEntry<float> fishingBaitOceanBonus;
private static ConfigEntry<float> fishingBaitAshlandsBonus;
private static ConfigEntry<float> fishingBaitDeepNorthBonus;
private static ConfigEntry<float> fishingBaitMistlandsBonus;
private static ConfigEntry<int> fishingBoosterStartLevel;
private static ConfigEntry<float> fishingBoosterMaxChance;
private const string caughtFlagKey = "FishHadBeenCaught";
private const string boostedByFishingLevelKey = "BoostedByFishingLevel";
private void Awake()
{
//IL_001e: 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_002b: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Expected O, but got Unknown
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Expected O, but got Unknown
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Expected O, but got Unknown
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Expected O, but got Unknown
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Expected O, but got Unknown
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Expected O, but got Unknown
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02ba: Expected O, but got Unknown
//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Expected O, but got Unknown
//IL_0334: Unknown result type (might be due to invalid IL or missing references)
//IL_033e: Expected O, but got Unknown
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Expected O, but got Unknown
//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
//IL_03b8: Expected O, but got Unknown
myAssetBundle = AssetUtils.LoadAssetBundleFromResources("kam_bundle", typeof(BetterFishing).Assembly);
ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
{
IsAdminOnly = true
};
hookExpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Hook_Exp_Multiplier", 2f, new ConfigDescription("Reeling exp with a hooked fish compared to vanilla empty reel. Vanilla/Default: 2x", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), new object[1] { val }));
stepsForCatch = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Steps_For_Catch", 10f, new ConfigDescription("Catching bonus compared to vanilla empty reel. 0 gives no bonus in any case", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[1] { val }));
bonusPerFishLevel = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Bonus_Per_Fish_Level", 0.5f, new ConfigDescription("Exp bonus multiplier given for fish level. 0 for no bonus. With 1.0 a 5 star fish will give +500% exp", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Simple_Fishing_Bait_bonus", 0f, new ConfigDescription("Bonus exp multiplier for using the default bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitForestBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Mossy_Fishing_Bait_bonus", 0.25f, new ConfigDescription("Bonus exp multiplier for using black forrest bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitSwampBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Sticky_Fishing_Bait_bonus", 0.4f, new ConfigDescription("Bonus exp multiplier for using swamp bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitCaveBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Cold_Fishing_Bait_bonus", 0.8f, new ConfigDescription("Bonus exp multiplier for using cave bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitPlainsBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Stingy_Fishing_Bait_bonus", 0.5f, new ConfigDescription("Bonus exp multiplier for using plains bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitOceanBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Heavy_Fishing_Bait_bonus", 1.2f, new ConfigDescription("Bonus exp multiplier for using ocean bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitMistlandsBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Misty_Fishing_Bait_bonus", 0.75f, new ConfigDescription("Bonus exp multiplier for using mistlands bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitAshlandsBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Hot_Fishing_Bait_bonus", 1f, new ConfigDescription("Bonus exp multiplier for using ashlands bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBaitDeepNorthBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fish type bonus", "Frosty_Fishing_Bait_bonus", 1.3f, new ConfigDescription("Bonus exp multiplier for using deep north bait. 0 for no additional bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), new object[1] { val }));
fishingBoosterStartLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Fish Level Booster", "Boosting_Starting_Level", 20, new ConfigDescription("At what level you can increase the level of fish by hooking them", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { val }));
fishingBoosterMaxChance = ((BaseUnityPlugin)this).Config.Bind<float>("Fish Level Booster", "Max_Boosting_Chance", 1f, new ConfigDescription("What is the max chance? You chances increase linearly as you level until max. 0 to turn off", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { val }));
baitBonusExpMap.Add("FishingBait", fishingBaitBonus.Value);
baitBonusExpMap.Add("FishingBaitForest", fishingBaitForestBonus.Value);
baitBonusExpMap.Add("FishingBaitSwamp", fishingBaitSwampBonus.Value);
baitBonusExpMap.Add("FishingBaitCave", fishingBaitCaveBonus.Value);
baitBonusExpMap.Add("FishingBaitPlains", fishingBaitPlainsBonus.Value);
baitBonusExpMap.Add("FishingBaitOcean", fishingBaitOceanBonus.Value);
baitBonusExpMap.Add("FishingBaitMistlands", fishingBaitMistlandsBonus.Value);
baitBonusExpMap.Add("FishingBaitAshlands", fishingBaitAshlandsBonus.Value);
baitBonusExpMap.Add("FishingBaitDeepNorth", fishingBaitDeepNorthBonus.Value);
SetupWatcher();
foreach (KeyValuePair<string, float> item in baitBonusExpMap)
{
logger.LogDebug((object)$"Added <key:{item.Key},value:{item.Value} in baitBonusExpMap");
}
harmony.PatchAll();
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(ConfigFileFullPath))
{
return;
}
try
{
logger.LogDebug((object)"Attempting to reload configuration...");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
logger.LogError((object)("There was an issue loading " + ConfigFileName));
}
}
private static float getExpGainOnCatch(float quality, string baitPrefabName)
{
float value = stepsForCatch.Value;
value *= 1f + bonusPerFishLevel.Value * (quality - 1f);
if (baitBonusExpMap.TryGetValue(baitPrefabName, out var value2))
{
value *= value2 + 1f;
logger.LogMessage((object)$"Skill raised by {value}");
return value;
}
logger.LogError((object)"Key wasn't found in bait bonus map.");
return value;
}
static BetterFishing()
{
string text = configFilePath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = text + directorySeparatorChar + ConfigFileName;
maxFishLevel = 5;
minFishLevel = 1;
logger = Logger.CreateLogSource("BetterFishing");
baitBonusExpMap = new Dictionary<string, float>();
}
}