diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/makeprefablibrary.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'hammer/makeprefablibrary.cpp')
| -rw-r--r-- | hammer/makeprefablibrary.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/hammer/makeprefablibrary.cpp b/hammer/makeprefablibrary.cpp new file mode 100644 index 0000000..94b2615 --- /dev/null +++ b/hammer/makeprefablibrary.cpp @@ -0,0 +1,140 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Utility function for creating HalfLife1-style prefab libraries from +// a directory full of RMF and MAP files. +// +// $NoKeywords: $ +//=============================================================================// + +#include "stdafx.h" +#include "hammer.h" +#include "Prefabs.h" +#include "Prefab3d.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include <tier0/memdbgon.h> + +//----------------------------------------------------------------------------- +// Purpose: One function - gets all the .rmf and .map files in the current dir, +// merges them with same-name .txt files, and creates a prefab library +// as specified in pszName. +// Input : pszName - +//----------------------------------------------------------------------------- +void MakePrefabLibrary(LPCTSTR pszName) +{ + CPrefabLibrary *pLibrary = new CPrefabLibraryRMF; + int nPrefabs = 0; + + printf("Making prefab library %s.ol\n", pszName); + + pLibrary->SetName(pszName); + + // disable caching of prefabs + CPrefab::EnableCaching(FALSE); + + // get files + static BOOL bFirst = TRUE; +Again: + WIN32_FIND_DATA fd; + HANDLE hnd = FindFirstFile(bFirst ? "*.rmf" : "*.map", &fd); + + if(hnd != INVALID_HANDLE_VALUE) do + { + // check file type + CPrefab *pPrefab = NULL; + int iLoadResult = -1; + + switch (CPrefab::CheckFileType(fd.cFileName)) + { + case CPrefab::pftUnknown: + { + continue; + } + + case CPrefab::pftRMF: + { + CPrefabRMF *pNew = new CPrefabRMF; + iLoadResult = pNew->Init(fd.cFileName, TRUE, CPrefab::lsRMF); + pPrefab = (CPrefab *)pNew; + break; + } + + case CPrefab::pftMAP: + { + CPrefabRMF *pNew = new CPrefabRMF; + iLoadResult = pNew->Init(fd.cFileName, TRUE, CPrefab::lsMAP); + pPrefab = (CPrefab *)pNew; + break; + } + + case CPrefab::pftScript: + { + Assert(0); // not supported yet + break; + } + } + + if(iLoadResult == -1) + { + // pPrefab might be null but delete doesn't care + delete pPrefab; + pPrefab = NULL; + } + + if(!pPrefab) + continue; + + printf(" including %s\n", fd.cFileName); + ++nPrefabs; + + // find text file - set info with it + CString strTextFile = fd.cFileName; + int iPos = strTextFile.Find('.'); + strTextFile.GetBuffer(0)[iPos] = 0; + strTextFile.ReleaseBuffer(); + strTextFile += ".txt"; + + if(GetFileAttributes(strTextFile) != 0xFFFFFFFF) + { + std::ifstream tfile(strTextFile); + char szBuffer[1024], szBuffer2[1024]; + memset(szBuffer, 0, sizeof szBuffer); + // read file + tfile.read(szBuffer, 1023); + // get rid of \r and \n chars + char *p1 = szBuffer, *p2 = szBuffer2; + while(p1[0]) + { + if(p1[0] != '\n' && p1[0] != '\r') + { + p2[0] = p1[0]; + ++p2; + } + ++p1; + } + p2[0] = 0; + // set the prefab's info + pPrefab->SetNotes(szBuffer2); + } + + // add to new library + pLibrary->Add(pPrefab); + + } while(FindNextFile(hnd, &fd)); + + if(bFirst) + { + bFirst = FALSE; + goto Again; + } + + // now rewrite library + pLibrary->Save(); + + CPrefab::FreeAllData(); // free memory + // re-enable prefab caching + CPrefab::EnableCaching(TRUE); + + printf("%d prefabs in library.\n", nPrefabs); +} + |