diff --git a/game/advconfig.c b/game/advconfig.c index 0f59f33..204d886 100644 --- a/game/advconfig.c +++ b/game/advconfig.c @@ -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)); } } diff --git a/game/builder.c b/game/builder.c index 3ff6461..6d34914 100644 --- a/game/builder.c +++ b/game/builder.c @@ -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) { diff --git a/game/dialogy.c b/game/dialogy.c index 089b202..904e0fb 100644 --- a/game/dialogy.c +++ b/game/dialogy.c @@ -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) diff --git a/game/gamesave.c b/game/gamesave.c index a47d17d..e4d4974 100644 --- a/game/gamesave.c +++ b/game/gamesave.c @@ -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) diff --git a/game/globals.h b/game/globals.h index 7303b31..8f12dd7 100644 --- a/game/globals.h +++ b/game/globals.h @@ -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); diff --git a/game/interfac.c b/game/interfac.c index 6d6cfaa..042893e 100644 --- a/game/interfac.c +++ b/game/interfac.c @@ -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; diff --git a/game/inv.c b/game/inv.c index 335feff..c8dd084 100644 --- a/game/inv.c +++ b/game/inv.c @@ -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) diff --git a/game/kouzla.c b/game/kouzla.c index a8aeac4..a2f34b4 100644 --- a/game/kouzla.c +++ b/game/kouzla.c @@ -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); } diff --git a/game/menu.c b/game/menu.c index dca97c6..8c056cc 100644 --- a/game/menu.c +++ b/game/menu.c @@ -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; diff --git a/game/realgame.c b/game/realgame.c index a17fda3..89b9245 100644 --- a/game/realgame.c +++ b/game/realgame.c @@ -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: diff --git a/game/skeldal.c b/game/skeldal.c index 8f4dc0a..a6cdd8e 100644 --- a/game/skeldal.c +++ b/game/skeldal.c @@ -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�sobil b�hovou chybu a bude ukon�en\n" - "Posledn� zpracov�van� data m�la rukoje� ��slo %xh\n",memman_handle); - printf("Map: %s Sector %d Direction %d\n",level_fname==NULL?"":level_fname,viewsector,viewdir); - printf("Nyn� se program pokus� ulo�it hru...\n\n"); - autosave_enabled=1; - autosave(); - printf("Hra byla �sp��n� ulo�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�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; } diff --git a/game/sndandmus.c b/game/sndandmus.c index 6c11d63..3ea55b8 100644 --- a/game/sndandmus.c +++ b/game/sndandmus.c @@ -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; diff --git a/libs/memman.c b/libs/memman.c index e064379..b346a9e 100644 --- a/libs/memman.c +++ b/libs/memman.c @@ -23,10 +23,8 @@ void bonz_table(); static const char ** mman_pathlist=NULL; -static FILE *swap = NULL; char mman_patch=0; -int memman_handle; static int max_handle=0; //static FILE *log; @@ -40,10 +38,7 @@ void def_mman_group_table(const char ** p) { void standard_mem_error(size_t size) { - char buff[256]; - SEND_LOG("(ERROR) Memory allocation error detected, %lu bytes missing",size); - sprintf(buff,"Memory allocation error\n Application can't allocate %lu bytes of memory (%xh)\n",(unsigned long)size,memman_handle); - display_error(buff); + display_error("memory allocation error %lu", (unsigned long)size); exit(1); } @@ -126,20 +121,21 @@ typedef struct tnametable_ref { uint32_t count; } TNAMETABLE_REF; -static int32_t *grptable,grptabsiz; -static TNAMETABLE_REF bmf_nametable; -static TNAMETABLE_REF patch_nametable; +typedef struct ddlmap_info { + const void *ptr; + size_t size; + TNAMETABLE_REF nametable; +} TDDLMAP_INFO; + +#define MAX_PATCHES 4 + +static TDDLMAP_INFO ddlmap[MAX_PATCHES]; + + static int next_name_read=0; static int last_group; -char *main_file_name=NULL; handle_groups _handles; -//static FILE *bmf=NULL; -//static FILE *patch=NULL; -static void *bmf_m = NULL; -static size_t bmf_s = 0; -static void *patch_m = NULL; -static size_t patch_s = 0; uint32_t bk_global_counter=0; char *swap_path; @@ -154,6 +150,7 @@ static int test_file_exist_DOS(int group,char *filename) +#if 0 void load_grp_table() { int32_t i = 0;; @@ -170,7 +167,7 @@ void load_grp_table() for(i=0;i<(grptabsiz>>3);i++) grptable[i*2+1]=(grptable[i*2+1]-grptabsiz)>>4; SEND_LOG("(LOAD) Group Table Loaded"); } - +#endif static TNAMETABLE_REF load_file_table(const void *bmf_m) { @@ -195,22 +192,25 @@ int get_file_entry_in_table(const TNAMETABLE_REF *where, char *name) { -int get_file_entry(int group,char *name) - { +char get_file_entry(int group,char *name, THANDLE_DATA *h) { char ex; ex=test_file_exist_DOS(group,name); - if (ex || bmf_m==0) return 0; - if (patch_m) { - int sk = get_file_entry_in_table(&patch_nametable, name); - if (sk >= 0) return -sk; - } - if (bmf_m) { - int sk = get_file_entry_in_table(&bmf_nametable, name); - if (sk >= 0) return sk; + if (!ex) { + for (int i = 0; i < MAX_PATCHES; ++i) { + const TDDLMAP_INFO *nfo = &ddlmap[i]; + if (nfo->ptr) { + int sk = get_file_entry_in_table(&nfo->nametable, name); + if (sk >= 0) { + h->src_index = i; + h->offset = sk; + return 1; + } + } + } } return 0; - } +} THANDLE_DATA *get_handle(int handle) @@ -230,11 +230,14 @@ THANDLE_DATA *get_handle(int handle) static char need_to_be_free(const void *ptr) { - const char *beg = (const char *)bmf_m; - const char *p = (const char *)ptr; - if (p >= beg && p < beg+bmf_s) return 0; - beg = (const char *)patch_m; - if (p >= beg && p < beg+bmf_s) return 0; + for (int i = 0; i < MAX_PATCHES; ++i) { + const TDDLMAP_INFO *nfo = &ddlmap[i]; + if (nfo->ptr) { + const char *beg = (const char *)nfo->ptr; + const char *p = (const char *)ptr; + if (p >= beg && p < beg+nfo->size) return 0; + } + } return 1; } @@ -254,7 +257,6 @@ THANDLE_DATA *kill_block(int handle) if (h->status==BK_PRESENT) { ablock_free(h->blockdata); } - if (h->flags & BK_HSWAP) swap_free_block(h->seekpos,h->size); h->status=BK_NOT_LOADED; h->flags&=~BK_HSWAP; return h; @@ -266,53 +268,41 @@ THANDLE_DATA *zneplatnit_block(int handle) h=kill_block(handle); if (h->status==BK_SAME_AS) - return zneplatnit_block(h->seekpos); - if (h->src_file[0]) h->seekpos=get_file_entry(h->path,h->src_file); + return zneplatnit_block(h->offset); return h; } -static void heap_error(size_t s) { - display_error("out of memory"); + +static void add_patch(const void *bmf, size_t sz) { + for (int i = 0; i < MAX_PATCHES; ++i) { + if (ddlmap[i].ptr == NULL) { + ddlmap[i].ptr = bmf; + ddlmap[i].size = sz; + ddlmap[i].nametable = load_file_table(bmf); + return; + } + } + display_error("memman: Too many patches"); abort(); } -void init_manager(const char *filename,const char *swap_is_not_supported) // filename= Jmeno datoveho souboru nebo NULL pak - // se pouzije DOS - // swp je cesta do TEMP adresare - { +char add_patch_file(const char *filename) { + size_t bmf_s; + const void *bmf = map_file_to_memory(file_icase_find(filename), &bmf_s); + if (bmf) { + add_patch(bmf, bmf_s); + return 1; + } + return 0; +} + +void init_manager(void) { next_name_read=0; last_group=0; memset(_handles,0,sizeof(_handles)); - if (filename!=NULL) - { - bmf_m = map_file_to_memory(file_icase_find(filename), &bmf_s); - if (bmf_m) - { - main_file_name=(char *)getmem(strlen(filename)+1); - strcpy(main_file_name,filename); - bmf_nametable = load_file_table(bmf_m); - } - else - main_file_name=NULL; - } - else - main_file_name=NULL; - mem_error=heap_error; - swap=NULL; - } + memset(ddlmap,0,sizeof(ddlmap)); +} -void *load_swaped_block(THANDLE_DATA *h) - { - void *i; - - if (mman_action!=NULL) mman_action(MMA_SWAP_READ); - i=getmem(h->size); - SEND_LOG("(LOAD)(SWAP) Loading block from swap named '%-.12s'",h->src_file); - fseek(swap,h->seekpos,SEEK_SET); - fread(i,1,h->size,swap); - h->status=BK_PRESENT; - return i; - } int find_same(const char *name,ABLOCK_DECODEPROC decomp) @@ -339,8 +329,9 @@ int find_handle(const char *name,ABLOCK_DECODEPROC decomp) int test_file_exist(int group,char *filename) { - if (get_file_entry(group,filename)==0) return test_file_exist_DOS(group,filename); - return 1; + THANDLE_DATA h; + if (get_file_entry(group, filename, &h) == 0) return test_file_exist_DOS(group,filename); + return 1; } THANDLE_DATA *def_handle(int handle,const char *filename,ABLOCK_DECODEPROC decompress,char path) @@ -359,15 +350,16 @@ THANDLE_DATA *def_handle(int handle,const char *filename,ABLOCK_DECODEPROC decom if (i!=-1 && i!=handle) { h->status=BK_SAME_AS; - h->seekpos=i; + h->offset=i; return h; } strcopy_n(h->src_file,filename,sizeof(h->src_file)); - h->seekpos=0; + h->offset=0; strupper(h->src_file); h->loadproc=decompress; - if (filename[0]) - h->seekpos=get_file_entry(path,h->src_file); + if (filename[0]) { + get_file_entry(path,h->src_file,h); + } SEND_LOG("(REGISTER) File/Block registred '%-.12s' handle %04X",h->src_file,handle); SEND_LOG("(REGISTER) Seekpos=%d",h->seekpos); h->flags=0; @@ -380,20 +372,19 @@ THANDLE_DATA *def_handle(int handle,const char *filename,ABLOCK_DECODEPROC decom const void *afile(char *filename,int group,int32_t *blocksize) { char *d; - int32_t entr; + char entr; void *p; d=alloca(strlen(filename)+1); strcpy(d,filename); strupper(d); - if (mman_patch && test_file_exist_DOS(group,d)) entr=0; - else entr=get_file_entry(group,d); + THANDLE_DATA hd; + entr = get_file_entry(group, d, &hd); if (entr!=0) { - const void *hnd; SEND_LOG("(LOAD) Afile is loading file '%s' from group %d",d,group); - if (entr<0) entr=-entr,hnd=patch_m;else hnd=bmf_m; - const int32_t * szptr = (const int32_t *)((const char *)hnd+entr); + const TDDLMAP_INFO *nfo = &ddlmap[hd.src_index]; + const int32_t * szptr = (const int32_t *)((const char *)nfo->ptr+hd.offset); *blocksize = *szptr; return szptr+1; } @@ -419,10 +410,10 @@ void *afile_copy(char *filename,int group,int32_t *blocksize) { } -static void decompress_data(THANDLE_DATA *h) { +static void decompress_data(THANDLE_DATA *h, int handle) { if (h->loadproc) { int32_t sz = h->size; - const void *r = h->loadproc(h->blockdata, &sz); + const void *r = h->loadproc(h->blockdata, &sz, handle); if (r != h->blockdata) { ablock_free(h->blockdata); h->blockdata = r; @@ -437,11 +428,9 @@ const void *ablock(int handle) sem: h=get_handle(handle); - if (memman_handle!=handle || h->status!=BK_PRESENT) h->counter=bk_global_counter++; - memman_handle=handle; if (h->status==BK_SAME_AS) { - handle=h->seekpos; + handle=h->offset; goto sem; } if (h->status==BK_PRESENT) { @@ -455,7 +444,7 @@ const void *ablock(int handle) void *p;int32_t s; SEND_LOG("(LOAD) Loading file as block '%-.12s' %04X",h->src_file,handle); - if (h->seekpos==0) + if (h->offset==0) { if (h->src_file[0]!=0) { @@ -473,30 +462,23 @@ const void *ablock(int handle) h->blockdata=p; h->status=BK_PRESENT; h->size=s; - decompress_data(h); + decompress_data(h, handle); return h->blockdata; } else { - int entr=h->seekpos; - const void *hnd; + const TDDLMAP_INFO *nfo = &ddlmap[h->src_index]; if (mman_action!=NULL) mman_action(MMA_READ); - if (entr<0) entr=-entr,hnd=patch_m;else hnd=bmf_m; - const int32_t *szptr =(const int32_t *)((const char *)hnd+entr); + const int32_t *szptr =(const int32_t *)((const char *)nfo->ptr+h->offset); s = *szptr; void *p = (void *)(szptr+1); h->blockdata=p; h->status=BK_PRESENT; h->size=s; - decompress_data(h); + decompress_data(h, handle); return h->blockdata; } } - //tato cast programu bude jeste dodelana - else .... - if (h->status==BK_SWAPED) - { - return h->blockdata=load_swaped_block(h); - } return NULL; } @@ -518,7 +500,7 @@ void alock(int handle) if (!h->lockcount) { h->flags|=BK_LOCKED; - if (h->status==BK_SAME_AS) alock(h->seekpos); + if (h->status==BK_SAME_AS) alock(h->offset); } h->lockcount++; //SEND_LOG("(LOCK) Handle locked %04X (count %d)",handle,h->lockcount); @@ -532,62 +514,10 @@ void aunlock(int handle) if (!h->lockcount) { h->flags&=~BK_LOCKED; - if (h->status==BK_SAME_AS) aunlock(h->seekpos); + if (h->status==BK_SAME_AS) aunlock(h->offset); } //SEND_LOG("(LOCK) Handle unlocked %04X (count %d)",handle,h->lockcount); } -void aswap(int handle) - { - THANDLE_DATA *h; - - h=get_handle(handle); - h->flags|=BK_SWAPABLE; - if (h->status==BK_SAME_AS) aswap(h->seekpos); - } - -void aunswap(int handle) - { - THANDLE_DATA *h; - - h=get_handle(handle); - h->flags|=BK_SWAPABLE; - if (h->status==BK_SAME_AS) aunswap(h->seekpos); - } - -void apreload(int handle) - { - THANDLE_DATA *h; - - - h=get_handle(handle); - if (h->src_file[0] && h->status!=BK_SAME_AS) - { - if (!(h->flags & BK_PRELOAD) || !(h->flags & BK_HSWAP)) h->flags|=BK_SWAPABLE | BK_PRELOAD; - ablock(handle); - } - } - -static int32_t *apr_sign=NULL; -static int32_t max_sign; - -void apreload_sign(int handle,int max_handle) - { - THANDLE_DATA *h; - if (apr_sign==NULL) - { - apr_sign=NewArr(int32_t,max_handle); - memset(apr_sign,0x7f,sizeof(int32_t)*max_handle); - max_sign=max_handle; - } - if (handle>=max_sign) - { - apreload(handle); - return; - } - h=get_handle(handle); - if (h->src_file[0] && h->status!=BK_SAME_AS && h->status!=BK_NOT_USED) - if (!(h->flags & BK_PRELOAD) || !(h->flags & BK_HSWAP)) apr_sign[handle]=h->seekpos; - } void undef_handle(int handle) @@ -601,9 +531,10 @@ void undef_handle(int handle) SEND_LOG("(REGISTER) File/Block unregistred %04X (%-.12s)",handle,h->src_file); } h->src_file[0]=0; - h->seekpos=0; + h->offset=0; h->flags=0; h->status=BK_NOT_USED; + h->loadproc = 0; } void close_manager() @@ -615,10 +546,9 @@ void close_manager() for(j=0;j