Terraria – Steamless Loading

Disclaimer: Usage of a method to load the game list this allows you to run without Steam. This means the game can be copied onto other machines without purchasing it. I do not condone in piracy. I simply made this because I was sick of Steam for a while. I take no responsibility in what you do with this information.

Since Terraria is a managed application, we can easily import it into a project and reference the main class. With this we can initiate an instance of the main class and effectively load the game through our own app. With this we can skip the entire launching method that is called by the application when it’s asked to start (Main(..)).

So in turn we land up with:

using System;
using System.IO;
using System.Reflection;
using Microsoft.Xna.Framework;

namespace tLock
{
#if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Set Terraria's Path..
            String strRealPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\Steam\steamapps\common\terraria"; //"C:\Program Files (x86)\Steam\steamapps\common\terraria";
            Directory.SetCurrentDirectory(strRealPath);

            // Run our game..
            var tLock = Assembly.GetExecutingAssembly().GetType("tLock.Hook", true, true);
            (Activator.CreateInstance(tLock) as Game).Run();
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            using (FileStream fStream = new FileStream("errorlog.txt", FileMode.CreateNew, FileAccess.ReadWrite))
            {
                using (StreamWriter sWriter = new StreamWriter(fStream))
                {
                    sWriter.Write(((Exception)e.ExceptionObject).Message);
                }
            }
        }
    }
#endif
}

Then we need to add our hook class which tells the game were to locate the content. This also allows you alter the game while it plays to do a ton of other stuff. (Not covered in this post though.)

Hook.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Terraria;

namespace tLock
{
    public class Hook : Terraria.Main
    {
        protected override void Initialize()
        {
            // Reset the content directory..
            Content.RootDirectory = Environment.CurrentDirectory + "\Content\";

            // Base initialization..
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}

Once compiled, drop in the same directory as Terraria.exe and use your app to launch the game. Tada~ no more Steam

Leave a comment