예제 #1
0
        public void ToStructVariables(TextWriter writer, LandTableFormat format, List <string> labels, string[] textures = null, bool decomp = false)
        {
            List <COL> cnk = new List <COL>();
            List <COL> bas = new List <COL>();

            foreach (COL item in COL)
            {
                if (item.Model.Attach is BasicAttach)
                {
                    bas.Add(item);
                }
                else
                {
                    cnk.Add(item);
                }
            }
            COL.Clear();
            COL.AddRange(cnk);
            COL.AddRange(bas);
            for (int i = 0; i < COL.Count; i++)
            {
                if (!labels.Contains(COL[i].Model.Name))
                {
                    labels.Add(COL[i].Model.Name);
                    if (!decomp)
                    {
                        COL[i].Model.ToStructVariables(writer, format == LandTableFormat.SADX, labels, textures);
                    }
                    else
                    {
                        writer.WriteLine("extern NJS_OBJECT " + COL[i].Model.Name + "[1];");
                    }
                }
            }
            for (int i = 0; i < Anim.Count; i++)
            {
                if (!labels.Contains(Anim[i].Model.Name))
                {
                    labels.Add(Anim[i].Model.Name);
                    if (!decomp)
                    {
                        Anim[i].Model.ToStructVariables(writer, format == LandTableFormat.SADX, labels, textures);
                    }
                    else
                    {
                        writer.WriteLine("extern NJS_OBJECT " + Anim[i].Model.Name + "[1];");
                    }
                    if (!decomp)
                    {
                        writer.WriteLine();
                    }
                }
                if (!labels.Contains(Anim[i].Animation.Name))
                {
                    if (!decomp)
                    {
                        Anim[i].Animation.ToStructVariables(writer, labels);
                    }
                    else
                    {
                        writer.WriteLine("extern NJS_ACTION " + Anim[i].Animation.ActionName + "[1];");
                    }
                    labels.Add(Anim[i].Animation.Name);
                    if (!decomp)
                    {
                        writer.WriteLine();
                    }
                }
            }
            writer.WriteLine();
            if (!labels.Contains(COLName))
            {
                labels.Add(COLName);
                writer.Write("_OBJ_LANDENTRY ");
                writer.Write(COLName);
                writer.WriteLine("[] = {");
                List <string> lines = new List <string>(COL.Count);
                foreach (COL item in COL)
                {
                    lines.Add(item.ToStruct(format, decomp));
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", lines.ToArray()));
                writer.WriteLine("};");
                writer.WriteLine();
            }
            if (Anim.Count > 0 && !labels.Contains(AnimName))
            {
                labels.Add(AnimName);
                writer.Write("_OBJ_MOTLANDENTRY ");
                writer.Write(AnimName);
                writer.WriteLine("[] = {");
                List <string> lines = new List <string>(Anim.Count);
                foreach (GeoAnimData item in Anim)
                {
                    lines.Add(item.ToStruct(decomp));
                }
                writer.WriteLine("\t" + string.Join("," + Environment.NewLine + "\t", lines.ToArray()));
                writer.WriteLine("};");
                writer.WriteLine();
            }
            writer.Write("_OBJ_LANDTABLE ");
            writer.Write(Name);
            writer.Write(" = { ");
            if (decomp)
            {
                writer.Write(COL.Count.ToString() + ", ");
            }
            else
            {
                writer.Write("LengthOfArray<int16_t>(" + COLName + "), ");
            }
            switch (format)
            {
            case LandTableFormat.SA1:
            case LandTableFormat.SADX:
                if (decomp)
                {
                    writer.Write(Anim.Count);
                }
                else
                {
                    writer.Write(Anim.Count > 0 ? "LengthOfArray<int16_t>(" + AnimName + ")" : "0");
                }
                writer.Write(", ");
                writer.Write("0x" + Attributes.ToString("X"));
                writer.Write(", ");
                writer.Write("0x" + Flags.ToString("X"));
                writer.Write(", ");
                writer.Write(FarClipping.ToC());
                writer.Write(", ");
                writer.Write(COLName);
                writer.Write(", ");
                writer.Write(Anim.Count > 0 ? AnimName : "NULL");
                writer.Write(", ");
                writer.Write(TextureFileName.ToC());
                writer.Write(", (NJS_TEXLIST *)");
                writer.Write(TextureList.ToCHex());
                writer.Write(", ");
                writer.Write(BinaryFilename.ToCHex());
                writer.Write(", ");
                writer.Write(BinaryLoadFunction.ToCHex());
                break;

            case LandTableFormat.SA2:
                writer.Write(cnk.Count);
                writer.Write(", 0, 0, 0, 0, ");
                writer.Write(FarClipping.ToC());
                writer.Write(", ");
                writer.Write(COLName);
                writer.Write(", ");
                writer.Write(Anim.Count > 0 ? AnimName : "NULL");
                writer.Write(", ");
                writer.Write(TextureFileName.ToC());
                writer.Write(", (NJS_TEXLIST *)");
                writer.Write(TextureList.ToCHex());
                break;
            }
            writer.WriteLine(" };");
        }
예제 #2
0
        public byte[] GetBytes(uint imageBase, LandTableFormat format, Dictionary <string, uint> labels, out uint address)
        {
            List <byte> result = new List <byte>();

            byte[]     tmpbyte;
            uint[]     colmdladdrs = new uint[COL.Count];
            uint       tmpaddr;
            List <COL> cnk = new List <COL>();
            List <COL> bas = new List <COL>();

            foreach (COL item in COL)
            {
                if (item.Model.Attach is BasicAttach)
                {
                    bas.Add(item);
                }
                else
                {
                    cnk.Add(item);
                }
            }
            COL.Clear();
            COL.AddRange(cnk);
            COL.AddRange(bas);
            for (int i = 0; i < COL.Count; i++)
            {
                if (labels.ContainsKey(COL[i].Model.Name))
                {
                    colmdladdrs[i] = labels[COL[i].Model.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte        = COL[i].Model.GetBytes(imageBase + (uint)result.Count, format == LandTableFormat.SADX, labels, new List <uint>(), out tmpaddr);
                    colmdladdrs[i] = tmpaddr + (uint)result.Count + imageBase;
                    result.AddRange(tmpbyte);
                }
            }
            uint[] animmdladdrs = new uint[Anim.Count];
            uint[] animaniaddrs = new uint[Anim.Count];
            for (int i = 0; i < Anim.Count; i++)
            {
                if (labels.ContainsKey(Anim[i].Model.Name))
                {
                    animmdladdrs[i] = labels[Anim[i].Model.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte = Anim[i].Model.GetBytes(imageBase + (uint)result.Count, format == LandTableFormat.SADX, labels, new List <uint>(),
                                                     out tmpaddr);
                    animmdladdrs[i] = tmpaddr + (uint)result.Count + imageBase;
                    result.AddRange(tmpbyte);
                }
                uint mtnaddr;
                if (labels.ContainsKey(Anim[i].Animation.Name))
                {
                    mtnaddr = labels[Anim[i].Animation.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte = Anim[i].Animation.GetBytes(imageBase + (uint)result.Count, labels, out tmpaddr);
                    mtnaddr = tmpaddr + (uint)result.Count + imageBase;
                    result.AddRange(tmpbyte);
                }
                result.Align(4);
                animaniaddrs[i] = (uint)result.Count + imageBase;
                result.AddRange(ByteConverter.GetBytes(animmdladdrs[i]));
                result.AddRange(ByteConverter.GetBytes(mtnaddr));
            }
            uint coladdr;

            if (COL.Count > 0)
            {
                if (labels.ContainsKey(COLName))
                {
                    coladdr = labels[COLName];
                }
                else
                {
                    coladdr = imageBase + (uint)result.Count;
                    labels.Add(COLName, coladdr);
                    for (int i = 0; i < COL.Count; i++)
                    {
                        result.Align(4);
                        result.AddRange(COL[i].GetBytes(imageBase + (uint)result.Count, colmdladdrs[i], format));
                    }
                }
            }
            else
            {
                coladdr = 0;
            }
            uint animaddr;

            if (Anim.Count > 0)
            {
                if (labels.ContainsKey(AnimName))
                {
                    animaddr = labels[AnimName];
                }
                else
                {
                    animaddr = imageBase + (uint)result.Count;
                    if (!labels.ContainsKey(AnimName))
                    {
                        labels.Add(AnimName, animaddr);
                    }
                    for (int i = 0; i < Anim.Count; i++)
                    {
                        if (!labels.ContainsValue(animaniaddrs[i]))
                        {
                            labels.Add(Anim[i].Animation.ActionName, animaniaddrs[i]);
                        }
                        result.Align(4);
                        result.AddRange(Anim[i].GetBytes(imageBase + (uint)result.Count, animmdladdrs[i], animaniaddrs[i]));
                    }
                }
            }
            else
            {
                animaddr = 0;
            }
            result.Align(4);
            uint texnameaddr = 0;

            if (TextureFileName != null)
            {
                texnameaddr = imageBase + (uint)result.Count;
                result.AddRange(Encoding.ASCII.GetBytes(TextureFileName));
                result.Add(0);
            }
            result.Align(4);
            address = (uint)result.Count;
            result.AddRange(ByteConverter.GetBytes((ushort)COL.Count));
            switch (format)
            {
            case LandTableFormat.SA1:
            case LandTableFormat.SADX:
                result.AddRange(ByteConverter.GetBytes((ushort)Anim.Count));
                result.AddRange(ByteConverter.GetBytes((short)Attributes));
                result.AddRange(ByteConverter.GetBytes(Flags));
                result.AddRange(ByteConverter.GetBytes(FarClipping));
                result.AddRange(ByteConverter.GetBytes(coladdr));
                result.AddRange(ByteConverter.GetBytes(animaddr));
                result.AddRange(ByteConverter.GetBytes(texnameaddr));
                result.AddRange(ByteConverter.GetBytes(TextureList));
                result.AddRange(ByteConverter.GetBytes(BinaryFilename));
                result.AddRange(ByteConverter.GetBytes(BinaryLoadFunction));
                break;

            case LandTableFormat.SA2:
            case LandTableFormat.SA2B:
                result.AddRange(ByteConverter.GetBytes((ushort)cnk.Count));
                result.AddRange(new byte[8]);                         // TODO: figure out what these do
                result.AddRange(ByteConverter.GetBytes(FarClipping));
                result.AddRange(ByteConverter.GetBytes(coladdr));
                result.AddRange(ByteConverter.GetBytes(animaddr));
                result.AddRange(ByteConverter.GetBytes(texnameaddr));
                result.AddRange(ByteConverter.GetBytes(TextureList));
                break;
            }
            labels.Add(Name, address + imageBase);
            return(result.ToArray());
        }