diff --git a/distribution/readme.txt b/distribution/readme.txt index afdde58b93..1407d5e551 100644 --- a/distribution/readme.txt +++ b/distribution/readme.txt @@ -1,5 +1,5 @@ Last updated: 2015-02-06 -Release version: 0.2.0-beta +Release version: 0.0.2-beta ------------------------------------------------------------------------ @@ -89,13 +89,14 @@ a directory of your choice. When you start OpenRCT2 for the first time, it will look for the RCT2 data files in the following locations: - - C:\Program Files\Infogrames\RollerCoaster Tycoon 2", - - C:\Program Files (x86)\Infogrames\RollerCoaster Tycoon 2", - - C:\Program Files\Infogrames Interactive\RollerCoaster Tycoon 2", - - C:\Program Files (x86)\Infogrames Interactive\RollerCoaster Tycoon 2", - - C:\Program Files\Atari\RollerCoaster Tycoon 2", - - C:\Program Files (x86)\Atari\RollerCoaster Tycoon 2", - - C:\GOG Games\RollerCoaster Tycoon 2 Triple Thrill Pack" + - C:\Program Files\Infogrames\RollerCoaster Tycoon 2, + - C:\Program Files (x86)\Infogrames\RollerCoaster Tycoon 2, + - C:\Program Files\Infogrames Interactive\RollerCoaster Tycoon 2, + - C:\Program Files (x86)\Infogrames Interactive\RollerCoaster Tycoon 2, + - C:\Program Files\Atari\RollerCoaster Tycoon 2, + - C:\Program Files (x86)\Atari\RollerCoaster Tycoon 2, + - C:\GOG Games\RollerCoaster Tycoon 2 Triple Thrill Pack + - The location of the openrct2.exe (where OpenRCT2 was extracted/installed) If none of these locations are found, OpenRCT2 will ask you to manually specify the directory. Alternatively after running OpenRCT2 for the first time, you can diff --git a/src/config.c b/src/config.c index 9105d3f9ed..cf7651288e 100644 --- a/src/config.c +++ b/src/config.c @@ -24,6 +24,7 @@ #include "localisation/localisation.h" #include "util/util.h" #include "interface/themes.h" +#include "openrct2.h" // Magic number for original game cfg file static const int MagicNumber = 0x0003113A; @@ -704,7 +705,8 @@ static bool config_find_rct2_path(char *resultPath) "C:\\Program Files (x86)\\Infogrames Interactive\\RollerCoaster Tycoon 2", "C:\\Program Files\\Atari\\RollerCoaster Tycoon 2", "C:\\Program Files (x86)\\Atari\\RollerCoaster Tycoon 2", - "C:\\GOG Games\\RollerCoaster Tycoon 2 Triple Thrill Pack" + "C:\\GOG Games\\RollerCoaster Tycoon 2 Triple Thrill Pack", + gExePath }; for (i = 0; i < countof(searchLocations); i++) { diff --git a/src/drawing/sprite.c b/src/drawing/sprite.c index 355204e3ba..024675facd 100644 --- a/src/drawing/sprite.c +++ b/src/drawing/sprite.c @@ -22,6 +22,8 @@ #include "../common.h" #include "../sprites.h" #include "drawing.h" +#include "../platform/platform.h" +#include "../openrct2.h" typedef struct { uint32 num_entries; @@ -90,7 +92,9 @@ int gfx_load_g2() FILE *file; unsigned int i; - file = fopen("data/g2.dat", "rb"); + char path[MAX_PATH]; + sprintf(path, "%s%cdata%cg2.dat", gExePath, platform_get_path_separator(), platform_get_path_separator()); + file = fopen(path, "rb"); if (file != NULL) { if (fread(&g2.header, 8, 1, file) == 1) { // Read element headers diff --git a/src/localisation/language.c b/src/localisation/language.c index f1ed4b0000..5d4e1b17d1 100644 --- a/src/localisation/language.c +++ b/src/localisation/language.c @@ -22,6 +22,7 @@ #include "../object.h" #include "../util/util.h" #include "localisation.h" +#include "../openrct2.h" typedef struct { int id; @@ -112,21 +113,21 @@ const char *language_get_string(rct_string_id id) int language_open(int id) { - static const char *languagePath = "data/language/%s.txt"; - char filename[_MAX_PATH]; + static const char *languagePath = "%s/data/language/%s.txt"; + char filename[MAX_PATH]; language_close_all(); if (id == LANGUAGE_UNDEFINED) return 1; if (id != LANGUAGE_ENGLISH_UK) { - sprintf(filename, languagePath, language_filenames[LANGUAGE_ENGLISH_UK]); + sprintf(filename, languagePath, gExePath, language_filenames[LANGUAGE_ENGLISH_UK]); if (language_open_file(filename, &_languageFallback)) { _languageFallback.id = LANGUAGE_ENGLISH_UK; } } - sprintf(filename, languagePath, language_filenames[id]); + sprintf(filename, languagePath, gExePath, language_filenames[id]); if (language_open_file(filename, &_languageCurrent)) { _languageCurrent.id = id; gCurrentLanguage = id; diff --git a/src/openrct2.c b/src/openrct2.c index c29b2dc45d..3dc7ff892b 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -33,6 +33,7 @@ int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; char gOpenRCT2StartupActionPath[512] = { 0 }; +char gExePath[MAX_PATH]; // This should probably be changed later and allow a custom selection of things to initialise like SDL_INIT bool gOpenRCT2Headless = false; @@ -99,6 +100,23 @@ static void openrct2_copy_files_over(const char *originalDirectory, const char * platform_enumerate_directories_end(fileEnumHandle); } +static void openrct2_set_exe_path() +{ + char exePath[MAX_PATH]; + char tempPath[MAX_PATH]; + char *exeDelimiter; + int pathEnd; + int exeDelimiterIndex; + + GetModuleFileName(NULL, exePath, MAX_PATH); + exeDelimiter = strrchr(exePath, platform_get_path_separator()); + exeDelimiterIndex = (int)(exeDelimiter - exePath); + pathEnd = strlen(exePath) - (strlen(exePath) - exeDelimiterIndex); + strncpy(tempPath, exePath, pathEnd); + tempPath[pathEnd] = '\0'; + _fullpath(gExePath, tempPath, strlen(tempPath)); +} + /** * Copy saved games and landscapes to user directory */ @@ -123,6 +141,8 @@ bool openrct2_initialise() return false; } + openrct2_set_exe_path(); + config_set_defaults(); if (!config_open_default()) { if (!config_find_or_browse_install_directory()) { diff --git a/src/openrct2.h b/src/openrct2.h index f170527a72..120b09051f 100644 --- a/src/openrct2.h +++ b/src/openrct2.h @@ -32,6 +32,7 @@ enum { extern int gOpenRCT2StartupAction; extern char gOpenRCT2StartupActionPath[512]; +extern char gExePath[MAX_PATH]; extern bool gOpenRCT2Headless; extern bool gOpenRCT2ShowChangelog; diff --git a/src/rct2.h b/src/rct2.h index 5a651c398c..0ea6a5665b 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -106,6 +106,9 @@ typedef fixed32_1dp money32; #define MONEY_FREE MONEY(0,00) #define MONEY32_UNDEFINED ((money32)0x80000000) +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif typedef void (EMPTY_ARGS_VOID_POINTER)(); typedef unsigned short rct_string_id; diff --git a/src/title.c b/src/title.c index 4b0f9636a9..c1b2334f82 100644 --- a/src/title.c +++ b/src/title.c @@ -325,7 +325,7 @@ static void title_do_next_script_opcode() } while (*(_currentScript - 1) != 0); // Construct full relative path - sprintf(path, "data%ctitle%c%s", platform_get_path_separator(), platform_get_path_separator(), filename); + sprintf(path, "%s%cData%ctitle%c%s", gExePath, platform_get_path_separator(), platform_get_path_separator(), platform_get_path_separator(), filename); if (title_load_park(path)) { _scriptNoLoadsSinceRestart = 0; } else { @@ -491,8 +491,10 @@ static uint8 *title_script_load() FILE *file; char parts[3 * 32], *token, *part1, *part2, *src; - char path[] = "data/title/script.txt"; - + char path[MAX_PATH]; + char filePath[] = "data/title/script.txt"; + + sprintf(path, "%s%c%s", gExePath, platform_get_path_separator(), filePath); log_verbose("loading title script, %s", path); file = fopen(path, "r"); if (file == NULL) { diff --git a/src/windows/changelog.c b/src/windows/changelog.c index bf4830f1b7..f7dd4616d7 100644 --- a/src/windows/changelog.c +++ b/src/windows/changelog.c @@ -7,6 +7,8 @@ #include "../world/map.h" #include "../world/footpath.h" #include "../util/util.h" +#include "../openrct2.h" +#include "../platform/platform.h" enum { WIDX_BACKGROUND, @@ -220,7 +222,9 @@ static void window_changelog_scrollpaint() static bool window_changelog_read_file() { window_changelog_dispose_file(); - if (!readentirefile("changelog.txt", &_changelogText, &_changelogTextSize)) { + char path[MAX_PATH]; + sprintf(path, "%s%cchangelog.txt", gExePath, platform_get_path_separator()); + if (!readentirefile(path, &_changelogText, &_changelogTextSize)) { log_error("Unable to read changelog.txt"); return false; }