Beispiel #1
0
 /// <summary>
 /// Load a material from a file buffer, with labels.
 /// </summary>
 /// <param name="file">byte array representing file</param>
 /// <param name="address">address of this material within 'file' byte array.</param>
 /// <param name="labels"></param>
 public NJS_MATERIAL(byte[] file, int address, Dictionary <int, string> labels)
 {
     if (ByteConverter.BigEndian)
     {
         //"Reverse" is for the order used in SADX Gamecube
         if (ByteConverter.Reverse)
         {
             DiffuseColor  = Color.FromArgb(file[address + 3], file[address], file[address + 1], file[address + 2]);
             SpecularColor = Color.FromArgb(file[address + 7], file[address + 4], file[address + 5], file[address + 6]);
         }
         else
         {
             DiffuseColor  = Color.FromArgb(file[address], file[address + 1], file[address + 2], file[address + 3]);
             SpecularColor = Color.FromArgb(file[address + 4], file[address + 5], file[address + 6], file[address + 7]);
         }
     }
     else
     {
         DiffuseColor  = Color.FromArgb(file[address + 3], file[address + 2], file[address + 1], file[address]);
         SpecularColor = Color.FromArgb(file[address + 7], file[address + 6], file[address + 5], file[address + 4]);
     }
     Exponent  = ByteConverter.ToSingle(file, address + 8);
     TextureID = ByteConverter.ToInt32(file, address + 0xC);
     Flags     = ByteConverter.ToUInt32(file, address + 0x10);
 }
Beispiel #2
0
        public GeoAnimData(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, Dictionary <int, Attach> attaches)
        {
            ModelFormat mfmt = 0;

            switch (format)
            {
            case LandTableFormat.SA1:
                mfmt = ModelFormat.Basic;
                break;

            case LandTableFormat.SADX:
                mfmt = ModelFormat.BasicDX;
                break;

            case LandTableFormat.SA2:
                mfmt = ModelFormat.Chunk;
                break;
            }
            Unknown1  = ByteConverter.ToInt32(file, address);
            Unknown2  = ByteConverter.ToSingle(file, address + 4);
            Unknown3  = ByteConverter.ToSingle(file, address + 8);
            Model     = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address + 0xC) - imageBase), imageBase, mfmt, labels, attaches);
            Animation = NJS_MOTION.ReadHeader(file, (int)(ByteConverter.ToUInt32(file, address + 0x10) - imageBase), imageBase, mfmt, labels, attaches);
            Unknown4  = ByteConverter.ToInt32(file, address + 0x14);
        }
Beispiel #3
0
 /// <summary>
 /// Load a material from a file buffer, with labels.
 /// </summary>
 /// <param name="file">byte array representing file</param>
 /// <param name="address">address of this material within 'file' byte array.</param>
 /// <param name="labels"></param>
 public NJS_MATERIAL(byte[] file, int address, Dictionary <int, string> labels)
 {
     DiffuseColor  = Color.FromArgb(ByteConverter.ToInt32(file, address));
     SpecularColor = Color.FromArgb(ByteConverter.ToInt32(file, address + 4));
     Exponent      = ByteConverter.ToSingle(file, address + 8);
     TextureID     = ByteConverter.ToInt32(file, address + 0xC);
     Flags         = ByteConverter.ToUInt32(file, address + 0x10);
 }
Beispiel #4
0
 public Vertex(byte[] file, int address)
 {
     if (address > file.Length - 12)
     {
         X = 0;
         Y = 0;
         Z = 0;
     }
     else
     {
         X = ByteConverter.ToSingle(file, address);
         Y = ByteConverter.ToSingle(file, address + 4);
         Z = ByteConverter.ToSingle(file, address + 8);
     }
 }
Beispiel #5
0
        public GeoAnimData(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, Dictionary <int, Attach> attaches)
        {
            ModelFormat mfmt = 0;

            switch (format)
            {
            case LandTableFormat.SA1:
                mfmt = ModelFormat.Basic;
                break;

            case LandTableFormat.SADX:
                mfmt = ModelFormat.BasicDX;
                break;

            case LandTableFormat.SA2:
                mfmt = ModelFormat.Chunk;
                break;
            }
            Unknown1 = ByteConverter.ToInt32(file, address);
            Unknown2 = ByteConverter.ToSingle(file, address + 4);
            Unknown3 = ByteConverter.ToSingle(file, address + 8);
            Model    = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address + 0xC) - imageBase), imageBase, mfmt, labels, attaches);
            int actionaddr = (int)(ByteConverter.ToUInt32(file, address + 0x10) - imageBase);
            int motionaddr = (int)(ByteConverter.ToUInt32(file, actionaddr + 4) - imageBase);

            Animation = NJS_MOTION.ReadDirect(file, Model.CountAnimated(), motionaddr, imageBase, labels, attaches);
            Unknown4  = ByteConverter.ToInt32(file, address + 0x14);
            if (labels.ContainsKey(actionaddr))
            {
                ActionName = labels[actionaddr];
            }
            else
            {
                NJS_ACTION action = new NJS_ACTION(file, actionaddr, imageBase, mfmt, labels, attaches);
                ActionName = action.Name;
                labels.Add(actionaddr + (int)imageBase, ActionName);
            }
        }
Beispiel #6
0
        public LandTable(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels)
        {
            Format = format;
            if (labels.ContainsKey(address))
            {
                Name = labels[address];
            }
            else
            {
                Name = "landtable_" + address.ToString("X8");
            }
            short colcnt = ByteConverter.ToInt16(file, address);

            switch (format)
            {
            case LandTableFormat.SA1:
            case LandTableFormat.SADX:
                short anicnt = ByteConverter.ToInt16(file, address + 2);
                Flags    = ByteConverter.ToInt32(file, address + 4);
                Unknown1 = ByteConverter.ToSingle(file, address + 8);
                COL      = new List <COL>();
                int tmpaddr = ByteConverter.ToInt32(file, address + 0xC);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        COLName = labels[tmpaddr];
                    }
                    else
                    {
                        COLName = "collist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < colcnt; i++)
                    {
                        COL.Add(new COL(file, tmpaddr, imageBase, format, labels));
                        tmpaddr += SAModel.COL.Size(format);
                    }
                }
                else
                {
                    COLName = "collist_" + Extensions.GenerateIdentifier();
                }
                Anim    = new List <GeoAnimData>();
                tmpaddr = ByteConverter.ToInt32(file, address + 0x10);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        AnimName = labels[tmpaddr];
                    }
                    else
                    {
                        AnimName = "animlist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < anicnt; i++)
                    {
                        Anim.Add(new GeoAnimData(file, tmpaddr, imageBase, format, labels));
                        tmpaddr += GeoAnimData.Size;
                    }
                }
                else
                {
                    AnimName = "animlist_" + Extensions.GenerateIdentifier();
                }
                tmpaddr = ByteConverter.ToInt32(file, address + 0x14);
                if (tmpaddr != 0)
                {
                    tmpaddr         = (int)unchecked ((uint)tmpaddr - imageBase);
                    TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII);
                }
                TextureList = ByteConverter.ToUInt32(file, address + 0x18);
                Unknown2    = ByteConverter.ToInt32(file, address + 0x1C);
                Unknown3    = ByteConverter.ToInt32(file, address + 0x20);
                break;

            case LandTableFormat.SA2:
                short cnkcnt = ByteConverter.ToInt16(file, address + 2);
                Unknown1 = ByteConverter.ToSingle(file, address + 0xC);
                COL      = new List <COL>();
                tmpaddr  = ByteConverter.ToInt32(file, address + 0x10);
                if (tmpaddr != 0)
                {
                    tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase);
                    if (labels.ContainsKey(tmpaddr))
                    {
                        COLName = labels[tmpaddr];
                    }
                    else
                    {
                        COLName = "collist_" + tmpaddr.ToString("X8");
                    }
                    for (int i = 0; i < colcnt; i++)
                    {
                        COL.Add(new COL(file, tmpaddr, imageBase, format, labels, cnkcnt < 0 ? null : (bool?)(i >= cnkcnt)));
                        tmpaddr += SAModel.COL.Size(format);
                    }
                }
                else
                {
                    COLName = "collist_" + Extensions.GenerateIdentifier();
                }
                Anim     = new List <GeoAnimData>();
                AnimName = "animlist_" + Extensions.GenerateIdentifier();
                tmpaddr  = ByteConverter.ToInt32(file, address + 0x18);
                if (tmpaddr != 0)
                {
                    tmpaddr         = (int)unchecked ((uint)tmpaddr - imageBase);
                    TextureFileName = file.GetCString(tmpaddr, Encoding.ASCII);
                }
                TextureList = ByteConverter.ToUInt32(file, address + 0x1C);
                break;
            }
            Metadata = new Dictionary <uint, byte[]>();
        }
Beispiel #7
0
 public BoundingSphere(byte[] file, int address)
 {
     Center = new Vertex(file, address);
     Radius = ByteConverter.ToSingle(file, address + Vertex.Size);
 }
Beispiel #8
0
        public COL(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, bool?forceBasic, Dictionary <int, Attach> attaches)
        {
            Bounds = new BoundingSphere(file, address);
            ModelFormat mfmt = 0;

            switch (format)
            {
            case LandTableFormat.SA1:
                mfmt = ModelFormat.Basic;
                break;

            case LandTableFormat.SADX:
                mfmt = ModelFormat.BasicDX;
                break;

            case LandTableFormat.SA2:
                if (forceBasic.HasValue && forceBasic.Value)
                {
                    mfmt = ModelFormat.Basic;
                }
                else
                {
                    mfmt = ModelFormat.Chunk;
                }
                break;

            case LandTableFormat.SA2B:
                if (forceBasic.HasValue && forceBasic.Value)
                {
                    mfmt = ModelFormat.Basic;
                }
                else
                {
                    mfmt = ModelFormat.GC;
                }
                break;
            }
            switch (format)
            {
            case LandTableFormat.SA1:
            case LandTableFormat.SADX:
                WidthY = ByteConverter.ToSingle(file, address + 0x10);
                WidthZ = ByteConverter.ToSingle(file, address + 0x14);
                uint tmpaddr = ByteConverter.ToUInt32(file, address + 0x18) - imageBase;
                Model     = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels, attaches);
                BlockBits = ByteConverter.ToInt32(file, address + 0x1C);
                Flags     = ByteConverter.ToInt32(file, address + 0x20);
                break;

            case LandTableFormat.SA2:
            case LandTableFormat.SA2B:
                Flags = ByteConverter.ToInt32(file, address + 0x1C);
                if (!forceBasic.HasValue && Flags >= 0)
                {
                    mfmt = ModelFormat.Basic;
                }
                tmpaddr   = ByteConverter.ToUInt32(file, address + 0x10) - imageBase;
                Model     = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels, attaches);
                WidthZ    = ByteConverter.ToInt32(file, address + 0x14);
                BlockBits = ByteConverter.ToInt32(file, address + 0x18);
                break;
            }
        }
Beispiel #9
0
 public Vertex(byte[] file, int address)
 {
     X = ByteConverter.ToSingle(file, address);
     Y = ByteConverter.ToSingle(file, address + 4);
     Z = ByteConverter.ToSingle(file, address + 8);
 }