Skip to content

Commit

Permalink
[map] fix map extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
yretenai committed Oct 14, 2020
1 parent c35f934 commit b450d88
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
23 changes: 11 additions & 12 deletions DataTool/SaveLogic/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public OverwatchMap(string name, FindLogic.Combo.ComboInfo info, teMapPlaceableD
Name = name;
Info = info;

SingleModels = singleModels;
ModelGroups = modelGroups;
Models = models;
Entities = entities;
Lights = lights;
Sounds = sounds;
Effects = effects;
SingleModels = singleModels ?? new teMapPlaceableData();
ModelGroups = modelGroups ?? new teMapPlaceableData();
Models = models ?? new teMapPlaceableData();
Entities = entities ?? new teMapPlaceableData();
Lights = lights ?? new teMapPlaceableData();
Sounds = sounds ?? new teMapPlaceableData();
Effects = effects ?? new teMapPlaceableData();
}

public void Write(Stream output) {
Expand Down Expand Up @@ -377,14 +377,13 @@ public static void Save(ICLIFlags flags, MapHeader mapInfo, STUMapHeader mapHead
}

public static teMapPlaceableData GetPlaceableData(STUMapHeader map, Enums.teMAP_PLACEABLE_TYPE modelGroup) {
return GetPlaceableData(map, (byte) modelGroup);
using (Stream stream = OpenFile(map.GetChunkKey(modelGroup))) {
return stream == null ? null : new teMapPlaceableData(stream, modelGroup);
}
}

public static teMapPlaceableData GetPlaceableData(STUMapHeader map, byte type) {
using (Stream stream = OpenFile(map.GetChunkKey(type))) {
if (stream == null) return null;
return new teMapPlaceableData(stream);
}
return GetPlaceableData(map, (Enums.teMAP_PLACEABLE_TYPE) type);
}
}
}
12 changes: 6 additions & 6 deletions DataTool/ToolLogic/Dbg/DebugMapDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ public void Parse(ICLIFlags toolFlags)

public static teMapPlaceableData GetPlaceableData(STUMapHeader map, Enums.teMAP_PLACEABLE_TYPE modelGroup)
{
return GetPlaceableData(map, (byte)modelGroup);
using (Stream stream = OpenFile(map.GetChunkKey(modelGroup)))
{
if (stream == null) return null;
return new teMapPlaceableData(stream, modelGroup);
}
}

public static teMapPlaceableData GetPlaceableData(STUMapHeader map, byte type)
{
using (Stream stream = OpenFile(map.GetChunkKey(type)))
{
if (stream == null) return null;
return new teMapPlaceableData(stream);
}
return GetPlaceableData(map, (Enums.teMAP_PLACEABLE_TYPE) type);
}
}
}
50 changes: 27 additions & 23 deletions TankLib/teMapChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ namespace TankLib {
/// Tank MapChunk, file type 0BC
/// </summary>
public abstract class teMapChunk {
protected abstract void Read(BinaryReader reader);
protected abstract void Read(BinaryReader reader, teMAP_PLACEABLE_TYPE type);

[SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
protected teMapChunk() {

}

[SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public teMapChunk(Stream stream) {
protected teMapChunk(Stream stream, teMAP_PLACEABLE_TYPE type) {
using (BinaryReader reader = new BinaryReader(stream)) {
Read(reader);
Read(reader, type);
}
}

[SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public teMapChunk(BinaryReader reader) {
Read(reader);
protected teMapChunk(BinaryReader reader, teMAP_PLACEABLE_TYPE type) {
Read(reader, type);
}
}

Expand All @@ -41,11 +46,7 @@ public struct CommonStructure {

public ushort Unknown1;
public byte Unknown2;

/// <summary>
/// Placeable type
/// </summary>
public teMAP_PLACEABLE_TYPE Type;
public byte Unknown3;

/// <summary>
/// Size in bytes (including this structure)
Expand Down Expand Up @@ -79,13 +80,16 @@ public struct PlaceableDataHeader {
public static teMapPlaceableManager Manager = new teMapPlaceableManager();

public PlaceableDataHeader Header;
public IMapPlaceable[] Placeables;
public CommonStructure[] CommonStructures;
public IMapPlaceable[] Placeables = {};
public CommonStructure[] CommonStructures = {};

public teMapPlaceableData() {
}

public teMapPlaceableData(Stream stream) : base(stream) { }
public teMapPlaceableData(BinaryReader reader) : base(reader) { }
public teMapPlaceableData(Stream stream, teMAP_PLACEABLE_TYPE type) : base(stream, type) { }
public teMapPlaceableData(BinaryReader reader, teMAP_PLACEABLE_TYPE type) : base(reader, type) { }

protected override void Read(BinaryReader reader) {
protected override void Read(BinaryReader reader, teMAP_PLACEABLE_TYPE type) {
Header = reader.Read<PlaceableDataHeader>();

if (Header.PlaceableOffset > 0) {
Expand All @@ -100,12 +104,12 @@ protected override void Read(BinaryReader reader) {
CommonStructure commonStructure = reader.Read<CommonStructure>();
CommonStructures[i] = commonStructure;

Placeables[i] = Manager.CreateType(commonStructure, reader);
Placeables[i] = Manager.CreateType(commonStructure, type, reader);

reader.BaseStream.Position = beforePos + CommonStructures[i].Size;
}

if (CommonStructures.Length > 0 && CommonStructures[0].Type == teMAP_PLACEABLE_TYPE.ENTITY && Header.InstanceDataOffset > 0) {
if (CommonStructures.Length > 0 && type == teMAP_PLACEABLE_TYPE.ENTITY && Header.InstanceDataOffset > 0) {
int execCount = 0;
reader.BaseStream.Position = Header.InstanceDataOffset+16;
foreach (IMapPlaceable placeable in Placeables) {
Expand All @@ -118,7 +122,7 @@ protected override void Read(BinaryReader reader) {
try {
teStructuredData structuredData = new teStructuredData(reader);
entity.InstanceData[i] = structuredData.GetInstance<STUComponentInstanceData>();
} catch (Exception e)
} catch
{
execCount++;
}
Expand Down Expand Up @@ -249,7 +253,7 @@ public void Read(BinaryReader reader) {
for (int i = 0; i < Header.InstanceDataCount; i++) {
long disStart = reader.BaseStream.Position;

var type = reader.ReadUInt32();
var _ = reader.ReadUInt32(); // type
var relOffset = reader.ReadUInt32();

var offset = disStart + relOffset;
Expand Down Expand Up @@ -480,12 +484,12 @@ private void AddType(Type type) {
Types[instance.Type] = type;
}

public IMapPlaceable CreateType(teMapPlaceableData.CommonStructure commonStructure, BinaryReader reader) {
public IMapPlaceable CreateType(teMapPlaceableData.CommonStructure commonStructure, teMAP_PLACEABLE_TYPE type, BinaryReader reader) {
IMapPlaceable value = new teMapPlaceableDummy((int)commonStructure.Size);
if (Types.TryGetValue(commonStructure.Type, out Type placeableType)) {
if (Types.TryGetValue(type, out Type placeableType)) {
value = (IMapPlaceable)Activator.CreateInstance(placeableType);
} else if (_misingTypes.Add(commonStructure.Type)) {
Debugger.Log(0, "teMapPlaceableManager", $"Unhandled placeable type: {commonStructure.Type}\r\n");
} else if (_misingTypes.Add(type)) {
Debugger.Log(0, "teMapPlaceableManager", $"Unhandled placeable type: {type}\r\n");
}
value.Read(reader);
return value;
Expand Down

0 comments on commit b450d88

Please sign in to comment.