Skip to content

Commit

Permalink
Remove use of commons-codec, which does not exist on servers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Feb 8, 2024
1 parent 654f730 commit 17f3ed0
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main/groovy/org/groovymc/gml/mappings/MappingsProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import groovy.transform.CompileStatic
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.fml.loading.FMLLoader
import net.minecraftforge.srgutils.IMappingFile
import org.apache.commons.codec.binary.Hex
import org.slf4j.Logger

import java.net.http.HttpClient
Expand Down Expand Up @@ -189,7 +188,7 @@ class MappingsProvider {

if (Files.exists(versionJsonPath)) {
byte[] existingSha1 = calcSha1(versionJsonPath)
byte[] knownSha1 = Hex.decodeHex(sha1)
byte[] knownSha1 = decodeHex(sha1)
if (Arrays.equals(knownSha1, existingSha1)) return
LOGGER.warn 'Checksum mismatch for version.json'
LOGGER.warn "Expected: $knownSha1"
Expand All @@ -201,6 +200,23 @@ class MappingsProvider {
}
}

private static byte[] decodeHex(String hex) {
int l = hex.length()
int len = l.intdiv(2)
byte[] data = new byte[len]
for (int i = 0; i < len; i += 1) {
data[i] = (byte) ((hexDigit(hex.charAt(i*2)) << 4)
+ hexDigit(hex.charAt(i*2 + 1)))
}
return data
}

private static byte hexDigit(char ch) {
int digit = Character.digit(ch, 16)
if (digit == -1) throw new IllegalArgumentException("Invalid hex digit: $ch")
return (byte) digit
}

private void checkAndUpdateMCPConfigFile() throws IOException {
Path srg = this.cacheDir.resolve(MCPCONFIG_ZIP)
if (Files.exists(srg))
Expand All @@ -224,7 +240,7 @@ class MappingsProvider {

if (Files.exists(officialPath)) {
byte[] existingSha1 = calcSha1(officialPath)
byte[] knownSha1 = Hex.decodeHex(sha1)
byte[] knownSha1 = decodeHex(sha1)
if (Arrays.equals(knownSha1, existingSha1)) return
}

Expand Down

0 comments on commit 17f3ed0

Please sign in to comment.