1 /* 2 ** d_protocol.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 1998-2006 Randy Heit 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 */ 33 34 #ifndef __D_PROTOCOL_H__ 35 #define __D_PROTOCOL_H__ 36 37 #include "doomtype.h" 38 39 // The IFF routines here all work with big-endian IDs, even if the host 40 // system is little-endian. 41 #define BIGE_ID(a,b,c,d) ((d)|((c)<<8)|((b)<<16)|((a)<<24)) 42 43 #define FORM_ID BIGE_ID('F','O','R','M') 44 #define ZDEM_ID BIGE_ID('Z','D','E','M') 45 #define ZDHD_ID BIGE_ID('Z','D','H','D') 46 #define VARS_ID BIGE_ID('V','A','R','S') 47 #define UINF_ID BIGE_ID('U','I','N','F') 48 #define COMP_ID BIGE_ID('C','O','M','P') 49 #define BODY_ID BIGE_ID('B','O','D','Y') 50 #define NETD_ID BIGE_ID('N','E','T','D') 51 #define WEAP_ID BIGE_ID('W','E','A','P') 52 53 #define ANGLE2SHORT(x) ((((x)/360) & 65535) 54 #define SHORT2ANGLE(x) ((x)*360) 55 56 57 struct zdemoheader_s { 58 BYTE demovermajor; 59 BYTE demoverminor; 60 BYTE minvermajor; 61 BYTE minverminor; 62 BYTE map[8]; 63 unsigned int rngseed; 64 BYTE consoleplayer; 65 }; 66 67 struct usercmd_t 68 { 69 DWORD buttons; 70 short pitch; // up/down 71 short yaw; // left/right 72 short roll; // "tilt" 73 short forwardmove; 74 short sidemove; 75 short upmove; 76 }; 77 78 class FArchive; 79 80 FArchive &operator<< (FArchive &arc, usercmd_t &cmd); 81 82 // When transmitted, the above message is preceded by a byte 83 // indicating which fields are actually present in the message. 84 enum 85 { 86 UCMDF_BUTTONS = 0x01, 87 UCMDF_PITCH = 0x02, 88 UCMDF_YAW = 0x04, 89 UCMDF_FORWARDMOVE = 0x08, 90 UCMDF_SIDEMOVE = 0x10, 91 UCMDF_UPMOVE = 0x20, 92 UCMDF_ROLL = 0x40, 93 }; 94 95 // When changing the following enum, be sure to update Net_SkipCommand() 96 // and Net_DoCommand() in d_net.cpp. 97 enum EDemoCommand 98 { 99 DEM_BAD, // 0 Bad command 100 DEM_USERCMD, // 1 Player movement 101 DEM_EMPTYUSERCMD, // 2 Equivalent to [DEM_USERCMD, 0] 102 DEM_UNDONE2, // 3 103 DEM_MUSICCHANGE, // 4 Followed by name of new music 104 DEM_PRINT, // 5 Print string to console 105 DEM_CENTERPRINT, // 6 Print string to middle of screen 106 DEM_STOP, // 7 End of demo 107 DEM_UINFCHANGED, // 8 User info changed 108 DEM_SINFCHANGED, // 9 Server/Host info changed 109 DEM_GENERICCHEAT, // 10 Next byte is cheat to apply (see next enum) 110 DEM_GIVECHEAT, // 11 String: item to give, Word: quantity 111 DEM_SAY, // 12 Byte: who to talk to, String: message to display 112 DEM_DROPPLAYER, // 13 Not implemented, takes a byte 113 DEM_CHANGEMAP, // 14 Name of map to change to 114 DEM_SUICIDE, // 15 Player wants to die 115 DEM_ADDBOT, // 16 Byte: botshift, String: userinfo for bot, 4 Bytes: skill (aiming, perfection, reaction, isp) 116 DEM_KILLBOTS, // 17 Remove all bots from the world 117 DEM_INVUSEALL, // 18 Use every item (panic!) 118 DEM_INVUSE, // 19 4 bytes: ID of item to use 119 DEM_PAUSE, // 20 Pause game 120 DEM_SAVEGAME, // 21 String: Filename, String: Description 121 DEM_UNDONE3, // 22 122 DEM_UNDONE4, // 23 123 DEM_UNDONE5, // 24 124 DEM_UNDONE6, // 25 125 DEM_SUMMON, // 26 String: Thing to fabricate 126 DEM_FOV, // 27 Byte: New FOV for all players 127 DEM_MYFOV, // 28 Byte: New FOV for this player 128 DEM_CHANGEMAP2, // 29 Byte: Position in new map, String: name of new map 129 DEM_UNDONE7, // 30 130 DEM_UNDONE8, // 31 131 DEM_RUNSCRIPT, // 32 Word: Script#, Byte: # of args; each arg is a 4-byte int 132 DEM_SINFCHANGEDXOR, // 33 Like DEM_SINFCHANGED, but data is a byte indicating how to set a bit 133 DEM_INVDROP, // 34 4 bytes: ID of item to drop 134 DEM_WARPCHEAT, // 35 4 bytes: 2 for x, 2 for y 135 DEM_CENTERVIEW, // 36 136 DEM_SUMMONFRIEND, // 37 String: Thing to fabricate 137 DEM_SPRAY, // 38 String: The decal to spray 138 DEM_CROUCH, // 39 139 DEM_RUNSCRIPT2, // 40 Same as DEM_RUNSCRIPT, but always executes 140 DEM_CHECKAUTOSAVE, // 41 Check if the user has autosaves enabled. Ignored for demoplayback. 141 DEM_DOAUTOSAVE, // 42 An autosave should be made 142 DEM_MORPHEX, // 43 String: The class to morph to. 143 DEM_SUMMONFOE, // 44 String: Thing to fabricate 144 DEM_UNDONE9, // 45 145 DEM_UNDONE10, // 46 146 DEM_TAKECHEAT, // 47 String: item to take, Word: quantity 147 DEM_ADDCONTROLLER, // 48 Player to add to the controller list. 148 DEM_DELCONTROLLER, // 49 Player to remove from the controller list. 149 DEM_KILLCLASSCHEAT, // 50 String: Class to kill. 150 DEM_UNDONE11, // 51 151 DEM_SUMMON2, // 52 String: Thing to fabricate, WORD: angle offset 152 DEM_SUMMONFRIEND2, // 53 153 DEM_SUMMONFOE2, // 54 154 DEM_ADDSLOTDEFAULT, // 55 155 DEM_ADDSLOT, // 56 156 DEM_SETSLOT, // 57 157 DEM_SUMMONMBF, // 58 158 DEM_CONVREPLY, // 59 Word: Dialogue node, Byte: Reply number 159 DEM_CONVCLOSE, // 60 160 DEM_CONVNULL, // 61 161 DEM_RUNSPECIAL, // 62 Byte: Special number, Byte: Arg count, Ints: Args 162 DEM_SETPITCHLIMIT, // 63 Byte: Up limit, Byte: Down limit (in degrees) 163 DEM_ADVANCEINTER, // 64 Advance intermission screen state 164 DEM_RUNNAMEDSCRIPT, // 65 String: Script name, Byte: Arg count + Always flag; each arg is a 4-byte int 165 DEM_REVERTCAMERA, // 66 166 DEM_SETSLOTPNUM, // 67 Byte: player number, the rest is the same as DEM_SETSLOT 167 DEM_REMOVE, // 68 168 DEM_FINISHGAME, // 69 169 }; 170 171 // The following are implemented by cht_DoCheat in m_cheat.cpp 172 enum ECheatCommand 173 { 174 CHT_GOD, 175 CHT_NOCLIP, 176 CHT_NOTARGET, 177 CHT_CHAINSAW, 178 CHT_IDKFA, 179 CHT_IDFA, 180 CHT_BEHOLDV, 181 CHT_BEHOLDS, 182 CHT_BEHOLDI, 183 CHT_BEHOLDR, 184 CHT_BEHOLDA, 185 CHT_BEHOLDL, 186 CHT_PUMPUPI, 187 CHT_PUMPUPM, 188 CHT_PUMPUPT, 189 CHT_PUMPUPH, 190 CHT_PUMPUPP, 191 CHT_PUMPUPS, 192 CHT_IDDQD, // Same as CHT_GOD, but sets health 193 CHT_MASSACRE, 194 CHT_CHASECAM, 195 CHT_FLY, 196 CHT_MORPH, 197 CHT_POWER, 198 CHT_HEALTH, 199 CHT_KEYS, 200 CHT_TAKEWEAPS, 201 CHT_NOWUDIE, 202 CHT_ALLARTI, 203 CHT_PUZZLE, 204 CHT_MDK, // Kill actor player is aiming at 205 CHT_ANUBIS, 206 CHT_NOVELOCITY, 207 CHT_DONNYTRUMP, 208 CHT_LEGO, 209 CHT_RESSURECT, // [GRB] 210 CHT_CLEARFROZENPROPS, 211 CHT_FREEZE, 212 CHT_GIMMIEA, 213 CHT_GIMMIEB, 214 CHT_GIMMIEC, 215 CHT_GIMMIED, 216 CHT_GIMMIEE, 217 CHT_GIMMIEF, 218 CHT_GIMMIEG, 219 CHT_GIMMIEH, 220 CHT_GIMMIEI, 221 CHT_GIMMIEJ, 222 CHT_GIMMIEZ, 223 CHT_BUDDHA, 224 CHT_NOCLIP2, 225 CHT_BUDDHA2, 226 CHT_GOD2 227 }; 228 229 void StartChunk (int id, BYTE **stream); 230 void FinishChunk (BYTE **stream); 231 void SkipChunk (BYTE **stream); 232 233 int UnpackUserCmd (usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream); 234 int PackUserCmd (const usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream); 235 int WriteUserCmdMessage (usercmd_t *ucmd, const usercmd_t *basis, BYTE **stream); 236 237 struct ticcmd_t; 238 239 int SkipTicCmd (BYTE **stream, int count); 240 void ReadTicCmd (BYTE **stream, int player, int tic); 241 void RunNetSpecs (int player, int buf); 242 243 int ReadByte (BYTE **stream); 244 int ReadWord (BYTE **stream); 245 int ReadLong (BYTE **stream); 246 float ReadFloat (BYTE **stream); 247 char *ReadString (BYTE **stream); 248 const char *ReadStringConst(BYTE **stream); 249 void WriteByte (BYTE val, BYTE **stream); 250 void WriteWord (short val, BYTE **stream); 251 void WriteLong (int val, BYTE **stream); 252 void WriteFloat (float val, BYTE **stream); 253 void WriteString (const char *string, BYTE **stream); 254 255 #endif //__D_PROTOCOL_H__ 256