Terraria ModLoader  0.11.1
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, 1)
 
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 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 24 of file ModLoader.cs.

Member Function Documentation

◆ DisplayLoadError()

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

Definition at line 216 of file ModLoader.cs.

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

216  {
217  msg += "\n\n" + (e.Data.Contains("hideStackTrace") ? e.Message : e.ToString());
218 
219  if (Main.dedServ) {
220  Console.ForegroundColor = ConsoleColor.Red;
221  Console.WriteLine(msg);
222  Console.ResetColor();
223 
224  if (fatal) {
225  Console.WriteLine("Press any key to exit...");
226  Console.ReadKey();
227  Environment.Exit(-1);
228  }
229  else {
230  Reload();
231  }
232  }
233  else {
234  Interface.errorMessage.Show(msg,
235  gotoMenu: fatal ? -1 : Interface.reloadModsID,
236  webHelpURL: e.HelpLink,
237  showRetry: continueIsRetry,
238  showSkip: !fatal);
239  }
240  }
Command can be used in server console during MP.
Sandstorm, Hell, Above surface during Eclipse, Space

◆ DotNet45Check()

static void Terraria.ModLoader.ModLoader.DotNet45Check ( )
staticprivate

Definition at line 157 of file ModLoader.cs.

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

157  {
158  if (FrameworkVersion.Framework != Framework.NetFramework || FrameworkVersion.Version >= new Version(4, 5))
159  return;
160 
161  var msg = Language.GetTextValue("tModLoader.LoadErrorDotNet45Required");
162 #if CLIENT
163  MessageBox.Show(msg);
164  Process.Start("https://www.microsoft.com/net/download/thank-you/net472");
165 #else
166  Console.ForegroundColor = ConsoleColor.Red;
167  Console.WriteLine(msg);
168  Console.ResetColor();
169  Console.WriteLine("Press any key to exit...");
170  Console.ReadKey();
171 #endif
172  Environment.Exit(-1);
173  }
Command can be used in server console during MP.
Sandstorm, Hell, Above surface during Eclipse, Space

◆ FileExists()

static bool Terraria.ModLoader.ModLoader.FileExists ( string  name)
static

◆ GetFileBytes()

static byte [] Terraria.ModLoader.ModLoader.GetFileBytes ( string  name)
static

◆ GetLoadedMods()

static string [] Terraria.ModLoader.ModLoader.GetLoadedMods ( )
static

◆ GetMod() [1/2]

◆ GetMod() [2/2]

static Mod Terraria.ModLoader.ModLoader.GetMod ( int  index)
static

◆ GetMusic()

static Music Terraria.ModLoader.ModLoader.GetMusic ( string  name)
static

◆ GetSound()

static SoundEffect Terraria.ModLoader.ModLoader.GetSound ( string  name)
static

◆ GetTexture()

static Texture2D Terraria.ModLoader.ModLoader.GetTexture ( string  name)
static

◆ IsSignedBy()

static bool Terraria.ModLoader.ModLoader.IsSignedBy ( TmodFile  mod,
string  xmlPublicKey 
)
static

Definition at line 243 of file ModLoader.cs.

243  {
244  var f = new RSAPKCS1SignatureDeformatter();
245  var v = AsymmetricAlgorithm.Create("RSA");
246  f.SetHashAlgorithm("SHA1");
247  v.FromXmlString(xmlPublicKey);
248  f.SetKey(v);
249  return f.VerifySignature(mod.hash, mod.signature);
250  }

◆ MusicExists()

static bool Terraria.ModLoader.ModLoader.MusicExists ( string  name)
static

◆ SoundExists()

static bool Terraria.ModLoader.ModLoader.SoundExists ( string  name)
static

◆ TextureExists()

static bool Terraria.ModLoader.ModLoader.TextureExists ( string  name)
static

◆ Unload()

static void Terraria.ModLoader.ModLoader.Unload ( )
staticprivate

Definition at line 196 of file ModLoader.cs.

References Terraria.ModLoader.Console.

196  {
197  Logging.tML.Info("Unloading mods");
198  if (Main.dedServ)
199  Console.WriteLine("Unloading mods...");
200 
201  ModContent.UnloadModContent();
202  Mods = new Mod[0];
203  modsByName.Clear();
204  ModContent.Unload();
205 
206  MemoryTracking.Clear();
207  Thread.MemoryBarrier();
208  GC.Collect();
209  badUnloaders.Clear();
210  foreach (var mod in weakModReferences.Where(r => r.IsAlive).Select(r => (Mod)r.Target)) {
211  Logging.tML.WarnFormat("{0} not fully unloaded during unload.", mod.Name);
212  badUnloaders.Add(mod.Name);
213  }
214  }
Command can be used in server console during MP.
static WeakReference [] weakModReferences
Definition: ModLoader.cs:54
static readonly IDictionary< string, Mod > modsByName
Definition: ModLoader.cs:53

Member Data Documentation

◆ _enabledMods

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

◆ beta

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

Definition at line 30 of file ModLoader.cs.

◆ branchName

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

Definition at line 28 of file ModLoader.cs.

◆ compressedPlatformRepresentation

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

Definition at line 47 of file ModLoader.cs.

◆ CompressedPlatformRepresentation

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

◆ linux

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

Definition at line 42 of file ModLoader.cs.

◆ LoadedMods

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

Definition at line 88 of file ModLoader.cs.

◆ mac

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

Definition at line 44 of file ModLoader.cs.

◆ ModCount

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

Definition at line 91 of file ModLoader.cs.

◆ ModPath

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

Definition at line 51 of file ModLoader.cs.

◆ modsByName

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

Definition at line 53 of file ModLoader.cs.

◆ steamID64

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

Definition at line 59 of file ModLoader.cs.

◆ version

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

Definition at line 26 of file ModLoader.cs.

◆ versionedName

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

Definition at line 32 of file ModLoader.cs.

◆ versionTag

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

Definition at line 35 of file ModLoader.cs.

◆ weakModReferences

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

Definition at line 54 of file ModLoader.cs.

◆ windows

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

Definition at line 40 of file ModLoader.cs.

Property Documentation

◆ Mods