Skip to content

Commit

Permalink
Fix compilation on Windows (remove basename() call)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-kennedy committed Jan 20, 2021
1 parent 01a76ee commit bd8ef59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.

Expand Down
11 changes: 6 additions & 5 deletions wad.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <string.h>
// for "tolower"
#include <ctype.h>
// for "basename"
#include <libgen.h>

struct s_wad * read_wad(const char* path)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd8ef59

Please sign in to comment.