Skip to content

Latest commit

 

History

History
185 lines (143 loc) · 7 KB

File metadata and controls

185 lines (143 loc) · 7 KB

Terraria AUTO-FISH Tutorial

中文版 (Chinese Version)

Tested and working on Terraria 1.4.5.3

avatar

Tool: dnSpy

Please download and use the 32-bit version.

Auto-Fishing Implementation

  1. Open the Terraria main executable with dnSpy and decompile it.
  2. In the left panel, locate Terraria - Terraria.exe - Terraria.
  3. Right-click TerrariaAdd Class, as shown in the red box in the image.

avatar

  1. In the popup window, paste the following code and click Compile.

avatar

using System;
using Microsoft.Xna.Framework;

namespace Terraria
{
    public class AutoFisher
    {
        // Pull countdown: decrements each frame when >0, triggers reel at 0
        public static int PullTimer;
        // Cast cooldown: wait a few frames after reeling before casting again
        public static int AutocastDelay;
        // Whether first reel is done (auto-cast only starts after first reel)
        public static bool FirstReelDone;
        // Flag: true = this reel was triggered by FishingCheck (fish bit), false = otherwise (reset when casting)
        public static bool ReelFromFishingCheck;
        // Had bobber last frame (used to detect manual reel)
        private static bool HadBobberLastFrame;
        // Optional: lock cast position
        public static float TargetX;
        public static float TargetY;

        public static void Update()
        {
            if (Main.myPlayer < 0 || Main.myPlayer >= Main.player.Length)
                return;

            Player player = Main.player[Main.myPlayer];
            if (!player.active || player.dead)
                return;

            bool hasBobber = CheckBobbersActive(Main.myPlayer);

            // 0. When not fishing (switched away from rod), turn off auto-cast immediately
            if (player.HeldItem.fishingPole == 0)
            {
                FirstReelDone = false;
                PullTimer = 0;
                ReelFromFishingCheck = false;
                HadBobberLastFrame = hasBobber;
                return;
            }

            // 0.5. Manual reel: had bobber last frame, none now, and not from FishingCheck -> turn off auto-cast
            if (HadBobberLastFrame && !hasBobber && !ReelFromFishingCheck)
                FirstReelDone = false;

            // 1. Auto reel: PullTimer countdown (set by FishingCheck, ReelFromFishingCheck is already true)
            if (PullTimer > 0)
            {
                PullTimer--;
                if (PullTimer == 0)
                {
                    player.controlUseItem = true;
                    player.releaseUseItem = true;
                    player.ItemCheck();
                    FirstReelDone = true;
                    AutocastDelay = 15;
                }
            }

            // 2. Auto cast: after reel, when no bobber and holding rod, cast automatically
            if (FirstReelDone && player.HeldItem.fishingPole > 0)
            {
                if (AutocastDelay > 0)
                    AutocastDelay--;
                else if (!hasBobber)
                {
                    ReelFromFishingCheck = false;  // Reset when casting, stays false until next reel
                    if (TargetX != 0f || TargetY != 0f)
                    {
                        Main.mouseX = (int)(TargetX - Main.screenPosition.X);
                        Main.mouseY = (int)(TargetY - Main.screenPosition.Y);
                    }
                    player.controlUseItem = true;
                    player.releaseUseItem = true;
                    player.ItemCheck();
                    AutocastDelay = 10;
                }
            }

            HadBobberLastFrame = CheckBobbersActive(Main.myPlayer);  // End-of-frame state (may have reeled this frame)
        }

        private static bool CheckBobbersActive(int whoAmI)
        {
            for (int i = 0; i < Main.projectile.Length; i++)
            {
                Projectile p = Main.projectile[i];
                if (p.active && p.owner == whoAmI && p.bobber)
                    return true;
            }
            return false;
        }
    }
}
  1. In dnSpy: File → Save Module → choose path → OK to save the new class into the exe.

avatar

  1. In the left panel, find Terraria - Terraria.exe - Terraria - Projectile - FishingCheck, right-click → Edit Method (C#).

avatar

  1. Insert the following code at the position shown in the image below, then click Compile.

avatar

if (owner == Main.myPlayer && Main.player[owner].active && !Main.player[owner].dead)
{
    AutoFisher.PullTimer = (int)(0.5f * 60 + 1);  // Reel after 0.5 second delay
    AutoFisher.ReelFromFishingCheck = true;       // Flag: this reel was triggered by FishingCheck
    AutoFisher.TargetX = Center.X;  // Remember cast position for auto-cast
    AutoFisher.TargetY = Center.Y;
}
  1. In the left panel, find Terraria - Terraria.exe - Terraria - Main - DoUpdate, right-click DoUpdateEdit Method (C#).

  2. Insert the following code above the position shown in the image, then click Compile.

avatar

Terraria.AutoFisher.Update();
  1. In dnSpy: File → Save Module → choose path → OK to save the changes into the exe.

Offline Play (No Steam)

  1. By commenting out the code that initializes Steam, you can play without logging in.
  2. In the left panel, find Terraria - Terraria.exe - Terraria.Social - SocialAPI - LoadSteam (displayed in orange), right-click LoadSteamEdit Method (C#). In the code area on the right, delete the red-boxed section as shown in the images.

avatar

avatar

  1. Save locations

    • Steam version: C:\Program Files (x86)\Steam\userdata\[your steam id]\105600\remote (path may vary with Steam install location and your Steam ID).
    • Offline version: %userprofile%\Documents\My Games\Terraria.
  2. Other useful locations

Terraria - Terraria.exe - Terraria - Item - SetDefaults  // Initialize item properties; change weapon damage/efficiency here
Terraria - Terraria.exe - Terraria.GameContent.ItemDropRules - ItemDropDatabase  // Drop items and probability (probability = 1/value, e.g. 20 → 1/20)
Terraria - Terraria.exe - Terraria - Item - buyPrice   // Buy price
Terraria - Terraria.exe - Terraria - Item - sellPrice   // Sell price
Terraria - Terraria.exe - Terraria - Player - Hurt     // Damage taken; returning a value can make you invincible (burn etc. not fully immune)
Terraria - Terraria.exe - Terraria - Player - GetWeaponDamage  // All weapon damage calculations

Compilation Errors

  • If you get "the type or namespace name 'ReLogic'" when compiling, go to Terraria - Terraria.exe - Resources, check for a matching dll, right-click and save the dll locally, then in dnSpy use File → Open to open that dll so compilation works.