Exemple #1
0
/**
 * Loads only the basic information from a scenario.
 *  rct2: 0x006761D6
 */
int scenario_load_basic(const char *path)
{
	FILE *file;
	rct_s6_header *s6Header = (rct_s6_header*)0x009E34E4;
	rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;

	file = fopen(path, "rb");
	if (file != NULL) {
		// Read first chunk
		sawyercoding_read_chunk(file, (uint8*)s6Header);
		if (s6Header->type == S6_TYPE_SCENARIO) {
			// Read second chunk
			sawyercoding_read_chunk(file, (uint8*)s6Info);
			fclose(file);
			RCT2_GLOBAL(0x009AA00C, uint8) = 0;

			// Checks for a scenario string object (possibly for localisation)
			if ((s6Info->entry.flags & 0xFF) != 255) {
				if (object_get_scenario_text(&s6Info->entry)) {
					int ebp = RCT2_GLOBAL(0x009ADAF8, uint32);
					format_string(s6Info->name, RCT2_GLOBAL(ebp, sint16), NULL);
					format_string(s6Info->details, RCT2_GLOBAL(ebp + 4, sint16), NULL);
					RCT2_GLOBAL(0x009AA00C, uint8) = RCT2_GLOBAL(ebp + 6, uint8);
					object_free_scenario_text();
				}
			}
			return 1;
		}
		fclose(file);
	}

	RCT2_GLOBAL(0x009AC31B, sint8) = -1;
	RCT2_GLOBAL(0x009AC31C, sint16) = 3011;
	return 0;
}
Exemple #2
0
/**
 * Loads only the basic information from a scenario.
 *  rct2: 0x006761D6
 */
int scenario_load_basic(const char *path, rct_s6_header *header, rct_s6_info *info)
{
	FILE *file;

	log_verbose("loading scenario details, %s", path);

	file = fopen(path, "rb");
	if (file != NULL) {
		// Read first chunk
		sawyercoding_read_chunk(file, (uint8*)header);
		if (header->type == S6_TYPE_SCENARIO) {
			// Read second chunk
			sawyercoding_read_chunk(file, (uint8*)info);
			fclose(file);
			RCT2_GLOBAL(0x009AA00C, uint8) = 0;

			// Checks for a scenario string object (possibly for localisation)
			if ((info->entry.flags & 0xFF) != 255) {
				if (object_get_scenario_text(&info->entry)) {
					rct_stex_entry* stex_entry = RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TEXT_TEMP_CHUNK, rct_stex_entry*);
					format_string(info->name, stex_entry->scenario_name, NULL);
					format_string(info->details, stex_entry->details, NULL);
					RCT2_GLOBAL(0x009AA00C, uint8) = stex_entry->var_06;
					object_free_scenario_text();
				}
			}
/**
 * Loads only the basic information from a scenario.
 *  rct2: 0x006761D6
 */
int scenario_load_basic(const char *path, rct_s6_header *header, rct_s6_info *info)
{
	SDL_RWops* rw;

	log_verbose("loading scenario details, %s", path);

	rw = SDL_RWFromFile(path, "rb");
	if (rw != NULL) {
		// Read first chunk
		sawyercoding_read_chunk(rw, (uint8*)header);
		if (header->type == S6_TYPE_SCENARIO) {
			// Read second chunk
			sawyercoding_read_chunk(rw, (uint8*)info);
			SDL_RWclose(rw);
			RCT2_GLOBAL(0x009AA00C, uint8) = 0;

			// Get filename
			utf8 filename[MAX_PATH];
			const char *temp_filename = path_get_filename(path);
			int len = strnlen(temp_filename, MAX_PATH);
			safe_strncpy(filename, temp_filename, MAX_PATH);
			if (len == MAX_PATH)
			{
				filename[MAX_PATH - 1] = '\0';
				log_warning("truncated string %s", filename);
			}
			path_remove_extension(filename);

			rct_string_id localisedStringIds[3];
			if (language_get_localised_scenario_strings(filename, localisedStringIds)) {
				if (localisedStringIds[0] != (rct_string_id)STR_NONE) {
					safe_strncpy(info->name, language_get_string(localisedStringIds[0]), 64);
				}
				if (localisedStringIds[2] != (rct_string_id)STR_NONE) {
					safe_strncpy(info->details, language_get_string(localisedStringIds[2]), 256);
				}
			} else {
				// Checks for a scenario string object (possibly for localisation)
				if ((info->entry.flags & 0xFF) != 255) {
					if (object_get_scenario_text(&info->entry)) {
						rct_stex_entry* stex_entry = RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TEXT_TEMP_CHUNK, rct_stex_entry*);
						format_string(info->name, stex_entry->scenario_name, NULL);
						format_string(info->details, stex_entry->details, NULL);
						RCT2_GLOBAL(0x009AA00C, uint8) = stex_entry->var_06;
						object_free_scenario_text();
					}
				}
			}
Exemple #4
0
/**
 * 
 *  rct2: 0x006AA0C6
 */
int object_read_and_load_entries(FILE *file)
{
	object_unload_all();

	int i, j;
	rct_object_entry *entries;

	// Read all the object entries
	entries = malloc(OBJECT_ENTRY_COUNT * sizeof(rct_object_entry));
	sawyercoding_read_chunk(file, (uint8*)entries);

	// Load each object
	for (i = 0; i < OBJECT_ENTRY_COUNT; i++) {
		if (!check_object_entry(&entries[i]))
			continue;

		// Get entry group index
		int entryGroupIndex = i;
		for (j = 0; j < countof(object_entry_group_counts); j++) {
			if (entryGroupIndex < object_entry_group_counts[j])
				break;
			entryGroupIndex -= object_entry_group_counts[j];
		}

		// Load the obect
		if (!object_load(entryGroupIndex, &entries[i])) {
			// Failed to load the object
			free(entries);
			memcpy((char*)0x13CE952, entries[i].name, 8);
			object_unload_all();
			return 0;
		}
	}

	free(entries);
	return 1;
}
Exemple #5
0
/**
 * 
 *  rct2: 0x00676053
 * scenario (ebx)
 */
void scenario_load(const char *path)
{
	FILE *file;
	int i, j;
	rct_s6_header *s6Header = (rct_s6_header*)0x009E34E4;
	rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;

	file = fopen(path, "rb");
	if (file != NULL) {
		if (!sawyercoding_validate_checksum(file)) {
			fclose(file);
			RCT2_GLOBAL(0x009AC31B, uint8) = 255;
			RCT2_GLOBAL(0x009AC31C, uint16) = STR_FILE_CONTAINS_INVALID_DATA;
			return;
		}

		// Read first chunk
		sawyercoding_read_chunk(file, (uint8*)s6Header);
		if (s6Header->type == S6_TYPE_SCENARIO) {
			// Read second chunk
			sawyercoding_read_chunk(file, (uint8*)s6Info);

			// Read packed objects
			if (s6Header->num_packed_objects > 0) {
				j = 0;
				for (i = 0; i < s6Header->num_packed_objects; i++)
					j += object_load_packed();
				if (j > 0)
					object_list_load();
			}

			object_read_and_load_entries(file);

			// Read flags (16 bytes)
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_MONTH_YEAR);

			// Read map elements
			memset((void*)RCT2_ADDRESS_MAP_ELEMENTS, 0, MAX_MAP_ELEMENTS * sizeof(rct_map_element));
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_MAP_ELEMENTS);

			// Read game data, including sprites
			sawyercoding_read_chunk(file, (uint8*)0x010E63B8);

			// Read number of guests in park and something else
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_GUESTS_IN_PARK);

			// Read ?
			sawyercoding_read_chunk(file, (uint8*)0x01357BC8);

			// Read park rating
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_RATING);

			// Read ?
			sawyercoding_read_chunk(file, (uint8*)0x01357CF2);

			// Read ?
			sawyercoding_read_chunk(file, (uint8*)0x0135832C);

			// Read ?
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_VALUE);

			// Read more game data, including research items and rides
			sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_COMPLETED_COMPANY_VALUE);

			fclose(file);

			// Check expansion pack
			// RCT2_CALLPROC_EBPSAFE(0x006757E6);

			RCT2_CALLPROC_EBPSAFE(0x006A9FC0);
			map_update_tile_pointers();
			reset_0x69EBE4();// RCT2_CALLPROC_EBPSAFE(0x0069EBE4);
			return;
		}

		fclose(file);
	}

	RCT2_GLOBAL(0x009AC31B, uint8) = 255;
	RCT2_GLOBAL(0x009AC31C, uint16) = STR_FILE_CONTAINS_INVALID_DATA;
}
Exemple #6
0
/**
 * 
 *  rct2: 0x00675E1B
 */
int game_load_save()
{
	rct_window *mainWindow;
	HANDLE hFile;
	char *path;
	int i, j;

	path = (char*)0x0141EF68;
	hFile = CreateFile(
		path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL
	);
	if (hFile == NULL) {
		RCT2_GLOBAL(0x009AC31B, uint8) = 255;
		RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, uint16) = STR_FILE_CONTAINS_INVALID_DATA;
		return 0;
	}

	RCT2_GLOBAL(0x009E382C, HANDLE) = hFile;
	if (!sawyercoding_validate_checksum(hFile)) {
		CloseHandle(hFile);
		RCT2_GLOBAL(0x009AC31B, uint8) = 255;
		RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, uint16) = STR_FILE_CONTAINS_INVALID_DATA;
		return 0;
	}

	rct_s6_header *s6Header = (rct_s6_header*)0x009E34E4;
	rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;

	// Read first chunk
	sawyercoding_read_chunk(hFile, (uint8*)s6Header);
	if (s6Header->type == S6_TYPE_SAVEDGAME) {
		// Read packed objects
		if (s6Header->num_packed_objects > 0) {
			j = 0;
			for (i = 0; i < s6Header->num_packed_objects; i++)
				j += object_load_packed();
			if (j > 0)
				object_load_list();
		}
	}

	object_read_and_load_entries(hFile);

	// Read flags (16 bytes)
	sawyercoding_read_chunk(hFile, (uint8*)RCT2_ADDRESS_CURRENT_MONTH_YEAR);

	// Read map elements
	memset((void*)RCT2_ADDRESS_MAP_ELEMENTS, 0, MAX_MAP_ELEMENTS * sizeof(rct_map_element));
	sawyercoding_read_chunk(hFile, (uint8*)RCT2_ADDRESS_MAP_ELEMENTS);

	// Read game data, including sprites
	sawyercoding_read_chunk(hFile, (uint8*)0x010E63B8);

	CloseHandle(hFile);

	// Check expansion pack
	// RCT2_CALLPROC_EBPSAFE(0x006757E6);

	// The rest is the same as in scenario load and play
	RCT2_CALLPROC_EBPSAFE(0x006A9FC0);
	map_update_tile_pointers();
	RCT2_CALLPROC_EBPSAFE(0x0069EBE4);
	RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_PLAYING;
	viewport_init_all();
	game_create_windows();
	mainWindow = window_get_main();

	mainWindow->var_4B0 = -1;
	mainWindow->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16);
	mainWindow->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16);
	uint8 _cl = (RCT2_GLOBAL(0x0138869E, sint16) & 0xFF) - mainWindow->viewport->zoom;
	mainWindow->viewport->zoom = RCT2_GLOBAL(0x0138869E, sint16) & 0xFF;
	*((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(0x0138869E, sint16) >> 8;
	if (_cl != 0) {
		if (_cl < 0) {
			_cl = -_cl;
			mainWindow->viewport->view_width >>= _cl;
			mainWindow->viewport->view_height >>= _cl;
		} else {