Use explicit Optional<T> type for OptionalCFrame.
This commit is contained in:
parent
0e7f9030c8
commit
f421743b08
@ -414,9 +414,13 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
|||||||
|
|
||||||
for (int i = 0; i < instCount; i++)
|
for (int i = 0; i < instCount; i++)
|
||||||
{
|
{
|
||||||
var cf = CFrames[i];
|
CFrame cf = CFrames[i];
|
||||||
bool active = reader.ReadBoolean();
|
bool archivable = reader.ReadBoolean();
|
||||||
CFrames[i] = active ? cf : null;
|
|
||||||
|
if (!archivable)
|
||||||
|
cf = null;
|
||||||
|
|
||||||
|
CFrames[i] = new Optional<CFrame>(cf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -984,7 +988,14 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Write(true);
|
if (prop.Value is Optional<CFrame> optional)
|
||||||
|
{
|
||||||
|
writer.Write(optional.HasValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cf = prop.Value as CFrame;
|
||||||
|
writer.Write(cf != null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
DataTypes/Optional.cs
Normal file
35
DataTypes/Optional.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
namespace RobloxFiles.DataTypes
|
||||||
|
{
|
||||||
|
// Optional represents a value that can be explicitly
|
||||||
|
// marked as an optional variant to a specified type.
|
||||||
|
// In practice this is used for OptionalCFrame.
|
||||||
|
|
||||||
|
public struct Optional<T>
|
||||||
|
{
|
||||||
|
public T Value;
|
||||||
|
public bool HasValue => (Value != null);
|
||||||
|
|
||||||
|
public Optional(T value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Value?.ToString() ?? "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator T(Optional<T> optional)
|
||||||
|
{
|
||||||
|
if (optional.HasValue)
|
||||||
|
return optional.Value;
|
||||||
|
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator Optional<T>(T value)
|
||||||
|
{
|
||||||
|
return new Optional<T>(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2408,7 +2408,7 @@ namespace RobloxFiles
|
|||||||
public Vector3 ModelMeshSize = new Vector3();
|
public Vector3 ModelMeshSize = new Vector3();
|
||||||
public bool NeedsPivotMigration;
|
public bool NeedsPivotMigration;
|
||||||
public BasePart PrimaryPart;
|
public BasePart PrimaryPart;
|
||||||
public CFrame WorldPivotData;
|
public Optional<CFrame> WorldPivotData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Actor : Model
|
public class Actor : Model
|
||||||
|
Binary file not shown.
@ -378,7 +378,7 @@ return
|
|||||||
ModelMeshData = "SharedString";
|
ModelMeshData = "SharedString";
|
||||||
ModelMeshSize = "Vector3";
|
ModelMeshSize = "Vector3";
|
||||||
NeedsPivotMigration = "bool";
|
NeedsPivotMigration = "bool";
|
||||||
WorldPivotData = "OptionalCFrame";
|
WorldPivotData = "Optional<CFrame>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -640,10 +640,6 @@ local function generateClasses()
|
|||||||
|
|
||||||
writeLine("[Obsolete]")
|
writeLine("[Obsolete]")
|
||||||
end
|
end
|
||||||
|
|
||||||
if valueType == "OptionalCFrame" then
|
|
||||||
valueType = "CFrame"
|
|
||||||
end
|
|
||||||
|
|
||||||
writeLine("public %s %s%s;", valueType, name, default)
|
writeLine("public %s %s%s;", valueType, name, default)
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
<Compile Include="BinaryFormat\IO\BinaryFileReader.cs" />
|
<Compile Include="BinaryFormat\IO\BinaryFileReader.cs" />
|
||||||
<Compile Include="BinaryFormat\IO\BinaryFileWriter.cs" />
|
<Compile Include="BinaryFormat\IO\BinaryFileWriter.cs" />
|
||||||
<Compile Include="DataTypes\Color3uint8.cs" />
|
<Compile Include="DataTypes\Color3uint8.cs" />
|
||||||
|
<Compile Include="DataTypes\Optional.cs" />
|
||||||
<Compile Include="DataTypes\ProtectedString.cs" />
|
<Compile Include="DataTypes\ProtectedString.cs" />
|
||||||
<Compile Include="DataTypes\Content.cs" />
|
<Compile Include="DataTypes\Content.cs" />
|
||||||
<Compile Include="DataTypes\Region3int16.cs" />
|
<Compile Include="DataTypes\Region3int16.cs" />
|
||||||
|
Binary file not shown.
@ -599,7 +599,7 @@ namespace RobloxFiles
|
|||||||
propType = Property.Types[fieldType];
|
propType = Property.Types[fieldType];
|
||||||
else if (fieldType.IsEnum)
|
else if (fieldType.IsEnum)
|
||||||
propType = PropertyType.Enum;
|
propType = PropertyType.Enum;
|
||||||
|
|
||||||
if (propType != PropertyType.Unknown)
|
if (propType != PropertyType.Unknown)
|
||||||
{
|
{
|
||||||
if (fieldName.EndsWith("_"))
|
if (fieldName.EndsWith("_"))
|
||||||
@ -615,24 +615,35 @@ namespace RobloxFiles
|
|||||||
case "String":
|
case "String":
|
||||||
case "Double":
|
case "Double":
|
||||||
case "Int64":
|
case "Int64":
|
||||||
|
{
|
||||||
xmlToken = xmlToken.ToLowerInvariant();
|
xmlToken = xmlToken.ToLowerInvariant();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "Boolean":
|
case "Boolean":
|
||||||
|
{
|
||||||
xmlToken = "bool";
|
xmlToken = "bool";
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "Single":
|
case "Single":
|
||||||
|
{
|
||||||
xmlToken = "float";
|
xmlToken = "float";
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "Int32":
|
case "Int32":
|
||||||
|
{
|
||||||
xmlToken = "int";
|
xmlToken = "int";
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "Rect":
|
case "Rect":
|
||||||
|
{
|
||||||
xmlToken = "Rect2D";
|
xmlToken = "Rect2D";
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "CFrame":
|
case "CFrame":
|
||||||
|
{
|
||||||
xmlToken = "CoordinateFrame";
|
xmlToken = "CoordinateFrame";
|
||||||
break;
|
break;
|
||||||
default: break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!props.ContainsKey(fieldName))
|
if (!props.ContainsKey(fieldName))
|
||||||
|
@ -88,8 +88,9 @@ namespace RobloxFiles
|
|||||||
{ typeof(SharedString), PropertyType.SharedString },
|
{ typeof(SharedString), PropertyType.SharedString },
|
||||||
{ typeof(Vector3int16), PropertyType.Vector3int16 },
|
{ typeof(Vector3int16), PropertyType.Vector3int16 },
|
||||||
|
|
||||||
{ typeof(ColorSequence), PropertyType.ColorSequence },
|
{ typeof(ColorSequence), PropertyType.ColorSequence },
|
||||||
{ typeof(NumberSequence), PropertyType.NumberSequence },
|
{ typeof(NumberSequence), PropertyType.NumberSequence },
|
||||||
|
{ typeof(Optional<CFrame>), PropertyType.OptionalCFrame },
|
||||||
|
|
||||||
{ typeof(ProtectedString), PropertyType.String },
|
{ typeof(ProtectedString), PropertyType.String },
|
||||||
{ typeof(PhysicalProperties), PropertyType.PhysicalProperties },
|
{ typeof(PhysicalProperties), PropertyType.PhysicalProperties },
|
||||||
|
Loading…
Reference in New Issue
Block a user