2007-10-11 23:11:58 +00:00
|
|
|
//
|
|
|
|
// GameFile.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 5/29/06.
|
|
|
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <GME/gme.h>
|
|
|
|
|
|
|
|
#import "GameContainer.h"
|
|
|
|
#import "GameDecoder.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
@implementation GameContainer
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
2007-10-20 03:17:43 +00:00
|
|
|
//There doesn't seem to be a way to get this list. These are the only multitrack types.
|
2019-11-08 23:04:43 +00:00
|
|
|
return [NSArray arrayWithObjects:@"ay", @"gbs", @"hes", @"kss", @"nsf", @"nsfe", @"sap", @"sgc",
|
|
|
|
@"vgm",@"vgz", // These are included so they can override AdPlug
|
|
|
|
nil];
|
2007-10-11 23:11:58 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:56:23 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
+ (float)priority
|
|
|
|
{
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
//This really should be source...
|
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
|
|
|
{
|
2013-10-11 12:41:36 +00:00
|
|
|
if ([url fragment]) {
|
|
|
|
// input url already has fragment defined - no need to expand further
|
|
|
|
return [NSMutableArray arrayWithObject:url];
|
|
|
|
}
|
2019-11-08 23:04:43 +00:00
|
|
|
|
|
|
|
// Dodge both VGMStream and AdPlug
|
|
|
|
NSString * extension = [url pathExtension];
|
|
|
|
if (extension && ([extension caseInsensitiveCompare:@"vgm"] == NSOrderedSame ||
|
|
|
|
[extension caseInsensitiveCompare:@"vgz"] == NSOrderedSame))
|
|
|
|
{
|
|
|
|
return [NSMutableArray arrayWithObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingString:@"#0"]]];
|
|
|
|
}
|
2013-10-11 12:41:36 +00:00
|
|
|
|
2013-10-04 16:00:18 +00:00
|
|
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
|
|
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
|
|
|
|
|
|
|
if (![source open:url])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (![source seekable])
|
|
|
|
return 0;
|
2007-10-11 23:11:58 +00:00
|
|
|
|
2013-10-04 16:00:18 +00:00
|
|
|
[source seek:0 whence:SEEK_END];
|
|
|
|
long size = [source tell];
|
|
|
|
[source seek:0 whence:SEEK_SET];
|
|
|
|
|
|
|
|
void * data = malloc(size);
|
|
|
|
[source read:data amount:size];
|
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
Music_Emu *emu;
|
2013-10-04 16:00:18 +00:00
|
|
|
gme_err_t error = gme_open_data(data, size, &emu, 44100);
|
|
|
|
free(data);
|
|
|
|
|
2009-07-16 02:11:55 +00:00
|
|
|
if (NULL != error) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: Error loading file: %@ %s", [url path], error);
|
2009-07-16 02:11:55 +00:00
|
|
|
return [NSArray arrayWithObject:url];
|
|
|
|
}
|
2016-08-05 01:55:13 +00:00
|
|
|
|
|
|
|
NSURL *m3uurl = [url URLByDeletingPathExtension];
|
|
|
|
m3uurl = [m3uurl URLByAppendingPathExtension:@"m3u"];
|
2016-09-16 09:49:17 +00:00
|
|
|
id<CogSource> m3usrc = [audioSourceClass audioSourceForURL:m3uurl];
|
|
|
|
if ([m3usrc open:m3uurl])
|
2016-08-05 01:55:13 +00:00
|
|
|
{
|
2016-09-16 09:49:17 +00:00
|
|
|
if ([m3usrc seekable])
|
2016-08-05 01:55:13 +00:00
|
|
|
{
|
2016-09-16 09:49:17 +00:00
|
|
|
[m3usrc seek:0 whence:SEEK_END];
|
|
|
|
size = [m3usrc tell];
|
|
|
|
[m3usrc seek:0 whence:SEEK_SET];
|
2016-08-05 01:55:13 +00:00
|
|
|
|
|
|
|
data = malloc(size);
|
2016-09-16 09:49:17 +00:00
|
|
|
[m3usrc read:data amount:size];
|
2016-08-05 01:55:13 +00:00
|
|
|
|
|
|
|
error = gme_load_m3u_data(emu, data, size);
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
ALog(@"M3U loaded: %s", error ? error : "no error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
int track_count = gme_track_count(emu);
|
2007-10-19 02:23:10 +00:00
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
NSMutableArray *tracks = [NSMutableArray array];
|
2007-10-19 02:23:10 +00:00
|
|
|
|
2007-10-11 23:11:58 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < track_count; i++) {
|
|
|
|
[tracks addObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%i", i]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|