Skip to content

Commit 8eaf5dc

Browse files
committed
write idx
1 parent a2ae3e5 commit 8eaf5dc

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

CathodeLib/Scripts/CATHODE/Shaders.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ override protected bool LoadInternal()
5656
{
5757
using (BinaryReader reader = new BinaryReader(new MemoryStream(content[i].Data)))
5858
{
59+
Entries.Add(new Shader());
60+
5961
reader.BaseStream.Position = 8; //0x7725BBA4, 36, 1
6062

6163
int textureCount = reader.ReadInt16();
@@ -139,19 +141,31 @@ override protected bool LoadInternal()
139141

140142
override protected bool SaveInternal()
141143
{
144+
List<Utilities.PAKContent> content = new List<Utilities.PAKContent>();
145+
for (int i = 0; i < Entries.Count; i++)
146+
{
147+
148+
}
142149
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepathBIN)))
143150
{
144151

145152
}
146-
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepathIDX)))
153+
154+
content = new List<Utilities.PAKContent>();
155+
for (int i = 0; i < Entries.Count; i++)
156+
{
157+
content.Add(new Utilities.PAKContent()
158+
{
159+
BinIndex = i,
160+
Data = BitConverter.GetBytes((Int32)i)
161+
});
162+
}
163+
Utilities.WritePAK(_filepathIDX, FileIdentifiers.SHADER_DATA, content);
164+
165+
content = new List<Utilities.PAKContent>();
166+
for (int i = 0; i < Entries.Count; i++)
147167
{
148-
writer.BaseStream.SetLength(0);
149-
writer.Write(0);
150-
writer.Write((int)FileIdentifiers.ASSET_FILE);
151-
writer.Write((int)FileIdentifiers.MODEL_DATA);
152-
writer.Write(Entries.Count);
153-
writer.Write(Entries.Count);
154-
writer.Write(new byte[12]);
168+
155169
}
156170
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
157171
{

CathodeLib/Scripts/Utilities.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ public static void WritePAK(string path, FileIdentifiers type, List<PAKContent>
250250
writer.BaseStream.Position = contentOffset;
251251
List<int> offsets = new List<int>();
252252
List<int> lengths = new List<int>();
253+
List<int> lengthsAligned = new List<int>();
253254
for (int i = 0; i < content.Count; i++)
254255
{
255256
offsets.Add((int)writer.BaseStream.Position - contentOffset);
256257
writer.Write(content[i].Data);
257258
lengths.Add((int)writer.BaseStream.Position - contentOffset - offsets[offsets.Count - 1]);
259+
Align(writer, 16);
260+
lengthsAligned.Add((int)writer.BaseStream.Position - contentOffset - offsets[offsets.Count - 1]);
258261
}
259262

260263
//Write model headers
@@ -263,11 +266,11 @@ public static void WritePAK(string path, FileIdentifiers type, List<PAKContent>
263266
{
264267
writer.Write(new byte[8]);
265268
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)lengths[i]) : BitConverter.GetBytes((Int32)lengths[i]));
266-
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)lengths[i]) : BitConverter.GetBytes((Int32)lengths[i]));
269+
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)lengthsAligned[i]) : BitConverter.GetBytes((Int32)lengthsAligned[i]));
267270
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)offsets[i]) : BitConverter.GetBytes((Int32)offsets[i]));
268271

269272
writer.Write(new byte[5]);
270-
writer.Write(type == FileIdentifiers.MODEL_DATA ? new byte[2] { 0x01, 0x01 } : new byte[2]);
273+
writer.Write(type == FileIdentifiers.MODEL_DATA ? new byte[2] { 0x01, 0x01 } : new byte[2] { 0x00, 0x01 });
271274
writer.Write(new byte[5]);
272275

273276
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)content[i].BinIndex) : BitConverter.GetBytes((Int32)content[i].BinIndex));
@@ -278,12 +281,14 @@ public static void WritePAK(string path, FileIdentifiers type, List<PAKContent>
278281
writer.BaseStream.Position = 0;
279282
writer.Write(new byte[4]);
280283
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)FileIdentifiers.ASSET_FILE) : BitConverter.GetBytes((Int32)FileIdentifiers.ASSET_FILE));
281-
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)FileIdentifiers.MODEL_DATA) : BitConverter.GetBytes((Int32)FileIdentifiers.MODEL_DATA));
284+
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)type) : BitConverter.GetBytes((Int32)type));
282285
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)content.Count) : BitConverter.GetBytes((Int32)content.Count));
283286
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)content.Count) : BitConverter.GetBytes((Int32)content.Count));
284287
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)16) : BitConverter.GetBytes((Int32)16));
285288
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)1) : BitConverter.GetBytes((Int32)1));
286-
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)1) : BitConverter.GetBytes((Int32)1));
289+
290+
int unk = type == FileIdentifiers.MODEL_DATA ? 1 : 0;
291+
writer.Write(e ? BigEndianUtils.FlipEndian((Int32)unk) : BitConverter.GetBytes((Int32)unk));
287292
}
288293
}
289294

0 commit comments

Comments
 (0)