fix(map): Fixes map diffs (Old Haven/Minax) (#720)

* Fixes reading map/static diffs.
This commit is contained in:
Kamron Batman 2021-08-22 23:35:18 -07:00 • committed by GitHub
parent 0bcf7a8d01
commit 9729b5a7b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 157 deletions

View file

@ -31,6 +31,14 @@ namespace Server
public FileStream DataStream { get; }
public BinaryReader IndexReader { get; }
private static bool Pre6000ClientSupport;
public static void Configure()
{
// Set to true to support < 6.0.0 clients where map0.mul is both Felucca & Trammel
Pre6000ClientSupport = ServerConfiguration.GetOrUpdateSetting("maps.enablePre6000Trammel", false);
}
public TileMatrix(Map owner, int fileIndex, int mapID, int width, int height)
{
lock (_instances)
@ -63,11 +71,13 @@ namespace Server
if (fileIndex != 0x7F)
{
fileIndex = Pre6000ClientSupport && mapID == 1 ? 0 : fileIndex;
var mapPath = Core.FindDataFile($"map{fileIndex}.mul", false);
if (mapPath != null)
{
MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
else
{
@ -75,7 +85,7 @@ namespace Server
if (mapPath != null)
{
MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
_mapIndex = new UOPIndex(MapStream);
}
else
@ -88,7 +98,7 @@ namespace Server
if (indexPath != null)
{
IndexStream = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
IndexStream = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
IndexReader = new BinaryReader(IndexStream);
}
else
@ -100,7 +110,7 @@ namespace Server
if (staticsPath != null)
{
DataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
DataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
else
{
@ -483,7 +493,7 @@ namespace Server
public int Height => 0;
public bool Ignored => m_ID == 2 || m_ID == 0x1DB || m_ID >= 0x1AE && m_ID <= 0x1B5;
public bool Ignored => m_ID is 2 or 0x1DB or >= 0x1AE and <= 0x1B5;
public LandTile(short id, sbyte z)
{

View file

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
@ -41,9 +42,8 @@ namespace Server
public static void Configure()
{
// Using this requires the old mapDif files to be present. Only needed to support Clients < 6.0.0.0
PatchLandEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableMapDiffPatches", false);
PatchStaticsEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableStaticsDiffPatches", false);
PatchLandEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableMapDiffPatches", !Core.HS);
PatchStaticsEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableStaticsDiffPatches", true);
}
[MethodImpl(MethodImplOptions.Synchronized)]
@ -51,15 +51,14 @@ namespace Server
{
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
var indexReader = new BinaryReader(fsIndex);
using var indexReader = new BinaryReader(fsIndex);
var count = (int)(indexReader.BaseStream.Length / 4);
for (var i = 0; i < count; ++i)
for (var i = 0; i < count; i++)
{
var blockID = indexReader.ReadInt32();
var x = blockID / matrix.BlockHeight;
var y = blockID % matrix.BlockHeight;
var x = Math.DivRem(blockID, matrix.BlockHeight, out var y);
fsData.Seek(4, SeekOrigin.Current);
@ -73,8 +72,6 @@ namespace Server
matrix.SetLandBlock(x, y, tiles);
}
indexReader.Close();
return count;
}