Skip to content

Commit

Permalink
Support for 1.43 (Beta) (#23)
Browse files Browse the repository at this point in the history
Added map overlay for viewpoints.
  • Loading branch information
dariowouters committed Nov 22, 2021
1 parent 90e6be1 commit 1a7f409
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Application reads ATS/ETS2 files to draw roads, prefabs, map overlays, ferr

![Preview of the map](/docs/preview.jpg "Preview of the map")

### **Support for 1.41 and Wyoming DLC**
### **Support for 1.43 (Beta)**

## Export Maps
Can now export maps as a tiled web map.
Expand Down
5 changes: 5 additions & 0 deletions TsMap/TsItem/TsCutsceneItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public TsCutsceneItem(TsSector sector, int startOffset) : base(sector, startOffs
public void TsCutsceneItem844(int startOffset)
{
var fileOffset = startOffset + 0x34; // Set position at start of flags
var isViewpoint = MemoryHelper.ReadUint8(Sector.Stream, fileOffset + 3) == 0;
if (isViewpoint)
{
Valid = true;
}
var tagsCount = MemoryHelper.ReadInt32(Sector.Stream, fileOffset += 0x05); // 0x05(flags)
var actionCount = MemoryHelper.ReadInt32(Sector.Stream, fileOffset += 0x04 + (0x08 * tagsCount) + 0x08); // 0x04(tagsCount) + tags + 0x08(node_uid)
fileOffset += 0x04; // 0x04(actionCount)
Expand Down
26 changes: 26 additions & 0 deletions TsMap/TsItem/TsVisibilityAreaItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;

namespace TsMap.TsItem
{
public class TsVisibilityAreaItem : TsItem
{
public TsVisibilityAreaItem(TsSector sector, int startOffset) : base(sector, startOffset)
{
Valid = false;

if (Sector.Version >= 891)
TsVisibilityAreaItem891(startOffset);
else
Log.Msg(
$"Unknown base file version ({Sector.Version}) for item {Type} in file '{Path.GetFileName(Sector.FilePath)}' @ {startOffset}.");
}

public void TsVisibilityAreaItem891(int startOffset)
{
var fileOffset = startOffset + 0x34; // Set position at start of flags
var childrenCount = MemoryHelper.ReadInt32(Sector.Stream, fileOffset += 0x05 + 0x10); // 0x05(flags) + 0x10(node_uid, width, height)
fileOffset += 0x04 + (0x08 * childrenCount); // 0x04(childrenCount) + childrenUids
BlockSize = fileOffset - startOffset;
}
}
}
1 change: 1 addition & 0 deletions TsMap/TsMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="TsItem\TsTrafficRuleItem.cs" />
<Compile Include="TsItem\TsTrajectoryItem.cs" />
<Compile Include="TsItem\TsTriggerItem.cs" />
<Compile Include="TsItem\TsVisibilityAreaItem.cs" />
<Compile Include="TsTypes.cs" />
<Compile Include="TsMapOverlay.cs" />
<Compile Include="TsMapper.cs" />
Expand Down
15 changes: 15 additions & 0 deletions TsMap/TsMapRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,21 @@ public void Render(Graphics g, Rectangle clip, float scale, PointF startPoint, M
if (b != null)
g.DrawImage(b, ferryItem.X, ferryItem.Z, b.Width, b.Height);
}

var viewpointOverlay = _mapper.LookupOverlay(ScsHash.StringToToken("viewpoint"));
var viewpointBitmap = viewpointOverlay?.GetBitmap();
if (viewpointBitmap != null)
{
var viewpoints = _mapper.Viewpoints.Where(item =>
item.X >= startPoint.X - itemDrawMargin && item.X <= endPoint.X + itemDrawMargin && item.Z >= startPoint.Y - itemDrawMargin &&
item.Z <= endPoint.Y + itemDrawMargin)
.ToList();

foreach (var viewpoint in viewpoints)
{
g.DrawImage(viewpointBitmap, viewpoint.X, viewpoint.Z, viewpointBitmap.Width, viewpointBitmap.Height);
}
}
}
var mapOverlay2Time = DateTime.Now.Ticks - mapOverlay2StartTime;

Expand Down
1 change: 1 addition & 0 deletions TsMap/TsMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class TsMapper
public readonly List<TsFerryItem> FerryConnections = new List<TsFerryItem>();
public readonly List<TsCompanyItem> Companies = new List<TsCompanyItem>();
public readonly List<TsTriggerItem> Triggers = new List<TsTriggerItem>();
public readonly List<TsCutsceneItem> Viewpoints = new List<TsCutsceneItem>();

public readonly Dictionary<ulong, TsNode> Nodes = new Dictionary<ulong, TsNode>();

Expand Down
12 changes: 12 additions & 0 deletions TsMap/TsSector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ public void Parse()
{
var item = new TsCutsceneItem(this, lastOffset);
lastOffset += item.BlockSize;
if (item.Valid) Mapper.Viewpoints.Add(item);
break;
}
case TsItemType.VisibilityArea:
{
var item = new TsVisibilityAreaItem(this, lastOffset);
lastOffset += item.BlockSize;
break;
}
default:
Expand All @@ -178,6 +185,11 @@ public void Parse()
}

lastOffset += 0x04;
if (Version >= 891)
{
var visAreaChildCount = BitConverter.ToInt32(Stream, lastOffset);
lastOffset += 0x04 + (0x08 * visAreaChildCount); // 0x04(visAreaChildCount) + (visAreaChildUids)
}
if (lastOffset != Stream.Length)
{
Log.Msg($"File '{Path.GetFileName(FilePath)}' was not read correctly. Read offset was at 0x{lastOffset:X} while file is 0x{Stream.Length:X} bytes long.");
Expand Down
1 change: 1 addition & 0 deletions TsMap/TsTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public enum TsItemType
Curve = 44,
Camera = 45,
Cutscene = 46,
VisibilityArea = 48,
};


Expand Down

0 comments on commit 1a7f409

Please sign in to comment.