Fixes data file loading (#145)
This commit is contained in:
parent
eb0f960be6
commit
5ea11cef11
10 changed files with 70 additions and 100 deletions
|
|
@ -147,9 +147,9 @@ namespace Server
|
|||
|
||||
if (m_Settings == null)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.WriteLine("failed");
|
||||
Console.ResetColor();
|
||||
Utility.PopColor();
|
||||
throw new Exception("Core: Server configuration failed to deserialize.");
|
||||
}
|
||||
|
||||
|
|
@ -174,9 +174,9 @@ namespace Server
|
|||
if (updated)
|
||||
{
|
||||
Save();
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.WriteLine($"Core: Configuration saved to {m_RelPath}.");
|
||||
Console.ResetColor();
|
||||
Utility.PopColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ namespace Server
|
|||
public static int ScriptItems => m_ItemCount;
|
||||
public static int ScriptMobiles => m_MobileCount;
|
||||
|
||||
public static string FindDataFile(string path)
|
||||
public static string FindDataFile(string path, bool throwNotFound = true, bool warnNotFound = false)
|
||||
{
|
||||
string fullPath = null;
|
||||
|
||||
|
|
@ -192,11 +192,19 @@ namespace Server
|
|||
fullPath = null;
|
||||
}
|
||||
|
||||
if (fullPath == null && (throwNotFound || warnNotFound))
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.WriteLine($"Data: {path} was not found");
|
||||
Console.WriteLine("Make sure modernuo.json is properly configured");
|
||||
Utility.PopColor();
|
||||
if (throwNotFound)
|
||||
throw new FileNotFoundException($"Data: {path} was not found");
|
||||
}
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public static string FindDataFile(string format, params object[] args) => FindDataFile(string.Format(format, args));
|
||||
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Console.WriteLine(e.IsTerminating ? "Error:" : "Warning:");
|
||||
|
|
@ -317,14 +325,13 @@ namespace Server
|
|||
|
||||
var ver = Assembly.GetName().Version ?? new Version();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
|
||||
Console.WriteLine("ModernUO - [https://github.com/kamronbatman/ModernUO] Version {0}.{1}.{2}.{3}", ver.Major,
|
||||
Console.WriteLine("ModernUO - [https://github.com/modernuo/modernuo] Version {0}.{1}.{2}.{3}", ver.Major,
|
||||
ver.Minor, ver.Build,
|
||||
ver.Revision);
|
||||
Console.WriteLine("Core: Running on {0}", RuntimeInformation.FrameworkDescription);
|
||||
Console.ResetColor();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Core: Running on {0}\n", RuntimeInformation.FrameworkDescription);
|
||||
Utility.PopColor();
|
||||
|
||||
var ttObj = new Timer.TimerThread();
|
||||
timerThread = new Thread(ttObj.TimerMain)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Server
|
|||
|
||||
static MultiData()
|
||||
{
|
||||
var multiUOPPath = Core.FindDataFile("MultiCollection.uop");
|
||||
var multiUOPPath = Core.FindDataFile("MultiCollection.uop", false);
|
||||
|
||||
if (File.Exists(multiUOPPath))
|
||||
{
|
||||
|
|
@ -49,47 +49,40 @@ namespace Server
|
|||
var idxPath = Core.FindDataFile("multi.idx");
|
||||
var mulPath = Core.FindDataFile("multi.mul");
|
||||
|
||||
if (File.Exists(idxPath) && File.Exists(mulPath))
|
||||
var idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
m_IndexReader = new BinaryReader(idx);
|
||||
|
||||
var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
m_StreamReader = new BinaryReader(stream);
|
||||
|
||||
var vdPath = Core.FindDataFile("verdata.mul", false);
|
||||
|
||||
if (!File.Exists(vdPath)) return;
|
||||
|
||||
using var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var bin = new BinaryReader(fs);
|
||||
|
||||
var count = bin.ReadInt32();
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
m_IndexReader = new BinaryReader(idx);
|
||||
var file = bin.ReadInt32();
|
||||
var index = bin.ReadInt32();
|
||||
var lookup = bin.ReadInt32();
|
||||
var length = bin.ReadInt32();
|
||||
bin.ReadInt32(); // extra
|
||||
|
||||
var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
m_StreamReader = new BinaryReader(stream);
|
||||
|
||||
var vdPath = Core.FindDataFile("verdata.mul");
|
||||
|
||||
if (!File.Exists(vdPath)) return;
|
||||
|
||||
using var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var bin = new BinaryReader(fs);
|
||||
|
||||
var count = bin.ReadInt32();
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
|
||||
{
|
||||
var file = bin.ReadInt32();
|
||||
var index = bin.ReadInt32();
|
||||
var lookup = bin.ReadInt32();
|
||||
var length = bin.ReadInt32();
|
||||
bin.ReadInt32(); // extra
|
||||
bin.BaseStream.Seek(lookup, SeekOrigin.Begin);
|
||||
|
||||
if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
|
||||
{
|
||||
bin.BaseStream.Seek(lookup, SeekOrigin.Begin);
|
||||
Components[index] = new MultiComponentList(bin, length / 12);
|
||||
|
||||
Components[index] = new MultiComponentList(bin, length / 12);
|
||||
|
||||
bin.BaseStream.Seek(24 + i * 20, SeekOrigin.Begin);
|
||||
}
|
||||
bin.BaseStream.Seek(24 + i * 20, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
bin.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Multi data files not found");
|
||||
}
|
||||
bin.Close();
|
||||
}
|
||||
|
||||
public static MultiComponentList GetComponents(int multiID)
|
||||
|
|
|
|||
|
|
@ -27,13 +27,8 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using Server.Accounting;
|
||||
using Server.Compression;
|
||||
using Server.ContextMenus;
|
||||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Menus;
|
||||
using Server.Menus.ItemLists;
|
||||
using Server.Menus.Questions;
|
||||
using Server.Prompts;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Network
|
||||
|
|
|
|||
|
|
@ -184,20 +184,6 @@ namespace Server
|
|||
{
|
||||
var filePath = Core.FindDataFile("tiledata.mul");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("tiledata.mul was not found");
|
||||
Console.WriteLine("Make sure your modernuo.json is properly configured");
|
||||
Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
|
||||
Console.ResetColor();
|
||||
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.WriteLine($"TileData: {filePath} not found");
|
||||
Utility.PopColor();
|
||||
return;
|
||||
}
|
||||
|
||||
using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var bin = new BinaryReader(fs);
|
||||
|
||||
|
|
|
|||
|
|
@ -92,32 +92,32 @@ namespace Server
|
|||
|
||||
if (fileIndex != 0x7F)
|
||||
{
|
||||
var mapPath = Core.FindDataFile("map{0}LegacyMUL.uop", fileIndex);
|
||||
var mapPath = Core.FindDataFile($"map{fileIndex}LegacyMUL.uop", false, true);
|
||||
|
||||
if (File.Exists(mapPath))
|
||||
if (mapPath != null)
|
||||
{
|
||||
m_MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
m_MapIndex = new UOPIndex(m_MapStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
mapPath = Core.FindDataFile("map{0}.mul", fileIndex);
|
||||
mapPath = Core.FindDataFile($"map{fileIndex}.mul", false, true);
|
||||
|
||||
if (File.Exists(mapPath))
|
||||
if (mapPath != null)
|
||||
m_MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
|
||||
var indexPath = Core.FindDataFile("staidx{0}.mul", fileIndex);
|
||||
var indexPath = Core.FindDataFile($"staidx{fileIndex}.mul", false, true);
|
||||
|
||||
if (File.Exists(indexPath))
|
||||
if (indexPath != null)
|
||||
{
|
||||
IndexStream = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
m_IndexReader = new BinaryReader(IndexStream);
|
||||
}
|
||||
|
||||
var staticsPath = Core.FindDataFile("statics{0}.mul", fileIndex);
|
||||
var staticsPath = Core.FindDataFile($"statics{fileIndex}.mul", false, true);
|
||||
|
||||
if (File.Exists(staticsPath))
|
||||
if (staticsPath != null)
|
||||
DataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ namespace Server
|
|||
|
||||
lock (shared)
|
||||
{
|
||||
if (x >= 0 && x < shared.BlockWidth && y >= 0 && y < shared.BlockHeight)
|
||||
if (x < shared.BlockWidth && y < shared.BlockHeight)
|
||||
{
|
||||
var theirTiles = shared.m_StaticTiles[x];
|
||||
|
||||
|
|
@ -205,12 +205,7 @@ namespace Server
|
|||
return m_StaticTiles[x][y] = tiles ?? ReadStaticBlock(x, y);
|
||||
}
|
||||
|
||||
public StaticTile[] GetStaticTiles(int x, int y)
|
||||
{
|
||||
var tiles = GetStaticBlock(x >> 3, y >> 3);
|
||||
|
||||
return tiles[x & 0x7][y & 0x7];
|
||||
}
|
||||
public StaticTile[] GetStaticTiles(int x, int y) => GetStaticBlock(x >> 3, y >> 3)[x & 0x7][y & 0x7];
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public StaticTile[] GetStaticTiles(int x, int y, bool multis)
|
||||
|
|
@ -277,7 +272,7 @@ namespace Server
|
|||
|
||||
lock (shared)
|
||||
{
|
||||
if (x >= 0 && x < shared.BlockWidth && y >= 0 && y < shared.BlockHeight)
|
||||
if (x < shared.BlockWidth && y < shared.BlockHeight)
|
||||
{
|
||||
var theirTiles = shared.m_LandTiles[x];
|
||||
|
||||
|
|
@ -346,7 +341,7 @@ namespace Server
|
|||
while (pCur < pEnd)
|
||||
{
|
||||
lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z);
|
||||
pCur = pCur + 1;
|
||||
pCur += 1;
|
||||
}
|
||||
|
||||
var tiles = new StaticTile[8][][];
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@ namespace Server
|
|||
if (!Enabled)
|
||||
return;
|
||||
|
||||
var mapDataPath = Core.FindDataFile("mapdif{0}.mul", index);
|
||||
var mapIndexPath = Core.FindDataFile("mapdifl{0}.mul", index);
|
||||
var mapDataPath = Core.FindDataFile($"mapdif{index}.mul", false);
|
||||
var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);
|
||||
|
||||
if (File.Exists(mapDataPath) && File.Exists(mapIndexPath))
|
||||
m_LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
|
||||
|
||||
var staDataPath = Core.FindDataFile("stadif{0}.mul", index);
|
||||
var staIndexPath = Core.FindDataFile("stadifl{0}.mul", index);
|
||||
var staLookupPath = Core.FindDataFile("stadifi{0}.mul", index);
|
||||
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))
|
||||
m_StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
|
||||
|
|
|
|||
|
|
@ -1548,7 +1548,7 @@ namespace Server.Commands
|
|||
{
|
||||
List<BodyEntry> list = new List<BodyEntry>();
|
||||
|
||||
string path = Core.FindDataFile("models/models.txt");
|
||||
string path = Path.Combine(Core.BaseDirectory, "Data/models.txt");
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
|
|
@ -1681,9 +1681,6 @@ namespace Server.Commands
|
|||
{
|
||||
Dictionary<int, SpeechEntry> table = tables[p];
|
||||
|
||||
if (p > 0)
|
||||
html.WriteLine(" <br>");
|
||||
|
||||
html.WriteLine(" <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
|
||||
html.WriteLine(" <tr><td class=\"tbl-border\">");
|
||||
html.WriteLine(" <table width=\"100%\" cellpadding=\"4\" cellspacing=\"1\">");
|
||||
|
|
@ -1767,7 +1764,7 @@ namespace Server.Commands
|
|||
|
||||
Dictionary<int, SpeechEntry> table = null;
|
||||
|
||||
string path = Core.FindDataFile("speech.mul");
|
||||
string path = Core.FindDataFile("speech.mul", false);
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Server.Engines.MLQuests.Objectives
|
|||
AcceptedType = type;
|
||||
Name = name;
|
||||
|
||||
if (MLQuestSystem.Debug && ShowDetailed && name.Number > 0)
|
||||
if (MLQuestSystem.Debug && ShowDetailed && name?.Number > 0)
|
||||
{
|
||||
int itemid = LabelToItemID(name.Number);
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,9 @@ namespace Server.Misc
|
|||
|
||||
EventSink.ClientVersionReceived += EventSink_ClientVersionReceived;
|
||||
|
||||
// ClientVersion.Required = null;
|
||||
// Required = new ClientVersion( "6.0.0.0" );
|
||||
|
||||
if (m_DetectClientRequirement)
|
||||
{
|
||||
string path = Core.FindDataFile("client.exe");
|
||||
string path = Core.FindDataFile("client.exe", false);
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
|
|
@ -71,10 +68,10 @@ namespace Server.Misc
|
|||
return;
|
||||
|
||||
if (Required != null && version < Required && (m_OldClientResponse == OldClientResponse.Kick ||
|
||||
(m_OldClientResponse == OldClientResponse.LenientKick &&
|
||||
m_OldClientResponse == OldClientResponse.LenientKick &&
|
||||
DateTime.UtcNow - state.Mobile.CreationTime > m_AgeLeniency &&
|
||||
state.Mobile is PlayerMobile mobile &&
|
||||
mobile.GameTime > m_GameTimeLeniency)))
|
||||
mobile.GameTime > m_GameTimeLeniency))
|
||||
{
|
||||
kickMessage = $"This server requires your client version be at least {Required}.";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue