From 36b6d84ee4b520bdf43891ea86df03cf660cb464 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak Date: Fri, 25 Oct 2024 23:24:45 -0400 Subject: create project --- .gitignore | 4 ++++ LICENSE | 13 +++++++++++++ Makefile | 15 +++++++++++++++ README | 7 +++++++ intdef.h | 16 ++++++++++++++++ log.h | 18 ++++++++++++++++++ main.c | 24 ++++++++++++++++++++++++ os.h | 20 ++++++++++++++++++++ 8 files changed, 117 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 intdef.h create mode 100644 log.h create mode 100644 main.c create mode 100644 os.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..165f4d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +compile_flags.txt +*.o +*.pdb +*.exe diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..80ef0cf --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2024 Matthew Wozniak + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91fdac8 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +CC = clang +CFLAGS = -g -O2 -target i686-windows-msvc -include stdbool.h +LDFLAGS = -g -fuse-ld=lld -O2 -m32 +OBJS = main.o + +all: rt.exe + +rt.exe: $(OBJS) + $(CC) $(LDFLAGS) $(OBJS) -o rt.exe + +%.o: %.c + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +clean: + rm -f *.o *.exe *.pdb diff --git a/README b/README new file mode 100644 index 0000000..e225edc --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +rendertools +----------- + +orange box engine demo renderer + +usage: + rt -w -h -g -r path/to/demo.dem diff --git a/intdef.h b/intdef.h new file mode 100644 index 0000000..03a8ac3 --- /dev/null +++ b/intdef.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: ISC +// SPDX-FileCopyrightText: 2024 Matthew Wozniak + +#ifndef INTDEF_H +#define INTDEF_H + +typedef unsigned char byte; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; +typedef long long vlong; +typedef unsigned long long uvlong; + +#endif + +// vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/log.h b/log.h new file mode 100644 index 0000000..88254bc --- /dev/null +++ b/log.h @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: ISC +// SPDX-FileCopyrightText: 2024 Matthew Wozniak + +#include +#include + +#define die(fmt, ...) {\ + fprintf(stderr, "err: " __FILE__ ": " fmt "\n", __VA_ARGS__); \ + exit(1); \ +} + +#define warn(fmt, ...) \ + fprintf(stderr, "warn: " __FILE__ ": " fmt "\n", __VA_ARGS__) + +#define info(fmt, ...) \ + fprintf(stderr, "info: " __FILE__ ": " fmt "\n", __VA_ARGS__) + +// vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/main.c b/main.c new file mode 100644 index 0000000..ae79d3b --- /dev/null +++ b/main.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: ISC +// SPDX-FileCopyrightText: 2024 Matthew Wozniak + +#include "os.h" +#include "log.h" + +#include +#include + +typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline, + int cmd_show); + +int main(int argc, char **argv) { + SetDllDirectoryA("bin/"); + + void *launcher_dll = os_dlopen("launcher"); + LauncherMain_t launcher_main = + (LauncherMain_t)os_dlsym(launcher_dll, "LauncherMain"); + + if (!launcher_main) die("couldn't open launcher"); + launcher_main(NULL, NULL, NULL, 0); +} + +// vi: sw=4 ts=4 noet tw=80 cc=80 diff --git a/os.h b/os.h new file mode 100644 index 0000000..2635268 --- /dev/null +++ b/os.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: ISC +// SPDX-FileCopyrightText: 2024 Matthew Wozniak + +#ifndef OS_H +#define OS_H + +#include +#include "intdef.h" + +#define os_dlopen LoadLibraryA +#define os_dlsym GetProcAddress + +inline bool os_mprot(void *mem, int len, int mode) { + ulong old; + return !!VirtualProtect(mem, len, mode, &old); +} + +#endif + +// vi: sw=4 ts=4 noet tw=80 cc=80 -- cgit v1.2.3-54-g00ecf