├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src └── main ├── java └── lumien │ └── resourceloader │ ├── ResourceLoader.java │ ├── asm │ ├── ClassTransformer.java │ ├── LoadingPlugin.java │ └── MCPNames.java │ └── loader │ ├── NormalResourceLoader.java │ └── OverridingResourceLoader.java └── resources ├── META-INF └── ResourceLoader_At.cfg └── mcmod.info /.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/.gitignore 3 | !/gradle/ 4 | !/gradle/* 5 | !/gradle* 6 | !/src/ 7 | !/src/* 8 | !/*.gradle 9 | !/*.md 10 | .gradle 11 | Thumbs.db 12 | Update.bat 13 | *.psd 14 | /libs/* 15 | /libs/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Resource-Loader 2 | Minecraft mod that makes adding new resources to the game easier for pack makers 3 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // For those who want the bleeding edge 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | maven { 6 | name = "forge" 7 | url = "http://files.minecraftforge.net/maven" 8 | } 9 | } 10 | dependencies { 11 | classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' 12 | } 13 | } 14 | apply plugin: 'net.minecraftforge.gradle.forge' 15 | 16 | jar { 17 | manifest { 18 | attributes("FMLCorePluginContainsFMLMod": "true", "FMLCorePlugin": "lumien.resourceloader.asm.LoadingPlugin") 19 | } 20 | } 21 | 22 | version = "1.5.3" 23 | group= "lumien.resourceloader" // http://maven.apache.org/guides/mini/guide-naming-conventions.html 24 | 25 | sourceCompatibility = targetCompatibility = "1.6" // Need this here so eclipse task generates correctly. 26 | compileJava { 27 | sourceCompatibility = targetCompatibility = "1.6" 28 | } 29 | 30 | minecraft { 31 | version = "1.12.1-14.22.0.2469" 32 | runDir = "eclipse" 33 | 34 | replaceIn "ResourceLoader.java" 35 | replace "@VERSION@",project.version 36 | replace "@FINGERPRINT@", project.signSHA1 37 | 38 | // the mappings can be changed at any time, and must be in the following format. 39 | // snapshot_YYYYMMDD snapshot are built nightly. 40 | // stable_# stables are built at the discretion of the MCP team. 41 | // Use non-default mappings at your own risk. they may not allways work. 42 | // simply re-run your setup task after changing the mappings to update your workspace. 43 | mappings = "snapshot_20161220" 44 | } 45 | 46 | archivesBaseName = "ResourceLoader-MC" + minecraft.version 47 | 48 | jar { 49 | manifest { 50 | attributes("FMLAT": "ResourceLoader_At.cfg") 51 | } 52 | } 53 | 54 | task deobfJar(type: Jar) { 55 | from sourceSets.main.output 56 | classifier = 'deobf' 57 | } 58 | 59 | 60 | dependencies { 61 | // you may put jars on which you depend on in ./libs 62 | // or you may define them like so.. 63 | //compile "some.group:artifact:version:classifier" 64 | //compile "some.group:artifact:version" 65 | 66 | // real examples 67 | //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env 68 | //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env 69 | 70 | // for more info... 71 | // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html 72 | // http://www.gradle.org/docs/current/userguide/dependency_management.html 73 | 74 | } 75 | 76 | processResources 77 | { 78 | // this will ensure that this task is redone when the versions change. 79 | inputs.property "version", project.version 80 | inputs.property "mcversion", project.minecraft.version 81 | 82 | // replace stuff in mcmod.info, nothing else 83 | from(sourceSets.main.resources.srcDirs) { 84 | include 'mcmod.info' 85 | 86 | // replace version and mcversion 87 | expand 'version':project.version, 'mcversion':project.minecraft.version 88 | } 89 | 90 | // copy everything else, thats not the mcmod.info 91 | from(sourceSets.main.resources.srcDirs) { 92 | exclude 'mcmod.info' 93 | } 94 | } 95 | 96 | task signJar(type: SignJar, dependsOn: reobfJar) { 97 | 98 | // Skips if the keyStore property is missing. 99 | onlyIf { 100 | project.hasProperty('keyStore') 101 | } 102 | 103 | keyStore = project.keyStore 104 | alias = project.keyStoreAlias 105 | storePass = project.keyStorePass 106 | keyPass = project.keyStoreKeyPass 107 | inputFile = jar.archivePath 108 | outputFile = jar.archivePath 109 | } 110 | 111 | // Runs this task automatically when build is ran. 112 | build.dependsOn signJar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lumien231/Resource-Loader/e82500eb51051ce94937d5c200319f89ba7c50af/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 16 19:56:41 CDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/ResourceLoader.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader; 2 | 3 | import java.io.File; 4 | import java.lang.reflect.Constructor; 5 | import java.lang.reflect.Field; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | 12 | import lumien.resourceloader.loader.NormalResourceLoader; 13 | import lumien.resourceloader.loader.OverridingResourceLoader; 14 | import net.minecraft.client.Minecraft; 15 | import net.minecraft.client.audio.PositionedSoundRecord; 16 | import net.minecraft.client.audio.SoundEventAccessor; 17 | import net.minecraft.client.audio.SoundHandler; 18 | import net.minecraft.client.audio.SoundRegistry; 19 | import net.minecraft.util.ResourceLocation; 20 | import net.minecraft.util.SoundCategory; 21 | import net.minecraftforge.client.event.GuiOpenEvent; 22 | import net.minecraftforge.common.MinecraftForge; 23 | import net.minecraftforge.fml.common.Mod; 24 | import net.minecraftforge.fml.common.Mod.EventHandler; 25 | import net.minecraftforge.fml.common.Mod.Instance; 26 | import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; 27 | import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; 28 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 29 | 30 | @Mod(modid = ResourceLoader.MOD_ID, name = ResourceLoader.MOD_NAME, version = ResourceLoader.MOD_VERSION, clientSideOnly = true, acceptedMinecraftVersions = "[1.12,1.13)", certificateFingerprint = "@FINGERPRINT@") 31 | public class ResourceLoader 32 | { 33 | public static final String MOD_ID = "resourceloader"; 34 | public static final String MOD_NAME = "Resource Loader"; 35 | public static final String MOD_VERSION = "@VERSION@"; 36 | 37 | @Instance(MOD_ID) 38 | public static ResourceLoader INSTANCE; 39 | 40 | public static Logger logger = LogManager.getLogger("ResourceLoader"); 41 | 42 | static NormalResourceLoader normalResourceLoader; 43 | static OverridingResourceLoader overridingResourceLoader; 44 | 45 | @EventHandler 46 | public void preInit(FMLPreInitializationEvent event) 47 | { 48 | 49 | } 50 | 51 | public static void insertNormalPack(List resourceList) 52 | { 53 | if (normalResourceLoader == null) 54 | { 55 | normalResourceLoader = new NormalResourceLoader(); 56 | } 57 | 58 | resourceList.add(normalResourceLoader); 59 | } 60 | 61 | public static void insertForcedPack(List resourcePackList) 62 | { 63 | if (overridingResourceLoader == null) 64 | { 65 | overridingResourceLoader = new OverridingResourceLoader(); 66 | } 67 | 68 | resourcePackList.add(overridingResourceLoader); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/asm/ClassTransformer.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader.asm; 2 | 3 | import static org.objectweb.asm.Opcodes.DUP; 4 | import static org.objectweb.asm.Opcodes.GETSTATIC; 5 | import static org.objectweb.asm.Opcodes.ILOAD; 6 | import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; 7 | import static org.objectweb.asm.Opcodes.ISTORE; 8 | import static org.objectweb.asm.Opcodes.SWAP; 9 | import net.minecraft.launchwrapper.IClassTransformer; 10 | 11 | import org.apache.logging.log4j.Level; 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | import org.objectweb.asm.ClassReader; 15 | import org.objectweb.asm.ClassWriter; 16 | import org.objectweb.asm.Opcodes; 17 | import org.objectweb.asm.tree.AbstractInsnNode; 18 | import org.objectweb.asm.tree.ClassNode; 19 | import org.objectweb.asm.tree.FieldInsnNode; 20 | import org.objectweb.asm.tree.InsnList; 21 | import org.objectweb.asm.tree.InsnNode; 22 | import org.objectweb.asm.tree.MethodInsnNode; 23 | import org.objectweb.asm.tree.MethodNode; 24 | import org.objectweb.asm.tree.VarInsnNode; 25 | 26 | public class ClassTransformer implements IClassTransformer 27 | { 28 | Logger logger = LogManager.getLogger("ResourceLoader"); 29 | 30 | public ClassTransformer() 31 | { 32 | 33 | } 34 | 35 | @Override 36 | public byte[] transform(String name, String transformedName, byte[] basicClass) 37 | { 38 | if (transformedName.equals("net.minecraft.client.Minecraft")) 39 | { 40 | return patchMinecraft(basicClass); 41 | } 42 | return basicClass; 43 | } 44 | 45 | private byte[] patchMinecraft(byte[] basicClass) 46 | { 47 | ClassNode classNode = new ClassNode(); 48 | ClassReader classReader = new ClassReader(basicClass); 49 | classReader.accept(classNode, 0); 50 | logger.log(Level.DEBUG, "Found Minecraft Class: " + classNode.name); 51 | 52 | MethodNode refreshResources = null; 53 | MethodNode startGame = null; 54 | 55 | for (MethodNode mn : classNode.methods) 56 | { 57 | if (mn.name.equals(MCPNames.method("func_110436_a"))) 58 | { 59 | refreshResources = mn; 60 | } 61 | else if (mn.name.equals(MCPNames.method("func_71384_a"))) 62 | { 63 | startGame = mn; 64 | } 65 | } 66 | 67 | if (refreshResources != null) 68 | { 69 | logger.log(Level.DEBUG, " - Found refreshResources 1/3"); 70 | 71 | for (int i = 0; i < refreshResources.instructions.size(); i++) 72 | { 73 | AbstractInsnNode ain = refreshResources.instructions.get(i); 74 | if (ain instanceof MethodInsnNode) 75 | { 76 | MethodInsnNode min = (MethodInsnNode) ain; 77 | if (min.name.equals(MCPNames.method("func_110541_a"))) 78 | { 79 | InsnList toInsert = new InsnList(); 80 | toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "lumien/resourceloader/ResourceLoader", "insertForcedPack", "(Ljava/util/List;)V", false)); 81 | toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1)); 82 | 83 | refreshResources.instructions.insertBefore(min, toInsert); 84 | logger.log(Level.DEBUG, " - Patched refreshResources 3/3"); 85 | 86 | i+=2; 87 | } 88 | else if (min.name.equals("newArrayList")) 89 | { 90 | AbstractInsnNode target = refreshResources.instructions.get(i + 1); 91 | 92 | InsnList toInsert = new InsnList(); 93 | toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1)); 94 | toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "lumien/resourceloader/ResourceLoader", "insertNormalPack", "(Ljava/util/List;)V", false)); 95 | 96 | refreshResources.instructions.insert(target, toInsert); 97 | logger.log(Level.DEBUG, " - Patched Patched refreshResources 2/3"); 98 | } 99 | } 100 | } 101 | } 102 | 103 | ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); 104 | classNode.accept(writer); 105 | 106 | return writer.toByteArray(); 107 | } 108 | 109 | private byte[] patchDummyClass(byte[] basicClass) 110 | { 111 | ClassNode classNode = new ClassNode(); 112 | ClassReader classReader = new ClassReader(basicClass); 113 | classReader.accept(classNode, 0); 114 | logger.log(Level.INFO, "Found Dummy Class: " + classNode.name); 115 | 116 | ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); 117 | classNode.accept(writer); 118 | 119 | return writer.toByteArray(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/asm/LoadingPlugin.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader.asm; 2 | 3 | import java.util.Map; 4 | 5 | import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; 6 | 7 | @IFMLLoadingPlugin.SortingIndex(1001) 8 | public class LoadingPlugin implements IFMLLoadingPlugin 9 | { 10 | public static boolean IN_MCP = false; 11 | 12 | @Override 13 | public String[] getASMTransformerClass() 14 | { 15 | return new String[] { ClassTransformer.class.getName() }; 16 | } 17 | 18 | @Override 19 | public String getModContainerClass() 20 | { 21 | return null; 22 | } 23 | 24 | @Override 25 | public String getSetupClass() 26 | { 27 | return null; 28 | } 29 | 30 | @Override 31 | public void injectData(Map data) 32 | { 33 | IN_MCP = !(Boolean) data.get("runtimeDeobfuscationEnabled"); 34 | } 35 | 36 | @Override 37 | public String getAccessTransformerClass() 38 | { 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/asm/MCPNames.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader.asm; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.reflect.Field; 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | import java.util.NoSuchElementException; 9 | 10 | import com.google.common.base.Charsets; 11 | import com.google.common.base.Splitter; 12 | import com.google.common.collect.ImmutableMap; 13 | import com.google.common.collect.Maps; 14 | import com.google.common.io.Files; 15 | import com.google.common.io.LineProcessor; 16 | 17 | public class MCPNames 18 | { 19 | private static Map fields; 20 | private static Map methods; 21 | 22 | static 23 | { 24 | if (mcp()) 25 | { 26 | try 27 | { 28 | Class gradleClass = Class.forName("net.minecraftforge.gradle.GradleStartCommon"); 29 | Field dirField = gradleClass.getDeclaredField("CSV_DIR"); 30 | dirField.setAccessible(true); 31 | File mappingDir = (File) dirField.get(null); 32 | 33 | fields = readMappings(new File(mappingDir , "fields.csv")); 34 | methods = readMappings(new File(mappingDir , "methods.csv")); 35 | } 36 | catch (Exception e) 37 | { 38 | e.printStackTrace(); 39 | 40 | System.out.println("[RL] [ERROR] Error getting mappings from Gradlew SRG, falling back to mcp folder."); 41 | fields = readMappings(new File("./../mcp/fields.csv")); 42 | methods = readMappings(new File("./../mcp/methods.csv")); 43 | } 44 | 45 | } 46 | else 47 | { 48 | fields = methods = null; 49 | } 50 | } 51 | 52 | public static boolean mcp() 53 | { 54 | return LoadingPlugin.IN_MCP; 55 | } 56 | 57 | public static String field(String srgName) 58 | { 59 | if (mcp()) 60 | { 61 | return fields.get(srgName); 62 | } 63 | else 64 | { 65 | return srgName; 66 | } 67 | } 68 | 69 | public static String method(String srgName) 70 | { 71 | if (mcp()) 72 | { 73 | return methods.get(srgName); 74 | } 75 | else 76 | { 77 | return srgName; 78 | } 79 | } 80 | 81 | private static Map readMappings(File file) 82 | { 83 | if (!file.isFile()) 84 | { 85 | throw new RuntimeException("Couldn't find MCP mappings."); 86 | } 87 | try 88 | { 89 | return Files.readLines(file, Charsets.UTF_8, new MCPFileParser()); 90 | } 91 | catch (IOException e) 92 | { 93 | throw new RuntimeException("Couldn't read SRG->MCP mappings", e); 94 | } 95 | } 96 | 97 | private static class MCPFileParser implements LineProcessor> 98 | { 99 | private static final Splitter splitter = Splitter.on(',').trimResults(); 100 | private final Map map = Maps.newHashMap(); 101 | private boolean foundFirst; 102 | 103 | @Override 104 | public boolean processLine(String line) throws IOException 105 | { 106 | if (!foundFirst) 107 | { 108 | foundFirst = true; 109 | return true; 110 | } 111 | 112 | Iterator splitted = splitter.split(line).iterator(); 113 | try 114 | { 115 | String srg = splitted.next(); 116 | String mcp = splitted.next(); 117 | if (!map.containsKey(srg)) 118 | { 119 | map.put(srg, mcp); 120 | } 121 | } 122 | catch (NoSuchElementException e) 123 | { 124 | throw new IOException("Invalid Mappings file!", e); 125 | } 126 | 127 | return true; 128 | } 129 | 130 | @Override 131 | public Map getResult() 132 | { 133 | return ImmutableMap.copyOf(map); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/loader/NormalResourceLoader.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader.loader; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.File; 5 | import java.io.FileFilter; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | import org.apache.commons.io.filefilter.DirectoryFileFilter; 13 | import org.apache.logging.log4j.Level; 14 | 15 | import lumien.resourceloader.ResourceLoader; 16 | import net.minecraft.client.Minecraft; 17 | import net.minecraft.client.resources.IResourcePack; 18 | import net.minecraft.client.resources.data.IMetadataSection; 19 | import net.minecraft.client.resources.data.MetadataSerializer; 20 | import net.minecraft.util.ResourceLocation; 21 | 22 | public class NormalResourceLoader implements IResourcePack 23 | { 24 | boolean debug = false; 25 | 26 | @Override 27 | public InputStream getInputStream(ResourceLocation rl) throws IOException 28 | { 29 | if (!resourceExists(rl)) 30 | { 31 | return null; 32 | } 33 | else 34 | { 35 | File file = new File(new File(Minecraft.getMinecraft().mcDataDir, "resources/" + rl.getResourceDomain()), rl.getResourcePath()); 36 | 37 | String realFileName = file.getCanonicalFile().getName(); 38 | if (!realFileName.equals(file.getName())) 39 | { 40 | ResourceLoader.logger.log(Level.WARN, "[NormalResourceLoader] Resource Location " + rl.toString() + " only matches the file " + realFileName + " because RL is running in an environment that isn't case sensitive in regards to file names. This will not work properly on for example Linux."); 41 | } 42 | 43 | return new FileInputStream(file); 44 | } 45 | } 46 | 47 | @Override 48 | public boolean resourceExists(ResourceLocation rl) 49 | { 50 | File fileRequested = new File(new File(Minecraft.getMinecraft().mcDataDir, "resources/" + rl.getResourceDomain()), rl.getResourcePath()); 51 | 52 | if (debug && !fileRequested.isFile()) 53 | { 54 | ResourceLoader.logger.log(Level.DEBUG, "[NormalResourceLoader] Asked for resource " + rl.toString() + " but can't find a file at " + fileRequested.getAbsolutePath()); 55 | } 56 | 57 | return fileRequested.isFile(); 58 | } 59 | 60 | @Override 61 | public Set getResourceDomains() 62 | { 63 | File folder = new File(Minecraft.getMinecraft().mcDataDir, "resources"); 64 | if (!folder.exists()) 65 | { 66 | folder.mkdir(); 67 | } 68 | HashSet folders = new HashSet(); 69 | 70 | ResourceLoader.logger.log(Level.DEBUG, "[NormalResourceLoader] Resource Loader Domains: "); 71 | 72 | File[] resourceDomains = folder.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); 73 | 74 | for (File resourceFolder : resourceDomains) 75 | { 76 | if (resourceFolder.getName().equals("debug")) 77 | { 78 | debug = true; 79 | } 80 | } 81 | 82 | for (File resourceFolder : resourceDomains) 83 | { 84 | ResourceLoader.logger.log(Level.DEBUG, "[NormalResourceLoader] - " + resourceFolder.getName() + " | " + resourceFolder.getAbsolutePath()); 85 | folders.add(resourceFolder.getName()); 86 | } 87 | 88 | return folders; 89 | } 90 | 91 | @Override 92 | public IMetadataSection getPackMetadata(MetadataSerializer p_135058_1_, String p_135058_2_) throws IOException 93 | { 94 | return null; 95 | } 96 | 97 | @Override 98 | public BufferedImage getPackImage() throws IOException 99 | { 100 | return null; 101 | } 102 | 103 | @Override 104 | public String getPackName() 105 | { 106 | return "CustomResources"; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/lumien/resourceloader/loader/OverridingResourceLoader.java: -------------------------------------------------------------------------------- 1 | package lumien.resourceloader.loader; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.File; 5 | import java.io.FileFilter; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | import org.apache.commons.io.filefilter.DirectoryFileFilter; 13 | import org.apache.logging.log4j.Level; 14 | 15 | import com.google.common.collect.Sets; 16 | 17 | import lumien.resourceloader.ResourceLoader; 18 | import net.minecraft.client.Minecraft; 19 | import net.minecraft.client.resources.IResourcePack; 20 | import net.minecraft.client.resources.data.IMetadataSection; 21 | import net.minecraft.client.resources.data.MetadataSerializer; 22 | import net.minecraft.util.ResourceLocation; 23 | 24 | public class OverridingResourceLoader implements IResourcePack 25 | { 26 | boolean debug = false; 27 | 28 | @Override 29 | public InputStream getInputStream(ResourceLocation rl) throws IOException 30 | { 31 | if (!resourceExists(rl)) 32 | { 33 | return null; 34 | } 35 | else 36 | { 37 | File file = new File(new File(Minecraft.getMinecraft().mcDataDir, "oresources//" + rl.getResourceDomain()), rl.getResourcePath()); 38 | 39 | String realFileName = file.getCanonicalFile().getName(); 40 | if (!realFileName.equals(file.getName())) 41 | { 42 | ResourceLoader.logger.log(Level.WARN, "[OverridingResourceLoader] Resource Location " + rl.toString() + " only matches the file " + realFileName + " because RL is running in an environment that isn't case sensitive in regards to file names. This will not work properly on for example Linux."); 43 | } 44 | 45 | return new FileInputStream(file); 46 | } 47 | } 48 | 49 | @Override 50 | public boolean resourceExists(ResourceLocation rl) 51 | { 52 | File fileRequested = new File(new File(Minecraft.getMinecraft().mcDataDir, "oresources/" + rl.getResourceDomain()), rl.getResourcePath()); 53 | 54 | if (debug && !fileRequested.isFile()) 55 | { 56 | ResourceLoader.logger.log(Level.DEBUG, "[OverridingResourceLoader] Asked for resource " + rl.toString() + " but can't find a file at " + fileRequested.getAbsolutePath()); 57 | } 58 | 59 | return fileRequested.isFile(); 60 | } 61 | 62 | @Override 63 | public Set getResourceDomains() 64 | { 65 | Set set = Sets. newHashSet(); 66 | File folder = new File(Minecraft.getMinecraft().mcDataDir, "oresources"); 67 | HashSet folders = new HashSet(); 68 | 69 | ResourceLoader.logger.log(Level.DEBUG, "[OverridingResourceLoader] Resource Loader Domains: "); 70 | 71 | if (folder.isDirectory()) 72 | { 73 | File[] resourceDomains = folder.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); 74 | 75 | for (File resourceFolder : resourceDomains) 76 | { 77 | if (resourceFolder.getName().equals("debug")) 78 | { 79 | debug = true; 80 | } 81 | } 82 | 83 | for (File resourceFolder : resourceDomains) 84 | { 85 | ResourceLoader.logger.log(Level.DEBUG, "[OverridingResourceLoader] - " + resourceFolder.getName() + " | " + resourceFolder.getAbsolutePath()); 86 | 87 | folders.add(resourceFolder.getName()); 88 | } 89 | } 90 | return folders; 91 | } 92 | 93 | @Override 94 | public IMetadataSection getPackMetadata(MetadataSerializer p_135058_1_, String p_135058_2_) throws IOException 95 | { 96 | return null; 97 | } 98 | 99 | @Override 100 | public BufferedImage getPackImage() throws IOException 101 | { 102 | return null; 103 | } 104 | 105 | @Override 106 | public String getPackName() 107 | { 108 | return "CustomOverridingResources"; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/ResourceLoader_At.cfg: -------------------------------------------------------------------------------- 1 | public-f net.minecraft.client.Minecraft field_110449_ao #defaultResourcePacks -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "resourceloader", 4 | "name": "Resource Loader", 5 | "description": "Allows mod pack creators / users to add their own custom textures to minecrafts resources without making a resource pack.", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "", 9 | "updateUrl": "", 10 | "authorList": ["lumien"], 11 | "credits": "", 12 | "logoFile": "", 13 | "screenshots": [], 14 | "dependencies": [] 15 | } 16 | ] 17 | --------------------------------------------------------------------------------