2001-09-28 07:09:38 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
|
|
|
Copyright (C) 2001 #AUTHOR#
|
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2003-01-14 20:18:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-06-01 21:57:59 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-02-26 13:10:59 +00:00
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/gib.h"
|
|
|
|
#include "QF/idparse.h"
|
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
2004-01-16 08:02:31 +00:00
|
|
|
#include "QF/ruamoko.h"
|
2020-02-26 13:10:59 +00:00
|
|
|
#include "QF/sys.h"
|
2002-11-12 02:30:08 +00:00
|
|
|
#include "QF/va.h"
|
2020-02-26 13:10:59 +00:00
|
|
|
#include "QF/zone.h"
|
2001-06-01 21:57:59 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "qwaq.h"
|
|
|
|
|
2001-06-05 23:53:55 +00:00
|
|
|
#define MAX_EDICTS 1024
|
|
|
|
|
2002-11-12 02:30:08 +00:00
|
|
|
static progs_t pr;
|
2001-06-01 21:57:59 +00:00
|
|
|
|
2020-02-26 13:10:59 +00:00
|
|
|
cbuf_t *qwaq_cbuf;
|
|
|
|
|
2002-11-12 02:30:08 +00:00
|
|
|
static QFile *
|
|
|
|
open_file (const char *path, int *len)
|
|
|
|
{
|
|
|
|
QFile *file = Qopen (path, "rbz");
|
2001-06-01 21:57:59 +00:00
|
|
|
|
2002-11-12 02:30:08 +00:00
|
|
|
if (!file) {
|
|
|
|
perror (path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*len = Qfilesize (file);
|
|
|
|
return file;
|
|
|
|
}
|
2001-06-06 20:05:08 +00:00
|
|
|
|
2002-11-12 02:30:08 +00:00
|
|
|
static void *
|
2020-02-21 12:17:28 +00:00
|
|
|
load_file (progs_t *pr, const char *name, off_t *_size)
|
2001-06-01 21:57:59 +00:00
|
|
|
{
|
2002-11-12 02:30:08 +00:00
|
|
|
QFile *file;
|
|
|
|
int size;
|
2004-11-02 05:12:00 +00:00
|
|
|
char *sym;
|
2002-11-12 02:30:08 +00:00
|
|
|
|
|
|
|
file = open_file (name, &size);
|
|
|
|
if (!file) {
|
|
|
|
file = open_file (va ("%s.gz", name), &size);
|
|
|
|
if (!file) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2004-11-02 05:12:00 +00:00
|
|
|
sym = malloc (size + 1);
|
|
|
|
sym[size] = 0;
|
2002-11-12 02:30:08 +00:00
|
|
|
Qread (file, sym, size);
|
2020-02-21 12:17:28 +00:00
|
|
|
*_size = size;
|
2002-11-12 02:30:08 +00:00
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
allocate_progs_mem (progs_t *pr, int size)
|
|
|
|
{
|
|
|
|
return malloc (size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_progs_mem (progs_t *pr, void *mem)
|
|
|
|
{
|
|
|
|
free (mem);
|
|
|
|
}
|
2001-06-01 21:57:59 +00:00
|
|
|
|
2002-11-12 02:30:08 +00:00
|
|
|
static void
|
|
|
|
init_qf (void)
|
|
|
|
{
|
2020-02-26 13:10:59 +00:00
|
|
|
qwaq_cbuf = Cbuf_New (&id_interp);
|
|
|
|
|
2011-09-11 05:56:47 +00:00
|
|
|
Sys_Init ();
|
2020-02-26 13:10:59 +00:00
|
|
|
COM_ParseConfig ();
|
|
|
|
|
|
|
|
//Cvar_Set (developer, "1");
|
2001-06-01 21:57:59 +00:00
|
|
|
|
2020-02-26 13:10:59 +00:00
|
|
|
Memory_Init (malloc (8 * 1024 * 1024), 8 * 1024 * 1024);
|
2007-06-09 09:43:21 +00:00
|
|
|
|
2007-06-09 13:44:06 +00:00
|
|
|
Cvar_Get ("pr_debug", "2", 0, 0, 0);
|
2001-12-12 08:39:47 +00:00
|
|
|
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
|
2002-11-12 02:30:08 +00:00
|
|
|
|
|
|
|
pr.load_file = load_file;
|
|
|
|
pr.allocate_progs_mem = allocate_progs_mem;
|
|
|
|
pr.free_progs_mem = free_progs_mem;
|
2004-11-08 23:27:00 +00:00
|
|
|
pr.no_exec_limit = 1;
|
2001-07-14 23:52:56 +00:00
|
|
|
|
2001-06-01 21:57:59 +00:00
|
|
|
PR_Init_Cvars ();
|
2020-02-23 06:56:36 +00:00
|
|
|
PR_Init (&pr);
|
2004-01-16 08:02:31 +00:00
|
|
|
RUA_Init (&pr, 0);
|
2020-02-26 13:10:59 +00:00
|
|
|
PR_Cmds_Init (&pr);
|
2002-11-12 02:30:08 +00:00
|
|
|
BI_Init (&pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
load_progs (const char *name)
|
|
|
|
{
|
|
|
|
QFile *file;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
file = open_file (name, &size);
|
|
|
|
if (!file) {
|
|
|
|
return 0;
|
2001-06-01 21:57:59 +00:00
|
|
|
}
|
2002-11-12 02:30:08 +00:00
|
|
|
pr.progs_name = name;
|
2018-10-11 01:06:48 +00:00
|
|
|
pr.max_edicts = 1;
|
|
|
|
pr.zone_size = 1024*1024;
|
|
|
|
PR_LoadProgsFile (&pr, file, size);
|
2002-11-12 02:30:08 +00:00
|
|
|
Qclose (file);
|
2004-01-03 08:43:57 +00:00
|
|
|
if (!PR_RunLoadFuncs (&pr))
|
2002-11-12 02:30:08 +00:00
|
|
|
PR_Error (&pr, "unable to load %s", pr.progs_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-26 13:10:59 +00:00
|
|
|
main (int argc, const char **argv)
|
2002-11-12 02:30:08 +00:00
|
|
|
{
|
2004-11-06 02:17:00 +00:00
|
|
|
dfunction_t *dfunc;
|
|
|
|
func_t main_func = 0;
|
2020-02-26 16:18:38 +00:00
|
|
|
const char *name = "qwaq-app.dat";
|
2002-11-12 02:56:10 +00:00
|
|
|
string_t *pr_argv;
|
|
|
|
int pr_argc = 1, i;
|
2002-11-12 02:30:08 +00:00
|
|
|
|
2020-02-26 13:10:59 +00:00
|
|
|
COM_InitArgv (argc, argv);
|
2002-11-12 02:30:08 +00:00
|
|
|
init_qf ();
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
name = argv[1];
|
|
|
|
|
2020-02-26 16:18:38 +00:00
|
|
|
if (!load_progs (name)) {
|
2018-10-11 04:39:48 +00:00
|
|
|
Sys_Error ("couldn't load %s", name);
|
2020-02-26 16:18:38 +00:00
|
|
|
}
|
2002-01-30 17:41:16 +00:00
|
|
|
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_PushFrame (&pr);
|
2002-11-12 02:56:10 +00:00
|
|
|
if (argc > 2)
|
|
|
|
pr_argc = argc - 1;
|
|
|
|
pr_argv = PR_Zone_Malloc (&pr, (pr_argc + 1) * 4);
|
2004-01-05 07:10:32 +00:00
|
|
|
pr_argv[0] = PR_SetTempString (&pr, name);
|
2002-11-12 02:56:10 +00:00
|
|
|
for (i = 1; i < pr_argc; i++)
|
2004-01-05 07:10:32 +00:00
|
|
|
pr_argv[i] = PR_SetTempString (&pr, argv[1 + i]);
|
2002-11-12 02:56:10 +00:00
|
|
|
pr_argv[i] = 0;
|
|
|
|
|
2011-01-12 14:35:56 +00:00
|
|
|
if ((dfunc = PR_FindFunction (&pr, ".main"))
|
|
|
|
|| (dfunc = PR_FindFunction (&pr, "main")))
|
2004-11-05 11:49:00 +00:00
|
|
|
main_func = dfunc - pr.pr_functions;
|
|
|
|
else
|
|
|
|
PR_Undefined (&pr, "function", "main");
|
2005-06-12 09:54:01 +00:00
|
|
|
PR_RESET_PARAMS (&pr);
|
2004-11-05 11:49:00 +00:00
|
|
|
P_INT (&pr, 0) = pr_argc;
|
|
|
|
P_POINTER (&pr, 1) = PR_SetPointer (&pr, pr_argv);
|
2020-02-25 08:28:32 +00:00
|
|
|
pr.pr_argc = 2;
|
2002-11-12 02:30:08 +00:00
|
|
|
PR_ExecuteProgram (&pr, main_func);
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_PopFrame (&pr);
|
2020-02-26 16:18:38 +00:00
|
|
|
Sys_Shutdown ();
|
2003-04-22 18:20:15 +00:00
|
|
|
return R_INT (&pr);
|
2001-06-01 21:57:59 +00:00
|
|
|
}
|