Example #1
0
        public void BackSpace(NitroFile bca, uint addr, uint len, ref BCAOffsetData offs, bool forAlignment = false)
        {
            bca.AddSpace(addr, (uint)-len);
            uint oldRotOffset  = offs.rotOffset;
            uint oldPosOffset  = offs.posOffset;
            uint oldAnimOffset = offs.animOffset;

            if (addr <= offs.scaleOffset)
            {
                offs.scaleOffset -= len;
            }
            if (addr <= offs.rotOffset)
            {
                offs.rotOffset -= len;
            }
            if (addr <= offs.posOffset)
            {
                offs.posOffset -= len;
            }
            if (addr <= offs.animOffset)
            {
                offs.animOffset -= len;
            }

            bca.Write32(0x08, offs.scaleOffset);
            bca.Write32(0x0c, offs.rotOffset);
            bca.Write32(0x10, offs.posOffset);
            bca.Write32(0x14, offs.animOffset);

            if (forAlignment)
            {
                return;
            }

            uint trTypeIndex;

            if (addr > offs.scaleOffset && addr <= oldRotOffset)
            {
                trTypeIndex = 0;
            }
            else if (addr > offs.rotOffset && addr <= oldPosOffset)
            {
                trTypeIndex = 1;
            }
            else if (addr > offs.posOffset && addr <= oldAnimOffset)
            {
                trTypeIndex = 2;
            }
            else
            {
                return;
            }

            uint dataOffset, unitSize;

            offs.GetDataOffsetAndSize(trTypeIndex, out dataOffset, out unitSize);

            uint startSubAt = (addr - dataOffset) / unitSize;
            uint valToSub   = len / unitSize;

            uint numBones = bca.Read16(0x00);

            for (uint i = 0; i < numBones; ++i)
            {
                for (uint j = 0; j < 3; ++j)
                {
                    uint offset = offs.animOffset + 0x24 * i + 4 * (3 * trTypeIndex + j) + 2;
                    uint temp   = bca.Read16(offset);
                    if (temp >= startSubAt)
                    {
                        bca.Write16(offset, (ushort)(temp - valToSub));
                    }
                }
            }
        }