Managed
The game’s C# runtime: Mono, IL2CPP or CoreCLR. Classes go by C# name, like Game.Player or
Game.Player/Stats for nested ones. Address text takes Class:Method+0x3a too.
Any thread, but calls queue on Wraith’s one runtime thread, so look things up once. Classes, fields and methods don’t move. Returned text and slices are good till the thread’s next call into Wraith.
Objects are addresses. CoreCLR’s GC moves them, so hold ones you keep and use heldAt before each use.
Managed
Section titled “Managed”Get it with Api.managed().
runtimeKind(): Wraith.Managed.Kindrunning(): Promise<void>images(): Array<string>classes(image: string): Array<string>find(class_name: string): Wraith.Managed.Classfields(class_name: string): Array<Wraith.Managed.Field>methods(class_name: string): Array<Wraith.Managed.Method>fieldOffset(class_name: string, field: string): numberstaticAddress(class_name: string, field: string): numberfindMethod(class_name: string, name: string, params: number): numbericall(class_name: string, method: string): numbertypeObject(class_name: string): numbercallNative(function_: number | bigint): numberinvoke(class_name: string, method: string, target: number | bigint, args: Array<import("salamander").Given<Wraith.Managed.Value>>): Wraith.Managed.Valuehold(object: number | bigint): numberrelease(handle: number): voidheldAt(handle: number): numberclassOf(object: number | bigint): stringreadString(address: number | bigint): stringgetField(object: number | bigint, field: string): Wraith.Managed.ValuesetField(object: number | bigint, field: string, value: import("salamander").Given<Wraith.Managed.Value>): voidruntimeKind(): Wraith.Managed.Kindrunning(): salamander.Promiseimages(): (string)[]classes(image: string): (string)[]find(class_name: string): Wraith.Managed.Classfields(class_name: string): (Wraith.Managed.Field)[]methods(class_name: string): (Wraith.Managed.Method)[]fieldOffset(class_name: string, field: string): integerstaticAddress(class_name: string, field: string): integerfindMethod(class_name: string, name: string, params: integer): integericall(class_name: string, method: string): integertypeObject(class_name: string): integercallNative(function_: integer): integerinvoke(class_name: string, method: string, target: integer, args: (Wraith.Managed.Value)[]): Wraith.Managed.Valuehold(object: integer): integerrelease(handle: integer)heldAt(handle: integer): integerclassOf(object: integer): stringreadString(address: integer): stringgetField(object: integer, field: string): Wraith.Managed.ValuesetField(object: integer, field: string, value: Wraith.Managed.Value)Wraith.Managed.Kind RuntimeKind()System.Threading.Tasks.Task RunningAsync(System.Threading.CancellationToken cancel = default)string[] Images()string[] Classes(string image)Wraith.Managed.Class Find(string class_name)Wraith.Managed.Field[] Fields(string class_name)Wraith.Managed.Method[] Methods(string class_name)nuint FieldOffset(string class_name, string field)nuint StaticAddress(string class_name, string field)nuint FindMethod(string class_name, string name, int @params)nuint Icall(string class_name, string method)nuint TypeObject(string class_name)nuint CallNative(nuint function)Wraith.Managed.Value Invoke(string class_name, string method, nuint target, System.Collections.Generic.IReadOnlyList<Wraith.Managed.Value> args)uint Hold(nuint @object)void Release(uint handle)nuint HeldAt(uint handle)string ClassOf(nuint @object)string ReadString(nuint address)Wraith.Managed.Value GetField(nuint @object, string field)void SetField(nuint @object, string field, Wraith.Managed.Value value)Wraith::Managed_Kind runtimeKind() constsal::Future<void, Wraith::ManagedError> running() constsal::Result<std::span<const sal::String>, Wraith::ManagedError> images() constsal::Result<std::span<const sal::String>, Wraith::ManagedError> classes(std::string_view image) constsal::Result<Wraith::Managed_Class, Wraith::ManagedError> find(std::string_view class_name) constsal::Result<std::span<const Wraith::Managed_Field>, Wraith::ManagedError> fields(std::string_view class_name) constsal::Result<std::span<const Wraith::Managed_Method>, Wraith::ManagedError> methods(std::string_view class_name) constsal::Result<uintptr_t, Wraith::ManagedError> fieldOffset(std::string_view class_name, std::string_view field) constsal::Result<uintptr_t, Wraith::ManagedError> staticAddress(std::string_view class_name, std::string_view field) constsal::Result<uintptr_t, Wraith::ManagedError> findMethod(std::string_view class_name, std::string_view name, int32_t params) constsal::Result<uintptr_t, Wraith::ManagedError> icall(std::string_view class_name, std::string_view method) constsal::Result<uintptr_t, Wraith::ManagedError> typeObject(std::string_view class_name) constsal::Result<uintptr_t, Wraith::ManagedError> callNative(uintptr_t function) constsal::Result<Wraith::Managed_Value, Wraith::ManagedError> invoke(std::string_view class_name, std::string_view method, uintptr_t target, std::span<const Wraith::Managed_Value> args) constsal::Result<uint32_t, Wraith::ManagedError> hold(uintptr_t object) constvoid release(uint32_t handle) constsal::Result<uintptr_t, Wraith::ManagedError> heldAt(uint32_t handle) constsal::Result<std::string_view, Wraith::ManagedError> classOf(uintptr_t object) constsal::Result<std::string_view, Wraith::ManagedError> readString(uintptr_t address) constsal::Result<Wraith::Managed_Value, Wraith::ManagedError> getField(uintptr_t object, std::string_view field) constsal::Result<void, Wraith::ManagedError> setField(uintptr_t object, std::string_view field, Wraith::Managed_Value value) constpub fn runtime_kind(&self) -> wraith::ManagedKindpub fn running(&self) -> salamander::Future<(), wraith::ManagedError>pub fn images(&self) -> Result<&[salamander::Str], wraith::ManagedError>pub fn classes(&self, image: &str) -> Result<&[salamander::Str], wraith::ManagedError>pub fn find(&self, class_name: &str) -> Result<wraith::ManagedClass, wraith::ManagedError>pub fn fields(&self, class_name: &str) -> Result<&[wraith::ManagedField], wraith::ManagedError>pub fn methods(&self, class_name: &str) -> Result<&[wraith::ManagedMethod], wraith::ManagedError>pub fn field_offset(&self, class_name: &str, field: &str) -> Result<usize, wraith::ManagedError>pub fn static_address(&self, class_name: &str, field: &str) -> Result<usize, wraith::ManagedError>pub fn find_method(&self, class_name: &str, name: &str, params: i32) -> Result<usize, wraith::ManagedError>pub fn icall(&self, class_name: &str, method: &str) -> Result<usize, wraith::ManagedError>pub fn type_object(&self, class_name: &str) -> Result<usize, wraith::ManagedError>pub fn call_native(&self, function: usize) -> Result<usize, wraith::ManagedError>pub fn invoke(&self, class_name: &str, method: &str, target: usize, args: &[wraith::ManagedValue]) -> Result<wraith::ManagedValue, wraith::ManagedError>pub fn hold(&self, object: usize) -> Result<u32, wraith::ManagedError>pub fn release(&self, handle: u32)pub fn held_at(&self, handle: u32) -> Result<usize, wraith::ManagedError>pub fn class_of(&self, object: usize) -> Result<&str, wraith::ManagedError>pub fn read_string(&self, address: usize) -> Result<&str, wraith::ManagedError>pub fn get_field(&self, object: usize, field: &str) -> Result<wraith::ManagedValue, wraith::ManagedError>pub fn set_field(&self, object: usize, field: &str, value: wraith::ManagedValue) -> Result<(), wraith::ManagedError>fn runtimeKind(self: Wraith.Managed) Wraith.Managed.Kindfn running(self: Wraith.Managed) rt.Promise((Wraith.ManagedError || rt.Failure)!void, Wraith.ManagedErrorCode)fn images(self: Wraith.Managed) (Wraith.ManagedError || rt.Failure)![]const []const u8fn classes(self: Wraith.Managed, image: []const u8) (Wraith.ManagedError || rt.Failure)![]const []const u8fn find(self: Wraith.Managed, class_name: []const u8) (Wraith.ManagedError || rt.Failure)!Wraith.Managed.Classfn fields(self: Wraith.Managed, class_name: []const u8) (Wraith.ManagedError || rt.Failure)![]const Wraith.Managed.Fieldfn methods(self: Wraith.Managed, class_name: []const u8) (Wraith.ManagedError || rt.Failure)![]const Wraith.Managed.Methodfn fieldOffset(self: Wraith.Managed, class_name: []const u8, field: []const u8) (Wraith.ManagedError || rt.Failure)!usizefn staticAddress(self: Wraith.Managed, class_name: []const u8, field: []const u8) (Wraith.ManagedError || rt.Failure)!usizefn findMethod(self: Wraith.Managed, class_name: []const u8, name: []const u8, params: i32) (Wraith.ManagedError || rt.Failure)!usizefn icall(self: Wraith.Managed, class_name: []const u8, method: []const u8) (Wraith.ManagedError || rt.Failure)!usizefn typeObject(self: Wraith.Managed, class_name: []const u8) (Wraith.ManagedError || rt.Failure)!usizefn callNative(self: Wraith.Managed, function: usize) (Wraith.ManagedError || rt.Failure)!usizefn invoke(self: Wraith.Managed, class_name: []const u8, method: []const u8, target: usize, args: []const Wraith.Managed.Value) (Wraith.ManagedError || rt.Failure)!Wraith.Managed.Valuefn hold(self: Wraith.Managed, object: usize) (Wraith.ManagedError || rt.Failure)!u32fn release(self: Wraith.Managed, handle: u32) voidfn heldAt(self: Wraith.Managed, handle: u32) (Wraith.ManagedError || rt.Failure)!usizefn classOf(self: Wraith.Managed, object: usize) (Wraith.ManagedError || rt.Failure)![]const u8fn readString(self: Wraith.Managed, address: usize) (Wraith.ManagedError || rt.Failure)![]const u8fn getField(self: Wraith.Managed, object: usize, field: []const u8) (Wraith.ManagedError || rt.Failure)!Wraith.Managed.Valuefn setField(self: Wraith.Managed, object: usize, field: []const u8, value: Wraith.Managed.Value) (Wraith.ManagedError || rt.Failure)!voidWraith_Managed_Kind Wraith_Managed_runtimeKind(Wraith_Managed self)sal_Promise Wraith_Managed_running(Wraith_Managed self)uint32_t Wraith_Managed_images(Wraith_Managed self, Slice_string *out)uint32_t Wraith_Managed_classes(Wraith_Managed self, sal_string image, Slice_string *out)uint32_t Wraith_Managed_find(Wraith_Managed self, sal_string class_name, Wraith_Managed_Class *out)uint32_t Wraith_Managed_fields(Wraith_Managed self, sal_string class_name, Slice_Wraith_Managed_Field *out)uint32_t Wraith_Managed_methods(Wraith_Managed self, sal_string class_name, Slice_Wraith_Managed_Method *out)uint32_t Wraith_Managed_fieldOffset(Wraith_Managed self, sal_string class_name, sal_string field, uintptr_t *out)uint32_t Wraith_Managed_staticAddress(Wraith_Managed self, sal_string class_name, sal_string field, uintptr_t *out)uint32_t Wraith_Managed_findMethod(Wraith_Managed self, sal_string class_name, sal_string name, int32_t params, uintptr_t *out)uint32_t Wraith_Managed_icall(Wraith_Managed self, sal_string class_name, sal_string method, uintptr_t *out)uint32_t Wraith_Managed_typeObject(Wraith_Managed self, sal_string class_name, uintptr_t *out)uint32_t Wraith_Managed_callNative(Wraith_Managed self, uintptr_t function, uintptr_t *out)uint32_t Wraith_Managed_invoke(Wraith_Managed self, sal_string class_name, sal_string method, uintptr_t target, Slice_Wraith_Managed_Value args, Wraith_Managed_Value *out)uint32_t Wraith_Managed_hold(Wraith_Managed self, uintptr_t object, uint32_t *out)void Wraith_Managed_release(Wraith_Managed self, uint32_t handle)uint32_t Wraith_Managed_heldAt(Wraith_Managed self, uint32_t handle, uintptr_t *out)uint32_t Wraith_Managed_classOf(Wraith_Managed self, uintptr_t object, sal_string *out)uint32_t Wraith_Managed_readString(Wraith_Managed self, uintptr_t address, sal_string *out)uint32_t Wraith_Managed_getField(Wraith_Managed self, uintptr_t object, sal_string field, Wraith_Managed_Value *out)uint32_t Wraith_Managed_setField(Wraith_Managed self, uintptr_t object, sal_string field, Wraith_Managed_Value value)runtimeKind
Section titled “runtimeKind”none till it’s running
Uses Managed.Kind.
running
Section titled “running”Waits till the game’s started its runtime, after plugins load. NotRunning if it has none.
Async. Fails with ManagedError.
images
Section titled “images”Loaded images, like Assembly-CSharp.dll
Fails with ManagedError.
classes
Section titled “classes”An image’s classes by full name, nested ones too
Fails with ManagedError.
An image’s classes by full name, nested ones too
Fails with ManagedError. Uses Managed.Class.
fields
Section titled “fields”Its own fields, not its parents’
Fails with ManagedError. Uses Managed.Field.
methods
Section titled “methods”Its own methods, not its parents’
Fails with ManagedError. Uses Managed.Method.
fieldOffset
Section titled “fieldOffset”Looks in parents too
Fails with ManagedError.
staticAddress
Section titled “staticAddress”Where a static is now. May run the static constructor. Salamander’s built-in Unsupported for
thread statics and IL2CPP before Unity 2019 or so.
Fails with ManagedError.
findMethod
Section titled “findMethod”A method’s code, with params parameters or any if -1. Looks in parents too. Mono compiles it if needed.
Fails with ManagedError.
The native function behind an extern method, callable with its C signature, this first.
Unity’s only on the game’s main thread.
Fails with ManagedError.
typeObject
Section titled “typeObject”The System.Type object for a class.
Fails with ManagedError.
callNative
Section titled “callNative”Calls function, taking nothing and giving a pointer-sized value, on Wraith’s runtime thread.
Not for Unity’s main-thread calls.
Fails with ManagedError.
invoke
Section titled “invoke”Calls a C# method by name, picking the best fitting overload. target is 0 for statics. Runs
here if the runtime knows this thread, else on Wraith’s. Structs come back boxed. .ctor with
a 0 target makes a new object.
Fails with ManagedError. Uses Managed.Value.
Keeps the object from being collected till release. Hold anything kept past the call it came
from. Released when the plugin goes. Any thread, straight away.
Fails with ManagedError.
release
Section titled “release”Fine to call twice.
heldAt
Section titled “heldAt”Where a held object is now, which only changes under CoreCLR. Any thread, straight away.
Fails with ManagedError.
classOf
Section titled “classOf”The object’s class’s full name
Fails with ManagedError.
readString
Section titled “readString”The System.String at address, as UTF-8
Fails with ManagedError.
getField
Section titled “getField”An instance field by name, parents included. Primitives and strings as themselves, structs as the address of their bytes, the rest as objects. Any thread.
Fails with ManagedError. Uses Managed.Value.
setField
Section titled “setField”Sets one through the runtime so the GC sees it. Any thread, but Unity objects want the main thread.
Fails with ManagedError. Uses Managed.Value.
ManagedError
Section titled “ManagedError”What can go wrong, besides Cancelled, Unsupported and Gone.
| Code | Error | |
|---|---|---|
| 1 | NotRunning |
The game has none, or hasn’t started it yet |
| 2 | NotFound |
|
| 3 | Unreadable |
Not an object or a string |
| 4 | Failed |
|
| 5 | Threw |
invoke’s method threw, and the message says what |
Managed.Kind
Section titled “Managed.Kind”An enum of u8.
| Value | Name | |
|---|---|---|
| 0 | none |
|
| 1 | mono |
|
| 2 | il2cpp |
|
| 3 | coreclr |
Managed.ValueKind
Section titled “Managed.ValueKind”Which of Value’s fields it is.
An enum of u8.
| Value | Name | |
|---|---|---|
| 0 | none |
|
| 1 | flag |
|
| 2 | integer |
|
| 3 | number |
|
| 4 | text |
|
| 5 | object |
Managed.Value
Section titled “Managed.Value”An invoke argument or result. Integers cover whole numbers and enums, numbers floats, text
strings, and objects the rest by address, structs and ref parameters included.
A struct, 0x30 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | kind |
Managed.ValueKind |
|
| 0x1 | flag |
bool |
|
| 0x8 | integer |
i64 |
|
| 0x10 | number |
f64 |
|
| 0x18 | text |
string |
|
| 0x28 | object |
usize |
kind: Wraith.Managed.ValueKind | Wraith.Managed.ValueKindNameflag: booleaninteger: bigintnumber: numbertext: stringobject: numberkind: Wraith.Managed.ValueKind|Wraith.Managed.ValueKindNameflag: booleaninteger: integernumber: numbertext: stringobject: integerWraith.Managed.ValueKind Kindbool Flaglong Integerdouble Numberstring Textnuint ObjectWraith::Managed_ValueKind kindbool flagint64_t integerdouble numbersal::String textuintptr_t objectpub kind: wraith::ManagedValueKindpub flag: boolpub integer: i64pub number: f64pub text: salamander::Strpub object: usizekind: Wraith.Managed.ValueKindflag: boolinteger: i64number: f64text: []const u8object: usizeWraith_Managed_ValueKind kindbool flagint64_t integerdouble numbersal_string textuintptr_t objectManaged.Class
Section titled “Managed.Class”A struct, 0x48 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | full_name |
string |
Like Game.Player, or Game.Player/Stats nested |
| 0x10 | name |
string |
Like Player |
| 0x20 | image |
string |
Like Assembly-CSharp.dll |
| 0x30 | parent |
string |
Its parent’s full name, or empty |
| 0x40 | size |
u32 |
Bytes in one, header included |
| 0x44 | value_type |
bool |
full_name: stringname: stringimage: stringparent: stringsize: numbervalue_type: booleanfull_name: stringname: stringimage: stringparent: stringsize: integervalue_type: booleanstring FullNamestring Namestring Imagestring Parentuint Sizebool ValueTypesal::String full_namesal::String namesal::String imagesal::String parentuint32_t sizebool value_typepub full_name: salamander::Strpub name: salamander::Strpub image: salamander::Strpub parent: salamander::Strpub size: u32pub value_type: boolfull_name: []const u8name: []const u8image: []const u8parent: []const u8size: u32value_type: boolsal_string full_namesal_string namesal_string imagesal_string parentuint32_t sizebool value_typeManaged.Field
Section titled “Managed.Field”A struct, 0x30 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | name |
string |
|
| 0x10 | type |
string |
Like System.Int32 or System.Collections.Generic.List<Game.Item> |
| 0x20 | offset |
usize |
From the object’s start, header included, even in value types. Statics: from the class’s static data, which staticAddress adds in. |
| 0x28 | is_static |
bool |
|
| 0x29 | literal |
bool |
A const, with no storage |
name: stringtype: stringoffset: numberis_static: booleanliteral: booleanname: stringtype: stringoffset: integeris_static: booleanliteral: booleanstring Namestring Typenuint Offsetbool IsStaticbool Literalsal::String namesal::String typeuintptr_t offsetbool is_staticbool literalpub name: salamander::Strpub r#type: salamander::Strpub offset: usizepub is_static: boolpub literal: boolname: []const u8@"type": []const u8offset: usizeis_static: boolliteral: boolsal_string namesal_string typeuintptr_t offsetbool is_staticbool literalManaged.Method
Section titled “Managed.Method”A struct, 0x38 bytes, aligned to 8.
| Offset | Field | Type | |
|---|---|---|---|
| 0x0 | name |
string |
|
| 0x10 | return_type |
string |
|
| 0x20 | params |
[]string |
Each parameter’s type |
| 0x30 | is_static |
bool |
Each parameter’s type |
name: stringreturn_type: stringparams: Array<string>is_static: booleanname: stringreturn_type: stringparams: (string)[]is_static: booleanstring Namestring ReturnTypestring[] Paramsbool IsStaticsal::String namesal::String return_typesal::Slice<sal::String> paramsbool is_staticpub name: salamander::Strpub return_type: salamander::Strpub params: salamander::Slice<salamander::Str>pub is_static: boolname: []const u8return_type: []const u8params: []const []const u8is_static: boolsal_string namesal_string return_typeSlice_string paramsbool is_staticwraith.io · Mods on the Hub · Get Wraith
Made with ♥ by Asgard
