From 111c923844989d9edd24ede9bc2477674b8543d7 Mon Sep 17 00:00:00 2001 From: terminx <terminx@1a8010ca-5511-0410-912e-c29ae57300e0> Date: Mon, 1 May 2006 05:03:44 +0000 Subject: [PATCH] Revert some of the aim changes as well as add the start of support for loading Duke3d_w32 network configuration files. The wrapper application reformats a Duke3d_w32 command line sent from Dukester X into something EDuke32 can work with. Still left to be done: sort IPs (they aren't in the same order on all machines in Rancidmeat config files) and construct a proper string of network parameters for Ken's netcode. git-svn-id: https://svn.eduke32.com/eduke32@130 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 95 +++++++++++++++++++++++++++++++- polymer/eduke32/source/player.c | 3 +- polymer/eduke32/source/wrapper.c | 60 ++++++++++++++++++++ 3 files changed, 155 insertions(+), 3 deletions(-) create mode 100755 polymer/eduke32/source/wrapper.c diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index ea46e7c65..3af3bdf44 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "osd.h" #include "osdfuncs.h" #include "osdcmds.h" +#include "scriptfile.h" //#include "crc32.h" @@ -7461,6 +7462,82 @@ void comlinehelp(char **argv) wm_msgbox(apptitle,s); } +enum { + T_EOF = -2, + T_ERROR = -1, + T_INTERFACE = 0, + T_MODE, + T_ALLOW +}; + +signed int rancid_players = 0; +char rancid_ips[MAXPLAYERS][16]; + +typedef struct { char *text; int tokenid; } tokenlist; +static tokenlist basetokens[] = + { + { "interface", T_INTERFACE }, + { "mode", T_MODE }, + { "allow", T_ALLOW }, + }; + +static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens) +{ + char *tok; + int i; + + if (!sf) return T_ERROR; + tok = scriptfile_gettoken(sf); + if (!tok) return T_EOF; + + for(i=0;i<ntokens;i++) { + if (!Bstrcasecmp(tok, tl[i].text)) + return tl[i].tokenid; + } + + return T_ERROR; +} + +static int parserancidnet(scriptfile *script) +{ + int tokn; + char *cmdtokptr; + while (1) { + tokn = getatoken(script,basetokens,sizeof(basetokens)/sizeof(tokenlist)); + cmdtokptr = script->ltextptr; + switch (tokn) { + case T_INTERFACE: + case T_ALLOW: + { + char *ip; + if (scriptfile_getstring(script,&ip)) break; + Bstrcpy(rancid_ips[rancid_players++],ip); + } + break; + case T_EOF: + return(0); + default: + break; + } + } + return 0; +} + +int loadrancidnet(char *fn) +{ + scriptfile *script; + + script = scriptfile_fromfile(fn); + if (!script) return -1; + + parserancidnet(script); + + scriptfile_close(script); + scriptfile_clearsymbols(); + + return 0; +} + void checkcommandline(int argc,char **argv) { short i, j; @@ -7495,6 +7572,20 @@ void checkcommandline(int argc,char **argv) c = argv[i]; if (((*c == '/') || (*c == '-')) && (!firstnet)) { + if (!Bstrcasecmp(c+1,"rmnet")) { + if (argc > i+1) { + CommandName = argv[i+1]; + i++; + } + if(CommandName) { + loadrancidnet(CommandName); + for(j=0;j<rancid_players;j++) + initprintf("Rancidmeat configuration IP %d: %s\n",j,rancid_ips[j]); + CommandName = 0; + } + i++; + continue; + } if (!Bstrcasecmp(c+1,"net")) { firstnet = i; netparamcount = argc - i - 1; @@ -8346,7 +8437,7 @@ void writestring(long a1,long a2,long a3,short a4,long vx,long vy,long vz) FILE *fp; - fp = (FILE *)fopenfrompath("debug.txt","rt+"); + fp = (FILE *)fopen("debug.txt","rt+"); fprintf(fp,"%ld %ld %ld %d %ld %ld %ld\n",a1,a2,a3,a4,vx,vy,vz); fclose(fp); @@ -9615,7 +9706,7 @@ FAKEHORIZONLY: } if(p->aim_mode) - myhoriz += syn->horz/2; + myhoriz += syn->horz>>1; else { if( myhoriz > 95 && myhoriz < 105) myhoriz = 100; diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 4dffeee85..f987ae7a2 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -2833,6 +2833,7 @@ void getinput(short snum) else horiz = (info.dz+lastinfo.dz)/(314-128); lastinfo.dz = (lastinfo.dz+info.dz) % (314-128); + if(horiz <= 0) horiz++; info.dz = 0; } else { lastinfo.dz = info.dz % (1<<6); @@ -4388,7 +4389,7 @@ HORIZONLY: } if(p->aim_mode) - p->horiz += sync[snum].horz/2; + p->horiz += sync[snum].horz>>1; else { if( p->horiz > 95 && p->horiz < 105) p->horiz = 100; diff --git a/polymer/eduke32/source/wrapper.c b/polymer/eduke32/source/wrapper.c new file mode 100755 index 000000000..5f3f2c479 --- /dev/null +++ b/polymer/eduke32/source/wrapper.c @@ -0,0 +1,60 @@ +// this is a wrapper to launch EDuke32 properly from Dukester X +// gcc -o duke3d_w32.exe wrapper.c + +#include <windows.h> +#include <stdio.h> + +#define ISWS(x) ((x == ' ') || (x == '\t') || (x == '\r') || (x == '\n')) + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) +{ + int i,j; + LPTSTR szCmdLine; + + char CmdLine[1024]; + char sCmdLine[1024]; + char szFileName[255]; + + FILE * fp=fopen("wrapper.log","w"); + STARTUPINFO si; + PROCESS_INFORMATION pi; + + for(i=0;i<sizeof(CmdLine);i++) + { + if(lpCmdLine[i] == ' ' && lpCmdLine[i+1] == '-' && lpCmdLine[i+2] == 'n' && lpCmdLine[i+3] == 'e' && lpCmdLine[i+4] == 't') + { + i += 6; + j = 0; + while(!ISWS(lpCmdLine[i])) + { + szFileName[j] = lpCmdLine[i]; + j++,i++; + fprintf(fp,"%d %d\n",j,i); + if(lpCmdLine[i] == ' ' || lpCmdLine[i] == '\n' || lpCmdLine[i] == '\r') + break; + } + break; + } + else CmdLine[i] = lpCmdLine[i]; + } + + sprintf(sCmdLine,"eduke32.exe %s -rmnet %s",CmdLine,szFileName); + szCmdLine = sCmdLine; + fprintf(fp,"EDuke32 wrapper for Dukester X v0.01\ + \nCopyright (c) 2006 EDuke32 team\n\ + \nArgs passed to wrapper: %s\ + \nRancidmeat net filename: %s\ + \nFinal command line: %s\n",lpCmdLine,szFileName,szCmdLine); + fclose(fp); + + ZeroMemory(&si,sizeof(si)); + ZeroMemory(&pi,sizeof(pi)); + si.cb = sizeof(si); + + if (!CreateProcess(NULL,szCmdLine,NULL,NULL,0,0,NULL,NULL,&si,&pi)) { + MessageBox(0,"Failed to start eduke32.exe.", "Failure starting game", MB_OK|MB_ICONSTOP); + return 1; + } + return 0; +} +