diff --git a/README.md b/README.md index dcc5354..8af54c5 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ Greg Kennedy, 2021 Reduce the size of GoldSrc (Half-Life, Counter-Strike 1.6, etc) .BSP files by eliminating embedded textures that already exist in .WAD files. +The official site for YesWADTextures is https://github.com/greg-kennedy/YesWADTextures. + +Windows users can find a recent download in the "Releases" section. Other users: clone (or download) the code, then run `make` in the root folder. + ## Usage Invoke the program like this: @@ -16,6 +20,9 @@ For example, [dm\_office.bsp](https://www.moddb.com/games/half-life/addons/dm-of will prune all but one texture from `dm_office.bsp`, and update its required WAD list to include `halflife.wad`. The new output file measures 572,828 bytes - a 28.5% decrease! +## Warning +This tool has not been extensively tested and may have BSP-damaging bugs. Keep backups. It does not warn before overwriting the output file - be careful not to accidentally overwrite something valuable. You have been warned! + ## Overview A `.WAD` file is a collection of textures, used by games based on the Quake engine. GoldSrc uses version 3 of the .WAD file to store and organize textures. Half-Life ships with a handful of .WAD files, while mods (Counter-Strike) or expansions (Opposing Force) include additional packs for their content. Map authors may also distribute a .WAD file to provide custom textures for their map. diff --git a/wad.c b/wad.c index 163cec6..fb46705 100644 --- a/wad.c +++ b/wad.c @@ -10,8 +10,6 @@ #include // for "tolower" #include -// for "basename" -#include struct s_wad * read_wad(const char* path) { @@ -43,12 +41,15 @@ struct s_wad * read_wad(const char* path) struct s_wad* ret = u_calloc(sizeof(struct s_wad)); // copy base path into name // HL tends to use lowercased WAD names and uppercased texture names - char *temp = strdup(path); - char *base = basename(temp); + const char *base = path + strlen(path); + do { + base--; + } while (base > path && *base != '/' && *base != '\\'); + ret->name = u_calloc(strlen(base) + 1); for (unsigned int i = 0; i < strlen(base); i ++) ret->name[i] = tolower(base[i]); - free(temp); + unsigned int texture_limit = 0; // read directory entries