diff --git a/Source.Common/BoneSetup.cs b/Source.Common/BoneSetup.cs index a4c61745..4e757840 100644 --- a/Source.Common/BoneSetup.cs +++ b/Source.Common/BoneSetup.cs @@ -1433,6 +1433,26 @@ private void AddSequenceLayers(Span pos, Span q, MStudioSeq } } + public static int Studio_MaxFrame(StudioHdr studioHdr, int sequence, ReadOnlySpan poseParameter) { + MStudioAnimDesc[] panim = ArrayPool.Shared.Rent(4); + Span weight = stackalloc float[4]; + + MStudioSeqDesc seqdesc = studioHdr.Seqdesc(sequence); + Studio_SeqAnims(studioHdr, seqdesc, sequence, poseParameter, panim, weight); + + float maxFrame = 0; + for (int i = 0; i < 4; i++) { + if (weight[i] > 0) + maxFrame += panim[i].NumFrames * weight[i]; + } + ArrayPool.Shared.Return(panim); + + if (maxFrame > 1) + maxFrame -= 1; + + return (int)(maxFrame + 0.01); + } + public static double Studio_Duration(StudioHdr studioHdr, int sequence, ReadOnlySpan poseParameter) { MStudioSeqDesc seqdesc = studioHdr.Seqdesc(sequence); float cps = Studio_CPS(studioHdr, seqdesc, sequence, poseParameter); diff --git a/Source.Common/Studio.cs b/Source.Common/Studio.cs index 86762d58..af4eac51 100644 --- a/Source.Common/Studio.cs +++ b/Source.Common/Studio.cs @@ -3113,6 +3113,8 @@ public MStudioPoseParamDesc LocalPoseParameter(int i) public string SurfaceProp() => Studio.ProduceASCIIString(ref surfacePropCache, Data.Span[SurfacePropIndex..]); public int KeyValueIndex; public int KeyValueSize; + string? keyValueTextCache; + public string? KeyValueText() => KeyValueSize != 0 ? Studio.ProduceASCIIString(ref keyValueTextCache, Data.Span.Slice(KeyValueIndex, KeyValueSize)) : null; public int NumLocalIKAutoplayLocks; public int LocalIKAutoplayLockIndex; diff --git a/Source.Engine/ModelInfo.cs b/Source.Engine/ModelInfo.cs index 2d2400c2..f13d5bfe 100644 --- a/Source.Engine/ModelInfo.cs +++ b/Source.Engine/ModelInfo.cs @@ -292,7 +292,14 @@ public bool IsModelVertexLit(Model? model) { } public ReadOnlySpan GetModelKeyValueText(Model? model) { - throw new NotImplementedException(); + if (model == null || model.Type != ModelType.Studio) + return null; + + StudioHeader? studioHdr = mdlCache.GetStudioHdr(model.Studio); + if (studioHdr == null) + return null; + + return studioHdr.KeyValueText(); } public float GetModelRadius(Model? model) => model?.Radius ?? 0;