From a8c9fced4c0fdd7a14fb9f204bcb10cda1ebda2e Mon Sep 17 00:00:00 2001 From: Ondrej Novak Date: Sun, 16 Feb 2025 20:41:29 +0100 Subject: [PATCH] fix crashes --- game/console.c | 2 +- game/enemy.c | 88 ++++++++++++++++++------------------ game/engine1.c | 2 + game/engine1.h | 1 + game/engine2.c | 4 +- game/gamesave.c | 2 +- game/interfac.c | 4 +- game/inv.c | 8 ++-- game/kouzla.c | 7 ++- game/setup.c | 2 +- game/sndandmus.c | 3 +- platform/sdl/sdl_context.cpp | 1 + 12 files changed, 65 insertions(+), 59 deletions(-) diff --git a/game/console.c b/game/console.c index bac29b9..a57f411 100644 --- a/game/console.c +++ b/game/console.c @@ -606,7 +606,7 @@ static int process_actions(const char *command) { if (istrcmp(command, "world-list") == 0) { int cnt = 0; list_files(gpathtable[SR_MAP], file_type_normal|file_type_just_name, add_file_to_console, &cnt); - printf("\n"); + wzprintf("\n"); return 1; } if (istrcmp(command, "beam-me-up") == 0) { diff --git a/game/enemy.c b/game/enemy.c index 059e280..70cc346 100644 --- a/game/enemy.c +++ b/game/enemy.c @@ -543,51 +543,53 @@ int q_vidis_postavu(int sector,int dir,TMOB *p,int *otocit_se,char ret) { char ok=0; THUMAN *ps=&postavy[i]; - xs=map_coord[sector].x-map_coord[postavy[i].sektor].x; - ys=map_coord[sector].y-map_coord[postavy[i].sektor].y; - d=MAX(abs(xs),abs(ys)); - if (d<=p->dohled && (!(ps->vlastnosti[VLS_KOUZLA] & SPL_INVIS)||p->vlajky & MOB_SENSE) && ps->used && ps->lives && ps->inmaphash == current_map_hash) - switch(dir) - { - case 0:ok=ys>=0;break; - case 1:ok=xs<=0;break; - case 2:ok=ys<=0;break; - case 3:ok=xs>=0;break; - } - if (ok) - if (je_mozne_videt(sector,postavy[i].sektor,SD_MONST_IMPS | SD_PLAY_IMPS)) - { - int alt = 0; - if (ys>=abs(xs)) {nd=0;alt=xs>0?3:1;} - else if (xs>=abs(ys)) {nd=3;alt=ys>0?0:2;} - else if (ys<=(-abs(xs))) {nd=2;alt=xs>0?1:3;} - else if (xs<=(-abs(ys))) {nd=1;alt=ys>0?2:0;} - if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) + if (ps->used && ps->inmaphash == current_map_hash) { + xs=map_coord[sector].x-map_coord[postavy[i].sektor].x; + ys=map_coord[sector].y-map_coord[postavy[i].sektor].y; + d=MAX(abs(xs),abs(ys)); + if (d<=p->dohled && (!(ps->vlastnosti[VLS_KOUZLA] & SPL_INVIS)||p->vlajky & MOB_SENSE) && ps->used && ps->lives && ps->inmaphash == current_map_hash) + switch(dir) { - nd=alt; - if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) - { - nd=(alt+2)&3; - if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) - { - nd=(alt+3)&3; - } - } + case 0:ok=ys>=0;break; + case 1:ok=xs<=0;break; + case 2:ok=ys<=0;break; + case 3:ok=xs>=0;break; } - } - else d=255; - else d=255; - if (d!=255) - { - d*=2; - if (xs!=0 && ys!=0) d+=3;//dej prednost tem co jsou na tve souradnici. - if (d=abs(xs)) {nd=0;alt=xs>0?3:1;} + else if (xs>=abs(ys)) {nd=3;alt=ys>0?0:2;} + else if (ys<=(-abs(xs))) {nd=2;alt=xs>0?1:3;} + else if (xs<=(-abs(ys))) {nd=1;alt=ys>0?2:0;} + if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) + { + nd=alt; + if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) + { + nd=(alt+2)&3; + if (mob_check_next_sector(p->sector,nd,p->stay_strategy & MOB_BIG,p->vlajky & MOB_PASSABLE)==1) + { + nd=(alt+3)&3; + } + } + } + } + else d=255; + else d=255; + if (d!=255) + { + d*=2; + if (xs!=0 && ys!=0) d+=3;//dej prednost tem co jsou na tve souradnici. + if (dxpos+xofs; if (-x>realsx) return; p=stena;p+=SHADE_PAL+2*2+2; + zoom.texture_end = p + txtsx*txtsy; i=0; while (x<0) { @@ -690,6 +691,7 @@ void show_cel2(int celx,int cely,const void *stena,int xofs,int yofs,char rev, i if (celx<=0) x=x3d->xpos+xofs; else x=x3d->xpos2+xofs; if (-x>realsx) return; p=stena;p+=SHADE_PAL+2*2+2; + zoom.texture_end = p + txtsx*txtsy; i=0; while (x<0) { diff --git a/game/engine1.h b/game/engine1.h index fc9dcc4..1099991 100644 --- a/game/engine1.h +++ b/game/engine1.h @@ -57,6 +57,7 @@ typedef struct zoominfo word *palette; word ycount; word xmax; + const void *texture_end; }ZOOMINFO; diff --git a/game/engine2.c b/game/engine2.c index 8b8ab18..65b6a8f 100644 --- a/game/engine2.c +++ b/game/engine2.c @@ -20,7 +20,7 @@ void sikma_zleva_##suffx(void) \ word cy = zoom.ycount; \ const unsigned char *pixmap = zoom.texture; \ const short *ytable = zoom.ytable; \ - while (cy) { \ + while (cy && pixmap < (const unsigned char *)zoom.texture_end) { \ const int32_t *xtable = zoom.xtable; \ word cx = zoom.xmax; \ word *scr_iter = scr; \ @@ -48,7 +48,7 @@ void sikma_zprava_##suffx(void) \ word cy = zoom.ycount; \ const unsigned char *pixmap = zoom.texture; \ const short *ytable = zoom.ytable; \ - while (cy) { \ + while (cy && pixmap < (const unsigned char *)zoom.texture_end) { \ const int32_t *xtable = zoom.xtable; \ word cx = zoom.xmax; \ word *scr_iter = scr; \ diff --git a/game/gamesave.c b/game/gamesave.c index 5d3ea90..78cb412 100644 --- a/game/gamesave.c +++ b/game/gamesave.c @@ -208,7 +208,7 @@ void restore_items(TMPFILE_RD *f) int32_t i,j; for(i=0;iwearing[PO_RUKA_L]-1; - short i2 = human_selected->wearing[PO_RUKA_R]-1; + short i1 = human_selected->wearing[PO_RUKA_L]; + short i2 = human_selected->wearing[PO_RUKA_R]; if (!i1 || !i2) return 0; - const TITEM *it1 = glob_items+i1; - const TITEM *it2 = glob_items+i2; + const TITEM *it1 = glob_items+i1-1; + const TITEM *it2 = glob_items+i2-1; if (it1->druh!=TYP_UTOC || it2->druh!=TYP_UTOC ) return 0; for (int i = VLS_SILA; i <=VLS_OBRAT; ++i) { if ((it1->podminky[i] + it2->podminky[i] > human_selected->vlastnosti[i]) diff --git a/game/kouzla.c b/game/kouzla.c index 7060d80..f871450 100644 --- a/game/kouzla.c +++ b/game/kouzla.c @@ -925,15 +925,14 @@ void spell_pripojenia(int owner) { int sect; sect=postavy[i].sektor; - if (map_coord[sect].flags & MC_NOSUMMON) + if (sect > 0 && sect < mapsize && map_coord[sect].flags & MC_NOSUMMON) { if (h==NULL) h=postavy+i;else more=1; - else - { + } else { postavy[i].sektor=postavy[owner].sektor; postavy[i].direction=postavy[owner].direction; postavy[i].inmaphash = postavy[owner].inmaphash; } - } + } auto_group(); if (more) bott_disp_text(texty[89]); else if (h!=NULL) diff --git a/game/setup.c b/game/setup.c index e76afda..88445d4 100644 --- a/game/setup.c +++ b/game/setup.c @@ -149,7 +149,7 @@ void new_setup() mix_back_sound(256000-16384); memset(&ctl,0,sizeof(ctl)); - change_click_map(setup,4); + change_click_map(setup,countof(setup)); set_font(H_FBOLD,SETUP_COL2); default_font=curfont; memcpy(f_default,charcolors,sizeof(f_default)); diff --git a/game/sndandmus.c b/game/sndandmus.c index 535ff90..9019ffe 100644 --- a/game/sndandmus.c +++ b/game/sndandmus.c @@ -544,7 +544,8 @@ void play_sample_at_sector(int sample,int listener,int source,int track, char lo int oldtrack; if (!sound_enabled) return; - if (map_coord[listener].layer!=map_coord[source].layer) return; + if (listener<0 || listener>=mapsize || map_coord[listener].layer!=map_coord[source].layer) return; + if (source<0 || source >=mapsize) return; xd=map_coord[source].x; yd=map_coord[source].y; chan=find_free_channel(track); diff --git a/platform/sdl/sdl_context.cpp b/platform/sdl/sdl_context.cpp index 9c89f77..2bdf983 100644 --- a/platform/sdl/sdl_context.cpp +++ b/platform/sdl/sdl_context.cpp @@ -10,6 +10,7 @@ #include #include #include +#include void SDLContext::SDL_Deleter::operator ()(SDL_Window* window) { SDL_DestroyWindow(window); }