mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-03 18:38:24 +01:00
Refactored transformers to mixins annotations
This commit is contained in:
parent
1aa0740a67
commit
4360abab2f
@ -81,7 +81,6 @@ public class ViaProxy {
|
|||||||
final IClassProvider classProvider = new GuavaClassPathProvider();
|
final IClassProvider classProvider = new GuavaClassPathProvider();
|
||||||
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
||||||
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
||||||
if (instrumentation != null) {
|
if (instrumentation != null) {
|
||||||
transformerManager.hookInstrumentation(instrumentation);
|
transformerManager.hookInstrumentation(instrumentation);
|
||||||
|
@ -15,17 +15,18 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 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)
|
@Mixin(C2SHandshakePacket.class)
|
||||||
public abstract class C2SHandshakePacketTransformer {
|
public abstract class MixinC2SHandshakePacket {
|
||||||
|
|
||||||
@CModifyConstant(method = "read", intValue = 255)
|
@ModifyConstant(method = "read", constant = @Constant(intValue = 255))
|
||||||
private int allowLargerHostnames() {
|
private int allowLargerHostnames(int constant) {
|
||||||
return Short.MAX_VALUE;
|
return Short.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
@ -15,20 +15,20 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 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 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;
|
import java.util.Map;
|
||||||
|
|
||||||
@CTransformer(Config.class)
|
@Mixin(Config.class)
|
||||||
public abstract class ConfigTransformer {
|
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) {
|
private boolean allowConfigPatching(final Map<String, Object> map, final Object key) {
|
||||||
if (((Object) this) instanceof ConfigPatcher) {
|
if (((Object) this) instanceof ConfigPatcher) {
|
||||||
return true;
|
return true;
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
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_17to1_16_4.ServerboundPackets1_17;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_18_2to1_18.Protocol1_18_2To1_18;
|
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 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 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)
|
@Mixin(Protocol1_18_2To1_18.class)
|
||||||
public abstract class Protocol1_18_2To1_18Transformer extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
|
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() {
|
private void fixDownloadingTerrainScreenNotClosing() {
|
||||||
this.registerClientbound(ClientboundPackets1_18.PLAYER_POSITION, new PacketHandlers() {
|
this.registerClientbound(ClientboundPackets1_18.PLAYER_POSITION, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
@ -15,20 +15,20 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||||
import net.lenni0451.classtransform.InjectionCallback;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import net.lenni0451.classtransform.annotations.CTarget;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import net.lenni0451.classtransform.annotations.CTransformer;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import net.lenni0451.classtransform.annotations.injection.CInject;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@CTransformer(UserConnectionImpl.class)
|
@Mixin(UserConnectionImpl.class)
|
||||||
public abstract class UserConnectionImplTransformer {
|
public abstract class MixinUserConnectionImpl {
|
||||||
|
|
||||||
@CInject(method = "shouldApplyBlockProtocol", target = @CTarget("HEAD"), cancellable = true)
|
@Inject(method = "shouldApplyBlockProtocol", at = @At("HEAD"), cancellable = true)
|
||||||
private void applyBlockProtocol(InjectionCallback ic) {
|
private void applyBlockProtocol(final CallbackInfoReturnable<Boolean> cir) {
|
||||||
ic.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,29 +15,29 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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.vialegacy.ViaLegacyConfig;
|
||||||
import net.raphimc.viaproxy.cli.options.Options;
|
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)
|
@Mixin(ViaLegacyConfig.class)
|
||||||
public abstract class ViaLegacyConfigTransformer {
|
public abstract class MixinViaLegacyConfig {
|
||||||
|
|
||||||
@CInject(method = "isLegacySkinLoading", target = @CTarget("HEAD"), cancellable = true)
|
@Inject(method = "isLegacySkinLoading", at = @At("HEAD"), cancellable = true)
|
||||||
private void makeGUIConfigurable1(final InjectionCallback ic) {
|
private void makeGUIConfigurable1(final CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (Options.LEGACY_SKIN_LOADING != null) {
|
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)
|
@Inject(method = "isLegacySkullLoading", at = @At("HEAD"), cancellable = true)
|
||||||
private void makeGUIConfigurable2(final InjectionCallback ic) {
|
private void makeGUIConfigurable2(final CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (Options.LEGACY_SKIN_LOADING != null) {
|
if (Options.LEGACY_SKIN_LOADING != null) {
|
||||||
ic.setReturnValue(Options.LEGACY_SKIN_LOADING);
|
cir.setReturnValue(Options.LEGACY_SKIN_LOADING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,21 +15,21 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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.ServicesKeyInfo;
|
||||||
import com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo;
|
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.lenni0451.reflect.stream.RStream;
|
||||||
import net.raphimc.netminecraft.netty.crypto.CryptUtil;
|
import net.raphimc.netminecraft.netty.crypto.CryptUtil;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
|
||||||
@CTransformer(YggdrasilServicesKeyInfo.class)
|
@Mixin(YggdrasilServicesKeyInfo.class)
|
||||||
public abstract class YggdrasilServicesKeyInfoTransformer {
|
public abstract class MixinYggdrasilServicesKeyInfo {
|
||||||
|
|
||||||
@COverride
|
@Overwrite
|
||||||
public static ServicesKeyInfo createFromResources() {
|
public static ServicesKeyInfo createFromResources() {
|
||||||
try {
|
try {
|
||||||
return RStream.of(YggdrasilServicesKeyInfo.class).constructors().by(PublicKey.class).newInstance(CryptUtil.MOJANG_PUBLIC_KEY);
|
return RStream.of(YggdrasilServicesKeyInfo.class).constructors().by(PublicKey.class).newInstance(CryptUtil.MOJANG_PUBLIC_KEY);
|
Loading…
Reference in New Issue
Block a user