From 7c29afa95ea1863eee1d41d60c1402057fc42f83 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 3 Mar 2020 22:19:23 +0900 Subject: [PATCH] =?UTF-8?q?fix=20RTM:=20SwitchTypeError=E3=82=92=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=89=E5=85=A8=E4=BD=93=E3=81=AB=E7=99=BA?= =?UTF-8?q?=E4=BF=A1=E3=81=97=E3=81=A6=E3=81=9F=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/anatawa12/fixRtm/Hocks.kt | 20 ++++ .../anatawa12/fixRtm/asm/FixRtmCorePlugin.kt | 1 + ...witchTypeErrorWillShownToAllTransformer.kt | 99 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 src/main/java/com/anatawa12/fixRtm/asm/SwitchTypeErrorWillShownToAllTransformer.kt diff --git a/src/main/java/com/anatawa12/fixRtm/Hocks.kt b/src/main/java/com/anatawa12/fixRtm/Hocks.kt index e07d67dd..b36508cc 100644 --- a/src/main/java/com/anatawa12/fixRtm/Hocks.kt +++ b/src/main/java/com/anatawa12/fixRtm/Hocks.kt @@ -5,9 +5,12 @@ package com.anatawa12.fixRtm import io.netty.buffer.ByteBuf import io.netty.buffer.Unpooled import jp.ngt.ngtlib.event.TickProcessEntry +import jp.ngt.ngtlib.io.NGTLog import jp.ngt.ngtlib.renderer.model.ModelFormatException import jp.ngt.rtm.modelpack.ResourceType import jp.ngt.rtm.modelpack.modelset.ResourceSet +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.util.text.TextComponentTranslation import java.util.zip.Inflater object ExModelPackManager { @@ -92,3 +95,20 @@ fun MovingSoundMaker_loadSoundJson_nullCheck(map: Map?, domain: Stri throw ModelFormatException("sound.json for $domain is invalid.") return map } + + +var BlockMarker_onMarkerActivated_player: EntityPlayer? = null +fun BlockMarker_onMarkerActivated(player: EntityPlayer) { + if (!player.world.isRemote) + BlockMarker_onMarkerActivated_player = player +} + +fun sendSwitchTypeError(message: String, vararg objects: Any?) { + val player = BlockMarker_onMarkerActivated_player + if (player == null) { + Exception("fixRTM Bug!!! BlockMarker_onMarkerActivated_player is not init-ed").printStackTrace() + NGTLog.sendChatMessageToAll(message, objects) + return + } + player.sendMessage(TextComponentTranslation(message, *objects)) +} diff --git a/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt b/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt index f3bf58aa..7e9d6447 100644 --- a/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt +++ b/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt @@ -13,6 +13,7 @@ class FixRtmCorePlugin : IFMLLoadingPlugin { , "com.anatawa12.fixRtm.asm.DummyModelSetTransform" , "com.anatawa12.fixRtm.asm.ModelPackConstructThreadTransformer" , "com.anatawa12.fixRtm.asm.NPEInMovingSoundMakerTransformer" + , "com.anatawa12.fixRtm.asm.SwitchTypeErrorWillShownToAllTransformer" //, "com.anatawa12.fixRtm.asm.ConstructDummisTransformer" ) diff --git a/src/main/java/com/anatawa12/fixRtm/asm/SwitchTypeErrorWillShownToAllTransformer.kt b/src/main/java/com/anatawa12/fixRtm/asm/SwitchTypeErrorWillShownToAllTransformer.kt new file mode 100644 index 00000000..4a62a84c --- /dev/null +++ b/src/main/java/com/anatawa12/fixRtm/asm/SwitchTypeErrorWillShownToAllTransformer.kt @@ -0,0 +1,99 @@ +package com.anatawa12.fixRtm.asm + +import net.minecraft.launchwrapper.IClassTransformer +import org.objectweb.asm.* +import org.objectweb.asm.Opcodes.* +import org.objectweb.asm.Type.BOOLEAN_TYPE +import org.objectweb.asm.Type.INT_TYPE + +@Suppress("PropertyName", "unused") +class SwitchTypeErrorWillShownToAllTransformer : IClassTransformer { + val RailMaker = Type.getObjectType("jp/ngt/rtm/rail/util/RailMaker")!! + val SwitchType = Type.getObjectType("jp/ngt/rtm/rail/util/SwitchType")!! + val BlockMarker = Type.getObjectType("jp/ngt/rtm/rail/BlockMarker")!! + val NGTLog = Type.getObjectType("jp/ngt/ngtlib/io/NGTLog")!! + + val World = Type.getObjectType("net/minecraft/world/World")!! + val EntityPlayer = Type.getObjectType("net/minecraft/entity/player/EntityPlayer")!! + + val HocksKt = Type.getObjectType("com/anatawa12/fixRtm/HocksKt")!! + + val String = Type.getObjectType("java/lang/String")!! + val Object = Type.getObjectType("java/lang/Object")!! + + // NGTLog + val sendChatMessageToAll = "sendChatMessageToAll" + val sendChatMessageToAll_desc = "($String[$Object)V" + + // RailMaker + val getSwitch = "getSwitch" + val getSwitch_desc = "()$SwitchType" + + // BlockMarker + val onMarkerActivated = "onMarkerActivated" + val onMarkerActivated_desc = "($World$INT_TYPE$INT_TYPE$INT_TYPE$EntityPlayer$BOOLEAN_TYPE)$BOOLEAN_TYPE" + + // HocksKt + val BlockMarker_onMarkerActivated = "BlockMarker_onMarkerActivated" + val BlockMarker_onMarkerActivated_desc = "($EntityPlayer)V" + + val sendSwitchTypeError = "sendSwitchTypeError" + val sendSwitchTypeError_desc = "($String[$Object)V" + + override fun transform(name: String, transformedName: String, basicClass: ByteArray?): ByteArray? { + if (basicClass == null) return basicClass + if (transformedName == RailMaker.className) { + val cr = ClassReader(basicClass) + val cw = ClassWriter(0) + val ca = object : ClassVisitor(ASM5, cw) { + override fun visitMethod(access: Int, name: String?, desc: String?, signature: String?, exceptions: Array?): MethodVisitor { + if (name == getSwitch && desc == getSwitch_desc) { + val mv1 = super.visitMethod(access, name, desc, signature, exceptions) + return object : MethodVisitor(ASM5, mv1) { + override fun visitMethodInsn(opcode: Int, owner: String?, name: String?, desc: String?, itf: Boolean) { + @Suppress("SimplifyBooleanWithConstants") + if (opcode == INVOKESTATIC && + owner == NGTLog.internalName && + name == sendChatMessageToAll && + desc == sendChatMessageToAll_desc && + itf == false) { + super.visitMethodInsn(INVOKESTATIC, HocksKt.internalName, sendSwitchTypeError, sendSwitchTypeError_desc, false) + } else { + super.visitMethodInsn(opcode, owner, name, desc, itf) + } + } + } + } + return super.visitMethod(access, name, desc, signature, exceptions) + } + } + cr.accept(ca, 0) + return cw.toByteArray() + } else if (transformedName == BlockMarker.className) { + val cr = ClassReader(basicClass) + val cw = ClassWriter(0) + val ca = object : ClassVisitor(ASM5, cw) { + override fun visitMethod(access: Int, name: String?, desc: String?, signature: String?, exceptions: Array?): MethodVisitor { + if (name == onMarkerActivated && desc == onMarkerActivated_desc) { + val mv1 = super.visitMethod(access, name, desc, signature, exceptions) + return object : MethodVisitor(ASM5, mv1) { + override fun visitCode() { + super.visitCode() + visitVarInsn(ALOAD, 5) + visitMethodInsn(INVOKESTATIC, HocksKt.internalName, BlockMarker_onMarkerActivated, BlockMarker_onMarkerActivated_desc, false) + } + } + } + return super.visitMethod(access, name, desc, signature, exceptions) + } + } + cr.accept(ca, 0) + return cw.toByteArray() + } + return basicClass + } +} + +/* +jp.ngt.rtm.modelpack.state.ResourceState.getResourceSet + */