Example #1
0
        // Draw_CachePic
        public static glpic_t CachePic(string path)
        {
            for (int i = 0; i < _MenuNumCachePics; i++)
            {
                cachepic_t p = _MenuCachePics[i];
                if (p.name == path)// !strcmp(path, pic->name))
                {
                    return(p.pic);
                }
            }

            if (_MenuNumCachePics == MAX_CACHED_PICS)
            {
                Sys.Error("menu_numcachepics == MAX_CACHED_PICS");
            }

            cachepic_t pic = _MenuCachePics[_MenuNumCachePics];

            _MenuNumCachePics++;
            pic.name = path;

            //
            // load the pic from disk
            //
            byte[] data = Common.LoadFile(path);
            if (data == null)
            {
                Sys.Error("Draw_CachePic: failed to load {0}", path);
            }

            dqpicheader_t header = Sys.BytesToStructure <dqpicheader_t>(data, 0);

            Wad.SwapPic(header);

            int headerSize = Marshal.SizeOf(typeof(dqpicheader_t));

            // HACK HACK HACK --- we need to keep the bytes for
            // the translatable player picture just for the menu
            // configuration dialog
            if (path == "gfx/menuplyr.lmp")
            {
                Buffer.BlockCopy(data, headerSize, _MenuPlayerPixels, 0, header.width * header.height);
                //memcpy (menuplyr_pixels, dat->data, dat->width*dat->height);
            }

            glpic_t gl = new glpic_t();

            gl.width  = header.width;
            gl.height = header.height;

            //gl = (glpic_t *)pic->pic.data;
            gl.texnum = LoadTexture(gl, new ByteArraySegment(data, headerSize));
            gl.sl     = 0;
            gl.sh     = 1;
            gl.tl     = 0;
            gl.th     = 1;
            pic.pic   = gl;

            return(gl);
        }
Example #2
0
        // W_LoadWadFile (char *filename)
        public static void LoadWadFile(string filename)
        {
            _Data = Common.LoadFile(filename);
            if (_Data == null)
            {
                Sys.Error("Wad.LoadWadFile: couldn't load {0}", filename);
            }

            if (_Handle.IsAllocated)
            {
                _Handle.Free();
            }
            _Handle  = GCHandle.Alloc(_Data, GCHandleType.Pinned);
            _DataPtr = _Handle.AddrOfPinnedObject();

            wadinfo_t header = Sys.BytesToStructure <wadinfo_t>(_Data, 0);

            if (header.identification[0] != 'W' || header.identification[1] != 'A' ||
                header.identification[2] != 'D' || header.identification[3] != '2')
            {
                Sys.Error("Wad file {0} doesn't have WAD2 id\n", filename);
            }

            int numlumps     = Common.LittleLong(header.numlumps);
            int infotableofs = Common.LittleLong(header.infotableofs);
            int lumpInfoSize = Marshal.SizeOf(typeof(lumpinfo_t));

            _Lumps = new Dictionary <string, lumpinfo_t>(numlumps);

            for (int i = 0; i < numlumps; i++)
            {
                IntPtr     ptr  = new IntPtr(_DataPtr.ToInt64() + infotableofs + i * lumpInfoSize);
                lumpinfo_t lump = (lumpinfo_t)Marshal.PtrToStructure(ptr, typeof(lumpinfo_t));
                lump.filepos = Common.LittleLong(lump.filepos);
                lump.size    = Common.LittleLong(lump.size);
                if (lump.type == TYP_QPIC)
                {
                    ptr = new IntPtr(_DataPtr.ToInt64() + lump.filepos);
                    dqpicheader_t pic = (dqpicheader_t)Marshal.PtrToStructure(ptr, typeof(dqpicheader_t));
                    SwapPic(pic);
                    Marshal.StructureToPtr(pic, ptr, true);
                }
                _Lumps.Add(Encoding.ASCII.GetString(lump.name).TrimEnd('\0').ToLower(), lump);
            }
        }
Example #3
0
        /// <summary>
        /// PR_LoadProgs
        /// </summary>
        public static void LoadProgs()
        {
            FreeHandles();

            QBuiltins.ClearState();
            _DynamicStrings.Clear();

            // flush the non-C variable lookup cache
            for (int i = 0; i < GEFV_CACHESIZE; i++)
            {
                _gefvCache[i].field = null;
            }

            CRC.Init(out _Crc);

            byte[] buf = Common.LoadFile("progs.dat");

            _Progs = Sys.BytesToStructure <dprograms_t>(buf, 0);
            if (_Progs == null)
            {
                Sys.Error("PR_LoadProgs: couldn't load progs.dat");
            }

            Con.DPrint("Programs occupy {0}K.\n", buf.Length / 1024);

            for (int i = 0; i < buf.Length; i++)
            {
                CRC.ProcessByte(ref _Crc, buf[i]);
            }

            // byte swap the header
            _Progs.SwapBytes();

            if (_Progs.version != PROG_VERSION)
            {
                Sys.Error("progs.dat has wrong version number ({0} should be {1})", _Progs.version, PROG_VERSION);
            }

            if (_Progs.crc != PROGHEADER_CRC)
            {
                Sys.Error("progs.dat system vars have been modified, progdefs.h is out of date");
            }

            // Functions
            _Functions = new dfunction_t[_Progs.numfunctions];
            int offset = _Progs.ofs_functions;

            for (int i = 0; i < _Functions.Length; i++, offset += dfunction_t.SizeInBytes)
            {
                _Functions[i] = Sys.BytesToStructure <dfunction_t>(buf, offset);
                _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;

            _Strings = Encoding.ASCII.GetString(buf, str0, length);

            // Globaldefs
            _GlobalDefs = new ddef_t[_Progs.numglobaldefs];
            offset      = _Progs.ofs_globaldefs;
            for (int i = 0; i < _GlobalDefs.Length; i++, offset += ddef_t.SizeInBytes)
            {
                _GlobalDefs[i] = Sys.BytesToStructure <ddef_t>(buf, offset);
                _GlobalDefs[i].SwapBytes();
            }

            // Fielddefs
            _FieldDefs = new ddef_t[_Progs.numfielddefs];
            offset     = _Progs.ofs_fielddefs;
            for (int i = 0; i < _FieldDefs.Length; i++, offset += ddef_t.SizeInBytes)
            {
                _FieldDefs[i] = Sys.BytesToStructure <ddef_t>(buf, offset);
                _FieldDefs[i].SwapBytes();
                if ((_FieldDefs[i].type & DEF_SAVEGLOBAL) != 0)
                {
                    Sys.Error("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
                }
            }

            // Statements
            _Statements = new dstatement_t[_Progs.numstatements];
            offset      = _Progs.ofs_statements;
            for (int i = 0; i < _Statements.Length; i++, offset += dstatement_t.SizeInBytes)
            {
                _Statements[i] = Sys.BytesToStructure <dstatement_t>(buf, offset);
                _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);
                }
            }
            GlobalStruct = Sys.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);

            _EdictSize = _Progs.entityfields * 4 + dedict_t.SizeInBytes - entvars_t.SizeInBytes;

            _HGlobals    = GCHandle.Alloc(_Globals, GCHandleType.Pinned);
            _GlobalsAddr = _HGlobals.AddrOfPinnedObject().ToInt64();

            _HGlobalStruct    = GCHandle.Alloc(Progs.GlobalStruct, GCHandleType.Pinned);
            _GlobalStructAddr = _HGlobalStruct.AddrOfPinnedObject().ToInt64();
        }
Example #4
0
        // Draw_Init
        public static void Init()
        {
            for (int i = 0; i < _MenuCachePics.Length; i++)
            {
                _MenuCachePics[i] = new cachepic_t();
            }

            if (_glNoBind == null)
            {
                _glNoBind  = new Cvar("gl_nobind", "0");
                _glMaxSize = new Cvar("gl_max_size", "1024");
                _glPicMip  = new Cvar("gl_picmip", "0");
            }

            // 3dfx can only handle 256 wide textures
            string renderer = GL.GetString(StringName.Renderer);

            if (renderer.Contains("3dfx") || renderer.Contains("Glide"))
            {
                Cvar.Set("gl_max_size", "256");
            }

            Cmd.Add("gl_texturemode", TextureMode_f);

            // load the console background and the charset
            // by hand, because we need to write the version
            // string into the background before turning
            // it into a texture
            int offset = Wad.GetLumpNameOffset("conchars");

            byte[] draw_chars = Wad.Data; // draw_chars
            for (int i = 0; i < 256 * 64; i++)
            {
                if (draw_chars[offset + i] == 0)
                {
                    draw_chars[offset + i] = 255;   // proper transparent color
                }
            }

            // now turn them into textures
            _CharTexture = LoadTexture("charset", 128, 128, new ByteArraySegment(draw_chars, offset), false, true);

            byte[] buf = Common.LoadFile("gfx/conback.lmp");
            if (buf == null)
            {
                Sys.Error("Couldn't load gfx/conback.lmp");
            }

            dqpicheader_t cbHeader = Sys.BytesToStructure <dqpicheader_t>(buf, 0);

            Wad.SwapPic(cbHeader);

            // hack the version number directly into the pic
            string ver     = String.Format("(c# {0,7:F2}) {1,7:F2}", (float)QDef.CSQUAKE_VERSION, (float)QDef.VERSION);
            int    offset2 = Marshal.SizeOf(typeof(dqpicheader_t)) + 320 * 186 + 320 - 11 - 8 * ver.Length;
            int    y       = ver.Length;

            for (int x = 0; x < y; x++)
            {
                CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset));
            }

            _ConBack        = new glpic_t();
            _ConBack.width  = cbHeader.width;
            _ConBack.height = cbHeader.height;
            int ncdataIndex = Marshal.SizeOf(typeof(dqpicheader_t)); // cb->data;

            SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);

            _ConBack.texnum = LoadTexture("conback", _ConBack.width, _ConBack.height, new ByteArraySegment(buf, ncdataIndex), false, false);
            _ConBack.width  = Scr.vid.width;
            _ConBack.height = Scr.vid.height;

            // save a texture slot for translated picture
            _TranslateTexture = _TextureExtensionNumber++;

            // save slots for scraps
            _ScrapTexNum             = _TextureExtensionNumber;
            _TextureExtensionNumber += MAX_SCRAPS;

            //
            // get the other pics we need
            //
            _Disc     = PicFromWad("disc");
            _BackTile = PicFromWad("backtile");
        }