Cocoa Port: Begin work on cleaning up and refactoring the cheat system. Also add some quality-of-life improvements to the GUI while I'm at it.

- Add new ClientCheatItem C++ class to handle cheat items, greatly reducing dependence on Objective-C code.
- Remove a bunch of methods from CocoaDSCheatItem and CocoaDSCheatManager that were never used and are no longer planned to ever be used in the new code refactor.
- The Cheat Manager window may now be resized.
- The Action Replay code editor now uses Monaco 13 font instead of the system default font.
- The command for "Enable/Disable Cheats" has been renamed to "Enable/Disable Cheat System" to help clarify that the command affects the entire cheat system as a whole, as opposed to enabling/disabling individual cheat items.
This commit is contained in:
rogerman 2023-06-23 14:18:02 -07:00
parent aeefd86f57
commit ba83b68b7f
9 changed files with 1016 additions and 1300 deletions

View File

@ -54,7 +54,7 @@
<string>Set Speed</string> <string>Set Speed</string>
<string>Enable/Disable Speed Limiter</string> <string>Enable/Disable Speed Limiter</string>
<string>Enable/Disable Auto Frame Skip</string> <string>Enable/Disable Auto Frame Skip</string>
<string>Enable/Disable Cheats</string> <string>Enable/Disable Cheat System</string>
<string>Enable/Disable GPU State</string> <string>Enable/Disable GPU State</string>
</array> </array>
<key>DefaultInputProfiles</key> <key>DefaultInputProfiles</key>
@ -805,7 +805,7 @@
<array/> <array/>
<key>Enable/Disable Auto Frame Skip</key> <key>Enable/Disable Auto Frame Skip</key>
<array/> <array/>
<key>Enable/Disable Cheats</key> <key>Enable/Disable Cheat System</key>
<array/> <array/>
<key>Enable/Disable GPU State</key> <key>Enable/Disable GPU State</key>
<array/> <array/>

View File

@ -829,7 +829,7 @@
<array/> <array/>
<key>Enable/Disable Auto Frame Skip</key> <key>Enable/Disable Auto Frame Skip</key>
<array/> <array/>
<key>Enable/Disable Cheats</key> <key>Enable/Disable Cheat System</key>
<array/> <array/>
<key>Enable/Disable GPU State</key> <key>Enable/Disable GPU State</key>
<array/> <array/>

View File

@ -16,6 +16,7 @@
along with the this software. If not, see <http://www.gnu.org/licenses/>. along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <string>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#undef BOOL #undef BOOL
@ -46,6 +47,78 @@ enum CheatSystemError
CheatSystemError_ExportError = 4 CheatSystemError_ExportError = 4
}; };
class ClientCheatItem
{
protected:
CHEATS_LIST *_engineItemPtr;
bool _isEnabled;
bool _willAddFromDB;
CheatType _cheatType;
std::string _descriptionString;
void *_clientData;
// Internal cheat type parameters
CheatFreezeType _freezeType;
char _addressString[10+1];
uint32_t _address;
uint32_t _value;
uint8_t _valueLength;
// Action Replay parameters
uint32_t _codeCount;
std::string _rawCodeString;
std::string _cleanCodeString;
void _ConvertInternalToActionReplay();
void _ConvertActionReplayToInternal();
public:
ClientCheatItem();
~ClientCheatItem();
void Init(const CHEATS_LIST &inCheatItem);
void Init(const ClientCheatItem &inCheatItem);
void SetEngineItemPtr(CHEATS_LIST *cheatItemPtr);
CHEATS_LIST* GetEngineItemPtr() const;
void SetEnabled(bool theState);
bool IsEnabled() const;
void SetWillAddFromDB(bool theState);
bool WillAddFromDB() const;
CheatType GetType() const;
void SetType(CheatType requestedType);
bool IsSupportedType() const;
const char* GetDescription() const;
void SetDescription(const char *descriptionString);
CheatFreezeType GetFreezeType() const;
void SetFreezeType(CheatFreezeType theFreezeType);
uint32_t GetAddress() const;
void SetAddress(uint32_t theAddress);
const char* GetAddressString() const;
const char* GetAddressSixDigitString() const;
void SetAddressSixDigitString(const char *sixDigitString);
uint32_t GetValue() const;
void SetValue(uint32_t theValue);
uint8_t GetValueLength() const;
void SetValueLength(uint8_t byteLength);
void SetRawCodeString(const char *rawString, const bool willSaveValidatedRawString);
const char* GetRawCodeString() const;
const char* GetCleanCodeString() const;
uint32_t GetCodeCount() const;
void ClientToDesmumeCheatItem(CHEATS_LIST *outCheatItem) const;
};
/******************************************************************************************** /********************************************************************************************
CocoaDSCheatItem - OBJECTIVE-C CLASS CocoaDSCheatItem - OBJECTIVE-C CLASS
@ -59,16 +132,16 @@ enum CheatSystemError
********************************************************************************************/ ********************************************************************************************/
@interface CocoaDSCheatItem : NSObject @interface CocoaDSCheatItem : NSObject
{ {
CHEATS_LIST *data; ClientCheatItem *_internalData;
CHEATS_LIST *internalData;
BOOL willAdd; BOOL willAdd;
pthread_mutex_t mutexData;
CocoaDSCheatItem *workingCopy; CocoaDSCheatItem *workingCopy;
CocoaDSCheatItem *parent; CocoaDSCheatItem *parent;
BOOL _isMemAddressAlreadyUpdating;
} }
@property (assign) CHEATS_LIST *data; @property (assign, nonatomic) CHEATS_LIST *data;
@property (assign) BOOL willAdd; @property (assign) BOOL willAdd;
@property (assign, nonatomic) BOOL enabled; @property (assign, nonatomic) BOOL enabled;
@property (assign, nonatomic) NSInteger cheatType; @property (assign, nonatomic) NSInteger cheatType;
@ -86,16 +159,13 @@ enum CheatSystemError
@property (readonly) CocoaDSCheatItem *workingCopy; @property (readonly) CocoaDSCheatItem *workingCopy;
@property (assign) CocoaDSCheatItem *parent; @property (assign) CocoaDSCheatItem *parent;
- (id) initWithCheatItem:(CocoaDSCheatItem *)cdsCheatItem;
- (id) initWithCheatData:(CHEATS_LIST *)cheatData; - (id) initWithCheatData:(CHEATS_LIST *)cheatData;
- (BOOL) retainData;
- (char *) descriptionCString; - (char *) descriptionCString;
- (void) update; - (void) update;
- (CocoaDSCheatItem *) createWorkingCopy; - (CocoaDSCheatItem *) createWorkingCopy;
- (void) destroyWorkingCopy; - (void) destroyWorkingCopy;
- (void) mergeFromWorkingCopy;
- (void) mergeToParent; - (void) mergeToParent;
- (void) setDataWithDictionary:(NSDictionary *)dataDict;
- (NSDictionary *) dataDictionary;
+ (void) setIconInternalCheat:(NSImage *)iconImage; + (void) setIconInternalCheat:(NSImage *)iconImage;
+ (NSImage *) iconInternalCheat; + (NSImage *) iconInternalCheat;
@ -151,7 +221,6 @@ enum CheatSystemError
+ (void) applyInternalCheatWithAddress:(UInt32)address value:(UInt32)value bytes:(NSUInteger)bytes; + (void) applyInternalCheatWithAddress:(UInt32)address value:(UInt32)value bytes:(NSUInteger)bytes;
+ (NSMutableArray *) cheatListWithListObject:(CHEATS *)cheatList; + (NSMutableArray *) cheatListWithListObject:(CHEATS *)cheatList;
+ (NSMutableArray *) cheatListWithItemStructArray:(CHEATS_LIST *)cheatItemArray count:(NSUInteger)itemCount; + (NSMutableArray *) cheatListWithItemStructArray:(CHEATS_LIST *)cheatItemArray count:(NSUInteger)itemCount;
+ (NSMutableDictionary *) cheatItemWithType:(NSInteger)cheatTypeID description:(NSString *)description;
@end @end

File diff suppressed because it is too large Load Diff

View File

@ -46,8 +46,8 @@
#define NSSTRING_TITLE_ENABLE_SPEED_LIMIT NSLocalizedString(@"Enable Speed Limit", nil) #define NSSTRING_TITLE_ENABLE_SPEED_LIMIT NSLocalizedString(@"Enable Speed Limit", nil)
#define NSSTRING_TITLE_DISABLE_AUTO_FRAME_SKIP NSLocalizedString(@"Disable Auto Frame Skip", nil) #define NSSTRING_TITLE_DISABLE_AUTO_FRAME_SKIP NSLocalizedString(@"Disable Auto Frame Skip", nil)
#define NSSTRING_TITLE_ENABLE_AUTO_FRAME_SKIP NSLocalizedString(@"Enable Auto Frame Skip", nil) #define NSSTRING_TITLE_ENABLE_AUTO_FRAME_SKIP NSLocalizedString(@"Enable Auto Frame Skip", nil)
#define NSSTRING_TITLE_DISABLE_CHEATS NSLocalizedString(@"Disable Cheats", nil) #define NSSTRING_TITLE_DISABLE_CHEATS NSLocalizedString(@"Disable Cheat System", nil)
#define NSSTRING_TITLE_ENABLE_CHEATS NSLocalizedString(@"Enable Cheats", nil) #define NSSTRING_TITLE_ENABLE_CHEATS NSLocalizedString(@"Enable Cheat System", nil)
#define NSSTRING_TITLE_DISABLE_HUD NSLocalizedString(@"Disable HUD", nil) #define NSSTRING_TITLE_DISABLE_HUD NSLocalizedString(@"Disable HUD", nil)
#define NSSTRING_TITLE_ENABLE_HUD NSLocalizedString(@"Enable HUD", nil) #define NSSTRING_TITLE_ENABLE_HUD NSLocalizedString(@"Enable HUD", nil)
#define NSSTRING_TITLE_EXIT_FULL_SCREEN NSLocalizedString(@"Exit Full Screen", nil) #define NSSTRING_TITLE_EXIT_FULL_SCREEN NSLocalizedString(@"Exit Full Screen", nil)

View File

@ -1170,7 +1170,7 @@ void HandleDeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSen
ClientCommandAttributes cmdToggleSpeedLimiter = NewCommandAttributesWithFunction("Enable/Disable Speed Limiter", &ClientCommandToggleSpeedLimiter); ClientCommandAttributes cmdToggleSpeedLimiter = NewCommandAttributesWithFunction("Enable/Disable Speed Limiter", &ClientCommandToggleSpeedLimiter);
ClientCommandAttributes cmdToggleAutoFrameSkip = NewCommandAttributesWithFunction("Enable/Disable Auto Frame Skip", &ClientCommandToggleAutoFrameSkip); ClientCommandAttributes cmdToggleAutoFrameSkip = NewCommandAttributesWithFunction("Enable/Disable Auto Frame Skip", &ClientCommandToggleAutoFrameSkip);
ClientCommandAttributes cmdToggleCheats = NewCommandAttributesWithFunction("Enable/Disable Cheats", &ClientCommandToggleCheats); ClientCommandAttributes cmdToggleCheats = NewCommandAttributesWithFunction("Enable/Disable Cheat System", &ClientCommandToggleCheats);
ClientCommandAttributes cmdCoreExecute = NewCommandAttributesWithFunction("Execute", &ClientCommandCoreExecute); ClientCommandAttributes cmdCoreExecute = NewCommandAttributesWithFunction("Execute", &ClientCommandCoreExecute);
ClientCommandAttributes cmdCorePause = NewCommandAttributesWithFunction("Pause", &ClientCommandCorePause); ClientCommandAttributes cmdCorePause = NewCommandAttributesWithFunction("Pause", &ClientCommandCorePause);
ClientCommandAttributes cmdToggleExecutePause = NewCommandAttributesWithFunction("Execute/Pause", &ClientCommandToggleExecutePause); ClientCommandAttributes cmdToggleExecutePause = NewCommandAttributesWithFunction("Execute/Pause", &ClientCommandToggleExecutePause);
@ -1227,7 +1227,7 @@ void HandleDeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSen
defaultCommandAttributes["Set Speed"] = cmdToggleSpeed; defaultCommandAttributes["Set Speed"] = cmdToggleSpeed;
defaultCommandAttributes["Enable/Disable Speed Limiter"] = cmdToggleSpeedLimiter; defaultCommandAttributes["Enable/Disable Speed Limiter"] = cmdToggleSpeedLimiter;
defaultCommandAttributes["Enable/Disable Auto Frame Skip"] = cmdToggleAutoFrameSkip; defaultCommandAttributes["Enable/Disable Auto Frame Skip"] = cmdToggleAutoFrameSkip;
defaultCommandAttributes["Enable/Disable Cheats"] = cmdToggleCheats; defaultCommandAttributes["Enable/Disable Cheat System"] = cmdToggleCheats;
defaultCommandAttributes["Execute"] = cmdCoreExecute; defaultCommandAttributes["Execute"] = cmdCoreExecute;
defaultCommandAttributes["Pause"] = cmdCorePause; defaultCommandAttributes["Pause"] = cmdCorePause;
defaultCommandAttributes["Execute/Pause"] = cmdToggleExecutePause; defaultCommandAttributes["Execute/Pause"] = cmdToggleExecutePause;

View File

@ -58,6 +58,7 @@
NSWindow *cheatDatabaseSheet; NSWindow *cheatDatabaseSheet;
NSUInteger untitledCount; NSUInteger untitledCount;
NSFont *codeEditorFont;
NSMutableDictionary *bindings; NSMutableDictionary *bindings;
CocoaDSCheatItem *workingCheat; CocoaDSCheatItem *workingCheat;
@ -92,6 +93,7 @@
@property (readonly) IBOutlet NSWindow *cheatDatabaseSheet; @property (readonly) IBOutlet NSWindow *cheatDatabaseSheet;
@property (assign) NSUInteger untitledCount; @property (assign) NSUInteger untitledCount;
@property (assign) NSFont *codeEditorFont;
@property (readonly) NSMutableDictionary *bindings; @property (readonly) NSMutableDictionary *bindings;
@property (retain) CocoaDSCheatItem *workingCheat; @property (retain) CocoaDSCheatItem *workingCheat;
@property (retain) CocoaDSCheatManager *cdsCheats; @property (retain) CocoaDSCheatManager *cdsCheats;

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2011 Roger Manuel Copyright (C) 2011 Roger Manuel
Copyright (C) 2012-2022 DeSmuME team Copyright (C) 2012-2023 DeSmuME team
This file is free software: you can redistribute it and/or modify This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -51,6 +51,7 @@
@synthesize cheatDatabaseSheet; @synthesize cheatDatabaseSheet;
@synthesize untitledCount; @synthesize untitledCount;
@synthesize codeEditorFont;
@synthesize bindings; @synthesize bindings;
@synthesize cdsCheats; @synthesize cdsCheats;
@synthesize cdsCheatSearch; @synthesize cdsCheatSearch;
@ -85,6 +86,7 @@
currentView = nil; currentView = nil;
currentSearchStyleView = nil; currentSearchStyleView = nil;
untitledCount = 0; untitledCount = 0;
codeEditorFont = [NSFont fontWithName:@"Monaco" size:13.0];
[bindings setValue:[NSNumber numberWithBool:NO] forKey:@"hasSelection"]; [bindings setValue:[NSNumber numberWithBool:NO] forKey:@"hasSelection"];
[bindings setValue:[NSNumber numberWithBool:NO] forKey:@"hasItems"]; [bindings setValue:[NSNumber numberWithBool:NO] forKey:@"hasItems"];
@ -242,7 +244,8 @@
NSInteger cheatTypeID = [CocoaDSUtil getIBActionSenderTag:sender]; NSInteger cheatTypeID = [CocoaDSUtil getIBActionSenderTag:sender];
CocoaDSCheatItem *cheatItem = [cheatSelectedItemController content]; CocoaDSCheatItem *cheatItem = [cheatSelectedItemController content];
cheatItem.cheatType = cheatTypeID; [window makeFirstResponder:nil]; // Force end of editing of any text fields.
[cheatItem setCheatType:cheatTypeID];
[self setCheatConfigViewByType:cheatTypeID]; [self setCheatConfigViewByType:cheatTypeID];
} }
@ -458,8 +461,7 @@
{ {
if (cheatItem.willAdd) if (cheatItem.willAdd)
{ {
CocoaDSCheatItem *newCheatItem = [[[CocoaDSCheatItem alloc] initWithCheatData:cheatItem.data] autorelease]; CocoaDSCheatItem *newCheatItem = [[[CocoaDSCheatItem alloc] initWithCheatItem:cheatItem] autorelease];
[newCheatItem retainData];
[cheatListController addObject:newCheatItem]; [cheatListController addObject:newCheatItem];
[self.cdsCheats add:newCheatItem]; [self.cdsCheats add:newCheatItem];
} }