├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── java.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── io │ └── github │ └── lxgaming │ └── mixin │ └── launch │ ├── MixinBootstrap.java │ ├── MixinClassLoader.java │ ├── MixinLaunchPluginService.java │ └── MixinTransformationService.java └── resources └── META-INF └── services ├── cpw.mods.modlauncher.api.ITransformationService ├── org.spongepowered.asm.service.IGlobalPropertyService ├── org.spongepowered.asm.service.IMixinService └── org.spongepowered.asm.service.IMixinServiceBootstrap /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Environment** 11 | - MixinBootstrap version: 12 | - Forge version: 13 | - Minecraft version: 14 | - Java version: 15 | - Mods: 16 | 17 | **Issue Description** 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/java.yml: -------------------------------------------------------------------------------- 1 | name: Java 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | java: 11 | name: Java 12 | runs-on: ubuntu-latest 13 | defaults: 14 | run: 15 | shell: bash {0} 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | - name: Gradle Wrapper Validation 20 | uses: gradle/wrapper-validation-action@v1 21 | - name: Setup Java 22 | uses: actions/setup-java@v3 23 | with: 24 | distribution: temurin 25 | java-version: 8 26 | - name: Cache Gradle 27 | uses: actions/cache@v3 28 | with: 29 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} 30 | path: | 31 | ~/.gradle/caches 32 | ~/.gradle/wrapper 33 | restore-keys: | 34 | ${{ runner.os }}-gradle- 35 | - name: Setup Gradle 36 | run: chmod +x gradlew 37 | - name: Build 38 | env: 39 | BUILD_NUMBER: ${{ github.run_number }} 40 | run: ./gradlew build --console=plain --refresh-dependencies -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build 2 | .checkstyle 3 | MANIFEST.MF 4 | dependency-reduced-pom.xml 5 | 6 | # Compiled 7 | /target 8 | bin 9 | build 10 | dist 11 | lib 12 | out 13 | run 14 | *.com 15 | *.class 16 | *.dll 17 | *.exe 18 | *.o 19 | *.so 20 | 21 | # Databases 22 | *.db 23 | *.sql 24 | *.sqlite 25 | 26 | # Logging 27 | /logs 28 | *.log 29 | 30 | # Misc 31 | *.bak 32 | 33 | # Packages 34 | *.7z 35 | *.cab 36 | *.dmg 37 | *.gz 38 | *.iso 39 | *.msi 40 | *.msm 41 | *.msp 42 | *.rar 43 | *.tar 44 | *.zip 45 | 46 | # Project 47 | .classpath 48 | .externalToolBuilders 49 | .gradle 50 | .idea 51 | .nb-gradle 52 | .project 53 | .settings 54 | atlassian-ide-plugin.xml 55 | build.bat 56 | build.ps1 57 | build.xml 58 | local.properties 59 | nb-configuration.xml 60 | nbproject 61 | *.iml 62 | *.ipr 63 | *.iws 64 | *.launch 65 | 66 | # Repository 67 | .git 68 | 69 | # System - macOS 70 | .AppleDB 71 | .AppleDesktop 72 | .AppleDouble 73 | .DS_Store 74 | .DocumentRevisions-V100 75 | .LSOverride 76 | .Spotlight-V100 77 | .TemporaryItems 78 | .Trashes 79 | .VolumeIcon.icns 80 | ._* 81 | .apdisk 82 | .fseventsd 83 | Network Trash Folder 84 | Temporary Items 85 | 86 | # System - Windows 87 | $RECYCLE.BIN/ 88 | Desktop.ini 89 | Thumbs.db 90 | ehthumbs.db 91 | *.lnk 92 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Alex Thomson 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MixinBootstrap 2 | 3 | [![License](https://img.shields.io/github/license/LXGaming/MixinBootstrap?label=License&cacheSeconds=86400)](https://github.com/LXGaming/MixinBootstrap/blob/master/LICENSE) 4 | 5 | ## This is an unofficial method of loading Mixin and as such do not expect any support. 6 | 7 | ## Mixin is available in Forge 1.15.2-31.2.44+ & 1.16.1-32.0.72+ (MixinBootstrap is no longer required). 8 | 9 | **MixinBootstrap** is a **temporary** way of booting [Mixin](https://github.com/SpongePowered/Mixin) in a [MinecraftForge](https://github.com/MinecraftForge/MinecraftForge) production environment. 10 | 11 | ## Usage 12 | Simply drop the `MixinBootstrap-.jar` into the [MinecraftForge](https://github.com/MinecraftForge/MinecraftForge) mods folder 13 | 14 | ### Development 15 | Add the `org.spongepowered:mixin:0.8.5` dependency to your `build.gradle`, If you want to depend on MixinBootstrap then simply don't compile Mixin into your mod. 16 | 17 | ## Download 18 | - [CurseForge](https://www.curseforge.com/minecraft/mc-mods/mixinbootstrap) 19 | - [GitHub](https://github.com/LXGaming/MixinBootstrap/releases) 20 | - [Modrinth](https://modrinth.com/mod/mixinbootstrap) 21 | 22 | ## Compatibility 23 | | Version | Support | Reason | 24 | | :-----: | :-----: | :----: | 25 | | 1.12.2 | :heavy_check_mark: | - | 26 | | 1.13.x | :x: | Not supported due to ModLauncher version | 27 | | 1.14.x | :warning: | Only Forge 28.1.45 or later | 28 | | 1.15.x | :heavy_check_mark: | - | 29 | | 1.16.x | :heavy_check_mark: | - | 30 | | 1.17.x | :heavy_check_mark: | - | 31 | 32 | :heavy_check_mark: - Full Support | :warning: - Partial Support | :x: - No Support 33 | 34 | ## License 35 | MixinBootstrap is licensed under the [Apache 2.0](https://github.com/LXGaming/MixinBootstrap/blob/master/LICENSE) license. 36 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | gradlePluginPortal() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | classpath("net.kyori:blossom:1.3.0") 9 | classpath("org.ow2.asm:asm:9.2") 10 | } 11 | } 12 | 13 | apply plugin: "java" 14 | apply plugin: "net.kyori.blossom" 15 | apply plugin: "signing" 16 | 17 | sourceCompatibility = 1.8 18 | targetCompatibility = 1.8 19 | 20 | group = "io.github.lxgaming" 21 | archivesBaseName = "_MixinBootstrap" 22 | version = "1.1.1" 23 | 24 | blossom { 25 | replaceToken("@version@", version) 26 | } 27 | 28 | configurations { 29 | compileJar { 30 | implementation.extendsFrom(compileJar) 31 | } 32 | 33 | // build.finalizedBy("signJar") 34 | } 35 | 36 | repositories { 37 | mavenCentral() 38 | maven { 39 | name = "minecraftforge" 40 | url = "https://maven.minecraftforge.net/" 41 | } 42 | maven { 43 | name = "spongepowered" 44 | url = "https://repo.spongepowered.org/repository/maven-public/" 45 | } 46 | } 47 | 48 | dependencies { 49 | compileOnly("com.google.code.findbugs:jsr305:3.0.2") 50 | compileOnly("cpw.mods:modlauncher:5.1.2") 51 | implementation("io.github.lxgaming:classloaderutils:1.0.0") 52 | compileOnly("net.sf.jopt-simple:jopt-simple:5.0.4") 53 | compileOnly("org.apache.logging.log4j:log4j-api:2.17.0") 54 | compileJar("org.ow2.asm:asm-analysis:6.2") { 55 | transitive = false 56 | } 57 | compileJar("org.ow2.asm:asm-util:6.2") { 58 | transitive = false 59 | } 60 | implementation("org.spongepowered:mixin:0.8.5") { 61 | transitive = false 62 | } 63 | } 64 | 65 | jar { 66 | dependsOn("patchMixinModule") 67 | duplicatesStrategy = DuplicatesStrategy.INCLUDE 68 | manifest { 69 | attributes( 70 | "Automatic-Module-Name": "mixinbootstrap", 71 | "TweakClass": "org.spongepowered.asm.launch.MixinTweaker", 72 | "TweakOrder": 0 73 | ) 74 | } 75 | 76 | from ((configurations.runtimeClasspath - configurations.compileJar).findAll({ 77 | it.isDirectory() || it.name.endsWith(".jar") 78 | }).collect({ 79 | it.isDirectory() ? it : zipTree(it) 80 | })) { 81 | exclude("META-INF/services/cpw.mods.modlauncher.*") 82 | exclude("META-INF/services/org.spongepowered.asm.service.*") 83 | exclude("META-INF/*.RSA") 84 | exclude("META-INF/*.SF") 85 | exclude("module-info.class") 86 | } 87 | 88 | into ("META-INF/libraries") { 89 | from (configurations.compileJar.findAll({ 90 | it.name.endsWith(".jar") 91 | }).collect({ 92 | it 93 | })) 94 | } 95 | } 96 | 97 | java { 98 | disableAutoTargetJvm() 99 | } 100 | 101 | processResources { 102 | from("LICENSE") 103 | rename("LICENSE", "LICENSE-MixinBootstrap") 104 | } 105 | 106 | task signJar { 107 | doFirst { 108 | if (!project.hasProperty("signing.keyStorePath") || !project.hasProperty("signing.secretKeyRingFile")) { 109 | project.logger.warn("========== [WARNING] ==========") 110 | project.logger.warn("") 111 | project.logger.warn(" This build is not signed! ") 112 | project.logger.warn("") 113 | project.logger.warn("========== [WARNING] ==========") 114 | throw new StopExecutionException() 115 | } 116 | } 117 | 118 | doLast { 119 | configurations.archives.allArtifacts.files.each { 120 | ant.signjar( 121 | jar: it, 122 | alias: project.property("signing.alias"), 123 | storepass: project.property("signing.keyStorePassword"), 124 | keystore: project.property("signing.keyStorePath"), 125 | keypass: project.property("signing.keyStorePassword"), 126 | preservelastmodified: project.property("signing.preserveLastModified"), 127 | tsaurl: project.property("signing.timestampAuthority"), 128 | digestalg: project.property("signing.digestAlgorithm") 129 | ) 130 | project.logger.lifecycle("JAR Signed: ${it.name}") 131 | 132 | signing.sign(it) 133 | project.logger.lifecycle("PGP Signed: ${it.name}") 134 | } 135 | } 136 | } 137 | 138 | import java.util.zip.ZipFile 139 | import org.objectweb.asm.ClassReader 140 | import org.objectweb.asm.ClassVisitor 141 | import org.objectweb.asm.ClassWriter 142 | import org.objectweb.asm.ModuleVisitor 143 | import org.objectweb.asm.Opcodes 144 | 145 | task patchMixinModule { 146 | doLast { 147 | configurations.compileClasspath.asFileTree.filter({ 148 | it.name.startsWith("mixin-") 149 | }).forEach({ file -> 150 | sourceSets.main.java.classesDirectory.get().file("module-info.class").asFile.withOutputStream { outputStream -> 151 | ZipFile zipFile = new ZipFile(file) 152 | ClassReader classReader = new ClassReader(zipFile.getInputStream(zipFile.getEntry("module-info.class"))) 153 | ClassWriter classWriter = new ClassWriter(0) 154 | 155 | classReader.accept(new ClassVisitor(Opcodes.ASM9, classWriter) { 156 | @Override 157 | ModuleVisitor visitModule(String name, int access, String version) { 158 | return new ModuleVisitor(Opcodes.ASM9, super.visitModule("io.github.lxgaming.mixin.launch", access, version)) { 159 | @Override 160 | void visitExport(String exportPackage, int exportAccess, String... modules) { 161 | } 162 | @Override 163 | void visitProvide(String service, String... providers) { 164 | // clean all mixin services 165 | if (service == "cpw/mods/modlauncher/api/ITransformationService") { 166 | providers = ["io/github/lxgaming/mixin/launch/MixinTransformationService"] 167 | } 168 | 169 | super.visitProvide(service, providers) 170 | } 171 | }.with { moduleVisitor -> 172 | moduleVisitor.visitRequire("jdk.unsupported", 0, null) 173 | moduleVisitor 174 | } 175 | } 176 | }, 0) 177 | 178 | outputStream.write(classWriter.toByteArray()) 179 | } 180 | }) 181 | } 182 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx512M 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LXGaming/MixinBootstrap/2019d8503ed580c37e31f787babfcd0a1c687197/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LXGaming/MixinBootstrap/2019d8503ed580c37e31f787babfcd0a1c687197/gradlew -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "MixinBootstrap" 2 | -------------------------------------------------------------------------------- /src/main/java/io/github/lxgaming/mixin/launch/MixinBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Alex Thomson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.lxgaming.mixin.launch; 18 | 19 | import cpw.mods.modlauncher.Launcher; 20 | import cpw.mods.modlauncher.api.IEnvironment; 21 | import cpw.mods.modlauncher.api.ITransformationService; 22 | import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; 23 | import io.github.lxgaming.classloader.ClassLoaderUtils; 24 | import org.apache.logging.log4j.LogManager; 25 | import org.apache.logging.log4j.Logger; 26 | 27 | import java.lang.reflect.Field; 28 | import java.lang.reflect.Method; 29 | import java.net.URI; 30 | import java.net.URL; 31 | import java.nio.file.FileSystem; 32 | import java.nio.file.FileSystems; 33 | import java.nio.file.Files; 34 | import java.nio.file.Path; 35 | import java.nio.file.StandardCopyOption; 36 | import java.util.HashMap; 37 | import java.util.List; 38 | import java.util.Map; 39 | import java.util.stream.Collectors; 40 | 41 | public class MixinBootstrap { 42 | 43 | public static final String ID = "mixinbootstrap"; 44 | public static final String NAME = "MixinBootstrap"; 45 | public static final String VERSION = "@version@"; 46 | public static final Logger LOGGER = LogManager.getLogger(NAME + " Launch"); 47 | 48 | static { 49 | LOGGER.info("{} v{}", NAME, VERSION); 50 | LOGGER.info("Mixin v{}", org.spongepowered.asm.launch.MixinBootstrap.VERSION); 51 | LOGGER.info("ModLauncher v{} ({})", IEnvironment.class.getPackage().getImplementationVersion(), IEnvironment.class.getPackage().getSpecificationVersion()); 52 | } 53 | 54 | public static void initialize(IEnvironment environment) { 55 | ensureTransformerExclusion(); 56 | } 57 | 58 | public static void onLoad(IEnvironment environment, MixinTransformationService service) throws IncompatibleEnvironmentException { 59 | if (environment.findLaunchPlugin("mixin").isPresent()) { 60 | LOGGER.debug("MixinLaunchPlugin detected"); 61 | return; 62 | } 63 | 64 | if (IEnvironment.class.getPackage().isCompatibleWith("8.0")) { 65 | setFallbackClassLoader(service.getClass().getClassLoader()); 66 | 67 | // Mixin 68 | // - Plugin Service 69 | service.registerLaunchPluginService("org.spongepowered.asm.launch.MixinLaunchPlugin", MixinBootstrap.class.getClassLoader()); 70 | 71 | // - Transformation Service 72 | // This cannot be loaded by the ServiceLoader as it will load classes under the wrong classloader 73 | service.registerTransformationService("org.spongepowered.asm.launch.MixinTransformationService", MixinBootstrap.class.getClassLoader()); 74 | return; 75 | } 76 | 77 | if (IEnvironment.class.getPackage().isCompatibleWith("4.0")) { 78 | appendToClassPath(); 79 | 80 | // Mixin 81 | // - Plugin Service 82 | service.registerLaunchPluginService("org.spongepowered.asm.launch.MixinLaunchPluginLegacy", Launcher.class.getClassLoader()); 83 | 84 | // - Transformation Service 85 | // This cannot be loaded by the ServiceLoader as it will load classes under the wrong classloader 86 | service.registerTransformationService("org.spongepowered.asm.launch.MixinTransformationServiceLegacy", Thread.currentThread().getContextClassLoader()); 87 | 88 | // MixinBootstrap 89 | // - Plugin Service 90 | service.registerLaunchPluginService("io.github.lxgaming.mixin.launch.MixinLaunchPluginService", Launcher.class.getClassLoader()); 91 | return; 92 | } 93 | 94 | LOGGER.error("-------------------------[ ERROR ]-------------------------"); 95 | LOGGER.error("Mixin is not compatible with ModLauncher v{}", ITransformationService.class.getPackage().getImplementationVersion()); 96 | LOGGER.error("Ensure you are running Forge v28.1.45 or later"); 97 | LOGGER.error("-------------------------[ ERROR ]-------------------------"); 98 | throw new IncompatibleEnvironmentException("Incompatibility with ModLauncher"); 99 | } 100 | 101 | private static void appendToClassPath() throws IncompatibleEnvironmentException { 102 | try { 103 | Map map = new HashMap<>(); 104 | map.put("create", "true"); 105 | FileSystem fileSystem = FileSystems.newFileSystem(URI.create("jar:" + MixinBootstrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()), map); 106 | Map libraries = Files.list(fileSystem.getPath("META-INF", "libraries")) 107 | .filter(path -> !Files.isDirectory(path) && path.getFileName().toString().endsWith(".jar")) 108 | .collect(Collectors.toMap(path -> path, path -> { 109 | String fileName = path.getFileName().toString(); 110 | int index = fileName.lastIndexOf('.'); 111 | return index != -1 ? fileName.substring(0, index) : fileName; 112 | })); 113 | 114 | LOGGER.debug("Found {} libraries", libraries.size()); 115 | 116 | for (Map.Entry entry : libraries.entrySet()) { 117 | Path temporaryPath = Files.createTempFile(MixinBootstrap.ID + "-" + entry.getValue() + "-", ".jar"); 118 | 119 | LOGGER.debug("Copying {} -> {}", entry.getKey(), temporaryPath); 120 | Files.copy(entry.getKey(), temporaryPath, StandardCopyOption.REPLACE_EXISTING); 121 | 122 | URL url = temporaryPath.toUri().toURL(); 123 | LOGGER.debug("Loading {}", url); 124 | ClassLoaderUtils.appendToClassPath(Thread.currentThread().getContextClassLoader(), url); 125 | } 126 | 127 | URL url = MixinBootstrap.class.getProtectionDomain().getCodeSource().getLocation().toURI().toURL(); 128 | LOGGER.debug("Loading {}", url); 129 | ClassLoaderUtils.appendToClassPath(Thread.currentThread().getContextClassLoader(), url); 130 | } catch (Throwable ex) { 131 | LOGGER.error("Encountered an error while appending to the class path", ex); 132 | throw new IncompatibleEnvironmentException("Failed to append to the class path"); 133 | } 134 | } 135 | 136 | /** 137 | * Mixin requires it can be loaded in context class loader. 138 | * Thanks ZekerZhayard 139 | */ 140 | private static void setFallbackClassLoader(ClassLoader classLoader) throws IncompatibleEnvironmentException { 141 | try { 142 | Class moduleClassLoaderClass = Class.forName("cpw.mods.cl.ModuleClassLoader"); 143 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 144 | if (!moduleClassLoaderClass.isInstance(contextClassLoader) || classLoader.equals(contextClassLoader)) { 145 | throw new IllegalStateException("Unexpected ClassLoader: " + contextClassLoader.getClass().getName()); 146 | } 147 | 148 | Method getPlatformClassLoaderMethod = ClassLoader.class.getMethod("getPlatformClassLoader"); 149 | getPlatformClassLoaderMethod.setAccessible(true); 150 | ClassLoader platformClassLoader = (ClassLoader) getPlatformClassLoaderMethod.invoke(null); 151 | 152 | Method setFallbackClassLoaderMethod = moduleClassLoaderClass.getMethod("setFallbackClassLoader", ClassLoader.class); 153 | setFallbackClassLoaderMethod.setAccessible(true); 154 | setFallbackClassLoaderMethod.invoke(contextClassLoader, new MixinClassLoader(platformClassLoader, classLoader)); 155 | } catch (Throwable ex) { 156 | LOGGER.error("Encountered an error while setting fallback classloader", ex); 157 | throw new IncompatibleEnvironmentException("Failed to set fallback classloader"); 158 | } 159 | } 160 | 161 | /** 162 | * Fixes https://github.com/MinecraftForge/MinecraftForge/pull/6600 163 | */ 164 | @SuppressWarnings("unchecked") 165 | private static void ensureTransformerExclusion() { 166 | try { 167 | Path path = Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.GAMEDIR.get()) 168 | .map(parentPath -> parentPath.resolve("mods")) 169 | .map(Path::toAbsolutePath) 170 | .map(Path::normalize) 171 | .map(parentPath -> { 172 | // Extract the file name 173 | String file = MixinBootstrap.class.getProtectionDomain().getCodeSource().getLocation().getFile(); 174 | return parentPath.resolve(file.substring(file.lastIndexOf('/') + 1)); 175 | }) 176 | .filter(Files::exists) 177 | .orElse(null); 178 | if (path == null) { 179 | return; 180 | } 181 | 182 | // Check if the path is behind a symbolic link 183 | if (path.equals(path.toRealPath())) { 184 | return; 185 | } 186 | 187 | Class modDirTransformerDiscovererClass = Class.forName("net.minecraftforge.fml.loading.ModDirTransformerDiscoverer", true, Launcher.class.getClassLoader()); 188 | 189 | // net.minecraftforge.fml.loading.ModDirTransformerDiscoverer.transformers 190 | Field transformersField = modDirTransformerDiscovererClass.getDeclaredField("transformers"); 191 | transformersField.setAccessible(true); 192 | List transformers = (List) transformersField.get(null); 193 | 194 | if (transformers != null && !transformers.contains(path)) { 195 | transformers.add(path); 196 | } 197 | } catch (Throwable ex) { 198 | LOGGER.error("Encountered an error while ensuring transformer exclusion", ex); 199 | } 200 | } 201 | } -------------------------------------------------------------------------------- /src/main/java/io/github/lxgaming/mixin/launch/MixinClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Alex Thomson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.lxgaming.mixin.launch; 18 | 19 | import java.util.Collections; 20 | import java.util.Set; 21 | import java.util.concurrent.ConcurrentHashMap; 22 | 23 | public class MixinClassLoader extends ClassLoader { 24 | 25 | private final ClassLoader child; 26 | private final Set invalidClasses; 27 | 28 | public MixinClassLoader(ClassLoader parent, ClassLoader child) { 29 | super(parent); 30 | this.child = child; 31 | this.invalidClasses = Collections.newSetFromMap(new ConcurrentHashMap<>()); 32 | } 33 | 34 | @Override 35 | protected Class findClass(String name) throws ClassNotFoundException { 36 | if (invalidClasses.contains(name)) { 37 | throw new ClassNotFoundException(name); 38 | } 39 | 40 | invalidClasses.add(name); 41 | Class validClass = child.loadClass(name); 42 | invalidClasses.remove(name); 43 | 44 | return validClass; 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/io/github/lxgaming/mixin/launch/MixinLaunchPluginService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Alex Thomson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.lxgaming.mixin.launch; 18 | 19 | import cpw.mods.modlauncher.TransformingClassLoader; 20 | import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; 21 | import org.objectweb.asm.Type; 22 | import org.objectweb.asm.tree.ClassNode; 23 | 24 | import java.nio.file.Path; 25 | import java.util.Arrays; 26 | import java.util.EnumSet; 27 | import java.util.List; 28 | 29 | public class MixinLaunchPluginService implements ILaunchPluginService { 30 | 31 | private static final List SKIP_PACKAGES = Arrays.asList( 32 | "org.objectweb.asm.", 33 | "org.spongepowered.asm.launch.", 34 | "org.spongepowered.asm.lib.", 35 | "org.spongepowered.asm.mixin.", 36 | "org.spongepowered.asm.service.", 37 | "org.spongepowered.asm.util." 38 | ); 39 | 40 | @Override 41 | public String name() { 42 | return MixinBootstrap.ID; 43 | } 44 | 45 | @Override 46 | public EnumSet handlesClass(Type classType, boolean isEmpty) { 47 | throw new UnsupportedOperationException("Outdated ModLauncher"); 48 | } 49 | 50 | @Override 51 | public boolean processClass(Phase phase, ClassNode classNode, Type classType) { 52 | throw new UnsupportedOperationException("Outdated ModLauncher"); 53 | } 54 | 55 | @Override 56 | public EnumSet handlesClass(Type classType, boolean isEmpty, String reason) { 57 | return EnumSet.noneOf(Phase.class); 58 | } 59 | 60 | @Override 61 | public boolean processClass(Phase phase, ClassNode classNode, Type classType, String reason) { 62 | return false; 63 | } 64 | 65 | @Override 66 | public void initializeLaunch(ITransformerLoader transformerLoader, Path[] specialPaths) { 67 | TransformingClassLoader classLoader = (TransformingClassLoader) Thread.currentThread().getContextClassLoader(); 68 | classLoader.addTargetPackageFilter(name -> SKIP_PACKAGES.stream().noneMatch(name::startsWith)); 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/io/github/lxgaming/mixin/launch/MixinTransformationService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Alex Thomson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.github.lxgaming.mixin.launch; 18 | 19 | import cpw.mods.modlauncher.LaunchPluginHandler; 20 | import cpw.mods.modlauncher.Launcher; 21 | import cpw.mods.modlauncher.api.IEnvironment; 22 | import cpw.mods.modlauncher.api.ITransformationService; 23 | import cpw.mods.modlauncher.api.ITransformer; 24 | import cpw.mods.modlauncher.api.IncompatibleEnvironmentException; 25 | import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; 26 | import joptsimple.OptionSpecBuilder; 27 | 28 | import java.lang.reflect.Field; 29 | import java.net.URL; 30 | import java.nio.file.Path; 31 | import java.util.ArrayList; 32 | import java.util.HashMap; 33 | import java.util.HashSet; 34 | import java.util.List; 35 | import java.util.Map; 36 | import java.util.Optional; 37 | import java.util.Set; 38 | import java.util.function.BiFunction; 39 | import java.util.function.Function; 40 | import java.util.function.Supplier; 41 | 42 | public class MixinTransformationService implements ITransformationService { 43 | 44 | private final Map launchPluginServices; 45 | private final Set transformationServices; 46 | 47 | public MixinTransformationService() { 48 | if (Launcher.INSTANCE == null) { 49 | throw new IllegalStateException("Launcher has not been initialized!"); 50 | } 51 | 52 | this.launchPluginServices = getLaunchPluginServices(); 53 | this.transformationServices = new HashSet<>(); 54 | } 55 | 56 | @Override 57 | public String name() { 58 | return MixinBootstrap.ID; 59 | } 60 | 61 | @Override 62 | public void initialize(IEnvironment environment) { 63 | MixinBootstrap.initialize(environment); 64 | 65 | for (ITransformationService transformationService : this.transformationServices) { 66 | transformationService.initialize(environment); 67 | } 68 | } 69 | 70 | @Override 71 | public void beginScanning(IEnvironment environment) { 72 | for (ITransformationService transformationService : this.transformationServices) { 73 | transformationService.beginScanning(environment); 74 | } 75 | } 76 | 77 | @Override 78 | public void onLoad(IEnvironment env, Set otherServices) throws IncompatibleEnvironmentException { 79 | MixinBootstrap.onLoad(env, this); 80 | 81 | for (ITransformationService transformationService : this.transformationServices) { 82 | transformationService.onLoad(env, otherServices); 83 | } 84 | } 85 | 86 | @Override 87 | @SuppressWarnings("rawtypes") 88 | public List transformers() { 89 | List list = new ArrayList<>(); 90 | for (ITransformationService transformationService : this.transformationServices) { 91 | list.addAll(transformationService.transformers()); 92 | } 93 | 94 | return list; 95 | } 96 | 97 | @Override 98 | public void arguments(BiFunction argumentBuilder) { 99 | for (ITransformationService transformationService : this.transformationServices) { 100 | transformationService.arguments(argumentBuilder); 101 | } 102 | } 103 | 104 | @Override 105 | public void argumentValues(OptionResult option) { 106 | for (ITransformationService transformationService : this.transformationServices) { 107 | transformationService.argumentValues(option); 108 | } 109 | } 110 | 111 | @Override 112 | public List> runScan(IEnvironment environment) { 113 | List> list = new ArrayList<>(); 114 | for (ITransformationService transformationService : this.transformationServices) { 115 | list.addAll(transformationService.runScan(environment)); 116 | } 117 | 118 | return list; 119 | } 120 | 121 | @Override 122 | public Map.Entry, Supplier>>> additionalClassesLocator() { 123 | return null; 124 | } 125 | 126 | @Override 127 | public Map.Entry, Supplier>>> additionalResourcesLocator() { 128 | return null; 129 | } 130 | 131 | @SuppressWarnings("unchecked") 132 | private Map getLaunchPluginServices() { 133 | try { 134 | // cpw.mods.modlauncher.Launcher.launchPlugins 135 | Field launchPluginsField = Launcher.class.getDeclaredField("launchPlugins"); 136 | launchPluginsField.setAccessible(true); 137 | LaunchPluginHandler launchPluginHandler = (LaunchPluginHandler) launchPluginsField.get(Launcher.INSTANCE); 138 | 139 | // cpw.mods.modlauncher.LaunchPluginHandler.plugins 140 | Field pluginsField = LaunchPluginHandler.class.getDeclaredField("plugins"); 141 | pluginsField.setAccessible(true); 142 | return (Map) pluginsField.get(launchPluginHandler); 143 | } catch (Exception ex) { 144 | MixinBootstrap.LOGGER.error("Encountered an error while getting LaunchPluginServices", ex); 145 | return null; 146 | } 147 | } 148 | 149 | @SuppressWarnings("unchecked") 150 | public void registerLaunchPluginService(String className, ClassLoader classLoader) throws IncompatibleEnvironmentException { 151 | try { 152 | Class launchPluginServiceClass = (Class) Class.forName(className, true, classLoader); 153 | if (isLaunchPluginServicePresent(launchPluginServiceClass)) { 154 | MixinBootstrap.LOGGER.warn("{} is already registered", launchPluginServiceClass.getSimpleName()); 155 | return; 156 | } 157 | 158 | ILaunchPluginService launchPluginService = launchPluginServiceClass.newInstance(); 159 | String pluginName = launchPluginService.name(); 160 | this.launchPluginServices.put(pluginName, launchPluginService); 161 | 162 | List> mods = Launcher.INSTANCE.environment().getProperty(IEnvironment.Keys.MODLIST.get()).orElse(null); 163 | if (mods != null) { 164 | Map mod = new HashMap<>(); 165 | mod.put("name", pluginName); 166 | mod.put("type", "PLUGINSERVICE"); 167 | String fileName = launchPluginServiceClass.getProtectionDomain().getCodeSource().getLocation().getFile(); 168 | mod.put("file", fileName.substring(fileName.lastIndexOf('/'))); 169 | mods.add(mod); 170 | } 171 | 172 | MixinBootstrap.LOGGER.debug("Registered {} ({})", launchPluginServiceClass.getSimpleName(), pluginName); 173 | } catch (Throwable ex) { 174 | MixinBootstrap.LOGGER.error("Encountered an error while registering {}", className, ex); 175 | throw new IncompatibleEnvironmentException(String.format("Failed to register %s", className)); 176 | } 177 | } 178 | 179 | @SuppressWarnings("unchecked") 180 | public void registerTransformationService(String className, ClassLoader classLoader) throws IncompatibleEnvironmentException { 181 | try { 182 | Class transformationServiceClass = (Class) Class.forName(className, true, classLoader); 183 | if (isTransformationServicePresent(transformationServiceClass)) { 184 | MixinBootstrap.LOGGER.warn("{} is already registered", transformationServiceClass.getSimpleName()); 185 | return; 186 | } 187 | 188 | ITransformationService transformationService = transformationServiceClass.newInstance(); 189 | String name = transformationService.name(); 190 | this.transformationServices.add(transformationService); 191 | MixinBootstrap.LOGGER.debug("Registered {} ({})", transformationServiceClass.getSimpleName(), name); 192 | } catch (Exception ex) { 193 | MixinBootstrap.LOGGER.error("Encountered an error while registering {}", className, ex); 194 | throw new IncompatibleEnvironmentException(String.format("Failed to register %s", className)); 195 | } 196 | } 197 | 198 | private boolean isLaunchPluginServicePresent(Class launchPluginServiceClass) { 199 | for (ILaunchPluginService launchPluginService : this.launchPluginServices.values()) { 200 | if (launchPluginServiceClass.isInstance(launchPluginService)) { 201 | return true; 202 | } 203 | } 204 | 205 | return false; 206 | } 207 | 208 | private boolean isTransformationServicePresent(Class transformationServiceClass) { 209 | for (ITransformationService transformationService : this.transformationServices) { 210 | if (transformationServiceClass.isInstance(transformationService)) { 211 | return true; 212 | } 213 | } 214 | 215 | return false; 216 | } 217 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/cpw.mods.modlauncher.api.ITransformationService: -------------------------------------------------------------------------------- 1 | io.github.lxgaming.mixin.launch.MixinTransformationService 2 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.spongepowered.asm.service.IGlobalPropertyService: -------------------------------------------------------------------------------- 1 | org.spongepowered.asm.service.mojang.Blackboard 2 | org.spongepowered.asm.service.modlauncher.Blackboard 3 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinService: -------------------------------------------------------------------------------- 1 | org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper 2 | org.spongepowered.asm.service.modlauncher.MixinServiceModLauncher 3 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.spongepowered.asm.service.IMixinServiceBootstrap: -------------------------------------------------------------------------------- 1 | org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapperBootstrap 2 | org.spongepowered.asm.service.modlauncher.MixinServiceModLauncherBootstrap 3 | --------------------------------------------------------------------------------