From 4f4796b469ae2dc4ba3f131d940971f24a997df5 Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Tue, 1 Mar 2011 08:48:53 +0800 Subject: [PATCH 1/4] INST works with caps lock/replace mode, and fix some replace mode out of screen crashes. --- src/powder.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/powder.c b/src/powder.c index 55c12337e..1a414071c 100644 --- a/src/powder.c +++ b/src/powder.c @@ -2763,7 +2763,7 @@ int flood_parts(int x, int y, int c, int cm, int bm) bm = 0; } - if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT)) + if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT && !(cm==PT_INST&&co==PT_SPRK))) return 1; // go left as far as possible @@ -2788,7 +2788,12 @@ int flood_parts(int x, int y, int c, int cm, int bm) // fill span for (x=x1; x<=x2; x++) { - if (!create_parts(x, y, 0, 0, co)) + if(cm==PT_INST&&co==PT_SPRK) + { + if(create_part(-1,x, y, co)==-1) + return 0; + } + else if (!create_parts(x, y, 0, 0, co)) return 0; } // fill children @@ -2939,10 +2944,14 @@ int create_parts(int x, int y, int rx, int ry, int c) for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + { + if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) + continue; if (!REPLACE_MODE) create_part(-2, x+i, y+j, c); else if ((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0) create_part(-2, x+i, y+j, c); + } return 1; } @@ -2981,6 +2990,8 @@ int create_parts(int x, int y, int rx, int ry, int c) for (i=-rx; i<=rx; i++) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) { + if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) + continue; if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0) continue; if ((pmap[y+j][x+i])) From 20edfacae5735e654b8dfa85e54768d7551a9382 Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Wed, 2 Mar 2011 02:33:10 +0800 Subject: [PATCH 2/4] fix "water spark bounce" --- src/powder.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/powder.c b/src/powder.c index 1a414071c..e93f88d79 100644 --- a/src/powder.c +++ b/src/powder.c @@ -79,6 +79,9 @@ int eval_move(int pt, int nx, int ny, unsigned *rr) if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL) return 1; + if(pt==PT_SPRK)//spark shouldn't move + return 0; + if (pt==PT_PHOT&&( (r&0xFF)==PT_GLAS || (r&0xFF)==PT_PHOT || (r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || From e055eb5893fc6f5eb064d2d42a83bf13d02e1267 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 25 Feb 2011 03:24:37 +0800 Subject: [PATCH 3/4] Fix ETRD not conducting correctly to adjacent particles --- src/elements/sprk.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/elements/sprk.c b/src/elements/sprk.c index f107b9af6..89480ad6d 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -120,7 +120,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { conduct_sprk = 0; if (ct==PT_NSCN && rt==PT_PSCN) conduct_sprk = 0; - if (ct==PT_ETRD && (parts[i].life!=5||!(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN))) + if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)) conduct_sprk = 0; if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0; if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR)) @@ -137,15 +137,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { conduct_sprk = 0; if (conduct_sprk) { - if (ct==PT_ETRD) { - part_change_type(i,x,y,PT_ETRD); - parts[i].ctype = PT_NONE; - parts[i].life = 20; - part_change_type(r>>8,x+rx,y+ry,PT_SPRK); - parts[r>>8].life = 4; - parts[r>>8].ctype = rt; - } - else if (rt==PT_WATR||rt==PT_SLTW) { + if (rt==PT_WATR||rt==PT_SLTW) { if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)>8,x+rx,y+ry,PT_SPRK); @@ -167,6 +159,15 @@ int update_SPRK(UPDATE_FUNC_ARGS) { if (parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON)) parts[r>>8].temp = parts[r>>8].temp+10.0f; } + else if (ct==PT_ETRD && parts[i].life==5) + { + part_change_type(i,x,y,ct); + parts[i].ctype = PT_NONE; + parts[i].life = 20; + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } } } return 0; From 647ff2bff073d525f1c02eea5c4e01e8dcd3f279 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 27 Feb 2011 04:58:22 +0800 Subject: [PATCH 4/4] Fix some potential crashes, better handling of empty server responses --- src/interface.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/interface.c b/src/interface.c index 9b1b495cd..b13917dee 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2549,7 +2549,8 @@ int search_ui(pixel *vid_buf) memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE); } is_p1 = (exp_res < GRID_X*GRID_Y); - free(results); + if (results) + free(results); active = 0; } @@ -2824,6 +2825,10 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) data = http_async_req_stop(http, &status, &data_size); if (status == 200) { + if (!data||!data_size) { + error_ui(vid_buf, 0, "Save data is empty (may be corrupt)"); + break; + } pixel *full_save = prerender_save(data, data_size, &imgw, &imgh); if (full_save!=NULL) { save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2); @@ -2842,15 +2847,16 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) { http_last_use_2 = time(NULL); info_data = http_async_req_stop(http_2, &status_2, NULL); - if (status_2 == 200) + if (status_2 == 200 || !info_data) { info_ready = info_parse(info_data, info); - if (info_ready==-1) { - error_ui(vid_buf, 0, "Not found"); + if (info_ready<=0) { + error_ui(vid_buf, 0, "Save info not found"); break; } } - free(info_data); + if (info_data) + free(info_data); active_2 = 0; free(http_2); http_2 = NULL; @@ -3546,7 +3552,7 @@ int execute_tagop(pixel *vid_buf, char *op, char *tag) return 1; } - if (result[2]) + if (result && result[2]) { strncpy(svf_tags, result+3, 255); svf_id[15] = 0; @@ -3604,14 +3610,16 @@ void execute_save(pixel *vid_buf) free(result); return; } - if (result && strncmp(result, "OK", 2)) + if (!result || strncmp(result, "OK", 2)) { + if (!result) + result = mystrdup("Could not save - no reply from server"); error_ui(vid_buf, 0, result); free(result); return; } - if (result[2]) + if (result && result[2]) { strncpy(svf_id, result+3, 15); svf_id[15] = 0;