Skip to content

Commit 06a635b

Browse files
Merge pull request #284 from 0xsequence/166-corrupted-sav-engine-crash
Engine should no longer crash on Mac due to a corrupted save file
2 parents 310f7e1 + ea24a1a commit 06a635b

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

Plugins/SequencePlugin/Source/SequencePlugin/Private/Native/AppleBridge.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,8 @@ FString UAppleBridge::AppleDecrypt(const FString& StringIn)
3232
#if PLATFORM_IOS || PLATFORM_MAC
3333
NSString * _ToDecrypt = StringIn.GetNSString();
3434
NativeAppleEncryptor * Encryptor = [[NativeAppleEncryptor alloc] init];
35-
36-
@try {
37-
char * CharResult = [Encryptor Decrypt:_ToDecrypt];
38-
Result = FString(UTF8_TO_TCHAR(CharResult));
39-
}
40-
@catch (NSException *exception) {
41-
// Handle the exception and log the error
42-
NSLog(@"Caught exception: %@ - Reason: %@", exception.name, exception.reason);
43-
}
44-
35+
char * CharResult = [Encryptor Decrypt:_ToDecrypt];
36+
Result = FString(UTF8_TO_TCHAR(CharResult));
4537
#endif
4638
return Result;
4739
}

Plugins/SequencePlugin/Source/SequencePlugin/Private/Native/IOS/objective_c/NativeAppleEncryptor.mm

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Horizon Blockchain Games Inc. All rights reserved.
1+
// Copyright 2024 Horizon Blockchain Games Inc. All rights reserved.
22

33
#import "NativeAppleEncryptor.h"
44
#import <Foundation/Foundation.h>
@@ -105,14 +105,24 @@ - (char *)Encrypt:(NSString *)str
105105
}
106106

107107
- (char *)Decrypt:(NSString *)str
108-
{
108+
{
109+
if (str == nil || [str length] == 0) {
110+
NSString *FailureString = @"Invalid input string";
111+
return [self ConvertNSStringToChars:FailureString];
112+
}
113+
109114
if ([self LoadKeys])
110115
{
111116
NSData *DecodedData = [[NSData alloc] initWithBase64EncodedString:str options:0];
117+
if (DecodedData == nil) {
118+
NSString *FailureString = @"Failed to decode base64 input";
119+
return [self ConvertNSStringToChars:FailureString];
120+
}
121+
112122
CFDataRef plainText = (__bridge CFDataRef)DecodedData;
113123
CFErrorRef error = NULL;
114124

115-
CFDataRef cfDecryptedData = SecKeyCreateDecryptedData(PrivateKeyRef,algorithm,plainText,&error);
125+
CFDataRef cfDecryptedData = SecKeyCreateDecryptedData(PrivateKeyRef, algorithm, plainText, &error);
116126

117127
if (cfDecryptedData)
118128
{
@@ -125,22 +135,21 @@ - (char *)Decrypt:(NSString *)str
125135
else
126136
{
127137
NSError *err = CFBridgingRelease(error);
128-
char * ErrorChars = [self ConvertNSStringToChars:err.localizedDescription];
138+
NSString *errorString = err ? err.localizedDescription : @"Unknown decryption error";
139+
char * ErrorChars = [self ConvertNSStringToChars:errorString];
129140
[self Clean];
130141
return ErrorChars;
131142
}
132143
}
133144
else
134145
{
135146
NSString * FailureString = @"Failed to load keys";
136-
char * ErrorChars = [self ConvertNSStringToChars:FailureString];
137-
[self Clean];
138-
return ErrorChars;
147+
return [self ConvertNSStringToChars:FailureString];
139148
}
140149
}
141150

142151
- (char *)ConvertNSStringToChars:(NSString *)str {
143152
const char *strChars = [str UTF8String];
144153
return (char*)strChars;
145154
}
146-
@end
155+
@end

0 commit comments

Comments
 (0)