Skip to content

Commit

Permalink
Cocoa Port: Begin work on cleaning up and refactoring the cheat syste…
Browse files Browse the repository at this point in the history
…m. 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.
  • Loading branch information
rogerman committed Jun 23, 2023
1 parent aeefd86 commit ba83b68
Show file tree
Hide file tree
Showing 9 changed files with 1,011 additions and 1,295 deletions.
4 changes: 2 additions & 2 deletions desmume/src/frontend/cocoa/DefaultKeyMappings.plist
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<string>Set Speed</string>
<string>Enable/Disable Speed Limiter</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>
</array>
<key>DefaultInputProfiles</key>
Expand Down Expand Up @@ -805,7 +805,7 @@
<array/>
<key>Enable/Disable Auto Frame Skip</key>
<array/>
<key>Enable/Disable Cheats</key>
<key>Enable/Disable Cheat System</key>
<array/>
<key>Enable/Disable GPU State</key>
<array/>
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/frontend/cocoa/DefaultUserPrefs.plist
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@
<array/>
<key>Enable/Disable Auto Frame Skip</key>
<array/>
<key>Enable/Disable Cheats</key>
<key>Enable/Disable Cheat System</key>
<array/>
<key>Enable/Disable GPU State</key>
<array/>
Expand Down
87 changes: 78 additions & 9 deletions desmume/src/frontend/cocoa/cocoa_cheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/

#include <string>
#import <Cocoa/Cocoa.h>
#undef BOOL

Expand Down Expand Up @@ -46,6 +47,78 @@ enum CheatSystemError
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
Expand All @@ -59,16 +132,16 @@ enum CheatSystemError
********************************************************************************************/
@interface CocoaDSCheatItem : NSObject
{
CHEATS_LIST *data;
CHEATS_LIST *internalData;
ClientCheatItem *_internalData;
BOOL willAdd;
pthread_mutex_t mutexData;

CocoaDSCheatItem *workingCopy;
CocoaDSCheatItem *parent;

BOOL _isMemAddressAlreadyUpdating;
}

@property (assign) CHEATS_LIST *data;
@property (assign, nonatomic) CHEATS_LIST *data;
@property (assign) BOOL willAdd;
@property (assign, nonatomic) BOOL enabled;
@property (assign, nonatomic) NSInteger cheatType;
Expand All @@ -86,16 +159,13 @@ enum CheatSystemError
@property (readonly) CocoaDSCheatItem *workingCopy;
@property (assign) CocoaDSCheatItem *parent;

- (id) initWithCheatItem:(CocoaDSCheatItem *)cdsCheatItem;
- (id) initWithCheatData:(CHEATS_LIST *)cheatData;
- (BOOL) retainData;
- (char *) descriptionCString;
- (void) update;
- (CocoaDSCheatItem *) createWorkingCopy;
- (void) destroyWorkingCopy;
- (void) mergeFromWorkingCopy;
- (void) mergeToParent;
- (void) setDataWithDictionary:(NSDictionary *)dataDict;
- (NSDictionary *) dataDictionary;

+ (void) setIconInternalCheat:(NSImage *)iconImage;
+ (NSImage *) iconInternalCheat;
Expand Down Expand Up @@ -151,7 +221,6 @@ enum CheatSystemError
+ (void) applyInternalCheatWithAddress:(UInt32)address value:(UInt32)value bytes:(NSUInteger)bytes;
+ (NSMutableArray *) cheatListWithListObject:(CHEATS *)cheatList;
+ (NSMutableArray *) cheatListWithItemStructArray:(CHEATS_LIST *)cheatItemArray count:(NSUInteger)itemCount;
+ (NSMutableDictionary *) cheatItemWithType:(NSInteger)cheatTypeID description:(NSString *)description;

@end

Expand Down

0 comments on commit ba83b68

Please sign in to comment.