TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ CompileMod()

void Terraria.ModLoader.Core.ModCompile.CompileMod ( BuildingMod mod,
out byte[] code,
out byte[] pdb )
inlineprivate

Definition at line 401 of file ModCompile.cs.

402 {
403 status.SetStatus(Language.GetTextValue("tModLoader.Compiling", mod.Name + ".dll"));
404 string tempDir = Path.Combine(mod.path, "compile_temp");
405 if (Directory.Exists(tempDir))
406 {
408 }
409 Directory.CreateDirectory(tempDir);
411 refs.AddRange(GetTerrariaReferences());
412 refs.AddRange(mod.properties.dllReferences.Select((string dllName) => DllRefPath(mod, dllName)));
413 foreach (LocalMod refMod in FindReferencedMods(mod.properties))
414 {
415 using (refMod.modFile.Open())
416 {
417 string path = Path.Combine(tempDir, refMod?.ToString() + ".dll");
418 File.WriteAllBytes(path, refMod.modFile.GetModAssembly());
419 refs.Add(path);
420 string[] dllReferences = refMod.properties.dllReferences;
421 foreach (string refDll in dllReferences)
422 {
423 path = Path.Combine(tempDir, refDll + ".dll");
424 File.WriteAllBytes(path, refMod.modFile.GetBytes("lib/" + refDll + ".dll"));
425 refs.Add(path);
426 }
427 }
428 }
429 string[] files = (from file in Directory.GetFiles(mod.path, "*.cs", SearchOption.AllDirectories)
430 where !IgnoreCompletely(mod, file)
431 select file).ToArray();
432 string unsafeParam;
433 bool _allowUnsafe = default(bool);
434 bool allowUnsafe = Program.LaunchParameters.TryGetValue("-unsafe", out unsafeParam) && bool.TryParse(unsafeParam, out _allowUnsafe) && _allowUnsafe;
436 if (Program.LaunchParameters.TryGetValue("-define", out var defineParam))
437 {
438 preprocessorSymbols.AddRange(defineParam.Split(';', ' '));
439 }
440 if (BuildInfo.IsStable)
441 {
442 string tmlVersionPreprocessorSymbol = $"TML_{BuildInfo.tMLVersion.Major}_{BuildInfo.tMLVersion.Minor:D2}";
444 }
445 Diagnostic[] results = RoslynCompile(mod.Name, refs, files, preprocessorSymbols.ToArray(), allowUnsafe, out code, out pdb);
446 int numWarnings = results.Count((Diagnostic e) => e.Severity == DiagnosticSeverity.Warning);
447 int numErrors = results.Length - numWarnings;
448 status.LogCompilerLine(Language.GetTextValue("tModLoader.CompilationResult", numErrors, numWarnings), Level.Info);
449 Diagnostic[] array = results;
450 foreach (Diagnostic line in array)
451 {
452 status.LogCompilerLine(line.ToString(), (line.Severity == DiagnosticSeverity.Warning) ? Level.Warn : Level.Error);
453 }
454 try
455 {
456 if (Directory.Exists(tempDir))
457 {
459 }
460 }
461 catch (Exception)
462 {
463 }
464 if (numErrors > 0)
465 {
466 Diagnostic firstError = results.First((Diagnostic e) => e.Severity == DiagnosticSeverity.Error);
467 throw new BuildException(Language.GetTextValue("tModLoader.CompileError", mod.Name + ".dll", numErrors, numWarnings) + $"\nError: {firstError}");
468 }
469 }
static string GetTextValue(string key)
Retrieves the text value for a specified localization key. The text returned will be for the currentl...
Definition Language.cs:35
Contains methods to access or retrieve localization values. The Localization Guideteaches more about ...
Definition Language.cs:12
static Diagnostic[] RoslynCompile(string name, List< string > references, string[] files, string[] preprocessorSymbols, bool allowUnsafe, out byte[] code, out byte[] pdb)
Compile a dll for the mod based on required includes.
static IEnumerable< string > GetTerrariaReferences()
List< LocalMod > FindReferencedMods(BuildProperties properties)
string DllRefPath(BuildingMod mod, string dllName)
bool IgnoreCompletely(BuildingMod mod, string resource)
void LogCompilerLine(string msg, Level level)

References Terraria.ModLoader.Core.ModCompile.DllRefPath(), Terraria.ModLoader.Core.ModCompile.FindReferencedMods(), Terraria.ModLoader.Core.ModCompile.GetTerrariaReferences(), Terraria.Localization.Language.GetTextValue(), Terraria.ModLoader.Core.ModCompile.IgnoreCompletely(), Terraria.ModLoader.BuildInfo.IsStable, Terraria.Program.LaunchParameters, Terraria.ModLoader.Core.ModCompile.IBuildStatus.LogCompilerLine(), Terraria.ModLoader.Core.LocalMod.Name, Terraria.ModLoader.Core.ModCompile.BuildingMod.path, Terraria.ModLoader.Core.LocalMod.properties, Terraria.ModLoader.Core.ModCompile.RoslynCompile(), Terraria.ModLoader.Core.ModCompile.IBuildStatus.SetStatus(), and Terraria.ModLoader.Core.ModCompile.status.

Referenced by Terraria.ModLoader.Core.ModCompile.BuildMod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: