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 = 1
 
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 224 of file ModLoader.cs.

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

224  {
225  msg += "\n\n" + (e.Data.Contains("hideStackTrace") ? e.Message : e.ToString());
226 
227  if (Main.dedServ) {
228  Console.ForegroundColor = ConsoleColor.Red;
229  Console.WriteLine(msg);
230  Console.ResetColor();
231 
232  if (fatal) {
233  Console.WriteLine("Press any key to exit...");
234  Console.ReadKey();
235  Environment.Exit(-1);
236  }
237  else {
238  Reload();
239  }
240  }
241  else {
242  Interface.errorMessage.Show(msg,
243  gotoMenu: fatal ? -1 : Interface.reloadModsID,
244  webHelpURL: e.HelpLink,
245  showRetry: continueIsRetry,
246  showSkip: !fatal);
247  }
248  }
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 167 of file ModLoader.cs.

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

167  {
168  if (FrameworkVersion.Framework != ".NET Framework" || FrameworkVersion.Version >= new Version(4, 5))
169  return true;
170 
171  var msg = Language.GetTextValue("tModLoader.LoadErrorDotNet45Required");
172  if (Main.dedServ) {
173  Console.ForegroundColor = ConsoleColor.Red;
174  Console.WriteLine(msg);
175  Console.ResetColor();
176  Console.WriteLine("Press any key to exit...");
177  Console.ReadKey();
178  Environment.Exit(-1);
179  }
180 
181  Interface.updateMessage.SetMessage(msg);
182  Interface.updateMessage.SetGotoMenu(0);
183  Interface.updateMessage.SetURL("https://www.microsoft.com/net/download/thank-you/net472");
184  Main.menuMode = Interface.updateMessageID;
185  return false;
186  }
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 251 of file ModLoader.cs.

References Terraria.ModLoader.IO.TmodFile.hash.

251  {
252  var f = new RSAPKCS1SignatureDeformatter();
253  var v = AsymmetricAlgorithm.Create("RSA");
254  f.SetHashAlgorithm("SHA1");
255  v.FromXmlString(xmlPublicKey);
256  f.SetKey(v);
257  return f.VerifySignature(mod.hash, mod.signature);
258  }
static bool Terraria.ModLoader.ModLoader.MusicExists ( string  name)
static
static void Terraria.ModLoader.ModLoader.PostBuildMenu ( bool  success)
staticprivate

Definition at line 291 of file ModLoader.cs.

291  {
292  Main.menuMode = success ? (reloadAfterBuild ? Interface.reloadModsID : 0) : Interface.errorMessageID;
293  }
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 208 of file ModLoader.cs.

References Terraria.ModLoader.Console, and Terraria.ModLoader.ModContent.Unload().

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

+ Here is the call graph for this function:

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 261 of file ModLoader.cs.

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

Definition at line 28 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 57 of file ModLoader.cs.

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

Definition at line 55 of file ModLoader.cs.

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

Definition at line 45 of file ModLoader.cs.

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

Definition at line 102 of file ModLoader.cs.

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

Definition at line 50 of file ModLoader.cs.

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

Definition at line 105 of file ModLoader.cs.

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

The file path in which mods are stored.

Definition at line 61 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 64 of file ModLoader.cs.

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

Definition at line 70 of file ModLoader.cs.

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

Definition at line 24 of file ModLoader.cs.

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

Definition at line 30 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 33 of file ModLoader.cs.

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

Definition at line 65 of file ModLoader.cs.

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

Property Documentation