예제 #1
0
        public byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, out uint address)
        {
            FixSiblings();
            List <byte> result      = new List <byte>();
            uint        childaddr   = 0;
            uint        siblingaddr = 0;
            uint        attachaddr  = 0;

            byte[] tmpbyte;
            if (Children.Count > 0)
            {
                if (labels.ContainsKey(Children[0].Name))
                {
                    childaddr = labels[Children[0].Name];
                }
                else
                {
                    result.Align(4);
                    result.AddRange(Children[0].GetBytes(imageBase, DX, labels, out childaddr));
                    childaddr += imageBase;
                }
            }
            if (Sibling != null)
            {
                if (labels.ContainsKey(Sibling.Name))
                {
                    siblingaddr = labels[Sibling.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte      = Sibling.GetBytes(imageBase + (uint)result.Count, DX, labels, out siblingaddr);
                    siblingaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            if (Attach != null)
            {
                if (labels.ContainsKey(Attach.Name))
                {
                    attachaddr = labels[Attach.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte     = Attach.GetBytes(imageBase + (uint)result.Count, DX, labels, out attachaddr);
                    attachaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            result.Align(4);
            address = (uint)result.Count;
            ObjectFlags flags = GetFlags();

            result.AddRange(ByteConverter.GetBytes((int)flags));
            result.AddRange(ByteConverter.GetBytes(attachaddr));
            result.AddRange(Position.GetBytes());
            result.AddRange(Rotation.GetBytes());
            result.AddRange(Scale.GetBytes());
            result.AddRange(ByteConverter.GetBytes(childaddr));
            result.AddRange(ByteConverter.GetBytes(siblingaddr));
            labels.Add(Name, address + imageBase);
            return(result.ToArray());
        }
예제 #2
0
        public byte[] GetBytes(uint imageBase, bool DX, Dictionary <string, uint> labels, List <uint> njOffsets, out uint address, bool isFirst = false)
        {
            List <byte> result = new List <byte>();

            if (isFirst)
            {
                result.AddRange(new byte[0x34]);                 //Add size of NGS_OBJECT if first since we're inserting later
            }
            FixSiblings();
            uint childaddr   = 0;
            uint siblingaddr = 0;
            uint attachaddr  = 0;

            byte[] tmpbyte;
            if (Children.Count > 0)
            {
                if (labels.ContainsKey(Children[0].Name))
                {
                    childaddr = labels[Children[0].Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte    = Children[0].GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out childaddr);
                    childaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            if (Sibling != null)
            {
                if (labels.ContainsKey(Sibling.Name))
                {
                    siblingaddr = labels[Sibling.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte      = Sibling.GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out siblingaddr);
                    siblingaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }
            if (Attach != null)
            {
                if (labels.ContainsKey(Attach.Name))
                {
                    attachaddr = labels[Attach.Name];
                }
                else
                {
                    result.Align(4);
                    tmpbyte     = Attach.GetBytes(imageBase + (uint)result.Count, DX, labels, njOffsets, out attachaddr);
                    attachaddr += imageBase + (uint)result.Count;
                    result.AddRange(tmpbyte);
                }
            }

            result.Align(4);
            address = isFirst ? 0 : (uint)result.Count;
            ObjectFlags flags    = GetFlags();
            List <byte> objBytes = new List <byte>();

            objBytes.AddRange(ByteConverter.GetBytes((int)flags));
            objBytes.AddRange(ByteConverter.GetBytes(attachaddr));
            objBytes.AddRange(Position.GetBytes());
            objBytes.AddRange(Rotation.GetBytes());
            objBytes.AddRange(Scale.GetBytes());
            objBytes.AddRange(ByteConverter.GetBytes(childaddr));
            objBytes.AddRange(ByteConverter.GetBytes(siblingaddr));

            if (isFirst)             //Formal ninja requires the initial object first since there's not a pointer to it
            {
                //POF0
                if (attachaddr != 0)
                {
                    njOffsets.Add(0x4);
                }
                if (childaddr != 0)
                {
                    njOffsets.Add(0x2C);
                }
                if (siblingaddr != 0)
                {
                    njOffsets.Add(0x30);
                }

                result.RemoveRange(0, 0x34);
                result.InsertRange(0, objBytes);
            }
            else
            {
                //POF0
                if (attachaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }
                if (childaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }
                if (siblingaddr != 0)
                {
                    njOffsets.Add((uint)(imageBase + result.Count));
                }

                result.AddRange(objBytes);
            }
            labels.Add(Name, address + imageBase);
            return(result.ToArray());
        }