Core/Maps: Updated vmaps and some cleaups
This commit is contained in:
@@ -76,7 +76,7 @@ namespace Game.DataStorage
|
||||
if (fieldInfo.IsArray)
|
||||
{
|
||||
Array array = (Array)fieldInfo.Getter(obj);
|
||||
SetArrayValue(obj, array.Length, fieldInfo, dataReader);
|
||||
SetArrayValue(obj, (uint)array.Length, fieldInfo, dataReader);
|
||||
|
||||
arrayLength -= array.Length;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ namespace Game.DataStorage
|
||||
if (fieldInfo.IsArray)
|
||||
{
|
||||
Array array = (Array)fieldInfo.Getter(obj);
|
||||
SetArrayValue(obj, array.Length, fieldInfo, dataReader);
|
||||
SetArrayValue(obj, (uint)array.Length, fieldInfo, dataReader);
|
||||
|
||||
dataFieldIndex += array.Length - 1;
|
||||
}
|
||||
@@ -258,11 +258,7 @@ namespace Game.DataStorage
|
||||
|
||||
// IndexTable
|
||||
if (Header.HasIndexTable())
|
||||
{
|
||||
m_indexes = new int[Header.RecordCount];
|
||||
for (int i = 0; i < Header.RecordCount; i++)
|
||||
m_indexes[i] = reader.ReadInt32();
|
||||
}
|
||||
m_indexes = reader.ReadArray<int>(Header.RecordCount);
|
||||
|
||||
// Copytable
|
||||
if (Header.CopyTableSize > 0)
|
||||
@@ -508,7 +504,7 @@ namespace Game.DataStorage
|
||||
return bits.ToArray();
|
||||
}
|
||||
|
||||
static void SetArrayValue(object obj, int arraySize, DB6FieldInfo fieldInfo, BinaryReader reader)
|
||||
static void SetArrayValue(object obj, uint arraySize, DB6FieldInfo fieldInfo, BinaryReader reader)
|
||||
{
|
||||
switch (Type.GetTypeCode(fieldInfo.FieldType))
|
||||
{
|
||||
|
||||
@@ -56,14 +56,14 @@ namespace Game.DataStorage
|
||||
for (uint k = 0; k < cam.target_positions.timestamps.number; ++k)
|
||||
{
|
||||
// Extract Target positions
|
||||
M2Array targTsArray = new M2Array(reader, cam.target_positions.timestamps.offset_elements);
|
||||
reader.BaseStream.Position = cam.target_positions.timestamps.offset_elements;
|
||||
M2Array targTsArray = reader.Read<M2Array>();
|
||||
|
||||
reader.BaseStream.Position = targTsArray.offset_elements;
|
||||
uint[] targTimestamps = new uint[targTsArray.number];
|
||||
for (var i = 0; i < targTsArray.number; ++i)
|
||||
targTimestamps[i] = reader.ReadUInt32();
|
||||
uint[] targTimestamps = reader.ReadArray<uint>(targTsArray.number);
|
||||
|
||||
M2Array targArray = new M2Array(reader, cam.target_positions.values.offset_elements);
|
||||
reader.BaseStream.Position = cam.target_positions.values.offset_elements;
|
||||
M2Array targArray = reader.Read<M2Array>();
|
||||
|
||||
reader.BaseStream.Position = targArray.offset_elements;
|
||||
M2SplineKey[] targPositions = new M2SplineKey[targArray.number];
|
||||
@@ -90,14 +90,14 @@ namespace Game.DataStorage
|
||||
for (uint k = 0; k < cam.positions.timestamps.number; ++k)
|
||||
{
|
||||
// Extract Camera positions for this set
|
||||
M2Array posTsArray = reader.ReadStruct<M2Array>(cam.positions.timestamps.offset_elements);
|
||||
reader.BaseStream.Position = cam.positions.timestamps.offset_elements;
|
||||
M2Array posTsArray = reader.Read<M2Array>();
|
||||
|
||||
reader.BaseStream.Position = posTsArray.offset_elements;
|
||||
uint[] posTimestamps = new uint[posTsArray.number];
|
||||
for (var i = 0; i < posTsArray.number; ++i)
|
||||
posTimestamps[i] = reader.ReadUInt32();
|
||||
uint[] posTimestamps = reader.ReadArray<uint>(posTsArray.number);
|
||||
|
||||
M2Array posArray = new M2Array(reader, cam.positions.values.offset_elements);
|
||||
reader.BaseStream.Position = cam.positions.values.offset_elements;
|
||||
M2Array posArray = reader.Read<M2Array>();
|
||||
|
||||
reader.BaseStream.Position = posArray.offset_elements;
|
||||
M2SplineKey[] positions = new M2SplineKey[posTsArray.number];
|
||||
@@ -181,7 +181,7 @@ namespace Game.DataStorage
|
||||
using (BinaryReader m2file = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
||||
{
|
||||
// Check file has correct magic (MD21)
|
||||
if (m2file.ReadStringFromChars(4) != "MD21")
|
||||
if (m2file.ReadUInt32() != 0x3132444D) //"MD21"
|
||||
{
|
||||
Log.outError(LogFilter.ServerLoading, "Camera file {0} is damaged. File identifier not found.", filename);
|
||||
continue;
|
||||
@@ -190,10 +190,11 @@ namespace Game.DataStorage
|
||||
var unknownSize = m2file.ReadUInt32(); //unknown size
|
||||
|
||||
// Read header
|
||||
M2Header header = m2file.ReadStruct<M2Header>();
|
||||
M2Header header = m2file.Read<M2Header>();
|
||||
|
||||
// Get camera(s) - Main header, then dump them.
|
||||
M2Camera cam = m2file.ReadStruct<M2Camera>(8 + header.ofsCameras);
|
||||
m2file.BaseStream.Position = 8 + header.ofsCameras;
|
||||
M2Camera cam = m2file.Read<M2Camera>();
|
||||
|
||||
m2file.BaseStream.Position = 8;
|
||||
readCamera(cam, new BinaryReader(new MemoryStream(m2file.ReadBytes((int)m2file.BaseStream.Length - 8))), cameraEntry);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
using Framework.GameMath;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Game.DataStorage
|
||||
{
|
||||
@@ -37,8 +36,7 @@ namespace Game.DataStorage
|
||||
|
||||
public struct M2Header
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
||||
public char[] Magic; // "MD20"
|
||||
public uint Magic; // "MD20"
|
||||
public uint Version; // The version of the format.
|
||||
public uint lName; // Length of the model's name including the trailing \0
|
||||
public uint ofsName; // Offset to the name, it seems like models can get reloaded by this name.should be unique, i guess.
|
||||
@@ -110,15 +108,6 @@ namespace Game.DataStorage
|
||||
|
||||
public struct M2Array
|
||||
{
|
||||
public M2Array(BinaryReader reader, uint offset)
|
||||
{
|
||||
if (offset != 0)
|
||||
reader.BaseStream.Position = offset;
|
||||
|
||||
number = reader.ReadUInt32();
|
||||
offset_elements = reader.ReadUInt32();
|
||||
}
|
||||
|
||||
public uint number;
|
||||
public uint offset_elements;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user