Terraria ModLoader  0.10.1.5
A framework for Terraria mods
Terraria.ModLoader.ModLoader Class Reference

This serves as the central class which loads mods. It contains many static fields and methods related to mods and their contents. More...

+ Collaboration diagram for Terraria.ModLoader.ModLoader:

Static Public Member Functions

static bool FileExists (string name)
 
static byte[] GetFileBytes (string name)
 
static string[] GetLoadedMods ()
 
static Mod GetMod (string name)
 Gets the instance of the Mod with the specified name. More...
 
static Mod GetMod (int index)
 
static Music GetMusic (string name)
 
static SoundEffect GetSound (string name)
 
static Texture2D GetTexture (string name)
 
static bool IsSignedBy (TmodFile mod, string xmlPublicKey)
 
static bool MusicExists (string name)
 
static bool SoundExists (string name)
 
static bool TextureExists (string name)
 

Static Public Attributes

static readonly int beta = beta_value
 
static readonly string branchName = ""
 
static readonly string compressedPlatformRepresentation = (windows ? "w" : (linux ? "l" : "m")) + (gog ? "g" : "s")
 
static readonly bool gog = false
 
static readonly bool linux = false
 
static Mod[] LoadedMods => Mods
 
static readonly bool mac = false
 
static int ModCount => Mods.Length
 
static string ModPath => modPath
 The file path in which mods are stored. More...
 
static readonly Version version = new Version(0, 11)
 
static readonly string versionedName
 
static readonly string versionTag
 
static readonly bool windows = false
 

Properties

static Mod[] Mods [get, private set]
 

Static Private Member Functions

static void DisplayLoadError (string msg, Exception e, bool fatal, bool continueIsRetry=false)
 
static bool DotNet45Check ()
 
static void PostBuildMenu (bool success)
 
static void Unload ()
 

Static Private Attributes

static HashSet< string > _enabledMods
 A cached list of enabled mods (not necessarily currently loaded or even installed), mirroring the enabled.json file. More...
 
static readonly IDictionary< string, ModmodsByName = new Dictionary<string, Mod>(StringComparer.OrdinalIgnoreCase)
 
static string steamID64 = ""
 
static WeakReference[] weakModReferences = new WeakReference[0]
 

Detailed Description

This serves as the central class which loads mods. It contains many static fields and methods related to mods and their contents.

Definition at line 22 of file ModLoader.cs.

Member Function Documentation

static void Terraria.ModLoader.ModLoader.DisplayLoadError ( string  msg,
Exception  e,
bool  fatal,
bool  continueIsRetry = false 
)
staticprivate

Definition at line 231 of file ModLoader.cs.

References Terraria.ModLoader.Console, and Terraria.ModLoader.Environment.

231  {
232  msg += "\n\n" + (e.Data.Contains("hideStackTrace") ? e.Message : e.ToString());
233 
234  if (Main.dedServ) {
235  Console.ForegroundColor = ConsoleColor.Red;
236  Console.WriteLine(msg);
237  Console.ResetColor();
238 
239  if (fatal) {
240  Console.WriteLine("Press any key to exit...");
241  Console.ReadKey();
242  Environment.Exit(-1);
243  }
244  else {
245  Reload();
246  }
247  }
248  else {
249  Interface.errorMessage.Show(msg,
250  gotoMenu: fatal ? -1 : Interface.reloadModsID,
251  webHelpURL: e.HelpLink,
252  showRetry: continueIsRetry,
253  showSkip: !fatal);
254  }
255  }
Command can be used in server console during MP.
Sandstorm, Hell, Above surface during Eclipse, Space
static bool Terraria.ModLoader.ModLoader.DotNet45Check ( )
staticprivate

Definition at line 168 of file ModLoader.cs.

References Terraria.ModLoader.Console, Terraria.ModLoader.Environment, and Framework.

168  {
169  if (FrameworkVersion.Framework != Framework.NetFramework || FrameworkVersion.Version >= new Version(4, 5))
170  return true;
171 
172  var msg = Language.GetTextValue("tModLoader.LoadErrorDotNet45Required");
173  if (Main.dedServ) {
174  Console.ForegroundColor = ConsoleColor.Red;
175  Console.WriteLine(msg);
176  Console.ResetColor();
177  Console.WriteLine("Press any key to exit...");
178  Console.ReadKey();
179  Environment.Exit(-1);
180  }
181 
182  Interface.updateMessage.SetMessage(msg);
183  Interface.updateMessage.SetGotoMenu(0);
184  Interface.updateMessage.SetURL("https://www.microsoft.com/net/download/thank-you/net472");
185  Interface.updateMessage.SetAutoUpdateURL(null);
186  Main.menuMode = Interface.updateMessageID;
187  return false;
188  }
´╗┐using Microsoft.Xna. Framework
Definition: ModNet.cs:2
Command can be used in server console during MP.
Sandstorm, Hell, Above surface during Eclipse, Space
static bool Terraria.ModLoader.ModLoader.FileExists ( string  name)
static
static byte [] Terraria.ModLoader.ModLoader.GetFileBytes ( string  name)
static
static string [] Terraria.ModLoader.ModLoader.GetLoadedMods ( )
static
static Mod Terraria.ModLoader.ModLoader.GetMod ( int  index)
static
static Music Terraria.ModLoader.ModLoader.GetMusic ( string  name)
static
static SoundEffect Terraria.ModLoader.ModLoader.GetSound ( string  name)
static
static Texture2D Terraria.ModLoader.ModLoader.GetTexture ( string  name)
static
static bool Terraria.ModLoader.ModLoader.IsSignedBy ( TmodFile  mod,
string  xmlPublicKey 
)
static

Definition at line 258 of file ModLoader.cs.

References Terraria.ModLoader.IO.TmodFile.hash.

258  {
259  var f = new RSAPKCS1SignatureDeformatter();
260  var v = AsymmetricAlgorithm.Create("RSA");
261  f.SetHashAlgorithm("SHA1");
262  v.FromXmlString(xmlPublicKey);
263  f.SetKey(v);
264  return f.VerifySignature(mod.hash, mod.signature);
265  }
static bool Terraria.ModLoader.ModLoader.MusicExists ( string  name)
static
static void Terraria.ModLoader.ModLoader.PostBuildMenu ( bool  success)
staticprivate

Definition at line 298 of file ModLoader.cs.

298  {
299  Main.menuMode = success ? (reloadAfterBuild ? Interface.reloadModsID : 0) : Interface.errorMessageID;
300  }
static bool Terraria.ModLoader.ModLoader.SoundExists ( string  name)
static
static bool Terraria.ModLoader.ModLoader.TextureExists ( string  name)
static
static void Terraria.ModLoader.ModLoader.Unload ( )
staticprivate

Definition at line 211 of file ModLoader.cs.

References Terraria.ModLoader.Console.

211  {
212  Logging.tML.Info("Unloading mods");
213  if (Main.dedServ)
214  Console.WriteLine("Unloading mods...");
215 
216  ModContent.UnloadModContent();
217  Mods = new Mod[0];
218  modsByName.Clear();
219  ModContent.Unload();
220 
221  MemoryTracking.Clear();
222  Thread.MemoryBarrier();
223  GC.Collect();
224  badUnloaders.Clear();
225  foreach (var mod in weakModReferences.Where(r => r.IsAlive).Select(r => (Mod)r.Target)) {
226  Logging.tML.WarnFormat("{0} not fully unloaded during unload.", mod.Name);
227  badUnloaders.Add(mod.Name);
228  }
229  }
Command can be used in server console during MP.
static WeakReference[] weakModReferences
Definition: ModLoader.cs:66
static readonly IDictionary< string, Mod > modsByName
Definition: ModLoader.cs:65

Member Data Documentation

HashSet<string> Terraria.ModLoader.ModLoader._enabledMods
staticprivate

A cached list of enabled mods (not necessarily currently loaded or even installed), mirroring the enabled.json file.

Definition at line 268 of file ModLoader.cs.

readonly int Terraria.ModLoader.ModLoader.beta = beta_value
static

Definition at line 29 of file ModLoader.cs.

readonly string Terraria.ModLoader.ModLoader.branchName = ""
static

Definition at line 26 of file ModLoader.cs.

readonly string Terraria.ModLoader.ModLoader.compressedPlatformRepresentation = (windows ? "w" : (linux ? "l" : "m")) + (gog ? "g" : "s")
static

Definition at line 58 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.gog = false
static

Definition at line 56 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.linux = false
static

Definition at line 46 of file ModLoader.cs.

Mod [] Terraria.ModLoader.ModLoader.LoadedMods => Mods
static

Definition at line 103 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.mac = false
static

Definition at line 51 of file ModLoader.cs.

int Terraria.ModLoader.ModLoader.ModCount => Mods.Length
static

Definition at line 106 of file ModLoader.cs.

string Terraria.ModLoader.ModLoader.ModPath => modPath
static

The file path in which mods are stored.

Definition at line 62 of file ModLoader.cs.

Referenced by Terraria.ModLoader.ModNet.ModHeader.ModHeader().

readonly IDictionary<string, Mod> Terraria.ModLoader.ModLoader.modsByName = new Dictionary<string, Mod>(StringComparer.OrdinalIgnoreCase)
staticprivate

Definition at line 65 of file ModLoader.cs.

string Terraria.ModLoader.ModLoader.steamID64 = ""
staticprivate

Definition at line 71 of file ModLoader.cs.

readonly Version Terraria.ModLoader.ModLoader.version = new Version(0, 11)
static

Definition at line 24 of file ModLoader.cs.

Referenced by Terraria.ModLoader.IO.TmodFile.GetEnumerator().

readonly string Terraria.ModLoader.ModLoader.versionedName
static
Initial value:
= $"tModLoader v{version}" +
(branchName.Length == 0 ? "" : $" {branchName}") +
(beta == 0 ? "" : $" Beta {beta}")

Definition at line 31 of file ModLoader.cs.

readonly string Terraria.ModLoader.ModLoader.versionTag
static
Initial value:
= $"v{version}" +
(branchName.Length == 0 ? "" : $"-{branchName.ToLower()}") +
(beta == 0 ? "" : $"-beta{beta}")

Definition at line 34 of file ModLoader.cs.

WeakReference [] Terraria.ModLoader.ModLoader.weakModReferences = new WeakReference[0]
staticprivate

Definition at line 66 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.windows = false
static

Property Documentation