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

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

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

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

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

References Terraria.ModLoader.IO.TmodFile.hash.

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

Definition at line 294 of file ModLoader.cs.

294  {
295  Main.menuMode = success ? (reloadAfterBuild ? Interface.reloadModsID : 0) : Interface.errorMessageID;
296  }
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  Thread.MemoryBarrier();
222  GC.Collect();
223  foreach (var mod in weakModReferences.Where(r => r.IsAlive).Select(r => (Mod)r.Target))
224  Logging.tML.WarnFormat("{0} not fully unloaded during unload.", mod.Name);
225  }
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 264 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 105 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 108 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.

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