From 8dc0522434e681a0b11518f9b1206a7b04f22305 Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 1 Jul 2014 20:13:23 +0000 Subject: [PATCH] (svn r26670) [1.4] -Backport from trunk: - Fix: CargoPacket::SourceStation() returns a StationID (r26660) - Fix: Production cheat cannot be allowed to be active in multiplayer for desync reasons, even when activated in singleplayer previously [FS#6044] (r26656) - Fix: Make sure an 'abs' is used that supports int64 when using 'abs' on those variables (r26651) - Fix: Support save/load chunk lengths of up to (1 << 32) - 1 [FS#6041] (r26650) --- src/cargopacket.h | 2 +- src/core/overflowsafe_type.hpp | 1 + src/industry_gui.cpp | 4 +++- src/saveload/saveload.cpp | 22 ++++++++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/cargopacket.h b/src/cargopacket.h index 5d0f671661..0ed4fd9bbc 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -157,7 +157,7 @@ public: * Gets the ID of the station where the cargo was loaded for the first time. * @return StationID. */ - inline SourceID SourceStation() const + inline StationID SourceStation() const { return this->source; } diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index cfc245c6cf..42ec98bd00 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -12,6 +12,7 @@ #ifndef OVERFLOWSAFE_TYPE_HPP #define OVERFLOWSAFE_TYPE_HPP +#include "math_func.hpp" /** * Overflow safe template for integers, i.e. integers that will never overflow diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 1351a64cd6..7c655bbb3a 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -24,6 +24,7 @@ #include "newgrf_industries.h" #include "newgrf_text.h" #include "newgrf_debug.h" +#include "network/network.h" #include "strings_func.h" #include "company_func.h" #include "tilehighlight_func.h" @@ -637,7 +638,8 @@ static inline bool IsProductionAlterable(const Industry *i) { const IndustrySpec *is = GetIndustrySpec(i->type); return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) && - (is->production_rate[0] != 0 || is->production_rate[1] != 0 || is->IsRawIndustry())); + (is->production_rate[0] != 0 || is->production_rate[1] != 0 || is->IsRawIndustry()) && + !_networking); } class IndustryViewWindow : public Window diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index d58fbc7ed7..229319b3b4 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -670,7 +670,11 @@ static uint SlReadSimpleGamma() if (HasBit(i, 5)) { i &= ~0x20; if (HasBit(i, 4)) { - SlErrorCorrupt("Unsupported gamma"); + i &= ~0x10; + if (HasBit(i, 3)) { + SlErrorCorrupt("Unsupported gamma"); + } + i = SlReadByte(); // 32 bits only. } i = (i << 8) | SlReadByte(); } @@ -690,6 +694,11 @@ static uint SlReadSimpleGamma() * 10xxxxxx xxxxxxxx * 110xxxxx xxxxxxxx xxxxxxxx * 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx + * 11110--- xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx + * We could extend the scheme ad infinum to support arbitrarily + * large chunks, but as sizeof(size_t) == 4 is still very common + * we don't support anything above 32 bits. That's why in the last + * case the 3 most significant bits are unused. * @param i Index being written */ @@ -698,8 +707,13 @@ static void SlWriteSimpleGamma(size_t i) if (i >= (1 << 7)) { if (i >= (1 << 14)) { if (i >= (1 << 21)) { - assert(i < (1 << 28)); - SlWriteByte((byte)(0xE0 | (i >> 24))); + if (i >= (1 << 28)) { + assert(i <= UINT32_MAX); // We can only support 32 bits for now. + SlWriteByte((byte)(0xF0)); + SlWriteByte((byte)(i >> 24)); + } else { + SlWriteByte((byte)(0xE0 | (i >> 24))); + } SlWriteByte((byte)(i >> 16)); } else { SlWriteByte((byte)(0xC0 | (i >> 16))); @@ -715,7 +729,7 @@ static void SlWriteSimpleGamma(size_t i) /** Return how many bytes used to encode a gamma value */ static inline uint SlGetGammaLength(size_t i) { - return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)); + return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)) + (i >= (1 << 28)); } static inline uint SlReadSparseIndex()