Change bunny to revenge

This commit is contained in:
Cristiandis 2024-11-15 11:45:12 +01:00
parent 051816832e
commit 3f5723ea20
6 changed files with 88 additions and 88 deletions

View file

@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
#define LOG_PREFIX @"[Bunny]"
#define BunnyLog(fmt, ...) NSLog((LOG_PREFIX @" " fmt), ##__VA_ARGS__)
#define LOG_PREFIX @"[Revenge]"
#define RevengeLog(fmt, ...) NSLog((LOG_PREFIX @" " fmt), ##__VA_ARGS__)

View file

@ -7,12 +7,12 @@ include $(THEOS)/makefiles/common.mk
TWEAK_NAME = Revenge
BUNDLE_NAME = RevengeResources
Bunny_FILES = $(wildcard Sources/*.x Sources/*.m Sources/**/*.x Sources/**/*.m)
Bunny_CFLAGS = -fobjc-arc -DPACKAGE_VERSION='@"$(THEOS_PACKAGE_BASE_VERSION)"' -I$(THEOS_PROJECT_DIR)/Headers
Bunny_FRAMEWORKS = Foundation UIKit CoreGraphics CoreText CoreFoundation
Revenge_FILES = $(wildcard Sources/*.x Sources/*.m Sources/**/*.x Sources/**/*.m)
Revenge_CFLAGS = -fobjc-arc -DPACKAGE_VERSION='@"$(THEOS_PACKAGE_BASE_VERSION)"' -I$(THEOS_PROJECT_DIR)/Headers
Revenge_FRAMEWORKS = Foundation UIKit CoreGraphics CoreText CoreFoundation
BunnyResources_INSTALL_PATH = "/Library/Application\ Support/"
BunnyResources_RESOURCE_DIRS = Resources
RevengeResources_INSTALL_PATH = "/Library/Application\ Support/"
RevengeResources_RESOURCE_DIRS = Resources
include $(THEOS_MAKE_PATH)/tweak.mk
include $(THEOS_MAKE_PATH)/bundle.mk

View file

@ -15,7 +15,7 @@ NSMutableDictionary<NSString *, NSString *> *fontMap;
UIFontDescriptor *replacementDescriptor = [UIFontDescriptor fontDescriptorWithName:replacementName size:size];
UIFontDescriptor *fallbackDescriptor = [replacementDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorNameAttribute: @[name]}];
UIFontDescriptor *finalDescriptor = [replacementDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorCascadeListAttribute: @[fallbackDescriptor]}];
return [UIFont fontWithDescriptor:finalDescriptor size:size];
}
return %orig;
@ -26,7 +26,7 @@ NSMutableDictionary<NSString *, NSString *> *fontMap;
if (replacementName) {
UIFontDescriptor *replacementDescriptor = [UIFontDescriptor fontDescriptorWithName:replacementName size:size];
UIFontDescriptor *finalDescriptor = [replacementDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorCascadeListAttribute: @[descriptor]}];
return [UIFont fontWithDescriptor:finalDescriptor size:size];
}
return %orig;
@ -51,77 +51,77 @@ NSMutableDictionary<NSString *, NSString *> *fontMap;
%end
void patchFonts(NSDictionary<NSString *, NSString *> *mainFonts, NSString *fontDefName) {
BunnyLog(@"patchFonts called with fonts: %@ and def name: %@", mainFonts, fontDefName);
RevengeLog(@"patchFonts called with fonts: %@ and def name: %@", mainFonts, fontDefName);
if (!fontMap) {
BunnyLog(@"Creating new fontMap");
RevengeLog(@"Creating new fontMap");
fontMap = [NSMutableDictionary dictionary];
}
NSString *fontJson = [NSString stringWithContentsOfURL:[getPyoncordDirectory() URLByAppendingPathComponent:@"fonts.json"]
encoding:NSUTF8StringEncoding
error:nil];
if (fontJson) {
BunnyLog(@"Found existing fonts.json: %@", fontJson);
RevengeLog(@"Found existing fonts.json: %@", fontJson);
}
for (NSString *fontName in mainFonts) {
NSString *url = mainFonts[fontName];
BunnyLog(@"Replacing font %@ with URL: %@", fontName, url);
RevengeLog(@"Replacing font %@ with URL: %@", fontName, url);
NSURL *fontURL = [NSURL URLWithString:url];
NSString *fontExtension = fontURL.pathExtension;
NSURL *fontCachePath = [[[getPyoncordDirectory()
URLByAppendingPathComponent:@"downloads" isDirectory:YES]
URLByAppendingPathComponent:@"fonts" isDirectory:YES]
URLByAppendingPathComponent:fontDefName isDirectory:YES];
fontCachePath = [fontCachePath URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", fontName, fontExtension]];
NSURL *parentDir = [fontCachePath URLByDeletingLastPathComponent];
if (![[NSFileManager defaultManager] fileExistsAtPath:parentDir.path]) {
BunnyLog(@"Creating parent directory: %@", parentDir.path);
RevengeLog(@"Creating parent directory: %@", parentDir.path);
[[NSFileManager defaultManager] createDirectoryAtURL:parentDir
withIntermediateDirectories:YES
attributes:nil
error:nil];
}
if (![[NSFileManager defaultManager] fileExistsAtPath:fontCachePath.path]) {
BunnyLog(@"Downloading font %@ from %@", fontName, url);
RevengeLog(@"Downloading font %@ from %@", fontName, url);
NSData *data = [NSData dataWithContentsOfURL:fontURL];
if (data) {
BunnyLog(@"Writing font data to: %@", fontCachePath.path);
RevengeLog(@"Writing font data to: %@", fontCachePath.path);
[data writeToURL:fontCachePath atomically:YES];
}
}
NSData *fontData = [NSData dataWithContentsOfURL:fontCachePath];
if (fontData) {
BunnyLog(@"Registering font %@ with provider", fontName);
RevengeLog(@"Registering font %@ with provider", fontName);
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)fontData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (font) {
CFStringRef postScriptName = CGFontCopyPostScriptName(font);
CTFontRef existingFont = CTFontCreateWithName(postScriptName, 0, NULL);
if (existingFont) {
CFErrorRef unregisterError = NULL;
if (!CTFontManagerUnregisterGraphicsFont(font, &unregisterError)) {
BunnyLog(@"Failed to deregister font %@: %@", (__bridge NSString *)postScriptName,
RevengeLog(@"Failed to deregister font %@: %@", (__bridge NSString *)postScriptName,
unregisterError ? (__bridge NSString *)CFErrorCopyDescription(unregisterError) : @"Unknown error");
if (unregisterError) CFRelease(unregisterError);
}
CFRelease(existingFont);
}
CFErrorRef error = NULL;
if (CTFontManagerRegisterGraphicsFont(font, &error)) {
fontMap[fontName] = (__bridge NSString *)postScriptName;
BunnyLog(@"Successfully registered font %@ to %@", fontName, (__bridge NSString *)postScriptName);
RevengeLog(@"Successfully registered font %@ to %@", fontName, (__bridge NSString *)postScriptName);
NSError *jsonError;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:fontMap options:0 error:&jsonError];
if (!jsonError) {
@ -129,22 +129,22 @@ void patchFonts(NSDictionary<NSString *, NSString *> *mainFonts, NSString *fontD
}
} else {
NSString *errorDesc = error ? (__bridge NSString *)CFErrorCopyDescription(error) : @"Unknown error";
BunnyLog(@"Failed to register font %@: %@", fontName, errorDesc);
RevengeLog(@"Failed to register font %@: %@", fontName, errorDesc);
if (error) CFRelease(error);
}
CFRelease(postScriptName);
CFRelease(font);
}
CGDataProviderRelease(provider);
}
}
}
}
%ctor {
@autoreleasepool {
fontMap = [NSMutableDictionary dictionary];
BunnyLog(@"Font hooks initialized");
RevengeLog(@"Font hooks initialized");
%init;
}
}
}

View file

@ -12,7 +12,7 @@
}
+ (instancetype)getLoaderConfig {
BunnyLog(@"Getting loader config");
RevengeLog(@"Getting loader config");
NSURL *loaderConfigUrl = [getPyoncordDirectory() URLByAppendingPathComponent:@"loader.json"];
@ -35,7 +35,7 @@
}
}
BunnyLog(@"Couldn't get loader config");
RevengeLog(@"Couldn't get loader config");
return [LoaderConfig defaultConfig];
}

View file

@ -4,34 +4,34 @@
#import <objc/runtime.h>
void swizzleDCDThemeColor(NSDictionary<NSString *, NSArray<NSString *> *> *semanticColors) {
BunnyLog(@"Swizzling DCDThemeColor");
RevengeLog(@"Swizzling DCDThemeColor");
Class DCDTheme = NSClassFromString(@"DCDTheme");
Class dcdThemeTarget = object_getClass(DCDTheme);
SEL themeIndexSelector = NSSelectorFromString(@"themeIndex");
Method themeIndexMethod = class_getClassMethod(dcdThemeTarget, themeIndexSelector);
IMP themeIndexImpl = method_getImplementation(themeIndexMethod);
int (*themeIndex)(id, SEL) = (int (*)(id, SEL))themeIndexImpl;
Class DCDThemeColor = NSClassFromString(@"DCDThemeColor");
Class target = object_getClass(DCDThemeColor);
unsigned int methodCount;
Method *methods = class_copyMethodList(target, &methodCount);
for (unsigned int i = 0; i < methodCount; i++) {
Method method = methods[i];
SEL selector = method_getName(method);
NSString *methodName = NSStringFromSelector(selector);
NSArray<NSString *> *semanticColor = semanticColors[methodName];
if (semanticColor) {
BunnyLog(@"Swizzling %@", methodName);
RevengeLog(@"Swizzling %@", methodName);
IMP originalImpl = method_getImplementation(method);
UIColor *(*original)(id, SEL) = (UIColor *(*)(id, SEL))originalImpl;
id block = ^UIColor *(id self) {
int themeIndexVal = themeIndex(dcdThemeTarget, themeIndexSelector);
if (semanticColor.count - 1 >= themeIndexVal) {
@ -42,41 +42,41 @@ void swizzleDCDThemeColor(NSDictionary<NSString *, NSArray<NSString *> *> *seman
}
return original(target, selector);
};
IMP newImpl = imp_implementationWithBlock(block);
method_setImplementation(method, newImpl);
}
}
free(methods);
}
void swizzleUIColor(NSDictionary<NSString *, NSString *> *rawColors) {
BunnyLog(@"Swizzling UIColor");
RevengeLog(@"Swizzling UIColor");
Class UIColorClass = NSClassFromString(@"UIColor");
Class target = object_getClass(UIColorClass);
unsigned int methodCount;
Method *methods = class_copyMethodList(target, &methodCount);
for (unsigned int i = 0; i < methodCount; i++) {
Method method = methods[i];
SEL selector = method_getName(method);
NSString *methodName = NSStringFromSelector(selector);
NSString *rawColor = rawColors[methodName];
if (rawColor) {
BunnyLog(@"Swizzling %@", methodName);
RevengeLog(@"Swizzling %@", methodName);
id block = ^UIColor *(id self) {
return hexToUIColor(rawColor);
};
IMP newImpl = imp_implementationWithBlock(block);
method_setImplementation(method, newImpl);
}
}
free(methods);
}
}

View file

@ -8,14 +8,14 @@
static NSURL *source;
static BOOL isJailbroken;
static NSString *bunnyPatchesBundlePath;
static NSString *revengePatchesBundlePath;
static NSURL *pyoncordDirectory;
static LoaderConfig *loaderConfig;
%hook NSFileManager
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier {
BunnyLog(@"containerURLForSecurityApplicationGroupIdentifier called! %@",
RevengeLog(@"containerURLForSecurityApplicationGroupIdentifier called! %@",
groupIdentifier ?: @"nil");
if (isJailbroken) {
@ -36,22 +36,22 @@ static LoaderConfig *loaderConfig;
return %orig;
}
NSBundle *bunnyPatchesBundle = [NSBundle bundleWithPath:bunnyPatchesBundlePath];
if (!bunnyPatchesBundle) {
BunnyLog(@"Failed to load BunnyPatches bundle from path: %@", bunnyPatchesBundlePath);
NSBundle *revengePatchesBundle = [NSBundle bundleWithPath:revengePatchesBundlePath];
if (!revengePatchesBundle) {
RevengeLog(@"Failed to load RevengePatches bundle from path: %@", revengePatchesBundlePath);
showErrorAlert(@"Loader Error", @"Failed to initialize mod loader. Please reinstall the tweak.");
return %orig;
}
NSURL *patchPath = [bunnyPatchesBundle URLForResource:@"payload-base" withExtension:@"js"];
NSURL *patchPath = [revengePatchesBundle URLForResource:@"payload-base" withExtension:@"js"];
if (!patchPath) {
BunnyLog(@"Failed to find payload-base.js in bundle");
RevengeLog(@"Failed to find payload-base.js in bundle");
showErrorAlert(@"Loader Error", @"Failed to initialize mod loader. Please reinstall the tweak.");
return %orig;
}
NSData *patchData = [NSData dataWithContentsOfURL:patchPath];
BunnyLog(@"Injecting loader");
RevengeLog(@"Injecting loader");
%orig(patchData, source, YES);
__block NSData *bundle = [NSData dataWithContentsOfURL:[pyoncordDirectory URLByAppendingPathComponent:@"bundle.js"]];
@ -62,10 +62,10 @@ static LoaderConfig *loaderConfig;
NSURL *bundleUrl;
if (loaderConfig.customLoadUrlEnabled && loaderConfig.customLoadUrl) {
bundleUrl = loaderConfig.customLoadUrl;
BunnyLog(@"Using custom load URL: %@", bundleUrl.absoluteString);
RevengeLog(@"Using custom load URL: %@", bundleUrl.absoluteString);
} else {
bundleUrl = [NSURL URLWithString:@"https://github.com/revenge-mod/revenge-bundle/releases/latest/download/revenge.min.js"];
BunnyLog(@"Using default bundle URL: %@", bundleUrl.absoluteString);
RevengeLog(@"Using default bundle URL: %@", bundleUrl.absoluteString);
}
NSMutableURLRequest *bundleRequest = [NSMutableURLRequest requestWithURL:bundleUrl
@ -114,13 +114,13 @@ static LoaderConfig *loaderConfig;
NSError *jsonError;
NSDictionary *fontDict = [NSJSONSerialization JSONObjectWithData:fontData options:0 error:&jsonError];
if (!jsonError && fontDict[@"main"]) {
BunnyLog(@"Found font configuration, applying...");
RevengeLog(@"Found font configuration, applying...");
patchFonts(fontDict[@"main"], fontDict[@"name"]);
}
}
if (bundle) {
BunnyLog(@"Executing JS bundle");
RevengeLog(@"Executing JS bundle");
%orig(bundle, source, async);
}
@ -134,7 +134,7 @@ static LoaderConfig *loaderConfig;
if (!error) {
for (NSURL *fileURL in contents) {
if ([[fileURL pathExtension] isEqualToString:@"js"]) {
BunnyLog(@"Executing preload JS file %@", fileURL.absoluteString);
RevengeLog(@"Executing preload JS file %@", fileURL.absoluteString);
NSData *data = [NSData dataWithContentsOfURL:fileURL];
if (data) {
%orig(data, source, async);
@ -142,7 +142,7 @@ static LoaderConfig *loaderConfig;
}
}
} else {
BunnyLog(@"Error reading contents of preloads directory");
RevengeLog(@"Error reading contents of preloads directory");
}
}
@ -153,30 +153,30 @@ static LoaderConfig *loaderConfig;
%ctor {
@autoreleasepool {
source = [NSURL URLWithString:@"bunny"];
source = [NSURL URLWithString:@"revenge"];
NSString *install_prefix = @"/var/jb";
isJailbroken = [[NSFileManager defaultManager] fileExistsAtPath:install_prefix];
NSString *bundlePath = [NSString stringWithFormat:@"%@/Library/Application Support/BunnyResources.bundle", install_prefix];
BunnyLog(@"Is jailbroken: %d", isJailbroken);
BunnyLog(@"Bundle path for jailbroken: %@", bundlePath);
NSString *bundlePath = [NSString stringWithFormat:@"%@/Library/Application Support/RevengeResources.bundle", install_prefix];
RevengeLog(@"Is jailbroken: %d", isJailbroken);
RevengeLog(@"Bundle path for jailbroken: %@", bundlePath);
NSString *jailedPath = [[NSBundle mainBundle].bundleURL.path stringByAppendingPathComponent:@"BunnyResources.bundle"];
BunnyLog(@"Bundle path for jailed: %@", jailedPath);
NSString *jailedPath = [[NSBundle mainBundle].bundleURL.path stringByAppendingPathComponent:@"RevengeResources.bundle"];
RevengeLog(@"Bundle path for jailed: %@", jailedPath);
bunnyPatchesBundlePath = isJailbroken ? bundlePath : jailedPath;
BunnyLog(@"Selected bundle path: %@", bunnyPatchesBundlePath);
revengePatchesBundlePath = isJailbroken ? bundlePath : jailedPath;
RevengeLog(@"Selected bundle path: %@", revengePatchesBundlePath);
BOOL bundleExists = [[NSFileManager defaultManager] fileExistsAtPath:bunnyPatchesBundlePath];
BunnyLog(@"Bundle exists at path: %d", bundleExists);
BOOL bundleExists = [[NSFileManager defaultManager] fileExistsAtPath:revengePatchesBundlePath];
RevengeLog(@"Bundle exists at path: %d", bundleExists);
NSError *error = nil;
NSArray *bundleContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bunnyPatchesBundlePath error:&error];
NSArray *bundleContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:revengePatchesBundlePath error:&error];
if (error) {
BunnyLog(@"Error listing bundle contents: %@", error);
RevengeLog(@"Error listing bundle contents: %@", error);
} else {
BunnyLog(@"Bundle contents: %@", bundleContents);
RevengeLog(@"Bundle contents: %@", bundleContents);
}
pyoncordDirectory = getPyoncordDirectory();