diff --git a/src/addresses.h b/src/addresses.h index 9b4ebfa942..6a1d0320fe 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -50,6 +50,7 @@ #define RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER 0x009AAC6E #define RCT2_ADDRESS_CONFIG_MUSIC 0x009AAC72 + #define RCT2_ADDRESS_CONFIG_FLAGS 0x009AAC74 #define RCT2_ADDRESS_CONFIG_SOUND_QUALITY 0x009AAC77 #define RCT2_ADDRESS_CONFIG_METRIC 0x009AAC78 diff --git a/src/config.c b/src/config.c index 916c183270..60d5721d5a 100644 --- a/src/config.c +++ b/src/config.c @@ -99,6 +99,36 @@ void config_load() // Read options ReadFile(hFile, (void*)0x009AAC5C, 2155, &bytesRead, NULL); CloseHandle(hFile); + + + //general configuration + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, sint8) = gGeneral_config.edge_scrolling; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_CURRENCY, sint8) = gGeneral_config.currency_format; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) = gGeneral_config.measurement_format; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_TEMPERATURE, sint8) = gGeneral_config.temperature_format; + + + //sound configuration + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8) = gSound_config.sound_quality; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, sint8) = gSound_config.forced_software_buffering; + + // Line below is temporaraly disabled until all config is in the new format. + //if (RCT2_GLOBAL(0x009AB4C6, sint8) == 1) + // return; + + + RCT2_GLOBAL(0x009AB4C6, sint8) = 1; // no idea on what this does + + RCT2_GLOBAL(0x009AACBD, sint16) = (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) + 2) * 256; + if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS)) + RCT2_GLOBAL(0x009AACBD, sint16) = (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) + 1) * 256; + RCT2_GLOBAL(0x009AA00D, sint8) = 0; + } + + } + + /* TODO: CLEANUP + if (RCT2_GLOBAL(0x009AB4C6, sint8) == 1) return; RCT2_GLOBAL(0x009AB4C6, sint8) = 1; @@ -119,6 +149,8 @@ void config_load() if (RCT2_GLOBAL(RCT2_ADDRESS_MEM_TOTAL_PHYSICAL, uint32) > 0x8000000) RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8) = 2; } + */ + RCT2_GLOBAL(0x009AAC75, sint8) = RCT2_ADDRESS(0x009AF601, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; RCT2_GLOBAL(0x009AAC76, sint8) = RCT2_ADDRESS(0x009AF604, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; @@ -147,15 +179,19 @@ void config_save() // New config format -configuration_t gConfig; +general_configuration_t gGeneral_config; +sound_configuration_t gSound_config; static char *config_show_directory_browser(); static void config_parse_settings(FILE *fp); +static void config_general(char *setting, char *value); +static void config_sound(char *setting, char *value); static int config_get_line(FILE *fp, char *setting, char *value); static int config_parse_setting(FILE *fp, char *setting); static int config_parse_value(FILE *fp, char *value); static int config_parse_section(FILE *fp, char *setting, char *value); static void config_create_default(char *path); +static int config_parse_currency(char* currency); static void config_error(char *msg); /** @@ -231,17 +267,25 @@ static void config_create_default(char *path) { FILE* fp; - if (!config_find_rct2_path(gConfig.game_path)) { + + if (!config_find_rct2_path(gGeneral_config.game_path)) { osinterface_show_messagebox("Unable to find RCT2 installation directory. Please select the directory where you installed RCT2!"); char *res = osinterface_open_directory_browser("Please select your RCT2 directory"); - strcpy(gConfig.game_path, res); + strcpy(gGeneral_config.game_path, res); } fp = fopen(path, "w"); fprintf(fp, "[general]\n"); - fprintf(fp, "game_path = %s\n", gConfig.game_path); + fprintf(fp, "game_path = %s\n", gGeneral_config.game_path); fprintf(fp, "screenshot_format = PNG\n"); fprintf(fp, "play_intro = false\n"); + fprintf(fp, "edge_scrolling = true\n"); + fprintf(fp, "currency = GBP\n"); + fprintf(fp, "use_imperial = false\n"); + fprintf(fp, "use_farenheit = false\n"); + fprintf(fp, "[sound]\n"); + fprintf(fp, "sound_quality = high\n"); + fprintf(fp, "forced_software_buffering = false\n"); fclose(fp); } @@ -266,27 +310,97 @@ static void config_parse_settings(FILE *fp) continue; } - - - if (strcmp(setting, "game_path") == 0){ - strcpy(gConfig.game_path, value); - } else if(strcmp(setting, "screenshot_format") == 0) { - if (strcmp(value, "png") == 0 || strcmp(value, "PNG") == 0) { - gConfig.screenshot_format = SCREENSHOT_FORMAT_PNG; - } else if (strcmp(value, "1") == 0) { //TODO: REMOVE LINE AT LATER DATE WHEN EVERYONE HAS NEW CONFIG FORMAT - gConfig.screenshot_format = SCREENSHOT_FORMAT_PNG; - } else { - gConfig.screenshot_format = SCREENSHOT_FORMAT_BMP; - } - } else if (strcmp(setting, "play_intro") == 0) { - gConfig.play_intro = (strcmp(value, "true") == 0); + if (strcmp(section, "sound") == 0){ + config_sound(setting, value); } + else if (strcmp(section, "general") == 0){ + config_general(setting, value); + } + + + } + //RCT2_GLOBAL(0x009AACBC, sint8) = CURRENCY_KRONA; + + + free(setting); free(value); free(section); } + +static void config_sound(char *setting, char *value){ + if (strcmp(setting, "sound_quality") == 0){ + if (strcmp(value, "low") == 0){ + gSound_config.sound_quality = SOUND_QUALITY_LOW; + } + else if (strcmp(value, "medium") == 0){ + gSound_config.sound_quality = SOUND_QUALITY_MEDIUM; + } + else{ + gSound_config.sound_quality = SOUND_QUALITY_HIGH; + } + } + else if (strcmp(setting, "forced_software_buffering") == 0){ + if (strcmp(value, "true") == 0){ + gSound_config.forced_software_buffering = 1; + } + else{ + gSound_config.forced_software_buffering = 0; + } + } + +} + +static void config_general(char *setting, char *value){ + if (strcmp(setting, "game_path") == 0){ + strcpy(gGeneral_config.game_path, value); + } + else if (strcmp(setting, "screenshot_format") == 0) { + if (strcmp(value, "png") == 0 || strcmp(value, "PNG") == 0) { + gGeneral_config.screenshot_format = SCREENSHOT_FORMAT_PNG; + } + else if (strcmp(value, "1") == 0) { //TODO: REMOVE LINE AT LATER DATE WHEN EVERYONE HAS NEW CONFIG FORMAT + gGeneral_config.screenshot_format = SCREENSHOT_FORMAT_PNG; + } + else { + gGeneral_config.screenshot_format = SCREENSHOT_FORMAT_BMP; + } + } + else if (strcmp(setting, "play_intro") == 0) { + gGeneral_config.play_intro = (strcmp(value, "true") == 0); + } + else if (strcmp(setting, "edge_scrolling") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.edge_scrolling = 1; + } + else { + gGeneral_config.edge_scrolling = 0; + } + } + else if (strcmp(setting, "use_imperial") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.measurement_format = MEASUREMENT_FORMAT_IMPERIAL; + } + else{ + gGeneral_config.measurement_format = MEASUREMENT_FORMAT_METRIC; + } + } + else if (strcmp(setting, "use_farenheit") == 0){ + if (strcmp(value, "true") == 0){ + gGeneral_config.temperature_format = TEMPERATURE_FORMAT_F; + } + else{ + gGeneral_config.temperature_format = TEMPERATURE_FORMAT_C; + } + } + else if (strcmp(setting, "currency") == 0){ + config_parse_currency(value); + } + +} + /** * Read one line in the settings file * @param fp filepointer to the config file @@ -458,13 +572,53 @@ static int config_parse_section(FILE *fp, char *setting, char *value){ } + +static int config_parse_currency(char* currency){ + if (strcmp(currency, "GBP") == 0 || strcmp(currency, "£") == 0){ + gGeneral_config.currency_format = CURRENCY_POUNDS; + } + else if(strcmp(currency, "USD") == 0 || strcmp(currency, "$") == 0){ + gGeneral_config.currency_format = CURRENCY_DOLLARS; + } + else if(strcmp(currency, "FRF") == 0){ + gGeneral_config.currency_format = CURRENCY_FRANC; + } + else if (strcmp(currency, "DEM") == 0){ + gGeneral_config.currency_format = CURRENCY_DEUTSCHMARK; + } + else if(strcmp(currency, "YEN") == 0){ + gGeneral_config.currency_format = CURRENCY_YEN; + } + else if (strcmp(currency, "ESP") == 0){ + gGeneral_config.currency_format = CURRENCY_PESETA; + } + else if (strcmp(currency, "ITL") == 0){ + gGeneral_config.currency_format = CURRENCY_LIRA; + } + else if (strcmp(currency, "NLG") == 0){ + gGeneral_config.currency_format = CURRENCY_GUILDERS; + } + else if (strcmp(currency, "NOK") == 0 || strcmp(currency, "SEK") == 0 || strcmp(currency, "DEK") == 0){ + gGeneral_config.currency_format = CURRENCY_KRONA; + } + else if (strcmp(currency, "EUR") == 0 || strcmp(currency, "€") == 0){ + gGeneral_config.currency_format = CURRENCY_EUROS; + } + else{ + config_error("Invalid currency set in config file"); + return -1; + } + return 1; +} /** * Error with config file. Print error message an quit the game * @param msg Message to print in message box */ static void config_error(char *msg){ + osinterface_show_messagebox(msg); //TODO:SHUT DOWN EVERYTHING! + } diff --git a/src/config.h b/src/config.h index 35b4b1e0b2..f319ddfa4d 100644 --- a/src/config.h +++ b/src/config.h @@ -77,6 +77,32 @@ enum { TEMPERATURE_FORMAT_F }; +enum { + MEASUREMENT_FORMAT_IMPERIAL, + MEASUREMENT_FORMAT_METRIC +}; + +enum{ + CURRENCY_POUNDS, + CURRENCY_DOLLARS, + CURRENCY_FRANC, + CURRENCY_DEUTSCHMARK, + CURRENCY_YEN, + CURRENCY_PESETA, + CURRENCY_LIRA, + CURRENCY_GUILDERS, + CURRENCY_KRONA, + CURRENCY_EUROS + +}; + +enum{ + SOUND_QUALITY_LOW, + SOUND_QUALITY_MEDIUM, + SOUND_QUALITY_HIGH + +}; + extern uint16 gShortcutKeys[SHORTCUT_COUNT]; void config_reset_shortcut_keys(); @@ -87,18 +113,31 @@ void config_save(); // New config format #define MAX_CONFIG_LENGTH 256 +typedef struct sound_configuration { + + sint8 sound_quality; + sint8 forced_software_buffering; +} sound_configuration_t; -typedef struct configuration { + +typedef struct general_configuration { uint8 play_intro; uint8 screenshot_format; char game_path[MAX_PATH]; -} configuration_t; + sint8 measurement_format; + sint8 temperature_format; + sint8 currency_format; + sint8 consturction_marker_colour; + sint8 edge_scrolling; + +} general_configuration_t; //typedef struct hotkey_configuration{ //}; -extern configuration_t gConfig; +extern general_configuration_t gGeneral_config; +extern sound_configuration_t gSound_config; void config_init(); diff --git a/src/rct2.c b/src/rct2.c index a53a31bf22..39b939e420 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -141,20 +141,20 @@ void rct2_init() title_load(); gfx_clear(RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo), 10); - RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, int) = gConfig.play_intro ? 8 : 0; + RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, int) = gGeneral_config.play_intro ? 8 : 0; } // rct2: 0x00683499 void rct2_init_directories() { // check install directory - DWORD dwAttrib = GetFileAttributes(gConfig.game_path); + DWORD dwAttrib = GetFileAttributes(gGeneral_config.game_path); if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { osinterface_show_messagebox("Invalid RCT2 installation path. Please correct in config.ini."); exit(-1); } - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char), gConfig.game_path); + strcpy(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char), gGeneral_config.game_path); strcpy(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); strcat(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), "\\"); diff --git a/src/screenshot.c b/src/screenshot.c index 25595520b8..bf92238c2e 100644 --- a/src/screenshot.c +++ b/src/screenshot.c @@ -75,7 +75,7 @@ static int screenshot_get_next_path(char *path, char *extension) int screenshot_dump() { - switch (gConfig.screenshot_format) { + switch (gGeneral_config.screenshot_format) { case SCREENSHOT_FORMAT_BMP: return screenshot_dump_bmp(); case SCREENSHOT_FORMAT_PNG: