Skip to content

Commit

Permalink
Fix compatibility with new large VMTs
Browse files Browse the repository at this point in the history
Some of the new VMT files for games like CSGO exceed the 1000 byte limit for data that is preloaded in the VPK tree. The rest of it is stored elsewhere in the archive. Before this, the application assumed the data for VMTs (usually a couple hundred bytes) was either all preloaded, or all located elsewhere in the file. Since the only time it's in both is if it's too large to be preloaded, I've only seen this show up with `hr_` textures in csgo.
  • Loading branch information
Dylancyclone committed Jun 30, 2021
1 parent c3cdd15 commit e7eac01
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/lathrum/VMF2OBJ/fileStructure/VPKEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,22 @@ protected VPKEntry(VPK archive, short archiveIndex, byte[] preloadData, String f
}

public byte[] readData() throws IOException, Exception {
byte[] data;
int dataOffset = 0;
// check for preload data
if (this.preloadData != null)
return this.preloadData;
if (this.preloadData != null) {
if (this.length == 0) {
return this.preloadData;
}
// Allocate enough space for the data
data = new byte[this.preloadData.length + this.length];
// Copy in the preloaded data
System.arraycopy(this.preloadData, 0, data, 0, this.preloadData.length);
// If there's additional data let it know to insert after the preloaded data
dataOffset = this.preloadData.length;
} else {
data = new byte[this.length];
}

// get target archive
File target = null;
Expand All @@ -63,9 +76,8 @@ public byte[] readData() throws IOException, Exception {
}

// read data
byte[] data = new byte[this.length];
fileInputStream.skip(this.offset);
fileInputStream.read(data, 0, this.length);
fileInputStream.read(data, dataOffset, this.length);

return data;
}
Expand Down

0 comments on commit e7eac01

Please sign in to comment.