From 3382be1430cda8790e03e2308fa6f16f144f40a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Lomax?= Date: Mon, 12 May 2014 17:29:16 +0200 Subject: [PATCH] intermidiate comit --- src/addresses.h | 1 + src/config.c | 117 ++++++++++++++++++++++++++++++++++++++++------- src/rct2.c | 6 +-- src/screenshot.c | 2 +- 4 files changed, 105 insertions(+), 21 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 2ec02b5edd..7b946e796d 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -53,6 +53,7 @@ #define RCT2_ADDRESS_CONFIG_FAHRENHEIT 0x009AAC79 #define RCT2_ADDRESS_CONFIG_KEYBOARD_SHORTCUTS 0x009AAC7A #define RCT2_ADDRESS_CONFIG_EDGE_SCROLLING 0x009AACBA +#define RCT2_ADDRESS_CONFIG_CURRENCY 0x009AACBB #define RCT2_ADDRESS_EXPANSION_NAMES 0x009AACC0 #define RCT2_ADDRESS_EXPANSION_FLAGS 0x009AB4C0 diff --git a/src/config.c b/src/config.c index f72a78c252..614e3be043 100644 --- a/src/config.c +++ b/src/config.c @@ -96,16 +96,24 @@ void config_load() // Read options ReadFile(hFile, (void*)0x009AAC5C, 2155, &bytesRead, NULL); CloseHandle(hFile); - if (RCT2_GLOBAL(0x009AB4C6, sint8) == 1) - return; + + + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, sint8) = gGeneral_config.edge_scrolling; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_CURRENCY, sint8) = gGeneral_config.currency_format; //i think this is curency + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) = gGeneral_config.measurement_format; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FAHRENHEIT, sint8) = gGeneral_config.temperature_format; + //if (RCT2_GLOBAL(0x009AB4C6, sint8) == 1) + // return; RCT2_GLOBAL(0x009AB4C6, sint8) = 1; - RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FAHRENHEIT, sint8) = 1; - RCT2_GLOBAL(0x009AACBB, sint8) = 1; + + + + + RCT2_GLOBAL(0x009AACBD, sint16) = 0; 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) = 1; + RCT2_GLOBAL(0x009AA00D, sint8) = 0; } } @@ -122,7 +130,7 @@ void config_load() RCT2_GLOBAL(0x009AACBD, sint16) = 0; 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) = 1; + RCT2_GLOBAL(0x009AA00D, sint8) = 0; //no idea what this does } /** @@ -144,7 +152,7 @@ void config_save() // New config format -configuration_t gConfig; +general_configuration_t gGeneral_config; static void config_parse_settings(FILE *fp); static int config_get_line(FILE *fp, char *setting, char *value); @@ -152,6 +160,7 @@ 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); /** @@ -227,16 +236,20 @@ 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)) { MessageBox(NULL, "Unable to find RCT2 installation directory. Please correct in config.ini.", "OpenRCT2", MB_OK); - strcpy(gConfig.game_path, "C:\\"); + strcpy(gGeneral_config.game_path, "C:\\"); } 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"); + fprintf(fp, "use_imperial = false\n"); + fprintf(fp, "use_farenheit = false\n"); fclose(fp); } @@ -263,19 +276,51 @@ static void config_parse_settings(FILE *fp) if (strcmp(setting, "game_path") == 0){ - strcpy(gConfig.game_path, value); + strcpy(gGeneral_config.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; + 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 - gConfig.screenshot_format = SCREENSHOT_FORMAT_PNG; + gGeneral_config.screenshot_format = SCREENSHOT_FORMAT_PNG; } else { - gConfig.screenshot_format = SCREENSHOT_FORMAT_BMP; + gGeneral_config.screenshot_format = SCREENSHOT_FORMAT_BMP; } } else if (strcmp(setting, "play_intro") == 0) { - gConfig.play_intro = (strcmp(value, "true") == 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_IMPRIAL; + } + 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); + } + } + //RCT2_GLOBAL(0x009AACBC, sint8) = CURRENCY_KRONA; + + + free(setting); free(value); free(section); @@ -452,13 +497,51 @@ 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){ MessageBox(NULL, msg, "OpenRCT2", MB_OK); - //TODO:SHUT DOWN EVERYTHING! + exit(-1); } diff --git a/src/rct2.c b/src/rct2.c index be54cd7306..9be9418e02 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -142,20 +142,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)) { MessageBox(NULL, "Invalid RCT2 installation path. Please correct in config.ini.", "OpenRCT2", MB_OK); 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 af65bf976b..8d85ddc85a 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: