cheatwnd: add utilities for exporting cheat data to a file

- Use a u32 vector instead of std::string
- Use that vector to allow exporting to file

Co-authored-by: Pk11 <pk11@outlook.jp>
This commit is contained in:
lifehackerhansol 2024-10-05 20:15:30 -07:00
parent e702d1bfbf
commit 1a88151eee
No known key found for this signature in database
GPG Key ID: 80FB184AFC0B3B0E
2 changed files with 28 additions and 6 deletions

View File

@ -395,11 +395,8 @@ bool cCheatWnd::parseInternal(FILE* aDat, u32 gamecode, u32 crc32) {
flagItem | ((*ccode & 0xff000000) ? selectValue : 0),
dataPos + (((char*)ccode + 3) - buffer)));
if ((*ccode & 0xff000000) && (flagItem & cParsedItem::EOne)) selectValue = 0;
for (size_t jj = 0; jj < cheatDataLen; ++jj) {
_data.back()._cheat += formatString("%08X", *(cheatData + jj));
_data.back()._cheat += ((jj + 1) % 2) ? " " : "\n";
}
if (cheatDataLen % 2) _data.back()._cheat += "\n";
_data.back()._cheat.resize(cheatDataLen);
memcpy(_data.back()._cheat.data(), cheatData, cheatDataLen * 4);
}
cc++;
ccode = (u32*)((u32)ccode + (((*ccode & 0x00ffffff) + 1) * 4));
@ -442,3 +439,23 @@ void cCheatWnd::deselectFolder(size_t anIndex) {
++itr;
}
}
std::vector<u32> cCheatWnd::getCheats() {
std::vector<u32> cheats;
for (uint i = 0; i < _data.size(); i++) {
if (_data[i]._flags & cParsedItem::ESelected) {
cheats.insert(cheats.end(), _data[i]._cheat.begin(), _data[i]._cheat.end());
}
}
return cheats;
}
void cCheatWnd::writeCheatsToFile(const char* path) {
FILE* file = fopen(path, "wb");
if (file) {
std::vector<u32> cheats(getCheats());
fwrite(cheats.data(), 4, cheats.size(), file);
fwrite("\0\0\0\xCF", 4, 1, file);
fclose(file);
}
}

View File

@ -7,6 +7,9 @@
#pragma once
#include <nds/ndstypes.h>
#include <vector>
#include "button.h"
#include "form.h"
#include "formdesc.h"
@ -20,6 +23,8 @@ class cCheatWnd : public akui::cForm {
bool parse(const std::string& aFileName);
static bool searchCheatData(FILE* aDat, u32 gamecode, u32 crc32, long& aPos, size_t& aSize);
static bool romData(const std::string& aFileName, u32& aGameCode, u32& aCrc32);
std::vector<u32> getCheats();
void writeCheatsToFile(const char* path);
protected:
void draw();
@ -58,7 +63,7 @@ class cCheatWnd : public akui::cForm {
public:
std::string _title;
std::string _comment;
std::string _cheat;
std::vector<u32> _cheat;
u32 _flags;
u32 _offset;
cParsedItem(const std::string& title, const std::string& comment, u32 flags, u32 offset = 0)