Skip to content

Commit

Permalink
Merge pull request #4 from tumuidle/dev/1.21.1
Browse files Browse the repository at this point in the history
1.21.1
  • Loading branch information
DvArcNode authored Aug 11, 2024
2 parents dcc8fdd + de8cf2d commit e93364a
Show file tree
Hide file tree
Showing 29 changed files with 384 additions and 213 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<h1>ResourceHack</h1>
Minecraft server resource pack protection tool

![Minecraft Version](https://img.shields.io/badge/Minecraft_Version-1.20.1-green?style=for-the-badge)
![Minecraft Version](https://img.shields.io/badge/Minecraft_Version-1.21.1-green?style=for-the-badge)

<img alt="paper" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/paper_vector.svg">
<img alt="fabric" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/fabric_vector.svg">
<img alt="forge" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/forge_vector.svg">
<img alt="forge" height="40" src="https://cdn.jsdelivr.net/gh/TheReal-Flo/devins-badges@neoforge/assets/compact/supported/neoforge_vector.svg">
</div>

<!-- Part: Features -->
Expand All @@ -28,3 +28,11 @@ Install the mod, no more configurations needed
3. Restart server or reload the plugin
4. Use `res-encrypt <path>` (Requires `reshack.encrypt` permission) command to encrypt your resource pack
5. Configure your server resource pack loading (ItemsAdder, Nova, JResourcePack, server.properties, etc.)

<div align="center"><h2>Building</h2></div>

**Fabric**: `gradlew :mod:fabric:build`

**NeoForge**: `gradlew :mod:neoforge:build`

**Server**: `gradlew :server:shadowJar`
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

public class Networking {
public static final String NAMESPACE = "reshack";
public static final String CHANNEL_CONFIG = "configure";
public static final String CHANNEL_CONFIG = "conf/send";
public static final String CHANNEL_CONFIG_REQUEST = "conf/request";
public static final String CHANNEL_RESET = "reset";

public static ConfigData read(ByteBuf data) {
Expand All @@ -20,11 +21,13 @@ public static ConfigData read(ByteBuf data) {

public static ByteBuf write(ConfigData data) {
ByteBuf bb = Unpooled.buffer();
write(data, bb);
return bb;
}

public static void write(ConfigData data, ByteBuf bb) {
byte[] keyBytes = data.getKey().getBytes(StandardCharsets.UTF_8);
bb.writeIntLE(keyBytes.length);
bb.writeBytes(keyBytes);

return bb;
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Sat Jul 27 21:16:38 HKT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Expand Down
8 changes: 4 additions & 4 deletions mod/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'dev.architectury.loom' version '1.6-SNAPSHOT' apply false
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
alias libs.plugins.shadow apply false
}
Expand Down Expand Up @@ -41,11 +41,11 @@ subprojects {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package arcnode.reshack.mod;

import arcnode.reshack.common.ConfigData;
import arcnode.reshack.common.Networking;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import org.jetbrains.annotations.NotNull;

public record ConfigurationPayload(ConfigData config) implements CustomPacketPayload {
public static final Type<ConfigurationPayload> TYPE = new Type<>(ResourceHack.getChannelConfig());
public static final StreamCodec<FriendlyByteBuf, ConfigurationPayload> CODEC = CustomPacketPayload.codec(ConfigurationPayload::write, ConfigurationPayload::read);

private static ConfigurationPayload read(FriendlyByteBuf fbb) {
var result = new ConfigurationPayload(Networking.read(fbb));
fbb.readBytes(fbb.readableBytes());
return result;
}

@Override
public @NotNull Type<? extends CustomPacketPayload> type() {
return TYPE;
}

private void write(FriendlyByteBuf fbb) {
ResourceHack.LOG.info("ENCODE");
Networking.write(this.config, fbb);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package arcnode.reshack.mod;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import org.jetbrains.annotations.NotNull;

public record ConfigurationRequestPayload() implements CustomPacketPayload {
public static final Type<ConfigurationRequestPayload> TYPE = new Type<>(ResourceHack.getChannelConfigRequest());
public static final StreamCodec<FriendlyByteBuf, ConfigurationRequestPayload> CODEC = CustomPacketPayload.codec(ConfigurationRequestPayload::write, ConfigurationRequestPayload::read);


@Override
public @NotNull Type<? extends CustomPacketPayload> type() {
return TYPE;
}
private static ConfigurationRequestPayload read(FriendlyByteBuf fbb) {
return new ConfigurationRequestPayload();
}

private void write(FriendlyByteBuf fbb) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package arcnode.reshack.mod;

public interface IResourceHackPlatform {
void sendConfigRequest();
}
41 changes: 24 additions & 17 deletions mod/common/src/main/java/arcnode/reshack/mod/ResourceHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,64 @@

import arcnode.reshack.common.ConfigData;
import arcnode.reshack.common.Networking;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.*;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.util.*;

public final class ResourceHack {
public static final String MOD_ID = "resourcehack";
public static final Logger LOG = LoggerFactory.getLogger("ResourceHack");


@Getter
private static final ResourceLocation channelConfig = new ResourceLocation("reshack", Networking.CHANNEL_CONFIG);
private static final ResourceLocation channelConfig = ResourceLocation.fromNamespaceAndPath(Networking.NAMESPACE, Networking.CHANNEL_CONFIG);
@Getter
private static final ResourceLocation channelReset = new ResourceLocation("reshack", Networking.CHANNEL_RESET);

private static final ResourceLocation channelConfigRequest = ResourceLocation.fromNamespaceAndPath(Networking.NAMESPACE, Networking.CHANNEL_CONFIG_REQUEST);
@Getter
private static final ResourceLocation channelReset = ResourceLocation.fromNamespaceAndPath(Networking.NAMESPACE, Networking.CHANNEL_RESET);

@Setter
private static ConfigData config = null;
@Getter
private static IResourceHackPlatform platform;

@Getter
private static final Map<String, File> decryptedPackCache = new HashMap<>();
@Getter
private static List<String> loadedUrls = new ArrayList<>();
@Getter
private static Map<UUID, String> packUrls = new HashMap<>();

public static void init() {
public static void init(IResourceHackPlatform platform) {
LOG.info("ResourceHack powered by ArcNode");
ResourceHack.platform = platform;
}

public static void sendRequest() {
LOG.info("Sending configuration request");
Minecraft.getInstance().getConnection().send(new ServerboundCustomPayloadPacket(
channelConfig,
new FriendlyByteBuf(Unpooled.buffer())
));

platform.sendConfigRequest();
}

public static boolean configure(ClientboundCustomPayloadPacket packet) {
public static void configure(ConfigData config) {
/*
if (packet.getIdentifier().equals(ResourceHack.getChannelConfig())) {
setConfig(Networking.read(packet.getData()));
return true;
} else if (packet.getIdentifier().equals(ResourceHack.getChannelReset())) {
ResourceHack.getLoadedUrls().clear();
return true;
}
return false;
*/
if (config.getKey().length() != 16)
throw new IllegalArgumentException("(ResHack) Invalid key length " + config.getKey().length());
ResourceHack.config = config;
}

public static String getKey() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package arcnode.reshack.mod.mixin;

import arcnode.reshack.mod.ResourceHack;
import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
import net.minecraft.network.protocol.common.ServerboundResourcePackPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientCommonPacketListenerImpl.class)
public abstract class MixinClientCommonPacketListenerImpl {
@Shadow public abstract void send(Packet<?> packet);

@Redirect(
method = "handleResourcePackPush",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ServerData;getResourcePackStatus()Lnet/minecraft/client/multiplayer/ServerData$ServerPackStatus;")
)
// Forced enable server resource pack
public ServerData.ServerPackStatus redirectGetServerPackStatus(ServerData instance) {
return ServerData.ServerPackStatus.ENABLED;
}

@Inject(
method = "handleResourcePackPush",
at = @At("HEAD"),
cancellable = true)
// Prevent resource reloading between servers when connecting through a proxy
public void injectHandleResourcePack(ClientboundResourcePackPushPacket packet, CallbackInfo ci) {
// TODO: Fix, not working in 1.21.1
// if (ResourceHack.getLoadedUrls().contains(packet.url())) {
// ResourceHack.LOG.info("Skipping loaded pack {}", packet.id());
// ci.cancel();
//
// // Notify server
// this.send(new ServerboundResourcePackPacket(packet.id(), ServerboundResourcePackPacket.Action.ACCEPTED));
// this.send(new ServerboundResourcePackPacket(packet.id(), ServerboundResourcePackPacket.Action.SUCCESSFULLY_LOADED));
// System.out.println(ResourceHack.getLoadedUrls());
// } else ResourceHack.getPackUrls().put(packet.id(), packet.url());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package arcnode.reshack.mod.mixin;

import arcnode.reshack.mod.ResourceHack;
import net.minecraft.client.resources.server.PackLoadFeedback;
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.CallbackInfo;

import java.util.UUID;

@Mixin(targets = "net.minecraft.client.resources.server.DownloadedPackSource$6")
public class MixinDownloadPackSource {
@Inject(
method = "reportFinalResult",
at = @At(value = "FIELD", target = "Lnet/minecraft/network/protocol/common/ServerboundResourcePackPacket$Action;SUCCESSFULLY_LOADED:Lnet/minecraft/network/protocol/common/ServerboundResourcePackPacket$Action;")
)
public void injectReportFinalResult(UUID uUID, PackLoadFeedback.FinalResult finalResult, CallbackInfo ci) {
String url = ResourceHack.getPackUrls().get(uUID);
if (url == null) {
ResourceHack.LOG.warn("Resource {} has no recorded URL", uUID);
return;
}
ResourceHack.getLoadedUrls().add(ResourceHack.getPackUrls().get(uUID));
ResourceHack.LOG.info("Added loaded resource pack {}", uUID);
}
}
Loading

0 comments on commit e93364a

Please sign in to comment.