|
36 | 36 | import net.minecraftforge.fml.common.versioning.ArtifactVersion; |
37 | 37 | import net.minecraftforge.fml.relauncher.MixinBooterPlugin; |
38 | 38 | import net.minecraftforge.fml.relauncher.libraries.LibraryManager; |
39 | | -import net.minecraftforge.fml.relauncher.mixinfix.MixinFixer; |
40 | 39 | import org.apache.logging.log4j.ThreadContext; |
41 | 40 | import org.apache.logging.log4j.message.FormattedMessage; |
| 41 | + |
42 | 42 | import org.spongepowered.asm.mixin.MixinEnvironment; |
43 | 43 | import org.spongepowered.asm.mixin.Mixins; |
| 44 | +import org.spongepowered.asm.mixin.ModUtil; |
| 45 | +import org.spongepowered.asm.mixin.transformer.Config; |
44 | 46 | import org.spongepowered.asm.mixin.transformer.Proxy; |
45 | 47 | import org.spongepowered.asm.service.MixinService; |
46 | 48 | import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; |
47 | 49 | import org.spongepowered.asm.util.Constants; |
| 50 | +import zone.rong.mixinbooter.Context; |
48 | 51 | import zone.rong.mixinbooter.ILateMixinLoader; |
49 | 52 |
|
50 | 53 | import javax.annotation.Nullable; |
51 | 54 | import java.io.File; |
52 | 55 | import java.io.IOException; |
53 | 56 | import java.lang.reflect.InvocationTargetException; |
54 | 57 | import java.lang.reflect.Method; |
55 | | -import java.net.URL; |
56 | 58 | import java.util.*; |
| 59 | +import java.util.function.Supplier; |
57 | 60 | import java.util.jar.Attributes; |
58 | 61 | import java.util.jar.JarFile; |
59 | 62 | import java.util.stream.Collectors; |
@@ -166,44 +169,55 @@ public void distributeStateMessage(LoaderState state, Object... eventData) |
166 | 169 | } |
167 | 170 |
|
168 | 171 | FMLContextQuery.init(); // Initialize FMLContextQuery and add it to the global list |
169 | | - boolean log = false; |
170 | | - |
171 | | - MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes..."); |
172 | 172 |
|
| 173 | + // Load late mixins |
| 174 | + FMLLog.log.info("Instantiating all ILateMixinLoader implemented classes..."); |
173 | 175 | for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) { |
174 | | - if (!log) { |
175 | | - MixinBooterPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes..."); |
176 | | - log = true; |
177 | | - } |
178 | | - modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance` |
179 | | - Class<?> clazz = Class.forName(asmData.getClassName().replace('/', '.')); |
180 | | - MixinBooterPlugin.LOGGER.info("Instantiating {} for its mixins.", clazz); |
181 | | - ILateMixinLoader loader = (ILateMixinLoader) clazz.newInstance(); |
182 | | - for (String mixinConfig : loader.getMixinConfigs()) { |
183 | | - if (loader.shouldMixinConfigQueue(mixinConfig)) { |
184 | | - MixinBooterPlugin.LOGGER.info("Adding {} mixin configuration.", mixinConfig); |
185 | | - Mixins.addConfiguration(mixinConfig); |
186 | | - loader.onMixinConfigQueued(mixinConfig); |
| 176 | + try { |
| 177 | + modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance` |
| 178 | + Class<?> clazz = Class.forName(asmData.getClassName().replace('/', '.')); |
| 179 | + FMLLog.log.info("Instantiating {} for its mixins.", clazz); |
| 180 | + @SuppressWarnings("deprecation") |
| 181 | + ILateMixinLoader loader = (ILateMixinLoader) clazz.getConstructor().newInstance(); |
| 182 | + for (String mixinConfig : loader.getMixinConfigs()) { |
| 183 | + @SuppressWarnings("deprecation") |
| 184 | + Context context = new Context(mixinConfig); |
| 185 | + if (loader.shouldMixinConfigQueue(context)) { |
| 186 | + try { |
| 187 | + FMLLog.log.info("Adding {} mixin configuration.", mixinConfig); |
| 188 | + Mixins.addConfiguration(mixinConfig); |
| 189 | + loader.onMixinConfigQueued(context); |
| 190 | + } catch (Throwable t) { |
| 191 | + FMLLog.log.error("Error adding mixin configuration for {}", mixinConfig, t); |
| 192 | + } |
| 193 | + } |
187 | 194 | } |
| 195 | + } catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) { |
| 196 | + FMLLog.log.error("Unable to load the ILateMixinLoader", e); |
188 | 197 | } |
189 | 198 | } |
190 | 199 |
|
191 | | - log = false; |
192 | | - |
193 | | - // Append all non-conventional mixin configurations gathered via MixinFixer |
194 | | - for (String mixinConfig : MixinFixer.retrieveLateMixinConfigs()) { |
195 | | - if (!log) { |
196 | | - MixinBooterPlugin.LOGGER.info("Appending non-conventional mixin configurations..."); |
197 | | - log = true; |
| 200 | + // mark config owners : for earlys, lates, and mfAttributes. |
| 201 | + for (Config config : Mixins.getConfigs()) { |
| 202 | + if (!config.getConfig().hasDecoration(ModUtil.OWNER_DECORATOR)) { |
| 203 | + String pkg = config.getConfig().getMixinPackage(); |
| 204 | + pkg = pkg.charAt(pkg.length() - 1) == '.' ? pkg.substring(0, pkg.length() - 1) : pkg; |
| 205 | + List<ModContainer> owners = getPackageOwners(pkg); |
| 206 | + if (owners.isEmpty()) { |
| 207 | + config.getConfig().decorate(ModUtil.OWNER_DECORATOR, (Supplier) () -> ModUtil.UNKNOWN_OWNER); |
| 208 | + } else { |
| 209 | + final String owner = owners.get(0).getModId(); // better assign ? |
| 210 | + config.getConfig().decorate(ModUtil.OWNER_DECORATOR, (Supplier) () -> owner); |
| 211 | + } |
198 | 212 | } |
199 | | - MixinBooterPlugin.LOGGER.info("Adding {} mixin configuration.", mixinConfig); |
200 | | - Mixins.addConfiguration(mixinConfig); |
201 | 213 | } |
202 | 214 |
|
203 | 215 | for (ModContainer container : this.loader.getActiveModList()) { |
204 | 216 | modClassLoader.addFile(container.getSource()); |
205 | 217 | } |
206 | | - } catch (Throwable ignored) {} |
| 218 | + } catch (Throwable t) { |
| 219 | + FMLLog.log.error("Error loading Mods", t); |
| 220 | + } |
207 | 221 | if (MixinService.getService() instanceof MixinServiceLaunchWrapper) { |
208 | 222 | ((MixinServiceLaunchWrapper) MixinService.getService()).setDelegatedTransformers(null); |
209 | 223 | } |
@@ -433,15 +447,20 @@ void forceState(LoaderState newState) |
433 | 447 | private ModContainer findActiveContainerFromStack() |
434 | 448 | { |
435 | 449 | return StackWalker.getInstance() |
436 | | - .walk(frames -> frames.map(StackWalker.StackFrame::getClassName) |
437 | | - .filter(name -> name.lastIndexOf('.') != -1) |
438 | | - .map(name -> name.substring(0, name.lastIndexOf('.'))) |
439 | | - .map(pkg -> packageOwners.get(pkg)) |
440 | | - .filter(l -> !l.isEmpty()) |
441 | | - .findFirst() |
442 | | - .map(List::getFirst) |
443 | | - .orElse(null) |
444 | | - ); |
| 450 | + .walk(frames -> frames.map(StackWalker.StackFrame::getClassName) |
| 451 | + .filter(name -> name.lastIndexOf('.') != -1) |
| 452 | + .map(name -> packageOwners.get(name.substring(0, name.lastIndexOf('.')))) |
| 453 | + .filter(l -> !l.isEmpty()) |
| 454 | + .findFirst() |
| 455 | + .map(List::getFirst) |
| 456 | + .orElse(null) |
| 457 | + ); |
| 458 | + } |
| 459 | + |
| 460 | + @Nullable |
| 461 | + public List<ModContainer> getPackageOwners(String pkg) |
| 462 | + { |
| 463 | + return packageOwners.get(pkg); |
445 | 464 | } |
446 | 465 |
|
447 | 466 | LoaderState getState() |
|
0 commit comments