Standalone [1.3] tModLoader - A Modding API

help, I don't know what I did,
[1/FATAL] [Terraria]: Main engine crash
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: m. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Terraria.IO.FavoritesFile.Load()
at Terraria.Main.Initialize()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Terraria.Program.LaunchGame_()
 
I play the 1.4 version of terraria I still didn't understand how to make our own mod. I jus want to edit some stats of weapons, buffs, maybe more accessory slots that's all.
 
Hello folks,

Is there any way to resize the UI?
01.png


I am running the game at 4k resolution.
 

Attachments

  • 02.png
    02.png
    334.6 KB · Views: 99
1639610846251.png

Alright, so:

I'm trying to get into modding, and without even modifying the newly-created mod file, this error message pops up when I try to reload+build. None of the tutorials I've watched have accounted for this issue, and I've looked online with many keywords to try and find a solve, but still can't find anything.

I've checked tModLoader's files and my mod's files for something named "Object", tried renaming the "obj" file in my mod file to "Object", and none of it has worked. I'm stumped.

Very sorry if this is a frequently asked question, I'm just confused as to what to do to solve this.
 
View attachment 351234
Alright, so:

I'm trying to get into modding, and without even modifying the newly-created mod file, this error message pops up when I try to reload+build. None of the tutorials I've watched have accounted for this issue, and I've looked online with many keywords to try and find a solve, but still can't find anything.

I've checked tModLoader's files and my mod's files for something named "Object", tried renaming the "obj" file in my mod file to "Object", and none of it has worked. I'm stumped.

Very sorry if this is a frequently asked question, I'm just confused as to what to do to solve this.
I don't know... really anything about C#, but judging by the error message, it looks like you need to reference a file. I have no idea how to do that, though, so my advice would be ask the Discord for help. Just tell them what you posted here in the modding-help channel, and you might be able to get someone who knows what they're doing pretty quickly.
 
View attachment 351234
Alright, so:

I'm trying to get into modding, and without even modifying the newly-created mod file, this error message pops up when I try to reload+build. None of the tutorials I've watched have accounted for this issue, and I've looked online with many keywords to try and find a solve, but still can't find anything.

I've checked tModLoader's files and my mod's files for something named "Object", tried renaming the "obj" file in my mod file to "Object", and none of it has worked. I'm stumped.

Very sorry if this is a frequently asked question, I'm just confused as to what to do to solve this.
Are you using Visual Studio 2022? If so, try uninstalling that, deleting its installer, and getting the 2019 version here. I had the same problem when I started a few days ago and doing this fixed it.
 
So, how much time left until we get tModLoader updated to 1.4?? The Journey's End update came almost 2 years ago and we still have nothing from tModLoader. And, no, tModLoader in alpha version is not valid here because it is laggy. I'm getting tired of waiting.-_-:rolleyes:
 
So, how much time left until we get tModLoader updated to 1.4?? The Journey's End update came almost 2 years ago and we still have nothing from tModLoader. And, no, tModLoader in alpha version is not valid here because it is laggy. I'm getting tired of waiting.-_-:rolleyes:
I can kinda understand, dude, I really want TModLoader to bw updated to 1.4 and its updates, cause as much as I love vanilla, I like using mods to add stuff or improve quality of life, like the Better Taxes mod, Nooby's OverPowered Mod cause it has a really powerful terrain destroying rocket launcher, or even Spirit, Tremor, and Calamity, but I'm hoping it wont be too much longer now.
 
Hello everybody,
I've just got into modding Terraria, and I'm coming across something I have no idea how to do. It's a bit ambitious, but any help would be appreciated. I'm trying to create a custom resource, similar to mana. Also, by "consuming" this custom resource, your character will gain buffs with animated visual effects, such as lightning around your feet for a speed boost, an increase in character size for a health boost, a glowing red outline for a damage boost, etc. Does anybody know how I would go about doing this? I am a bit new to coding, so I may be in over my head here, but any help would be greatly appreciated!
 
Last edited:
Hello everybody,
I've just got into modding Terraria, and I'm coming across something I have no idea how to do. It's a bit ambitious, but any help would be appreciated. I'm trying to create a custom resource, similar to mana. Also, by "consuming" this custom resource, your character will gain buffs with animated visual effects, such as lightning around your feet for a speed boost, an increase in character size for a health boost, a glowing red outline for a damage boost, etc. Does anybody know how I would go about doing this? I am a bit new to coding, so I may be in over my head here, but any help would be greatly appreciated!
It is most definitely not the easiest thing for someone completely new to coding. The most basic tmodloader functions revolve around making basic items or npcs. What you are trying to make involves running a global player script that holds a variable for your resource which is then referenced in every script that uses said resource. Depending on how you want these buffs to activate you might need to catch player inputs in update methods and whatnot. It isn't the most complicated thing in the world but it requires a bit of knowledge of how object oriented programing works and it depends on how versed you are on the fundamentals of coding.
 
It is most definitely not the easiest thing for someone completely new to coding. The most basic tmodloader functions revolve around making basic items or npcs. What you are trying to make involves running a global player script that holds a variable for your resource which is then referenced in every script that uses said resource. Depending on how you want these buffs to activate you might need to catch player inputs in update methods and whatnot. It isn't the most complicated thing in the world but it requires a bit of knowledge of how object oriented programing works and it depends on how versed you are on the fundamentals of coding.
I only have a few months of coding experience, but I would really like to give it a try... do you have any idea how I would go about starting to code this? And if not, do you know how I could incorporate animated sprites to my buffs, as mentioned above? Thank you!

Edit: Turns out, I was able to code the resource first try! Well, almost... I'm having a small issue where the resource is regenerating and is able to be used, but the "bar" that is supposed to show how much of the resource the player has isn't showing up for some reason... any ideas? Here's all my code:

using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;

namespace Test
{
public abstract class EssenceItem : ModItem
{
public override bool CloneNewInstances => true;
public int essenceCost = 0;

public virtual void SafeSetDefaults()
{
}

public sealed override void SetDefaults()
{
SafeSetDefaults();
item.melee = false;
item.ranged = false;
item.magic = false;
item.thrown = false;
item.summon = false;
}

public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat)
{
add += EssencePlayer.ModPlayer(player).essenceDamageAdd;
mult *= EssencePlayer.ModPlayer(player).essenceDamageMult;
}

public override void GetWeaponKnockback(Player player, ref float knockback)
{
knockback += EssencePlayer.ModPlayer(player).essenceKnockback;
}

public override void GetWeaponCrit(Player player, ref int crit)
{
crit += EssencePlayer.ModPlayer(player).essenceCrit;
}

public override void ModifyTooltips(List<TooltipLine> tooltips)
{
TooltipLine tt = tooltips.FirstOrDefault(x => x.Name == "Damage" && x.mod == "Terraria");
if (tt != null)
{
string[] splitText = tt.text.Split(' ');
string damageValue = splitText.First();
string damageWord = splitText.Last();
tt.text = damageValue + " essence " + damageWord;
}

if (essenceCost > 0)
{
tooltips.Add(new TooltipLine(mod, "Essence Cost", $"Uses {essenceCost} essence"));
}
}

public override bool CanUseItem(Player player)
{
var exampleDamagePlayer = player.GetModPlayer<EssencePlayer>();

if (exampleDamagePlayer.essenceCurrent >= essenceCost)
{
exampleDamagePlayer.essenceCurrent -= essenceCost;
return true;
}
return false;
}
}
}


using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace Test
{
public class EssencePlayer : ModPlayer
{
public static EssencePlayer ModPlayer(Player player)
{
return player.GetModPlayer<EssencePlayer>();
}

public float essenceDamageAdd;
public float essenceDamageMult = 1f;
public float essenceKnockback;
public int essenceCrit;

public int essenceCurrent;
public const int DefaultEssenceMax = 100;
public int essenceMax;
public int essenceMax2;
public float essenceRegenRate;
internal int essenceRegenTimer = 0;
public static readonly Color HealEssence = new Color(187, 91, 201);

public override void Initialize()
{
essenceMax = DefaultEssenceMax;
}

public override void ResetEffects()
{
ResetVariables();
}

public override void UpdateDead()
{
ResetVariables();
}

private void ResetVariables()
{
essenceDamageAdd = 0f;
essenceDamageMult = 1f;
essenceKnockback = 0f;
essenceCrit = 0;
essenceRegenRate = 1f;
essenceMax2 = essenceMax;
}

public override void PostUpdateMiscEffects()
{
UpdateResource();
}

private void UpdateResource()
{
essenceRegenTimer++;

if (essenceRegenTimer > 180 * essenceRegenRate)
{
essenceCurrent += 1;
essenceRegenTimer = 0;
}

essenceCurrent = Utils.Clamp(essenceCurrent, 0,essenceMax2);
}
}
}


using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.UI;
using Terraria.ModLoader;
using Test;

namespace Test.UI
{
internal class EssenceBar : UIState
{
private UIText text;
private UIElement area;
private UIImage barFrame;
private Color gradientA;
private Color gradientB;

public override void OnInitialize()
{
area = new UIElement();
area.Left.Set(-area.Width.Pixels - 600, 1f);
area.Top.Set(30, 0f);
area.Width.Set(182, 0f);
area.Height.Set(60, 0f);

barFrame = new UIImage(ModContent.GetTexture("Test/UI/EssenceBarFrame"));
barFrame.Left.Set(22, 0f);
barFrame.Top.Set(0, 0f);
barFrame.Width.Set(138, 0f);
barFrame.Height.Set(34, 0f);

text = new UIText("0/0", 0.8f);
text.Width.Set(138, 0f);
text.Height.Set(34, 0f);
text.Top.Set(40, 0f);
text.Left.Set(0, 0f);

gradientA = new Color(123, 25, 138);
gradientB = new Color(187, 91, 201);

area.Append(text);
area.Append(barFrame);
Append(area);
}

public override void Draw(SpriteBatch spriteBatch)
{
if (!(Main.LocalPlayer.HeldItem.modItem is EssenceItem))
return;

base.Draw(spriteBatch);
}

protected override void DrawSelf(SpriteBatch spriteBatch)
{
base.DrawSelf(spriteBatch);

var modPlayer = Main.LocalPlayer.GetModPlayer<EssencePlayer>();
float quotient = (float)modPlayer.essenceCurrent / modPlayer.essenceMax2;
quotient = Utils.Clamp(quotient, 0f, 1f);

Rectangle hitbox = barFrame.GetInnerDimensions().ToRectangle();
hitbox.X += 12;
hitbox.Width -= 24;
hitbox.Y += 8;
hitbox.Height -= 16;

int left = hitbox.Left;
int right = hitbox.Right;
int steps = (int)((right - left) * quotient);
for (int i = 0; i < steps; i += 1)
{
float percent = (float)i / (right - left);
spriteBatch.Draw(Main.magicPixel, new Rectangle(left + i, hitbox.Y, 1, hitbox.Height), Color.Lerp(gradientA, gradientB, percent));
}
}
public override void Update(GameTime gameTime)
{
if (!(Main.LocalPlayer.HeldItem.modItem is EssenceItem))
return;

var modPlayer = Main.LocalPlayer.GetModPlayer<EssencePlayer>();
text.SetText($"Essence: {modPlayer.essenceCurrent} / {modPlayer.essenceMax2}");
base.Update(gameTime);
}
}
}


using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;

namespace Test.Items.Weapons
{
public class EssenceStaff : EssenceItem
{
public override void SetStaticDefaults()
{
Item.staff[item.type] = true;
}

public override void SafeSetDefaults()
{
item.CloneDefaults(ItemID.AmethystStaff);
item.Size = new Vector2(28, 36);
item.damage = 32;
item.knockBack = 3;
item.rare = ItemRarityID.Red;
item.mana = 0;
item.useStyle = ItemUseStyleID.HoldingOut;
essenceCost = 10;
}
}
}
 
Last edited:
  • Like
Reactions: W1K
I only have a few months of coding experience, but I would really like to give it a try... do you have any idea how I would go about starting to code this? And if not, do you know how I could incorporate animated sprites to my buffs, as mentioned above? Thank you!

Edit: Turns out, I was able to code the resource first try! Well, almost... I'm having a small issue where the resource is regenerating and is able to be used, but the "bar" that is supposed to show how much of the resource the player has isn't showing up for some reason... any ideas? Here's all my code:
That is quite a lot of good progress. I'd suggest to either upload the codes to hastebin or use the forum's "Insert Code" command to make things more readable.

I can't really spend much time on it atm, and tMod's UI coding is something I'm a bit behind with myself as I haven't done much of it. First thing I'd try is debug and make sure the UI can at least draw anything at all to bar any problems with the logic, for instance I'd remove the condition in Draw to make sure it always draws, and simplify the drawing logic with something that easily verifies the method is being called at all (like drawing some gibberish on screen or debug text).
 
ok so i play on pc a friend LEGALLY gave me his terraria version from gog and when i tried to run mod loader this came up:

[23:22:52] [1/INFO] [tML]: Starting tModLoader v0.11.8.4 Windows client (4/7/2022)
[23:22:52] [1/INFO] [tML]: Running on NetFramework 4.8
[23:22:52] [1/INFO] [tML]: Executable: C:\GOG Games\Terraria\tModLoader.exe
[23:22:52] [1/INFO] [tML]: Working Directory: C:\GOG Games\Terraria
[23:22:52] [1/INFO] [tML]: Launch Parameters:
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: -> MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null -> MonoMod.Utils, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null
[23:22:52] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.RuntimeDetour, Version=20.11.16.1, Culture=neutral, PublicKeyToken=null -> Mono.Cecil, Version=0.11.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e
[23:22:53] [1/DEBUG] [tML]: Assembly Resolve: -> Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
[23:22:53] [1/DEBUG] [tML]: Assembly Resolve: -> Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
[23:22:55] [1/INFO] [tML]: Checking GOG or manual installation...
[23:22:55] [1/FATAL] [tML]: Terraria.exe is not the unmodified Terraria executable.

GOG installs must have the unmodified Terraria executable to function.

If you patched the .exe, you can create a copy of the original exe and name it "Terraria_v<VERSION>.exe"


PLS HELP
 

Attachments

  • Emotional Damage.png
    Emotional Damage.png
    73.9 KB · Views: 215
Looking for help, when playing t-modloader with a bunch of mods (Calamity, Stars Above, Split, AlchemistNPC, Fargos's Soulsmod, and more i cannot remember atm, will give them if needed.) my game crashes whenever the first wave of the Old Ones Army starts. Same thing happens if i just spawn an Ogre. My game also crashes as the Warrior of Light boss from Stars Above would go into his final phase.

Crash log (Old Ones Army)_________________________________________________

11/4/22 2:32:08 AM
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at SDL2.SDL.SDL_GL_SwapWindow(IntPtr window)
at Microsoft.Xna.Framework.Graphics.OpenGLDevice.SwapBuffers(Nullable`1 sourceRectangle, Nullable`1 destinationRectangle, IntPtr overrideWindowHandle)
at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present()
at Microsoft.Xna.Framework.GraphicsDeviceManager.Microsoft.Xna.Framework.IGraphicsDeviceManager.EndDraw()
at Microsoft.Xna.Framework.Game.EndDraw()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.SDL2_FNAPlatform.RunLoop(Game game)
at Microsoft.Xna.Framework.Game.Run()
at Terraria.Program.LaunchGame_()
________________________________________________________

I tried to uninstall and reinstall mods, tmodloader and verfiy steam files and I'm unsure if this correlates, but when verifying the base game files i receive this message

1649660535731.png


and if I verify the files the same message pops up.

Any help with fixing these?
 
Back
Top Bottom