Question

I have a SliderCell in a Preference Bundle for an iOS 7 tweak I am developing. On any 32 but device the tweak works fine when pulling values from the slider. However on 64 bit devices it does not work properly and it always defaults to 0.0

static float blur;
static float tint;

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.bla.blarfr~prefs.plist"];

static void NBLoad()
{
blur = [dict objectForKey:@"blurf"] ? [[dict objectForKey:@"blurf"] floatValue] : 0.0f;
tint = [dict objectForKey:@"tintf"] ? [[dict objectForKey:@"tintf"] floatValue] : 0.0f;
}

%hook UIKBFactory
-(float) tintAlpha {
NBLoad();
if ([[dict objectForKey:@"enabled"] boolValue])
{
    return tint;
}
else
{
    return %orig;
}
}
-(float) blurRadius {
NBLoad();
if ([[dict objectForKey:@"enabled"] boolValue])
{
    return blur;
}
else
{
    return %orig;
}
}
%end

If I do change all of the floats to doubles it works fine on 64 bit and vice versa. Is there any way to make it so that the code works properly on both devices?

Was it helpful?

Solution

I recently was faced with this problem to, and a fellow developer pointed me in the right direction. What you have to do is create two hook groups with %group, add %ctor to the end of your file and %init the groups after a condition. Here's a little example:

%group 32bit
%hook Class
-(float) tintAlpha {
    return float;
}
%end
%end

%group 64bit
%hook Class
-(double) tintAlpha {
    return double;
}
%end
%end

%ctor {
    if (deviceIs64bit) {
        %init(64bit);
    }
    else {
        %init(32bit);
    }
 }

For 'deviceIs64bit', I do a check for hardware version (i.e. iPhone 6,1), everything else I found wasn't runtime compatible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top