// METHODS public static Lump<SourceCubemap> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_VINDICTUS: case mapType.TYPE_DMOMAM: structLength = 16; break; default: structLength = 0; // This will cause the shit to hit the fan. break; } int offset = 0; Lump<SourceCubemap> lump = new Lump<SourceCubemap>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new SourceCubemap(bytes, type)); offset += structLength; } return lump; }
// METHODS public static Lump<DSector> createLump(byte [] data) { int offset = 0; int structLength = 26; Lump<DSector> lump = new Lump<DSector>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new DSector(bytes)); offset += structLength; } return lump; }
// METHODS //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextSettingsIndex'&keyword='jlca1156'" public static Lump<DThing> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_DOOM: structLength = 10; break; case mapType.TYPE_HEXEN: structLength = 20; break; } int offset = 0; Lump<DThing> lump = new Lump<DThing>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new DThing(bytes, type)); offset += structLength; } return lump; }
public Things_Hexen(Lump lump) : base(lump) { }
} //mxd internal void ModifyByDecorateActor(ActorStructure actor, bool replacetitle) { // Keep reference to actor this.actor = actor; this.classname = actor.ClassName; //mxd // Set the title if (actor.HasPropertyWithValue("$title")) { title = actor.GetPropertyAllValues("$title"); } else if (actor.HasPropertyWithValue("tag")) { string tag = actor.GetPropertyAllValues("tag"); if (!tag.StartsWith("\"$")) { title = tag; //mxd. Don't use LANGUAGE keywords. } } if (string.IsNullOrEmpty(title) || replacetitle) { title = actor.ClassName; } //mxd. Color override? if (actor.HasPropertyWithValue("$color")) { int ci = actor.GetPropertyValueInt("$color", 0); color = (ci == 0 || ci > 19 ? 18 : ci); } //mxd. Custom argument titles? for (int i = 0; i < args.Length; i++) { ArgumentInfo arg = actor.GetArgumentInfo(i); if (arg != null) { args[i] = arg; } } //mxd. Some SLADE compatibility if (actor.HasProperty("$angled")) { this.arrow = true; } else if (actor.HasProperty("$notangled")) { this.arrow = false; } //mxd. Marked as obsolete? if (actor.HasPropertyWithValue("$obsolete")) { obsoletemessage = actor.GetPropertyValueString("$obsolete", 0, true); obsolete = true; color = 4; //red } // Remove doublequotes from title title = ZDTextParser.StripQuotes(title); //mxd // Set sprite StateStructure.FrameInfo info = actor.FindSuitableSprite(); //mxd if (!locksprite && info != null) //mxd. Added locksprite property { sprite = info.Sprite; } else if (string.IsNullOrEmpty(sprite)) //mxd { sprite = DataManager.INTERNAL_PREFIX + "unknownthing"; } //mxd. Store dynamic light name lightname = (info != null ? info.LightName : string.Empty); //mxd. Create sprite frame this.spriteframe = new[] { new SpriteFrameInfo { Sprite = sprite, SpriteLongName = Lump.MakeLongName(sprite, true) } }; // Set sprite scale (mxd. Scale is translated to xscale and yscale in ActorStructure) if (actor.HasPropertyWithValue("xscale")) { this.spritescale.Width = actor.GetPropertyValueFloat("xscale", 0); } if (actor.HasPropertyWithValue("yscale")) { this.spritescale.Height = actor.GetPropertyValueFloat("yscale", 0); } // Size if (actor.HasPropertyWithValue("radius")) { radius = actor.GetPropertyValueInt("radius", 0); } if (actor.HasPropertyWithValue("height")) { height = actor.GetPropertyValueInt("height", 0); } //mxd. DistanceCheck. The value is CVAR. Also we'll need squared value if (actor.HasPropertyWithValue("distancecheck")) { string cvarname = actor.GetPropertyValueString("distancecheck", 0); if (!General.Map.Data.CVars.Integers.ContainsKey(cvarname)) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". DistanceCheck property references undefined cvar \"" + cvarname + "\""); distancechecksq = int.MaxValue; } else { distancechecksq = (int)Math.Pow(General.Map.Data.CVars.Integers[cvarname], 2); } } //mxd. Renderstyle if (actor.HasPropertyWithValue("renderstyle") && !actor.HasProperty("$ignorerenderstyle")) { renderstyle = actor.GetPropertyValueString("renderstyle", 0, true).ToLower(); } //mxd. Alpha if (actor.HasPropertyWithValue("alpha")) { this.alpha = General.Clamp(actor.GetPropertyValueFloat("alpha", 0), 0f, 1f); this.alphabyte = (byte)(this.alpha * 255); } else if (actor.HasProperty("defaultalpha")) { this.alpha = (General.Map.Config.BaseGame == GameType.HERETIC ? 0.4f : 0.6f); this.alphabyte = (byte)(this.alpha * 255); } //mxd. BRIGHT this.bright = (info != null && info.Bright) || actor.GetFlagValue("bright", false); // Safety if (this.radius < 4f || this.fixedsize) { this.radius = THING_FIXED_SIZE; } if (this.spritescale.Width == 0.0f) { this.spritescale.Width = 1.0f; } if (this.spritescale.Height == 0.0f) { this.spritescale.Height = 1.0f; } // Options hangs = actor.GetFlagValue("spawnceiling", hangs); int blockvalue = (blocking > 0) ? blocking : 2; blocking = actor.GetFlagValue("solid", (blocking != 0)) ? blockvalue : 0; xybillboard = actor.GetFlagValue("forcexybillboard", false); //mxd //mxd. GZDoom rendering flags if (actor.GetFlagValue("wallsprite", false)) { rendermode = ThingRenderMode.WALLSPRITE; } if (actor.GetFlagValue("flatsprite", false)) { // WALLSPRITE + FLATSPRITE = HORRIBLE GLITCHES in GZDoom if (rendermode == ThingRenderMode.WALLSPRITE) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". WALLSPRITE and FLATSPRITE flags can not be combined"); } else { rendermode = ThingRenderMode.FLATSPRITE; } } //mxd. WALLSPRITE and FLATSPRITE support rolling without the ROLLSPRITE flag rollsprite = actor.GetFlagValue("rollsprite", (rendermode == ThingRenderMode.WALLSPRITE || rendermode == ThingRenderMode.FLATSPRITE)); if (rollsprite) { rollcenter = actor.GetFlagValue("rollcenter", false); } //mxd if (blocking > THING_BLOCKING_NONE) { errorcheck = THING_ERROR_INSIDE_STUCK; } // [ZZ] dynamiclighttype = GZGeneral.GetGZLightTypeByClass(actor); }
private int LumpOffset(Lump lump) { return header.DirectoryEntries[(int)lump].Offset; }
// METHODS public static Lump<Node> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_QUAKE: structLength = 24; break; case mapType.TYPE_QUAKE2: case mapType.TYPE_SIN: case mapType.TYPE_SOF: case mapType.TYPE_DAIKATANA: structLength = 28; break; case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_DMOMAM: structLength = 32; break; case mapType.TYPE_VINDICTUS: structLength = 48; break; case mapType.TYPE_QUAKE3: case mapType.TYPE_FAKK: case mapType.TYPE_COD: case mapType.TYPE_STEF2: case mapType.TYPE_STEF2DEMO: case mapType.TYPE_MOHAA: case mapType.TYPE_RAVEN: case mapType.TYPE_NIGHTFIRE: structLength = 36; break; default: structLength = 0; // This will cause the shit to hit the fan. break; } int offset = 0; Lump<Node> lump = new Lump<Node>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new Node(bytes, type)); offset += structLength; } return lump; }
// Flood-fill textures public virtual void OnTextureFloodfill() { if (BuilderPlug.Me.CopiedFlat != null) { string oldtexture = GetTextureName(); string newtexture = BuilderPlug.Me.CopiedFlat; if (newtexture != oldtexture) { // Get the texture ImageData newtextureimage = General.Map.Data.GetFlatImage(newtexture); if (newtextureimage != null) { bool fillceilings = (this is VisualCeiling); if (fillceilings) { mode.CreateUndo("Flood-fill ceilings with " + newtexture); mode.SetActionResult("Flood-filled ceilings with " + newtexture + "."); } else { mode.CreateUndo("Flood-fill floors with " + newtexture); mode.SetActionResult("Flood-filled floors with " + newtexture + "."); } mode.Renderer.SetCrosshairBusy(true); General.Interface.RedrawDisplay(); if (mode.IsSingleSelection) { // Clear all marks, this will align everything it can General.Map.Map.ClearMarkedSectors(false); } else { // Limit the alignment to selection only General.Map.Map.ClearMarkedSectors(true); List <Sector> sectors = mode.GetSelectedSectors(); foreach (Sector s in sectors) { s.Marked = false; } } //mxd. We potentially need to deal with 2 textures (because of long and short texture names)... HashSet <long> oldtexturehashes = new HashSet <long> { Texture.LongName, Lump.MakeLongName(oldtexture) }; // Do the fill Tools.FloodfillFlats(this.Sector.Sector, fillceilings, oldtexturehashes, newtexture, false); // Get the changed sectors List <Sector> changes = General.Map.Map.GetMarkedSectors(true); foreach (Sector s in changes) { // Update the visual sector if (mode.VisualSectorExists(s)) { BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(s); if (fillceilings) { vs.Ceiling.Setup(); } else { vs.Floor.Setup(); } } } General.Map.Data.UpdateUsedTextures(); mode.Renderer.SetCrosshairBusy(false); mode.ShowTargetInfo(); } } } }
public void PassAnArgumentIntoExplicitArgumentsForARequestedInterfaceUsingObjectFactory() { ObjectFactory.Initialize(x => { x.For<IProvider>().Use<LumpProvider>(); }); var theLump = new Lump(); var provider = (LumpProvider)ObjectFactory.Container.With(theLump).GetInstance<IProvider>(); Assert.AreSame(theLump, provider.Lump); }
// Constructor public TextureBrowserForm(string selecttexture, bool browseflats) { Cursor.Current = Cursors.WaitCursor; General.Interface.DisableProcessing(); //mxd TreeNode item; //mxd long longname = Lump.MakeLongName(selecttexture ?? ""); longname = (browseflats ? General.Map.Data.GetFullLongFlatName(longname) : General.Map.Data.GetFullLongTextureName(longname)); //mxd int count; //mxd selectedset = null; //mxd this.browseflats = browseflats; //mxd // Initialize InitializeComponent(); //mxd. Set title string imagetype = (browseflats ? "flats" : "textures"); this.Text = "Browse " + imagetype; // Setup texture browser ImageBrowserControl.ShowTexturesFromSubDirectories = General.Settings.ReadSetting("windows." + configname + ".showtexturesfromsubdirs", true); ImageBrowserControl.UseLongTextureNames = General.Map.Options.UseLongTextureNames; browser.BrowseFlats = browseflats; browser.ApplySettings(); // Update the used textures General.Map.Data.UpdateUsedTextures(); tvTextureSets.BeginUpdate(); //mxd //mxd. Texture longname to select when list is filled selecttextureonfill = longname; // Make groups usedgroup = browser.AddGroup("Used " + imagetype + ":"); availgroup = browser.AddGroup("Available " + imagetype + ":"); //mxd. Make "Used" group collapsible usedgroupcollapsed = General.Settings.ReadSetting("windows." + configname + ".usedgroupcollapsed", false); browser.SetGroupCollapsed(usedgroup, usedgroupcollapsed); //mxd. Fill texture sets list with normal texture sets foreach (IFilledTextureSet ts in General.Map.Data.TextureSets) { count = (browseflats ? ts.Flats.Count : ts.Textures.Count); if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0)) { continue; } item = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]"); item.Name = ts.Name; item.Tag = ts; item.ImageIndex = 0; } //mxd. Add container-specific texture sets foreach (ResourceTextureSet ts in General.Map.Data.ResourceTextureSets) { count = (browseflats ? ts.Flats.Count : ts.Textures.Count); if ((count == 0 && !General.Map.Config.MixTexturesFlats) || (ts.Flats.Count == 0 && ts.Textures.Count == 0)) { continue; } item = tvTextureSets.Nodes.Add(ts.Name + " [" + count + "]"); item.Name = ts.Name; item.Tag = ts; item.ImageIndex = 2 + ts.Location.type; item.SelectedImageIndex = item.ImageIndex; CreateNodes(item); item.Expand(); } //mxd. Add "All" texture set count = (browseflats ? General.Map.Data.AllTextureSet.Flats.Count : General.Map.Data.AllTextureSet.Textures.Count); item = tvTextureSets.Nodes.Add(General.Map.Data.AllTextureSet.Name + " [" + count + "]"); item.Name = General.Map.Data.AllTextureSet.Name; item.Tag = General.Map.Data.AllTextureSet; item.ImageIndex = 1; item.SelectedImageIndex = item.ImageIndex; //mxd. Should we bother finding the correct texture set? if (General.Settings.LocateTextureGroup) { //mxd. Get the previously selected texture set string prevtextureset = General.Settings.ReadSetting("windows." + configname + ".textureset", ""); TreeNode match; // When texture set name is empty, select "All" texture set if (string.IsNullOrEmpty(prevtextureset)) { match = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1]; } else { match = FindNodeByName(tvTextureSets.Nodes, prevtextureset); } if (match != null) { IFilledTextureSet set = (match.Tag as IFilledTextureSet); foreach (ImageData img in (browseflats ? set.Flats : set.Textures)) { if (img.LongName == longname) { selectedset = match; break; } } } //mxd. If the selected texture was not found in the last-selected set, try finding it in the other sets if (selectedset == null && selecttexture != "-") { foreach (TreeNode n in tvTextureSets.Nodes) { selectedset = FindTextureByLongName(n, longname); if (selectedset != null) { break; } } } //mxd. Texture still not found? Then just select the last used set if (selectedset == null && match != null) { selectedset = match; } } //mxd. Select the found set or "All", if none were found if (tvTextureSets.Nodes.Count > 0) { if (selectedset == null) { selectedset = tvTextureSets.Nodes[tvTextureSets.Nodes.Count - 1]; } tvTextureSets.SelectedNodes.Clear(); tvTextureSets.SelectedNodes.Add(selectedset); selectedset.EnsureVisible(); } tvTextureSets.EndUpdate(); //mxd //mxd. Set splitter position and state (doesn't work when layout is suspended) if (General.Settings.ReadSetting("windows." + configname + ".splittercollapsed", false)) { splitter.IsCollapsed = true; } //mxd. Looks like SplitterDistance is unaffected by DPI scaling. Let's fix that... int splitterdistance = General.Settings.ReadSetting("windows." + configname + ".splitterdistance", int.MinValue); if (splitterdistance == int.MinValue) { splitterdistance = 210; if (MainForm.DPIScaler.Width != 1.0f) { splitterdistance = (int)Math.Round(splitterdistance * MainForm.DPIScaler.Width); } } splitter.SplitPosition = splitterdistance; }
// METHODS // createLump(byte[], uint) // Parses a byte array into a Lump object containing Brushes. public static Lump<Brush> createLump(byte[] inBytes, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_QUAKE2: case mapType.TYPE_DAIKATANA: case mapType.TYPE_SIN: case mapType.TYPE_SOF: case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_VINDICTUS: case mapType.TYPE_DMOMAM: case mapType.TYPE_NIGHTFIRE: case mapType.TYPE_STEF2: case mapType.TYPE_MOHAA: case mapType.TYPE_STEF2DEMO: case mapType.TYPE_RAVEN: case mapType.TYPE_QUAKE3: case mapType.TYPE_FAKK: structLength = 12; break; case mapType.TYPE_COD: case mapType.TYPE_COD2: case mapType.TYPE_COD4: structLength = 4; break; } int offset = 0; Lump<Brush> lump = new Lump<Brush>(inBytes.Length, structLength, inBytes.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < inBytes.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = inBytes[offset + j]; } lump.Add(new Brush(bytes, type)); offset += structLength; } return lump; }
private bool ParseGlowingFlats() { // Next sould be opening brace if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } // Parse inner blocks while (SkipWhitespace(true)) { string token = ReadToken().ToLowerInvariant(); if (token == "}") { break; // End of Glow structure } switch (token) { case "walls": case "flats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = ReadToken(); if (token == "}") { break; } // Add glow data long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullbright = true, Color = new PixelColor(255, 255, 255, 255), CalculateTextureColor = true }; } break; case "subwalls": case "subflats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = ReadToken(); if (token == "}") { break; } // Add glow data long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullblack = true, Subtractive = true, Color = new PixelColor(255, 0, 0, 0), CalculateTextureColor = false }; } break; case "subtexture": case "texture": { int color; int glowheight = DEFAULT_GLOW_HEIGHT; bool subtractivetexture = (token == "subtexture"); string texturename = StripQuotes(ReadToken(false)); if (string.IsNullOrEmpty(texturename)) { ReportError("expected " + token + " name"); return(false); } // Now we should find a comma if (!NextTokenIs(",", false)) { ReportError("Expected a comma"); return(false); } // Next is color SkipWhitespace(true); token = ReadToken(); if (!int.TryParse(token, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color)) { //probably it's a color name? Color c = Color.FromName(token); //should be similar to C++ color name detection, I suppose if (c.IsKnownColor) { color = PixelColor.FromColor(c).ToInt(); } else { ReportError("expected glow color value, but got \"" + token + "\""); return(false); } } // The glow data is valid at thispoint. Let's get texture hash long texturehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(texturename, General.Map.Options.UseLongTextureNames)); // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; continue; } // Can be glow height SkipWhitespace(true); token = ReadToken(); int h; if (int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out h)) { // Can't pass glowheight directly cause TryParse will unconditionally set it to 0 glowheight = h; // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; continue; } // Read the flag SkipWhitespace(true); token = ReadToken().ToLowerInvariant(); } // Next is "fullbright" or "fullblack" flag bool fullbright = (token == "fullbright"); bool fullblack = (!subtractivetexture && token == "fullblack"); if (!fullblack && !fullbright) { string expectedflags = (subtractivetexture ? "\"fullbright\"" : "\"fullbright\" or \"fullblack\""); ReportError("expected " + expectedflags + " flag, but got \"" + token + "\""); return(false); } // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Fullbright = fullbright, Fullblack = fullblack, Subtractive = subtractivetexture, Color = PixelColor.FromInt(color).WithAlpha(255), CalculateTextureColor = false }; } break; } } // All done here return(true); }
// METHODS public static Lump<Face> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_QUAKE: case mapType.TYPE_QUAKE2: case mapType.TYPE_DAIKATANA: structLength = 20; break; case mapType.TYPE_SIN: structLength = 36; break; case mapType.TYPE_SOF: structLength = 40; break; case mapType.TYPE_NIGHTFIRE: structLength = 48; break; case mapType.TYPE_SOURCE17: structLength = 104; break; case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_DMOMAM: structLength = 56; break; case mapType.TYPE_VINDICTUS: structLength = 72; break; case mapType.TYPE_QUAKE3: structLength = 104; break; case mapType.TYPE_MOHAA: structLength = 108; break; case mapType.TYPE_STEF2: case mapType.TYPE_STEF2DEMO: structLength = 132; break; case mapType.TYPE_RAVEN: structLength = 148; break; } int offset = 0; Lump<Face> lump = new Lump<Face>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new Face(bytes, type)); offset += structLength; } return lump; }
/// <summary> /// Parse the given WAD file located at <paramref name="wadFileStream"/> into a <see cref="Wad"/> object. If <paramref name="readBytes"/> is false /// then the bytes in each lump can be read using <see cref="ReadBytesIntoLump(FileStream, Lump)"/>. /// </summary> /// <param name="wadFileStream">The WAD FileStream</param> /// <param name="readBytes">Should the bytes be parsed into the lump object or not. Defaults to <c>true</c></param> /// <exception cref="WadParseException">Thrown if the WAD is in an invalid format</exception> /// <returns>The parsed WAD file with each of it's <see cref="Lump"/>s</returns> public static Wad Parse(FileStream wadFileStream, bool readBytes = true) { // read first 4 bytes to determine the WAD type var wadTypeBytes = ReadBytesAtPosition(wadFileStream, 0, 4); string wadType = Identifier.GetWadType(wadTypeBytes); int dirSize = WAD_DIRECTORY_SIZE; int nameOffset = WAD_NAME_OFFSET; int nameSize = WAD_NAME_SIZE; switch (wadType) { case Identifier.PWAD: case Identifier.IWAD: break; case Identifier.WAD2: case Identifier.WAD3: dirSize = WAD2_DIRECTORY_SIZE; nameOffset = WAD2_NAME_OFFSET; nameSize = WAD2_NAME_SIZE; break; default: throw new WadParseException($"Invalid WAD type '{wadType}'. Type must be one of: PWAD, IWAD, WAD2 or WAD3"); } int lumpCount = BitConverter.ToInt32(ReadBytesAtPosition(wadFileStream, 4, 4)); if (lumpCount > 65536 || lumpCount < 0) { throw new WadParseException($"Invalid number of lumps listed in header. Max supported 65536, found {lumpCount}"); } int directoryOffset = BitConverter.ToInt32(ReadBytesAtPosition(wadFileStream, 8, 4)); if (directoryOffset > wadFileStream.Length) { throw new WadParseException($"Directory offset {directoryOffset} is beyond the WAD filesize of {wadFileStream.Length}"); } if (directoryOffset < HEADER_SIZE) { throw new WadParseException($"Directory offset {directoryOffset} is before the WAD header"); } if ((directoryOffset + (dirSize * lumpCount)) > wadFileStream.Length) { throw new WadParseException($"Directory goes off the end of the WAD file"); } var lumpEntryNumber = -1; var maxLumpSize = wadFileStream.Length - (dirSize * lumpCount); var wad = new Wad(wadFileStream.Name, (int)wadFileStream.Length, Path.GetFileName(wadFileStream.Name)); wad.WadType = wadType; for (int position = directoryOffset; position < (directoryOffset + (lumpCount * dirSize)); position += dirSize) { int lumpOffset = BitConverter.ToInt32(ReadBytesAtPosition(wadFileStream, position, 4)); lumpEntryNumber++; byte[] lumpNameBytes = ReadBytesAtPosition(wadFileStream, position + nameOffset, nameSize); var nameLength = lumpNameBytes.Length; for (int i = 0; i < lumpNameBytes.Length; i++) { if (lumpNameBytes[i] == 0) { nameLength = i; break; } } string lumpName = Encoding.ASCII.GetString(lumpNameBytes, 0, nameLength); lumpName = lumpName.Trim(); Lump lump = new Lump { Offset = lumpOffset, Position = lumpEntryNumber, Size = BitConverter.ToInt32(ReadBytesAtPosition(wadFileStream, position + 4, 4)) }; if (String.IsNullOrEmpty(lumpName)) { lump.Name = "<CORRUPT NAME>"; lump.IsCorrupt = true; } else { lump.Name = lumpName; } switch (wadType) { case "WAD2": case "WAD3": lump.LumpType = BitConverter.ToInt16(ReadBytesAtPosition(wadFileStream, position + 12, 2)); lump.IsCompressed = BitConverter.ToInt16(ReadBytesAtPosition(wadFileStream, position + 14, 2)) == 1; break; } if (lump.Size == 0) { lump.Bytes = new byte[0]; } else if (lump.Size < 0 || lump.Size > maxLumpSize || lumpOffset < HEADER_SIZE) { lump.IsCorrupt = true; lump.Bytes = new byte[0]; lump.IsCorruptBytes = true; } else if (readBytes) { lump.Bytes = ReadBytesAtPosition(wadFileStream, lumpOffset, lump.Size); } wad.AddLump(lump); } return(wad); }
public DMXGUS(Lump lump) : base(lump) { }
public PCSpeaker(Lump lump) : base(lump) { }
// ARGH NO NO NO public FileStream GetLumpStream(Lump lump) { _stream.Seek(lump.Offset, 0); return(_stream); }
// This sets the name protected void SetName(string name) { this.name = name; this.longname = Lump.MakeLongName(name); }
public static bool Load(string mapName) { if (WadLoader.lumps.Count == 0) { Debug.LogError("MapLoader: Load: WadLoader.lumps == 0"); return(false); } //lumps { int i = 0; foreach (Lump l in WadLoader.lumps) { if (l.lumpName.Equals(mapName)) { goto found; } i++; } Debug.LogError("MapLoader: Load: Could not find map \"" + mapName + "\""); return(false); found: things_lump = WadLoader.lumps[++i]; linedefs_lump = WadLoader.lumps[++i]; sidedefs_lump = WadLoader.lumps[++i]; vertexes_lump = WadLoader.lumps[++i]; segs_lump = WadLoader.lumps[++i]; ssectors_lump = WadLoader.lumps[++i]; nodes_lump = WadLoader.lumps[++i]; sectors_lump = WadLoader.lumps[++i]; reject_lump = WadLoader.lumps[++i]; blockmap_lump = WadLoader.lumps[++i]; } //fixes a small mishap by original level developer, sector 7 is not closed if (mapName == "E1M3") { //linedef 933 second vertex will be changed to vertex index 764 linedefs_lump.data[13064] = 252; linedefs_lump.data[13065] = 2; } //things { int num = things_lump.data.Length / 10; things = new List <Thing>(num); for (int i = 0, n = 0; i < num; i++) { short x = (short)(things_lump.data[n++] | (short)things_lump.data[n++] << 8); short y = (short)(things_lump.data[n++] | (short)things_lump.data[n++] << 8); int facing = (int)(things_lump.data[n++] | (int)things_lump.data[n++] << 8); int thingtype = (int)things_lump.data[n++] | ((int)things_lump.data[n++]) << 8; int flags = (int)things_lump.data[n++] | ((int)things_lump.data[n++]) << 8; things.Add(new Thing(x, y, facing, thingtype, flags)); } } //vertices { int num = vertexes_lump.data.Length / 4; vertices = new List <Vertex>(num); for (int i = 0, n = 0; i < num; i++) { short x = (short)(vertexes_lump.data[n++] | (short)vertexes_lump.data[n++] << 8); short y = (short)(vertexes_lump.data[n++] | (short)vertexes_lump.data[n++] << 8); vertices.Add(new Vertex(x, y)); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } //sectors { int num = sectors_lump.data.Length / 26; sectors = new List <Sector>(num); for (int i = 0, n = 0; i < num; i++) { short hfloor = (short)(sectors_lump.data[n++] | (short)sectors_lump.data[n++] << 8); short hceil = (short)(sectors_lump.data[n++] | (short)sectors_lump.data[n++] << 8); string tfloor = Encoding.ASCII.GetString(new byte[] { sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tceil = Encoding.ASCII.GetString(new byte[] { sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++] }).TrimEnd('\0').ToUpper(); int bright = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; int special = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; int tag = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; sectors.Add(new Sector(hfloor, hceil, tfloor, tceil, special, tag, bright)); if (hfloor < minZ) { minZ = hfloor; } if (hceil > maxZ) { maxZ = hceil; } } } //sidedefs { int num = sidedefs_lump.data.Length / 30; sidedefs = new List <Sidedef>(num); for (int i = 0, n = 0; i < num; i++) { short offsetx = (short)(sidedefs_lump.data[n++] | (short)sidedefs_lump.data[n++] << 8); short offsety = (short)(sidedefs_lump.data[n++] | (short)sidedefs_lump.data[n++] << 8); string thigh = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tlow = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tmid = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); int sector = (int)(sidedefs_lump.data[n++] | (int)sidedefs_lump.data[n++] << 8); sidedefs.Add(new Sidedef(sectors[sector], offsetx, offsety, thigh, tlow, tmid, i)); } } //linedefs { int num = linedefs_lump.data.Length / 14; linedefs = new List <Linedef>(num); for (int i = 0, n = 0; i < num; i++) { int v1 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int v2 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int flags = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int action = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int tag = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int s1 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int s2 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; Linedef line = new Linedef(vertices[v1], vertices[v2], flags, action, tag); linedefs.Add(line); if (s1 != ushort.MaxValue) { sidedefs[s1].SetLine(line, true); } if (s2 != ushort.MaxValue) { sidedefs[s2].SetLine(line, false); } } } //SKY FIX { foreach (Linedef l in linedefs) { if (l.Back == null) { continue; } if (IsSkyTexture(l.Front.Sector.ceilingTexture)) { if (IsSkyTexture(l.Back.Sector.ceilingTexture)) { l.Front.tHigh = "F_SKY1"; l.Back.tHigh = "F_SKY1"; } } if (IsSkyTexture(l.Front.Sector.floorTexture)) { if (IsSkyTexture(l.Back.Sector.floorTexture)) { l.Front.tLow = "F_SKY1"; l.Back.tLow = "F_SKY1"; } } } } //modify geometry to accomodate expected changes foreach (Linedef l in linedefs) { if (l.lineType == 0) { continue; } switch (l.lineType) { default: break; //common doors case 1: case 26: case 27: case 28: case 31: case 46: { if (l.Back != null) { if (l.Back.Sector.maximumCeilingHeight == l.Back.Sector.ceilingHeight || l.Front.Sector.ceilingHeight - _4units < l.Back.Sector.maximumCeilingHeight) { l.Back.Sector.maximumCeilingHeight = l.Front.Sector.ceilingHeight - _4units; } } } break; //remote doors case 2: case 63: case 90: case 103: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Front.Sector == sector) { continue; } if (sector.maximumCeilingHeight == sector.ceilingHeight || s.Line.Front.Sector.ceilingHeight - _4units < sector.maximumCeilingHeight) { sector.maximumCeilingHeight = s.Line.Front.Sector.ceilingHeight - _4units; } } } } break; //stairbuilder, 8units case 8: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { List <Sector> stairs = new List <Sector>(); Sector targetSector = sector; int count = 0; bool failed = false; while (!failed) { count++; stairs.Add(targetSector); targetSector.maximumFloorHeight = sector.floorHeight + _8units * count; failed = true; foreach (Sidedef s in targetSector.Sidedefs) { if (s.Line.Back == null) { continue; } if (s.Line.Back.Sector == targetSector) { continue; } if (s.Line.Back.Sector.floorTexture != targetSector.floorTexture) { continue; } if (stairs.Contains(s.Line.Back.Sector)) { continue; } targetSector = s.Line.Back.Sector; failed = false; } } } } break; //raise floor to next higher case 20: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { float targetHeight = float.MaxValue; foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Back == null) { continue; } if (s.Line.Back.Sector == s.Line.Front.Sector) { continue; } if (s.Line.Front.Sector == sector) { if (s.Line.Back.Sector.floorHeight > sector.floorHeight && s.Line.Back.Sector.floorHeight < targetHeight) { targetHeight = s.Line.Back.Sector.floorHeight; } } if (s.Line.Back.Sector == sector) { if (s.Line.Front.Sector.floorHeight > sector.floorHeight && s.Line.Front.Sector.floorHeight < targetHeight) { targetHeight = s.Line.Front.Sector.floorHeight; } } } if (targetHeight < float.MaxValue) { sector.maximumFloorHeight = targetHeight; } } } break; //lowering platform case 36: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Front.Sector.floorHeight + _8units < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Front.Sector.floorHeight + _8units; } if (s.Line.Back != null) { if (s.Line.Back.Sector.floorHeight + _8units < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Back.Sector.floorHeight + _8units; } } } } } break; //common lifts case 62: case 88: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Front.Sector.floorHeight < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Front.Sector.floorHeight; } if (s.Line.Back != null) { if (s.Line.Back.Sector.floorHeight < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Back.Sector.floorHeight; } } } } } break; } } sizeX = maxX - minX; sizeY = maxY - minY; sizeZ = maxZ - minZ; CurrentMap = mapName; Debug.Log("Loaded map \"" + mapName + "\""); return(true); }
// This updates the properties from a decorate actor internal void ModifyByDecorateActor(ActorStructure actor) { // Keep reference to actor this.actor = actor; // Set the title if (actor.HasPropertyWithValue("$title")) { title = actor.GetPropertyAllValues("$title"); } else if (actor.HasPropertyWithValue("tag")) { title = actor.GetPropertyAllValues("tag"); } else if (string.IsNullOrEmpty(title)) { title = actor.ClassName; } // Remove doublequotes from title if ((title.Length > 2) && title.StartsWith("\"") && title.EndsWith("\"")) { title = title.Substring(1, title.Length - 2); } // Set sprite string suitablesprite = actor.FindSuitableSprite(); if (!string.IsNullOrEmpty(suitablesprite)) { sprite = suitablesprite; } this.spritelongname = Lump.MakeLongName(this.sprite); // Set sprite scale if (actor.HasPropertyWithValue("scale")) { float scale = actor.GetPropertyValueFloat("scale", 0); this.spritescale = new SizeF(scale, scale); } else { if (actor.HasPropertyWithValue("xscale")) { this.spritescale.Width = actor.GetPropertyValueFloat("xscale", 0); } if (actor.HasPropertyWithValue("yscale")) { this.spritescale.Height = actor.GetPropertyValueFloat("yscale", 0); } } // Size if (actor.HasPropertyWithValue("radius")) { radius = actor.GetPropertyValueInt("radius", 0); } if (actor.HasPropertyWithValue("height")) { height = actor.GetPropertyValueInt("height", 0); } // Safety if (this.radius < 4f) { this.radius = 8f; } if (this.spritescale.Width <= 0.0f) { this.spritescale.Width = 1.0f; } if (this.spritescale.Height <= 0.0f) { this.spritescale.Height = 1.0f; } // Options hangs = actor.GetFlagValue("spawnceiling", hangs); int blockvalue = (blocking > 0) ? blocking : 2; blocking = actor.GetFlagValue("solid", (blocking != 0)) ? blockvalue : 0; }
public static void Unload() { if (string.IsNullOrEmpty(CurrentMap)) { return; } foreach (Vertex v in vertices) { v.Linedefs.Clear(); } Sector.TaggedSectors = new Dictionary <int, List <Sector> >(); foreach (Sector s in sectors) { s.Sidedefs.Clear(); s.triangles.Clear(); } foreach (Linedef l in linedefs) { l.start = null; l.end = null; l.Front = null; l.Back = null; } foreach (Sidedef s in sidedefs) { s.Line = null; s.Sector = null; } AI.heatmap = new Vector3[0, 0]; for (int y = 0; y < TheGrid.sizeY; y++) { for (int x = 0; x < TheGrid.sizeX; x++) { foreach (Triangle t in TheGrid.triangles[x, y]) { t.sector = null; } TheGrid.triangles[x, y].Clear(); TheGrid.sectors[x, y].Clear(); TheGrid.linedefs[x, y].Clear(); TheGrid.decorThings[x, y].Clear(); TheGrid.neutralThings[x, y].Clear(); TheGrid.monsterThings[x, y].Clear(); TheGrid.itemThings[x, y].Clear(); } } TheGrid.triangles = new List <Triangle> [0, 0]; TheGrid.sizeX = 0; TheGrid.sizeY = 0; things_lump = null; linedefs_lump = null; sidedefs_lump = null; vertexes_lump = null; segs_lump = null; ssectors_lump = null; nodes_lump = null; sectors_lump = null; reject_lump = null; blockmap_lump = null; vertices.Clear(); sectors.Clear(); linedefs.Clear(); sidedefs.Clear(); things.Clear(); for (int c = 0; c < GameManager.Instance.transform.childCount; c++) { GameObject.Destroy(GameManager.Instance.transform.GetChild(c).gameObject); } for (int c = 0; c < GameManager.Instance.TemporaryObjectsHolder.childCount; c++) { GameObject.Destroy(GameManager.Instance.TemporaryObjectsHolder.GetChild(c).gameObject); } GameManager.Instance.Player[0].LastSector = null; GameManager.Instance.Player[0].currentSector = null; PlayerInfo.Instance.unfoundSecrets = new List <Sector>(); PlayerInfo.Instance.foundSecrets = new List <Sector>(); CurrentMap = ""; }
public Sectors(Lump lump) : base(lump) { }
public Vertices(Lump lump) : base(lump) { }
// Constructor public TextureBrowserForm(string selecttexture) { Cursor.Current = Cursors.WaitCursor; ListViewItem item; bool foundselecttexture = false; long longname = Lump.MakeLongName(selecttexture ?? ""); // Initialize InitializeComponent(); browser.ApplySettings(); // Update the used textures General.Map.Data.UpdateUsedTextures(); // Resize columns to maximize available width countcolumn.Width = COLUMN_WIDTH_COUNT; namecolumn.Width = texturesets.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth - countcolumn.Width - 2; // Fill texture sets list with normal texture sets foreach (IFilledTextureSet ts in General.Map.Data.TextureSets) { item = texturesets.Items.Add(ts.Name); item.Tag = ts; item.ImageIndex = 0; item.UseItemStyleForSubItems = false; item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular)); } // Add container-specific texture sets foreach (ResourceTextureSet ts in General.Map.Data.ResourceTextureSets) { item = texturesets.Items.Add(ts.Name); item.Tag = ts; item.ImageIndex = 2 + ts.Location.type; item.UseItemStyleForSubItems = false; item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular)); } // Add All textures set item = texturesets.Items.Add(General.Map.Data.AllTextureSet.Name); item.Tag = General.Map.Data.AllTextureSet; item.ImageIndex = 1; item.UseItemStyleForSubItems = false; item.SubItems.Add(General.Map.Data.AllTextureSet.Textures.Count.ToString(), item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular)); if (General.Map.Config.MixTexturesFlats && General.Map.Data.WallsTextureSet != null) { // Add All textures set item = texturesets.Items.Add(General.Map.Data.WallsTextureSet.Name); item.Tag = General.Map.Data.WallsTextureSet; item.ImageIndex = 1; item.UseItemStyleForSubItems = false; item.SubItems.Add(General.Map.Data.WallsTextureSet.Textures.Count.ToString(), item.ForeColor, item.BackColor, new Font(item.Font, FontStyle.Regular)); } // Select the last one that was selected // ano - renamed this from "selectname" because there's also a "selectedname" // in scope and it's confusing string cfgTextureSet = General.Settings.ReadSetting("browserwindow.textureset", ""); // ano - select flats box if we're on a mixflats/textures cfg and we're looking in "All" if (!foundselecttexture && General.Map.Config.MixTexturesFlats && cfgTextureSet == "All") { cfgTextureSet = "Textures"; } foreach (ListViewItem i in texturesets.Items) { if (i.Text == cfgTextureSet) { IFilledTextureSet set = (i.Tag as IFilledTextureSet); foreach (ImageData img in set.Textures) { if (img.LongName == longname) { i.Selected = true; foundselecttexture = true; break; } } break; } } // If the selected texture was not found in the last-selected set, try finding it in the other sets if (!foundselecttexture) { foreach (ListViewItem i in texturesets.Items) { IFilledTextureSet set = (i.Tag as IFilledTextureSet); foreach (ImageData img in set.Textures) { if (img.LongName == longname) { i.Selected = true; foundselecttexture = true; break; } } if (foundselecttexture) { break; } } } // Texture still now found? Then just select the last used set if (!foundselecttexture) { foreach (ListViewItem i in texturesets.Items) { if (i.Text == cfgTextureSet) { i.Selected = true; foundselecttexture = true; break; } } } // WARNING: Some strange behavior of the listview here! // When you leave this line out, the list becomes very slow. // Also, this does not change the item selected previously. texturesets.Items[0].Selected = true; // Texture to select when list is filled selecttextureonfill = selecttexture; // Make groups usedgroup = browser.AddGroup("Used Textures"); availgroup = browser.AddGroup("Available Textures"); // Keep last position and size lastposition = this.Location; lastsize = this.Size; // Position window from configuration settings this.SuspendLayout(); /* * this.Location = new Point(General.Settings.ReadSetting("browserwindow.positionx", this.Location.X), * General.Settings.ReadSetting("browserwindow.positiony", this.Location.Y)); */ this.Size = new Size(General.Settings.ReadSetting("browserwindow.sizewidth", this.Size.Width), General.Settings.ReadSetting("browserwindow.sizeheight", this.Size.Height)); this.WindowState = (FormWindowState)General.Settings.ReadSetting("browserwindow.windowstate", (int)FormWindowState.Normal); if (this.WindowState == FormWindowState.Normal) { this.StartPosition = FormStartPosition.CenterParent; } this.ResumeLayout(true); }
Tuple <Resource, Font> GetResource(Lump lump) { Reader.Seek(lump.Offset, SeekOrigin.Begin); if (lump.Type == 0x40 || lump.Type == 0x43) { string name = Trim(Encoding.ASCII.GetString(Reader.ReadBytes(16))); Contract.Assert(name == lump.Name); } int width = Reader.ReadInt32(); int height = Reader.ReadInt32(); Font font = null; if (lump.Type == 0x46) { int rows = Reader.ReadInt32(); int rowheight = Reader.ReadInt32(); int[] offsets = new int[256]; int[] widths = new int[256]; for (int i = 0; i < 256; ++i) { offsets[i] = Reader.ReadByte(); widths[i] = Reader.ReadByte(); } font = new Font(rows, rowheight, offsets, widths); } int mips = lump.Type == 0x40 || lump.Type == 0x43 ? 4 : 1; Resource resource = new Resource(new Size3i(width, height, 1), mips, 1, Format.R8G8B8A8UNorm); byte[][] images = new byte[mips][]; if (lump.Type == 0x40 || lump.Type == 0x43) { long offset0 = Reader.ReadUInt32(); long offset1 = Reader.ReadUInt32(); long offset2 = Reader.ReadUInt32(); long offset3 = Reader.ReadUInt32(); Reader.Seek(lump.Offset + offset0, SeekOrigin.Begin); images[0] = Reader.ReadBytes(width * height); Reader.Seek(lump.Offset + offset1, SeekOrigin.Begin); images[1] = Reader.ReadBytes((width / 2) * (height / 2)); Reader.Seek(lump.Offset + offset2, SeekOrigin.Begin); images[2] = Reader.ReadBytes((width / 4) * (height / 4)); Reader.Seek(lump.Offset + offset3, SeekOrigin.Begin); images[3] = Reader.ReadBytes((width / 8) * (height / 8)); } else { long offset0 = Reader.ReadUInt32(); Reader.Seek(lump.Offset + offset0, SeekOrigin.Begin); images[0] = Reader.ReadBytes(width * height); } Reader.Seek(2, SeekOrigin.Current); byte[] pallet; if (lump.Type == 0x42 || lump.Type == 0x43) { pallet = Reader.ReadBytes(256 * 3); } else { pallet = new byte[256 * 3]; for (int i = 0; i < 256; ++i) { int palletIndex = i * 3; pallet[palletIndex + 0] = (byte)i; pallet[palletIndex + 1] = (byte)i; pallet[palletIndex + 2] = (byte)i; } } for (int mipSlice = 0; mipSlice < mips; ++mipSlice) { byte[] image = images[mipSlice]; byte[] data = resource[mipSlice, 0]; for (int i = 0; i < image.Length; ++i) { int palletIndex = image[i] * 3; int dataIndex = i * 3; data[dataIndex + 0] = pallet[palletIndex + 0]; data[dataIndex + 1] = pallet[palletIndex + 1]; data[dataIndex + 2] = pallet[palletIndex + 2]; } } return(Tuple.Create(resource, font)); }
public static Lump<TexInfo> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_NIGHTFIRE: structLength = 32; break; case mapType.TYPE_QUAKE: structLength = 40; break; case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_VINDICTUS: structLength = 72; break; case mapType.TYPE_DMOMAM: structLength = 96; break; } int offset = 0; Lump<TexInfo> lump = new Lump<TexInfo>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new TexInfo(bytes, type)); offset += structLength; } return lump; }
public ColorWithLump(string color, Lump lump) { _color = color; _lump = lump; }
// Constructor internal ThingTypeInfo(ThingCategory cat, int index, Configuration cfg, IDictionary <string, EnumList> enums) { string key = index.ToString(CultureInfo.InvariantCulture); // Initialize this.index = index; this.category = cat; this.args = new ArgumentInfo[Linedef.NUM_ARGS]; this.isknown = true; this.actor = null; this.bright = false; //mxd this.distancechecksq = int.MaxValue; //mxd // Read properties this.title = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".title", "<" + key + ">"); this.sprite = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".sprite", cat.Sprite); this.color = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".color", cat.Color); this.alpha = General.Clamp(cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".alpha", cat.Alpha), 0f, 1f); //mxd this.alphabyte = (byte)(this.alpha * 255); //mxd this.renderstyle = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".renderstyle", cat.RenderStyle).ToLower(); //mxd this.arrow = (cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".arrow", cat.Arrow) != 0); this.radius = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".width", cat.Radius); this.height = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".height", cat.Height); this.hangs = (cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".hangs", cat.Hangs) != 0); this.blocking = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".blocking", cat.Blocking); this.errorcheck = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".error", cat.ErrorCheck); this.fixedsize = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".fixedsize", cat.FixedSize); this.fixedrotation = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".fixedrotation", cat.FixedRotation); //mxd this.absolutez = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".absolutez", cat.AbsoluteZ); float sscale = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".spritescale", cat.SpriteScale); this.spritescale = new SizeF(sscale, sscale); this.locksprite = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".locksprite", false); //mxd this.classname = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".class", String.Empty); //mxd this.thinglink = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".thinglink", 0); //mxd. Read flagsrename this.flagsrename = new Dictionary <string, Dictionary <string, string> >(StringComparer.OrdinalIgnoreCase); IDictionary maindic = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".flagsrename", new Hashtable()); foreach (DictionaryEntry de in maindic) { string ioname = de.Key.ToString().ToLowerInvariant(); switch (ioname) { case "doommapsetio": case "hexenmapsetio": case "universalmapsetio": IDictionary flagdic = de.Value as IDictionary; if (flagdic == null) { continue; } flagsrename.Add(ioname, new Dictionary <string, string>()); foreach (DictionaryEntry fe in flagdic) { flagsrename[ioname].Add(fe.Key.ToString(), fe.Value.ToString()); } break; default: throw new NotImplementedException("Unsupported MapSetIO"); } } // Read the args for (int i = 0; i < Linedef.NUM_ARGS; i++) { this.args[i] = new ArgumentInfo(cfg, "thingtypes." + cat.Name + "." + key, i, enums); } // Safety if (this.radius < 4f || this.fixedsize) { this.radius = THING_FIXED_SIZE; } if (this.hangs && this.absolutez) { this.hangs = false; //mxd } //mxd. Create sprite frame this.spriteframe = new[] { new SpriteFrameInfo { Sprite = sprite, SpriteLongName = Lump.MakeLongName(sprite, true) } }; // [ZZ] optional thing sprite. this.optional = cfg.ReadSetting("thingtypes." + cat.Name + "." + key + ".optional", cat.Optional); // We have no destructor GC.SuppressFinalize(this); }
public LumpProvider(Lump lump) { _lump = lump; }
//mxd. This tries to find all possible sprite rotations. Returns true when voxel substitute exists internal bool SetupSpriteFrame(HashSet <string> allspritenames, HashSet <string> allvoxelnames) { // Empty, invalid or internal sprites don't have rotations // Info: we can have either partial 5-char sprite name from DECORATE parser, // or fully defined 6/8-char sprite name defined in Game configuration or by $Sprite property if (string.IsNullOrEmpty(sprite) || sprite.StartsWith(DataManager.INTERNAL_PREFIX) || (sprite.Length != 5 && sprite.Length != 6 && sprite.Length != 8)) { return(false); } string sourcename = sprite.Substring(0, 4); char sourceframe = sprite[4]; // First try voxels if (allvoxelnames.Count > 0) { // Find a voxel, which matches sourcename HashSet <string> voxelnames = new HashSet <string>(); foreach (string s in allvoxelnames) { if (s.StartsWith(sourcename)) { voxelnames.Add(s); } } // Find a voxel, which matches baseframe // Valid voxel can be either 4-char (POSS), 5-char (POSSA) or 6-char (POSSA0) string newsprite = string.Empty; // Check 6-char voxels... foreach (string v in voxelnames) { if (v.Length == 6 && v.StartsWith(sourcename + sourceframe) && WADReader.IsValidSpriteName(v)) { newsprite = v; break; } } // Check 5-char voxels... if (voxelnames.Contains(sourcename + sourceframe)) { newsprite = sourcename + sourceframe; } // Check 4-char voxels... if (voxelnames.Contains(sourcename)) { newsprite = sourcename; } // Voxel found? if (!string.IsNullOrEmpty(newsprite)) { // Assign new sprite sprite = newsprite; // Recreate sprite frame spriteframe = new[] { new SpriteFrameInfo { Sprite = sprite, SpriteLongName = Lump.MakeLongName(sprite, true) } }; // Substitute voxel found return(true); } } // Then try sprites // Find a sprite, which matches sourcename string sourcesprite = string.Empty; HashSet <string> spritenames = new HashSet <string>(); foreach (string s in allspritenames) { if (s.StartsWith(sourcename)) { spritenames.Add(s); } } // Find a sprite, which matches baseframe foreach (string s in spritenames) { if (s[4] == sourceframe || (s.Length == 8 && s[6] == sourceframe)) { sourcesprite = s; break; } } // Abort if no sprite was found if (string.IsNullOrEmpty(sourcesprite)) { return(false); } // Get sprite angle string anglestr = sourcesprite.Substring(5, 1); int sourceangle; if (!int.TryParse(anglestr, NumberStyles.Integer, CultureInfo.InvariantCulture, out sourceangle)) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". Unable to get sprite angle from sprite \"" + sourcesprite + "\""); return(false); } if (sourceangle < 0 || sourceangle > 8) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ", sprite \"" + sourcesprite + "\". Sprite angle must be in [0..8] range"); return(false); } // No rotations? Then spriteframe is already setup if (sourceangle == 0) { // Sprite name still incomplete? if (sprite.Length < 6) { sprite = sourcesprite; // Recreate sprite frame. Mirror the sprite if sourceframe matches the second frame block spriteframe = new[] { new SpriteFrameInfo { Sprite = sprite, SpriteLongName = Lump.MakeLongName(sprite, true), Mirror = (sprite.Length == 8 && sprite[6] == sourceframe) } }; } return(false); } // Gather rotations string[] frames = new string[8]; bool[] mirror = new bool[8]; int processedcount = 0; // Process gathered sprites foreach (string s in spritenames) { // Check first frame block char targetframe = s[4]; if (targetframe == sourceframe) { // Check angle int targetangle; anglestr = s.Substring(5, 1); if (!int.TryParse(anglestr, NumberStyles.Integer, CultureInfo.InvariantCulture, out targetangle)) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". Unable to get sprite angle from sprite \"" + s + "\""); return(false); } // Sanity checks if (targetangle == 0) { General.ErrorLogger.Add(ErrorType.Warning, "Warning: actor \"" + title + "\":" + index + ", sprite \"" + sourcename + "\", frame " + targetframe + " has both rotated and non-rotated versions"); continue; } // More sanity checks if (targetangle < 1 || targetangle > 8) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ", sprite \"" + s + "\". Expected sprite angle in [1..8] range"); return(false); } // Even more sanity checks if (!string.IsNullOrEmpty(frames[targetangle - 1])) { General.ErrorLogger.Add(ErrorType.Warning, "Warning in actor \"" + title + "\":" + index + ". Sprite \"" + sourcename + "\", frame " + targetframe + ", angle " + targetangle + " is double-defined in sprites \"" + frames[targetangle - 1] + "\" and \"" + s + "\""); } else { // Add to collection frames[targetangle - 1] = s; processedcount++; } } // Check second frame block? if (s.Length == 6) { continue; } targetframe = s[6]; if (targetframe == sourceframe) { // Check angle int targetangle; anglestr = s.Substring(7, 1); if (!int.TryParse(anglestr, NumberStyles.Integer, CultureInfo.InvariantCulture, out targetangle)) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". Unable to get sprite angle from sprite \"" + s + "\""); return(false); } // Sanity checks if (targetangle == 0) { General.ErrorLogger.Add(ErrorType.Warning, "Warning: actor \"" + title + "\":" + index + ", sprite \"" + sourcename + "\", frame " + targetframe + " has both rotated and non-rotated versions"); continue; } // More sanity checks if (targetangle < 1 || targetangle > 8) { General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ", sprite \"" + s + "\". Expected sprite angle in [1..8] range"); return(false); } // Even more sanity checks if (!string.IsNullOrEmpty(frames[targetangle - 1])) { General.ErrorLogger.Add(ErrorType.Warning, "Warning in actor \"" + title + "\":" + index + ". Sprite \"" + sourcename + "\", frame " + targetframe + ", angle " + targetangle + " is double-defined in sprites \"" + frames[targetangle - 1] + "\" and \"" + s + "\""); } else { // Add to collections frames[targetangle - 1] = s; mirror[targetangle - 1] = true; processedcount++; } } // Gathered all sprites? if (processedcount == 8) { break; } } // Check collected data if (processedcount != 8) { // Check which angles are missing List <string> missingangles = new List <string>(); for (int i = 0; i < frames.Length; i++) { if (string.IsNullOrEmpty(frames[i])) { missingangles.Add((i + 1).ToString()); } } // Assemble angles to display string ma = string.Join(", ", missingangles.ToArray()); if (missingangles.Count > 2) { int pos = ma.LastIndexOf(",", StringComparison.Ordinal); if (pos != -1) { ma = ma.Remove(pos, 1).Insert(pos, " and"); } } General.ErrorLogger.Add(ErrorType.Error, "Error in actor \"" + title + "\":" + index + ". Sprite rotations " + ma + " for sprite " + sourcename + ", frame " + sourceframe + " are missing"); return(false); } // Create collection spriteframe = new SpriteFrameInfo[frames.Length]; for (int i = 0; i < frames.Length; i++) { spriteframe[i] = new SpriteFrameInfo { Sprite = frames[i], SpriteLongName = Lump.MakeLongName(frames[i]), Mirror = mirror[i] }; } // Update preview sprite sprite = spriteframe[1].Sprite; // Done return(false); }
// METHODS public static Lump<Edge> createLump(byte [] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_QUAKE: case mapType.TYPE_SIN: case mapType.TYPE_DAIKATANA: case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_DMOMAM: case mapType.TYPE_QUAKE2: case mapType.TYPE_SOF: structLength = 4; break; case mapType.TYPE_VINDICTUS: structLength = 8; break; case mapType.TYPE_DOOM: case mapType.TYPE_HEXEN: structLength = 4; break; } int offset = 0; Lump<Edge> lump = new Lump<Edge>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new Edge(bytes, type)); offset += structLength; } return lump; }
public Things(Lump lump) : base(lump) { }
public void SetLump(Lump lump) { TLump = lump; }
// This loads a set of textures public static void LoadTextureSet(string sourcename, Stream texturedata, ref List <ImageData> images, PatchNames pnames) { BinaryReader reader = new BinaryReader(texturedata); int flags, width, height, patches, px, py, pi; uint numtextures; byte scalebytex, scalebytey; float scalex, scaley, defaultscale; byte[] namebytes; TextureImage image = null; bool strifedata; if (texturedata.Length == 0) { return; } // Determine default scale defaultscale = General.Map.Config.DefaultTextureScale; // Get number of textures texturedata.Seek(0, SeekOrigin.Begin); numtextures = reader.ReadUInt32(); // Skip offset bytes (we will read all textures sequentially) texturedata.Seek(4 * numtextures, SeekOrigin.Current); // Go for all textures defined in this lump for (uint i = 0; i < numtextures; i++) { // Read texture properties namebytes = reader.ReadBytes(8); flags = reader.ReadUInt16(); scalebytex = reader.ReadByte(); scalebytey = reader.ReadByte(); width = reader.ReadInt16(); height = reader.ReadInt16(); patches = reader.ReadInt16(); // Check for doom or strife data format if (patches == 0) { // Ignore 2 bytes and then read number of patches texturedata.Seek(2, SeekOrigin.Current); patches = reader.ReadInt16(); strifedata = false; } else { // Texture data is in strife format strifedata = true; } // Determine actual scales if (scalebytex == 0) { scalex = defaultscale; } else { scalex = 1f / ((float)scalebytex / 8f); } if (scalebytey == 0) { scaley = defaultscale; } else { scaley = 1f / ((float)scalebytey / 8f); } // Validate data if ((width > 0) && (height > 0) && (patches > 0) && (scalex != 0) || (scaley != 0)) { string texname = Lump.MakeNormalName(namebytes, WAD.ENCODING); if (texname.Length > 0) { // Make the image object image = new TextureImage(Lump.MakeNormalName(namebytes, WAD.ENCODING), width, height, scalex, scaley); } else { // Can't load image without name General.ErrorLogger.Add(ErrorType.Error, "Can't load an unnamed texture from \"" + sourcename + "\". Please consider giving names to your resources."); } // Go for all patches in texture for (int p = 0; p < patches; p++) { // Read patch properties px = reader.ReadInt16(); py = reader.ReadInt16(); pi = reader.ReadUInt16(); if (!strifedata) { texturedata.Seek(4, SeekOrigin.Current); } // Validate data if ((pi >= 0) && (pi < pnames.Length)) { if (pnames[pi].Length > 0) { // Create patch on image if (image != null) { image.AddPatch(new TexturePatch(pnames[pi], px, py)); } } else { // Can't load image without name General.ErrorLogger.Add(ErrorType.Error, "Can't use an unnamed patch referenced in \"" + sourcename + "\". Please consider giving names to your resources."); } } } // Add image to collection images.Add(image); } else { // Skip patches data texturedata.Seek(6 * patches, SeekOrigin.Current); if (!strifedata) { texturedata.Seek(4 * patches, SeekOrigin.Current); } } } }
private static Texture ReadTexture(Stream stream, Lump lump) { stream.Seek(lump.Offset, SeekOrigin.Begin); if (lump.Type == TextureType.MipmapTexture) { var name = stream.ReadString(16); var width = (int)stream.ReadUint(); var height = (int)stream.ReadUint(); var offset = stream.ReadUint(); var mipmap1Offset = stream.ReadUint(); var mipmap2Offset = stream.ReadUint(); var mipmap3Offset = stream.ReadUint(); stream.Seek(lump.Offset + offset, SeekOrigin.Begin); var imageData = stream.ReadBytes(width * height); stream.Seek(lump.Offset + mipmap1Offset, SeekOrigin.Begin); var mipmap1Data = stream.ReadBytes(width / 2 * height / 2); stream.Seek(lump.Offset + mipmap2Offset, SeekOrigin.Begin); var mipmap2Data = stream.ReadBytes(width / 4 * height / 4); stream.Seek(lump.Offset + mipmap3Offset, SeekOrigin.Begin); var mipmap3Data = stream.ReadBytes(width / 8 * height / 8); var paletteSize = stream.ReadUshort(); var palette = Enumerable.Range(0, paletteSize) .Select(i => stream.ReadColor()) .ToArray(); return(Texture.CreateMipmapTexture(name, width, height, imageData, palette, mipmap1Data, mipmap2Data, mipmap3Data)); } else if (lump.Type == TextureType.Font) { var width = (int)stream.ReadUint(); var height = (int)stream.ReadUint(); var rowCount = (int)stream.ReadUint(); var rowHeight = (int)stream.ReadUint(); var charInfos = Enumerable.Range(0, 256) .Select(i => new CharInfo { StartOffset = stream.ReadUshort(), CharWidth = stream.ReadUshort() }) .ToArray(); var imageData = stream.ReadBytes(width * height); var paletteSize = stream.ReadUshort(); var palette = Enumerable.Range(0, paletteSize) .Select(i => stream.ReadColor()) .ToArray(); return(Texture.CreateFont(lump.Name, width, height, rowCount, rowHeight, charInfos, imageData, palette)); } else if (lump.Type == TextureType.SimpleTexture) { var width = (int)stream.ReadUint(); var height = (int)stream.ReadUint(); var imageData = stream.ReadBytes(width * height); var paletteSize = stream.ReadUshort(); var palette = Enumerable.Range(0, paletteSize) .Select(i => stream.ReadColor()) .ToArray(); return(Texture.CreateSimpleTexture(lump.Name, width, height, imageData, palette)); } else { throw new InvalidDataException($"Unknown texture type: {lump.Type}."); } }
// METHODS public static Lump <Leaf> createLump(byte[] data, mapType type) { int structLength = 0; switch (type) { case mapType.TYPE_QUAKE: case mapType.TYPE_QUAKE2: case mapType.TYPE_SIN: structLength = 28; break; case mapType.TYPE_SOURCE17: case mapType.TYPE_SOURCE20: case mapType.TYPE_SOURCE21: case mapType.TYPE_SOURCE22: case mapType.TYPE_SOURCE23: case mapType.TYPE_SOURCE27: case mapType.TYPE_TACTICALINTERVENTION: case mapType.TYPE_SOF: case mapType.TYPE_DAIKATANA: case mapType.TYPE_DMOMAM: structLength = 32; break; case mapType.TYPE_VINDICTUS: structLength = 56; break; case mapType.TYPE_COD: structLength = 36; break; case mapType.TYPE_NIGHTFIRE: case mapType.TYPE_QUAKE3: case mapType.TYPE_FAKK: case mapType.TYPE_STEF2DEMO: case mapType.TYPE_STEF2: case mapType.TYPE_RAVEN: structLength = 48; break; case mapType.TYPE_SOURCE18: case mapType.TYPE_SOURCE19: structLength = 56; break; case mapType.TYPE_MOHAA: structLength = 64; break; default: structLength = 0; // This will cause the shit to hit the fan. break; } int offset = 0; Lump <Leaf> lump = new Lump <Leaf>(data.Length, structLength, data.Length / structLength); byte[] bytes = new byte[structLength]; for (int i = 0; i < data.Length / structLength; i++) { for (int j = 0; j < structLength; j++) { bytes[j] = data[offset + j]; } lump.Add(new Leaf(bytes, type)); offset += structLength; } return(lump); }
// This is called to perform a search (and replace) // Returns a list of items to show in the results list // replacewith is null when not replacing public override FindReplaceObject[] Find(string value, bool withinselection, string replacewith, bool keepselection) { List <FindReplaceObject> objs = new List <FindReplaceObject>(); // Interpret the replacement if (replacewith != null) { // If it cannot be interpreted, set replacewith to null (not replacing at all) if (replacewith.Length < 0) { replacewith = null; } if ((General.Map.Config.MaxTextureNamelength > 0) && (replacewith.Length > General.Map.Config.MaxTextureNamelength)) { replacewith = null; } if (replacewith == null) { MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error); return(objs.ToArray()); } } // Interpret the find long longfind = Lump.MakeLongName(value.Trim()); // Where to search? ICollection <Sidedef> list = withinselection ? General.Map.Map.GetSidedefsFromSelectedLinedefs(true) : General.Map.Map.Sidedefs; // Go for all sidedefs foreach (Sidedef sd in list) { string side = sd.IsFront ? "front" : "back"; if (sd.LongHighTexture == longfind) { // Replace and add to list if (replacewith != null) { sd.SetTextureHigh(replacewith); } objs.Add(new FindReplaceObject(sd, "Sidedef " + sd.Index + " (" + side + ", high)")); } if (sd.LongMiddleTexture == longfind) { // Replace and add to list if (replacewith != null) { sd.SetTextureMid(replacewith); } objs.Add(new FindReplaceObject(sd, "Sidedef " + sd.Index + " (" + side + ", middle)")); } if (sd.LongLowTexture == longfind) { // Replace and add to list if (replacewith != null) { sd.SetTextureLow(replacewith); } objs.Add(new FindReplaceObject(sd, "Sidedef " + sd.Index + " (" + side + ", low)")); } } // When replacing, make sure we keep track of used textures if (replacewith != null) { General.Map.Data.UpdateUsedTextures(); } return(objs.ToArray()); }
public void can_build_a_concrete_type_from_explicit_args_passed_into_a_named_instance() { var container = new Container(x => { x.For<ColorWithLump>().AddInstances(o => { o.Type<ColorWithLump>().Ctor<string>("color").Is("red").Named("red"); o.Type<ColorWithLump>().Ctor<string>("color").Is("green").Named("green"); o.Type<ColorWithLump>().Ctor<string>("color").Is("blue").Named("blue"); }); }); var lump = new Lump(); var colorLump = container.With(lump).GetInstance<ColorWithLump>("red"); colorLump.Lump.ShouldBeTheSameAs(lump); colorLump.Color.ShouldEqual("red"); }
private bool ParseGlowingFlats() { // Next sould be opening brace if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } // Parse inner blocks while (SkipWhitespace(true)) { string token = ReadToken().ToLowerInvariant(); if (token == "}") { break; // End of Glow structure } switch (token) { case "walls": case "flats": if (!NextTokenIs("{", false)) { ReportError("Expected opening brace"); return(false); } while (SkipWhitespace(true)) { token = StripQuotes(ReadToken(false)); if (string.IsNullOrEmpty(token)) { continue; } if (token == "}") { break; } // Add glow data. Hash the name exactly as given. long flatnamehash = Lump.MakeLongName(token, true); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, Fullbright = true, Color = new PixelColor(255, 255, 255, 255), CalculateTextureColor = true }; } break; case "texture": { PixelColor color = new PixelColor(); int glowheight = DEFAULT_GLOW_HEIGHT; string texturename; if (!ReadTextureName(out texturename)) { return(false); } if (string.IsNullOrEmpty(texturename)) { ReportError("Expected " + token + " name"); return(false); } // Now we should find a comma if (!NextTokenIs(",", false)) { ReportError("Expected a comma"); return(false); } // Next is color SkipWhitespace(true); token = ReadToken(false); if (!GetColorFromString(token, ref color)) { ReportError("Expected glow color value, but got \"" + token + "\""); return(false); } // The glow data is valid at thispoint. Hash the name exactly as given. long texturehash = Lump.MakeLongName(texturename, true); // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; } // Can be glow height SkipWhitespace(true); token = ReadToken(); int h; if (int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out h)) { // Can't pass glowheight directly cause TryParse will unconditionally set it to 0 glowheight = h; // Now we can find a comma if (!NextTokenIs(",", false)) { // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; } // Read the flag SkipWhitespace(true); token = ReadToken().ToLowerInvariant(); } // Next must be "fullbright" flag if (token != "fullbright") { ReportError("Expected \"fullbright\" flag, but got \"" + token + "\""); return(false); } // Add glow data glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, Fullbright = true, Color = color.WithAlpha(255), CalculateTextureColor = false }; } break; } } // All done here return(true); }
public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { IContainer manager = new Container( registry => registry.For<IProvider>().Use<LumpProvider>()); var args = new ExplicitArguments(); var theLump = new Lump(); args.Set(theLump); var instance = (LumpProvider) manager.GetInstance<IProvider>(args); Assert.AreSame(theLump, instance.Lump); }
// This is called to perform a search (and replace) // Returns a list of items to show in the results list // replacewith is null when not replacing public override FindReplaceObject[] Find(string value, bool withinselection, string replacewith, bool keepselection) { List <FindReplaceObject> objs = new List <FindReplaceObject>(); // Interpret the replacement if (replacewith != null) { // If it cannot be interpreted, set replacewith to null (not replacing at all) if (replacewith.Length < 0) { replacewith = null; } if (replacewith.Length > 8) { replacewith = null; } if (replacewith == null) { MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error); return(objs.ToArray()); } } // Interpret the find long longfind = Lump.MakeLongName(value.Trim()); // Where to search? ICollection <Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors; // Go for all sectors foreach (Sector s in list) { // Flat matches? if (s.LongCeilTexture == longfind) { // Replace and add to list if (replacewith != null) { s.SetCeilTexture(replacewith); } objs.Add(new FindReplaceObject(s, "Sector " + s.Index + " (ceiling)")); } if (s.LongFloorTexture == longfind) { // Replace and add to list if (replacewith != null) { s.SetFloorTexture(replacewith); } objs.Add(new FindReplaceObject(s, "Sector " + s.Index + " (floor)")); } } // When replacing, make sure we keep track of used textures if (replacewith != null) { General.Map.Data.UpdateUsedTextures(); } return(objs.ToArray()); }
public void PassAnArgumentIntoExplicitArgumentsThatMightNotAlreadyBeRegistered() { var theLump = new Lump(); var provider = ObjectFactory.Container.With(theLump).GetInstance<LumpProvider>(); Assert.AreSame(theLump, provider.Lump); }
public bool Load(string mapName) { if (WadLoader.lumps.Count == 0) { Debug.LogError("MapLoader: Load: WadLoader.lumps == 0"); return(false); } //lumps { int i = 0; foreach (Lump l in WadLoader.lumps) { if (l.lumpName.Equals(mapName)) { goto found; } i++; } Debug.Log("MapLoader: Load: Could not find map name \"" + mapName + "\""); return(false); found: things_lump = WadLoader.lumps[++i]; linedefs_lump = WadLoader.lumps[++i]; sidedefs_lump = WadLoader.lumps[++i]; vertexes_lump = WadLoader.lumps[++i]; segs_lump = WadLoader.lumps[++i]; ssectors_lump = WadLoader.lumps[++i]; nodes_lump = WadLoader.lumps[++i]; sectors_lump = WadLoader.lumps[++i]; reject_lump = WadLoader.lumps[++i]; blockmap_lump = WadLoader.lumps[++i]; } //things { int num = things_lump.data.Length / 10; things = new List <Thing>(num); for (int i = 0, n = 0; i < num; i++) { short x = (short)(things_lump.data[n++] | (short)things_lump.data[n++] << 8); short y = (short)(things_lump.data[n++] | (short)things_lump.data[n++] << 8); int facing = (int)(things_lump.data[n++] | (int)things_lump.data[n++] << 8); int thingtype = (int)things_lump.data[n++] | ((int)things_lump.data[n++]) << 8; int flags = (int)things_lump.data[n++] | ((int)things_lump.data[n++]) << 8; things.Add(new Thing(x, y, facing, thingtype, flags)); } } //vertices { int num = vertexes_lump.data.Length / 4; vertices = new List <Vertex>(num); for (int i = 0, n = 0; i < num; i++) { short x = (short)(vertexes_lump.data[n++] | (short)vertexes_lump.data[n++] << 8); short y = (short)(vertexes_lump.data[n++] | (short)vertexes_lump.data[n++] << 8); vertices.Add(new Vertex(x, y)); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } //sectors { int num = sectors_lump.data.Length / 26; sectors = new List <Sector>(num); for (int i = 0, n = 0; i < num; i++) { short hfloor = (short)(sectors_lump.data[n++] | (short)sectors_lump.data[n++] << 8); short hceil = (short)(sectors_lump.data[n++] | (short)sectors_lump.data[n++] << 8); string tfloor = Encoding.ASCII.GetString(new byte[] { sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tceil = Encoding.ASCII.GetString(new byte[] { sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++], sectors_lump.data[n++] }).TrimEnd('\0').ToUpper(); int bright = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; int special = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; int tag = sectors_lump.data[n++] | ((int)sectors_lump.data[n++]) << 8; sectors.Add(new Sector(hfloor, hceil, tfloor, tceil, special, tag, bright)); if (hfloor < minZ) { minZ = hfloor; } if (hceil > maxZ) { maxZ = hceil; } } } //sidedefs { int num = sidedefs_lump.data.Length / 30; sidedefs = new List <Sidedef>(num); for (int i = 0, n = 0; i < num; i++) { short offsetx = (short)(sidedefs_lump.data[n++] | (short)sidedefs_lump.data[n++] << 8); short offsety = (short)(sidedefs_lump.data[n++] | (short)sidedefs_lump.data[n++] << 8); string thigh = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tlow = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); string tmid = Encoding.ASCII.GetString(new byte[] { sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++], sidedefs_lump.data[n++] }).TrimEnd('\0').ToUpper(); int sector = (int)(sidedefs_lump.data[n++] | (int)sidedefs_lump.data[n++] << 8); sidedefs.Add(new Sidedef(sectors[sector], offsetx, offsety, thigh, tlow, tmid)); } } //linedefs { int num = linedefs_lump.data.Length / 14; linedefs = new List <Linedef>(num); for (int i = 0, n = 0; i < num; i++) { int v1 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int v2 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int flags = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int action = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int tag = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int s1 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; int s2 = linedefs_lump.data[n++] | ((int)linedefs_lump.data[n++]) << 8; Linedef line = new Linedef(vertices[v1], vertices[v2], flags, action, tag); linedefs.Add(line); if (s1 != ushort.MaxValue) { sidedefs[s1].SetLine(line, true); } if (s2 != ushort.MaxValue) { sidedefs[s2].SetLine(line, false); } } } //SKY FIX { foreach (Linedef l in linedefs) { if (l.Back == null) { continue; } if (IsSkyTexture(l.Front.Sector.ceilingTexture)) { if (IsSkyTexture(l.Back.Sector.ceilingTexture)) { l.Front.tHigh = "F_SKY1"; l.Back.tHigh = "F_SKY1"; } } if (IsSkyTexture(l.Front.Sector.floorTexture)) { if (IsSkyTexture(l.Back.Sector.floorTexture)) { l.Front.tLow = "F_SKY1"; l.Back.tLow = "F_SKY1"; } } } } //modify geometry to accomodate expected changes foreach (Linedef l in linedefs) { if (l.lineType == 0) { continue; } switch (l.lineType) { default: break; case 1: case 26: //keycard doors case 27: case 28: { if (l.Back != null) { if (l.Back.Sector.maximumCeilingHeight == l.Back.Sector.ceilingHeight || l.Front.Sector.ceilingHeight - _4units < l.Back.Sector.maximumCeilingHeight) { l.Back.Sector.maximumCeilingHeight = l.Front.Sector.ceilingHeight - _4units; } } } break; case 36: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Front.Sector.floorHeight + _8units < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Front.Sector.floorHeight + _8units; } } } } break; case 88: { if (!Sector.TaggedSectors.ContainsKey(l.lineTag)) { break; } foreach (Sector sector in Sector.TaggedSectors[l.lineTag]) { foreach (Sidedef s in sector.Sidedefs) { if (s.Line.Front.Sector.floorHeight < sector.minimumFloorHeight) { sector.minimumFloorHeight = s.Line.Front.Sector.floorHeight; } } } } break; } } Debug.Log("Loaded map \"" + mapName + "\""); return(true); }