Esempio n. 1
0
        //Splash is 640x400 16BPP typical TIM with palette of ggg bbbbb a rrrrr gg
        public static void ReadSplash(bool bLogo = false)
        {
            string[] lof = aw.GetListOfFiles();
            string   filename;

            if (splashName > 0x0f)
            {
                return;
            }
            filename = !bLogo
                ? bNames
                    ? lof.First(x => x.ToLower().Contains($"{names}{splashName.ToString("D2")}"))
                    : lof.First(x => x.ToLower().Contains($"{loops}{splashLoop.ToString("D2")}"))
                : lof.First(x => x.ToLower().Contains($"ff8.lzs"));

            byte[] buffer     = ArchiveWorker.GetBinaryFile(Memory.Archives.A_MAIN, filename);
            uint   uncompSize = BitConverter.ToUInt32(buffer, 0);

            buffer = buffer.Skip(4).ToArray(); //hotfix for new LZSS
            buffer = LZSS.DecompressAllNew(buffer);

            if (splashTex != null && !splashTex.IsDisposed)
            {
                splashTex.Dispose();
            }

            splashTex = TIM2.Overture(buffer);
            //using (FileStream fs = File.Create(Path.Combine("D:\\main", Path.GetFileNameWithoutExtension(filename) + ".png")))
            //    splashTex.SaveAsPng(fs, splashTex.Width, splashTex.Height);

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Esempio n. 2
0
        private static Data read(string file)
        {
            byte[] decmp;

            using (FileStream fs = File.OpenRead(file))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    uint size = br.ReadUInt32();
                    //uint fsLen = BitConverter.ToUInt32(FI, loc * 12);
                    //uint fSpos = BitConverter.ToUInt32(FI, (loc * 12) + 4);
                    //bool compe = BitConverter.ToUInt32(FI, (loc * 12) + 8) != 0;
                    //fs.Seek(0, SeekOrigin.Begin);
                    byte[] tmp = br.ReadBytes((int)fs.Length - 4);
                    decmp = LZSS.DecompressAllNew(tmp);
                }
            //using (FileStream fs = File.Create(Path.Combine(@"d:\", Path.GetFileName(file))))
            //using (BinaryWriter bw = new BinaryWriter(fs))
            //{
            //    bw.Write(decmp);
            //}
            using (MemoryStream ms = new MemoryStream(decmp))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    ms.Seek(0x184, SeekOrigin.Begin);
                    Data d = new Data();
                    d.Read(br);

                    return(d);
                }
        }
Esempio n. 3
0
 public static byte[] GetBinaryFile(string archiveName, string fileName)
 {
     byte[] isComp = GetBin(Extended.GetUnixFullPath(archiveName), fileName);
     if (isComp == null)
     {
         throw new FileNotFoundException($"Searched {archiveName} and could not find {fileName}.", fileName);
     }
     if (_compressed)
     {
         isComp = isComp.Skip(4).ToArray();
     }
     return(isComp == null ? null : _compressed?LZSS.DecompressAllNew(isComp) : isComp);
 }
Esempio n. 4
0
        /// <summary>
        /// Give me three archives as bytes uncompressed please!
        /// </summary>
        /// <param name="FI">FileIndex</param>
        /// <param name="FS">FileSystem</param>
        /// <param name="FL">FileList</param>
        /// <param name="filename">Filename of the file to get</param>
        /// <returns></returns>
        public static byte[] FileInTwoArchives(byte[] FI, byte[] FS, byte[] FL, string filename)
        {
            string a = filename.TrimEnd('\0');

            string flText = System.Text.Encoding.UTF8.GetString(FL);

            flText = flText.Replace(Convert.ToString(0x0d), "");
            int loc = -1;

            string[] files = flText.Split((char)0x0a);
            for (int i = 0; i != files.Length; i++) //check archive for filename
            {
                if (string.IsNullOrWhiteSpace(files[i]))
                {
                    Debug.WriteLine("ArchiveWorker::File entry is null. Returning null");
                    return(null);
                }
                string testme = files[i].Substring(0, files[i].Length - 1).ToUpper().TrimEnd('\0');
                if (testme != a.ToUpper())
                {
                    continue;
                }
                loc = i;
                break;
            }
            if (loc == -1)
            {
                Debug.WriteLine("ArchiveWorker: NO SUCH FILE!");
                return(null);
                //throw new Exception("ArchiveWorker: No such file!");
            }


            uint fsLen = BitConverter.ToUInt32(FI, loc * 12);
            uint fSpos = BitConverter.ToUInt32(FI, (loc * 12) + 4);
            bool compe = BitConverter.ToUInt32(FI, (loc * 12) + 8) != 0;

            byte[] file = new byte[fsLen];

            Array.Copy(FS, fSpos, file, 0, file.Length);
            return(compe ? LZSS.DecompressAllNew(file) : file);
        }
Esempio n. 5
0
 public static byte[] GetBinaryFile(string archiveName, string fileName)
 {
     byte[] isComp = GetBin(MakiExtended.GetUnixFullPath(archiveName), fileName);
     return(isComp == null ? null : _compressed?LZSS.DecompressAll(isComp, (uint)isComp.Length, (int)_unpackedFileSize) : isComp);
 }
Esempio n. 6
0
        //Splash is 640x400 16BPP typical TIM with palette of ggg bbbbb a rrrrr gg
        internal static void ReadSplash(bool bLogo = false)
        {
            if (!bLogo)
            {
                if (splashName > 0x0f)
                {
                    return;
                }

                string[] lof      = aw.GetListOfFiles();
                string   fileName = bNames
                    ? lof.First(x => x.ToLower().Contains($"{names}{splashName.ToString("D2")}"))
                    : lof.First(x => x.ToLower().Contains($"{loops}{splashLoop.ToString("D2")}"));
                byte[] buffer     = ArchiveWorker.GetBinaryFile(Memory.Archives.A_MAIN, fileName);
                uint   uncompSize = BitConverter.ToUInt32(buffer, 0);
                buffer = LZSS.DecompressAll(buffer, (uint)buffer.Length);

                if (splashTex != null && !splashTex.IsDisposed)
                {
                    splashTex.Dispose();
                }
                splashTex = new Texture2D(Memory.graphics.GraphicsDevice, 640, 400, false, SurfaceFormat.Color);
                byte[] rgbBuffer        = new byte[splashTex.Width * splashTex.Height * 4];
                int    innerBufferIndex = 0;
                for (int i = 0; i < rgbBuffer.Length; i += 4)
                {
                    if (innerBufferIndex + 1 >= buffer.Length)
                    {
                        break;
                    }

                    ushort pixel = (ushort)((buffer[innerBufferIndex + 1] << 8) | buffer[innerBufferIndex]);
                    byte   red   = (byte)((pixel) & 0x1F);
                    byte   green = (byte)((pixel >> 5) & 0x1F);
                    byte   blue  = (byte)((pixel >> 10) & 0x1F);
                    red               = (byte)MathHelper.Clamp((red * 8), 0, 255);
                    green             = (byte)MathHelper.Clamp((green * 8), 0, 255);
                    blue              = (byte)MathHelper.Clamp((blue * 8), 0, 255);
                    rgbBuffer[i]      = red;
                    rgbBuffer[i + 1]  = green;
                    rgbBuffer[i + 2]  = blue;
                    rgbBuffer[i + 3]  = 255;//(byte)(((pixel >> 7) & 0x1) == 1 ? 255 : 0);
                    innerBufferIndex += 2;
                }
                splashTex.SetData(rgbBuffer);
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            else
            {
                string[] lof      = aw.GetListOfFiles();
                string   fileName = lof.First(x => x.ToLower().Contains($"ff8.lzs"));

                byte[] buffer     = ArchiveWorker.GetBinaryFile(Memory.Archives.A_MAIN, fileName);
                uint   uncompSize = BitConverter.ToUInt32(buffer, 0);
                buffer = LZSS.DecompressAll(buffer, (uint)buffer.Length);
                if (splashTex != null && !splashTex.IsDisposed)
                {
                    splashTex.Dispose();
                }
                splashTex = new Texture2D(Memory.graphics.GraphicsDevice, 640, 400, false, SurfaceFormat.Color);
                byte[] rgbBuffer        = new byte[splashTex.Width * splashTex.Height * 4];
                int    innerBufferIndex = 0;
                for (int i = 0; i < rgbBuffer.Length; i += 4)
                {
                    if (innerBufferIndex + 1 >= buffer.Length)
                    {
                        break;
                    }

                    ushort pixel = (ushort)((buffer[innerBufferIndex + 1] << 8) | buffer[innerBufferIndex]);
                    byte   red   = (byte)((pixel) & 0x1F);
                    byte   green = (byte)((pixel >> 5) & 0x1F);
                    byte   blue  = (byte)((pixel >> 10) & 0x1F);
                    red               = (byte)MathHelper.Clamp((red * 8), 0, 255);
                    green             = (byte)MathHelper.Clamp((green * 8), 0, 255);
                    blue              = (byte)MathHelper.Clamp((blue * 8), 0, 255);
                    rgbBuffer[i]      = red;
                    rgbBuffer[i + 1]  = green;
                    rgbBuffer[i + 2]  = blue;
                    rgbBuffer[i + 3]  = 255;//(byte)(((pixel >> 7) & 0x1) == 1 ? 255 : 0);
                    innerBufferIndex += 2;
                }
                splashTex.SetData(rgbBuffer);
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }