Files
LibBSP/LibBSP/Source/Structs/BSP/Lumps/StaticProps.cs
Will 27736ef13f Add partial support for Titanfall.
So far I'm not sure this format can be decompiled like the others. Need to do more research and reverse engineering.
2018-12-01 16:20:44 -07:00

59 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// List of <see cref="StaticProp"/> objects containing data relevant to Static Props, like the dictionary of actual model paths.
/// </summary>
public class StaticProps : List<StaticProp> {
public string[] dictionary { get; private set; }
/// <summary>
/// Parses the passed <c>byte</c> array into a <c>List</c> of <see cref="StaticProp"/> objects.
/// </summary>
/// <param name="data">Array of <c>byte</c>s to parse.</param>
/// <param name="type">Format identifier.</param>
/// <param name="version">Version of static prop lump this is.</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
public StaticProps(byte[] data, MapType type, int version = 0) {
if (data == null) {
throw new ArgumentNullException();
}
int structLength = 0;
dictionary = new string[0];
if (data.Length > 0) {
int offset = 0;
dictionary = new string[BitConverter.ToInt32(data, 0)];
offset += 4;
for (int i = 0; i < dictionary.Length; ++i) {
dictionary[i] = data.ToNullTerminatedString(offset, 128);
offset += 128;
}
int numLeafDefinitions = BitConverter.ToInt32(data, offset);
offset += 4 + (numLeafDefinitions * 2);
if (type == MapType.Vindictus && version == 6) {
int numPropScales = BitConverter.ToInt32(data, offset);
offset += 4 + (numPropScales * 16);
}
int numProps = BitConverter.ToInt32(data, offset);
if (version == 12) { // So far only Titanfall
offset += 12;
} else {
offset += 4;
}
if (numProps > 0) {
structLength = (data.Length - offset) / numProps;
for (int i = 0; i < numProps; ++i) {
byte[] bytes = new byte[structLength];
Array.Copy(data, offset, bytes, 0, structLength);
Add(new StaticProp(bytes, type, version));
offset += structLength;
}
}
}
}
}
}