Skip to content

Commit a6ec73a

Browse files
committed
Merge branch 'old/pre-acit-ufrags'
2 parents ac431ae + 8f7c1fc commit a6ec73a

29 files changed

+561
-211
lines changed

AssetExtractor/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System.Numerics;
2+
using System.Text;
23
using LibLunacy;
34

45
namespace AssetExtractor
@@ -10,7 +11,10 @@ public static void Main(string[] args)
1011
FileManager fm = new FileManager();
1112
fm.LoadFolder(args[0]);
1213
AssetLoader al = new AssetLoader(fm);
13-
al.LoadAssets();
14+
Vector2 __prog = new();
15+
float totprog = 0;
16+
string status = "";
17+
al.LoadAssets(ref __prog, ref totprog, ref status);
1418
foreach(KeyValuePair<ulong, CMoby> mobys in al.mobys)
1519
{
1620
if(!mobys.Value.name.Contains("talwyn")) continue;

LibLunacy/AssetLoader.cs

Lines changed: 82 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Numerics;
2+
13
namespace LibLunacy
24
{
35
//Assets are managed here and whenever an asset needs to reference another, that is done here
@@ -20,29 +22,43 @@ public AssetLoader(FileManager fileManager)
2022
fm = fileManager;
2123
}
2224

23-
public void LoadAssets()
25+
public void LoadAssets(ref Vector2 progress, ref float totalProgress, ref string status)
2426
{
25-
LoadTextures();
26-
LoadShaders();
27-
LoadMobys();
28-
LoadTies();
29-
LoadZones();
27+
status = "Loading textures...";
28+
totalProgress = 0;
29+
LoadTextures(ref progress);
30+
status = "Loading shaders...";
31+
totalProgress = 1;
32+
LoadShaders(ref progress);
33+
status = "Loading mobys...";
34+
totalProgress = 2;
35+
LoadMobys(ref progress);
36+
status = "Loading ties...";
37+
totalProgress = 3;
38+
LoadTies(ref progress);
39+
status = "Loading Zones...";
40+
totalProgress = 4;
41+
LoadZones(ref progress);
42+
totalProgress = 5;
3043
}
31-
public void LoadMobys()
44+
public void LoadMobys(ref Vector2 progress)
3245
{
33-
if(fm.isOld) LoadMobysOld();
34-
else LoadMobysNew();
46+
if(fm.isOld) LoadMobysOld(ref progress);
47+
else LoadMobysNew(ref progress);
3548
}
36-
private void LoadMobysOld()
49+
private void LoadMobysOld(ref Vector2 progress)
3750
{
3851
IGFile main = fm.igfiles["main.dat"];
3952
IGFile.SectionHeader mobySection = main.QuerySection(0xD100);
53+
progress.X = 0;
54+
progress.Y = mobySection.count;
4055
for(int i = 0; i < mobySection.count; i++)
4156
{
4257
mobys.Add((ulong)i, new CMoby(main, this, (uint)i));
58+
progress.X = i + 1;
4359
}
4460
}
45-
private void LoadMobysNew()
61+
private void LoadMobysNew(ref Vector2 progress)
4662
{
4763
if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
4864
{
@@ -57,6 +73,8 @@ private void LoadMobysNew()
5773
IGFile.SectionHeader mobySection = assetlookup.QuerySection(0x1D600);
5874
assetlookup.sh.Seek(mobySection.offset);
5975
AssetPointer[] mobyPtrs = FileUtils.ReadStructureArray<AssetPointer>(assetlookup.sh, mobySection.length / 0x10);
76+
progress.X = 0;
77+
progress.Y = mobyPtrs.Length;
6078
Stream mobyStream = fm.rawfiles["mobys.dat"];
6179
for(int i = 0; i < mobyPtrs.Length; i++)
6280
{
@@ -69,25 +87,29 @@ private void LoadMobysNew()
6987
CMoby moby = new CMoby(igmoby, this);
7088
Console.WriteLine($"Moby {i.ToString("X04")} is {moby.name}");
7189
mobys.Add(mobyPtrs[i].tuid, moby);
90+
progress.X = i + 1;
7291
}
7392
}
7493

75-
public void LoadTies()
94+
public void LoadTies(ref Vector2 progress)
7695
{
77-
if(fm.isOld) LoadTiesOld();
78-
else LoadTiesNew();
96+
if(fm.isOld) LoadTiesOld(ref progress);
97+
else LoadTiesNew(ref progress);
7998
}
80-
private void LoadTiesOld()
99+
private void LoadTiesOld(ref Vector2 progress)
81100
{
82101
IGFile main = fm.igfiles["main.dat"];
83102
IGFile.SectionHeader tieSection = main.QuerySection(0x3400);
103+
progress.X = 0;
104+
progress.Y = tieSection.count;
84105
for(int i = 0; i < tieSection.count; i++)
85106
{
86107
CTie tie = new CTie(main, this, (uint)i);
87108
ties.Add(tie.id, tie);
109+
progress.X = i + 1;
88110
}
89111
}
90-
private void LoadTiesNew()
112+
private void LoadTiesNew(ref Vector2 progress)
91113
{
92114
if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
93115
{
@@ -102,6 +124,8 @@ private void LoadTiesNew()
102124
IGFile.SectionHeader tieSection = assetlookup.QuerySection(0x1D300);
103125
assetlookup.sh.Seek(tieSection.offset);
104126
AssetPointer[] tiePtrs = FileUtils.ReadStructureArray<AssetPointer>(assetlookup.sh, tieSection.length / 0x10);
127+
progress.X = 0;
128+
progress.Y = tiePtrs.Length;
105129
Stream tieStream = fm.rawfiles["ties.dat"];
106130
for(int i = 0; i < tiePtrs.Length; i++)
107131
{
@@ -114,26 +138,30 @@ private void LoadTiesNew()
114138
CTie tie = new CTie(igtie, this);
115139
Console.WriteLine($"tie {i.ToString("X04")} is {tie.name}");
116140
ties.Add(tiePtrs[i].tuid, tie);
141+
progress.X = i + 1;
117142
}
118143
}
119144

120-
public void LoadShaders()
145+
public void LoadShaders(ref Vector2 progress)
121146
{
122-
if(fm.isOld) LoadShadersOld();
123-
else LoadShadersNew();
147+
if(fm.isOld) LoadShadersOld(ref progress);
148+
else LoadShadersNew(ref progress);
124149
}
125150

126-
private void LoadShadersOld()
151+
private void LoadShadersOld(ref Vector2 progress)
127152
{
128153
IGFile main = fm.igfiles["main.dat"];
129154
IGFile.SectionHeader shaderSection = main.QuerySection(0x5000);
155+
progress.X = 0;
156+
progress.Y = shaderSection.count;
130157
for(int i = 0; i < shaderSection.count; i++)
131158
{
132159
shaderDB.Add(new CShader(main, this, (uint)i));
133160
shaders.Add((ulong)i, shaderDB[i]);
161+
progress.X = i + 1;
134162
}
135163
}
136-
private void LoadShadersNew()
164+
private void LoadShadersNew(ref Vector2 progress)
137165
{
138166
if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
139167
{
@@ -148,6 +176,8 @@ private void LoadShadersNew()
148176
IGFile.SectionHeader shaderSection = assetlookup.QuerySection(0x1D100);
149177
assetlookup.sh.Seek(shaderSection.offset);
150178
AssetPointer[] shaderPtrs = FileUtils.ReadStructureArray<AssetPointer>(assetlookup.sh, shaderSection.length / 0x10);
179+
progress.X = 0;
180+
progress.Y = shaderPtrs.Length;
151181
Stream shaderStream = fm.rawfiles["shaders.dat"];
152182
for(int i = 0; i < shaderPtrs.Length; i++)
153183
{
@@ -158,25 +188,29 @@ private void LoadShadersNew()
158188
IGFile igshader = new IGFile(shaderms);
159189
CShader shader = new CShader(igshader, this);
160190
shaders.Add(shaderPtrs[i].tuid, shader);
191+
progress.X = i + 1;
161192
}
162193
}
163194

164-
public void LoadTextures()
195+
public void LoadTextures(ref Vector2 progress)
165196
{
166-
if(fm.isOld) LoadTexturesOld();
167-
else LoadTexturesNew();
197+
if(fm.isOld) LoadTexturesOld(ref progress);
198+
else LoadTexturesNew(ref progress);
168199
}
169200

170-
private void LoadTexturesOld()
201+
private void LoadTexturesOld(ref Vector2 progress)
171202
{
172203
IGFile main = fm.igfiles["main.dat"];
173204
IGFile.SectionHeader textureSection = main.QuerySection(0x5200);
205+
progress.X = 0;
206+
progress.Y = textureSection.count;
174207
for(int i = 0; i < textureSection.count; i++)
175208
{
176209
textures.Add((uint)(textureSection.offset + i * 0x20), new CTexture(fm, i));
210+
progress.X = i + 1;
177211
}
178212
}
179-
private void LoadTexturesNew()
213+
private void LoadTexturesNew(ref Vector2 progress)
180214
{
181215
if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
182216
{
@@ -192,31 +226,34 @@ private void LoadTexturesNew()
192226
assetlookup.sh.Seek(highmipSection.offset);
193227
AssetPointer[] highmips = FileUtils.ReadStructureArray<AssetPointer>(assetlookup.sh, highmipSection.length / 0x10);
194228

229+
progress.X = 0;
230+
progress.Y = highmips.Length;
231+
195232
for(int i = 0; i < highmips.Length; i++)
196233
{
197234
textures.Add((uint)highmips[i].tuid, new CTexture(fm, i));
235+
progress.X = i + 1;
198236
}
199237
}
200238

201-
public void LoadZones()
239+
public void LoadZones(ref Vector2 progress)
202240
{
203-
if(fm.isOld) LoadZonesOld();
204-
else LoadZonesNew();
241+
if(fm.isOld) LoadZonesOld(ref progress);
242+
else LoadZonesNew(ref progress);
205243
}
206244

207-
private void LoadZonesOld()
245+
private void LoadZonesOld(ref Vector2 progress)
208246
{
209247
IGFile main = fm.igfiles["main.dat"];
210248
IGFile.SectionHeader zoneSection = main.QuerySection(0x5000);
249+
progress.X = 0;
250+
progress.Y = zoneSection.count;
211251
Console.WriteLine($"{zoneSection.count} zones detected (0x{zoneSection.length:X} bytes long)");
212252
for (int i = 0; i < zoneSection.count; i++)
213253
{
214-
CZone zone = new(main, this)
215-
{
216-
index = i
217-
};
254+
CZone zone = new(main, this, i);
218255

219-
Console.WriteLine("[0x{0:X}] Zone {1} ({2}/{3}) has {4} ufrags", "unk", zone.name, i, zoneSection.count, zone.ufrags.Length);
256+
Console.WriteLine("[0x{0:X}] Zone {1} ({2}/{3}) has {4} ufrags", "unk", zone.name, i+1, zoneSection.count, zone.ufrags.Length);
220257
zones.Add((ulong)i, zone);
221258

222259
ufrags.Add((ulong)zone.index, new());
@@ -225,12 +262,14 @@ private void LoadZonesOld()
225262
if (zone.ufrags is null) continue;
226263
for (int j = 0; j < zone.ufrags.Length; j++)
227264
{
228-
locUfrags.Add(zone.ufrags[j].GetTuid(), zone.ufrags[j]);
265+
locUfrags.TryAdd(zone.ufrags[j].GetTuid(), zone.ufrags[j]);
229266
}
267+
progress.X = i + 1;
230268
}
231269
}
232-
private void LoadZonesNew()
233-
{ if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
270+
private void LoadZonesNew(ref Vector2 progress)
271+
{
272+
if (!fm.igfiles.TryGetValue("assetlookup.dat", out IGFile? assetlookup))
234273
{
235274
Console.WriteLine("Cannot find assetlookup.dat.");
236275
return;
@@ -243,15 +282,17 @@ private void LoadZonesNew()
243282
IGFile.SectionHeader zoneSection = assetlookup.QuerySection(0x1DA00);
244283
assetlookup.sh.Seek(zoneSection.offset);
245284
AssetPointer[] zonePtrs = FileUtils.ReadStructureArray<AssetPointer>(assetlookup.sh, zoneSection.length / 0x10);
246-
Stream zoneStream = fm.rawfiles["zones.dat"];
285+
progress.X = 0;
286+
progress.Y = zonePtrs.Length;
287+
Stream zoneStream = fm.rawfiles["zones.dat"];
247288
for(int i = 0; i < zonePtrs.Length; i++)
248289
{
249290
byte[] zonedat = new byte[zonePtrs[i].length];
250291
zoneStream.Seek(zonePtrs[i].offset, SeekOrigin.Begin);
251292
zoneStream.Read(zonedat, 0x00, (int)zonePtrs[i].length);
252293
MemoryStream zonems = new MemoryStream(zonedat);
253294
IGFile igzone = new(zonems);
254-
CZone zone = new(igzone, this) { index = i };
295+
CZone zone = new(igzone, this, i);
255296
Console.WriteLine($"[0x{zonePtrs[i].offset:X}] Zone {zone.index} {zone.name} (0x{zonePtrs[i].tuid:X}) has {zone.ufrags.Length} ufrags and {zone.tieInstances.Count} ties.");
256297
zones.Add(zonePtrs[i].tuid, zone);
257298

@@ -261,7 +302,7 @@ private void LoadZonesNew()
261302
localUfrags.TryAdd(zone.ufrags[j].GetTuid(), zone.ufrags[j]);
262303
}
263304
ufrags.Add((ulong)zone.index, localUfrags);
264-
305+
progress.X = i + 1;
265306
}
266307
}
267308

LibLunacy/FileUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static T ReadStructure<T>(StreamHelper sh, uint size = 0) where T : struc
9191
else if(fields[i].FieldType == typeof(float)) field = sh.ReadSingle();
9292
else if(fields[i].FieldType == typeof(string)) field = sh.ReadString();
9393
else if(fields[i].FieldType == typeof(Vector3)) field = new Vector3(sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle());
94+
else if (fields[i].FieldType == typeof(Vector4)) field = new Vector4(sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle());
9495
else if(fields[i].FieldType == typeof(Matrix4x4)) field = new Matrix4x4(
9596
sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle(),
9697
sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle(), sh.ReadSingle(),

LibLunacy/Gameplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Region(IGFile file, AssetLoader al)
131131
OldMobyInstance[] mobys = FileUtils.ReadStructureArray<OldMobyInstance>(file.sh, mobyInstSections.count);
132132

133133
zones = new CZone[1];
134-
zones[0] = new CZone(al.fm.igfiles["main.dat"], al);
134+
zones[0] = new CZone(al.fm.igfiles["main.dat"], al, 0);
135135
zones[0].name = "art";
136136

137137
DebugFile.DebugInstanceName[] names = null;

LibLunacy/Texture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public CTexture(FileManager fm, int index)
8888

8989
width = otr.width;
9090
height = otr.height;
91-
mipmapCount = otr.mipmapCount;
91+
mipmapCount = 0;
9292
format = (TexFormat)((otr.formatBitField >> 8) & 0xF);
9393

9494
if(texstream != null && ots.Any(x => x.index == index))
@@ -105,7 +105,7 @@ public CTexture(FileManager fm, int index)
105105
if(texstream != null && ots.Any(x => x.index == index))
106106
{
107107
texstream.Seek(ots.First(x => x.index == index).offset, SeekOrigin.Begin);
108-
if((format == TexFormat.DXT1 || format == TexFormat.DXT3 || format == TexFormat.DXT5) && (otr.formatBitField & 0x2000) == 0)
108+
if((format == TexFormat.DXT1 || format == TexFormat.DXT3 || format == TexFormat.DXT5) /*&& (otr.formatBitField & 0x2000) == 0*/)
109109
{
110110
texstream.Read(data);
111111
}
@@ -120,7 +120,7 @@ public CTexture(FileManager fm, int index)
120120
else
121121
{
122122
textures.Seek(otr.offset, SeekOrigin.Begin);
123-
if((format == TexFormat.DXT1 || format == TexFormat.DXT3 || format == TexFormat.DXT5) && (otr.formatBitField & 0x2000) == 0)
123+
if((format == TexFormat.DXT1 || format == TexFormat.DXT3 || format == TexFormat.DXT5) /*&& (otr.formatBitField & 0x2000) == 0*/)
124124
{
125125
textures.Read(data);
126126
}

0 commit comments

Comments
 (0)