198 lines
6.5 KiB
Kotlin
198 lines
6.5 KiB
Kotlin
package ru.dbotthepony.kstarbound
|
|
|
|
|
|
import com.google.common.collect.ImmutableList
|
|
import com.google.gson.reflect.TypeToken
|
|
import org.apache.logging.log4j.LogManager
|
|
import org.lwjgl.Version
|
|
import org.lwjgl.glfw.GLFW.glfwSetWindowShouldClose
|
|
import ru.dbotthepony.kstarbound.client.StarboundClient
|
|
import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition
|
|
import ru.dbotthepony.kstarbound.io.BTreeDB
|
|
import ru.dbotthepony.kstarbound.player.Avatar
|
|
import ru.dbotthepony.kstarbound.player.QuestDescriptor
|
|
import ru.dbotthepony.kstarbound.player.QuestInstance
|
|
import ru.dbotthepony.kstarbound.util.JVMTimeSource
|
|
import ru.dbotthepony.kstarbound.world.api.IChunkCell
|
|
import ru.dbotthepony.kstarbound.world.entities.ItemEntity
|
|
import ru.dbotthepony.kstarbound.io.json.VersionedJson
|
|
import ru.dbotthepony.kstarbound.io.readVarInt
|
|
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
|
import ru.dbotthepony.kstarbound.world.entities.WorldObject
|
|
import ru.dbotthepony.kstarbound.world.physics.Poly
|
|
import ru.dbotthepony.kvector.util2d.AABB
|
|
import ru.dbotthepony.kvector.vector.Vector2d
|
|
import java.io.BufferedInputStream
|
|
import java.io.ByteArrayInputStream
|
|
import java.io.DataInputStream
|
|
import java.io.File
|
|
import java.util.*
|
|
import java.util.concurrent.TimeUnit
|
|
import java.util.zip.Inflater
|
|
import java.util.zip.InflaterInputStream
|
|
import kotlin.collections.ArrayList
|
|
|
|
private val LOGGER = LogManager.getLogger()
|
|
|
|
fun main() {
|
|
LOGGER.info("Running LWJGL ${Version.getVersion()}")
|
|
|
|
//Thread.sleep(6_000L)
|
|
|
|
val db = BTreeDB(File("F:\\SteamLibrary\\steamapps\\common\\Starbound - Unstable\\storage\\universe\\389760395_938904237_-238610574_5.world"))
|
|
//val db = BTreeDB(File("world.world"))
|
|
|
|
//val meta = DataInputStream(BufferedInputStream(InflaterInputStream(ByteArrayInputStream(db.read(byteArrayOf(0, 0, 0, 0, 0))), Inflater())))
|
|
|
|
//println(meta.readInt())
|
|
//println(meta.readInt())
|
|
|
|
val client = StarboundClient()
|
|
|
|
//Starbound.addFilePath(File("./unpacked_assets/"))
|
|
Starbound.addPakPath(File("J:\\Steam\\steamapps\\common\\Starbound\\assets\\packed.pak"))
|
|
|
|
/*for (folder in File("J:\\Steam\\steamapps\\workshop\\content\\211820").list()!!) {
|
|
val f = File("J:\\Steam\\steamapps\\workshop\\content\\211820\\$folder\\contents.pak")
|
|
|
|
if (f.exists()) {
|
|
Starbound.addPakPath(f)
|
|
}
|
|
}*/
|
|
|
|
//Starbound.addPakPath(File("packed.pak"))
|
|
|
|
Starbound.initializeGame(client.loadingLog)
|
|
|
|
client.onTermination {
|
|
Starbound.terminateLoading = true
|
|
}
|
|
|
|
Starbound.onInitialize {
|
|
//for (chunkX in 17 .. 18) {
|
|
//for (chunkX in 14 .. 24) {
|
|
for (chunkX in 0 .. 100) {
|
|
//for (chunkX in 0 .. 17) {
|
|
// for (chunkY in 21 .. 21) {
|
|
for (chunkY in 18 .. 24) {
|
|
val data = db.read(byteArrayOf(1, (chunkX shr 8).toByte(), chunkX.toByte(), (chunkY shr 8).toByte(), chunkY.toByte()))
|
|
val data2 = db.read(byteArrayOf(2, (chunkX shr 8).toByte(), chunkX.toByte(), (chunkY shr 8).toByte(), chunkY.toByte()))
|
|
|
|
if (data != null) {
|
|
var reader = DataInputStream(BufferedInputStream(InflaterInputStream(ByteArrayInputStream(data), Inflater())))
|
|
reader.skipBytes(3)
|
|
|
|
for (y in 0 .. 31) {
|
|
for (x in 0 .. 31) {
|
|
val cell = client.world!!.getCellDirect(chunkX * 32 + x, chunkY * 32 + y)
|
|
if (cell == null) {
|
|
IChunkCell.skip(reader)
|
|
} else {
|
|
cell.read(reader)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (data2 != null) {
|
|
val reader = DataInputStream(BufferedInputStream(InflaterInputStream(ByteArrayInputStream(data2), Inflater())))
|
|
val i = reader.readVarInt()
|
|
|
|
for (i2 in 0 until i) {
|
|
val obj = VersionedJson(reader)
|
|
|
|
if (obj.identifier == "ObjectEntity") {
|
|
try {
|
|
WorldObject(client.world!!, obj.content.asJsonObject).spawn()
|
|
//println(obj.content)
|
|
//println(created)
|
|
} catch (err: Throwable) {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//val read = BinaryJsonReader.readElement(reader)
|
|
//println(read)
|
|
}
|
|
}
|
|
}
|
|
|
|
//client.world!!.parallax = Starbound.parallaxAccess["garden"]
|
|
|
|
val rand = Random()
|
|
|
|
for (i in 0 .. 128) {
|
|
val item = ItemEntity(client.world!!, Registries.items.values.random().value)
|
|
|
|
item.position = Vector2d(225.0 - i, 685.0)
|
|
item.spawn()
|
|
item.velocity = Vector2d(rand.nextDouble() * 32.0 - 16.0, rand.nextDouble() * 32.0 - 16.0)
|
|
//item.movement.applyVelocity(Vector2d(rand.nextDouble() * 1000.0 - 500.0, rand.nextDouble() * 1000.0 - 500.0))
|
|
}
|
|
|
|
// println(Starbound.statusEffects["firecharge"])
|
|
|
|
AssetPathStack.push("/animations/dust4")
|
|
val def = Starbound.gson.fromJson(Starbound.locate("/animations/dust4/dust4.animation").reader(), AnimationDefinition::class.java)
|
|
AssetPathStack.pop()
|
|
|
|
val avatar = Avatar(UUID.randomUUID())
|
|
val quest = QuestInstance(avatar, descriptor = QuestDescriptor("floran_mission1"))
|
|
quest.init()
|
|
quest.start()
|
|
|
|
var last = JVMTimeSource.INSTANCE.millis
|
|
|
|
client.onPostDrawWorld {
|
|
if (JVMTimeSource.INSTANCE.millis - last > 20L) {
|
|
quest.update(1)
|
|
last = JVMTimeSource.INSTANCE.millis
|
|
}
|
|
}
|
|
|
|
println(Registries.treasurePools["motherpoptopTreasure"]!!.value.evaluate(Random(), 2.0))
|
|
}
|
|
|
|
//ent.position += Vector2d(y = 14.0, x = -10.0)
|
|
client.camera.pos = Vector2d(238.0, 685.0)
|
|
//client.camera.pos = Vector2f(0f, 0f)
|
|
|
|
client.onDrawGUI {
|
|
client.font.render("Camera: ${client.camera.pos} ${client.settings.zoom}", y = 140f, scale = 0.25f)
|
|
client.font.render("Cursor: ${client.mouseCoordinates} -> ${client.screenToWorld(client.mouseCoordinates)}", y = 160f, scale = 0.25f)
|
|
client.font.render("World chunk: ${client.world!!.chunkFromCell(client.camera.pos)}", y = 180f, scale = 0.25f)
|
|
}
|
|
|
|
//ent.spawn()
|
|
|
|
client.input.addScrollCallback { _, x, y ->
|
|
if (y > 0.0) {
|
|
client.settings.zoom *= y.toFloat() * 2f
|
|
} else if (y < 0.0) {
|
|
client.settings.zoom /= -y.toFloat() * 2f
|
|
}
|
|
}
|
|
|
|
while (client.renderFrame()) {
|
|
Starbound.pollCallbacks()
|
|
|
|
//ent.think(client.frameRenderTime)
|
|
//client.camera.pos.x = ent.position.x.toFloat()
|
|
//client.camera.pos.y = ent.position.y.toFloat()
|
|
|
|
client.camera.pos += Vector2d(
|
|
(if (client.input.KEY_A_DOWN) -Starbound.TICK_TIME_ADVANCE * 32f / client.settings.zoom else 0.0) + (if (client.input.KEY_D_DOWN) Starbound.TICK_TIME_ADVANCE * 32f / client.settings.zoom else 0.0),
|
|
(if (client.input.KEY_W_DOWN) Starbound.TICK_TIME_ADVANCE * 32f / client.settings.zoom else 0.0) + (if (client.input.KEY_S_DOWN) -Starbound.TICK_TIME_ADVANCE * 32f / client.settings.zoom else 0.0)
|
|
)
|
|
|
|
//println(client.camera.velocity.toDoubleVector() * client.frameRenderTime * 0.1)
|
|
|
|
if (client.input.KEY_ESCAPE_PRESSED) {
|
|
glfwSetWindowShouldClose(client.window, true)
|
|
}
|
|
|
|
//ent.wantsToDuck = client.input.KEY_DOWN_DOWN
|
|
}
|
|
}
|