mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-08 23:07:46 +07:00
Added D2 finder to search for cofs in d2 files or dump d2 file entries
This commit is contained in:
10
.idea/runConfigurations/D2_Finder.xml
generated
Normal file
10
.idea/runConfigurations/D2_Finder.xml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="D2 Finder" type="Application" factoryName="Application" folderName="tools" singleton="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="com.riiablo.codec.D2Finder" />
|
||||||
|
<module name="tools" />
|
||||||
|
<option name="PROGRAM_PARAMETERS" value=""C:\Program Files (x86)\Steam\steamapps\common\Diablo II" SOSC1HS" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/android/assets" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
import com.badlogic.gdx.utils.StreamUtils;
|
import com.badlogic.gdx.utils.StreamUtils;
|
||||||
|
import com.riiablo.util.BufferUtils;
|
||||||
|
|
||||||
import org.apache.commons.io.EndianUtils;
|
import org.apache.commons.io.EndianUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -14,13 +15,11 @@ import java.io.InputStream;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
import com.riiablo.util.BufferUtils;
|
|
||||||
|
|
||||||
public class D2 {
|
public class D2 {
|
||||||
private static final String TAG = "D2";
|
private static final String TAG = "D2";
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = !true;
|
||||||
private static final boolean DEBUG_BLOCKS = DEBUG && true;
|
private static final boolean DEBUG_BLOCKS = DEBUG && true;
|
||||||
private static final boolean DEBUG_ENTRIES = DEBUG && false;
|
private static final boolean DEBUG_ENTRIES = DEBUG && true;
|
||||||
|
|
||||||
Block blocks[];
|
Block blocks[];
|
||||||
|
|
||||||
|
114
tools/src/com/riiablo/codec/D2Finder.java
Normal file
114
tools/src/com/riiablo/codec/D2Finder.java
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
package com.riiablo.codec;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Application;
|
||||||
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
|
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||||
|
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
||||||
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import com.riiablo.Riiablo;
|
||||||
|
import com.riiablo.mpq.MPQFileHandleResolver;
|
||||||
|
import com.riiablo.util.DebugUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class D2Finder extends ApplicationAdapter {
|
||||||
|
private static final String TAG = "D2Viewer";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration();
|
||||||
|
new HeadlessApplication(new D2Finder(args), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] cofs;
|
||||||
|
|
||||||
|
D2Finder(String[] args) {
|
||||||
|
Riiablo.home = new FileHandle(args[0]);
|
||||||
|
if (args.length > 1) {
|
||||||
|
this.cofs = Arrays.copyOfRange(args, 1, args.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create() {
|
||||||
|
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||||
|
|
||||||
|
Riiablo.home = Gdx.files.absolute(Riiablo.home.path());
|
||||||
|
Riiablo.assets = new AssetManager();
|
||||||
|
Riiablo.mpqs = new MPQFileHandleResolver();
|
||||||
|
|
||||||
|
String[] d2Names = { "animdata", "eanimdata" };
|
||||||
|
Array<Pair<String, D2>> d2s = new Array<>();
|
||||||
|
for (String d2Name : d2Names) {
|
||||||
|
String path = "data\\global\\" + d2Name + ".d2";
|
||||||
|
FileHandle handle = Riiablo.mpqs.resolve(path);
|
||||||
|
D2 d2 = D2.loadFromFile(handle);
|
||||||
|
d2s.add(Pair.of(d2Name, d2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cofs == null) {
|
||||||
|
for (Pair<String, D2> pair : d2s) {
|
||||||
|
dump(pair.getValue(), pair.getKey());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String cof : cofs) {
|
||||||
|
Gdx.app.log(TAG, cof);
|
||||||
|
int i = 0;
|
||||||
|
for (Pair<String, D2> pair : d2s) {
|
||||||
|
if (lookup(cof, pair.getValue(), pair.getKey()) != null) i++;
|
||||||
|
}
|
||||||
|
if (i == 0) Gdx.app.log(TAG, cof + " was not found in any file!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Gdx.app.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dump(D2 lib, String libName) {
|
||||||
|
if (lib == null) return;
|
||||||
|
FileHandle handle = Gdx.files.local(libName + ".tmp");
|
||||||
|
PrintWriter writer = null;
|
||||||
|
try {
|
||||||
|
writer = new PrintWriter(handle.write(false));
|
||||||
|
writer.println("cof"
|
||||||
|
+ '\t' + "framesPerDir"
|
||||||
|
+ '\t' + "b1"
|
||||||
|
+ '\t' + "b2"
|
||||||
|
+ '\t' + "data"
|
||||||
|
);
|
||||||
|
for (D2.Block block : lib.blocks) {
|
||||||
|
Gdx.app.log(TAG, "Writing " + block.numEntries + " to " + handle);
|
||||||
|
for (D2.Entry entry : block.entries) {
|
||||||
|
writer.println(entry.cof
|
||||||
|
+ '\t' + entry.framesPerDir
|
||||||
|
+ '\t' + (entry.b1 & 0xFF)
|
||||||
|
+ '\t' + (entry.b2 & 0xFF)
|
||||||
|
+ '\t' + DebugUtils.toByteArray(entry.data)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
Gdx.app.error(TAG, t.getMessage(), t);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private D2.Entry lookup(String cof, D2 lib, String libName) {
|
||||||
|
if (lib == null) return null;
|
||||||
|
D2.Entry resolved = lib.getEntry(cof);
|
||||||
|
if (resolved != null) Gdx.app.log(TAG, " " + libName + " : " + resolved);
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
Riiablo.assets.dispose();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user