diff --git a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp index 994a6349..94535b56 100644 --- a/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IFxEffectDef.cpp @@ -21,7 +21,7 @@ namespace Assets { if (visuals->model) { - visuals->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, reader->readString().data(), builder).model; + visuals->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, reader->readString(), builder).model; } break; @@ -44,7 +44,7 @@ namespace Assets { if (visuals->effectDef.handle) { - visuals->effectDef.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, reader->readString().data(), builder).fx; + visuals->effectDef.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, reader->readString(), builder).fx; } break; @@ -54,7 +54,7 @@ namespace Assets { if (visuals->material) { - visuals->material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader->readString().data(), builder).material; + visuals->material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader->readString(), builder).material; } break; @@ -120,12 +120,12 @@ namespace Assets { if (elemDef->visuals.markArray[j].materials[0]) { - elemDef->visuals.markArray[j].materials[0] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, buffer.readString().data(), builder).material; + elemDef->visuals.markArray[j].materials[0] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, buffer.readString(), builder).material; } if (elemDef->visuals.markArray[j].materials[1]) { - elemDef->visuals.markArray[j].materials[1] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, buffer.readString().data(), builder).material; + elemDef->visuals.markArray[j].materials[1] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, buffer.readString(), builder).material; } } } @@ -150,17 +150,17 @@ namespace Assets if (elemDef->effectOnImpact.handle) { - elemDef->effectOnImpact.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString().data(), builder).fx; + elemDef->effectOnImpact.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString(), builder).fx; } if (elemDef->effectOnDeath.handle) { - elemDef->effectOnDeath.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString().data(), builder).fx; + elemDef->effectOnDeath.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString(), builder).fx; } if (elemDef->effectEmitted.handle) { - elemDef->effectEmitted.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString().data(), builder).fx; + elemDef->effectEmitted.handle = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_FX, buffer.readString(), builder).fx; } // Save_FxElemExtendedDefPtr diff --git a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp index 3c7bfee4..4ff564c6 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxImage.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxImage.cpp @@ -67,7 +67,7 @@ namespace Assets } else if (name[0] != '*') { - char nameBuffer[MAX_PATH] = { 0 }; + char nameBuffer[MAX_PATH]{}; Components::Materials::FormatImagePath(nameBuffer, sizeof(nameBuffer), 0, 0, name.data()); Components::FileSystem::File iwi(nameBuffer); diff --git a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp index c2e58c70..ca029d05 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxLightDef.cpp @@ -36,7 +36,7 @@ namespace Assets if (asset->attenuation.image) { - asset->attenuation.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString().data(), builder).image; + asset->attenuation.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString(), builder).image; } } } diff --git a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp index 8548c309..44eab247 100644 --- a/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp +++ b/src/Components/Modules/AssetInterfaces/IGfxWorld.cpp @@ -48,7 +48,7 @@ namespace Assets if (surface->material) { - world->dpvs.surfaces[i].material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader->readString().data(), builder).material; + world->dpvs.surfaces[i].material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader->readString(), builder).material; } } } @@ -70,7 +70,7 @@ namespace Assets { auto name = reader->readString(); - model->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, name.data(), builder).model; + model->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, name, builder).model; assert(model->model); } @@ -86,7 +86,7 @@ namespace Assets for (unsigned int i = 0; i < asset->reflectionProbeCount; ++i) { - asset->reflectionProbes[i] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString().data(), builder).image; + asset->reflectionProbes[i] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString(), builder).image; } } @@ -105,24 +105,24 @@ namespace Assets if (lightmapArray->primary) { - lightmapArray->primary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString().data(), builder).image; + lightmapArray->primary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString(), builder).image; } if (lightmapArray->secondary) { - lightmapArray->secondary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString().data(), builder).image; + lightmapArray->secondary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString(), builder).image; } } } if (asset->lightmapOverridePrimary) { - asset->lightmapOverridePrimary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString().data(), builder).image; + asset->lightmapOverridePrimary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString(), builder).image; } if (asset->lightmapOverrideSecondary) { - asset->lightmapOverrideSecondary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString().data(), builder).image; + asset->lightmapOverrideSecondary = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader->readString(), builder).image; } // saveGfxWorldVertexData @@ -200,7 +200,7 @@ namespace Assets if (sky->skyImage) { - sky->skyImage = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString().data(), builder).image; + sky->skyImage = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString(), builder).image; } } } @@ -348,24 +348,24 @@ namespace Assets if (materialMemory->material) { - materialMemory->material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString().data(), builder).material; + materialMemory->material = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString(), builder).material; } } } if (asset->sun.spriteMaterial) { - asset->sun.spriteMaterial = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString().data(), builder).material; + asset->sun.spriteMaterial = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString(), builder).material; } if (asset->sun.flareMaterial) { - asset->sun.flareMaterial = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString().data(), builder).material; + asset->sun.flareMaterial = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.readString(), builder).material; } if (asset->outdoorImage) { - asset->outdoorImage = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString().data(), builder).image; + asset->outdoorImage = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString(), builder).image; } if (asset->primaryLightCount > 0) diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp index d651e99a..5f22deea 100644 --- a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp @@ -94,7 +94,7 @@ namespace Assets return; } - sound->name = builder->getAllocator()->duplicateString(name.data()); + sound->name = builder->getAllocator()->duplicateString(name); header->loadSnd = sound; } diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index ebe509e2..44116037 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -140,7 +140,7 @@ namespace Assets { auto imageName = waterJson["image"].get(); - water->image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, imageName.data(), builder).image; + water->image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, imageName, builder).image; } water->amplitude = waterJson["amplitude"].get(); @@ -426,7 +426,7 @@ namespace Assets Game::MaterialTechniqueSet* techset; // Pass 1: Identical techset (1:1) - techset = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, techsetName.data(), builder).techniqueSet; + techset = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, techsetName, builder).techniqueSet; if (techset != nullptr) { return techset; @@ -485,7 +485,7 @@ namespace Assets { std::string techsetName = reader.readString(); if (!techsetName.empty() && techsetName.front() == ',') techsetName.erase(techsetName.begin()); - asset->techniqueSet = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, techsetName.data(), builder).techniqueSet; + asset->techniqueSet = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, techsetName, builder).techniqueSet; if (!asset->techniqueSet) { @@ -499,7 +499,7 @@ namespace Assets for (int i = 0; i < ARRAYSIZE(techsetSuffix); ++i) { - Game::MaterialTechniqueSet* techsetPtr = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, (techsetName + techsetSuffix[i] + suffix).data(), builder).techniqueSet; + Game::MaterialTechniqueSet* techsetPtr = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_TECHNIQUE_SET, (techsetName + techsetSuffix[i] + suffix), builder).techniqueSet; if (techsetPtr) { @@ -550,13 +550,13 @@ namespace Assets if (water->image) { - water->image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString().data(), builder).image; + water->image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString(), builder).image; } } } else if (textureDef->u.image) { - textureDef->u.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString().data(), builder).image; + textureDef->u.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, reader.readString(), builder).image; } } } diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 949ff759..5b8bcfcd 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -242,6 +242,12 @@ namespace Components void Debug::CG_DrawDebugOverlays_Hk(const int localClientNum) { + assert(DebugOverlay); + if (!DebugOverlay) + { + return; + } + switch (DebugOverlay->current.integer) { case 2: diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index c1e446b7..c6db9af7 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -80,11 +80,12 @@ namespace Components void Logger::ErrorInternal(const Game::errorParm_t error, const std::string_view& fmt, std::format_args&& args) { + const auto msg = std::vformat(fmt, args); + #ifdef _DEBUG if (IsDebuggerPresent()) __debugbreak(); #endif - const auto msg = std::vformat(fmt, args); Game::Com_Error(error, "%s", msg.data()); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 5297d176..04840947 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -2497,24 +2497,121 @@ namespace Game SAT_COUNT = 0x4, }; - struct SoundFile + struct snd_volume_info_t { - char type; - char exists; - SoundFileRef u; + float volume; + float goalvolume; + float goalrate; }; - union $C8D87EB0090687D323381DFB7A82089C + struct snd_channelvolgroup { - float slavePercentage; - float masterPercentage; + snd_volume_info_t channelvol[64]; + bool active; }; - struct SndCurve + struct snd_background_info_t { - const char* filename; - unsigned __int16 knotCount; - float knots[16][2]; + float goalvolume; + float goalrate; + }; + + struct snd_enveffect + { + int roomtype; + float drylevel; + float drygoal; + float dryrate; + float wetlevel; + float wetgoal; + float wetrate; + bool active; + }; + + struct orientation_t + { + float origin[3]; + float axis[3][3]; + }; + + struct snd_listener + { + orientation_t orient; + float velocity; + int clientNum; + bool active; + }; + + struct snd_amplifier + { + snd_listener* listener; + int minRadius; + int maxRadius; + float falloffExp; + float minVol; + float maxVol; + }; + + struct snd_entchannel_info_t + { + char name[64]; + int priority; + bool is3d; + bool isRestricted; + bool isPausable; + int maxVoices; + int voiceCount; + }; + + struct snd_entchan_overrides_t + { + unsigned int isPausable[2]; + float timescaleLerp[64]; + }; + + enum SndFileLoadingState + { + SFLS_UNLOADED = 0x0, + SFLS_LOADING = 0x1, + SFLS_LOADED = 0x2, + }; + + struct SndFileSpecificChannelInfo + { + SndFileLoadingState loadingState; + int srcChannelCount; + int baserate; + }; + + union SndEntHandle + { + struct + { + unsigned int entIndex; + } field; + int handle; + }; + + enum SndLengthId + { + SndLengthNotify_Subtitle = 0x0, + SndLengthNotify_EntityCustom = 0x1, + SndLengthNotifyCount = 0x2, + }; + + struct sndLengthNotifyInfo + { + SndLengthId id[4]; + void* data[4]; + int count; + }; + + enum snd_alias_system_t + { + SASYS_UI = 0x0, + SASYS_CGAME = 0x1, + SASYS_GAME = 0x2, + SASYS_COUNT = 0x3, }; struct MSSSpeakerLevels @@ -2537,7 +2634,21 @@ namespace Game MSSChannelMap channelMaps[2][2]; }; - const struct snd_alias_t + struct SoundFile + { + char type; + char exists; + SoundFileRef u; + }; + + struct SndCurve + { + const char* filename; + unsigned __int16 knotCount; + float knots[16][2]; + }; + + struct snd_alias_t { const char* aliasName; const char* subtitle; @@ -2554,7 +2665,11 @@ namespace Game float distMax; float velocityMin; int flags; - $C8D87EB0090687D323381DFB7A82089C ___u15; + union + { + float slavePercentage; + float masterPercentage; + } ___u15; float probability; float lfePercentage; float centerPercentage; @@ -2566,6 +2681,71 @@ namespace Game SpeakerMap* speakerMap; }; + struct snd_channel_info_t + { + SndFileSpecificChannelInfo soundFileInfo; + SndEntHandle sndEnt; + int entchannel; + int startDelay; + int looptime; + int totalMsec; + int playbackId; + sndLengthNotifyInfo lengthNotifyInfo; + float basevolume; + float pitch; + snd_alias_t* alias0; + snd_alias_t* alias1; + int saveIndex0; + int saveIndex1; + float lerp; + float org[3]; + float offset[3]; + bool paused; + bool master; + float timescaleLerp; + snd_alias_system_t system; + }; + + struct snd_local_t + { + bool Initialized2d; + bool Initialized3d; + bool paused; + int playbackIdCounter; + unsigned int playback_rate; + int playback_channels; + float timescale; + int pausetime; + int cpu; + struct + { + char buffer[16384]; + volatile int size; + bool compress; + } restore; + float volume; + snd_volume_info_t mastervol; + snd_channelvolgroup channelVolGroups[4]; + snd_channelvolgroup* channelvol; + snd_background_info_t background[4]; + int ambient_track; + float slaveLerp; + float masterPercentage; + snd_enveffect envEffects[5]; + snd_enveffect* effect; + snd_listener listeners[2]; + int time; + int looptime; + snd_amplifier amplifier; + snd_entchannel_info_t entchaninfo[64]; + snd_entchan_overrides_t entchanOverrides; + int entchannel_count; + snd_channel_info_t chaninfo[52]; + int max_2D_channels; + int max_3D_channels; + int max_stream_channels; + }; + struct Poly { float(*pts)[3]; diff --git a/src/Utils/Stream.cpp b/src/Utils/Stream.cpp index dc50f51c..7aa0d189 100644 --- a/src/Utils/Stream.cpp +++ b/src/Utils/Stream.cpp @@ -16,14 +16,14 @@ namespace Utils const char* Stream::Reader::readCString() { - return this->allocator->duplicateString(this->readString()); + return this->allocator_->duplicateString(this->readString()); } char Stream::Reader::readByte() { - if ((this->position + 1) <= this->buffer.size()) + if ((this->position_ + 1) <= this->buffer_.size()) { - return this->buffer[this->position++]; + return this->buffer_[this->position_++]; } throw std::runtime_error("Reading past the buffer"); @@ -33,43 +33,43 @@ namespace Utils { size_t bytes = size * count; - if ((this->position + bytes) <= this->buffer.size()) + if ((this->position_ + bytes) <= this->buffer_.size()) { - void* _buffer = this->allocator->allocate(bytes); + void* buffer = this->allocator_->allocate(bytes); - std::memcpy(_buffer, this->buffer.data() + this->position, bytes); - this->position += bytes; + std::memcpy(buffer, this->buffer_.data() + this->position_, bytes); + this->position_ += bytes; - return _buffer; + return buffer; } throw std::runtime_error("Reading past the buffer"); } - bool Stream::Reader::end() + bool Stream::Reader::end() const { - return (this->buffer.size() == this->position); + return (this->buffer_.size() == this->position_); } - void Stream::Reader::seek(unsigned int _position) + void Stream::Reader::seek(unsigned int position) { - if (this->buffer.size() >= _position) + if (this->buffer_.size() >= position) { - this->position = _position; + this->position_ = position; } } - void Stream::Reader::seekRelative(unsigned int _position) + void Stream::Reader::seekRelative(unsigned int position) { - return this->seek(_position + this->position); + return this->seek(position + this->position_); } void* Stream::Reader::readPointer() { - void* pointer = this->read(); + auto* pointer = this->read(); if (!this->hasPointer(pointer)) { - this->pointerMap[pointer] = nullptr; + this->pointerMap_[pointer] = nullptr; } return pointer; } @@ -78,18 +78,18 @@ namespace Utils { if (this->hasPointer(oldPointer)) { - this->pointerMap[oldPointer] = newPointer; + this->pointerMap_[oldPointer] = newPointer; } } - bool Stream::Reader::hasPointer(void* pointer) + bool Stream::Reader::hasPointer(void* pointer) const { - return this->pointerMap.find(pointer) != this->pointerMap.end(); + return this->pointerMap_.find(pointer) != this->pointerMap_.end(); } Stream::Stream() : ptrAssertion(false), criticalSectionState(0) { - memset(this->blockSize, 0, sizeof(this->blockSize)); + std::memset(this->blockSize, 0, sizeof(this->blockSize)); #ifdef WRITE_LOGS this->structLevel = 0; @@ -99,12 +99,12 @@ namespace Utils Stream::Stream(size_t size) : Stream() { - this->buffer.reserve(size); + this->buffer_.reserve(size); } Stream::~Stream() { - this->buffer.clear(); + this->buffer_.clear(); if (this->criticalSectionState != 0) { @@ -114,12 +114,12 @@ namespace Utils std::size_t Stream::length() const { - return this->buffer.length(); + return this->buffer_.length(); } std::size_t Stream::capacity() const { - return this->buffer.capacity(); + return this->buffer_.capacity(); } void Stream::assertPointer(const void* pointer, std::size_t length) @@ -143,12 +143,12 @@ namespace Utils this->ptrList.push_back({ pointer, length }); } - char* Stream::save(const void* _str, std::size_t size, std::size_t count) + char* Stream::save(const void* str, std::size_t size, std::size_t count) { - return this->save(this->getCurrentBlock(), _str, size, count); + return this->save(this->getCurrentBlock(), str, size, count); } - char* Stream::save(Game::XFILE_BLOCK_TYPES stream, const void * _str, std::size_t size, std::size_t count) + char* Stream::save(Game::XFILE_BLOCK_TYPES stream, const void * str, std::size_t size, std::size_t count) { // Only those seem to actually write data. // everything else is allocated at runtime but XFILE_BLOCK_RUNTIME is the only one that actually allocates anything @@ -167,7 +167,7 @@ namespace Utils __debugbreak(); } - this->buffer.append(static_cast(_str), size * count); + this->buffer_.append(static_cast(str), size * count); if (this->data() != data && this->isCriticalSection()) { @@ -176,7 +176,7 @@ namespace Utils } this->increaseBlockSize(stream, size * count); - this->assertPointer(_str, size * count); + this->assertPointer(str, size * count); return this->at() - (size * count); } @@ -319,7 +319,7 @@ namespace Utils char* Stream::data() { - return const_cast(this->buffer.data()); + return const_cast(this->buffer_.data()); } unsigned int Stream::getBlockSize(Game::XFILE_BLOCK_TYPES stream) @@ -350,9 +350,9 @@ namespace Utils std::string Stream::toBuffer() { - std::string _buffer; - this->toBuffer(_buffer); - return _buffer; + std::string buffer; + this->toBuffer(buffer); + return buffer; } void Stream::enterCriticalSection() diff --git a/src/Utils/Stream.hpp b/src/Utils/Stream.hpp index 3739cc3a..18970c58 100644 --- a/src/Utils/Stream.hpp +++ b/src/Utils/Stream.hpp @@ -21,13 +21,13 @@ namespace Utils int criticalSectionState; unsigned int blockSize[Game::MAX_XFILE_COUNT]; std::vector streamStack; - std::string buffer; + std::string buffer_; public: class Reader { public: - Reader(Memory::Allocator* _allocator, const std::string& _buffer) : position(0), buffer(_buffer), allocator(_allocator) {} + Reader(Memory::Allocator* allocator, std::string buffer) : position_(0), buffer_(std::move(buffer)), allocator_(allocator) {} std::string readString(); const char* readCString(); @@ -53,18 +53,18 @@ namespace Utils auto ptr = read(); auto* voidPtr = reinterpret_cast(ptr); - if (allocator->isPointerMapped(voidPtr)) + if (allocator_->isPointerMapped(voidPtr)) { - return allocator->getPointer(voidPtr); + return allocator_->getPointer(voidPtr); } throw std::runtime_error("Bad data: missing ptr"); } case FOLLOWING: { - auto filePosition = position; + auto filePosition = position_; auto data = readArray(count); - allocator->mapPointer(reinterpret_cast(filePosition), data); + allocator_->mapPointer(reinterpret_cast(filePosition), data); return data; } default: @@ -89,19 +89,19 @@ namespace Utils return obj; } - bool end(); + bool end() const; void seek(unsigned int position); void seekRelative(unsigned int position); void* readPointer(); void mapPointer(void* oldPointer, void* newPointer); - bool hasPointer(void* pointer); + bool hasPointer(void* pointer) const; private: - unsigned int position; - std::string buffer; - std::map pointerMap; - Memory::Allocator* allocator; + unsigned int position_; + std::string buffer_; + std::map pointerMap_; + Memory::Allocator* allocator_; }; enum Alignment