|
|
|
@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled |
|
|
|
|
import org.openrs2.buffer.use |
|
|
|
|
import org.openrs2.cache.Js5Archive |
|
|
|
|
import org.openrs2.cache.Store |
|
|
|
|
import org.openrs2.crypto.XteaKey |
|
|
|
|
import org.openrs2.db.Database |
|
|
|
|
import java.time.Instant |
|
|
|
|
import javax.inject.Inject |
|
|
|
@ -24,6 +25,14 @@ public class CacheExporter @Inject constructor( |
|
|
|
|
val name: String? |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
public data class GroupKey( |
|
|
|
|
val archive: Int, |
|
|
|
|
val group: Int, |
|
|
|
|
val nameHash: Int?, |
|
|
|
|
val name: String?, |
|
|
|
|
val key: XteaKey |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
public suspend fun list(): List<Cache> { |
|
|
|
|
return database.execute { connection -> |
|
|
|
|
connection.prepareStatement( |
|
|
|
@ -116,6 +125,56 @@ public class CacheExporter @Inject constructor( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public suspend fun exportKeys(id: Long): List<GroupKey> { |
|
|
|
|
return database.execute { connection -> |
|
|
|
|
connection.prepareStatement( |
|
|
|
|
""" |
|
|
|
|
WITH t AS ( |
|
|
|
|
SELECT a.archive_id, c.data, g.container_id |
|
|
|
|
FROM master_indexes m |
|
|
|
|
JOIN master_index_archives a ON a.container_id = m.container_id |
|
|
|
|
JOIN groups g ON g.archive_id = 255 AND g.group_id = a.archive_id::INTEGER AND g.truncated_version = a.version & 65535 |
|
|
|
|
JOIN containers c ON c.id = g.container_id AND c.crc32 = a.crc32 |
|
|
|
|
JOIN indexes i ON i.container_id = g.container_id AND i.version = a.version |
|
|
|
|
WHERE m.container_id = ? |
|
|
|
|
) |
|
|
|
|
SELECT t.archive_id, ig.group_id, ig.name_hash, n.name, (k.key).k0, (k.key).k1, (k.key).k2, (k.key).k3 |
|
|
|
|
FROM t |
|
|
|
|
JOIN index_groups ig ON ig.container_id = t.container_id |
|
|
|
|
JOIN groups g ON g.archive_id = t.archive_id::INTEGER AND g.group_id = ig.group_id AND g.truncated_version = ig.version & 65535 |
|
|
|
|
JOIN containers c ON c.id = g.container_id AND c.crc32 = ig.crc32 |
|
|
|
|
JOIN keys k ON k.id = c.key_id |
|
|
|
|
LEFT JOIN names n ON n.hash = ig.name_hash AND n.name ~ '^l(?:[0-9]|[1-9][0-9])_(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' |
|
|
|
|
""".trimIndent() |
|
|
|
|
).use { stmt -> |
|
|
|
|
stmt.setLong(1, id) |
|
|
|
|
|
|
|
|
|
stmt.executeQuery().use { rows -> |
|
|
|
|
val keys = mutableListOf<GroupKey>() |
|
|
|
|
|
|
|
|
|
while (rows.next()) { |
|
|
|
|
val archive = rows.getInt(1) |
|
|
|
|
val group = rows.getInt(2) |
|
|
|
|
var nameHash: Int? = rows.getInt(3) |
|
|
|
|
if (rows.wasNull()) { |
|
|
|
|
nameHash = null |
|
|
|
|
} |
|
|
|
|
val name = rows.getString(4) |
|
|
|
|
|
|
|
|
|
val k0 = rows.getInt(5) |
|
|
|
|
val k1 = rows.getInt(6) |
|
|
|
|
val k2 = rows.getInt(7) |
|
|
|
|
val k3 = rows.getInt(8) |
|
|
|
|
|
|
|
|
|
keys += GroupKey(archive, group, nameHash, name, XteaKey(k0, k1, k2, k3)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
keys |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private companion object { |
|
|
|
|
private const val BATCH_SIZE = 1024 |
|
|
|
|
} |
|
|
|
|