Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

Commit 8eef4fc

Browse files
committed
[ADT] Start working on ADT.
1 parent a1faffd commit 8eef4fc

5 files changed

Lines changed: 114 additions & 27 deletions

File tree

MultiConverter.GUI/Form1.Designer.cs

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MultiConverter.GUI/Form1.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Win32;
22
using MultiConverter.Lib;
33
using MultiConverter.Lib.Converters;
4+
using MultiConverter.Lib.Converters.ADT;
45
using MultiConverter.Lib.Converters.Base;
56
using MultiConverter.Lib.Converters.WMO;
67
using System;
@@ -76,14 +77,14 @@ private void FixList(List<string> list)
7677

7778
if (filename.EndsWith("m2"))
7879
{
79-
var m2converter = new M2Converter(filename, helm_fix_cb.Checked);
80+
var m2converter = new M2Converter(filename, helmFix.Checked);
8081
if (m2converter.Fix())
8182
m2converter.Save();
8283

8384
continue;
8485
}
85-
// else if (filename.EndsWith("adt"))
86-
// converter = new AdtConverter(filename, adt_water.Checked, adt_models.Checked);
86+
else if (filename.EndsWith("adt"))
87+
converter = new ADTFile(filename.Replace(".adt", "_obj0.adt"), filename.Replace(".adt", "_tex0.adt"));
8788
// else if (filename.EndsWith("wdt"))
8889
// converter = new WDTConverter(filename);
8990
else if (Regex.IsMatch(filename, @".*_[0-9]{3}(_(lod[0-9]))?\.(wmo)"))
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using MultiConverter.Lib.Converters.Base;
2+
// using MultiConverter.Lib.Converters.ADT.Chunks;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
8+
9+
namespace MultiConverter.Lib.Converters.ADT
10+
{
11+
public class ADTFile : IConverter
12+
{
13+
public static List<IChunk> Chunks = new List<IChunk>();
14+
public static Dictionary<string, byte[]> ChunkData = new Dictionary<string, byte[]>();
15+
public static Dictionary<string, (uint order, bool disabled)> ChunkExtraData = new Dictionary<string, (uint order, bool disabled)>();
16+
17+
public static bool DisableDoodads = false;
18+
public static bool DisableWMOs = false;
19+
20+
public ADTFile(string objFilename, string texFilename)
21+
{
22+
23+
}
24+
25+
public void Read(byte[] inData)
26+
{
27+
// Clear chunks to prevent double data.
28+
Chunks.Clear();
29+
30+
using (var stream = new MemoryStream(inData))
31+
using (var reader = new BinaryReader(stream))
32+
{
33+
var chunkOrder = 0u;
34+
while (reader.BaseStream.Position < reader.BaseStream.Length)
35+
{
36+
var chunkId = new string(reader.ReadChars(4).Reverse().ToArray());
37+
var chunkSize = reader.ReadUInt32();
38+
39+
var chunkData = new byte[chunkSize];
40+
Buffer.BlockCopy(stream.ToArray(), (int)reader.BaseStream.Position, chunkData, 0, (int)chunkSize);
41+
42+
IChunk chunk = null;
43+
switch (chunkId)
44+
{
45+
default:
46+
Console.WriteLine($"Skipping {chunkId}");
47+
break;
48+
}
49+
50+
if (chunk != null)
51+
chunk.Read(chunkData);
52+
53+
ChunkExtraData.Add(chunkId, (chunkOrder, false));
54+
ChunkData.Add(chunkId, chunk != null ? chunk.Write() : chunkData);
55+
56+
++chunkOrder;
57+
reader.BaseStream.Position += chunkSize;
58+
}
59+
60+
// Close the streams so they can be written.
61+
reader.Close();
62+
stream.Close();
63+
}
64+
}
65+
66+
public void Write(string filename)
67+
{
68+
using (var stream = new MemoryStream())
69+
using (var writer = new BinaryWriter(stream))
70+
{
71+
foreach (var chunk in ChunkData)
72+
{
73+
var reversedSignature = chunk.Key.Reverse().ToArray();
74+
75+
foreach (var signatureChar in reversedSignature)
76+
writer.Write(signatureChar);
77+
78+
writer.Write(chunk.Value.Length);
79+
writer.Write(chunk.Value);
80+
}
81+
82+
File.WriteAllBytes(filename, stream.ToArray());
83+
}
84+
}
85+
}
86+
}

MultiConverter.Lib/MultiConverter.Lib.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<Folder Include="Converters\ADT\Chunks\Texture\" />
9+
<Folder Include="Converters\ADT\Chunks\Object\" />
10+
<Folder Include="Converters\ADT\Chunks\Root\" />
11+
</ItemGroup>
12+
713
</Project>

MultiConverter.Lib/Util/Utils.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ public class Utils
88
{
99
public static bool IsCorrectFile(string s)
1010
{
11-
return s.EndsWith("m2", StringComparison.OrdinalIgnoreCase)
12-
|| s.EndsWith("anim", StringComparison.OrdinalIgnoreCase)
13-
|| s.EndsWith("wmo", StringComparison.OrdinalIgnoreCase)
14-
|| (s.EndsWith("wdt", StringComparison.OrdinalIgnoreCase)
15-
// todo: match with a regex maybe ?
16-
&& !(s.EndsWith("_lgt.wdt", StringComparison.OrdinalIgnoreCase))
17-
&& !(s.EndsWith("_occ.wdt", StringComparison.OrdinalIgnoreCase))
18-
&& !(s.EndsWith("_fog.wdt", StringComparison.OrdinalIgnoreCase))
19-
)
20-
|| (Regex.IsMatch(s.ToLower(), @".*((_[0-9]{1,2}){2})(\.adt)"))
21-
;
11+
return s.EndsWith(".m2", StringComparison.OrdinalIgnoreCase)
12+
|| s.EndsWith(".anim", StringComparison.OrdinalIgnoreCase)
13+
|| s.EndsWith(".wmo", StringComparison.OrdinalIgnoreCase)
14+
|| s.EndsWith(".adt", StringComparison.OrdinalIgnoreCase)
15+
|| s.EndsWith(".wdt", StringComparison.OrdinalIgnoreCase);
2216
}
2317

2418
public static bool IsChunk(ref byte[] buff, int pos, int magic)

0 commit comments

Comments
 (0)