Terraria ModLoader  0.10.1.5
A framework for Terraria mods
Terraria.ModLoader.MonoModHooks Class Reference
+ Collaboration diagram for Terraria.ModLoader.MonoModHooks:

Static Public Member Functions

static void RequestNativeAccess ()
 

Static Private Member Functions

static ModuleDefinition GenerateCecilModule (AssemblyName name)
 
static string GetOwnerName (Delegate d)
 
static void NativeAccessCheck (Assembly asm)
 
static string StringRep (MethodBase m)
 

Static Private Attributes

static bool isInitialized
 
static DetourModManager manager = new DetourModManager()
 
static HashSet< Assembly > NativeDetouringGranted = new HashSet<Assembly>()
 

Detailed Description

Definition at line 15 of file MonoModHooks.cs.

Member Function Documentation

static ModuleDefinition Terraria.ModLoader.MonoModHooks.GenerateCecilModule ( AssemblyName  name)
staticprivate

Definition at line 126 of file MonoModHooks.cs.

126  {
127  string resourceName = name.Name + ".dll";
128  resourceName = Array.Find(typeof(Program).Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));
129  if (resourceName != null) {
130  Logging.tML.DebugFormat("Generating ModuleDefinition for {0}", name);
131  using (Stream stream = typeof(Program).Assembly.GetManifestResourceStream(resourceName))
132  return ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
133  }
134 
135  var modAssemblyBytes = AssemblyManager.GetAssemblyBytes(name.Name);
136  if (modAssemblyBytes != null) {
137  Logging.tML.DebugFormat("Generating ModuleDefinition for {0}", name);
138  using (MemoryStream stream = new MemoryStream(modAssemblyBytes))
139  return ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
140  }
141 
142  return null;
143  }
static string Terraria.ModLoader.MonoModHooks.GetOwnerName ( Delegate  d)
staticprivate

Definition at line 77 of file MonoModHooks.cs.

77  {
78  return d.Method.DeclaringType.Assembly.GetName().Name;
79  }
static void Terraria.ModLoader.MonoModHooks.NativeAccessCheck ( Assembly  asm)
staticprivate

Definition at line 60 of file MonoModHooks.cs.

60  {
61  if (NativeDetouringGranted.Contains(asm))
62  return;
63 
64  throw new UnauthorizedAccessException(
65  $"Native detouring permissions not granted to {asm.GetName().Name}. \n" +
66  $"Mods should use HookEndpointManager for compatibility. \n" +
67  $"If Detour or NativeDetour are required, call MonoModHooks.RequestNativeAccess()");
68  }
static HashSet< Assembly > NativeDetouringGranted
Definition: MonoModHooks.cs:18
static void Terraria.ModLoader.MonoModHooks.RequestNativeAccess ( )
static

Definition at line 70 of file MonoModHooks.cs.

70  {
71  var stack = new StackTrace();
72  var asm = stack.GetFrame(1).GetMethod().DeclaringType.Assembly;
73  NativeDetouringGranted.Add(asm);
74  Logging.tML.Warn($"Granted native detouring access to {asm.GetName().Name}");
75  }
static HashSet< Assembly > NativeDetouringGranted
Definition: MonoModHooks.cs:18
static string Terraria.ModLoader.MonoModHooks.StringRep ( MethodBase  m)
staticprivate

Definition at line 81 of file MonoModHooks.cs.

References Terraria.ModLoader.Mod.Name.

81  {
82  var paramString = string.Join(", ", m.GetParameters().Select(p => {
83  var s = p.ParameterType.Name;
84  if (p.ParameterType.IsByRef)
85  s = p.IsOut ? "out " : "ref ";
86  return s;
87  }));
88  var owner = m.DeclaringType?.FullName ??
89  (m is DynamicMethod ? "dynamic" : "unknown");
90  return $"{owner}::{m.Name}({paramString})";
91  }

Member Data Documentation

bool Terraria.ModLoader.MonoModHooks.isInitialized
staticprivate

Definition at line 20 of file MonoModHooks.cs.

DetourModManager Terraria.ModLoader.MonoModHooks.manager = new DetourModManager()
staticprivate

Definition at line 17 of file MonoModHooks.cs.

HashSet<Assembly> Terraria.ModLoader.MonoModHooks.NativeDetouringGranted = new HashSet<Assembly>()
staticprivate

Definition at line 18 of file MonoModHooks.cs.