|
3 | 3 |
|
4 | 4 | namespace MultiplayerUtil; |
5 | 5 |
|
6 | | -/* |
7 | | -// An example of a data packet that i made for pvp multiplayer |
8 | | -
|
9 | | -[Serializable] |
10 | | -public class DataPacket |
11 | | -{ |
12 | | - // Player Core stuff |
13 | | - public byte PlayerHealth; |
14 | | -
|
15 | | - // Pos and Movement |
16 | | - public float PositionX; |
17 | | - public float PositionY; |
18 | | - public float PositionZ; |
19 | | - public float VelocityX; |
20 | | - public float VelocityY; |
21 | | - public float VelocityZ; |
22 | | - public short RotationX; |
23 | | - public short RotationY; |
24 | | -
|
25 | | - // Combat State |
26 | | - public byte CurrentWeapon; |
27 | | - public byte CurrentVariation; |
28 | | - public bool IsSliding; |
29 | | - public bool IsPunching; |
30 | 6 |
|
31 | | - // Movement State |
32 | | - public bool IsWallJumping; |
33 | | - public bool IsSlamStorage; |
34 | | -
|
35 | | - public DataPacket( |
36 | | - int Health, |
37 | | - Vector3 Position, |
38 | | - Vector3 Velocity, |
39 | | - Vector3 Rotation, |
40 | | - int CurrentWeapon, |
41 | | - int CurrentVariation, |
42 | | - bool IsSliding, |
43 | | - bool IsPunching, |
44 | | - bool IsWallJumping, |
45 | | - bool IsSlamStorage) |
46 | | - { |
47 | | - this.PlayerHealth = (byte)Health; |
48 | | - this.PositionX = Position.x; |
49 | | - this.PositionY = Position.y; |
50 | | - this.PositionZ = Position.z; |
51 | | - this.VelocityX = Velocity.x; |
52 | | - this.VelocityY = Velocity.y; |
53 | | - this.VelocityZ = Velocity.z; |
54 | | - this.RotationX = (short)Rotation.x; |
55 | | - this.RotationY = (short)Rotation.y; |
56 | | - this.CurrentWeapon = (byte)CurrentWeapon; |
57 | | - this.CurrentVariation = (byte)CurrentVariation; |
58 | | - this.IsSliding = IsSliding; |
59 | | - this.IsPunching = IsPunching; |
60 | | - this.IsWallJumping = IsWallJumping; |
61 | | - this.IsSlamStorage = IsSlamStorage; |
62 | | - } |
63 | | -
|
64 | | - public void Display() |
65 | | - { |
66 | | - Console.WriteLine($"Health: {PlayerHealth}"); |
67 | | - Console.WriteLine($"Position: ({PositionX:F2}, {PositionY:F2}, {PositionZ:F2})"); |
68 | | - Console.WriteLine($"Velocity: ({VelocityX:F2}, {VelocityY:F2}, {VelocityZ:F2})"); |
69 | | - Console.WriteLine($"Rotation: ({RotationX:F2}, {RotationY:F2}"); |
70 | | - Console.WriteLine($"Weapon: {CurrentWeapon} | Variation: {CurrentVariation}"); |
71 | | - Console.WriteLine($"States: Sliding={IsSliding}, WallJump={IsWallJumping}, IsSlamStorage;={IsSlamStorage}"); |
72 | | - } |
73 | | -} |
74 | | -
|
75 | | -*/ |
76 | 7 | public static class Data |
77 | 8 | { |
78 | 9 | public static T Deserialize<T>(byte[] serializedData) |
@@ -167,4 +98,100 @@ public static MultiplayerUtil.SendMethod ConvertP2PSendToSendMethod(P2PSend p2pS |
167 | 98 |
|
168 | 99 | return method; |
169 | 100 | } |
| 101 | + |
| 102 | + public static byte boolsToBinary(bool[] bools) |
| 103 | + { |
| 104 | + byte binary = 0b00000000; |
| 105 | + int length = Math.Min(bools.Length, 8); |
| 106 | + |
| 107 | + for (int i = 0; i < length; i++) |
| 108 | + { |
| 109 | + if (bools[i]) |
| 110 | + { |
| 111 | + binary |= (byte)(1 << i); |
| 112 | + } |
| 113 | + } |
| 114 | + return binary; |
| 115 | + } |
| 116 | + |
| 117 | + public static bool[] byteToBools(byte data) |
| 118 | + { |
| 119 | + bool[] result = new bool[8]; |
| 120 | + for (int i = 0; i < 8; i++) |
| 121 | + { |
| 122 | + result[i] = (data & (1 << i)) != 0; |
| 123 | + } |
| 124 | + return result; |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +/* |
| 129 | +// An example of a data packet that i made for pvp multiplayer |
| 130 | +
|
| 131 | +[Serializable] |
| 132 | +public class DataPacket |
| 133 | +{ |
| 134 | + // Player Core stuff |
| 135 | + public byte PlayerHealth; |
| 136 | +
|
| 137 | + // Pos and Movement |
| 138 | + public float PositionX; |
| 139 | + public float PositionY; |
| 140 | + public float PositionZ; |
| 141 | + public float VelocityX; |
| 142 | + public float VelocityY; |
| 143 | + public float VelocityZ; |
| 144 | + public short RotationX; |
| 145 | + public short RotationY; |
| 146 | +
|
| 147 | + // Combat State |
| 148 | + public byte CurrentWeapon; |
| 149 | + public byte CurrentVariation; |
| 150 | + public bool IsSliding; |
| 151 | + public bool IsPunching; |
| 152 | +
|
| 153 | + // Movement State |
| 154 | + public bool IsWallJumping; |
| 155 | + public bool IsSlamStorage; |
| 156 | +
|
| 157 | + public DataPacket( |
| 158 | + int Health, |
| 159 | + Vector3 Position, |
| 160 | + Vector3 Velocity, |
| 161 | + Vector3 Rotation, |
| 162 | + int CurrentWeapon, |
| 163 | + int CurrentVariation, |
| 164 | + bool IsSliding, |
| 165 | + bool IsPunching, |
| 166 | + bool IsWallJumping, |
| 167 | + bool IsSlamStorage) |
| 168 | + { |
| 169 | + this.PlayerHealth = (byte)Health; |
| 170 | + this.PositionX = Position.x; |
| 171 | + this.PositionY = Position.y; |
| 172 | + this.PositionZ = Position.z; |
| 173 | + this.VelocityX = Velocity.x; |
| 174 | + this.VelocityY = Velocity.y; |
| 175 | + this.VelocityZ = Velocity.z; |
| 176 | + this.RotationX = (short)Rotation.x; |
| 177 | + this.RotationY = (short)Rotation.y; |
| 178 | + this.CurrentWeapon = (byte)CurrentWeapon; |
| 179 | + this.CurrentVariation = (byte)CurrentVariation; |
| 180 | + this.IsSliding = IsSliding; |
| 181 | + this.IsPunching = IsPunching; |
| 182 | + this.IsWallJumping = IsWallJumping; |
| 183 | + this.IsSlamStorage = IsSlamStorage; |
| 184 | + } |
| 185 | +
|
| 186 | + public void Display() |
| 187 | + { |
| 188 | + Console.WriteLine($"Health: {PlayerHealth}"); |
| 189 | + Console.WriteLine($"Position: ({PositionX:F2}, {PositionY:F2}, {PositionZ:F2})"); |
| 190 | + Console.WriteLine($"Velocity: ({VelocityX:F2}, {VelocityY:F2}, {VelocityZ:F2})"); |
| 191 | + Console.WriteLine($"Rotation: ({RotationX:F2}, {RotationY:F2}"); |
| 192 | + Console.WriteLine($"Weapon: {CurrentWeapon} | Variation: {CurrentVariation}"); |
| 193 | + Console.WriteLine($"States: Sliding={IsSliding}, WallJump={IsWallJumping}, IsSlamStorage;={IsSlamStorage}"); |
| 194 | + } |
170 | 195 | } |
| 196 | +
|
| 197 | +*/ |
0 commit comments