-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Mixin Fixer system #1201
base: llama
Are you sure you want to change the base?
New Mixin Fixer system #1201
Conversation
…hout needing to update the descriptor
@Chocohead should I continue this PR? The next step would be to port everything from |
I think it's worth continuing the PR. I would start with converting #1179, given it's the messiest fix needed yet. What I have locally is not dissimilar, but approaches the problem from the opposite side. I was going to change the presented Minecraft classes that mixins see, then correct it back afterwards. I've thought about changing mod's mixins directly in the past. Beyond the obvious difficulties in reflecting your way to the I think there is probably a balance such that moving locals around (such as from a new parameter) is fine, but adding or changing the logic purely in bytecode is a bit obscure. At least without marking the line numbers as being from OptiFabric. I was also going to deduplicate the fixes further; where certain methods in Hope that is some use to explain my thinking/plans. A blend of the two approaches might well be the best solution of all, but anything which improves on the current approach can't hurt. |
This could be handled by an I'm also planning to make the crash screen always appear and explicitly state what went wrong, instead of letting the game crash and only provide a stack trace. I will push tomorrow some stuff because I don't have time to finish today. This includes the following:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u add my discord? its .trolf
@Chocohead I finally updated the PR description. I think it will take some time before I can complete a user friendly error handling system, but the logging should suffice for now. Merging the PR in order to fix FAPI 0.86.0+ is unlikely to result in any compatibility regression and I can continue working on the system itself and porting stuff from |
MixinNodeTransformer supersedes the old MixinFixerUtils and doesn't expose the ClassNode of the mixin to Fixers. ModMixinFixer.getFixers has also been changed, now taking an IMixinInfo instead of the FQN of the mixin.
Removed FeatureFinder and turned some of the `predictFuture`s into fields of OptifabricSetup. Also removed 1.18-beta.1 support since it isn't a valid version. FRDA had an injector method called "init" before 1.18-rc1, but that isn't relevant.
Removed MixinNodeTransformer.placeSurrogate since it's broken.
When merge? |
Done a bunch of testing related to this, so far Ive noticed it also seems to fix a bunch of issues related to Optifine reflector (or maybe theres something else, but im no longer crashing on load at all), and mod support seems pretty good. I can confirm it works right out of the box on an instance that was iffy before, even with mixin fixes. I also haven't crashed with a Batching Chunks error since switching to this build. |
I think it's worth using https://github.com/Sinytra/Adapter to patch mixins... |
I might switch to this if Chocohead is ok with it since Adapter has rigor put into it, unlike my lazy implementation. Porting would mean closing this PR and making a new one, but at this moment I don't have the time, nor the motivation to do it. I'm going to start working on it this week, as this PR is already a mess. |
Everything seems to work fine, even with about 50 mods, but for some reason, as soon as I equip some resources packs, the game cant launch and gets stuck in the MOJANG Logo screen |
I started working on another system that wraps the mixins of other mods instead of messing with their annotations directly. I'm currently stuck on the part where I dynamically generate the wrapper mixins since I've been trying to use Fabric ASM's I'll close this PR when I manage to push something on the new branch. Until then, this PR remains a draft. Regarding Adapter, there's no way of using it since it requires Java 17 or a forking it and making it compatible with Java 8. |
Did you work out your class generation problems? Fabric ASM has Now that bundling Tiny Remapper is necessary, including Adapter is not as complicated (forked for Java 8 or not). I don't think it's really suitable for what we need though. Lazy or not, your implementation here is fairly simple, which Adapter is certainly not. Your implementation is also designed for what OptiFabric need, compared to Adapter which might coincidentally work with some glue code to actually make it work within Fabric Loader. |
The system itself
There's still a lot of stuff that needs to be polished, mainly the error handling. I'm also not particularly satisfied with the naming and package structure so I might slightly alter them. The PR can be merged, but there's still a lot of refactoring to do.
Goal
The main advantage over the old system is its lack of reliance on
InterceptingMixin
s andInterceptingMixinPlugin
s in order to placate Injectors, changing said Injectors directly by modifying the annotation and/or the method parameters and in some cases even the body, using raw ASM, although this should be avoided. By not relying on mixins there will be way less boilerplate (i.e.: things with 'Newerererer' in their name), making the project easier to maintain. When the pull request is ready to merge, this system should be able to fully replace the following:@Shim
@PlacatingSurrogate
@InterceptingMixin
InterceptingMixinPlugin
@LoudCoerce
shim
sourcesetUsage
Similarly to how
OptifineFixer
works,addFixer
method calls may be added toModMixinFixer
's private constructor, the first argument being the fully qualified name of the targeted mixin class and the second anIMixinFixer
that changes theIMixinInfo
and theClassNode
of the given mixin. Said changes will, at least in most cases, be to:MixinFixerUtils
InjectionInfo.getInjectorAnnotation(mixinInfo, method)
Design
The system relies on Mixin internals (as suggested by the class with this name), in similar fashion to the way MixinExtras works, making use of an
IExtension
loaded byOptifabricMixinPlugin
(which is the plugin of the main mixin config) and some hacky reflection. Because it does not rely on mixins, creating custom mappings fromnamed
tointermediary
is unnecessary asRemappingUtils
will be used instead.Error handling
Since this system gives no clue whatsoever that OptiFabric tampered with the mixins of other mods, logging errors is required.
OptifabricSetup.LOGGER
is now used in favor of STDOUT & STDERR, fixing the issue where messages aren't printed in the Minecraft console until the game starts. The logger, named "OptiFabric", is created via log4j'sLogManager
since slf4j doesn't exist in older versions.All errors should be handled by either
OptifabricMixinErrorHandler
orMixinFixerExtension.postApply()
. The latter takes care of any LVT related exceptions thrown by generated error injectors, while the former should take care of any other mixin related error. At the moment, potential exceptions thrown by OptiFabric itself aren't properly handled. Besides the obvious necessity ofproperly logging errors, one of the goals of error handling is to allow the game to start and show the crash screen. A better way of providing the end user with crash information would be a dialogue box, similar to the way Fabric handles mod conflicts, due to the following:
Concrete example: Fabric Model Loading API's
ModelLoaderBakerImpl
fails to apply without a patch. While the game does start (since the exception is caught inModelLoader.bake()
), the font cannot be loaded and there is a re-entrance issue ("Already patched net/minecraft/class_1088$class_7778"). By insisting (not returning when a class has already been patched, which is really bad), the class will successfully be replaced with OptiFine's, but only after heavily spamming the console with said re-entrance logs and "Unable to bake model: ...". I have no idea how to fix the re-entrance problem, but I want to move away from the Minecraft-based crash screen and simply show a dialogue box clearly stating the issue and showing potential fixes (namely downgrading the mod causing issues) anyways.Fabric API 0.86.0+ fix
Quick note
If the Optifine cache in the
.optifine
folder already exists, the new mappings will not take effect. The easiest way of fixing this is manually deleting the.optifine
folder. Users will likely expect the game to work properly if they update to a version with the changelog Fixed Fabric API 0.86.0+ without having to do any additional stuff, making this a slight issue.Testing
The following configurations have been tested:
This should suffice, but you can never be sure. I will do more testing soon.
Fabric Screen API, Architectury, Charm & Cloth port
Testing
The following configurations have been tested:
Due to the fact that the original fix consisted of a lot of mixins (6 for Fabric API and 8 for Architectury) and was required across many versions, the port might have some issues.
Fabric Rendering Data Attach API port & (new) Fabric Block View API fix
Fixing the latter somewhat requires porting the former. I tested the following configurations:
Fixed issues
This list is not exhaustive
fixes #1123 fixes #1124 fixes #1127 fixes #1134 fixes #1136 fixes #1139 fixes #1151 fixes #1153 fixes #1156 fixes #1157 fixes #1161 fixes #1166 fixes #1169 fixes #1172 fixes #1177 fixes #1181 fixes #1182 fixes #1183 fixes #1184 fixes #1185 fixes #1186 fixes #1187 fixes #1188 fixes #1189 fixes #1215 fixes #1226 fixes #1222 fixes #1221 fixes #1216 fixes #1217