2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.IO ;
2016-04-29 13:42:52 +00:00
using System.Text.RegularExpressions ;
using CodeImp.DoomBuilder.Compilers ;
2016-05-12 13:56:25 +00:00
using CodeImp.DoomBuilder.Config ;
2016-11-24 11:55:11 +00:00
using CodeImp.DoomBuilder.Data.Scripting ;
2016-04-29 13:42:52 +00:00
using CodeImp.DoomBuilder.GZBuilder.Data ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.IO ;
2022-01-04 19:17:12 +00:00
using CodeImp.DoomBuilder.Rendering ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.ZDoom ;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal sealed class WADReader : DataReader
{
#region = = = = = = = = = = = = = = = = = = Constants
2016-06-15 14:48:21 +00:00
//mxd. TEXTUREx flags
private const int TX_WORLDPANNING = 0x8000 ;
2016-06-26 22:42:24 +00:00
//mxd. Sprite recognition. Also http://regexr.com/ is a nice site ^.^
private static readonly Regex sprite6 = new Regex ( @"(\S{4}[A-Za-z\[\]\\]{1}[0-8]{1})" ) ;
private static readonly Regex sprite8 = new Regex ( @"(\S{4}[A-Za-z\[\]\\]{1}[0-8]{1}[A-Za-z\[\]\\]{1}[0-8]{1})" ) ;
2016-07-11 22:13:43 +00:00
//mxd. Voxel recognition.
private static readonly Regex voxel = new Regex ( @"^\S{4}(([A-Za-z][0-9]){0,2}|[A-Za-z]{0,1})$" ) ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Structures
private struct LumpRange
{
public int start ;
public int end ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
2022-09-18 17:54:53 +00:00
// Optional setting
public bool Silent = false ;
2009-04-19 18:07:22 +00:00
// Source
private WAD file ;
private bool is_iwad ;
2016-04-29 13:42:52 +00:00
private bool strictpatches ;
2009-04-19 18:07:22 +00:00
// Lump ranges
2016-04-29 13:42:52 +00:00
private List < LumpRange > flatranges ;
private List < LumpRange > invertedflatranges ; //mxd
private List < LumpRange > patchranges ;
private List < LumpRange > spriteranges ;
private List < LumpRange > textureranges ;
private List < LumpRange > hiresranges ; //mxd
private List < LumpRange > colormapranges ;
private List < LumpRange > voxelranges ; //mxd
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public bool IsIWAD { get { return is_iwad ; } }
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
internal WAD WadFile { get { return file ; } } //mxd
2016-11-24 11:55:11 +00:00
internal PK3StructuredReader ParentResource ; //mxd
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor
2022-09-18 17:54:53 +00:00
public WADReader ( DataLocation dl , GameConfiguration config , bool asreadonly ) : base ( dl , asreadonly )
2009-04-19 18:07:22 +00:00
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . WriteLogLine ( "Opening WAD resource \"" + location . location + "\"" ) ;
2009-04-19 18:07:22 +00:00
2010-10-03 16:54:38 +00:00
if ( ! File . Exists ( location . location ) )
throw new FileNotFoundException ( "Could not find the file \"" + location . location + "\"" , location . location ) ;
2016-04-29 13:42:52 +00:00
2009-04-19 18:07:22 +00:00
// Initialize
2016-11-24 11:55:11 +00:00
file = new WAD ( location . location , asreadonly ) ;
2009-04-19 18:07:22 +00:00
strictpatches = dl . option1 ;
2022-09-18 17:54:53 +00:00
Initialize ( config ) ; //mxd
2016-04-29 13:42:52 +00:00
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
2016-06-13 23:37:55 +00:00
//mxd. Constructor for temporary WAD files
2022-09-18 17:54:53 +00:00
internal WADReader ( DataLocation dl , GameConfiguration config , bool asreadonly , bool create ) : base ( dl , asreadonly )
2016-04-29 13:42:52 +00:00
{
if ( ! create )
{
General . WriteLogLine ( "Opening WAD resource \"" + location . location + "\"" ) ;
if ( ! File . Exists ( location . location ) )
throw new FileNotFoundException ( "Could not find the file \"" + location . location + "\"" , location . location ) ;
}
// Initialize
file = new WAD ( location . location , asreadonly ) ;
strictpatches = dl . option1 ;
2022-09-18 17:54:53 +00:00
Initialize ( config ) ;
2016-04-29 13:42:52 +00:00
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
//mxd
2022-09-18 17:54:53 +00:00
private void Initialize ( GameConfiguration config )
2016-04-29 13:42:52 +00:00
{
is_iwad = file . IsIWAD ;
2016-12-24 21:52:42 +00:00
isreadonly | = file . IsReadOnly ; // Just in case...
2016-04-29 13:42:52 +00:00
// Initialize
2009-04-19 18:07:22 +00:00
patchranges = new List < LumpRange > ( ) ;
spriteranges = new List < LumpRange > ( ) ;
flatranges = new List < LumpRange > ( ) ;
textureranges = new List < LumpRange > ( ) ;
2016-03-04 08:10:56 +00:00
hiresranges = new List < LumpRange > ( ) ; //mxd
2009-05-12 09:50:08 +00:00
colormapranges = new List < LumpRange > ( ) ;
2014-01-08 09:46:57 +00:00
voxelranges = new List < LumpRange > ( ) ; //mxd
2009-04-19 18:07:22 +00:00
// Find ranges
2022-09-18 17:54:53 +00:00
FindRanges ( config , patchranges , config . PatchRanges , "patches" , "Patch" ) ;
FindRanges ( config , spriteranges , config . SpriteRanges , "sprites" , "Sprite" ) ;
FindRanges ( config , flatranges , config . FlatRanges , "flats" , "Flat" ) ;
FindRanges ( config , textureranges , config . TextureRanges , "textures" , "Texture" ) ;
FindRanges ( config , hiresranges , config . HiResRanges , "hires" , "HiRes texture" ) ;
FindRanges ( config , colormapranges , config . ColormapRanges , "colormaps" , "Colormap" ) ;
FindRanges ( config , voxelranges , config . VoxelRanges , "voxels" , "Voxel" ) ;
2009-04-19 18:07:22 +00:00
2013-12-02 15:02:01 +00:00
//mxd
invertedflatranges = new List < LumpRange > ( ) ;
2014-12-03 23:15:26 +00:00
if ( flatranges . Count > 0 )
{
2014-04-09 10:16:33 +00:00
//add range before the first flatrange
2015-12-28 15:01:53 +00:00
if ( flatranges [ 0 ] . start > 0 )
2014-12-03 23:15:26 +00:00
{
2014-04-03 12:57:02 +00:00
LumpRange range = new LumpRange { start = 0 , end = flatranges [ 0 ] . start - 1 } ;
invertedflatranges . Add ( range ) ;
}
2013-12-02 15:02:01 +00:00
2014-04-08 11:09:05 +00:00
//add ranges between flatranges
2014-12-03 23:15:26 +00:00
for ( int i = 1 ; i < flatranges . Count ; i + + )
{
2014-04-08 11:09:05 +00:00
LumpRange range = new LumpRange { start = flatranges [ i - 1 ] . end + 1 , end = flatranges [ i ] . start - 1 } ;
invertedflatranges . Add ( range ) ;
}
2014-04-09 10:16:33 +00:00
//add range after the last flatrange
2014-12-03 23:15:26 +00:00
if ( flatranges [ flatranges . Count - 1 ] . end < file . Lumps . Count - 1 )
{
2014-04-08 11:09:05 +00:00
LumpRange range = new LumpRange { start = flatranges [ flatranges . Count - 1 ] . end + 1 , end = file . Lumps . Count - 1 } ;
2013-12-02 15:02:01 +00:00
invertedflatranges . Add ( range ) ;
}
2014-12-03 23:15:26 +00:00
}
else // No flat ranges? Make one giant range then...
{
2014-04-08 11:09:05 +00:00
LumpRange range = new LumpRange { start = 0 , end = file . Lumps . Count - 1 } ;
invertedflatranges . Add ( range ) ;
2013-12-02 15:02:01 +00:00
}
2009-04-19 18:07:22 +00:00
}
// Disposer
public override void Dispose ( )
{
// Not already disposed?
if ( ! isdisposed )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
General . WriteLogLine ( "Closing WAD resource \"" + location . location + "\"" ) ;
2009-04-19 18:07:22 +00:00
// Clean up
2019-12-29 14:38:53 +00:00
if ( file ! = null )
file . Dispose ( ) ;
2009-04-19 18:07:22 +00:00
// Done
base . Dispose ( ) ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Management
// Return a short name for this data location
public override string GetTitle ( )
{
return Path . GetFileName ( location . location ) ;
}
// This suspends use of this resource
public override void Suspend ( )
{
file . Dispose ( ) ;
2017-01-21 01:13:36 +00:00
file = null ;
2009-04-19 18:07:22 +00:00
base . Suspend ( ) ;
}
// This resumes use of this resource
public override void Resume ( )
{
base . Resume ( ) ;
2019-12-29 14:38:53 +00:00
file = new WAD ( location . location , IsReadOnly ) ;
2017-01-21 01:13:36 +00:00
}
// This fills a ranges list
2022-09-18 17:54:53 +00:00
private void FindRanges ( GameConfiguration config , List < LumpRange > ranges , IDictionary rangeinfos , string rangename , string elementname )
2009-04-19 18:07:22 +00:00
{
2014-10-31 13:53:43 +00:00
Dictionary < LumpRange , KeyValuePair < string , string > > failedranges = new Dictionary < LumpRange , KeyValuePair < string , string > > ( ) ; //mxd
Dictionary < int , bool > successfulrangestarts = new Dictionary < int , bool > ( ) ; //mxd
Dictionary < int , bool > failedrangestarts = new Dictionary < int , bool > ( ) ; //mxd
2009-04-19 18:07:22 +00:00
foreach ( DictionaryEntry r in rangeinfos )
{
// Read start and end
2022-09-18 17:54:53 +00:00
string rangestart = config . ReadSetting ( rangename + "." + r . Key + ".start" , "" ) ;
string rangeend = config . ReadSetting ( rangename + "." + r . Key + ".end" , "" ) ;
2009-04-19 18:07:22 +00:00
if ( ( rangestart . Length > 0 ) & & ( rangeend . Length > 0 ) )
{
// Find ranges
int startindex = file . FindLumpIndex ( rangestart ) ;
while ( startindex > - 1 )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
LumpRange range = new LumpRange { start = startindex , end = file . FindLumpIndex ( rangeend , startindex ) } ;
2009-04-19 18:07:22 +00:00
if ( range . end > - 1 )
{
2014-10-31 13:53:43 +00:00
if ( ! successfulrangestarts . ContainsKey ( startindex ) ) successfulrangestarts . Add ( startindex , false ) ; //mxd
2009-04-19 18:07:22 +00:00
ranges . Add ( range ) ;
startindex = file . FindLumpIndex ( rangestart , range . end ) ;
}
else
{
2014-10-31 13:53:43 +00:00
//mxd
2015-12-28 15:01:53 +00:00
if ( ! failedrangestarts . ContainsKey ( startindex ) )
2014-10-31 13:53:43 +00:00
{
failedranges . Add ( range , new KeyValuePair < string , string > ( rangestart , rangeend ) ) ; //mxd
failedrangestarts . Add ( startindex , false ) ;
}
2009-04-19 18:07:22 +00:00
startindex = - 1 ;
}
}
}
}
2014-10-31 13:53:43 +00:00
2016-03-14 10:25:27 +00:00
// Don't check official IWADs
if ( ! file . IsOfficialIWAD )
2014-10-31 13:53:43 +00:00
{
2016-03-14 10:25:27 +00:00
//mxd. Display warnings for unclosed ranges
foreach ( KeyValuePair < LumpRange , KeyValuePair < string , string > > group in failedranges )
{
if ( successfulrangestarts . ContainsKey ( group . Key . start ) ) continue ;
2022-09-18 17:54:53 +00:00
if ( ! Silent ) General . ErrorLogger . Add ( ErrorType . Warning , "\"" + group . Value . Key + "\" range at index " + group . Key . start + " is not closed in resource \"" + location . GetDisplayName ( ) + "\" (\"" + group . Value . Value + "\" marker is missing)." ) ;
2016-03-14 10:25:27 +00:00
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
2016-03-14 10:25:27 +00:00
//mxd. Check duplicates
foreach ( LumpRange range in ranges )
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
{
2016-03-14 10:25:27 +00:00
HashSet < string > names = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
for ( int i = range . start + 1 ; i < range . end ; i + + )
{
2022-09-18 17:54:53 +00:00
if ( names . Contains ( file . Lumps [ i ] . Name ) )
{
if ( ! Silent ) General . ErrorLogger . Add ( ErrorType . Warning , elementname + " \"" + file . Lumps [ i ] . Name + "\", index " + i + " is double defined in resource \"" + location . GetDisplayName ( ) + "\"." ) ;
}
2016-03-14 10:25:27 +00:00
else
names . Add ( file . Lumps [ i ] . Name ) ;
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
2014-10-31 13:53:43 +00:00
}
2009-04-19 18:07:22 +00:00
}
#endregion
#region = = = = = = = = = = = = = = = = = = Palette
// This loads the PLAYPAL palette
public override Playpal LoadPalette ( )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Look for a lump named PLAYPAL
2013-12-04 13:27:34 +00:00
Lump lump = file . FindLump ( "PLAYPAL" ) ;
2017-03-03 18:33:40 +00:00
if ( lump ! = null )
{
using ( Stream s = lump . GetSafeStream ( ) )
return new Playpal ( s ) ; // Read the PLAYPAL from stream
}
2013-12-04 13:27:34 +00:00
return null ; // No palette
2009-04-19 18:07:22 +00:00
}
2022-01-04 19:17:12 +00:00
public override ColorMap LoadMainColorMap ( Playpal palette )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Look for a lump named COLORMAP
Lump lump = file . FindLump ( "COLORMAP" ) ;
if ( lump ! = null )
{
using ( Stream s = lump . GetSafeStream ( ) )
return new ColorMap ( s , palette ) ;
}
return null ; // No palette
}
2009-04-19 18:07:22 +00:00
#endregion
2009-05-12 09:50:08 +00:00
#region = = = = = = = = = = = = = = = = = = Colormaps
// This loads the textures
public override ICollection < ImageData > LoadColormaps ( )
{
List < ImageData > images = new List < ImageData > ( ) ;
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Read ranges from configuration
foreach ( DictionaryEntry r in General . Map . Config . ColormapRanges )
{
// Read start and end
2015-12-28 15:01:53 +00:00
string rangestart = General . Map . Config . ReadSetting ( "colormaps." + r . Key + ".start" , "" ) ;
string rangeend = General . Map . Config . ReadSetting ( "colormaps." + r . Key + ".end" , "" ) ;
2009-05-12 09:50:08 +00:00
if ( ( rangestart . Length > 0 ) & & ( rangeend . Length > 0 ) )
{
// Load texture range
LoadColormapsRange ( rangestart , rangeend , ref images ) ;
}
}
// Add images to the container-specific texture set
2015-12-28 15:01:53 +00:00
foreach ( ImageData img in images ) textureset . AddFlat ( img ) ;
2009-05-12 09:50:08 +00:00
// Return result
return images ;
}
// This loads a range of colormaps
private void LoadColormapsRange ( string startlump , string endlump , ref List < ImageData > images )
{
// Continue until no more start can be found
2015-12-27 21:54:50 +00:00
int startindex = file . FindLumpIndex ( startlump ) ;
2009-05-12 09:50:08 +00:00
while ( startindex > - 1 )
{
// Find end index
2015-12-27 21:54:50 +00:00
int endindex = file . FindLumpIndex ( endlump , startindex + 1 ) ;
2009-05-12 09:50:08 +00:00
if ( endindex > - 1 )
{
// Go for all lumps between start and end exclusive
for ( int i = startindex + 1 ; i < endindex ; i + + )
{
// Lump not zero-length?
if ( file . Lumps [ i ] . Length > 0 )
{
// Make the image object
2015-12-27 21:54:50 +00:00
ColormapImage image = new ColormapImage ( file . Lumps [ i ] . Name ) ;
2009-05-12 09:50:08 +00:00
// Add image to collection
images . Add ( image ) ;
}
}
}
// Find the next start
startindex = file . FindLumpIndex ( startlump , startindex + 1 ) ;
}
}
// This finds and returns a colormap stream
public override Stream GetColormapData ( string pname )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2009-05-13 20:54:45 +00:00
// Strictly read patches only between C_START and C_END?
if ( strictpatches )
2009-05-12 09:50:08 +00:00
{
2009-05-13 20:54:45 +00:00
// Find the lump in ranges
foreach ( LumpRange range in colormapranges )
{
2015-12-27 21:54:50 +00:00
Lump lump = file . FindLump ( pname , range . start , range . end ) ;
2017-03-03 18:33:40 +00:00
if ( lump ! = null ) return lump . GetSafeStream ( ) ;
2009-05-13 20:54:45 +00:00
}
}
else
{
// Find the lump anywhere
2015-12-27 21:54:50 +00:00
Lump lump = file . FindLump ( pname ) ;
2017-03-03 18:33:40 +00:00
if ( lump ! = null ) return lump . GetSafeStream ( ) ;
2009-05-12 09:50:08 +00:00
}
return null ;
}
#endregion
2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Textures
// This loads the textures
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
public override IEnumerable < ImageData > LoadTextures ( PatchNames pnames , Dictionary < string , TexturesParser > cachedparsers )
2009-04-19 18:07:22 +00:00
{
2014-01-08 09:46:57 +00:00
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2009-04-19 18:07:22 +00:00
List < ImageData > images = new List < ImageData > ( ) ;
2014-01-08 09:46:57 +00:00
float defaultscale = General . Map . Config . DefaultTextureScale ; //mxd
2009-04-19 18:07:22 +00:00
// Load two sets of textures, if available
2015-01-15 20:48:57 +00:00
Lump lump = file . FindLump ( "TEXTURE1" ) ;
if ( lump ! = null )
{
2022-09-18 17:54:53 +00:00
LoadTextureSet ( "TEXTURE1" , lump . GetSafeStream ( ) , ref images , pnames , Silent ) ;
2015-01-15 20:48:57 +00:00
if ( images . Count > 0 ) images . RemoveAt ( 0 ) ; //mxd. The first TEXTURE1 texture cannot be used. Let's remove it here
}
2009-04-19 18:07:22 +00:00
lump = file . FindLump ( "TEXTURE2" ) ;
2022-09-18 17:54:53 +00:00
if ( lump ! = null ) LoadTextureSet ( "TEXTURE2" , lump . GetSafeStream ( ) , ref images , pnames , Silent ) ;
2009-04-19 18:07:22 +00:00
// Read ranges from configuration
foreach ( LumpRange range in textureranges )
{
2014-01-08 09:46:57 +00:00
// Go for all lumps between start and end exclusive
2014-12-03 23:15:26 +00:00
for ( int i = range . start + 1 ; i < range . end ; i + + )
{
2014-01-08 09:46:57 +00:00
// Lump not zero length?
2014-12-03 23:15:26 +00:00
if ( file . Lumps [ i ] . Length > 0 )
{
2014-01-08 09:46:57 +00:00
// Make the image
SimpleTextureImage image = new SimpleTextureImage ( file . Lumps [ i ] . Name , file . Lumps [ i ] . Name , defaultscale , defaultscale ) ;
// Add image to collection
images . Add ( image ) ;
2014-12-03 23:15:26 +00:00
}
else
{
2014-01-08 09:46:57 +00:00
// Can't load image without size
2022-09-18 17:54:53 +00:00
if ( ! Silent ) General . ErrorLogger . Add ( ErrorType . Error , "Can't load texture \"" + file . Lumps [ i ] . Name + "\" from \"" + location . GetDisplayName ( ) + "\" because it doesn't contain any data." ) ;
2014-01-08 09:46:57 +00:00
}
}
2009-04-19 18:07:22 +00:00
}
2010-08-13 15:19:51 +00:00
2009-04-19 18:07:22 +00:00
// Load TEXTURES lump file
2015-01-15 20:48:57 +00:00
int lumpindex = file . FindLumpIndex ( "TEXTURES" ) ;
2010-08-13 15:19:51 +00:00
while ( lumpindex > - 1 )
2009-04-19 18:07:22 +00:00
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Added TexturesParser caching
string fullpath = Path . Combine ( this . location . location , "TEXTURES#" + lumpindex ) ;
if ( cachedparsers . ContainsKey ( fullpath ) )
{
// Make the textures
foreach ( TextureStructure t in cachedparsers [ fullpath ] . Textures )
images . Add ( t . MakeImage ( ) ) ;
2022-03-05 15:57:23 +00:00
foreach ( TextureStructure t in cachedparsers [ fullpath ] . WallTextures )
images . Add ( t . MakeImage ( ) ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
else
{
2017-03-03 18:33:40 +00:00
Stream filedata = file . Lumps [ lumpindex ] . GetSafeStream ( ) ;
cachedparsers . Add ( fullpath , LoadTEXTURESTextures ( new TextResourceData ( this , filedata , "TEXTURES" , lumpindex , true ) , ref images ) ) ; //mxd
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
filedata . Dispose ( ) ;
}
2010-08-13 15:19:51 +00:00
// Find next
lumpindex = file . FindLumpIndex ( "TEXTURES" , lumpindex + 1 ) ;
2009-04-19 18:07:22 +00:00
}
2010-08-13 15:19:51 +00:00
2009-04-19 18:07:22 +00:00
// Add images to the container-specific texture set
2015-01-15 20:48:57 +00:00
foreach ( ImageData img in images ) textureset . AddTexture ( img ) ;
2009-04-19 18:07:22 +00:00
// Return result
return images ;
}
2016-03-04 08:10:56 +00:00
//mxd. This loads the HiRes textures
public override IEnumerable < HiResImage > LoadHiResTextures ( )
{
List < HiResImage > images = new List < HiResImage > ( ) ;
// Read ranges from configuration
foreach ( LumpRange range in hiresranges )
{
// Go for all lumps between start and end exclusive
for ( int i = range . start + 1 ; i < range . end ; i + + )
{
// Lump not zero length?
if ( file . Lumps [ i ] . Length > 0 )
{
// Add image to collection
images . Add ( new HiResImage ( file . Lumps [ i ] . Name ) ) ;
}
else
{
// Can't load image without size
2022-09-18 17:54:53 +00:00
if ( ! Silent ) General . ErrorLogger . Add ( ErrorType . Error , "Can't load HiRes texture \"" + file . Lumps [ i ] . Name + "\" from \"" + location . GetDisplayName ( ) + "\" because it doesn't contain any data." ) ;
2016-03-04 08:10:56 +00:00
}
}
}
return images ;
}
2009-04-19 18:07:22 +00:00
// This loads the texture definitions from a TEXTURES lump
2016-03-04 08:10:56 +00:00
public static TexturesParser LoadTEXTURESTextures ( TextResourceData data , ref List < ImageData > images )
2009-04-19 18:07:22 +00:00
{
// Parse the data
TexturesParser parser = new TexturesParser ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
parser . Parse ( data , false ) ;
2015-12-17 10:07:28 +00:00
if ( parser . HasError ) parser . LogError ( ) ; //mxd
2009-04-19 18:07:22 +00:00
2022-04-14 22:19:16 +00:00
// Make and add the textures
foreach ( TextureStructure t in parser . Textures )
images . Add ( t . MakeImage ( ) ) ;
// Make and add the wall textures
foreach ( TextureStructure t in parser . WallTextures )
2016-03-04 08:10:56 +00:00
images . Add ( t . MakeImage ( ) ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Add to text resources collection
2016-11-24 11:55:11 +00:00
if ( ! General . Map . Data . ScriptResources . ContainsKey ( parser . ScriptType ) )
General . Map . Data . ScriptResources [ parser . ScriptType ] = new HashSet < ScriptResource > ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
2016-11-24 11:55:11 +00:00
foreach ( KeyValuePair < string , ScriptResource > group in parser . ScriptResources )
General . Map . Data . ScriptResources [ parser . ScriptType ] . Add ( group . Value ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
return parser ; //mxd
2009-04-19 18:07:22 +00:00
}
// This loads a set of textures
2022-09-18 17:54:53 +00:00
public static void LoadTextureSet ( string sourcename , Stream texturedata , ref List < ImageData > images , PatchNames pnames , bool silent )
2009-04-19 18:07:22 +00:00
{
2013-12-03 10:50:33 +00:00
if ( texturedata . Length = = 0 ) return ;
2015-12-27 21:54:50 +00:00
BinaryReader reader = new BinaryReader ( texturedata ) ;
2010-08-14 15:44:47 +00:00
2009-04-19 18:07:22 +00:00
// Determine default scale
2015-12-27 21:54:50 +00:00
float defaultscale = General . Map . Config . DefaultTextureScale ;
2009-04-19 18:07:22 +00:00
// Get number of textures
texturedata . Seek ( 0 , SeekOrigin . Begin ) ;
2015-12-27 21:54:50 +00:00
uint numtextures = reader . ReadUInt32 ( ) ;
2009-04-19 18:07:22 +00:00
// 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
2015-12-27 21:54:50 +00:00
byte [ ] namebytes = reader . ReadBytes ( 8 ) ;
int flags = reader . ReadUInt16 ( ) ;
2016-06-15 14:48:21 +00:00
bool worldpanning = ( flags & TX_WORLDPANNING ) ! = 0 ; //mxd
2015-12-27 21:54:50 +00:00
byte scalebytex = reader . ReadByte ( ) ;
byte scalebytey = reader . ReadByte ( ) ;
int width = reader . ReadInt16 ( ) ;
int height = reader . ReadInt16 ( ) ;
int patches = reader . ReadInt16 ( ) ;
2009-04-19 18:07:22 +00:00
// Check for doom or strife data format
2015-12-27 21:54:50 +00:00
bool strifedata ;
2009-04-19 18:07:22 +00:00
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
2015-12-27 21:54:50 +00:00
float scalex = ( scalebytex = = 0 ? defaultscale : 1f / ( scalebytex / 8f ) ) ;
float scaley = ( scalebytey = = 0 ? defaultscale : 1f / ( scalebytey / 8f ) ) ;
2009-04-19 18:07:22 +00:00
// Validate data
2015-12-27 21:54:50 +00:00
if ( ( width > 0 ) & & ( height > 0 ) & & ( patches > 0 ) & & ( scalex ! = 0 ) | | ( scaley ! = 0 ) )
2009-04-19 18:07:22 +00:00
{
string texname = Lump . MakeNormalName ( namebytes , WAD . ENCODING ) ;
2015-12-27 21:54:50 +00:00
TextureImage image = null ;
2009-04-19 18:07:22 +00:00
if ( texname . Length > 0 )
{
// Make the image object
2015-03-22 20:43:05 +00:00
image = new TextureImage ( sourcename , Lump . MakeNormalName ( namebytes , WAD . ENCODING ) ,
2016-06-15 14:48:21 +00:00
width , height , scalex , scaley , worldpanning ) ;
2009-04-19 18:07:22 +00:00
}
else
{
// Can't load image without name
2022-09-18 17:54:53 +00:00
if ( ! silent ) General . ErrorLogger . Add ( ErrorType . Error , "Can't load an unnamed texture from \"" + sourcename + "\". Please consider giving names to your resources." ) ;
2009-04-19 18:07:22 +00:00
}
// Go for all patches in texture
for ( int p = 0 ; p < patches ; p + + )
{
// Read patch properties
2015-12-27 21:54:50 +00:00
int px = reader . ReadInt16 ( ) ;
int py = reader . ReadInt16 ( ) ;
int pi = reader . ReadUInt16 ( ) ;
2009-04-19 18:07:22 +00:00
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
2022-09-18 17:54:53 +00:00
if ( ! silent ) General . ErrorLogger . Add ( ErrorType . Error , "Can't use an unnamed patch referenced in \"" + sourcename + "\". Please consider giving names to your resources." ) ;
2009-04-19 18:07:22 +00:00
}
}
}
// Add image to collection
2015-12-29 18:22:08 +00:00
if ( image ! = null ) images . Add ( image ) ;
2009-04-19 18:07:22 +00:00
}
else
{
// Skip patches data
texturedata . Seek ( 6 * patches , SeekOrigin . Current ) ;
if ( ! strifedata ) texturedata . Seek ( 4 * patches , SeekOrigin . Current ) ;
}
}
}
// This returns the patch names from the PNAMES lump
public override PatchNames LoadPatchNames ( )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Look for a lump named PNAMES
2013-12-04 13:27:34 +00:00
Lump lump = file . FindLump ( "PNAMES" ) ;
2017-03-03 18:33:40 +00:00
if ( lump ! = null )
{
using ( Stream s = lump . GetSafeStream ( ) )
return new PatchNames ( s ) ; // Read the PNAMES from stream
}
2013-12-04 13:27:34 +00:00
return null ; // No patch names found
2009-04-19 18:07:22 +00:00
}
// This finds and returns a patch stream
2016-03-14 21:53:53 +00:00
public override Stream GetPatchData ( string pname , bool longname , ref string patchlocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-11-25 11:52:01 +00:00
if ( longname ) return null ; //mxd
Lump lump ;
2009-04-19 18:07:22 +00:00
2013-12-02 15:02:01 +00:00
// mxd. First strictly read patches between P_START and P_END
2014-11-25 11:52:01 +00:00
foreach ( LumpRange range in patchranges )
{
2013-12-02 15:02:01 +00:00
lump = file . FindLump ( pname , range . start , range . end ) ;
2017-03-03 18:33:40 +00:00
if ( lump ! = null ) return lump . GetSafeStream ( ) ;
2013-12-02 15:02:01 +00:00
}
2015-12-28 15:01:53 +00:00
if ( ! strictpatches )
2014-11-25 11:52:01 +00:00
{
2013-12-02 15:02:01 +00:00
//mxd. Find the lump anywhere EXCEPT flat ranges (the way it's done in ZDoom)
2015-12-28 15:01:53 +00:00
foreach ( LumpRange range in invertedflatranges )
2014-11-25 11:52:01 +00:00
{
2009-04-19 18:07:22 +00:00
lump = file . FindLump ( pname , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
patchlocation = location . GetDisplayName ( ) ;
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ;
2016-03-14 21:53:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
2013-12-02 15:02:01 +00:00
// Find the lump anywhere IN flat ranges
2015-12-28 15:01:53 +00:00
foreach ( LumpRange range in flatranges )
2014-11-25 11:52:01 +00:00
{
2013-12-02 15:02:01 +00:00
lump = file . FindLump ( pname , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
patchlocation = location . GetDisplayName ( ) ;
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ;
2016-03-14 21:53:53 +00:00
}
2013-09-11 09:47:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
return null ;
}
// This finds and returns a texture stream
2016-03-14 21:53:53 +00:00
public override Stream GetTextureData ( string pname , bool longname , ref string texturelocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-11-25 11:52:01 +00:00
if ( longname ) return null ; //mxd
2009-04-19 18:07:22 +00:00
// Find the lump in ranges
foreach ( LumpRange range in textureranges )
{
2015-12-28 15:01:53 +00:00
Lump lump = file . FindLump ( pname , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
texturelocation = location . GetDisplayName ( ) ; //mxd
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ;
2016-03-14 21:53:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
return null ;
}
2009-05-12 09:50:08 +00:00
2016-03-04 08:10:56 +00:00
//mxd. This finds and returns a HiRes texture stream
2016-03-14 21:53:53 +00:00
public override Stream GetHiResTextureData ( string name , ref string hireslocation )
2016-03-04 08:10:56 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find the lump in ranges
foreach ( LumpRange range in hiresranges )
{
Lump lump = file . FindLump ( name , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
hireslocation = location . GetDisplayName ( ) ;
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ;
2016-03-14 21:53:53 +00:00
}
2016-03-04 08:10:56 +00:00
}
return null ;
}
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Flats
2014-01-08 09:46:57 +00:00
//mxd. This loads the flats
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
public override IEnumerable < ImageData > LoadFlats ( Dictionary < string , TexturesParser > cachedparsers )
2014-11-25 11:52:01 +00:00
{
2009-04-19 18:07:22 +00:00
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-01-08 09:46:57 +00:00
List < ImageData > images = new List < ImageData > ( ) ;
2014-11-25 11:52:01 +00:00
foreach ( LumpRange range in flatranges )
{
2014-01-08 09:46:57 +00:00
if ( range . end < range . start + 2 ) continue ;
2014-11-25 11:52:01 +00:00
for ( int i = range . start + 1 ; i < range . end ; i + + )
{
2014-01-08 09:46:57 +00:00
// Lump not zero-length?
2015-12-28 15:01:53 +00:00
if ( file . Lumps [ i ] . Length > 0 )
2014-11-25 11:52:01 +00:00
{
2014-01-08 09:46:57 +00:00
// Make the image object
2015-12-28 15:01:53 +00:00
FlatImage image = new FlatImage ( file . Lumps [ i ] . Name ) ;
2014-01-08 09:46:57 +00:00
// Add image to collection
images . Add ( image ) ;
}
2009-04-19 18:07:22 +00:00
}
}
2010-08-18 05:49:15 +00:00
// Load TEXTURES lump file
2014-01-08 09:46:57 +00:00
int lumpindex = file . FindLumpIndex ( "TEXTURES" ) ;
2014-11-25 11:52:01 +00:00
while ( lumpindex > - 1 )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Added TexturesParser caching
string fullpath = Path . Combine ( this . location . location , "TEXTURES#" + lumpindex ) ;
if ( cachedparsers . ContainsKey ( fullpath ) )
{
// Make the textures
foreach ( TextureStructure t in cachedparsers [ fullpath ] . Flats )
images . Add ( t . MakeImage ( ) ) ;
}
else
{
2017-03-03 18:33:40 +00:00
Stream filedata = file . Lumps [ lumpindex ] . GetSafeStream ( ) ;
2016-03-04 08:10:56 +00:00
cachedparsers . Add ( fullpath , LoadTEXTURESFlats ( new TextResourceData ( this , filedata , "TEXTURES" , lumpindex , true ) , ref images ) ) ; //mxd
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
filedata . Dispose ( ) ;
}
2010-08-18 05:49:15 +00:00
// Find next
lumpindex = file . FindLumpIndex ( "TEXTURES" , lumpindex + 1 ) ;
}
2014-01-08 09:46:57 +00:00
2009-04-19 18:07:22 +00:00
// Add images to the container-specific texture set
2014-01-08 09:46:57 +00:00
foreach ( ImageData img in images ) textureset . AddFlat ( img ) ;
2009-04-19 18:07:22 +00:00
// Return result
return images ;
}
2010-08-18 05:49:15 +00:00
// This loads the flat definitions from a TEXTURES lump
2016-03-04 08:10:56 +00:00
public static TexturesParser LoadTEXTURESFlats ( TextResourceData data , ref List < ImageData > images )
2010-08-18 05:49:15 +00:00
{
// Parse the data
TexturesParser parser = new TexturesParser ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
parser . Parse ( data , false ) ;
2015-12-17 10:07:28 +00:00
if ( parser . HasError ) parser . LogError ( ) ; //mxd
2010-08-18 05:49:15 +00:00
2016-03-04 08:10:56 +00:00
// Make the flat
2010-08-18 05:49:15 +00:00
foreach ( TextureStructure t in parser . Flats )
{
2016-03-04 08:10:56 +00:00
// Add the flat
images . Add ( t . MakeImage ( ) ) ;
2010-08-18 05:49:15 +00:00
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Add to text resources collection
2016-11-24 11:55:11 +00:00
if ( ! General . Map . Data . ScriptResources . ContainsKey ( parser . ScriptType ) )
General . Map . Data . ScriptResources [ parser . ScriptType ] = new HashSet < ScriptResource > ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
2016-11-24 11:55:11 +00:00
foreach ( KeyValuePair < string , ScriptResource > group in parser . ScriptResources )
General . Map . Data . ScriptResources [ parser . ScriptType ] . Add ( group . Value ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
return parser ; //mxd
2010-08-18 05:49:15 +00:00
}
2009-04-19 18:07:22 +00:00
// This finds and returns a patch stream
2016-03-14 21:53:53 +00:00
public override Stream GetFlatData ( string pname , bool longname , ref string flatlocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-11-25 11:52:01 +00:00
if ( longname ) return null ; //mxd
2014-01-08 09:46:57 +00:00
2009-04-19 18:07:22 +00:00
// Find the lump in ranges
foreach ( LumpRange range in flatranges )
{
2015-12-28 15:01:53 +00:00
Lump lump = file . FindLump ( pname , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
flatlocation = location . GetDisplayName ( ) ; //mxd
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ;
2016-03-14 21:53:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
return null ;
}
#endregion
2016-06-26 22:42:24 +00:00
#region = = = = = = = = = = = = = = = = = = Sprites
2009-04-19 18:07:22 +00:00
2010-08-18 09:07:54 +00:00
// This loads the textures
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
public override IEnumerable < ImageData > LoadSprites ( Dictionary < string , TexturesParser > cachedparsers )
2010-08-18 09:07:54 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-01-08 09:46:57 +00:00
List < ImageData > images = new List < ImageData > ( ) ;
2010-08-18 09:07:54 +00:00
// Load TEXTURES lump file
2014-01-08 09:46:57 +00:00
int lumpindex = file . FindLumpIndex ( "TEXTURES" ) ;
2010-08-18 09:07:54 +00:00
while ( lumpindex > - 1 )
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Added TexturesParser caching
string fullpath = Path . Combine ( this . location . location , "TEXTURES#" + lumpindex ) ;
if ( cachedparsers . ContainsKey ( fullpath ) )
{
// Make the textures
foreach ( TextureStructure t in cachedparsers [ fullpath ] . Sprites )
images . Add ( t . MakeImage ( ) ) ;
}
else
{
2017-03-03 18:33:40 +00:00
Stream filedata = file . Lumps [ lumpindex ] . GetSafeStream ( ) ;
cachedparsers . Add ( fullpath , LoadTEXTURESSprites ( new TextResourceData ( this , filedata , "TEXTURES" , lumpindex , true ) , ref images ) ) ; //mxd
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
filedata . Dispose ( ) ;
}
2010-08-18 09:07:54 +00:00
// Find next
lumpindex = file . FindLumpIndex ( "TEXTURES" , lumpindex + 1 ) ;
}
// Return result
return images ;
}
// This loads the sprites definitions from a TEXTURES lump
2016-03-04 08:10:56 +00:00
public static TexturesParser LoadTEXTURESSprites ( TextResourceData data , ref List < ImageData > images )
2010-08-18 09:07:54 +00:00
{
// Parse the data
TexturesParser parser = new TexturesParser ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
parser . Parse ( data , false ) ;
2015-12-17 10:07:28 +00:00
if ( parser . HasError ) parser . LogError ( ) ; //mxd
2010-08-18 09:07:54 +00:00
2016-03-04 08:10:56 +00:00
// Make the sprites
2010-08-18 09:07:54 +00:00
foreach ( TextureStructure t in parser . Sprites )
{
2015-12-17 10:07:28 +00:00
// Add the sprite
2016-03-04 08:10:56 +00:00
images . Add ( t . MakeImage ( ) ) ;
2010-08-18 09:07:54 +00:00
}
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
//mxd. Add to text resources collection
2016-11-24 11:55:11 +00:00
if ( ! General . Map . Data . ScriptResources . ContainsKey ( parser . ScriptType ) )
General . Map . Data . ScriptResources [ parser . ScriptType ] = new HashSet < ScriptResource > ( ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
2016-11-24 11:55:11 +00:00
foreach ( KeyValuePair < string , ScriptResource > group in parser . ScriptResources )
General . Map . Data . ScriptResources [ parser . ScriptType ] . Add ( group . Value ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
return parser ; //mxd
2010-08-18 09:07:54 +00:00
}
2009-04-19 18:07:22 +00:00
// This finds and returns a sprite stream
2016-03-14 21:53:53 +00:00
public override Stream GetSpriteData ( string pname , ref string spritelocation )
2009-04-19 18:07:22 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find the lump in ranges
foreach ( LumpRange range in spriteranges )
{
2015-12-28 15:01:53 +00:00
Lump lump = file . FindLump ( pname , range . start , range . end ) ;
2016-03-14 21:53:53 +00:00
if ( lump ! = null )
{
spritelocation = location . GetDisplayName ( ) ; //mxd
2017-03-03 18:33:40 +00:00
return lump . GetSafeStream ( ) ; // [ZZ] return duplicate MemoryStream, not direct WAD stream. hopefully reduces esoteric errors and crashes.
2016-03-14 21:53:53 +00:00
}
2009-04-19 18:07:22 +00:00
}
return null ;
}
// This checks if the given sprite exists
public override bool GetSpriteExists ( string pname )
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
// Find the lump in ranges
foreach ( LumpRange range in spriteranges )
{
2015-12-28 15:01:53 +00:00
Lump lump = file . FindLump ( pname , range . start , range . end ) ;
2009-04-19 18:07:22 +00:00
if ( lump ! = null ) return true ;
}
return false ;
}
2016-04-08 14:02:08 +00:00
2016-07-11 22:13:43 +00:00
//mxd. This returns all sprite names in the WAD
public override HashSet < string > GetSpriteNames ( )
2016-04-08 14:02:08 +00:00
{
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
HashSet < string > result = new HashSet < string > ( ) ;
foreach ( LumpRange range in spriteranges )
{
for ( int i = range . start ; i < range . end + 1 ; i + + )
2016-07-11 22:13:43 +00:00
if ( IsValidSpriteName ( file . Lumps [ i ] . Name ) ) result . Add ( file . Lumps [ i ] . Name ) ;
2016-04-08 14:02:08 +00:00
}
return result ;
}
2016-06-26 22:42:24 +00:00
//mxd
internal static bool IsValidSpriteName ( string name )
{
return ( name . Length = = 6 & & sprite6 . IsMatch ( name ) ) | | ( name . Length = = 8 & & sprite8 . IsMatch ( name ) ) ;
}
2009-04-19 18:07:22 +00:00
#endregion
2014-01-08 09:46:57 +00:00
#region = = = = = = = = = = = = = = = = = = Voxels ( mxd )
//mxd. This returns the list of voxels, which can be used without VOXELDEF definition
2016-07-11 22:13:43 +00:00
public override HashSet < string > GetVoxelNames ( )
2014-12-03 23:15:26 +00:00
{
2014-01-08 09:46:57 +00:00
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2016-07-11 22:13:43 +00:00
HashSet < string > result = new HashSet < string > ( ) ;
2014-12-03 23:15:26 +00:00
foreach ( LumpRange range in voxelranges )
{
2014-01-08 09:46:57 +00:00
if ( range . start = = range . end ) continue ;
2014-12-03 23:15:26 +00:00
for ( int i = range . start + 1 ; i < range . end ; i + + )
{
2016-07-11 22:13:43 +00:00
if ( IsValidVoxelName ( file . Lumps [ i ] . Name ) ) result . Add ( file . Lumps [ i ] . Name ) ;
2014-01-08 09:46:57 +00:00
}
}
2016-07-11 22:13:43 +00:00
return result ;
2014-01-08 09:46:57 +00:00
}
//mxd. This finds and returns a voxel stream or null if no voxel was found
2016-07-11 22:13:43 +00:00
public override Stream GetVoxelData ( string name , ref string voxellocation )
2014-12-03 23:15:26 +00:00
{
2014-01-08 09:46:57 +00:00
// Error when suspended
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2014-12-03 23:15:26 +00:00
foreach ( LumpRange range in voxelranges )
{
2014-01-08 09:46:57 +00:00
if ( range . start = = range . end ) continue ;
2015-12-28 15:01:53 +00:00
Lump lump = file . FindLump ( name , range . start , range . end ) ;
2016-07-11 22:13:43 +00:00
if ( lump ! = null )
{
voxellocation = location . GetDisplayName ( ) ;
2017-03-03 18:33:40 +00:00
// Copy stream, because model/voxel streams are expected to be disposed
return lump . GetSafeStream ( ) ;
2016-07-11 22:13:43 +00:00
}
2014-01-08 09:46:57 +00:00
}
return null ;
}
2016-07-11 22:13:43 +00:00
//mxd
internal static bool IsValidVoxelName ( string name )
{
return ( name . Length > 3 & & name . Length < 7 ) & & voxel . IsMatch ( name ) ;
}
2014-01-08 09:46:57 +00:00
#endregion
2012-07-23 21:28:23 +00:00
#region = = = = = = = = = = = = = = = = = = Decorate , Gldefs , Mapinfo , etc . . .
2009-04-19 18:07:22 +00:00
2021-11-28 17:20:46 +00:00
public override IEnumerable < TextResourceData > GetDehackedData ( )
2021-09-05 12:59:31 +00:00
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2021-11-28 17:20:46 +00:00
return GetAllLumpsData ( "DEHACKED" ) ;
2021-09-05 12:59:31 +00:00
}
2021-12-10 10:10:42 +00:00
#region = = = = = = = = = = = = = = = = = = IWADINFO
public override List < IWadInfo > GetIWadInfos ( )
{
IWadInfoParser parser = new IWadInfoParser ( ) ;
foreach ( TextResourceData trd in GetAllLumpsData ( "IWADINFO" ) )
{
parser . Parse ( trd , false ) ;
if ( parser . HasError ) parser . LogError ( ) ;
}
return parser . IWads ;
}
#endregion
2016-02-26 23:35:32 +00:00
// This finds and returns DECORATE streams
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
public override IEnumerable < TextResourceData > GetDecorateData ( string pname )
2009-04-19 18:07:22 +00:00
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2016-12-02 13:45:03 +00:00
List < TextResourceData > result = GetAllLumpsData ( pname ) ; //mxd
2016-02-26 23:35:32 +00:00
//mxd. Return ALL DECORATE lumps
if ( result . Count = = 0 | | string . Compare ( pname , "DECORATE" , StringComparison . OrdinalIgnoreCase ) = = 0 )
return result ;
//mxd. Return THE LAST include lump, because that's the way ZDoom seems to operate
return new List < TextResourceData > { result [ result . Count - 1 ] } ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
}
2014-02-26 14:11:06 +00:00
2017-01-15 22:00:45 +00:00
// [ZZ] This finds and returns ZSCRIPT streams
public override IEnumerable < TextResourceData > GetZScriptData ( string pname )
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
List < TextResourceData > result = GetAllLumpsData ( pname ) ; //mxd
//mxd. Return ALL DECORATE lumps
if ( result . Count = = 0 | | string . Compare ( pname , "ZSCRIPT" , StringComparison . OrdinalIgnoreCase ) = = 0 )
return result ;
//mxd. Return THE LAST include lump, because that's the way ZDoom seems to operate
return new List < TextResourceData > { result [ result . Count - 1 ] } ;
}
2018-06-09 14:26:03 +00:00
// [ZZ] This finds and returns MODELDEF streams
public override IEnumerable < TextResourceData > GetModeldefData ( string pname )
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
List < TextResourceData > result = GetAllLumpsData ( pname ) ; //mxd
//mxd. Return ALL DECORATE lumps
if ( result . Count = = 0 | | string . Compare ( pname , "MODELDEF" , StringComparison . OrdinalIgnoreCase ) = = 0 )
return result ;
//mxd. Return THE LAST include lump, because that's the way ZDoom seems to operate
return new List < TextResourceData > { result [ result . Count - 1 ] } ;
}
2017-01-15 22:00:45 +00:00
//mxd. Should be only one entry per wad
public override IEnumerable < TextResourceData > GetMapinfoData ( )
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2010-08-12 10:03:29 +00:00
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
// First look for ZMAPINFO
List < TextResourceData > result = new List < TextResourceData > ( ) ;
2016-12-02 13:45:03 +00:00
result . AddRange ( GetLastLumpData ( "ZMAPINFO" ) ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
// Then for MAPINFO
2016-12-02 13:45:03 +00:00
if ( result . Count = = 0 ) result . AddRange ( GetLastLumpData ( "MAPINFO" ) ) ;
2014-10-23 12:48:31 +00:00
return result ;
2009-04-19 18:07:22 +00:00
}
2012-06-01 10:17:47 +00:00
2013-09-11 09:47:53 +00:00
//mxd
2016-07-14 23:39:48 +00:00
public override IEnumerable < TextResourceData > GetGldefsData ( string basegame )
2014-12-03 23:15:26 +00:00
{
2015-12-28 15:01:53 +00:00
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2012-06-01 10:17:47 +00:00
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
List < TextResourceData > result = new List < TextResourceData > ( ) ;
2012-06-01 10:17:47 +00:00
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
// Try to load game specific GLDEFS first
2016-07-14 23:39:48 +00:00
if ( basegame ! = GameType . UNKNOWN )
2014-12-03 23:15:26 +00:00
{
2016-07-14 23:39:48 +00:00
string lumpname = GameType . GldefsLumpsPerGame [ basegame ] ;
2016-12-02 13:45:03 +00:00
result . AddRange ( GetAllLumpsData ( lumpname ) ) ;
2013-09-11 09:47:53 +00:00
}
2012-06-01 10:17:47 +00:00
2016-04-23 23:15:43 +00:00
// Can be many entries per wad
2016-12-02 13:45:03 +00:00
result . AddRange ( GetAllLumpsData ( "GLDEFS" ) ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
return result ;
2013-09-11 09:47:53 +00:00
}
2012-06-01 10:17:47 +00:00
2023-09-15 19:28:20 +00:00
// sphere
public override IEnumerable < TextResourceData > GetLuaData ( )
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
return GetAllLumpsData ( "LUA_" ) ;
}
2013-09-11 09:47:53 +00:00
//mxd
2016-12-12 12:35:18 +00:00
public override IEnumerable < TextResourceData > GetTextLumpData ( ScriptType scripttype , bool singular , bool ignored )
2016-11-24 21:09:24 +00:00
{
if ( issuspended ) throw new Exception ( "Data reader is suspended" ) ;
2016-12-12 12:35:18 +00:00
string lumpname = Enum . GetName ( typeof ( ScriptType ) , scripttype ) . ToUpperInvariant ( ) ;
return ( singular ? GetLastLumpData ( lumpname ) : GetAllLumpsData ( lumpname ) ) ;
2016-11-24 21:09:24 +00:00
}
//mxd
2016-12-02 13:45:03 +00:00
private IEnumerable < TextResourceData > GetFirstLumpData ( string name )
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
{
List < TextResourceData > result = new List < TextResourceData > ( ) ;
int lumpindex = file . FindLumpIndex ( name ) ;
if ( lumpindex ! = - 1 )
2017-03-03 18:33:40 +00:00
result . Add ( new TextResourceData ( this , file . Lumps [ lumpindex ] . GetSafeStream ( ) , name , lumpindex , true ) ) ;
2015-05-28 13:45:01 +00:00
2015-12-18 10:16:53 +00:00
return result ;
}
//mxd
2016-12-02 13:45:03 +00:00
private IEnumerable < TextResourceData > GetLastLumpData ( string name )
{
List < TextResourceData > result = new List < TextResourceData > ( ) ;
int lumpindex = file . FindLastLumpIndex ( name ) ;
if ( lumpindex ! = - 1 )
2017-03-03 18:33:40 +00:00
result . Add ( new TextResourceData ( this , file . Lumps [ lumpindex ] . GetSafeStream ( ) , name , lumpindex , true ) ) ;
2016-12-02 13:45:03 +00:00
return result ;
}
//mxd
private List < TextResourceData > GetAllLumpsData ( string name )
2015-12-18 10:16:53 +00:00
{
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
List < TextResourceData > result = new List < TextResourceData > ( ) ;
// Find all lumps with given name
int lumpindex = file . FindLumpIndex ( name ) ;
while ( lumpindex > - 1 )
{
// Add to collection
2017-03-03 18:33:40 +00:00
result . Add ( new TextResourceData ( this , file . Lumps [ lumpindex ] . GetSafeStream ( ) , name , lumpindex , true ) ) ;
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
// Find next entry
lumpindex = file . FindLumpIndex ( name , lumpindex + 1 ) ;
}
2015-12-18 10:16:53 +00:00
2015-05-28 13:45:01 +00:00
return result ;
}
2016-04-29 13:42:52 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = IO ( mxd )
2014-12-03 23:15:26 +00:00
internal override MemoryStream LoadFile ( string name )
{
2013-09-11 09:47:53 +00:00
Lump l = file . FindLump ( name ) ;
2013-03-18 13:52:27 +00:00
2015-12-28 15:01:53 +00:00
if ( l ! = null )
2017-03-03 18:33:40 +00:00
return ( MemoryStream ) l . GetSafeStream ( ) ;
2013-03-18 13:52:27 +00:00
2013-09-11 09:47:53 +00:00
return null ;
}
2012-07-23 21:28:23 +00:00
2016-04-29 13:42:52 +00:00
internal override MemoryStream LoadFile ( string name , int lumpindex )
{
2016-11-24 11:55:11 +00:00
if ( lumpindex < 0 | | file . Lumps . Count < = lumpindex | | file . Lumps [ lumpindex ] . Name ! = name . ToUpperInvariant ( ) )
2016-04-29 13:42:52 +00:00
return null ;
Lump l = file . Lumps [ lumpindex ] ;
2017-03-03 18:33:40 +00:00
if ( l ! = null )
return ( MemoryStream ) l . GetSafeStream ( ) ;
return null ;
2016-04-29 13:42:52 +00:00
}
internal override bool SaveFile ( MemoryStream lumpdata , string lumpname )
{
if ( isreadonly ) return false ;
int insertindex = file . Lumps . Count ;
// Remove the lump if it already exists
int li = file . FindLumpIndex ( lumpname ) ;
if ( li > - 1 )
{
insertindex = li ;
file . RemoveAt ( li ) ;
}
// Insert new lump
Lump l = file . Insert ( lumpname , insertindex , ( int ) lumpdata . Length ) ;
l . Stream . Seek ( 0 , SeekOrigin . Begin ) ;
lumpdata . WriteTo ( l . Stream ) ;
2016-11-24 11:55:11 +00:00
// Update WAD file
file . WriteHeaders ( ) ;
2016-04-29 13:42:52 +00:00
return true ;
}
internal override bool SaveFile ( MemoryStream lumpdata , string lumpname , int lumpindex )
{
2016-11-24 11:55:11 +00:00
if ( isreadonly | | lumpindex < 0 | | file . Lumps . Count < = lumpindex | | file . Lumps [ lumpindex ] . Name ! = lumpname . ToUpperInvariant ( ) )
2016-04-29 13:42:52 +00:00
return false ;
2017-01-21 01:13:36 +00:00
// Remove the lump
file . RemoveAt ( lumpindex ) ;
2016-04-29 13:42:52 +00:00
2017-01-21 01:13:36 +00:00
// Insert new lump
Lump l = file . Insert ( lumpname , lumpindex , ( int ) lumpdata . Length ) ;
l . Stream . Seek ( 0 , SeekOrigin . Begin ) ;
lumpdata . WriteTo ( l . Stream ) ;
2016-04-29 13:42:52 +00:00
2017-01-21 01:13:36 +00:00
// Update WAD file
file . WriteHeaders ( ) ;
2016-11-24 11:55:11 +00:00
2016-04-29 13:42:52 +00:00
return true ;
}
internal override bool FileExists ( string lumpname )
{
return file . FindLumpIndex ( lumpname ) ! = - 1 ;
}
internal override bool FileExists ( string lumpname , int lumpindex )
{
return file . FindLumpIndex ( lumpname ) = = lumpindex ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Compiling ( mxd )
// This compiles a script lump and returns any errors that may have occurred
// Returns true when our code worked properly (even when the compiler returned errors)
2016-05-12 13:56:25 +00:00
internal override bool CompileLump ( string lumpname , ScriptConfiguration scriptconfig , List < CompilerError > errors )
2016-04-29 13:42:52 +00:00
{
int index = file . FindLumpIndex ( lumpname ) ;
if ( index = = - 1 )
{
2016-11-26 00:02:56 +00:00
errors . Add ( new CompilerError ( "Lump \"" + lumpname + "\" does not exist" , location . GetDisplayName ( ) ) ) ;
2016-04-29 13:42:52 +00:00
return false ;
}
2016-05-12 13:56:25 +00:00
return CompileLump ( lumpname , index , scriptconfig , errors ) ;
2016-04-29 13:42:52 +00:00
}
// This compiles a script lump and returns any errors that may have occurred
// Returns true when our code worked properly (even when the compiler returned errors)
2016-05-12 13:56:25 +00:00
internal override bool CompileLump ( string lumpname , int lumpindex , ScriptConfiguration scriptconfig , List < CompilerError > errors )
2014-12-03 23:15:26 +00:00
{
2016-05-12 13:56:25 +00:00
// No compiling required
if ( scriptconfig . Compiler = = null ) return true ;
string inputfile ;
Compiler compiler ;
string reallumpname = lumpname ;
// Find the lump
if ( lumpname = = MapManager . CONFIG_MAP_HEADER ) reallumpname = MapManager . TEMP_MAP_HEADER ;
2016-11-24 11:55:11 +00:00
Lump lump = file . FindLump ( reallumpname , lumpindex , lumpindex ) ;
2016-05-12 13:56:25 +00:00
if ( lump = = null )
throw new Exception ( "Unable to find lump \"" + reallumpname + "\" to compile in \"" + location . GetDisplayName ( ) + "\"." ) ;
// Determine source file
string sourcefile = ( General . Map . FilePathName . Length > 0 ? General . Map . FilePathName : file . Filename ) ;
// Initialize compiler
try
{
compiler = scriptconfig . Compiler . Create ( ) ;
}
catch ( Exception e )
{
// Fail
errors . Add ( new CompilerError ( "Unable to initialize compiler. " + e . GetType ( ) . Name + ": " + e . Message ) ) ;
return false ;
}
2016-11-24 11:55:11 +00:00
//mxd. AccCompiler requires some additional settings...
if ( scriptconfig . ScriptType = = ScriptType . ACS )
{
AccCompiler acccompiler = compiler as AccCompiler ;
if ( acccompiler = = null )
{
// Fail
errors . Add ( new CompilerError ( "Unexpected ACS compiler: " + compiler ) ) ;
return false ;
}
if ( lumpname = = "SCRIPTS" & & this = = General . Map . TemporaryMapFile )
{
acccompiler . SourceIsMapScriptsLump = true ;
}
else
{
//TODO: implement library compiling...
errors . Add ( new CompilerError ( "Compilation of ACS libraries is not supported yet..." ) ) ;
return false ;
}
}
2016-05-12 13:56:25 +00:00
try
{
// Write lump data to temp script file in compiler's temp directory
inputfile = General . MakeTempFilename ( compiler . Location , "tmp" ) ;
lump . Stream . Seek ( 0 , SeekOrigin . Begin ) ;
BinaryReader reader = new BinaryReader ( lump . Stream ) ;
File . WriteAllBytes ( inputfile , reader . ReadBytes ( ( int ) lump . Stream . Length ) ) ;
}
catch ( Exception e )
{
// Fail
compiler . Dispose ( ) ;
errors . Add ( new CompilerError ( "Unable to write script to working file. " + e . GetType ( ) . Name + ": " + e . Message ) ) ;
return false ;
}
// Make random output filename
string outputfile = General . MakeTempFilename ( compiler . Location , "tmp" ) ;
// Run compiler
compiler . Parameters = scriptconfig . Parameters ;
compiler . InputFile = Path . GetFileName ( inputfile ) ;
compiler . OutputFile = Path . GetFileName ( outputfile ) ;
compiler . SourceFile = sourcefile ;
compiler . WorkingDirectory = Path . GetDirectoryName ( inputfile ) ;
if ( compiler . Run ( ) )
{
// Process errors
foreach ( CompilerError e in compiler . Errors )
{
CompilerError newerror = e ;
// If the error's filename equals our temporary file, use the lump name instead and prefix it with ?
if ( string . Compare ( e . filename , inputfile , true ) = = 0 ) newerror . filename = "?" + reallumpname ;
errors . Add ( newerror ) ;
}
// No errors?
if ( compiler . Errors . Length = = 0 )
{
// Output file exists?
if ( File . Exists ( outputfile ) )
{
// Copy output file data into a lump?
if ( ! string . IsNullOrEmpty ( scriptconfig . ResultLump ) )
{
// Do that now then
byte [ ] filedata ;
try
{
filedata = File . ReadAllBytes ( outputfile ) ;
}
catch ( Exception e )
{
// Fail
compiler . Dispose ( ) ;
errors . Add ( new CompilerError ( "Unable to read compiler output file. " + e . GetType ( ) . Name + ": " + e . Message ) ) ;
return false ;
}
// Store data
SaveFile ( new MemoryStream ( filedata ) , scriptconfig . ResultLump ) ;
}
}
}
// Clean up
compiler . Dispose ( ) ;
// Done
return true ;
}
// Fail
compiler . Dispose ( ) ;
return false ;
2013-09-11 09:47:53 +00:00
}
2012-07-23 21:28:23 +00:00
2009-04-19 18:07:22 +00:00
#endregion
}
}