From 7a4abf3f134cce01cd52f2bf05557dd17145bba6 Mon Sep 17 00:00:00 2001 From: ceikry Date: Mon, 5 Sep 2022 10:38:06 -0500 Subject: [PATCH] Thanos tool will now detect and ignore duplicate drop table, npc config, and item config entries --- src/main/kotlin/Editors.kt | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/Editors.kt b/src/main/kotlin/Editors.kt index 5a46bd9..db6a8d6 100644 --- a/src/main/kotlin/Editors.kt +++ b/src/main/kotlin/Editors.kt @@ -8,6 +8,7 @@ import java.io.IOException import java.lang.Exception import java.lang.StringBuilder import javax.script.ScriptEngineManager +import kotlin.io.println enum class Editors(val data: EditorData) { DROP_TABLES(object : EditorData("drop_tables.json"){ @@ -15,10 +16,19 @@ enum class Editors(val data: EditorData) { override fun parse() { Logger.logInfo("Parsing Drop Tables") configureParser() - data.forEach { dropTableRaw -> - val dropTable = dropTableRaw as org.json.simple.JSONObject + val usedIds = ArrayList() + data.forEach dataLoop@ { dropTableRaw -> + val dropTable = dropTableRaw as JSONObject val table = NPCDropTable() table.ids = dropTable["ids"].toString() + table.ids.split(",").map { it.toInt() }.forEach {id -> + if(usedIds.contains(id)) { + println("Detected duplicate ID, ignoring table: ") + println(dropTableRaw.toJSONString()) + return@dataLoop + } + usedIds.add(id) + } parseTable(dropTable["main"] as JSONArray,table,false) parseTable(dropTable["default"] as JSONArray,table,true) parseTable(dropTable["charm"] as JSONArray,table.charmTable,false) @@ -70,9 +80,16 @@ enum class Editors(val data: EditorData) { override fun parse() { Logger.logInfo("Parsing NPC configs") configureParser() + val usedIds = ArrayList() data.forEach { npcDataRaw -> val npcData = npcDataRaw as JSONObject val id = npcData["id"].toString().toInt() + if (usedIds.contains(id)) { + println("Duplicate NPC Config detected, ignoring config entry:") + println(npcDataRaw.toJSONString()) + return@forEach + } + usedIds.add(id) val name = npcData["name"].toString() TableData.npcNames[id] = name TableData.npcConfigKeys.addAll(npcData.keys.toHashSet() as HashSet) @@ -104,9 +121,15 @@ enum class Editors(val data: EditorData) { ITEM_CONFIGS(object : EditorData("item_configs.json"){ override fun parse() { configureParser() + val usedIds = ArrayList() data.forEach { itemDataRaw -> val itemData = itemDataRaw as JSONObject val id = itemData["id"].toString().toInt() + if (usedIds.contains(id)) { + println("Duplicate Item Config detected, ignoring config entry:") + println(itemDataRaw.toJSONString()) + return@forEach + } val name = itemData["name"].toString() TableData.itemConfigKeys.addAll(itemData.keys.toHashSet() as HashSet) TableData.itemNames[id] = name