support for hotpatching to restore ADV patch support

This commit is contained in:
Ondřej Novák 2025-03-25 19:47:01 +01:00
parent 2be7f5d2b2
commit 04b57b4088
14 changed files with 168 additions and 278 deletions

View file

@ -49,6 +49,8 @@ static void process_row(INI_CONFIG_SECTION *sec, const char *row) {
ini_replace_key(sec, "dialogs", file_icase_find(value));
} else if (istrcmp(key, "DEFAULT_MAP") == 0) {
ini_replace_key(sec, "default_map", value);
} else if (istrcmp(key, "PATCH_FILE") == 0) {
ini_replace_key(sec, "patch_file", file_icase_find(value));
}
}

View file

@ -582,7 +582,7 @@ void bott_text_forever()
bott_timer=NULL;
}
const void *bott_draw_proc(const void *p, int32_t *s)
const void *bott_draw_proc(const void *p, int32_t *s, int h)
{
switch (bott_display)
{

View file

@ -1435,7 +1435,6 @@ void call_dialog(int entr,int mob)
goto_paragraph(entr);
schovej_mysku();
alock(H_DIALOGY_DAT);
aswap(H_DIALOGY_DAT);
selected_player=-1;
do_dialog();
}
@ -1482,7 +1481,6 @@ char load_dialog_info(TMPFILE_RD *f)
SEND_LOG("(DIALOGS)(SAVELOAD) Loading dialogs info...");
p=ablock_copy(H_DIALOGY_DAT);
aswap(H_DIALOGY_DAT);
temp_storage_read(&pgf_pocet,1*4,f);
siz=(pgf_pocet+3)/4;
if (pgf_pocet!=*p)

View file

@ -511,11 +511,15 @@ static void add_status_file(FILE *f, const char *name, size_t sz, void *data) {
static void pack_status_file_cb(const char *name, void *ctx) {
FILE *f = ctx;
int32_t sz = temp_storage_find(name);
assert(sz > 0);
void *data = getmem(sz);
temp_storage_retrieve(name, data, sz);
add_status_file(f, name, sz, data);
free(data);
assert(sz >= 0);
if (sz == 0) {
add_status_file(f, name, 0, 0);
} else {
void *data = getmem(sz);
temp_storage_retrieve(name, data, sz);
add_status_file(f, name, sz, data);
free(data);
}
}
int pack_all_status(FILE *f)

View file

@ -636,18 +636,18 @@ void calc_animations(void);
int load_map(const char *filename);
void other_draw(void);
void refresh_scene(THE_TIMER *t);
const void *pcx_fade_decomp(const void *p, int32_t *s);
const void *pcx_15bit_decomp(const void *p, int32_t *s);
const void *pcx_15bit_autofade(const void *p, int32_t *s);
const void *pcx_15bit_backgrnd(const void *p, int32_t *s);
const void *pcx_8bit_decomp(const void *p, int32_t *s);
const void *hi_8bit_correct(const void *p, int32_t *s);
const void *pcx_8bit_nopal(const void *p, int32_t *s);
const void *set_background(const void *p, int32_t *s);
const void *wav_load(const void *p, int32_t *s);
const void *load_mob_legacy_format_direct(const void *p, int32_t *s);
const void *load_mob_legacy_format(const void *p, int32_t *s);
const void *load_spells_legacy_format(const void *p, int32_t *s);
const void *pcx_fade_decomp(const void *p, int32_t *s, int h);
const void *pcx_15bit_decomp(const void *p, int32_t *s, int h);
const void *pcx_15bit_autofade(const void *p, int32_t *s, int h);
const void *pcx_15bit_backgrnd(const void *p, int32_t *s, int h);
const void *pcx_8bit_decomp(const void *p, int32_t *s, int h);
const void *hi_8bit_correct(const void *p, int32_t *s, int h);
const void *pcx_8bit_nopal(const void *p, int32_t *s, int h);
const void *set_background(const void *p, int32_t *s, int h);
const void *wav_load(const void *p, int32_t *s, int h);
const void *load_mob_legacy_format_direct(const void *p, int32_t *s, int h);
const void *load_mob_legacy_format(const void *p, int32_t *s, int h);
const void *load_spells_legacy_format(const void *p, int32_t *s, int h);
void wire_main_functs(void);
void ukaz_kompas(char mode);
void timming(EVENT_MSG *msg,void **data);
@ -663,7 +663,7 @@ void mouse_set_cursor(int cursor);
#define FONT_TSHADOW_GRAY 0x30000
void set_font(int font,int c1,...);
void bott_draw(char);
const void *bott_draw_proc(const void *p, int32_t *s);
const void *bott_draw_proc(const void *p, int32_t *s, int h);
void mouse_set_default(int cursor);
void create_frame(int x,int y,int xs,int ys,char clear);
void save_dump(const uint16_t *screen_addr,
@ -994,7 +994,7 @@ void calc_fly(THE_TIMER *t);
void zmen_skupinu(THUMAN *p);
void add_to_group(int num);
void group_all(void);
const void *build_items_called(const void *p, int32_t *s);
const void *build_items_called(const void *p, int32_t *s, int h);
void real_regeneration(THE_TIMER *t); //regenerace postav behem hry v realu (pouze kondice a mana)
char sleep_regenerace(THUMAN *p); //regenerace postav behem spani
char check_jidlo_voda(THUMAN *p);
@ -1688,7 +1688,7 @@ int message(int butts,char def,char canc,char *keys,...);
void type_text(EVENT_MSG *msg,void **data); //event procedura (parms: X,Y,TEXT,MAX_SPACE,MAX_CHARS);
void type_text_v2(va_list args);//char *text_buffer,int x,int y,int max_size,int max_chars,int font,int color,void (*exit_proc)(char));
void zalamovani(const char *source,char *target,int maxxs,int *xs,int *ys);
const void *col_load(const void *data, int32_t *size);
const void *col_load(const void *data, int32_t *size, int h);
void open_story_file(void);
void write_story_text(char *text);
void close_story_file(void);

View file

@ -532,7 +532,7 @@ void type_text_v2(va_list args)
}
const void *col_load(const void *data, int32_t *size)
const void *col_load(const void *data, int32_t *size, int h)
{
int siz=*size;
char *s;

View file

@ -1246,9 +1246,9 @@ void *build_items_wearing(THUMAN *h, int32_t *s)
}
const void *build_items_called(const void *p, int32_t *s)
const void *build_items_called(const void *p, int32_t *s, int h)
{
return build_items_wearing(&postavy[memman_handle-H_POSTAVY], s);
return build_items_wearing(&postavy[h-H_POSTAVY], s);
}
void display_items_wearing(THUMAN *h)

View file

@ -187,7 +187,7 @@ static void animace_kouzla(MGIF_HEADER_T *_,int act,const void *data, int ssize)
}
const void *load_spells_legacy_format(const void *p, int32_t *s) {
const void *load_spells_legacy_format(const void *p, int32_t *s, int h) {
TSTRINGTABLE *strtable = lang_load("spells.csv");
void *np = getmem(*s);
memcpy(np,p,*s);
@ -1934,9 +1934,9 @@ void cast(int num,THUMAN *p,int owner, char backfire)
p->exp+=k->mge;
check_player_new_level(p);
if (p->mana>p->mana_battery) {
p->mana=p->mana_battery;
p->mana=p->mana_battery;
}
p->mana_battery=32767;
p->mana_battery=32767;
end:
GlobEvent(MAGLOB_AFTERMAGIC,p->sektor,p->direction);
}

View file

@ -67,7 +67,7 @@ static char promacknuti(int id,int xa,int ya,int xr,int yr)
word *w;
z=ablock(H_MENU_MASK);w=(word *)z;
z+=6+512;
z+=6+512;
z+=xr+yr*w[0];
vymacknout(id,xa,ya,xr,yr);
if (*z!=0) cur_dir[*z-1]=SELECT;
@ -123,7 +123,7 @@ jp1:lodsb
}
}*/
static const void *nahraj_rozdilovy_pcx(const void *pp, int32_t *s)
static const void *nahraj_rozdilovy_pcx(const void *pp, int32_t *s, int h)
{
char *org,*pos;
char *vysl;

View file

@ -358,7 +358,7 @@ int load_map(const char *filename)
vyk_max=size/sizeof(TVYKLENEK);
break;
case A_MOBS:
mob_template=load_mob_legacy_format_direct(temp, &size);
mob_template=load_mob_legacy_format_direct(temp, &size,0);
mob_size=size;
break;
case A_MOBSND:

View file

@ -91,15 +91,15 @@ void (*wire_proc)(void);
char cur_mode,battle_mode;
static char titles_on=0;
const void *pcx_fade_decomp(const void *p, int32_t *s);
const void *pcx_15bit_decomp(const void *p, int32_t *s);
const void *pcx_15bit_decomp_transp0(const void *p, int32_t *s);
const void *pcx_15bit_autofade(const void *p, int32_t *s);
const void *pcx_15bit_backgrnd(const void *p, int32_t *s);
const void *pcx_8bit_decomp(const void *p, int32_t *s);
const void *pcx_fade_decomp(const void *p, int32_t *s, int h);
const void *pcx_15bit_decomp(const void *p, int32_t *s, int h);
const void *pcx_15bit_decomp_transp0(const void *p, int32_t *s, int h);
const void *pcx_15bit_autofade(const void *p, int32_t *s, int h);
const void *pcx_15bit_backgrnd(const void *p, int32_t *s, int h);
const void *pcx_8bit_decomp(const void *p, int32_t *s, int h);
const char *texty_knihy;
static char *patch_file=NULL;
static const char *patch_file=NULL;
int cur_page=0;
TSTR_LIST cur_config=NULL;
@ -281,7 +281,7 @@ void purge_temps(char _) {
temp_storage_clear();
}
const void *pcx_fade_decomp(const void *p, int32_t *s)
const void *pcx_fade_decomp(const void *p, int32_t *s, int h)
{
char *buff;
int r = load_pcx(p,*s,A_FADE_PAL,&buff,mglob.fade_r,mglob.fade_g,mglob.fade_b);
@ -290,7 +290,7 @@ const void *pcx_fade_decomp(const void *p, int32_t *s)
return buff;
}
const void *pcx_15bit_decomp(const void *p, int32_t *s)
const void *pcx_15bit_decomp(const void *p, int32_t *s, int h)
{
char *buff;
int r = load_pcx(p,*s,A_16BIT,&buff);
@ -298,7 +298,7 @@ const void *pcx_15bit_decomp(const void *p, int32_t *s)
*s=r;
return buff;
}
const void *pcx_15bit_decomp_transp0(const void *p, int32_t *s)
const void *pcx_15bit_decomp_transp0(const void *p, int32_t *s, int h)
{
char *buff;
int r = load_pcx(p,*s,A_16BIT_ZERO_TRANSP,&buff);
@ -307,7 +307,7 @@ const void *pcx_15bit_decomp_transp0(const void *p, int32_t *s)
return buff;
}
const void *pcx_15bit_autofade(const void *p, int32_t *s)
const void *pcx_15bit_autofade(const void *p, int32_t *s, int h)
{
char *buff;
int r = load_pcx(p,*s,A_16BIT,&buff);
@ -317,7 +317,7 @@ const void *pcx_15bit_autofade(const void *p, int32_t *s)
return buff;
}
const void *pcx_15bit_backgrnd(const void *p, int32_t *s)
const void *pcx_15bit_backgrnd(const void *p, int32_t *s, int h)
{
char *buff;
int32_t i;int32_t *z;
@ -334,7 +334,7 @@ const void *pcx_15bit_backgrnd(const void *p, int32_t *s)
return NULL;
}
const void *pcx_8bit_nopal(const void *p,int32_t *s)
const void *pcx_8bit_nopal(const void *p,int32_t *s, int h)
{
char *buff = NULL;
@ -349,7 +349,7 @@ const void *pcx_8bit_nopal(const void *p,int32_t *s)
const void *pcx_8bit_decomp(const void *p, int32_t *s)
const void *pcx_8bit_decomp(const void *p, int32_t *s, int h)
{
char *buff;
int r = load_pcx(p,*s,A_8BIT,&buff);
@ -358,7 +358,7 @@ const void *pcx_8bit_decomp(const void *p, int32_t *s)
return buff;
}
const void *hi_8bit_correct(const void *p,int32_t *s)
const void *hi_8bit_correct(const void *p,int32_t *s, int h)
{
word *out = (word *)getmem(*s);
memcpy(out, p, *s);
@ -375,7 +375,7 @@ const void *hi_8bit_correct(const void *p,int32_t *s)
}
const void *load_mob_legacy_format_direct(const void *p, int32_t *s) {
const void *load_mob_legacy_format_direct(const void *p, int32_t *s, int h) {
const char *c = p;
const int sz = 376;
int count = *s / sz;;
@ -404,15 +404,15 @@ const void *load_mob_legacy_format_direct(const void *p, int32_t *s) {
*s = count * sizeof(TMOB);
return out;
}
const void *load_mob_legacy_format(const void *p, int32_t *s) {
const void *load_mob_legacy_format(const void *p, int32_t *s, int h) {
const char *c = p;
c+=8;
*s-=8;
return load_mob_legacy_format_direct(c, s);
return load_mob_legacy_format_direct(c, s,h);
}
const void *set_background(const void *p, int32_t *s)
const void *set_background(const void *p, int32_t *s, int h)
{
const word *data;
word *ptr;
@ -857,31 +857,12 @@ void error_exception(EVENT_MSG *msg,void **unused)
SEND_LOG("(ERROR) Log: Battle: %d Select_player %d",battle,select_player);
closemode();
printf("Program zp<7A>sobil b<>hovou chybu a bude ukon<6F>en\n"
"Posledn<EFBFBD> zpracov<6F>van<61> data m<>la rukoje<6A> <20><>slo %xh\n",memman_handle);
printf("Map: %s Sector %d Direction %d\n",level_fname==NULL?"<unknown>":level_fname,viewsector,viewdir);
printf("Nyn<EFBFBD> se program pokus<75> ulo<6C>it hru...\n\n");
autosave_enabled=1;
autosave();
printf("Hra byla <20>sp<73><70>n<EFBFBD> ulo<6C>ena pod n<>zvem AUTOSAVE\n");
exit(0);
display_error("error_exception called");
}
}
void swap_error_exception(void)
{
closemode();
puts("Program jiz nema kam odkladat, protoze disk s odkladacim souborem byl \n"
"zaplnen. Uvolnete prosim nejake misto na odkladacim disku, nebo zmente \n"
"adresar odkladani na jednotku, kde je vice mista");
puts("Vase pozice bude ulozena pod nazvem AUTOSAVE\n"
"Pokud vsak mate pozice na stejn<6A>m disku jako odkladaci soubor (coz je\n"
"zakladni nastaveni) bude ulozeni z 90% bohuzel neuspesne...");
autosave_enabled=1;
autosave();
exit(0);
}
const void *boldcz;
@ -919,29 +900,22 @@ char device_error(int chyba,char disk,char info)
return (c==13?_ERR_RETRY:_ERR_FAIL);
}
*/
static void patch_error(int err)
{
position(0,460);
curcolor=0;bar32(0,460,640,479);
memcpy(charcolors,flat_color(RGB555(31,31,31)),sizeof(charcolors));
curfont=boldcz;
switch(err)
{
case 0:outtext("File has been patched: ");outtext(patch_file);break;
case 1:outtext("Patch error within file: ");outtext(patch_file);break;
case 2:outtext("Cannot patch");break;
case 3:outtext("Missing or error in main data file, patching ingnored!");break;
break;
}
showview(0,460,640,20);
}
void init_DDL_manager() {
const char *ddlfile = build_pathname(2, gpathtable[SR_DATA],"SKELDAL.DDL");
ddlfile = local_strdup(ddlfile);
init_manager(ddlfile, NULL);
init_manager();
if (patch_file && !add_patch_file(patch_file)) {
display_error("Can't open resource file (adv_patch): %s", ddlfile);
abort();
}
if (!add_patch_file(ddlfile)) {
display_error("Can't open resource file (main): %s", ddlfile);
abort();
}
SEND_LOG("(GAME) Memory manager initialized. Using DDL: '%s'",ddlfile);
register_basic_data();
@ -1032,7 +1006,6 @@ void init_skeldal(const INI_CONFIG *cfg)
show_joystick_info();
}
if (patch_file!=NULL) patch_error(add_patch_file(patch_file));
send_message(E_DONE,E_WATCH,timer);
@ -1672,7 +1645,7 @@ const char *configure_pathtable(const INI_CONFIG *cfg) {
if (defmap) {
strcopy_n(default_map, defmap, sizeof(default_map));
}
patch_file = ini_get_string(paths, "patch_file", NULL);
return groot;
}

View file

@ -265,7 +265,7 @@ int set_channel_volume_from_sector(int channel,
return 0;
}
*/
const void *wav_load(const void *p, int32_t *s)
const void *wav_load(const void *p, int32_t *s, int h)
{
const char *sr;
char *tg;