Bug in BodyTable, Bodies with an ID over 1000 we not being properly read.
Using Enum.TryParse where applicable
This commit is contained in:
parent
26899493c0
commit
b9f0138b08
5 changed files with 30 additions and 45 deletions
|
|
@ -45,7 +45,7 @@ namespace Server
|
|||
{
|
||||
using ( StreamReader ip = new StreamReader( "Data/bodyTable.cfg" ) )
|
||||
{
|
||||
m_Types = new BodyType[1000];
|
||||
m_Types = new BodyType[0x1000];
|
||||
|
||||
string line;
|
||||
|
||||
|
|
@ -56,15 +56,14 @@ namespace Server
|
|||
|
||||
string[] split = line.Split( '\t' );
|
||||
|
||||
try
|
||||
{
|
||||
int bodyID = int.Parse( split[0] );
|
||||
BodyType type = (BodyType)Enum.Parse( typeof( BodyType ), split[1], true );
|
||||
BodyType type;
|
||||
int bodyID;
|
||||
|
||||
if ( bodyID >= 0 && bodyID < m_Types.Length )
|
||||
m_Types[bodyID] = type;
|
||||
if( int.TryParse( split[0], out bodyID ) && Enum.TryParse( split[1], true, out type ) && bodyID >= 0 && bodyID < m_Types.Length )
|
||||
{
|
||||
m_Types[bodyID] = type;
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "Warning: Invalid bodyTable entry:" );
|
||||
Console.WriteLine( line );
|
||||
|
|
|
|||
|
|
@ -1126,32 +1126,30 @@ namespace Server
|
|||
return true;
|
||||
}
|
||||
|
||||
public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value )
|
||||
public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value ) where T : struct
|
||||
{
|
||||
return ReadEnum( xml, attribute, ref value, true );
|
||||
}
|
||||
|
||||
public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value, bool mandatory )
|
||||
public static bool ReadEnum<T>( XmlElement xml, string attribute, ref T value, bool mandatory ) where T : struct
|
||||
{
|
||||
string s = GetAttribute( xml, attribute, mandatory );
|
||||
|
||||
if ( s == null )
|
||||
return false;
|
||||
|
||||
Type type = typeof(T);
|
||||
T tempVal;
|
||||
|
||||
try
|
||||
if( Enum.TryParse( s, true, out tempVal ) )
|
||||
{
|
||||
value = (T)Enum.Parse(type, s, true);
|
||||
//TODO: On .NET 4.0, use Enum.TryParse
|
||||
value = tempVal;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", type, attribute, xml.Name );
|
||||
Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", typeof(T), attribute, xml.Name );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ReadMap( XmlElement xml, string attribute, ref Map value )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue