Skip to content

Commit e73ee91

Browse files
committed
tank: support season 17 trg change
1 parent 3175c6a commit e73ee91

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

TACTLib/Core/Product/Tank/ResourceGraph.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Buffers.Binary;
23
using System.Collections.Generic;
4+
using System.Diagnostics;
35
using System.IO;
46
using System.Linq;
57
using System.Runtime.InteropServices;
@@ -110,11 +112,19 @@ public struct TRGHeader { // version 11
110112
public const uint ENCRYPTED_MAGIC = 0x677274;
111113

112114
public uint GetNonEncryptedMagic() {
113-
return (uint) (UNENCRYPTED_MAGIC | (GetVersion() << 24));
115+
if (!IsEncrypted()) return m_footerMagic;
116+
return BinaryPrimitives.ReverseEndianness(m_footerMagic);
114117
}
115118

116119
public byte GetVersion() {
117-
return IsEncrypted() ? (byte) (m_footerMagic & 0x000000FF) : (byte) ((m_footerMagic & 0xFF000000) >> 24);
120+
var shift = IsPost217(this) ? 25 : 24; // todo: why?
121+
122+
var magic = GetNonEncryptedMagic();
123+
var version = magic >> shift;
124+
125+
// if we see version lower than 11 with new shift, build check is wrong
126+
Debug.Assert(shift < 25 || version >= 11);
127+
return (byte)version;
118128
}
119129

120130
public bool IsEncrypted() {
@@ -223,6 +233,10 @@ public static bool IsPre152(TRGHeader header) {
223233
public static bool IsPre212(TRGHeader header) {
224234
return header.m_buildVersion < 128702; // 128702 = 2.12 on pro
225235
}
236+
237+
public static bool IsPost217(TRGHeader header) {
238+
return header.m_buildVersion >= 139475; // 139475 = 2.17 on pro
239+
}
226240

227241
public ResourceGraph(ClientHandler client, Stream stream, string name) {
228242
m_name = name;
@@ -241,8 +255,10 @@ public ResourceGraph(ClientHandler client, Stream stream, string name) {
241255
throw new UnsupportedBuildVersionException($"unable to parse TRG. invalid version {version}, expected 5, 6, 7, 8, 9, 10, or 11");
242256
}
243257

258+
// version 7: type bundle index added
244259
// version 10: added extra entries to skin assets.. for trg runtime overrides (instead of on the skin asset)
245260
// version 11: 2 new header fields, unknown
261+
// s17: no version change but 1 bit was stolen from magic (shift for version number changed)...
246262

247263
var isEnc = m_header.IsEncrypted();
248264

0 commit comments

Comments
 (0)