From be1d3ff74a87de04069cd7ca499cc49f78b03dda Mon Sep 17 00:00:00 2001 From: Duncan Date: Thu, 7 Aug 2014 13:00:49 +0100 Subject: [PATCH 1/6] Added very rough 0x684027 function --- src/game.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/game.c b/src/game.c index 841fcb2031..5bc158bb28 100644 --- a/src/game.c +++ b/src/game.c @@ -129,6 +129,75 @@ const draw_rain_func draw_rain_function[] = { &draw_heavy_rain // Heavy rain }; + +void sub_0x684027(int left, int top, int width, int height, int ebp, int edi, int esi){ + int eax = left, ebx = top, ecx = width, edx = height; + ebp = RCT2_ADDRESS(0x9AC010,uint32)[ebp]; + RCT2_GLOBAL(0xee7854,uint32) = eax; + RCT2_GLOBAL(0xee7858,uint32) = ebx; + RCT2_GLOBAL(0xee785C,uint32) = ecx; + RCT2_GLOBAL(0xee7860,uint32) = edx; + eax = *((uint8*)ebp); + ebx = *((uint8*)(ebp+1)); + RCT2_GLOBAL(0xEE7864,uint32) = eax; + eax--; + ebx--; + RCT2_GLOBAL(0xEE7868,uint32) = eax; + RCT2_GLOBAL(0xEE786C,uint32) = ebx; + edi &= eax; + esi &= ebx; + RCT2_GLOBAL(0xEE7870,uint32) = edi; + ebp+=2; + ebx = RCT2_GLOBAL(0x9ABDD4,uint16); + ebx += RCT2_GLOBAL(0x9ABDD0,uint16); + RCT2_GLOBAL(0xEE7874,uint32) = ebx; + ebx *= top; + ebx += left; + ecx = esi; + edi = RCT2_GLOBAL(0x9AC00C,uint32); + edi <<= 2; + esi = RCT2_GLOBAL(0x9ABDC8,uint32); + edi += 0xEDF850; + + //loop at 6840A4 + int al = *((uint8*)(ecx*2+ebp)); + if (al == 0xFF) continue; + if (RCT2_GLOBAL(0x9AC00C,uint32) > 0x1F38) continue; + //push ebx + //push ecx + eax -= RCT2_GLOBAL(0xEE7870,uint32); + edx = RCT2_GLOBAL(0xEE785C,uint32); + eax &= RCT2_GLOBAL(0xEE7868,uint32); + edx += ebx; + ebx += eax; + if (ebx >= edx)continue; + int ah = *((uint8*)(ecx*2+ebp+1)); + ecx = RCT2_GLOBAL(0xEE7864,uint32); + + //inner loop + al = ah; + int old_al = al; + al = *((uint8*)(esi+ebx)); + *((uint8*)(esi+ebx)) = old_al; + RCT2_GLOBAL(0x9AC00C,uint32)++; + ebx <<= 8; + ebx |= al; + *(uint32*)edi = ebx; + ebx >>= 8; + edi += 4; + ebx += ecx; + if (ebx < edx) inner loop; + + //pop ecx + //pop ebx + ecx++; + ebx += RCT2_GLOBAL(0xEE7874,uint32); + ecx &= RCT2_GLOBAL(0xEE786C,uint32); + RCT2_GLOBAL(0xEE7860,uint32)--; + if (RCT2_GLOBAL(0xEE7860,uint32)!= 0) loop; + +} + /** * * rct2: 0x006ED801 From ca38d60b6f856aaa2a5ad660385b4e49753d7c23 Mon Sep 17 00:00:00 2001 From: Duncan Date: Thu, 7 Aug 2014 16:05:35 +0100 Subject: [PATCH 2/6] Cleaned up 684027 Not tested. --- src/game.c | 133 +++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/src/game.c b/src/game.c index 5bc158bb28..ac92b5d8f5 100644 --- a/src/game.c +++ b/src/game.c @@ -131,71 +131,74 @@ const draw_rain_func draw_rain_function[] = { void sub_0x684027(int left, int top, int width, int height, int ebp, int edi, int esi){ - int eax = left, ebx = top, ecx = width, edx = height; - ebp = RCT2_ADDRESS(0x9AC010,uint32)[ebp]; - RCT2_GLOBAL(0xee7854,uint32) = eax; - RCT2_GLOBAL(0xee7858,uint32) = ebx; - RCT2_GLOBAL(0xee785C,uint32) = ecx; - RCT2_GLOBAL(0xee7860,uint32) = edx; - eax = *((uint8*)ebp); - ebx = *((uint8*)(ebp+1)); - RCT2_GLOBAL(0xEE7864,uint32) = eax; - eax--; - ebx--; - RCT2_GLOBAL(0xEE7868,uint32) = eax; - RCT2_GLOBAL(0xEE786C,uint32) = ebx; - edi &= eax; - esi &= ebx; - RCT2_GLOBAL(0xEE7870,uint32) = edi; - ebp+=2; - ebx = RCT2_GLOBAL(0x9ABDD4,uint16); - ebx += RCT2_GLOBAL(0x9ABDD0,uint16); - RCT2_GLOBAL(0xEE7874,uint32) = ebx; - ebx *= top; - ebx += left; - ecx = esi; - edi = RCT2_GLOBAL(0x9AC00C,uint32); - edi <<= 2; - esi = RCT2_GLOBAL(0x9ABDC8,uint32); - edi += 0xEDF850; - - //loop at 6840A4 - int al = *((uint8*)(ecx*2+ebp)); - if (al == 0xFF) continue; - if (RCT2_GLOBAL(0x9AC00C,uint32) > 0x1F38) continue; - //push ebx - //push ecx - eax -= RCT2_GLOBAL(0xEE7870,uint32); - edx = RCT2_GLOBAL(0xEE785C,uint32); - eax &= RCT2_GLOBAL(0xEE7868,uint32); - edx += ebx; - ebx += eax; - if (ebx >= edx)continue; - int ah = *((uint8*)(ecx*2+ebp+1)); - ecx = RCT2_GLOBAL(0xEE7864,uint32); - - //inner loop - al = ah; - int old_al = al; - al = *((uint8*)(esi+ebx)); - *((uint8*)(esi+ebx)) = old_al; - RCT2_GLOBAL(0x9AC00C,uint32)++; - ebx <<= 8; - ebx |= al; - *(uint32*)edi = ebx; - ebx >>= 8; - edi += 4; - ebx += ecx; - if (ebx < edx) inner loop; - - //pop ecx - //pop ebx - ecx++; - ebx += RCT2_GLOBAL(0xEE7874,uint32); - ecx &= RCT2_GLOBAL(0xEE786C,uint32); - RCT2_GLOBAL(0xEE7860,uint32)--; - if (RCT2_GLOBAL(0xEE7860,uint32)!= 0) loop; - + int eax = left, ebx = top, ecx = width, edx = height; + ebp = RCT2_ADDRESS(0x9AC010,uint32)[ebp]; + //RCT2_GLOBAL(0xee7854,uint32) = eax; + //RCT2_GLOBAL(0xee7858,uint32) = ebx; + //RCT2_GLOBAL(0xee785C,uint32) = ecx; + //RCT2_GLOBAL(0xee7860,uint32) = edx; + eax = *((uint8*)ebp); + ebx = *((uint8*)(ebp+1)); + RCT2_GLOBAL(0xEE7864,uint32) = eax; + eax--; + ebx--; + RCT2_GLOBAL(0xEE7868,uint32) = eax; + RCT2_GLOBAL(0xEE786C,uint32) = ebx; + edi &= eax; + esi &= ebx; + RCT2_GLOBAL(0xEE7870,uint32) = edi; + ebp+=2; + rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI,rct_drawpixelinfo); + + RCT2_GLOBAL(0xEE7874,uint32) = dpi->pitch + dpi->width; + ebx = (dpi->pitch + dpi->width)*top + left; + ecx = esi; + edi = RCT2_GLOBAL(0x9AC00C,uint32); + edi <<= 2; + + //esi = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_DPI,uint32); + edi += 0xEDF850; + + for( ; height != 0; height--){ + //0x6840A4 + int al = *((uint8*)(ecx*2+ebp)); + if (al == 0xFF) continue; + if (RCT2_GLOBAL(0x9AC00C,uint32) > 0x1F38) continue; + //push ebx + //push ecx + int _ebx = ebx; + int _ecx = ecx; + + eax -= RCT2_GLOBAL(0xEE7870,uint32); + edx = width; + eax &= RCT2_GLOBAL(0xEE7868,uint32); + edx += ebx; + ebx += eax; + if (ebx >= edx)continue; + int ah = *((uint8*)(ecx*2+ebp+1)); + ecx = RCT2_GLOBAL(0xEE7864,uint32); + + //inner loop + while(ebx < edx){ + al = ah; + int old_al = al; + al = dpi->bits[ebx]; + dpi->bits[ebx] = old_al; + RCT2_GLOBAL(0x9AC00C,uint32)++; + ebx <<= 8; + ebx |= al; + *(uint32*)edi = ebx; + ebx >>= 8; + edi += 4; + ebx += ecx; + } + //pop ecx + //pop ebx + ecx = _ecx; + ebx = _ebx; + ecx++; + ebx += dpi->pitch + dpi->width; + ecx &= RCT2_GLOBAL(0xEE786C,uint32); } /** From 6ec15b240bc30ab5742293751ad9aaabed15425e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 7 Aug 2014 17:12:27 +0100 Subject: [PATCH 3/6] Fix compile mistakes --- src/game.c | 79 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/game.c b/src/game.c index ac92b5d8f5..e8c18a56d1 100644 --- a/src/game.c +++ b/src/game.c @@ -159,46 +159,47 @@ void sub_0x684027(int left, int top, int width, int height, int ebp, int edi, in //esi = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_DPI,uint32); edi += 0xEDF850; - for( ; height != 0; height--){ - //0x6840A4 - int al = *((uint8*)(ecx*2+ebp)); - if (al == 0xFF) continue; - if (RCT2_GLOBAL(0x9AC00C,uint32) > 0x1F38) continue; - //push ebx - //push ecx - int _ebx = ebx; - int _ecx = ecx; - - eax -= RCT2_GLOBAL(0xEE7870,uint32); - edx = width; - eax &= RCT2_GLOBAL(0xEE7868,uint32); - edx += ebx; - ebx += eax; - if (ebx >= edx)continue; - int ah = *((uint8*)(ecx*2+ebp+1)); - ecx = RCT2_GLOBAL(0xEE7864,uint32); - - //inner loop - while(ebx < edx){ - al = ah; - int old_al = al; - al = dpi->bits[ebx]; - dpi->bits[ebx] = old_al; - RCT2_GLOBAL(0x9AC00C,uint32)++; - ebx <<= 8; - ebx |= al; - *(uint32*)edi = ebx; - ebx >>= 8; - edi += 4; - ebx += ecx; + for (; height != 0; height--){ + //0x6840A4 + int al = *((uint8*)(ecx * 2 + ebp)); + if (al == 0xFF) continue; + if (RCT2_GLOBAL(0x9AC00C, uint32) > 0x1F38) continue; + //push ebx + //push ecx + int _ebx = ebx; + int _ecx = ecx; + + eax -= RCT2_GLOBAL(0xEE7870, uint32); + edx = width; + eax &= RCT2_GLOBAL(0xEE7868, uint32); + edx += ebx; + ebx += eax; + if (ebx >= edx)continue; + int ah = *((uint8*)(ecx * 2 + ebp + 1)); + ecx = RCT2_GLOBAL(0xEE7864, uint32); + + //inner loop + while (ebx < edx){ + al = ah; + int old_al = al; + al = dpi->bits[ebx]; + dpi->bits[ebx] = old_al; + RCT2_GLOBAL(0x9AC00C, uint32)++; + ebx <<= 8; + ebx |= al; + *(uint32*)edi = ebx; + ebx >>= 8; + edi += 4; + ebx += ecx; + } + //pop ecx + //pop ebx + ecx = _ecx; + ebx = _ebx; + ecx++; + ebx += dpi->pitch + dpi->width; + ecx &= RCT2_GLOBAL(0xEE786C, uint32); } - //pop ecx - //pop ebx - ecx = _ecx; - ebx = _ebx; - ecx++; - ebx += dpi->pitch + dpi->width; - ecx &= RCT2_GLOBAL(0xEE786C,uint32); } /** From 5257f368c982b5acb04dd02bc57d78c8e324d3f3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 7 Aug 2014 22:37:24 +0100 Subject: [PATCH 4/6] Cleaned up rain code. Remember to remove constant rain --- src/game.c | 139 ++++++++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 77 deletions(-) diff --git a/src/game.c b/src/game.c index e8c18a56d1..38c5631f12 100644 --- a/src/game.c +++ b/src/game.c @@ -51,6 +51,55 @@ void game_handle_keyboard_input(); void process_mouse_over(int x, int y); +void sub_0x684027(int left, int top, int width, int height, int ebp, uint32 edi, uint32 esi){ + uint32 eax = left, ecx = width, edx = height; + uint32 ebx = top; + uint8* pattern = RCT2_ADDRESS(0x9AC010, uint8*)[ebp]; + uint8 pattern_x_space = *pattern++; + uint8 pattern_y_space = *pattern++; + + uint8 pattern_start_x_offset = edi % pattern_x_space; + uint8 pattern_start_y_offset = esi % pattern_y_space;; + + rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo); + uint32 pixel_offset = (dpi->pitch + dpi->width)*top + left; + uint8 pattern_y_pos = pattern_start_y_offset; + + //Stores the colours of changed pixels + uint32* pixel_store = RCT2_ADDRESS(0xEDF850, uint32); + pixel_store += RCT2_GLOBAL(0x9AC00C, uint32); + + for (; height != 0; height--){ + int al = pattern[pattern_y_pos * 2]; + if (al != 0xFF){ + if (RCT2_GLOBAL(0x9AC00C, uint32) <= 0x1F38){ + int _pixel_offset = pixel_offset; + + eax = al - pattern_start_x_offset; + edx = width; + eax %= pattern_x_space; + //eax &= RCT2_GLOBAL(0xEE7868, uint32); + edx += _pixel_offset; + _pixel_offset += eax; + if (_pixel_offset < edx){ + uint8 pattern_pixel = pattern[pattern_y_pos * 2 + 1]; + //inner loop + while (_pixel_offset < edx){ + uint8 current_pixel = dpi->bits[_pixel_offset]; + dpi->bits[_pixel_offset] = pattern_pixel; + RCT2_GLOBAL(0x9AC00C, uint32)++; + *pixel_store++ = (_pixel_offset << 8) | current_pixel; //Store colour and position + _pixel_offset += pattern_x_space; + } + } + } + } + pattern_y_pos++; + pixel_offset += dpi->pitch + dpi->width; + pattern_y_pos %= pattern_y_space; + } +} + typedef void(*draw_rain_func)(int left, int top, int width, int height); /** @@ -65,7 +114,8 @@ void draw_light_rain(int left, int top, int width, int height){ edi += left; esi += top; - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x18; esi = (RCT2_GLOBAL(0x00F663AC, int) * 4) + 0x0D; @@ -73,8 +123,8 @@ void draw_light_rain(int left, int top, int width, int height){ edi += left; esi += top; - - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); } /** @@ -89,7 +139,8 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x10; esi = (RCT2_GLOBAL(0x00F663AC, int) * 6) + 5; @@ -98,7 +149,8 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); edi = -RCT2_GLOBAL(0x00F663AC, int) + 8; esi = (RCT2_GLOBAL(0x00F663AC, int) * 3) + 7; @@ -107,7 +159,8 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x18; esi = (RCT2_GLOBAL(0x00F663AC, int) * 4) + 0x0D; @@ -116,7 +169,8 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + sub_0x684027(left, top, width, height, 0, edi, esi); + //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); } /** @@ -130,77 +184,7 @@ const draw_rain_func draw_rain_function[] = { }; -void sub_0x684027(int left, int top, int width, int height, int ebp, int edi, int esi){ - int eax = left, ebx = top, ecx = width, edx = height; - ebp = RCT2_ADDRESS(0x9AC010,uint32)[ebp]; - //RCT2_GLOBAL(0xee7854,uint32) = eax; - //RCT2_GLOBAL(0xee7858,uint32) = ebx; - //RCT2_GLOBAL(0xee785C,uint32) = ecx; - //RCT2_GLOBAL(0xee7860,uint32) = edx; - eax = *((uint8*)ebp); - ebx = *((uint8*)(ebp+1)); - RCT2_GLOBAL(0xEE7864,uint32) = eax; - eax--; - ebx--; - RCT2_GLOBAL(0xEE7868,uint32) = eax; - RCT2_GLOBAL(0xEE786C,uint32) = ebx; - edi &= eax; - esi &= ebx; - RCT2_GLOBAL(0xEE7870,uint32) = edi; - ebp+=2; - rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI,rct_drawpixelinfo); - - RCT2_GLOBAL(0xEE7874,uint32) = dpi->pitch + dpi->width; - ebx = (dpi->pitch + dpi->width)*top + left; - ecx = esi; - edi = RCT2_GLOBAL(0x9AC00C,uint32); - edi <<= 2; - - //esi = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_DPI,uint32); - edi += 0xEDF850; - - for (; height != 0; height--){ - //0x6840A4 - int al = *((uint8*)(ecx * 2 + ebp)); - if (al == 0xFF) continue; - if (RCT2_GLOBAL(0x9AC00C, uint32) > 0x1F38) continue; - //push ebx - //push ecx - int _ebx = ebx; - int _ecx = ecx; - eax -= RCT2_GLOBAL(0xEE7870, uint32); - edx = width; - eax &= RCT2_GLOBAL(0xEE7868, uint32); - edx += ebx; - ebx += eax; - if (ebx >= edx)continue; - int ah = *((uint8*)(ecx * 2 + ebp + 1)); - ecx = RCT2_GLOBAL(0xEE7864, uint32); - - //inner loop - while (ebx < edx){ - al = ah; - int old_al = al; - al = dpi->bits[ebx]; - dpi->bits[ebx] = old_al; - RCT2_GLOBAL(0x9AC00C, uint32)++; - ebx <<= 8; - ebx |= al; - *(uint32*)edi = ebx; - ebx >>= 8; - edi += 4; - ebx += ecx; - } - //pop ecx - //pop ebx - ecx = _ecx; - ebx = _ebx; - ecx++; - ebx += dpi->pitch + dpi->width; - ecx &= RCT2_GLOBAL(0xEE786C, uint32); - } -} /** * @@ -505,6 +489,7 @@ void update_rain_animation() // Get rain draw function and draw rain uint32 draw_rain_func = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RAIN_LEVEL, uint8); + draw_rain_func = 2; if (draw_rain_func > 0 && !(RCT2_GLOBAL(0x009DEA6F, uint8) & 1)) draw_rain_animation(draw_rain_func); } From 13b51fe4755bd948499e0a647b50342f22c68a2d Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 8 Aug 2014 08:46:18 +0100 Subject: [PATCH 5/6] More cleanup of gfx_rain. --- src/game.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/game.c b/src/game.c index 38c5631f12..0b6ab19667 100644 --- a/src/game.c +++ b/src/game.c @@ -52,8 +52,6 @@ void game_handle_keyboard_input(); void process_mouse_over(int x, int y); void sub_0x684027(int left, int top, int width, int height, int ebp, uint32 edi, uint32 esi){ - uint32 eax = left, ecx = width, edx = height; - uint32 ebx = top; uint8* pattern = RCT2_ADDRESS(0x9AC010, uint8*)[ebp]; uint8 pattern_x_space = *pattern++; uint8 pattern_y_space = *pattern++; @@ -70,32 +68,29 @@ void sub_0x684027(int left, int top, int width, int height, int ebp, uint32 edi, pixel_store += RCT2_GLOBAL(0x9AC00C, uint32); for (; height != 0; height--){ - int al = pattern[pattern_y_pos * 2]; - if (al != 0xFF){ + uint8 pattern_x = pattern[pattern_y_pos * 2]; + if (pattern_x != 0xFF){ if (RCT2_GLOBAL(0x9AC00C, uint32) <= 0x1F38){ - int _pixel_offset = pixel_offset; + - eax = al - pattern_start_x_offset; - edx = width; - eax %= pattern_x_space; - //eax &= RCT2_GLOBAL(0xEE7868, uint32); - edx += _pixel_offset; - _pixel_offset += eax; - if (_pixel_offset < edx){ - uint8 pattern_pixel = pattern[pattern_y_pos * 2 + 1]; - //inner loop - while (_pixel_offset < edx){ - uint8 current_pixel = dpi->bits[_pixel_offset]; - dpi->bits[_pixel_offset] = pattern_pixel; - RCT2_GLOBAL(0x9AC00C, uint32)++; - *pixel_store++ = (_pixel_offset << 8) | current_pixel; //Store colour and position - _pixel_offset += pattern_x_space; - } + int final_pixel_offset = width + pixel_offset; + + int x_pixel_offset = pixel_offset; + x_pixel_offset += (pattern_x - pattern_start_x_offset)%pattern_x_space; + + uint8 pattern_pixel = pattern[pattern_y_pos * 2 + 1]; + for( ; x_pixel_offset < final_pixel_offset; x_pixel_offset += pattern_x_space){ + uint8 current_pixel = dpi->bits[_pixel_offset]; + dpi->bits[_pixel_offset] = pattern_pixel; + RCT2_GLOBAL(0x9AC00C, uint32)++; + *pixel_store++ = (x_pixel_offset << 8) | current_pixel; //Store colour and position } } } - pattern_y_pos++; + pixel_offset += dpi->pitch + dpi->width; + + pattern_y_pos++; pattern_y_pos %= pattern_y_space; } } From 57f17f62e54b168a24629be56c91835e30a06e6a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 8 Aug 2014 17:19:08 +0100 Subject: [PATCH 6/6] Moved function to gfx.c added new addresses --- src/addresses.h | 9 +++++++ src/game.c | 63 +++++-------------------------------------------- src/gfx.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/gfx.h | 2 ++ 4 files changed, 74 insertions(+), 57 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 56912ac3e9..b2e7533375 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -84,6 +84,11 @@ #define RCT2_ADDRESS_DIRTY_BLOCK_COLUMNS 0x009ABDE8 #define RCT2_ADDRESS_DIRTY_BLOCK_ROWS 0x009ABDEC +//This is the number of pixels that are in the +//rain_pixel_store +#define RCT2_ADDRESS_NO_RAIN_PIXELS 0x009AC00C +#define RCT2_ADDRESS_RAIN_PATTERN 0x009AC010 + #define RCT2_ADDRESS_LIGHTNING_ACTIVE 0x009AC068 #define RCT2_ADDRESS_VIEWPORT_PAINT_BITS_PTR 0x009AC118 @@ -163,6 +168,10 @@ #define RCT2_ADDRESS_PATH_TYPES 0x009ADA14 +//Every pixel changed by rain is stored. +//32bit (pixel_offset 24 bit)(pixel_colour 8 bit) +#define RCT2_ADDRESS_RAIN_PIXEL_STORE 0x00EDF850 + #define RCT2_ADDRESS_MAP_IMAGE_DATA 0x00F1AD68 #define RCT2_ADDRESS_PROVISIONAL_PATH_FLAGS 0x00F3EF92 diff --git a/src/game.c b/src/game.c index 0b6ab19667..101d760904 100644 --- a/src/game.c +++ b/src/game.c @@ -51,50 +51,6 @@ void game_handle_keyboard_input(); void process_mouse_over(int x, int y); -void sub_0x684027(int left, int top, int width, int height, int ebp, uint32 edi, uint32 esi){ - uint8* pattern = RCT2_ADDRESS(0x9AC010, uint8*)[ebp]; - uint8 pattern_x_space = *pattern++; - uint8 pattern_y_space = *pattern++; - - uint8 pattern_start_x_offset = edi % pattern_x_space; - uint8 pattern_start_y_offset = esi % pattern_y_space;; - - rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo); - uint32 pixel_offset = (dpi->pitch + dpi->width)*top + left; - uint8 pattern_y_pos = pattern_start_y_offset; - - //Stores the colours of changed pixels - uint32* pixel_store = RCT2_ADDRESS(0xEDF850, uint32); - pixel_store += RCT2_GLOBAL(0x9AC00C, uint32); - - for (; height != 0; height--){ - uint8 pattern_x = pattern[pattern_y_pos * 2]; - if (pattern_x != 0xFF){ - if (RCT2_GLOBAL(0x9AC00C, uint32) <= 0x1F38){ - - - int final_pixel_offset = width + pixel_offset; - - int x_pixel_offset = pixel_offset; - x_pixel_offset += (pattern_x - pattern_start_x_offset)%pattern_x_space; - - uint8 pattern_pixel = pattern[pattern_y_pos * 2 + 1]; - for( ; x_pixel_offset < final_pixel_offset; x_pixel_offset += pattern_x_space){ - uint8 current_pixel = dpi->bits[_pixel_offset]; - dpi->bits[_pixel_offset] = pattern_pixel; - RCT2_GLOBAL(0x9AC00C, uint32)++; - *pixel_store++ = (x_pixel_offset << 8) | current_pixel; //Store colour and position - } - } - } - - pixel_offset += dpi->pitch + dpi->width; - - pattern_y_pos++; - pattern_y_pos %= pattern_y_space; - } -} - typedef void(*draw_rain_func)(int left, int top, int width, int height); /** @@ -109,8 +65,7 @@ void draw_light_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x18; esi = (RCT2_GLOBAL(0x00F663AC, int) * 4) + 0x0D; @@ -118,8 +73,7 @@ void draw_light_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); } /** @@ -134,8 +88,7 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x10; esi = (RCT2_GLOBAL(0x00F663AC, int) * 6) + 5; @@ -144,8 +97,7 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); edi = -RCT2_GLOBAL(0x00F663AC, int) + 8; esi = (RCT2_GLOBAL(0x00F663AC, int) * 3) + 7; @@ -154,8 +106,7 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); edi = -RCT2_GLOBAL(0x00F663AC, int) + 0x18; esi = (RCT2_GLOBAL(0x00F663AC, int) * 4) + 0x0D; @@ -164,8 +115,7 @@ void draw_heavy_rain(int left, int top, int width, int height){ edi += left; esi += top; - sub_0x684027(left, top, width, height, 0, edi, esi); - //RCT2_CALLPROC_X(0x00684027, left, top, width, height, esi, edi, 0); + gfx_draw_rain(left, top, width, height, edi, esi); } /** @@ -484,7 +434,6 @@ void update_rain_animation() // Get rain draw function and draw rain uint32 draw_rain_func = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RAIN_LEVEL, uint8); - draw_rain_func = 2; if (draw_rain_func > 0 && !(RCT2_GLOBAL(0x009DEA6F, uint8) & 1)) draw_rain_animation(draw_rain_func); } diff --git a/src/gfx.c b/src/gfx.c index 272de4cdb0..bfdea7ccbd 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -2322,4 +2322,61 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt rct2_free(newDrawPixelInfo); return NULL; +} + +/*** +* +* rct2: 0x00684027 +* +* ebp used to be a parameter but it is always zero +* left : eax +* top : ebx +* width : ecx +* height : edx +* x_start: edi +* y_start: esi +*/ +void gfx_draw_rain(int left, int top, int width, int height, uint32 x_start, uint32 y_start){ + uint8* pattern = RCT2_GLOBAL(RCT2_ADDRESS_RAIN_PATTERN, uint8*); + uint8 pattern_x_space = *pattern++; + uint8 pattern_y_space = *pattern++; + + uint8 pattern_start_x_offset = x_start % pattern_x_space; + uint8 pattern_start_y_offset = y_start % pattern_y_space;; + + rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo); + uint32 pixel_offset = (dpi->pitch + dpi->width)*top + left; + uint8 pattern_y_pos = pattern_start_y_offset; + + //Stores the colours of changed pixels + uint32* pixel_store = RCT2_ADDRESS(RCT2_ADDRESS_RAIN_PIXEL_STORE, uint32); + pixel_store += RCT2_GLOBAL(RCT2_ADDRESS_NO_RAIN_PIXELS, uint32); + + for (; height != 0; height--){ + uint8 pattern_x = pattern[pattern_y_pos * 2]; + if (pattern_x != 0xFF){ + if (RCT2_GLOBAL(0x9AC00C, uint32) <= 0x1F38){ + + int final_pixel_offset = width + pixel_offset; + + int x_pixel_offset = pixel_offset; + x_pixel_offset += ((uint8)(pattern_x - pattern_start_x_offset)) % pattern_x_space; + + uint8 pattern_pixel = pattern[pattern_y_pos * 2 + 1]; + for (; x_pixel_offset < final_pixel_offset; x_pixel_offset += pattern_x_space){ + uint8 current_pixel = dpi->bits[x_pixel_offset]; + dpi->bits[x_pixel_offset] = pattern_pixel; + RCT2_GLOBAL(RCT2_ADDRESS_NO_RAIN_PIXELS, uint32)++; + + //Store colour and position + *pixel_store++ = (x_pixel_offset << 8) | current_pixel; + } + } + } + + pixel_offset += dpi->pitch + dpi->width; + + pattern_y_pos++; + pattern_y_pos %= pattern_y_space; + } } \ No newline at end of file diff --git a/src/gfx.h b/src/gfx.h index f20d37e428..f57cc558f6 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -92,6 +92,8 @@ void gfx_draw_all_dirty_blocks(); void gfx_redraw_screen_rect(short left, short top, short right, short bottom); void gfx_invalidate_screen(); +void gfx_draw_rain(int left, int top, int width, int height, uint32 x_start, uint32 y_start); + rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int width, int top, int height); #endif