CodeWalker/CodeWalker.Test/MetaTypesTests.cs

716 lines
59 KiB
C#
Raw Normal View History

using CodeWalker.GameFiles;
using System;
using System.Buffers.Binary;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;
namespace CodeWalker.Test
{
public static class TestData
{
public const string ReferenceDataBytes = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAADWA9YDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAATABMAAAAAAAAAAAAAAAAACgAAAAAAAADZAdkBAAAAAAYAAAAAAAAAogGiAQAAAAABAAAAAAAAADsAOwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP3///8mAAAANgAAAEkAAAAAAAAAAAAAAAAAAAAAAAAAAACAQgAAgEIAAAAAAAAAAAAAAAAIQDQAAAAAAEgDSAMAAAAABwAAAAAAAAAGAAYAAAAAAAgAAAAAAAAANwA3AAAAAAAIwA0AAAAAAB4AHgAAAAAACEAVAAAAAAAOAA4AAAAAAAjAGAAAAAAACQAJAAAAAAAIABsAAAAAAAIAAgAAAAAACIAbAAAAAAABAAEAAAAAAA==";
public static CScenarioPointRegion ReferenceData => new CScenarioPointRegion
{
AccelGrid = new rage__spdGrid2D
{
CellDimX = 64,
CellDimY = 64,
MaxCellX = 38,
MaxCellY = 73,
MinCellX = -3,
MinCellY = 54,
},
ChainingGraph = new CodeWalker.GameFiles.CScenarioChainingGraph
{
Chains = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 59,
Count2 = 59,
Pointer = 1,
},
Edges = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 418,
Count2 = 418,
Pointer = 6,
},
Nodes = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 473,
Count2 = 473,
Pointer = 10,
}
},
Clusters = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 6,
Count2 = 6,
Pointer = 7,
},
EntityOverrides = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 19,
Count2 = 19,
Pointer = 2,
},
LookUps = new CodeWalker.GameFiles.CScenarioPointLookUps
{
GroupNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 9,
Count2 = 9,
Pointer = 1622024,
},
InteriorNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 2,
Count2 = 2,
Pointer = 1769480,
},
PedModelSetNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 30,
Count2 = 30,
Pointer = 901128,
},
RequiredIMapNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 1,
Count2 = 1,
Pointer = 1802248,
},
TypeNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 55,
Count2 = 55,
Pointer = 8,
},
VehicleModelSetNames = new CodeWalker.GameFiles.Array_uint
{
Count1 = 14,
Count2 = 14,
Pointer = 1392648,
},
},
Points = new CodeWalker.GameFiles.CScenarioPointContainer
{
LoadSavePoints = new CodeWalker.GameFiles.Array_Structure
{
PointerDataIndex = 4294967295,
},
MyPoints = new CodeWalker.GameFiles.Array_Structure
{
Count1 = 982,
Count2 = 982,
Pointer = 3,
}
},
Unk_3844724227 = new CodeWalker.GameFiles.Array_ushort
{
Count1 = 840,
Count2 = 840,
Pointer = 3424264,
}
};
}
public class PsoTypesTests
{
private readonly ITestOutputHelper _output;
public PsoTypesTests(ITestOutputHelper testOutputHelper)
{
_output = testOutputHelper;
}
private const string ExpectedResult = "AAAAA3pyMzUwX2Rhc2gxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6cjM1MF9kYXNoMStoaWZyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3pyMzUwX2Rhc2gyAA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AAAAAAAAAAAAAAAAAAAAAAA3pyMzUwX2hvb2RhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6cjM1MF9ob29kYStoaWZyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3pyMzUwX2ludGVyY29vbGVyMWEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6cjM1MF9pbnRlcmNvb2xlcjFhK2hpZnIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3pyMzUwX2ludGVyY29vbGVyMWIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6cjM1MF9pbnRlcmNvb2xlcjFiK2hpZnIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3pyMzUwX2ludGVyY29vbGVyMWMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB6cjM1MF9pbnRlcmNvb2xlcjFjK2hpZnIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[Fact]
public void TestConvertData()
{
var data = Convert.FromBase64String(InputData);
var result = PsoTypes.ConvertDataArrayRaw<CHDTxdAssetBinding>(data, 0, 43);
Assert.Equal(43, result.Length);
var firstResult = result[0];
Assert.Equal(768, firstResult.Unused02);
Assert.Equal("zr350_dash1+hifr", firstResult.HDTxd.ToString());
Assert.Equal("zr350_dash1", firstResult.targetAsset.ToString());
var outputData = Convert.ToBase64String(MemoryMarshal.AsBytes(result.AsSpan()));
Assert.Equal(ExpectedResult, outputData);
Assert.Equal(InputData, outputData);
}
private const string InputDataWithOffset = "UFNJTgAAAXhwcHBwcHBwcAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAACAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANnYl9idW1mAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ2JfYnVtZitoaWZyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANnYl9idW1yAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ2JfYnVtcitoaWZyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
[Fact]
public void TestConvertDataWithOffset()
{
var data = Convert.FromBase64String(InputDataWithOffset);
var result = PsoTypes.ConvertDataArrayRaw<CHDTxdAssetBinding>(data, 112, 2);
Assert.Equal(2, result.Length);
var firstResult = result[0];
Assert.Equal(768, firstResult.Unused02);
Assert.Equal("gb_bumf+hifr", firstResult.HDTxd.ToString());
Assert.Equal("gb_bumf", firstResult.targetAsset.ToString());
var secondResult = result[1];
Assert.Equal(768, secondResult.Unused02);
Assert.Equal("gb_bumr+hifr", secondResult.HDTxd.ToString());
Assert.Equal("gb_bumr", secondResult.targetAsset.ToString());
data = Convert.FromBase64String("UFNJTgAAJBBwcHBwcHBwcFYVuAxACWAVAAAAAPJlYolcYBoCAAAAAAmC8HDuekF4AAAAADUL+WFACWAVAAAAAFjK8ellJCzqAAAAAIOyHh1OoX6FAAAAAJ9UxM3KoXfjAAAAAFjUJ/bnD60/AAAAAMpEH+i7aVgrAAAAAE/rnt/r3zvtAAAAAHBwcHBwcHBw/DbCSgAAAAAAAAADAAAAAAABAAEAAA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yHAAAAAAA4IADAAAAAAABAAEAAAAA1pIbAwAAAAAA4MADAAAAAAANAA0AAAAAB59vQwAAAAAA5AADAAAAAAAFAAUAAAAAyBaLigAAAAAA5UADAAAAAAAEAAQAAAAA7GTUJgAAAAAA5kADAAAAAAACAAIAAAAAm/qzUwAAAAAA5sADAAAAAAADAAMAAAAAkeefLQAAAAAA54ADAAAAAAADAAMAAAAAREIDtwAAAAAA6EADAAAAAAAFAAUAAAAAYZ4+bwAAAAAA6YADAAAAAAACAAIAAAAAZUCDcQAAAAAA6gADAAAAAAACAAIAAAAAzHKKuQAAAAAA6oADAAAAAAASABIAAAAAviXuHAAAAAAA7wADAAAAAAARABEAAAAArJvLaAAAAAAA80ADAAAAAAAUABQAAAAA3tSv3QAAAAAA+EADAAAAAAAaABoAAAAA0SaUgQAAAAAA/sADAAAAAAAJAAkAAAAAA2j5BQAAAAABAQADAAAAAAARABEAAAAAI9HlRAAAAAABBUADAA
var result2 = PsoTypes.ConvertDataArrayRaw<CImapDependencies>(data, 144, 160);
Assert.Equal(160, result2.Length);
var firstResult2 = result2[0];
Assert.Equal(0, firstResult2.Unused0);
Assert.Equal(1254242044u, firstResult2.imapName.Hash);
Assert.Equal(256, firstResult2.itypDepArray.Count1);
Assert.Equal(256, firstResult2.itypDepArray.Count2);
Assert.Equal(50331648ul, firstResult2.itypDepArray.Pointer);
var lastResult = result2[159];
Assert.Equal(0, lastResult.Unused0);
Assert.Equal(2255575624, lastResult.imapName.Hash);
Assert.Equal(256, lastResult.itypDepArray.Count1);
Assert.Equal(256, lastResult.itypDepArray.Count2);
Assert.Equal(54542593ul, lastResult.itypDepArray.Pointer);
}
[Fact]
public void TestStringConversion()
{
var arr = new byte[64];
for (int i = 0; i <= 'j' - 'a'; i++)
{
arr[i] = (byte)('a' + i);
}
MemoryMarshal.TryRead<PsoChar64>(arr, out var str1);
MemoryMarshal.TryRead<PsoChar32>(arr, out var str2);
Assert.Equal("abcdefghij", str1.ToString());
Assert.Equal("abcdefghij", str2.ToString());
for (int i = 0; i <= 'Z' - 'A'; i++)
{
arr[i] = (byte)('A' + i);
}
MemoryMarshal.TryRead<PsoChar64>(arr, out str1);
MemoryMarshal.TryRead<PsoChar32>(arr, out str2);
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWXYZ", str1.ToString());
Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWXYZ", str2.ToString());
}
[Fact]
public void StringConversionShouldRespectNullTerminators()
{
var arr = new byte[64];
for (int i = 0; i <= 'Z' - 'A'; i++)
{
arr[i] = (byte)('A' + i);
}
arr[15] = (byte)'\0';
MemoryMarshal.TryRead<PsoChar64>(arr, out var str1);
Assert.Equal("ABCDEFGHIJKLMNO", str1.ToString());
MemoryMarshal.TryRead<PsoChar32>(arr, out var str2);
Assert.Equal("ABCDEFGHIJKLMNO", str2.ToString());
}
[Fact]
public void TestGetItem()
{
var data = Convert.FromBase64String("UFNJTgAAAoBwcHBwcHBwcAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN6aGFiX2Noc3NfMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAemhhYl9jaHNzXzMraGlmcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN6aGFiX2ZlbmRfMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAemhhYl9mZW5kXzIraGlmcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN6aGFiX21pcnJfMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAemhhYl9taXJyXzEraGlmcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN6aGFiX21pcnJfMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAemhhYl9taXJyXzIraGlmcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==");
var result = PsoTypes.ConvertData<CPackFileMetaData>(data, 16);
Assert.Equal(4, result._HDTxdBindingArray.Count1);
Assert.Equal(4, result._HDTxdBindingArray.Count2);
Assert.Equal(2ul, result._HDTxdBindingArray.Pointer);
Assert.Equal(0, result._Interiors.Count1);
Assert.Equal(0, result._Interiors.Count2);
Assert.Equal(0ul, result._Interiors.Pointer);
Assert.Equal(0, result._MapDataGroups.Count1);
Assert.Equal(0, result._MapDataGroups.Count2);
Assert.Equal(0ul, result._MapDataGroups.Pointer);
Assert.Equal(0, result._imapDependencies.Count1);
Assert.Equal(0, result._imapDependencies.Count2);
Assert.Equal(0ul, result._imapDependencies.Pointer);
Assert.Equal(0, result._imapDependencies_2.Count1);
Assert.Equal(0, result._imapDependencies_2.Count2);
Assert.Equal(0ul, result._imapDependencies_2.Pointer);
Assert.Equal(0, result._itypDependencies_2.Count1);
Assert.Equal(0, result._itypDependencies_2.Count2);
Assert.Equal(0ul, result._itypDependencies_2.Pointer);
}
}
public class MetaTypesTests
{
private readonly ITestOutputHelper _output;
public MetaTypesTests(ITestOutputHelper testOutputHelper)
{
_output = testOutputHelper;
}
[Fact]
public void TestConvertData()
{
var data = BitConverter.GetBytes((uint)1234);
var number = MetaTypes.ConvertData<uint>(data);
Assert.Equal(1234U, number);
}
[Fact]
public void Test_Convert_Data_From_Bytes()
{
var bytes = Convert.FromBase64String(TestData.ReferenceDataBytes);
var newData = MetaTypes.ConvertData<CScenarioPointRegion>(bytes);
Assert.Equivalent(TestData.ReferenceData, newData);
}
[Fact]
public void Test_Convert_Data_From_Bytes_Offset()
{
var bytes = Convert.FromBase64String(TestData.ReferenceDataBytes);
bytes = new byte[4].Concat(bytes).ToArray();
var newData = MetaTypes.ConvertData<CScenarioPointRegion>(bytes, 4);
Assert.Equivalent(TestData.ReferenceData, newData);
MetaTypes.TryConvertData<CScenarioPointRegion>(bytes, 4, out newData);
Assert.Equivalent(TestData.ReferenceData, newData);
}
[Fact]
public void Test_Convert_To_Bytes()
{
var bytes = MetaTypes.ConvertToBytes(TestData.ReferenceData);
var bytesBase64 = Convert.ToBase64String(bytes);
Assert.Equivalent(TestData.ReferenceDataBytes, bytesBase64);
}
[Fact]
public void Test_Convert_Data_From_And_To_Bytes()
{
var bytes = MetaTypes.ConvertToBytes(TestData.ReferenceData);
var newData = MetaTypes.ConvertData<CScenarioPointRegion>(bytes);
Assert.Equivalent(TestData.ReferenceData, newData);
}
private readonly SharpDX.Vector3[] referenceArray = new SharpDX.Vector3[] { new SharpDX.Vector3(12.5f, 23.0f, 65.0f), new SharpDX.Vector3(1234.234f, 17896.22f, 9845.12f), new SharpDX.Vector3(-12.3f, -82349.123f, 1234.9f), new SharpDX.Vector3(-23412.4f, 1289.2f, 948.0f) };
private readonly string referenceArrayBytes = "AABIQQAAuEEAAIJCfUeaRHHQi0Z71BlGzcxEwZDWoMfNXJpEzei2xmYmoUQAAG1E";
[Fact]
public void Test_Convert_Array_To_Bytes()
{
var bytes = MetaTypes.ConvertArrayToBytes(referenceArray);
var base64 = Convert.ToBase64String(bytes);
Assert.Equal(referenceArrayBytes, base64);
}
[Fact]
public void Test_Convert_Bytes_To_Array()
{
var bytes = Convert.FromBase64String(referenceArrayBytes);
var arr = MetaTypes.ConvertDataArray<SharpDX.Vector3>(bytes, 0, referenceArray.Length).ToArray();
Assert.Equal(referenceArray, arr);
var newBytes = MetaTypes.ConvertArrayToBytes(arr);
var base64 = Convert.ToBase64String(newBytes);
Assert.Equal(referenceArrayBytes, base64);
}
[Fact]
public void TestSwapBytes()
{
ushort testValue = (ushort)12345u;
ushort result = MetaTypes.SwapBytes(testValue);
Assert.Equal(14640, result);
Assert.Equal(testValue, MetaTypes.SwapBytes(result));
uint testValueUInt = 12345u;
uint resultUInt = MetaTypes.SwapBytes(testValueUInt);
Assert.Equal(959447040u, resultUInt);
Assert.Equal(testValueUInt, MetaTypes.SwapBytes(resultUInt));
int testValueInt = 12345;
int resultInt = MetaTypes.SwapBytes(testValueInt);
Assert.Equal(959447040, resultInt);
Assert.Equal(testValueInt, MetaTypes.SwapBytes(resultInt));
short testValueShort = (short)12345;
short resultShort = MetaTypes.SwapBytes(testValueShort);
Assert.Equal(14640, resultShort);
Assert.Equal(testValueShort, MetaTypes.SwapBytes(resultShort));
ulong testValueUlong = 0x123456789ABCDEFFUL;
ulong resultUlong = MetaTypes.SwapBytes(testValueUlong);
Assert.Equal(0x78563412FFDEBC9AUL, resultUlong);
Assert.Equal(testValueUlong, MetaTypes.SwapBytes(resultUlong));
float testValueFloat = 12345.12345f;
float resultFloat = MetaTypes.SwapBytes(testValueFloat);
Assert.Equal(1.5169885490328965E+38, resultFloat);
Assert.Equal(testValueFloat, MetaTypes.SwapBytes(resultFloat));
}
}
public class TestResourceData
{
[Fact]
public void Test_Write_Struct()
{
using var systemStream = new MemoryStream();
using var graphicsStream = new MemoryStream();
using var dataWriter = new ResourceDataWriter(systemStream, graphicsStream);
dataWriter.Position = 0x50000000;
dataWriter.WriteStruct(TestData.ReferenceData);
var buffer = systemStream.ToArray();
var base64 = Convert.ToBase64String(buffer);
Assert.Equal(TestData.ReferenceDataBytes, base64);
}
[Fact]
public void Test_Read_Struct()
{
var buffer = Convert.FromBase64String(TestData.ReferenceDataBytes);
using var systemStream = new MemoryStream(buffer);
using var graphicsStream = new MemoryStream();
using var dataReader = new ResourceDataReader(systemStream, graphicsStream);
var region = dataReader.ReadStruct<CScenarioPointRegion>();
Assert.Equal(TestData.ReferenceData, region);
}
[Fact]
public void Test_Write_Single()
{
using var systemStream = new MemoryStream();
using var graphicsStream = new MemoryStream();
using var dataWriter = new ResourceDataWriter(systemStream, graphicsStream);
dataWriter.Position = 0x50000000;
dataWriter.Write(20.0f);
var buffer = systemStream.ToArray();
var result = BitConverter.ToSingle(buffer, 0);
Assert.Equal(20.0f, result);
}
[Fact]
public void Test_Write_Single_Big_Endian()
{
using var systemStream = new MemoryStream();
using var graphicsStream = new MemoryStream();
using var dataWriter = new ResourceDataWriter(systemStream, graphicsStream, Endianess.BigEndian);
dataWriter.Position = 0x50000000;
dataWriter.Write(20.0f);
var buffer = systemStream.ToArray();
var valueInt = BinaryPrimitives.ReadInt32BigEndian(buffer);
var valueFloat = Unsafe.ReadUnaligned<float>(ref Unsafe.As<int, byte>(ref valueInt));
//BinaryPrimitives.ReverseEndianness(20.0f)
Assert.Equal(20.0f, valueFloat);
dataWriter.Position = 0x50000000;
dataWriter.Write(double.MaxValue);
buffer = systemStream.ToArray();
var valueLong = BinaryPrimitives.ReadInt64BigEndian(buffer);
var valueDouble = Unsafe.ReadUnaligned<double>(ref Unsafe.As<long, byte>(ref valueLong));
Assert.Equal(double.MaxValue, valueDouble);
}
[Fact]
public void Test_Write_Multiple_Structs()
{
using var systemStream = new MemoryStream();
using var graphicsStream = new MemoryStream();
using var dataWriter = new ResourceDataWriter(systemStream, graphicsStream);
dataWriter.Position = 0x50000000;
dataWriter.WriteStructs(new[]
{
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData
});
var buffer = systemStream.ToArray();
var structs = MemoryMarshal.Cast<byte, CScenarioPointRegion>(buffer);
Assert.Equal(4, structs.Length);
foreach (var scenarioRegion in structs)
{
Assert.Equal(TestData.ReferenceData, scenarioRegion);
}
}
[Fact]
public void Test_Read_Multiple_Structs()
{
using var systemStream = new MemoryStream();
using var graphicsStream = new MemoryStream();
using var dataWriter = new ResourceDataWriter(systemStream, graphicsStream);
dataWriter.Position = 0x50000000;
dataWriter.WriteStructs(new[]
{
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData
});
var buffer = systemStream.ToArray();
systemStream.Position = 0;
var dataReader = new ResourceDataReader(systemStream, graphicsStream);
var structs = dataReader.ReadStructs<CScenarioPointRegion>(4);
Assert.Equal(4, structs.Length);
foreach (var scenarioRegion in structs)
{
Assert.Equal(TestData.ReferenceData, scenarioRegion);
}
structs = dataReader.ReadStructsAt<CScenarioPointRegion>(0 | 0x50000000, 4);
foreach (var scenarioRegion in structs)
{
Assert.Equal(TestData.ReferenceData, scenarioRegion);
}
systemStream.Position = 0;
dataWriter.Position = 0x50000000;
dataWriter.Write(new byte[] { 0, 0, 0, 0 });
dataWriter.WriteStructs(new[]
{
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData,
TestData.ReferenceData
});
structs = dataReader.ReadStructsAt<CScenarioPointRegion>(4 | 0x50000000, 4);
foreach (var scenarioRegion in structs)
{
Assert.Equal(TestData.ReferenceData, scenarioRegion);
}
}
//[Fact]
//public void Test()
//{
// var attachedObjects = MetaTypes.GetUintArray(meta, _Data.attachedObjects);
//}
private const string ArchetypeData = "AAAAAAAAAAAAAMhCACAAAAAAAAAAAAAAAAAAAAAAAACYimfA1ehVuLYT5b4BAIB/JopnQFmFTTiUE+U+AQCAfwAAZLfAN4a1AAAItQEAgH/sTWlAAACgQFVVCx0lzgxeAAAAAAAAAAAAAAAAAgAAAFVVCx0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCACAAAAAAAAAAAAAAAAAAAAAAAAAY0EjAAAAAAC6txr4BAIB/MdBIQL03hjUMrcY+AQCAfwAAQDa9NwY1AAAItQEAgH/FV0pAAACgQNUOy/klzgxeAAAAAAAAAAAAAAAAAgAAANUOy/kAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCACAAAAAAAAAAAAAAAAAAAAAA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eAAAAAAAAAAAAAAAAAgAAAIFf4BwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCACAAAAAAAAAAAAAAAAAAAAAAAADG+0XAsDpHwL03hrUBAIB/ZftFQKw6R0C9NwY2AQCAfwAAQLcAAAC1vjcGNQEAgH+zb4xAAACgQCUyMgYlzgxeAAAAAAAAAAAAAAAAAgAAACUyMgYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCACAAAAAAAAAAAAAAAAAAAAAAAAD/JX2/AHAjwL03hrUBAIB/ryR9P+9vI0AAAAAAAQCAfwAAKLcAAAC2vTcGtQEAgH81Qy9AAACgQJqWbPglzgxeAAAAAAAAAAAAAAAAAgAAAJqWbPgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCA
private readonly CBaseArchetypeDef referenceArchetype = new CBaseArchetypeDef
{
assetName = new MetaHash((uint)0x1d0b5555),
assetType = rage__fwArchetypeDef__eAssetType.ASSET_TYPE_DRAWABLE,
bbMax = new SharpDX.Vector3(3.617807f, 4.9E-05f, 0.447415f),
bbMin = new SharpDX.Vector3(-3.617834f, -5.1E-05f, -0.447416f),
bsCentre = new SharpDX.Vector3(-1.3589859E-05f, -1.00000034E-06f, -5.066395E-07f),
bsRadius = 3.645381f,
hdTextureDist = 5,
lodDist = 100,
Unused05 = float.NaN,
Unused06 = float.NaN,
Unused07 = float.NaN,
name = new MetaHash((uint)0x1d0b5555),
textureDictionary = new MetaHash((uint)0x5e0cce25),
flags = 0x00002000,
};
[Fact]
public void TestConvertDataRaw()
{
var data = Convert.FromBase64String(ArchetypeData);
var basearch = PsoTypes.ConvertDataRawOld<CBaseArchetypeDef>(data, 0);
Assert.Equivalent(referenceArchetype, basearch);
var basearch2 = PsoTypes.ConvertDataRaw<CBaseArchetypeDef>(data, 0);
Assert.Equivalent(basearch, basearch2);
var random = new Random();
var length = random.Next(100);
var newData = Enumerable.Empty<byte>().Concat(new byte[length]).Concat(data).ToArray();
basearch = PsoTypes.ConvertDataRawOld<CBaseArchetypeDef>(newData, length);
Assert.Equivalent(basearch, referenceArchetype);
basearch2 = PsoTypes.ConvertDataRaw<CBaseArchetypeDef>(newData, length);
Assert.Equivalent(basearch, basearch2);
//a.Extensions = MetaTypes.GetExtensions(Meta, basearch.extensions);
}
}
public class TestConvertDataArray
{
private readonly ITestOutputHelper _output;
public TestConvertDataArray(ITestOutputHelper output)
{
_output = output;
}
private static string GetFilePath(string filename)
{
// Directory we're looking for.
var dirToFind = Path.Combine(@"CodeWalker.Test", "Files");
// Search up directory tree starting at assembly path looking for 'Images' dir.
var searchPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
while (true)
{
var testPath = Path.Combine(searchPath, dirToFind);
if (Directory.Exists(testPath))
{
// Found it!
return Path.Combine(testPath, filename);
}
// Move up one directory.
var newSearchPath = Path.GetFullPath(Path.Combine(searchPath, ".."));
if (newSearchPath == searchPath)
{
// Didn't move up, so we're at the root.
throw new FileNotFoundException($"Could not find '{dirToFind}' directory.");
}
searchPath = newSearchPath;
}
}
public string TestData = "AAAAAAAAAAAFAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAKDAAACgwAAAAMAAAAAAAACgQAAAoEAAAABAAAAAAAAAgD9kViJCAAAAAGAAAAABAAAAAAAAAP////8AAAAABgAAAAAAAAABAAEAAAAAAAAAAAAAAAAABWAAAAAAAAAKAAoAAAAAAAAAAAAAAAAAgPEnwiB/QcIAcFzBAAAAAADgDsL9ke/BHKgswQAAAAAAAIA/yyTUkwAAAABgAAAAAQAAAAEAAAD/////AAAAAAYAAQAAAAAALgAuAAAAAAA=";
[Fact]
public void ConvertDataArrayShouldReturnSameAsConvertData()
{
var data = Convert.FromBase64String(TestData);
var referenceData = MetaTypes.ConvertData<CMloRoomDef>(data);
var arrayData = MetaTypes.ConvertDataArray<CMloRoomDef>(data, 0, 2);
var path = GetFilePath("anwblokaal.ytyp");
var bytes = File.ReadAllBytes(path);
var entry = RpfFile.CreateFileEntry("anwblokaal.ytyp", path, ref bytes);
var ytypFile = RpfFile.GetFile<YtypFile>(entry, bytes);
var rooms = ytypFile.AllArchetypes
.Where(p => p is MloArchetype)
.Select(p => p as MloArchetype)
.SelectMany(p => p.rooms)
.Select(p => p.Data);
var secondRoom = rooms.Last();
var arr = new byte[Marshal.SizeOf<CMloRoomDef>() * rooms.Count()];
//MemoryMarshal.Write(arr.AsSpan(), ref rooms);
_output.WriteLine(Convert.ToBase64String(MemoryMarshal.AsBytes(rooms.ToArray().AsSpan())));
// I know the bbMax values don't really make sense here, seems to be a weird ytyp, but it's mostly about testing the serialization, not about using a 100% correct ytyp
// And didn't want to include a ytyp from Rockstar Games since that could cause some legal issues down the road
// Another possible solution would be to do abest attempt to find the GTA V installed on the user's computer running the tests and use files from there, but this would add complexity and links which could break tests
// However this would be more in the scope of implementation testing as it tests the whole chain including encryption which is not wanted here
Assert.Equivalent(new SharpDX.Vector3(-41.98584f, -48.3741455f, -13.7773438f), secondRoom.bbMin);
Assert.Equivalent(new SharpDX.Vector3(-35.71875f, -29.9462833f, -10.7910423f), secondRoom.bbMax);
Assert.Equivalent(new Array_uint(65542, 46), secondRoom.attachedObjects);
Assert.Equal(96u, secondRoom.flags);
Assert.Equal(1, secondRoom.floorId);
Assert.Equivalent(new CharPointer() { Count1 = 10, Count2 = 10, Pointer = 24581 }, secondRoom.name);
Assert.Equal(1u, secondRoom.portalCount);
Assert.Equal(2480153803, secondRoom.timecycleName.Hash);
// First room is limbo, so this check isn't that useful, but just make sure, and the following check will compare the entire array anyways
Assert.Equivalent(referenceData, rooms.First());
Assert.Equivalent(arrayData.ToArray(), rooms);
}
}
}