Skip to content

Commit

Permalink
remove AR code size limit (#1802)
Browse files Browse the repository at this point in the history
Co-authored-by: Arisotura <thetotalworm@gmail.com>
  • Loading branch information
StraDaMa and Arisotura authored Aug 27, 2023
1 parent 2bd1266 commit bc71618
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
17 changes: 4 additions & 13 deletions src/ARCodeFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool ARCodeFile::Load()

curcode.Name = codename;
curcode.Enabled = enable!=0;
curcode.CodeLen = 0;
curcode.Code.clear();
}
else
{
Expand All @@ -141,17 +141,8 @@ bool ARCodeFile::Load()
return false;
}

if (curcode.CodeLen >= 2*64)
{
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;
curcode.Code.push_back(c0);
curcode.Code.push_back(c1);
}
}

Expand Down Expand Up @@ -179,7 +170,7 @@ bool ARCodeFile::Save()
ARCode& code = *jt;
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]);
}
Expand Down
5 changes: 2 additions & 3 deletions src/ARCodeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

#include <string>
#include <list>

#include <vector>
#include "types.h"

struct ARCode
{
std::string Name;
bool Enabled;
u32 CodeLen;
u32 Code[2*64];
std::vector<u32> Code;
};

typedef std::list<ARCode> ARCodeList;
Expand Down
2 changes: 1 addition & 1 deletion src/AREngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void RunCheat(ARCode& arcode)

for (;;)
{
if (code >= &arcode.Code[arcode.CodeLen])
if (code >= &arcode.Code[arcode.Code.size()])
break;

u32 a = *code++;
Expand Down
22 changes: 7 additions & 15 deletions src/frontend/qt_sdl/CheatsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ void CheatsDialog::on_btnNewARCode_clicked()
ARCode code;
code.Name = "(new AR code)";
code.Enabled = true;
code.CodeLen = 0;
memset(code.Code, 0, sizeof(code.Code));
code.Code.clear();

cat.Codes.push_back(code);
ARCodeList::iterator id = cat.Codes.end(); id--;
Expand Down Expand Up @@ -251,7 +250,7 @@ void CheatsDialog::onCheatSelectionChanged(const QItemSelection& sel, const QIte
ui->txtCode->setPlaceholderText("(enter AR code here)");

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 c1 = code.Code[i+1];
Expand Down Expand Up @@ -312,8 +311,8 @@ void CheatsDialog::on_txtCode_textChanged()
return;

bool error = false;
u32 codeout[2*64];
u32 codelen = 0;
std::vector<u32> codeout;
codeout.reserve(64);

QString text = ui->txtCode->document()->toPlainText();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Expand Down Expand Up @@ -356,14 +355,8 @@ void CheatsDialog::on_txtCode_textChanged()
break;
}

if (codelen >= 2*64)
{
error = true;
break;
}

codeout[codelen++] = c0;
codeout[codelen++] = c1;
codeout.push_back(c0);
codeout.push_back(c1);
}

ui->btnNewCat->setEnabled(!error);
Expand All @@ -375,8 +368,7 @@ void CheatsDialog::on_txtCode_textChanged()
if (error) return;

ARCode& code = *(data.value<ARCodeList::iterator>());
memcpy(code.Code, codeout, codelen*sizeof(u32));
code.CodeLen = codelen;
code.Code = codeout;
}

void ARCodeChecker::highlightBlock(const QString& text)
Expand Down

0 comments on commit bc71618

Please sign in to comment.