Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgamerz committed Oct 6, 2024
2 parents e3d501e + e7c26cc commit 6c449c7
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ Release_x64/
# Ignore Doxygen working folder and Doxygen output
/Documentation/Output
/Documentation/Doxygen
/LegendaryExplorer/TexConverter/TexConverter/WinRelease/TexConverter.vcxproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
using LegendaryExplorerCore.Localization;
using LegendaryExplorerCore.UnrealScript.Language.Tree;
using GongSolutions.Wpf.DragDrop;
using LegendaryExplorerCore.Unreal.Collections;

namespace LegendaryExplorer.Tools.PackageEditor
{
Expand Down Expand Up @@ -1635,9 +1636,13 @@ static IEntry GetExternallyReferencedEntry(List<IEntry> entriesToTrash)
{
return pcc.GetEntry(exp.idxSuperClass);
}
if (exp.HasComponentMap && exp.ComponentMap.Any(kvp => uIndexes.Contains(kvp.Value)))
if (exp.HasComponentMap)
{
return pcc.GetEntry(exp.ComponentMap.Values.First(uIdx => uIndexes.Contains(uIdx)));
var componentMap = exp.ComponentMap;
if (componentMap.Any(kvp => uIndexes.Contains(kvp.Value + 1)))
{
return pcc.GetEntry(componentMap.Values.First(idx => uIndexes.Contains(idx + 1)));
}
}

//find stack references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,23 @@ public void SetShape(bool polygon, bool cylinder = false)
outlinePen = new Pen(GetDefaultShapeColor()); //Can't put this in a class variable becuase it doesn't seem to work for some reason.
if (polygon)
{
PointF[] polygonShape = get3DBrushShape();
var polygonShape = get3DBrushShape();
int calculatedHeight = get3DBrushHeight();
if (polygonShape != null)
{
shape = PPath.CreatePolygon(polygonShape);
var AveragePoint = GetAveragePoint(polygonShape);
val.X = AveragePoint.X - val.Width / 2;
val.Y = AveragePoint.Y - val.Height / 2;
shape = new PPath();
foreach (PointF[] polyPoints in polygonShape)
{
shape.AddPolygon(polyPoints);
}
var averagePoint = GetAveragePoint(shape.PathReference.PathPoints);
val.X = averagePoint.X - val.Width / 2;
val.Y = averagePoint.Y - val.Height / 2;
if (calculatedHeight >= 0)
{
SText brushText = new SText($"Brush total height: {calculatedHeight}");
brushText.X = AveragePoint.X - brushText.Width / 2;
brushText.Y = AveragePoint.Y + 20 - brushText.Height / 2;
brushText.X = averagePoint.X - brushText.Width / 2;
brushText.Y = averagePoint.Y + 20 - brushText.Height / 2;
brushText.Pickable = false;
brushText.TextAlignment = StringAlignment.Center;
shape.AddChild(brushText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected int get3DBrushHeight()
return -1;
}

protected PointF[] get3DBrushShape()
protected IEnumerable<PointF[]> get3DBrushShape()
{
try
{
Expand Down Expand Up @@ -220,59 +220,84 @@ protected PointF[] get3DBrushShape()
return null;
}
ExportEntry brush = export.FileRef.GetUExport(brushComponent.Value);
var graphVertices = new List<PointF>();
PropertyCollection brushProps = brush.GetProperties();
var brushAggGeom = brushProps.GetProp<StructProperty>("BrushAggGeom");
if (brushAggGeom == null)
{
return null;
}
var convexList = brushAggGeom.GetProp<ArrayProperty<StructProperty>>("ConvexElems");

if (convexList.Count is 0)
{
return null;
}
var polys = new List<PointF[]>(convexList.Count);
foreach (StructProperty convexElem in convexList)
{
var brushVertices = new List<Vector3>();
//Vertices
var verticiesList = convexElem.GetProp<ArrayProperty<StructProperty>>("VertexData");
foreach (StructProperty vertex in verticiesList)
var verts = new PointF[verticiesList.Count];
//Vertices
for (int i = 0; i < verticiesList.Count; i++)
{
brushVertices.Add(new Vector3
StructProperty vertex = verticiesList[i];
verts[i] = new PointF
{
X = vertex.GetProp<FloatProperty>("X") * xScalar,
Y = vertex.GetProp<FloatProperty>("Y") * yScalar,
Z = vertex.GetProp<FloatProperty>("Z")
});
};
}

//FaceTris
var faceTriData = convexElem.GetProp<ArrayProperty<IntProperty>>("FaceTriData");
float prevX = float.MinValue;
float prevY = float.MinValue;
foreach (IntProperty triPoint in faceTriData)
//2D convex hull algorithm from https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
int n = verts.Length;
if (n <= 3)
{
Vector3 vertex = brushVertices[triPoint];
if (vertex.X == prevX && vertex.Y == prevY)
{
continue; //Z is on the difference
}
polys.Add(verts);
continue;
}
// Sort points lexicographically
Array.Sort(verts, new PointFLexicalComparer());
int k = 0;
var hullVerts = new PointF[n * 2];

float x = vertex.X;
float y = vertex.Y;
// Build lower hull
for (int i = 0; i < n; ++i)
{
while (k >= 2 && Cross(hullVerts[k - 2], hullVerts[k - 1], verts[i]) <= 0) --k;
hullVerts[k++] = verts[i];
}

prevX = x;
prevY = y;
var graphPoint = new PointF(x, y);
graphVertices.Add(graphPoint);
// Build upper hull
for (int i = n - 1, t = k + 1; i > 0; --i)
{
while (k >= t && Cross(hullVerts[k - 2], hullVerts[k - 1], verts[i - 1]) <= 0) --k;
hullVerts[k++] = verts[i - 1];
}

var hullPoints = new PointF[k];
Array.Copy(hullVerts, hullPoints, k);
polys.Add(hullPoints);
}
return polys;

float Cross(PointF p1, PointF p2, PointF p3)
{
return (p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X);
}
return graphVertices.ToArray();
}
catch (Exception)
{
return null;
}
}

private struct PointFLexicalComparer : IComparer<PointF>
{
public int Compare(PointF x, PointF y)
{
int xComparison = x.X.CompareTo(y.X);
return xComparison != 0 ? xComparison : x.Y.CompareTo(y.Y);
}
}

protected Tuple<float, float, float> getCylinderDimensions()
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ public override void LoadExport(ExportEntry exportEntry)
var componentMap = exportEntry.ComponentMap;
string components = $"ComponentMap: 0x{40:X2} {componentMap.Count} items\n";
int pairOffset = 44;
foreach ((NameReference name, int uIndex) in componentMap)
foreach ((NameReference name, int index) in componentMap)
{
components += $"0x{pairOffset:X2} {name.Instanced} => {uIndex} {exportEntry.FileRef.GetEntryString(uIndex + 1)}\n"; // +1 because it appears to be 0 based?
components += $"0x{pairOffset:X2} {name.Instanced} => {index} {exportEntry.FileRef.GetEntryString(index + 1)}\n"; // +1 because it appears to be 0 based?
pairOffset += 12;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ private void linesListBox_Drop(object sender, DragEventArgs e)
lineEntry.Line.NameIndex = FaceFX.Names.FindOrAdd(sourceNames[lineEntry.Line.NameIndex]);
if (FaceFX.Binary is FaceFXAnimSet animSet) animSet.FixNodeTable();
lineEntry.Line.AnimationNames = lineEntry.Line.AnimationNames.Select(idx => FaceFX.Names.FindOrAdd(sourceNames[idx])).ToList();
lineEntry.Line.Index = FaceFX.Lines.Count;
FaceFX.Lines.Add(lineEntry.Line);

if (int.TryParse(lineEntry.Line.ID, out int tlkID))
Expand Down Expand Up @@ -750,7 +751,8 @@ private void AddLine_Click(object sender, RoutedEventArgs e)
private void CloneLine_Click(object sender, RoutedEventArgs e)
{
// HenBagle: We don't need to do anything with names here because we're cloning within the same file
FaceFXLineEntry newEntry = new FaceFXLineEntry(SelectedLine.Clone());
var newEntry = new FaceFXLineEntry(SelectedLine.Clone());
newEntry.Line.Index = FaceFX.Lines.Count;
FaceFX.Lines.Add(newEntry.Line);

if (int.TryParse(newEntry.Line.ID, out int tlkID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ public static class CoalescedConverter
"BioCompat",
"BioCredits",
"BioDifficulty",
"BioEditor", // LE1
"BioEditorKeyBindings", // LE1
"BIoEditorUserSettings", // LE1
"BioEngine",
"BioGame",
"BioGuiResources", // PC Main Menu PC New Character
"BioInput",
"BioLightmass",
"BioParty", // LE1
"BioStringTypeMap", // LE1
"BioTest",
"BioUI",
"BioQA",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ public static void CheckReferences(ReferenceCheckPackage item, IMEPackage packag

if (exp.HasComponentMap)
{
foreach (var c in exp.ComponentMap)
foreach ((_, int index) in exp.ComponentMap)
{
if (c.Value != 0 && !package.IsEntry(c.Value))
int uindex = index + 1;
if (uindex != 0 && !package.IsEntry(uindex))
{
// Can components point to 0? I don't think so
item.AddSignificantIssue(localizationDelegate(LECLocalizationShim.string_interp_warningComponentMapItemOutsideTables, prefix, c.Value), exp);
item.AddSignificantIssue(localizationDelegate(LECLocalizationShim.string_interp_warningComponentMapItemOutsideTables, prefix, uindex), exp);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ public static void Relink(ExportEntry sourceExport, ExportEntry relinkingExport,
if (relinkingExport.HasComponentMap && relinkingExport.ComponentMap.Count > 0)
{
var newComponentMap = new UMultiMap<NameReference, int>();
foreach (var cmk in sourceExport.ComponentMap)
foreach ((NameReference componentName, int componentIndex) in sourceExport.ComponentMap)
{
// 04/07/2024 - Remove temp cross package mapping and have this call skip its internal relink step since this call is already in a relink - Mgamerz
EntryImporter.ImportAndRelinkEntries(EntryImporter.PortingOption.CloneAllDependencies, sourceExport.FileRef.GetUExport(cmk.Value + 1), relinkingExport.FileRef, relinkingExport, false, rop, out var newComponent);
newComponentMap.Add(cmk.Key, newComponent.UIndex - 1); // TODO: Relink the
EntryImporter.ImportAndRelinkEntries(EntryImporter.PortingOption.CloneAllDependencies, sourceExport.FileRef.GetUExport(componentIndex + 1), relinkingExport.FileRef, relinkingExport, false, rop, out var newComponent);
newComponentMap.Add(componentName, newComponent.UIndex - 1); // TODO: Relink the
}
relinkingExport.ComponentMap = newComponentMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ public int DataOffset

//me1 and me2 only
private byte[] _componentMap;

//Does not contain UIndexes! The ints in this are indexes into the exports array. +1 to get the UIndex
public UMultiMap<NameReference, int> ComponentMap
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ public static HashSet<int> GetReferencedEntries(this IMEPackage pcc, bool getref
}
if (exp.HasComponentMap)
{
foreach (var kvp in exp.ComponentMap)
foreach ((_, int index) in exp.ComponentMap)
{
//theserefs.Add(pcc.GetEntry(kvp.Value)); //THIS IS INCORRECT SHOULD NOT BE ON UINDEX
theserefs.Add(pcc.GetEntry(index + 1));
}
}
}
Expand Down Expand Up @@ -742,7 +742,7 @@ public static Dictionary<IEntry, List<string>> GetEntriesThatReferenceThisOne(th
{
result.AddToListAt(exp, "Header: SuperClass");
}
if (exp.HasComponentMap && exp.ComponentMap.Any(kvp => kvp.Value == baseUIndex))
if (exp.HasComponentMap && exp.ComponentMap.Any(kvp => kvp.Value + 1 == baseUIndex))
{
result.AddToListAt(exp, "Header: ComponentMap");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static void UpdateReferencedWwiseEventLengths(ExportEntry wwiseStreamExpo
tlkId = parsed;
specifyByGender = wwiseStreamExport.ObjectName.Name.Contains("player_", StringComparison.OrdinalIgnoreCase);
isFemaleStream = splits[i + 1] == "f";
break; // assume first int we find is the tlk id
}
}
if (tlkId == 0) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@ static float getW(float x, float y, float z)

private void CompressAnimationData(MEGame game, AnimationCompressionFormat newRotationCompression)
{
if (RawAnimationData is null)
{
DecompressAnimationData();
}
/* SirCxyrtyx 8/12/24: Always decompress, do not use pre-existing RawAnimationData if from a upk.
* In same cases, the RawAnimationData is wrong for unknown reasons ¯\_(ツ)_/¯
* The compressed data should be regarded as the source of truth
*/
DecompressAnimationData();

keyEncoding = AnimationKeyFormat.AKF_ConstantKeyLerp;
posCompression = AnimationCompressionFormat.ACF_None;
Expand Down
9 changes: 5 additions & 4 deletions LegendaryExplorer/LegendaryExplorerCore/Unreal/PSA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ public static PSA CreateFrom(List<AnimSequence> animSeqs)
});
frameCount += numFrames;

if (animSeq.RawAnimationData is null)
{
animSeq.DecompressAnimationData();
}
/* SirCxyrtyx 8/12/24: Always decompress, do not use pre-existing RawAnimationData if from a upk.
* In same cases, the RawAnimationData is wrong for unknown reasons ¯\_(ツ)_/¯
* The compressed data should be regarded as the source of truth
*/
animSeq.DecompressAnimationData();

for (int frameIdx = 0; frameIdx < numFrames; frameIdx++)
{
Expand Down

0 comments on commit 6c449c7

Please sign in to comment.