CheatList: Preserve comments in PCSXR format files
This commit is contained in:
parent
abc035b15a
commit
39a61d2207
|
@ -40,6 +40,7 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
std::string comments;
|
||||||
CheatCode current_code;
|
CheatCode current_code;
|
||||||
current_code.group = "Ungrouped";
|
current_code.group = "Ungrouped";
|
||||||
while (std::fgets(line, sizeof(line), fp.get()))
|
while (std::fgets(line, sizeof(line), fp.get()))
|
||||||
|
@ -61,7 +62,11 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
|
|
||||||
// skip comments and empty line
|
// skip comments and empty line
|
||||||
if (*start == '#' || *start == ';' || *start == '/' || *start == '\"')
|
if (*start == '#' || *start == ';' || *start == '/' || *start == '\"')
|
||||||
|
{
|
||||||
|
comments.append(start);
|
||||||
|
comments += '\n';
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (*start == '[' && *end == ']')
|
if (*start == '[' && *end == ']')
|
||||||
{
|
{
|
||||||
|
@ -74,6 +79,8 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
|
|
||||||
current_code = CheatCode();
|
current_code = CheatCode();
|
||||||
current_code.group = "Ungrouped";
|
current_code.group = "Ungrouped";
|
||||||
|
current_code.comments = std::move(comments);
|
||||||
|
comments = std::string();
|
||||||
|
|
||||||
if (*start == '*')
|
if (*start == '*')
|
||||||
{
|
{
|
||||||
|
@ -105,7 +112,12 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_code.Valid())
|
if (current_code.Valid())
|
||||||
|
{
|
||||||
|
// technically this isn't the place for end of file
|
||||||
|
if (!comments.empty())
|
||||||
|
current_code.comments += comments;
|
||||||
m_codes.push_back(std::move(current_code));
|
m_codes.push_back(std::move(current_code));
|
||||||
|
}
|
||||||
|
|
||||||
Log_InfoPrintf("Loaded %zu cheats from '%s' (PCSXR format)", m_codes.size(), filename);
|
Log_InfoPrintf("Loaded %zu cheats from '%s' (PCSXR format)", m_codes.size(), filename);
|
||||||
return !m_codes.empty();
|
return !m_codes.empty();
|
||||||
|
@ -342,6 +354,8 @@ bool CheatList::SaveToPCSXRFile(const char* filename)
|
||||||
|
|
||||||
for (const CheatCode& cc : m_codes)
|
for (const CheatCode& cc : m_codes)
|
||||||
{
|
{
|
||||||
|
if (!cc.comments.empty())
|
||||||
|
std::fputs(cc.comments.c_str(), fp.get());
|
||||||
std::fprintf(fp.get(), "[%s%s]\n", cc.enabled ? "*" : "", cc.description.c_str());
|
std::fprintf(fp.get(), "[%s%s]\n", cc.enabled ? "*" : "", cc.description.c_str());
|
||||||
for (const CheatCode::Instruction& i : cc.instructions)
|
for (const CheatCode::Instruction& i : cc.instructions)
|
||||||
std::fprintf(fp.get(), "%08X %04X\n", i.first, i.second);
|
std::fprintf(fp.get(), "%08X %04X\n", i.first, i.second);
|
||||||
|
|
|
@ -61,6 +61,7 @@ struct CheatCode
|
||||||
std::string group;
|
std::string group;
|
||||||
std::string description;
|
std::string description;
|
||||||
std::vector<Instruction> instructions;
|
std::vector<Instruction> instructions;
|
||||||
|
std::string comments;
|
||||||
Type type = Type::Gameshark;
|
Type type = Type::Gameshark;
|
||||||
Activation activation = Activation::EndFrame;
|
Activation activation = Activation::EndFrame;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
Loading…
Reference in New Issue