Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Multiverse::Api::Memory::Utils {
- struct FieldMatchInfo {
- public:
- bool isMatched;
- std::string matchedString;
- int matchedIdx;
- int matchedPadding;
- uintptr_t matchedAddress;
- bool isArray;
- bool isList;
- };
- class LibMbinMem {
- /*
- *****************************************************
- * *
- * libMbinMem by RaYRoD TV *
- * - Serves as a wrapper around libMBIN - *
- * *
- *****************************************************
- */
- private:
- // Index:
- // [SECTION] CONVERSIONS
- // [SECTION] CHECKS
- // [SECTION] GETTERS
- // [SECTION] SETTERS
- //-----------------------------------------------------------------------------
- // [SECTION] CONVERSIONS
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // [SECTION] CHECKS
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // [SECTION] GETTERS
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // [SECTION] SETTERS
- //-----------------------------------------------------------------------------
- public:
- // Index:
- // [SECTION] PRINT
- // [SECTION] CONVERSIONS
- // [SECTION] CHECKS
- // [SECTION] GETTERS
- // [SECTION] SETTERS
- //-----------------------------------------------------------------------------
- // [SECTION] PRINT
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // [SECTION] CONVERSIONS
- //-----------------------------------------------------------------------------
- static std::vector<std::string> SplitArrayFieldName(std::string fieldName);
- static Type^ ConvertType(Type^ type);
- static std::string ConvertTypeName(std::string string);
- //-----------------------------------------------------------------------------
- // [SECTION] CHECKS
- //-----------------------------------------------------------------------------
- static Type^ SearchForFieldTypeInClass(Type^ classType, String^ fieldName);
- static bool SearchForFieldInClass(Type^ classType, String^ fieldName);
- static FieldMatchInfo FindFieldMatch(std::vector<std::string>& vecString, std::vector<int>& idx, uintptr_t baseAddress, Type^ classType, Type^& matchedType);
- //-----------------------------------------------------------------------------
- // [SECTION] GETTERS
- //-----------------------------------------------------------------------------
- // - Gets the type of a field in a Class .. GcUIGlobals -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: fieldName - The name of the field to search for
- static Type^ GetFieldType(Type^ classType, std::string fieldName);
- // - Gets the relative address of a field .. 0xDEADBEEF -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static uintptr_t GetField(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- static uintptr_t GetFieldTest(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of aN Array or List field -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static MemVec_t GetField(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- // - Gets the relative address of a 'Colour' field .. .. (R, G, B, A) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- static MemColour_t GetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of a 'Colour' Array or List field .. (R, G, B, A) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static Vec_t<MemColour_t> GetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- // - Gets the relative address of a 'Vector2f' field .. (x, y) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- static MemVec2f_t GetFieldVector2f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of a 'Vector2f' Array or List field .. (x, y) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static Vec_t<MemVec2f_t> GetFieldVector2f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- // - Gets the relative address of a 'Vector3f' field .. (x, y, z) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- static MemVec3f_t GetFieldVector3f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of a 'Vector3f' Array or List field .. (x, y, z) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static Vec_t<MemVec3f_t> GetFieldVector3f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- // - Gets the relative address of a 'Vector4f' field -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- static MemVec4f_t GetFieldVector4f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of a 'Vector4f' Array or List field .. (x, y, z, t) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static Vec_t<MemVec4f_t> GetFieldVector4f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- // - Gets the relative address of a 'Quaternion' field -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- static MemQuaternion_t GetFieldQuaternion(Type^ classType, uintptr_t baseAddress, std::string fieldName);
- // - Gets the indexed relative addresses of a 'Quaternion' Array or List field .. (x, y, z, t) -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: length - Length of Array or List
- static Vec_t<MemQuaternion_t> GetFieldQuaternion(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
- //-----------------------------------------------------------------------------
- // [SECTION] SETTERS
- //-----------------------------------------------------------------------------
- // - Sets/Writes to the memory address of a 'field' in a Class -
- // Param 1: classType - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4 valueToSet - Value to write to memory (eg. 1.f)
- // usage: - LibMbinMem::SetFieldValue(parentClassType, baseAddr, "FieldName", value);
- template <typename T>
- static uintptr_t SetFieldValue(Type^ classType, uintptr_t baseAddress, std::string fieldName, T valueToSet) {
- auto address{ LibMbinMem::GetField(classType, baseAddress, fieldName) };
- *(T*)address = valueToSet;
- return address;
- }
- // - Sets/Writes Values to the memory addresses of a List or Array field in a Class -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: values to set - eg. { 1.f, 2.f, 3.f, 4.f, 5.f }
- // usage: - LibMbinMem::SetFieldValue(parentClassType, baseAddr, "FieldName", value);
- template <typename T>
- static void SetFieldValues(Type^ classType, uintptr_t baseAddress, std::string fieldName, vector<T> valueToSet) {
- uintptr_t fieldAddress{ LibMbinMem::GetField(classType, baseAddress, fieldName) };
- for (size_t i = 0; i < valueToSet.size(); i++) {
- if (fieldAddress) {
- *(T*)fieldAddress = valueToSet[i];
- fieldAddress += sizeof(T);
- }
- }
- }
- // - Sets / Writes to the memory addresses of a 'Colour field' in a class -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: Colour to set - eg. #B0807D49
- // usage: - LibMbinMem::SetFieldColour(parentClassType, baseAddr, "FieldName", "#B0807D49");
- static void SetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName, std::string colourToSet);
- // - Sets/Writes to the memory addresses of a 'String field' in a class -
- // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
- // Param 2: baseAddress - Base Address of class in memory
- // Param 3: fieldName - The name of the field to search for
- // Param 4: String to set - eg. "METADATA/SIMULATION/SOLARSYSTEM/BIOMES/LUSH/LUSHBIOME.MBIN"
- // for reference: - LibMbinMem::SetString(parentClassType, baseAddr, "ClassType.StringFieldName", "String");
- static void SetFieldString(Type^ classType, uintptr_t baseAddress, std::string fieldName, char* stringToSet);
- };
- inline LibMbinMem libMbinMem;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement