Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enittiy tracker hook not working #152

Merged
merged 2 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/main/java/com/anatawa12/fixRtm/asm/Types.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.anatawa12.fixRtm.asm.hooking

import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin


@IFMLLoadingPlugin.SortingIndex(2000)
class HookingFixRtmCorePlugin : IFMLLoadingPlugin {
override fun getASMTransformerClass(): Array<String> = arrayOf(
HookingTransformer::class.qualifiedName!!,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.anatawa12.fixRtm.asm.hooking

import com.anatawa12.fixRtm.asm.Types
import net.minecraft.launchwrapper.IClassTransformer
import org.objectweb.asm.*

class HookingTransformer : IClassTransformer {
override fun transform(name: String?, transformedName: String?, basicClass: ByteArray?): ByteArray? {
if (basicClass == null) return null
val isHooks = name == Types.hooksName
val cw = ClassWriter(0)
var cv: ClassVisitor = cw
cv = MethodVisitingClassVisitor(cv, listOfNotNull(
::NewEntityTrackerVisitor.takeUnless { isHooks },
::NewEntityTrackerVisitor.takeUnless { name == "com.anatawa12.fixRtm.rtm.entity.vehicle.VehicleTrackerEntryKt" },
))
ClassReader(basicClass).accept(cv, 0)
return cw.toByteArray()
Expand All @@ -21,21 +19,21 @@ class HookingTransformer : IClassTransformer {
var afterNew = false

override fun visitTypeInsn(opcode: Int, type: String?) {
if (opcode == Opcodes.NEW && type == Types.entityTrackerEntryInternalName)
if (opcode == Opcodes.NEW && type == "net/minecraft/entity/EntityTrackerEntry")
afterNew = true
super.visitTypeInsn(opcode, type)
}

override fun visitMethodInsn(opcode: Int, owner: String?, name: String?, desc: String?, itf: Boolean) {
if (afterNew
&& opcode == Opcodes.INVOKESPECIAL
&& owner == Types.entityTrackerEntryInternalName
&& owner == "net/minecraft/entity/EntityTrackerEntry"
&& name == "<init>"
&& desc == "(Lnet/minecraft/entity/Entity;IIIZ)V"
) {
afterNew = false
super.visitMethodInsn(Opcodes.INVOKESTATIC,
Types.hooksInternalName,
"com/anatawa12/fixRtm/rtm/entity/vehicle/VehicleTrackerEntryKt",
"newEntityTrackerEntry",
"(Lnet/minecraft/entity/Entity;IIIZ)Lnet/minecraft/entity/EntityTrackerEntry;",
false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@file:JvmName("HooksKt")

package com.anatawa12.fixRtm
package com.anatawa12.fixRtm.rtm.entity.vehicle

import jp.ngt.rtm.entity.train.EntityBogie
import jp.ngt.rtm.entity.vehicle.EntityVehicleBase
Expand Down