Exemplo n.º 1
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     Location pos = Location.FromDoubleBytes(dr.ReadBytes(24), 0);
     Location vel = Location.FromDoubleBytes(dr.ReadBytes(24), 0);
     long cid = dr.ReadLong();
     for (int i = 0; i < TheClient.TheRegion.Clouds.Count; i++)
     {
         if (TheClient.TheRegion.Clouds[i].CID == cid)
         {
             TheClient.TheRegion.Clouds.RemoveAt(i);
             break;
         }
     }
     Cloud cloud = new Cloud(TheClient.TheRegion, pos);
     cloud.Velocity = vel;
     cloud.CID = cid;
     int count = dr.ReadInt();
     for (int i = 0; i < count; i++)
     {
         cloud.Points.Add(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
         cloud.Sizes.Add(dr.ReadFloat());
         cloud.EndSizes.Add(dr.ReadFloat());
     }
     TheClient.TheRegion.Clouds.Add(cloud);
     dr.Close();
     return true;
 }
Exemplo n.º 2
0
 public ItemStack(Client tclient, byte[] data)
 {
     TheClient = tclient;
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     Load(dr, (b) => new ItemStack(tclient, b));
 }
Exemplo n.º 3
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     if (data.Length < 4)
     {
         return false;
     }
     DataStream datums = new DataStream(data);
     DataReader dr = new DataReader(datums);
     int len = dr.ReadInt();
     List<Location> locs = new List<Location>();
     List<ushort> mats = new List<ushort>();
     for (int i = 0; i < len; i++)
     {
         locs.Add(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
     }
     for (int i = 0; i < len; i++)
     {
         mats.Add(Utilities.BytesToUshort(dr.ReadBytes(2)));
     }
     byte[] dats = dr.ReadBytes(len);
     byte[] paints = dr.ReadBytes(len);
     for (int i = 0; i < len; i++)
     {
         TheClient.TheRegion.SetBlockMaterial(locs[i], mats[i], dats[i], paints[i], true); // TODO: Regen in PBAE not SBM.
     }
     return true;
 }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     DataReader dr = new DataReader(new DataStream(data));
     int cvarname_id = dr.ReadInt();
     string cvarvalue = dr.ReadFullString();
     string cvarname = TheClient.Network.Strings.StringForIndex(cvarname_id);
     CVar cvar = TheClient.CVars.system.Get(cvarname);
     if (cvar == null || !cvar.Flags.HasFlag(CVarFlag.ServerControl))
     {
         SysConsole.Output(OutputType.WARNING, "Invalid CVar " + cvarname);
         return false;
     }
     cvar.Set(cvarvalue, true);
     return true;
 }
Exemplo n.º 6
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     if (data.Length < 16)
     {
         SysConsole.Output(OutputType.WARNING, "Got chunk info packet of size: " + data.Length);
         return false;
     }
     DataStream ds = new DataStream(data);
     DataReader dr = new DataReader(ds);
     int x = dr.ReadInt();
     int y = dr.ReadInt();
     int z = dr.ReadInt();
     int posMult = dr.ReadInt();
     double prio = (new Location(x, y, z) * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition());
     lock (TheClient.TheRegion.PreppingNow)
     {
         TheClient.TheRegion.PrepChunks.Enqueue(() =>
         {
             lock (TheClient.TheRegion.PreppingNow)
             {
                 TheClient.TheRegion.PreppingNow.Add(new Vector3i(x, y, z));
             }
             TheClient.Schedule.StartASyncTask(() =>
             {
                 try
                 {
                     ParseData(data, dr, x, y, z, posMult);
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output(ex);
                     lock (TheClient.TheRegion.PreppingNow)
                     {
                         TheClient.TheRegion.PreppingNow.Remove(new Vector3i(x, y, z));
                     }
                 }
             });
         }, prio);
     }
     return true;
 }
Exemplo n.º 7
0
 void ParseData(byte[] data, DataReader dr, int x, int y, int z, int posMult)
 {
     byte[] reach = dr.ReadBytes((int)ChunkReachability.COUNT);
     int csize = Chunk.CHUNK_SIZE / posMult;
     byte[] data_unzipped = dr.ReadBytes(data.Length - 16);
     byte[] data_orig = FileHandler.Uncompress(data_unzipped);
     if (posMult == 1)
     {
         if (data_orig.Length != Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * 4)
         {
             SysConsole.Output(OutputType.WARNING, "Invalid chunk size! Expected " + (Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * Chunk.CHUNK_SIZE * 3) + ", got " + data_orig.Length + ")");
             lock (TheClient.TheRegion.PreppingNow)
             {
                 TheClient.TheRegion.PreppingNow.Remove(new Vector3i(x, y, z));
             }
             return;
         }
     }
     else if (data_orig.Length != csize * csize * csize * 2)
     {
         SysConsole.Output(OutputType.WARNING, "Invalid LOD'ed chunk size! (LOD = " + posMult + ", Expected " + (csize * csize * csize * 2) + ", got " + data_orig.Length + ")");
         lock (TheClient.TheRegion.PreppingNow)
         {
             TheClient.TheRegion.PreppingNow.Remove(new Vector3i(x, y, z));
         }
         return;
     }
     Action act = () =>
     {
         Chunk chk = TheClient.TheRegion.LoadChunk(new Vector3i(x, y, z), posMult);
         for (int i = 0; i < reach.Length; i++)
         {
             chk.Reachability[i] = reach[i] == 1;
         }
         chk.LOADING = true;
         chk.PROCESSED = false;
         lock (TheClient.TheRegion.PreppingNow)
         {
             TheClient.Schedule.StartASyncTask(() =>
             {
                 try
                 {
                     parsechunk2(chk, data_orig, posMult);
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output(ex);
                     lock (TheClient.TheRegion.PreppingNow)
                     {
                         TheClient.TheRegion.PreppingNow.Remove(chk.WorldPosition);
                     }
                 }
             });
         }
     };
     TheClient.Schedule.ScheduleSyncTask(act);
 }
Exemplo n.º 8
0
 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()));
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Loads a model from .VMD (Voxalia Model Data) input.
 /// </summary>
 public Model3D LoadModel(byte[] data)
 {
     if (data.Length < 3 || data[0] != 'V' || data[1] != 'M' || data[2] != 'D')
     {
         throw new Exception("Model3D: Invalid header bits.");
     }
     byte[] dat_filt = new byte[data.Length - "VMD001".Length];
     Array.ConstrainedCopy(data, "VMD001".Length, dat_filt, 0, dat_filt.Length);
     dat_filt = FileHandler.UnGZip(dat_filt);
     DataStream ds = new DataStream(dat_filt);
     DataReader dr = new DataReader(ds);
     Model3D mod = new Model3D();
     mod.MatrixA = ReadMat(dr);
     int meshCount = dr.ReadInt();
     mod.Meshes = new List<Model3DMesh>(meshCount);
     for (int m = 0; m < meshCount; m++)
     {
         Model3DMesh mesh = new Model3DMesh();
         mod.Meshes.Add(mesh);
         mesh.Name = dr.ReadFullString();
         int vertexCount = dr.ReadInt();
         mesh.Vertices = new List<Vector3>(vertexCount);
         for (int v = 0; v < vertexCount; v++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             double f3 = dr.ReadFloat();
             mesh.Vertices.Add(new Vector3(f1, f2, f3));
         }
         int indiceCount = dr.ReadInt() * 3;
         mesh.Indices = new List<int>(indiceCount);
         for (int i = 0; i < indiceCount; i++)
         {
             mesh.Indices.Add(dr.ReadInt());
         }
         int tcCount = dr.ReadInt();
         mesh.TexCoords = new List<Vector2>(tcCount);
         for (int t = 0; t < tcCount; t++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             mesh.TexCoords.Add(new Vector2(f1, f2));
         }
         int normCount = dr.ReadInt();
         mesh.Normals = new List<Vector3>(normCount);
         for (int n = 0; n < normCount; n++)
         {
             double f1 = dr.ReadFloat();
             double f2 = dr.ReadFloat();
             double f3 = dr.ReadFloat();
             mesh.Normals.Add(new Vector3(f1, f2, f3));
         }
         int boneCount = dr.ReadInt();
         mesh.Bones = new List<Model3DBone>(boneCount);
         for (int b = 0; b < boneCount; b++)
         {
             Model3DBone bone = new Model3DBone();
             mesh.Bones.Add(bone);
             bone.Name = dr.ReadFullString();
             int weights = dr.ReadInt();
             bone.IDs = new List<int>(weights);
             bone.Weights = new List<double>(weights);
             for (int w = 0; w < weights; w++)
             {
                 bone.IDs.Add(dr.ReadInt());
                 bone.Weights.Add(dr.ReadFloat());
             }
             bone.MatrixA = ReadMat(dr);
         }
     }
     mod.RootNode = ReadSingleNode(null, dr);
     return mod;
 }
Exemplo n.º 10
0
 public Model3DNode ReadSingleNode(Model3DNode root, DataReader dr)
 {
     Model3DNode n = new Model3DNode();
     n.Parent = root;
     n.Name = dr.ReadFullString();
     n.MatrixA = ReadMat(dr);
     int cCount = dr.ReadInt();
     n.Children = new List<Model3DNode>(cCount);
     for (int i = 0; i < cCount; i++)
     {
         n.Children.Add(ReadSingleNode(n, dr));
     }
     return n;
 }
Exemplo n.º 11
0
 public Matrix ReadMat(DataReader reader)
 {
     double a1 = reader.ReadFloat();
     double a2 = reader.ReadFloat();
     double a3 = reader.ReadFloat();
     double a4 = reader.ReadFloat();
     double b1 = reader.ReadFloat();
     double b2 = reader.ReadFloat();
     double b3 = reader.ReadFloat();
     double b4 = reader.ReadFloat();
     double c1 = reader.ReadFloat();
     double c2 = reader.ReadFloat();
     double c3 = reader.ReadFloat();
     double c4 = reader.ReadFloat();
     double d1 = reader.ReadFloat();
     double d2 = reader.ReadFloat();
     double d3 = reader.ReadFloat();
     double d4 = reader.ReadFloat();
     return new Matrix(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
     //return new Matrix(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
 }
Exemplo n.º 12
0
 public byte[] LoadWAVE(DataStream stream, out int channels, out int bits, out int rate)
 {
     DataReader dr = new DataReader(stream);
     string signature = new string(dr.ReadChars(4));
     if (signature != "RIFF")
     {
         throw new NotSupportedException("Not a RIFF .wav file: " + signature);
     }
     /*int riff_chunk_size = */dr.ReadInt32();
     string format = new string(dr.ReadChars(4));
     if (format != "WAVE")
     {
         throw new NotSupportedException("Not a WAVE .wav file: " + format);
     }
     string format_signature = new string(dr.ReadChars(4));
     if (format_signature != "fmt ")
     {
         throw new NotSupportedException("Not a 'fmt ' .wav file: " + format_signature);
     }
     /*int format_chunk_size = */dr.ReadInt32();
     /*int audio_format = */dr.ReadInt16();
     int num_channels = dr.ReadInt16();
     if (num_channels != 1 && num_channels != 2)
     {
         throw new NotSupportedException("Invalid number of channels: " + num_channels);
     }
     int sample_rate = dr.ReadInt32();
     /*int byte_rate = */dr.ReadInt32();
     /*int block_align = */dr.ReadInt16();
     int bits_per_sample = dr.ReadInt16();
     string data_signature = new string(dr.ReadChars(4));
     if (data_signature != "data")
     {
         throw new NotSupportedException("Not a DATA .wav file: " + data_signature);
     }
     /*int data_chunk_size = */dr.ReadInt32();
     channels = num_channels;
     bits = bits_per_sample;
     rate = sample_rate;
     return dr.ReadBytes((int)dr.BaseStream.Length);
 }
 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;
 }
Exemplo n.º 14
0
 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;
 }