Browse Source

Marshal animation frame names as bytes and manually decode them using QuakeTextMarshaler. Fixes invalid byte sequence exception upon loading QRally.

readme
Nico de Poel 4 years ago
parent
commit
1e948a2dd3
  1. 4
      Assets/Scripts/Data/QModel.cs
  2. 10
      Assets/Scripts/QuakeTextMarshaler.cs
  3. 2
      Assets/Scripts/Support/AliasModel.cs

4
Assets/Scripts/Data/QModel.cs

@ -177,7 +177,9 @@ public struct QAliasFrameDesc
public QTriVertex bboxMin;
public QTriVertex bboxMax;
public int frame;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] nameBytes;
public string Name => QuakeTextMarshaler.GetString(nameBytes);
}
/// <summary>

10
Assets/Scripts/QuakeTextMarshaler.cs

@ -62,6 +62,16 @@
return sb.ToString();
}
public static string GetString(byte[] bytes)
{
var sb = new StringBuilder(bytes.Length);
for (int i = 0; i < bytes.Length; ++i)
{
sb.Append(CharacterTable[bytes[i]]);
}
return sb.ToString();
}
public void CleanUpManagedData(object managedObj)
{
}

2
Assets/Scripts/Support/AliasModel.cs

@ -147,7 +147,7 @@ public class AliasModel
for (int frameIdx = 0; frameIdx < header.numFrames; ++frameIdx)
{
// Individual sequences are identified by their prefix
string frameName = AnimationRegex.Match(header.frames[frameIdx].name ?? "").Value;
string frameName = AnimationRegex.Match(header.frames[frameIdx].Name ?? "").Value;
if (animName == null)
{
animName = frameName;

Loading…
Cancel
Save