public ItemStack(byte[] data, Server tserver) { TheServer = tserver; DataStream ds = new DataStream(data); DataReader dr = new DataReader(ds); int attribs = dr.ReadInt(); for (int i = 0; i < attribs; i++) { string cattrib = dr.ReadFullString(); byte b = dr.ReadByte(); if (b == 0) { Attributes.Add(cattrib, new IntegerTag(dr.ReadInt64())); } else if (b == 1) { Attributes.Add(cattrib, new NumberTag(dr.ReadDouble())); } else if (b == 2) { Attributes.Add(cattrib, new BooleanTag(dr.ReadByte() == 1)); } else { Attributes.Add(cattrib, new TextTag(dr.ReadFullString())); } } Load(dr, (b) => new ItemStack(b, tserver)); }
public void Load(DataReader dr, Func<byte[], ItemStackBase> getItem) { Count = dr.ReadInt(); Datum = dr.ReadInt(); Weight = dr.ReadFloat(); Volume = dr.ReadFloat(); Temperature = dr.ReadFloat(); DrawColor = System.Drawing.Color.FromArgb(dr.ReadInt()); SetName(dr.ReadFullString()); string secondary_name = dr.ReadFullString(); SecondaryName = secondary_name.Length == 0 ? null : secondary_name; DisplayName = dr.ReadFullString(); Description = dr.ReadFullString(); string tex = dr.ReadFullString(); SetModelName(dr.ReadFullString()); SetTextureName(tex); RenderAsComponent = dr.ReadByte() == 1; ComponentRenderOffset.X = dr.ReadFloat(); ComponentRenderOffset.Y = dr.ReadFloat(); ComponentRenderOffset.Z = dr.ReadFloat(); int attribs = dr.ReadInt(); for (int i = 0; i < attribs; i++) { string cattrib = dr.ReadFullString(); byte b = dr.ReadByte(); if (b == 0) { SharedAttributes.Add(cattrib, new IntegerTag(dr.ReadInt64())); } else if (b == 1) { SharedAttributes.Add(cattrib, new NumberTag(dr.ReadDouble())); } else if (b == 2) { SharedAttributes.Add(cattrib, new BooleanTag(dr.ReadByte() == 1)); } else { SharedAttributes.Add(cattrib, new TextTag(dr.ReadFullString())); } } int comps = dr.ReadInt(); for (int i = 0; i < comps; i++) { Components.Add(getItem(dr.ReadFullBytes())); } }
public override bool ParseBytesAndExecute(byte[] data) { DataStream ds = new DataStream(data); DataReader dr = new DataReader(ds); long PEID = dr.ReadLong(); byte type = dr.ReadByte(); Entity e = TheClient.TheRegion.GetEntity(PEID); if (type == 0) { if (e is PlayerEntity) { ((PlayerEntity)e).InVehicle = true; int drivecount = dr.ReadInt(); int steercount = dr.ReadInt(); PlayerEntity player = (PlayerEntity)e; player.DrivingMotors.Clear(); player.SteeringMotors.Clear(); for (int i = 0; i < drivecount; i++) { long jid = dr.ReadLong(); JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid); if (jvm == null) { dr.Close(); return false; } player.DrivingMotors.Add(jvm); } for (int i = 0; i < steercount; i++) { long jid = dr.ReadLong(); JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid); if (jvm == null) { dr.Close(); return false; } player.SteeringMotors.Add(jvm); } dr.Close(); return true; } // TODO: other CharacterEntity's } else if (type == 1) { if (e is PlayerEntity) { long heloid = dr.ReadLong(); Entity helo = TheClient.TheRegion.GetEntity(heloid); if (!(helo is ModelEntity)) { dr.Close(); return false; } ((PlayerEntity)e).InVehicle = true; ((PlayerEntity)e).Vehicle = helo; ModelEntity helomod = (ModelEntity)helo; helomod.TurnIntoHelicopter((PlayerEntity)e); dr.Close(); return true; } // TODO: other CharacterEntity's dr.Close(); return true; } else if (type == 2) { if (e is PlayerEntity) { long planeid = dr.ReadLong(); Entity plane = TheClient.TheRegion.GetEntity(planeid); if (!(plane is ModelEntity)) { dr.Close(); return false; } ((PlayerEntity)e).InVehicle = true; ((PlayerEntity)e).Vehicle = plane; ModelEntity planemod = (ModelEntity)plane; planemod.TurnIntoPlane((PlayerEntity)e); dr.Close(); return true; } // TODO: other CharacterEntity's dr.Close(); return true; } dr.Close(); return false; }
public override Entity Create(Region tregion, byte[] data) { DataStream ds = new DataStream(data); DataReader dr = new DataReader(ds); GenericCharacterEntity ent = new GenericCharacterEntity(tregion); ent.SetPosition(Location.FromDoubleBytes(dr.ReadBytes(24), 0)); ent.SetOrientation(new BEPUutilities.Quaternion(dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat())); ent.SetMass(dr.ReadFloat()); ent.CBAirForce = dr.ReadFloat(); ent.CBAirSpeed = dr.ReadFloat(); ent.CBCrouchSpeed = dr.ReadFloat(); ent.CBDownStepHeight = dr.ReadFloat(); ent.CBGlueForce = dr.ReadFloat(); ent.CBHHeight = dr.ReadFloat(); ent.CBJumpSpeed = dr.ReadFloat(); ent.CBMargin = dr.ReadFloat(); ent.CBMaxSupportSlope = dr.ReadFloat(); ent.CBMaxTractionSlope = dr.ReadFloat(); ent.CBProneSpeed = dr.ReadFloat(); ent.CBRadius = dr.ReadFloat(); ent.CBSlideForce = dr.ReadFloat(); ent.CBSlideJumpSpeed = dr.ReadFloat(); ent.CBSlideSpeed = dr.ReadFloat(); ent.CBStandSpeed = dr.ReadFloat(); ent.CBStepHeight = dr.ReadFloat(); ent.CBTractionForce = dr.ReadFloat(); ent.PreRot *= Matrix4d.CreateRotationX(dr.ReadFloat() * Utilities.PI180); ent.PreRot *= Matrix4d.CreateRotationY(dr.ReadFloat() * Utilities.PI180); ent.PreRot *= Matrix4d.CreateRotationZ(dr.ReadFloat() * Utilities.PI180); ent.mod_scale = dr.ReadFloat(); ent.PreRot = Matrix4d.Scale(ent.mod_scale) * ent.PreRot; ent.color = System.Drawing.Color.FromArgb(dr.ReadInt()); byte dtx = dr.ReadByte(); ent.Visible = (dtx & 1) == 1; int solidity = (dtx & (2 | 4 | 8)); if (solidity == 2) { ent.CGroup = CollisionUtil.Solid; } else if (solidity == 4) { ent.CGroup = CollisionUtil.NonSolid; } else if (solidity == (2 | 4)) { ent.CGroup = CollisionUtil.Item; } else if (solidity == 8) { ent.CGroup = CollisionUtil.Player; } else if (solidity == (2 | 8)) { ent.CGroup = CollisionUtil.Water; } else if (solidity == (2 | 4 | 8)) { ent.CGroup = CollisionUtil.WorldSolid; } else if (solidity == 16) { ent.CGroup = CollisionUtil.Character; } ent.model = tregion.TheClient.Models.GetModel(tregion.TheClient.Network.Strings.StringForIndex(dr.ReadInt())); dr.Close(); return ent; }