1using Microsoft.Xna.Framework.Audio;
2using Microsoft.Xna.Framework.Graphics;
4using System.Collections.Generic;
8using Terraria.DataStructures;
9using Terraria.GameContent.UI;
10using Terraria.GameInput;
11using Terraria.Localization;
13using Terraria.ModLoader.Core;
14using Terraria.ModLoader.Engine;
17using Terraria.ModLoader.UI;
30 public static
void SplitName(
string name, out
string domain, out
string subName) {
31 int slash = name.IndexOf(
'/');
35 domain = name.Substring(0, slash);
36 subName = name.Substring(slash + 1);
44 string modName, subName;
45 SplitName(name, out modName, out subName);
58 if (!name.Contains(
'/'))
61 string modName, subName;
62 SplitName(name, out modName, out subName);
76 string modName, subName;
77 SplitName(name, out modName, out subName);
78 if (modName ==
"Terraria")
79 return Main.instance.Content.Load<Texture2D>(
"Images" + Path.DirectorySeparatorChar + subName);
85 return mod.GetTexture(subName);
92 if (Main.dedServ ||
string.IsNullOrWhiteSpace(name) || !name.Contains(
'/'))
95 SplitName(name, out
string modName, out
string subName);
97 if (modName ==
"Terraria")
98 return (Main.instance.Content as TMLContentManager).ImageExists(subName);
111 internal static bool TryGetTexture(
string name, out Texture2D texture) {
112 if (Main.dedServ ||
string.IsNullOrWhiteSpace(name) || !name.Contains(
'/')) {
118 SplitName(name, out
string modName, out
string subName);
120 if (modName ==
"Terraria") {
121 if ((Main.instance.Content as TMLContentManager).ImageExists(subName)) {
122 texture = Main.instance.Content.Load<Texture2D>(
"Images" + Path.DirectorySeparatorChar + subName);
140 return mod.textures.TryGetValue(subName, out texture);
151 string modName, subName;
152 SplitName(name, out modName, out subName);
165 if (!name.Contains(
'/'))
168 string modName, subName;
169 SplitName(name, out modName, out subName);
180 if (Main.dedServ) {
return null; }
181 string modName, subName;
182 SplitName(name, out modName, out subName);
192 if (!name.Contains(
'/')) {
return false; }
193 string modName, subName;
194 SplitName(name, out modName, out subName);
302 public static
byte PrefixType<T>() where T :
ModPrefix => GetInstance<T>()?.Type ?? 0;
307 public static
int DustType<T>() where T :
ModDust => GetInstance<T>()?.Type ?? 0;
312 public static
int TileType<T>() where T :
ModTile => GetInstance<T>()?.Type ?? 0;
317 public static
int TileEntityType<T>() where T :
ModTileEntity => GetInstance<T>()?.Type ?? 0;
322 public static
int WallType<T>() where T :
ModWall => GetInstance<T>()?.Type ?? 0;
327 public static
int ProjectileType<T>() where T :
ModProjectile => GetInstance<T>()?.projectile.type ?? 0;
332 public static
int NPCType<T>() where T :
ModNPC => GetInstance<T>()?.npc.type ?? 0;
337 public static
int BuffType<T>() where T :
ModBuff => GetInstance<T>()?.Type ?? 0;
342 public static
int MountType<T>() where T :
ModMountData => GetInstance<T>()?.Type ?? 0;
344 private static LocalizedText
SetLocalizedText(Dictionary<
string, LocalizedText> dict, LocalizedText value) {
345 if (dict.ContainsKey(value.Key)) {
346 dict[value.Key].SetValue(value.Value);
349 dict[value.Key] = value;
351 return dict[value.Key];
354 internal static void Load(CancellationToken token) {
357 Interface.loadMods.SetLoadStage(
"tModLoader.MSIntializing",
ModLoader.
Mods.Length);
361 mod.AutoloadConfig();
368 Interface.loadMods.SetLoadStage(
"tModLoader.MSSettingUp");
370 RecipeGroupHelper.FixRecipeGroupLookups();
372 Interface.loadMods.SetLoadStage(
"tModLoader.MSLoading",
ModLoader.
Mods.Length);
378 MemoryTracking.Finish();
383 Main.player[255] =
new Player(
false);
386 MapLoader.SetupModMap();
387 ItemSorting.SetupWhiteLists();
388 PlayerInput.reinitialize =
true;
393 EffectsTracker.CacheVanillaState();
396 internal static Mod LoadingMod {
get;
private set; }
397 private static void LoadModContent(CancellationToken token, Action<Mod> loadAction) {
398 MemoryTracking.Checkpoint();
401 token.ThrowIfCancellationRequested();
402 Interface.loadMods.SetCurrentMod(num++, $
"{mod.Name} ({mod.DisplayName}) v{mod.Version}");
408 e.Data[
"mod"] = mod.Name;
413 MemoryTracking.Update(mod.Name);
419 Interface.loadMods.SetLoadStage(
"tModLoader.MSAddingRecipes");
420 for (
int k = 0; k < Recipe.maxRecipes; k++) {
421 token.ThrowIfCancellationRequested();
422 Main.recipe[k] =
new Recipe();
425 Recipe.numRecipes = 0;
426 RecipeGroupHelper.ResetRecipeGroups();
427 RecipeHooks.setupRecipes =
true;
428 Recipe.SetupRecipes();
429 RecipeHooks.setupRecipes =
false;
432 internal static void UnloadModContent() {
437 Console.WriteLine($
"Unloading {mod.DisplayName}...");
439 Interface.loadMods.SetCurrentMod(i++, $
"{mod.Name} ({mod.DisplayName}) v{mod.Version}");
444 e.Data[
"mod"] = mod.Name;
453 internal static void Unload() {
474 GlobalBgStyleLoader.Unload();
479 for (
int k = 0; k < Recipe.maxRecipes; k++) {
480 Main.recipe[k] =
new Recipe();
482 Recipe.numRecipes = 0;
483 RecipeGroupHelper.ResetRecipeGroups();
484 Recipe.SetupRecipes();
485 MapLoader.UnloadModMap();
486 ItemSorting.SetupWhiteLists();
487 HotKeyLoader.Unload();
492 Config.ConfigManager.Unload();
493 CustomCurrencyManager.Initialize();
494 EffectsTracker.RemoveModEffects();
496 CleanupModReferences();
503 Main.InitializeItemAnimations();
518 GlobalBgStyleLoader.ResizeAndFillArrays(unloading);
522 foreach (LocalizedText text
in LanguageManager.Instance._localizedTexts.Values) {
523 text.Override =
null;
528 Dictionary<string, LocalizedText> dict = LanguageManager.Instance._localizedTexts;
533 if (text.Value !=
null) {
535 Lang._itemTooltipCache[item.
item.type] = ItemTooltip.FromLanguageKey(text.Key);
542 foreach (var keyValuePair
in MapLoader.tileEntries) {
543 foreach (MapEntry entry
in keyValuePair.Value) {
544 if (entry.translation !=
null) {
545 LocalizedText text =
new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
550 foreach (var keyValuePair
in MapLoader.wallEntries) {
551 foreach (MapEntry entry
in keyValuePair.Value) {
552 if (entry.translation !=
null) {
553 LocalizedText text =
new LocalizedText(entry.translation.Key, entry.translation.GetTranslation(culture));
574 LocalizedText text =
new LocalizedText(translation.
Key, translation.
GetTranslation(culture));
578 LanguageManager.Instance.ProcessCopyCommandsInTexts();
590 internal static void CleanupModReferences()
593 for (
int i = 0; i < Main.player.Length; i++) {
594 Main.player[i] =
new Player();
598 Main.clientPlayer =
new Player(
false);
599 Main.ActivePlayerFileData =
new Terraria.IO.PlayerFileData();
600 Main._characterSelectMenu._playerList?.Clear();
601 Main.PlayerList.Clear();
603 for (
int i = 0; i < Main.npc.Length; i++) {
604 Main.npc[i] =
new NPC();
605 Main.npc[i].whoAmI = i;
608 for (
int i = 0; i < Main.item.Length; i++) {
609 Main.item[i] =
new Item();
613 if (ItemSlot.singleSlotArray[0] !=
null) {
614 ItemSlot.singleSlotArray[0] =
new Item();
617 for (
int i = 0; i < Main.chest.Length; i++) {
618 Main.chest[i] =
new Chest();
621 for (
int i = 0; i < Main.projectile.Length; i++) {
622 Main.projectile[i] =
new Projectile();
629 public static Stream
OpenRead(
string assetName,
bool newFileStream =
false) {
630 if (!assetName.StartsWith(
"tmod:"))
631 return File.OpenRead(assetName);
633 SplitName(assetName.Substring(5).Replace(
'\\',
'/'), out var modName, out var entryPath);
This is the class that keeps track of all modded background textures and their slots/IDs.
static int GetBackgroundSlot(string texture)
Returns the slot/ID of the background texture with the given name.
This serves as the central class from which buff-related functions are supported and carried out.
static ModBuff GetBuff(int type)
Gets the ModBuff instance with the given type. If no ModBuff with the given type exists,...
This serves as the central class from which ModCommand functions are supported and carried out.
static void Register(object obj)
This serves as a central place to store equipment slots and their corresponding textures....
static EquipTexture GetEquipTexture(EquipType type, int slot)
Gets the equipment texture for the specified equipment type and ID.
This serves as a place for you to program behaviors of equipment textures. This is useful for equipme...
This serves as the central class from which item-related functions are carried out....
static ModItem GetItem(int type)
Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the...
This class serves as a place for you to define a new buff and how that buff behaves.
int Type
The buff id of this buff.
ModTranslation Description
The translations of this buff's description.
ModTranslation DisplayName
The translations of this buff's display name.
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
static void CacheVanillaState()
static ModProjectile GetModProjectile(int type)
Gets the ModProjectile instance corresponding to the specified type.
static int GetModBossHeadSlot(string texture)
Gets the index of the boss head texture corresponding to the given texture path.
static ModWaterStyle GetModWaterStyle(int style)
Returns the ModWaterStyle with the given ID.
static int GetModBackgroundSlot(string texture)
Returns the slot/ID of the background texture with the given name.
static ModWall GetModWall(int type)
Gets the ModWall instance with the given type. If no ModWall with the given type exists,...
static bool TextureExists(string name)
Returns whether or not a texture with the specified name exists.
static void DisposeMusic()
static ModWaterfallStyle GetModWaterfallStyle(int style)
Returns the ModWaterfallStyle with the given ID.
static void ResizeArrays(bool unloading=false)
static bool FileExists(string name)
Returns whether or not a file with the specified name exists.
static ModSurfaceBgStyle GetModSurfaceBgStyle(int style)
Returns the ModSurfaceBgStyle object with the given ID.
static SoundEffect GetSound(string name)
Gets the sound with the specified name. The name is in the same format as for texture names....
static Stream OpenRead(string assetName, bool newFileStream=false)
static Music GetMusic(string name)
Gets the music with the specified name. The name is in the same format as for texture names....
static void SplitName(string name, out string domain, out string subName)
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
static bool SoundExists(string name)
Returns whether or not a sound with the specified name exists.
static int GetModHeadSlot(string texture)
Gets the index of the head texture corresponding to the given texture path.
static void SetupRecipes(CancellationToken token)
static ModTile GetModTile(int type)
Gets the ModTile instance with the given type. If no ModTile with the given type exists,...
static void RefreshModLanguage(GameCulture culture)
static ModUgBgStyle GetModUgBgStyle(int style)
Returns the ModUgBgStyle object with the given ID.
static bool MusicExists(string name)
Returns whether or not a sound with the specified name exists.
static ModBuff GetModBuff(int type)
Gets the ModBuff instance with the given type. If no ModBuff with the given type exists,...
static T GetInstance< T >()
static ModItem GetModItem(int type)
Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the...
static ModNPC GetModNPC(int type)
Gets the ModNPC instance corresponding to the specified type.
static byte[] GetFileBytes(string name)
Gets the byte representation of the file with the specified name. The name is in the format of "ModFo...
static EquipTexture GetEquipTexture(EquipType type, int slot)
Gets the equipment texture for the specified equipment type and ID.
static ModDust GetModDust(int type)
Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists.
static ModMountData GetModMountData(int type)
Gets the ModMountData instance corresponding to the given type. Returns null if no ModMountData has t...
static int ItemType< T >()
Get the id (type) of a ModItem by class. Assumes one instance per class.
static LocalizedText SetLocalizedText(Dictionary< string, LocalizedText > dict, LocalizedText value)
static void LoadModContent(CancellationToken token, Action< Mod > loadAction)
This class represents a type of dust that is added by a mod. Only one instance of this class will eve...
static ModDust GetDust(int type)
Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists.
This class allows you to customize the behavior of a custom gore. Create a new instance of this and p...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
virtual void PostSetupContent()
Allows you to load things in your mod after its content has been setup (arrays have been resized to f...
bool SoundExists(string name)
Shorthand for calling ModLoader.SoundExists(this.FileName(name)).
SoundEffect GetSound(string name)
Shorthand for calling ModContent.GetSound(this.FileName(name)).
Music GetMusic(string name)
Shorthand for calling ModContent.GetMusic(this.FileName(name)).
byte[] GetFileBytes(string name)
Retrieve contents of files within the tmod file
virtual void LoadResources()
bool TextureExists(string name)
Shorthand for calling ModLoader.TextureExists(this.FileName(name)).
bool FileExists(string name)
Shorthand for calling ModLoader.FileExists(this.FileName(name)). Note that file extensions are used h...
Stream GetFileStream(string name, bool newFileStream=false)
Retrieve contents of files within the tmod file
bool MusicExists(string name)
Shorthand for calling ModLoader.MusicExists(this.FileName(name)).
virtual void Load()
Override this method to add most of your content to your mod. Here you will call other methods such a...
This class serves as a place for you to place all your properties and hooks for each item....
ModTranslation Tooltip
The translations for the display name of this tooltip.
Item item
The item object that this ModItem controls.
ModTranslation DisplayName
The translations for the display name of this item.
This serves as the central class which loads mods. It contains many static fields and methods related...
static Mod GetMod(string name)
Gets the instance of the Mod with the specified name.
This class serves as a place for you to place all your properties and hooks for each mount....
This class serves as a place for you to place all your properties and hooks for each NPC....
NPC npc
The NPC object that this ModNPC controls.
ModTranslation DisplayName
The translations for the display name of this NPC.
ModTranslation DisplayName
This class serves as a place for you to place all your properties and hooks for each projectile....
Projectile projectile
The projectile object that this ModProjectile controls.
ModTranslation DisplayName
The translations for the display name of this projectile.
Each background style determines in its own way how exactly the background is drawn....
Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit c...
This class represents a type of tile that can be added by a mod. Only one instance of this class will...
string GetTranslation(int culture)
Each background style determines in its own way how exactly the background is drawn....
This class represents a type of wall that can be added by a mod. Only one instance of this class will...
Represents a style of water that gets drawn, based on factors such as the background....
Represents a style of waterfalls that gets drawn. This is mostly used to determine the color of the w...
This serves as the central place from which mounts are stored and mount-related functions are carried...
static ModMountData GetMount(int type)
Gets the ModMountData instance corresponding to the given type. Returns null if no ModMountData has t...
This class serves as a central place from which NPC head slots are stored and NPC head textures are a...
static int GetBossHeadSlot(string texture)
Gets the index of the boss head texture corresponding to the given texture path.
static int GetHeadSlot(string texture)
Gets the index of the head texture corresponding to the given texture path.
This serves as the central class from which NPC-related functions are carried out....
static ModNPC GetNPC(int type)
Gets the ModNPC instance corresponding to the specified type.
This is where all ModPlayer hooks are gathered and called.
This serves as the central class from which projectile-related functions are carried out....
static ModProjectile GetProjectile(int type)
Gets the ModProjectile instance corresponding to the specified type.
This is where all ModRecipe and GlobalRecipe hooks are gathered and called.
This class is used to keep track of and support the existence of custom sounds that have been added t...
static ModSurfaceBgStyle GetSurfaceBgStyle(int style)
Returns the ModSurfaceBgStyle object with the given ID.
This serves as the central class from which tile-related functions are supported and carried out.
static ModTile GetTile(int type)
Gets the ModTile instance with the given type. If no ModTile with the given type exists,...
This serves as the central class from which ModUgBgStyle functions are supported and carried out.
static ModUgBgStyle GetUgBgStyle(int style)
Returns the ModUgBgStyle object with the given ID.
This serves as the central class from which wall-related functions are supported and carried out.
static ModWall GetWall(int type)
Gets the ModWall instance with the given type. If no ModWall with the given type exists,...
This serves as the central class from which WaterStyle functions are supported and carried out.
static ModWaterStyle GetWaterStyle(int style)
Returns the ModWaterStyle with the given ID.
static ModWaterfallStyle GetWaterfallStyle(int style)
Returns the ModWaterfallStyle with the given ID.
This is where all ModWorld hooks are gathered and called.
@ Console
Command can be used in server console during MP.
EquipType
This is an enum of all the types of equipment that exist. An equipment type is defined as a type or l...