public void A_Wad_Has_The_Correct_Number_Of_Sectors() { WadLoader loader = new WadLoader(); WadFile wad = loader.Load(@"TestData\testmap.wad"); DoomFormatMapElement map = (DoomFormatMapElement)wad.Elements[0]; Assert.AreEqual(17, map.Sectors.Count); }
public void BuildMap(WadFile wad, string mapname) { this.wad = wad; textureTable = new TextureTable(wad.GetLump("TEXTURE1")); if (wad.Contains("TEXTURE2")) { textureTable.Add(wad.GetLump("TEXTURE2")); } paletteLookup = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture(); colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture(); doomMaterial = new Material(Shader.Find("Doom/Texture")); doomMaterial.SetTexture("_Palette", paletteLookup); doomMaterial.SetTexture("_Colormap", colormapLookup); skyMaterial = new Material(Shader.Find("Doom/Sky")); skyMaterial.SetTexture("_Palette", paletteLookup); skyMaterial.SetTexture("_RenderMap", GetTexture("SKY1")); map = new MapData(wad, mapname); levelObject = new GameObject(mapname); unclaimedThings = new List <int>(); for (int i = 0; i < map.things.Count; i++) { unclaimedThings.Add(i); } thingSectors = new Dictionary <int, Sector>(); for (int i = 0; i < map.linedefs.Count; i++) { //Debug.Log(i); BuildLine(i); } for (int i = 0; i < map.sectors.Count; i++) { //Debug.Log(i); BuildSector(i); } // BuildSector(24); levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE); GameObject player = new GameObject("Player"); int playerIndex = 0; for (int i = 0; i < map.things.Count; i++) { if (map.things[i].type == 1) { playerIndex = i; break; } } }
/// <summary> /// Adds the map lumps to a Doom wad file. /// </summary> /// <param name="wad">The wad file to which the map should be added</param> public void AddToWad(WadFile wad) { wad.AddLump(Name, new byte[0]); wad.AddLump("LINEDEFS", Linedefs.SelectMany(x => x.ToBytes()).ToArray()); wad.AddLump("SECTORS", Sectors.SelectMany(x => x.ToBytes()).ToArray()); wad.AddLump("SIDEDEFS", Sidedefs.SelectMany(x => x.ToBytes()).ToArray()); wad.AddLump("THINGS", Things.SelectMany(x => x.ToBytes()).ToArray()); wad.AddLump("VERTEXES", Vertices.SelectMany(x => x.ToBytes()).ToArray()); }
public void BuildMap(WadFile wad, string mapname, bool benchmark = false) { this.benchmark = benchmark; this.wad = wad; textureTable = wad.textureTable; // Graphics setup. TODO: Move this to DoomGraphic, or somewhere else graphic related. paletteLookup = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture(); colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture(); doomMaterial = new Material(Shader.Find("Doom/Texture")); doomMaterial.SetTexture("_Palette", paletteLookup); doomMaterial.SetTexture("_Colormap", colormapLookup); pngMaterial = new Material(Shader.Find("Doom/Unlit Truecolor Texture")); skyMaterial = new Material(Shader.Find("Doom/Sky")); skyMaterial.SetTexture("_Palette", paletteLookup); skyMaterial.SetTexture("_RenderMap", GetTexture(skyName)); spriteMaterial = new Material(Shader.Find("Doom/Texture")); spriteMaterial.SetTexture("_Palette", paletteLookup); spriteMaterial.SetTexture("_Colormap", colormapLookup); map = MapData.Load(wad, mapname); if (map == null) { throw new Exception("Loading map failed."); } st = new SectorTriangulation(map, benchmark); levelObject = new GameObject(mapname); geoObject = new GameObject("Geometry"); thingsObject = new GameObject("Things"); geoObject.transform.SetParent(levelObject.transform); thingsObject.transform.SetParent(levelObject.transform); // Build thing information unclaimedThings = new List <int>(); for (int i = 0; i < map.things.Length; i++) { unclaimedThings.Add(i); } thingSectors = new Dictionary <int, Sector>(); CoroutineRunner cr = levelObject.AddComponent <CoroutineRunner>(); cr.dmb = this; cr.map = map; linesDone = false; sectorsDone = false; cr.StartCoroutine(cr.BuildLines()); cr.StartCoroutine(cr.BuildSectors()); levelObject.transform.localScale = new Vector3(SCALE, SCALE * 1.2f, SCALE); }
public void Build(WadFile wad) { if (mr == null) { InitSelf(wad); } SetupMaterial(wad); }
public PatchTable(byte[] lumpData) { patches = new List <string>(); for (int i = 0; i < (int)BitConverter.ToUInt32(lumpData, 0); i++) { patches.Add(WadFile.GetString(lumpData, 4 + (i * 8))); } }
public MapData(WadFile wad, string name) { int index = wad.GetIndex(name); LoadThings(wad.GetLump(index + 1)); LoadLinedefs(wad.GetLump(index + 2)); LoadSidedefs(wad.GetLump(index + 3)); LoadVertices(wad.GetLump(index + 4)); LoadSectors(wad.GetLump(index + 8)); }
public void Build(WadFile wad) { if (mr == null) { InitSelf(wad); } mr.material.SetTexture("_Palette", new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture()); mr.material.SetTexture("_Colormap", new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture()); mr.material.SetTexture("_MainTex", DoomGraphic.BuildPatch("TITLEPIC", wad, true)); }
public static void ImportTextures(WadImportSettings settings) { var wad = new WadFile(); WadFile.Load(wad, settings.WadPath); foreach(var t in wad.Textures) { string path = Path.Combine(settings.SaveDirectory, t.Name + ".png"); File.WriteAllBytes(path, t.Bitmap.EncodeToPNG()); } }
public void Build(WadFile wad) { this.wad = wad; aspectRatio = (float)Screen.width / (float)Screen.height; SetupMaterial(); BuildStatusBar(); transform.localScale = new Vector3(aspectRatio / 1.6f, aspectRatio / 1.6f, 1f); }
public static Vector3 SCALE = new Vector3(0.015625f, 0.01875f, 0.015625f); // 1/64 public DoomMapBuilder(WadFile wad, MapData map, MapInfo mapInfo = null) { this.map = map; this.wad = wad; this.mapInfo = mapInfo; this.nodeTri = new NodeTriangulation(map); container = new GameObject("MAP").transform; Vector3 scale = SCALE; container.localScale = scale; thingContainer = new GameObject("Things").transform; }
/// <summary> /// Gets an array of bytes descripting this sidedef to add to the SIDEDEFS lump. /// </summary> /// <returns>An array of bytes</returns> public byte[] ToBytes() { List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes((short)XOffset)); bytes.AddRange(BitConverter.GetBytes((short)YOffset)); bytes.AddRange(WadFile.GetBytesFromString(UpperTexture)); bytes.AddRange(WadFile.GetBytesFromString(LowerTexture)); bytes.AddRange(WadFile.GetBytesFromString(MiddleTexture)); bytes.AddRange(BitConverter.GetBytes((short)Sector)); return(bytes.ToArray()); }
/// <summary> /// Gets an array of bytes descripting this sector to add to the SECTORS lump. /// </summary> /// <returns>An array of bytes</returns> public byte[] ToBytes() { List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes((short)FloorHeight)); bytes.AddRange(BitConverter.GetBytes((short)CeilingHeight)); bytes.AddRange(WadFile.GetBytesFromString(FloorTexture)); bytes.AddRange(WadFile.GetBytesFromString(CeilingTexture)); bytes.AddRange(BitConverter.GetBytes((short)LightLevel)); bytes.AddRange(BitConverter.GetBytes((short)Special)); bytes.AddRange(BitConverter.GetBytes((short)Tag)); return(bytes.ToArray()); }
public static bool Save(WadFile wad, string path) { if (File.Exists(path)) { return(false); } using (var stream = File.Open(path, FileMode.CreateNew, FileAccess.Write, FileShare.None)) { Save(wad, stream); return(true); } }
/// <summary> /// Main method. /// </summary> /// <param name="args">Array of command-line parameters</param> private static void Main(string[] args) { if (args.Length == 0) { return; } string wadPath = args[0]; string indexPath = Path.ChangeExtension(wadPath, ".txt"); using (WadFile wad = new WadFile(wadPath)) { File.WriteAllLines(indexPath, wad.LumpNames, Encoding.UTF8); } }
public void Merge(WadFile wad) { numLumps += wad.numLumps; for (int i = 0; i < wad.directory.Count; i++) { wad.directory[i].position += wadData.Length; } directory.AddRange(wad.directory); byte[] newWadData = new byte[wadData.Length + wad.wadData.Length]; Buffer.BlockCopy(wadData, 0, newWadData, 0, wadData.Length); Buffer.BlockCopy(wad.wadData, 0, newWadData, wadData.Length, wad.wadData.Length); wadData = newWadData; }
// Append a texture definition public void Add(byte[] lumpData) { uint amt = BitConverter.ToUInt32(lumpData, 0); uint[] offsets = new uint[amt]; int i; for (i = 0; i < amt; i++) { offsets[i] = BitConverter.ToUInt32(lumpData, 4 + (i * 4)); } for (i = 0; i < amt; i++) { int offset = (int)offsets[i]; uint patchCount = BitConverter.ToUInt16(lumpData, offset + 20); List <DoomPatch> patches = new List <DoomPatch>(); for (int j = offset + 22; j < (offset + 22) + (patchCount * 10); j += 10) { DoomPatch np = new DoomPatch( (int)BitConverter.ToInt16(lumpData, j), (int)BitConverter.ToInt16(lumpData, j + 2), (int)BitConverter.ToUInt16(lumpData, j + 4) ); patches.Add(np); } DoomTexture newTex = new DoomTexture( WadFile.GetString(lumpData, offset), (int)BitConverter.ToUInt16(lumpData, offset + 12), (int)BitConverter.ToUInt16(lumpData, offset + 14), patches ); if (textures.ContainsKey(newTex.name)) { textures[newTex.name] = newTex; } else { //Debug.Log(newTex.name); textures.Add(newTex.name, newTex); } } }
public static Sprite BuildSprite(string name, WadFile wad) { if (spriteCache == null) { spriteCache = new Dictionary <string, Sprite>(); } if (spriteCache.ContainsKey(name)) { return(spriteCache[name]); } Sprite output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToSprite(); spriteCache.Add(name, output); return(output); }
void SetupWad(IwadInfo info) { wad = new WadFile(info.filenames[0]); if (info.mapnameFormat == "MAP") { mapFormat = MapFormat.MAP; } if (info.mapnameFormat == "EM") { mapFormat = MapFormat.EM; } iwadSelector = false; for (int i = 0; i < args.pwads.Count; i++) { wad.Merge(args.pwads[i]); } StartGame(info); }
// Test a map without building it public int TestMap(WadFile wad, string mapname) { map = new DoomMapData(wad, mapname); st = new SectorTriangulation(map); int failedSectors = 0; for (int i = 0; i < map.sectors.Length; i++) { List <SectorPolygon> polygons = null; try { polygons = st.Triangulate(i); } catch { //Debug.Log("Exception found in "+mapname+" sector "+i); } if (polygons == null) { failedSectors += 1; } } return(failedSectors); }
public void ShouldReadCreatedWadFile() { var fileInfo = new FileInfo(Path.GetTempFileName()); try { var map = ThingDemoMap.Create(); var lumps = new List <ILump> { new Marker("MAP01"), new UwmfLump("TEXTMAP", ThingDemoMap.Create()), new Marker("ENDMAP") }; WadWriter.SaveTo(lumps, fileInfo.FullName); var wad = WadFile.Read(fileInfo.FullName); wad.Should().HaveCount(3); wad.Select(l => l.Name).Should().BeEquivalentTo( new[] { new LumpName("MAP01"), new LumpName("TEXTMAP"), new LumpName("ENDMAP"), }, "correct lump names should have been read."); var mapBytes = wad[1].GetData(); using var ms = new MemoryStream(mapBytes); var roundTripped = UwmfReader.Read(ms); UwmfComparison.AssertEqual(roundTripped, map); } finally { if (fileInfo.Exists) { fileInfo.Delete(); } } }
private static Wad.DirectoryEntry GetOrCreateDirectory(WadFile wad, string path) { var parts = path.Split(Path.DirectorySeparatorChar); Wad.DirectoryEntry root; root = wad.Directories.SingleOrDefault(d => d.Name == parts[0]); if (root == null) { root = new Wad.DirectoryEntry(null) { Name = parts[0], }; wad.Directories.Add(root); } Wad.DirectoryEntry current = root; foreach (string part in parts.Skip(1)) { var child = current.Directories.SingleOrDefault( d => d.Name == part); if (child == null) { child = new Wad.DirectoryEntry(current) { Name = part, }; current.Directories.Add(child); } current = child; } return(current); }
public static void Main(string[] args) { ushort wadVersion = 0x202; bool compressFiles = false; bool uppercaseFileNames = false; bool verbose = false; bool showHelp = false; string headerFileName = null; var options = new OptionSet() { { "c|compress", "overwrite files", v => compressFiles = v != null }, { "u|uppercase", "uppsercase file names", v => uppercaseFileNames = v != null }, { "wh|wad-header=", "specify WAD header file name (default is @header.xml)", v => headerFileName = v }, { "wv|wad-version=", "specify WAD version (default is 0x201)", v => { if (v != null) { if (v.StartsWith("0x") == false) { wadVersion = ushort.Parse(v); } else { wadVersion = ushort.Parse(v.Substring(2), NumberStyles.AllowHexSpecifier); } } } }, { "v|verbose", "show verbose messages", v => verbose = v != null }, { "h|help", "show this message and exit", v => showHelp = v != null }, }; List <string> extra; try { extra = options.Parse(args); } catch (OptionException e) { Console.Write("{0}: ", GetExecutableName()); Console.WriteLine(e.Message); Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName()); return; } if (extra.Count < 1 || extra.Count > 2 || showHelp == true) { Console.WriteLine("Usage: {0} [OPTIONS]+ input_dir [output_wad]", GetExecutableName()); Console.WriteLine("Pack a Duels of the Planewalkers WAD."); Console.WriteLine(); Console.WriteLine("Options:"); options.WriteOptionDescriptions(Console.Out); return; } if (wadVersion != 0x201 && wadVersion != 0x202) { Console.WriteLine("Warning: unexpected WAD version specified."); } var paths = new SortedDictionary <string, string>(); var inputPath = Path.GetFullPath(extra[0]); var outputPath = extra.Count > 1 ? extra[1] : Path.ChangeExtension(inputPath, ".wad"); Wad.ArchiveFlags flags = Wad.ArchiveFlags.None; flags |= Wad.ArchiveFlags.Unknown6Observed; flags |= Wad.ArchiveFlags.HasDataTypes; if (compressFiles == true) { flags |= Wad.ArchiveFlags.HasCompressedFiles; } var wad = new WadFile() { Version = wadVersion, Flags = flags, }; bool usingDefaultHeaderFile; string headerPath; if (string.IsNullOrWhiteSpace(headerFileName) == true) { headerPath = Path.Combine(inputPath, "@header.xml"); usingDefaultHeaderFile = true; } else { headerPath = headerFileName; usingDefaultHeaderFile = false; if (Path.IsPathRooted(headerPath) == false) { headerPath = Path.Combine(inputPath, headerPath); } } if (wad.Version >= 0x202) { if (File.Exists(headerPath) == false) { Console.WriteLine("Could not find read header file '{0}'!", headerPath); return; } wad.HeaderXml = File.ReadAllBytes(headerPath); } Console.WriteLine("Collecting files..."); foreach (var path in Directory.GetFiles(inputPath, "*", SearchOption.AllDirectories)) { var fullPath = Path.GetFullPath(path); if (usingDefaultHeaderFile == true && fullPath == headerPath) { continue; } var partPath = fullPath.Substring(inputPath.Length + 1); if (uppercaseFileNames == true) { partPath = partPath.ToUpperInvariant(); } if (paths.ContainsKey(partPath) == true) { // warning? continue; } paths[partPath] = fullPath; } var files = new List <MyFileEntry>(); foreach (var kvp in paths) { string fileName = Path.GetFileName(kvp.Key); var directoryName = Path.GetDirectoryName(kvp.Key); if (directoryName == null) { throw new InvalidOperationException(); } var dir = GetOrCreateDirectory(wad, directoryName); var file = new MyFileEntry(dir); file.FilePath = kvp.Value; file.Name = fileName; file.Size = 0; file.Unknown0C = 0; file.OffsetIndex = wad.DataOffsets.Count; file.OffsetCount = 1; wad.DataOffsets.Add(0); dir.Files.Add(file); files.Add(file); } if (verbose == true) { Console.WriteLine("Collected {0} files.", files.Count); } using (var output = File.Create(outputPath)) { Console.WriteLine("Writing stub header..."); wad.Serialize(output); Console.WriteLine("Writing file data..."); foreach (var entry in files) { if (verbose == true) { Console.WriteLine(">> {0}", entry); } wad.DataOffsets[entry.OffsetIndex] = (uint)output.Position; using (var input = File.OpenRead(entry.FilePath)) { if (compressFiles == false) { entry.Size = (uint)input.Length; output.WriteFromStream(input, input.Length); } else { using (var temp = new MemoryStream()) { var zlib = new DeflaterOutputStream(temp, new Deflater(Deflater.BEST_COMPRESSION)); zlib.WriteFromStream(input, input.Length); zlib.Finish(); temp.Flush(); temp.Position = 0; if (temp.Length < input.Length) { entry.Size = (uint)(4 + temp.Length); output.WriteValueU32((uint)input.Length); output.WriteFromStream(temp, temp.Length); } else { input.Seek(0, SeekOrigin.Begin); entry.Size = (uint)(4 + input.Length); output.WriteValueU32(0xFFFFFFFFu); output.WriteFromStream(input, input.Length); } } } } } Console.WriteLine("Writing header..."); output.Seek(0, SeekOrigin.Begin); wad.Serialize(output); Console.WriteLine("Done!"); } }
public void BuildMap(string wadpath, string mapname) { wad = new WadFile(wadpath); BuildMap(wad, mapname); }
public void LoadMultigen(MultigenParser multigen, MultigenObject mobj, WadFile wad) { this.mobj = mobj; this.multigen = multigen; this.wad = wad; if (sprites == null) { sprites = new Dictionary <string, Sprite[]>(); } if (itemPickupSound == null) { itemPickupSound = new DoomSound(wad.GetLump("DSITEMUP"), "DSITEMUP").ToAudioClip(); } if (weaponPickupSound == null) { weaponPickupSound = new DoomSound(wad.GetLump("DSWPNUP"), "DSWPNUP").ToAudioClip(); } boxCollider = GetComponent <BoxCollider>(); boxCollider.isTrigger = !mobj.data["flags"].Contains("MF_SOLID"); radius = ReadFracValue(mobj.data["radius"]); height = ReadFracValue(mobj.data["height"]); speed = float.Parse(mobj.data["speed"]) / 128f; move = new Vector3(); boxCollider.size = new Vector3(radius, height, radius); reactionTime = float.Parse(mobj.data["reactiontime"]) * tick; spriteMaterial = new Material(Shader.Find("Doom/Texture")); Texture2D paletteLookup = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture(); Texture2D colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture(); spriteMaterial.SetTexture("_Palette", paletteLookup); spriteMaterial.SetTexture("_Colormap", colormapLookup); spriteRenderer = GetComponent <SpriteRenderer>(); spriteRenderer.material = spriteMaterial; string seeSoundName = ParseSoundName(mobj.data["seesound"]); if (wad.Contains(seeSoundName)) { seeSound = new DoomSound(wad.GetLump(seeSoundName), seeSoundName).ToAudioClip(); } string activeSoundName = ParseSoundName(mobj.data["activesound"]); if (wad.Contains(activeSoundName)) { activeSound = new DoomSound(wad.GetLump(activeSoundName), activeSoundName).ToAudioClip(); } string attackSoundName = ParseSoundName(mobj.data["attacksound"]); if (wad.Contains(attackSoundName)) { attackSound = new DoomSound(wad.GetLump(attackSoundName), attackSoundName).ToAudioClip(); } UpdateVerticalPosition(); SetState(mobj.data["spawnstate"]); }
public static Texture2D BuildTexture(string name, WadFile wad) { TextureTable textures = new TextureTable(wad.GetLump("TEXTURE1")); return(BuildTexture(name, wad, textures)); }
public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures) { if (textureCache == null) { textureCache = new Dictionary <string, Texture2D>(); } if (textureCache.ContainsKey(name)) { return(textureCache[name]); } PatchTable pnames = new PatchTable(wad.GetLump("PNAMES")); DoomTexture texture = textures.Get(name.ToUpper()); Texture2D output = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false, true); for (int i = 0; i < texture.patches.Count; i++) { DoomPatch p = texture.patches[i]; Texture2D patch2d = DoomGraphic.BuildPatch(p.patchIndex, pnames, wad); if (patch2d == null) { return(null); } int copyX = (p.originX < 0)?-p.originX:0; int copyY = (p.originY < 0)?-p.originY:0; int pasteX = (p.originX > 0)?p.originX:0; int pasteY = (p.originY > 0)?p.originY:0; int copyWidth = patch2d.width - copyX; if (copyWidth > output.width - pasteX) { copyWidth = output.width - pasteX; } int copyHeight = patch2d.height - copyY; if (copyHeight > output.height - pasteY) { copyHeight = output.height - pasteY; } for (int a = 0; a < copyWidth; a++) { for (int b = 0; b < copyHeight; b++) { Color col = patch2d.GetPixel(copyX + a, copyY + b); if (col.a != 0f) { output.SetPixel(pasteX + a, pasteY + b, col); } } } } output.Apply(); output.wrapMode = TextureWrapMode.Repeat; output.filterMode = FilterMode.Point; textureCache.Add(name, output); return(output); }
public void TestLoadWad2() { using FileStream f = File.OpenRead(@"F:\SteamLibrary\steamapps\common\quake\Id1\gfx_modified.wad"); WadFile wad = new WadFile(f); }
public void TestLoadWad3() { using FileStream f = File.OpenRead(@"F:\SteamLibrary\steamapps\common\Half-Life\valve\halflife.wad"); WadFile wad = new WadFile(f); }
public DoomText(WadFile wad) { this.wad = wad; }