Advertisement
RaYRoDTV

Multiverse API - LibMbinMem (Documentation)

Aug 27th, 2022 (edited)
1,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.25 KB | None | 0 0
  1.     class LibMbinMem {
  2.  
  3.         /*
  4.         *****************************************************
  5.         *                                                   *
  6.         *            libMbinMem by RaYRoD TV                *
  7.         *     - Serves as a wrapper around libMBIN -        *
  8.         *                                                   *
  9.         *****************************************************
  10.         */
  11.  
  12.     public:
  13.  
  14.         // Index of this Class:
  15.         // [SECTION] Getters
  16.         // [SECTION] Setters
  17.  
  18.         //-----------------------------------------------------------------------------
  19.  
  20.         // - Resolves info of Fields -
  21.         static std::string RemoveArrayString(std::string arrayString);
  22.         static std::string RemoveArrayString(String^ arrayString);
  23.         static void        ResolveFieldInfo(Type^ classType, FieldInfo^ fieldInfo, String^ inheritedFieldIndex, uintptr_t currentAddress);
  24.         static void        ResolveFieldInfo(Type^ classType, FieldInfo^ fieldInfo, String^ inheritedFieldIndex);
  25.         static std::string ResolveFieldType(Type^ classType, String^ fieldName);
  26.         static Type^       ResolveFieldTypeID(Type^ fieldType);
  27.         static Type^       ResolveFieldTypeInfo(Type^ classType, String^ fieldName);
  28.         static int         ResolveFieldPadding(String^ fieldName);
  29.         static uintptr_t   ResolveFieldAddress(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  30.  
  31.         //-----------------------------------------------------------------------------
  32.         // [SECTION] Print
  33.         //-----------------------------------------------------------------------------
  34.  
  35.         // - Prints all Array fields in a class (eg. hierarchy, types, names, addresses) -
  36.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  37.         static void PrintFieldArrayTypes(Type^ classType);
  38.  
  39.         // - Prints all List fields in a class (eg. hierarchy, types, names, addresses) -
  40.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  41.         static void PrintFieldListTypes(Type^ classType);
  42.  
  43.         //-----------------------------------------------------------------------------
  44.         // [SECTION] Getters
  45.         //-----------------------------------------------------------------------------
  46.  
  47.         // - Gets the type of a specified field in a class -
  48.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  49.         // Param 2: fieldName       - The name of the field to search for
  50.         static std::string GetFieldType(Type^ classType, String^ fieldName);
  51.  
  52.         // - Gets the memory address of a specified field in a class -
  53.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  54.         // Param 2: baseAddress     - Base Address of class in memory
  55.         // Param 3: fieldName       - The name of the field to search for
  56.         static uintptr_t GetField(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  57.  
  58.         // - Gets the memory addresses of a 'Colour' field & stores them in a Colour object  -
  59.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  60.         // Param 2: baseAddress     - Base Address of class in memory
  61.         // Param 3: fieldName       - The name of the field to search for
  62.         static Colour GetColour(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  63.  
  64.         // - Gets the memory addresses of a 'Vector2f' field & stores them in a Vector2f object  -
  65.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  66.         // Param 2: baseAddress     - Base Address of class in memory
  67.         // Param 3: fieldName       - The name of the field to search for
  68.         static Vector2f GetVector2f(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  69.  
  70.         // - Gets the memory addresses of a 'Vector3f' field & stores them in a Vector3f object  -
  71.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  72.         // Param 2: baseAddress     - Base Address of class in memory
  73.         // Param 3: fieldName       - The name of the field to search for
  74.         static Vector3f GetVector3f(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  75.  
  76.         // - Gets the memory addresses of a 'Vector4f' field & stores them in a Vector4f object  -
  77.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  78.         // Param 2: baseAddress     - Base Address of class in memory
  79.         // Param 3: fieldName       - The name of the field to search for
  80.         static Vector4f GetVector4f(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  81.  
  82.         // - Gets the memory addresses of a 'Quaternion' field & stores them in a Quaternion object  -
  83.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  84.         // Param 2: baseAddress     - Base Address of class in memory
  85.         // Param 3: fieldName       - The name of the field to search for
  86.         static Quaternion GetQuaternion(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  87.  
  88.         // - Gets the memory addresses of a 'String' field -
  89.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  90.         // Param 2: baseAddress     - Base Address of class in memory
  91.         // Param 3: fieldName       - The name of the field to search for
  92.         static uintptr_t GetString(Type^ classType, uintptr_t baseAddress, String^ fieldName);
  93.  
  94.         // - Gets/Dereferences the memory address of a 'List' field in a class -
  95.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  96.         // Param 2: baseAddress     - Base Address of class in memory
  97.         // Param 3: padding         - the number of bytes to jump at the initial dereference at the resolved location
  98.         // Param 4: fieldName       - The name of the field to search for
  99.         static uintptr_t GetList(Type^ classType, uintptr_t baseAddress, int padding, String^ fieldName);
  100.  
  101.         // - Gets the memory addresses of a 'One Dimensional Array' field & stores them in an std::vector variable  -
  102.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  103.         // Param 2: baseAddress     - Base Address of class in memory
  104.         // Param 3: arrayLength     - The length of the array (number of elements in it)
  105.         // Param 4: fieldName       - The name of the field to search for
  106.         static MemVec_t GetArray(Type^ classType, uintptr_t baseAddress, int arrayLength, String^ arrayFieldName);
  107.  
  108.         // - Gets the memory addresses of a 'Two Dimensional Array/Matrix' field & stores them in an std::vector variable  -
  109.         // eg. MapLargeAreaPrimaryDefaultColours[0][1] = MapLargeAreaPrimaryDefaultColours 'Colour index 0, R')
  110.  
  111.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  112.         // Param 2: baseAddress     - Base Address of class in memory
  113.         // Param 3: xMatrix         - The size of the 2D array (array index count)
  114.         // Param 4: yMatrix         - The length of each array element (number of elements in each xMatrix index)
  115.         // Param 5: arrayField      - The name of the first array to search for
  116.         // Param 6: fieldName       - The name of the field to search for
  117.         static MemVec2D_t Get2DArray(Type^ classType, uintptr_t baseAddress, int xMatrix, int yMatrix, String^ arrayField, String^ fieldName);
  118.  
  119.         // - Gets the memory addresses of a 'Three Dimensional Array/Matrix' field & stores them in an std::vector variable  -
  120.         // eg.
  121.         //field[0] = MarkerSettings array(index)
  122.         //field[0][0] = Colours array(index)
  123.         //field[0][0][0] = Colour field at Colours array(index)
  124.  
  125.         // Param 1: classType       - Class Type ID ( eg. NMS::Globals::GcGalaxyGlobals::typeid; )
  126.         // Param 2: baseAddress     - Base Address of class in memory
  127.         // Param 3: xMatrix         - The size of the 3D array (array index count)
  128.         // Param 4: yMatrix         - The size of the nested array (array index count)
  129.         // Param 5: zMatrix         - The length of each array element (number of elements in each yMatrix index)
  130.         // Param 6: arrayField1     - The name of the first array to search for
  131.         // Param 7: arrayField2     - The name of the nested array to search for
  132.         // Param 8: fieldName       - The name of the field in the nested array to search for
  133.         static MemVec3D_t Get3DArray(Type^ classType, uintptr_t baseAddress, int xMatrix, int yMatrix, int zMatrix, String^ arrayField1, String^ arrayField2, String^ fieldName);
  134.  
  135.         //-----------------------------------------------------------------------------
  136.         // [SECTION] Setters
  137.         //-----------------------------------------------------------------------------
  138.  
  139.         // - Sets/Writes to the memory addresses of a 'Bool Array' - ( eg. { false, true, false ... } ) -
  140.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  141.         // Param 2: baseAddress      - Base Address of class in memory
  142.         // Param 3: fieldName        - The name of the field to search for
  143.         // Param 4: value to set     - eg. { false, true, false, true }
  144.         // for reference:            - LibMbinMem::SetBoolArray(parentClassType, baseAddr, "ClassType.BoolFieldName", { false, true });
  145.         static void SetBoolArray(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<bool> valueToSet);
  146.  
  147.         // - Sets/Writes to the memory addresses of an 'Int Array' -  ( eg. { 0, 1, 2 ... } ) -
  148.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  149.         // Param 2: baseAddress      - Base Address of class in memory
  150.         // Param 3: fieldName        - The name of the field to search for
  151.         // Param 4: value to set     - eg. { 1, 2, 3, 4 }
  152.         // for reference:            - LibMbinMem::SetIntArray(parentClassType, baseAddr, "ClassType.IntFieldName", { 1, 2, 3, 4 });
  153.         static void SetIntArray(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<int> valueToSet);
  154.  
  155.         // - Sets/Writes to the memory addresses of a 'Float Array' class ( eg. { 0.f, 1.f, 2.f ... } ) -
  156.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::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.         // Param 4: value to set     - eg. { 1.f, 2.f, 3.f, 4.f, 5.f }
  160.         // for reference:            - LibMbinMem::SetFloatArray(parentClassType, baseAddr, "ClassType.FloatFieldName", { 1.f, 2.f, 3.f, 4.f, 5.f });
  161.         static void SetFloatArray(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<float> valueToSet);
  162.  
  163.         // - Sets/Writes to the memory addresses of a 'Vector2f Field' class ( eg. { 0.f, 1.f, } = X.Y ) -
  164.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  165.         // Param 2: baseAddress      - Base Address of class in memory
  166.         // Param 3: fieldName        - The name of the field to search for
  167.         // Param 4: value to set     - eg. { 1.f, 2.f }
  168.         // for reference:            - LibMbinMem::SetFloatArray(parentClassType, baseAddr, "ClassType.Vector2f_FieldName", { 1.f, 2.f});
  169.         static void SetVector2f(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<float> valueToSet);
  170.  
  171.         // - Sets/Writes to the memory addresses of a 'Vector3f Field' class ( eg. { 0.f, 1.f, 2.f } = X.Y.Z ) -
  172.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  173.         // Param 2: baseAddress      - Base Address of class in memory
  174.         // Param 3: fieldName        - The name of the field to search for
  175.         // Param 4: value to set     - eg. { 1.f, 2.f, 3.f }
  176.         // for reference:            - LibMbinMem::SetFloatArray(parentClassType, baseAddr, "ClassType.Vector3f_FieldName", { 1.f, 2.f, 3.f });
  177.         static void SetVector3f(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<float> valueToSet);
  178.  
  179.         // - Sets/Writes to the memory addresses of a 'Vector4f Field' class ( eg. { 0.f, 1.f, 2.f, 3.f } = X.Y.Z.T ) -
  180.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  181.         // Param 2: baseAddress      - Base Address of class in memory
  182.         // Param 3: fieldName        - The name of the field to search for
  183.         // Param 4: value to set     - eg. { 1.f, 2.f, 3.f, 4.f }
  184.         // for reference:            - LibMbinMem::SetFloatArray(parentClassType, baseAddr, "ClassType.Vector4f_FieldName", { 1.f, 2.f, 3.f, 4.f });
  185.         static void SetVector4f(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<float> valueToSet);
  186.  
  187.         // - Sets/Writes to the memory addresses of a 'Quaternion Field' class  ( eg. { 0.f, 1.f, 2.f, 3.f } = X.Y.Z.T ) -
  188.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::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: value to set     - eg. { 1.f, 2.f, 3.f, 4.f }
  192.         // for reference:            - LibMbinMem::SetFloatArray(parentClassType, baseAddr, "ClassType.Vector4f_FieldName", { 1.f, 2.f, 3.f, 4.f });
  193.         static void SetQuaternion(Type^ classType, uintptr_t baseAddress, String^ fieldName, vector<float> valueToSet);
  194.  
  195.         // - Sets/Writes to the memory addresses of a 'Colour field' in a class -
  196.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  197.         // Param 2: baseAddress      - Base Address of class in memory
  198.         // Param 3: fieldName        - The name of the field to search for
  199.         // Param 4: Colour to set    - eg. #B0807D49
  200.         // for reference:            - LibMbinMem::SetColour(parentClassType, baseAddr, "ClassType.ColourFieldName", "#B0807D49");
  201.         static void SetColour(Type^ classType, uintptr_t baseAddress, String^ fieldName, std::string colourToSet);
  202.  
  203.         // - Sets/Writes to the memory addresses of a 'String field' in a class -
  204.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  205.         // Param 2: baseAddress      - Base Address of class in memory
  206.         // Param 3: fieldName        - The name of the field to search for
  207.         // Param 4: String to set    - eg. "METADATA/SIMULATION/SOLARSYSTEM/BIOMES/LUSH/LUSHBIOME.MBIN"
  208.         // for reference:            - LibMbinMem::SetString(parentClassType, baseAddr, "ClassType.StringFieldName", "String");
  209.         static void SetString(Type^ classType, uintptr_t baseAddress, String^ fieldName, char* stringToSet);
  210.  
  211.         // - Sets/Writes to the memory addresses of a 'field' in a class -
  212.         // Param 1: classType        - Class Type ID ( eg. NMS::Globals::GcUIGlobals::typeid; )
  213.         // Param 2: baseAddress      - Base Address of class in memory
  214.         // Param 3: fieldName        - The name of the field to search for
  215.         // Param 4: Value to set
  216.         // for reference:           - LibMbinMem::SetValue(parentClassType, baseAddr, "ClassType.ColourFieldName", value);
  217.         template <typename T>
  218.         static uintptr_t SetValue(Type^ classType, uintptr_t baseAddress, String^ fieldName, T valueToSet) {
  219.  
  220.             auto address{ ResolveFieldAddress(classType, baseAddress, fieldName) };
  221.  
  222.             *(T*)address = valueToSet;
  223.             return address;
  224.         }
  225.     };
  226.     inline LibMbinMem libMbinMem;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement