Batch #1614 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_18182 ResourceMgr::Exists: logic confirmed by peer review Reviewed-by: ragnarok-clanker Adds to the build: Source/Resource/ResourcePresence.cpp
39 lines
1,002 B
C++
39 lines
1,002 B
C++
#include "File/ResourcePath.h"
|
|
#include "Resource/ResourceMgr.h"
|
|
#include "Utility/Text/GroupedInteger.h"
|
|
|
|
#include <string>
|
|
#include <windows.h>
|
|
#include <timeapi.h>
|
|
|
|
// OFFSET: 0x00AEF940
|
|
// FUNCTION: fn_18182
|
|
bool ResourceMgr::Exists(std::string name) {
|
|
const char* text = name.c_str();
|
|
if (!text) {
|
|
return false;
|
|
}
|
|
|
|
char normalized[260] = {};
|
|
strncpy_s(normalized, sizeof(normalized), text, _TRUNCATE);
|
|
|
|
for (unsigned char* byte = reinterpret_cast<unsigned char*>(normalized); *byte; ++byte) {
|
|
if (*byte >= 'A' && *byte <= 'Z') {
|
|
*byte += 'a' - 'A';
|
|
}
|
|
}
|
|
|
|
const char* dot = ReverseFindChar(normalized, '.');
|
|
const int type = this->FindType(dot ? dot + 1 : nullptr);
|
|
if (type < 0) {
|
|
return false;
|
|
}
|
|
|
|
const std::string resolved = AddResourcePrefix(normalized, this->m_prefixes[type]);
|
|
if (CRes* existing = this->Find(type, resolved.c_str())) {
|
|
existing->lastUse = timeGetTime();
|
|
return true;
|
|
}
|
|
|
|
return ResourceExists(resolved.c_str(), 0);
|
|
}
|