From 6c5269c61e678d1b57024e93a0b275e6330d554f Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 19 Aug 2020 22:00:02 -0700 Subject: [PATCH] Greatly improved logging of property lists and attributes for items --- core/src/com/riiablo/item/Item.java | 17 ++++++++++++++++ core/src/com/riiablo/item/ItemReader.java | 7 ++++++- core/src/com/riiablo/item/PropertyList.java | 22 ++++++++++++++------- core/src/com/riiablo/item/Stat.java | 10 ++++++---- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/core/src/com/riiablo/item/Item.java b/core/src/com/riiablo/item/Item.java index 59aff585..b90010e2 100644 --- a/core/src/com/riiablo/item/Item.java +++ b/core/src/com/riiablo/item/Item.java @@ -118,6 +118,23 @@ public class Item { static final int SET_6_PROPS_FLAG = 1 << SET_PROPS + 4; static final int RUNE_PROPS_FLAG = 1 << RUNE_PROPS; + static String getPropListString(int i) { + switch (i) { + case MAGIC_PROPS: return "MAGIC_PROPS"; + case SET_PROPS: + case SET_PROPS + 1: + case SET_PROPS + 2: + case SET_PROPS + 3: + case SET_PROPS + 4: + return "SET_PROPS (" + (i + 1) + " items)"; + case RUNE_PROPS: + return "RUNE_PROPS"; + default: + assert false : "i(" + i + ") is not a valid prop list id!"; + return String.valueOf(i); + } + } + static final int GEMPROPS_WEAPON = 0; static final int GEMPROPS_ARMOR = 1; static final int GEMPROPS_SHIELD = 2; diff --git a/core/src/com/riiablo/item/ItemReader.java b/core/src/com/riiablo/item/ItemReader.java index 4402173e..46339e42 100644 --- a/core/src/com/riiablo/item/ItemReader.java +++ b/core/src/com/riiablo/item/ItemReader.java @@ -127,7 +127,12 @@ public class ItemReader { PropertyList[] props = item.stats = new PropertyList[Item.NUM_PROPS]; for (int i = 0; i < Item.NUM_PROPS; i++) { if (((listFlags >> i) & 1) == 1) { - props[i] = PropertyList.obtain().read(bits); + try { + Log.put("propList", Item.getPropListString(i)); + props[i] = PropertyList.obtain().read(bits); + } finally { + Log.remove("propList"); + } } } } diff --git a/core/src/com/riiablo/item/PropertyList.java b/core/src/com/riiablo/item/PropertyList.java index 705597d3..a8c5dd8a 100644 --- a/core/src/com/riiablo/item/PropertyList.java +++ b/core/src/com/riiablo/item/PropertyList.java @@ -2,8 +2,8 @@ package com.riiablo.item; import java.util.Comparator; import java.util.Iterator; +import org.apache.logging.log4j.Logger; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntMap; @@ -13,9 +13,11 @@ import com.riiablo.codec.excel.ItemStatCost; import com.riiablo.codec.excel.Properties; import com.riiablo.io.BitInput; import com.riiablo.io.BitOutput; +import com.riiablo.log.Log; +import com.riiablo.log.LogManager; public class PropertyList implements Iterable { - private static final String TAG = "PropertyList"; + private static final Logger log = LogManager.getLogger(PropertyList.class); private static final int[] ATTRIBUTES = {Stat.strength, Stat.energy, Stat.dexterity, Stat.vitality}; private static final int[] RESISTS = {Stat.fireresist, Stat.lightresist, Stat.coldresist, Stat.poisonresist}; @@ -80,9 +82,15 @@ public class PropertyList implements Iterable { } public PropertyList read(BitInput bitStream) { - for (int prop; (prop = bitStream.read15u(Stat.BITS)) != Stat.NONE;) { - for (int j = prop, size = j + Stat.getNumEncoded(prop); j < size; j++) { - read(j, bitStream); + for (int prop; (prop = bitStream.read15u(Stat.BITS)) != Stat.NONE; ) { + final int numEncoded = Stat.getNumEncoded(prop); + try { + if (numEncoded > 1) Log.put("numEncoded", numEncoded); + for (int j = prop, size = j + numEncoded; j < size; j++) { + read(j, bitStream); + } + } finally { + Log.remove("numEncoded"); } } @@ -347,7 +355,7 @@ public class PropertyList implements Iterable { props.put(inst.hash, inst); return value; case 18: // */time // TODO: Add support - Gdx.app.error(TAG, "Unsupported property function: " + prop.func[i]); + log.error("Unsupported property function: {}", prop.func[i]); return Integer.MIN_VALUE; case 19: // charged (skill) value = Stat.encodeValue(3, min[i], min[i]); // charges @@ -390,7 +398,7 @@ public class PropertyList implements Iterable { case 4: case 9: default: - Gdx.app.error(TAG, "Unsupported property function: " + prop.func[i]); + log.error("Unsupported property function: {}", prop.func[i]); return Integer.MIN_VALUE; } } diff --git a/core/src/com/riiablo/item/Stat.java b/core/src/com/riiablo/item/Stat.java index f7fa93a3..64a2b2db 100644 --- a/core/src/com/riiablo/item/Stat.java +++ b/core/src/com/riiablo/item/Stat.java @@ -2,8 +2,7 @@ package com.riiablo.item; import com.google.common.primitives.UnsignedInts; import java.util.Arrays; - -import com.badlogic.gdx.Gdx; +import org.apache.logging.log4j.Logger; import com.riiablo.CharacterClass; import com.riiablo.Riiablo; @@ -13,11 +12,12 @@ import com.riiablo.codec.excel.SkillDesc; import com.riiablo.codec.excel.Skills; import com.riiablo.io.BitInput; import com.riiablo.io.BitOutput; +import com.riiablo.log.LogManager; import com.riiablo.save.CharData; @SuppressWarnings("unused") public class Stat implements Comparable { - private static final String TAG = "Stat"; + private static final Logger log = LogManager.getLogger(Stat.class); public static final int strength = 0; public static final int energy = 1; @@ -492,6 +492,7 @@ public class Stat implements Comparable { val = bitStream.read31u(entry.Save_Bits) - entry.Save_Add; hash = hash(stat, param); modified = false; + log.trace("{}: {} {}", entry, val, param); // TODO: improve return this; } @@ -502,6 +503,7 @@ public class Stat implements Comparable { entry = Riiablo.files.ItemStatCost.get(stat); hash = Stat.hash(stat, param); modified = false; + log.trace("{}: {} {}", entry, val, param); // TODO: improve return this; } @@ -576,7 +578,7 @@ public class Stat implements Comparable { switch (entry.Encode) { case 3: case 4: - Gdx.app.error(TAG, "add unsupported when Encoding = " + entry.Encode); + log.error("add unsupported when Encoding = {}", entry.Encode); break; case 0: case 1: