Terraria ModLoader  0.11.4
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 = 0
 
static readonly string branchName = ""
 
static readonly string compressedPlatformRepresentation = Platform.IsWindows ? "w" : (Platform.IsLinux ? "l" : "m")
 
static string CompressedPlatformRepresentation => (Platform.IsWindows ? "w" : (Platform.IsLinux ? "l" : "m")) + (GoGVerifier.IsGoG ? "g" : "s") + (FrameworkVersion.Framework == Framework.NetFramework ? "n" : (FrameworkVersion.Framework == Framework.Mono ? "o" : "u"))
 
static readonly bool linux = Platform.IsLinux
 
static Mod[] LoadedMods => Mods
 
static readonly bool mac = Platform.IsOSX
 
static int ModCount => Mods.Length
 
static string ModPath => ModOrganizer.modPath
 
static readonly Version version = new Version(0, 11, 4)
 
static readonly string versionedName
 
static readonly string versionTag
 
static readonly bool windows = Platform.IsWindows
 

Properties

static Mod[] Mods [get, private set]
 

Static Private Member Functions

static void DisplayLoadError (string msg, Exception e, bool fatal, bool continueIsRetry=false)
 
static void DotNet45Check ()
 
static bool 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 25 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 void Terraria.ModLoader.ModLoader.DotNet45Check ( )
staticprivate

Definition at line 163 of file ModLoader.cs.

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

163  {
164  if (FrameworkVersion.Framework != Framework.NetFramework || FrameworkVersion.Version >= new Version(4, 5))
165  return;
166 
167  var msg = Language.GetTextValue("tModLoader.LoadErrorDotNet45Required");
168 #if CLIENT
169  MessageBox.Show(msg);
170  Process.Start("https://www.microsoft.com/net/download/thank-you/net472");
171 #else
172  Console.ForegroundColor = ConsoleColor.Red;
173  Console.WriteLine(msg);
174  Console.ResetColor();
175  Console.WriteLine("Press any key to exit...");
176  Console.ReadKey();
177 #endif
178  Environment.Exit(-1);
179  }
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.

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 bool Terraria.ModLoader.ModLoader.SoundExists ( string  name)
static
static bool Terraria.ModLoader.ModLoader.TextureExists ( string  name)
static
static bool Terraria.ModLoader.ModLoader.Unload ( )
staticprivate

Definition at line 192 of file ModLoader.cs.

References Terraria.ModLoader.Console.

192  {
193  try {
194  Logging.tML.Info("Unloading mods");
195  if (Main.dedServ) {
196  Console.WriteLine("Unloading mods...");
197  } else {
198  Main.menuMode = Interface.unloadModsID;
199  Interface.unloadModsProgress.SetLoadStage("tModLoader.MSUnloading", Mods.Length);
200  }
201 
202  ModContent.UnloadModContent();
203  Mods = new Mod[0];
204  modsByName.Clear();
205  ModContent.Unload();
206 
207  MemoryTracking.Clear();
208  Thread.MemoryBarrier();
209  GC.Collect();
210  badUnloaders.Clear();
211  foreach (var mod in weakModReferences.Where(r => r.IsAlive).Select(r => (Mod)r.Target)) {
212  Logging.tML.WarnFormat("{0} not fully unloaded during unload.", mod.Name);
213  badUnloaders.Add(mod.Name);
214  }
215 
216  return true;
217  }
218  catch (Exception e) {
219  var msg = Language.GetTextValue("tModLoader.UnloadError");
220 
221  if (e.Data.Contains("mod"))
222  msg += "\n" + Language.GetTextValue("tModLoader.DefensiveUnload", e.Data["mod"]);
223 
224  Logging.tML.Fatal(msg, e);
225  DisplayLoadError(msg, e, true);
226 
227  return false;
228  }
229  }
Command can be used in server console during MP.
static WeakReference[] weakModReferences
Definition: ModLoader.cs:55
static void DisplayLoadError(string msg, Exception e, bool fatal, bool continueIsRetry=false)
Definition: ModLoader.cs:231
static readonly IDictionary< string, Mod > modsByName
Definition: ModLoader.cs:54

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 = 0
static

Definition at line 31 of file ModLoader.cs.

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

Definition at line 29 of file ModLoader.cs.

readonly string Terraria.ModLoader.ModLoader.compressedPlatformRepresentation = Platform.IsWindows ? "w" : (Platform.IsLinux ? "l" : "m")
static

Definition at line 48 of file ModLoader.cs.

string Terraria.ModLoader.ModLoader.CompressedPlatformRepresentation => (Platform.IsWindows ? "w" : (Platform.IsLinux ? "l" : "m")) + (GoGVerifier.IsGoG ? "g" : "s") + (FrameworkVersion.Framework == Framework.NetFramework ? "n" : (FrameworkVersion.Framework == Framework.Mono ? "o" : "u"))
static

Definition at line 50 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.linux = Platform.IsLinux
static

Definition at line 43 of file ModLoader.cs.

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

Definition at line 89 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.mac = Platform.IsOSX
static

Definition at line 45 of file ModLoader.cs.

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

Definition at line 92 of file ModLoader.cs.

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

Definition at line 52 of file ModLoader.cs.

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

Definition at line 54 of file ModLoader.cs.

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

Definition at line 60 of file ModLoader.cs.

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

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

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

Definition at line 55 of file ModLoader.cs.

readonly bool Terraria.ModLoader.ModLoader.windows = Platform.IsWindows
static

Definition at line 41 of file ModLoader.cs.

Property Documentation