fix: Fixes loading map and static files (#1177)
This commit is contained in:
parent
cd5541ec74
commit
4946afee51
5 changed files with 727 additions and 712 deletions
|
|
@ -34,11 +34,11 @@ public class ClientVersion : IComparable<ClientVersion>, IComparer<ClientVersion
|
|||
public static readonly ClientVersion Version407a = new("4.0.7a");
|
||||
public static readonly ClientVersion Version500a = new("5.0.0a");
|
||||
public static readonly ClientVersion Version502b = new("5.0.2b");
|
||||
public static readonly ClientVersion Version6000 = new("6.0.0.0");
|
||||
public static readonly ClientVersion Version6000 = new("6.0.0.0"); // Map & Static diffs are no longer loaded
|
||||
public static readonly ClientVersion Version6017 = new("6.0.1.7");
|
||||
public static readonly ClientVersion Version60142 = new("6.0.14.2");
|
||||
public static readonly ClientVersion Version7000 = new("7.0.0.0");
|
||||
public static readonly ClientVersion Version7090 = new("7.0.9.0");
|
||||
public static readonly ClientVersion Version7090 = new("7.0.9.0"); // HS File format change
|
||||
public static readonly ClientVersion Version70120 = new("7.0.12.0"); // Plant localization change
|
||||
public static readonly ClientVersion Version70130 = new("7.0.13.0");
|
||||
public static readonly ClientVersion Version70160 = new("7.0.16.0");
|
||||
|
|
|
|||
|
|
@ -264,35 +264,10 @@ public static class ServerConfiguration
|
|||
m_Settings.Listeners.AddRange(ServerConfigurationPrompts.GetListeners());
|
||||
}
|
||||
|
||||
bool? isPre60000 = null;
|
||||
|
||||
if (m_Settings.Expansion == null)
|
||||
{
|
||||
var expansion = GetSetting<Expansion>("currentExpansion");
|
||||
var hasExpansion = expansion != null;
|
||||
|
||||
expansion ??= ServerConfigurationPrompts.GetExpansion();
|
||||
|
||||
if (expansion <= Expansion.ML && !hasExpansion)
|
||||
{
|
||||
isPre60000 = ServerConfigurationPrompts.GetIsClientPre6000();
|
||||
if (isPre60000 == true)
|
||||
{
|
||||
SetSetting("maps.enablePre6000Trammel", true);
|
||||
}
|
||||
}
|
||||
|
||||
m_Settings.Expansion = GetSetting<Expansion>("currentExpansion") ?? ServerConfigurationPrompts.GetExpansion();
|
||||
updated = true;
|
||||
m_Settings.Expansion = expansion;
|
||||
}
|
||||
|
||||
if (isPre60000 != true)
|
||||
{
|
||||
if (ServerConfigurationPrompts.GetIsClient7090())
|
||||
{
|
||||
updated = true;
|
||||
SetSetting("maps.enablePostHSMultiComponentFormat", true);
|
||||
}
|
||||
}
|
||||
|
||||
Core.Expansion = m_Settings.Expansion.Value;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public static class MultiData
|
|||
// OSI Client 7.0.9.0+ uses 64bit tiledata flags
|
||||
var postHSMulFormat = ServerConfiguration.GetSetting(
|
||||
"maps.enablePostHSMultiComponentFormat",
|
||||
UOClient.ServerClientVersion >= ClientVersion.Version7090
|
||||
UOClient.ServerClientVersion == null || UOClient.ServerClientVersion >= ClientVersion.Version7090
|
||||
);
|
||||
|
||||
LoadMul(postHSMulFormat);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,158 +1,183 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: TileMatrixPatch.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Server
|
||||
namespace Server;
|
||||
|
||||
public class TileMatrixPatch
|
||||
{
|
||||
public class TileMatrixPatch
|
||||
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)
|
||||
{
|
||||
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 (PatchLandEnabled)
|
||||
{
|
||||
if (PatchLandEnabled)
|
||||
var mapDataPath = Core.FindDataFile($"mapdif{index}.mul", false);
|
||||
var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);
|
||||
|
||||
if (mapDataPath != null && mapIndexPath != null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (PatchStaticsEnabled)
|
||||
{
|
||||
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 (staDataPath != null && staIndexPath != null && staLookupPath != null)
|
||||
{
|
||||
StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
|
||||
}
|
||||
LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
if (PatchStaticsEnabled)
|
||||
{
|
||||
PatchLandEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableMapDiffPatches", !Core.HS);
|
||||
PatchStaticsEnabled = ServerConfiguration.GetOrUpdateSetting("maps.enableStaticsDiffPatches", true);
|
||||
}
|
||||
var staDataPath = Core.FindDataFile($"stadif{index}.mul", false);
|
||||
var staIndexPath = Core.FindDataFile($"stadifl{index}.mul", false);
|
||||
var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false);
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
|
||||
{
|
||||
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var indexReader = new BinaryReader(fsIndex);
|
||||
|
||||
var count = (int)(indexReader.BaseStream.Length / 4);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
if (staDataPath != null && staIndexPath != null && staLookupPath != null)
|
||||
{
|
||||
var blockID = indexReader.ReadInt32();
|
||||
var x = Math.DivRem(blockID, matrix.BlockHeight, out var y);
|
||||
|
||||
fsData.Seek(4, SeekOrigin.Current);
|
||||
|
||||
var tiles = new LandTile[64];
|
||||
fixed (LandTile* pTiles = tiles)
|
||||
{
|
||||
fsData.Read(new Span<byte>(pTiles, 192));
|
||||
}
|
||||
|
||||
matrix.SetLandBlock(x, y, tiles);
|
||||
StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
|
||||
{
|
||||
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var indexReader = new BinaryReader(fsIndex);
|
||||
using var lookupReader = new BinaryReader(fsLookup);
|
||||
|
||||
var count = (int)(indexReader.BaseStream.Length / 4);
|
||||
|
||||
var lists = new TileList[8][];
|
||||
|
||||
for (var x = 0; x < 8; ++x)
|
||||
{
|
||||
lists[x] = new TileList[8];
|
||||
|
||||
for (var y = 0; y < 8; ++y)
|
||||
{
|
||||
lists[x][y] = new TileList();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var blockID = indexReader.ReadInt32();
|
||||
var blockX = blockID / matrix.BlockHeight;
|
||||
var blockY = blockID % matrix.BlockHeight;
|
||||
|
||||
var offset = lookupReader.ReadInt32();
|
||||
var length = lookupReader.ReadInt32();
|
||||
lookupReader.ReadInt32(); // Extra
|
||||
|
||||
if (offset < 0 || length <= 0)
|
||||
{
|
||||
matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
|
||||
continue;
|
||||
}
|
||||
|
||||
fsData.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
var tileCount = length / 7;
|
||||
|
||||
if (_tileBuffer.Length < tileCount)
|
||||
{
|
||||
_tileBuffer = new StaticTile[tileCount];
|
||||
}
|
||||
|
||||
var staTiles = _tileBuffer;
|
||||
|
||||
fixed (StaticTile* pTiles = staTiles)
|
||||
{
|
||||
fsData.Read(new Span<byte>(pTiles, length));
|
||||
|
||||
StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;
|
||||
|
||||
while (pCur < pEnd)
|
||||
{
|
||||
lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z);
|
||||
pCur += 1;
|
||||
}
|
||||
|
||||
var tiles = new StaticTile[8][][];
|
||||
|
||||
for (var x = 0; x < 8; ++x)
|
||||
{
|
||||
tiles[x] = new StaticTile[8][];
|
||||
|
||||
for (var y = 0; y < 8; ++y)
|
||||
{
|
||||
tiles[x][y] = lists[x][y].ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
matrix.SetStaticBlock(blockX, blockY, tiles);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
if (UOClient.ServerClientVersion != null)
|
||||
{
|
||||
PatchLandEnabled = ServerConfiguration.GetSetting(
|
||||
"maps.enableMapDiffPatches",
|
||||
UOClient.ServerClientVersion < ClientVersion.Version6000
|
||||
);
|
||||
|
||||
// TODO: Should this be enabled for 6.0 through <7.0.9?
|
||||
PatchStaticsEnabled = ServerConfiguration.GetSetting(
|
||||
"maps.enableStaticsDiffPatches",
|
||||
UOClient.ServerClientVersion < ClientVersion.Version7090
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
|
||||
{
|
||||
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var indexReader = new BinaryReader(fsIndex);
|
||||
|
||||
var count = (int)(indexReader.BaseStream.Length / 4);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var blockID = indexReader.ReadInt32();
|
||||
var x = Math.DivRem(blockID, matrix.BlockHeight, out var y);
|
||||
|
||||
fsData.Seek(4, SeekOrigin.Current);
|
||||
|
||||
var tiles = new LandTile[64];
|
||||
fixed (LandTile* pTiles = tiles)
|
||||
{
|
||||
fsData.Read(new Span<byte>(pTiles, 192));
|
||||
}
|
||||
|
||||
matrix.SetLandBlock(x, y, tiles);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
|
||||
{
|
||||
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var indexReader = new BinaryReader(fsIndex);
|
||||
using var lookupReader = new BinaryReader(fsLookup);
|
||||
|
||||
var count = (int)(indexReader.BaseStream.Length / 4);
|
||||
|
||||
var lists = new TileList[8][];
|
||||
|
||||
for (var x = 0; x < 8; ++x)
|
||||
{
|
||||
lists[x] = new TileList[8];
|
||||
|
||||
for (var y = 0; y < 8; ++y)
|
||||
{
|
||||
lists[x][y] = new TileList();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var blockID = indexReader.ReadInt32();
|
||||
var blockX = blockID / matrix.BlockHeight;
|
||||
var blockY = blockID % matrix.BlockHeight;
|
||||
|
||||
var offset = lookupReader.ReadInt32();
|
||||
var length = lookupReader.ReadInt32();
|
||||
lookupReader.ReadInt32(); // Extra
|
||||
|
||||
if (offset < 0 || length <= 0)
|
||||
{
|
||||
matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
|
||||
continue;
|
||||
}
|
||||
|
||||
fsData.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
var tileCount = length / 7;
|
||||
|
||||
if (_tileBuffer.Length < tileCount)
|
||||
{
|
||||
_tileBuffer = new StaticTile[tileCount];
|
||||
}
|
||||
|
||||
var staTiles = _tileBuffer;
|
||||
|
||||
fixed (StaticTile* pTiles = staTiles)
|
||||
{
|
||||
fsData.Read(new Span<byte>(pTiles, length));
|
||||
|
||||
StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;
|
||||
|
||||
while (pCur < pEnd)
|
||||
{
|
||||
lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z);
|
||||
pCur += 1;
|
||||
}
|
||||
|
||||
var tiles = new StaticTile[8][][];
|
||||
|
||||
for (var x = 0; x < 8; ++x)
|
||||
{
|
||||
tiles[x] = new StaticTile[8][];
|
||||
|
||||
for (var y = 0; y < 8; ++y)
|
||||
{
|
||||
tiles[x][y] = lists[x][y].ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
matrix.SetStaticBlock(blockX, blockY, tiles);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue