diff --git a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 index 0c873ef..241fa57 100644 Binary files a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 and b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/05f9b26b-16b6-4b0b-803e-c7d09bc7b820.vsidx b/.vs/CommunityServerAPI/FileContentIndex/05f9b26b-16b6-4b0b-803e-c7d09bc7b820.vsidx new file mode 100644 index 0000000..ef4d679 Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/05f9b26b-16b6-4b0b-803e-c7d09bc7b820.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/07cf8ced-6e3f-450c-bbaa-39bf7633932b.vsidx b/.vs/CommunityServerAPI/FileContentIndex/07cf8ced-6e3f-450c-bbaa-39bf7633932b.vsidx deleted file mode 100644 index c9d92cb..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/07cf8ced-6e3f-450c-bbaa-39bf7633932b.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/3ae1dde2-3a5c-48d1-bcae-69ff6adbb231.vsidx b/.vs/CommunityServerAPI/FileContentIndex/3ae1dde2-3a5c-48d1-bcae-69ff6adbb231.vsidx new file mode 100644 index 0000000..a5d6d01 Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/3ae1dde2-3a5c-48d1-bcae-69ff6adbb231.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/3dc4cfb3-2b79-40e6-9d63-f8af8e48b076.vsidx b/.vs/CommunityServerAPI/FileContentIndex/3dc4cfb3-2b79-40e6-9d63-f8af8e48b076.vsidx deleted file mode 100644 index 7984a2e..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/3dc4cfb3-2b79-40e6-9d63-f8af8e48b076.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/618adb22-40f0-407a-b594-74505fed54dc.vsidx b/.vs/CommunityServerAPI/FileContentIndex/618adb22-40f0-407a-b594-74505fed54dc.vsidx deleted file mode 100644 index 7b595c3..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/618adb22-40f0-407a-b594-74505fed54dc.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/6a799850-ee7f-4a85-9a0e-49a6a23e58dc.vsidx b/.vs/CommunityServerAPI/FileContentIndex/6a799850-ee7f-4a85-9a0e-49a6a23e58dc.vsidx new file mode 100644 index 0000000..c9f5a27 Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/6a799850-ee7f-4a85-9a0e-49a6a23e58dc.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/b3e55f13-7a50-464d-b033-ad88ca92f108.vsidx b/.vs/CommunityServerAPI/FileContentIndex/b3e55f13-7a50-464d-b033-ad88ca92f108.vsidx deleted file mode 100644 index e40ddd9..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/b3e55f13-7a50-464d-b033-ad88ca92f108.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/c950d57b-a920-430b-ba6a-c877dd7bdd0f.vsidx b/.vs/CommunityServerAPI/FileContentIndex/c950d57b-a920-430b-ba6a-c877dd7bdd0f.vsidx new file mode 100644 index 0000000..dadd25b Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/c950d57b-a920-430b-ba6a-c877dd7bdd0f.vsidx differ diff --git a/BattleBitAPI/Common/Data/Attachment.cs b/BattleBitAPI/Common/Data/Attachment.cs new file mode 100644 index 0000000..2cb870f --- /dev/null +++ b/BattleBitAPI/Common/Data/Attachment.cs @@ -0,0 +1,74 @@ +using BattleBitAPI.Common; +using System; + +namespace BattleBitAPI.Common +{ + public class Attachment : IEquatable, IEquatable + { + public string Name { get; private set; } + public AttachmentType AttachmentType { get; private set; } + public Attachment(string name, AttachmentType attachmentType) + { + Name = name; + AttachmentType = attachmentType; + } + + public override string ToString() + { + return this.Name; + } + public bool Equals(string other) + { + if (other == null) + return false; + return this.Name.Equals(other); + } + public bool Equals(Attachment other) + { + if (other == null) + return false; + return this.Name.Equals(other.Name); + } + + public static bool operator ==(string left, Attachment right) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(string left, Attachment right) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator ==(Attachment right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(Attachment right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + } +} diff --git a/BattleBitAPI/Common/Data/Gadget.cs b/BattleBitAPI/Common/Data/Gadget.cs new file mode 100644 index 0000000..dbc4b54 --- /dev/null +++ b/BattleBitAPI/Common/Data/Gadget.cs @@ -0,0 +1,69 @@ +namespace BattleBitAPI.Common +{ + public class Gadget : IEquatable, IEquatable + { + public string Name { get; private set; } + public Gadget(string name) + { + Name = name; + } + + public override string ToString() + { + return this.Name; + } + public bool Equals(string other) + { + if (other == null) + return false; + return this.Name.Equals(other); + } + public bool Equals(Gadget other) + { + if (other == null) + return false; + return this.Name.Equals(other.Name); + } + + public static bool operator ==(string left, Gadget right) + { + bool leftNull = object.ReferenceEquals(left,null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(string left, Gadget right) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator ==(Gadget right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(Gadget right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + } +} diff --git a/BattleBitAPI/Common/Data/PlayerLoadout.cs b/BattleBitAPI/Common/Data/PlayerLoadout.cs new file mode 100644 index 0000000..cc072ac --- /dev/null +++ b/BattleBitAPI/Common/Data/PlayerLoadout.cs @@ -0,0 +1,349 @@ +namespace BattleBitAPI.Common +{ + public struct PlayerLoadout + { + public WeaponItem PrimaryWeapon; + public WeaponItem SecondaryWeapon; + public string FirstAidName; + public string LightGadgetName; + public string HeavyGadgetName; + public string ThrowableName; + + public byte PrimaryExtraMagazines; + public byte SecondaryExtraMagazines; + public byte FirstAidExtra; + public byte LightGadgetExtra; + public byte HeavyGadgetExtra; + public byte ThrowableExtra; + + public Gadget FirstAid + { + get + { + if (Gadgets.TryFind(FirstAidName, out var gadget)) + return gadget; + return null; + } + set + { + if (value == null) + this.FirstAidName = "none"; + else + this.FirstAidName = value.Name; + } + } + public Gadget LightGadget + { + get + { + if (Gadgets.TryFind(LightGadgetName, out var gadget)) + return gadget; + return null; + } + set + { + if (value == null) + this.LightGadgetName = "none"; + else + this.LightGadgetName = value.Name; + } + } + public Gadget HeavyGadget + { + get + { + if (Gadgets.TryFind(HeavyGadgetName, out var gadget)) + return gadget; + return null; + } + set + { + if (value == null) + this.HeavyGadgetName = "none"; + else + this.HeavyGadgetName = value.Name; + } + } + public Gadget Throwable + { + get + { + if (Gadgets.TryFind(ThrowableName, out var gadget)) + return gadget; + return null; + } + set + { + if (value == null) + this.ThrowableName = "none"; + else + this.ThrowableName = value.Name; + } + } + + public bool HasGadget(Gadget gadget) + { + if (this.FirstAid == gadget) + return true; + if (this.LightGadget == gadget) + return true; + if (this.HeavyGadget == gadget) + return true; + if (this.Throwable == gadget) + return true; + return false; + } + + public void Write(Common.Serialization.Stream ser) + { + this.PrimaryWeapon.Write(ser); + this.SecondaryWeapon.Write(ser); + ser.WriteStringItem(this.FirstAidName); + ser.WriteStringItem(this.LightGadgetName); + ser.WriteStringItem(this.HeavyGadgetName); + ser.WriteStringItem(this.ThrowableName); + + ser.Write(this.PrimaryExtraMagazines); + ser.Write(this.SecondaryExtraMagazines); + ser.Write(this.FirstAidExtra); + ser.Write(this.LightGadgetExtra); + ser.Write(this.HeavyGadgetExtra); + ser.Write(this.ThrowableExtra); + } + public void Read(Common.Serialization.Stream ser) + { + this.PrimaryWeapon.Read(ser); + this.SecondaryWeapon.Read(ser); + ser.TryReadString(out this.FirstAidName); + ser.TryReadString(out this.LightGadgetName); + ser.TryReadString(out this.HeavyGadgetName); + ser.TryReadString(out this.ThrowableName); + + this.PrimaryExtraMagazines = ser.ReadInt8(); + this.SecondaryExtraMagazines = ser.ReadInt8(); + this.FirstAidExtra = ser.ReadInt8(); + this.LightGadgetExtra = ser.ReadInt8(); + this.HeavyGadgetExtra = ser.ReadInt8(); + this.ThrowableExtra = ser.ReadInt8(); + } + + public struct WeaponItem + { + public string ToolName; + public string MainSightName; + public string TopSightName; + public string CantedSightName; + public string BarrelName; + public string SideRailName; + public string UnderRailName; + public string BoltActionName; + public byte SkinIndex; + public byte MagazineIndex; + + public Weapon Tool + { + get + { + if (Weapons.TryFind(ToolName, out var weapon)) + return weapon; + return null; + } + set + { + if (value == null) + this.ToolName = "none"; + else + this.ToolName = value.Name; + } + } + public Attachment MainSight + { + get + { + if (Attachments.TryFind(MainSightName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.MainSightName = "none"; + else + this.MainSightName = value.Name; + } + } + public Attachment TopSight + { + get + { + if (Attachments.TryFind(TopSightName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.TopSightName = "none"; + else + this.TopSightName = value.Name; + } + } + public Attachment CantedSight + { + get + { + if (Attachments.TryFind(CantedSightName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.CantedSightName = "none"; + else + this.CantedSightName = value.Name; + } + } + public Attachment Barrel + { + get + { + if (Attachments.TryFind(BarrelName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.BarrelName = "none"; + else + this.BarrelName = value.Name; + } + } + public Attachment SideRail + { + get + { + if (Attachments.TryFind(SideRailName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.SideRailName = "none"; + else + this.SideRailName = value.Name; + } + } + public Attachment UnderRail + { + get + { + if (Attachments.TryFind(UnderRailName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.UnderRailName = "none"; + else + this.UnderRailName = value.Name; + } + } + public Attachment BoltAction + { + get + { + if (Attachments.TryFind(BoltActionName, out var attachment)) + return attachment; + return null; + } + set + { + if (value == null) + this.BoltActionName = "none"; + else + this.BoltActionName = value.Name; + } + } + + public bool HasAttachment(Attachment attachment) + { + switch (attachment.AttachmentType) + { + case AttachmentType.MainSight: + return this.MainSight == attachment; + case AttachmentType.TopSight: + return this.TopSight == attachment; + case AttachmentType.CantedSight: + return this.CantedSight == attachment; + case AttachmentType.Barrel: + return this.Barrel == attachment; + case AttachmentType.UnderRail: + return this.Barrel == attachment; + case AttachmentType.SideRail: + return this.SideRail == attachment; + case AttachmentType.Bolt: + return this.BoltAction == attachment; + } + return false; + } + public void SetAttachment(Attachment attachment) + { + switch (attachment.AttachmentType) + { + case AttachmentType.MainSight: + this.MainSight = attachment; + break; + case AttachmentType.TopSight: + this.TopSight = attachment; + break; + case AttachmentType.CantedSight: + this.CantedSight = attachment; + break; + case AttachmentType.Barrel: + this.Barrel = attachment; + break; + case AttachmentType.UnderRail: + this.Barrel = attachment; + break; + case AttachmentType.SideRail: + this.SideRail = attachment; + break; + case AttachmentType.Bolt: + this.BoltAction = attachment; + break; + } + } + + public void Write(Common.Serialization.Stream ser) + { + ser.WriteStringItem(this.ToolName); + ser.WriteStringItem(this.MainSightName); + ser.WriteStringItem(this.TopSightName); + ser.WriteStringItem(this.CantedSightName); + ser.WriteStringItem(this.BarrelName); + ser.WriteStringItem(this.SideRailName); + ser.WriteStringItem(this.UnderRailName); + ser.WriteStringItem(this.BoltActionName); + ser.Write(this.SkinIndex); + ser.Write(this.MagazineIndex); + } + public void Read(Common.Serialization.Stream ser) + { + ser.TryReadString(out this.ToolName); + ser.TryReadString(out this.MainSightName); + ser.TryReadString(out this.TopSightName); + ser.TryReadString(out this.CantedSightName); + ser.TryReadString(out this.BarrelName); + ser.TryReadString(out this.SideRailName); + ser.TryReadString(out this.UnderRailName); + ser.TryReadString(out this.BoltActionName); + this.SkinIndex = ser.ReadInt8(); + this.MagazineIndex = ser.ReadInt8(); + } + } + } +} diff --git a/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs b/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs new file mode 100644 index 0000000..cb2dfb9 --- /dev/null +++ b/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs @@ -0,0 +1,50 @@ +using System.Numerics; + +namespace BattleBitAPI.Common +{ + public struct PlayerSpawnRequest + { + public PlayerSpawningPosition RequestedPoint; + public PlayerLoadout Loadout; + public PlayerWearings Wearings; + public Vector3 SpawnPosition; + public Vector3 LookDirection; + public PlayerStand SpawnStand; + public float SpawnProtection; + + public void Write(Common.Serialization.Stream ser) + { + ser.Write((byte)this.RequestedPoint); + this.Loadout.Write(ser); + this.Wearings.Write(ser); + ser.Write(this.SpawnPosition.X); + ser.Write(this.SpawnPosition.Y); + ser.Write(this.SpawnPosition.Z); + ser.Write(this.LookDirection.X); + ser.Write(this.LookDirection.Y); + ser.Write(this.LookDirection.Z); + ser.Write((byte)this.SpawnStand); + ser.Write(this.SpawnProtection); + } + public void Read(Common.Serialization.Stream ser) + { + this.RequestedPoint = (PlayerSpawningPosition)ser.ReadInt8(); + this.Loadout.Read(ser); + this.Wearings.Read(ser); + this.SpawnPosition = new Vector3() + { + X = ser.ReadFloat(), + Y = ser.ReadFloat(), + Z = ser.ReadFloat() + }; + this.LookDirection = new Vector3() + { + X = ser.ReadFloat(), + Y = ser.ReadFloat(), + Z = ser.ReadFloat() + }; + this.SpawnStand = (PlayerStand)ser.ReadInt8(); + this.SpawnProtection = ser.ReadFloat(); + } + } +} diff --git a/BattleBitAPI/Common/Data/PlayerStats.cs b/BattleBitAPI/Common/Data/PlayerStats.cs index 802495b..b649407 100644 --- a/BattleBitAPI/Common/Data/PlayerStats.cs +++ b/BattleBitAPI/Common/Data/PlayerStats.cs @@ -2,6 +2,9 @@ { public class PlayerStats { + public PlayerStats() { } + public PlayerStats(byte[] data) { Load(data); } + public bool IsBanned; public Roles Roles; public PlayerProgess Progress = new PlayerProgess(); @@ -63,6 +66,26 @@ this.Selections = ser.ReadByteArray(size); } + public byte[] SerializeToByteArray() + { + using (var ser = Common.Serialization.Stream.Get()) + { + Write(ser); + return ser.AsByteArrayData(); + } + } + public void Load(byte[] data) + { + var ser = new Common.Serialization.Stream() + { + Buffer = data, + InPool = false, + ReadPosition = 0, + WritePosition = data.Length, + }; + Read(ser); + } + public class PlayerProgess { private const uint ParamCount = 42; diff --git a/BattleBitAPI/Common/Data/PlayerWearings.cs b/BattleBitAPI/Common/Data/PlayerWearings.cs new file mode 100644 index 0000000..aa043cb --- /dev/null +++ b/BattleBitAPI/Common/Data/PlayerWearings.cs @@ -0,0 +1,43 @@ +namespace BattleBitAPI.Common +{ + public struct PlayerWearings + { + public string Head; + public string Chest; + public string Belt; + public string Backbag; + public string Eye; + public string Face; + public string Hair; + public string Skin; + public string Uniform; + public string Camo; + + public void Write(Common.Serialization.Stream ser) + { + ser.WriteStringItem(this.Head); + ser.WriteStringItem(this.Chest); + ser.WriteStringItem(this.Belt); + ser.WriteStringItem(this.Backbag); + ser.WriteStringItem(this.Eye); + ser.WriteStringItem(this.Face); + ser.WriteStringItem(this.Hair); + ser.WriteStringItem(this.Skin); + ser.WriteStringItem(this.Uniform); + ser.WriteStringItem(this.Camo); + } + public void Read(Common.Serialization.Stream ser) + { + ser.TryReadString(out this.Head); + ser.TryReadString(out this.Chest); + ser.TryReadString(out this.Belt); + ser.TryReadString(out this.Backbag); + ser.TryReadString(out this.Eye); + ser.TryReadString(out this.Face); + ser.TryReadString(out this.Hair); + ser.TryReadString(out this.Skin); + ser.TryReadString(out this.Uniform); + ser.TryReadString(out this.Camo); + } + } +} diff --git a/BattleBitAPI/Common/Data/Weapon.cs b/BattleBitAPI/Common/Data/Weapon.cs new file mode 100644 index 0000000..751a58d --- /dev/null +++ b/BattleBitAPI/Common/Data/Weapon.cs @@ -0,0 +1,73 @@ +using System; + +namespace BattleBitAPI.Common +{ + public class Weapon : IEquatable, IEquatable + { + public string Name { get; private set; } + public WeaponType WeaponType { get; private set; } + public Weapon(string name, WeaponType weaponType) + { + Name = name; + WeaponType = weaponType; + } + + public override string ToString() + { + return this.Name; + } + public bool Equals(string other) + { + if (other == null) + return false; + return this.Name.Equals(other); + } + public bool Equals(Weapon other) + { + if (other == null) + return false; + return this.Name.Equals(other.Name); + } + + public static bool operator ==(string left, Weapon right) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(string left, Weapon right) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator ==(Weapon right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + public static bool operator !=(Weapon right, string left) + { + bool leftNull = object.ReferenceEquals(left, null); + bool rightNull = object.ReferenceEquals(right, null); + if (leftNull && rightNull) + return true; + if (leftNull || rightNull) + return false; + return right.Name.Equals(left); + } + } +} \ No newline at end of file diff --git a/BattleBitAPI/Common/Datasets/Attachments.cs b/BattleBitAPI/Common/Datasets/Attachments.cs new file mode 100644 index 0000000..63fbeb9 --- /dev/null +++ b/BattleBitAPI/Common/Datasets/Attachments.cs @@ -0,0 +1,127 @@ +using System.Reflection; + +namespace BattleBitAPI.Common +{ + public static class Attachments + { + // ----- Private Variables ----- + private static Dictionary mAttachments; + + // ----- Barrels ----- + public static readonly Attachment Basic = new Attachment("Basic", AttachmentType.Barrel); + public static readonly Attachment Compensator = new Attachment("Compensator", AttachmentType.Barrel); + public static readonly Attachment Heavy = new Attachment("Heavy", AttachmentType.Barrel); + public static readonly Attachment LongBarrel = new Attachment("Long_Barrel", AttachmentType.Barrel); + public static readonly Attachment MuzzleBreak = new Attachment("Muzzle_Break", AttachmentType.Barrel); + public static readonly Attachment Ranger = new Attachment("Ranger", AttachmentType.Barrel); + public static readonly Attachment SuppressorLong = new Attachment("Suppressor_Long", AttachmentType.Barrel); + public static readonly Attachment SuppressorShort = new Attachment("Suppressor_Short", AttachmentType.Barrel); + public static readonly Attachment Tactical = new Attachment("Tactical", AttachmentType.Barrel); + public static readonly Attachment FlashHider = new Attachment("Flash_Hider", AttachmentType.Barrel); + public static readonly Attachment Osprey9 = new Attachment("Osprey_9", AttachmentType.Barrel); + public static readonly Attachment DGN308 = new Attachment("DGN-308", AttachmentType.Barrel); + public static readonly Attachment VAMB762 = new Attachment("VAMB-762", AttachmentType.Barrel); + public static readonly Attachment SDN6762 = new Attachment("SDN-6_762", AttachmentType.Barrel); + public static readonly Attachment NT4556 = new Attachment("NT-4_556", AttachmentType.Barrel); + + // ----- Canted Sights ----- + public static readonly Attachment Ironsight = new Attachment("Ironsight", AttachmentType.CantedSight); + public static readonly Attachment CantedRedDot = new Attachment("Canted_Red_Dot", AttachmentType.CantedSight); + public static readonly Attachment FYouCanted = new Attachment("FYou_Canted", AttachmentType.CantedSight); + public static readonly Attachment HoloDot = new Attachment("Holo_Dot", AttachmentType.CantedSight); + + // ----- Scope ----- + public static readonly Attachment _6xScope = new Attachment("6x_Scope", AttachmentType.MainSight); + public static readonly Attachment _8xScope = new Attachment("8x_Scope", AttachmentType.MainSight); + public static readonly Attachment _15xScope = new Attachment("15x_Scope", AttachmentType.MainSight); + public static readonly Attachment _20xScope = new Attachment("20x_Scope", AttachmentType.MainSight); + public static readonly Attachment PTR40Hunter = new Attachment("PTR-40_Hunter", AttachmentType.MainSight); + public static readonly Attachment _1P78 = new Attachment("1P78", AttachmentType.MainSight); + public static readonly Attachment Acog = new Attachment("Acog", AttachmentType.MainSight); + public static readonly Attachment M125 = new Attachment("M_125", AttachmentType.MainSight); + public static readonly Attachment Prisma = new Attachment("Prisma", AttachmentType.MainSight); + public static readonly Attachment Slip = new Attachment("Slip", AttachmentType.MainSight); + public static readonly Attachment PistolDeltaSight = new Attachment("Pistol_Delta_Sight", AttachmentType.MainSight); + public static readonly Attachment PistolRedDot = new Attachment("Pistol_Red_Dot", AttachmentType.MainSight); + public static readonly Attachment AimComp = new Attachment("Aim_Comp", AttachmentType.MainSight); + public static readonly Attachment Holographic = new Attachment("Holographic", AttachmentType.MainSight); + public static readonly Attachment Kobra = new Attachment("Kobra", AttachmentType.MainSight); + public static readonly Attachment OKP7 = new Attachment("OKP7", AttachmentType.MainSight); + public static readonly Attachment PKAS = new Attachment("PK-AS", AttachmentType.MainSight); + public static readonly Attachment RedDot = new Attachment("Red_Dot", AttachmentType.MainSight); + public static readonly Attachment Reflex = new Attachment("Reflex", AttachmentType.MainSight); + public static readonly Attachment Strikefire = new Attachment("Strikefire", AttachmentType.MainSight); + public static readonly Attachment Razor = new Attachment("Razor", AttachmentType.MainSight); + public static readonly Attachment Flir = new Attachment("Flir", AttachmentType.MainSight); + public static readonly Attachment Echo = new Attachment("Echo", AttachmentType.MainSight); + public static readonly Attachment TRI4X32 = new Attachment("TRI4X32", AttachmentType.MainSight); + public static readonly Attachment FYouSight = new Attachment("FYou_Sight", AttachmentType.MainSight); + public static readonly Attachment HoloPK120 = new Attachment("Holo_PK-120", AttachmentType.MainSight); + public static readonly Attachment Pistol8xScope = new Attachment("Pistol_8x_Scope", AttachmentType.MainSight); + public static readonly Attachment BurrisAR332 = new Attachment("BurrisAR332", AttachmentType.MainSight); + public static readonly Attachment HS401G5 = new Attachment("HS401G5", AttachmentType.MainSight); + + // ----- Top Scope ----- + public static readonly Attachment DeltaSightTop = new Attachment("Delta_Sight_Top", AttachmentType.TopSight); + public static readonly Attachment RedDotTop = new Attachment("Red_Dot_Top", AttachmentType.TopSight); + public static readonly Attachment CRedDotTop = new Attachment("C_Red_Dot_Top", AttachmentType.TopSight); + public static readonly Attachment FYouTop = new Attachment("FYou_Top", AttachmentType.TopSight); + + // ----- Under Rails ----- + public static readonly Attachment AngledGrip = new Attachment("Angled_Grip", AttachmentType.UnderRail); + public static readonly Attachment Bipod = new Attachment("Bipod", AttachmentType.UnderRail); + public static readonly Attachment VerticalGrip = new Attachment("Vertical_Grip", AttachmentType.UnderRail); + public static readonly Attachment StubbyGrip = new Attachment("Stubby_Grip", AttachmentType.UnderRail); + public static readonly Attachment StabilGrip = new Attachment("Stabil_Grip", AttachmentType.UnderRail); + public static readonly Attachment VerticalSkeletonGrip = new Attachment("Vertical_Skeleton_Grip", AttachmentType.UnderRail); + public static readonly Attachment FABDTFG = new Attachment("FAB-DTFG", AttachmentType.UnderRail); + public static readonly Attachment MagpulAngled = new Attachment("Magpul_Angled", AttachmentType.UnderRail); + public static readonly Attachment BCMGunFighter = new Attachment("BCM-Gun_Fighter", AttachmentType.UnderRail); + public static readonly Attachment ShiftShortAngledGrip = new Attachment("Shift_Short_Angled_Grip", AttachmentType.UnderRail); + public static readonly Attachment SE5Grip = new Attachment("SE-5_Grip", AttachmentType.UnderRail); + public static readonly Attachment RK6Foregrip = new Attachment("RK-6_Foregrip", AttachmentType.UnderRail); + public static readonly Attachment HeraCQRFront = new Attachment("HeraCQR_Front", AttachmentType.UnderRail); + public static readonly Attachment B25URK = new Attachment("B-25URK", AttachmentType.UnderRail); + public static readonly Attachment VTACUVGTacticalGrip = new Attachment("VTAC_UVG_TacticalGrip", AttachmentType.UnderRail); + + // ----- Side Rails ----- + public static readonly Attachment Flashlight = new Attachment("Flashlight", AttachmentType.SideRail); + public static readonly Attachment Rangefinder = new Attachment("Rangefinder", AttachmentType.SideRail); + public static readonly Attachment Redlaser = new Attachment("Redlaser", AttachmentType.SideRail); + public static readonly Attachment TacticalFlashlight = new Attachment("Tactical_Flashlight", AttachmentType.SideRail); + public static readonly Attachment Greenlaser = new Attachment("Greenlaser", AttachmentType.SideRail); + public static readonly Attachment Searchlight = new Attachment("Searchlight", AttachmentType.SideRail); + + // ----- Bolts ----- + public static readonly Attachment BoltActionA = new Attachment("Bolt_Action_A", AttachmentType.Bolt); + public static readonly Attachment BoltActionB = new Attachment("Bolt_Action_B", AttachmentType.Bolt); + public static readonly Attachment BoltActionC = new Attachment("Bolt_Action_C", AttachmentType.Bolt); + public static readonly Attachment BoltActionD = new Attachment("Bolt_Action_D", AttachmentType.Bolt); + public static readonly Attachment BoltActionE = new Attachment("Bolt_Action_E", AttachmentType.Bolt); + + // ----- Public Calls ----- + public static bool TryFind(string name, out Attachment item) + { + return mAttachments.TryGetValue(name, out item); + } + + // ----- Init ----- + static Attachments() + { + var members = typeof(Attachments).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); + mAttachments = new Dictionary(members.Length); + foreach (var memberInfo in members) + { + if (memberInfo.MemberType == System.Reflection.MemberTypes.Field) + { + var field = ((FieldInfo)memberInfo); + if (field.FieldType == typeof(Attachment)) + { + var att = (Attachment)field.GetValue(null); + mAttachments.Add(att.Name, att); + } + } + } + } + } +} diff --git a/BattleBitAPI/Common/Datasets/Gadgets.cs b/BattleBitAPI/Common/Datasets/Gadgets.cs new file mode 100644 index 0000000..b8e6216 --- /dev/null +++ b/BattleBitAPI/Common/Datasets/Gadgets.cs @@ -0,0 +1,76 @@ +using System.Reflection; + +namespace BattleBitAPI.Common +{ + public static class Gadgets + { + // ----- Private Variables ----- + private static Dictionary mGadgets; + + // ----- Public Variables ----- + public static readonly Gadget Bandage = new Gadget("Bandage"); + public static readonly Gadget Binoculars = new Gadget("Binoculars"); + public static readonly Gadget RangeFinder = new Gadget("Range Finder"); + public static readonly Gadget RepairTool = new Gadget("Repair Tool"); + public static readonly Gadget C4 = new Gadget("C4"); + public static readonly Gadget Claymore = new Gadget("Claymore"); + public static readonly Gadget M320SmokeGrenadeLauncher = new Gadget("M320 Smoke Grenade Launcher"); + public static readonly Gadget SmallAmmoKit = new Gadget("Small Ammo Kit"); + public static readonly Gadget AntiPersonnelMine = new Gadget("Anti Personnel Mine"); + public static readonly Gadget AntiVehicleMine = new Gadget("Anti Vehicle Mine"); + public static readonly Gadget MedicKit = new Gadget("Medic Kit"); + public static readonly Gadget Rpg7HeatExplosive = new Gadget("Rpg7 Heat Explosive"); + public static readonly Gadget RiotShield = new Gadget("Riot Shield"); + public static readonly Gadget FragGrenade = new Gadget("Frag Grenade"); + public static readonly Gadget ImpactGrenade = new Gadget("Impact Grenade"); + public static readonly Gadget AntiVehicleGrenade = new Gadget("Anti Vehicle Grenade"); + public static readonly Gadget SmokeGrenadeBlue = new Gadget("Smoke Grenade Blue"); + public static readonly Gadget SmokeGrenadeGreen = new Gadget("Smoke Grenade Green"); + public static readonly Gadget SmokeGrenadeRed = new Gadget("Smoke Grenade Red"); + public static readonly Gadget SmokeGrenadeWhite = new Gadget("Smoke Grenade White"); + public static readonly Gadget Flare = new Gadget("Flare"); + public static readonly Gadget SledgeHammer = new Gadget("Sledge Hammer"); + public static readonly Gadget AdvancedBinoculars = new Gadget("Advanced Binoculars"); + public static readonly Gadget Mdx201 = new Gadget("Mdx 201"); + public static readonly Gadget BinoSoflam = new Gadget("Bino Soflam"); + public static readonly Gadget HeavyAmmoKit = new Gadget("Heavy Ammo Kit"); + public static readonly Gadget Rpg7Pgo7Tandem = new Gadget("Rpg7 Pgo7 Tandem"); + public static readonly Gadget Rpg7Pgo7HeatExplosive = new Gadget("Rpg7 Pgo7 Heat Explosive"); + public static readonly Gadget Rpg7Pgo7Fragmentation = new Gadget("Rpg7 Pgo7 Fragmentation"); + public static readonly Gadget Rpg7Fragmentation = new Gadget("Rpg7 Fragmentation"); + public static readonly Gadget GrapplingHook = new Gadget("Grappling Hook"); + public static readonly Gadget AirDrone = new Gadget("Air Drone"); + public static readonly Gadget Flashbang = new Gadget("Flashbang"); + public static readonly Gadget Pickaxe = new Gadget("Pickaxe"); + public static readonly Gadget SuicideC4 = new Gadget("SuicideC4"); + public static readonly Gadget SledgeHammerSkinA = new Gadget("Sledge Hammer SkinA"); + public static readonly Gadget SledgeHammerSkinB = new Gadget("Sledge Hammer SkinB"); + public static readonly Gadget SledgeHammerSkinC = new Gadget("Sledge Hammer SkinC"); + public static readonly Gadget PickaxeIronPickaxe = new Gadget("Pickaxe IronPickaxe"); + + // ----- Public Calls ----- + public static bool TryFind(string name, out Gadget item) + { + return mGadgets.TryGetValue(name, out item); + } + + // ----- Init ----- + static Gadgets() + { + var members = typeof(Gadgets).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); + mGadgets = new Dictionary(members.Length); + foreach (var memberInfo in members) + { + if (memberInfo.MemberType == System.Reflection.MemberTypes.Field) + { + var field = ((FieldInfo)memberInfo); + if (field.FieldType == typeof(Gadget)) + { + var gad = (Gadget)field.GetValue(null); + mGadgets.Add(gad.Name, gad); + } + } + } + } + } +} diff --git a/BattleBitAPI/Common/Datasets/Weapons.cs b/BattleBitAPI/Common/Datasets/Weapons.cs new file mode 100644 index 0000000..49cd6f3 --- /dev/null +++ b/BattleBitAPI/Common/Datasets/Weapons.cs @@ -0,0 +1,82 @@ +using Microsoft.VisualBasic; +using System.Reflection; + +namespace BattleBitAPI.Common +{ + public static class Weapons + { + // ----- Private Variables ----- + private static Dictionary mWeapons; + + // ----- Public Variables ----- + public readonly static Weapon ACR = new Weapon("ACR", WeaponType.Rifle); + public readonly static Weapon AK15 = new Weapon("AK15", WeaponType.Rifle); + public readonly static Weapon AK74 = new Weapon("AK74", WeaponType.Rifle); + public readonly static Weapon G36C = new Weapon("G36C", WeaponType.Rifle); + public readonly static Weapon HoneyBadger = new Weapon("Honey Badger", WeaponType.PersonalDefenseWeapon_PDW); + public readonly static Weapon KrissVector = new Weapon("Kriss Vector", WeaponType.SubmachineGun_SMG); + public readonly static Weapon L86A1 = new Weapon("L86A1", WeaponType.LightSupportGun_LSG); + public readonly static Weapon L96 = new Weapon("L96", WeaponType.SniperRifle); + public readonly static Weapon M4A1 = new Weapon("M4A1", WeaponType.Rifle); + public readonly static Weapon M9 = new Weapon("M9", WeaponType.Pistol); + public readonly static Weapon M110 = new Weapon("M110", WeaponType.DMR); + public readonly static Weapon M249 = new Weapon("M249", WeaponType.LightMachineGun_LMG); + public readonly static Weapon MK14EBR = new Weapon("MK14 EBR", WeaponType.DMR); + public readonly static Weapon MK20 = new Weapon("MK20", WeaponType.DMR); + public readonly static Weapon MP7 = new Weapon("MP7", WeaponType.SubmachineGun_SMG); + public readonly static Weapon PP2000 = new Weapon("PP2000", WeaponType.SubmachineGun_SMG); + public readonly static Weapon SCARH = new Weapon("SCAR-H", WeaponType.Rifle); + public readonly static Weapon SSG69 = new Weapon("SSG 69", WeaponType.SniperRifle); + public readonly static Weapon SV98 = new Weapon("SV-98", WeaponType.SniperRifle); + public readonly static Weapon UMP45 = new Weapon("UMP-45", WeaponType.SubmachineGun_SMG); + public readonly static Weapon Unica = new Weapon("Unica", WeaponType.HeavyPistol); + public readonly static Weapon USP = new Weapon("USP", WeaponType.Pistol); + public readonly static Weapon AsVal = new Weapon("As Val", WeaponType.Carbine); + public readonly static Weapon AUGA3 = new Weapon("AUG A3", WeaponType.Rifle); + public readonly static Weapon DesertEagle = new Weapon("Desert Eagle", WeaponType.HeavyPistol); + public readonly static Weapon FAL = new Weapon("FAL", WeaponType.Rifle); + public readonly static Weapon Glock18 = new Weapon("Glock 18", WeaponType.AutoPistol); + public readonly static Weapon M200 = new Weapon("M200", WeaponType.SniperRifle); + public readonly static Weapon MP443 = new Weapon("MP 443", WeaponType.Pistol); + public readonly static Weapon FAMAS = new Weapon("FAMAS", WeaponType.Rifle); + public readonly static Weapon MP5 = new Weapon("MP5", WeaponType.SubmachineGun_SMG); + public readonly static Weapon P90 = new Weapon("P90", WeaponType.PersonalDefenseWeapon_PDW); + public readonly static Weapon MSR = new Weapon("MSR", WeaponType.SniperRifle); + public readonly static Weapon PP19 = new Weapon("PP19", WeaponType.SubmachineGun_SMG); + public readonly static Weapon SVD = new Weapon("SVD", WeaponType.DMR); + public readonly static Weapon Rem700 = new Weapon("Rem700", WeaponType.SniperRifle); + public readonly static Weapon SG550 = new Weapon("SG550", WeaponType.Rifle); + public readonly static Weapon Groza = new Weapon("Groza", WeaponType.PersonalDefenseWeapon_PDW); + public readonly static Weapon HK419 = new Weapon("HK419", WeaponType.Rifle); + public readonly static Weapon ScorpionEVO = new Weapon("ScorpionEVO", WeaponType.Carbine); + public readonly static Weapon Rsh12 = new Weapon("Rsh12", WeaponType.HeavyPistol); + public readonly static Weapon MG36 = new Weapon("MG36", WeaponType.LightSupportGun_LSG); + public readonly static Weapon AK5C = new Weapon("AK5C", WeaponType.Rifle); + public readonly static Weapon Ultimax100 = new Weapon("Ultimax100", WeaponType.LightMachineGun_LMG); + + // ----- Public Calls ----- + public static bool TryFind(string name, out Weapon item) + { + return mWeapons.TryGetValue(name, out item); + } + + // ----- Init ----- + static Weapons() + { + var members = typeof(Weapons).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); + mWeapons = new Dictionary(members.Length); + foreach (var memberInfo in members) + { + if (memberInfo.MemberType == System.Reflection.MemberTypes.Field) + { + var field = ((FieldInfo)memberInfo); + if (field.FieldType == typeof(Weapon)) + { + var wep = (Weapon)field.GetValue(null); + mWeapons.Add(wep.Name, wep); + } + } + } + } + } +} diff --git a/BattleBitAPI/Common/Enums/AttachmentType.cs b/BattleBitAPI/Common/Enums/AttachmentType.cs new file mode 100644 index 0000000..89ce99d --- /dev/null +++ b/BattleBitAPI/Common/Enums/AttachmentType.cs @@ -0,0 +1,13 @@ +namespace BattleBitAPI.Common +{ + public enum AttachmentType + { + MainSight, + TopSight, + CantedSight, + Barrel, + UnderRail, + SideRail, + Bolt, + } +} diff --git a/BattleBitAPI/Common/Enums/ChatChannel.cs b/BattleBitAPI/Common/Enums/ChatChannel.cs index ac7d5a4..5c36756 100644 --- a/BattleBitAPI/Common/Enums/ChatChannel.cs +++ b/BattleBitAPI/Common/Enums/ChatChannel.cs @@ -1,4 +1,4 @@ -namespace BattleBitAPI.Common.Enums +namespace BattleBitAPI.Common { public enum ChatChannel { diff --git a/BattleBitAPI/Common/Enums/GameRole.cs b/BattleBitAPI/Common/Enums/GameRole.cs new file mode 100644 index 0000000..3c99489 --- /dev/null +++ b/BattleBitAPI/Common/Enums/GameRole.cs @@ -0,0 +1,7 @@ +namespace BattleBitAPI.Common +{ + public enum GameRole + { + Assault = 0, Medic = 1, Support = 2, Engineer = 3, Recon = 4, Leader = 5 + } +} diff --git a/BattleBitAPI/Common/Enums/MapDayNight.cs b/BattleBitAPI/Common/Enums/MapDayNight.cs index 0a40c84..9f54ec1 100644 --- a/BattleBitAPI/Common/Enums/MapDayNight.cs +++ b/BattleBitAPI/Common/Enums/MapDayNight.cs @@ -1,4 +1,4 @@ -namespace BattleBitAPI.Common.Enums +namespace BattleBitAPI.Common { public enum MapDayNight : byte { diff --git a/BattleBitAPI/Common/Enums/MapSize.cs b/BattleBitAPI/Common/Enums/MapSize.cs index b9cc5b8..f623976 100644 --- a/BattleBitAPI/Common/Enums/MapSize.cs +++ b/BattleBitAPI/Common/Enums/MapSize.cs @@ -1,4 +1,4 @@ -namespace BattleBitAPI.Common.Enums +namespace BattleBitAPI.Common { public enum MapSize : byte { diff --git a/BattleBitAPI/Common/Enums/PlayerSpawningPoint.cs b/BattleBitAPI/Common/Enums/PlayerSpawningPoint.cs new file mode 100644 index 0000000..8501baa --- /dev/null +++ b/BattleBitAPI/Common/Enums/PlayerSpawningPoint.cs @@ -0,0 +1,7 @@ +namespace BattleBitAPI.Common +{ + public enum PlayerSpawningPosition : byte + { + SpawnAtPoint, SpawnAtRally, SpawnAtFriend, SpawnAtVehicle, Null + } +} diff --git a/BattleBitAPI/Common/Enums/PlayerStand.cs b/BattleBitAPI/Common/Enums/PlayerStand.cs new file mode 100644 index 0000000..84102e1 --- /dev/null +++ b/BattleBitAPI/Common/Enums/PlayerStand.cs @@ -0,0 +1,7 @@ +namespace BattleBitAPI.Common +{ + public enum PlayerStand : byte + { + Standing = 0, Crouching = 1, Proning = 2 + } +} diff --git a/BattleBitAPI/Common/Enums/Squads.cs b/BattleBitAPI/Common/Enums/Squads.cs new file mode 100644 index 0000000..a152faf --- /dev/null +++ b/BattleBitAPI/Common/Enums/Squads.cs @@ -0,0 +1,72 @@ +namespace BattleBitAPI.Common +{ + public enum Squads + { + NoSquad = 0, + + Alpha = 1, + Bravo = 2, + Charlie = 3, + Delta = 4, + Echo = 5, + Foxtrot = 6, + Golf = 7, + Hotel = 8, + India = 9, + Juliett = 10, + Kilo = 11, + Lima = 12, + Mike = 13, + November = 14, + Oscar = 15, + Papa = 16, + Quebec = 17, + Romeo = 18, + Sierra = 19, + Tango = 20, + Uniform = 21, + Whiskey = 22, + Xray = 23, + Yankee = 24, + Zulu = 25, + Ash = 26, + Baker = 27, + Cast = 28, + Diver = 29, + Eagle = 30, + Fisher = 31, + George = 32, + Hanover = 33, + Ice = 34, + Jake = 35, + King = 36, + Lash = 37, + Mule = 38, + Neptune = 39, + Ostend = 40, + Page = 41, + Quail = 42, + Raft = 43, + Scout = 44, + Tare = 45, + Unit = 46, + William = 47, + Xaintrie = 48, + Yoke = 49, + Zebra = 50, + Ace = 51, + Beer = 52, + Cast2 = 53, + Duff = 54, + Edward = 55, + Freddy = 56, + Gustav = 57, + Henry = 58, + Ivar = 59, + Jazz = 60, + Key = 61, + Lincoln = 62, + Mary = 63, + Nora = 64 + } +} diff --git a/BattleBitAPI/Common/Enums/Team.cs b/BattleBitAPI/Common/Enums/Team.cs new file mode 100644 index 0000000..370b3b2 --- /dev/null +++ b/BattleBitAPI/Common/Enums/Team.cs @@ -0,0 +1,9 @@ +namespace BattleBitAPI.Common +{ + public enum Team : byte + { + TeamA = 0, + TeamB = 1, + None = 2 + } +} diff --git a/BattleBitAPI/Common/Enums/WeaponType.cs b/BattleBitAPI/Common/Enums/WeaponType.cs new file mode 100644 index 0000000..5bd1f23 --- /dev/null +++ b/BattleBitAPI/Common/Enums/WeaponType.cs @@ -0,0 +1,17 @@ +namespace BattleBitAPI.Common +{ + public enum WeaponType : int + { + Rifle, + DMR, + SniperRifle, + LightSupportGun_LSG, + LightMachineGun_LMG, + SubmachineGun_SMG, + Pistol, + AutoPistol, + HeavyPistol, + Carbine, + PersonalDefenseWeapon_PDW, + } +} diff --git a/BattleBitAPI/Common/Serialization/Stream.cs b/BattleBitAPI/Common/Serialization/Stream.cs index eddf56f..8a4acc2 100644 --- a/BattleBitAPI/Common/Serialization/Stream.cs +++ b/BattleBitAPI/Common/Serialization/Stream.cs @@ -182,6 +182,13 @@ namespace BattleBitAPI.Common.Serialization System.Array.Copy(source.Buffer, 0, this.Buffer, this.WritePosition, source.WritePosition); this.WritePosition += source.WritePosition; } + public void WriteStringItem(string value) + { + if (value == null) + this.Write("none"); + else + this.Write(value); + } public unsafe void WriteAt(byte value, int position) { @@ -624,13 +631,11 @@ namespace BattleBitAPI.Common.Serialization System.Array.Copy(this.Buffer, 0, data, 0, this.WritePosition); return data; } - public void Reset() { this.ReadPosition = 0; this.WritePosition = 0; } - public void Dispose() { if (InPool) diff --git a/BattleBitAPI/Networking/NetworkCommuncation.cs b/BattleBitAPI/Networking/NetworkCommuncation.cs index 3e57317..eba91b7 100644 --- a/BattleBitAPI/Networking/NetworkCommuncation.cs +++ b/BattleBitAPI/Networking/NetworkCommuncation.cs @@ -9,6 +9,7 @@ ExecuteCommand = 10, SendPlayerStats = 11, + SpawnPlayer = 12, PlayerConnected = 50, PlayerDisconnected = 51, @@ -16,6 +17,11 @@ OnPlayerKilledAnotherPlayer = 53, GetPlayerStats = 54, SavePlayerStats = 55, - + OnPlayerAskingToChangeRole = 56, + OnPlayerChangedRole = 57, + OnPlayerJoinedASquad = 58, + OnPlayerLeftSquad = 59, + OnPlayerChangedTeam = 60, + OnPlayerRequestingToSpawn = 61, } } diff --git a/BattleBitAPI/Player.cs b/BattleBitAPI/Player.cs index 1c999d1..3806114 100644 --- a/BattleBitAPI/Player.cs +++ b/BattleBitAPI/Player.cs @@ -1,13 +1,22 @@ -using BattleBitAPI.Server; +using BattleBitAPI.Common; +using BattleBitAPI.Server; using System.Numerics; namespace BattleBitAPI { public class Player { - public ulong SteamID { get; set; } - public string Name { get; set; } - public GameServer GameServer { get; set; } + public ulong SteamID { get; internal set; } + public string Name { get; internal set; } + public GameServer GameServer { get; internal set; } + public GameRole Role { get; internal set; } + public Team Team { get; internal set; } + public Squads Squad { get; internal set; } + + internal virtual void OnInitialized() + { + + } public void Kick(string reason = "") { @@ -41,6 +50,10 @@ namespace BattleBitAPI { this.GameServer.MessageToPlayer(this, msg); } + public void SetNewRole(GameRole role) + { + this.GameServer.SetRoleTo(this, role); + } public void Teleport(Vector3 target) { diff --git a/BattleBitAPI/Server/GameServer.cs b/BattleBitAPI/Server/GameServer.cs index d146a2b..095fad0 100644 --- a/BattleBitAPI/Server/GameServer.cs +++ b/BattleBitAPI/Server/GameServer.cs @@ -1,7 +1,6 @@ using System.Net; using System.Net.Sockets; -using System.Numerics; -using BattleBitAPI.Common.Enums; +using BattleBitAPI.Common; using BattleBitAPI.Common.Extentions; using BattleBitAPI.Networking; using CommunityServerAPI.BattleBitAPI; @@ -204,6 +203,14 @@ namespace BattleBitAPI.Server } } + // ---- Team ---- + public IEnumerable GetAllPlayers() + { + var list = new List(254); + list.AddRange(this.mInternal.Players.Values); + return list; + } + // ---- Functions ---- public void WriteToSocket(Common.Serialization.Stream pck) { @@ -336,6 +343,14 @@ namespace BattleBitAPI.Server { MessageToPlayer(player.SteamID, msg); } + public void SetRoleTo(ulong steamID, GameRole role) + { + ExecuteCommand("setrole " + steamID + " " + role); + } + public void SetRoleTo(Player player, GameRole role) + { + SetRoleTo(player.SteamID, role); + } // ---- Closing ---- private void mClose(string reason) diff --git a/BattleBitAPI/Server/ServerListener.cs b/BattleBitAPI/Server/ServerListener.cs index 70d0067..9077d13 100644 --- a/BattleBitAPI/Server/ServerListener.cs +++ b/BattleBitAPI/Server/ServerListener.cs @@ -2,7 +2,6 @@ using System.Net.Sockets; using System.Numerics; using BattleBitAPI.Common; -using BattleBitAPI.Common.Enums; using BattleBitAPI.Common.Extentions; using BattleBitAPI.Common.Serialization; using BattleBitAPI.Networking; @@ -59,20 +58,6 @@ namespace BattleBitAPI.Server /// public Func OnGameServerDisconnected { get; set; } - /// - /// Fired when a new instance of PlayerClass is being created. - /// - /// - /// - /// ulong - SteamID of the player
- /// string - Username of the player
- /// Gameserver - The game server instance that player in
- ///
- /// - /// Returns: An instance of Player class where 'SteamID', 'Username', 'Gameserver' assiged. - /// - public Func OnCreateClient { get; set; } - /// /// Fired when a player connects to a server.
/// Check player.GameServer get the server that player joined. @@ -123,11 +108,12 @@ namespace BattleBitAPI.Server /// /// /// ulong - SteamID of the player
+ /// PlayerStats - The official stats of the player
///
/// - /// Returns: The stats of the player. + /// Returns: The modified stats of the player. /// - public Func> OnGetPlayerStats { get; set; } + public Func> OnGetPlayerStats { get; set; } /// /// Fired when game server requests to save the stats of a player. @@ -142,6 +128,72 @@ namespace BattleBitAPI.Server /// public Func OnSavePlayerStats { get; set; } + /// + /// Fired when a player requests server to change role. + /// + /// + /// + /// TPlayer - The player requesting
+ /// GameRole - The role the player asking to change
+ ///
+ /// + /// Returns: True if you accept if, false if you don't. + /// + public Func> OnPlayerRequestingToChangeRole { get; set; } + + /// + /// Fired when a player changes their game role. + /// + /// + /// + /// TPlayer - The player
+ /// GameRole - The new role of the player
+ ///
+ public Func OnPlayerChangedRole { get; set; } + + /// + /// Fired when a player joins a squad. + /// + /// + /// + /// TPlayer - The player
+ /// Squads - The squad player joined
+ ///
+ public Func OnPlayerJoinedASquad { get; set; } + + /// + /// Fired when a player leaves their squad. + /// + /// + /// + /// TPlayer - The player
+ /// Squads - The squad that player left
+ ///
+ public Func OnPlayerLeftSquad { get; set; } + + /// + /// Fired when a player changes team. + /// + /// + /// + /// TPlayer - The player
+ /// Team - The new team that player joined
+ ///
+ public Func OnPlayerChangedTeam { get; set; } + + /// + /// Fired when a player is spawning. + /// + /// + /// + /// TPlayer - The player
+ /// PlayerSpawnRequest - The request
+ ///
+ /// + /// Returns: The new spawn response + /// + public Func> OnPlayerSpawning { get; set; } + // --- Private --- private TcpListener mSocket; private Dictionary mActiveConnections; @@ -451,20 +503,45 @@ namespace BattleBitAPI.Server } } - if (OnCreateClient != null) + //Team + Team team; { - var player = OnCreateClient(steamid, username, server); - resources.AddPlayer(player); + readStream.Reset(); + if (!await networkStream.TryRead(readStream, 1, source.Token)) + throw new Exception("Unable to read the Team"); + team = (Team)readStream.ReadInt8(); } - else - { - TPlayer player = Activator.CreateInstance(); - player.SteamID = steamid; - player.Name = username; - player.GameServer = server; - resources.AddPlayer(player); + //Squad + Squads squad; + { + readStream.Reset(); + if (!await networkStream.TryRead(readStream, 1, source.Token)) + throw new Exception("Unable to read the Squad"); + squad = (Squads)readStream.ReadInt8(); } + + //Role + GameRole role; + { + readStream.Reset(); + if (!await networkStream.TryRead(readStream, 1, source.Token)) + throw new Exception("Unable to read the Role"); + role = (GameRole)readStream.ReadInt8(); + } + + TPlayer player = Activator.CreateInstance(); + player.SteamID = steamid; + player.Name = username; + player.GameServer = server; + + player.Team = team; + player.Squad = squad; + player.Role = role; + + player.OnInitialized(); + + resources.AddPlayer(player); } //Send accepted notification. @@ -563,29 +640,29 @@ namespace BattleBitAPI.Server { case NetworkCommuncation.PlayerConnected: { - if (stream.CanRead(8)) + if (stream.CanRead(8 + 2 + (1 + 1 + 1))) { ulong steamID = stream.ReadUInt64(); if (stream.TryReadString(out var username)) { - if (OnCreateClient != null) - { - var player = OnCreateClient(steamID, username, server); - resources.AddPlayer(player); - if (OnPlayerConnected != null) - await OnPlayerConnected.Invoke(player); - } - else - { - TPlayer player = Activator.CreateInstance(); - player.SteamID = steamID; - player.Name = username; - player.GameServer = server; + Team team = (Team)stream.ReadInt8(); + Squads squad = (Squads)stream.ReadInt8(); + GameRole role = (GameRole)stream.ReadInt8(); - resources.AddPlayer(player); - if (OnPlayerConnected != null) - await OnPlayerConnected.Invoke(player); - } + TPlayer player = Activator.CreateInstance(); + player.SteamID = steamID; + player.Name = username; + player.GameServer = server; + + player.Team = team; + player.Squad = squad; + player.Role = role; + + player.OnInitialized(); + + resources.AddPlayer(player); + if (OnPlayerConnected != null) + await OnPlayerConnected.Invoke(player); } } break; @@ -641,7 +718,7 @@ namespace BattleBitAPI.Server if (resources.TryGetPlayer(killer, out var killerClient)) if (resources.TryGetPlayer(victim, out var victimClient)) if (OnAPlayerKilledAnotherPlayer != null) - OnAPlayerKilledAnotherPlayer.Invoke((TPlayer)killerClient, killerPos, (TPlayer)victimClient, victimPos, tool); + await OnAPlayerKilledAnotherPlayer.Invoke((TPlayer)killerClient, killerPos, (TPlayer)victimClient, victimPos, tool); } } @@ -649,22 +726,22 @@ namespace BattleBitAPI.Server } case NetworkCommuncation.GetPlayerStats: { - if (stream.CanRead(8)) + if (stream.CanRead(8 + 2)) { ulong steamID = stream.ReadUInt64(); + var stats = new PlayerStats(); + stats.Read(stream); + if (OnGetPlayerStats != null) + stats = await OnGetPlayerStats.Invoke(steamID, stats); + + using (var response = Common.Serialization.Stream.Get()) { - var stats = await OnGetPlayerStats.Invoke(steamID); - - using (var response = Common.Serialization.Stream.Get()) - { - response.Write((byte)NetworkCommuncation.SendPlayerStats); - response.Write(steamID); - stats.Write(response); - - server.WriteToSocket(response); - } + response.Write((byte)NetworkCommuncation.SendPlayerStats); + response.Write(steamID); + stats.Write(response); + server.WriteToSocket(response); } } break; @@ -682,6 +759,121 @@ namespace BattleBitAPI.Server } break; } + case NetworkCommuncation.OnPlayerAskingToChangeRole: + { + if (stream.CanRead(8 + 1)) + { + ulong steamID = stream.ReadUInt64(); + GameRole role = (GameRole)stream.ReadInt8(); + + if (resources.TryGetPlayer(steamID, out var client)) + { + bool accepted = true; + + if (OnPlayerRequestingToChangeRole != null) + accepted = await OnPlayerRequestingToChangeRole.Invoke((TPlayer)client, role); + + if (accepted) + server.SetRoleTo(steamID, role); + } + } + break; + } + case NetworkCommuncation.OnPlayerChangedRole: + { + if (stream.CanRead(8 + 1)) + { + ulong steamID = stream.ReadUInt64(); + GameRole role = (GameRole)stream.ReadInt8(); + + if (resources.TryGetPlayer(steamID, out var client)) + { + client.Role = role; + if (OnPlayerChangedRole != null) + await OnPlayerChangedRole.Invoke((TPlayer)client, role); + } + } + break; + } + case NetworkCommuncation.OnPlayerJoinedASquad: + { + if (stream.CanRead(8 + 1)) + { + ulong steamID = stream.ReadUInt64(); + Squads squad = (Squads)stream.ReadInt8(); + + if (resources.TryGetPlayer(steamID, out var client)) + { + client.Squad = squad; + if (OnPlayerJoinedASquad != null) + await OnPlayerJoinedASquad.Invoke((TPlayer)client, squad); + } + } + break; + } + case NetworkCommuncation.OnPlayerLeftSquad: + { + if (stream.CanRead(8)) + { + ulong steamID = stream.ReadUInt64(); + + if (resources.TryGetPlayer(steamID, out var client)) + { + var oldSquad = client.Squad; + var oldRole = client.Role; + client.Squad = Squads.NoSquad; + client.Role = GameRole.Assault; + + if (OnPlayerLeftSquad != null) + await OnPlayerLeftSquad.Invoke((TPlayer)client, oldSquad); + + if (oldRole != GameRole.Assault) + if (OnPlayerChangedRole != null) + await OnPlayerChangedRole.Invoke((TPlayer)client, GameRole.Assault); + } + } + break; + } + case NetworkCommuncation.OnPlayerChangedTeam: + { + if (stream.CanRead(8 + 1)) + { + ulong steamID = stream.ReadUInt64(); + Team team = (Team)stream.ReadInt8(); + + if (resources.TryGetPlayer(steamID, out var client)) + { + client.Team = team; + if (OnPlayerChangedTeam != null) + await OnPlayerChangedTeam.Invoke((TPlayer)client, team); + } + } + break; + } + case NetworkCommuncation.OnPlayerRequestingToSpawn: + { + if (stream.CanRead(2)) + { + ulong steamID = stream.ReadUInt64(); + + var request = new PlayerSpawnRequest(); + request.Read(stream); + + if (resources.TryGetPlayer(steamID, out var client)) + if (this.OnPlayerSpawning != null) + request = await OnPlayerSpawning.Invoke((TPlayer)client, request); + + //Respond back. + using (var response = Common.Serialization.Stream.Get()) + { + response.Write((byte)NetworkCommuncation.SpawnPlayer); + response.Write(steamID); + request.Write(response); + server.WriteToSocket(response); + } + } + break; + } } } diff --git a/BattleBitAPI/Storage/DiskStorage.cs b/BattleBitAPI/Storage/DiskStorage.cs new file mode 100644 index 0000000..512d3b4 --- /dev/null +++ b/BattleBitAPI/Storage/DiskStorage.cs @@ -0,0 +1,41 @@ +using BattleBitAPI.Common; + +namespace BattleBitAPI.Storage +{ + public class DiskStorage : IPlayerStatsDatabase + { + private string mDirectory; + public DiskStorage(string directory) + { + var info = new DirectoryInfo(directory); + if (!info.Exists) + info.Create(); + + this.mDirectory = info.FullName + Path.DirectorySeparatorChar; + } + + public async Task GetPlayerStatsOf(ulong steamID) + { + var file = this.mDirectory + steamID + ".data"; + if (File.Exists(file)) + { + try + { + var data = await File.ReadAllBytesAsync(file); + return new PlayerStats(data); + } + catch { } + } + return null; + } + public async Task SavePlayerStatsOf(ulong steamID, PlayerStats stats) + { + var file = this.mDirectory + steamID + ".data"; + try + { + await File.WriteAllBytesAsync(file, stats.SerializeToByteArray()); + } + catch { } + } + } +} diff --git a/BattleBitAPI/Storage/IPlayerStatsDatabase.cs b/BattleBitAPI/Storage/IPlayerStatsDatabase.cs new file mode 100644 index 0000000..6689cfb --- /dev/null +++ b/BattleBitAPI/Storage/IPlayerStatsDatabase.cs @@ -0,0 +1,10 @@ +using BattleBitAPI.Common; + +namespace BattleBitAPI.Storage +{ + public interface IPlayerStatsDatabase + { + public Task GetPlayerStatsOf(ulong steamID); + public Task SavePlayerStatsOf(ulong steamID, PlayerStats stats); + } +} diff --git a/Program.cs b/Program.cs index bdc5e1c..87a2663 100644 --- a/Program.cs +++ b/Program.cs @@ -1,37 +1,78 @@ using BattleBitAPI; using BattleBitAPI.Common; -using BattleBitAPI.Common.Enums; using BattleBitAPI.Server; +using BattleBitAPI.Storage; using System.Numerics; class Program { + + static DiskStorage playerStats; static void Main(string[] args) { + playerStats = new DiskStorage("Players\\"); var listener = new ServerListener(); listener.OnGetPlayerStats += OnGetPlayerStats; - listener.OnSavePlayerStats += OnSavePlayerStats; + listener.OnPlayerSpawning += OnPlayerSpawning; listener.Start(29294);//Port + Thread.Sleep(-1); } - public static PlayerStats Stats; - private static async Task OnSavePlayerStats(ulong steamID, PlayerStats stats) + + private static async Task OnPlayerSpawning(MyPlayer player, PlayerSpawnRequest request) { - Stats = stats; + if (request.Loadout.PrimaryWeapon.Tool == Weapons.M4A1) + { + //Don't allow M4A1 + request.Loadout.PrimaryWeapon.Tool = null; + } + else if (request.Loadout.PrimaryWeapon.Tool.WeaponType == WeaponType.SniperRifle) + { + //Force 6x if weapon is sniper. + request.Loadout.PrimaryWeapon.MainSight = Attachments._6xScope; + } + + //Override pistol with deagle + request.Loadout.SecondaryWeapon.Tool = Weapons.DesertEagle; + + //Force everyone to use RPG + request.Loadout.LightGadget = Gadgets.Rpg7HeatExplosive; + + //Don't allow C4s + if (request.Loadout.HeavyGadget == Gadgets.C4) + request.Loadout.HeavyGadget = null; + + //Spawn player 2 meter above than the original position. + request.SpawnPosition.Y += 2f; + + //Remove spawn protection + request.SpawnProtection = 0f; + + //Remove chest armor + request.Wearings.Chest = null; + + //Give extra 10 more magazines on primary + request.Loadout.PrimaryExtraMagazines += 10; + + //Give extra 5 more throwables + request.Loadout.ThrowableExtra += 5; + + return request; } - private static async Task OnGetPlayerStats(ulong steamID) + + + + private async static Task OnGetPlayerStats(ulong steamID, PlayerStats officialStats) { - if (Stats == null) - Stats = new PlayerStats(); - Stats.Progress.Rank = 155; - Stats.Roles = Roles.Moderator; - Stats.IsBanned = true; - return Stats; + officialStats.Progress.Rank = 200; + return officialStats; } } class MyPlayer : Player { + public int Cash; + public bool InJail = false; } diff --git a/bin/Debug/net6.0/CommunityServerAPI.dll b/bin/Debug/net6.0/CommunityServerAPI.dll index 65a6ac3..38fe434 100644 Binary files a/bin/Debug/net6.0/CommunityServerAPI.dll and b/bin/Debug/net6.0/CommunityServerAPI.dll differ diff --git a/bin/Debug/net6.0/CommunityServerAPI.pdb b/bin/Debug/net6.0/CommunityServerAPI.pdb index c8b0d6d..4017406 100644 Binary files a/bin/Debug/net6.0/CommunityServerAPI.pdb and b/bin/Debug/net6.0/CommunityServerAPI.pdb differ diff --git a/bin/Debug/net6.0/Database/Players/0.data b/bin/Debug/net6.0/Database/Players/0.data new file mode 100644 index 0000000..633f17f Binary files /dev/null and b/bin/Debug/net6.0/Database/Players/0.data differ diff --git a/bin/Debug/net6.0/Database/Players/76561000000045304.data b/bin/Debug/net6.0/Database/Players/76561000000045304.data new file mode 100644 index 0000000..cafec53 Binary files /dev/null and b/bin/Debug/net6.0/Database/Players/76561000000045304.data differ diff --git a/bin/Debug/net6.0/Database/Players/76561000000217991.data b/bin/Debug/net6.0/Database/Players/76561000000217991.data new file mode 100644 index 0000000..cafec53 Binary files /dev/null and b/bin/Debug/net6.0/Database/Players/76561000000217991.data differ diff --git a/bin/Debug/net6.0/Players/76561000000073947.data b/bin/Debug/net6.0/Players/76561000000073947.data new file mode 100644 index 0000000..2fcfa78 Binary files /dev/null and b/bin/Debug/net6.0/Players/76561000000073947.data differ diff --git a/bin/Debug/net6.0/Players/76561000000811832.data b/bin/Debug/net6.0/Players/76561000000811832.data new file mode 100644 index 0000000..517a15e Binary files /dev/null and b/bin/Debug/net6.0/Players/76561000000811832.data differ diff --git a/obj/Debug/net6.0/CommunityServerAPI.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/CommunityServerAPI.csproj.CoreCompileInputs.cache index a7ee0bd..4cd02b9 100644 --- a/obj/Debug/net6.0/CommunityServerAPI.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/CommunityServerAPI.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -6499f830a3ef23dc09747dba385a33c80022cbb9 +037b534b95ed15aafcef5ecdb4d5a0fad75c5328 diff --git a/obj/Debug/net6.0/CommunityServerAPI.dll b/obj/Debug/net6.0/CommunityServerAPI.dll index 65a6ac3..38fe434 100644 Binary files a/obj/Debug/net6.0/CommunityServerAPI.dll and b/obj/Debug/net6.0/CommunityServerAPI.dll differ diff --git a/obj/Debug/net6.0/CommunityServerAPI.pdb b/obj/Debug/net6.0/CommunityServerAPI.pdb index c8b0d6d..4017406 100644 Binary files a/obj/Debug/net6.0/CommunityServerAPI.pdb and b/obj/Debug/net6.0/CommunityServerAPI.pdb differ diff --git a/obj/Debug/net6.0/ref/CommunityServerAPI.dll b/obj/Debug/net6.0/ref/CommunityServerAPI.dll index dd81350..6c0f19b 100644 Binary files a/obj/Debug/net6.0/ref/CommunityServerAPI.dll and b/obj/Debug/net6.0/ref/CommunityServerAPI.dll differ diff --git a/obj/Debug/net6.0/refint/CommunityServerAPI.dll b/obj/Debug/net6.0/refint/CommunityServerAPI.dll index dd81350..6c0f19b 100644 Binary files a/obj/Debug/net6.0/refint/CommunityServerAPI.dll and b/obj/Debug/net6.0/refint/CommunityServerAPI.dll differ