fix(core): Fixes map issues at New Haven (#509)

- [X] Fixes map issues at New Haven by turning off static diffs
- [X] Some code cleanup and reformatting of tile matrix, tile matrix patch, and tile data
- [X] Adds NetState.Flush for generating spawners so it doesn't feel like the server is frozen
- [X] Reverts NativeReader changes from a while back.
- [X] Adds more string reading for BufferReader.


Notes:
BufferReader is still `little endian` compared to `SpanReader` which is `big endian` (for packets). To that end, the RunUO deserialization `ReadString()` was made obsolete since it is ambiguous, and contains extra fields other than simply reading a string. Furthermore, we shouldn't be using UTF8 (for now) since it is slow.
This commit is contained in:
Kamron Batman 2021-02-14 16:06:49 -08:00 committed by GitHub
parent d070efeab3
commit ea5d09a7d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 724 additions and 482 deletions

View file

@ -1,4 +1,3 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
@ -6,45 +5,47 @@ namespace Server
{
public class TileMatrixPatch
{
private StaticTile[] m_TileBuffer = new StaticTile[128];
private StaticTile[] _tileBuffer = new StaticTile[128];
public static bool PatchLandEnabled { get; private set; }
public static bool PatchStaticsEnabled { get; private set; }
public int LandBlocks { get; }
public int StaticBlocks { get; }
public TileMatrixPatch(TileMatrix matrix, int index)
{
if (!Enabled)
if (PatchLandEnabled)
{
return;
var mapDataPath = Core.FindDataFile($"mapdif{index}.mul", false);
var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);
if (mapDataPath != null && mapIndexPath != null)
{
LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
}
}
var mapDataPath = Core.FindDataFile($"mapdif{index}.mul", false);
var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);
if (File.Exists(mapDataPath) && File.Exists(mapIndexPath))
if (PatchStaticsEnabled)
{
LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
}
var staDataPath = Core.FindDataFile($"stadif{index}.mul", false);
var staIndexPath = Core.FindDataFile($"stadifl{index}.mul", false);
var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false);
var staDataPath = Core.FindDataFile($"stadif{index}.mul", false);
var staIndexPath = Core.FindDataFile($"stadifl{index}.mul", false);
var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false);
if (File.Exists(staDataPath) && File.Exists(staIndexPath) && File.Exists(staLookupPath))
{
StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
if (staDataPath != null && staIndexPath != null && staLookupPath != null)
{
StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
}
}
}
public static bool Enabled { get; set; }
public static void Configure()
{
// Using this requires the old mapDif files to be present. Only needed to support Clients < 6.0.0.0
Enabled = ServerConfiguration.GetOrUpdateSetting("maps.enableTileMatrixPatches", !Core.SE);
PatchLandEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableMapDiffPatches", false);
PatchStaticsEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableStaticsDiffPatches", false);
}
public int LandBlocks { get; }
public int StaticBlocks { get; }
[MethodImpl(MethodImplOptions.Synchronized)]
private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
{
@ -66,13 +67,7 @@ namespace Server
fixed (LandTile* pTiles = tiles)
{
var ptr = fsData.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {fsData.Name}");
}
NativeReader.Read(ptr.Value, pTiles, 192);
NativeReader.Read(fsData, pTiles, 192);
}
matrix.SetLandBlock(x, y, tiles);
@ -126,22 +121,16 @@ namespace Server
var tileCount = length / 7;
if (m_TileBuffer.Length < tileCount)
if (_tileBuffer.Length < tileCount)
{
m_TileBuffer = new StaticTile[tileCount];
_tileBuffer = new StaticTile[tileCount];
}
var staTiles = m_TileBuffer;
var staTiles = _tileBuffer;
fixed (StaticTile* pTiles = staTiles)
{
var ptr = fsData.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {fsData.Name}");
}
NativeReader.Read(ptr.Value, pTiles, length);
NativeReader.Read(fsData, pTiles, length);
StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;