88#define kCurseForgeGameIDMinecraft 432
99#define kCurseForgeClassIDModpack 4471
1010#define kCurseForgeClassIDMod 6
11+ #define kCurseForgeClassIDResourcePack 12
12+ #define kCurseForgeClassIDShader 6552
1113#define kCurseForgePageSize 50
1214#define kCurseForgeModLoaderForge 1
1315#define kCurseForgeModLoaderFabric 4
@@ -113,6 +115,19 @@ - (NSArray *)normalizedCurseForgeDependencies:(NSArray *)dependencies {
113115 return result;
114116}
115117
118+ - (NSString *)installDirectoryForProject : (NSDictionary *)project {
119+ NSInteger classID = [project[@" classId" ] respondsToSelector: @selector (integerValue )] ? [project[@" classId" ] integerValue ] : kCurseForgeClassIDMod ;
120+ NSDictionary *links = [project[@" links" ] isKindOfClass: NSDictionary .class] ? project[@" links" ] : nil ;
121+ NSString *websiteURL = [links[@" websiteUrl" ] isKindOfClass: NSString .class] ? [links[@" websiteUrl" ] lowercaseString ] : @" " ;
122+ if (classID == kCurseForgeClassIDResourcePack || [websiteURL containsString: @" /texture-packs/" ]) {
123+ return @" resourcepacks" ;
124+ }
125+ if (classID == kCurseForgeClassIDShader || [websiteURL containsString: @" /shaders/" ]) {
126+ return @" shaderpacks" ;
127+ }
128+ return @" mods" ;
129+ }
130+
116131- (NSDictionary *)modManagerRecordForFile : (NSDictionary *)file projectID : (NSNumber *)projectID fileName : (NSString *)fileName projectCache : (NSMutableDictionary *)projectCache {
117132 NSDictionary *project = [self projectInfoForProjectID: projectID cache: projectCache];
118133 NSDictionary *logo = [project[@" logo" ] isKindOfClass: NSDictionary .class] ? project[@" logo" ] : nil ;
@@ -136,6 +151,8 @@ - (NSDictionary *)modManagerRecordForFile:(NSDictionary *)file projectID:(NSNumb
136151 @" gameVersion" : [self minecraftVersionForFile: file],
137152 @" dependencies" : [self normalizedCurseForgeDependencies: ([file[@" dependencies" ] isKindOfClass: NSArray .class] ? file[@" dependencies" ] : @[])],
138153 @" dependencyMetadataCheckedAt" : @([[NSDate date ] timeIntervalSince1970 ]),
154+ @" artifactType" : @" mod" ,
155+ @" installDirectory" : @" mods" ,
139156 @" enabled" : @YES
140157 };
141158}
@@ -215,7 +232,14 @@ - (NSString *)manualDownloadPageURLForFile:(NSDictionary *)file projectID:(NSNum
215232 NSString *slug = project[@" slug" ];
216233 if ([slug isKindOfClass: NSString .class] && slug.length > 0 ) {
217234 NSInteger classID = [project[@" classId" ] respondsToSelector: @selector (integerValue )] ? [project[@" classId" ] integerValue ] : kCurseForgeClassIDMod ;
218- NSString *section = classID == kCurseForgeClassIDModpack ? @" modpacks" : @" mc-mods" ;
235+ NSString *section = @" mc-mods" ;
236+ if (classID == kCurseForgeClassIDModpack ) {
237+ section = @" modpacks" ;
238+ } else if (classID == kCurseForgeClassIDResourcePack ) {
239+ section = @" texture-packs" ;
240+ } else if (classID == kCurseForgeClassIDShader ) {
241+ section = @" shaders" ;
242+ }
219243 return [NSString stringWithFormat: @" https://www.curseforge.com/minecraft/%@ /%@ /download/%@ " , section, slug, fileID];
220244 }
221245
@@ -368,7 +392,8 @@ - (NSMutableArray *)searchModWithFilters:(NSDictionary<NSString *, NSString *> *
368392 @" id" : modID,
369393 @" title" : title,
370394 @" description" : description,
371- @" imageUrl" : imageUrl
395+ @" imageUrl" : imageUrl,
396+ @" classId" : mod[@" classId" ] ?: @0
372397 }.mutableCopy];
373398 }
374399
@@ -574,7 +599,9 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
574599 return ;
575600 }
576601
577- [NSFileManager .defaultManager removeItemAtPath: [destPath stringByAppendingPathComponent: @" mods" ] error: nil ];
602+ for (NSString *managedDirectory in @[@" mods" , @" resourcepacks" , @" shaderpacks" ]) {
603+ [NSFileManager .defaultManager removeItemAtPath: [destPath stringByAppendingPathComponent: managedDirectory] error: nil ];
604+ }
578605
579606 NSMutableArray *manualDownloads = [NSMutableArray new ];
580607 NSMutableArray *modManagerRecords = [NSMutableArray new ];
@@ -600,14 +627,18 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
600627 return ;
601628 }
602629
603- NSString *relativePath = [@" mods" stringByAppendingPathComponent: fileName];
630+ NSDictionary *project = [self projectInfoForProjectID: projectID cache: projectCache];
631+ NSString *installDirectory = [self installDirectoryForProject: project];
632+ NSString *relativePath = [installDirectory stringByAppendingPathComponent: fileName];
604633 NSString *path = [destPath stringByAppendingPathComponent: relativePath];
605634 NSUInteger size = [file[@" fileLength" ] respondsToSelector: @selector (unsignedLongLongValue )] ? [file[@" fileLength" ] unsignedLongLongValue ] : 0 ;
606635 if (size == 0 ) {
607636 size = [file[@" fileSizeOnDisk" ] respondsToSelector: @selector (unsignedLongLongValue )] ? [file[@" fileSizeOnDisk" ] unsignedLongLongValue ] : 0 ;
608637 }
609638 NSString *sha = [self sha1HashForFile: file];
610- [modManagerRecords addObject: [self modManagerRecordForFile: file projectID: projectID fileName: fileName projectCache: projectCache]];
639+ if ([installDirectory isEqualToString: @" mods" ]) {
640+ [modManagerRecords addObject: [self modManagerRecordForFile: file projectID: projectID fileName: fileName projectCache: projectCache]];
641+ }
611642 NSString *url = [self downloadURLForFile: file projectID: projectID];
612643 if (url.length == 0 ) {
613644 NSString *manualURL = [self manualDownloadPageURLForFile: file projectID: projectID cache: projectCache];
0 commit comments