Esempio n. 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);
        }
Esempio n. 2
0
        public static FObjectExport ReadEntry(IOMemoryStream ms, UassetFile f)
        {
            //Read in
            FObjectExport g = new FObjectExport();

            g.entryLocation = ms.position;
            g.id            = ms.ReadInt();
            g.unknown1      = ms.ReadInt();
            g.unknown2      = ms.ReadInt();
            g.unknown3      = ms.ReadInt();
            g.type          = ms.ReadNameTableEntry(f);
            g.unknown4      = ms.ReadInt();
            g.unknown5      = ms.ReadInt();
            g.LengthOffset  = (int)ms.position;
            g.dataLength    = ms.ReadInt();
            g.dataLocation  = ms.ReadInt();
            g.unknown6      = ms.ReadInt();
            g.unknown7      = ms.ReadInt();
            g.unknown8      = ms.ReadInt();
            g.unknown9      = ms.ReadInt();
            g.unknown10     = ms.ReadInt();
            g.unknown11     = ms.ReadInt();
            g.unknown12     = ms.ReadInt();
            g.unknown13     = ms.ReadInt();
            g.unknown14     = ms.ReadInt();
            g.unknown15     = ms.ReadInt();
            g.unknown16     = ms.ReadInt();
            g.unknown17     = ms.ReadInt();
            g.unknown18     = ms.ReadInt();
            g.unknown19     = ms.ReadInt();
            g.unknown20     = ms.ReadInt();
            g.unknown21     = ms.ReadInt();
            g.unknown22     = ms.ReadInt();

            long lastPos = ms.position;

            ms.position = g.dataLocation;
            g.data      = ms.ReadBytes(g.dataLength);
            ms.position = lastPos;

            g.uassetFile = f;

            return(g);
        }
Esempio n. 3
0
        public static UTexture2D GetTextureFromUAsset(UassetFile uassetFile)
        {
            /*if (uassetFile.UE4Version != UE4Version.UE4__4_14)
             *  throw new NotSupportedException($"Texture extraction from {uassetFile.UE4Version.ToString()} uasset files is not supported.");*/

            TKContext.LogInner("INFO", $"Attempting to get a texture from file {uassetFile.Filename}");

            try
            {
                FObjectExport export       = uassetFile.ExportsTable[0];
                EPixelFormat  ePixelFormat = EPixelFormat.PF_Unknown;

                int pfOffset = 0x0;

                // TODO: Simplify this mess.
                for (int i = 0; i < uassetFile.NamesTable.Length; i++)
                {
                    if (uassetFile.NamesTable[i].Name.ToUpper().StartsWith("PF_"))
                    {
                        if (!Enum.TryParse(uassetFile.NamesTable[i].Name, out ePixelFormat))
                        {
                            TKContext.LogError("Pixel Format is not supported.");
                            return(null);
                        }
                    }
                }

                UTexture2D uTexture2D = new UTexture2D();
                //uTexture2D.USerializedData = uSerializedData;
                uTexture2D.UassetFile = uassetFile;
                TKContext.LogInner("INFO", $"Attempting to find {ePixelFormat.ToString()}");
                pfOffset = ArrayExtensions.IndexOfPattern(export.data, Encoding.ASCII.GetBytes(ePixelFormat.ToString()));
                TKContext.LogInner("INFO", $"Pixel Format offset is 0x{pfOffset:X8}");

                if (pfOffset == int.MaxValue)
                {
                    TKContext.LogError("No texture was found.");
                    return(null);
                }

                uTexture2D.PFOffset = pfOffset;

                uTexture2D.PixelFormat  = ePixelFormat;
                uTexture2D.Height       = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, pfOffset - UASSET_RELATIVE_PF_HEIGHT, 4), 0);
                uTexture2D.Width        = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, pfOffset - UASSET_RELATIVE_PF_WIDTH, 4), 0);
                uTexture2D.UnknownValue = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, pfOffset + 0x8, 4), 0);

                TKContext.LogInner("INFO", $"Texture resolution is {uTexture2D.Width}x{uTexture2D.Height}");

                int[] offsets = ArrayExtensions.Locate(export.data, BitConverter.GetBytes(PF_SEPERATOR));

                uTexture2D.MipMapCount = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[0] - 0x4, 4), 0);
                uTexture2D.Mipmaps     = new List <FTexture2DMipMap>();

                TKContext.LogInner("INFO", $"Texture has {uTexture2D.MipMapCount} mipmaps");

                uTexture2D.FirstSeperatorOffset = offsets[0];

                for (int i = 0; i < uTexture2D.MipMapCount; i++)
                {
                    FTexture2DMipMap fTexture2DMipMap = new FTexture2DMipMap();

                    fTexture2DMipMap.UncompressedSize    = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_UNCOMPRESSED_SIZE_OFFSET, 4), 0);
                    fTexture2DMipMap.TextureUassetOffset = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_TEXTURE_START_OFFSET_OFFSET, 4), 0);
                    fTexture2DMipMap.UnknownValue        = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_UNKNOWN_OFFSET, 4), 0);
                    fTexture2DMipMap.Texture             = ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_TEXTURE_DATA, fTexture2DMipMap.UncompressedSize);
                    fTexture2DMipMap.Width  = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_TEXTURE_DATA + fTexture2DMipMap.UncompressedSize, 4), 0);
                    fTexture2DMipMap.Height = BitConverter.ToInt32(ArrayExtensions.GetBytesFromByteArray(export.data, offsets[i] + SEPERATOR_TEXTURE_DATA + fTexture2DMipMap.UncompressedSize + 0x4, 4), 0);

                    uTexture2D.Mipmaps.Add(fTexture2DMipMap);

                    TKContext.LogInner("INFO", fTexture2DMipMap.ToString());
                }

                return(uTexture2D);
            }
            catch (Exception ex)
            {
                TKContext.LogException(ex.ToString());
                return(null);
            }
        }