From a8f8444d45b231d38ccd1c776efbe826281fcd69 Mon Sep 17 00:00:00 2001
From: comp500 <comp500@users.noreply.github.com>
Date: Mon, 18 Jul 2022 16:40:39 +0100
Subject: [PATCH] Fix handling of old packwiz.json files with negative murmur2
 values

---
 .../link/infra/packwiz/installer/metadata/hash/Hash.kt   | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main/kotlin/link/infra/packwiz/installer/metadata/hash/Hash.kt b/src/main/kotlin/link/infra/packwiz/installer/metadata/hash/Hash.kt
index 30d9319..1e9ca5b 100644
--- a/src/main/kotlin/link/infra/packwiz/installer/metadata/hash/Hash.kt
+++ b/src/main/kotlin/link/infra/packwiz/installer/metadata/hash/Hash.kt
@@ -21,7 +21,14 @@ data class Hash<T>(val type: HashFormat<T>, val value: T) {
 
 		object UInt: Encoding<kotlin.UInt> {
 			override fun encodeToString(value: kotlin.UInt) = value.toString()
-			override fun decodeFromString(str: String) = str.toUInt()
+			override fun decodeFromString(str: String) =
+				try {
+					str.toUInt()
+				} catch (e: NumberFormatException) {
+					// Old packwiz.json values are signed; if they are negative they should be parsed as signed integers
+					// and reinterpreted as unsigned integers
+					str.toInt().toUInt()
+				}
 		}
 	}