CheatList: Save additional DuckStation fields in comments
This commit is contained in:
parent
39a61d2207
commit
cb6ef03775
|
@ -41,8 +41,10 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
std::string comments;
|
std::string comments;
|
||||||
|
std::string group;
|
||||||
|
CheatCode::Type type = CheatCode::Type::Gameshark;
|
||||||
|
CheatCode::Activation activation = CheatCode::Activation::EndFrame;
|
||||||
CheatCode current_code;
|
CheatCode current_code;
|
||||||
current_code.group = "Ungrouped";
|
|
||||||
while (std::fgets(line, sizeof(line), fp.get()))
|
while (std::fgets(line, sizeof(line), fp.get()))
|
||||||
{
|
{
|
||||||
char* start = line;
|
char* start = line;
|
||||||
|
@ -60,6 +62,23 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DuckStation metadata
|
||||||
|
if (StringUtil::Strncasecmp(start, "#group=", 7) == 0)
|
||||||
|
{
|
||||||
|
group = start + 7;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StringUtil::Strncasecmp(start, "#type=", 6) == 0)
|
||||||
|
{
|
||||||
|
type = CheatCode::ParseTypeName(start + 6).value_or(CheatCode::Type::Gameshark);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StringUtil::Strncasecmp(start, "#activation=", 12) == 0)
|
||||||
|
{
|
||||||
|
activation = CheatCode::ParseActivationName(start + 12).value_or(CheatCode::Activation::EndFrame);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// skip comments and empty line
|
// skip comments and empty line
|
||||||
if (*start == '#' || *start == ';' || *start == '/' || *start == '\"')
|
if (*start == '#' || *start == ';' || *start == '/' || *start == '\"')
|
||||||
{
|
{
|
||||||
|
@ -78,9 +97,17 @@ bool CheatList::LoadFromPCSXRFile(const char* filename)
|
||||||
m_codes.push_back(std::move(current_code));
|
m_codes.push_back(std::move(current_code));
|
||||||
|
|
||||||
current_code = CheatCode();
|
current_code = CheatCode();
|
||||||
current_code.group = "Ungrouped";
|
if (group.empty())
|
||||||
|
group = "Ungrouped";
|
||||||
|
|
||||||
|
current_code.group = std::move(group);
|
||||||
|
group = std::string();
|
||||||
current_code.comments = std::move(comments);
|
current_code.comments = std::move(comments);
|
||||||
comments = std::string();
|
comments = std::string();
|
||||||
|
current_code.type = type;
|
||||||
|
type = CheatCode::Type::Gameshark;
|
||||||
|
current_code.activation = activation;
|
||||||
|
activation = CheatCode::Activation::EndFrame;
|
||||||
|
|
||||||
if (*start == '*')
|
if (*start == '*')
|
||||||
{
|
{
|
||||||
|
@ -356,6 +383,9 @@ bool CheatList::SaveToPCSXRFile(const char* filename)
|
||||||
{
|
{
|
||||||
if (!cc.comments.empty())
|
if (!cc.comments.empty())
|
||||||
std::fputs(cc.comments.c_str(), fp.get());
|
std::fputs(cc.comments.c_str(), fp.get());
|
||||||
|
std::fprintf(fp.get(), "#group=%s\n", cc.group.c_str());
|
||||||
|
std::fprintf(fp.get(), "#type=%s\n", CheatCode::GetTypeName(cc.type));
|
||||||
|
std::fprintf(fp.get(), "#activation=%s\n", CheatCode::GetActivationName(cc.activation));
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue