예제 #1
0
        public static alien_pak Load(string filepath, bool BigEndian)
        {
            alien_pak    Result = new alien_pak();
            BinaryReader Stream = new BinaryReader(File.OpenRead(filepath));

            alien_pak_header Header = Utilities.Consume <alien_pak_header>(ref Stream);

            if (BigEndian)
            {
                Header.Version       = BinaryPrimitives.ReverseEndianness(Header.Version);
                Header.MaxEntryCount = BinaryPrimitives.ReverseEndianness(Header.MaxEntryCount);
                Header.EntryCount    = BinaryPrimitives.ReverseEndianness(Header.EntryCount);
            }

            List <alien_pak_entry> Entries = Utilities.ConsumeArray <alien_pak_entry>(ref Stream, Header.MaxEntryCount);

            //todo-mattf; remove the need for this
            long resetpos = Stream.BaseStream.Position;

            byte[] DataStart = Stream.ReadBytes((int)Stream.BaseStream.Length - (int)resetpos);
            Stream.BaseStream.Position = resetpos;

            List <byte[]> EntryDatas = new List <byte[]>(Header.MaxEntryCount);

            for (int EntryIndex = 0; EntryIndex < Header.MaxEntryCount; ++EntryIndex)
            {
                if (BigEndian)
                {
                    alien_pak_entry Entry = Entries[EntryIndex];
                    Entry.Length        = BinaryPrimitives.ReverseEndianness(Entries[EntryIndex].Length);
                    Entry.DataLength    = BinaryPrimitives.ReverseEndianness(Entries[EntryIndex].DataLength);
                    Entry.UnknownIndex  = BinaryPrimitives.ReverseEndianness(Entries[EntryIndex].UnknownIndex);
                    Entry.BINIndex      = BinaryPrimitives.ReverseEndianness(Entries[EntryIndex].BINIndex);
                    Entry.Offset        = BinaryPrimitives.ReverseEndianness(Entries[EntryIndex].Offset);
                    Entries[EntryIndex] = Entry;
                }
                byte[] Buffer = (Entries[EntryIndex].DataLength == -1) ? new byte[] { } : Stream.ReadBytes(Entries[EntryIndex].DataLength);
                EntryDatas.Add(Buffer);
            }

            Result.Header     = Header;
            Result.Entries    = Entries;
            Result.DataStart  = DataStart;
            Result.EntryDatas = EntryDatas;

            Stream.Close();
            return(Result);
        }
예제 #2
0
        public static alien_shader_pak Load(string FullFilePath)
        {
            alien_shader_pak Result = new alien_shader_pak();

            Result.PAK     = Generic.PAK.Load(FullFilePath, false);
            Result.Shaders = new List <alien_shader_pak_shader>(Result.PAK.Header.EntryCount);

            for (int EntryIndex = 0; EntryIndex < Result.PAK.Header.EntryCount; EntryIndex++)
            {
                alien_pak_entry Entry = Result.PAK.Entries[EntryIndex];

                byte[]       Buffer = Result.PAK.EntryDatas[EntryIndex];
                BinaryReader Stream = new BinaryReader(new MemoryStream(Buffer));

                alien_shader_pak_shader Shader = new alien_shader_pak_shader();
                Shader.Index  = Entry.UnknownIndex;
                Shader.Header = Utilities.Consume <alien_shader_pak_shader_header>(ref Stream);
                byte[] Name = Stream.ReadBytes(40);
                Shader.Name        = Utilities.ReadString(Name);
                Shader.Header2     = Utilities.Consume <alien_shader_pak_shader_header2>(ref Stream);
                Shader.Entry0Count = Stream.ReadUInt16();
                Shader.Entries0    = Utilities.ConsumeArray <alien_shader_pak_shader_unknown_entry>(ref Stream, Shader.Entry0Count);

                Shader.TextureEntries = Utilities.ConsumeArray <alien_shader_pak_shader_texture_entry>(ref Stream, Shader.Header.TextureCount);
                Shader.TextureThings  = Stream.ReadBytes(Shader.Header.TextureCount);

                byte[][] CSTLinks = new byte[5][];
                for (int TableIndex = 0; TableIndex < Shader.Header.CSTCounts.Length; ++TableIndex)
                {
                    CSTLinks[TableIndex] = Stream.ReadBytes(Shader.Header.CSTCounts[TableIndex]);
                }
                Shader.CSTLinks = CSTLinks;

                Shader.TextureLinks = Stream.ReadBytes(Shader.Header.TextureLinkCount);
                Shader.Indices      = Utilities.Consume <alien_shader_pak_shader_indices>(ref Stream);

                Result.Shaders.Add(Shader);

                Utilities.Align(ref Stream, 16);
            }

            return(Result);
        }
예제 #3
0
    private AlienTexture LoadTexture(int EntryIndex, bool loadV1 = true)
    {
        AlienTexture toReturn = new AlienTexture();

        if (EntryIndex < 0 || EntryIndex >= LevelTextures.PAK.Header.EntryCount)
        {
            Debug.LogWarning("Asked to load texture at index " + EntryIndex + ", which is out of bounds!");
            return(null);
        }

        alien_pak_entry           Entry     = LevelTextures.PAK.Entries[EntryIndex];
        alien_texture_bin_texture InTexture = LevelTextures.BIN.Textures[Entry.BINIndex];

        Vector2 textureDims;
        int     textureLength = 0;
        int     mipLevels     = 0;

        if (loadV1)
        {
            textureDims   = new Vector2(InTexture.Size_V1[0], InTexture.Size_V1[1]);
            textureLength = InTexture.Length_V1;
            mipLevels     = InTexture.MipLevelsV1;
        }
        else
        {
            textureDims   = new Vector2(InTexture.Size_V2[0], InTexture.Size_V2[1]);
            textureLength = InTexture.Length_V2;
            mipLevels     = InTexture.MipLevelsV2;
        }

        if (textureLength == 0)
        {
            Debug.LogWarning("LENGTH ZERO - NOT LOADING");
            return(toReturn);
        }

        UnityEngine.TextureFormat format = UnityEngine.TextureFormat.BC7;
        switch (InTexture.Format)
        {
        case alien_texture_format.Alien_R32G32B32A32_SFLOAT:
            format = UnityEngine.TextureFormat.RGBA32;
            break;

        case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM:
            format = UnityEngine.TextureFormat.ETC2_RGBA8;     //?
            break;

        case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM_0:
            format = UnityEngine.TextureFormat.ETC2_RGBA8;     //?
            break;

        case alien_texture_format.Alien_FORMAT_SIGNED_DISTANCE_FIELD:
            Debug.LogWarning("SDF! NOT LOADED");
            return(toReturn);

        case alien_texture_format.Alien_FORMAT_R8:
            format = UnityEngine.TextureFormat.R8;
            break;

        case alien_texture_format.Alien_FORMAT_BC1:
            format = UnityEngine.TextureFormat.DXT1;
            break;

        case alien_texture_format.Alien_FORMAT_BC2:
            Debug.LogWarning("BC2! NOT LOADED");
            return(toReturn);

        case alien_texture_format.Alien_FORMAT_BC5:
            format = UnityEngine.TextureFormat.BC5;     //Is this correct?
            break;

        case alien_texture_format.Alien_FORMAT_BC3:
            format = UnityEngine.TextureFormat.DXT5;
            break;

        case alien_texture_format.Alien_FORMAT_BC7:
            format = UnityEngine.TextureFormat.BC7;
            break;

        case alien_texture_format.Alien_FORMAT_R8G8:
            format = UnityEngine.TextureFormat.BC5;     // is this correct?
            break;
        }

        BinaryReader tempReader = new BinaryReader(new MemoryStream(LevelTextures.PAK.DataStart));

        tempReader.BaseStream.Position = Entry.Offset;

        if (InTexture.Type == 7)
        {
            Cubemap cubemapTex = new Cubemap((int)textureDims.x, format, true);
            cubemapTex.name = LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveX);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeX);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveY);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeY);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveZ);
            cubemapTex.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeZ);
            cubemapTex.Apply();
            toReturn.cubemap = cubemapTex;
            //AssetDatabase.CreateAsset(cubemapTex, "Assets/Cubemaps/" + Path.GetFileNameWithoutExtension(cubemapTex.name) + ".cubemap");
        }
        else
        {
            Texture2D texture = new Texture2D((int)textureDims[0], (int)textureDims[1], format, mipLevels, true);
            texture.name = LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
            texture.LoadRawTextureData(tempReader.ReadBytes(textureLength));
            texture.Apply();
            toReturn.texture = texture;
        }

        tempReader.Close();
        return(toReturn);
    }
예제 #4
0
    private void LoadTextureAssets()
    {
        bool[] textureTracker = new bool[levelData.LevelTextures.BIN.Header.EntryCount];
        AssetDatabase.StartAssetEditing();
        for (int i = 0; i < levelData.LevelTextures.PAK.Entries.Count; i++)
        {
            alien_pak_entry           Entry     = levelData.LevelTextures.PAK.Entries[i];
            alien_texture_bin_texture InTexture = levelData.LevelTextures.BIN.Textures[Entry.BINIndex];

            Vector2 textureDims;
            int     textureLength = 0;
            int     mipLevels     = 0;

            if (!textureTracker[Entry.BINIndex])
            {
                textureDims   = new Vector2(InTexture.Size_V1[0], InTexture.Size_V1[1]);
                textureLength = InTexture.Length_V1;
                mipLevels     = InTexture.MipLevelsV1;
            }
            else
            {
                textureDims   = new Vector2(InTexture.Size_V2[0], InTexture.Size_V2[1]);
                textureLength = InTexture.Length_V2;
                mipLevels     = InTexture.MipLevelsV2;
            }
            textureTracker[Entry.BINIndex] = true;

            if (textureLength == 0)
            {
                continue;
            }
            if (InTexture.Format == alien_texture_format.Alien_FORMAT_SIGNED_DISTANCE_FIELD || InTexture.Format == alien_texture_format.Alien_FORMAT_BC2)
            {
                continue;
            }

            TextureFormat format = TextureFormat.BC7;
            switch (InTexture.Format)
            {
            case alien_texture_format.Alien_R32G32B32A32_SFLOAT:
                format = TextureFormat.RGBA32;
                break;

            case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM:
                format = TextureFormat.ETC2_RGBA8;     //?
                break;

            case alien_texture_format.Alien_FORMAT_R8G8B8A8_UNORM_0:
                format = TextureFormat.ETC2_RGBA8;     //?
                break;

            case alien_texture_format.Alien_FORMAT_R8:
                format = TextureFormat.R8;
                break;

            case alien_texture_format.Alien_FORMAT_BC1:
                format = TextureFormat.DXT1;
                break;

            case alien_texture_format.Alien_FORMAT_BC5:
                format = TextureFormat.BC5;     //Is this correct?
                break;

            case alien_texture_format.Alien_FORMAT_BC3:
                format = TextureFormat.DXT5;
                break;

            case alien_texture_format.Alien_FORMAT_BC7:
                format = TextureFormat.BC7;
                break;

            case alien_texture_format.Alien_FORMAT_R8G8:
                format = TextureFormat.BC5;     // is this correct?
                break;
            }

            BinaryReader tempReader = new BinaryReader(new MemoryStream(levelData.LevelTextures.PAK.DataStart));
            tempReader.BaseStream.Position = Entry.Offset;
            if (InTexture.Type == 7)
            {
                Cubemap cubemap = new Cubemap((int)textureDims.x, format, true);
                cubemap.name = levelData.LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveX);
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeX);
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveY);
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeY);
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.PositiveZ);
                cubemap.SetPixelData(tempReader.ReadBytes(textureLength / 6), 0, CubemapFace.NegativeZ);
                cubemap.Apply();

                string fullFilePath  = "Assets/Resources/" + SharedVals.instance.LevelName + "/Cubemaps/" + cubemap.name.Substring(0, cubemap.name.Length - Path.GetExtension(cubemap.name).Length) + ".cubemap";
                string fileDirectory = GetDirectory(fullFilePath);
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }
                AssetDatabase.CreateAsset(cubemap, fullFilePath);
            }
            else
            {
                Texture2D texture = new Texture2D((int)textureDims[0], (int)textureDims[1], format, mipLevels, true);
                texture.name = levelData.LevelTextures.BIN.TextureFilePaths[Entry.BINIndex];
                texture.LoadRawTextureData(tempReader.ReadBytes(textureLength));
                texture.Apply();

                string fullFilePath  = "Assets/Resources/" + SharedVals.instance.LevelName + "/Textures/" + texture.name.Substring(0, texture.name.Length - Path.GetExtension(texture.name).Length) + ".asset";
                string fileDirectory = GetDirectory(fullFilePath);
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }
                AssetDatabase.CreateAsset(texture, fullFilePath);
            }
            tempReader.Close();
        }
        AssetDatabase.StopAssetEditing();
    }