Skip to content

Commit 62870da

Browse files
fix: unintentional filename conflicts within raw_models in streaming (#120)
* Fix for unintentional filename conflicts within raw_models in streaming * Inline comparison in lambda * std.stream: store pre-init raw_models in a multimap by filename Same basename in different .img paths no longer overwrites earlier entries. Look up and remove with equal_range/find_if instead of linear scan or erase-by-key. --------- Co-authored-by: Denilson Amorim <denimorim@gmail.com>
1 parent 18f85c2 commit 62870da

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/plugins/gta3/std.stream/data.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ std::string CAbstractStreaming::TryLoadNonStreamedResource(std::string filepath,
8282

8383
if(!this->bHasInitializedStreaming)
8484
{
85-
auto it = this->raw_models.find(filename);
86-
if(it != this->raw_models.end())
85+
const auto range = this->raw_models.equal_range(filename);
86+
auto it = range.first;
87+
if(it != range.second)
8788
{
8889
// Log about non streamed resource and make sure it's unique
8990
plugin_ptr->Log("Using non-streamed resource \"%s\"", it->second->filepath());

src/plugins/gta3/std.stream/streaming.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ bool CAbstractStreaming::InstallFile(const modloader::file& file)
202202
// Just push it to this list and it will get loaded when the streaming initializes
203203
// At this point we don't know if this is a clothing item or an model, for that reason "raw"
204204
// The initializer will take care of filtering clothes and models from the list
205-
this->raw_models[file.filename()] = &file;
205+
this->raw_models.insert({ file.filename(), &file });
206206
return true;
207207
}
208208
else
@@ -242,7 +242,13 @@ bool CAbstractStreaming::UninstallFile(const modloader::file& file)
242242
return false;
243243

244244
// Streaming hasn't initialized, just remove it from our raw list
245-
raw_models.erase(file.filename());
245+
const auto range = this->raw_models.equal_range(file.filename());
246+
const auto it = std::find_if(range.first, range.second, [&file](const auto& p) {
247+
return p.second == &file;
248+
});
249+
if(it != range.second)
250+
this->raw_models.erase(it);
251+
246252
return true;
247253
}
248254
else

src/plugins/gta3/std.stream/streaming.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ class CAbstractStreaming
226226
std::map<id_t, id_t> prev_on_cd; // Original InfoForModel next on cd information, <next, prev>
227227

228228
// Custom files
229-
std::map<std::string, const modloader::file*> raw_models; // Models installed before the streaming initialization ---- (sorted by name!!)
230-
std::map<id_t, ModelInfo> imports; // Imported abstract models
231-
std::map<hash_t, const modloader::file*> special; // Abstract special models ---- (imported by me) (hashed filename has no extension)
232-
std::map<uint32_t, const modloader::file*> clothes; // Imported abstract clothes --- (key is offset)
233-
std::map<hash_t, NonStreamedInfo_t> non_stream; // Non streamed resources (requested by default.dat/gta.dat) (.second.first may be nullptr)
229+
std::multimap<std::string, const modloader::file*> raw_models; // Models installed before the streaming initialization. Sorted by name. Duplicates allowed (e.g. coach.dff which is both a streaming and a clothing item)
230+
std::map<id_t, ModelInfo> imports; // Imported abstract models
231+
std::map<hash_t, const modloader::file*> special; // Abstract special models ---- (imported by me) (hashed filename has no extension)
232+
std::map<uint32_t, const modloader::file*> clothes; // Imported abstract clothes --- (key is offset)
233+
std::map<hash_t, NonStreamedInfo_t> non_stream; // Non streamed resources (requested by default.dat/gta.dat) (.second.first may be nullptr)
234234

235235
// Information for refreshing
236236
std::map<hash_t, const modloader::file*> to_import; // Files to be imported by the refresher --- (null pointer on mapped piece means uninstall)

0 commit comments

Comments
 (0)