public void LoadWadFile(string filename, byte[] buffer) { this._Data = buffer; if (this._Data == null) { Utilities.Error("Wad.LoadWadFile: couldn't load {0}", filename); } if (this._Handle.IsAllocated) { this._Handle.Free( ); } this._Handle = GCHandle.Alloc(this._Data, GCHandleType.Pinned); this._DataPtr = this._Handle.AddrOfPinnedObject( ); var header = Utilities.BytesToStructure <WadInfo>(this._Data, 0); this.Version = Encoding.ASCII.GetString(header.identification); if (this.Version != "WAD2" && this.Version != "WAD3") { Utilities.Error($"Wad file {filename} doesn't have WAD2 or WAD3 id, got {this.Version}\n", filename); } var numlumps = EndianHelper.LittleLong(header.numlumps); var infotableofs = EndianHelper.LittleLong(header.infotableofs); var lumpInfoSize = Marshal.SizeOf(typeof(WadLumpInfo)); this._Lumps = new(numlumps); for (var i = 0; i < numlumps; i++) { var ptr = new IntPtr(this._DataPtr.ToInt64( ) + infotableofs + i * lumpInfoSize); var lump = ( WadLumpInfo )Marshal.PtrToStructure(ptr, typeof(WadLumpInfo)); lump.filepos = EndianHelper.LittleLong(lump.filepos); lump.size = EndianHelper.LittleLong(lump.size); if (lump.type == Wad.TYP_QPIC) { ptr = new(this._DataPtr.ToInt64( ) + lump.filepos); var pic = ( WadPicHeader )Marshal.PtrToStructure(ptr, typeof(WadPicHeader)); EndianHelper.SwapPic(pic); Marshal.StructureToPtr(pic, ptr, true); } this._Lumps.Add(Encoding.ASCII.GetString(lump.name).TrimEnd('\0').ToLower( ), lump); } }
public static BasePicture FromFile(BaseDevice device, string path, string filter = "GL_LINEAR_MIPMAP_NEAREST", bool ignoreAtlas = false) { if (BasePicture.PicturePool.ContainsKey(path)) { return(BasePicture.PicturePool[path]); } var data = FileSystem.LoadFile(path); if (data == null) { Utilities.Error($"BaseTexture_FromFile: failed to load {path}"); } var ext = Path.GetExtension(path).ToLower( ).Substring(1); switch (ext) { case "lmp": var header = Utilities.BytesToStructure <WadPicHeader>(data, 0); EndianHelper.SwapPic(header); var headerSize = Marshal.SizeOf(typeof(WadPicHeader)); return(BasePicture.FromBuffer(device, new(data, headerSize), ( int )header.width, ( int )header.height, path, filter, ignoreAtlas)); case "jpg": case "bmp": case "png": break; case "tga": break; } return(null); }
// Draw_Init public void Initialise( ) { if (Host.Cvars.glNoBind == null) { Host.Cvars.glNoBind = Host.CVars.Add("gl_nobind", false); Host.Cvars.glMaxSize = Host.CVars.Add("gl_max_size", 8192); Host.Cvars.glPicMip = Host.CVars.Add("gl_picmip", 0f); } // 3dfx can only handle 256 wide textures var renderer = Host.Video.Device.Desc.Renderer; if (renderer.Contains("3dfx") || renderer.Contains("Glide")) { Host.CVars.Set("gl_max_size", 256); } Host.Commands.Add("gl_texturemode", TextureMode_f); Host.Commands.Add("imagelist", Imagelist_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 var concharsWad = Host.Wads.FromTexture("conchars"); var offset = concharsWad.GetLumpNameOffset("conchars"); var draw_chars = concharsWad.Data; // draw_chars for (var i = 0; i < 256 * 64; i++) { if (draw_chars[offset + i] == 0) { draw_chars[offset + i] = 255; // proper transparent color } } // Temporarily set here BaseTexture.PicMip = Host.Cvars.glPicMip.Get <Single>( ); BaseTexture.MaxSize = Host.Cvars.glMaxSize.Get <Int32>(); CharSetFont = new Renderer.Font(Host.Video.Device, "charset"); CharSetFont.Initialise(new ByteArraySegment(draw_chars, offset)); var buf = FileSystem.LoadFile("gfx/conback.lmp"); if (buf == null) { Utilities.Error("Couldn't load gfx/conback.lmp"); } var cbHeader = Utilities.BytesToStructure <WadPicHeader>(buf, 0); EndianHelper.SwapPic(cbHeader); // hack the version number directly into the pic var ver = String.Format($"(c# {QDef.CSQUAKE_VERSION,7:F2}) {QDef.VERSION,7:F2}"); var offset2 = Marshal.SizeOf(typeof(WadPicHeader)) + 320 * 186 + 320 - 11 - 8 * ver.Length; var y = ver.Length; for (var x = 0; x < y; x++) { CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset)); } var ncdataIndex = Marshal.SizeOf(typeof(WadPicHeader)); // cb->data; ConsoleBackground = BasePicture.FromBuffer(Host.Video.Device, new ByteArraySegment(buf, ncdataIndex), ( Int32 )cbHeader.width, ( Int32 )cbHeader.height, "conback", "GL_LINEAR"); TranslateTexture = BaseTexture.FromDynamicBuffer(Host.Video.Device, "_TranslateTexture", new ByteArraySegment(_MenuPlayerPixels), _MenuPlayerPixelWidth, _MenuPlayerPixelHeight, false, true, "GL_LINEAR"); // // get the other pics we need // Disc = BasePicture.FromWad(Host.Video.Device, Host.Wads.FromTexture("disc"), "disc", "GL_NEAREST"); BackgroundTile = BasePicture.FromWad(Host.Video.Device, Host.Wads.FromTexture("backtile"), "backtile", "GL_NEAREST"); IsInitialised = true; }