Standalone [1.3] tModLoader - A Modding API

Oh, yeah, by the way, another question. How do I get drills to work? When I use them currently, the sprite just flips out re-appearing over and over again, and making the drill sounds rapidly. Am I doing something wrong there, or is it a bug too?
I'm not really sure what's happening there. It looks like drills should work properly.
 
I might be interested in writing a Linux (and possibly Mac) port of tModLoader. It uses Mono, so the .exe is very similar. I'll try recompiling when i get access to my windows laptop. As long as you don't hook too much into Terraria.WindowsLaunch, it should work!

I don't have that much experience with C#, but I know JS, Java, VB and I have been doing some C coding recently.
Looking at the code, it has to be compiled on windows using the .exe from Linux Terraria. I don't have a Mac, so I don't know if the Mac version has a different .exe to Linux, but if it is different, a Mac will be needed to get the .exe for each update. Linux is free, so you can just set up an Ubuntu install with Steam.

By the way, the modloader is awesome. Now that it's come out for 1.3.0.8, I might test it on my windows laptop.

EDIT: Now installing VS. Confirmed there is no Terraria.MacLaunch in the Linux .exe, a mac .exe may be needed to make tModLoader.
 
Last edited:
Ive got my armor working in the game at the moment.. but it wont let me craft it at an anvil with iron bars?


here is a sample of the code


using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items.Armor {
public class ExampleBreastplate : ModItem
{
public override bool Autoload(ref string name, ref string texture, ref EquipType? equip)
{
equip = EquipType.Body;
return true;
}

public override void SetDefaults()
{
item.name = "Abyss Armor";
item.width = 18;
item.height = 18;
item.toolTip = "Crocs personal armor, originates from a dark land.";
item.value = 10000;
item.rare = 10;
item.defense = 60;
}

public override void UpdateEquip(Player player)
{

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "IronBar", 45);
recipe.AddTile(null, "Anvil");
recipe.SetResult(this);
recipe.AddRecipe();
}
}}




I removed stuff from the example that i didnt want
 
Last edited:
Just tried to decompile linux Terraria. It says it can't find FNA, but FNA.dll is in the same directory as Terraria.exe.

Code:
Decompiling: Terraria\Animation.cs
Decompiling: Terraria.UI\ItemSlot.cs
System.AggregateException: One or more errors occurred. ---> ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Void Terraria.UI.ItemSlot::OverrideHover(Terraria.Item[],System.Int32,System.Int32)
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'FNA, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Terraria.ModLoader.Setup.DecompileTask.EmbeddedAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 44
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.MetadataResolver.Resolve(MethodReference method)
   at Mono.Cecil.MethodReference.Resolve()
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILExpression expr, ILExpression parentExpr, Int32 posInParent)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.Optimize(DecompilerContext context, ILBlock method, ILAstOptimizationStep abortBeforeStep)
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters)
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable`1 parameters)
   --- End of inner exception stack trace ---
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable`1 parameters)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition methodDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddTypeMembers(TypeDeclaration astType, TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateType(TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddType(TypeDefinition typeDef)
   at Terraria.ModLoader.Setup.DecompileTask.DecompileSourceFile(IGrouping`2 src, DecompilationOptions options) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 259
   at Terraria.ModLoader.Setup.DecompileTask.<>c__DisplayClass1d.<>c__DisplayClass1f.<Run>b__13() in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 155
   at Terraria.ModLoader.Setup.Task.<>c__DisplayClassb.<ExecuteParallel>b__8(WorkItem item) in d:\Games\Terraria\tModLoader\setup\Setup\Task.cs:line 40
   at System.Threading.Tasks.Parallel.<>c__DisplayClass9`1.<ForWorker>b__11()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass0.<ExecuteSelfReplicating>b__1(Object )
   --- End of inner exception stack trace ---
   at Terraria.ModLoader.Setup.Task.ExecuteParallel(List`1 items, Boolean resetProgress, Int32 maxDegree) in d:\Games\Terraria\tModLoader\setup\Setup\Task.cs:line 52
   at Terraria.ModLoader.Setup.DecompileTask.Run() in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 175
   at Terraria.ModLoader.Setup.SetupTask.Run() in d:\Games\Terraria\tModLoader\setup\Setup\SetupTask.cs:line 43
   at Terraria.ModLoader.Setup.MainForm.RunTaskThread(Task task) in d:\Games\Terraria\tModLoader\setup\Setup\MainForm.cs:line 107
---> (Inner Exception #0) ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Void Terraria.UI.ItemSlot::OverrideHover(Terraria.Item[],System.Int32,System.Int32)
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'FNA, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Terraria.ModLoader.Setup.DecompileTask.EmbeddedAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 44
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.MetadataResolver.Resolve(MethodReference method)
   at Mono.Cecil.MethodReference.Resolve()
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILExpression expr, ILExpression parentExpr, Int32 posInParent)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.IntroducePropertyAccessInstructions(ILNode node)
   at ICSharpCode.Decompiler.ILAst.ILAstOptimizer.Optimize(DecompilerContext context, ILBlock method, ILAstOptimizationStep abortBeforeStep)
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters)
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable`1 parameters)
   --- End of inner exception stack trace ---
   at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable`1 parameters)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition methodDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddTypeMembers(TypeDeclaration astType, TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateType(TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddType(TypeDefinition typeDef)
   at Terraria.ModLoader.Setup.DecompileTask.DecompileSourceFile(IGrouping`2 src, DecompilationOptions options) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 259
   at Terraria.ModLoader.Setup.DecompileTask.<>c__DisplayClass1d.<>c__DisplayClass1f.<Run>b__13() in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 155
   at Terraria.ModLoader.Setup.Task.<>c__DisplayClassb.<ExecuteParallel>b__8(WorkItem item) in d:\Games\Terraria\tModLoader\setup\Setup\Task.cs:line 40
   at System.Threading.Tasks.Parallel.<>c__DisplayClass9`1.<ForWorker>b__11()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass0.<ExecuteSelfReplicating>b__1(Object )<---

---> (Inner Exception #1) Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'FNA, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Terraria.ModLoader.Setup.DecompileTask.EmbeddedAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 44
   at ICSharpCode.Decompiler.Ast.Transforms.IntroduceUsingDeclarations.Run(AstNode compilationUnit)
   at ICSharpCode.Decompiler.Ast.Transforms.TransformationPipeline.RunTransformationsUntil(AstNode node, Predicate`1 abortCondition, DecompilerContext context)
   at ICSharpCode.Decompiler.Ast.AstBuilder.GenerateCode(ITextOutput output)
   at Terraria.ModLoader.Setup.DecompileTask.DecompileSourceFile(IGrouping`2 src, DecompilationOptions options) in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 261
   at Terraria.ModLoader.Setup.DecompileTask.<>c__DisplayClass1d.<>c__DisplayClass1f.<Run>b__13() in d:\Games\Terraria\tModLoader\setup\Setup\DecompileTask.cs:line 155
   at Terraria.ModLoader.Setup.Task.<>c__DisplayClassb.<ExecuteParallel>b__8(WorkItem item) in d:\Games\Terraria\tModLoader\setup\Setup\Task.cs:line 40
   at System.Threading.Tasks.Parallel.<>c__DisplayClass9`1.<ForWorker>b__11()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass0.<ExecuteSelfReplicating>b__1(Object )<---

When VS installs, I'll see how I can modify the setup to include FNA.dll
 
Last edited:
Yay! I did it! I don't know if it will actually patch terraria, but it's decompiling alright!

Here are the few modifications I did to Resolve() in DecompileTask.cs
Code:
                    if (baseModule != null) {
                        var resName = name.Name + ".dll";
                        var res =
                            baseModule.Resources.OfType<EmbeddedResource>()
                                .SingleOrDefault(r => r.Name.EndsWith(resName));
                        if (res != null)
                            assemblyDefinition = AssemblyDefinition.ReadAssembly(res.GetResourceStream(), parameters);
                    }

                    if (assemblyDefinition == null)
                    {
                        var assemblyPath = Path.Combine(SteamDir.Get(), name.Name + ".dll");
                        if (File.Exists(assemblyPath) == false)
                        {
                            assemblyDefinition = base.Resolve(name, parameters);
                        }
                        else
                        {
                            var res = File.OpenRead(assemblyPath);
                            assemblyDefinition = AssemblyDefinition.ReadAssembly(res, parameters);
                        }
                    }

                skip:
                    cache[name.FullName] = assemblyDefinition;
                    return assemblyDefinition;
                }


EDIT: Aah! I see what you mean about ram usage. Anyway, it should be decompiling. It doesn't seem to care that the rest of my (6gb ram is not enough for windows) programs can't respond as there is no ram left.
 
Last edited:
Ive got my armor working in the game at the moment.. but it wont let me craft it at an anvil with iron bars?


here is a sample of the code


using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items.Armor {
public class ExampleBreastplate : ModItem
{
public override bool Autoload(ref string name, ref string texture, ref EquipType? equip)
{
equip = EquipType.Body;
return true;
}

public override void SetDefaults()
{
item.name = "Abyss Armor";
item.width = 18;
item.height = 18;
item.toolTip = "Crocs personal armor, originates from a dark land.";
item.value = 10000;
item.rare = 10;
item.defense = 60;
}

public override void UpdateEquip(Player player)
{

}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "IronBar", 45);
recipe.AddTile(null, "Anvil");
recipe.SetResult(this);
recipe.AddRecipe();
}
}}




I removed stuff from the example that i didnt want

Are you trying to craft it using VANILLA iron bars and at a vanilla anvil? Because right now you're passing MODitems, and not vanilla ones.
If you want to use vanilla, then replace it with this:
Code:
        recipe.AddIngredient(ItemID.IronBar, 45);
        recipe.AddTile(TileID.Anvils);
 
Soooo I made a drop for a mod mob using GlobalNPC! (I think it isn't supported yet)
Maybe someone already did it.
Code:
    if(npc.type == mod.NPCType("BossName")  && Main.rand.Next(1) == 0)

    {
        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
    }
 
Soooo I made a drop for a mod mob using GlobalNPC! (I think it isn't supported yet)
Maybe someone already did it.
Code:
    if(npc.type == mod.NPCType("BossName")  && Main.rand.Next(1) == 0)

    {
        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"));
    }

Why would you use GlobalNPC for a custom mob? You can just do that in it's own file? GlobalNPC is for vanilla things.
 
Why would you use GlobalNPC for a custom mob? You can just do that in it's own file? GlobalNPC is for vanilla things.
Oh, so I can use this code in mob code, right?
At first I wanted just to test will this code work for custom monster so I used GlobalNPC.

Edit: How to change amount of drop? For example I need from 25 to 48 items.
 
Are you trying to craft it using VANILLA iron bars and at a vanilla anvil? Because right now you're passing MODitems, and not vanilla ones.
If you want to use vanilla, then replace it with this:
Code:
        recipe.AddIngredient(ItemID.IronBar, 45);
        recipe.AddTile(TileID.Anvils);
<3 thankyou
 
Oh, so I can use this code in mob code, right?
At first I wanted just to test will this code work for custom monster so I used GlobalNPC.

Edit: How to change amount of drop? For example I need from 25 to 48 items.
You can just add the amount after the type of item that is dropped.
You could use Main.rand.Next(25,49) to get a random amount between 25 and 48

I thought there isn't a ModNPC class, yet. As well as ModProjecile. :eek:
What's the point of adding a drop to an NPC that isn't possible to create yet then? By the way ModProjectile and ModNPC is part of v0.4 so you can use it, just only Autoload and SetDefaults functions. I was just trying to point out that adding it to GlobalNPC would be bad practice, but for now if that works it could be a workaround.
 
It seems to always get stuck on Terraria/Projectile.cs and Terraria/NPC.cs
I'll leave it running for now, but I will have to shut down the laptop if it isn't finished by tonight.
 
So after reading a few bits of this thread regarding the missing texture i'm really at the point of no hope. I hope someone can check my codes for the weapon i am trying to make and can tell me what is wrong (don't mind the crafting recipe for now)

souce code of the cs file in the folder ModSources/MyMod

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using HardmodeArkhalis.Items

namespace Eclipse {
public class Eclipse : Mod
{
public override void SetModInfo(out string name, ref ModProperties properties)
{
name = "Eclipse";
properties.Autoload = true;
}

public override void Load()
{

}
}

public override void Load()
{
AddItem("Eclipse", new Eclipse(), "HardmodeArkhalis/Items/Eclipse");
____________________________________________________________________

And my code in the cs file inside the Items folder

using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Eclipse.Items
{
public class Eclipse : ModItem
{
public override void SetDefaults()
{
item.name = "Eclipse";
item.toolTip = "A sword imbued with enormous Power";
item.knockBack = 3;
item.damage = 68;
item.melee = true;
item.useTime = 16;
item.useStyle = 5;
item.width = 34;
item.height = 38;
item.value = 100;
item.rare = 7;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}


When i try to build the mod i get the following error:

c:\Users\Izzy\Documents\My Games\Terraria\ModLoader\Mod Sources\Hardmode Arkhalis\Eclipse.cs(25,69) : error CS1513: } expected
 
When i try to build the mod i get the following error:

c:\Users\Izzy\Documents\My Games\Terraria\ModLoader\Mod Sources\Hardmode Arkhalis\Eclipse.cs(25,69) : error CS1513: } expected
The error explains itself. You need to put a } where it is missing one. Also, why do you override Load twice when only the second one has content?
 
Okay i fixed that one but i've encountered afew others and the last one i don't understand is this one :

c:\Users\Izzy\Documents\My Games\Terraria\ModLoader\Mod Sources\Hardmode Arkhalis\Eclipse.cs(23,29) : error CS0116: A namespace cannot directly contain members such as fields or methods
 
Okay i fixed that one but i've encountered afew others and the last one i don't understand is this one :

c:\Users\Izzy\Documents\My Games\Terraria\ModLoader\Mod Sources\Hardmode Arkhalis\Eclipse.cs(23,29) : error CS0116: A namespace cannot directly contain members such as fields or methods
Yeah, I don't know. I always get stuck at those errors too.
 
Back
Top Bottom