Skip to content

Commit

Permalink
Fix[parser]: remove bad args specified by custom version metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Mar 1, 2024
1 parent faadb60 commit 0f518de
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Natives/MinecraftResourceUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ + (void)insertSafety:(NSMutableDictionary *)targetVer from:(NSDictionary *)fromV
}
}

+ (NSInteger)numberOfArgsToSkipForArg:(NSString *)arg {
if (![arg isKindOfClass:NSString.class]) {
// Skip non-string arg
return 1;
} else if ([arg hasPrefix:@"-cp"]) {
// Skip "-cp <classpath>"
return 2;
} else if ([arg hasPrefix:@"-Djava.library.path="]) {
return 1;
} else if ([arg hasPrefix:@"-XX:HeapDumpPath"]) {
return 1;
} else {
return 0;
}
}

+ (void)tweakVersionJson:(NSMutableDictionary *)json {
// Exclude some libraries
for (NSMutableDictionary *library in json[@"libraries"]) {
Expand Down Expand Up @@ -109,13 +125,19 @@ + (void)tweakVersionJson:(NSMutableDictionary *)json {
@"${library_directory}": [NSString stringWithFormat:@"%s/libraries", getenv("POJAV_GAME_DIR")],
@"${version_name}": json[@"id"]
};
for (id arg in json[@"arguments"][@"jvm"]) {
if ([arg isKindOfClass:NSString.class]) {
int argsToSkip = 0;
for (NSString *arg in json[@"arguments"][@"jvm"]) {
if (argsToSkip == 0) {
argsToSkip = [self numberOfArgsToSkipForArg:arg];
}
if (argsToSkip == 0) {
NSString *argStr = arg;
for (NSString *key in varArgMap.allKeys) {
argStr = [argStr stringByReplacingOccurrencesOfString:key withString:varArgMap[key]];
}
[json[@"arguments"][@"jvm_processed"] addObject:argStr];
} else {
argsToSkip--;
}
}
}
Expand Down

0 comments on commit 0f518de

Please sign in to comment.