public Motion(Motion motion) { // copy constructor IsAutonomous = motion.IsAutonomous; MovementType = motion.MovementType; MotionFlags = motion.MotionFlags; Stance = motion.Stance; if (motion.MotionState != null) { MotionState = new InterpretedMotionState(motion.MotionState); } TargetGuid = motion.TargetGuid; if (motion.Position != null) { Position = new Position(motion.Position); } if (motion.MoveToParameters != null) { MoveToParameters = new MoveToParameters(motion.MoveToParameters); } RunRate = motion.RunRate; DesiredHeading = motion.DesiredHeading; }
public override byte[] GetPayload(WorldObject animationTarget) { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write((byte)MovementTypes.General); // movement_type MotionFlags flags = MotionFlags.None; if (HasTarget) { flags |= MotionFlags.HasTarget; } if (Jumping) { flags |= MotionFlags.Jumping; } writer.Write((byte)flags); // these can be or and has sticky object | is long jump mode | writer.Write((ushort)Stance); // called command in the client MovementStateFlag generalFlags = MovementData.MovementStateFlag; generalFlags += (uint)Commands.Count << 7; writer.Write((uint)generalFlags); MovementData.Serialize(writer); foreach (var item in Commands) { writer.Write((ushort)item.Motion); writer.Write(animationTarget.Sequences.GetNextSequence(Sequence.SequenceType.Motion)); writer.Write(item.Speed); } return(stream.ToArray()); }
public CommandController(int index, string bone, MotionFlags type, float start, float end) { _Index = index; _Bone = bone; _Type = type; _Start = start; _End = end; }
public BoneController(byte[] raw) { _Bone = BitConverter.ToInt32(raw, 0); _Type = (MotionFlags)BitConverter.ToInt32(raw, 4); _Start = BitConverter.ToSingle(raw, 8); _End = BitConverter.ToSingle(raw, 12); _Rest = BitConverter.ToInt32(raw, 16); _Index = BitConverter.ToInt32(raw, 20); }
public BoneController(int bone, MotionFlags type, float start, float end, int rest, int index) { _Bone = bone; _Type = type; _Start = start; _End = end; _Rest = rest; _Index = index; }
private void WriteBase(Entity.WorldObject animationTarget, Session session, MotionActivity activity, MotionType type, MotionFlags flags, MotionStance stance) { Writer.WriteGuid(animationTarget.Guid); Writer.Write((ushort)session.Player.TotalLogins); Writer.Write(animationTarget.Sequences.GetNextSequence(Sequence.SequenceType.MotionMessage)); Writer.Write((ushort)1); // Index, needs more research, it changes sometimes, but not every packet Writer.Write((ushort)activity); Writer.Write((byte)type); Writer.Write((byte)flags); Writer.Write((ushort)stance); }
public GameMessageMotion(Entity.WorldObject animationTarget, Session session, MotionActivity activity, MotionType type, MotionFlags flags, MotionStance stance, MotionCommand command, float speed) : this() { WriteBase(animationTarget, session, activity, type, flags, stance); List <MotionItem> animations = new List <MotionItem>() { new MotionItem(command, speed) }; WriteAnimations(animationTarget, animations); }
public GameMessageMotion(WorldObject animationTarget, Session session, MotionAutonomous activity, MovementTypes type, MotionFlags flags, MotionStance stance, MovementData movement, List <MotionItem> animations = null) : this() { WriteBase(animationTarget, session, activity, type, flags, stance); movement?.Serialize(this.Writer); if (animations == null) { this.Writer.Write((ushort)0); } else { this.WriteAnimations(animationTarget, animations); } }
public MovementData(WorldObject wo, Motion motion) { WorldObject = wo; //var sequence = wo.Sequences; // do this here, or in network writer? IsAutonomous = motion.IsAutonomous; //MovementSequence = BitConverter.ToUInt16(sequence.GetNextSequence(SequenceType.ObjectMovement)); //if (IsAutonomous) //ServerControlSequence = BitConverter.ToUInt16(sequence.GetCurrentSequence(SequenceType.ObjectServerControl)); //else //ServerControlSequence = BitConverter.ToUInt16(sequence.GetNextSequence(SequenceType.ObjectServerControl)); MovementType = motion.MovementType; MotionFlags = motion.MotionFlags; //if (motion.HasTarget) //MotionFlags |= MotionFlags.StickToObject; //if (motion.StandingLongJump) //MotionFlags |= MotionFlags.StandingLongJump; // indicates if player started charging jump bar while standing still CurrentStyle = motion.Stance; switch (MovementType) { case MovementType.Invalid: Invalid = new MovementInvalid(this, motion); break; case MovementType.MoveToObject: MoveToObject = new MoveToObject(motion); break; case MovementType.MoveToPosition: MoveToPosition = new MoveToPosition(motion); break; case MovementType.TurnToObject: TurnToObject = new TurnToObject(motion); break; case MovementType.TurnToHeading: TurnToHeading = new TurnToHeading(motion); break; } }
private void WriteBase(WorldObject animationTarget, Session session, MotionAutonomous autonomous, MovementTypes type, MotionFlags flags, MotionStance stance) { Writer.WriteGuid(animationTarget.Guid); // Object_Id (uint) Writer.Write(animationTarget.Sequences.GetCurrentSequence(SequenceType.ObjectInstance)); // Instance_Timestamp Writer.Write(animationTarget.Sequences.GetNextSequence(SequenceType.ObjectPosition)); // Movement_Timestamp if (autonomous == MotionAutonomous.False) { Writer.Write(animationTarget.Sequences.GetNextSequence(SequenceType.ObjectServerControl)); // Server_Control_Timestamp } else { Writer.Write(animationTarget.Sequences.GetCurrentSequence(SequenceType.ObjectServerControl)); // Server_Control_Timestamp } Writer.Write((ushort)type); // movement_type Writer.Write((byte)autonomous); // autonomous flag - 1 or 0. I think this is set if you have are holding the run key or some other autonomous movement Writer.Write((byte)flags); // these can be or and has sticky object | is long jump mode | Writer.Write((ushort)stance); // called command in the client }
public Sequence(byte[] raw) { _Name = Encoding.ASCII.GetString(raw, 0, 32).Trim('\0'); _FramesPerSecond = BitConverter.ToSingle(raw, 32); _Flags = (SequenceFlags)BitConverter.ToInt32(raw, 36); _Activity = BitConverter.ToInt32(raw, 40); _ActivityWeight = BitConverter.ToInt32(raw, 44); _Events = new CountOffsetPair(BitConverter.ToInt32(raw, 48), BitConverter.ToInt32(raw, 52)); _EventCollection = new Event[_Events.Count]; _FrameCount = BitConverter.ToInt32(raw, 56); _Pivots = new CountOffsetPair(BitConverter.ToInt32(raw, 60), BitConverter.ToInt32(raw, 64)); _PivotCollection = new Pivot[_Pivots.Count]; _MotionType = (MotionFlags)BitConverter.ToInt32(raw, 68); _MotionBone = BitConverter.ToInt32(raw, 72); _LinearMovement = new Point3D(BitConverter.ToSingle(raw, 76), BitConverter.ToSingle(raw, 80), BitConverter.ToSingle(raw, 84)); _AutomovePositionIndex = BitConverter.ToInt32(raw, 88); _AutomoveAngleIndex = BitConverter.ToInt32(raw, 92); _BoundingBoxMin = new Point3D(BitConverter.ToSingle(raw, 96), BitConverter.ToSingle(raw, 100), BitConverter.ToSingle(raw, 104)); _BoundingBoxMax = new Point3D(BitConverter.ToSingle(raw, 108), BitConverter.ToSingle(raw, 112), BitConverter.ToSingle(raw, 116)); _BlendCount = BitConverter.ToInt32(raw, 120); _AnimationOffset = BitConverter.ToInt32(raw, 124); _BlendType[0] = (MotionFlags)BitConverter.ToInt32(raw, 128); _BlendType[1] = (MotionFlags)BitConverter.ToInt32(raw, 132); _BlendStart[0] = BitConverter.ToSingle(raw, 136); _BlendStart[1] = BitConverter.ToSingle(raw, 140); _BlendEnd[0] = BitConverter.ToSingle(raw, 144); _BlendEnd[1] = BitConverter.ToSingle(raw, 148); _BlendParent = BitConverter.ToInt32(raw, 152); _SequenceGroupIndex = BitConverter.ToInt32(raw, 156); _NodeEntry = BitConverter.ToInt32(raw, 160); _NodeExit = BitConverter.ToInt32(raw, 164); _NodeFlags = (NodeFlags)BitConverter.ToInt32(raw, 168); _Unknown[0] = BitConverter.ToInt32(raw, 172); _Unknown[1] = BitConverter.ToInt32(raw, 176); _Unknown[2] = BitConverter.ToInt32(raw, 180); _Unknown[3] = BitConverter.ToInt32(raw, 184); }
public void Read(string file) { Clear(); FileInfo fi = new FileInfo(file); _Tokenizer = new FileTokenizer(file); bool eof = false; bool havetoken = false; while (!eof) { try { if (!havetoken) { eof = _Tokenizer.GetToken(); } havetoken = false; switch (_Tokenizer.Token.ToLower()) { #region " Attachment " case CommandAttachment.Command: CommandAttachment attach = new CommandAttachment(); _Tokenizer.GetToken(); attach.Name = _Tokenizer.Token; _Tokenizer.GetToken(); attach.Bone = _Tokenizer.Token; _Tokenizer.GetToken(); attach.Position.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); attach.Position.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); attach.Position.Z = Convert.ToSingle(_Tokenizer.Token); _AttachmentCollection.Add(attach); break; #endregion #region " BBox " case CommandBBox.Command: _BBox = new CommandBBox(); _Tokenizer.GetToken(); _BBox.Min.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _BBox.Min.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _BBox.Min.Z = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _BBox.Max.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _BBox.Max.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _BBox.Max.Z = Convert.ToSingle(_Tokenizer.Token); break; #endregion #region " Body " case CommandBody.Command: CommandBody body = new CommandBody(); _Tokenizer.GetToken(); body.Name = _Tokenizer.Token; _Tokenizer.GetToken(); body.File = _Tokenizer.Token; StaticMethods.SmdFile = fi.DirectoryName + "\\" + body.File + ".smd"; _BodyCollection.Add(body); break; #endregion #region " Body Group " case CommandBodyGroup.Command: CommandBodyGroup bodygroup = new CommandBodyGroup(); _Tokenizer.GetToken(); bodygroup.Name = _Tokenizer.Token; _Tokenizer.GetToken(); if (_Tokenizer.Token == "{") { while (true) { _Tokenizer.GetToken(); if (_Tokenizer.Token != "}") { if (_Tokenizer.Token.ToLower() != "blank") { BodyGroupItem bgi = new BodyGroupItem(); bgi.Name = _Tokenizer.Token; _Tokenizer.GetToken(); bgi.File = _Tokenizer.Token; StaticMethods.SmdFile = fi.DirectoryName + "\\" + bgi.File + ".smd"; bodygroup.BodyCollection.Add(bgi); } else { BodyGroupItem bgi = new BodyGroupItem(); bgi.Name = _Tokenizer.Token; bodygroup.BodyCollection.Add(bgi); } } else { break; } } } _BodyGroupCollection.Add(bodygroup); break; #endregion #region " CBox " case CommandCBox.Command: _CBox = new CommandCBox(); _Tokenizer.GetToken(); _CBox.Min.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _CBox.Min.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _CBox.Min.Z = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _CBox.Max.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _CBox.Max.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); _CBox.Max.Z = Convert.ToSingle(_Tokenizer.Token); break; #endregion #region " Cd " case CommandCd.Command: _Tokenizer.GetToken(); _Cd = new CommandCd(_Tokenizer.Token); break; #endregion #region " Cd Texture " case CommandCdTexture.Command: _Tokenizer.GetToken(); _CdTexture = new CommandCdTexture(_Tokenizer.Token); break; #endregion #region " Clip To Textures " case CommandClipToTextures.Command: _ClipToTextures = new CommandClipToTextures(); break; #endregion #region " Controller " case CommandController.Command: CommandController controller = new CommandController(); _Tokenizer.GetToken(); if (_Tokenizer.Token == "mouth") { controller.Index = 4; } else { controller.Index = Convert.ToInt32(_Tokenizer.Token); } _Tokenizer.GetToken(); controller.Bone = _Tokenizer.Token; _Tokenizer.GetToken(); controller.Type = Enumerators.ToMotionFlags(_Tokenizer.Token); _Tokenizer.GetToken(); controller.Start = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); controller.End = Convert.ToInt32(_Tokenizer.Token); _ControllerCollection.Add(controller); break; #endregion #region " External Textures " case CommandExternalTextures.Command: _ExternalTextures = new CommandExternalTextures(); break; #endregion #region " Eye Position " case CommandEyePosition.Command: CommandEyePosition eyeposition = new CommandEyePosition(); _Tokenizer.GetToken(); eyeposition.Value.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); eyeposition.Value.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); eyeposition.Value.Z = Convert.ToSingle(_Tokenizer.Token); _EyePosition = eyeposition; break; #endregion #region " Flags " case CommandFlags.Command: _Tokenizer.GetToken(); _Flags = new CommandFlags((TypeFlag)Convert.ToInt32(_Tokenizer.Token)); break; #endregion #region " Gamma " case CommandGamma.Command: _Tokenizer.GetToken(); _Gamma = new CommandGamma(Convert.ToSingle(_Tokenizer.Token)); break; #endregion #region " HBox " case CommandHBox.Command: CommandHBox hbox = new CommandHBox(); _Tokenizer.GetToken(); hbox.Group = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Bone = _Tokenizer.Token; _Tokenizer.GetToken(); hbox.Min.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Min.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Min.Z = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Max.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Max.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); hbox.Max.Z = Convert.ToSingle(_Tokenizer.Token); _HBoxCollection.Add(hbox); break; #endregion #region " Mirror Bone " case CommandMirrorBone.Command: _Tokenizer.GetToken(); _MirrorBone = new CommandMirrorBone(_Tokenizer.Token); break; #endregion #region " Model Name " case CommandModelName.Command: _Tokenizer.GetToken(); _ModelName = new CommandModelName(_Tokenizer.Token); break; #endregion #region " Origin " case CommandOrigin.Command: CommandOrigin origin = new CommandOrigin(); _Tokenizer.GetToken(); origin.Value.X = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); origin.Value.Y = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); origin.Value.Z = Convert.ToSingle(_Tokenizer.Token); _Origin = origin; break; #endregion #region " Pivot " case CommandPivot.Command: CommandPivot pivot = new CommandPivot(); _Tokenizer.GetToken(); pivot.Index = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); pivot.Bone = _Tokenizer.Token; _Pivot = pivot; break; #endregion #region " Rename Bone " case CommandRenameBone.Command: CommandRenameBone renamebone = new CommandRenameBone(); _Tokenizer.GetToken(); renamebone.OldName = _Tokenizer.Token; _Tokenizer.GetToken(); renamebone.NewName = _Tokenizer.Token; break; #endregion #region " Root " case CommandRoot.Command: _Tokenizer.GetToken(); _Root = new CommandRoot(_Tokenizer.Token); break; #endregion #region " Scale " case CommandScale.Command: _Tokenizer.GetToken(); _Scale = new CommandScale(Convert.ToSingle(_Tokenizer.Token)); break; #endregion #region " Sequence " case CommandSequenceV10.Command: CommandSequenceV10 sequence = new CommandSequenceV10(); _Tokenizer.GetToken(); sequence.Name = _Tokenizer.Token; int seqdepth = 0; while (!_Tokenizer.GetToken()) { // Ran into another command, get out. if (_Tokenizer.Token.StartsWith("$")) { havetoken = true; break; } switch (_Tokenizer.Token.ToLower()) { #region " Depth " case "{": seqdepth++; break; case "}": seqdepth--; break; #endregion #region " Animation " case OptionAnimation.Option: _Tokenizer.GetToken(); sequence.Animation = new OptionAnimation(_Tokenizer.Token); break; #endregion #region " Blend " case OptionBlend.Option: OptionBlend blend = new OptionBlend(); _Tokenizer.GetToken(); blend.Type = Enumerators.ToMotionFlags(_Tokenizer.Token); _Tokenizer.GetToken(); blend.Start = Convert.ToSingle(_Tokenizer.Token); _Tokenizer.GetToken(); blend.End = Convert.ToSingle(_Tokenizer.Token); sequence.BlendCollection.Add(blend); break; #endregion #region " Event " case OptionEvent.Option: OptionEvent @event = new OptionEvent(); _Tokenizer.GetToken(); @event.EventValue = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); @event.Frame = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); @event.Options = _Tokenizer.Token; sequence.EventCollection.Add(@event); break; #endregion #region " Fps " case OptionFps.Option: _Tokenizer.GetToken(); sequence.Fps = new OptionFps(Convert.ToSingle(_Tokenizer.Token)); break; #endregion #region " Frame " case OptionFrame.Option: OptionFrame frame = new OptionFrame(); _Tokenizer.GetToken(); frame.Start = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); frame.End = Convert.ToInt32(_Tokenizer.Token); sequence.Frame = frame; break; #endregion #region " Loop " case OptionLoop.Option: sequence.Loop = new OptionLoop(true); break; #endregion #region " Node " case OptionNodeV10.Option: _Tokenizer.GetToken(); sequence.Node = new OptionNodeV10(Convert.ToSByte(_Tokenizer.Token)); break; #endregion #region " Pivot " case OptionPivot.Option: OptionPivot pivot2 = new OptionPivot(); _Tokenizer.GetToken(); pivot2.Index = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); pivot2.Start = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); pivot2.End = Convert.ToInt32(_Tokenizer.Token); sequence.PivotCollection.Add(pivot2); break; #endregion #region " Rotate " case OptionRotate.Option: _Tokenizer.GetToken(); sequence.Rotate = new OptionRotate(Convert.ToInt32(_Tokenizer.Token)); break; #endregion #region " RTransition " case OptionRTransition.Option: OptionRTransition rtransition = new OptionRTransition(); _Tokenizer.GetToken(); rtransition.EntryBone = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); rtransition.ExitBone = Convert.ToInt32(_Tokenizer.Token); sequence.RTransition = rtransition; break; #endregion #region " Scale " case OptionScale.Option: _Tokenizer.GetToken(); sequence.Scale = new OptionScale(Convert.ToSingle(_Tokenizer.Token)); break; #endregion #region " Transition " case OptionTransition.Option: OptionTransition transition = new OptionTransition(); _Tokenizer.GetToken(); transition.EntryBone = Convert.ToInt32(_Tokenizer.Token); _Tokenizer.GetToken(); transition.ExitBone = Convert.ToInt32(_Tokenizer.Token); sequence.Transition = transition; break; #endregion #region " Control, Activity, and SMD " default: MotionFlags controltemp = Enumerators.ToMotionFlags(_Tokenizer.Token); ActivityV10 activitytemp; try { activitytemp = (ActivityV10)Enum.Parse(typeof(ActivityV10), _Tokenizer.Token); } catch (ArgumentException) { activitytemp = ActivityV10.ACT_INVALID; } if (controltemp != MotionFlags.Invalid) { sequence.Control.Flags |= controltemp; } else if (activitytemp != ActivityV10.ACT_INVALID) { OptionActivityV10 activity = new OptionActivityV10(); activity.Activity = activitytemp; _Tokenizer.GetToken(); activity.ActivityWeight = Convert.ToSingle(_Tokenizer.Token); sequence.Activity = activity; } else { StaticMethods.SmdFile = fi.DirectoryName + "\\" + _Tokenizer.Token + ".smd"; sequence.FileCollection.Add(_Tokenizer.Token); } break; #endregion } } _SequenceCollection.Add(sequence); break; #endregion #region " Texture Group " case CommandTextureGroup.Command: CommandTextureGroup texturegroup = new CommandTextureGroup(); _Tokenizer.GetToken(); texturegroup.Name = _Tokenizer.Token; int depth = 0; List <string> references = new List <string>(); while (!_Tokenizer.GetToken()) { if (_Tokenizer.Token == "{") { depth++; } else if (_Tokenizer.Token == "}") { depth--; if (depth == 0) { break; } texturegroup.SkinCollection.Add(references); references = new List <string>(); } else if (depth == 2) { references.Add(_Tokenizer.Token); } } break; #endregion #region " Default " default: if (_Tokenizer.Token.StartsWith("$")) { _OmittedCommands.Add(new OmittedCommand(_Tokenizer.Line, _Tokenizer.Token)); } break; #endregion } } catch (Exception e) { Messages.ThrowException("Qc.QcFileV10.Read(string)", e.Message + " (" + Messages.LINE + _Tokenizer.Line + ", " + Messages.TOKEN + _Tokenizer.Token + ")"); } } }
internal static MotionCommand CreateSimpleMotion( string name, Func<MotionData> func, MotionFlags? flags = null) { var flagsRaw = flags ?? MotionFlags.CursorMovement; var commandName = KeyNotationUtil.StringToKeyInputSet(name); return MotionCommand.NewSimpleMotionCommand( commandName, flagsRaw, FuncUtil.CreateMotionFunc(func)); }
/// <summary> /// Converts a MoveToState packet from the client -> MovementData packet to send to other clients /// This is effectively a shortcut for converting RawMotionState -> InterpretedMotionState /// </summary> public MovementData(Creature creature, MoveToState state) { WorldObject = creature; var rawState = state.RawMotionState; // keeping most of this existing logic, ported from ConvertToClientAccepted if ((rawState.Flags & RawMotionFlags.CurrentStyle) != 0) { CurrentStyle = rawState.CurrentStyle; } // only using primary hold key? var holdKey = rawState.CurrentHoldKey; var speed = holdKey == HoldKey.Run ? creature.GetRunRate() : 1.0f; var interpState = new InterpretedMotionState(this); // move forwards / backwards / animation if ((rawState.Flags & RawMotionFlags.ForwardCommand) != 0 && !state.StandingLongJump) { if (rawState.ForwardCommand == MotionCommand.WalkForward || rawState.ForwardCommand == MotionCommand.WalkBackwards) { interpState.ForwardCommand = MotionCommand.WalkForward; if (rawState.ForwardCommand == MotionCommand.WalkForward && holdKey == HoldKey.Run) { interpState.ForwardCommand = MotionCommand.RunForward; } interpState.ForwardSpeed = speed; if (rawState.ForwardCommand == MotionCommand.WalkBackwards) { interpState.ForwardSpeed *= -0.65f; } } else { interpState.ForwardCommand = rawState.ForwardCommand; } } // sidestep if ((rawState.Flags & RawMotionFlags.SideStepCommand) != 0 && !state.StandingLongJump) { interpState.SidestepCommand = MotionCommand.SideStepRight; interpState.SidestepSpeed = speed * 3.12f / 1.25f * 0.5f; if (rawState.SidestepCommand == MotionCommand.SideStepLeft) { interpState.SidestepSpeed *= -1; } Math.Clamp(interpState.SidestepSpeed, -3, 3); } // rotate if ((rawState.Flags & RawMotionFlags.TurnCommand) != 0) { interpState.TurnCommand = MotionCommand.TurnRight; interpState.TurnSpeed = holdKey == HoldKey.Run ? 1.5f : 1.0f; if (rawState.TurnCommand == MotionCommand.TurnLeft) { interpState.TurnSpeed *= -1; } } // contact/sticky? // this alone isn't enough for standing long jump, // and observing clients seems to show a buggy shallow arc jump // without the above exclusions of ForwardCommand / SidestepCommand if (state.StandingLongJump) { MotionFlags |= MotionFlags.StandingLongJump; } interpState.Commands = rawState.Commands; interpState.Flags = interpState.BuildMovementFlags(); // this is a hack to make walking work correctly - investigate this // wouldn't all of these be autonomous? // walk backwards? //if (holdKey != HoldKey.Invalid || rawState.ForwardCommand == MotionCommand.WalkForward) IsAutonomous = true; Invalid = new MovementInvalid(this, interpState); }
public MotionActivityEvent(MotionFlags flags, Confidence confidence, DateTime dt) { this.Motions = flags; this.Confidence = confidence; this.StartDate = dt; }
public OptionBlend(MotionFlags type, float start, float end) { _Type = type; _Start = start; _End = end; }
public override byte[] GetPayload(WorldObject animationTarget, float distanceFromObject = 0.6f) { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write((byte)MovementTypes); MotionFlags flags = MotionFlags.None; if (HasTarget) { flags |= MotionFlags.HasTarget; } if (Jumping) { flags |= MotionFlags.Jumping; } writer.Write((byte)flags); // these can be or and has sticky object | is long jump mode | writer.Write((ushort)Stance); // called command in the client switch (MovementTypes) { case MovementTypes.General: { MovementStateFlag generalFlags = MovementData.MovementStateFlag; generalFlags += (uint)Commands.Count << 7; writer.Write((uint)generalFlags); MovementData.Serialize(writer); foreach (var item in Commands) { writer.Write((ushort)item.Motion); writer.Write(animationTarget.Sequences.GetNextSequence(Sequence.SequenceType.Motion)); writer.Write(item.Speed); } break; } case MovementTypes.MoveToObject: { // 4320783 = EE0F // 4320847 = EE4F // 4321264 = EFF0 // 4321136 = EF70 // 4319823 = EA4F // EE9F -? fail distance 100 writer.Write(animationTarget.Guid.Full); Position.Serialize(writer, false); // TODO: Og Fix to real numbers writer.Write(Flag); writer.Write(distanceFromObject); writer.Write((float)0); writer.Write(float.MaxValue); writer.Write((float)1); writer.Write((float)15); writer.Write((float)0); writer.Write(1.0f); break; } case MovementTypes.MoveToPosition: { try { Position.Serialize(writer, false); // TODO: Og Fix to real numbers writer.Write(Flag); writer.Write(distanceFromObject); writer.Write((float)0); writer.Write(float.MaxValue); writer.Write((float)1); writer.Write((float)15); writer.Write((float)0); writer.Write(1.0f); } catch (Exception) { // Do nothing // TODO: This prevents a crash in Kryst and possibly other locations, Please investigate and fix if possible. } break; } } return(stream.ToArray()); }
public UniversalMotion(byte[] currentMotionState) { MemoryStream stream = new MemoryStream(currentMotionState); BinaryReader reader = new BinaryReader(stream); MovementTypes = (MovementTypes)reader.ReadByte(); // movement_type MotionFlags flags = (MotionFlags)reader.ReadByte(); // these can be or and has sticky object | is long jump mode | if ((flags & MotionFlags.HasTarget) != 0) { HasTarget = true; } if ((flags & MotionFlags.Jumping) != 0) { Jumping = true; } Stance = (MotionStance)reader.ReadUInt16(); // called command in the client MovementStateFlag generalFlags = (MovementStateFlag)reader.ReadUInt32(); MovementData = new MovementData(); if ((generalFlags & MovementStateFlag.CurrentStyle) != 0) { try { MovementData.CurrentStyle = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.CurrentStyle = 0; } } if ((generalFlags & MovementStateFlag.ForwardCommand) != 0) { try { MovementData.ForwardCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.ForwardCommand = 0; } } if ((generalFlags & MovementStateFlag.ForwardSpeed) != 0) { try { MovementData.ForwardSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.ForwardSpeed = 0; } } if ((generalFlags & MovementStateFlag.SideStepCommand) != 0) { try { MovementData.SideStepCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.SideStepCommand = 0; } } if ((generalFlags & MovementStateFlag.SideStepSpeed) != 0) { try { MovementData.SideStepSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.SideStepSpeed = 0; } } if ((generalFlags & MovementStateFlag.TurnCommand) != 0) { try { MovementData.TurnCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.TurnCommand = 0; } } if ((generalFlags & MovementStateFlag.TurnSpeed) != 0) { try { MovementData.TurnSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.TurnSpeed = 0; } } // foreach (var item in Commands) // { // writer.Write((ushort)item.Motion); // writer.Write(animationTarget.Sequences.GetNextSequence(Sequence.SequenceType.Motion)); // writer.Write(item.Speed); // } // if ((generalFlags & MovementStateFlag.ForwardCommand) != 0) // { // MotionItem item = new MotionItem(); // item.Motion = (MotionCommand)reader.ReadUInt16(); // item.Speed = reader.ReadSingle(); // Commands.Add(item); // } // if ((generalFlags & MovementStateFlag.SideStepCommand) != 0) // { // MotionItem item = new MotionItem(); // item.Motion = (MotionCommand)reader.ReadUInt16(); // item.Speed = reader.ReadSingle(); // Commands.Add(item); // } // if ((generalFlags & MovementStateFlag.TurnCommand) != 0) // { // MotionItem item = new MotionItem(); // item.Motion = (MotionCommand)reader.ReadUInt16(); // item.Speed = reader.ReadSingle(); // Commands.Add(item); // } // return stream.ToArray(); }
public override byte[] GetPayload(ObjectGuid animationTargetGuid, SequenceManager sequence) { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write((byte)MovementTypes); MotionFlags flags = MotionFlags.None; if (HasTarget) { flags |= MotionFlags.HasTarget; } if (Jumping) { flags |= MotionFlags.Jumping; } writer.Write((byte)flags); // these can be or and has sticky object | is long jump mode | writer.Write((ushort)Stance); // called command in the client switch (MovementTypes) { case MovementTypes.General: { MovementData.SetMovementStateFlag(); MovementStateFlag generalFlags = MovementData.MovementStateFlag; generalFlags += (uint)Commands.Count << 7; writer.Write((uint)generalFlags); MovementData.Serialize(writer); // Must be aligned for correct alignment. - sigh Og II writer.Align(); foreach (var item in Commands) { writer.Write((ushort)item.Motion); writer.Write(sequence.GetNextSequence(SequenceType.Motion)); writer.Write(item.Speed); } break; } case MovementTypes.MoveToPosition: case MovementTypes.MoveToObject: { try { if (MovementTypes == MovementTypes.MoveToObject) { writer.Write(TargetGuid.Full); } Position.Serialize(writer, false); writer.Write(Flag); writer.Write(DistanceFrom); writer.Write(MinimumDistance); writer.Write(FailDistance); writer.Write(Speed); writer.Write(WalkRunThreshold); writer.Write(Heading); writer.Write(RunRate); } catch (Exception) { // Do nothing // TODO: This prevents a crash in Kryst and possibly other locations, Please investigate and fix if possible. } break; } case MovementTypes.TurnToObject: { // This had the wrong value being passed. We had never used this // movement type yet - coded it up but had not used or tested. writer.Write(TargetGuid.Full); writer.Write(Heading); writer.Write(Flag); writer.Write(Speed); writer.Write(DesiredHeading); // always 0.0 in every pcap of this type. break; } case MovementTypes.TurnToHeading: { writer.Write(Flag); writer.Write(Speed); writer.Write(Heading); break; } } return(stream.ToArray()); }
public UniversalMotion(byte[] currentMotionState) { MemoryStream stream = new MemoryStream(currentMotionState); BinaryReader reader = new BinaryReader(stream); MovementTypes = (MovementTypes)reader.ReadByte(); // movement_type MotionFlags flags = (MotionFlags)reader.ReadByte(); // these can be or and has sticky object | is long jump mode | if ((flags & MotionFlags.HasTarget) != 0) { HasTarget = true; } if ((flags & MotionFlags.Jumping) != 0) { Jumping = true; } Stance = (MotionStance)reader.ReadUInt16(); // called command in the client MovementStateFlag generalFlags = (MovementStateFlag)reader.ReadUInt32(); MovementData = new MovementData(); if ((generalFlags & MovementStateFlag.CurrentStyle) != 0) { try { MovementData.CurrentStyle = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.CurrentStyle = 0; } } if ((generalFlags & MovementStateFlag.ForwardCommand) != 0) { try { MovementData.ForwardCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.ForwardCommand = 0; } } if ((generalFlags & MovementStateFlag.ForwardSpeed) != 0) { try { MovementData.ForwardSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.ForwardSpeed = 0; } } if ((generalFlags & MovementStateFlag.SideStepCommand) != 0) { try { MovementData.SideStepCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.SideStepCommand = 0; } } if ((generalFlags & MovementStateFlag.SideStepSpeed) != 0) { try { MovementData.SideStepSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.SideStepSpeed = 0; } } if ((generalFlags & MovementStateFlag.TurnCommand) != 0) { try { MovementData.TurnCommand = (ushort)reader.ReadUInt32(); } catch (Exception) { MovementData.TurnCommand = 0; } } if ((generalFlags & MovementStateFlag.TurnSpeed) != 0) { try { MovementData.TurnSpeed = (ushort)reader.ReadSingle(); } catch (Exception) { MovementData.TurnSpeed = 0; } } }