mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-10 05:01:50 +09:00
reflection function update
This commit is contained in:
@@ -3,15 +3,15 @@ package net.torvald.reflection
|
||||
/**
|
||||
* Created by minjaesong on 2023-03-25.
|
||||
*/
|
||||
fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name
|
||||
inline fun <reified T> Any.extortField(name: String): T? { // yes I'm deliberately using negative words for the function name
|
||||
return this.javaClass.getDeclaredField(name).let {
|
||||
it.isAccessible = true
|
||||
it.get(this)
|
||||
it.get(this) as T?
|
||||
}
|
||||
}
|
||||
fun Any.forceInvoke(name: String, params: Array<Any>): Any? { // yes I'm deliberately using negative words for the function name
|
||||
inline fun <reified T> Any.forceInvoke(name: String, params: Array<Any>): T? { // yes I'm deliberately using negative words for the function name
|
||||
return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let {
|
||||
it.isAccessible = true
|
||||
it.invoke(this, *params)
|
||||
it.invoke(this, *params) as T?
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe
|
||||
for (i in 0..3) { batch.fillRect(7, 5 + 115*i, 102, 8*FONT.H + 4) }
|
||||
}
|
||||
for (i in 0..3) {
|
||||
val ahead = (adev.extortField("playheads") as Array<AudioAdapter.Playhead>)[i]
|
||||
val ahead = adev.extortField<Array<AudioAdapter.Playhead>>("playheads")!![i]
|
||||
drawStatusLCD(adev, ahead, batch, i, 9f + 7, 7f + 7 + 115 * i)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe
|
||||
for (i in 0..3) { batch.fillRect(117, 5 + 115*i, 512, 8*FONT.H + 4) }
|
||||
}
|
||||
for (i in 0..3) {
|
||||
val ahead = (adev.extortField("playheads") as Array<AudioAdapter.Playhead>)[i]
|
||||
val ahead = adev.extortField<Array<AudioAdapter.Playhead>>("playheads")!![i]
|
||||
drawSoundscope(adev, ahead, batch, i, 117f, 5f + 115 * i)
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,8 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe
|
||||
|
||||
private fun drawSoundscope(audio: AudioAdapter, ahead: AudioAdapter.Playhead, batch: SpriteBatch, index: Int, x: Float, y: Float) {
|
||||
val gdxadev = ahead.audioDevice
|
||||
val bytes = gdxadev.extortField("bytes") as ByteArray?
|
||||
val bytesLen = gdxadev.extortField("bytesLength") as Int
|
||||
val bytes = gdxadev.extortField<ByteArray>("bytes")
|
||||
val bytesLen = gdxadev.extortField<Int>("bytesLength")!!
|
||||
val envelopeHalfHeight = 27
|
||||
|
||||
batch.inUse {
|
||||
|
||||
@@ -28,7 +28,7 @@ class TevdMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMen
|
||||
|
||||
if (dev?.javaClass?.simpleName == "TevdDiskDrive") {
|
||||
val dev = dev as TevdDiskDrive
|
||||
val DOM = dev.extortField("DOM") as PartialDOM
|
||||
val DOM = dev.extortField<PartialDOM>("DOM")
|
||||
|
||||
batch.inUse {
|
||||
batch.color = Color.WHITE
|
||||
|
||||
Reference in New Issue
Block a user