implement FileSystem::getLanguageMask and use it in ResolveReceiver

This commit is contained in:
Adam Jensen 2023-01-17 15:04:03 +00:00
parent f38ae7f91b
commit b7561871c3
9 changed files with 40 additions and 6 deletions

View File

@ -175,3 +175,11 @@ uint32_t ArchiveFileSystem::getSize(const char *path) {
return 0;
}
void ArchiveFileSystem::setLanguageMask(uint32_t mask) {
languageMask = mask;
}
uint32_t ArchiveFileSystem::getLanguageMask() {
return languageMask;
}

View File

@ -47,4 +47,6 @@ public:
cdc::FileRequest *createRequest(cdc::FileReceiver *receiver, const char *path, uint32_t offset) override;
cdc::File *createFile(const char *path) override;
uint32_t getSize(const char *path) override;
void setLanguageMask(uint32_t) override;
uint32_t getLanguageMask() override;
};

View File

@ -41,6 +41,8 @@ public:
virtual FileRequest *createRequest(FileReceiver*, const char*, uint32_t) = 0; // 00
virtual File *createFile(const char*) = 0; // 04
virtual uint32_t getSize(const char*) = 0; // 0C
virtual void setLanguageMask(uint32_t) = 0; // 1C
virtual uint32_t getLanguageMask() = 0; // 20
virtual bool hasRequests() = 0; // 2C
virtual void processRequest() = 0; // 30
virtual inline void processAll() { // 34

View File

@ -14,6 +14,14 @@ uint32_t FileSystemLayer::getSize(const char *path) {
return wrapped->getSize(path);
}
void FileSystemLayer::setLanguageMask(uint32_t mask) {
return wrapped->setLanguageMask(mask);
}
uint32_t FileSystemLayer::getLanguageMask() {
return wrapped->getLanguageMask();
}
bool FileSystemLayer::hasRequests() {
return wrapped->hasRequests();
}

View File

@ -12,6 +12,8 @@ public:
FileRequest *createRequest(FileReceiver*, const char*, uint32_t) override;
File *createFile(const char*) override;
uint32_t getSize(const char*) override;
void setLanguageMask(uint32_t) override;
uint32_t getLanguageMask() override;
bool hasRequests() override;
void processRequest() override;
void processAll() override;

View File

@ -68,6 +68,14 @@ uint32_t HackFileSystem::getSize(const char *path) {
return hf.getSize();
}
void HackFileSystem::setLanguageMask(uint32_t) {
// empty
}
uint32_t HackFileSystem::getLanguageMask() {
return 0;
}
bool HackFileSystem::hasRequests() {
return !requests.empty();
}

View File

@ -59,6 +59,8 @@ public:
FileRequest *createRequest(FileReceiver*, const char*, uint32_t) override;
File *createFile(const char*) override;
uint32_t getSize(const char*) override;
void setLanguageMask(uint32_t) override;
uint32_t getLanguageMask() override;
bool hasRequests() override;
void processRequest() override;
};

View File

@ -8,6 +8,7 @@
#include "ResolveObject.h"
#include "ResolveReceiver.h"
#include "ResolveSection.h"
#include "cdcFile/FileHelpers.h"
#include "cdcFile/FileSystem.h"
#include "cdcFile/FileUserBufferReceiver.h"
@ -174,6 +175,7 @@ std::vector<DRMSectionHeader> hackResolveReceiver(
std::vector<char> data,
ResolveSection **resolveSections,
ResolveObject *resolveObject,
uint32_t languageMask,
bool requestDependencies)
{
data = decompressCDRM(data);
@ -252,7 +254,7 @@ std::vector<DRMSectionHeader> hackResolveReceiver(
cursor = (cursor+15) & ~15;
auto *resolveSection = sectionHeader.type < 16 ? resolveSections[sectionHeader.type] : nullptr;
if (resolveSection && (sectionHeader.languageBits >> 30) != 1) {
if (resolveSection && (languageMask & sectionHeader.languageBits) == languageMask) {
bool alreadyLoaded = false;
uint32_t id = resolveSection->allocate(
sectionHeader.id,
@ -274,7 +276,7 @@ std::vector<DRMSectionHeader> hackResolveReceiver(
for (uint32_t i = 0; i < header.sectionCount; i++) {
DRMSectionHeader& sectionHeader = sectionHeaders[i];
if (relocPtrs[i] && (sectionHeader.languageBits >> 30) != 1)
if (relocPtrs[i] && (languageMask & sectionHeader.languageBits) == languageMask)
if (sectionHeader.unknown05)
applyRelocs(resolveSections, sectionHeaders.data(), sectionDomainIds.data(), i, relocPtrs[i]);
}
@ -282,7 +284,7 @@ std::vector<DRMSectionHeader> hackResolveReceiver(
for (uint32_t i = 0; i < header.sectionCount; i++) {
DRMSectionHeader& sectionHeader = sectionHeaders[i];
auto *resolveSection = sectionHeader.type < 16 ? resolveSections[sectionHeader.type] : nullptr;
if (resolveSection && (sectionHeader.languageBits >> 30) != 1)
if (resolveSection && (languageMask & sectionHeader.languageBits) == languageMask)
if (sectionHeader.unknown05)
resolveSection->construct(sectionDomainIds[i], nullptr);
}
@ -317,7 +319,7 @@ void hackResolveReceiver(FileSystem *fs, const char *path, ResolveSection **reso
// req is owned by fs which takes care of it in processAll()
delete file;
auto sectionHeaders = hackResolveReceiver(buffer, resolveSections, resolveObject);
auto sectionHeaders = hackResolveReceiver(buffer, resolveSections, resolveObject, fs->getLanguageMask());
if (index)
index->sectionHeaders[std::string(path)] = std::move(sectionHeaders);
}
@ -339,7 +341,7 @@ void ResolveReceiver::requestFailed(FileRequest *req) {
void ResolveReceiver::requestComplete(FileRequest *req) {
printf("loading %s\n", resolveObject->path);
auto sectionHeaders = hackResolveReceiver(std::move(buffer), g_resolveSections, resolveObject);
auto sectionHeaders = hackResolveReceiver(std::move(buffer), g_resolveSections, resolveObject, getDefaultFileSystem()->getLanguageMask());
if (sectionHeaders.empty()) {
// recreate this receiver, for a time when the dependencies have arrived

View File

@ -10,7 +10,7 @@ class ResolveObject;
struct ObjectTracker;
class ResolveSection;
std::vector<DRMSectionHeader> hackResolveReceiver(std::vector<char> data, ResolveSection **sections, ResolveObject *resolveObject, bool requestDependencies=true);
std::vector<DRMSectionHeader> hackResolveReceiver(std::vector<char> data, ResolveSection **sections, ResolveObject *resolveObject, uint32_t languageMask, bool requestDependencies=true);
void hackResolveReceiver(FileSystem *fs, const char *path, ResolveSection **sections, ResolveObject *resolveObject, DRMIndex *index=nullptr);
class ResolveReceiver : public FileReceiver {