Terraria ModLoader  0.11.1
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 bool isInitialized
 
static DetourModManager manager = new DetourModManager()
 
static HashSet< Assembly > NativeDetouringGranted = new HashSet<Assembly>()
 

Detailed Description

Definition at line 16 of file MonoModHooks.cs.

Member Function Documentation

◆ GetOwnerName()

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

Definition at line 78 of file MonoModHooks.cs.

78  {
79  return d.Method.DeclaringType.Assembly.GetName().Name;
80  }

◆ NativeAccessCheck()

static void Terraria.ModLoader.MonoModHooks.NativeAccessCheck ( Assembly  asm)
staticprivate

Definition at line 61 of file MonoModHooks.cs.

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

◆ RequestNativeAccess()

static void Terraria.ModLoader.MonoModHooks.RequestNativeAccess ( )
static

Definition at line 71 of file MonoModHooks.cs.

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

◆ StringRep()

static string Terraria.ModLoader.MonoModHooks.StringRep ( MethodBase  m)
staticprivate

Definition at line 82 of file MonoModHooks.cs.

References Terraria.ModLoader.Mod.Name.

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

Member Data Documentation

◆ isInitialized

bool Terraria.ModLoader.MonoModHooks.isInitialized
staticprivate

Definition at line 21 of file MonoModHooks.cs.

◆ manager

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

Definition at line 18 of file MonoModHooks.cs.

◆ NativeDetouringGranted

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

Definition at line 19 of file MonoModHooks.cs.