public static Object pr_globals_read(int address) { globalvars_t globalvars = pr_global_struct[address * 4 / sizeof_globalvars_t]; int offset = address % (sizeof_globalvars_t / 4); switch (offset) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: return(globalvars.pad[offset]); case 28: return(globalvars.self); case 29: return(globalvars.other); case 30: return(globalvars.world); case 31: return(globalvars.time); case 32: return(globalvars.frametime); case 33: return(globalvars.force_retouch); case 34: return(globalvars.mapname); case 35: return(globalvars.deathmatch); case 36: return(globalvars.coop); case 37: return(globalvars.teamplay); case 38: return(globalvars.serverflags); case 39: return(globalvars.total_secrets); case 40: return(globalvars.total_monsters); case 41: return(globalvars.found_secrets); case 42: return(globalvars.killed_monsters); case 43: return(globalvars.parm1); case 44: return(globalvars.parm2); case 45: return(globalvars.parm3); case 46: return(globalvars.parm4); case 47: return(globalvars.parm5); case 48: return(globalvars.parm6); case 49: return(globalvars.parm7); case 50: return(globalvars.parm8); case 51: return(globalvars.parm9); case 52: return(globalvars.parm10); case 53: return(globalvars.parm11); case 54: return(globalvars.parm12); case 55: return(globalvars.parm13); case 56: return(globalvars.parm14); case 57: return(globalvars.parm15); case 58: return(globalvars.parm16); case 59: return(globalvars.v_forward[0]); case 60: return(globalvars.v_forward[1]); case 61: return(globalvars.v_forward[2]); case 62: return(globalvars.v_up[0]); case 63: return(globalvars.v_up[1]); case 64: return(globalvars.v_up[2]); case 65: return(globalvars.v_right[0]); case 66: return(globalvars.v_right[1]); case 67: return(globalvars.v_right[2]); case 68: return(globalvars.trace_allsolid); case 69: return(globalvars.trace_startsolid); case 70: return(globalvars.trace_fraction); case 71: return(globalvars.trace_endpos[0]); case 72: return(globalvars.trace_endpos[1]); case 73: return(globalvars.trace_endpos[2]); case 74: return(globalvars.trace_plane_normal[0]); case 75: return(globalvars.trace_plane_normal[1]); case 76: return(globalvars.trace_plane_normal[2]); case 77: return(globalvars.trace_plane_dist); case 78: return(globalvars.trace_ent); case 79: return(globalvars.trace_inopen); case 80: return(globalvars.trace_inwater); case 81: return(globalvars.msg_entity); case 82: return(globalvars.main); case 83: return(globalvars.StartFrame); case 84: return(globalvars.PlayerPreThink); case 85: return(globalvars.PlayerPostThink); case 86: return(globalvars.ClientKill); case 87: return(globalvars.ClientConnect); case 88: return(globalvars.PutClientInServer); case 89: return(globalvars.ClientDisconnect); case 90: return(globalvars.SetNewParms); case 91: return(globalvars.SetChangeParms); } return(null); }
public static void PR_LoadProgs() { FreeHandles(); ClearState(); _DynamicStrings.Clear(); // flush the non-C variable lookup cache for (int i = 0; i < q_shared.GEFV_CACHESIZE; i++) { gefvCache[i].field = null; } CRC_Init(out pr_crc); byte[] buf = COM_LoadFile("progs.dat"); progs = BytesToStructure <dprograms_t>(buf, 0); if (progs == null) { Sys_Error("PR_LoadProgs: couldn't load progs.dat"); } Con_DPrintf("Programs occupy {0}K.\n", buf.Length / 1024); for (int i = 0; i < buf.Length; i++) { CRC_ProcessByte(ref pr_crc, buf[i]); } // byte swap the header progs.SwapBytes(); if (progs.version != q_shared.PROG_VERSION) { Sys_Error("progs.dat has wrong version number ({0} should be {1})", progs.version, q_shared.PROG_VERSION); } if (progs.crc != q_shared.PROGHEADER_CRC) { Sys_Error("progs.dat system vars have been modified, progdefs.h is out of date"); } // Functions pr_functions = new dfunction_t[progs.numfunctions]; int offset = progs.ofs_functions; for (int i = 0; i < pr_functions.Length; i++, offset += dfunction_t.SizeInBytes) { pr_functions[i] = BytesToStructure <dfunction_t>(buf, offset); pr_functions[i].SwapBytes(); } // strings offset = progs.ofs_strings; int str0 = offset; for (int i = 0; i < progs.numstrings; i++, offset++) { // count string length while (buf[offset] != 0) { offset++; } } int length = offset - str0; pr_strings = Encoding.ASCII.GetString(buf, str0, length); // Globaldefs pr_globaldefs = new ddef_t[progs.numglobaldefs]; offset = progs.ofs_globaldefs; for (int i = 0; i < pr_globaldefs.Length; i++, offset += ddef_t.SizeInBytes) { pr_globaldefs[i] = BytesToStructure <ddef_t>(buf, offset); pr_globaldefs[i].SwapBytes(); } // Fielddefs pr_fielddefs = new ddef_t[progs.numfielddefs]; offset = progs.ofs_fielddefs; for (int i = 0; i < pr_fielddefs.Length; i++, offset += ddef_t.SizeInBytes) { pr_fielddefs[i] = BytesToStructure <ddef_t>(buf, offset); pr_fielddefs[i].SwapBytes(); if ((pr_fielddefs[i].type & q_shared.DEF_SAVEGLOBAL) != 0) { Sys_Error("PR_LoadProgs: pr_fielddefs[i].type & q_shared.DEF_SAVEGLOBAL"); } } // Statements pr_statements = new dstatement_t[progs.numstatements]; offset = progs.ofs_statements; for (int i = 0; i < pr_statements.Length; i++, offset += dstatement_t.SizeInBytes) { pr_statements[i] = BytesToStructure <dstatement_t>(buf, offset); pr_statements[i].SwapBytes(); } // Swap bytes inplace if needed if (!BitConverter.IsLittleEndian) { offset = progs.ofs_globals; for (int i = 0; i < progs.numglobals; i++, offset += 4) { SwapHelper.Swap4b(buf, offset); } } pr_global_struct = BytesToStructure <globalvars_t>(buf, progs.ofs_globals); _Globals = new float[progs.numglobals - globalvars_t.SizeInBytes / 4]; Buffer.BlockCopy(buf, progs.ofs_globals + globalvars_t.SizeInBytes, _Globals, 0, _Globals.Length * 4); pr_edict_size = progs.entityfields * 4 + dedict_t.SizeInBytes - entvars_t.SizeInBytes; _HGlobals = GCHandle.Alloc(_Globals, GCHandleType.Pinned); _GlobalsAddr = _HGlobals.AddrOfPinnedObject().ToInt64(); _HGlobalStruct = GCHandle.Alloc(pr_global_struct, GCHandleType.Pinned); _GlobalStructAddr = _HGlobalStruct.AddrOfPinnedObject().ToInt64(); }
public static void pr_globals_write(int address, Object value) { globalvars_t globalvars = pr_global_struct[address * 4 / sizeof_globalvars_t]; int offset = address % (sizeof_globalvars_t / 4); switch (offset) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: globalvars.pad[offset] = cast_int(value); break; case 28: globalvars.self = cast_int(value); break; case 29: globalvars.other = cast_int(value); break; case 30: globalvars.world = cast_int(value); break; case 31: globalvars.time = cast_float(value); break; case 32: globalvars.frametime = cast_float(value); break; case 33: globalvars.force_retouch = cast_float(value); break; case 34: globalvars.mapname = cast_int(value); break; case 35: globalvars.deathmatch = cast_float(value); break; case 36: globalvars.coop = cast_float(value); break; case 37: globalvars.teamplay = cast_float(value); break; case 38: globalvars.serverflags = cast_float(value); break; case 40: globalvars.total_monsters = cast_float(value); break; case 41: globalvars.found_secrets = cast_float(value); break; case 42: globalvars.killed_monsters = cast_float(value); break; case 43: globalvars.parm1 = cast_float(value); break; case 44: globalvars.parm2 = cast_float(value); break; case 45: globalvars.parm3 = cast_float(value); break; case 46: globalvars.parm4 = cast_float(value); break; case 47: globalvars.parm5 = cast_float(value); break; case 48: globalvars.parm6 = cast_float(value); break; case 49: globalvars.parm7 = cast_float(value); break; case 50: globalvars.parm8 = cast_float(value); break; case 51: globalvars.parm9 = cast_float(value); break; case 52: globalvars.parm10 = cast_float(value); break; case 53: globalvars.parm11 = cast_float(value); break; case 54: globalvars.parm12 = cast_float(value); break; case 55: globalvars.parm13 = cast_float(value); break; case 56: globalvars.parm14 = cast_float(value); break; case 57: globalvars.parm15 = cast_float(value); break; case 58: globalvars.parm16 = cast_float(value); break; case 59: globalvars.v_forward[0] = cast_float(value); break; case 60: globalvars.v_forward[1] = cast_float(value); break; case 61: globalvars.v_forward[2] = cast_float(value); break; case 62: globalvars.v_up[0] = cast_float(value); break; case 63: globalvars.v_up[1] = cast_float(value); break; case 64: globalvars.v_up[2] = cast_float(value); break; case 65: globalvars.v_right[0] = cast_float(value); break; case 66: globalvars.v_right[1] = cast_float(value); break; case 67: globalvars.v_right[2] = cast_float(value); break; case 68: globalvars.trace_allsolid = cast_float(value); break; case 69: globalvars.trace_startsolid = cast_float(value); break; case 70: globalvars.trace_fraction = cast_float(value); break; case 71: globalvars.trace_endpos[0] = cast_float(value); break; case 72: globalvars.trace_endpos[1] = cast_float(value); break; case 73: globalvars.trace_endpos[2] = cast_float(value); break; case 74: globalvars.trace_plane_normal[0] = cast_float(value); break; case 75: globalvars.trace_plane_normal[1] = cast_float(value); break; case 76: globalvars.trace_plane_normal[2] = cast_float(value); break; case 77: globalvars.trace_plane_dist = cast_float(value); break; case 78: globalvars.trace_ent = cast_int(value); break; case 79: globalvars.trace_inopen = cast_float(value); break; case 80: globalvars.trace_inwater = cast_float(value); break; case 81: globalvars.msg_entity = cast_int(value); break; case 82: globalvars.main = cast_int(value); break; case 83: globalvars.StartFrame = cast_int(value); break; case 84: globalvars.PlayerPreThink = cast_int(value); break; case 85: globalvars.PlayerPostThink = cast_int(value); break; case 86: globalvars.ClientKill = cast_int(value); break; case 87: globalvars.ClientConnect = cast_int(value); break; case 88: globalvars.PutClientInServer = cast_int(value); break; case 89: globalvars.ClientDisconnect = cast_int(value); break; case 90: globalvars.SetNewParms = cast_int(value); break; case 91: globalvars.SetChangeParms = cast_int(value); break; default: break; } }