From 6ec395bbcf40bde1473164417eb066259e771715 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Sun, 15 Sep 2024 00:44:13 +0000 Subject: [PATCH] Remove KondoKit dependency on XPGlobes --- client/src/main/java/plugin/api/API.java | 4 ++ client/src/main/java/rt4/HashTable.java | 60 ++++++++--------- .../src/main/java/rt4/HashTableIterator.java | 10 +-- client/src/main/java/rt4/LinkedList.java | 40 +++++------ client/src/main/java/rt4/MixerPcmStream.java | 20 +++--- client/src/main/java/rt4/Node.java | 16 ++--- .../src/main/kotlin/KondoKit/XPTable.kt | 66 +++++++++++++++++++ .../src/main/kotlin/KondoKit/XPTrackerView.kt | 1 - .../src/main/kotlin/KondoKit/plugin.kt | 2 +- .../main/kotlin/KondoKit/plugin.properties | 2 +- .../src/main/kotlin/XPGlobesPlugin/XPTable.kt | 42 ++++++++---- 11 files changed, 173 insertions(+), 90 deletions(-) create mode 100644 plugin-playground/src/main/kotlin/KondoKit/XPTable.kt diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index b545280..aabc7a3 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -67,6 +67,10 @@ public class API { return LoginManager.staffModLevel >= privilege.ordinal(); } + public static EnumType GetDataMap(int id) { + return EnumTypeList.get(id); + } + public static boolean IsHD() { return GlRenderer.enabled; } diff --git a/client/src/main/java/rt4/HashTable.java b/client/src/main/java/rt4/HashTable.java index 4fccd3d..b603544 100644 --- a/client/src/main/java/rt4/HashTable.java +++ b/client/src/main/java/rt4/HashTable.java @@ -21,28 +21,28 @@ public final class HashTable { private int anInt5037 = 0; @OriginalMember(owner = "client!sc", name = "c", descriptor = "[Lclient!ab;") - public final Node[] aClass3Array1; + public final Node[] nodes; @OriginalMember(owner = "client!sc", name = "h", descriptor = "I") public final int anInt5023; @OriginalMember(owner = "client!sc", name = "", descriptor = "(I)V") public HashTable(@OriginalArg(0) int arg0) { - this.aClass3Array1 = new Node[arg0]; + this.nodes = new Node[arg0]; this.anInt5023 = arg0; - for (@Pc(13) int local13 = 0; local13 < arg0; local13++) { - @Pc(25) Node local25 = this.aClass3Array1[local13] = new Node(); - local25.aClass3_223 = local25; - local25.aClass3_222 = local25; + for (@Pc(13) int i = 0; i < arg0; i++) { + @Pc(25) Node node = this.nodes[i] = new Node(); + node.previousNode = node; + node.nextNode = node; } } @OriginalMember(owner = "client!sc", name = "a", descriptor = "(I)V") public final void clear() { for (@Pc(5) int local5 = 0; local5 < this.anInt5023; local5++) { - @Pc(14) Node local14 = this.aClass3Array1[local5]; + @Pc(14) Node local14 = this.nodes[local5]; while (true) { - @Pc(17) Node local17 = local14.aClass3_222; + @Pc(17) Node local17 = local14.nextNode; if (local14 == local17) { break; } @@ -62,42 +62,42 @@ public final class HashTable { @OriginalMember(owner = "client!sc", name = "d", descriptor = "(I)Lclient!ab;") public final Node next() { @Pc(24) Node local24; - if (this.anInt5037 > 0 && this.aClass3_193 != this.aClass3Array1[this.anInt5037 - 1]) { + if (this.anInt5037 > 0 && this.aClass3_193 != this.nodes[this.anInt5037 - 1]) { local24 = this.aClass3_193; - this.aClass3_193 = local24.aClass3_222; + this.aClass3_193 = local24.nextNode; return local24; } do { if (this.anInt5037 >= this.anInt5023) { return null; } - local24 = this.aClass3Array1[this.anInt5037++].aClass3_222; - } while (this.aClass3Array1[this.anInt5037 - 1] == local24); - this.aClass3_193 = local24.aClass3_222; + local24 = this.nodes[this.anInt5037++].nextNode; + } while (this.nodes[this.anInt5037 - 1] == local24); + this.aClass3_193 = local24.nextNode; return local24; } @OriginalMember(owner = "client!sc", name = "a", descriptor = "(ILclient!ab;J)V") public final void put(@OriginalArg(1) Node arg0, @OriginalArg(2) long arg1) { - if (arg0.aClass3_223 != null) { + if (arg0.previousNode != null) { arg0.unlink(); } - @Pc(21) Node local21 = this.aClass3Array1[(int) (arg1 & (long) (this.anInt5023 - 1))]; - arg0.aClass3_222 = local21; + @Pc(21) Node local21 = this.nodes[(int) (arg1 & (long) (this.anInt5023 - 1))]; + arg0.nextNode = local21; arg0.key = arg1; - arg0.aClass3_223 = local21.aClass3_223; - arg0.aClass3_223.aClass3_222 = arg0; - arg0.aClass3_222.aClass3_223 = arg0; + arg0.previousNode = local21.previousNode; + arg0.previousNode.nextNode = arg0; + arg0.nextNode.previousNode = arg0; } @OriginalMember(owner = "client!sc", name = "a", descriptor = "(JI)Lclient!ab;") public final Node get(@OriginalArg(0) long arg0) { this.aLong168 = arg0; - @Pc(24) Node local24 = this.aClass3Array1[(int) (arg0 & (long) (this.anInt5023 - 1))]; - for (this.aClass3_192 = local24.aClass3_222; this.aClass3_192 != local24; this.aClass3_192 = this.aClass3_192.aClass3_222) { + @Pc(24) Node local24 = this.nodes[(int) (arg0 & (long) (this.anInt5023 - 1))]; + for (this.aClass3_192 = local24.nextNode; this.aClass3_192 != local24; this.aClass3_192 = this.aClass3_192.nextNode) { if (arg0 == this.aClass3_192.key) { @Pc(46) Node local46 = this.aClass3_192; - this.aClass3_192 = this.aClass3_192.aClass3_222; + this.aClass3_192 = this.aClass3_192.nextNode; return local46; } } @@ -109,10 +109,10 @@ public final class HashTable { public final int size() { @Pc(15) int local15 = 0; for (@Pc(17) int local17 = 0; local17 < this.anInt5023; local17++) { - @Pc(26) Node local26 = this.aClass3Array1[local17]; - @Pc(29) Node local29 = local26.aClass3_222; + @Pc(26) Node local26 = this.nodes[local17]; + @Pc(29) Node local29 = local26.nextNode; while (local29 != local26) { - local29 = local29.aClass3_222; + local29 = local29.nextNode; local15++; } } @@ -123,8 +123,8 @@ public final class HashTable { public final int method3865(@OriginalArg(0) Node[] arg0) { @Pc(13) int local13 = 0; for (@Pc(15) int local15 = 0; local15 < this.anInt5023; local15++) { - @Pc(24) Node local24 = this.aClass3Array1[local15]; - for (@Pc(27) Node local27 = local24.aClass3_222; local27 != local24; local27 = local27.aClass3_222) { + @Pc(24) Node local24 = this.nodes[local15]; + for (@Pc(27) Node local27 = local24.nextNode; local27 != local24; local27 = local27.nextNode) { arg0[local13++] = local27; } } @@ -136,14 +136,14 @@ public final class HashTable { if (this.aClass3_192 == null) { return null; } - @Pc(23) Node local23 = this.aClass3Array1[(int) (this.aLong168 & (long) (this.anInt5023 - 1))]; + @Pc(23) Node local23 = this.nodes[(int) (this.aLong168 & (long) (this.anInt5023 - 1))]; while (local23 != this.aClass3_192) { if (this.aClass3_192.key == this.aLong168) { @Pc(45) Node local45 = this.aClass3_192; - this.aClass3_192 = this.aClass3_192.aClass3_222; + this.aClass3_192 = this.aClass3_192.nextNode; return local45; } - this.aClass3_192 = this.aClass3_192.aClass3_222; + this.aClass3_192 = this.aClass3_192.nextNode; } this.aClass3_192 = null; return null; diff --git a/client/src/main/java/rt4/HashTableIterator.java b/client/src/main/java/rt4/HashTableIterator.java index e03a702..2a100f8 100644 --- a/client/src/main/java/rt4/HashTableIterator.java +++ b/client/src/main/java/rt4/HashTableIterator.java @@ -25,18 +25,18 @@ public final class HashTableIterator { @OriginalMember(owner = "client!l", name = "a", descriptor = "(I)Lclient!ab;") public final Node method2700() { @Pc(30) Node local30; - if (this.anInt3447 > 0 && this.aClass133_10.aClass3Array1[this.anInt3447 - 1] != this.aClass3_135) { + if (this.anInt3447 > 0 && this.aClass133_10.nodes[this.anInt3447 - 1] != this.aClass3_135) { local30 = this.aClass3_135; - this.aClass3_135 = local30.aClass3_222; + this.aClass3_135 = local30.nextNode; return local30; } do { if (this.aClass133_10.anInt5023 <= this.anInt3447) { return null; } - local30 = this.aClass133_10.aClass3Array1[this.anInt3447++].aClass3_222; - } while (local30 == this.aClass133_10.aClass3Array1[this.anInt3447 - 1]); - this.aClass3_135 = local30.aClass3_222; + local30 = this.aClass133_10.nodes[this.anInt3447++].nextNode; + } while (local30 == this.aClass133_10.nodes[this.anInt3447 - 1]); + this.aClass3_135 = local30.nextNode; return local30; } diff --git a/client/src/main/java/rt4/LinkedList.java b/client/src/main/java/rt4/LinkedList.java index 44303b7..86f0aa0 100644 --- a/client/src/main/java/rt4/LinkedList.java +++ b/client/src/main/java/rt4/LinkedList.java @@ -16,14 +16,14 @@ public final class LinkedList { @OriginalMember(owner = "client!ih", name = "", descriptor = "()V") public LinkedList() { - this.aClass3_109.aClass3_223 = this.aClass3_109; - this.aClass3_109.aClass3_222 = this.aClass3_109; + this.aClass3_109.previousNode = this.aClass3_109; + this.aClass3_109.nextNode = this.aClass3_109; } @OriginalMember(owner = "client!ih", name = "a", descriptor = "(I)V") public final void clear() { while (true) { - @Pc(5) Node local5 = this.aClass3_109.aClass3_222; + @Pc(5) Node local5 = this.aClass3_109.nextNode; if (local5 == this.aClass3_109) { this.aClass3_110 = null; return; @@ -34,36 +34,36 @@ public final class LinkedList { @OriginalMember(owner = "client!ih", name = "b", descriptor = "(I)Lclient!ab;") public final Node tail() { - @Pc(7) Node local7 = this.aClass3_109.aClass3_223; + @Pc(7) Node local7 = this.aClass3_109.previousNode; if (this.aClass3_109 == local7) { this.aClass3_110 = null; return null; } else { - this.aClass3_110 = local7.aClass3_223; + this.aClass3_110 = local7.previousNode; return local7; } } @OriginalMember(owner = "client!ih", name = "a", descriptor = "(ZLclient!ab;)V") public final void addTail(@OriginalArg(1) Node arg0) { - if (arg0.aClass3_223 != null) { + if (arg0.previousNode != null) { arg0.unlink(); } - arg0.aClass3_222 = this.aClass3_109; - arg0.aClass3_223 = this.aClass3_109.aClass3_223; - arg0.aClass3_223.aClass3_222 = arg0; - arg0.aClass3_222.aClass3_223 = arg0; + arg0.nextNode = this.aClass3_109; + arg0.previousNode = this.aClass3_109.previousNode; + arg0.previousNode.nextNode = arg0; + arg0.nextNode.previousNode = arg0; } @OriginalMember(owner = "client!ih", name = "a", descriptor = "(ILclient!ab;)V") public final void addHead(@OriginalArg(1) Node arg0) { - if (arg0.aClass3_223 != null) { + if (arg0.previousNode != null) { arg0.unlink(); } - arg0.aClass3_222 = this.aClass3_109.aClass3_222; - arg0.aClass3_223 = this.aClass3_109; - arg0.aClass3_223.aClass3_222 = arg0; - arg0.aClass3_222.aClass3_223 = arg0; + arg0.nextNode = this.aClass3_109.nextNode; + arg0.previousNode = this.aClass3_109; + arg0.previousNode.nextNode = arg0; + arg0.nextNode.previousNode = arg0; } @OriginalMember(owner = "client!ih", name = "d", descriptor = "(I)Lclient!ab;") @@ -73,14 +73,14 @@ public final class LinkedList { this.aClass3_110 = null; return null; } else { - this.aClass3_110 = local13.aClass3_223; + this.aClass3_110 = local13.previousNode; return local13; } } @OriginalMember(owner = "client!ih", name = "a", descriptor = "(B)Lclient!ab;") public final Node removeHead() { - @Pc(3) Node local3 = this.aClass3_109.aClass3_222; + @Pc(3) Node local3 = this.aClass3_109.nextNode; if (this.aClass3_109 == local3) { return null; } else { @@ -96,19 +96,19 @@ public final class LinkedList { this.aClass3_110 = null; return null; } else { - this.aClass3_110 = local12.aClass3_222; + this.aClass3_110 = local12.nextNode; return local12; } } @OriginalMember(owner = "client!ih", name = "f", descriptor = "(I)Lclient!ab;") public final Node head() { - @Pc(3) Node local3 = this.aClass3_109.aClass3_222; + @Pc(3) Node local3 = this.aClass3_109.nextNode; if (this.aClass3_109 == local3) { this.aClass3_110 = null; return null; } else { - this.aClass3_110 = local3.aClass3_222; + this.aClass3_110 = local3.nextNode; return local3; } } diff --git a/client/src/main/java/rt4/MixerPcmStream.java b/client/src/main/java/rt4/MixerPcmStream.java index 17f0e2f..f97937e 100644 --- a/client/src/main/java/rt4/MixerPcmStream.java +++ b/client/src/main/java/rt4/MixerPcmStream.java @@ -22,20 +22,20 @@ public final class MixerPcmStream extends PcmStream { @OriginalMember(owner = "client!ok", name = "a", descriptor = "(Lclient!ab;Lclient!ab;I)V") public static void method3331(@OriginalArg(0) Node arg0, @OriginalArg(1) Node arg1) { - if (arg0.aClass3_223 != null) { + if (arg0.previousNode != null) { arg0.unlink(); } - arg0.aClass3_222 = arg1; - arg0.aClass3_223 = arg1.aClass3_223; - arg0.aClass3_223.aClass3_222 = arg0; - arg0.aClass3_222.aClass3_223 = arg0; + arg0.nextNode = arg1; + arg0.previousNode = arg1.previousNode; + arg0.previousNode.nextNode = arg0; + arg0.nextNode.previousNode = arg0; } @OriginalMember(owner = "client!ei", name = "a", descriptor = "(Lclient!cc;)V") private void method1342(@OriginalArg(0) MixerListener arg0) { arg0.unlink(); arg0.method780(); - @Pc(9) Node local9 = this.aClass69_44.aClass3_109.aClass3_222; + @Pc(9) Node local9 = this.aClass69_44.aClass3_109.nextNode; if (local9 == this.aClass69_44.aClass3_109) { this.anInt1781 = -1; } else { @@ -75,7 +75,7 @@ public final class MixerPcmStream extends PcmStream { this.method1342(local60); } else { local60.anInt905 = local68; - this.method1348(local60.aClass3_222, local60); + this.method1348(local60.nextNode, local60); } } } while (arg2 != 0); @@ -150,7 +150,7 @@ public final class MixerPcmStream extends PcmStream { this.method1342(local50); } else { local50.anInt905 = local58; - this.method1348(local50.aClass3_222, local50); + this.method1348(local50.nextNode, local50); } } } while (arg0 != 0); @@ -165,9 +165,9 @@ public final class MixerPcmStream extends PcmStream { @OriginalMember(owner = "client!ei", name = "a", descriptor = "(Lclient!ab;Lclient!cc;)V") private void method1348(@OriginalArg(0) Node arg0, @OriginalArg(1) MixerListener arg1) { while (arg0 != this.aClass69_44.aClass3_109 && ((MixerListener) arg0).anInt905 <= arg1.anInt905) { - arg0 = arg0.aClass3_222; + arg0 = arg0.nextNode; } method3331(arg1, arg0); - this.anInt1781 = ((MixerListener) this.aClass69_44.aClass3_109.aClass3_222).anInt905; + this.anInt1781 = ((MixerListener) this.aClass69_44.aClass3_109.nextNode).anInt905; } } diff --git a/client/src/main/java/rt4/Node.java b/client/src/main/java/rt4/Node.java index 5010d4c..dfb0dfe 100644 --- a/client/src/main/java/rt4/Node.java +++ b/client/src/main/java/rt4/Node.java @@ -10,23 +10,23 @@ public class Node { public long key; @OriginalMember(owner = "client!ab", name = "d", descriptor = "Lclient!ab;") - public Node aClass3_222; + public Node nextNode; @OriginalMember(owner = "client!ab", name = "l", descriptor = "Lclient!ab;") - public Node aClass3_223; + public Node previousNode; @OriginalMember(owner = "client!ab", name = "a", descriptor = "(I)Z") public final boolean isLinked() { - return this.aClass3_223 != null; + return this.previousNode != null; } @OriginalMember(owner = "client!ab", name = "b", descriptor = "(I)V") public final void unlink() { - if (this.aClass3_223 != null) { - this.aClass3_223.aClass3_222 = this.aClass3_222; - this.aClass3_222.aClass3_223 = this.aClass3_223; - this.aClass3_223 = null; - this.aClass3_222 = null; + if (this.previousNode != null) { + this.previousNode.nextNode = this.nextNode; + this.nextNode.previousNode = this.previousNode; + this.previousNode = null; + this.nextNode = null; } } } diff --git a/plugin-playground/src/main/kotlin/KondoKit/XPTable.kt b/plugin-playground/src/main/kotlin/KondoKit/XPTable.kt new file mode 100644 index 0000000..38df208 --- /dev/null +++ b/plugin-playground/src/main/kotlin/KondoKit/XPTable.kt @@ -0,0 +1,66 @@ +package KondoKit + +import plugin.api.API +import rt4.IntNode +import rt4.Node + +object XPTable { + + const val MAX_LEVEL = 99 + const val INVALID_LEVEL = -1 + const val SKILLS_XP_TABLE = 716 + + private var xpTable: MutableList = mutableListOf() + + // Lazily load the XP table from the API if it's empty + private fun loadXpTable() { + if (xpTable.isEmpty()) { + // Add the initial entry for key 1 = 0 + xpTable.add(0) + + // Fetch XP table from the API + API.GetDataMap(SKILLS_XP_TABLE).table.nodes.forEach { bucket -> + var currentNode: Node = bucket.nextNode + while (currentNode !== bucket) { + if (currentNode is IntNode) { + xpTable.add(currentNode.value) + } + currentNode = currentNode.nextNode + } + } + } + } + + fun getXpRequiredForLevel(level: Int): Int { + loadXpTable() + if (level in 1..xpTable.size) { + return xpTable[level - 1] + } + return 0 + } + + fun getLevelForXp(xp: Int): Pair { + loadXpTable() + var lowIndex = 0 + var highIndex = xpTable.size - 1 + + if (xp >= xpTable[highIndex]) { + return Pair(MAX_LEVEL, xp - xpTable[highIndex]) // Level is max or above, return the highest level + } + + while (lowIndex <= highIndex) { + val midIndex = (lowIndex + highIndex) / 2 + when { + xp < xpTable[midIndex] -> highIndex = midIndex - 1 + xp >= xpTable[midIndex + 1] -> lowIndex = midIndex + 1 + else -> { + val currentLevel = midIndex + 1 + val xpGained = xp - xpTable[midIndex] + return Pair(currentLevel, xpGained) + } + } + } + + return Pair(INVALID_LEVEL, 0) // If xp is below all defined levels + } +} diff --git a/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt b/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt index e060a48..0472ce9 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt @@ -14,7 +14,6 @@ import KondoKit.plugin.Companion.kondoExposed_playerXPMultiplier import KondoKit.plugin.Companion.primaryColor import KondoKit.plugin.Companion.secondaryColor import KondoKit.plugin.StateManager.totalXPWidget -import XPGlobesPlugin.XPTable import plugin.api.API import java.awt.* import java.io.BufferedReader diff --git a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt index f6775b2..65de95e 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt @@ -22,7 +22,6 @@ import KondoKit.plugin.StateManager.initialXP import KondoKit.plugin.StateManager.totalXPWidget import KondoKit.plugin.StateManager.xpWidgets import plugin.Plugin -import plugin.annotations.PluginMeta import plugin.api.* import plugin.api.API.* import plugin.api.FontColor.fromColor @@ -39,6 +38,7 @@ import java.awt.event.MouseAdapter import java.awt.event.MouseEvent import javax.swing.* + class plugin : Plugin() { companion object { val WIDGET_SIZE = Dimension(270, 55) diff --git a/plugin-playground/src/main/kotlin/KondoKit/plugin.properties b/plugin-playground/src/main/kotlin/KondoKit/plugin.properties index edd523a..51c6d2a 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/plugin.properties +++ b/plugin-playground/src/main/kotlin/KondoKit/plugin.properties @@ -1,3 +1,3 @@ AUTHOR='downthecrop' DESCRIPTION='A plugin that adds a right-side panel with custom widgets and navigation.' -VERSION=1.0 \ No newline at end of file +VERSION=1.1 \ No newline at end of file diff --git a/plugin-playground/src/main/kotlin/XPGlobesPlugin/XPTable.kt b/plugin-playground/src/main/kotlin/XPGlobesPlugin/XPTable.kt index 90cb88a..15f161a 100644 --- a/plugin-playground/src/main/kotlin/XPGlobesPlugin/XPTable.kt +++ b/plugin-playground/src/main/kotlin/XPGlobesPlugin/XPTable.kt @@ -1,22 +1,36 @@ package XPGlobesPlugin +import plugin.api.API +import rt4.IntNode +import rt4.Node + object XPTable { - // source for the experience table: https://oldschool.runescape.wiki/w/Experience#Experience_table - private val xpTable = arrayOf( - 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, - 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, - 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, - 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, - 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, - 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, - 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, - 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, - 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, - 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 - ) + const val SKILLS_XP_TABLE = 716 + + private var xpTable: MutableList = mutableListOf() + + // Function to lazily load the XP table from the API if it's not already populated + private fun loadXpTable() { + if (xpTable.isEmpty()) { + // Add the initial entry for key 1 = 0 + xpTable.add(0) + + // Fetch XP table from the API + API.GetDataMap(SKILLS_XP_TABLE).table.nodes.forEach { bucket -> + var currentNode: Node = bucket.nextNode + while (currentNode !== bucket) { + if (currentNode is IntNode) { + xpTable.add(currentNode.value) + } + currentNode = currentNode.nextNode + } + } + } + } fun getXpRequiredForLevel(level: Int): Int { + loadXpTable() if (level in 1..xpTable.size) { return xpTable[level - 1] } @@ -24,6 +38,7 @@ object XPTable { } fun getLevelForXp(xp: Int): Pair { + loadXpTable() var lowIndex = 0 var highIndex = xpTable.size - 1 @@ -46,5 +61,4 @@ object XPTable { return Pair(Constants.INVALID_LEVEL, 0) // If xp is below all defined levels } - }