Add build script and hook updates

This commit is contained in:
√(noham)²
2026-05-15 19:44:54 +02:00
parent bb174602ba
commit 33f9772c90
8 changed files with 289 additions and 30 deletions

86
src/Config.mm Normal file
View File

@@ -0,0 +1,86 @@
#import "Config.h"
NSString *gConfiguredHost = @"";
NSNumber *gConfiguredPort = @(0);
void saveConfiguration(NSString *host, NSNumber *port) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:host forKey:@"RMHook_Host"];
[defaults setObject:port forKey:@"RMHook_Port"];
[defaults synchronize];
gConfiguredHost = host;
gConfiguredPort = port;
NSLog(@"[RMHook-iOS] Saved config - Host: %@, Port: %@", gConfiguredHost, gConfiguredPort);
}
void loadConfiguration() {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *host = [defaults stringForKey:@"RMHook_Host"];
NSNumber *port = [defaults objectForKey:@"RMHook_Port"];
if (host && host.length > 0 && port && [port intValue] > 0) {
gConfiguredHost = host;
gConfiguredPort = port;
NSLog(@"[RMHook-iOS] Loaded config - Host: %@, Port: %@", gConfiguredHost, gConfiguredPort);
}
}
void showConfigAlert() {
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow *window = nil;
if (@available(iOS 13.0, *)) {
for (UIWindowScene *scene in [UIApplication sharedApplication].connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive) {
for (UIWindow *w in scene.windows) {
if (w.isKeyWindow) {
window = w;
break;
}
}
}
}
}
if (!window) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
window = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
}
if (!window || !window.rootViewController) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
showConfigAlert();
});
return;
}
UIViewController *rootVC = window.rootViewController;
while (rootVC.presentedViewController) {
rootVC = rootVC.presentedViewController;
}
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"RMHook"
message:@"First Launch: Enter Host and Port"
preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Host (e.g. example.com)";
textField.text = @"example.com";
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Port (e.g. 443)";
textField.text = @"443";
textField.keyboardType = UIKeyboardTypeNumberPad;
}];
UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *host = alert.textFields[0].text;
NSNumber *port = @([alert.textFields[1].text integerValue]);
saveConfiguration(host, port);
}];
[alert addAction:saveAction];
[rootVC presentViewController:alert animated:YES completion:nil];
});
}