Skip to content

Commit

Permalink
Fix Windows build and add build.bat.
Browse files Browse the repository at this point in the history
  • Loading branch information
g0mb4 committed Jan 16, 2025
1 parent 6418adc commit 263a91e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Misc/qext_hello/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ src/*.o

*.so
*.dll
*.obj
*.exp
*.lib
43 changes: 35 additions & 8 deletions Misc/qext_hello/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
Windows and Shared Object (SO) files on Linux. They allows external
code to be executed within QC programs.

In theory it works on macOS using the Dynamic Librariy (dylib), but I do
not have a Mac to test with.
In theory it works on macOS using the Dynamic Librariy (dylib), but I
do not have a Mac to test with.

2. Usage

The `extensions` cvar must be set to a non-zero value to enable
qextensions. If it is set through the command line `+extensions 1`
must come before `+map`.

In order to use qextensions the new built-in functions must be defined.
This usually happens in `defs.qc`:

Expand Down Expand Up @@ -102,9 +106,6 @@

4. Installation

The `extensions` cvar must be set to a non-zero value to enable qextensions.
If it is set through the command line `+extensions 1` must prelude `+map`.

qextensions use the filesystem of Quake. They can be placed into the
game directory or embedded into a .PAK file, e.g.:

Expand All @@ -124,6 +125,32 @@
src/ contains the source code of the qextension
qsrc/ contains the source code of the mod uses the qextension

It requres gcc and gcc-mingw-w64 to compile on Linux.
It can be compiled using Visual Studio on Windows.
It requres qcc to compile progs.dat.
5.1. Building

qcc is required to be in the $PATH/%PATH% in order to compile progs.dat.

5.2. Linux

gcc is required to compile the qextension. Simply type:

make

A Win64 version also can be compiled, it requires the gcc-mingw-w64 toolchain.
If it is not present remove the following line from Makefile.

cd src; make -f Makefile.w64

5.3. Windows

Open an `x64 Native Tools Command Prompt for VS X` ant type:

build.bat

5.4. Running

To run the hello qextension copy the generated hello folder to the folder of
quakespasm (where id1 lives) then type:

quakespasm --args -game hello +extensions 1 +developer 1 +map start

If you see the outside of the start map the extension is working.
21 changes: 21 additions & 0 deletions Misc/qext_hello/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
echo off

mkdir hello 2> NUL

cd qsrc
qcc || goto :error
copy "progdefs.h" "..\src\progdefs.h" || goto :error
copy "progs.dat" "..\hello\progs.dat" || goto :error
cd ..

cd src
cl.exe /DWIN32 /D_MSVC_VER hello.c /link /DLL /OUT:hello_x86_64.dll
copy "hello_x86_64.dll" "..\hello\hello_x86_64.dll" || goto :error
cd ..

goto :EOF

:error
echo ---------- ERROR ----------
cd ..
exit /b 1
1 change: 0 additions & 1 deletion Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

extern cvar_t pausable;
extern cvar_t nomonsters;
extern cvar_t extensions;

int current_skill;

Expand Down
16 changes: 11 additions & 5 deletions Quake/pr_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,9 @@ static void LoadExtensionFunctionsLinux (const char *path)
qext_fn_entity fn_ent;

filelen = COM_OpenFile (path, &filehandle, &path_id);
if (filelen < 0)
PR_RunError ("unable to open %s", path);

COM_CloseFile (filehandle);

filedata = COM_LoadMallocFile (path, &path_id);
Expand Down Expand Up @@ -1888,6 +1891,9 @@ static void LoadExtensionFunctionsWindows (const char* path)
qext_fn_entity fn_ent;

filelen = COM_OpenFile (path, &filehandle, &path_id);
if (filelen < 0)
PR_RunError ("unable to open %s", path);

COM_CloseFile (filehandle);

filedata = COM_LoadMallocFile (path, &path_id);
Expand Down Expand Up @@ -1916,7 +1922,7 @@ static void LoadExtensionFunctionsWindows (const char* path)
if (!libhandle)
PR_RunError ("unable to load library %s: %d", tmp_buffer, GetLastError());

fn_ver = (qext_fn_string)GetProcAddress (libhandle, "qextension_version");
fn_ver = (qext_fn_version)GetProcAddress (libhandle, "qextension_version");
if (!fn_ver)
PR_RunError ("unable to find qextension_version in %s", path);

Expand Down Expand Up @@ -1987,7 +1993,7 @@ static void PF_OpenExtension (void)
LoadExtensionFunctions (realpath);

ext_desc = qextensions_ctr;
Con_DPrintf ("Extension %s is loaded as %d\n", path, ext_desc);
Con_DPrintf ("Extension %s (v%d) is loaded as %d\n", path, qextensions[qextensions_ctr].version, ext_desc);

qextensions_ctr++;
G_INT(OFS_RETURN) = ext_desc;
Expand Down Expand Up @@ -2025,7 +2031,7 @@ static void PF_CallExtensionNumber (void)

ext_desc = G_INT(OFS_PARM0);

if (ext_desc < 0 || ext_desc >= MAX_QEXTS)
if (ext_desc < 0 || ext_desc >= MAX_QEXTS || ext_desc >= qextensions_ctr)
PR_RunError ("invalid extension descriptor");

if (!qextensions[ext_desc].fn_num || !qextensions[ext_desc].path)
Expand All @@ -2049,7 +2055,7 @@ static void PF_CallExtensionVector (void)

ext_desc = G_INT(OFS_PARM0);

if (ext_desc < 0 || ext_desc >= MAX_QEXTS)
if (ext_desc < 0 || ext_desc >= MAX_QEXTS || ext_desc >= qextensions_ctr)
PR_RunError ("invalid extension descriptor");

if (!qextensions[ext_desc].fn_vec || !qextensions[ext_desc].path)
Expand All @@ -2073,7 +2079,7 @@ static void PF_CallExtensionEntity (void)

ext_desc = G_INT(OFS_PARM0);

if (ext_desc < 0 || ext_desc >= MAX_QEXTS)
if (ext_desc < 0 || ext_desc >= MAX_QEXTS || ext_desc >= qextensions_ctr)
PR_RunError ("invalid extension descriptor");

if (!qextensions[ext_desc].fn_ent || !qextensions[ext_desc].path)
Expand Down

0 comments on commit 263a91e

Please sign in to comment.