Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export/import missing nav poly flags #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion CodeWalker.Core/GameFiles/FileTypes/YnvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ public Vector4[] GetNodePositions()
public byte Flags2 { get { return _RawData.Flags2; } set { _RawData.Flags2 = value; } }
public byte Flags3 { get { return _RawData.Flags3; } set { _RawData.Flags3 = value; } }
public byte Flags4 { get { return _RawData.Flags4; } set { _RawData.Flags4 = value; } }
public byte Flags5 { get { return _RawData.Flags5; } set { _RawData.Flags5 = value; } }
public bool B00_AvoidUnk { get { return (_RawData.PolyFlags0 & 1) > 0; } set { _RawData.PolyFlags0 = (ushort)BitUtil.UpdateBit(_RawData.PolyFlags0, 0, value); } }
public bool B01_AvoidUnk { get { return (_RawData.PolyFlags0 & 2) > 0; } set { _RawData.PolyFlags0 = (ushort)BitUtil.UpdateBit(_RawData.PolyFlags0, 1, value); } }
public bool B02_IsFootpath { get { return (_RawData.PolyFlags0 & 4) > 0; } set { _RawData.PolyFlags0 = (ushort)BitUtil.UpdateBit(_RawData.PolyFlags0, 2, value); } }
Expand Down Expand Up @@ -997,7 +998,7 @@ public void CalculateAABB()

public void WriteXml(StringBuilder sb, int indent)
{
byte[] flags = { Flags1, Flags2, Flags3, Flags4, UnkX, UnkY };
byte[] flags = { Flags1, Flags2, Flags3, Flags4, UnkX, UnkY, Flags5 };
YnvXml.WriteRawArray(sb, flags, indent, "Flags", "");
YnvXml.WriteRawArray(sb, Vertices, indent, "Vertices", "", YnvXml.FormatVector3, 1);
var cind = indent + 1;
Expand All @@ -1009,6 +1010,14 @@ public void WriteXml(StringBuilder sb, int indent)
sb.AppendLine();
}
YnvXml.CloseTag(sb, indent, "Edges");
YnvXml.OpenTag(sb, indent, "EdgesFlags");
foreach (var e in Edges)
{
YnvXml.Indent(sb, cind);
sb.AppendFormat("{0}:{1}, {2}:{3}", e.Poly1Unk2, e.Poly1Unk3, e.Poly2Unk2, e.Poly2Unk3);
sb.AppendLine();
}
YnvXml.CloseTag(sb, indent, "EdgesFlags");
if ((PortalLinks != null) && (PortalLinks.Length > 0))
{
YnvXml.WriteRawArray(sb, PortalLinks, indent, "Portals", "");
Expand All @@ -1025,6 +1034,7 @@ public void ReadXml(XmlNode node)
Flags4 = (flags.Length > 3) ? flags[3] : (byte)0;
UnkX = (flags.Length > 4) ? flags[4] : (byte)0;
UnkY = (flags.Length > 5) ? flags[5] : (byte)0;
Flags5 = (flags.Length > 6) ? flags[6] : (byte)0;
}
Vertices = Xml.GetChildRawVector3Array(node, "Vertices");
Indices = new ushort[Vertices?.Length ?? 0];//needs to be present for later
Expand Down Expand Up @@ -1060,6 +1070,34 @@ public void ReadXml(XmlNode node)
{
Edges = edges.ToArray();
}
var edgesflagsstr = Xml.GetChildInnerText(node, "EdgesFlags");
var edgesflagsstrarr = edgesflagsstr.Trim().Split('\n');
int edgeflagidx = -1;
foreach (var edgeflagsstr in edgesflagsstrarr)
{
edgeflagidx++;
var estrparts = edgeflagsstr.Trim().Split(',');
if (estrparts.Length != 2)
{ continue; }
var estrp0 = estrparts[0].Trim().Split(':');
var estrp1 = estrparts[1].Trim().Split(':');
if (estrp0.Length != 2)
{ continue; }
if (estrp1.Length != 2)
{ continue; }

uint p1u2, p1u3, p2u2, p2u3;
uint.TryParse(estrp0[0].Trim(), out p1u2);
uint.TryParse(estrp0[1].Trim(), out p1u3);
uint.TryParse(estrp1[0].Trim(), out p2u2);
uint.TryParse(estrp1[1].Trim(), out p2u3);

var e = Edges[edgeflagidx];
e.Poly1Unk2 = p1u2;
e.Poly1Unk3 = p1u3;
e.Poly2Unk2 = p2u2;
e.Poly2Unk3 = p2u3;
}

PortalLinks = Xml.GetChildRawUshortArrayNullable(node, "Portals");
}
Expand Down Expand Up @@ -1242,6 +1280,10 @@ public override string ToString()
public uint AreaID2 { get; set; }
public uint PolyID1 { get { return _RawData._Poly1.PolyID; } set { _RawData._Poly1.PolyID = value; } }
public uint PolyID2 { get { return _RawData._Poly2.PolyID; } set { _RawData._Poly2.PolyID = value; } }
public uint Poly1Unk2 { get { return _RawData._Poly1.Unk2; } set { _RawData._Poly1.Unk2 = value; } }
public uint Poly2Unk2 { get { return _RawData._Poly2.Unk2; } set { _RawData._Poly2.Unk2 = value; } }
public uint Poly1Unk3 { get { return _RawData._Poly1.Unk3; } set { _RawData._Poly1.Unk3 = value; } }
public uint Poly2Unk3 { get { return _RawData._Poly2.Unk3; } set { _RawData._Poly2.Unk3 = value; } }
public YnvPoly Poly1 { get; set; }
public YnvPoly Poly2 { get; set; }

Expand Down
1 change: 1 addition & 0 deletions CodeWalker.Core/GameFiles/Resources/Nav.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ public override string ToString()
public byte Flags2 { get { return (byte)((PolyFlags1 >> 0) & 0xFF); } set { PolyFlags1 = ((PolyFlags1 & 0xFFFFFF00u) | ((value & 0xFFu) << 0)); } }
public byte Flags3 { get { return (byte)((PolyFlags1 >> 9) & 0xFF); } set { PolyFlags1 = ((PolyFlags1 & 0xFFFE01FFu) | ((value & 0xFFu) << 9)); } }
public byte Flags4 { get { return (byte)((PolyFlags2 >> 16) & 0xFF); } set { PolyFlags2 = ((PolyFlags2 & 0xFF00FFFFu) | ((value & 0xFFu) << 16)); } }
public byte Flags5 { get { return (byte)((PolyFlags1 >> 8) & 0x1); } set { PolyFlags1 = ((PolyFlags1 & 0xFFFFFEFFu) | ((value & 0x1u) << 8)); } }

//public uint UnkFlags0 { get { return (uint)((PolyFlags0 >> 8) & 0xFF); } } //always 0
//public uint UnkFlags1 { get { return (uint)((PolyFlags1 >> 17) & 0xFFFF); } } //always 0
Expand Down