3
0
mirror of https://github.com/CrazyRedMachine/popnhax.git synced 2024-11-23 22:00:57 +01:00

use tinycurl, dynamic loading

This commit is contained in:
CrazyRedMachine 2024-07-22 22:24:19 +02:00
parent 10df260174
commit 5922e0d820
7 changed files with 90 additions and 141 deletions

View File

@ -49,7 +49,7 @@ cflags := -O3 -pipe -ffunction-sections -fdata-sections \
cxxflags := -O3 -pipe -ffunction-sections -fdata-sections \ cxxflags := -O3 -pipe -ffunction-sections -fdata-sections \
-std=c++11 $(wxxflags) -std=c++11 $(wxxflags)
ldflags := -Wl,--gc-sections -static -static-libgcc -lstdc++ -L./libcurl/ -llibcurl \ ldflags := -Wl,--gc-sections -static -static-libgcc -lstdc++ \
-fdiagnostics-color -Werror \ -fdiagnostics-color -Werror \
-Wl,--gc-keep-exported \ -Wl,--gc-keep-exported \
-Wl,--enable-auto-image-base \ -Wl,--enable-auto-image-base \

Binary file not shown.

Binary file not shown.

View File

@ -1,105 +0,0 @@
LIBRARY LIBCURL
EXPORTS
curl_dbg_accept
curl_dbg_calloc
curl_dbg_fclose
curl_dbg_fdopen
curl_dbg_fopen
curl_dbg_free
curl_dbg_log
curl_dbg_malloc
curl_dbg_mark_sclose
curl_dbg_memdebug
curl_dbg_memlimit
curl_dbg_realloc
curl_dbg_recv
curl_dbg_sclose
curl_dbg_send
curl_dbg_socket
curl_dbg_strdup
curl_easy_cleanup
curl_easy_duphandle
curl_easy_escape
curl_easy_getinfo
curl_easy_init
curl_easy_option_by_id
curl_easy_option_by_name
curl_easy_option_next
curl_easy_pause
curl_easy_perform
curl_easy_perform_ev
curl_easy_recv
curl_easy_reset
curl_easy_send
curl_easy_setopt
curl_easy_strerror
curl_easy_unescape
curl_easy_upkeep
curl_escape
curl_formadd
curl_formfree
curl_formget
curl_free
curl_getdate
curl_getenv
curl_global_cleanup
curl_global_init
curl_global_init_mem
curl_global_sslset
curl_maprintf
curl_mfprintf
curl_mime_addpart
curl_mime_data
curl_mime_data_cb
curl_mime_encoder
curl_mime_filedata
curl_mime_filename
curl_mime_free
curl_mime_headers
curl_mime_init
curl_mime_name
curl_mime_subparts
curl_mime_type
curl_mprintf
curl_msnprintf
curl_msprintf
curl_multi_add_handle
curl_multi_assign
curl_multi_cleanup
curl_multi_fdset
curl_multi_info_read
curl_multi_init
curl_multi_perform
curl_multi_poll
curl_multi_remove_handle
curl_multi_setopt
curl_multi_socket
curl_multi_socket_action
curl_multi_socket_all
curl_multi_strerror
curl_multi_timeout
curl_multi_wait
curl_multi_wakeup
curl_mvaprintf
curl_mvfprintf
curl_mvprintf
curl_mvsnprintf
curl_mvsprintf
curl_pushheader_byname
curl_pushheader_bynum
curl_share_cleanup
curl_share_init
curl_share_setopt
curl_share_strerror
curl_slist_append
curl_slist_free_all
curl_strequal
curl_strnequal
curl_unescape
curl_url
curl_url_cleanup
curl_url_dup
curl_url_get
curl_url_set
curl_version
curl_version_info

Binary file not shown.

View File

@ -36,7 +36,7 @@
#include "SearchFile.h" #include "SearchFile.h"
#define PROGRAM_VERSION "2.2" #define PROGRAM_VERSION "2.3.dev"
const char *g_game_dll_fn = NULL; const char *g_game_dll_fn = NULL;
char *g_config_fn = NULL; char *g_config_fn = NULL;

View File

@ -49,6 +49,46 @@ fprintf(stderr, __VA_ARGS__); \
#define SCORE_TABLE_COMPARE(cmp_a, cmp_b) chash_string_compare(cmp_a, cmp_b) #define SCORE_TABLE_COMPARE(cmp_a, cmp_b) chash_string_compare(cmp_a, cmp_b)
#define SCORE_TABLE_INIT(bucket, _key, _value) chash_default_init(bucket, _key, _value) #define SCORE_TABLE_INIT(bucket, _key, _value) chash_default_init(bucket, _key, _value)
/* libcurl imports */
typedef CURL* (*curl_easy_init_fn_t)(void);
typedef CURLcode (*curl_easy_setopt_fn_t)(CURL *curl, CURLoption option, ...);
typedef CURLcode (*curl_easy_perform_fn_t)(CURL *curl);
typedef void (*curl_easy_cleanup_fn_t)(CURL *curl);
typedef struct curl_slist* (*curl_slist_append_fn_t)(struct curl_slist *, const char *);
typedef void (*curl_slist_free_all_fn_t)(struct curl_slist *);
curl_slist_append_fn_t _curl_slist_append = NULL;
curl_slist_free_all_fn_t _curl_slist_free_all = NULL;
curl_easy_init_fn_t _curl_easy_init = NULL;
curl_easy_setopt_fn_t _curl_easy_setopt = NULL;
curl_easy_perform_fn_t _curl_easy_perform = NULL;
curl_easy_cleanup_fn_t _curl_easy_cleanup = NULL;
HINSTANCE g_libcurl = NULL;
/* */
bool load_libcurl()
{
if ( g_libcurl != NULL )
return true; //already done
g_libcurl = LoadLibrary("libcurl.dll");
if ( g_libcurl == NULL )
return false;
_curl_easy_init = (curl_easy_init_fn_t)GetProcAddress(g_libcurl, "curl_easy_init");
_curl_easy_setopt = (curl_easy_setopt_fn_t)GetProcAddress(g_libcurl, "curl_easy_setopt");
_curl_easy_perform = (curl_easy_perform_fn_t)GetProcAddress(g_libcurl, "curl_easy_perform");
_curl_easy_cleanup = (curl_easy_cleanup_fn_t)GetProcAddress(g_libcurl, "curl_easy_cleanup");
_curl_slist_append = (curl_slist_append_fn_t)GetProcAddress(g_libcurl, "curl_slist_append");
_curl_slist_free_all = (curl_slist_free_all_fn_t)GetProcAddress(g_libcurl, "curl_slist_free_all");
return ( _curl_easy_init != NULL
&& _curl_easy_setopt != NULL
&& _curl_easy_perform != NULL
&& _curl_easy_cleanup != NULL
&& _curl_slist_append != NULL
&& _curl_slist_free_all != NULL);
}
#pragma pack(1) #pragma pack(1)
typedef struct score_info_s { typedef struct score_info_s {
uint32_t score; uint32_t score;
@ -456,17 +496,17 @@ static size_t parse_rivals(void *ptr, size_t size, size_t nmemb, void *data)
bool tachi_get_status() bool tachi_get_status()
{ {
CURL *curl = curl_easy_init(); CURL *curl = _curl_easy_init();
if(!curl) if(!curl)
return false; return false;
curl_easy_setopt(curl, CURLOPT_URL, g_status_url); _curl_easy_setopt(curl, CURLOPT_URL, g_status_url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); _curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); _curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&g_curl_data); _curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&g_curl_data);
CURLcode res = curl_easy_perform(curl); CURLcode res = _curl_easy_perform(curl);
curl_easy_cleanup(curl); _curl_easy_cleanup(curl);
return (res == CURLE_OK); return (res == CURLE_OK);
} }
@ -715,7 +755,7 @@ bool tachi_send_score()
}", g_score_info->score, g_clear_medal[g_score_info->clear_type], song_id, curr_time, diff, g_score_info->nb_fast, g_score_info->nb_slow, g_score_info->max_combo, gauge, g_score_info->nb_cool, g_score_info->nb_great, g_score_info->nb_good, g_score_info->nb_bad, hispeed, (g_hidden_is_offset) ? 0 : g_song_info->hidden_value, g_song_info->sudden_value, g_random_type[g_song_info->random], g_gauge_type[g_song_info->gauge_type]); }", g_score_info->score, g_clear_medal[g_score_info->clear_type], song_id, curr_time, diff, g_score_info->nb_fast, g_score_info->nb_slow, g_score_info->max_combo, gauge, g_score_info->nb_cool, g_score_info->nb_great, g_score_info->nb_good, g_score_info->nb_bad, hispeed, (g_hidden_is_offset) ? 0 : g_song_info->hidden_value, g_song_info->sudden_value, g_random_type[g_song_info->random], g_gauge_type[g_song_info->gauge_type]);
/* curl request */ /* curl request */
CURL *curl = curl_easy_init(); CURL *curl = _curl_easy_init();
struct curl_slist *list = NULL; struct curl_slist *list = NULL;
@ -726,17 +766,17 @@ bool tachi_send_score()
if(curl) if(curl)
{ {
curl_easy_setopt(curl, CURLOPT_URL, g_import_url); _curl_easy_setopt(curl, CURLOPT_URL, g_import_url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); _curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
list = curl_slist_append(list, auth_header); list = _curl_slist_append(list, auth_header);
list = curl_slist_append(list, "Content-Type: application/json"); list = _curl_slist_append(list, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, score_json); _curl_easy_setopt(curl, CURLOPT_POSTFIELDS, score_json);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); _curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_perform(curl); _curl_easy_perform(curl);
curl_slist_free_all(list); _curl_slist_free_all(list);
curl_easy_cleanup(curl); _curl_easy_cleanup(curl);
} }
return false; return false;
@ -747,7 +787,7 @@ bool tachi_get_rival_scores(int idx)
if ( !load_profile_if_needed() ) if ( !load_profile_if_needed() )
return false; return false;
CURL *curl = curl_easy_init(); CURL *curl = _curl_easy_init();
if(!curl) if(!curl)
return false; return false;
@ -765,16 +805,16 @@ bool tachi_get_rival_scores(int idx)
g_curl_data.size = 0; g_curl_data.size = 0;
} }
curl_easy_setopt(curl, CURLOPT_URL, rival_url); _curl_easy_setopt(curl, CURLOPT_URL, rival_url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); _curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
list = curl_slist_append(list, auth_header); list = _curl_slist_append(list, auth_header);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); _curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); _curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&g_curl_data); _curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&g_curl_data);
CURLcode res = curl_easy_perform(curl); CURLcode res = _curl_easy_perform(curl);
curl_easy_cleanup(curl); _curl_easy_cleanup(curl);
return (res == CURLE_OK); return (res == CURLE_OK);
} }
@ -806,7 +846,7 @@ bool tachi_get_rivals()
if ( !load_profile_if_needed() ) if ( !load_profile_if_needed() )
return false; return false;
CURL *curl = curl_easy_init(); CURL *curl = _curl_easy_init();
if(!curl) if(!curl)
return false; return false;
@ -814,15 +854,15 @@ bool tachi_get_rivals()
char auth_header[128]; char auth_header[128];
sprintf(auth_header, "Authorization: Bearer %s", g_api_key); sprintf(auth_header, "Authorization: Bearer %s", g_api_key);
curl_easy_setopt(curl, CURLOPT_URL, g_rivals_url); _curl_easy_setopt(curl, CURLOPT_URL, g_rivals_url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); _curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
list = curl_slist_append(list, auth_header); list = _curl_slist_append(list, auth_header);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); _curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, parse_rivals); _curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, parse_rivals);
CURLcode res = curl_easy_perform(curl); CURLcode res = _curl_easy_perform(curl);
curl_easy_cleanup(curl); _curl_easy_cleanup(curl);
if ( res != CURLE_OK ) if ( res != CURLE_OK )
CURL_PRINT("[tachi] WARNING: get rivals request failed\n"); CURL_PRINT("[tachi] WARNING: get rivals request failed\n");
@ -1016,6 +1056,13 @@ bool patch_tachi_rivals(const char *dllFilename, bool scorehook)
g_curl_log_fp = fopen("popnhax_curl.log", "w"); g_curl_log_fp = fopen("popnhax_curl.log", "w");
#endif #endif
if ( !load_libcurl())
{
LOG("popnhax: tachi rivals: cannot load libcurl\n");
g_libcurl = NULL;
return false;
}
/* retrieve get_rivals_ptr() */ /* retrieve get_rivals_ptr() */
{ {
int64_t pattern_offset = search(data, dllSize, "\x0F\xB6\x8E\x38\x02\x00\x00", 7, 0); int64_t pattern_offset = search(data, dllSize, "\x0F\xB6\x8E\x38\x02\x00\x00", 7, 0);
@ -1124,6 +1171,13 @@ bool patch_tachi_scorehook(const char *dllFilename, bool pfree, bool hidden_is_o
g_curl_log_fp = fopen("popnhax_curl.log", "w"); g_curl_log_fp = fopen("popnhax_curl.log", "w");
#endif #endif
if ( !load_libcurl())
{
LOG("popnhax: tachi scorehook: cannot load libcurl\n");
g_libcurl = NULL;
return false;
}
/* do not send a "hidden" value if it really is an offset */ /* do not send a "hidden" value if it really is an offset */
if (hidden_is_offset) if (hidden_is_offset)
g_hidden_is_offset = 1; g_hidden_is_offset = 1;