コード例 #1
0
        public override byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.endian = Endianness.Big;

            f.WriteHex("4C494748"); //LIGH
            f.WriteInt(version);
            f.WriteInt(frameCount);
            if (version == 5)
            {
                f.WriteInt(frameDuration);
            }

            //Offsets
            int padding = 0;

            while ((((frameCount * 3) + padding) % 4) != 0) //All offsets must be multiples of 4 or the game won't use the file properly
            {
                padding++;
            }

            int[] offsets = new int[6];
            int   currOff = 0x24;

            if (version == 4)
            {
                currOff = 0x24;
            }
            else if (version == 5)
            {
                currOff = 0x28;
            }

            for (int i = 0; i < 5; i++)
            {
                offsets[i + 1] = (rgbProperties[i].enabled) ? currOff : 0x0;
                if (rgbProperties[i].enabled)
                {
                    currOff += (frameCount * 3) + padding;
                }
            }
            offsets[0] = currOff;

            for (int i = 0; i < 6; i++)
            {
                f.WriteInt(offsets[i]);
            }

            //RGB properties
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < frameCount; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        f.WriteByte(rgbProperties[i].frames[j][k]);
                    }
                }

                for (int j = 0; j < padding; j++)
                {
                    f.WriteByte(0);
                }
            }

            //Light data
            for (int i = 0; i < frameCount; i++)
            {
                for (int j = 0; j < 17; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        f.WriteInt(lightFrames[i].lightSets[j].lights[k].enabled);
                        for (int l = 0; l < 3; l++)
                        {
                            f.WriteFloat(lightFrames[i].lightSets[j].lights[k].angle[l]);
                        }
                        f.WriteFloat(lightFrames[i].lightSets[j].lights[k].colorHue);
                        f.WriteFloat(lightFrames[i].lightSets[j].lights[k].colorSat);
                        f.WriteFloat(lightFrames[i].lightSets[j].lights[k].colorVal);
                    }
                    f.WriteByte(lightFrames[i].lightSets[j].fog.unknown);
                    for (int k = 0; k < 3; k++)
                    {
                        f.WriteByte(lightFrames[i].lightSets[j].fog.color[k]);
                    }
                }
                f.WriteByte(lightFrames[i].effect.unknown);
                for (int j = 0; j < 3; j++)
                {
                    f.WriteByte(lightFrames[i].effect.color[j]);
                }
                for (int j = 0; j < 3; j++)
                {
                    f.WriteFloat(lightFrames[i].effect.position[j]);
                }
            }

            return(f.GetBytes());
        }