BNM 2.4.0
 
Loading...
Searching...
No Matches
BNM::Class Struct Reference

Class for working with il2cpp classes. More...

#include <Class.hpp>

Public Member Functions

constexpr Class ()=default
 Create empty class.
 
 Class (const BNM::IL2CPP::Il2CppClass *_class)
 Create class from il2cpp class.
 
 Class (const BNM::IL2CPP::Il2CppObject *object)
 Create class from il2cpp object.
 
 Class (const BNM::IL2CPP::Il2CppType *type)
 Create class from il2cpp type.
 
 Class (const BNM::MonoType *type)
 Create class from mono type.
 
 Class (const BNM::CompileTimeClass &compileTimeClass)
 Create class from compile time class.
 
 Class (const std::string_view &_namespace, const std::string_view &name)
 Create class from name and namespace.
 
 Class (const std::string_view &_namespace, const std::string_view &name, const BNM::Image &image)
 Create class from name, namespace and image.
 
std::vector< BNM::ClassGetInnerClasses (bool includeParent=true) const
 Get all inner classes of target class.
 
std::vector< BNM::FieldBaseGetFields (bool includeParent=true) const
 Get all fields of target class.
 
std::vector< BNM::MethodBaseGetMethods (bool includeParent=true) const
 Get all methods of target class.
 
std::vector< BNM::PropertyBaseGetProperties (bool includeParent=true) const
 Get all properties of target class.
 
std::vector< BNM::EventBaseGetEvents (bool includeParent=true) const
 Get all events of target class.
 
BNM::MethodBase GetMethod (const std::string_view &name, int parameters=-1) const
 Get method by name and parameters count.
 
BNM::MethodBase GetMethod (const std::string_view &name, const std::initializer_list< std::string_view > &parameterNames) const
 Get method by name and parameters name.
 
BNM::MethodBase GetMethod (const std::string_view &name, const std::initializer_list< BNM::CompileTimeClass > &parameterTypes) const
 Get method by name and parameters types.
 
BNM::PropertyBase GetProperty (const std::string_view &name) const
 Get property by name.
 
BNM::Class GetInnerClass (const std::string_view &name) const
 Get inner class by name.
 
BNM::FieldBase GetField (const std::string_view &name) const
 Get field by name.
 
BNM::EventBase GetEvent (const std::string_view &name) const
 Get event by name.
 
BNM::Class GetParent () const
 Get parent.
 
BNM::Class GetArray () const
 Get array class.
 
BNM::Class GetPointer () const
 Get pointer to class.
 
BNM::Class GetReference () const
 Get reference class.
 
BNM::Class GetGeneric (const std::initializer_list< BNM::CompileTimeClass > &templateTypes) const
 Get typed generic class.
 
BNM::IL2CPP::Il2CppType * GetIl2CppType () const
 Get Il2CppType.
 
BNM::MonoTypeGetMonoType () const
 Get MonoType.
 
BNM::IL2CPP::Il2CppClass * GetClass () const
 Get Il2CppClass.
 
BNM::CompileTimeClass GetCompileTimeClass () const
 Get CompileTimeClass.
 
BNM::Image GetImage () const
 Get Image of class.
 
 operator BNM::IL2CPP::Il2CppType * () const
 Get Il2CppType.
 
 operator BNM::MonoType * () const
 Get MonoType.
 
 operator BNM::IL2CPP::Il2CppClass * () const
 Get Il2CppClass.
 
 operator BNM::CompileTimeClass () const
 Get CompileTimeClass.
 
BNM::IL2CPP::Il2CppObject * CreateNewInstance () const
 Create class instance.
 
template<typename T>
BNM::Structures::Mono::Array< T > * NewArray (IL2CPP::il2cpp_array_size_t size=0) const
 Create array of this type.
 
template<typename T>
Structures::Mono::List< T > * NewList () const
 Create list of this type.
 
template<typename T>
Structures::Mono::List< T > * NewListBNM () const
 Create list of this type.
 
template<typename T, typename = std::enable_if<!std::is_pointer<T>::value>>
IL2CPP::Il2CppObject * BoxObject (T obj) const
 Box object of this type.
 
template<typename ... Parameters>
BNM::IL2CPP::Il2CppObject * CreateNewObjectParameters (Parameters ...parameters) const
 Create class instance.
 
template<typename ... Parameters>
BNM::IL2CPP::Il2CppObject * CreateNewObjectTypes (const std::initializer_list< std::string_view > &parameterNames, Parameters ...parameters) const
 Create class instance.
 
bool IsValid () const
 Check if class is valid.
 
bool Alive () const
 Check if class is valid.
 
 operator bool () const
 Check if class is valid.
 
std::string str () const
 Get full class name.
 

Public Attributes

BNM::IL2CPP::Il2CppClass * _data {}
 

Detailed Description

Class for working with il2cpp classes.

This class allows to find classes or get class from types, objects and work with it.

Constructor & Destructor Documentation

◆ Class() [1/7]

BNM::Class::Class ( const BNM::IL2CPP::Il2CppClass * _class)
inline

Create class from il2cpp class.

Parameters
_classIl2cpp class

◆ Class() [2/7]

BNM::Class::Class ( const BNM::IL2CPP::Il2CppObject * object)

Create class from il2cpp object.

Creates class using type of object, that passed as parameter.

Parameters
objectIl2cpp object

◆ Class() [3/7]

BNM::Class::Class ( const BNM::IL2CPP::Il2CppType * type)

Create class from il2cpp type.

Creates class using type, that passed as parameter.

Parameters
typeIl2cpp type

◆ Class() [4/7]

BNM::Class::Class ( const BNM::MonoType * type)

Create class from mono type.

Creates class using mono type (il2cpp vm's type), that passed as parameter.

Parameters
typeMono type

◆ Class() [5/7]

BNM::Class::Class ( const BNM::CompileTimeClass & compileTimeClass)

Create class from compile time class.

Creates class using compile time class, that passed as parameter.

Parameters
compileTimeClassCompileTimeClass type

◆ Class() [6/7]

BNM::Class::Class ( const std::string_view & _namespace,
const std::string_view & name )

Create class from name and namespace.

Trying to find class using namespace and name in all assemblies.

Parameters
_namespaceClass namespace
nameClass name

◆ Class() [7/7]

BNM::Class::Class ( const std::string_view & _namespace,
const std::string_view & name,
const BNM::Image & image )

Create class from name, namespace and image.

Trying to find class using namespace and name in target image.

Parameters
_namespaceClass namespace
nameClass name
imageTarget image

Member Function Documentation

◆ Alive()

bool BNM::Class::Alive ( ) const
inlinenodiscard

Check if class is valid.

Alias of IsValid().

Returns
State of class

◆ BoxObject()

template<typename T, typename = std::enable_if<!std::is_pointer<T>::value>>
IL2CPP::Il2CppObject * BNM::Class::BoxObject ( T obj) const
inline

Box object of this type.

Box object that you pass into it, used to pass int and other system types as Il2CppObject. If you unsure, read C# documentation about object boxing.

Template Parameters
TNon pointer object type
Returns
Boxed object

◆ CreateNewInstance()

BNM::IL2CPP::Il2CppObject * BNM::Class::CreateNewInstance ( ) const
nodiscard

Create class instance.

Creates instance of current class. The same as new Object() in C#, but without calling the constructor (.ctor).

Returns
New instance

◆ CreateNewObjectParameters()

template<typename ... Parameters>
BNM::IL2CPP::Il2CppObject * BNM::Class::CreateNewObjectParameters ( Parameters ... parameters) const

Create class instance.

Creates instance of current class and calls constructor. The same as new Object() in C# with calling the constructor by number of parameters.

Template Parameters
ParametersConstructor parameter types
Parameters
parametersConstructor parameters
Returns
New instance

◆ CreateNewObjectTypes()

template<typename ... Parameters>
BNM::IL2CPP::Il2CppObject * BNM::Class::CreateNewObjectTypes ( const std::initializer_list< std::string_view > & parameterNames,
Parameters ... parameters ) const

Create class instance.

Creates instance of current class and calls constructor. The same as new Object() in C# with calling the constructor by parameter names.

Template Parameters
ParametersConstructor parameters
Parameters
parametersConstructor parameters
Returns
New instance

◆ GetArray()

BNM::Class BNM::Class::GetArray ( ) const
nodiscard

Get array class.

Gets array class of current class (class[]).

Returns
Array class

◆ GetClass()

BNM::IL2CPP::Il2CppClass * BNM::Class::GetClass ( ) const
inlinenodiscard

Get Il2CppClass.

Gets Il2CppClass object of current class.

Returns
Il2CppClass

◆ GetCompileTimeClass()

BNM::CompileTimeClass BNM::Class::GetCompileTimeClass ( ) const
nodiscard

Get CompileTimeClass.

Gets CompileTimeClass of current class.

Returns
CompileTimeClass of class

◆ GetEvent()

BNM::EventBase BNM::Class::GetEvent ( const std::string_view & name) const
nodiscard

Get event by name.

Tries to get event using its name. If event isn't found in target class, the code will search event in parents.

Parameters
nameTarget event name
Returns
EventBase object

◆ GetEvents()

std::vector< BNM::EventBase > BNM::Class::GetEvents ( bool includeParent = true) const
nodiscard

Get all events of target class.

Gets all events of target class and of its parent.

Parameters
includeParentShould include events from parents
Returns
Vector of events if anyone of them exists.

◆ GetField()

BNM::FieldBase BNM::Class::GetField ( const std::string_view & name) const
nodiscard

Get field by name.

Tries to get field using its name. If field isn't found in target class, the code will search field in parents.

Parameters
nameTarget field name
Returns
FieldBase object

◆ GetFields()

std::vector< BNM::FieldBase > BNM::Class::GetFields ( bool includeParent = true) const
nodiscard

Get all fields of target class.

Gets all fields of target class and of its parents.

Parameters
includeParentShould include fields from parents
Returns
Vector of fields if anyone of them exists.

◆ GetGeneric()

BNM::Class BNM::Class::GetGeneric ( const std::initializer_list< BNM::CompileTimeClass > & templateTypes) const
nodiscard

Get typed generic class.

Gets typed generic class of current class (class <types from the list>).

Parameters
templateTypesList of template types
Returns
Typed generic class

◆ GetIl2CppType()

BNM::IL2CPP::Il2CppType * BNM::Class::GetIl2CppType ( ) const
nodiscard

Get Il2CppType.

Gets Il2CppType object of current class.

Returns
Il2CppType of class

◆ GetImage()

BNM::Image BNM::Class::GetImage ( ) const
nodiscard

Get Image of class.

Gets Image of current class.

Returns
Image

◆ GetInnerClass()

BNM::Class BNM::Class::GetInnerClass ( const std::string_view & name) const
nodiscard

Get inner class by name.

Tries to get inner class using its name. If inner class isn't found in target class, the code will search inner class in parents.

Parameters
nameTarget property name
Returns
PropertyBase object

◆ GetInnerClasses()

std::vector< BNM::Class > BNM::Class::GetInnerClasses ( bool includeParent = true) const
nodiscard

Get all inner classes of target class.

Gets all inner classes of target class and of its parents.

Parameters
includeParentShould include inner classes from parents
Returns
Vector of inner classes if anyone of them exists.

◆ GetMethod() [1/3]

BNM::MethodBase BNM::Class::GetMethod ( const std::string_view & name,
const std::initializer_list< BNM::CompileTimeClass > & parameterTypes ) const
nodiscard

Get method by name and parameters types.

Tries to get method using its name and parameter types. If method isn't found in target class, the code will search method in parents.

Parameters
nameTarget method name
parameterTypesTarget method parameter types
Returns
MethodBase object

◆ GetMethod() [2/3]

BNM::MethodBase BNM::Class::GetMethod ( const std::string_view & name,
const std::initializer_list< std::string_view > & parameterNames ) const
nodiscard

Get method by name and parameters name.

Tries to get method using its name and parameter names. If method isn't found in target class, the code will search method in parents.

Parameters
nameTarget method name
parameterNamesTarget method parameter names
Returns
MethodBase object

◆ GetMethod() [3/3]

BNM::MethodBase BNM::Class::GetMethod ( const std::string_view & name,
int parameters = -1 ) const
nodiscard

Get method by name and parameters count.

Tries to get method using its name and parameters count. If method isn't found in target class, the code will search method in parents.

Parameters
nameTarget method name
parametersTarget method parameters count
Returns
MethodBase object

◆ GetMethods()

std::vector< BNM::MethodBase > BNM::Class::GetMethods ( bool includeParent = true) const
nodiscard

Get all methods of target class.

Gets all methods of target class and of its parents.

Parameters
includeParentShould include methods from parents
Returns
Vector of methods if anyone of them exists.

◆ GetMonoType()

BNM::MonoType * BNM::Class::GetMonoType ( ) const
nodiscard

Get MonoType.

Gets MonoType object of current class.

Returns
MonoType of class

◆ GetParent()

BNM::Class BNM::Class::GetParent ( ) const
nodiscard

Get parent.

Gets parent of current class.

Returns
Parent class if it exists.

◆ GetPointer()

BNM::Class BNM::Class::GetPointer ( ) const
nodiscard

Get pointer to class.

Gets pointer class of current class (class *).

Returns
Pointer class

◆ GetProperties()

std::vector< BNM::PropertyBase > BNM::Class::GetProperties ( bool includeParent = true) const
nodiscard

Get all properties of target class.

Gets all properties of target class and of its parents.

Parameters
includeParentShould include properties from parents
Returns
Vector of properties if anyone of them exists.

◆ GetProperty()

BNM::PropertyBase BNM::Class::GetProperty ( const std::string_view & name) const
nodiscard

Get property by name.

Tries to get property using its name. If property isn't found in target class, the code will search property in parents.

Parameters
nameTarget property name
Returns
PropertyBase object

◆ GetReference()

BNM::Class BNM::Class::GetReference ( ) const
nodiscard

Get reference class.

Gets reference class of current class (class &).

Returns
Reference class

◆ IsValid()

bool BNM::Class::IsValid ( ) const
inlinenodiscard

Check if class is valid.

Returns
State of class

◆ NewArray()

template<typename T>
BNM::Structures::Mono::Array< T > * BNM::Class::NewArray ( IL2CPP::il2cpp_array_size_t size = 0) const
inline

Create array of this type.

Creates new array with set size (capacity). The same as new Object[] in C#.

Parameters
sizeNew array size
Template Parameters
TArray element type
Returns
New array

◆ NewList()

template<typename T>
Structures::Mono::List< T > * BNM::Class::NewList ( ) const

Create list of this type.

Creates new list of this types. The same as new List<Object>() in C#.

Template Parameters
TList element type
Returns
New list

◆ NewListBNM()

template<typename T>
Structures::Mono::List< T > * BNM::Class::NewListBNM ( ) const
inline

Create list of this type.

Warning
It's not recommended to use for beginners!

Creates new list of this types, but new list will use BNM code instead of il2cpp. This can be useful if you want to create list of struct that doesn't exist in target Unity app.

Template Parameters
TList element type
Returns
New list

◆ operator BNM::CompileTimeClass()

BNM::Class::operator BNM::CompileTimeClass ( ) const

◆ operator BNM::IL2CPP::Il2CppClass *()

BNM::Class::operator BNM::IL2CPP::Il2CppClass * ( ) const
inline

Get Il2CppClass.

Alias of GetClass().

Returns
Il2CppClass

◆ operator BNM::IL2CPP::Il2CppType *()

BNM::Class::operator BNM::IL2CPP::Il2CppType * ( ) const
inline

Get Il2CppType.

Alias of GetIl2CppType().

Returns
Il2CppType of class

◆ operator BNM::MonoType *()

BNM::Class::operator BNM::MonoType * ( ) const
inline

Get MonoType.

Alias of GetMonoType().

Returns
MonoType of class

◆ operator bool()

BNM::Class::operator bool ( ) const
inline

Check if class is valid.

Alias of IsValid().

Returns
State of class

◆ str()

std::string BNM::Class::str ( ) const
inlinenodiscard

Get full class name.

Returns string with full class name: [Image name]::[Namespace]::[Name]->[Inner name]

Returns
Class full name or "Dead class"