Skip to content

Commit

Permalink
fix: patch native mac correctly (hopefully!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Jul 9, 2024
1 parent 1816656 commit 2363368
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package net.rsprox.patch.native

import com.github.michaelbull.logging.InlineLogger
import net.rsprox.patch.NativeClientType
import net.rsprox.patch.PatchResult
import net.rsprox.patch.Patcher
import java.nio.file.LinkOption
import java.nio.file.Path
import kotlin.io.path.isRegularFile

public class NativePatcher : Patcher {
public class NativePatcher : Patcher<NativeClientType> {
override fun patch(
path: Path,
rsa: String,
javConfigUrl: String,
worldListUrl: String,
port: Int,
metadata: NativeClientType,
): PatchResult {
if (!path.isRegularFile(LinkOption.NOFOLLOW_LINKS)) {
throw IllegalArgumentException("Path $path does not point to a file.")
}
logger.debug { "Attempting to patch $path" }
val bytes = path.toFile().readBytes()
val result = patchModulus(bytes, rsa)
patchLocalhost(bytes)
when (metadata) {
NativeClientType.WIN -> {
patchLocalhost(bytes)
patchJs5Port(bytes, port)
patchGamePort(bytes, port)
}
NativeClientType.MAC -> {
patchMacPort(bytes, port)
}
}
patchJavConfig(bytes, javConfigUrl)
patchWorldList(bytes, worldListUrl)
patchJs5Port(bytes, port)
patchGamePort(bytes, port)
logger.debug { "Successfully patched $path" }
path.toFile().writeBytes(bytes)
return PatchResult.Success(
Expand All @@ -50,6 +59,14 @@ public class NativePatcher : Patcher {
logger.debug { "Replaced game port 43594 with $port" }
}

private fun patchMacPort(
bytes: ByteArray,
port: Int,
) {
bytes.patchPort(0xBE, port)
logger.debug { "Replaced game port 43594 with $port" }
}

private fun ByteArray.patchPort(
opcode: Int,
port: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.rsprox.proxy.downloader
package net.rsprox.patch

public enum class NativeClientType(
public val systemShortName: String,
Expand Down
3 changes: 2 additions & 1 deletion patch/src/main/kotlin/net/rsprox/patch/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package net.rsprox.patch

import java.nio.file.Path

public fun interface Patcher {
public fun interface Patcher<T> {
public fun patch(
path: Path,
rsa: String,
javConfigUrl: String,
worldListUrl: String,
port: Int,
metadata: T,
): PatchResult
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.rsprox.proxy.downloader

import com.github.michaelbull.logging.InlineLogger
import net.rsprox.patch.NativeClientType
import net.rsprox.proxy.config.CLIENTS_DIRECTORY
import java.nio.ByteBuffer
import java.nio.file.Files
Expand Down

0 comments on commit 2363368

Please sign in to comment.