Compare commits

..

No commits in common. "master" and "v1.2.8" have entirely different histories.

11 changed files with 103 additions and 107 deletions

View File

@ -1,38 +1,15 @@
import io.gitlab.jfronny.scripts.*
plugins { plugins {
id("jfmod") version "1.6-SNAPSHOT" id("jfmod") version "1.2-SNAPSHOT"
} id("io.gitlab.jfronny.libjf.libjf-config-compiler-plugin")
allprojects { group = "io.gitlab.jfronny" }
base.archivesName = "dynres"
jfMod {
minecraftVersion = "1.21"
yarn("build.1")
loaderVersion = "0.15.11"
libJfVersion = "3.16.0"
fabricApiVersion = "0.100.1+1.21"
modrinth {
projectId = "dynres"
requiredDependencies.add("libjf")
optionalDependencies.add("modmenu")
}
curseforge {
projectId = "407012"
requiredDependencies.add("libjf")
optionalDependencies.add("modmenu")
}
} }
dependencies { dependencies {
modImplementation("io.gitlab.jfronny.libjf:libjf-web-v1") modImplementation("io.gitlab.jfronny.libjf:libjf-web-v0:${prop("libjf_version")}")
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v2") modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${prop("libjf_version")}")
// Dev env // Dev env
modLocalRuntime("com.terraformersmc:modmenu:11.0.0-beta.1") modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-reflect-v1:${prop("libjf_version")}")
// for modmenu modLocalRuntime("com.terraformersmc:modmenu:5.0.0-alpha.4")
modLocalRuntime("net.fabricmc.fabric-api:fabric-resource-loader-v0")
modLocalRuntime("net.fabricmc.fabric-api:fabric-screen-api-v1")
modLocalRuntime("net.fabricmc.fabric-api:fabric-key-binding-api-v1")
} }

17
gradle.properties Normal file
View File

@ -0,0 +1,17 @@
# check these on https://fabricmc.net/develop/
minecraft_version=1.19.3
yarn_mappings=build.2
loader_version=0.14.11
maven_group=io.gitlab.jfronny
archives_base_name=dynres
modrinth_id=dynres
modrinth_required_dependencies=libjf
modrinth_optional_dependencies=modmenu
curseforge_id=407012
curseforge_required_dependencies=libjf
curseforge_optional_dependencies=modmenu
fabric_version=0.68.1+1.19.3
libjf_version=3.3.1

View File

@ -1,9 +1,13 @@
pluginManagement { pluginManagement {
val libjf_version: String by settings
repositories { repositories {
maven("https://maven.fabricmc.net/") // FabricMC maven("https://maven.fabricmc.net/") // FabricMC
maven("https://maven.frohnmeyer-wds.de/artifacts") // scripts maven("https://maven.frohnmeyer-wds.de/artifacts") // scripts
gradlePluginPortal() gradlePluginPortal()
} }
plugins {
id("io.gitlab.jfronny.libjf.libjf-config-compiler-plugin") version libjf_version
}
} }
rootProject.name = "dynres" rootProject.name = "dynres"

View File

@ -1,33 +0,0 @@
package io.gitlab.jfronny.dynres.mixin;
import io.gitlab.jfronny.dynres.DynRes;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.network.packet.c2s.common.ResourcePackStatusC2SPacket;
import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.URL;
@Mixin(ClientCommonNetworkHandler.class)
public abstract class ClientCommonNetworkHandlerMixin {
@Shadow @Nullable protected static URL getParsedResourcePackUrl(String url) {
throw new RuntimeException("Mixin not applied");
}
@Inject(at = @At("HEAD"), method = "onResourcePackSend(Lnet/minecraft/network/packet/s2c/common/ResourcePackSendS2CPacket;)V")
public void logResourcePackStatus(ResourcePackSendS2CPacket status, CallbackInfo info) {
DynRes.LOGGER.info("[RECEIVE] ResourcePackUrl={0}", status.url());
DynRes.LOGGER.info("[RECEIVE] ResourcePackHash={0}", status.hash());
}
@Redirect(method = "onResourcePackSend(Lnet/minecraft/network/packet/s2c/common/ResourcePackSendS2CPacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;getParsedResourcePackUrl(Ljava/lang/String;)Ljava/net/URL;"))
public URL logResourcePackStatus(String url) {
URL res = getParsedResourcePackUrl(url);
DynRes.LOGGER.info("[CHECK] ResourcePackUrlValid={0}", res != null);
return res;
}
}

View File

@ -0,0 +1,38 @@
package io.gitlab.jfronny.dynres.mixin;
import io.gitlab.jfronny.dynres.*;
import net.minecraft.client.network.*;
import net.minecraft.network.packet.c2s.play.*;
import net.minecraft.network.packet.s2c.play.*;
import org.jetbrains.annotations.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.*;
import java.net.*;
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Shadow @Nullable
private static URL resolveUrl(String url) {
throw new RuntimeException("Mixin not applied");
}
@Inject(at = @At("HEAD"), method = "sendResourcePackStatus(Lnet/minecraft/network/packet/c2s/play/ResourcePackStatusC2SPacket$Status;)V")
public void logSentResourcePackStatus(ResourcePackStatusC2SPacket.Status packStatus, CallbackInfo info) {
DynRes.LOGGER.info("[SEND] ResourcePackStatus=" + packStatus);
}
@Inject(at = @At("HEAD"), method = "onResourcePackSend(Lnet/minecraft/network/packet/s2c/play/ResourcePackSendS2CPacket;)V")
public void logResourcePackStatus(ResourcePackSendS2CPacket status, CallbackInfo info) {
DynRes.LOGGER.info("[RECEIVE] ResourcePackUrl=" + status.getURL());
DynRes.LOGGER.info("[RECEIVE] ResourcePackSha1=" + status.getSHA1());
}
@Redirect(method = "onResourcePackSend(Lnet/minecraft/network/packet/s2c/play/ResourcePackSendS2CPacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;resolveUrl(Ljava/lang/String;)Ljava/net/URL;"))
public URL logResourcePackStatus(String url) {
URL res = resolveUrl(url);
DynRes.LOGGER.info("[CHECK] ResourcePackUrlValid=" + (res != null));
return res;
}
}

View File

@ -11,6 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class ServerInfoMixin { public class ServerInfoMixin {
@Inject(at = @At("RETURN"), method = "getResourcePackPolicy()Lnet/minecraft/client/network/ServerInfo$ResourcePackPolicy;") @Inject(at = @At("RETURN"), method = "getResourcePackPolicy()Lnet/minecraft/client/network/ServerInfo$ResourcePackPolicy;")
public void getResPackState(CallbackInfoReturnable<ServerInfo.ResourcePackPolicy> info) { public void getResPackState(CallbackInfoReturnable<ServerInfo.ResourcePackPolicy> info) {
DynRes.LOGGER.info("[RECEIVE] ResourcePackStatus={0}", info.getReturnValue()); DynRes.LOGGER.info("[RECEIVE] ResourcePackStatus=" + info.getReturnValue());
} }
} }

View File

@ -4,7 +4,7 @@
"package": "io.gitlab.jfronny.dynres.mixin", "package": "io.gitlab.jfronny.dynres.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"client": [ "client": [
"ClientCommonNetworkHandlerMixin", "ClientPlayNetworkHandlerMixin",
"ServerInfoMixin" "ServerInfoMixin"
], ],
"injectors": { "injectors": {

View File

@ -1,14 +1,10 @@
package io.gitlab.jfronny.dynres; package io.gitlab.jfronny.dynres;
import io.gitlab.jfronny.libjf.config.api.v2.Entry; import io.gitlab.jfronny.libjf.config.api.v1.Entry;
import io.gitlab.jfronny.libjf.config.api.v2.JfConfig; import io.gitlab.jfronny.libjf.config.api.v1.JfConfig;
@JfConfig(referencedConfigs = "libjf-web-v0") @JfConfig
public class Cfg { public class Cfg {
@Entry public static String resourcesFile = "resources.zip"; @Entry public static String resourcesFile = "resources.zip";
@Entry public static boolean hashResources = false; @Entry public static boolean hashResources = false;
static {
JFC_Cfg.ensureInitialized();
}
} }

View File

@ -1,16 +1,18 @@
package io.gitlab.jfronny.dynres; package io.gitlab.jfronny.dynres;
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus; import io.gitlab.jfronny.libjf.web.api.WebInit;
import io.gitlab.jfronny.libjf.web.api.v1.*; import io.gitlab.jfronny.libjf.web.api.WebServer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
public class DynRes implements WebEntrypoint { public class DynRes implements WebInit {
public static final SystemLoggerPlus LOGGER = SystemLoggerPlus.forName("DynRes"); public static final Logger LOGGER = LoggerFactory.getLogger("DynRes");
public static Path packFile; public static Path packFile;
public static String packUrl = ""; public static String packUrl = "";
@ -28,10 +30,10 @@ public class DynRes implements WebEntrypoint {
public void register(WebServer api) { public void register(WebServer api) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && packFile != null) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER && packFile != null) {
try { try {
packUrl = api.registerFile(PathSegment.of("resources.zip"), packFile, !Cfg.hashResources); packUrl = api.registerFile("/resources.zip", packFile, !Cfg.hashResources);
LOGGER.info("Initialized DynRes at {0}", packUrl); LOGGER.info("Initialized DynRes at " + packUrl);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Could not register DynRes resource pack", e); e.printStackTrace();
} }
} }
} }

View File

@ -1,26 +1,20 @@
package io.gitlab.jfronny.dynres.mixin; package io.gitlab.jfronny.dynres.mixin;
import io.gitlab.jfronny.dynres.Cfg; import io.gitlab.jfronny.dynres.*;
import io.gitlab.jfronny.dynres.DynRes; import io.gitlab.jfronny.libjf.web.api.*;
import io.gitlab.jfronny.libjf.web.api.v1.WebServer; import io.gitlab.jfronny.libjf.web.impl.util.*;
import io.gitlab.jfronny.libjf.web.impl.util.WebPaths; import net.minecraft.server.*;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.*;
import net.minecraft.server.dedicated.ServerPropertiesHandler; import net.minecraft.text.*;
import net.minecraft.text.Text; import org.jetbrains.annotations.*;
import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.callback.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.file.*;
import java.nio.file.Files; import java.security.*;
import java.security.MessageDigest; import java.util.*;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import java.util.UUID;
@Mixin(ServerPropertiesHandler.class) @Mixin(ServerPropertiesHandler.class)
public abstract class ServerPropertiesHandlerMixin { public abstract class ServerPropertiesHandlerMixin {
@ -29,8 +23,8 @@ public abstract class ServerPropertiesHandlerMixin {
throw new IllegalStateException("Mixin not applied"); throw new IllegalStateException("Mixin not applied");
} }
@Inject(method = "getServerResourcePackProperties(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/lang/String;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true) @Inject(method = "getServerResourcePackProperties(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/lang/String;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true)
private static void getServerResourcePackProperties(String id, String url, String sha1, String hash, boolean required, String prompt, CallbackInfoReturnable<Optional<MinecraftServer.ServerResourcePackProperties>> cir) { private static void getServerResourcePackProperties(String url, String sha1, @Nullable String hash, boolean required, String prompt, CallbackInfoReturnable<Optional<MinecraftServer.ServerResourcePackProperties>> cir) {
if (DynRes.packFile != null) { if (DynRes.packFile != null) {
sha1 = ""; sha1 = "";
if (Cfg.hashResources) { if (Cfg.hashResources) {
@ -40,15 +34,13 @@ public abstract class ServerPropertiesHandlerMixin {
result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
} }
sha1 = result.toString(); sha1 = result.toString();
DynRes.LOGGER.info("Set hash to {0}", sha1); DynRes.LOGGER.info("Set hash to " + sha1);
} catch (IOException | NoSuchAlgorithmException e) { } catch (IOException | NoSuchAlgorithmException e) {
DynRes.LOGGER.error("Failed to get hash, continuing with empty", e); DynRes.LOGGER.error("Failed to get hash, continuing with empty", e);
} }
} }
url = WebPaths.concat(WebServer.getInstance().getServerRoot(), "resources.zip");
cir.setReturnValue(Optional.of(new MinecraftServer.ServerResourcePackProperties( cir.setReturnValue(Optional.of(new MinecraftServer.ServerResourcePackProperties(
UUID.nameUUIDFromBytes(url.getBytes(StandardCharsets.UTF_8)), WebPaths.concat(WebServer.getInstance().getServerRoot(), "resources.zip"),
url,
sha1, sha1,
required, required,
parseResourcePackPrompt(prompt) parseResourcePackPrompt(prompt)

View File

@ -17,7 +17,7 @@
"entrypoints": { "entrypoints": {
"libjf:web": ["io.gitlab.jfronny.dynres.DynRes"], "libjf:web": ["io.gitlab.jfronny.dynres.DynRes"],
"client": ["io.gitlab.jfronny.dynres.DebugClient"], "client": ["io.gitlab.jfronny.dynres.DebugClient"],
"libjf:config": ["io.gitlab.jfronny.dynres.JFC_Cfg"] "libjf:config": ["io.gitlab.jfronny.dynres.Cfg"]
}, },
"mixins": [ "mixins": [
"dynres.mixins.json", "dynres.mixins.json",
@ -34,6 +34,9 @@
"custom": { "custom": {
"libjf": { "libjf": {
"web": true "web": true
},
"libjf:config": {
"referencedConfigs": ["libjf-web-v0"]
} }
} }
} }