Standalone [1.3] tModLoader - A Modding API

Oh, darn! I could've sworn I had! Retrying :p

EDIT: Now it's complaining that I don't even have the files. Is there somewhere special they should be? Currently, they're located in bin/Release, though I've tried just bin/ and there's another copy of the files in bin/Debug as well.
Root of the mods folder it looks like (I mean the folder in mod Sources)
 
Success! ExampleMod built successfully! I'm still going to test it in-game, but this is great!

I'll post a guide for other OSX/Linux users out there soon :) (the guide will be posted in this thread)

Nope. Another block. On reloading mods:
Code:
Could not load type 'ExampleMod.ExampleMod' from assembly 'ExampleMod_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0 
  at Terraria.ModLoader.AssemblyManager.InstantiateMods (System.Collections.Generic.List`1 modsToLoad) [0x00000] in <filename unknown>:0
Help please?
 
Success! ExampleMod built successfully! I'm still going to test it in-game, but this is great!

I'll post a guide for other OSX/Linux users out there soon :) (the guide will be posted in this thread)

Nope. Another block. On reloading mods:
Code:
Could not load type 'ExampleMod.ExampleMod' from assembly 'ExampleMod_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
  at Terraria.ModLoader.AssemblyManager.InstantiateMods (System.Collections.Generic.List`1 modsToLoad) [0x00000] in <filename unknown>:0
Help please?
I fixed the problem! Turns out I was supposed to use the files generated in the obj/ directory as opposed to the bin/ directory. The mod works perfectly in-game!

I'll be able to provide that OSX development guide soon!
 
Success! ExampleMod built successfully! I'm still going to test it in-game, but this is great!

I'll post a guide for other OSX/Linux users out there soon :) (the guide will be posted in this thread)

Nope. Another block. On reloading mods:
Code:
Could not load type 'ExampleMod.ExampleMod' from assembly 'ExampleMod_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
  at Terraria.ModLoader.AssemblyManager.InstantiateMods (System.Collections.Generic.List`1 modsToLoad) [0x00000] in <filename unknown>:0
Help please?
Are you saying it loads once, but on reload it breaks?

This might be a code path we didn't anticipate, looking at that error.


Edit: oh, ok
 
Send help pls...


Specified argument was out of the range of valid values.
Parameter name: Cannot assign music box to vanilla music ID 0
at Terraria.ModLoader.Mod.AddMusicBox(Int32 musicSlot, Int32 itemType, Int32 tileType, Int32 tileFrameY)
at SpiritMod.SpiritMod.Load()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)


Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod
{
    class SpiritMod : Mod
    {
        public SpiritMod()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
        public override void Load()
        {
            AddMusicBox(GetSoundSlot(SoundType.Music, "MusicBox/Megalovania"), ItemType("MysteryMusicBoxItem"), TileType("MysteryMusicBox"));
    }
            public override void UpdateMusic(ref int music)
            {
                    music = this.GetSoundSlot(SoundType.Music, "MusicBox/Megalovania");
                }
           
        }

}
 
That is a bit fast. So I'm guessing that I'll have to use pre/postAI for this. The problem for me there is that I have never tried to use those and don't know anything that you can do with those or even where to start. I understand it would be tricky, but not impossible, right?
preAI and postAI behave just like the AI hook, except they are called before & after the AI hook. You could experiment with both preAI and postAI and see what happens if you try something like projectile.velocity *= 1.5f; to speed it up. You could try using the onHitNPC hook with something like the following, though I don't know how well it would work.
Code:
if (projectile.ai[1] > 0)
     projectile.ai[0] = 0;
if (this.ai[0] == 0f)
{
     this.velocity *= -1;
}
this.netUpdate = true;
If that fails, I guess I could show you some of my boomerang code, but I've made some changes to it so it would need a bit more work to get it back how you'd want it.

Not sure whether this has been reported before but controller support seems to be causing a crash while reloading mods. Specifically, it happens when a world is loaded, exited and then mods are reloaded. To note I was using my keyboard most of the time despite having a controller plugged in and the crash happened essentially every single time conditions mentioned were met. As soon as I unplugged my controller, everything worked fine.

Code:
Indice oltre i limiti della matrice. (Index exceeds matrix dimension)
  in Terraria.GameInput.PlayerInput.GamePadInput()
  in Terraria.GameInput.PlayerInput.UpdateInput()
  in Terraria.Main.do_Update(GameTime gameTime)
  in Terraria.Main.Update(GameTime gameTime)
I have the exact same problem. tModLoader will appear to freeze and require a forced close, but I later realised I could get control back by unplugging my controller, then click the continue button like normal. I'm using a dual PS2 to USB adapter, what kind are you using?
 
A while ago I asked...

How would I make a ore spawn like the hardmode ores (Cobalt, Mythril, Adamantite etc) do?

Is it possible to change the image of the moon after the Wall of Flesh and later the Moon Lord are defeated? (Like how wearing sunglasses causes the sun image to change).

Also how would I make a item spawn in one of the dungeon gold chests?

Also how would I make modded biome chests?

For recipes how would I make the tile required be the hardmode anvils (Mythril or Orichalcum) or forges (Adamantite or Titanium) without the pre-hardmode ones being usable?

Also how would I make something require the Demon/Crimson altar to be made?

Sorry if I seem impatient, but I doubt anyone is reading that page anymore :redspin:
 
Send help pls...


Specified argument was out of the range of valid values.
Parameter name: Cannot assign music box to vanilla music ID 0
at Terraria.ModLoader.Mod.AddMusicBox(Int32 musicSlot, Int32 itemType, Int32 tileType, Int32 tileFrameY)
at SpiritMod.SpiritMod.Load()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)


Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace SpiritMod
{
    class SpiritMod : Mod
    {
        public SpiritMod()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
        public override void Load()
        {
            AddMusicBox(GetSoundSlot(SoundType.Music, "MusicBox/Megalovania"), ItemType("MysteryMusicBoxItem"), TileType("MysteryMusicBox"));
    }
            public override void UpdateMusic(ref int music)
            {
                    music = this.GetSoundSlot(SoundType.Music, "MusicBox/Megalovania");
                }
          
        }

}
I just rally want to get this fixed
 
I have the exact same problem. tModLoader will appear to freeze and require a forced close, but I later realised I could get control back by unplugging my controller, then click the continue button like normal. I'm using a dual PS2 to USB adapter, what kind are you using?
An Xbox gamepad, it should be as compatible as it can be. We can guess it's a problem with controller support in general.
 
Mod Development Guide for OSX/Linux
(or How to Build Your Mod Without Using tModLoader)
Introduction
Building a mod in a non-Windows operating system can be a bit difficult, since there is a lack of access to Visual Studio (on Linux; VS is now available for OSX, though none of the instructions below have changed) and tModLoader is unable to build the mod files itself. However, it is possible, and it's actually not all that hard. I will be using the Xamarin IDE (now replaced by VS on OSX, and MonoDevelop on Linux). Here's the steps:

1. Install Visual Studio (if on OSX) or Monodevelop (on Linux).
2. You're going to need a .csproj file. Copy the one from ExampleMod into your mod's root directory.
NOTE: All steps from 3 to 7 can be ignored if you use one of the pre-made .csproj XMLs in the attachments. Instructions on how to use them are included below.
3. Open the .csproj file in any text editor. You're gonna need to change a couple things. Specifically:
3a. Find the AssemblyName tag and change the value from "ExampleMod" to whatever your mod's name is (this is the name of the root folder).
3b. Go down to the end of the file and delete the line within the last PropertyGroup (the one that says "PostBuild" or whatever).
4. For convenience, rename this .csproj "Windows". Duplicate it and make another called "Mono".
5. Open the Windows.csproj in Xamarin, and expand the References "folder". Several Microsoft.Xna.* references and a Terraria reference should be missing.
6. Remove these references. Right-click on References and click Edit References. Go over to the .NET Assembly tab and click Browse. Now select all the .dll files and the .exe that came in the ModCompile folder of your non-Windows tModLoader download. Make sure the boxes of these new references are checked in the Edit References window, and click OK.
6b. If you aren't building ExampleMod, you'll probably notice many ExampleMod files that don't exist in your project. Go ahead and remove them at this time.
7. Do the same thing in the Mono .csproj file. However, this time, you're targeting different files: FNA.dll and a non-Windows tModLoader Terraria.exe. You can get these from either a non-Windows tModLoader Terraria installation or from the ModCompile folder in a Windows tModLoader download (the Terraria reference is tModLoaderMac.exe).
8. Build both .csproj files (click the 'Play' looking button on the top-left of the Xamarin window). I don't know if there's much of a difference between making a Debug and a Release build - for convenience, I just have Windows build as one type and Mono build as another.
9. If you've set everything up correctly, your mod builds should have succeeded. Go into the obj/release folder and the obj/debug folder. Take the ModName.dll files from each and rename them according to what built them (if you had Windows build to Debug, then rename the obj/debug file Windows.dll). Place these .dlls in the mod's root directory.
10. Open build.txt and add the line "noCompile = true" to the end of it.
11. Open Terraria and have tModLoader build your mod!
I hope this helps!

How to use the included .csproj files:
These files are pre-made .csproj files that have gone through the steps above and then some. TCF doesn't allow uploading files with the .csproj extension, so the .txt extension must be removed before use.
They should already have working sources, provided the .csproj is inside a folder in the Mod Sources directory. Sources are also set up to switch to the correct one depending on how you're building the project, so there's no need to have two separate projects for Mono and Windows builds.
The missing ReLogic dependencies ReLogic.dll and ReLogicLinux.dll can be downloaded from the tModLoader GitHub (found in the "references" folder) and placed into the ModCompile folder in your Terraria installation.

Additionally, they're already set up to automatically copy the built .dll files to the proper place when building, so you'll never have to manually move them yourself.
Build with both Mono and Windows settings to build both Mono.dll and Windows.dll!

_Blank files: These .csproj files don't contain any references to ExampleMod files and are perfect for starting a mod from scratch. They still contain build.txt and description.txt, which every mod should have anyway.
OSX/Linux files: Each version gets the sources from a slightly different location for the indicated operating system. Get the one that matches yours!

Don't forget that these files are still named ExampleMod both outside and inside, so be sure to change the assembly and root namespace name as you see fit!

A few notes:
-The mod's root folder must be located in Terraria/ModLoader/Mod Sources. You can access this folder from the Mod Sources option on the tModLoader main menu.
-If your mod is not referencing Microsoft.Xna.* in any way, then you don't need to do the double build: instead, just build one file and name it All.dll.
-tModLoader cannot build your mod if the AssemblyName does not match the name of the root folder.
-It's best to practice these steps by applying them to ExampleMod first, so that you know how it works. If you have issues building ExampleMod, check the steps again. If you're still having issues, contact me via Discord and I can put you in the right direction ;)
-Changing the RootNamespace option in your .csproj will change the default namespace that new .cs files are put into by the skeleton code.

-If you want your mod to be editable by non-Windows users, you can remove the exclusion of the .csproj file in build.txt. Others will then be able to open the .csproj after unpacking it with tModReader.

This is guide version 1.2. Changelog:
- 1.0: Initial release.
- 1.1: A bit more information, typo fixes.
- 1.2: More information, added template .csproj files
 

Attachments

  • ExampleMod_OSX_Blank.csproj.txt
    4.5 KB · Views: 1,169
  • ExampleMod_Linux_Blank.csproj.txt
    4.3 KB · Views: 633
  • ExampleMod_Linux.csproj.txt
    14.9 KB · Views: 752
  • ExampleMod_OSX.csproj.txt
    15.1 KB · Views: 907
Last edited:
I want to add bumping sound when my projectile collides with tile using OnTileCollide hook, but PlaySound method uses sounds of totally not items, like when 10 is harpoon's bumping sound, it is actually sound of opening the menu.
 
help trying to update my mods but the mod browser says 'Tha Mod rowser server is under heavy load. Try again later'.
what do i do if i only have 15 minutes to play?
 
Code:
if (projectile.ai[1] > 0)
projectile.ai[0] = 0;
if (this.ai[0] == 0f)
{
this.velocity *= -1;
}
this.netUpdate = true;
Error:
file stuff (32,22) : error CS 1061 : file stuff does not contain a definition for 'ai' and no extension method 'ai' accepting a first argument of type file stuff could be found
help please
 
How would I make a ore spawn like the hardmode ores (Cobalt, Mythril, Adamantite etc) do?



Also how would I make a item spawn in one of the dungeon gold chests?

Also how would I make modded biome chests?

For recipes how would I make the tile required be the hardmode anvils (Mythril or Orichalcum) or forges (Adamantite or Titanium) without the pre-hardmode ones being usable?

Also how would I make something require the Demon/Crimson altar to be made?
For the last 2, just add the correct tile.

The ExampleMod has an example of ice chest items.

The other ones need to be more specific, so I know which part is the part you need help with
[doublepost=1465662220,1465662165][/doublepost]
Error:
file stuff (32,22) : error CS 1061 : file stuff does not contain a definition for 'ai' and no extension method 'ai' accepting a first argument of type file stuff could be found
help please
"this" needs to be "projectile"
[doublepost=1465662293][/doublepost]
help trying to update my mods but the mod browser says 'Tha Mod rowser server is under heavy load. Try again later'.
what do i do if i only have 15 minutes to play?
There's been an unusual amount of traffic these last few days, so the daily bandwidth gets eaten up really quickly. I'm looking into it.
[doublepost=1465662337][/doublepost]
I want to add bumping sound when my projectile collides with tile using OnTileCollide hook, but PlaySound method uses sounds of totally not items, like when 10 is harpoon's bumping sound, it is actually sound of opening the menu.
Show me what you got and tell me where you got the numbers that you expected to work.
 
i dont know if this is exactly the right place to report problems, but i have a problem when i try to download any mod with mod browser
Code:
The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Terraria.ModLoader.UI.UIErrorMessage.OpenFile(UIMouseEvent evt, UIElement listeningElement)
   at Terraria.UI.UIElement.Click(UIMouseEvent evt)
   at Terraria.UI.UserInterface.Update(GameTime time)
   at Terraria.Main.do_Update(GameTime gameTime)
   at Terraria.Main.Update(GameTime gameTime)
 
How do I make stream/ray projectile like Water Scepter's one?
You can copy the item properties from the spreadsheet. As far as the projectile is concerned, most of the visual is just dust that looks flowy. I think the actual projectile is transparent.
[doublepost=1465662584,1465662492][/doublepost]
i dont know if this is exactly the right place to report problems, but i have a problem when i try to download any mod with mod browser
Code:
The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Terraria.ModLoader.UI.UIErrorMessage.OpenFile(UIMouseEvent evt, UIElement listeningElement)
   at Terraria.UI.UIElement.Click(UIMouseEvent evt)
   at Terraria.UI.UserInterface.Update(GameTime time)
   at Terraria.Main.do_Update(GameTime gameTime)
   at Terraria.Main.Update(GameTime gameTime)
That looks like the mod browser is telling you there is an error, but that directory is somehow not accessable by the program.
 
i dont know if this is exactly the right place to report problems, but i have a problem when i try to download any mod with mod browser
Code:
The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Terraria.ModLoader.UI.UIErrorMessage.OpenFile(UIMouseEvent evt, UIElement listeningElement)
   at Terraria.UI.UIElement.Click(UIMouseEvent evt)
   at Terraria.UI.UserInterface.Update(GameTime time)
   at Terraria.Main.do_Update(GameTime gameTime)
   at Terraria.Main.Update(GameTime gameTime)
I've tried to run as administrator, and make the Terraria folder in Documents/My Games/ non read only (like, untick the read only thing), but still nothing.
 
Back
Top Bottom