Workaround for issue #9

This commit is contained in:
Collin Smith 2019-03-11 19:10:01 -07:00
parent 6b5ab8224e
commit 8eb19c2063
3 changed files with 22 additions and 1 deletions

View File

@ -237,6 +237,7 @@ public class Client extends Game {
Riiablo.mpqs = mpqs = new MPQFileHandleResolver();
mpqs.add(home.child("patch_d2.mpq"));
mpqs.add(home.child("d2exp.mpq"));
mpqs.delete("data\\global\\sfx\\Item\\gem.wav"); // workaround for issue #9
mpqs.add(home.child("d2xmusic.mpq"));
mpqs.add(home.child("d2xtalk.mpq"));
mpqs.add(home.child("d2xvideo.mpq"));

View File

@ -49,6 +49,11 @@ public class MPQ {
return hashTable.contains(fileName);
}
public boolean delete(String fileName) {
fileName = fileName.replaceAll("/", "\\\\");
return hashTable.deleteEntry(fileName);
}
public long length(String fileName) {
fileName = fileName.replaceAll("/", "\\\\");
HashTable.Entry entry = hashTable.getEntry(fileName);
@ -238,6 +243,15 @@ public class MPQ {
return index != -1 ? entries[index] : null;
}
boolean deleteEntry(String file) {
Entry entry = getEntry(file);
System.out.println("deleting entry " + entry);
if (entry == null || entry.blockIndex == Entry.DELETED) return false;
entry.blockIndex = Entry.DELETED;
System.out.println("-> " + entry);
return true;
}
public boolean contains(String file) {
return getIndex(File.key(file), File.offset(file), Entry.DEFAULT_LOCALE) != -1;
}
@ -276,7 +290,7 @@ public class MPQ {
final long key; // QWORD
final short locale; // WORD
final short platform; // WORD
final int blockIndex; // DWORD
int blockIndex; // DWORD
Entry(ByteBuffer in) {
key = in.getLong();

View File

@ -20,6 +20,12 @@ public class MPQFileHandleResolver implements FileHandleResolver {
add(MPQ.loadFromFile(file));
}
public boolean delete(String fileName) {
boolean deleted = false;
for (MPQ mpq : mpqs) deleted = mpq.delete(fileName);
return deleted;
}
public boolean contains(String fileName) {
for (MPQ mpq : mpqs) {
if (mpq.contains(fileName)) {