Advertisement
malice936

ExtractMorrowindFormLibrary.cpp

Apr 17th, 2025
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | Gaming | 0 0
  1. // Warning! Experimental! No guarantees on functionality! Use at your own risk!!!!!
  2. #include "ExtractMorrowindFormLibrary.h"
  3. #include "Serialization/MemoryReader.h"
  4.  
  5. TArray<uint8> UExtractMorrowindFormLibrary::ExtractMorrowindFormData(const TArray<uint8>& MainFileData)
  6. {
  7.     TArray<uint8> ExtractedData;
  8.     FMemoryReader Ar(MainFileData, true);
  9.  
  10.     while (!Ar.AtEnd())
  11.     {
  12.         // Read record type (4 bytes)
  13.         FString RecordType;
  14.         Ar << RecordType;
  15.  
  16.         // Read record size (4 bytes)
  17.         int32 RecordSize;
  18.         Ar << RecordSize;
  19.  
  20.         int64 RecordEnd = Ar.Tell() + RecordSize;
  21.  
  22.         while (Ar.Tell() < RecordEnd)
  23.         {
  24.             // Read subrecord type (4 bytes)
  25.             FString SubrecordType;
  26.             Ar << SubrecordType;
  27.  
  28.             // Read subrecord size (4 bytes)
  29.             int32 SubrecordSize;
  30.             Ar << SubrecordSize;
  31.  
  32.             // Read subrecord data
  33.             TArray<uint8> SubrecordData;
  34.             SubrecordData.SetNum(SubrecordSize);
  35.             Ar.Serialize(SubrecordData.GetData(), SubrecordSize);
  36.  
  37.             // Append all subrecord data to the result
  38.             ExtractedData.Append(SubrecordData);
  39.         }
  40.     }
  41.  
  42.     return ExtractedData;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement