mirror of https://github.com/OpenRCT2/OpenRCT2.git
fix loading object via console
This commit is contained in:
parent
8d168fb2ce
commit
faf1f08b7f
|
@ -30,6 +30,7 @@
|
||||||
#include "../input.h"
|
#include "../input.h"
|
||||||
#include "../network/twitch.h"
|
#include "../network/twitch.h"
|
||||||
#include "../object.h"
|
#include "../object.h"
|
||||||
|
#include "../object/ObjectRepository.h"
|
||||||
#include "../world/banner.h"
|
#include "../world/banner.h"
|
||||||
#include "../world/climate.h"
|
#include "../world/climate.h"
|
||||||
#include "../world/scenery.h"
|
#include "../world/scenery.h"
|
||||||
|
@ -868,84 +869,69 @@ static int cc_twitch(const utf8 **argv, int argc)
|
||||||
|
|
||||||
static int cc_load_object(const utf8 **argv, int argc) {
|
static int cc_load_object(const utf8 **argv, int argc) {
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
utf8 path[MAX_PATH];
|
char name[9] = { 0 };
|
||||||
|
memset(name, ' ', 8);
|
||||||
substitute_path(path, gRCT2AddressObjectDataPath, argv[0]);
|
int i = 0;
|
||||||
strcat(path, ".DAT\0");
|
for (const char * ch = argv[0]; *ch != '\0' && i < 8; ch++) {
|
||||||
|
name[i++] = *ch;
|
||||||
rct_object_entry entry;
|
|
||||||
if (object_load_entry(path, &entry)) {
|
|
||||||
uint8 type = entry.flags & 0xF;
|
|
||||||
uint8 index;
|
|
||||||
|
|
||||||
if (check_object_entry(&entry)) {
|
|
||||||
if (!find_object_in_entry_group(&entry, &type, &index)){
|
|
||||||
|
|
||||||
int entryGroupIndex = 0;
|
|
||||||
for (; entryGroupIndex < object_entry_group_counts[type]; entryGroupIndex++){
|
|
||||||
if (object_entry_groups[type].chunks[entryGroupIndex] == (uint8*)-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entryGroupIndex >= object_entry_group_counts[type]) {
|
|
||||||
console_writeline_error("Too many objects of that type.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Load the obect
|
|
||||||
if (!object_load_chunk(entryGroupIndex, &entry, NULL)) {
|
|
||||||
console_writeline_error("Could not load object file.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reset_loaded_objects();
|
|
||||||
if (type == OBJECT_TYPE_RIDE) {
|
|
||||||
// Automatically research the ride so it's supported by the game.
|
|
||||||
rct_ride_entry *rideEntry;
|
|
||||||
int rideType;
|
|
||||||
|
|
||||||
rideEntry = get_ride_entry(entryGroupIndex);
|
|
||||||
|
|
||||||
for (int j = 0; j < 3; j++) {
|
|
||||||
rideType = rideEntry->ride_type[j];
|
|
||||||
if (rideType != 255)
|
|
||||||
research_insert(true, 0x10000 | (rideType << 8) | entryGroupIndex, rideEntry->category[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
gSilentResearch = true;
|
|
||||||
sub_684AC3();
|
|
||||||
gSilentResearch = false;
|
|
||||||
}
|
|
||||||
else if (type == OBJECT_TYPE_SCENERY_SETS) {
|
|
||||||
rct_scenery_set_entry *scenerySetEntry;
|
|
||||||
|
|
||||||
scenerySetEntry = get_scenery_group_entry(entryGroupIndex);
|
|
||||||
|
|
||||||
research_insert(true, entryGroupIndex, RESEARCH_CATEGORY_SCENERYSET);
|
|
||||||
|
|
||||||
gSilentResearch = true;
|
|
||||||
sub_684AC3();
|
|
||||||
gSilentResearch = false;
|
|
||||||
}
|
|
||||||
scenery_set_default_placement_configuration();
|
|
||||||
window_new_ride_init_vars();
|
|
||||||
|
|
||||||
RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, uint16) = 0;
|
|
||||||
gfx_invalidate_screen();
|
|
||||||
console_writeline("Object file loaded.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console_writeline_error("Object is already in scenario.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console_writeline_error("The object file was invalid.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console_writeline_error("Could not find the object file.");
|
const ObjectRepositoryItem * ori = object_repository_find_object_by_name(name);
|
||||||
|
if (ori == NULL) {
|
||||||
|
console_writeline_error("Could not find the object.");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rct_object_entry * entry = &ori->ObjectEntry;
|
||||||
|
void * loadedObject = object_repository_find_loaded_object(entry);
|
||||||
|
if (loadedObject != NULL) {
|
||||||
|
console_writeline_error("Object is already in scenario.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int groupIndex;
|
||||||
|
if (!object_load_chunk(-1, entry, &groupIndex)) {
|
||||||
|
console_writeline_error("Unable to load object.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_loaded_objects();
|
||||||
|
|
||||||
|
uint8 objectType = entry->flags & 0x0F;
|
||||||
|
if (objectType == OBJECT_TYPE_RIDE) {
|
||||||
|
// Automatically research the ride so it's supported by the game.
|
||||||
|
rct_ride_entry *rideEntry;
|
||||||
|
int rideType;
|
||||||
|
|
||||||
|
rideEntry = get_ride_entry(groupIndex);
|
||||||
|
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
rideType = rideEntry->ride_type[j];
|
||||||
|
if (rideType != 255)
|
||||||
|
research_insert(true, 0x10000 | (rideType << 8) | groupIndex, rideEntry->category[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
gSilentResearch = true;
|
||||||
|
sub_684AC3();
|
||||||
|
gSilentResearch = false;
|
||||||
|
}
|
||||||
|
else if (objectType == OBJECT_TYPE_SCENERY_SETS) {
|
||||||
|
rct_scenery_set_entry *scenerySetEntry;
|
||||||
|
|
||||||
|
scenerySetEntry = get_scenery_group_entry(groupIndex);
|
||||||
|
|
||||||
|
research_insert(true, groupIndex, RESEARCH_CATEGORY_SCENERYSET);
|
||||||
|
|
||||||
|
gSilentResearch = true;
|
||||||
|
sub_684AC3();
|
||||||
|
gSilentResearch = false;
|
||||||
|
}
|
||||||
|
scenery_set_default_placement_configuration();
|
||||||
|
window_new_ride_init_vars();
|
||||||
|
|
||||||
|
RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_UPDATE_TICKS, uint16) = 0;
|
||||||
|
gfx_invalidate_screen();
|
||||||
|
console_writeline("Object file loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -119,7 +119,7 @@ bool object_saved_packed(SDL_RWops* rw, const rct_object_entry * entry);
|
||||||
void object_unload_all();
|
void object_unload_all();
|
||||||
|
|
||||||
int check_object_entry(rct_object_entry *entry);
|
int check_object_entry(rct_object_entry *entry);
|
||||||
int object_load_chunk(int groupIndex, const rct_object_entry *entry, int* chunk_size);
|
bool object_load_chunk(int groupIndex, const rct_object_entry * entry, int * outGroupIndex);
|
||||||
int object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
int object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
||||||
int object_calculate_checksum(const rct_object_entry *entry, const uint8 *data, int dataLength);
|
int object_calculate_checksum(const rct_object_entry *entry, const uint8 *data, int dataLength);
|
||||||
void reset_loaded_objects();
|
void reset_loaded_objects();
|
||||||
|
|
|
@ -595,7 +595,7 @@ extern "C"
|
||||||
IObjectRepository * objRepo = GetObjectRepository();
|
IObjectRepository * objRepo = GetObjectRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
int object_load_chunk(int groupIndex, const rct_object_entry * entry, int * chunkSize)
|
bool object_load_chunk(int groupIndex, const rct_object_entry * entry, int * outGroupIndex)
|
||||||
{
|
{
|
||||||
IObjectRepository * objRepo = GetObjectRepository();
|
IObjectRepository * objRepo = GetObjectRepository();
|
||||||
Object * object = objRepo->LoadObject(entry);
|
Object * object = objRepo->LoadObject(entry);
|
||||||
|
@ -623,6 +623,10 @@ extern "C"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chunkList[groupIndex] = object->GetLegacyData();
|
chunkList[groupIndex] = object->GetLegacyData();
|
||||||
|
if (outGroupIndex != nullptr)
|
||||||
|
{
|
||||||
|
*outGroupIndex = groupIndex;
|
||||||
|
}
|
||||||
|
|
||||||
rct_object_entry_extended * extendedEntry = &object_entry_groups[objectType].entries[groupIndex];
|
rct_object_entry_extended * extendedEntry = &object_entry_groups[objectType].entries[groupIndex];
|
||||||
Memory::Copy<void>(extendedEntry, object->GetObjectEntry(), sizeof(rct_object_entry));
|
Memory::Copy<void>(extendedEntry, object->GetObjectEntry(), sizeof(rct_object_entry));
|
||||||
|
@ -658,6 +662,23 @@ extern "C"
|
||||||
return (void *)object;
|
return (void *)object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void * object_repository_find_loaded_object(const rct_object_entry * objectEntry)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < 721; i++)
|
||||||
|
{
|
||||||
|
Object * object = _loadedObjects[i];
|
||||||
|
if (object != nullptr)
|
||||||
|
{
|
||||||
|
const rct_object_entry * entry = object->GetObjectEntry();
|
||||||
|
if (memcmp(objectEntry->name, entry->name, 8) == 0)
|
||||||
|
{
|
||||||
|
return (void *)object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void * object_repository_get_loaded_object(uint8 objectType, uint8 entryIndex)
|
void * object_repository_get_loaded_object(uint8 objectType, uint8 entryIndex)
|
||||||
{
|
{
|
||||||
int index = GetObjectEntryIndex(objectType, entryIndex);
|
int index = GetObjectEntryIndex(objectType, entryIndex);
|
||||||
|
@ -820,6 +841,12 @@ extern "C"
|
||||||
return objectRepository->FindObject(entry);
|
return objectRepository->FindObject(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ObjectRepositoryItem * object_repository_find_object_by_name(const char * name)
|
||||||
|
{
|
||||||
|
IObjectRepository * objectRepository = GetObjectRepository();
|
||||||
|
return objectRepository->FindObject(name);
|
||||||
|
}
|
||||||
|
|
||||||
void object_delete(void * object)
|
void object_delete(void * object)
|
||||||
{
|
{
|
||||||
if (object != nullptr)
|
if (object != nullptr)
|
||||||
|
|
|
@ -76,7 +76,9 @@ IObjectRepository * GetObjectRepository();
|
||||||
size_t object_repository_get_items_count();
|
size_t object_repository_get_items_count();
|
||||||
const ObjectRepositoryItem * object_repository_get_items();
|
const ObjectRepositoryItem * object_repository_get_items();
|
||||||
const ObjectRepositoryItem * object_repository_find_object_by_entry(const rct_object_entry * entry);
|
const ObjectRepositoryItem * object_repository_find_object_by_entry(const rct_object_entry * entry);
|
||||||
|
const ObjectRepositoryItem * object_repository_find_object_by_name(const char * name);
|
||||||
void * object_repository_load_object(const rct_object_entry * objectEntry);
|
void * object_repository_load_object(const rct_object_entry * objectEntry);
|
||||||
|
void * object_repository_find_loaded_object(const rct_object_entry * objectEntry);
|
||||||
void * object_repository_get_loaded_object(uint8 objectType, uint8 entryIndex);
|
void * object_repository_get_loaded_object(uint8 objectType, uint8 entryIndex);
|
||||||
void object_repository_unload(size_t itemIndex);
|
void object_repository_unload(size_t itemIndex);
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ void RideObject::Load()
|
||||||
_legacyType.name = language_allocate_object_string(GetName());
|
_legacyType.name = language_allocate_object_string(GetName());
|
||||||
_legacyType.description = language_allocate_object_string(GetDescription());
|
_legacyType.description = language_allocate_object_string(GetDescription());
|
||||||
_legacyType.images_offset = gfx_object_allocate_images(GetImageTable()->GetImages(), GetImageTable()->GetCount());
|
_legacyType.images_offset = gfx_object_allocate_images(GetImageTable()->GetImages(), GetImageTable()->GetCount());
|
||||||
|
_legacyType.vehicle_preset_list = &_presetColours;
|
||||||
|
|
||||||
int cur_vehicle_images_offset = _legacyType.images_offset + 3;
|
int cur_vehicle_images_offset = _legacyType.images_offset + 3;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
|
|
|
@ -1708,8 +1708,7 @@ static void editor_load_selected_objects()
|
||||||
if (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED) {
|
if (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED) {
|
||||||
uint8 entry_index, entry_type;
|
uint8 entry_index, entry_type;
|
||||||
if (!find_object_in_entry_group(&items[i].ObjectEntry, &entry_type, &entry_index)) {
|
if (!find_object_in_entry_group(&items[i].ObjectEntry, &entry_type, &entry_index)) {
|
||||||
int chunk_size;
|
if (!object_load_chunk(-1, &items[i].ObjectEntry, NULL)) {
|
||||||
if (!object_load_chunk(-1, &items[i].ObjectEntry, &chunk_size)) {
|
|
||||||
log_error("Failed to load entry %.8s", items->Name);
|
log_error("Failed to load entry %.8s", items->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue