mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-05 14:10:27 -04:00
support for hotpatching to restore ADV patch support
This commit is contained in:
parent
2be7f5d2b2
commit
04b57b4088
14 changed files with 168 additions and 278 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
263
libs/memman.c
263
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<BK_MINOR_HANDLES;j ++) undef_handle(i*BK_MINOR_HANDLES+j);
|
||||
free(_handles[i]);
|
||||
}
|
||||
free(main_file_name);
|
||||
if (bmf_m) unmap_file(bmf_m, bmf_s);
|
||||
if (patch_m) unmap_file(patch_m, patch_s);
|
||||
if (swap) fclose(swap);
|
||||
for (int i = 0; i < MAX_PATCHES; ++i) {
|
||||
unmap_file((void *)ddlmap[i].ptr, ddlmap[i].size);
|
||||
}
|
||||
|
||||
max_handle=0;
|
||||
}
|
||||
|
@ -715,22 +645,7 @@ void *grealloc(void *p,int32_t size)
|
|||
}
|
||||
|
||||
|
||||
int read_group(int index)
|
||||
{
|
||||
return grptable[index<<1];
|
||||
}
|
||||
|
||||
char add_patch_file(char *filename)
|
||||
{
|
||||
SEND_LOG("Adding patch: %s",filename);
|
||||
if (!patch_m) return 2;
|
||||
if (!bmf_m) return 3;
|
||||
patch_m = map_file_to_memory(file_icase_find(filename), &bmf_s);
|
||||
if (!patch_m) return 1;
|
||||
patch_nametable = load_file_table(patch_m);
|
||||
SEND_LOG("Patch added: %s - %u entries modified",filename,patch_nametable.count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOGFILE
|
||||
/*
|
||||
|
|
|
@ -18,7 +18,7 @@ extern "C" {
|
|||
* @param size source size - you need to write own size if data has been converted
|
||||
* @param pointer either to src or newly allocated block with replacement (must be allocated by malloc)
|
||||
*/
|
||||
typedef const void *(*ABLOCK_DECODEPROC)(const void *src, int32_t *size);
|
||||
typedef const void *(*ABLOCK_DECODEPROC)(const void *src, int32_t *size, int handle);
|
||||
|
||||
|
||||
#define freemem(size) free(size);
|
||||
|
@ -42,14 +42,15 @@ typedef struct meminfo {
|
|||
|
||||
typedef struct thandle_data
|
||||
{
|
||||
char src_file[16]; //12
|
||||
int32_t seekpos; //16
|
||||
const void *blockdata; //20
|
||||
char flags; //21
|
||||
uint8_t path; //22
|
||||
char src_file[16];
|
||||
uint32_t offset;
|
||||
const void *blockdata;
|
||||
unsigned char src_index;
|
||||
char flags;
|
||||
uint8_t path;
|
||||
short status;
|
||||
ABLOCK_DECODEPROC loadproc;
|
||||
unsigned short lockcount; //32
|
||||
unsigned short lockcount;
|
||||
uint32_t counter;
|
||||
uint32_t size;
|
||||
}THANDLE_DATA;
|
||||
|
@ -77,20 +78,17 @@ typedef handle_list *handle_groups[BK_MAJOR_HANDLES];
|
|||
#define BK_READONLY 32
|
||||
|
||||
//extern char *const * mman_pathlist; //tento pointer musi byt naplnen ukazatelem na tabulku cest
|
||||
extern int memman_handle; //cislo handle naposled zpracovavaneho prikazem ablock
|
||||
extern char mman_patch; //jednicka zapina moznost pouziti patchu
|
||||
void *getmem(int32_t size); //alokace pameti pres memman. alokovat pomoci malloc lze ale hrozi nebezpeci ze vrati NULL
|
||||
void *grealloc(void *m,int32_t size); //realokace pameti pres memman
|
||||
void *load_file(const char *filename, size_t *size); //obycejne natahne soubor do pameti a vrati ukazatel.
|
||||
void init_manager(const char *filename,const char *swp); //inicializuje manager. Jmeno filename i swapname nejsou povinne (musi byt NULL kdyz nejsou pouzity)
|
||||
void init_manager(void); //inicializuje manager. Jmeno filename i swapname nejsou povinne (musi byt NULL kdyz nejsou pouzity)
|
||||
void def_mman_group_table(const char ** ); //define pointer to table of paths, for each group there is path
|
||||
THANDLE_DATA *def_handle(int handle,const char *filename,ABLOCK_DECODEPROC decompress,char path); //deklaruje rukojet. promenna decompress je ukazatel na funkci ktera upravi data pred vracenim ukazatele
|
||||
const void *ablock(int handle); //vraci ukazatel bloku spojeneho s handlem
|
||||
void *ablock_copy(int handle); //vraci ukazatel bloku spojeneho s handlem
|
||||
void alock(int handle); //zamyka blok
|
||||
void aunlock(int handle); //odmyka blok
|
||||
void aswap(int handle); //zapina swapovani pro blok
|
||||
void aunswap(int handle); //vypina swapovani pro blok
|
||||
//void free(void); //free
|
||||
void close_manager(void); //uzavre manager a uvolni veskerou pamet
|
||||
void undef_handle(int handle); //uvolni hadle k dalsimu pouziti
|
||||
|
@ -106,7 +104,7 @@ void ablock_free(const void *ptr);
|
|||
|
||||
|
||||
int read_group(int index);
|
||||
char add_patch_file(char *filename); //pripojuje zaplatu
|
||||
char add_patch_file(const char *filename); //pripojuje zaplatu
|
||||
|
||||
|
||||
#define MMA_READ 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue