Example #1
0
        public static FObjectImport ReadEntry(IOMemoryStream ms, UassetFile f)
        {
            //Read in
            FObjectImport g = new FObjectImport();

            g.startPos   = ms.position;
            g.coreType   = ms.ReadNameTableEntry(f);
            g.unknown1   = ms.ReadInt();
            g.objectType = ms.ReadNameTableEntry(f);
            g.unknown2   = ms.ReadInt();
            g.index      = ms.ReadInt();
            g.name       = ms.ReadNameTableEntry(f);
            g.unknown4   = ms.ReadInt();
            return(g);
        }
Example #2
0
        public UassetFile(byte[] data, string fullPath)
        {
            Fullpath = fullPath;
            Filename = Path.GetFileNameWithoutExtension(Fullpath);

            //Create a stream
            stream = new IOMemoryStream(new MemoryStream(data), true);

            stream.position = 0;

            var signature = stream.ReadUInt();

            // Check for the file's signature.
            if (signature != UNREAL_ASSET_MAGIC)
            {
                TKContext.LogError("The file provided is not a valid uasset file.");
                return;
            }

            Version = stream.ReadUInt();

            stream.ReadBytes(0x10);
            UnkOffset = stream.ReadInt();
            stream.ReadInt();

            PackageGroup = Encoding.ASCII.GetString(stream.ReadBytes(0x4));

            stream.ReadBytes(0x1);

            PackageFlags = stream.ReadUInt();
            NamesCount   = stream.ReadInt();
            NamesOffset  = stream.ReadInt();

            stream.ReadBytes(0x8);

            ExportsCount  = stream.ReadInt();
            ExportsOffset = stream.ReadInt();

            ImportsCount  = stream.ReadInt();
            ImportsOffset = stream.ReadInt();

            stream.ReadBytes(0x8);

            UnkOffset2 = stream.ReadInt();

            stream.ReadBytes(0x1C);

            NamesCount2 = stream.ReadInt();

            stream.ReadBytes(0x2C);

            UnkOffset3      = stream.ReadInt();
            EndOfFileOffset = stream.ReadInt();

            stream.ReadBytes(0x10);
            UnkOffset4 = stream.ReadInt();

            stream.position = NamesOffset;

            NamesTable = stream.ReadFNameEntries(NamesCount, UE4Version.UE4__4_14);


            for (int i = 0; i < NamesCount; i++)
            {
                TKContext.DebugLog("UassetFile", $"Name Table Entry {i}", NamesTable[i].Name, ConsoleColor.Yellow);
            }

            TKContext.LogInner("INFO", $"Uasset names count is {NamesCount}");

            //Starts directly after the name table. Assume we're already there
            ImportsTable = new FObjectImport[ImportsCount];
            for (int i = 0; i < ImportsCount; i++)
            {
                FObjectImport h = FObjectImport.ReadEntry(stream, this);
                ImportsTable[i] = h;
                DebugDump($"FObjectImport {i} @ {h.startPos}", ConsoleColor.Blue, "cType", h.coreType, "u1", h.unknown1.ToString(), "oType", h.objectType, "u2", h.unknown2.ToString(), "i", h.index.ToString(), "name", h.name, "u4", h.unknown4.ToString());
            }

            TKContext.LogInner("INFO", $"Uasset import table size is {ImportsCount}");

            //Starts directly after the referenced GameObject table. Assume we're already there
            ExportsTable = new FObjectExport[ExportsCount];
            for (int i = 0; i < ExportsCount; i++)
            {
                ExportsTable[i] = FObjectExport.ReadEntry(stream, this);
                DebugDump($"FObjectExport {i} @ {ExportsTable[i].entryLocation}", ConsoleColor.Magenta, "id", ExportsTable[i].id.ToString(), "u2", ExportsTable[i].unknown2.ToString(),
                          "u3", ExportsTable[i].unknown3.ToString(), "type", ExportsTable[i].type, "u4", ExportsTable[i].unknown4.ToString(), "u5", ExportsTable[i].unknown5.ToString(),
                          "length", ExportsTable[i].dataLength.ToString(), "location", ExportsTable[i].dataLocation.ToString(), "u6", ExportsTable[i].unknown6.ToString(), "u7",
                          ExportsTable[i].unknown7.ToString(), "u8", ExportsTable[i].unknown8.ToString(), "u9", ExportsTable[i].unknown9.ToString(), "u10", ExportsTable[i].unknown10.ToString(), "u11", ExportsTable[i].unknown11.ToString(),
                          "u12", ExportsTable[i].unknown12.ToString(), "u13", ExportsTable[i].unknown13.ToString(), "u14", ExportsTable[i].unknown14.ToString(), "u15", ExportsTable[i].unknown15.ToString(),
                          "u16", ExportsTable[i].unknown16.ToString(), "u17", ExportsTable[i].unknown17.ToString(), "u18", ExportsTable[i].unknown18.ToString(), "u19", ExportsTable[i].unknown19.ToString(),
                          "u20", ExportsTable[i].unknown20.ToString(), "u21", ExportsTable[i].unknown21.ToString(), "u22", ExportsTable[i].unknown22.ToString());
            }

            TKContext.LogInner("INFO", $"Uasset export table size is {ExportsCount}");

            using (MemoryStream ms = new MemoryStream())
            {
                stream.position = 0;
                stream.ms.CopyTo(ms);
                stream.Close();

                FileData = ms.ToArray();
            }
        }