You are viewing a potentially older version of this package. View all versions.
LordAshes-GenericClassPlugin-1.0.0 icon

GenericClassPlugin

Provides reflection access to types, methods, field, properties and events

Date uploaded 5 days ago
Version 1.0.0
Download link LordAshes-GenericClassPlugin-1.0.0.zip
Downloads 7
Dependency string LordAshes-GenericClassPlugin-1.0.0

This mod requires the following mods to function

bbepisTaleSpire-BepInExPack-5.4.10 icon
bbepisTaleSpire-BepInExPack

Unified BepInEx all-in-one modding pack - plugin framework, detour library

Preferred version: 5.4.10
brcoding-SetInjectionFlagPlugin-2.3.0 icon
brcoding-SetInjectionFlagPlugin

Allows players to flag mods are installed

Preferred version: 2.3.0

README

Generic Class Plugin

This unofficial TaleSpire dependency pluigin which allows plugins to access types, methods, fields, properties and events using reflection. This allows plugins to access BR libraries without needing to add the BR assembly as a reference which makes the plugin more resilient if BR changes the namespace or location of the type.

Install

Use R2ModMan or similar installer to install this asset pack.

Generally this plugin will be added automatically as a dependency of another plugin that uses it.

Usage

The plugin exposes the Generic class as LordAshes.GenClassPlugin.Generic.

Static types

To reference a static type use a syntax similart to:

LordAshes.GenClassPlugin.Generic _InitiativeManager = new GenClassPlugin.Generic("InitiativeManager");

Non-Static types

To reference instances of a type use a syntax similar to:

LordAshes.GenClassPlugin.Generic cid = new GenClassPlugin.Generic("CreatureGuid", genericElement.GetType().GetRuntimeField("CreatureGuid").GetValue(genericElement));

In the example above CreatureGuid is the type and we provide it a instance from the property of another object.

Resolving ambiguity

In some cases, the name alone is not sufficient to identify a type becuase there may be many different sources that use the same type name. Since using a full namespace name would defeat the purpose of this endeavour, a mechanism is provided to try to narrow down the choice.

When calling the Generic constructor, the second parameter can be an array of strings. This lists fields and/or properties that the type must have in addition to matching the name.

For example:

LordAshes.GenClassPlugin.Generic _InitiativeManager = new GenClassPlugin.Generic("InitiativeManager", new string[] { "TurnIndex", "TurnsCount" });

Generic Class

The Generic class provides a way to store and interact with objects of various types without needing to provide a reference to that type. By avoiding any direct reference to any non-referenced types, adding references can be avoided and this means a more resilient solution if those (no longer referenced) assemblies change.

The Generic class provides:

Instance(): A reference to the instance of the given class. Type(): A reference to the type. Invoke(method,parameters): Executes a method on a static type or a type instance. The first parameter is the method name. Following parameters are the parameters sent to the method. Get(name): Gets the value of a field or proprty with the given name. Set(name, value): Sets the value of a field or proprty with the given name. AddEvent(name, handler): Adds a handler to the name event.

Assembly access

The Generic Class plugin does not actually load any assemblies. As such, it has access to any types that have already been loaded into memory. Since the main purpose of this plugin is to provide access to BR types and the BR types would be loaded by core Talespire, any types in BR assemblies should be available. As such, if using this to access types besides BR assembly types, it may be necessary to load the assembley into memory before being able to access it with this plugin.

CHANGELOG

1.0.4: Added GetAsGeneric
1.0.4: More Constructor Options
1.0.3: Improvements to Invoke and Method
1.0.2: Improvements to the Info method
1.0.1: Exposed Method to make Harmony patching easier
1.0.0: Initial release