private static void IfWriter(MappingWriteArgs args) { var item = args.Item as If; args.Writer.Write(item.Value); Write(args.Writer.BaseStream, item.Commands); }
private static void WriteLoadAssets(MappingWriteArgs args) { var item = args.Item as ReadAssets; args.Writer.Write((short)item.Set.Count); args.Writer.Write(item.FrameStart); args.Writer.Write(item.FrameEnd); args.Writer.Write(item.Unk06); var stream = args.Writer.BaseStream; foreach (var loadItem in item.Set) { var startPosition = stream.Position; stream.Position += 4; Mapping.WriteObject(stream, loadItem); var nextPosition = stream.AlignPosition(2).Position; var id = _typeId[loadItem.GetType()]; var length = stream.Position - startPosition; stream.Position = startPosition; stream.Write((short)id); stream.Write((short)length); stream.Position = nextPosition; } }
private static void WriteString(MappingWriteArgs arg) { var index = 0; var str = arg.Item as string; var remaining = arg.Count; while (index < str.Length && remaining-- > 0) { var data = 0; var ch = str[index++]; if (ch >= 'A' && ch <= 'Z') { data = ch - 'A' + 0xa1; } else if (ch >= 'a' && ch <= 'z') { data = ch - 'a' + 0xc1; } else { throw new NotImplementedException($"Write P5 string: can't write '{ch}'"); } arg.Writer.Write((byte)0x80); arg.Writer.Write((byte)data); } while (remaining-- > 0) { arg.Writer.Write((short)0); } }
private static void SetInventoryWriter(MappingWriteArgs args) { var items = args.Item as SetInventory; args.Writer.Write((short)items.Items.Count); foreach (var item in items.Items) { args.Writer.Write(item); } }
private unsafe static void WriteFloat(MappingWriteArgs arg) { var value = (float)arg.Item; var data = *(int *)&value; arg.Writer.Write((byte)((data >> 24) & 0xff)); arg.Writer.Write((byte)((data >> 16) & 0xff)); arg.Writer.Write((byte)((data >> 8) & 0xff)); arg.Writer.Write((byte)(data & 0xff)); }
private static void ScriptMultipleStringWriter(MappingWriteArgs args) { var items = (List <string>)args.Item; foreach (var item in items) { args.Item = item; args.Count = 4; ScriptStringWriter(args); } }
private static void AreaSettingsWriter(MappingWriteArgs args) { var settings = args.Item as AreaSettings; args.Writer.Write(settings.Unk00); args.Writer.Write(settings.Unk02); foreach (var setting in settings.Settings) { var opcode = (short)_typeSetId[setting.GetType()]; args.Writer.Write(opcode); Mapping.WriteObject(args.Writer.BaseStream, setting); } }
private static void WriteUnk1E(MappingWriteArgs args) { var item = args.Item as Unk1E; args.Writer.Write(item.Id); args.Writer.Write((short)item.Entries.Count); args.Writer.Write((short)3); args.Writer.Write((short)0); foreach (var entry in item.Entries) { Mapping.WriteObject(args.Writer.BaseStream, entry); } args.Writer.Write(item.UnkG); args.Writer.Write(item.UnkH); }
private static void WriteVoices(MappingWriteArgs args) { var item = (SeqVoices)args.Item; args.Writer.Write(item.Voices.Count); foreach (var voice in item.Voices) { var startPos = args.Writer.BaseStream.Position; args.Writer.Write(0); args.Writer.Write(voice.FrameStart); args.Writer.Write((byte)0); WriteCStyleString(args.Writer.BaseStream, voice.Name); args.Writer.BaseStream.Position = startPos + 0x20; } var endPosition = args.Writer.BaseStream.Position; if (endPosition > args.Writer.BaseStream.Length) { args.Writer.BaseStream.SetLength(endPosition); } }
private static void ScriptStringWriter(MappingWriteArgs args) { byte[] data; var value = (string)args.Item; if (args.Count == 4) { data = new byte[4]; if (value.Length > 2) { data[0] = (byte)value[0]; data[1] = (byte)value[1]; data[2] = (byte)value[2]; if (value.Length >= 4) { data[3] = (byte)value[3]; } } else if (value.Length > 0) { data[0] = (byte)value[0]; if (value.Length == 2) { data[1] = (byte)value[1]; } } } else { var strData = Encoding.ASCII.GetBytes(value); var length = args.Count == 1 ? Helpers.Align(strData.Length + 1, 4) : args.Count; data = new byte[length]; Array.Copy(strData, data, strData.Length); args.Writer.BaseStream.AlignPosition(4); } args.Writer.BaseStream.Write(data); }
private static void WriteSetCameraData(MappingWriteArgs args) { void WriteHeader(Stream stream, List <SetCameraData.CameraKeys> values, int startIndex) => Mapping.WriteObject(stream, new SetCameraDataHeader { Index = (short)startIndex, Count = (short)values.Count }); void WriteData(Stream stream, List <SetCameraData.CameraKeys> values) { foreach (var value in values.Select(x => new CameraValueInternal { FlagData = (uint)((((x.KeyFrame + 0x10000000) ^ 0x10000000) & 0x1FFFFFFF) | ((int)x.Interpolation << 29)), Value = x.Value, TangentEaseIn = x.TangentEaseIn, TangentEaseOut = x.TangentEaseOut })) { Mapping.WriteObject(stream, value); } } var item = args.Item as SetCameraData; args.Writer.Write(item.CameraId); var channelCountList = new List <int>(8) { item.PositionX.Count, item.PositionY.Count, item.PositionZ.Count, item.LookAtX.Count, item.LookAtY.Count, item.LookAtZ.Count, item.Roll.Count, item.FieldOfView.Count, }; var indexList = new List <int>(8); var startIndex = 0; foreach (var channelCount in channelCountList) { indexList.Add(startIndex); startIndex += channelCount; } WriteHeader(args.Writer.BaseStream, item.PositionX, indexList[0]); WriteHeader(args.Writer.BaseStream, item.PositionY, indexList[1]); WriteHeader(args.Writer.BaseStream, item.PositionZ, indexList[2]); WriteHeader(args.Writer.BaseStream, item.LookAtX, indexList[3]); WriteHeader(args.Writer.BaseStream, item.LookAtY, indexList[4]); WriteHeader(args.Writer.BaseStream, item.LookAtZ, indexList[5]); WriteHeader(args.Writer.BaseStream, item.Roll, indexList[6]); WriteHeader(args.Writer.BaseStream, item.FieldOfView, indexList[7]); args.Writer.BaseStream.AlignPosition(4); WriteData(args.Writer.BaseStream, item.PositionX); WriteData(args.Writer.BaseStream, item.PositionY); WriteData(args.Writer.BaseStream, item.PositionZ); WriteData(args.Writer.BaseStream, item.LookAtX); WriteData(args.Writer.BaseStream, item.LookAtY); WriteData(args.Writer.BaseStream, item.LookAtZ); WriteData(args.Writer.BaseStream, item.Roll); WriteData(args.Writer.BaseStream, item.FieldOfView); }
private static void CStringWriter(MappingWriteArgs args) => WriteCStyleString(args.Writer.BaseStream, (string)args.Item);