diff --git a/Headers/LoaderConfig.h b/Headers/LoaderConfig.h index 6c63fa8..d15774d 100644 --- a/Headers/LoaderConfig.h +++ b/Headers/LoaderConfig.h @@ -5,4 +5,6 @@ @property (nonatomic, strong) NSURL *customLoadUrl; + (instancetype)defaultConfig; + (instancetype)getLoaderConfig; +- (instancetype)init; +- (BOOL)loadConfig; @end \ No newline at end of file diff --git a/Sources/LoaderConfig.m b/Sources/LoaderConfig.m index bfc31f4..bfd6794 100644 --- a/Sources/LoaderConfig.m +++ b/Sources/LoaderConfig.m @@ -4,6 +4,50 @@ @implementation LoaderConfig +- (instancetype)init { + self = [super init]; + if (self) { + self.customLoadUrlEnabled = NO; + self.customLoadUrl = [NSURL URLWithString:@"http://localhost:4040/bunny.js"]; + } + return self; +} + +- (BOOL)loadConfig { + NSURL *loaderConfigUrl = [getPyoncordDirectory() URLByAppendingPathComponent:@"loader.json"]; + BunnyLog(@"Attempting to load config from: %@", loaderConfigUrl.path); + + if ([[NSFileManager defaultManager] fileExistsAtPath:loaderConfigUrl.path]) { + NSError *error = nil; + NSData *data = [NSData dataWithContentsOfURL:loaderConfigUrl]; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; + + if (error) { + BunnyLog(@"Error parsing loader config: %@", error); + return NO; + } + + if (json) { + NSDictionary *customLoadUrl = json[@"customLoadUrl"]; + if (customLoadUrl) { + self.customLoadUrlEnabled = [customLoadUrl[@"enabled"] boolValue]; + NSString *urlString = customLoadUrl[@"url"]; + if (urlString) { + self.customLoadUrl = [NSURL URLWithString:urlString]; + } + } + + BunnyLog(@"Loader config loaded - Custom URL %@: %@", + self.customLoadUrlEnabled ? @"enabled" : @"disabled", + self.customLoadUrl.absoluteString); + return YES; + } + } + + BunnyLog(@"Using default loader config: %@", self.customLoadUrl.absoluteString); + return NO; +} + + (instancetype)defaultConfig { LoaderConfig *config = [[LoaderConfig alloc] init]; config.customLoadUrlEnabled = NO; diff --git a/Sources/Tweak.x b/Sources/Tweak.x index 79f31f1..2fa7468 100644 --- a/Sources/Tweak.x +++ b/Sources/Tweak.x @@ -162,8 +162,9 @@ static LoaderConfig *loaderConfig; BunnyLog(@"Bundle contents: %@", bundleContents); } - pyoncordDirectory = getPyoncordDirectory(); +pyoncordDirectory = getPyoncordDirectory(); loaderConfig = [[LoaderConfig alloc] init]; + [loaderConfig loadConfig]; %init; }