remove AR code size limit (#1802)

Co-authored-by: Arisotura <thetotalworm@gmail.com>
This commit is contained in:
StraDaMa 2023-08-27 04:34:11 -07:00 committed by GitHub
parent 2bd12669b2
commit bc71618457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 32 deletions

View File

@ -120,7 +120,7 @@ bool ARCodeFile::Load()
curcode.Name = codename; curcode.Name = codename;
curcode.Enabled = enable!=0; curcode.Enabled = enable!=0;
curcode.CodeLen = 0; curcode.Code.clear();
} }
else else
{ {
@ -141,17 +141,8 @@ bool ARCodeFile::Load()
return false; return false;
} }
if (curcode.CodeLen >= 2*64) curcode.Code.push_back(c0);
{ curcode.Code.push_back(c1);
Log(LogLevel::Error, "AR: code too long!\n");
CloseFile(f);
return false;
}
u32 idx = curcode.CodeLen;
curcode.Code[idx+0] = c0;
curcode.Code[idx+1] = c1;
curcode.CodeLen += 2;
} }
} }
@ -179,7 +170,7 @@ bool ARCodeFile::Save()
ARCode& code = *jt; ARCode& code = *jt;
FileWriteFormatted(f, "CODE %d %s\r\n", code.Enabled, code.Name.c_str()); FileWriteFormatted(f, "CODE %d %s\r\n", code.Enabled, code.Name.c_str());
for (u32 i = 0; i < code.CodeLen; i+=2) for (size_t i = 0; i < code.Code.size(); i+=2)
{ {
FileWriteFormatted(f, "%08X %08X\r\n", code.Code[i], code.Code[i + 1]); FileWriteFormatted(f, "%08X %08X\r\n", code.Code[i], code.Code[i + 1]);
} }

View File

@ -21,15 +21,14 @@
#include <string> #include <string>
#include <list> #include <list>
#include <vector>
#include "types.h" #include "types.h"
struct ARCode struct ARCode
{ {
std::string Name; std::string Name;
bool Enabled; bool Enabled;
u32 CodeLen; std::vector<u32> Code;
u32 Code[2*64];
}; };
typedef std::list<ARCode> ARCodeList; typedef std::list<ARCode> ARCodeList;

View File

@ -110,7 +110,7 @@ void RunCheat(ARCode& arcode)
for (;;) for (;;)
{ {
if (code >= &arcode.Code[arcode.CodeLen]) if (code >= &arcode.Code[arcode.Code.size()])
break; break;
u32 a = *code++; u32 a = *code++;

View File

@ -162,8 +162,7 @@ void CheatsDialog::on_btnNewARCode_clicked()
ARCode code; ARCode code;
code.Name = "(new AR code)"; code.Name = "(new AR code)";
code.Enabled = true; code.Enabled = true;
code.CodeLen = 0; code.Code.clear();
memset(code.Code, 0, sizeof(code.Code));
cat.Codes.push_back(code); cat.Codes.push_back(code);
ARCodeList::iterator id = cat.Codes.end(); id--; ARCodeList::iterator id = cat.Codes.end(); id--;
@ -251,7 +250,7 @@ void CheatsDialog::onCheatSelectionChanged(const QItemSelection& sel, const QIte
ui->txtCode->setPlaceholderText("(enter AR code here)"); ui->txtCode->setPlaceholderText("(enter AR code here)");
QString codestr = ""; QString codestr = "";
for (u32 i = 0; i < code.CodeLen; i += 2) for (size_t i = 0; i < code.Code.size(); i += 2)
{ {
u32 c0 = code.Code[i+0]; u32 c0 = code.Code[i+0];
u32 c1 = code.Code[i+1]; u32 c1 = code.Code[i+1];
@ -312,8 +311,8 @@ void CheatsDialog::on_txtCode_textChanged()
return; return;
bool error = false; bool error = false;
u32 codeout[2*64]; std::vector<u32> codeout;
u32 codelen = 0; codeout.reserve(64);
QString text = ui->txtCode->document()->toPlainText(); QString text = ui->txtCode->document()->toPlainText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
@ -356,14 +355,8 @@ void CheatsDialog::on_txtCode_textChanged()
break; break;
} }
if (codelen >= 2*64) codeout.push_back(c0);
{ codeout.push_back(c1);
error = true;
break;
}
codeout[codelen++] = c0;
codeout[codelen++] = c1;
} }
ui->btnNewCat->setEnabled(!error); ui->btnNewCat->setEnabled(!error);
@ -375,8 +368,7 @@ void CheatsDialog::on_txtCode_textChanged()
if (error) return; if (error) return;
ARCode& code = *(data.value<ARCodeList::iterator>()); ARCode& code = *(data.value<ARCodeList::iterator>());
memcpy(code.Code, codeout, codelen*sizeof(u32)); code.Code = codeout;
code.CodeLen = codelen;
} }
void ARCodeChecker::highlightBlock(const QString& text) void ARCodeChecker::highlightBlock(const QString& text)