diff --git a/src/fileio.cpp b/src/fileio.cpp index a72950bc73..8df7a82dab 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -75,7 +75,7 @@ size_t FioGetPos() * @param slot Index of queried file. * @return Name of the file. */ -const char *FioGetFilename(uint8 slot) +const char *FioGetFilename(uint slot) { return _fio.shortnames[slot]; } @@ -112,7 +112,7 @@ static void FioRestoreFile(int slot) * @param slot Slot number of the new file. * @param pos New absolute position in the new file. */ -void FioSeekToFile(uint8 slot, size_t pos) +void FioSeekToFile(uint slot, size_t pos) { FILE *f; #if defined(LIMITED_FDS) @@ -247,7 +247,7 @@ static void FioFreeHandle() * @param filename Name of the file at the disk. * @param subdir The sub directory to search this file in. */ -void FioOpenFile(int slot, const char *filename, Subdirectory subdir) +void FioOpenFile(uint slot, const char *filename, Subdirectory subdir) { FILE *f; diff --git a/src/fileio_func.h b/src/fileio_func.h index 443460b2d3..d6d943d4e1 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -16,14 +16,14 @@ #include "fileio_type.h" void FioSeekTo(size_t pos, int mode); -void FioSeekToFile(uint8 slot, size_t pos); +void FioSeekToFile(uint slot, size_t pos); size_t FioGetPos(); -const char *FioGetFilename(uint8 slot); +const char *FioGetFilename(uint slot); byte FioReadByte(); uint16 FioReadWord(); uint32 FioReadDword(); void FioCloseAll(); -void FioOpenFile(int slot, const char *filename, Subdirectory subdir); +void FioOpenFile(uint slot, const char *filename, Subdirectory subdir); void FioReadBlock(void *ptr, size_t size); void FioSkipBytes(int n); diff --git a/src/fios.h b/src/fios.h index 73f233f84a..c954c5c83c 100644 --- a/src/fios.h +++ b/src/fios.h @@ -90,8 +90,10 @@ enum FileSlots { SOUND_SLOT = 1, /** First slot usable for (New)GRFs used during the game. */ FIRST_GRF_SLOT = 2, + /** Maximum number of GRFs in single-player */ + MAX_NEWGRFS = 256, /** Maximum number of slots. */ - MAX_FILE_SLOTS = 256, + MAX_FILE_SLOTS = 300, }; /** Deals with finding savegames */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index edf34ba5f9..500c34c4cb 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1179,7 +1179,7 @@ struct NetworkStartServerWindow : public Window { } case WID_NSS_GENERATE_GAME: // Start game - if ((uint) CountSelectedGRFs (_grfconfig_newgame) > NETWORK_MAX_GRF_COUNT) { + if (CountSelectedGRFs(_grfconfig_newgame) > NETWORK_MAX_GRF_COUNT) { ShowErrorMessage(STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, INVALID_STRING_ID, WL_ERROR); break; } diff --git a/src/newgrf.cpp b/src/newgrf.cpp index b61db5918e..65eb1d7784 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -9271,7 +9271,7 @@ void LoadNewGRF(uint load_index, uint file_index, uint num_baseset) if (stage == GLS_LABELSCAN) InitNewGRFFile(c); if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) { - if (num_non_static == NETWORK_MAX_GRF_COUNT) { + if ((_networking && num_non_static == NETWORK_MAX_GRF_COUNT) || slot == MAX_FILE_SLOTS) { DEBUG(grf, 0, "'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename); c->status = GCS_DISABLED; c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED); @@ -9314,12 +9314,13 @@ void LoadNewGRF(uint load_index, uint file_index, uint num_baseset) /** * Returns amount of user selected NewGRFs files. */ -int CountSelectedGRFs(GRFConfig *grfconf) +uint CountSelectedGRFs(GRFConfig *grfconf) { - int i = 0; + uint i = 0; /* Find last entry in the list */ - for (const GRFConfig *list = grfconf; list != NULL; list = list->next, i++) { + for (const GRFConfig *list = grfconf; list != NULL; list = list->next) { + if (!HasBit(list->flags, GCF_STATIC) && !HasBit(list->flags, GCF_SYSTEM)) i++; } return i; } diff --git a/src/newgrf.h b/src/newgrf.h index c08b5476f8..5a8217b27f 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -194,7 +194,7 @@ bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile); StringID MapGRFStringID(uint32 grfid, StringID str); void ShowNewGRFError(); -int CountSelectedGRFs(GRFConfig *grfconf); +uint CountSelectedGRFs(GRFConfig *grfconf); struct TemplateVehicle; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 6ef07deb20..adda456e87 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1521,7 +1521,7 @@ private: if (!HasBit((*list)->flags, GCF_STATIC)) count++; } if (entry == NULL) entry = list; - if (count >= NETWORK_MAX_GRF_COUNT) { + if (count >= MAX_NEWGRFS) { ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO); return false; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 61b932e3ff..628297d1bf 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -741,6 +741,13 @@ bool AfterLoadGame() return false; } + if (_networking && CountSelectedGRFs(_grfconfig) > NETWORK_MAX_GRF_COUNT) { + SetSaveLoadError(STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED); + /* Restore the signals */ + ResetSignalHandlers(); + return false; + } + /* The value of _date_fract got divided, so make sure that old games are converted correctly. */ if (IsSavegameVersionBefore(11, 1) || (IsSavegameVersionBefore(147) && _date_fract > DAY_TICKS)) _date_fract /= 885;