0 Replies - 148 Views - Last Post: 31 July 2013 - 03:02 AM Rate Topic: -----

#1 WelshCerberus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-July 13

Problem extracting .adf file

Posted 31 July 2013 - 03:02 AM

Hey i cant figure out what i am doing wrong, Its to extract some images from .adf files, I have had it working about 2 years ago but now i cant figure out the right directory. I can post the files i need to extract and the project if it helps.

Thanks




using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;

namespace ADFReader
{
    class Program
    {
        public static int ApplyOffset(int data, int offset)
        {
            return (data - offset);
        }

        public static byte ApplyOffsetByte(byte data, int offset)
        {
            if (offset > data)
            {
                data = (byte)(data + (0x100 - offset));
                return data;
            }
            data = (byte)(data - offset);
            return data;
        }

        public static int RealSize(int datasize, int chunksize)
        {
            return (datasize - (datasize / (chunksize + 1)));
        }

        static void Main(string[] args)
        {
            foreach (string file in Directory.GetFiles(@"data\", "*.adf")) ;
            {
                byte[] bytes = File.ReadAllBytes(file);

                // so the last byte happens to be twice the "offset" number.
                // but that doesn't matter because the second to last byte is *always?* the offset number anyways!
                byte offset = bytes[bytes.Length - 2];

                BinaryReader reader = new BinaryReader(new MemoryStream(bytes));
                StreamWriter writer = new StreamWriter(@"asppp\" + Path.GetFileName(file) + "-header.txt");

                byte fileType = reader.ReadByte();
                int extraLength = reader.ReadInt32() + 1;
                writer.WriteLine("Type: {0}, Extra Length: {1}", fileType, extraLength);
                // not sure what these extra bytes are
                writer.Write("Extra Bytes: ");
                for (int i = 0; i < extraLength; i++) writer.Write("{0,4}", ApplyOffsetByte(reader.ReadByte(), offset));
                writer.WriteLine();
                int numberOfFrames = ApplyOffset(reader.ReadInt32(), offset);
                writer.WriteLine("NumberOfFrames: {0}", numberOfFrames);

                for (int i = 0; i < numberOfFrames; i++)
                {
                    int frameId = ApplyOffset(reader.ReadInt32(), offset);
                    // always 1 as far as i have seen
                    byte unknownByte = ApplyOffsetByte(reader.ReadByte(), offset);
                    int x = ApplyOffset(reader.ReadInt32(), offset);
                    int y = ApplyOffset(reader.ReadInt32(), offset);
                    int width = ApplyOffset(reader.ReadInt32(), offset);
                    int height = ApplyOffset(reader.ReadInt32(), offset);

                    writer.WriteLine("Id: {0,4} U: {1,4} X: {2,4} Y: {3,4} W: {4,4} H: {5,4}", frameId, unknownByte, x, y, width, height);
                }

                // not sure what this is, 36 = wav though i think
                int unknown = ApplyOffset(reader.ReadInt32(), offset);
                writer.WriteLine("U: {0}", unknown);

                writer.Close();

                int length = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
                byte[] buffer = reader.ReadBytes(length);
                byte[] data = new byte[RealSize(buffer.Length, 0x315)];
                for (int k = 0; k < buffer.Length; k++)
                {
                    data[k - (k / 790)] = ApplyOffsetByte(buffer[k], offset);
                }

                string ext = ".bmp";
                if (unknown == 36) ext = ".wav";

                File.WriteAllBytes(@"asppp\" + Path.GetFileName(file) + ext, data);
            }
        }
    }
}







Sorry for the double post, The main problem is


static void Main(string[] args)
        {
            foreach (string file in Directory.GetFiles(@"data\", "*.adf")) ;
            {
                byte[] bytes = File.ReadAllBytes(file);

                // so the last byte happens to be twice the "offset" number.
                // but that doesn't matter because the second to last byte is *always?* the offset number anyways!
                byte offset = bytes[bytes.Length - 2];

                BinaryReader reader = new BinaryReader(new MemoryStream(bytes));
                StreamWriter writer = new StreamWriter(@"asppp\" + Path.GetFileName(file) + "-header.txt");





Is This A Good Question/Topic? 0
  • +

Page 1 of 1