Closed kbatbouta closed 4 years ago
Using default value for bools result in black screen of death.
<Field Name="isNotHackable" FieldType="bool" TargetType="Verse.Pawn" DefaultValue="False"/>
or
<Field Name="isNotHackable" FieldType="bool" TargetType="Verse.Pawn" DefaultValue="false"/>
object defaultValue = null;
if (fieldTypeType != null)
{
var str = xml.Attributes[DefaultValueAttr]?.Value;
if (str != null)
{
if (str == "new()" && fieldTypeType.GetConstructor(new Type[0]) != null)
defaultValue = NewFieldData.DEFAULT_VALUE_NEW_CTOR;
else if (GetConstantOpCode(fieldTypeType) != null)
defaultValue = ParseHelper.FromString(str, fieldTypeType);
else if (fieldTypeType.IsValueType)
defaultValue = Activator.CreateInstance(fieldTypeType);
}
}
private static Type[] NotDefaultableTypes = new Type[]
{
typeof(bool)
};
and at the last two line of addfield
if (!NotDefaultableTypes.Contains(fieldType) && !IsNull(newField.defaultValue))
WriteFieldInitializers(newField, ceField, ceFieldType, fieldType);
if (code >= TypeCode.Boolean && code <= TypeCode.UInt32)
return cecilOpCodes.Ldc_I4;
Fixed
Code
results in:
Error
Notes