Updates in cheats handling.
This commit is contained in:
55
cheats.cpp
55
cheats.cpp
@@ -59,27 +59,23 @@ int find_by_crc(uint32_t romcrc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct dirent *de = 0;
|
||||
struct dirent *de;
|
||||
while((de = readdir(d)))
|
||||
{
|
||||
if (de->d_type == DT_REG)
|
||||
{
|
||||
char *ext = strcasestr(de->d_name, ".zip");
|
||||
if (ext && (ext - de->d_name) > 10)
|
||||
int len = strlen(de->d_name);
|
||||
if (len >= 14 && de->d_name[len - 14] == '[' && !strcasecmp(de->d_name+len-5, "].zip"))
|
||||
{
|
||||
ext -= 10;
|
||||
if (ext[0] == '[' && ext[9] == ']')
|
||||
uint32_t crc = 0;
|
||||
if (sscanf(de->d_name + len - 14, "[%X].zip", &crc) == 1)
|
||||
{
|
||||
uint32_t crc = 0;
|
||||
if (sscanf(ext, "[%X].zip", &crc) == 1)
|
||||
if (crc == romcrc)
|
||||
{
|
||||
if (crc == romcrc)
|
||||
{
|
||||
strcat(cheat_zip, "/");
|
||||
strcat(cheat_zip, de->d_name);
|
||||
closedir(d);
|
||||
return 1;
|
||||
}
|
||||
strcat(cheat_zip, "/");
|
||||
strcat(cheat_zip, de->d_name);
|
||||
closedir(d);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +86,7 @@ int find_by_crc(uint32_t romcrc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cheats_init(char *rom_path, uint32_t romcrc)
|
||||
void cheats_init(const char *rom_path, uint32_t romcrc)
|
||||
{
|
||||
cheats.clear();
|
||||
loaded = 0;
|
||||
@@ -109,17 +105,26 @@ void cheats_init(char *rom_path, uint32_t romcrc)
|
||||
{
|
||||
memset(&_z, 0, sizeof(_z));
|
||||
|
||||
char *rom_name = strrchr(rom_path, '/');
|
||||
if (!rom_name) return;
|
||||
|
||||
sprintf(cheat_zip, "%s/cheats/%s%s", getRootDir(), HomeDir, rom_name);
|
||||
char *p = strrchr(cheat_zip, '.');
|
||||
if (p) *p = 0;
|
||||
strcat(cheat_zip, ".zip");
|
||||
|
||||
if (!mz_zip_reader_init_file(&_z, cheat_zip, 0))
|
||||
const char *rom_name = strrchr(rom_path, '/');
|
||||
if (rom_name)
|
||||
{
|
||||
sprintf(cheat_zip, "%s/cheats/%s%s", getRootDir(), HomeDir, rom_name);
|
||||
char *p = strrchr(cheat_zip, '.');
|
||||
if (p) *p = 0;
|
||||
strcat(cheat_zip, ".zip");
|
||||
|
||||
if (!mz_zip_reader_init_file(&_z, cheat_zip, 0))
|
||||
{
|
||||
memset(&_z, 0, sizeof(_z));
|
||||
if (!find_by_crc(romcrc) || !mz_zip_reader_init_file(&_z, cheat_zip, 0))
|
||||
{
|
||||
printf("no cheat file found\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(&_z, 0, sizeof(_z));
|
||||
if (!find_by_crc(romcrc) || !mz_zip_reader_init_file(&_z, cheat_zip, 0))
|
||||
{
|
||||
printf("no cheat file found\n");
|
||||
|
||||
2
cheats.h
2
cheats.h
@@ -1,7 +1,7 @@
|
||||
#ifndef CHEATS_H
|
||||
#define CHEATS_H
|
||||
|
||||
void cheats_init(char *rom_path, uint32_t romcrc);
|
||||
void cheats_init(const char *rom_path, uint32_t romcrc);
|
||||
int cheats_available();
|
||||
void cheats_scan(int mode);
|
||||
void cheats_scroll_name();
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "charrom.h"
|
||||
#include "scaler.h"
|
||||
#include "miniz.h"
|
||||
#include "cheats.h"
|
||||
|
||||
#include "support.h"
|
||||
|
||||
@@ -622,6 +623,9 @@ void user_io_init(const char *path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cheats for boot file
|
||||
if (user_io_use_cheats()) cheats_init("", user_io_get_file_crc());
|
||||
}
|
||||
|
||||
if (is_cpc_core())
|
||||
|
||||
Reference in New Issue
Block a user