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

Better Packs, Shapes, and Selections #75

Merged
merged 11 commits into from
Dec 5, 2023
2 changes: 1 addition & 1 deletion Fushigi/Fushigi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="ImGui.NET" Version="1.89.9.3" />
<PackageReference Include="ImGui.NET" Version="1.90.0.1" />
<PackageReference Include="NativeFileDialogSharp" Version="0.6.0-alpha" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Silk.NET.Core" Version="2.19.0" />
Expand Down
1 change: 1 addition & 0 deletions Fushigi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Fushigi.ui;
using System.Runtime.InteropServices;


FileStream outputStream = new FileStream("output.log", FileMode.Create);
var consoleWriter = new StreamWriter(outputStream);
consoleWriter.AutoFlush = true;
Expand Down
123 changes: 118 additions & 5 deletions Fushigi/actor_pack/ActorPack.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Fushigi.actor_pack.components;
using Fushigi.Bfres;
using Fushigi.Byml.Serializer;
using Fushigi.gl.Bfres;
using Fushigi.SARC;
using Fushigi.util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -30,9 +33,14 @@ public static ActorPack Load(string gyml)

public class ActorPack
{
Dictionary<string, ActorParam> paramTree = [];
public ModelInfo DrawArrayModelInfoRef;
public ModelInfo ModelInfoRef;
public ModelExpandParam ModelExpandParamRef;
public DrainPipe DrainPipeRef;
public GamePhysics GamePhysicsRef;
public ControllerSetParam ControllerPath;
public ShapeParamList ShapeParams;

public string Category = "";

Expand Down Expand Up @@ -77,11 +85,35 @@ private void Load(string path)
{
var paramInfo = BymlSerialize.Deserialize<ActorParam>(sarc.OpenFile(file));

LoadComponents(sarc, paramInfo);
paramInfo.path = file;
if(paramInfo.Components != null)
paramTree.Add(GetPathGyml(paramInfo.parent ?? "root"), paramInfo);
}

foreach (var param in paramTree)
{
if(param.Key == "root")
{
LoadComponents(sarc, param.Value);

if (!string.IsNullOrEmpty(param.Value.Category))
this.Category = param.Value.Category;

var parFile = param.Value.path;
while(paramTree.ContainsKey(parFile))
{
var parent = paramTree[parFile];

LoadComponents(sarc, parent);

if (!string.IsNullOrEmpty(paramInfo.Category))
this.Category = paramInfo.Category;
if (!string.IsNullOrEmpty(parent.Category))
this.Category = parent.Category;

parFile = parent.path;
}
}
}

stream.Dispose();
}

Expand All @@ -102,16 +134,92 @@ private void LoadComponents(SARC.SARC sarc, ActorParam param)
switch (component.Key)
{
case "DrawArrayModelInfoRef":
this.DrawArrayModelInfoRef = BymlSerialize.Deserialize<ModelInfo>(data);
if(DrawArrayModelInfoRef == null)
this.DrawArrayModelInfoRef = BymlSerialize.Deserialize<ModelInfo>(data);
else{
var child = BymlSerialize.Deserialize<ModelInfo>(data);
foreach(var v in DrawArrayModelInfoRef.GetType().GetProperties())
{
if (v.GetValue(child) != null && v.GetValue(child) != default)
v.SetValue(DrawArrayModelInfoRef, v.GetValue(child));
}
}
break;
case "ModelInfoRef":
this.ModelInfoRef = BymlSerialize.Deserialize<ModelInfo>(data);
if(ModelInfoRef == null)
this.ModelInfoRef = BymlSerialize.Deserialize<ModelInfo>(data);
else{
var child = BymlSerialize.Deserialize<ModelInfo>(data);
foreach(var v in ModelInfoRef.GetType().GetProperties())
{

if (v.GetValue(child) != null && v.GetValue(child) != default)
v.SetValue(ModelInfoRef, v.GetValue(child));
}
}
break;
case "ModelExpandRef":
this.ModelExpandParamRef = BymlSerialize.Deserialize<ModelExpandParam>(data);
break;
case "DrainPipeRef":
this.DrainPipeRef = BymlSerialize.Deserialize<DrainPipe>(data);
break;
case "GamePhysicsRef":
this.GamePhysicsRef = BymlSerialize.Deserialize<GamePhysics>(data);
if(!string.IsNullOrEmpty(GamePhysicsRef.mPath))
ShapeParams = GetActorShape(sarc, data, filePath);
break;
}
}
}

private ShapeParamList GetActorShape(SARC.SARC sarc, byte[] data, string filePath)
{
filePath = GetPathGyml(GamePhysicsRef.mPath);
data = sarc.OpenFile(filePath);
ControllerPath = BymlSerialize.Deserialize<ControllerSetParam>(data);
if(ControllerPath.ShapeNamePathAry != null)
{
var shapes = ControllerPath.ShapeNamePathAry;
while (!string.IsNullOrEmpty(ControllerPath.parent) &&
ControllerPath.mRigids == null && ControllerPath.mEntity == null)
{
filePath = GetPathGyml(ControllerPath.parent);
data = sarc.OpenFile(filePath);
ControllerPath = BymlSerialize.Deserialize<ControllerSetParam>(data);
}
var rigidBodies = (ControllerPath.mRigids ?? new()).Concat(ControllerPath.mEntity ?? new());

foreach(var rigid in rigidBodies)
{
filePath = GetPathGyml(rigid.FilePath);
data = sarc.OpenFile(filePath);
var body = BymlSerialize.Deserialize<RigidParam>(data);

foreach(var shape in shapes)
{
if(body.ShapeName != null)
{
if(body.ShapeName == shape.Name && shape.FilePath != null)
{
filePath = GetPathGyml(shape.FilePath);
data = sarc.OpenFile(filePath);
return BymlSerialize.Deserialize<ShapeParamList>(data);
}
}
else if(body.ShapeNames != null)
{
if(body.ShapeNames.Cast<string>().Contains(shape.Name) && shape.FilePath != null)
{
filePath = GetPathGyml(shape.FilePath);
data = sarc.OpenFile(filePath);
return BymlSerialize.Deserialize<ShapeParamList>(data);
}
}
}
}
}
return null;
}

private string GetPathGyml(string path)
Expand All @@ -122,6 +230,11 @@ private string GetPathGyml(string path)

class ActorParam
{
public string path;

[BymlProperty("$parent")]
public string parent { get; set; }

public string Category { get; set; }
public Dictionary<string, object> Components { get; set; }
}
Expand Down
17 changes: 17 additions & 0 deletions Fushigi/actor_pack/components/DrainPipe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Fushigi.Byml.Serializer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Fushigi.actor_pack.components
{
[Serializable]
public class DrainPipe
{
public string ModelKeyMiddle { get; set; }
public string ModelKeyTop { get; set; }
}
}
110 changes: 110 additions & 0 deletions Fushigi/actor_pack/components/GamePhysics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using Fushigi.Byml.Serializer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Fushigi.actor_pack.components
{
[Serializable]
public class GamePhysics
{
[BymlProperty("ControllerSetPath", DefaultValue = "")]
public string mPath { get; set; }
}

[Serializable]
public class ControllerSetParam
{
[BymlProperty("$parent")]
public string parent { get; set; }

public List<ShapeName> ShapeNamePathAry { get; set; }

[BymlProperty("MatterRigidBodyNamePathAry", DefaultValue = "")]
public List<ShapeName> mRigids { get; set; }

[BymlProperty("RigidBodyEntityNamePathAry", DefaultValue = "")]
public List<ShapeName> mEntity { get; set; }
}

[Serializable]
public class ShapeName
{
public string FilePath { get; set; }
public string Name { get; set; }
}

[Serializable]
public class ShapeParamList
{
[BymlProperty("AutoCalc")]
public AutoCalc mCalc { get; set; }

[BymlProperty("Box", DefaultValue = "")]
public List<ShapeParam> mBox { get; set; }

[BymlProperty("Sphere", DefaultValue = "")]
public List<ShapeParam> mSphere { get; set; }

[BymlProperty("Capsule", DefaultValue = "")]
public List<ShapeParam> mCapsule { get; set; }

[BymlProperty("Polytope", DefaultValue = "")]
public List<ShapeParam> mPoly { get; set; }
}

[Serializable]
public class RigidParam
{
public string ShapeName { get; set; }

public List<object> ShapeNames { get; set; }
}

[Serializable]
public class AutoCalc
{
[BymlProperty("Axis")]
public Vector3 mAxis { get; set; }

[BymlProperty("Center")]
public Vector3 mCenter { get; set; }

[BymlProperty("Min")]
public Vector3 mMin { get; set; }

[BymlProperty("Max")]
public Vector3 mMax { get; set; }
}

[Serializable]
public class ShapeParam
{
[BymlProperty("AutoCalc", DefaultValue = "")]
public AutoCalc mCalc { get; set; }

public float Radius { get; set; }

[BymlProperty("Center")]
public Vector3 mCenter { get; set; }

[BymlProperty("HalfExtents")]
public Vector3 mExtents { get; set; }

}

[Serializable]
public class Capsule
{
public float Radius { get; set; }

[BymlProperty("CenterA")]
public Vector3 mCenterA { get; set; }

[BymlProperty("CenterB")]
public Vector3 mCenterB { get; set; }
}
}
10 changes: 10 additions & 0 deletions Fushigi/actor_pack/components/ModelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -10,12 +11,17 @@ namespace Fushigi.actor_pack.components
[Serializable]
public class ModelInfo
{
[BymlProperty("$parent")]
public string parent { get; set; }

[BymlProperty("FmdbName", DefaultValue = "")]
public string mModelName { get; set; }

[BymlProperty("ModelProjectName", DefaultValue = "")]
public string mFilePath { get; set; }

[BymlProperty("DebugModelScale")]
public Vector3 mModelScale { get; set; }
public string SearchModelKey { get; set; }

public List<SubModel> SubModels { get; set; }
Expand All @@ -24,6 +30,10 @@ public class ModelInfo
public class SubModel
{
public string FmdbName { get; set; }

public string ModelProjectName { get; set; }

public string SearchModelKey { get; set; }
}

[Serializable]
Expand Down
1 change: 1 addition & 0 deletions Fushigi/course/CourseActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
public string mPackName;
public string mName;
public string mLayer;
public System.Numerics.Vector3 mStartingTrans;
public System.Numerics.Vector3 mTranslation;
public System.Numerics.Vector3 mRotation;
public System.Numerics.Vector3 mScale;
Expand Down
Loading
Loading