tModLoader v0.11.8.9
A mod to make and play 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

◆ GetOwnerName()

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 }

◆ NativeAccessCheck()

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

References Terraria.ModLoader.MonoModHooks.NativeDetouringGranted.

◆ RequestNativeAccess()

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;
97 Logging.tML.Warn($"Granted native detouring access to {asm.GetName().Name}");
98 }

References Terraria.ModLoader.MonoModHooks.NativeDetouringGranted.

◆ StringRep()

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

Definition at line 104 of file MonoModHooks.cs.

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

References Terraria.ModLoader.MonoModHooks.defaultAliases.

Member Data Documentation

◆ defaultAliases

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.

Referenced by Terraria.ModLoader.MonoModHooks.StringRep().

◆ isInitialized

bool Terraria.ModLoader.MonoModHooks.isInitialized
staticprivate

Definition at line 38 of file MonoModHooks.cs.

◆ manager

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

Definition at line 35 of file MonoModHooks.cs.

◆ NativeDetouringGranted

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