mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
Divorce content_crc from global struct
This commit is contained in:
parent
11f7735965
commit
058c3acbdc
22
content.c
22
content.c
@ -74,8 +74,11 @@ struct sram_block
|
||||
static bool read_content_file(unsigned i, const char *path, void **buf,
|
||||
ssize_t *length)
|
||||
{
|
||||
uint8_t *ret_buf = NULL;
|
||||
global_t *global = global_get_ptr();
|
||||
#ifdef HAVE_ZLIB
|
||||
uint32_t *content_crc_ptr = NULL;
|
||||
#endif
|
||||
uint8_t *ret_buf = NULL;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
RARCH_LOG("%s: %s.\n",
|
||||
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
|
||||
@ -93,9 +96,11 @@ static bool read_content_file(unsigned i, const char *path, void **buf,
|
||||
patch_content(&ret_buf, length);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
global->content_crc = zlib_crc32_calculate(ret_buf, *length);
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)global->content_crc);
|
||||
*content_crc_ptr = zlib_crc32_calculate(ret_buf, *length);
|
||||
|
||||
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)*content_crc_ptr);
|
||||
#endif
|
||||
*buf = ret_buf;
|
||||
|
||||
@ -756,6 +761,7 @@ bool content_ctl(enum content_ctl_state state, void *data)
|
||||
static struct string_list *temporary_content = NULL;
|
||||
static bool content_is_inited = false;
|
||||
static bool core_does_not_need_content = false;
|
||||
static uint32_t content_crc = 0;
|
||||
|
||||
switch(state)
|
||||
{
|
||||
@ -764,6 +770,13 @@ bool content_ctl(enum content_ctl_state state, void *data)
|
||||
case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT:
|
||||
core_does_not_need_content = true;
|
||||
break;
|
||||
case CONTENT_CTL_GET_CRC:
|
||||
{
|
||||
uint32_t **content_crc_ptr = (uint32_t**)data;
|
||||
if (!content_crc_ptr)
|
||||
return false;
|
||||
*content_crc_ptr = &content_crc;
|
||||
}
|
||||
case CONTENT_CTL_LOAD_STATE:
|
||||
{
|
||||
const char *path = (const char*)data;
|
||||
@ -782,6 +795,7 @@ bool content_ctl(enum content_ctl_state state, void *data)
|
||||
return content_is_inited;
|
||||
case CONTENT_CTL_DEINIT:
|
||||
content_ctl(CONTENT_CTL_TEMPORARY_FREE, NULL);
|
||||
content_crc = 0;
|
||||
content_is_inited = false;
|
||||
core_does_not_need_content = false;
|
||||
break;
|
||||
|
@ -43,6 +43,8 @@ enum content_ctl_state
|
||||
|
||||
CONTENT_CTL_DEINIT,
|
||||
|
||||
CONTENT_CTL_GET_CRC,
|
||||
|
||||
/* Load a state from disk to memory. */
|
||||
CONTENT_CTL_LOAD_STATE,
|
||||
|
||||
|
21
movie.c
21
movie.c
@ -22,6 +22,7 @@
|
||||
#include <retro_endianness.h>
|
||||
|
||||
#include "movie.h"
|
||||
#include "content.h"
|
||||
#include "general.h"
|
||||
#include "msg_hash.h"
|
||||
#include "verbosity.h"
|
||||
@ -66,11 +67,11 @@ struct bsv_state bsv_movie_state;
|
||||
static bool init_playback(bsv_movie_t *handle, const char *path)
|
||||
{
|
||||
uint32_t state_size;
|
||||
uint32_t header[4] = {0};
|
||||
global_t *global = global_get_ptr();
|
||||
uint32_t *content_crc_ptr = NULL;
|
||||
uint32_t header[4] = {0};
|
||||
|
||||
handle->playback = true;
|
||||
handle->file = fopen(path, "rb");
|
||||
handle->playback = true;
|
||||
handle->file = fopen(path, "rb");
|
||||
|
||||
if (!handle->file)
|
||||
{
|
||||
@ -93,7 +94,9 @@ static bool init_playback(bsv_movie_t *handle, const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (swap_if_big32(header[CRC_INDEX]) != global->content_crc)
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
if (swap_if_big32(header[CRC_INDEX]) != *content_crc_ptr)
|
||||
RARCH_WARN("CRC32 checksum mismatch between content file and saved content checksum in replay file header; replay highly likely to desync on playback.\n");
|
||||
|
||||
state_size = swap_if_big32(header[STATE_SIZE_INDEX]);
|
||||
@ -125,8 +128,8 @@ static bool init_playback(bsv_movie_t *handle, const char *path)
|
||||
static bool init_record(bsv_movie_t *handle, const char *path)
|
||||
{
|
||||
uint32_t state_size;
|
||||
uint32_t header[4] = {0};
|
||||
global_t *global = global_get_ptr();
|
||||
uint32_t header[4] = {0};
|
||||
uint32_t *content_crc_ptr = NULL;
|
||||
|
||||
handle->file = fopen(path, "wb");
|
||||
if (!handle->file)
|
||||
@ -135,10 +138,12 @@ static bool init_record(bsv_movie_t *handle, const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
/* This value is supposed to show up as
|
||||
* BSV1 in a HEX editor, big-endian. */
|
||||
header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC);
|
||||
header[CRC_INDEX] = swap_if_big32(global->content_crc);
|
||||
header[CRC_INDEX] = swap_if_big32(*content_crc_ptr);
|
||||
state_size = core.retro_serialize_size();
|
||||
header[STATE_SIZE_INDEX] = swap_if_big32(state_size);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
|
||||
#include "netplay_private.h"
|
||||
#include "../content.h"
|
||||
|
||||
bool np_get_nickname(netplay_t *netplay, int fd)
|
||||
{
|
||||
uint8_t nick_size;
|
||||
@ -60,10 +62,10 @@ bool np_send_nickname(netplay_t *netplay, int fd)
|
||||
|
||||
uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic)
|
||||
{
|
||||
uint32_t *content_crc_ptr;
|
||||
uint32_t *header, bsv_header[4] = {0};
|
||||
size_t serialize_size = core.retro_serialize_size();
|
||||
size_t header_size = sizeof(bsv_header) + serialize_size;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
*size = header_size;
|
||||
|
||||
@ -71,9 +73,11 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic)
|
||||
if (!header)
|
||||
return NULL;
|
||||
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
bsv_header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC);
|
||||
bsv_header[SERIALIZER_INDEX] = swap_if_big32(magic);
|
||||
bsv_header[CRC_INDEX] = swap_if_big32(global->content_crc);
|
||||
bsv_header[CRC_INDEX] = swap_if_big32(*content_crc_ptr);
|
||||
bsv_header[STATE_SIZE_INDEX] = swap_if_big32(serialize_size);
|
||||
|
||||
if (serialize_size && !core.retro_serialize(header + 4, serialize_size))
|
||||
@ -88,9 +92,9 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic)
|
||||
|
||||
bool np_bsv_parse_header(const uint32_t *header, uint32_t magic)
|
||||
{
|
||||
uint32_t *content_crc_ptr;
|
||||
uint32_t in_crc, in_magic, in_state_size;
|
||||
uint32_t in_bsv = swap_if_little32(header[MAGIC_INDEX]);
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (in_bsv != BSV_MAGIC)
|
||||
{
|
||||
@ -107,10 +111,13 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic)
|
||||
}
|
||||
|
||||
in_crc = swap_if_big32(header[CRC_INDEX]);
|
||||
if (in_crc != global->content_crc)
|
||||
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
if (in_crc != *content_crc_ptr)
|
||||
{
|
||||
RARCH_ERR("CRC32 mismatch, got 0x%x, expected 0x%x.\n", in_crc,
|
||||
global->content_crc);
|
||||
*content_crc_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -171,12 +178,14 @@ uint32_t np_impl_magic(void)
|
||||
bool np_send_info(netplay_t *netplay)
|
||||
{
|
||||
unsigned sram_size;
|
||||
char msg[512] = {0};
|
||||
void *sram = NULL;
|
||||
uint32_t header[3] = {0};
|
||||
global_t *global = global_get_ptr();
|
||||
char msg[512] = {0};
|
||||
uint32_t *content_crc_ptr = NULL;
|
||||
void *sram = NULL;
|
||||
uint32_t header[3] = {0};
|
||||
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
header[0] = htonl(global->content_crc);
|
||||
header[0] = htonl(*content_crc_ptr);
|
||||
header[1] = htonl(np_impl_magic());
|
||||
header[2] = htonl(core.retro_get_memory_size(RETRO_MEMORY_SAVE_RAM));
|
||||
|
||||
@ -216,8 +225,8 @@ bool np_get_info(netplay_t *netplay)
|
||||
{
|
||||
unsigned sram_size;
|
||||
uint32_t header[3];
|
||||
const void *sram = NULL;
|
||||
global_t *global = global_get_ptr();
|
||||
uint32_t *content_crc_ptr = NULL;
|
||||
const void *sram = NULL;
|
||||
|
||||
if (!socket_receive_all_blocking(netplay->fd, header, sizeof(header)))
|
||||
{
|
||||
@ -225,7 +234,9 @@ bool np_get_info(netplay_t *netplay)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (global->content_crc != ntohl(header[0]))
|
||||
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
||||
|
||||
if (*content_crc_ptr != ntohl(header[0]))
|
||||
{
|
||||
RARCH_ERR("Content CRC32s differ. Cannot use different games.\n");
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user