コード例 #1
0
        private void ReplaceStatic(string path, int map, int width, int height)
        {
            string       indexPath = Files.GetFilePath($"staidx{map}.mul");
            BinaryReader mIndexReader;

            if (indexPath != null)
            {
                var mIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                mIndexReader = new BinaryReader(mIndex);
            }
            else
            {
                return;
            }

            string staticsPath = Files.GetFilePath($"statics{map}.mul");

            FileStream   mStatics;
            BinaryReader mStaticsReader;

            if (staticsPath != null)
            {
                mStatics       = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                mStaticsReader = new BinaryReader(mStatics);
            }
            else
            {
                return;
            }

            int blockx = width >> 3;
            int blocky = height >> 3;

            string idx = Path.Combine(path, $"staidx{map}.mul");
            string mul = Path.Combine(path, $"statics{map}.mul");

            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                   fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                using (BinaryWriter binidx = new BinaryWriter(fsidx),
                       binmul = new BinaryWriter(fsmul))
                {
                    for (int x = 0; x < blockx; ++x)
                    {
                        for (int y = 0; y < blocky; ++y)
                        {
                            try
                            {
                                mIndexReader.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin);
                                int lookup = mIndexReader.ReadInt32();
                                int length = mIndexReader.ReadInt32();
                                int extra  = mIndexReader.ReadInt32();

                                if (lookup < 0 || length <= 0)
                                {
                                    binidx.Write(-1); // lookup
                                    binidx.Write(-1); // length
                                    binidx.Write(-1); // extra
                                }
                                else
                                {
                                    if (lookup >= 0 && length > 0)
                                    {
                                        mStatics.Seek(lookup, SeekOrigin.Begin);
                                    }

                                    int fsMulLength = (int)fsmul.Position;
                                    int count       = length / 7;

                                    bool firstItem = true;
                                    for (int i = 0; i < count; ++i)
                                    {
                                        ushort graphic = mStaticsReader.ReadUInt16();
                                        byte   sx      = mStaticsReader.ReadByte();
                                        byte   sy      = mStaticsReader.ReadByte();
                                        sbyte  sz      = mStaticsReader.ReadSByte();
                                        short  sHue    = mStaticsReader.ReadInt16();
                                        int    temp    = ModArea.IsStaticReplace(_toReplace, graphic, x, y, i);

                                        if (graphic > Art.GetMaxItemID())
                                        {
                                            continue;
                                        }

                                        if (sHue < 0)
                                        {
                                            sHue = 0;
                                        }

                                        if (firstItem)
                                        {
                                            binidx.Write((int)fsmul.Position); //lookup
                                            firstItem = false;
                                        }
                                        if (temp != -1)
                                        {
                                            graphic = (ushort)temp;
                                        }

                                        binmul.Write(graphic);
                                        binmul.Write(sx);
                                        binmul.Write(sy);
                                        binmul.Write(sz);
                                        binmul.Write(sHue);
                                    }

                                    fsMulLength = (int)fsmul.Position - fsMulLength;
                                    if (fsMulLength > 0)
                                    {
                                        binidx.Write(fsMulLength); //length
                                        if (extra == -1)
                                        {
                                            extra = 0;
                                        }

                                        binidx.Write(extra); //extra
                                    }
                                    else
                                    {
                                        binidx.Write(-1); //lookup
                                        binidx.Write(-1); //length
                                        binidx.Write(-1); //extra
                                    }
                                }
                            }
                            catch // fill the rest
                            {
                                binidx.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin);
                                for (; x < blockx; ++x)
                                {
                                    for (; y < blocky; ++y)
                                    {
                                        binidx.Write(-1); //lookup
                                        binidx.Write(-1); //length
                                        binidx.Write(-1); //extra
                                    }
                                    y = 0;
                                }
                                return;
                            }
                        }
                    }
                }
            }
            mIndexReader.Close();
            mStaticsReader.Close();
        }
コード例 #2
0
        private void ReplaceMap(string path, int map, int width, int height)
        {
            string       mapPath = Files.GetFilePath($"map{map}.mul");
            BinaryReader mMapReader;

            if (mapPath != null)
            {
                var mMap = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                mMapReader = new BinaryReader(mMap);
            }
            else
            {
                return;
            }

            int blockx = width >> 3;
            int blocky = height >> 3;

            string mul = Path.Combine(path, $"map{map}.mul");

            using (FileStream fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                using (BinaryWriter binmul = new BinaryWriter(fsmul))
                {
                    for (int x = 0; x < blockx; ++x)
                    {
                        for (int y = 0; y < blocky; ++y)
                        {
                            try
                            {
                                mMapReader.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin);
                                int header = mMapReader.ReadInt32();
                                binmul.Write(header);
                                for (int i = 0; i < 64; ++i)
                                {
                                    ushort tileid = mMapReader.ReadUInt16();
                                    int    temp   = ModArea.IsLandReplace(_toReplace, tileid, x, y, i);
                                    sbyte  z      = mMapReader.ReadSByte();
                                    if (tileid >= 0x4000)
                                    {
                                        tileid = 0;
                                    }
                                    else if (temp != -1)
                                    {
                                        tileid = (ushort)temp;
                                    }

                                    if (z < -128)
                                    {
                                        z = -128;
                                    }

                                    if (z > 127)
                                    {
                                        z = 127;
                                    }

                                    binmul.Write(tileid);
                                    binmul.Write(z);
                                }
                            }
                            catch //fill rest
                            {
                                binmul.BaseStream.Seek(((x * blocky) + y) * 196, SeekOrigin.Begin);
                                for (; x < blockx; ++x)
                                {
                                    for (; y < blocky; ++y)
                                    {
                                        binmul.Write(0);
                                        for (int i = 0; i < 64; ++i)
                                        {
                                            binmul.Write((short)0);
                                            binmul.Write((sbyte)0);
                                        }
                                    }
                                    y = 0;
                                }
                                return;
                            }
                        }
                    }
                }
            }
            mMapReader.Close();
        }