Refactored transformers to mixins annotations

This commit is contained in:
Lenni0451 2023-11-03 20:46:28 +01:00
parent 1aa0740a67
commit 4360abab2f
No known key found for this signature in database
GPG Key ID: 5D59B86635AD3F2F
7 changed files with 51 additions and 51 deletions

View File

@ -81,7 +81,6 @@ public class ViaProxy {
final IClassProvider classProvider = new GuavaClassPathProvider();
final TransformerManager transformerManager = new TransformerManager(classProvider);
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
if (instrumentation != null) {
transformerManager.hookInstrumentation(instrumentation);

View File

@ -15,17 +15,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CModifyConstant;
import net.raphimc.netminecraft.packet.impl.handshake.C2SHandshakePacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@CTransformer(C2SHandshakePacket.class)
public abstract class C2SHandshakePacketTransformer {
@Mixin(C2SHandshakePacket.class)
public abstract class MixinC2SHandshakePacket {
@CModifyConstant(method = "read", intValue = 255)
private int allowLargerHostnames() {
@ModifyConstant(method = "read", constant = @Constant(intValue = 255))
private int allowLargerHostnames(int constant) {
return Short.MAX_VALUE;
}

View File

@ -15,20 +15,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.util.Config;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CRedirect;
import net.raphimc.viaproxy.protocolhack.ConfigPatcher;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Map;
@CTransformer(Config.class)
public abstract class ConfigTransformer {
@Mixin(Config.class)
public abstract class MixinConfig {
@CRedirect(method = "loadConfig(Ljava/io/File;Ljava/net/URL;)Ljava/util/Map;", target = @CTarget(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z"))
@Redirect(method = "loadConfig(Ljava/io/File;Ljava/net/URL;)Ljava/util/Map;", at = @At(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z"))
private boolean allowConfigPatching(final Map<String, Object> map, final Object key) {
if (((Object) this) instanceof ConfigPatcher) {
return true;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
@ -24,15 +24,15 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_18_2to1_18.Protocol1_18_2To1_18;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CInject;
import net.raphimc.viaproxy.protocolhack.viaproxy.loading_terrain_fix.SpawnPositionTracker;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@CTransformer(Protocol1_18_2To1_18.class)
public abstract class Protocol1_18_2To1_18Transformer extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
@Mixin(Protocol1_18_2To1_18.class)
public abstract class MixinProtocol1_18_2To1_18 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
@CInject(method = "registerPackets", target = @CTarget("RETURN"))
@Inject(method = "registerPackets", at = @At("RETURN"))
private void fixDownloadingTerrainScreenNotClosing() {
this.registerClientbound(ClientboundPackets1_18.PLAYER_POSITION, new PacketHandlers() {
@Override

View File

@ -15,20 +15,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.connection.UserConnectionImpl;
import net.lenni0451.classtransform.InjectionCallback;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CInject;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@CTransformer(UserConnectionImpl.class)
public abstract class UserConnectionImplTransformer {
@Mixin(UserConnectionImpl.class)
public abstract class MixinUserConnectionImpl {
@CInject(method = "shouldApplyBlockProtocol", target = @CTarget("HEAD"), cancellable = true)
private void applyBlockProtocol(InjectionCallback ic) {
ic.setReturnValue(true);
@Inject(method = "shouldApplyBlockProtocol", at = @At("HEAD"), cancellable = true)
private void applyBlockProtocol(final CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
}
}

View File

@ -15,29 +15,29 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import net.lenni0451.classtransform.InjectionCallback;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CInject;
import net.raphimc.vialegacy.ViaLegacyConfig;
import net.raphimc.viaproxy.cli.options.Options;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@CTransformer(ViaLegacyConfig.class)
public abstract class ViaLegacyConfigTransformer {
@Mixin(ViaLegacyConfig.class)
public abstract class MixinViaLegacyConfig {
@CInject(method = "isLegacySkinLoading", target = @CTarget("HEAD"), cancellable = true)
private void makeGUIConfigurable1(final InjectionCallback ic) {
@Inject(method = "isLegacySkinLoading", at = @At("HEAD"), cancellable = true)
private void makeGUIConfigurable1(final CallbackInfoReturnable<Boolean> cir) {
if (Options.LEGACY_SKIN_LOADING != null) {
ic.setReturnValue(Options.LEGACY_SKIN_LOADING);
cir.setReturnValue(Options.LEGACY_SKIN_LOADING);
}
}
@CInject(method = "isLegacySkullLoading", target = @CTarget("HEAD"), cancellable = true)
private void makeGUIConfigurable2(final InjectionCallback ic) {
@Inject(method = "isLegacySkullLoading", at = @At("HEAD"), cancellable = true)
private void makeGUIConfigurable2(final CallbackInfoReturnable<Boolean> cir) {
if (Options.LEGACY_SKIN_LOADING != null) {
ic.setReturnValue(Options.LEGACY_SKIN_LOADING);
cir.setReturnValue(Options.LEGACY_SKIN_LOADING);
}
}

View File

@ -15,21 +15,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
package net.raphimc.viaproxy.injection.mixins;
import com.mojang.authlib.yggdrasil.ServicesKeyInfo;
import com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.COverride;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.netminecraft.netty.crypto.CryptUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import java.security.PublicKey;
@CTransformer(YggdrasilServicesKeyInfo.class)
public abstract class YggdrasilServicesKeyInfoTransformer {
@Mixin(YggdrasilServicesKeyInfo.class)
public abstract class MixinYggdrasilServicesKeyInfo {
@COverride
@Overwrite
public static ServicesKeyInfo createFromResources() {
try {
return RStream.of(YggdrasilServicesKeyInfo.class).constructors().by(PublicKey.class).newInstance(CryptUtil.MOJANG_PUBLIC_KEY);