1 using Microsoft.Xna.Framework.Audio;
2 using Microsoft.Xna.Framework.Graphics;
4 using System.Collections.Generic;
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);
297 public static int ItemType<T>() where T :
ModItem => GetInstance<T>()?.
item.type ?? 0;
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;
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);
358 LoadModContent(token, mod => {
361 mod.AutoloadConfig();
368 Interface.loadMods.SetLoadStage(
"tModLoader.MSSettingUp");
370 RecipeGroupHelper.FixRecipeGroupLookups();
372 Interface.loadMods.SetLoadStage(
"tModLoader.MSLoading",
ModLoader.
Mods.Length);
373 LoadModContent(token, mod => {
375 mod.PostSetupContent();
378 MemoryTracking.Finish();
383 Main.player[255] =
new Player(
false);
385 RefreshModLanguage(Language.ActiveCulture);
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} 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();
428 Recipe.SetupRecipes();
432 internal static void UnloadModContent() {
437 Console.WriteLine($
"Unloading {mod.DisplayName}...");
439 Interface.loadMods.SetCurrentMod(i++, mod.DisplayName);
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;
531 Lang._itemNameCache[item.
item.type] = SetLocalizedText(dict, text);
533 if (text.Value != null) {
534 text = SetLocalizedText(dict, text);
535 Lang._itemTooltipCache[item.
item.type] = ItemTooltip.FromLanguageKey(text.Key);
540 Lang.prefix[prefix.
Type] = SetLocalizedText(dict, text);
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));
546 SetLocalizedText(dict, text);
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));
554 SetLocalizedText(dict, text);
560 Lang._projectileNameCache[proj.
projectile.type] = SetLocalizedText(dict, text);
564 Lang._npcNameCache[npc.
npc.type] = SetLocalizedText(dict, text);
568 Lang._buffNameCache[buff.
Type] = SetLocalizedText(dict, text);
570 Lang._buffDescriptionCache[buff.
Type] = SetLocalizedText(dict, text);
574 LocalizedText text =
new LocalizedText(translation.
Key, translation.
GetTranslation(culture));
575 SetLocalizedText(dict, text);
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);
static void LoadModContent(CancellationToken token, Action< Mod > loadAction)
static byte[] GetFileBytes(string name)
Gets the byte representation of the file with the specified name. The name is in the format of "ModFo...
int Type
The ID of this type of dust.
static ModWaterfallStyle GetWaterfallStyle(int style)
Returns the ModWaterfallStyle with the given ID.
int Type
The index of this ModMountData in the Mount.mounts array.
static ModMountData GetMount(int type)
Gets the ModMountData instance corresponding to the given type. Returns null if no ModMountData has t...
ModTranslation DisplayName
The translations for the display name of this NPC.
This class represents a type of tile that can be added by a mod. Only one instance of this class will...
int Type
The numeric type used to identify this kind of tile entity.
This class serves as a place for you to place all your properties and hooks for each NPC...
ModTranslation Description
The translations of this buff's description.
Each background style determines in its own way how exactly the background is drawn. This class serves as a collection of functions for above-ground backgrounds.
This is the class that keeps track of all modded background textures and their slots/IDs.
static void CacheVanillaState()
This serves as the central class from which projectile-related functions are carried out...
static EquipTexture GetEquipTexture(EquipType type, int slot)
Gets the equipment texture for the specified equipment type and ID.
This is where all ModPlayer hooks are gathered and called.
static Music GetMusic(string name)
Gets the music with the specified name. The name is in the same format as for texture names...
This is where all ModRecipe and GlobalRecipe hooks are gathered and called.
Tile Entities are Entities tightly coupled with tiles, allowing the possibility of tiles to exhibit c...
static Texture2D GetTexture(string name)
Gets the texture with the specified name. The name is in the format of "ModFolder/OtherFolders/FileNa...
This serves as the central class from which ModUgBgStyle functions are supported and carried out...
static void SetupRecipes(CancellationToken token)
static void DisposeMusic()
static ModWall GetWall(int type)
Gets the ModWall instance with the given type. If no ModWall with the given type exists, returns null.
static LocalizedText SetLocalizedText(Dictionary< string, LocalizedText > dict, LocalizedText value)
ModTranslation DisplayName
This serves as a place for you to program behaviors of equipment textures. This is useful for equipme...
static ModTile GetTile(int type)
Gets the ModTile instance with the given type. If no ModTile with the given type exists, returns null.
Item item
The item object that this ModItem controls.
This serves as the central class which loads mods. It contains many static fields and methods related...
Music GetMusic(string name)
Shorthand for calling ModContent.GetMusic(this.FileName(name)).
This serves as the central class from which tile-related functions are supported and carried out...
static ModProjectile GetProjectile(int type)
Gets the ModProjectile instance corresponding to the specified type.
This is where all ModWorld hooks are gathered and called.
ushort Type
The internal ID of this type of wall.
Command can be used in server console during MP.
This class allows you to customize the behavior of a custom gore. Create a new instance of this and p...
NPC npc
The NPC object that this ModNPC controls.
static int GetBackgroundSlot(string texture)
Returns the slot/ID of the background texture with the given name.
Represents a style of water that gets drawn, based on factors such as the background. This is used to determine the color of the water, as well as other things as determined by the hooks below.
This class serves as a central place from which NPC head slots are stored and NPC head textures are a...
static ModItem GetItem(int type)
Gets the ModItem instance corresponding to the specified type. Returns null if no modded item has the...
static ModUgBgStyle GetUgBgStyle(int style)
Returns the ModUgBgStyle object with the given ID.
This serves as a central place to store equipment slots and their corresponding textures. You will use this to obtain the IDs for your equipment textures.
Manages content added by mods. Liasons between mod content and Terraria's arrays and oversees the Loa...
static bool TextureExists(string name)
Returns whether or not a texture with the specified name exists.
static int GetHeadSlot(string texture)
Gets the index of the head texture corresponding to the given texture path.
EquipType
This is an enum of all the types of equipment that exist. An equipment type is defined as a type or l...
Projectile projectile
The projectile object that this ModProjectile controls.
This class is used to keep track of and support the existence of custom sounds that have been added t...
bool FileExists(string name)
Shorthand for calling ModLoader.FileExists(this.FileName(name)). Note that file extensions are used h...
ModTranslation DisplayName
The translations for the display name of this item.
static Stream OpenRead(string assetName, bool newFileStream=false)
static ModSurfaceBgStyle GetSurfaceBgStyle(int style)
Returns the ModSurfaceBgStyle object with the given ID.
This class represents a type of wall that can be added by a mod. Only one instance of this class will...
This serves as the central class from which item-related functions are carried out. It also stores a list of mod items by ID.
This class serves as a place for you to place all your properties and hooks for each mount...
bool SoundExists(string name)
Shorthand for calling ModLoader.SoundExists(this.FileName(name)).
ushort Type
The internal ID of this type of tile.
static bool MusicExists(string name)
Returns whether or not a sound with the specified name exists.
bool TextureExists(string name)
Shorthand for calling ModLoader.TextureExists(this.FileName(name)).
Represents a style of waterfalls that gets drawn. This is mostly used to determine the color of the w...
SoundEffect GetSound(string name)
Shorthand for calling ModContent.GetSound(this.FileName(name)).
This serves as the central class from which WaterStyle functions are supported and carried out...
This serves as the central class from which ModCommand functions are supported and carried out...
This class serves as a place for you to define a new buff and how that buff behaves.
Stream GetFileStream(string name, bool newFileStream=false)
Retrieve contents of files within the tmod file
static ModNPC GetNPC(int type)
Gets the ModNPC instance corresponding to the specified type.
bool MusicExists(string name)
Shorthand for calling ModLoader.MusicExists(this.FileName(name)).
static SoundEffect GetSound(string name)
Gets the sound with the specified name. The name is in the same format as for texture names...
static ModDust GetDust(int type)
Gets the ModDust instance with the given type. Returns null if no ModDust with the given type exists...
static ModBuff GetBuff(int type)
Gets the ModBuff instance with the given type. If no ModBuff with the given type exists, returns null.
ModTranslation DisplayName
The translations of this buff's display name.
This serves as the central class from which NPC-related functions are carried out. It also stores a list of mod NPCs by ID.
static void SplitName(string name, out string domain, out string subName)
This serves as the central class from which buff-related functions are supported and carried out...
This class serves as a place for you to place all your properties and hooks for each projectile...
byte[] GetFileBytes(string name)
Retrieve contents of files within the tmod file
static void RefreshModLanguage(GameCulture culture)
This serves as the central class from which wall-related functions are supported and carried out...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
static void ResizeArrays(bool unloading=false)
static int GetBossHeadSlot(string texture)
Gets the index of the boss head texture corresponding to the given texture path.
ModTranslation DisplayName
The translations for the display name of this projectile.
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 item...
ModTranslation Tooltip
The translations for the display name of this tooltip.
This class represents a type of dust that is added by a mod. Only one instance of this class will eve...
int Type
The buff id of this buff.
static bool SoundExists(string name)
Returns whether or not a sound with the specified name exists.
string GetTranslation(int culture)
This serves as the central place from which mounts are stored and mount-related functions are carried...
static ModWaterStyle GetWaterStyle(int style)
Returns the ModWaterStyle with the given ID.
Each background style determines in its own way how exactly the background is drawn. This class serves as a collection of functions for underground backgrounds.
static bool FileExists(string name)
Returns whether or not a file with the specified name exists.