diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking.Defs.inc | 2 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc | 4 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc | 1 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 27 | ||||
-rw-r--r-- | src/plugins/mapcache.c | 106 |
5 files changed, 140 insertions, 0 deletions
diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index e5117e289..bd17dc7fe 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -6434,6 +6434,8 @@ typedef int (*HPMHOOK_pre_script_cleanfloor_sub) (struct block_list **bl, va_lis typedef int (*HPMHOOK_post_script_cleanfloor_sub) (int retVal___, struct block_list *bl, va_list ap); typedef int (*HPMHOOK_pre_script_run_func) (struct script_state **st); typedef int (*HPMHOOK_post_script_run_func) (int retVal___, struct script_state *st); +typedef bool (*HPMHOOK_pre_script_sprintf) (struct script_state **st, int *start, struct StringBuf **out); +typedef bool (*HPMHOOK_post_script_sprintf) (bool retVal___, struct script_state *st, int start, struct StringBuf *out); typedef const char* (*HPMHOOK_pre_script_getfuncname) (struct script_state **st); typedef const char* (*HPMHOOK_post_script_getfuncname) (const char* retVal___, struct script_state *st); typedef unsigned int (*HPMHOOK_pre_script_calc_hash_ci) (const char **p); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 0e027043e..9d531e370 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -5054,6 +5054,8 @@ struct { struct HPMHookPoint *HP_script_cleanfloor_sub_post; struct HPMHookPoint *HP_script_run_func_pre; struct HPMHookPoint *HP_script_run_func_post; + struct HPMHookPoint *HP_script_sprintf_pre; + struct HPMHookPoint *HP_script_sprintf_post; struct HPMHookPoint *HP_script_getfuncname_pre; struct HPMHookPoint *HP_script_getfuncname_post; struct HPMHookPoint *HP_script_calc_hash_ci_pre; @@ -11333,6 +11335,8 @@ struct { int HP_script_cleanfloor_sub_post; int HP_script_run_func_pre; int HP_script_run_func_post; + int HP_script_sprintf_pre; + int HP_script_sprintf_post; int HP_script_getfuncname_pre; int HP_script_getfuncname_post; int HP_script_calc_hash_ci_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index f668cfec6..5551668d2 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -2589,6 +2589,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(script->buildin_mobuseskill_sub, HP_script_buildin_mobuseskill_sub) }, { HP_POP(script->cleanfloor_sub, HP_script_cleanfloor_sub) }, { HP_POP(script->run_func, HP_script_run_func) }, + { HP_POP(script->sprintf, HP_script_sprintf) }, { HP_POP(script->getfuncname, HP_script_getfuncname) }, { HP_POP(script->calc_hash_ci, HP_script_calc_hash_ci) }, { HP_POP(script->array_src, HP_script_array_src) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 91c513fc0..2e20ab157 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -67480,6 +67480,33 @@ int HP_script_run_func(struct script_state *st) { } return retVal___; } +bool HP_script_sprintf(struct script_state *st, int start, struct StringBuf *out) { + int hIndex = 0; + bool retVal___ = false; + if (HPMHooks.count.HP_script_sprintf_pre > 0) { + bool (*preHookFunc) (struct script_state **st, int *start, struct StringBuf **out); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_script_sprintf_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_script_sprintf_pre[hIndex].func; + retVal___ = preHookFunc(&st, &start, &out); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.script.sprintf(st, start, out); + } + if (HPMHooks.count.HP_script_sprintf_post > 0) { + bool (*postHookFunc) (bool retVal___, struct script_state *st, int start, struct StringBuf *out); + for (hIndex = 0; hIndex < HPMHooks.count.HP_script_sprintf_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_script_sprintf_post[hIndex].func; + retVal___ = postHookFunc(retVal___, st, start, out); + } + } + return retVal___; +} const char* HP_script_getfuncname(struct script_state *st) { int hIndex = 0; const char* retVal___ = NULL; diff --git a/src/plugins/mapcache.c b/src/plugins/mapcache.c index f1dab97c1..5e44492f6 100644 --- a/src/plugins/mapcache.c +++ b/src/plugins/mapcache.c @@ -341,6 +341,100 @@ bool mapcache_rebuild(void) return true; } +bool fix_md5_truncation_sub(FILE *fp, const char *map_name) +{ + unsigned int file_size; + struct map_cache_header mheader = { 0 }; + uint8 *buf = NULL; + + nullpo_retr(false, fp); + nullpo_retr(false, map_name); + + fseek(fp, 0, SEEK_END); + file_size = (unsigned int)ftell(fp); + fseek(fp, 0, SEEK_SET); // Rewind file pointer before passing it to the read function. + + if (file_size <= sizeof(mheader) || fread(&mheader, sizeof(mheader), 1, fp) < 1) { + ShowError("fix_md5_truncation: Failed to read cache header for map '%s'.\n", map_name); + return false; + } + + if (mheader.len <= 0) { + ShowError("fix_md5_truncation: A file with negative or zero compressed length passed '%d'.\n", mheader.len); + return false; + } + + if (file_size < sizeof(mheader) + mheader.len) { + ShowError("fix_md5_truncation: An incomplete file passed for map '%s'.\n", map_name); + return false; + } + + CREATE(buf, uint8, mheader.len); + if (fread(buf, mheader.len, 1, fp) < 1) { + ShowError("fix_md5_truncation: Could not load the compressed cell data for map '%s'.\n", map_name); + aFree(buf); + return false; + } + + md5->binary(buf, mheader.len, mheader.md5_checksum); + aFree(buf); + + fseek(fp, 0, SEEK_SET); + fwrite(&mheader, sizeof(mheader), 1, fp); + fclose(fp); + + return true; +} + +bool fix_md5_truncation(void) +{ + int i; + bool retval = true; + + if (mapcache_read_maplist("db/map_index.txt") == false) { + ShowError("mapcache_rebuild: Could not read maplist, aborting\n"); + return false; + } + + for (i = 0; i < VECTOR_LENGTH(maplist); ++i) { + const char *map_name = VECTOR_INDEX(maplist, i); + char file_path[255]; + FILE *fp = NULL; + int16 version; + + snprintf(file_path, sizeof(file_path), "%s%s%s.%s", "maps/", DBPATH, map_name, "mcache"); + + fp = fopen(file_path, "r+b"); + + if (fp == NULL) { + ShowWarning("fix_md5_truncation: Could not open the mapcache file for map '%s' at path '%s'.\n", map_name, file_path); + retval = false; + continue; + } + + if (fread(&version, sizeof(version), 1, fp) < 1) { + ShowError("fix_md5_truncation: Could not read file version for map '%s'.\n", map_name); + fclose(fp); + retval = false; + continue; + } + + if (version != 1) { + ShowError("fix_md5_truncation: Mapcache for map '%s' has version %d. The update is only applied to version 1.\n", map_name, version); + fclose(fp); + continue; + } + + ShowStatus("Updating mapcache: %s'\n", map_name); + if (!fix_md5_truncation_sub(fp, map_name)) + retval = false; + + fclose(fp); + } + + return retval; +} + CMDLINEARG(convertmapcache) { map->minimal = true; @@ -363,6 +457,12 @@ CMDLINEARG(cachemap) return mapcache_cache_map(params); } +CMDLINEARG(fixmd5) +{ + map->minimal = true; + return fix_md5_truncation(); +} + HPExport void server_preinit(void) { addArg("--convert-old-mapcache", false, convertmapcache, @@ -371,6 +471,8 @@ HPExport void server_preinit(void) "Rebuilds the entire mapcache folder (maps/"DBPATH"), using db/map_index.txt as index."); addArg("--map", true, cachemap, "Rebuilds an individual map's cache into maps/"DBPATH" (usage: --map <map_name_without_extension>)."); + addArg("--fix-md5", false, fixmd5, + "Updates the checksum for the files in maps/"DBPATH", using db/map_index.txt as index (see PR #1981)."); needs_grfio = false; VECTOR_INIT(maplist); @@ -378,6 +480,10 @@ HPExport void server_preinit(void) HPExport void plugin_final(void) { + while (VECTOR_LENGTH(maplist) > 0) { + char *name = VECTOR_POP(maplist); + aFree(name); + } VECTOR_CLEAR(maplist); if (needs_grfio) grfio->final(); |