|
| 1 | +using MiloLib.Assets.Rnd; |
| 2 | +using MiloLib.Classes; |
| 3 | +using MiloLib.Utils; |
| 4 | + |
| 5 | +namespace MiloLib.Assets.Char |
| 6 | +{ |
| 7 | + // this description will always sound very metal |
| 8 | + [Name("CharCollide"), Description("Feeds the bones when executed.")] |
| 9 | + public class CharCollide : Object |
| 10 | + { |
| 11 | + public enum Shape |
| 12 | + { |
| 13 | + kPlane = 0, |
| 14 | + kSphere = 1, |
| 15 | + kInsideSphere = 2, |
| 16 | + kCigar = 3, |
| 17 | + kInsideCigar = 4, |
| 18 | + }; |
| 19 | + |
| 20 | + public struct CharCollideStruct |
| 21 | + { |
| 22 | + public int unk0; |
| 23 | + public Vector3 vec; |
| 24 | + |
| 25 | + public void Read(EndianReader reader) |
| 26 | + { |
| 27 | + unk0 = reader.ReadInt32(); |
| 28 | + vec = new Vector3().Read(reader); |
| 29 | + } |
| 30 | + |
| 31 | + public void Write(EndianWriter writer) |
| 32 | + { |
| 33 | + writer.WriteInt32(unk0); |
| 34 | + vec.Write(writer); |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + private ushort altRevision; |
| 39 | + private ushort revision; |
| 40 | + |
| 41 | + public RndTrans trans = new(); |
| 42 | + |
| 43 | + [Name("Shape"), Description("Type of collision")] |
| 44 | + public Shape shape; |
| 45 | + |
| 46 | + [Name("Radius0"), Description("Radius of the sphere, or of length0 hemisphere if cigar")] |
| 47 | + public float[] origRadius = new float[2] { 0, 0 }; |
| 48 | + [Name("Length0"), Description("cigar: placement of radius0 hemisphere along X axis, must be < than length0, not used for sphere shapes")] |
| 49 | + public float[] origLength = new float[2] { 0, 0 }; |
| 50 | + [Name("Radius1"), Description("cigar: Radius of length1 hemisphere")] |
| 51 | + public float[] curRadius = new float[2] { 0, 0 }; |
| 52 | + [Name("Length1"), Description("cigar: placement of radius1 hemisphere along X axis, must be >= length0")] |
| 53 | + public float[] curLength = new float[2] { 0, 0 }; |
| 54 | + |
| 55 | + [MinVersion(2)] |
| 56 | + public int flags; |
| 57 | + |
| 58 | + [MinVersion(6)] |
| 59 | + public Matrix unknownTransform = new(); |
| 60 | + |
| 61 | + [Name("Mesh"), Description("Optional mesh that will deform, used to resize ourselves. If this is set, make sure you are not parented to any bone with scale, such as an exo bone"), MinVersion(6)] |
| 62 | + public Symbol mesh = new(0, ""); |
| 63 | + |
| 64 | + [MinVersion(6)] |
| 65 | + public List<CharCollideStruct> structs = new(8); |
| 66 | + |
| 67 | + [MinVersion(6)] |
| 68 | + public byte[] sha1Digest = new byte[20]; |
| 69 | + |
| 70 | + [Name("Mesh Y Bias"), Description("For spheres + cigars, finds mesh points along positive y axis (the green one), makes a better fit for spheres where only one side should be the fit, like for chest and back collision volumes"), MinVersion(6)] |
| 71 | + public bool meshYBias; |
| 72 | + |
| 73 | + public CharCollide Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry) |
| 74 | + { |
| 75 | + uint combinedRevision = reader.ReadUInt32(); |
| 76 | + if (BitConverter.IsLittleEndian) (revision, altRevision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF)); |
| 77 | + else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF)); |
| 78 | + |
| 79 | + base.Read(reader, false, parent, entry); |
| 80 | + trans.Read(reader, false, parent, entry); |
| 81 | + |
| 82 | + shape = (Shape)reader.ReadUInt32(); |
| 83 | + |
| 84 | + origRadius[1] = reader.ReadFloat(); |
| 85 | + |
| 86 | + if (revision > 4) |
| 87 | + origLength[0] = reader.ReadFloat(); |
| 88 | + if (revision > 2) |
| 89 | + origLength[1] = reader.ReadFloat(); |
| 90 | + if (revision > 1) |
| 91 | + flags = reader.ReadInt32(); |
| 92 | + if (revision > 3) |
| 93 | + curRadius[0] = reader.ReadFloat(); |
| 94 | + |
| 95 | + if (revision > 5) |
| 96 | + { |
| 97 | + origRadius[1] = reader.ReadFloat(); |
| 98 | + curRadius[1] = reader.ReadFloat(); |
| 99 | + curLength[0] = reader.ReadFloat(); |
| 100 | + curLength[1] = reader.ReadFloat(); |
| 101 | + unknownTransform.Read(reader); |
| 102 | + mesh = Symbol.Read(reader); |
| 103 | + for (int i = 0; i < 8; i++) |
| 104 | + { |
| 105 | + CharCollideStruct unkStruct = new CharCollideStruct(); |
| 106 | + unkStruct.Read(reader); |
| 107 | + structs.Add(unkStruct); |
| 108 | + } |
| 109 | + |
| 110 | + sha1Digest = reader.ReadBlock(20); |
| 111 | + meshYBias = reader.ReadBoolean(); |
| 112 | + } |
| 113 | + if (standalone) |
| 114 | + if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed"); |
| 115 | + |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry) |
| 120 | + { |
| 121 | + writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision)); |
| 122 | + |
| 123 | + base.Write(writer, false, parent, entry); |
| 124 | + trans.Write(writer, false, true); |
| 125 | + |
| 126 | + writer.WriteUInt32((uint)shape); |
| 127 | + |
| 128 | + writer.WriteFloat(origRadius[1]); |
| 129 | + |
| 130 | + if (revision > 4) |
| 131 | + writer.WriteFloat(origLength[0]); |
| 132 | + if (revision > 2) |
| 133 | + writer.WriteFloat(origLength[1]); |
| 134 | + if (revision > 1) |
| 135 | + writer.WriteInt32(flags); |
| 136 | + if (revision > 3) |
| 137 | + writer.WriteFloat(curRadius[0]); |
| 138 | + |
| 139 | + if (revision > 5) |
| 140 | + { |
| 141 | + writer.WriteFloat(origRadius[1]); |
| 142 | + writer.WriteFloat(curRadius[1]); |
| 143 | + writer.WriteFloat(curLength[0]); |
| 144 | + writer.WriteFloat(curLength[1]); |
| 145 | + unknownTransform.Write(writer); |
| 146 | + Symbol.Write(writer, mesh); |
| 147 | + foreach (var unkStruct in structs) |
| 148 | + { |
| 149 | + unkStruct.Write(writer); |
| 150 | + } |
| 151 | + writer.WriteBlock(sha1Digest); |
| 152 | + writer.WriteBoolean(meshYBias); |
| 153 | + } |
| 154 | + |
| 155 | + if (standalone) |
| 156 | + writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE }); |
| 157 | + } |
| 158 | + |
| 159 | + } |
| 160 | +} |
0 commit comments