Decompiled source of FishSlap v1.1.0

BepInEx/plugins/FishSlap.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("ClassLibrary3")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary3")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("326bffc6-6fe8-4664-bb45-5d208e992e70")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FishSlap;

[BepInPlugin("com.you.fishslap", "Fish Slap", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<float> DoubleChance;

	public static ConfigEntry<float> DestroyChance;

	public static ConfigEntry<float> NoChangeChance;

	public static ConfigEntry<float> WorthMultiplier;

	public static ConfigEntry<bool> EnableText;

	public static ConfigEntry<float> TextSize;

	public static ConfigEntry<float> TextHeight;

	private void Awake()
	{
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Expected O, but got Unknown
		DoubleChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DoubleChance", 0.3f, "Chance to double value / 翻倍概率");
		DestroyChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DestroyChance", 0.2f, "Chance to destroy / 消失概率");
		NoChangeChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "NoChangeChance", 0.5f, "Chance nothing / 不变概率");
		WorthMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WorthMultiplier", 2f, "Multiplier / 翻倍倍数");
		EnableText = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableText", true, "Show floating text / 显示漂浮文字");
		TextSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TextSize", 0.15f, "Floating text size / 漂浮文字大小");
		TextHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TextHeight", 0.5f, "Height above the fish / 文字离鱼的高度");
		Harmony val = new Harmony("com.you.fishslap");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"FishSlap loaded! / FishSlap 已加载!");
	}
}
[HarmonyPatch(typeof(Melee), "HitTarget")]
internal class Patch_HitTarget
{
	private static void Postfix(Melee __instance, int side)
	{
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(Melee).GetField("_curTarget", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null || !(field.GetValue(__instance) is Transform[] array) || side < 0 || side >= array.Length)
		{
			return;
		}
		Transform val = array[side];
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Item val2 = ItemManager.Get(val);
		if ((Object)(object)val2 == (Object)null || (Object)(object)val2.Fish == (Object)null || (Object)(object)val2.Creature == (Object)null)
		{
			return;
		}
		if (!val2.Creature.IsDead)
		{
			Debug.Log((object)"[FishSlap] Alive fish ignored / 活鱼无效");
			return;
		}
		float value = Plugin.DoubleChance.Value;
		float value2 = Plugin.DestroyChance.Value;
		float value3 = Plugin.NoChangeChance.Value;
		float num = value + value2 + value3;
		if (num <= 0f)
		{
			num = 1f;
		}
		value /= num;
		value2 /= num;
		float value4 = Random.value;
		if (value4 < value2)
		{
			val2.DestroyItem((byte)0, byte.MaxValue);
			Debug.Log((object)"[FishSlap] Fish destroyed! / 鱼被打没了!");
		}
		else if (value4 < value2 + value)
		{
			FieldInfo field2 = typeof(Item).GetField("_worth", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field2 != null)
			{
				int num2 = (int)field2.GetValue(val2);
				int num3 = Mathf.RoundToInt((float)num2 * Plugin.WorthMultiplier.Value);
				field2.SetValue(val2, num3);
				Debug.Log((object)$"[FishSlap] Value doubled: {num2} -> {num3} / 鱼价翻倍");
				if (Plugin.EnableText.Value)
				{
					ShowFloatingText(((Component)val2).transform.position + Vector3.up * Plugin.TextHeight.Value, "VALUE DOUBLED!");
				}
			}
		}
		else
		{
			Debug.Log((object)"[FishSlap] Nothing happened / 什么都不发生");
		}
	}

	private static void ShowFloatingText(Vector3 pos, string text)
	{
		//IL_0022: 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)
		try
		{
			WorldText worldTextPrefab = GameInfo.WorldTextPrefab;
			if ((Object)(object)worldTextPrefab == (Object)null)
			{
				Debug.LogWarning((object)"[FishSlap] WorldTextPrefab is null");
				return;
			}
			WorldText val = Object.Instantiate<WorldText>(worldTextPrefab, pos, Quaternion.identity);
			val.SetText(text, Plugin.TextSize.Value);
			val.FloatAndRemoveAnimation();
			Debug.Log((object)("[FishSlap] Floating text shown: " + text + " / 漂浮文字已显示"));
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[FishSlap] Floating text failed: " + ex.Message));
		}
	}
}