29 SoundID sound_id = _cur_gps.file->ReadWord();
32 if (file ==
nullptr || file->sound_offset == 0) {
33 GrfMsg(1,
"ImportGRFSound: Source file not available");
37 if (sound_id >= file->num_sounds) {
38 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
42 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {}", sound_id, file->sound_offset + sound_id,
FormatArrayAsHex(grfid));
44 *sound = *GetSound(file->sound_offset + sound_id);
47 sound->volume = SOUND_EFFECT_MAX_VOLUME;
59 sound->volume = SOUND_EFFECT_MAX_VOLUME;
62 if (offs != SIZE_MAX) {
64 sound->file = _cur_gps.file;
65 sound->file_offset = offs;
82 if (_cur_gps.grffile->sound_offset == 0) {
83 _cur_gps.grffile->sound_offset = GetNumSounds();
84 _cur_gps.grffile->num_sounds = num;
87 sound = GetSound(_cur_gps.grffile->sound_offset);
92 for (
int i = 0; i < num; i++) {
97 bool invalid = i >= _cur_gps.grffile->num_sounds;
99 size_t offs = file.
GetPos();
104 if (grf_container_version >= 2 && type == 0xFD) {
107 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
109 }
else if (len != 4) {
110 GrfMsg(1,
"GRFSound: Invalid sprite section import");
120 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
127 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
136 if (grf_container_version >= 2) {
137 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
149 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
157 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
171 _cur_gps.skip_sprites = buf.
ReadWord();
173 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur_gps.skip_sprites);
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
size_t GetPos() const
Get position in the file.
uint8_t ReadByte()
Read a byte from the file.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
void SkipBytes(size_t n)
Skip n bytes ahead in the file.
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
RandomAccessFile with some extra information specific for sprite files.
uint8_t GetContainerVersion() const
Get the version number of container type used by the file.
Functions related to debugging.
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
GRFFile * GetFileByGRFID(GrfID grfid)
Obtain a NewGRF file by its grfID.
@ Init
Second step of NewGRF loading; load all actions into memory.
@ Activation
Forth step of NewGRF loading; activate the features.
constexpr T UnflattenNewGRFLabel(uint32_t value)
Unflatten a NewGRF related label from a 32 bits integer.
static void LoadGRFSound(size_t offs, SoundEntry *sound)
Load a sound from a file.
static void ImportGRFSound(SoundEntry *sound)
Process a sound import from another GRF file.
NewGRF buffer reader definition.
Functions related to NewGRF houses.
NewGRF internal processing state.
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
Functions related to NewGRF provided sounds.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
A number of safeguards to prevent using unsafe methods.
@ NewGRF
Contained within a NewGRF.
size_t GetGRFSpriteOffset(uint32_t id)
Get the file offset for a specific sprite in the sprite section of a GRF.
bool SkipSpriteData(SpriteFile &file, uint8_t type, uint16_t num)
Skip the given amount of sprite graphics data.
Functions to cache sprites in memory.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Functions related to low-level strings.
Dynamic data of a loaded NewGRF.
static void FileScan(ByteReader &buf)
Implementation of the GrfLoadingStage::FileScan stage of this action.
static void SafetyScan(ByteReader &buf)
Implementation of the GrfLoadingStage::SafetyScan stage of this action.
static void Reserve(ByteReader &buf)
Implementation of the GrfLoadingStage::Reserve stage of this action.
static void Activation(ByteReader &buf)
Implementation of the GrfLoadingStage::Activation stage of this action.
static void Init(ByteReader &buf)
Implementation of the GrfLoadingStage::Init stage of this action.
static void LabelScan(ByteReader &buf)
Implementation of the GrfLoadingStage::LabelScan stage of this action.
uint8_t grf_container_ver
NewGRF container version if the sound is from a NewGRF.