Skip to content

Commit

Permalink
Update for UnrealEngine's wrong file path
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu-ga committed Dec 7, 2024
1 parent c996174 commit ab77730
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions PlayTools/PlayLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,26 @@ static OSStatus pt_SecItemDelete(CFDictionaryRef query) {
DYLD_INTERPOSE(pt_SecItemUpdate, SecItemUpdate)
DYLD_INTERPOSE(pt_SecItemDelete, SecItemDelete)

static bool is_ue4 = false;

static char const* ue4_fix_filename(char const* filename) {
char const UE4_PATTERN[] = "Library//Users";
char const* p = NULL;
if (!is_ue4) {
return filename;
}

if ((p = strstr(filename, UE4_PATTERN))) {
return p + 8;
static uint8_t ue_status = 0;

static char const* ue_fix_filename(char const* filename) {
static char const UE_PATTERN[] = "//Users/";

char const* p = filename;
if (ue_status == 2) {
char const* last_p = p;
while ((p = strstr(p, UE_PATTERN))) {
last_p = p + 1;
}

return last_p;
}

return filename;
return p;
}

static int pt_open(char const* restrict filename, int oflag, ... ) {
filename = ue4_fix_filename(filename);
filename = ue_fix_filename(filename);

if (oflag == O_CREAT) {
int mod;
Expand All @@ -212,19 +214,19 @@ static int pt_open(char const* restrict filename, int oflag, ... ) {
}

static int pt_stat(char const* restrict path, struct stat* restrict buf) {
return stat(ue4_fix_filename(path), buf);
return stat(ue_fix_filename(path), buf);
}

static int pt_access(char const* path, int mode) {
return access(ue4_fix_filename(path), mode);
return access(ue_fix_filename(path), mode);
}

static int pt_rename(char const* restrict old_name, char const* restrict new_name) {
return rename(ue4_fix_filename(old_name), ue4_fix_filename(new_name));
return rename(ue_fix_filename(old_name), ue_fix_filename(new_name));
}

static int pt_unlink(char const* path) {
return unlink(ue4_fix_filename(path));
return unlink(ue_fix_filename(path));
}

DYLD_INTERPOSE(pt_open, open)
Expand All @@ -237,15 +239,23 @@ @implementation PlayLoader

static void __attribute__((constructor)) initialize(void) {
[PlayCover launch];

NSURL* appFolder = [[NSBundle mainBundle] bundleURL];
NSURL* ue4commandlinetxt = [appFolder URLByAppendingPathComponent:@"ue4commandline.txt"];

is_ue4 |= !access(
[[ue4commandlinetxt path] cStringUsingEncoding:NSUTF8StringEncoding], F_OK
);
if (is_ue4) {
[PlayKeychain debugLogger: [NSString stringWithFormat:@"Is it UE4? : %@", @(is_ue4)]];

if (ue_status == 0) {
NSURL* appFolder = [[NSBundle mainBundle] bundleURL];
NSArray* ueFiles = @[
[appFolder URLByAppendingPathComponent:@"ue4commandline.txt"],
[appFolder URLByAppendingPathComponent:@"uecommandline.txt"],
];

for (NSURL* ueFile in ueFiles) {
if (!access([[ueFile path] cStringUsingEncoding:NSUTF8StringEncoding], F_OK)) {
ue_status = 2;
}
}
}

if (ue_status == 2) {
[PlayKeychain debugLogger: [NSString stringWithFormat:@"UnrealEngine Hooked"]];
}
}

Expand Down

0 comments on commit ab77730

Please sign in to comment.