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

Add the clisten command #598

Merged
merged 17 commits into from
Mar 7, 2024
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ dependencies {
modRuntimeOnly('me.djtheredstoner:DevAuth-fabric:1.1.0') {
exclude group: 'net.fabricmc', module: 'fabric-loader'
}

include api('net.fabricmc:mapping-io:0.5.1')
xpple marked this conversation as resolved.
Show resolved Hide resolved
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.xpple.betterconfig.api.ModConfigBuilder;
import io.netty.buffer.Unpooled;
import net.earthcomputer.clientcommands.command.*;
import net.earthcomputer.clientcommands.features.MappingsHelper;
import net.earthcomputer.clientcommands.render.RenderQueue;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
Expand Down Expand Up @@ -85,6 +86,8 @@ public void onInitializeClient() {
new ModConfigBuilder("clientcommands", Configs.class).build();

ItemGroupCommand.registerItemGroups();

MappingsHelper.load();
}

private static Set<String> getCommands(CommandDispatcher<?> dispatcher) {
Expand Down Expand Up @@ -161,6 +164,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
WeatherCommand.register(dispatcher);
PluginsCommand.register(dispatcher);
CGameModeCommand.register(dispatcher);
ListenCommand.register(dispatcher);

Calendar calendar = Calendar.getInstance();
boolean registerChatCommand = calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,15 @@ public static void setMaxChorusItemThrows(int maxChorusItemThrows) {
public static boolean conditionLessThan1_20() {
return MultiVersionCompat.INSTANCE.getProtocolVersion() < MultiVersionCompat.V1_20;
}

@Config
public static PacketDumpMethod packetDumpMethod = PacketDumpMethod.REFLECTION;

public enum PacketDumpMethod {
REFLECTION,
BYTE_BUF,
}

@Config
public static int maximumPacketFieldDepth = 10;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.earthcomputer.clientcommands;

import java.lang.reflect.Field;
import java.util.stream.Stream;

public final class ReflectionUtils {

private ReflectionUtils() {
}

public static Stream<Field> getAllFields(Class<?> clazz) {
Stream.Builder<Field> builder = Stream.builder();
Class<?> targetClass = clazz;
while (targetClass.getSuperclass() != null) {
Field[] fields = targetClass.getDeclaredFields();
for (Field field : fields) {
builder.add(field);
}
targetClass = targetClass.getSuperclass();
}
return builder.build();
}
}
54 changes: 54 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/UnsafeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.earthcomputer.clientcommands;

import com.mojang.logging.LogUtils;
import net.minecraft.Util;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import sun.misc.Unsafe;

import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;

/**
* @author Gaming32
*/
public final class UnsafeUtils {

private UnsafeUtils() {
}

private static final Logger LOGGER = LogUtils.getLogger();

private static final @Nullable Unsafe UNSAFE = Util.make(() -> {
try {
final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
return (Unsafe) unsafeField.get(null);
} catch (Exception e) {
LOGGER.error("Could not access theUnsafe", e);
return null;
}
});

private static final @Nullable MethodHandles.Lookup IMPL_LOOKUP = Util.make(() -> {
try {
//noinspection ConstantValue
if (UNSAFE == null) {
return null;
}
final Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
return (MethodHandles.Lookup) UNSAFE.getObject(UNSAFE.staticFieldBase(implLookupField), UNSAFE.staticFieldOffset(implLookupField));
} catch (Exception e) {
LOGGER.error("Could not access IMPL_LOOKUP", e);
return null;
}
});

public static @Nullable Unsafe getUnsafe() {
return UNSAFE;
}

public static @Nullable MethodHandles.Lookup getImplLookup() {
return IMPL_LOOKUP;
}
}
Loading
Loading