Terraria ModLoader  0.11.4
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 17 of file MonoModHooks.cs.

Member Function Documentation

static string Terraria.ModLoader.MonoModHooks.GetOwnerName ( Delegate  d)
staticprivate

Definition at line 98 of file MonoModHooks.cs.

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

Definition at line 81 of file MonoModHooks.cs.

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

Definition at line 91 of file MonoModHooks.cs.

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

Definition at line 102 of file MonoModHooks.cs.

References Terraria.ModLoader.Mod.Name.

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

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 19 of file MonoModHooks.cs.

bool Terraria.ModLoader.MonoModHooks.isInitialized
staticprivate

Definition at line 40 of file MonoModHooks.cs.

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

Definition at line 37 of file MonoModHooks.cs.

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

Definition at line 38 of file MonoModHooks.cs.