Beispiel #1
0
        private static StaticRecord[][] LoadStatics(int map)
        {
            string staticIndexFile = Path.Combine(_dataPath, $"staidx{map}.mul");
            string staticMulFile   = Path.Combine(_dataPath, $"statics{map}.mul");

            if (!File.Exists(staticIndexFile))
            {
                return(null);
            }

            if (!File.Exists(staticMulFile))
            {
                return(null);
            }

            byte[] indexBytes = File.ReadAllBytes(staticIndexFile);

            StaticRecord[][] staticItems = new StaticRecord[indexBytes.Length / 12][];

            using (FileStream fileStream =
                       new FileStream(staticMulFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    for (int x = 0; x < indexBytes.Length / 12; x++)
                    {
                        int offset = x * 12;
                        int start  = BitConverter.ToInt32(indexBytes, offset);
                        int length = BitConverter.ToInt32(indexBytes, offset + 4);

                        if (start == -1)
                        {
                            continue;
                        }

                        fileStream.Seek(start, SeekOrigin.Begin);

                        staticItems[x] = new StaticRecord[length / 7];

                        for (int y = 0; y < length / 7; y++)
                        {
                            staticItems[x][y].ID  = binaryReader.ReadUInt16();
                            staticItems[x][y].X   = binaryReader.ReadByte();
                            staticItems[x][y].Y   = binaryReader.ReadByte();
                            staticItems[x][y].Z   = binaryReader.ReadSByte();
                            staticItems[x][y].Hue = binaryReader.ReadUInt16();
                        }
                    }
                }
            }

            return(staticItems);
        }
Beispiel #2
0
        private static StaticRecord[] GetStaticRecords(StaticIndexRecord indexRecord, FileStream fileStream)
        {
            if (indexRecord.length == -1)
            {
                return(null);
            }

            StaticRecord[] staticRecords = new StaticRecord[indexRecord.length / 7];
            byte[]         fileBytes     = new byte[indexRecord.length];
            lock (fileStream)
            {
                fileStream.Seek(indexRecord.start, SeekOrigin.Begin);
                fileStream.Read(fileBytes, 0, indexRecord.length);
            }
            for (int x = 0; x < staticRecords.Length; x++)
            {
                staticRecords[x].id = BitConverter.ToUInt16(fileBytes, x * 7);
                staticRecords[x].x  = fileBytes[x * 7 + 2];
                staticRecords[x].y  = fileBytes[x * 7 + 3];
                staticRecords[x].z  = (sbyte)fileBytes[x * 7 + 4];
            }
            return(staticRecords);
        }
Beispiel #3
0
 private static void LoadStatics(string fileName, ref StaticIndexRecord[] staticIndexRecord, ref StaticRecord[][] staticItems)
 {
     if (File.Exists(fileName))
     {
         byte[] fileBytes = File.ReadAllBytes(fileName);
         for (int x = 0; x < staticIndexRecord.Length; x++)
         {
             if (staticIndexRecord[x].start == -1)
             {
                 continue;
             }
             int recordsToFetch = staticIndexRecord[x].length / 7;
             staticItems[x] = new StaticRecord[recordsToFetch];
             for (int y = 0; y < recordsToFetch; y++)
             {
                 staticItems[x][y].id = BitConverter.ToUInt16(fileBytes, staticIndexRecord[x].start + y * 7);
                 staticItems[x][y].x  = fileBytes[staticIndexRecord[x].start + y * 7 + 2];
                 staticItems[x][y].y  = fileBytes[staticIndexRecord[x].start + y * 7 + 3];
                 staticItems[x][y].z  = (sbyte)fileBytes[staticIndexRecord[x].start + y * 7 + 4];
             }
         }
     }
 }
Beispiel #4
0
 private static void LoadStatics(string fileName, ref StaticIndexRecord[] staticIndexRecord, ref StaticRecord[][] staticItems)
 {
     if (File.Exists(fileName))
     {
         byte[] fileBytes = File.ReadAllBytes(fileName);
         for (int x = 0; x < staticIndexRecord.Length; x++)
         {
             if (staticIndexRecord[x].start == -1) continue;
             int recordsToFetch = staticIndexRecord[x].length / 7;
             staticItems[x] = new StaticRecord[recordsToFetch];
             for (int y = 0; y < recordsToFetch; y++)
             {
                 staticItems[x][y].id = BitConverter.ToUInt16(fileBytes, staticIndexRecord[x].start + y * 7);
                 staticItems[x][y].x = fileBytes[staticIndexRecord[x].start + y * 7 + 2];
                 staticItems[x][y].y = fileBytes[staticIndexRecord[x].start + y * 7 + 3];
                 staticItems[x][y].z = (sbyte)fileBytes[staticIndexRecord[x].start + y * 7 + 4];
             }
         }
     }
 }
Beispiel #5
0
        private static StaticRecord[] GetStaticRecords(StaticIndexRecord indexRecord, FileStream fileStream)
        {
            if (indexRecord.length == -1) return null;

            StaticRecord[] staticRecords = new StaticRecord[indexRecord.length / 7];
            byte[] fileBytes = new byte[indexRecord.length];
            lock (fileStreamLock)
            {
                fileStream.Seek(indexRecord.start, SeekOrigin.Begin);
                fileStream.Read(fileBytes, 0, indexRecord.length);
            }
            for (int x = 0; x < staticRecords.Length; x++)
            {
                staticRecords[x].id = BitConverter.ToUInt16(fileBytes, x * 7);
                staticRecords[x].x = fileBytes[x * 7 + 2];
                staticRecords[x].y = fileBytes[x * 7 + 3];
                staticRecords[x].z = (sbyte)fileBytes[x * 7 + 4];
            }
            return staticRecords;
        }
Beispiel #6
0
 private static StaticTile[] GetMatchingTiles(StaticRecord[] staticRecords, int x, int y)
 {
     if (staticRecords == null) return null;
     int cellX = x % 8;
     int cellY = y % 8;
     List<StaticTile> tileList = new List<StaticTile>(32);
     foreach (StaticRecord s in staticRecords)
     {
         if (s.x == cellX && s.y == cellY)
         {
             StaticTile staticTile = new StaticTile(TileData.GetStaticTile(s.id));
             staticTile.X = x;
             staticTile.Y = y;
             staticTile.Z = s.z;
             tileList.Add(staticTile);
         }
     }
     if (tileList.Count > 0) return tileList.ToArray();
     return null;
 }