Terraria ModLoader  0.11.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 string GetOwnerName (Delegate d)
 
static void NativeAccessCheck (Assembly asm)
 
static string StringRep (MethodBase m)
 

Static Private Attributes

static Dictionary< Type, string > defaultAliases
 
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 string Terraria.ModLoader.MonoModHooks.GetOwnerName ( Delegate  d)
staticprivate

Definition at line 100 of file MonoModHooks.cs.

100  {
101  return d.Method.DeclaringType.Assembly.GetName().Name;
102  }
static void Terraria.ModLoader.MonoModHooks.NativeAccessCheck ( Assembly  asm)
staticprivate

Definition at line 83 of file MonoModHooks.cs.

83  {
84  if (NativeDetouringGranted.Contains(asm))
85  return;
86 
87  throw new UnauthorizedAccessException(
88  $"Native detouring permissions not granted to {asm.GetName().Name}. \n" +
89  $"Mods should use HookEndpointManager for compatibility. \n" +
90  $"If Detour or NativeDetour are required, call MonoModHooks.RequestNativeAccess()");
91  }
static HashSet< Assembly > NativeDetouringGranted
Definition: MonoModHooks.cs:36
static void Terraria.ModLoader.MonoModHooks.RequestNativeAccess ( )
static

Definition at line 93 of file MonoModHooks.cs.

93  {
94  var stack = new StackTrace();
95  var asm = stack.GetFrame(1).GetMethod().DeclaringType.Assembly;
96  NativeDetouringGranted.Add(asm);
97  Logging.tML.Warn($"Granted native detouring access to {asm.GetName().Name}");
98  }
static HashSet< Assembly > NativeDetouringGranted
Definition: MonoModHooks.cs:36
static string Terraria.ModLoader.MonoModHooks.StringRep ( MethodBase  m)
staticprivate

Definition at line 104 of file MonoModHooks.cs.

References Terraria.ModLoader.Mod.Name.

104  {
105  var paramString = string.Join(", ", m.GetParameters().Select(p => {
106  var t = p.ParameterType;
107  var s = "";
108 
109  if (t.IsByRef) {
110  s = p.IsOut ? "out " : "ref ";
111  t = t.GetElementType();
112  }
113 
114  return s + (defaultAliases.TryGetValue(t, out string n) ? n : t.Name);
115  }));
116 
117  var owner = m.DeclaringType?.FullName ??
118  (m is DynamicMethod ? "dynamic" : "unknown");
119  return $"{owner}::{m.Name}({paramString})";
120  }
static Dictionary< Type, string > defaultAliases
Definition: MonoModHooks.cs:17

Member Data Documentation

Dictionary<Type, string> Terraria.ModLoader.MonoModHooks.defaultAliases
staticprivate
Initial value:
= new Dictionary<Type, string> {
{ typeof(object), "object" },
{ typeof(bool), "bool" },
{ typeof(float), "float" },
{ typeof(double), "double" },
{ typeof(decimal), "decimal" },
{ typeof(byte), "byte" },
{ typeof(sbyte), "sbyte" },
{ typeof(short), "short" },
{ typeof(ushort), "ushort" },
{ typeof(int), "int" },
{ typeof(uint), "uint" },
{ typeof(long), "long" },
{ typeof(ulong), "ulong" },
{ typeof(char), "char" },
{ typeof(string), "string" }
}

Definition at line 17 of file MonoModHooks.cs.

bool Terraria.ModLoader.MonoModHooks.isInitialized
staticprivate

Definition at line 38 of file MonoModHooks.cs.

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

Definition at line 35 of file MonoModHooks.cs.

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

Definition at line 36 of file MonoModHooks.cs.