mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 23:12:11 +00:00
Fix some version checks to properly respect *major* class version
This commit is contained in:
1 parent
33c1d2ee0d
commit
0dc21a78ee
3 files changed
+32
-6
No files matched your search
@@ -671,9 +671,9 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
|
||||
private CompatibilityLevel maxCompatibleLevel;
|
||||
|
||||
private CompatibilityLevel(int ver, int classMajorVersion, int languageFeatures) {
|
||||
private CompatibilityLevel(int ver, int classVersion, int languageFeatures) {
|
||||
this.ver = ver;
|
||||
this.classVersion = classMajorVersion & 0xFF;
|
||||
this.classVersion = classVersion;
|
||||
this.languageFeatures = languageFeatures;
|
||||
}
|
||||
|
||||
@@ -702,6 +702,13 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
return this.classVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major class version expected at this compatibility level
|
||||
*/
|
||||
public int getClassMajorVersion() {
|
||||
return this.classVersion & 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all supported language features
|
||||
*/
|
||||
|
||||
@@ -434,7 +434,11 @@ class MixinApplicatorStandard {
|
||||
if (mixin.shouldSetSourceFile()) {
|
||||
this.targetClass.sourceFile = mixin.getSourceFile();
|
||||
}
|
||||
this.targetClass.version = Math.max(this.targetClass.version, mixin.getMinRequiredClassVersion());
|
||||
|
||||
int requiredVersion = mixin.getMinRequiredClassVersion();
|
||||
if ((requiredVersion & 0xFFFF) > (this.targetClass.version & 0xFFFF)) {
|
||||
this.targetClass.version = requiredVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1071,13 +1071,28 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
* @param version version to require
|
||||
*/
|
||||
protected void requireVersion(int version) {
|
||||
this.minRequiredClassVersion = Math.max(this.minRequiredClassVersion, version);
|
||||
int majorVersion = version & 0xFFFF;
|
||||
int minorVersion = (version >> 16) & 0xFFFF;
|
||||
|
||||
if (majorVersion <= (this.minRequiredClassVersion & 0xFFFF)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.minRequiredClassVersion = version;
|
||||
|
||||
// This validation is done on the mixin beforehand, however it's still
|
||||
// possible that an upstream transformer can inject unsupported
|
||||
// instructions without updating the class version.
|
||||
if ((version & 0xFFFF) > ASM.getMaxSupportedClassVersionMajor()) {
|
||||
throw new InvalidMixinException(this, "Unsupported mixin class version " + version);
|
||||
if (majorVersion > ASM.getMaxSupportedClassVersionMajor()) {
|
||||
throw new InvalidMixinException(this, String.format("Unsupported mixin class version %d.%d. ASM supports %s",
|
||||
majorVersion, minorVersion, ASM.getClassVersionString()));
|
||||
}
|
||||
|
||||
CompatibilityLevel compatibilityLevel = MixinEnvironment.getCompatibilityLevel();
|
||||
if (majorVersion > compatibilityLevel.getClassMajorVersion()) {
|
||||
MixinTargetContext.logger.warn(
|
||||
"{}: Class version {}.{} required is higher than the class version supported by the current compatibility level {} ",
|
||||
this, majorVersion, minorVersion, compatibilityLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user