From 75cdc5055423dfeb94a03d7c4206c15b40f50480 Mon Sep 17 00:00:00 2001 From: thedaneeffect Date: Wed, 17 Mar 2021 04:18:36 -0400 Subject: [PATCH] Stuff --- .idea/compiler.xml | 2 +- 317.iml | 4 +- pom.xml | 4 +- src/main/java/BZip2.java | 14 ++++ src/main/java/FileStore.java | 4 + src/main/java/Game.java | 140 +++++++++++++++++++++----------- src/main/java/IDKType.java | 4 +- src/main/java/LocType.java | 2 +- src/main/java/Model.java | 4 +- src/main/java/NPCType.java | 4 +- src/main/java/ObjType.java | 9 +- src/main/java/OnDemand.java | 2 +- src/main/java/PlayerEntity.java | 8 +- src/main/java/Scene.java | 68 ++++++++++------ src/main/java/SeqFrame.java | 11 +-- src/main/java/SpotAnimType.java | 23 +++--- 16 files changed, 192 insertions(+), 111 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 363ec27..0ec659c 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/317.iml b/317.iml index 1e4206e..42fd409 100644 --- a/317.iml +++ b/317.iml @@ -1,6 +1,6 @@ - + @@ -8,8 +8,8 @@ - + diff --git a/pom.xml b/pom.xml index fb82650..01ee5e1 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ org.apache.maven.plugins maven-compiler-plugin - 7 - 7 + 8 + 8 diff --git a/src/main/java/BZip2.java b/src/main/java/BZip2.java index d121492..d1c2791 100644 --- a/src/main/java/BZip2.java +++ b/src/main/java/BZip2.java @@ -15,6 +15,20 @@ public class BZip2 extends InputStream { private static final byte[] MAGIC = {'B', 'Z', 'h', '1'}; + /** + * @see #decompress(byte[], int, int, byte[]) + */ + public static byte[] decompress(byte[] src) throws IOException { + return decompress(src, 0, src.length, null); + } + + /** + * @see #decompress(byte[], int, int, byte[]) + */ + public static byte[] decompress(byte[] src, int off, int len) throws IOException { + return decompress(src, off, len, null); + } + /** * Decompresses the source. * diff --git a/src/main/java/FileStore.java b/src/main/java/FileStore.java index 2cc67f3..8b252cf 100644 --- a/src/main/java/FileStore.java +++ b/src/main/java/FileStore.java @@ -21,6 +21,10 @@ public class FileStore { this.maxFileSize = maxFileSize; } + public synchronized long getFileCount() throws IOException { + return idx.length() / 6L; + } + public synchronized byte[] read(int file) { try { idx.seek(file * 6L); diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 7bee39f..c0aaa4c 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -2,21 +2,21 @@ // Jad home page: http://www.kpdus.com/jad.html // Decompiler options: packimports(3) +import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.math3.random.ISAACRandom; import java.applet.AppletContext; import java.awt.*; -import java.io.DataInputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.math.BigInteger; import java.net.InetAddress; import java.net.Socket; import java.net.URL; import java.net.UnknownHostException; -import java.util.Arrays; +import java.util.List; +import java.util.*; import java.util.zip.CRC32; +import java.util.zip.GZIPInputStream; public class Game extends GameShell { @@ -746,14 +746,55 @@ public class Game extends GameShell { } } + { + CRC32 crc32 = new CRC32(); + + Map> skeletonGroups = new HashMap<>(); + + for (int file = 0; file < filestores[2].getFileCount(); file++) { + byte[] data = filestores[2].read(file); + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + IOUtils.copy(new GZIPInputStream(new ByteArrayInputStream(data)), baos); + + data = baos.toByteArray(); + + Buffer buffer = new Buffer(data); + buffer.position = data.length - 8; + + int off = buffer.get2U() + 2; // header + off += buffer.get2U(); // tran1 + off += buffer.get2U(); // tran2 + off += buffer.get2U(); // del + + int len = data.length - 8 - off; + + crc32.reset(); + crc32.update(data, off, len); // get skeleton crc32 + + long crc = crc32.getValue(); + + List list; + + if (!skeletonGroups.containsKey(crc)) { + list = new ArrayList<>(); + skeletonGroups.put(crc, list); + } else { + list = skeletonGroups.get(crc); + } + + list.add(file); + } + } + + skeletonGroups.forEach((key, value) -> System.out.printf("%s: %s%n", key, Arrays.toString(value.toArray()))); + } + showProgress(70, "Requesting models"); total = ondemand.getFileCount(0); for (int i = 0; i < total; i++) { - int index = ondemand.getModelIndex(i); - - if ((index & 1) != 0) { + if ((ondemand.getModelFlags(i) & 1) != 0) { ondemand.request(0, i); } } @@ -810,29 +851,29 @@ public class Game extends GameShell { } total = ondemand.getFileCount(0); - for (int k2 = 0; k2 < total; k2++) { - int l2 = ondemand.getModelIndex(k2); - byte byte0 = 0; - if ((l2 & 8) != 0) { - byte0 = 10; - } else if ((l2 & 0x20) != 0) { - byte0 = 9; - } else if ((l2 & 0x10) != 0) { - byte0 = 8; - } else if ((l2 & 0x40) != 0) { - byte0 = 7; - } else if ((l2 & 0x80) != 0) { - byte0 = 6; - } else if ((l2 & 2) != 0) { - byte0 = 5; - } else if ((l2 & 4) != 0) { - byte0 = 4; + for (int i = 0; i < total; i++) { + int flags = ondemand.getModelFlags(i); + byte priority = 0; + if ((flags & 8) != 0) { + priority = 10; + } else if ((flags & 0x20) != 0) { + priority = 9; + } else if ((flags & 0x10) != 0) { + priority = 8; + } else if ((flags & 0x40) != 0) { + priority = 7; + } else if ((flags & 0x80) != 0) { + priority = 6; + } else if ((flags & 2) != 0) { + priority = 5; + } else if ((flags & 4) != 0) { + priority = 4; } - if ((l2 & 1) != 0) { - byte0 = 3; + if ((flags & 1) != 0) { + priority = 3; } - if (byte0 != 0) { - ondemand.prefetch(byte0, 0, k2); + if (priority != 0) { + ondemand.prefetch(priority, 0, i); } } ondemand.prefetchMaps(members); @@ -1724,17 +1765,19 @@ public class Game extends GameShell { method63(); } catch (Exception ignored) { } + LocType.aCache_785.clear(); + if (super.frame != null) { aBuffer_1192.putOp(210); aBuffer_1192.put4(0x3f008edd); } + if (lowmem && (Signlink.cache_dat != null)) { - int j = ondemand.getFileCount(0); - for (int i1 = 0; i1 < j; i1++) { - int l1 = ondemand.getModelIndex(i1); - if ((l1 & 0x79) == 0) { - Model.unload(i1); + int count = ondemand.getFileCount(0); + for (int i = 0; i < count; i++) { + if ((ondemand.getModelFlags(i) & 0x79) == 0) { + Model.unload(i); } } } @@ -1784,7 +1827,7 @@ public class Game extends GameShell { public void createMinimap(int plane) { int[] pixels = imageMinimap.pixels; - Arrays.fill(pixels,0); + Arrays.fill(pixels, 0); for (int z = 1; z < 103; z++) { int offset = 24628 + ((103 - z) * 512 * 4); @@ -3488,7 +3531,7 @@ public class Game extends GameShell { if (request.store == 0) { Model.unpack(request.data, request.file); - if ((ondemand.getModelIndex(request.file) & 0x62) != 0) { + if ((ondemand.getModelFlags(request.file) & 0x62) != 0) { aBoolean1153 = true; if (anInt1276 != -1) { aBoolean1223 = true; @@ -5597,9 +5640,9 @@ public class Game extends GameShell { Model model = new Model(i2, aclass30_sub2_sub4_sub6); for (int l2 = 0; l2 < 5; l2++) { if (anIntArray990[l2] != 0) { - model.replaceColor(anIntArrayArray1003[l2][0], anIntArrayArray1003[l2][anIntArray990[l2]]); + model.recolor(anIntArrayArray1003[l2][0], anIntArrayArray1003[l2][anIntArray990[l2]]); if (l2 == 1) { - model.replaceColor(anIntArray1204[0], anIntArray1204[anIntArray990[l2]]); + model.recolor(anIntArray1204[0], anIntArray1204[anIntArray990[l2]]); } } } @@ -7131,6 +7174,7 @@ public class Game extends GameShell { int seq = entity.seqTurnAround; // Since the game uses a left-handed coordinate system, an increasing angle goes clockwise. + // See PreviewSinCos2D // yaw >= -45 deg && yaw <= 45 deg if ((remainingYaw >= -256) && (remainingYaw <= 256)) { @@ -9236,20 +9280,20 @@ public class Game extends GameShell { public void method136() { flameThread = true; - while (flameActive) { - flameCycle++; + while (flameActive) { + flameCycle++; - updateFlames(); - drawFlames(); + updateFlames(); + drawFlames(); - // the code here originally was some sort of lag detection code. It's not very useful anymore, and - // made the flames look choppier. + // the code here originally was some sort of lag detection code. It's not very useful anymore, and + // made the flames look choppier. - try { - Thread.sleep(20); // 50fps seems fine - } catch (Exception ignored) { - } + try { + Thread.sleep(20); // 50fps seems fine + } catch (Exception ignored) { } + } flameThread = false; } diff --git a/src/main/java/IDKType.java b/src/main/java/IDKType.java index 870a43f..383b885 100644 --- a/src/main/java/IDKType.java +++ b/src/main/java/IDKType.java @@ -91,7 +91,7 @@ public class IDKType { if (anIntArray659[j] == 0) { break; } - model.replaceColor(anIntArray659[j], anIntArray660[j]); + model.recolor(anIntArray659[j], anIntArray660[j]); } return model; } @@ -119,7 +119,7 @@ public class IDKType { if (anIntArray659[l] == 0) { break; } - model.replaceColor(anIntArray659[l], anIntArray660[l]); + model.recolor(anIntArray659[l], anIntArray660[l]); } return model; } diff --git a/src/main/java/LocType.java b/src/main/java/LocType.java index 74e06b3..00db8af 100644 --- a/src/main/java/LocType.java +++ b/src/main/java/LocType.java @@ -311,7 +311,7 @@ public class LocType { } if (anIntArray784 != null) { for (int k2 = 0; k2 < anIntArray784.length; k2++) { - model_3.replaceColor(anIntArray784[k2], anIntArray747[k2]); + model_3.recolor(anIntArray784[k2], anIntArray747[k2]); } } if (flag) { diff --git a/src/main/java/Model.java b/src/main/java/Model.java index 10d1db4..5180959 100644 --- a/src/main/java/Model.java +++ b/src/main/java/Model.java @@ -1512,7 +1512,7 @@ public class Model extends Entity { * @param src the source texture id. * @param dst the destination texture id. */ - public void replaceColor(int src, int dst) { + public void recolor(int src, int dst) { for (int k = 0; k < faceCount; k++) { if (faceColor[k] == src) { faceColor[k] = dst; @@ -1584,9 +1584,11 @@ public class Model extends Entity { int a = faceVertexA[f]; int b = faceVertexB[f]; int c = faceVertexC[f]; + int dxAB = vertexX[b] - vertexX[a]; int dyAB = vertexY[b] - vertexY[a]; int dzAB = vertexZ[b] - vertexZ[a]; + int dxAC = vertexX[c] - vertexX[a]; int dyAC = vertexY[c] - vertexY[a]; int dzAC = vertexZ[c] - vertexZ[a]; diff --git a/src/main/java/NPCType.java b/src/main/java/NPCType.java index cd49a5f..a9a8801 100644 --- a/src/main/java/NPCType.java +++ b/src/main/java/NPCType.java @@ -125,7 +125,7 @@ public class NPCType { } if (anIntArray76 != null) { for (int k = 0; k < anIntArray76.length; k++) { - model.replaceColor(anIntArray76[k], anIntArray70[k]); + model.recolor(anIntArray76[k], anIntArray70[k]); } } return model; @@ -185,7 +185,7 @@ public class NPCType { } if (anIntArray76 != null) { for (int k1 = 0; k1 < anIntArray76.length; k1++) { - model.replaceColor(anIntArray76[k1], anIntArray70[k1]); + model.recolor(anIntArray76[k1], anIntArray70[k1]); } } model.createLabelReferences(); diff --git a/src/main/java/ObjType.java b/src/main/java/ObjType.java index 933f7e2..e95fcc0 100644 --- a/src/main/java/ObjType.java +++ b/src/main/java/ObjType.java @@ -194,6 +194,7 @@ public class ObjType { class30_sub2_sub1_sub1_1.cropH = j; return class30_sub2_sub1_sub1_1; } + public byte aByte154; public int anInt155; public int[] anIntArray156; @@ -276,7 +277,7 @@ public class ObjType { } if (anIntArray156 != null) { for (int i1 = 0; i1 < anIntArray156.length; i1++) { - model.replaceColor(anIntArray156[i1], anIntArray160[i1]); + model.recolor(anIntArray156[i1], anIntArray160[i1]); } } return model; @@ -340,7 +341,7 @@ public class ObjType { } if (anIntArray156 != null) { for (int i1 = 0; i1 < anIntArray156.length; i1++) { - model.replaceColor(anIntArray156[i1], anIntArray160[i1]); + model.recolor(anIntArray156[i1], anIntArray160[i1]); } } return model; @@ -437,7 +438,7 @@ public class ObjType { } if (anIntArray156 != null) { for (int l = 0; l < anIntArray156.length; l++) { - model.replaceColor(anIntArray156[l], anIntArray160[l]); + model.recolor(anIntArray156[l], anIntArray160[l]); } } model.calculateNormals(64 + anInt196, 768 + anInt184, -50, -10, -50, true); @@ -464,7 +465,7 @@ public class ObjType { } if (anIntArray156 != null) { for (int l = 0; l < anIntArray156.length; l++) { - model.replaceColor(anIntArray156[l], anIntArray160[l]); + model.recolor(anIntArray156[l], anIntArray160[l]); } } return model; diff --git a/src/main/java/OnDemand.java b/src/main/java/OnDemand.java index 244cce9..14f224c 100644 --- a/src/main/java/OnDemand.java +++ b/src/main/java/OnDemand.java @@ -355,7 +355,7 @@ public class OnDemand implements Runnable { } } - public int getModelIndex(int id) { + public int getModelFlags(int id) { return modelIndex[id] & 0xff; } diff --git a/src/main/java/PlayerEntity.java b/src/main/java/PlayerEntity.java index 47f8372..8b5dcd2 100644 --- a/src/main/java/PlayerEntity.java +++ b/src/main/java/PlayerEntity.java @@ -274,9 +274,9 @@ public class PlayerEntity extends PathingEntity { model_1 = new Model(j2, aclass30_sub2_sub4_sub6); for (int j3 = 0; j3 < 5; j3++) { if (anIntArray1700[j3] != 0) { - model_1.replaceColor(Game.anIntArrayArray1003[j3][0], Game.anIntArrayArray1003[j3][anIntArray1700[j3]]); + model_1.recolor(Game.anIntArrayArray1003[j3][0], Game.anIntArrayArray1003[j3][anIntArray1700[j3]]); if (j3 == 1) { - model_1.replaceColor(Game.anIntArray1204[0], Game.anIntArray1204[anIntArray1700[j3]]); + model_1.recolor(Game.anIntArray1204[0], Game.anIntArray1204[anIntArray1700[j3]]); } } } @@ -346,9 +346,9 @@ public class PlayerEntity extends PathingEntity { Model model = new Model(k, aclass30_sub2_sub4_sub6); for (int j1 = 0; j1 < 5; j1++) { if (anIntArray1700[j1] != 0) { - model.replaceColor(Game.anIntArrayArray1003[j1][0], Game.anIntArrayArray1003[j1][anIntArray1700[j1]]); + model.recolor(Game.anIntArrayArray1003[j1][0], Game.anIntArrayArray1003[j1][anIntArray1700[j1]]); if (j1 == 1) { - model.replaceColor(Game.anIntArray1204[0], Game.anIntArray1204[anIntArray1700[j1]]); + model.recolor(Game.anIntArray1204[0], Game.anIntArray1204[anIntArray1700[j1]]); } } } diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java index e4dc912..9c11c14 100644 --- a/src/main/java/Scene.java +++ b/src/main/java/Scene.java @@ -803,43 +803,59 @@ public class Scene { for (int j1 = 0; j1 < model.vertexCount; j1++) { VertexNormal normal = model.vertexNormal[j1]; VertexNormal normal_1 = model.vertexNormalOriginal[j1]; - if (normal_1.w != 0) { - int i2 = model.vertexY[j1] - j; - if (i2 <= model_1.maxY) { - int j2 = model.vertexX[j1] - i; - if ((j2 >= model_1.minX) && (j2 <= model_1.maxX)) { - int k2 = model.vertexZ[j1] - k; - if ((k2 >= model_1.minZ) && (k2 <= model_1.maxZ)) { - for (int l2 = 0; l2 < i1; l2++) { - VertexNormal normal_2 = model_1.vertexNormal[l2]; - VertexNormal normal_3 = model_1.vertexNormalOriginal[l2]; - if ((j2 == ai[l2]) && (k2 == model_1.vertexZ[l2]) && (i2 == model_1.vertexY[l2]) && (normal_3.w != 0)) { - normal.x += normal_3.x; - normal.y += normal_3.y; - normal.z += normal_3.z; - normal.w += normal_3.w; - normal_2.x += normal_1.x; - normal_2.y += normal_1.y; - normal_2.z += normal_1.z; - normal_2.w += normal_1.w; - l++; - anIntArray486[j1] = anInt488; - anIntArray487[l2] = anInt488; - } - } - } - } + + if (normal_1.w == 0) { + continue; + } + + int i2 = model.vertexY[j1] - j; + + if (i2 > model_1.maxY) { + continue; + } + + int j2 = model.vertexX[j1] - i; + + if ((j2 < model_1.minX) || (j2 > model_1.maxX)) { + continue; + } + + int k2 = model.vertexZ[j1] - k; + + if ((k2 < model_1.minZ) || (k2 > model_1.maxZ)) { + continue; + } + + for (int l2 = 0; l2 < i1; l2++) { + VertexNormal normal_2 = model_1.vertexNormal[l2]; + VertexNormal normal_3 = model_1.vertexNormalOriginal[l2]; + + if ((j2 == ai[l2]) && (k2 == model_1.vertexZ[l2]) && (i2 == model_1.vertexY[l2]) && (normal_3.w != 0)) { + normal.x += normal_3.x; + normal.y += normal_3.y; + normal.z += normal_3.z; + normal.w += normal_3.w; + normal_2.x += normal_1.x; + normal_2.y += normal_1.y; + normal_2.z += normal_1.z; + normal_2.w += normal_1.w; + l++; + anIntArray486[j1] = anInt488; + anIntArray487[l2] = anInt488; } } } + if ((l < 3) || !flag) { return; } + for (int k1 = 0; k1 < model.faceCount; k1++) { if ((anIntArray486[model.faceVertexA[k1]] == anInt488) && (anIntArray486[model.faceVertexB[k1]] == anInt488) && (anIntArray486[model.faceVertexC[k1]] == anInt488)) { model.faceInfo[k1] = -1; } } + for (int l1 = 0; l1 < model_1.faceCount; l1++) { if ((anIntArray487[model_1.faceVertexA[l1]] == anInt488) && (anIntArray487[model_1.faceVertexB[l1]] == anInt488) && (anIntArray487[model_1.faceVertexC[l1]] == anInt488)) { model_1.faceInfo[l1] = -1; diff --git a/src/main/java/SeqFrame.java b/src/main/java/SeqFrame.java index d46b457..df676b0 100644 --- a/src/main/java/SeqFrame.java +++ b/src/main/java/SeqFrame.java @@ -61,24 +61,25 @@ public class SeqFrame { Buffer offsets = new Buffer(src); offsets.position = src.length - 8; - int offset = 0; Buffer header = new Buffer(src); + Buffer tran1 = new Buffer(src); + Buffer tran2 = new Buffer(src); + Buffer del = new Buffer(src); + Buffer skel = new Buffer(src); + + int offset = 0; header.position = offset; offset += offsets.get2U() + 2; - Buffer tran1 = new Buffer(src); tran1.position = offset; offset += offsets.get2U(); - Buffer tran2 = new Buffer(src); tran2.position = offset; offset += offsets.get2U(); - Buffer del = new Buffer(src); del.position = offset; offset += offsets.get2U(); - Buffer skel = new Buffer(src); skel.position = offset; SeqSkeleton skeleton = new SeqSkeleton(skel); diff --git a/src/main/java/SpotAnimType.java b/src/main/java/SpotAnimType.java index b69bcf3..a89bdcc 100644 --- a/src/main/java/SpotAnimType.java +++ b/src/main/java/SpotAnimType.java @@ -8,27 +8,26 @@ import java.io.IOException; public class SpotAnimType { - public static int anInt402; public static SpotAnimType[] instances; public static LRUMap modelCache = new LRUMap<>(30); public static void unpack(FileArchive archive) throws IOException { Buffer buffer = new Buffer(archive.read("spotanim.dat")); - anInt402 = buffer.get2U(); + int count = buffer.get2U(); if (instances == null) { - instances = new SpotAnimType[anInt402]; + instances = new SpotAnimType[count]; } - for (int j = 0; j < anInt402; j++) { - if (instances[j] == null) { - instances[j] = new SpotAnimType(); + for (int i = 0; i < count; i++) { + if (instances[i] == null) { + instances[i] = new SpotAnimType(); } - instances[j].anInt404 = j; - instances[j].method265(buffer); + instances[i].index = i; + instances[i].method265(buffer); } } public final int[] anIntArray408 = new int[6]; public final int[] anIntArray409 = new int[6]; - public int anInt404; + public int index; public int anInt405; public int anInt406 = -1; public SeqType seq; @@ -75,7 +74,7 @@ public class SpotAnimType { } public Model method266() { - Model model = modelCache.get(anInt404); + Model model = modelCache.get(index); if (model != null) { return model; } @@ -85,10 +84,10 @@ public class SpotAnimType { } for (int i = 0; i < 6; i++) { if (anIntArray408[0] != 0) { - model.replaceColor(anIntArray408[i], anIntArray409[i]); + model.recolor(anIntArray408[i], anIntArray409[i]); } } - modelCache.put(anInt404, model); + modelCache.put(index, model); return model; }