mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-20 05:04:53 -04:00
allow all MAP files to be read from DDL archive
This commit is contained in:
parent
96eaeb4851
commit
73a4187f79
18 changed files with 185 additions and 165 deletions
|
@ -160,7 +160,7 @@ static void mob_reload(EVENT_MSG *msg,void **_){
|
|||
TMOB *m;
|
||||
int32_t vl;
|
||||
|
||||
static int last;
|
||||
static int last = 0;
|
||||
counter=0;
|
||||
while (last<MAX_MOBS)
|
||||
{
|
||||
|
|
|
@ -113,19 +113,19 @@ static void unable_write_temp(char *c)
|
|||
|
||||
int load_org_map(const char *filename,TSTENA **sides,TSECTOR **sectors,TMAP_EDIT_INFO **coords,int *mapsize)
|
||||
{
|
||||
FILE *f;
|
||||
TMPFILE_RD *f;
|
||||
void *temp;
|
||||
int sect;
|
||||
int32_t size,r;
|
||||
char nmapend=1;
|
||||
|
||||
|
||||
const char *c=build_pathname(2, gpathtable[SR_MAP],filename);
|
||||
f=fopen_icase(c,"rb");
|
||||
|
||||
f = open_ddl_file(filename, SR_MAP);
|
||||
if (f==NULL) return -1;
|
||||
do
|
||||
{
|
||||
r=load_section(f,&temp,§,&size);
|
||||
r=load_section_mem(f,&temp,§,&size);
|
||||
if (r==size)
|
||||
switch (sect)
|
||||
{
|
||||
|
@ -152,12 +152,12 @@ int load_org_map(const char *filename,TSTENA **sides,TSECTOR **sectors,TMAP_EDIT
|
|||
else
|
||||
{
|
||||
if (temp!=NULL)free(temp);
|
||||
fclose(f);
|
||||
temp_storage_close_rd(f);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (nmapend);
|
||||
fclose(f);
|
||||
temp_storage_close_rd(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ static int convert_map_strings_1(const char *source_name, LIST_FILE_TYPE type, s
|
|||
const char *target_name = set_file_extension(concat2("map_", source_name),".csv");
|
||||
const char *target_path = *(const char **)context;
|
||||
TSTR_LIST lst = create_list(100);
|
||||
int err = load_string_list_ex(&lst, build_pathname(2, gpathtable[SR_MAP], source_name));
|
||||
int err = load_string_list_ex(&lst, source_name, SR_MAP);
|
||||
if (err) {
|
||||
release_list(lst);
|
||||
fprintf(stderr,"Failed to read: %s, error code: %d\n",source_name, err);
|
||||
|
@ -115,9 +115,9 @@ static char make_map_name_stringtable(const char *target_path) {
|
|||
}
|
||||
|
||||
|
||||
static char convert_file_to(const char *src_file, const char *target_file) {
|
||||
TMPFILE_RD *rd = enc_open(src_file);
|
||||
size_t sz = temp_storage_find("__enc_temp");
|
||||
static char convert_file_to(const char *src_file, int group, const char *target_file) {
|
||||
TMPFILE_RD *rd = enc_open(src_file,group);
|
||||
size_t sz = temp_storage_remain_size(rd);
|
||||
char *buff = malloc(sz);
|
||||
temp_storage_retrieve("__enc_temp", buff, sz);
|
||||
FILE *out = fopen_icase(target_file, "w");
|
||||
|
@ -128,31 +128,31 @@ static char convert_file_to(const char *src_file, const char *target_file) {
|
|||
printf("Writing %s\n", target_file);
|
||||
fwrite(buff,1,sz,out);
|
||||
fclose(out);
|
||||
enc_close(rd);
|
||||
temp_storage_close_rd(rd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char convert_book(const char *target_path) {
|
||||
const char *path = build_pathname(2, target_path, "book.txt");
|
||||
path = local_strdup(path);
|
||||
return convert_file_to(build_pathname(2, gpathtable[SR_MAP], "kniha.txt"), path);
|
||||
return convert_file_to("kniha.txt", SR_MAP, path);
|
||||
}
|
||||
|
||||
static char convert_end_titles(const char *target_path) {
|
||||
const char *path = build_pathname(2, target_path, "end_titles.txt");
|
||||
path = local_strdup(path);
|
||||
|
||||
return convert_file_to(build_pathname(2, gpathtable[SR_DATA], "titulky.txt"), path);
|
||||
return convert_file_to("titulky.txt",SR_DATA, path);
|
||||
}
|
||||
|
||||
static char convert_epilog(const char *target_path) {
|
||||
const char *path = build_pathname(2, target_path, "epilog.txt");
|
||||
path = local_strdup(path);
|
||||
return convert_file_to(build_pathname(2, gpathtable[SR_DATA], "endtext.txt"), path);
|
||||
return convert_file_to("endtext.txt",SR_DATA, path);
|
||||
}
|
||||
static char convert_intro_titles(const char *target_path) {
|
||||
TSTR_LIST lst = create_list(100);
|
||||
int err = load_string_list_ex(&lst, build_pathname(2, gpathtable[SR_VIDEO], "intro.txt"));
|
||||
int err = load_string_list_ex(&lst, "intro.txt", SR_VIDEO);
|
||||
if (err) {
|
||||
release_list(lst);
|
||||
fprintf(stderr,"Failed to read: %s, error code: %d\n","intro.txt", err);
|
||||
|
|
|
@ -608,7 +608,6 @@ extern char set_halucination;
|
|||
extern int hal_sector; //cislo sektoru a smeru pri halucinaci
|
||||
extern int hal_dir;
|
||||
extern char side_touched; //promena se nastavuje na 1 pri kazdem uspesnem dotyku steny
|
||||
extern const char *texty_knihy; //jmeno souboru s textamy knihy
|
||||
extern int cur_page; //cislo stranky v knize;
|
||||
extern int32_t game_time; //hraci cas
|
||||
extern char autoattack;
|
||||
|
@ -755,7 +754,9 @@ void turn_zoom(int smer);
|
|||
void a_touch(int sector,int dir);
|
||||
int do_action(int action_numb,int sector,int direct,int flags,int nosend);
|
||||
void delay_action(int action_numb,int sector,int direct,int flags,int nosend,int delay);
|
||||
int32_t load_section(FILE *f,void **section, int *sct_type,int32_t *sect_size);
|
||||
//int32_t load_section(FILE *f,void **section, int *sct_type,int32_t *sect_size);
|
||||
int32_t load_section_mem(TMPFILE_RD *f,void **section, int *sct_type,int32_t *sect_size);
|
||||
TMPFILE_RD *open_ddl_file(const char *name, int group);
|
||||
int prepare_graphics(int *ofs,char *names,int32_t size,ABLOCK_DECODEPROC decomp,int class);
|
||||
void show_automap(char full);
|
||||
void draw_medium_map(void);
|
||||
|
@ -1721,9 +1722,9 @@ void check_global_fletna(THE_TIMER *t);
|
|||
void fletna_glob_add_note(uint8_t note);
|
||||
|
||||
|
||||
TMPFILE_RD *enc_open(const char *filename); //dekoduje a otevira TXT soubor (ENC)
|
||||
void enc_close(TMPFILE_RD *fil);
|
||||
int load_string_list_ex(char ***list,const char *filename);
|
||||
TMPFILE_RD *enc_open(const char *filename, int group); //dekoduje a otevira TXT soubor (ENC)
|
||||
int load_string_list_ex(char ***list,const char *filename, int group);
|
||||
|
||||
|
||||
typedef struct {
|
||||
int hprice;
|
||||
|
@ -1756,8 +1757,8 @@ extern char trace_dialogs;
|
|||
char enter_generator(void);
|
||||
|
||||
//kniha
|
||||
#define add_to_book(odst) add_text_to_book(texty_knihy,odst)
|
||||
void add_text_to_book(const char *filename,int odst);
|
||||
void add_to_book(int odst);
|
||||
void add_text_to_book(const char *filename,int group, int odst);
|
||||
void write_book(int page);
|
||||
int count_pages(void);
|
||||
void save_book(void);
|
||||
|
|
|
@ -1350,64 +1350,39 @@ void check_global_fletna(THE_TIMER *t)
|
|||
//---------------------------------------
|
||||
|
||||
|
||||
static char *load_file_to_string(FILE *f, int *size) {
|
||||
fseek(f,0, SEEK_END);
|
||||
int sz = ftell(f);
|
||||
fseek(f, 0 , SEEK_SET);
|
||||
char *c = getmem(sz+1);
|
||||
fread(c,1,sz,f);
|
||||
*size = sz;
|
||||
c[sz] = 0;
|
||||
return c;
|
||||
}
|
||||
|
||||
TMPFILE_RD *enc_open(const char *filename)
|
||||
TMPFILE_RD *enc_open(const char *filename, int group)
|
||||
{
|
||||
FILE *f;
|
||||
char *c,*enc;
|
||||
TMPFILE_RD *f;
|
||||
int last=0;
|
||||
int size;
|
||||
char *encdata;
|
||||
|
||||
f=fopen_icase(filename,"r");
|
||||
f=open_ddl_file(filename, group);
|
||||
if (f!=NULL) {
|
||||
encdata = load_file_to_string(f, &size);
|
||||
fclose(f);
|
||||
return f;
|
||||
} else {
|
||||
|
||||
enc=alloca(strlen(filename)+5);
|
||||
strcpy(enc,filename);
|
||||
c=strrchr(enc,'.');
|
||||
if (c==NULL) c=strchr(enc,0);
|
||||
strcpy(c,".ENC");
|
||||
f=fopen_icase(enc,"rb");
|
||||
if (f==NULL) return NULL;
|
||||
encdata = load_file_to_string(f, &size);
|
||||
fclose(f);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const char *enc_name = set_file_extension(filename, ".ENC");
|
||||
int32_t sz;
|
||||
void *data = afile_copy(enc_name,group,&sz);
|
||||
if (data == NULL) return NULL;
|
||||
char *encdata = (char *)data;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
last = (last + encdata[i]) & 0xFF;
|
||||
encdata[i] = last;
|
||||
}
|
||||
f = temp_storage_from_binary(encdata, sz, &free, data);
|
||||
return f;
|
||||
}
|
||||
temp_storage_store("__enc_temp", encdata, size);
|
||||
free(encdata);
|
||||
return temp_storage_open("__enc_temp");
|
||||
}
|
||||
|
||||
void enc_close(TMPFILE_RD *fil)
|
||||
{
|
||||
temp_storage_close_rd(fil);
|
||||
temp_storage_delete("__enc_temp");
|
||||
}
|
||||
|
||||
|
||||
int load_string_list_ex(TSTR_LIST *list,const char *filename)
|
||||
|
||||
int load_string_list_ex(TSTR_LIST *list,const char *filename, int group)
|
||||
{
|
||||
char c[1024],*p;
|
||||
int i=0,j,lin=0;
|
||||
TMPFILE_RD *f;
|
||||
|
||||
f=enc_open(filename);
|
||||
f=enc_open(filename, group);
|
||||
if (*list==NULL) *list=create_list(256);
|
||||
if (f==NULL) return -1;
|
||||
do
|
||||
|
@ -1424,12 +1399,12 @@ int load_string_list_ex(TSTR_LIST *list,const char *filename)
|
|||
j=temp_storage_scanf(f,"%d",&i);
|
||||
if (j==EOF)
|
||||
{
|
||||
enc_close(f);
|
||||
temp_storage_close_rd(f);
|
||||
return -2;
|
||||
}
|
||||
if (j!=1)
|
||||
{
|
||||
enc_close(f);
|
||||
temp_storage_close_rd(f);
|
||||
return lin;
|
||||
}
|
||||
if (i==-1) break;
|
||||
|
@ -1437,7 +1412,7 @@ int load_string_list_ex(TSTR_LIST *list,const char *filename)
|
|||
if (j!=EOF) temp_storage_ungetc(f);
|
||||
if (temp_storage_gets(c,1022,f)==NULL)
|
||||
{
|
||||
enc_close(f);
|
||||
temp_storage_close_rd(f);
|
||||
return lin;
|
||||
}
|
||||
|
||||
|
@ -1449,12 +1424,12 @@ int load_string_list_ex(TSTR_LIST *list,const char *filename)
|
|||
for(p=c;*p;p++) *p=*p=='|'?'\n':*p;
|
||||
if (str_replace(list,i,c)==NULL)
|
||||
{
|
||||
enc_close(f);
|
||||
temp_storage_close_rd(f);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
enc_close(f);
|
||||
temp_storage_close_rd(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
40
game/inv.c
40
game/inv.c
|
@ -149,8 +149,7 @@ void item_sound_event(int item,int sector)
|
|||
|
||||
void load_items()
|
||||
{
|
||||
const char *name;
|
||||
FILE *f;
|
||||
TMPFILE_RD *f;
|
||||
int sect,i,hs;
|
||||
int32_t size;
|
||||
void *p;
|
||||
|
@ -167,8 +166,7 @@ void load_items()
|
|||
break;
|
||||
}
|
||||
} while (1);
|
||||
name=build_pathname(2, gpathtable[SR_MAP],ITEM_FILE);
|
||||
f=fopen_icase(name,"rb");
|
||||
f=open_ddl_file(ITEM_FILE,SR_MAP);
|
||||
if (f==NULL)
|
||||
{
|
||||
closemode();
|
||||
|
@ -177,7 +175,7 @@ void load_items()
|
|||
}
|
||||
do
|
||||
{
|
||||
load_section(f,&p,§,&size);
|
||||
load_section_mem(f,&p,§,&size);
|
||||
switch (sect)
|
||||
{
|
||||
case 1:
|
||||
|
@ -218,7 +216,7 @@ void load_items()
|
|||
}
|
||||
}
|
||||
while (sect!=SV_END);
|
||||
fclose(f);
|
||||
temp_storage_close_rd(f);
|
||||
{
|
||||
TITEM *t;
|
||||
for(i=0,t=glob_items;i<it_count_orgn;i++,t++) if (t->druh==TYP_SPECIALNI)
|
||||
|
@ -606,11 +604,7 @@ void do_items_specs(void)
|
|||
cur_page&=~0x1;
|
||||
cur_page++;
|
||||
if (p->popis[0]==0) add_to_book(p->user_value);
|
||||
else
|
||||
{
|
||||
const char *s = build_pathname(2, gpathtable[SR_MAP], p->popis);
|
||||
add_text_to_book(s,p->user_value);
|
||||
}
|
||||
else add_text_to_book(p->popis,SR_MAP,p->user_value);
|
||||
play_fx_at(FX_BOOK);
|
||||
if (game_extras & EX_AUTOOPENBOOK) autoopenaction=1;
|
||||
break;
|
||||
|
@ -1867,7 +1861,7 @@ static char uloz_sip_action(char fast_key) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static char MakeItemCombinations(short *itm1, short *itm2)
|
||||
/*static char MakeItemCombinations(short *itm1, short *itm2)
|
||||
{
|
||||
short i1=*itm1-1,i2=*itm2-1;
|
||||
int src1;
|
||||
|
@ -1877,12 +1871,11 @@ static char MakeItemCombinations(short *itm1, short *itm2)
|
|||
int cnt;
|
||||
char succ=0;
|
||||
|
||||
FILE *table;
|
||||
TMPFILE_RD *table;
|
||||
|
||||
const char *fname = build_pathname(2,gpathtable[SR_MAP],"COMBITEM.DAT");
|
||||
table=fopen_icase(fname,"r");
|
||||
table=open_ddl_file("COMBITEM.DAT",SR_MAP);
|
||||
if (table==NULL) return 0;
|
||||
cnt=fscanf(table,"%d %d -> %d %d",&src1,&src2,&trg1,&trg2);
|
||||
cnt=temp_storage_scanf(table,"%d %d -> %d %d",&src1,&src2,&trg1,&trg2);
|
||||
while(cnt>=3)
|
||||
{
|
||||
if (src1==i1 && src2==i2)
|
||||
|
@ -1915,13 +1908,18 @@ static char MakeItemCombinations(short *itm1, short *itm2)
|
|||
succ=1;
|
||||
break;
|
||||
}
|
||||
if (fscanf(table," ;")==-1) break;
|
||||
cnt=fscanf(table,"%d %d -> %d %d",&src1,&src2,&trg1,&trg2);
|
||||
int x = temp_storage_getc(table);
|
||||
while (x >= 0 && isspace(x)) x = temp_storage_getc(table);
|
||||
if (x )
|
||||
|
||||
|
||||
if (temp_storage_scanf(table," ;")==-1) break;
|
||||
cnt=temp_storage_scanf(table,"%d %d -> %d %d",&src1,&src2,&trg1,&trg2);
|
||||
}
|
||||
fclose(table);
|
||||
temp_storage_close_rd(table);
|
||||
return succ;
|
||||
}
|
||||
|
||||
*/
|
||||
static char bag_action(int xr, int yr);
|
||||
char bag_click(int id,int xa,int ya,int xr,int yr)
|
||||
{
|
||||
|
@ -1940,7 +1938,7 @@ static char bag_action(int xr, int yr) {
|
|||
if (pk!=NULL)
|
||||
{
|
||||
if (picked_item[1]!=0 && vejdou_se(count_items_total(picked_item))) return 0;
|
||||
if (picked_item[1]!=0 || human_selected->inv[id]==0 || !MakeItemCombinations(picked_item,human_selected->inv+id))
|
||||
if (picked_item[1]!=0 || human_selected->inv[id]==0 /* || !MakeItemCombinations(picked_item,human_selected->inv+id)*/)
|
||||
while (*pk)
|
||||
{
|
||||
p=human_selected->inv[id];
|
||||
|
|
30
game/kniha.c
30
game/kniha.c
|
@ -50,6 +50,7 @@
|
|||
#include <libs/event.h>
|
||||
#include "globals.h"
|
||||
|
||||
#include "lang.h"
|
||||
#define XMAX 254
|
||||
#define YMAX 390
|
||||
#define XLEFT 34
|
||||
|
@ -535,18 +536,37 @@ static void seek_section(TMPFILE_RD *txt,int sect_number)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
void add_text_to_book(const char *filename,int odst)
|
||||
void add_to_book(int odst) {
|
||||
add_text_to_book("kniha.txt", SR_MAP, odst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void add_text_to_book(const char *filename,int group, int odst)
|
||||
{
|
||||
TMPFILE_RD *fl;
|
||||
TMPFILE_RD *fl = NULL;
|
||||
|
||||
set_font(H_FKNIHA,NOSHADOW(0));
|
||||
if (all_text==NULL) all_text=create_list(256);
|
||||
fl=enc_open(filename);
|
||||
if (fl==NULL) return;
|
||||
|
||||
if (istrcmp(filename, "kniha.txt") == 0) {
|
||||
|
||||
if (lang_get_folder()) {
|
||||
char *text = lang_load_string("book.txt");
|
||||
if (text) {
|
||||
fl = temp_storage_from_binary(text,strlen(text),free, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fl) {
|
||||
fl=enc_open(filename, group);
|
||||
if (fl==NULL) return;
|
||||
}
|
||||
seek_section(fl,odst);
|
||||
read_text(fl);
|
||||
next_line(1000);
|
||||
enc_close(fl);
|
||||
temp_storage_close_rd(fl);
|
||||
}
|
||||
|
||||
static char *displ_picture(char *c)
|
||||
|
|
|
@ -565,9 +565,7 @@ void zmen_vlastnost(int num,int cil,int what,int how)
|
|||
postavy[cil].stare_vls[what]+=how;
|
||||
prepocitat_postavu(&postavy[cil]);
|
||||
if (p->lives>p->vlastnosti[VLS_MAXHIT]) p->lives=p->vlastnosti[VLS_MAXHIT];
|
||||
//if (p->mana>p->vlastnosti[VLS_MAXMANA]) p->lives=p->vlastnosti[VLS_MAXMANA];
|
||||
if (p->kondice>p->vlastnosti[VLS_KONDIC]) p->lives=p->vlastnosti[VLS_KONDIC];
|
||||
|
||||
if (p->kondice>p->vlastnosti[VLS_KONDIC]) p->kondice=p->vlastnosti[VLS_KONDIC];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
game/lang.c
17
game/lang.c
|
@ -3,6 +3,7 @@
|
|||
#include "globals.h"
|
||||
#include "lang.h"
|
||||
#include <libs/strlite.h>
|
||||
#include <libs/memman.h>
|
||||
|
||||
|
||||
static char *lang_folder = NULL;
|
||||
|
@ -47,3 +48,19 @@ const char *lang_replace_path_if_exists(const char *file) {
|
|||
if (check_file_exists(path)) return path;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *lang_load_string(const char *filename) {
|
||||
if (lang_folder == NULL) return NULL;
|
||||
const char *path = build_pathname(2, lang_folder, filename);
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f == NULL) return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
long sz = ftell(f);
|
||||
char *trg = getmem(sz+1);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(trg, 1 , sz, f);
|
||||
fclose(f);
|
||||
trg[sz] = 0;
|
||||
return trg;
|
||||
}
|
||||
|
|
|
@ -9,4 +9,5 @@ const char *lang_get_folder(void);
|
|||
void lang_patch_stringtable(TSTR_LIST *lst, const char *object_name, const char *prefix);
|
||||
const char *lang_replace_path_if_exists(const char *file);
|
||||
TSTRINGTABLE *lang_load(const char *object_name);
|
||||
char *lang_load_string(const char *filename);
|
||||
|
||||
|
|
|
@ -572,8 +572,7 @@ static int ma_picki(const TMA_TWOP *i,int abs_pos)
|
|||
|
||||
static void ma_wbook(const TMA_LOADLEV *l)
|
||||
{
|
||||
const char *s = build_pathname(2, gpathtable[SR_MAP], l->name);
|
||||
add_text_to_book(s,l->start_pos);
|
||||
add_text_to_book(l->name, SR_MAP,l->start_pos);
|
||||
play_fx_at(FX_BOOK);
|
||||
}
|
||||
|
||||
|
|
40
game/menu.c
40
game/menu.c
|
@ -376,44 +376,30 @@ int enter_menu(char open)
|
|||
return c;
|
||||
}
|
||||
|
||||
static const char *end_titles_path(const char *fname) {
|
||||
if (istrcmp(fname,"TITULKY.TXT") == 0) fname = "end_titles.txt";
|
||||
else if (istrcmp(fname,"ENDTEXT.TXT") == 0) fname = "epilog.txt";
|
||||
return lang_replace_path_if_exists(fname);
|
||||
}
|
||||
|
||||
static TMPFILE_RD *end_titles_lang(const char *filename) {
|
||||
if (istrcmp(filename,"TITULKY.TXT") == 0) filename = "end_titles.txt";
|
||||
else if (istrcmp(filename,"ENDTEXT.TXT") == 0) filename = "epilog.txt";
|
||||
char *c = lang_load_string(filename);
|
||||
if (!c) return NULL;
|
||||
return temp_storage_from_binary(c, strlen(c), free, c);
|
||||
}
|
||||
char *get_next_title(signed char control,const char *filename)
|
||||
{
|
||||
|
||||
static TMPFILE_RD *titles=NULL;
|
||||
static char buffer[81];
|
||||
char *c;
|
||||
const char *path;
|
||||
|
||||
switch(control)
|
||||
{
|
||||
case 1:
|
||||
path = end_titles_path(filename);
|
||||
if (path == NULL) {
|
||||
path = build_pathname(2, gpathtable[SR_MAP],filename);
|
||||
titles = end_titles_lang(filename);
|
||||
if (titles != NULL) {
|
||||
return (char *)titles;
|
||||
}
|
||||
path = local_strdup(path);
|
||||
titles=enc_open(path);
|
||||
if (titles==NULL)
|
||||
{
|
||||
const char *path2 = build_pathname(2, gpathtable[SR_DATA],filename);
|
||||
path2 = local_strdup(path2);
|
||||
titles=enc_open(path2);
|
||||
if (titles==NULL)
|
||||
{
|
||||
char popis[300];
|
||||
closemode();
|
||||
sprintf(popis,"Soubor nenalezen: %s nebo %s\n",path,path2);
|
||||
display_error(popis);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return (char *)titles;
|
||||
titles = enc_open(filename, SR_DATA);
|
||||
return (char *)titles;
|
||||
case 0:if (titles!=NULL && temp_storage_gets(buffer,80,titles)) {
|
||||
c=strchr(buffer,'\n');if (c!=NULL) *c=0;
|
||||
c=strchr(buffer,'\r');if (c!=NULL) *c=0;
|
||||
|
@ -421,7 +407,7 @@ char *get_next_title(signed char control,const char *filename)
|
|||
strcpy(buffer, "*KONEC");
|
||||
}
|
||||
return buffer;
|
||||
case -1:if (titles!=NULL)enc_close(titles);
|
||||
case -1:if (titles!=NULL)temp_storage_close_rd(titles);
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -99,6 +99,7 @@ char runes[5]={0,0,0,0,0};
|
|||
|
||||
char group_sort[POCET_POSTAV]={0,1,2,3,4,5};
|
||||
|
||||
/*
|
||||
int32_t load_section(FILE *f,void **section, int *sct_type,int32_t *sect_size)
|
||||
//
|
||||
{
|
||||
|
@ -115,6 +116,33 @@ int32_t load_section(FILE *f,void **section, int *sct_type,int32_t *sect_size)
|
|||
s=fread(*section,1,*sect_size,f);
|
||||
return s;
|
||||
}
|
||||
*/
|
||||
static void ddl_file_deleter(void *ctx) {
|
||||
ablock_free(ctx);
|
||||
}
|
||||
|
||||
TMPFILE_RD *open_ddl_file(const char *name, int group) {
|
||||
int32_t size;
|
||||
if (!test_file_exist(group, name)) return NULL;
|
||||
const void *data = afile(name, group, &size);
|
||||
if (!data) return NULL;
|
||||
return temp_storage_from_binary(data, size, &ddl_file_deleter, (void *)data);
|
||||
}
|
||||
|
||||
int32_t load_section_mem(TMPFILE_RD *f,void **section, int *sct_type,int32_t *sect_size) {
|
||||
int32_t s;
|
||||
char c[20];
|
||||
|
||||
*section=NULL;
|
||||
temp_storage_read(c,sizeof(sekceid),f);
|
||||
if (strcmp(c,sekceid)) return -1;
|
||||
temp_storage_read(sct_type,sizeof(*sct_type),f);
|
||||
temp_storage_read(sect_size,sizeof(*sect_size),f);
|
||||
temp_storage_read(&s,sizeof(s),f);
|
||||
*section=getmem(*sect_size);
|
||||
s=temp_storage_read(*section,*sect_size,f);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int prepare_graphics(int *ofs,char *names,int32_t size,ABLOCK_DECODEPROC decomp,int class)
|
||||
|
@ -142,7 +170,7 @@ int load_level_texts(const char *filename)
|
|||
int err;
|
||||
|
||||
level_texts=create_list(10);
|
||||
err=load_string_list_ex(&level_texts,filename);
|
||||
err=load_string_list_ex(&level_texts,filename, SR_MAP);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -243,7 +271,7 @@ void translate_map_name(const char *mapfile, MAPGLOBAL *mglob) {
|
|||
|
||||
int load_map(const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
TMPFILE_RD *f;
|
||||
void *temp;
|
||||
int sect;
|
||||
int32_t size,r;
|
||||
|
@ -255,11 +283,9 @@ int load_map(const char *filename)
|
|||
int failed = 0;
|
||||
|
||||
map_with_password=0;
|
||||
const char *mpath = build_pathname(2, gpathtable[SR_MAP], filename);
|
||||
mpath = local_strdup(mpath);
|
||||
schovej_mysku();
|
||||
zobraz_mysku();
|
||||
f=fopen_icase(mpath,"rb");
|
||||
f=open_ddl_file(filename, SR_MAP);
|
||||
if (level_fname!=NULL) free(level_fname);
|
||||
level_fname=(char *)getmem(strlen(filename)+1);
|
||||
strcpy(level_fname,filename);
|
||||
|
@ -270,7 +296,7 @@ int load_map(const char *filename)
|
|||
if (f==NULL) return -1;
|
||||
do
|
||||
{
|
||||
r=load_section(f,&temp,§,&size);
|
||||
r=load_section_mem(f,&temp,§,&size);
|
||||
if (r==size)
|
||||
switch (sect)
|
||||
{
|
||||
|
@ -396,17 +422,17 @@ int load_map(const char *filename)
|
|||
{
|
||||
if (temp!=NULL)free(temp);
|
||||
ablock_free(mob_template);
|
||||
fclose(f);
|
||||
temp_storage_close_rd(f);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
while (nmapend);
|
||||
ablock_free(mob_template);
|
||||
fclose(f);
|
||||
temp_storage_close_rd(f);
|
||||
flag_map=(char *)getmem(mapsize*4);
|
||||
memset(minimap,0,sizeof(minimap));
|
||||
end_ptr=ofsts;
|
||||
const char *tpath=set_file_extension(mpath,".txt");
|
||||
const char *tpath=set_file_extension(filename,".txt");
|
||||
failed=load_level_texts(tpath);
|
||||
if (!failed && level_texts!=NULL) {
|
||||
lang_patch_stringtable(&level_texts, filename, "map_");
|
||||
|
|
|
@ -103,7 +103,6 @@ const void *pcx_8bit_decomp(const void *p, int32_t *s, int h);
|
|||
const void *pcx_fade_decomp(const void *p, int32_t *s, int h);
|
||||
const void *load_text_decomp(const void *p, int32_t *s, int h);
|
||||
|
||||
const char *texty_knihy;
|
||||
static const char *patch_file=NULL;
|
||||
int cur_page=0;
|
||||
|
||||
|
@ -805,14 +804,13 @@ void cti_texty(void)
|
|||
{
|
||||
int err;
|
||||
texty=(TSTR_LIST)create_list(4);
|
||||
const char *path = build_pathname(2,gpathtable[SR_DATA], TEXTY);
|
||||
if ((err=load_string_list_ex(&texty,path))!=0)
|
||||
if ((err=load_string_list_ex(&texty,TEXTY, SR_DATA))!=0)
|
||||
{
|
||||
char buff[256];
|
||||
closemode();
|
||||
switch (err)
|
||||
{
|
||||
case -1:sprintf(buff,"Can't load string table. File %s has not been found\n",path);break;
|
||||
case -1:sprintf(buff,"Can't load string table. File %s has not been found\n",TEXTY);break;
|
||||
case -2:sprintf(buff,"Missing end mark (-1) at the end of string table\n");break;
|
||||
case -3:sprintf(buff,"Memory very low (need min 4MB)\n");break;
|
||||
default:sprintf(buff,"Error in string table at line %d\n",err);break;
|
||||
|
@ -1012,16 +1010,6 @@ void init_skeldal(const INI_CONFIG *cfg)
|
|||
init_DDL_manager();
|
||||
show_loading_picture("LOADING.HI");
|
||||
|
||||
if (lang_get_folder()) {
|
||||
texty_knihy = build_pathname(2, lang_get_folder(), "book.txt");
|
||||
if (!check_file_exists(texty_knihy)) {
|
||||
texty_knihy=strdup(build_pathname(2,gpathtable[SR_MAP],"kniha.txt"));
|
||||
} else {
|
||||
texty_knihy=strdup(texty_knihy);
|
||||
}
|
||||
} else {
|
||||
texty_knihy=strdup(build_pathname(2,gpathtable[SR_MAP],"kniha.txt"));
|
||||
}
|
||||
|
||||
install_gui();
|
||||
if (is_joystick_enabled()) {
|
||||
|
@ -1335,8 +1323,8 @@ void play_anim(int anim_num)
|
|||
TSTR_LIST titl=NULL;
|
||||
const char *s = build_pathname(2,gpathtable[SR_VIDEO], texty[anim_num]);
|
||||
s = local_strdup(s);
|
||||
char *n = set_file_extension(s, ".TXT");
|
||||
if (load_string_list_ex(&titl,n)) titl=NULL;
|
||||
char *n = set_file_extension(texty[anim_num], ".TXT");
|
||||
if (load_string_list_ex(&titl,n, SR_VIDEO)) titl=NULL;
|
||||
else {
|
||||
lang_patch_stringtable(&titl, "intro", "");
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ typedef struct _temp_storage_file_wr {
|
|||
typedef struct _temp_storage_file_rd {
|
||||
std::string_view _data;
|
||||
int skp = 0;
|
||||
void (*deleter)(void *ctx) = nullptr;
|
||||
void *deleter_ctx = nullptr;
|
||||
} TMPFILE_RD;
|
||||
|
||||
struct icompare {
|
||||
|
@ -87,6 +89,7 @@ TMPFILE_WR* temp_storage_append(const char *name) {
|
|||
}
|
||||
|
||||
void temp_storage_close_rd(TMPFILE_RD *f) {
|
||||
if (f->deleter) f->deleter(f->deleter_ctx);
|
||||
delete f;
|
||||
}
|
||||
|
||||
|
@ -167,3 +170,9 @@ void temp_storage_ungetc(TMPFILE_RD *f) {
|
|||
TMPFILE_RD *temp_storage_from_string(const char *content) {
|
||||
return new TMPFILE_RD{{content, std::strlen(content)}};
|
||||
}
|
||||
TMPFILE_RD *temp_storage_from_binary(const void *content, size_t sz, void (*deleter)(void *ctx), void *ctx) {
|
||||
return new TMPFILE_RD{{static_cast<const char *>(content), sz}, 0, deleter, ctx};
|
||||
}
|
||||
uint32_t temp_storage_remain_size(TMPFILE_RD *f) {
|
||||
return f->_data.size();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ typedef struct _temp_storage_file_wr TMPFILE_WR;
|
|||
|
||||
TMPFILE_RD *temp_storage_open(const char *name);
|
||||
TMPFILE_RD *temp_storage_from_string(const char *content);
|
||||
TMPFILE_RD *temp_storage_from_binary(const void *content, size_t sz, void (*deleter)(void *ctx), void *ctx);
|
||||
TMPFILE_WR *temp_storage_create(const char *name);
|
||||
TMPFILE_WR *temp_storage_append(const char *name);
|
||||
void temp_storage_delete(const char *name);
|
||||
|
@ -26,6 +27,7 @@ char *temp_storage_gets(char *buff, size_t sz, TMPFILE_RD *f);
|
|||
void temp_storage_ungetc(TMPFILE_RD *f);
|
||||
void temp_storage_write(const void *data, uint32_t size, TMPFILE_WR *f);
|
||||
uint32_t temp_storage_read(void *data, uint32_t size, TMPFILE_RD *f);
|
||||
uint32_t temp_storage_remain_size(TMPFILE_RD *f);
|
||||
void temp_storage_skip(TMPFILE_RD *f, int bytes);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
|
@ -140,7 +140,7 @@ uint32_t bk_global_counter=0;
|
|||
char *swap_path;
|
||||
|
||||
|
||||
static int test_file_exist_DOS(int group,char *filename)
|
||||
static int test_file_exist_DOS(int group,const char *filename)
|
||||
{
|
||||
const char *f = build_pathname(2, mman_pathlist[group], filename);
|
||||
if (!check_file_exists(f)) return 0;
|
||||
|
@ -180,7 +180,7 @@ static TNAMETABLE_REF load_file_table(const void *bmf_m)
|
|||
}
|
||||
|
||||
|
||||
int get_file_entry_in_table(const TNAMETABLE_REF *where, char *name) {
|
||||
int get_file_entry_in_table(const TNAMETABLE_REF *where, const char *name) {
|
||||
for(uint32_t i = 0; i< where->count; ++i) {
|
||||
if (strncmp(where->data[i].name, name, 12) == 0) {
|
||||
return where->data[i].seek;
|
||||
|
@ -192,7 +192,7 @@ int get_file_entry_in_table(const TNAMETABLE_REF *where, char *name) {
|
|||
|
||||
|
||||
|
||||
char get_file_entry(int group,char *name, THANDLE_DATA *h) {
|
||||
char get_file_entry(int group,const char *name, THANDLE_DATA *h) {
|
||||
char ex;
|
||||
|
||||
ex=mman_patch && test_file_exist_DOS(group,name);
|
||||
|
@ -327,7 +327,7 @@ int find_handle(const char *name,ABLOCK_DECODEPROC decomp)
|
|||
return find_same(name,decomp);
|
||||
}
|
||||
|
||||
int test_file_exist(int group,char *filename)
|
||||
int test_file_exist(int group,const char *filename)
|
||||
{
|
||||
THANDLE_DATA h;
|
||||
if (get_file_entry(group, filename, &h) == 0) return test_file_exist_DOS(group,filename);
|
||||
|
@ -369,7 +369,7 @@ THANDLE_DATA *def_handle(int handle,const char *filename,ABLOCK_DECODEPROC decom
|
|||
return h;
|
||||
}
|
||||
|
||||
const void *afile(char *filename,int group,int32_t *blocksize)
|
||||
const void *afile(const char *filename,int group,int32_t *blocksize)
|
||||
{
|
||||
char *d;
|
||||
char entr;
|
||||
|
@ -401,7 +401,7 @@ const void *afile(char *filename,int group,int32_t *blocksize)
|
|||
return p;
|
||||
}
|
||||
|
||||
void *afile_copy(char *filename,int group,int32_t *blocksize) {
|
||||
void *afile_copy(const char *filename,int group,int32_t *blocksize) {
|
||||
const void *ptr = afile(filename, group, blocksize);
|
||||
if (need_to_be_free(ptr)) return (void *)ptr;
|
||||
void *cpy = getmem(*blocksize);
|
||||
|
|
|
@ -95,9 +95,9 @@ void undef_handle(int handle); //uvolni hadle k dalsimu pouziti
|
|||
THANDLE_DATA *zneplatnit_block(int handle); //zneplatni data bloku
|
||||
THANDLE_DATA *get_handle(int handle); //vraci informace o rukojeti
|
||||
int find_handle(const char *name,ABLOCK_DECODEPROC decomp); //hleda mezi rukojeti stejnou definici
|
||||
int test_file_exist(int group,char *filename); //testuje zda soubor existuje v ramci mmanageru
|
||||
const void *afile(char *filename,int group,int32_t *blocksize); //nahraje do pameti soubor registrovany v ramci mmanageru
|
||||
void *afile_copy(char *filename,int group,int32_t *blocksize); //nahraje do pameti soubor registrovany v ramci mmanageru
|
||||
int test_file_exist(int group,const char *filename); //testuje zda soubor existuje v ramci mmanageru
|
||||
const void *afile(const char *filename,int group,int32_t *blocksize); //nahraje do pameti soubor registrovany v ramci mmanageru
|
||||
void *afile_copy(const char *filename,int group,int32_t *blocksize); //nahraje do pameti soubor registrovany v ramci mmanageru
|
||||
int32_t get_handle_size(int handle);
|
||||
//void get_mem_info(MEMORYSTATUS *mem);
|
||||
void ablock_free(const void *ptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue