From ff2d6b9c2bcbe5caa476042610e0acaa838b144c Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Wed, 14 Oct 2015 20:52:25 -0300 Subject: [PATCH 1/3] removed special snes case, recompute md5 if the first one fails instead --- cheevos.c | 94 +++++++++++++++++++++++++++++++++---------------------- cheevos.h | 7 +---- content.c | 2 +- 3 files changed, 58 insertions(+), 45 deletions(-) diff --git a/cheevos.c b/cheevos.c index 28ab1d2af7..4b97355771 100644 --- a/cheevos.c +++ b/cheevos.c @@ -1321,42 +1321,14 @@ int cheevos_get_by_game_id( const char** json, unsigned game_id ) return 0; } -#define CHEEVOS_EIGHT_MB ( 8 * 1024 * 1024 ) - -int cheevos_get_by_content( const char** json, const void* data, size_t size, unsigned flags ) +static unsigned cheevos_get_game_id( unsigned char* hash ) { MD5_CTX ctx; - char buffer[ 4096 ]; - size_t len; - unsigned char hash[ 16 ]; char request[ 256 ]; + const char* json; char game_id[ 16 ]; int res; - MD5_Init( &ctx ); - MD5_Update( &ctx, data, size ); - - if ( ( flags & CHEEVOS_FLAGS_IS_SNES ) && size < CHEEVOS_EIGHT_MB ) - { - size = CHEEVOS_EIGHT_MB - size; - memset( (void*)buffer, 0, sizeof( buffer ) ); - - while ( size ) - { - len = sizeof( buffer ); - - if ( len > size ) - { - len = size; - } - - MD5_Update( &ctx, (void*)buffer, len ); - size -= len; - } - } - - MD5_Final( hash, &ctx ); - snprintf( request, sizeof( request ), "http://retroachievements.org/dorequest.php?r=gameid&u=%s&m=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -1369,23 +1341,69 @@ int cheevos_get_by_content( const char** json, const void* data, size_t size, un request[ sizeof( request ) - 1 ] = 0; - *json = cheevos_http_get( request, NULL ); + json = cheevos_http_get( request, NULL ); - if ( !*json ) + if ( !json ) { return -1; } - res = cheevos_get_value( *json, 0xb4960eecU /* GameID */, game_id, sizeof( game_id ) ); - free( (void*)*json ); + res = cheevos_get_value( json, 0xb4960eecU /* GameID */, game_id, sizeof( game_id ) ); + free( (void*)json ); - if ( !res ) + return res ? 0 : strtoul( game_id, NULL, 10 ); +} + +#define CHEEVOS_EIGHT_MB ( 8 * 1024 * 1024 ) + +int cheevos_get_by_content( const char** json, const void* data, size_t size ) +{ + MD5_CTX ctx, saved_ctx; + char buffer[ 4096 ]; + size_t len; + unsigned char hash[ 16 ]; + char request[ 256 ]; + unsigned game_id; + int res; + + MD5_Init( &ctx ); + MD5_Update( &ctx, data, size ); + saved_ctx = ctx; + MD5_Final( hash, &ctx ); + + game_id = cheevos_get_game_id( hash ); + + if ( !game_id ) { - RARCH_LOG( "game id is %s\n", game_id ); - res = cheevos_get_by_game_id( json, strtoul( game_id, NULL, 10 ) ); + /* If the content is a SNES game, continue MD5 with zeroes. */ + size = CHEEVOS_EIGHT_MB - size; + memset( (void*)buffer, 0, sizeof( buffer ) ); + + while ( size ) + { + len = sizeof( buffer ); + + if ( len > size ) + { + len = size; + } + + MD5_Update( &saved_ctx, (void*)buffer, len ); + size -= len; + } + + MD5_Final( hash, &saved_ctx ); + + game_id = cheevos_get_game_id( hash ); + + if ( !game_id ) + { + return -1; + } } - return res; + RARCH_LOG( "cheevos game id is %u\n", game_id ); + return cheevos_get_by_game_id( json, game_id ); } #else /* HAVE_CHEEVOS */ diff --git a/cheevos.h b/cheevos.h index a8dfdc27f0..ce37e89495 100644 --- a/cheevos.h +++ b/cheevos.h @@ -29,17 +29,12 @@ typedef struct } cheevos_config_t; -enum -{ - CHEEVOS_FLAGS_IS_SNES = 1 << 0, /* forces * mb padded with zeroes */ -}; - extern cheevos_config_t cheevos_config; int cheevos_load( const char* json ); void cheevos_test( void ); void cheevos_unload( void ); int cheevos_get_by_game_id( const char** json, unsigned game_id ); -int cheevos_get_by_content( const char** json, const void* data, size_t size, unsigned flags ); +int cheevos_get_by_content( const char** json, const void* data, size_t size ); #endif /* __RARCH_CHEEVOS_H */ diff --git a/content.c b/content.c index aff3bfab2a..1fbd1f51d6 100644 --- a/content.c +++ b/content.c @@ -515,7 +515,7 @@ static bool load_content(const struct retro_subsystem_info *special, { if (*content->elems[0].data) { - if ( cheevos_get_by_content(&json, info->data, info->size, CHEEVOS_FLAGS_IS_SNES) == 0 ) + if ( cheevos_get_by_content(&json, info->data, info->size) == 0 ) { cheevos_load(json); free((void*)json); From 3f1d902aada2f738b63e1d8f7a0fe6dc9181e929 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Wed, 14 Oct 2015 21:08:19 -0300 Subject: [PATCH 2/3] show achievement using osd messages --- cheevos.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cheevos.c b/cheevos.c index 4b97355771..ab09d23375 100644 --- a/cheevos.c +++ b/cheevos.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "cheevos.h" @@ -1028,6 +1029,10 @@ static void test_cheevo_set( const cheevoset_t* set ) { RARCH_LOG( "ACHIEVEMENT! %s\n", cheevo->title ); RARCH_LOG( "ACHIEVEMENT! %s\n", cheevo->description ); + + rarch_main_msg_queue_push( cheevo->title, 0, 3 * 60, false ); + rarch_main_msg_queue_push( cheevo->description, 0, 5 * 60, false ); + cheevo->active = 0; } } From 6cce351e3d178a599f3ea5a513277d1e81730dc5 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Wed, 14 Oct 2015 21:30:23 -0300 Subject: [PATCH 3/3] prefix log messages with CHEEVOS --- cheevos.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cheevos.c b/cheevos.c index ab09d23375..531ad2597f 100644 --- a/cheevos.c +++ b/cheevos.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -983,7 +984,7 @@ static int test_cheevo( cheevo_t* cheevo ) if ( condset < end ) { ret_val = test_cond_set( condset, &dirty_conds, &reset_conds, 0 ); - if ( ret_val ) RARCH_LOG( "%s\n", condset->expression ); + if ( ret_val ) RARCH_LOG( "CHEEVOS %s\n", condset->expression ); condset++; } @@ -991,7 +992,7 @@ static int test_cheevo( cheevo_t* cheevo ) { int res = test_cond_set( condset, &dirty_conds, &reset_conds, 0 ); ret_val_sub_cond |= res; - if ( res ) RARCH_LOG( "%s\n", condset->expression ); + if ( res ) RARCH_LOG( "CHEEVOS %s\n", condset->expression ); condset++; } @@ -1027,8 +1028,8 @@ static void test_cheevo_set( const cheevoset_t* set ) { if ( cheevo->active && test_cheevo( cheevo ) ) { - RARCH_LOG( "ACHIEVEMENT! %s\n", cheevo->title ); - RARCH_LOG( "ACHIEVEMENT! %s\n", cheevo->description ); + RARCH_LOG( "CHEEVOS %s\n", cheevo->title ); + RARCH_LOG( "CHEEVOS %s\n", cheevo->description ); rarch_main_msg_queue_push( cheevo->title, 0, 3 * 60, false ); rarch_main_msg_queue_push( cheevo->description, 0, 5 * 60, false ); @@ -1103,7 +1104,7 @@ static const char* cheevos_http_get( const char* url, size_t* size ) size_t length; char* result; - RARCH_LOG( "HTTP GET %s\n", url ); + RARCH_LOG( "CHEEVOS http get %s\n", url ); conn = net_http_connection_new( url ); if ( !conn ) @@ -1151,7 +1152,7 @@ error1: net_http_delete( http ); net_http_connection_free( conn ); - RARCH_LOG( "HTTP result is %s\n", result ); + RARCH_LOG( "CHEEVOS http result is %s\n", result ); if ( size ) { @@ -1162,8 +1163,8 @@ error1: #else /* HAVE_NETWORKING */ - RARCH_LOG( "HTTP GET %s\n", url ); - RARCH_ERROR( "Network unavailable\n" ); + RARCH_LOG( "CHEEVOS http get %s\n", url ); + RARCH_ERROR( "CHEEVOS Network unavailable\n" ); if ( size ) { @@ -1298,7 +1299,7 @@ static int cheevos_login( void ) res = cheevos_get_value( json, 0x0e2dbd26U /* Token */, cheevos_config.token, sizeof( cheevos_config.token ) ); } - RARCH_LOG( "cheevos user token is %s\n", cheevos_config.token ); + RARCH_LOG( "CHEEVOS user token is %s\n", cheevos_config.token ); return res; } @@ -1407,7 +1408,7 @@ int cheevos_get_by_content( const char** json, const void* data, size_t size ) } } - RARCH_LOG( "cheevos game id is %u\n", game_id ); + RARCH_LOG( "CHEEVOS game id is %u\n", game_id ); return cheevos_get_by_game_id( json, game_id ); }