Update: Translations from eints
[openttd-github.git] / src / spriteloader / sprite_file.cpp
blob82498cf83e051d57e67e9493c7c724b1c5692267
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file sprite_file.cpp Implementation of logic specific to the SpriteFile class. */
10 #include "../stdafx.h"
11 #include "sprite_file_type.hpp"
13 /** Signature of a container version 2 GRF. */
14 extern const uint8_t _grf_cont_v2_sig[8] = {'G', 'R', 'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A};
16 /**
17 * Get the container version of the currently opened GRF file.
18 * @return Container version of the GRF file or 0 if the file is corrupt/no GRF file.
20 static uint8_t GetGRFContainerVersion(SpriteFile &file)
22 size_t pos = file.GetPos();
24 if (file.ReadWord() == 0) {
25 /* Check for GRF container version 2, which is identified by the bytes
26 * '47 52 46 82 0D 0A 1A 0A' at the start of the file. */
27 for (const auto &expected_sig_byte : _grf_cont_v2_sig) {
28 if (file.ReadByte() != expected_sig_byte) return 0; // Invalid format
31 return 2;
34 /* Container version 1 has no header, rewind to start. */
35 file.SeekTo(pos, SEEK_SET);
36 return 1;
39 /**
40 * Create the SpriteFile.
41 * @param filename Name of the file at the disk.
42 * @param subdir The sub directory to search this file in.
43 * @param palette_remap Whether a palette remap needs to be performed for this file.
45 SpriteFile::SpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap)
46 : RandomAccessFile(filename, subdir), palette_remap(palette_remap)
48 this->container_version = GetGRFContainerVersion(*this);
49 this->content_begin = this->GetPos();