From 2eb773633a7b8bcb396901d4565c66e82b129d2e Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sun, 16 Aug 2020 01:18:21 -0700 Subject: [PATCH] Added D2S#getTownsString() and implemented it into D2S Reader logging --- core/src/com/riiablo/save/d2s/D2S.java | 16 ++++++++++++++++ core/src/com/riiablo/save/d2s/D2SReader96.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/com/riiablo/save/d2s/D2S.java b/core/src/com/riiablo/save/d2s/D2S.java index 9cf3e67f..2d364354 100644 --- a/core/src/com/riiablo/save/d2s/D2S.java +++ b/core/src/com/riiablo/save/d2s/D2S.java @@ -127,6 +127,22 @@ public class D2S { return ""; } + public String getTownsString() { + final int DIFF_ACT_MASK = 0x7; + final int DIFF_FLAG_ACTIVE = 1 << 7; + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (byte town : towns) { + sb.append('A').append((town & DIFF_ACT_MASK) + 1); + if ((town & DIFF_FLAG_ACTIVE) == DIFF_FLAG_ACTIVE) sb.append('*'); + sb.append(", "); + } + + sb.setLength(sb.length() - 2); + sb.append("]"); + return sb.toString(); + } + public static class MercData { int flags; int seed; diff --git a/core/src/com/riiablo/save/d2s/D2SReader96.java b/core/src/com/riiablo/save/d2s/D2SReader96.java index 43ba4aef..b8cf49ef 100644 --- a/core/src/com/riiablo/save/d2s/D2SReader96.java +++ b/core/src/com/riiablo/save/d2s/D2SReader96.java @@ -105,7 +105,7 @@ public class D2SReader96 { d2s.colors = in.readBytes(COF.Component.NUM_COMPONENTS); if (log.isDebugEnabled()) log.debug("colors: {}", ByteBufUtil.hexDump(d2s.colors)); d2s.towns = in.readBytes(Riiablo.MAX_DIFFS); - if (log.isDebugEnabled()) log.debug("towns: {}", ByteBufUtil.hexDump(d2s.towns)); + if (log.isDebugEnabled()) log.debug("towns: {} ({})", ByteBufUtil.hexDump(d2s.towns), d2s.getTownsString()); d2s.mapSeed = in.read32(); Log.debugf(log, "mapSeed: 0x%08X", d2s.mapSeed); try {