mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Detect self-patching in pfPatcher
This commit is contained in:
@ -89,6 +89,10 @@ struct pfPatcherWorker : public hsThread
|
|||||||
|
|
||||||
// Any file
|
// Any file
|
||||||
kFlagZipped = 1<<3,
|
kFlagZipped = 1<<3,
|
||||||
|
|
||||||
|
// Begin internal flags
|
||||||
|
kLastManifestFlag = 1<<4,
|
||||||
|
kSelfPatch = 1<<5,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::deque<Request> fRequests;
|
std::deque<Request> fRequests;
|
||||||
@ -103,6 +107,7 @@ struct pfPatcherWorker : public hsThread
|
|||||||
pfPatcher::FileDownloadFunc fFileDownloaded;
|
pfPatcher::FileDownloadFunc fFileDownloaded;
|
||||||
pfPatcher::GameCodeDiscoverFunc fGameCodeDiscovered;
|
pfPatcher::GameCodeDiscoverFunc fGameCodeDiscovered;
|
||||||
pfPatcher::ProgressTickFunc fProgressTick;
|
pfPatcher::ProgressTickFunc fProgressTick;
|
||||||
|
pfPatcher::FileDownloadFunc fSelfPatch;
|
||||||
|
|
||||||
pfPatcher* fParent;
|
pfPatcher* fParent;
|
||||||
volatile bool fStarted;
|
volatile bool fStarted;
|
||||||
@ -199,6 +204,7 @@ public:
|
|||||||
|
|
||||||
void Begin() { fDLStartTime = hsTimer::GetSysSeconds(); }
|
void Begin() { fDLStartTime = hsTimer::GetSysSeconds(); }
|
||||||
plFileName GetFileName() const { return fFilename; }
|
plFileName GetFileName() const { return fFilename; }
|
||||||
|
bool IsSelfPatch() const { return hsCheckBits(fFlags, pfPatcherWorker::kSelfPatch); }
|
||||||
void Unlink() const { plFileSystem::Unlink(fFilename); }
|
void Unlink() const { plFileSystem::Unlink(fFilename); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -306,6 +312,8 @@ static void IFileThingDownloadCB(ENetError result, void* param, const plFileName
|
|||||||
if (IS_NET_SUCCESS(result)) {
|
if (IS_NET_SUCCESS(result)) {
|
||||||
PatcherLogGreen("\tDownloaded File '%s'", stream->GetFileName().AsString().c_str());
|
PatcherLogGreen("\tDownloaded File '%s'", stream->GetFileName().AsString().c_str());
|
||||||
patcher->WhitelistFile(stream->GetFileName(), true);
|
patcher->WhitelistFile(stream->GetFileName(), true);
|
||||||
|
if (patcher->fSelfPatch && stream->IsSelfPatch())
|
||||||
|
patcher->fSelfPatch(stream->GetFileName());
|
||||||
patcher->IssueRequest();
|
patcher->IssueRequest();
|
||||||
} else {
|
} else {
|
||||||
PatcherLogRed("\tDownloaded Failed: File '%s'", stream->GetFileName().AsString().c_str());
|
PatcherLogRed("\tDownloaded Failed: File '%s'", stream->GetFileName().AsString().c_str());
|
||||||
@ -454,7 +462,7 @@ hsError pfPatcherWorker::Run()
|
|||||||
void pfPatcherWorker::ProcessFile()
|
void pfPatcherWorker::ProcessFile()
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
const NetCliFileManifestEntry& entry = fQueuedFiles.front();
|
NetCliFileManifestEntry& entry = fQueuedFiles.front();
|
||||||
|
|
||||||
// eap sucks
|
// eap sucks
|
||||||
plFileName clName = plString::FromWchar(entry.clientName);
|
plFileName clName = plString::FromWchar(entry.clientName);
|
||||||
@ -478,6 +486,15 @@ void pfPatcherWorker::ProcessFile()
|
|||||||
PatcherLogYellow("\tEnqueuing '%S'", entry.clientName);
|
PatcherLogYellow("\tEnqueuing '%S'", entry.clientName);
|
||||||
plFileSystem::CreateDir(plFileName(clName).StripFileName());
|
plFileSystem::CreateDir(plFileName(clName).StripFileName());
|
||||||
|
|
||||||
|
// If someone registered for SelfPatch notifications, then we should probably
|
||||||
|
// let them handle the gruntwork... Otherwise, go nuts!
|
||||||
|
if (fSelfPatch) {
|
||||||
|
if (clName == plFileSystem::GetCurrentAppPath().GetFileName()) {
|
||||||
|
clName += ".tmp"; // don't overwrite myself!
|
||||||
|
entry.flags |= kSelfPatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pfPatcherStream* s = new pfPatcherStream(this, dlName, entry);
|
pfPatcherStream* s = new pfPatcherStream(this, dlName, entry);
|
||||||
s->Open(clName, "wb");
|
s->Open(clName, "wb");
|
||||||
|
|
||||||
@ -562,6 +579,11 @@ void pfPatcher::OnProgressTick(ProgressTickFunc cb)
|
|||||||
fWorker->fProgressTick = cb;
|
fWorker->fProgressTick = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pfPatcher::OnSelfPatch(FileDownloadFunc cb)
|
||||||
|
{
|
||||||
|
fWorker->fSelfPatch = cb;
|
||||||
|
}
|
||||||
|
|
||||||
// ===================================================
|
// ===================================================
|
||||||
|
|
||||||
void pfPatcher::RequestGameCode()
|
void pfPatcher::RequestGameCode()
|
||||||
|
@ -112,6 +112,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
void OnProgressTick(ProgressTickFunc cb);
|
void OnProgressTick(ProgressTickFunc cb);
|
||||||
|
|
||||||
|
/** This is called when the current application has been updated. */
|
||||||
|
void OnSelfPatch(FileDownloadFunc cb);
|
||||||
|
|
||||||
void RequestGameCode();
|
void RequestGameCode();
|
||||||
void RequestManifest(const plString& mfs);
|
void RequestManifest(const plString& mfs);
|
||||||
void RequestManifest(const std::vector<plString>& mfs);
|
void RequestManifest(const std::vector<plString>& mfs);
|
||||||
|
Reference in New Issue
Block a user