diff --git a/common/cmdlib.cc b/common/cmdlib.cc index acf6b921..d4817e3e 100644 --- a/common/cmdlib.cc +++ b/common/cmdlib.cc @@ -744,7 +744,7 @@ DefaultExtension(char *path, const char *extension) /* (extension should include the .) */ src = path + strlen(path) - 1; - while (*src != PATHSEPERATOR && src != path) { + while (*src != PATHSEPERATOR && *src != '\\' && src != path) { if (*src == '.') return; /* it has an extension */ src--; @@ -784,7 +784,7 @@ StripExtension(char *path) length = strlen(path) - 1; while (length > 0 && path[length] != '.') { length--; - if (path[length] == '/') + if (path[length] == '/' || path[length] == '\\') return; /* no extension */ } if (length) @@ -799,7 +799,7 @@ StrippedExtension(const std::string& path) { length = static_cast(path.size()) - 1; while (length > 0 && path[length] != '.') { length--; - if (path[length] == '/') + if (path[length] == '/' || path[length] == '\\') return path; /* no extension */ } if (length) @@ -842,9 +842,10 @@ ExtractFileBase(char *path, char *dest) src = path + strlen(path) - 1; /* back up until a \ or the start */ - while (src != path && *(src - 1) != PATHSEPERATOR) + while (src != path && *(src - 1) != PATHSEPERATOR + && *(src - 1) != '\\') { src--; - + } while (*src && *src != '.') { *dest++ = *src++; } diff --git a/include/qbsp/writebsp.hh b/include/qbsp/writebsp.hh index 90ee1474..073d53e0 100644 --- a/include/qbsp/writebsp.hh +++ b/include/qbsp/writebsp.hh @@ -27,5 +27,6 @@ int ExportMapTexinfo(int texinfonum); void BeginBSPFile(void); void FinishBSPFile(void); +void UpdateBSPFileEntitiesLump(); #endif diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 70557cc1..54969893 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -302,9 +302,8 @@ UpdateEntLump(void) FixRotateOrigin(entity); } - //LoadBSPFile(); // FIXME: fix -onlyents - WriteEntitiesToString(); - //WriteBSPFile(); // FIXME: fix -onlyents + WriteEntitiesToString(); + UpdateBSPFileEntitiesLump(); if (!options.fAllverbose) options.fVerbose = false; diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 1733f383..c0d87341 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -469,3 +469,29 @@ FinishBSPFile(void) options.fVerbose = options.fAllverbose; } + +/* +================== +UpdateBSPFileEntitiesLump +================== +*/ +void +UpdateBSPFileEntitiesLump() +{ + bspdata_t bspdata; + StripExtension(options.szBSPName); + DefaultExtension(options.szBSPName, ".bsp"); + + // load the .bsp + LoadBSPFile(options.szBSPName, &bspdata); + ConvertBSPFormat(&bspdata, &bspver_generic); + + // replace the existing entities lump with map.exported_entities + CopyString(map.exported_entities, true, &bspdata.data.mbsp.entdatasize, (void**)&bspdata.data.mbsp.dentdata); + + // write the .bsp back to disk + ConvertBSPFormat(&bspdata, bspdata.loadversion); + WriteBSPFile(options.szBSPName, &bspdata); + + logprint("Wrote %s\n", options.szBSPName); +}