Skip to content

Commit

Permalink
Merge pull request #266 from dpogue/preserve-ids
Browse files Browse the repository at this point in the history
Add ResMgr option to preserve Object IDs
  • Loading branch information
zrax authored Mar 21, 2023
2 parents b56c71b + ba1d890 commit 5c02e85
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
13 changes: 8 additions & 5 deletions Tools/src/prcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ static void doHelp(const char* exename)
ST::printf("Usage: {} infile [options]\n", exename);
puts("");
puts("Options:");
puts("\t-o file Write output to `file`");
puts("\t-v ver Select output version (prime, pots, moul, eoa, hex, universal)");
puts("\t--help Display this help and then exit");
puts("\t-o file Write output to `file`");
puts("\t-v ver Select output version (prime, pots, moul, eoa, hex, universal)");
puts("\t--keep-ids Preserve the object IDs in the prc file");
puts("\t--help Display this help and then exit");
puts("");
}

int main(int argc, char* argv[])
{
ST::string inputFile, outputFile;
PlasmaVer outVer = PlasmaVer::pvUnknown;
bool keepIDs = false;

if (argc == 1) {
doHelp(argv[0]);
Expand Down Expand Up @@ -64,6 +66,8 @@ int main(int argc, char* argv[])
ST::printf(stderr, "Error: unrecognized version: {}\n", ver);
return 1;
}
} else if (strcmp(argv[i], "--keep-ids") == 0) {
keepIDs = true;
} else if (strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "--help") == 0) {
doHelp(argv[0]);
return 0;
Expand All @@ -82,8 +86,7 @@ int main(int argc, char* argv[])
}

plDebug::Init(plDebug::kDLAll);
plResManager rm;
rm.setVer(outVer, true);
plResManager rm(outVer, keepIDs);
hsFileStream S;
if (!S.open(inputFile, fmRead)) {
fputs("Error opening input file\n", stderr);
Expand Down
3 changes: 1 addition & 2 deletions Tools/src/prcdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ int main(int argc, char* argv[])
}

plDebug::Init(plDebug::kDLAll);
plResManager rm;
rm.setVer(inVer, true);
plResManager rm(inVer, true);

hsFileStream out;
out.open(outputFile, fmCreate);
Expand Down
4 changes: 4 additions & 0 deletions core/PRP/KeyedObject/plUoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ void plUoid::prcParse(const pfPrcTag* tag)
loadMask.prcParse(tag);
cloneID = tag->getParam("CloneID", "0").to_uint();
clonePlayerID = tag->getParam("ClonePlayerID", "0").to_uint();

unsigned int oid = tag->getParam("ObjID", "0").to_uint();
if (oid != 0)
objID = oid;
}

ST::string plUoid::toString() const
Expand Down
23 changes: 15 additions & 8 deletions core/ResManager/plResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ void plResManager::WritePage(hsStream* S, plPageInfo* page)
S->setVer(getVer());
std::vector<short> types = keys.getTypes(page->getLocation());
page->setClassList(types);
//keys.sortKeys(page->getLocation());

if (preserveIDs)
keys.sortKeys(page->getLocation());

page->write(S);
page->setDataStart(S->pos());
page->setNumObjects(WriteObjects(S, page->getLocation()));
Expand Down Expand Up @@ -510,7 +513,8 @@ unsigned int plResManager::ReadKeyring(hsStream* S, const plLocation& loc)
keys.setFlags(loc, type, flags);
}

keys.sortKeys(loc);
if (!preserveIDs)
keys.sortKeys(loc);

return pageKeys;
}
Expand Down Expand Up @@ -638,13 +642,16 @@ unsigned int plResManager::WriteObjects(hsStream* S, const plLocation& loc)
#endif
for (unsigned int j=0; j<kList.size(); j++) {
kList[j]->setFileOff(S->pos());
unsigned int objID = j + 1;
if (kList[j]->getID() != objID) {
plDebug::Warning("Object ID changing ({} -> {}) during write: [{04X}]:{}",
kList[j]->getID(), objID, kList[j]->getType(),
kList[j]->getUoid().getName());
if (!preserveIDs) {
unsigned int objID = j + 1;
if (kList[j]->getID() != objID) {
plDebug::Warning("Object ID changing ({} -> {}) during write: [{04X}]:{}",
kList[j]->getID(), objID, kList[j]->getType(),
kList[j]->getUoid().getName());
}
kList[j]->setID(objID);
}
kList[j]->setID(objID);

if (kList[j]->getObj()) {
try {
#ifdef RMTRACE
Expand Down
5 changes: 3 additions & 2 deletions core/ResManager/plResManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class HSPLASMA_EXPORT plResManager
LoadProgressCallback progressFunc;
PageUnloadCallback pageUnloadFunc;
bool mustStub;
bool preserveIDs;

private:
unsigned int ReadKeyring(hsStream* S, const plLocation& loc);
Expand All @@ -82,8 +83,8 @@ class HSPLASMA_EXPORT plResManager
* ReadPage() or ReadAge()
* \sa setVer(), getVer()
*/
plResManager(PlasmaVer pv = PlasmaVer::pvUnknown)
: fPlasmaVer(PlasmaVer::pvUnknown), mustStub(false)
plResManager(PlasmaVer pv = PlasmaVer::pvUnknown, bool preserveObjIDs = false)
: fPlasmaVer(PlasmaVer::pvUnknown), mustStub(), preserveIDs(preserveObjIDs)
{
setVer(pv);
}
Expand Down

0 comments on commit 5c02e85

Please sign in to comment.