Advertisement
RaYRoDTV

Multiverse API - LibMbinMem (Documentation)

Jul 28th, 2022 (edited)
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.85 KB | None | 0 0
  1. namespace Multiverse::Api::Memory::Utils {
  2.  
  3.     struct FieldMatchInfo {
  4.  
  5.     public:
  6.         bool isMatched;
  7.         std::string matchedString;
  8.         int matchedIdx;
  9.         int matchedPadding;
  10.         uintptr_t matchedAddress;
  11.         bool isArray;
  12.         bool isList;
  13.     };
  14.  
  15.     class LibMbinMem {
  16.  
  17.         /*
  18.         *****************************************************
  19.         *                                                   *
  20.         *            libMbinMem by RaYRoD TV                *
  21.         *     - Serves as a wrapper around libMBIN -        *
  22.         *                                                   *
  23.         *****************************************************
  24.         */
  25.  
  26.     private:
  27.  
  28.         // Index:
  29.         // [SECTION] CONVERSIONS
  30.         // [SECTION] CHECKS
  31.         // [SECTION] GETTERS
  32.         // [SECTION] SETTERS
  33.  
  34.         //-----------------------------------------------------------------------------
  35.         // [SECTION] CONVERSIONS
  36.         //-----------------------------------------------------------------------------
  37.  
  38.         //-----------------------------------------------------------------------------
  39.         // [SECTION] CHECKS
  40.         //-----------------------------------------------------------------------------
  41.  
  42.         //-----------------------------------------------------------------------------
  43.         // [SECTION] GETTERS
  44.         //-----------------------------------------------------------------------------
  45.  
  46.         //-----------------------------------------------------------------------------
  47.         // [SECTION] SETTERS
  48.         //-----------------------------------------------------------------------------
  49.  
  50.     public:
  51.  
  52.         // Index:
  53.         // [SECTION] PRINT
  54.         // [SECTION] CONVERSIONS
  55.         // [SECTION] CHECKS
  56.         // [SECTION] GETTERS
  57.         // [SECTION] SETTERS
  58.  
  59.         //-----------------------------------------------------------------------------
  60.         // [SECTION] PRINT
  61.         //-----------------------------------------------------------------------------
  62.  
  63.         //-----------------------------------------------------------------------------
  64.         // [SECTION] CONVERSIONS
  65.         //-----------------------------------------------------------------------------
  66.  
  67.         static std::vector<std::string> SplitArrayFieldName(std::string fieldName);
  68.         static Type^ ConvertType(Type^ type);
  69.         static std::string ConvertTypeName(std::string string);
  70.  
  71.         //-----------------------------------------------------------------------------
  72.         // [SECTION] CHECKS
  73.         //-----------------------------------------------------------------------------
  74.  
  75.         static Type^ SearchForFieldTypeInClass(Type^ classType, String^ fieldName);
  76.         static bool  SearchForFieldInClass(Type^ classType, String^ fieldName);
  77.         static FieldMatchInfo FindFieldMatch(std::vector<std::string>& vecString, std::vector<int>& idx, uintptr_t baseAddress, Type^ classType, Type^& matchedType);
  78.  
  79.         //-----------------------------------------------------------------------------
  80.         // [SECTION] GETTERS
  81.         //-----------------------------------------------------------------------------
  82.  
  83.         // - Gets the type of a field in a Class .. GcUIGlobals -
  84.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  85.         // Param 2: fieldName    - The name of the field to search for
  86.         static Type^ GetFieldType(Type^ classType, std::string fieldName);
  87.  
  88.         // - Gets the relative address of a field .. 0xDEADBEEF -
  89.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  90.         // Param 2: baseAddress  - Base Address of class in memory
  91.         // Param 3: fieldName    - The name of the field to search for
  92.         // Param 4: length       - Length of Array or List
  93.         static uintptr_t GetField(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  94.         static uintptr_t GetFieldTest(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  95.  
  96.         // - Gets the indexed relative addresses of aN Array or List field -
  97.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  98.         // Param 2: baseAddress  - Base Address of class in memory
  99.         // Param 3: fieldName    - The name of the field to search for
  100.         // Param 4: length       - Length of Array or List
  101.         static MemVec_t GetField(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  102.  
  103.         // - Gets the relative address of a 'Colour' field .. .. (R, G, B, A) -
  104.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  105.         // Param 2: baseAddress  - Base Address of class in memory
  106.         // Param 3: fieldName    - The name of the field to search for
  107.         static MemColour_t GetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  108.  
  109.         // - Gets the indexed relative addresses of a 'Colour' Array or List field .. (R, G, B, A) -
  110.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  111.         // Param 2: baseAddress  - Base Address of class in memory
  112.         // Param 3: fieldName    - The name of the field to search for
  113.         // Param 4: length       - Length of Array or List
  114.         static Vec_t<MemColour_t> GetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  115.  
  116.         // - Gets the relative address of a 'Vector2f' field .. (x, y) -
  117.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  118.         // Param 2: baseAddress  - Base Address of class in memory
  119.         // Param 3: fieldName    - The name of the field to search for
  120.         static MemVec2f_t GetFieldVector2f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  121.  
  122.         // - Gets the indexed relative addresses of a 'Vector2f' Array or List field .. (x, y) -
  123.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  124.         // Param 2: baseAddress  - Base Address of class in memory
  125.         // Param 3: fieldName    - The name of the field to search for
  126.         // Param 4: length       - Length of Array or List
  127.         static Vec_t<MemVec2f_t> GetFieldVector2f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  128.  
  129.         // - Gets the relative address of a 'Vector3f' field .. (x, y, z) -
  130.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  131.         // Param 2: baseAddress  - Base Address of class in memory
  132.         // Param 3: fieldName    - The name of the field to search for
  133.         static MemVec3f_t GetFieldVector3f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  134.  
  135.         // - Gets the indexed relative addresses of a 'Vector3f' Array or List field .. (x, y, z) -
  136.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  137.         // Param 2: baseAddress  - Base Address of class in memory
  138.         // Param 3: fieldName    - The name of the field to search for
  139.         // Param 4: length       - Length of Array or List
  140.         static Vec_t<MemVec3f_t> GetFieldVector3f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  141.  
  142.         // - Gets the relative address of a 'Vector4f' field -
  143.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  144.         // Param 2: baseAddress  - Base Address of class in memory
  145.         // Param 3: fieldName    - The name of the field to search for
  146.         static MemVec4f_t GetFieldVector4f(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  147.  
  148.         // - Gets the indexed relative addresses of a 'Vector4f' Array or List field .. (x, y, z, t) -
  149.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  150.         // Param 2: baseAddress  - Base Address of class in memory
  151.         // Param 3: fieldName    - The name of the field to search for
  152.         // Param 4: length       - Length of Array or List
  153.         static Vec_t<MemVec4f_t> GetFieldVector4f(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  154.  
  155.         // - Gets the relative address of a 'Quaternion' field -
  156.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  157.         // Param 2: baseAddress  - Base Address of class in memory
  158.         // Param 3: fieldName    - The name of the field to search for
  159.         static MemQuaternion_t GetFieldQuaternion(Type^ classType, uintptr_t baseAddress, std::string fieldName);
  160.  
  161.         // - Gets the indexed relative addresses of a 'Quaternion' Array or List field .. (x, y, z, t) -
  162.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  163.         // Param 2: baseAddress  - Base Address of class in memory
  164.         // Param 3: fieldName    - The name of the field to search for
  165.         // Param 4: length       - Length of Array or List
  166.         static Vec_t<MemQuaternion_t> GetFieldQuaternion(Type^ classType, uintptr_t baseAddress, std::string fieldName, int length);
  167.  
  168.         //-----------------------------------------------------------------------------
  169.         // [SECTION] SETTERS
  170.         //-----------------------------------------------------------------------------
  171.  
  172.         // - Sets/Writes to the memory address of a 'field' in a Class -
  173.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  174.         // Param 2: baseAddress      - Base Address of class in memory
  175.         // Param 3: fieldName        - The name of the field to search for
  176.         // Param 4 valueToSet        - Value to write to memory (eg. 1.f)
  177.         // usage:                    - LibMbinMem::SetFieldValue(parentClassType, baseAddr, "FieldName", value);
  178.         template <typename T>
  179.         static uintptr_t SetFieldValue(Type^ classType, uintptr_t baseAddress, std::string fieldName, T valueToSet) {
  180.  
  181.             auto address{ LibMbinMem::GetField(classType, baseAddress, fieldName) };
  182.  
  183.             *(T*)address = valueToSet;
  184.             return address;
  185.         }
  186.  
  187.         // - Sets/Writes Values to the memory addresses of a List or Array field in a Class -
  188.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  189.         // Param 2: baseAddress   - Base Address of class in memory
  190.         // Param 3: fieldName     - The name of the field to search for
  191.         // Param 4: values to set - eg. { 1.f, 2.f, 3.f, 4.f, 5.f }
  192.         // usage:                 - LibMbinMem::SetFieldValue(parentClassType, baseAddr, "FieldName", value);
  193.         template <typename T>
  194.         static void SetFieldValues(Type^ classType, uintptr_t baseAddress, std::string fieldName, vector<T> valueToSet) {
  195.  
  196.             uintptr_t fieldAddress{ LibMbinMem::GetField(classType, baseAddress, fieldName) };
  197.  
  198.             for (size_t i = 0; i < valueToSet.size(); i++) {
  199.  
  200.                 if (fieldAddress) {
  201.                     *(T*)fieldAddress = valueToSet[i];
  202.                     fieldAddress += sizeof(T);
  203.                 }
  204.             }
  205.         }
  206.  
  207.         // - Sets / Writes to the memory addresses of a 'Colour field' in a class -
  208.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  209.         // Param 2: baseAddress    - Base Address of class in memory
  210.         // Param 3: fieldName      - The name of the field to search for
  211.         // Param 4: Colour to set  - eg. #B0807D49
  212.         // usage:                  - LibMbinMem::SetFieldColour(parentClassType, baseAddr, "FieldName", "#B0807D49");
  213.         static void SetFieldColour(Type^ classType, uintptr_t baseAddress, std::string fieldName, std::string colourToSet);
  214.  
  215.         // - Sets/Writes to the memory addresses of a 'String field' in a class -
  216.         // Param 1: Class Type ID ( eg. GcUIGlobals::typeid; )
  217.         // Param 2: baseAddress    - Base Address of class in memory
  218.         // Param 3: fieldName      - The name of the field to search for
  219.         // Param 4: String to set  - eg. "METADATA/SIMULATION/SOLARSYSTEM/BIOMES/LUSH/LUSHBIOME.MBIN"
  220.         // for reference:          - LibMbinMem::SetString(parentClassType, baseAddr, "ClassType.StringFieldName", "String");
  221.         static void SetFieldString(Type^ classType, uintptr_t baseAddress, std::string fieldName, char* stringToSet);
  222.  
  223.     };
  224.     inline LibMbinMem libMbinMem;
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement