diff --git a/build.sh b/build.sh index 6bdf0829f1..d1dc442fa3 100755 --- a/build.sh +++ b/build.sh @@ -13,7 +13,7 @@ if [[ ! -d build ]]; then fi # keep in sync with version in install.sh -sha256sum=0a7b5ea46e9cb4b19000b69690eae0b75929752f7db192c78bd7ffb61d696835 +sha256sum=69ff98c9544838fb16384bc78af9dc1c452b9d01d919e43f5fec686d02c9bdd8 libVFile="./libversion" libdir="./lib" currentversion=0 diff --git a/data/language/chinese_traditional.txt b/data/language/chinese_traditional.txt index 6364397fb5..4e2ef366cd 100644 --- a/data/language/chinese_traditional.txt +++ b/data/language/chinese_traditional.txt @@ -3864,8 +3864,8 @@ STR_5521 :{SMALLFONT}{BLACK}明紫色 STR_5522 :{SMALLFONT}{BLACK}暗藍色 STR_5523 :{SMALLFONT}{BLACK}淺藍色 STR_5524 :{SMALLFONT}{BLACK}冰藍色 -STR_5525 :{SMALLFONT}{BLACK}鴨綠色 -STR_5526 :{SMALLFONT}{BLACK}藍綠色 +STR_5525 :{SMALLFONT}{BLACK}深水配色 +STR_5526 :{SMALLFONT}{BLACK}淺水配色 STR_5527 :{SMALLFONT}{BLACK}深綠色 STR_5528 :{SMALLFONT}{BLACK}暗綠色 STR_5529 :{SMALLFONT}{BLACK}苔蘚綠色 diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 5cacdaf8bb..fc5773a30c 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -2723,8 +2723,8 @@ STR_2714 :- STR_2715 :. STR_2716 :/ STR_2717 :' -STR_2718 :(up) -STR_2719 :(new file) +STR_2718 :Up +STR_2719 :New file STR_2720 :{UINT16}sec STR_2721 :{UINT16}secs STR_2722 :{UINT16}min:{UINT16}sec diff --git a/data/language/english_us.txt b/data/language/english_us.txt index a173125c84..3f9cdf3d31 100644 --- a/data/language/english_us.txt +++ b/data/language/english_us.txt @@ -3907,7 +3907,7 @@ STR_5563 :This feature is currently unstable, take extra caution. STR_5564 :Insert Corrupt Element STR_5565 :{SMALLFONT}{BLACK}Inserts a corrupt map element at top of tile. This will hide any element above the corrupt element. STR_5566 :Password: -STR_5567 :Advertize +STR_5567 :Advertise STR_5568 :Password Required STR_5569 :This server requires a password STR_5570 :Fetch Servers diff --git a/install.sh b/install.sh index fe2a71da27..eb04f41dd3 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ SDL2_PV=2.0.3 SDL2_TTF_PV=2.0.12 cachedir=.cache -liburl=https://openrct.net/launcher/libs/orctlibs.zip +liburl=https://openrct2.website/files/orctlibs.zip mkdir -p $cachedir echo $(uname) diff --git a/pre-build.ps1 b/pre-build.ps1 index 539e65755f..3e350d0c26 100644 --- a/pre-build.ps1 +++ b/pre-build.ps1 @@ -1,10 +1,10 @@ #init -$libversion = 3 +$libversion = 4 $path = Split-Path $Script:MyInvocation.MyCommand.Path $zip = $path+'\orctlibs.zip' $libs = $path+'\lib' $libsVFile = $path+'\libversion' -$liburl = 'https://openrct.net/launcher/libs/orctlibs_vs.zip' +$liburl = 'https://openrct2.website/files/orctlibs-vs.zip' $libsTest = Test-Path $libs #libs version test diff --git a/readme.md b/readme.md index 99733e8b68..7e9b97ec3b 100644 --- a/readme.md +++ b/readme.md @@ -5,8 +5,12 @@ An open source clone of RollerCoaster Tycoon 2 built by decompiling the original - [Screenshot 3, high resolution](http://i.imgur.com/yFzNyVu.jpg) - [Screenshot 4, resizable window](http://imgur.com/a/3GDuT) -[![Travis CI](https://travis-ci.org/OpenRCT2/OpenRCT2.svg)](https://travis-ci.org/OpenRCT2/OpenRCT2) [![AppVeyor](https://ci.appveyor.com/api/projects/status/fib6re830brysuo2?svg=true)](https://ci.appveyor.com/project/IntelOrca/openrct2) +Linux Build: +[![Travis CI](https://travis-ci.org/OpenRCT2/OpenRCT2.svg)](https://travis-ci.org/OpenRCT2/OpenRCT2) +Windows Build: +[![AppVeyor](https://ci.appveyor.com/api/projects/status/fib6re830brysuo2?svg=true)](https://ci.appveyor.com/project/IntelOrca/openrct2) +Come talk with us if you have any questions: [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/OpenRCT2/OpenRCT2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) # Contents diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index d6e8ac2c21..0e8f84a83a 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -260,10 +260,12 @@ bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **ou } uint8 *buffer = malloc((height * 2) + (width * height * 16)); + memset(buffer, 0, (height * 2) + (width * height * 16)); uint16 *yOffsets = (uint16*)buffer; // A larger range is needed for proper dithering sint16 *src = malloc(height * width * 4 * 2); + sint16 *src_orig = src; for (uint32 x = 0; x < height * width * 4; x++){ src[x] = (sint16) pixels[x]; } @@ -375,7 +377,7 @@ bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **ou } } free(pixels); - free(src); + free(src_orig); int bufferLength = (int)(dst - buffer); buffer = realloc(buffer, bufferLength); diff --git a/src/config.c b/src/config.c index 916466eb60..763a0d163c 100644 --- a/src/config.c +++ b/src/config.c @@ -1494,7 +1494,7 @@ static void title_sequence_open(const char *path, const char *customName) token = &parts[0 * 128]; part1 = &parts[1 * 128]; part2 = &parts[2 * 128]; - title_command command; + title_command command = { 0 }; command.command = 0xFF; if (token[0] != 0) { diff --git a/src/peep/peep.c b/src/peep/peep.c index d1d06e3ec7..e714c8de93 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -4147,7 +4147,7 @@ static void peep_update_using_bin(rct_peep* peep){ uint32 empty_containers = peep_empty_container_standard_flag(peep); for (uint8 cur_container = 0; cur_container < 32; cur_container++){ - if (!(empty_containers & (1 << cur_container))) continue; + if (!(empty_containers & (1u << cur_container))) continue; if (rubbish_in_bin != 0){ // OpenRCT2 modification: This previously used @@ -4177,7 +4177,7 @@ static void peep_update_using_bin(rct_peep* peep){ empty_containers = peep_empty_container_extra_flag(peep); for (uint8 cur_container = 0; cur_container < 32; cur_container++){ - if (!(empty_containers & (1 << cur_container))) continue; + if (!(empty_containers & (1u << cur_container))) continue; if (rubbish_in_bin != 0){ // OpenRCT2 modification: This previously used @@ -5741,9 +5741,9 @@ int peep_is_mechanic(rct_peep *peep) bool peep_has_item(rct_peep *peep, int peepItem) { if (peepItem < 32) { - return peep->item_standard_flags & (1 << peepItem); + return peep->item_standard_flags & (1u << peepItem); } else { - return peep->item_extra_flags & (1 << peepItem); + return peep->item_extra_flags & (1u << (peepItem - 32)); } } @@ -8608,7 +8608,7 @@ static void peep_pick_ride_to_go_on(rct_peep *peep) int i; FOR_ALL_RIDES(i, ride) { if (!peep_has_ridden(peep, i)) { - RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1 << (i & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1u << (i & 0x1F)); } } } else { @@ -8623,7 +8623,7 @@ static void peep_pick_ride_to_go_on(rct_peep *peep) if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK) continue; int rideIndex = mapElement->properties.track.ride_index; - RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1 << (rideIndex & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1u << (rideIndex & 0x1F)); } while (!map_element_is_last_for_tile(mapElement++)); } } @@ -8636,7 +8636,7 @@ static void peep_pick_ride_to_go_on(rct_peep *peep) if (ride->excitement == (ride_rating)0xFFFF) continue; if (ride->highest_drop_height <= 66 && ride->excitement < RIDE_RATING(8,00)) continue; - RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1 << (i & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1u << (i & 0x1F)); } } @@ -8645,7 +8645,7 @@ static void peep_pick_ride_to_go_on(rct_peep *peep) uint8 *nextPotentialRide = potentialRides; int numPotentialRides = 0; for (int i = 0; i < MAX_RIDES; i++) { - if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1 << (i & 0x1F)))) + if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1u << (i & 0x1F)))) continue; rct_ride *ride = GET_RIDE(i); @@ -8724,7 +8724,7 @@ static void peep_head_for_nearest_ride_type(rct_peep *peep, int rideType) int i; FOR_ALL_RIDES(i, ride) { if (ride->type == rideType) { - RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1 << (i & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1u << (i & 0x1F)); } } } else { @@ -8741,7 +8741,7 @@ static void peep_head_for_nearest_ride_type(rct_peep *peep, int rideType) int rideIndex = mapElement->properties.track.ride_index; ride = GET_RIDE(rideIndex); if (ride->type == rideType) { - RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1 << (rideIndex & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1u << (rideIndex & 0x1F)); } } while (!map_element_is_last_for_tile(mapElement++)); } @@ -8754,7 +8754,7 @@ static void peep_head_for_nearest_ride_type(rct_peep *peep, int rideType) uint8 *nextPotentialRide = potentialRides; int numPotentialRides = 0; for (int i = 0; i < MAX_RIDES; i++) { - if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1 << (i & 0x1F)))) + if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1u << (i & 0x1F)))) continue; rct_ride *ride = GET_RIDE(i); @@ -8836,7 +8836,7 @@ static void peep_head_for_nearest_ride_with_flags(rct_peep *peep, int rideTypeFl int i; FOR_ALL_RIDES(i, ride) { if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & rideTypeFlags) { - RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1 << (i & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] |= (1u << (i & 0x1F)); } } } else { @@ -8853,7 +8853,7 @@ static void peep_head_for_nearest_ride_with_flags(rct_peep *peep, int rideTypeFl int rideIndex = mapElement->properties.track.ride_index; ride = GET_RIDE(rideIndex); if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & rideTypeFlags) { - RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1 << (rideIndex & 0x1F)); + RCT2_ADDRESS(0x00F1AD98, uint32)[rideIndex >> 5] |= (1u << (rideIndex & 0x1F)); } } while (!map_element_is_last_for_tile(mapElement++)); } @@ -8866,7 +8866,7 @@ static void peep_head_for_nearest_ride_with_flags(rct_peep *peep, int rideTypeFl uint8 *nextPotentialRide = potentialRides; int numPotentialRides = 0; for (int i = 0; i < MAX_RIDES; i++) { - if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1 << (i & 0x1F)))) + if (!(RCT2_ADDRESS(0x00F1AD98, uint32)[i >> 5] & (1u << (i & 0x1F)))) continue; rct_ride *ride = GET_RIDE(i); diff --git a/src/peep/staff.c b/src/peep/staff.c index 3d44d0cb53..b187d632b3 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -389,6 +389,7 @@ uint16 hire_new_staff_member(uint8 staffType) RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = STR_CANT_HIRE_NEW_STAFF; int eax, ebx, ecx, edx, esi, edi, ebp; + ecx = edx = esi = edi = ebp = 0; eax = 0x8000; ebx = staffType << 8 | GAME_COMMAND_FLAG_APPLY; diff --git a/src/platform/linux.c b/src/platform/linux.c index 5117966ece..68291e8d3a 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -209,10 +209,10 @@ int platform_enumerate_files_begin(const utf8 *pattern) enumerate_file_info *enumFileInfo; wchar_t *wpattern = utf8_to_widechar(pattern); int length = min(utf8_length(pattern), MAX_PATH); - char *npattern = malloc(length); + char *npattern = malloc(length+1); int converted; converted = wcstombs(npattern, wpattern, length); - npattern[length - 1] = '\0'; + npattern[length] = '\0'; if (converted == MAX_PATH) { log_warning("truncated string %s", npattern); } @@ -271,7 +271,7 @@ int platform_enumerate_files_begin(const utf8 *pattern) for (int i = 0; i < countof(_enumerateFileInfoList); i++) { enumFileInfo = &_enumerateFileInfoList[i]; if (!enumFileInfo->active) { - safe_strncpy(enumFileInfo->pattern, npattern, length); + safe_strncpy(enumFileInfo->pattern, npattern, sizeof(enumFileInfo->pattern)); cnt = scandir(dir_name, &enumFileInfo->fileListTemp, winfilter, alphasort); if (cnt < 0) { @@ -395,10 +395,10 @@ int platform_enumerate_directories_begin(const utf8 *directory) enumerate_file_info *enumFileInfo; wchar_t *wpattern = utf8_to_widechar(directory); int length = min(utf8_length(directory), MAX_PATH); - char *npattern = malloc(length); + char *npattern = malloc(length+1); int converted; converted = wcstombs(npattern, wpattern, length); - npattern[length - 1] = '\0'; + npattern[length] = '\0'; if (converted == MAX_PATH) { log_warning("truncated string %s", npattern); } @@ -477,7 +477,7 @@ bool platform_enumerate_directories_next(int handle, utf8 *path) log_error("failed to stat file '%s'! errno = %i", fileName, errno); return false; } - // so very, very wrong… + // so very, very wrong safe_strncpy(path, basename(fileName), MAX_PATH); strncat(path, "/", MAX_PATH); path[MAX_PATH - 1] = '\0'; diff --git a/src/ride/ride.c b/src/ride/ride.c index bb7261ad5b..573251d0d1 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -850,6 +850,7 @@ int ride_create_ride(ride_list_item listItem) ebx = GAME_COMMAND_FLAG_APPLY; edi = 0; esi = 0; + ebp = 0; RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = 0x3DC; @@ -1194,7 +1195,7 @@ int sub_6C683D(int* x, int* y, int* z, int direction, int type, uint16 extra_par mapElement->properties.track.colour &= 0x0F; mapElement->properties.track.colour |= (extra_params & 0xFF) << 4; } - + if (flags & (1 << 3)) { track_element_set_cable_lift(mapElement); } @@ -5562,7 +5563,7 @@ void game_command_callback_ride_remove_track_piece(int eax, int ebx, int ecx, in z = gRideRemoveTrackPieceCallbackZ; direction = gRideRemoveTrackPieceCallbackDirection; type = gRideRemoveTrackPieceCallbackType; - + window_ride_construction_mouseup_demolish_next_piece(x, y, z, direction, type); } @@ -6412,9 +6413,9 @@ static void ride_update_vehicle_colours(int rideIndex) { rct_ride *ride; rct_vehicle *vehicle; - rct_vehicle_colour colours; + rct_vehicle_colour colours = { 0 }; uint16 spriteIndex; - uint8 coloursExtended; + uint8 coloursExtended = 0; ride = GET_RIDE(rideIndex); if (ride->type == RIDE_TYPE_SPACE_RINGS || ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_16)) { diff --git a/src/scenario.c b/src/scenario.c index 4d94b7be70..6975421c80 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -497,7 +497,7 @@ void scenario_success_submit_name(const char *name) **/ void scenario_entrance_fee_too_high_check() { - uint16 x, y; + uint16 x = 0, y = 0; uint16 totalRideValue = RCT2_GLOBAL(RCT2_TOTAL_RIDE_VALUE, uint16); uint16 park_entrance_fee = RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, uint16); int max_fee = totalRideValue + (totalRideValue / 2); diff --git a/src/util/util.c b/src/util/util.c index a1c93d7ebe..bfccdfa706 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -146,7 +146,7 @@ int bitscanforward(int source) return success != 0 ? i : -1; #else for (i = 0; i < 32; i++) - if (source & (1 << i)) + if (source & (1u << i)) return i; return -1; @@ -157,7 +157,7 @@ int bitcount(int source) { int result = 0; for (int i = 0; i < 32; i++) { - if (source & (1 << i)) { + if (source & (1u << i)) { result++; } } diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index ca10ca179d..d9d9b5a3f4 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -43,6 +43,8 @@ enum { WIDX_BACKGROUND, WIDX_TITLE, WIDX_CLOSE, + WIDX_UP, + WIDX_NEW, WIDX_SORT_NAME, WIDX_SORT_DATE, WIDX_SCROLL, @@ -53,10 +55,12 @@ enum { static rct_widget window_loadsave_widgets[] = { { WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, { WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_NONE, STR_WINDOW_TITLE_TIP }, - { WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, - { WWT_CLOSEBOX, 0, 4, (WW - 5) / 2, 36, 47, STR_NONE, STR_NONE }, - { WWT_CLOSEBOX, 0, (WW - 5) / 2 + 1, WW - 5 - 1, 36, 47, STR_NONE, STR_NONE }, - { WWT_SCROLL, 0, 4, WW - 5, 47, WH - 40, 2, STR_NONE }, + { WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, //Window close button + { WWT_CLOSEBOX, 0, 4, 104, 36, 47, 2718, STR_NONE}, // Up + { WWT_CLOSEBOX, 0, 105, 205, 36, 47, 2719, STR_NONE}, // New + { WWT_CLOSEBOX, 0, 4, (WW - 5) / 2, 50, 61, STR_NONE, STR_NONE }, // Name + { WWT_CLOSEBOX, 0, (WW - 5) / 2 + 1, WW - 5 - 1, 50, 61, STR_NONE, STR_NONE }, // Date + { WWT_SCROLL, 0, 4, WW - 5, 61, WH - 40, 2, STR_NONE }, // File list { WWT_CLOSEBOX, 0, 4, 200, WH - 36, WH - 18, 2707, STR_NONE }, // Use native browser { WIDGETS_END } }; @@ -111,8 +115,6 @@ static rct_window_event_list window_loadsave_events = { #pragma endregion enum { - TYPE_UP, - TYPE_NEW_FILE, TYPE_DIRECTORY, TYPE_FILE, }; @@ -130,12 +132,13 @@ int _listItemsCount = 0; loadsave_list_item *_listItems = NULL; char _directory[MAX_PATH]; char _shortenedDirectory[MAX_PATH]; +static char _parentDirectory[MAX_PATH]; char _extension[32]; char _defaultName[MAX_PATH]; int _loadsaveType; int _type; -static void window_loadsave_populate_list(int includeNewItem, bool browsable, const char *directory, const char *extension); +static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension); static void window_loadsave_select(rct_window *w, const char *path); static void window_loadsave_sort_list(int index, int endIndex); @@ -164,7 +167,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) if (w == NULL) { w = window_create_centred(WW, WH, &window_loadsave_events, WC_LOADSAVE, WF_STICK_TO_FRONT); w->widgets = window_loadsave_widgets; - w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_SORT_NAME) | (1 << WIDX_SORT_DATE) | (1 << WIDX_BROWSE); + w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_UP) | (1 << WIDX_NEW) | (1 << WIDX_SORT_NAME) | (1 << WIDX_SORT_DATE) | (1 << WIDX_BROWSE); w->colours[0] = 7; w->colours[1] = 7; w->colours[2] = 7; @@ -205,7 +208,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) return NULL; } - window_loadsave_populate_list(includeNewItem, true, path, ".sv6"); + window_loadsave_populate_list(w, includeNewItem, path, ".sv6"); break; case LOADSAVETYPE_LANDSCAPE: platform_get_user_directory(path, "landscape"); @@ -215,7 +218,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) return NULL; } - window_loadsave_populate_list(includeNewItem, true, path, ".sc6"); + window_loadsave_populate_list(w, includeNewItem, path, ".sc6"); break; case LOADSAVETYPE_SCENARIO: /* @@ -234,7 +237,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) if (ch != NULL) *ch = 0; - window_loadsave_populate_list(includeNewItem, true, path, ".sc6"); + window_loadsave_populate_list(w, includeNewItem, path, ".sc6"); break; case LOADSAVETYPE_TRACK: /* @@ -253,7 +256,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) if (ch != NULL) *ch = 0; - window_loadsave_populate_list(includeNewItem, true, path, ".td?"); + window_loadsave_populate_list(w, includeNewItem, path, ".td?"); break; } w->no_list_items = _listItemsCount; @@ -280,6 +283,27 @@ static void window_loadsave_mouseup(rct_window *w, int widgetIndex) case WIDX_CLOSE: window_close(w); break; + case WIDX_UP: + { + char directory[MAX_PATH]; + int includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE; + + safe_strncpy(directory, _parentDirectory, sizeof(directory)); + window_loadsave_populate_list(w, includeNewItem, directory, _extension); + window_init_scroll_widgets(w); + w->no_list_items = _listItemsCount; + break; + } + case WIDX_NEW: + { + rct_string_id templateStringId = 3165; + char *templateString; + + templateString = (char *)language_get_string(templateStringId); + strcpy(templateString, _defaultName); + window_text_input_open(w, WIDX_NEW, STR_NONE, 2710, templateStringId, 0, 64); + break; + } case WIDX_BROWSE: safe_strncpy(filename, _directory, MAX_PATH); if (_type & LOADSAVETYPE_SAVE) @@ -363,40 +387,28 @@ static void window_loadsave_scrollmousedown(rct_window *w, int scrollIndex, int selectedItem = y / 10; if (selectedItem >= w->no_list_items) return; + if (_listItems[selectedItem].type == TYPE_DIRECTORY){ + // The selected item is a folder + int includeNewItem; - if (_listItems[selectedItem].type == TYPE_NEW_FILE) { - rct_string_id templateStringId = 3165; - char *templateString; + w->no_list_items = 0; + w->selected_list_item = -1; + includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE; - templateString = (char*)language_get_string(templateStringId); - strcpy(templateString, _defaultName); + char directory[MAX_PATH]; + safe_strncpy(directory, _listItems[selectedItem].path, sizeof(directory)); - window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64); + window_loadsave_populate_list(w, includeNewItem, directory, _extension); + window_init_scroll_widgets(w); + + w->no_list_items = _listItemsCount; } else { - if (_listItems[selectedItem].type == TYPE_DIRECTORY || _listItems[selectedItem].type == TYPE_UP){ - // The selected item is a folder - int includeNewItem; - - w->no_list_items = 0; - w->selected_list_item = -1; - - includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE; - - char directory[MAX_PATH]; - safe_strncpy(directory, _listItems[selectedItem].path, sizeof(directory)); - - window_loadsave_populate_list(includeNewItem, true, directory, _extension); - window_init_scroll_widgets(w); - - w->no_list_items = _listItemsCount; - } else { - // TYPE_FILE - // Load or overwrite - if ((_loadsaveType & 0x01) == LOADSAVETYPE_SAVE) - window_overwrite_prompt_open(_listItems[selectedItem].name, _listItems[selectedItem].path); - else - window_loadsave_select(w, _listItems[selectedItem].path); - } + // TYPE_FILE + // Load or overwrite + if ((_loadsaveType & 0x01) == LOADSAVETYPE_SAVE) + window_overwrite_prompt_open(_listItems[selectedItem].name, _listItems[selectedItem].path); + else + window_loadsave_select(w, _listItems[selectedItem].path); } } @@ -482,18 +494,20 @@ static void window_loadsave_paint(rct_window *w, rct_drawpixelinfo *dpi) // Draw shadow gfx_draw_string(dpi, buffer, 0, w->x + 4, w->y + 20); rct_string_id id = STR_NONE; + // Name button text if (gConfigGeneral.load_save_sort == SORT_NAME_ASCENDING) id = STR_UP; else if (gConfigGeneral.load_save_sort == SORT_NAME_DESCENDING) id = STR_DOWN; - gfx_draw_string_centred_clipped(dpi, STR_NAME, &id, 1, w->x + 4 + (w->width - 8) / 4, w->y + 36, (w->width - 8) / 2); + gfx_draw_string_centred_clipped(dpi, STR_NAME, &id, 1, w->x + 4 + (w->width - 8) / 4, w->y + 50, (w->width - 8) / 2); + // Date button text if (gConfigGeneral.load_save_sort == SORT_DATE_ASCENDING) id = STR_UP; else if (gConfigGeneral.load_save_sort == SORT_DATE_DESCENDING) id = STR_DOWN; else id = STR_NONE; - gfx_draw_string_centred_clipped(dpi, STR_DATE, &id, 1, w->x + 4 + (w->width - 8) * 3 / 4, w->y + 36, (w->width - 8) / 2); + gfx_draw_string_centred_clipped(dpi, STR_DATE, &id, 1, w->x + 4 + (w->width - 8) * 3 / 4, w->y + 50, (w->width - 8) / 2); } static void shorten_path(char* path, char* buffer, int available_width){ @@ -599,14 +613,14 @@ static void window_loadsave_sort_list(int index, int endIndex) qsort(_listItems + index, count, sizeof(loadsave_list_item), list_item_sort); } -static void window_loadsave_populate_list(int includeNewItem, bool browsable, const char *directory, const char *extension) +static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension) { - int i, listItemCapacity, fileEnumHandle; - file_info fileInfo; + int i; + int sortStartIndex = 0; + int listItemCapacity = 8; loadsave_list_item *listItem; - const char *src; - char *dst, *last_dot_in_filename, filter[MAX_PATH], subDir[MAX_PATH]; - + char filter[MAX_PATH]; + safe_strncpy(_directory, directory, sizeof(_directory)); if (_extension != extension) { safe_strncpy(_extension, extension, sizeof(_extension)); @@ -620,58 +634,55 @@ static void window_loadsave_populate_list(int includeNewItem, bool browsable, co if (_listItems != NULL) free(_listItems); - - listItemCapacity = 8; _listItems = (loadsave_list_item*)malloc(listItemCapacity * sizeof(loadsave_list_item)); _listItemsCount = 0; + + window_loadsave_widgets[WIDX_NEW].type = includeNewItem?WWT_CLOSEBOX:WWT_EMPTY; // Hide/Show "new" button + if(directory[0]=='\0' && platform_get_drives()!=0) // List Windows drives + { + w->disabled_widgets |= (1<= 0; index--) { - if (directory[index] == platform_get_path_separator()) { - if (lastSlash != directoryLength){ - // The last slash has been changed before, we're now one up - lastSlash = index; - topLevel = 0; - break; - } else { - // The last slash, after the whole path - lastSlash = index; - } + if (platform_get_drives() & (1 << (x))){ + listItem = &_listItems[_listItemsCount]; + memset(listItem->path, '\0', MAX_PATH); + listItem->path[0] = 'A' + x; + listItem->path[1] = ':'; + listItem->path[2] = platform_get_path_separator(); + strcpy(listItem->name, listItem->path); + listItem->type = TYPE_DIRECTORY; + _listItemsCount++; } } - if (!topLevel){ - listItem = &_listItems[_listItemsCount]; - safe_strncpy(listItem->name, language_get_string(2718), sizeof(listItem->name)); - memset(listItem->path, '\0', sizeof(listItem->path)); - strncpy(listItem->path, directory, lastSlash + 1); - listItem->type = TYPE_UP; - _listItemsCount++; - } else if (platform_get_drives() != 0 && directory[0] != '\0'){ - includeNewItem = false; - listItem = &_listItems[_listItemsCount]; - safe_strncpy(listItem->name, language_get_string(2718), sizeof(listItem->name)); - memset(listItem->path, '\0', sizeof(listItem->path)); - listItem->type = TYPE_UP; - _listItemsCount++; + } + else + { + //Get parent directory + int directoryLength = strlen(directory); + char separator = platform_get_path_separator(); + for(i = directoryLength-2; i>=0; i--) + { + if(directory[i]==separator) + break; } - } - - if (includeNewItem) { - listItem = &_listItems[_listItemsCount]; - safe_strncpy(listItem->name, language_get_string(2719), sizeof(listItem->name)); - listItem->path[0] = '\0'; - listItem->type = TYPE_NEW_FILE; - _listItemsCount++; - } - - int sortStartIndex = _listItemsCount; - - if (directory[0] != '\0'){ + safe_strncpy(_parentDirectory, directory, sizeof(_parentDirectory)); + _parentDirectory[i+1] = '\0'; + if(_parentDirectory[0]=='\0' && platform_get_drives()==0) + w->disabled_widgets |= (1<disabled_widgets &= ~(1<disabled_widgets &= ~(1<path, '\0', MAX_PATH); - listItem->path[0] = 'A' + x; - listItem->path[1] = ':'; - listItem->path[2] = platform_get_path_separator(); - strcpy(listItem->name, listItem->path); - listItem->type = TYPE_DIRECTORY; - _listItemsCount++; - } - } } - - window_loadsave_sort_list(sortStartIndex, _listItemsCount - 1); } static void window_loadsave_invoke_callback(int result) diff --git a/src/windows/map.c b/src/windows/map.c index 163604d879..7c46d62645 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -1597,7 +1597,7 @@ static uint16 map_window_get_pixel_colour_ride(int x, int y) static void map_window_set_pixels(rct_window *w) { - uint16 colour, *destination; + uint16 colour = 0, *destination; int x, y, dx, dy; destination = (uint16*)((RCT2_GLOBAL(0x00F1AD6C, uint32) * 511) + RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, uint32) + 255); diff --git a/src/windows/park.c b/src/windows/park.c index 6b32b71bed..91be02ae90 100644 --- a/src/windows/park.c +++ b/src/windows/park.c @@ -1053,6 +1053,7 @@ static void window_park_entrance_paint(rct_window *w, rct_drawpixelinfo *dpi) static void window_park_init_viewport(rct_window *w) { int i, x, y, z, r, xy, zr, viewportFlags; + x = y = z = r = xy = zr = 0; rct_viewport *viewport; rct_widget *viewportWidget; diff --git a/src/windows/ride.c b/src/windows/ride.c index b04e0f2cb7..b6f44dde0b 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -5341,6 +5341,9 @@ static void window_ride_graphs_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi top = measurement->lateral[x] + 52; bottom = measurement->lateral[x + 1] + 52; break; + default: + log_error("Wrong graph type %d", listType); + top = bottom = 0; } top = widget->bottom - widget->top - top - 13; diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index 02de05c631..b3dae4b8de 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -2273,7 +2273,7 @@ static void sub_6CBCE2( offsetX = -trackBlock->y; offsetY = trackBlock->x; bl = rol8(bl, 3); - bh |= bl; + bh = bl; bh = ror8(bh, 4); bl &= 0x88; bh &= 0x77; diff --git a/src/windows/scenery.c b/src/windows/scenery.c index f9f99c7c73..fd42a10f44 100644 --- a/src/windows/scenery.c +++ b/src/windows/scenery.c @@ -188,7 +188,7 @@ void window_scenery_update_scroll(rct_window *w); * The same code repeated five times for every scenery entry type */ void init_scenery_entry(rct_scenery_entry *sceneryEntry, int index, uint8 sceneryTabId) { - if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1 << (index & 0x1F))) { + if (RCT2_ADDRESS(0x01357BD0, sint32)[index >> 5] & (1u << (index & 0x1F))) { if (sceneryTabId != 0xFF) { for (int i = 0; i < SCENERY_ENTRIES_BY_TAB; i++) { if (window_scenery_tab_entries[sceneryTabId][i] == -1) @@ -246,7 +246,7 @@ void init_scenery() for (int i = 0; i < scenerySetEntry->entry_count; i++) { uint16 sceneryEntryId = scenerySetEntry->scenery_entries[i]; uint32 ecx = RCT2_ADDRESS(0x01357BD0, uint32)[sceneryEntryId >> 5]; - uint32 edx = 1 << (sceneryEntryId & 0x1F); + uint32 edx = 1u << (sceneryEntryId & 0x1F); if (ecx & edx) { window_scenery_tab_entries[scenerySetIndex][sceneryTabEntryCount] = sceneryEntryId; window_scenery_tab_entries[scenerySetIndex][++sceneryTabEntryCount] = -1; @@ -1185,4 +1185,4 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol } sceneryTabItemIndex++; } -} \ No newline at end of file +} diff --git a/src/windows/title_editor.c b/src/windows/title_editor.c index eb82afe2a8..41c2974acd 100644 --- a/src/windows/title_editor.c +++ b/src/windows/title_editor.c @@ -943,7 +943,7 @@ void window_title_editor_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int gfx_fill_rect(dpi, x, y, x + SCROLL_WIDTH + 100, y + ROW_HEIGHT - 1, ColourMapA[w->colours[1]].lighter | 0x1000000); } - rct_string_id commandName; + rct_string_id commandName = STR_NONE; switch (command->command) { case TITLE_SCRIPT_LOAD: commandName = 5415; @@ -984,6 +984,8 @@ void window_title_editor_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int case TITLE_SCRIPT_END: commandName = 5426; break; + default: + log_warning("Unknown command %d", command->command); } if ((selected || hover) && !error) { diff --git a/src/windows/track_place.c b/src/windows/track_place.c index c879b4907a..85365c9dc9 100644 --- a/src/windows/track_place.c +++ b/src/windows/track_place.c @@ -352,6 +352,7 @@ static void window_track_place_attempt_placement(int x, int y, int z, int bl, mo int eax, ebx, ecx, edx, esi, edi, ebp; money32 result; + edx = esi = ebp = 0; eax = x; ebx = bl; ecx = y;