reformat and cleanup code

This commit is contained in:
Niko Storni 2023-08-14 17:49:24 +02:00
parent 164cf6b349
commit db51bbbc4a
48 changed files with 5572 additions and 5253 deletions

View File

@ -1,10 +1,9 @@
using System.Numerics;
using CommunityServerAPI.BattleBitAPI.Server;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public struct OnPlayerKillArguments<TPlayer> where TPlayer : Player<TPlayer>
{
public struct OnPlayerKillArguments<TPlayer> where TPlayer : Player<TPlayer>
{
public TPlayer Killer;
public Vector3 KillerPosition;
@ -14,5 +13,4 @@ namespace BattleBitAPI.Common
public string KillerTool;
public PlayerBody BodyPart;
public ReasonOfDamage SourceOfDamage;
}
}

View File

@ -1,9 +1,10 @@
using System.Numerics;
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public struct OnPlayerSpawnArguments
{
public struct OnPlayerSpawnArguments
{
public PlayerSpawningPosition RequestedPoint;
public PlayerLoadout Loadout;
public PlayerWearings Wearings;
@ -12,7 +13,7 @@ namespace BattleBitAPI.Common
public PlayerStand SpawnStand;
public float SpawnProtection;
public void Write(Common.Serialization.Stream ser)
public void Write(Stream ser)
{
ser.Write((byte)RequestedPoint);
Loadout.Write(ser);
@ -26,18 +27,19 @@ namespace BattleBitAPI.Common
ser.Write((byte)SpawnStand);
ser.Write(SpawnProtection);
}
public void Read(Common.Serialization.Stream ser)
public void Read(Stream ser)
{
RequestedPoint = (PlayerSpawningPosition)ser.ReadInt8();
Loadout.Read(ser);
Wearings.Read(ser);
SpawnPosition = new Vector3()
SpawnPosition = new Vector3
{
X = ser.ReadFloat(),
Y = ser.ReadFloat(),
Z = ser.ReadFloat()
};
LookDirection = new Vector3()
LookDirection = new Vector3
{
X = ser.ReadFloat(),
Y = ser.ReadFloat(),
@ -46,5 +48,4 @@ namespace BattleBitAPI.Common
SpawnStand = (PlayerStand)ser.ReadInt8();
SpawnProtection = ser.ReadFloat();
}
}
}

View File

@ -1,18 +1,17 @@
using System;
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public class PlayerJoiningArguments
{
public class PlayerJoiningArguments
{
public Squads Squad;
public PlayerStats Stats;
public Team Team;
public Squads Squad;
public void Write(BattleBitAPI.Common.Serialization.Stream ser)
public void Write(Stream ser)
{
this.Stats.Write(ser);
ser.Write((byte)this.Team);
ser.Write((byte)this.Squad);
}
Stats.Write(ser);
ser.Write((byte)Team);
ser.Write((byte)Squad);
}
}

View File

@ -1,20 +1,25 @@
namespace CommunityServerAPI.BattleBitAPI
namespace CommunityServerAPI.BattleBitAPI;
public static class Const
{
public static class Const
{
// ---- Networking ----
/// <summary>
/// Maximum data size for a single package. 4MB is default.
/// </summary>
public const int MaxNetworkPackageSize = 1024 * 1024 * 4;//4mb
public const int MaxNetworkPackageSize = 1024 * 1024 * 4; //4mb
/// <summary>
/// How long should server/client wait until connection is determined as timed out when no packages is being sent for long time.
/// How long should server/client wait until connection is determined as timed out when no packages is being sent for
/// long time.
/// </summary>
public const int NetworkTimeout = 60 * 1000;//60 seconds
public const int NetworkTimeout = 60 * 1000; //60 seconds
/// <summary>
/// How frequently client/server will send keep alive to each other when no message is being sent to each other for a while.
/// How frequently client/server will send keep alive to each other when no message is being sent to each other for a
/// while.
/// </summary>
public const int NetworkKeepAlive = 5 * 1000;//15 seconds
public const int NetworkKeepAlive = 5 * 1000; //15 seconds
/// <summary>
/// How long server/client will wait other side to send their hail/initial package. In miliseconds.
/// </summary>
@ -39,6 +44,4 @@
public const int MinServerRulesTextLength = 0;
public const int MaxServerRulesTextLength = 1024 * 8;
}
}

View File

@ -1,74 +1,76 @@
using BattleBitAPI.Common;
using System;
namespace BattleBitAPI.Common;
namespace BattleBitAPI.Common
public class Attachment : IEquatable<string>, IEquatable<Attachment>
{
public class Attachment : IEquatable<string>, IEquatable<Attachment>
{
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 string Name { get; }
public AttachmentType AttachmentType { get; private set; }
public bool Equals(Attachment other)
{
if (other == null)
return false;
return this.Name.Equals(other.Name);
return Name.Equals(other.Name);
}
public bool Equals(string other)
{
if (other == null)
return false;
return Name.Equals(other);
}
public override string ToString()
{
return Name;
}
public static bool operator ==(string left, Attachment right)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
}
}

View File

@ -1,69 +1,74 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public class Gadget : IEquatable<string>, IEquatable<Gadget>
{
public class Gadget : IEquatable<string>, IEquatable<Gadget>
{
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 string Name { get; }
public bool Equals(Gadget other)
{
if (other == null)
return false;
return this.Name.Equals(other.Name);
return Name.Equals(other.Name);
}
public bool Equals(string other)
{
if (other == null)
return false;
return Name.Equals(other);
}
public override string ToString()
{
return Name;
}
public static bool operator ==(string left, Gadget right)
{
bool leftNull = object.ReferenceEquals(left,null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
}
}

View File

@ -1,69 +1,62 @@
using System.Reflection;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public static class Gadgets
{
public static class Gadgets
{
// ----- Private Variables -----
private static Dictionary<string, Gadget> mGadgets;
private static readonly Dictionary<string, Gadget> 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);
}
public static readonly Gadget Bandage = new("Bandage");
public static readonly Gadget Binoculars = new("Binoculars");
public static readonly Gadget RangeFinder = new("Range Finder");
public static readonly Gadget RepairTool = new("Repair Tool");
public static readonly Gadget C4 = new("C4");
public static readonly Gadget Claymore = new("Claymore");
public static readonly Gadget M320SmokeGrenadeLauncher = new("M320 Smoke Grenade Launcher");
public static readonly Gadget SmallAmmoKit = new("Small Ammo Kit");
public static readonly Gadget AntiPersonnelMine = new("Anti Personnel Mine");
public static readonly Gadget AntiVehicleMine = new("Anti Vehicle Mine");
public static readonly Gadget MedicKit = new("Medic Kit");
public static readonly Gadget Rpg7HeatExplosive = new("Rpg7 Heat Explosive");
public static readonly Gadget RiotShield = new("Riot Shield");
public static readonly Gadget FragGrenade = new("Frag Grenade");
public static readonly Gadget ImpactGrenade = new("Impact Grenade");
public static readonly Gadget AntiVehicleGrenade = new("Anti Vehicle Grenade");
public static readonly Gadget SmokeGrenadeBlue = new("Smoke Grenade Blue");
public static readonly Gadget SmokeGrenadeGreen = new("Smoke Grenade Green");
public static readonly Gadget SmokeGrenadeRed = new("Smoke Grenade Red");
public static readonly Gadget SmokeGrenadeWhite = new("Smoke Grenade White");
public static readonly Gadget Flare = new("Flare");
public static readonly Gadget SledgeHammer = new("Sledge Hammer");
public static readonly Gadget AdvancedBinoculars = new("Advanced Binoculars");
public static readonly Gadget Mdx201 = new("Mdx 201");
public static readonly Gadget BinoSoflam = new("Bino Soflam");
public static readonly Gadget HeavyAmmoKit = new("Heavy Ammo Kit");
public static readonly Gadget Rpg7Pgo7Tandem = new("Rpg7 Pgo7 Tandem");
public static readonly Gadget Rpg7Pgo7HeatExplosive = new("Rpg7 Pgo7 Heat Explosive");
public static readonly Gadget Rpg7Pgo7Fragmentation = new("Rpg7 Pgo7 Fragmentation");
public static readonly Gadget Rpg7Fragmentation = new("Rpg7 Fragmentation");
public static readonly Gadget GrapplingHook = new("Grappling Hook");
public static readonly Gadget AirDrone = new("Air Drone");
public static readonly Gadget Flashbang = new("Flashbang");
public static readonly Gadget Pickaxe = new("Pickaxe");
public static readonly Gadget SuicideC4 = new("SuicideC4");
public static readonly Gadget SledgeHammerSkinA = new("Sledge Hammer SkinA");
public static readonly Gadget SledgeHammerSkinB = new("Sledge Hammer SkinB");
public static readonly Gadget SledgeHammerSkinC = new("Sledge Hammer SkinC");
public static readonly Gadget PickaxeIronPickaxe = new("Pickaxe IronPickaxe");
// ----- Init -----
static Gadgets()
{
var members = typeof(Gadgets).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
var members = typeof(Gadgets).GetMembers(BindingFlags.Public | BindingFlags.Static);
mGadgets = new Dictionary<string, Gadget>(members.Length);
foreach (var memberInfo in members)
if (memberInfo.MemberType == MemberTypes.Field)
{
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
{
var field = ((FieldInfo)memberInfo);
var field = (FieldInfo)memberInfo;
if (field.FieldType == typeof(Gadget))
{
var gad = (Gadget)field.GetValue(null);
@ -71,6 +64,10 @@ namespace BattleBitAPI.Common
}
}
}
}
// ----- Public Calls -----
public static bool TryFind(string name, out Gadget item)
{
return mGadgets.TryGetValue(name, out item);
}
}

View File

@ -1,69 +1,74 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public class Map : IEquatable<string>, IEquatable<Map>
{
public class Map : IEquatable<string>, IEquatable<Map>
{
public string Name { get; private set; }
public Map(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 string Name { get; }
public bool Equals(Map other)
{
if (other == null)
return false;
return this.Name.Equals(other.Name);
return Name.Equals(other.Name);
}
public bool Equals(string other)
{
if (other == null)
return false;
return Name.Equals(other);
}
public override string ToString()
{
return Name;
}
public static bool operator ==(string left, Map right)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
public static bool operator !=(string left, Map right)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
public static bool operator ==(Map right, string left)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
public static bool operator !=(Map right, string left)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
}
}

View File

@ -1,7 +1,9 @@
namespace BattleBitAPI.Common
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common;
public struct PlayerLoadout
{
public struct PlayerLoadout
{
public WeaponItem PrimaryWeapon;
public WeaponItem SecondaryWeapon;
public string FirstAidName;
@ -27,11 +29,12 @@
set
{
if (value == null)
this.FirstAidName = "none";
FirstAidName = "none";
else
this.FirstAidName = value.Name;
FirstAidName = value.Name;
}
}
public Gadget LightGadget
{
get
@ -43,11 +46,12 @@
set
{
if (value == null)
this.LightGadgetName = "none";
LightGadgetName = "none";
else
this.LightGadgetName = value.Name;
LightGadgetName = value.Name;
}
}
public Gadget HeavyGadget
{
get
@ -59,11 +63,12 @@
set
{
if (value == null)
this.HeavyGadgetName = "none";
HeavyGadgetName = "none";
else
this.HeavyGadgetName = value.Name;
HeavyGadgetName = value.Name;
}
}
public Gadget Throwable
{
get
@ -75,60 +80,62 @@
set
{
if (value == null)
this.ThrowableName = "none";
ThrowableName = "none";
else
this.ThrowableName = value.Name;
ThrowableName = value.Name;
}
}
public bool HasGadget(Gadget gadget)
{
if (this.FirstAid == gadget)
if (FirstAid == gadget)
return true;
if (this.LightGadget == gadget)
if (LightGadget == gadget)
return true;
if (this.HeavyGadget == gadget)
if (HeavyGadget == gadget)
return true;
if (this.Throwable == gadget)
if (Throwable == gadget)
return true;
return false;
}
public void Write(Common.Serialization.Stream ser)
public void Write(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);
PrimaryWeapon.Write(ser);
SecondaryWeapon.Write(ser);
ser.WriteStringItem(FirstAidName);
ser.WriteStringItem(LightGadgetName);
ser.WriteStringItem(HeavyGadgetName);
ser.WriteStringItem(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);
ser.Write(PrimaryExtraMagazines);
ser.Write(SecondaryExtraMagazines);
ser.Write(FirstAidExtra);
ser.Write(LightGadgetExtra);
ser.Write(HeavyGadgetExtra);
ser.Write(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 void Read(Stream ser)
{
PrimaryWeapon.Read(ser);
SecondaryWeapon.Read(ser);
ser.TryReadString(out FirstAidName);
ser.TryReadString(out LightGadgetName);
ser.TryReadString(out HeavyGadgetName);
ser.TryReadString(out ThrowableName);
PrimaryExtraMagazines = ser.ReadInt8();
SecondaryExtraMagazines = ser.ReadInt8();
FirstAidExtra = ser.ReadInt8();
LightGadgetExtra = ser.ReadInt8();
HeavyGadgetExtra = ser.ReadInt8();
ThrowableExtra = ser.ReadInt8();
}
}
public struct WeaponItem
{
public string ToolName;
public string MainSightName;
public string TopSightName;
@ -151,11 +158,12 @@
set
{
if (value == null)
this.ToolName = "none";
ToolName = "none";
else
this.ToolName = value.Name;
ToolName = value.Name;
}
}
public Attachment MainSight
{
get
@ -167,11 +175,12 @@
set
{
if (value == null)
this.MainSightName = "none";
MainSightName = "none";
else
this.MainSightName = value.Name;
MainSightName = value.Name;
}
}
public Attachment TopSight
{
get
@ -183,11 +192,12 @@
set
{
if (value == null)
this.TopSightName = "none";
TopSightName = "none";
else
this.TopSightName = value.Name;
TopSightName = value.Name;
}
}
public Attachment CantedSight
{
get
@ -199,11 +209,12 @@
set
{
if (value == null)
this.CantedSightName = "none";
CantedSightName = "none";
else
this.CantedSightName = value.Name;
CantedSightName = value.Name;
}
}
public Attachment Barrel
{
get
@ -215,11 +226,12 @@
set
{
if (value == null)
this.BarrelName = "none";
BarrelName = "none";
else
this.BarrelName = value.Name;
BarrelName = value.Name;
}
}
public Attachment SideRail
{
get
@ -231,11 +243,12 @@
set
{
if (value == null)
this.SideRailName = "none";
SideRailName = "none";
else
this.SideRailName = value.Name;
SideRailName = value.Name;
}
}
public Attachment UnderRail
{
get
@ -247,11 +260,12 @@
set
{
if (value == null)
this.UnderRailName = "none";
UnderRailName = "none";
else
this.UnderRailName = value.Name;
UnderRailName = value.Name;
}
}
public Attachment BoltAction
{
get
@ -263,9 +277,9 @@
set
{
if (value == null)
this.BoltActionName = "none";
BoltActionName = "none";
else
this.BoltActionName = value.Name;
BoltActionName = value.Name;
}
}
@ -274,75 +288,77 @@
switch (attachment.AttachmentType)
{
case AttachmentType.MainSight:
return this.MainSight == attachment;
return MainSight == attachment;
case AttachmentType.TopSight:
return this.TopSight == attachment;
return TopSight == attachment;
case AttachmentType.CantedSight:
return this.CantedSight == attachment;
return CantedSight == attachment;
case AttachmentType.Barrel:
return this.Barrel == attachment;
return Barrel == attachment;
case AttachmentType.UnderRail:
return this.Barrel == attachment;
return Barrel == attachment;
case AttachmentType.SideRail:
return this.SideRail == attachment;
return SideRail == attachment;
case AttachmentType.Bolt:
return this.BoltAction == attachment;
return BoltAction == attachment;
}
return false;
}
public void SetAttachment(Attachment attachment)
{
switch (attachment.AttachmentType)
{
case AttachmentType.MainSight:
this.MainSight = attachment;
MainSight = attachment;
break;
case AttachmentType.TopSight:
this.TopSight = attachment;
TopSight = attachment;
break;
case AttachmentType.CantedSight:
this.CantedSight = attachment;
CantedSight = attachment;
break;
case AttachmentType.Barrel:
this.Barrel = attachment;
Barrel = attachment;
break;
case AttachmentType.UnderRail:
this.Barrel = attachment;
Barrel = attachment;
break;
case AttachmentType.SideRail:
this.SideRail = attachment;
SideRail = attachment;
break;
case AttachmentType.Bolt:
this.BoltAction = attachment;
BoltAction = attachment;
break;
}
}
public void Write(Common.Serialization.Stream ser)
public void Write(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);
ser.WriteStringItem(ToolName);
ser.WriteStringItem(MainSightName);
ser.WriteStringItem(TopSightName);
ser.WriteStringItem(CantedSightName);
ser.WriteStringItem(BarrelName);
ser.WriteStringItem(SideRailName);
ser.WriteStringItem(UnderRailName);
ser.WriteStringItem(BoltActionName);
ser.Write(SkinIndex);
ser.Write(MagazineIndex);
}
public void Read(Common.Serialization.Stream ser)
public void Read(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();
}
ser.TryReadString(out ToolName);
ser.TryReadString(out MainSightName);
ser.TryReadString(out TopSightName);
ser.TryReadString(out CantedSightName);
ser.TryReadString(out BarrelName);
ser.TryReadString(out SideRailName);
ser.TryReadString(out UnderRailName);
ser.TryReadString(out BoltActionName);
SkinIndex = ser.ReadInt8();
MagazineIndex = ser.ReadInt8();
}
}

View File

@ -1,21 +1,30 @@
namespace BattleBitAPI.Common
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common;
public class PlayerStats
{
public class PlayerStats
{
public PlayerStats() { }
public PlayerStats(byte[] data) { Load(data); }
public byte[] Achievements;
public bool IsBanned;
public PlayerProgess Progress = new();
public Roles Roles;
public PlayerProgess Progress = new PlayerProgess();
public byte[] ToolProgress;
public byte[] Achievements;
public byte[] Selections;
public byte[] ToolProgress;
public void Write(Common.Serialization.Stream ser)
public PlayerStats()
{
ser.Write(this.IsBanned);
ser.Write((ulong)this.Roles);
}
public PlayerStats(byte[] data)
{
Load(data);
}
public void Write(Stream ser)
{
ser.Write(IsBanned);
ser.Write((ulong)Roles);
Progress.Write(ser);
@ -49,39 +58,41 @@
ser.Write((ushort)0);
}
}
public void Read(Common.Serialization.Stream ser)
{
this.IsBanned = ser.ReadBool();
this.Roles = (Roles)ser.ReadUInt64();
this.Progress.Read(ser);
public void Read(Stream ser)
{
IsBanned = ser.ReadBool();
Roles = (Roles)ser.ReadUInt64();
Progress.Read(ser);
int size = ser.ReadInt16();
this.ToolProgress = ser.ReadByteArray(size);
ToolProgress = ser.ReadByteArray(size);
size = ser.ReadInt16();
this.Achievements = ser.ReadByteArray(size);
Achievements = ser.ReadByteArray(size);
size = ser.ReadInt16();
this.Selections = ser.ReadByteArray(size);
Selections = ser.ReadByteArray(size);
}
public byte[] SerializeToByteArray()
{
using (var ser = Common.Serialization.Stream.Get())
using (var ser = Stream.Get())
{
Write(ser);
return ser.AsByteArrayData();
}
}
public void Load(byte[] data)
{
var ser = new Common.Serialization.Stream()
var ser = new Stream
{
Buffer = data,
InPool = false,
ReadPosition = 0,
WritePosition = data.Length,
WritePosition = data.Length
};
Read(ser);
}
@ -89,51 +100,51 @@
public class PlayerProgess
{
private const uint ParamCount = 42;
public uint AssaultKills;
public uint AssaultPlayTime;
public uint AssaultScore;
public uint Assists;
public uint DeathCount;
public uint EngineerKills;
public uint EngineerPlayTime;
public uint EngineerScore;
public uint EXP;
public uint FriendlyKills;
public uint FriendlyShots;
public uint Headshots;
public uint HealedHPs;
public uint KillCount;
public uint LeaderKills;
public uint AssaultKills;
public uint MedicKills;
public uint EngineerKills;
public uint SupportKills;
public uint ReconKills;
public uint DeathCount;
public uint WinCount;
public uint LeaderPlayTime;
public uint LeaderScore;
public uint LongestKill;
public uint LoseCount;
public uint FriendlyShots;
public uint FriendlyKills;
public uint Revived;
public uint RevivedTeamMates;
public uint Assists;
public uint MedicKills;
public uint MedicPlayTime;
public uint MedicScore;
public uint ObjectivesComplated;
public uint PlayTimeSeconds;
public uint Prestige;
public uint Rank;
public uint EXP;
public uint ReconKills;
public uint ReconPlayTime;
public uint ReconScore;
public uint Revived;
public uint RevivedTeamMates;
public uint RoadKills;
public uint ShotsFired;
public uint ShotsHit;
public uint Headshots;
public uint ObjectivesComplated;
public uint HealedHPs;
public uint RoadKills;
public uint Suicides;
public uint VehiclesDestroyed;
public uint VehicleHPRepaired;
public uint LongestKill;
public uint PlayTimeSeconds;
public uint LeaderPlayTime;
public uint AssaultPlayTime;
public uint MedicPlayTime;
public uint EngineerPlayTime;
public uint SupportKills;
public uint SupportPlayTime;
public uint ReconPlayTime;
public uint LeaderScore;
public uint AssaultScore;
public uint MedicScore;
public uint EngineerScore;
public uint SupportScore;
public uint ReconScore;
public uint TotalScore;
public uint VehicleHPRepaired;
public uint VehiclesDestroyed;
public uint WinCount;
public void Write(Common.Serialization.Stream ser)
public void Write(Stream ser)
{
ser.Write(ParamCount);
{
@ -181,101 +192,107 @@
ser.Write(TotalScore);
}
}
public void Read(Common.Serialization.Stream ser)
public void Read(Stream ser)
{
Reset();
uint mParamCount = ser.ReadUInt32();
int maxReadPosition = ser.ReadPosition + (int)(mParamCount * 4);
var mParamCount = ser.ReadUInt32();
var maxReadPosition = ser.ReadPosition + (int)(mParamCount * 4);
{
bool canRead() => ser.ReadPosition < maxReadPosition;
bool canRead()
{
return ser.ReadPosition < maxReadPosition;
}
if (canRead())
this.KillCount = ser.ReadUInt32();
KillCount = ser.ReadUInt32();
if (canRead())
this.LeaderKills = ser.ReadUInt32();
LeaderKills = ser.ReadUInt32();
if (canRead())
this.AssaultKills = ser.ReadUInt32();
AssaultKills = ser.ReadUInt32();
if (canRead())
this.MedicKills = ser.ReadUInt32();
MedicKills = ser.ReadUInt32();
if (canRead())
this.EngineerKills = ser.ReadUInt32();
EngineerKills = ser.ReadUInt32();
if (canRead())
this.SupportKills = ser.ReadUInt32();
SupportKills = ser.ReadUInt32();
if (canRead())
this.ReconKills = ser.ReadUInt32();
ReconKills = ser.ReadUInt32();
if (canRead())
this.DeathCount = ser.ReadUInt32();
DeathCount = ser.ReadUInt32();
if (canRead())
this.WinCount = ser.ReadUInt32();
WinCount = ser.ReadUInt32();
if (canRead())
this.LoseCount = ser.ReadUInt32();
LoseCount = ser.ReadUInt32();
if (canRead())
this.FriendlyShots = ser.ReadUInt32();
FriendlyShots = ser.ReadUInt32();
if (canRead())
this.FriendlyKills = ser.ReadUInt32();
FriendlyKills = ser.ReadUInt32();
if (canRead())
this.Revived = ser.ReadUInt32();
Revived = ser.ReadUInt32();
if (canRead())
this.RevivedTeamMates = ser.ReadUInt32();
RevivedTeamMates = ser.ReadUInt32();
if (canRead())
this.Assists = ser.ReadUInt32();
Assists = ser.ReadUInt32();
if (canRead())
this.Prestige = ser.ReadUInt32();
Prestige = ser.ReadUInt32();
if (canRead())
this.Rank = ser.ReadUInt32();
Rank = ser.ReadUInt32();
if (canRead())
this.EXP = ser.ReadUInt32();
EXP = ser.ReadUInt32();
if (canRead())
this.ShotsFired = ser.ReadUInt32();
ShotsFired = ser.ReadUInt32();
if (canRead())
this.ShotsHit = ser.ReadUInt32();
ShotsHit = ser.ReadUInt32();
if (canRead())
this.Headshots = ser.ReadUInt32();
Headshots = ser.ReadUInt32();
if (canRead())
this.ObjectivesComplated = ser.ReadUInt32();
ObjectivesComplated = ser.ReadUInt32();
if (canRead())
this.HealedHPs = ser.ReadUInt32();
HealedHPs = ser.ReadUInt32();
if (canRead())
this.RoadKills = ser.ReadUInt32();
RoadKills = ser.ReadUInt32();
if (canRead())
this.Suicides = ser.ReadUInt32();
Suicides = ser.ReadUInt32();
if (canRead())
this.VehiclesDestroyed = ser.ReadUInt32();
VehiclesDestroyed = ser.ReadUInt32();
if (canRead())
this.VehicleHPRepaired = ser.ReadUInt32();
VehicleHPRepaired = ser.ReadUInt32();
if (canRead())
this.LongestKill = ser.ReadUInt32();
LongestKill = ser.ReadUInt32();
if (canRead())
this.PlayTimeSeconds = ser.ReadUInt32();
PlayTimeSeconds = ser.ReadUInt32();
if (canRead())
this.LeaderPlayTime = ser.ReadUInt32();
LeaderPlayTime = ser.ReadUInt32();
if (canRead())
this.AssaultPlayTime = ser.ReadUInt32();
AssaultPlayTime = ser.ReadUInt32();
if (canRead())
this.MedicPlayTime = ser.ReadUInt32();
MedicPlayTime = ser.ReadUInt32();
if (canRead())
this.EngineerPlayTime = ser.ReadUInt32();
EngineerPlayTime = ser.ReadUInt32();
if (canRead())
this.SupportPlayTime = ser.ReadUInt32();
SupportPlayTime = ser.ReadUInt32();
if (canRead())
this.ReconPlayTime = ser.ReadUInt32();
ReconPlayTime = ser.ReadUInt32();
if (canRead())
this.LeaderScore = ser.ReadUInt32();
LeaderScore = ser.ReadUInt32();
if (canRead())
this.AssaultScore = ser.ReadUInt32();
AssaultScore = ser.ReadUInt32();
if (canRead())
this.MedicScore = ser.ReadUInt32();
MedicScore = ser.ReadUInt32();
if (canRead())
this.EngineerScore = ser.ReadUInt32();
EngineerScore = ser.ReadUInt32();
if (canRead())
this.SupportScore = ser.ReadUInt32();
SupportScore = ser.ReadUInt32();
if (canRead())
this.ReconScore = ser.ReadUInt32();
ReconScore = ser.ReadUInt32();
if (canRead())
this.TotalScore = ser.ReadUInt32();
TotalScore = ser.ReadUInt32();
}
ser.ReadPosition = maxReadPosition;
}
public void Reset()
{
KillCount = 0;
@ -322,5 +339,4 @@
TotalScore = 0;
}
}
}
}

View File

@ -1,7 +1,9 @@
namespace BattleBitAPI.Common
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common;
public struct PlayerWearings
{
public struct PlayerWearings
{
public string Head;
public string Chest;
public string Belt;
@ -13,31 +15,31 @@
public string Uniform;
public string Camo;
public void Write(Common.Serialization.Stream ser)
public void Write(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);
ser.WriteStringItem(Head);
ser.WriteStringItem(Chest);
ser.WriteStringItem(Belt);
ser.WriteStringItem(Backbag);
ser.WriteStringItem(Eye);
ser.WriteStringItem(Face);
ser.WriteStringItem(Hair);
ser.WriteStringItem(Skin);
ser.WriteStringItem(Uniform);
ser.WriteStringItem(Camo);
}
public void Read(Common.Serialization.Stream ser)
public void Read(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);
}
ser.TryReadString(out Head);
ser.TryReadString(out Chest);
ser.TryReadString(out Belt);
ser.TryReadString(out Backbag);
ser.TryReadString(out Eye);
ser.TryReadString(out Face);
ser.TryReadString(out Hair);
ser.TryReadString(out Skin);
ser.TryReadString(out Uniform);
ser.TryReadString(out Camo);
}
}

View File

@ -1,73 +1,76 @@
using System;
namespace BattleBitAPI.Common;
namespace BattleBitAPI.Common
public class Weapon : IEquatable<string>, IEquatable<Weapon>
{
public class Weapon : IEquatable<string>, IEquatable<Weapon>
{
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 string Name { get; }
public WeaponType WeaponType { get; private set; }
public bool Equals(string other)
{
if (other == null)
return false;
return this.Name.Equals(other);
return Name.Equals(other);
}
public bool Equals(Weapon other)
{
if (other == null)
return false;
return this.Name.Equals(other.Name);
return Name.Equals(other.Name);
}
public override string ToString()
{
return Name;
}
public static bool operator ==(string left, Weapon right)
{
bool leftNull = object.ReferenceEquals(left, null);
bool rightNull = object.ReferenceEquals(right, null);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = 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);
var leftNull = ReferenceEquals(left, null);
var rightNull = ReferenceEquals(right, null);
if (leftNull && rightNull)
return true;
if (leftNull || rightNull)
return false;
return right.Name.Equals(left);
}
}
}

View File

@ -1,120 +1,113 @@
using System.Reflection;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public static class Attachments
{
public static class Attachments
{
// ----- Private Variables -----
private static Dictionary<string, Attachment> mAttachments;
private static readonly Dictionary<string, Attachment> 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);
public static readonly Attachment Basic = new("Basic", AttachmentType.Barrel);
public static readonly Attachment Compensator = new("Compensator", AttachmentType.Barrel);
public static readonly Attachment Heavy = new("Heavy", AttachmentType.Barrel);
public static readonly Attachment LongBarrel = new("Long_Barrel", AttachmentType.Barrel);
public static readonly Attachment MuzzleBreak = new("Muzzle_Break", AttachmentType.Barrel);
public static readonly Attachment Ranger = new("Ranger", AttachmentType.Barrel);
public static readonly Attachment SuppressorLong = new("Suppressor_Long", AttachmentType.Barrel);
public static readonly Attachment SuppressorShort = new("Suppressor_Short", AttachmentType.Barrel);
public static readonly Attachment Tactical = new("Tactical", AttachmentType.Barrel);
public static readonly Attachment FlashHider = new("Flash_Hider", AttachmentType.Barrel);
public static readonly Attachment Osprey9 = new("Osprey_9", AttachmentType.Barrel);
public static readonly Attachment DGN308 = new("DGN-308", AttachmentType.Barrel);
public static readonly Attachment VAMB762 = new("VAMB-762", AttachmentType.Barrel);
public static readonly Attachment SDN6762 = new("SDN-6_762", AttachmentType.Barrel);
public static readonly Attachment NT4556 = new("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);
public static readonly Attachment Ironsight = new("Ironsight", AttachmentType.CantedSight);
public static readonly Attachment CantedRedDot = new("Canted_Red_Dot", AttachmentType.CantedSight);
public static readonly Attachment FYouCanted = new("FYou_Canted", AttachmentType.CantedSight);
public static readonly Attachment HoloDot = new("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);
public static readonly Attachment _6xScope = new("6x_Scope", AttachmentType.MainSight);
public static readonly Attachment _8xScope = new("8x_Scope", AttachmentType.MainSight);
public static readonly Attachment _15xScope = new("15x_Scope", AttachmentType.MainSight);
public static readonly Attachment _20xScope = new("20x_Scope", AttachmentType.MainSight);
public static readonly Attachment PTR40Hunter = new("PTR-40_Hunter", AttachmentType.MainSight);
public static readonly Attachment _1P78 = new("1P78", AttachmentType.MainSight);
public static readonly Attachment Acog = new("Acog", AttachmentType.MainSight);
public static readonly Attachment M125 = new("M_125", AttachmentType.MainSight);
public static readonly Attachment Prisma = new("Prisma", AttachmentType.MainSight);
public static readonly Attachment Slip = new("Slip", AttachmentType.MainSight);
public static readonly Attachment PistolDeltaSight = new("Pistol_Delta_Sight", AttachmentType.MainSight);
public static readonly Attachment PistolRedDot = new("Pistol_Red_Dot", AttachmentType.MainSight);
public static readonly Attachment AimComp = new("Aim_Comp", AttachmentType.MainSight);
public static readonly Attachment Holographic = new("Holographic", AttachmentType.MainSight);
public static readonly Attachment Kobra = new("Kobra", AttachmentType.MainSight);
public static readonly Attachment OKP7 = new("OKP7", AttachmentType.MainSight);
public static readonly Attachment PKAS = new("PK-AS", AttachmentType.MainSight);
public static readonly Attachment RedDot = new("Red_Dot", AttachmentType.MainSight);
public static readonly Attachment Reflex = new("Reflex", AttachmentType.MainSight);
public static readonly Attachment Strikefire = new("Strikefire", AttachmentType.MainSight);
public static readonly Attachment Razor = new("Razor", AttachmentType.MainSight);
public static readonly Attachment Flir = new("Flir", AttachmentType.MainSight);
public static readonly Attachment Echo = new("Echo", AttachmentType.MainSight);
public static readonly Attachment TRI4X32 = new("TRI4X32", AttachmentType.MainSight);
public static readonly Attachment FYouSight = new("FYou_Sight", AttachmentType.MainSight);
public static readonly Attachment HoloPK120 = new("Holo_PK-120", AttachmentType.MainSight);
public static readonly Attachment Pistol8xScope = new("Pistol_8x_Scope", AttachmentType.MainSight);
public static readonly Attachment BurrisAR332 = new("BurrisAR332", AttachmentType.MainSight);
public static readonly Attachment HS401G5 = new("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);
public static readonly Attachment DeltaSightTop = new("Delta_Sight_Top", AttachmentType.TopSight);
public static readonly Attachment RedDotTop = new("Red_Dot_Top", AttachmentType.TopSight);
public static readonly Attachment CRedDotTop = new("C_Red_Dot_Top", AttachmentType.TopSight);
public static readonly Attachment FYouTop = new("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);
public static readonly Attachment AngledGrip = new("Angled_Grip", AttachmentType.UnderRail);
public static readonly Attachment Bipod = new("Bipod", AttachmentType.UnderRail);
public static readonly Attachment VerticalGrip = new("Vertical_Grip", AttachmentType.UnderRail);
public static readonly Attachment StubbyGrip = new("Stubby_Grip", AttachmentType.UnderRail);
public static readonly Attachment StabilGrip = new("Stabil_Grip", AttachmentType.UnderRail);
public static readonly Attachment VerticalSkeletonGrip = new("Vertical_Skeleton_Grip", AttachmentType.UnderRail);
public static readonly Attachment FABDTFG = new("FAB-DTFG", AttachmentType.UnderRail);
public static readonly Attachment MagpulAngled = new("Magpul_Angled", AttachmentType.UnderRail);
public static readonly Attachment BCMGunFighter = new("BCM-Gun_Fighter", AttachmentType.UnderRail);
public static readonly Attachment ShiftShortAngledGrip = new("Shift_Short_Angled_Grip", AttachmentType.UnderRail);
public static readonly Attachment SE5Grip = new("SE-5_Grip", AttachmentType.UnderRail);
public static readonly Attachment RK6Foregrip = new("RK-6_Foregrip", AttachmentType.UnderRail);
public static readonly Attachment HeraCQRFront = new("HeraCQR_Front", AttachmentType.UnderRail);
public static readonly Attachment B25URK = new("B-25URK", AttachmentType.UnderRail);
public static readonly Attachment VTACUVGTacticalGrip = new("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);
public static readonly Attachment Flashlight = new("Flashlight", AttachmentType.SideRail);
public static readonly Attachment Rangefinder = new("Rangefinder", AttachmentType.SideRail);
public static readonly Attachment Redlaser = new("Redlaser", AttachmentType.SideRail);
public static readonly Attachment TacticalFlashlight = new("Tactical_Flashlight", AttachmentType.SideRail);
public static readonly Attachment Greenlaser = new("Greenlaser", AttachmentType.SideRail);
public static readonly Attachment Searchlight = new("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);
}
public static readonly Attachment BoltActionA = new("Bolt_Action_A", AttachmentType.Bolt);
public static readonly Attachment BoltActionB = new("Bolt_Action_B", AttachmentType.Bolt);
public static readonly Attachment BoltActionC = new("Bolt_Action_C", AttachmentType.Bolt);
public static readonly Attachment BoltActionD = new("Bolt_Action_D", AttachmentType.Bolt);
public static readonly Attachment BoltActionE = new("Bolt_Action_E", AttachmentType.Bolt);
// ----- Init -----
static Attachments()
{
var members = typeof(Attachments).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
var members = typeof(Attachments).GetMembers(BindingFlags.Public | BindingFlags.Static);
mAttachments = new Dictionary<string, Attachment>(members.Length);
foreach (var memberInfo in members)
if (memberInfo.MemberType == MemberTypes.Field)
{
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
{
var field = ((FieldInfo)memberInfo);
var field = (FieldInfo)memberInfo;
if (field.FieldType == typeof(Attachment))
{
var att = (Attachment)field.GetValue(null);
@ -122,6 +115,10 @@ namespace BattleBitAPI.Common
}
}
}
}
// ----- Public Calls -----
public static bool TryFind(string name, out Attachment item)
{
return mAttachments.TryGetValue(name, out item);
}
}

View File

@ -1,75 +1,67 @@
using Microsoft.VisualBasic;
using System.Reflection;
using System.Reflection;
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public static class Weapons
{
public static class Weapons
{
// ----- Private Variables -----
private static Dictionary<string, Weapon> mWeapons;
private static readonly Dictionary<string, Weapon> 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);
}
public static readonly Weapon ACR = new("ACR", WeaponType.Rifle);
public static readonly Weapon AK15 = new("AK15", WeaponType.Rifle);
public static readonly Weapon AK74 = new("AK74", WeaponType.Rifle);
public static readonly Weapon G36C = new("G36C", WeaponType.Rifle);
public static readonly Weapon HoneyBadger = new("Honey Badger", WeaponType.PersonalDefenseWeapon_PDW);
public static readonly Weapon KrissVector = new("Kriss Vector", WeaponType.SubmachineGun_SMG);
public static readonly Weapon L86A1 = new("L86A1", WeaponType.LightSupportGun_LSG);
public static readonly Weapon L96 = new("L96", WeaponType.SniperRifle);
public static readonly Weapon M4A1 = new("M4A1", WeaponType.Rifle);
public static readonly Weapon M9 = new("M9", WeaponType.Pistol);
public static readonly Weapon M110 = new("M110", WeaponType.DMR);
public static readonly Weapon M249 = new("M249", WeaponType.LightMachineGun_LMG);
public static readonly Weapon MK14EBR = new("MK14 EBR", WeaponType.DMR);
public static readonly Weapon MK20 = new("MK20", WeaponType.DMR);
public static readonly Weapon MP7 = new("MP7", WeaponType.SubmachineGun_SMG);
public static readonly Weapon PP2000 = new("PP2000", WeaponType.SubmachineGun_SMG);
public static readonly Weapon SCARH = new("SCAR-H", WeaponType.Rifle);
public static readonly Weapon SSG69 = new("SSG 69", WeaponType.SniperRifle);
public static readonly Weapon SV98 = new("SV-98", WeaponType.SniperRifle);
public static readonly Weapon UMP45 = new("UMP-45", WeaponType.SubmachineGun_SMG);
public static readonly Weapon Unica = new("Unica", WeaponType.HeavyPistol);
public static readonly Weapon USP = new("USP", WeaponType.Pistol);
public static readonly Weapon AsVal = new("As Val", WeaponType.Carbine);
public static readonly Weapon AUGA3 = new("AUG A3", WeaponType.Rifle);
public static readonly Weapon DesertEagle = new("Desert Eagle", WeaponType.HeavyPistol);
public static readonly Weapon FAL = new("FAL", WeaponType.Rifle);
public static readonly Weapon Glock18 = new("Glock 18", WeaponType.AutoPistol);
public static readonly Weapon M200 = new("M200", WeaponType.SniperRifle);
public static readonly Weapon MP443 = new("MP 443", WeaponType.Pistol);
public static readonly Weapon FAMAS = new("FAMAS", WeaponType.Rifle);
public static readonly Weapon MP5 = new("MP5", WeaponType.SubmachineGun_SMG);
public static readonly Weapon P90 = new("P90", WeaponType.PersonalDefenseWeapon_PDW);
public static readonly Weapon MSR = new("MSR", WeaponType.SniperRifle);
public static readonly Weapon PP19 = new("PP19", WeaponType.SubmachineGun_SMG);
public static readonly Weapon SVD = new("SVD", WeaponType.DMR);
public static readonly Weapon Rem700 = new("Rem700", WeaponType.SniperRifle);
public static readonly Weapon SG550 = new("SG550", WeaponType.Rifle);
public static readonly Weapon Groza = new("Groza", WeaponType.PersonalDefenseWeapon_PDW);
public static readonly Weapon HK419 = new("HK419", WeaponType.Rifle);
public static readonly Weapon ScorpionEVO = new("ScorpionEVO", WeaponType.Carbine);
public static readonly Weapon Rsh12 = new("Rsh12", WeaponType.HeavyPistol);
public static readonly Weapon MG36 = new("MG36", WeaponType.LightSupportGun_LSG);
public static readonly Weapon AK5C = new("AK5C", WeaponType.Rifle);
public static readonly Weapon Ultimax100 = new("Ultimax100", WeaponType.LightMachineGun_LMG);
// ----- Init -----
static Weapons()
{
var members = typeof(Weapons).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
var members = typeof(Weapons).GetMembers(BindingFlags.Public | BindingFlags.Static);
mWeapons = new Dictionary<string, Weapon>(members.Length);
foreach (var memberInfo in members)
if (memberInfo.MemberType == MemberTypes.Field)
{
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
{
var field = ((FieldInfo)memberInfo);
var field = (FieldInfo)memberInfo;
if (field.FieldType == typeof(Weapon))
{
var wep = (Weapon)field.GetValue(null);
@ -77,6 +69,10 @@ namespace BattleBitAPI.Common
}
}
}
}
// ----- Public Calls -----
public static bool TryFind(string name, out Weapon item)
{
return mWeapons.TryGetValue(name, out item);
}
}

View File

@ -1,13 +1,12 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum AttachmentType
{
public enum AttachmentType
{
MainSight,
TopSight,
CantedSight,
Barrel,
UnderRail,
SideRail,
Bolt,
}
Bolt
}

View File

@ -1,9 +1,8 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum ChatChannel
{
public enum ChatChannel
{
AllChat,
TeamChat,
SquadChat
}
}

View File

@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BattleBitAPI.Common;
namespace BattleBitAPI.Common
public enum ReasonOfDamage : byte
{
public enum ReasonOfDamage : byte
{
Server = 0,
Weapon = 1,
Bleeding = 2,
@ -22,6 +16,5 @@ namespace BattleBitAPI.Common
CountAsKill = 11,
Suicide = 12,
HelicopterCrash = 13,
BarbedWire = 14,
}
BarbedWire = 14
}

View File

@ -1,7 +1,11 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum GameRole
{
public enum GameRole
{
Assault = 0, Medic = 1, Support = 2, Engineer = 3, Recon = 4, Leader = 5
}
Assault = 0,
Medic = 1,
Support = 2,
Engineer = 3,
Recon = 4,
Leader = 5
}

View File

@ -1,10 +1,9 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum GameState : byte
{
public enum GameState : byte
{
WaitingForPlayers = 0,
CountingDown = 1,
Playing = 2,
EndingGame = 3
}
}

View File

@ -1,7 +1,8 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum LeaningSide
{
public enum LeaningSide
{
Left, None, Right
}
Left,
None,
Right
}

View File

@ -1,12 +1,11 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum LoadoutIndex : byte
{
public enum LoadoutIndex : byte
{
Primary = 0,
Secondary = 1,
FirstAid = 2,
LightGadget = 3,
HeavyGadget = 4,
Throwable = 5,
}
Throwable = 5
}

View File

@ -1,8 +1,7 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum MapDayNight : byte
{
public enum MapDayNight : byte
{
Day = 0,
Night = 1,
}
Night = 1
}

View File

@ -1,12 +1,11 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum MapSize : byte
{
public enum MapSize : byte
{
None = 0,
_8v8=8,
_8v8 = 8,
_16vs16 = 16,
_32vs32 = 32,
_64vs64 = 64,
_127vs127 = 90,
}
_127vs127 = 90
}

View File

@ -1,7 +1,7 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum PlayerBody : byte
{
public enum PlayerBody : byte
{
None = 0,
Head = 2,
Neck = 3,
@ -9,7 +9,5 @@
Arm = 5,
Leg = 6,
Foot = 7,
Chest = 10,
}
Chest = 10
}

View File

@ -1,7 +1,10 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum PlayerSpawningPosition : byte
{
public enum PlayerSpawningPosition : byte
{
SpawnAtPoint, SpawnAtRally, SpawnAtFriend, SpawnAtVehicle, Null
}
SpawnAtPoint,
SpawnAtRally,
SpawnAtFriend,
SpawnAtVehicle,
Null
}

View File

@ -1,7 +1,8 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum PlayerStand : byte
{
public enum PlayerStand : byte
{
Standing = 0, Crouching = 1, Proning = 2
}
Standing = 0,
Crouching = 1,
Proning = 2
}

View File

@ -1,7 +1,7 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum ReportReason
{
public enum ReportReason
{
Cheating_WallHack = 0,
Cheating_Aimbot = 1,
Cheating_Speedhack = 2,
@ -18,6 +18,5 @@
Griefing = 9,
Exploiting = 10,
OtherToxicBehaviour = 11,
UserProfileNamePicture = 12,
}
UserProfileNamePicture = 12
}

View File

@ -1,12 +1,11 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum Roles : ulong
{
public enum Roles : ulong
{
None = 0,
Admin = 1 << 0,
Moderator = 1 << 1,
Special = 1 << 2,
Vip = 1 << 3,
}
Vip = 1 << 3
}

View File

@ -1,7 +1,7 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum Squads
{
public enum Squads
{
NoSquad = 0,
Alpha = 1,
@ -68,5 +68,4 @@
Lincoln = 62,
Mary = 63,
Nora = 64
}
}

View File

@ -1,9 +1,8 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum Team : byte
{
public enum Team : byte
{
TeamA = 0,
TeamB = 1,
None = 2
}
}

View File

@ -1,7 +1,7 @@
namespace BattleBitAPI.Common
namespace BattleBitAPI.Common;
public enum WeaponType
{
public enum WeaponType : int
{
Rifle,
DMR,
SniperRifle,
@ -12,6 +12,5 @@
AutoPistol,
HeavyPistol,
Carbine,
PersonalDefenseWeapon_PDW,
}
PersonalDefenseWeapon_PDW
}

View File

@ -1,22 +1,24 @@
using System.Net;
using System.Net.Sockets;
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI.Common.Extentions
namespace BattleBitAPI.Common.Extentions;
public static class Extentions
{
public static class Extentions
{
public static long TickCount
{
get
{
#if NETCOREAPP
return System.Environment.TickCount64;
return Environment.TickCount64;
#else
return (long)Environment.TickCount;
#endif
}
}
public unsafe static uint ToUInt(this IPAddress address)
public static uint ToUInt(this IPAddress address)
{
#if NETCOREAPP
return BitConverter.ToUInt32(address.GetAddressBytes());
@ -27,13 +29,27 @@ namespace BattleBitAPI.Common.Extentions
public static void SafeClose(this TcpClient client)
{
try { client.Close(); } catch { }
try { client.Dispose(); } catch { }
}
public static async Task<int> Read(this NetworkStream networkStream, Serialization.Stream outputStream, int size, CancellationToken token = default)
try
{
int read = 0;
int readUntil = outputStream.WritePosition + size;
client.Close();
}
catch
{
}
try
{
client.Dispose();
}
catch
{
}
}
public static async Task<int> Read(this NetworkStream networkStream, Stream outputStream, int size, CancellationToken token = default)
{
var read = 0;
var readUntil = outputStream.WritePosition + size;
//Ensure we have space.
outputStream.EnsureWriteBufferSize(size);
@ -41,8 +57,8 @@ namespace BattleBitAPI.Common.Extentions
//Continue reading until we have the package.
while (outputStream.WritePosition < readUntil)
{
int sizeToRead = readUntil - outputStream.WritePosition;
int received = await networkStream.ReadAsync(outputStream.Buffer, outputStream.WritePosition, sizeToRead, token);
var sizeToRead = readUntil - outputStream.WritePosition;
var received = await networkStream.ReadAsync(outputStream.Buffer, outputStream.WritePosition, sizeToRead, token);
if (received <= 0)
throw new Exception("NetworkStream was closed.");
@ -52,11 +68,12 @@ namespace BattleBitAPI.Common.Extentions
return read;
}
public static async Task<bool> TryRead(this NetworkStream networkStream, Serialization.Stream outputStream, int size, CancellationToken token = default)
public static async Task<bool> TryRead(this NetworkStream networkStream, Stream outputStream, int size, CancellationToken token = default)
{
try
{
int readUntil = outputStream.WritePosition + size;
var readUntil = outputStream.WritePosition + size;
//Ensure we have space.
outputStream.EnsureWriteBufferSize(size);
@ -64,8 +81,8 @@ namespace BattleBitAPI.Common.Extentions
//Continue reading until we have the package.
while (outputStream.WritePosition < readUntil)
{
int sizeToRead = readUntil - outputStream.WritePosition;
int received = await networkStream.ReadAsync(outputStream.Buffer, outputStream.WritePosition, sizeToRead, token);
var sizeToRead = readUntil - outputStream.WritePosition;
var received = await networkStream.ReadAsync(outputStream.Buffer, outputStream.WritePosition, sizeToRead, token);
if (received <= 0)
throw new Exception("NetworkStream was closed.");
outputStream.WritePosition += received;
@ -78,5 +95,4 @@ namespace BattleBitAPI.Common.Extentions
return false;
}
}
}
}

View File

@ -1,8 +1,7 @@
namespace BattleBitAPI.Common.Serialization
namespace BattleBitAPI.Common.Serialization;
public interface IStreamSerializable
{
public interface IStreamSerializable
{
void Read(Stream ser);
void Write(Stream ser);
}
}

View File

@ -1,10 +1,11 @@
using BattleBitAPI.Common.Extentions;
using System.Net;
using System.Text;
using BattleBitAPI.Common.Extentions;
namespace BattleBitAPI.Common.Serialization
namespace BattleBitAPI.Common.Serialization;
public class Stream : IDisposable
{
public class Stream : IDisposable
{
public const int DefaultBufferSize = 1024 * 512;
#if BIGENDIAN
@ -20,18 +21,19 @@ namespace BattleBitAPI.Common.Serialization
public bool CanRead(int size)
{
int readableLenght = WritePosition - ReadPosition;
return (readableLenght >= size);
var readableLenght = WritePosition - ReadPosition;
return readableLenght >= size;
}
public void EnsureWriteBufferSize(int requiredSize)
{
int bufferLenght = Buffer.Length;
var bufferLenght = Buffer.Length;
int leftSpace = bufferLenght - WritePosition;
var leftSpace = bufferLenght - WritePosition;
if (leftSpace < requiredSize)
{
int newSize = bufferLenght + Math.Max(requiredSize, 1024);
System.Array.Resize(ref Buffer, newSize);
var newSize = bufferLenght + Math.Max(requiredSize, 1024);
Array.Resize(ref Buffer, newSize);
}
}
@ -42,207 +44,277 @@ namespace BattleBitAPI.Common.Serialization
Buffer[WritePosition] = value;
WritePosition += 1;
}
public void Write(bool value)
{
EnsureWriteBufferSize(1);
Buffer[WritePosition] = value ? (byte)1 : (byte)0;
WritePosition += 1;
}
public unsafe void Write(short value)
{
EnsureWriteBufferSize(2);
fixed (byte* ptr = &Buffer[WritePosition])
*((short*)ptr) = value;
{
*(short*)ptr = value;
}
WritePosition += 2;
}
public unsafe void Write(ushort value)
{
EnsureWriteBufferSize(2);
fixed (byte* ptr = &Buffer[WritePosition])
*((ushort*)ptr) = value;
{
*(ushort*)ptr = value;
}
WritePosition += 2;
}
public unsafe void Write(int value)
{
EnsureWriteBufferSize(4);
fixed (byte* ptr = &Buffer[WritePosition])
*((int*)ptr) = value;
{
*(int*)ptr = value;
}
WritePosition += 4;
}
public unsafe void Write(uint value)
{
EnsureWriteBufferSize(4);
fixed (byte* ptr = &Buffer[WritePosition])
*((uint*)ptr) = value;
{
*(uint*)ptr = value;
}
WritePosition += 4;
}
public unsafe void Write(long value)
{
EnsureWriteBufferSize(8);
fixed (byte* ptr = &Buffer[WritePosition])
*((long*)ptr) = value;
{
*(long*)ptr = value;
}
WritePosition += 8;
}
public unsafe void Write(ulong value)
{
EnsureWriteBufferSize(8);
fixed (byte* ptr = &Buffer[WritePosition])
*((ulong*)ptr) = value;
{
*(ulong*)ptr = value;
}
WritePosition += 8;
}
public unsafe void Write(decimal value)
{
EnsureWriteBufferSize(16);
fixed (byte* ptr = &Buffer[WritePosition])
*((decimal*)ptr) = value;
{
*(decimal*)ptr = value;
}
WritePosition += 16;
}
public unsafe void Write(double value)
{
EnsureWriteBufferSize(8);
fixed (byte* ptr = &Buffer[WritePosition])
*((double*)ptr) = value;
{
*(double*)ptr = value;
}
WritePosition += 8;
}
public unsafe void Write(float value)
{
int intValue = *((int*)&value);
var intValue = *(int*)&value;
EnsureWriteBufferSize(4);
fixed (byte* ptr = &Buffer[WritePosition])
*((int*)ptr) = intValue;
{
*(int*)ptr = intValue;
}
WritePosition += 4;
}
public unsafe void Write(string value)
{
int charCount = value.Length;
var charCount = value.Length;
fixed (char* strPtr = value)
{
int size = System.Text.Encoding.UTF8.GetByteCount(strPtr, charCount);
var size = Encoding.UTF8.GetByteCount(strPtr, charCount);
EnsureWriteBufferSize(size + 2);
fixed (byte* buffPtr = &Buffer[WritePosition])
{
*((ushort*)buffPtr) = (ushort)size;
System.Text.Encoding.UTF8.GetBytes(strPtr, charCount, buffPtr + 2, size);
*(ushort*)buffPtr = (ushort)size;
Encoding.UTF8.GetBytes(strPtr, charCount, buffPtr + 2, size);
}
WritePosition += size + 2;
}
}
public unsafe void Write(DateTime value)
{
var utc = value.ToUniversalTime();
EnsureWriteBufferSize(8);
fixed (byte* ptr = &Buffer[WritePosition])
*((long*)ptr) = utc.Ticks;
{
*(long*)ptr = utc.Ticks;
}
WritePosition += 8;
}
public unsafe void Write(IPAddress value)
public void Write(IPAddress value)
{
uint ip = value.ToUInt();
var ip = value.ToUInt();
Write(ip);
}
public unsafe void Write(IPEndPoint value)
public void Write(IPEndPoint value)
{
uint ip = value.Address.ToUInt();
var ip = value.Address.ToUInt();
Write(ip);
Write((ushort)value.Port);
}
public unsafe void WriteRaw(string value)
{
int charCount = value.Length;
var charCount = value.Length;
fixed (char* strPtr = value)
{
int size = System.Text.Encoding.UTF8.GetByteCount(strPtr, charCount);
var size = Encoding.UTF8.GetByteCount(strPtr, charCount);
EnsureWriteBufferSize(size);
fixed (byte* buffPtr = &Buffer[WritePosition])
System.Text.Encoding.UTF8.GetBytes(strPtr, charCount, buffPtr, size);
{
Encoding.UTF8.GetBytes(strPtr, charCount, buffPtr, size);
}
WritePosition += size;
}
}
public unsafe void Write<T>(T value) where T : IStreamSerializable
public void Write<T>(T value) where T : IStreamSerializable
{
value.Write(this);
}
public void Write(byte[] source, int sourceIndex, int length)
{
if (length == 0)
return;
EnsureWriteBufferSize(length);
System.Array.Copy(source, sourceIndex, this.Buffer, this.WritePosition, length);
this.WritePosition += length;
Array.Copy(source, sourceIndex, Buffer, WritePosition, length);
WritePosition += length;
}
public void Write(Stream source)
{
EnsureWriteBufferSize(source.WritePosition);
System.Array.Copy(source.Buffer, 0, this.Buffer, this.WritePosition, source.WritePosition);
this.WritePosition += source.WritePosition;
Array.Copy(source.Buffer, 0, Buffer, WritePosition, source.WritePosition);
WritePosition += source.WritePosition;
}
public void WriteStringItem(string value)
{
if (value == null)
this.Write("none");
Write("none");
else
this.Write(value);
Write(value);
}
public unsafe void WriteAt(byte value, int position)
public void WriteAt(byte value, int position)
{
Buffer[position] = value;
}
public unsafe void WriteAt(short value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((short*)ptr) = value;
{
*(short*)ptr = value;
}
}
public unsafe void WriteAt(ushort value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((ushort*)ptr) = value;
{
*(ushort*)ptr = value;
}
}
public unsafe void WriteAt(int value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((int*)ptr) = value;
{
*(int*)ptr = value;
}
}
public unsafe void WriteAt(uint value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((uint*)ptr) = value;
{
*(uint*)ptr = value;
}
}
public unsafe void WriteAt(long value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((long*)ptr) = value;
{
*(long*)ptr = value;
}
}
public unsafe void WriteAt(ulong value, int position)
{
fixed (byte* ptr = &Buffer[position])
*((ulong*)ptr) = value;
{
*(ulong*)ptr = value;
}
}
// -------- Read ------
public byte ReadInt8()
{
var value = Buffer[ReadPosition];
ReadPosition++;
return value;
}
public bool ReadBool()
{
var value = Buffer[ReadPosition];
ReadPosition++;
return value == 1;
}
public unsafe short ReadInt16()
{
short value = 0;
@ -251,24 +323,21 @@ namespace BattleBitAPI.Common.Serialization
{
if (ReadPosition % 2 == 0)
{
value = *((short*)pbyte);
value = *(short*)pbyte;
}
else
{
if (IsLittleEndian)
{
value = (short)((*pbyte) | (*(pbyte + 1) << 8));
}
value = (short)(*pbyte | (*(pbyte + 1) << 8));
else
{
value = (short)((*pbyte << 8) | (*(pbyte + 1)));
}
value = (short)((*pbyte << 8) | *(pbyte + 1));
}
}
ReadPosition += 2;
return value;
}
public unsafe ushort ReadUInt16()
{
ushort value = 0;
@ -277,49 +346,44 @@ namespace BattleBitAPI.Common.Serialization
{
if (ReadPosition % 2 == 0)
{
value = *((ushort*)pbyte);
value = *(ushort*)pbyte;
}
else
{
if (IsLittleEndian)
{
value = (ushort)((*pbyte) | (*(pbyte + 1) << 8));
}
value = (ushort)(*pbyte | (*(pbyte + 1) << 8));
else
{
value = (ushort)((*pbyte << 8) | (*(pbyte + 1)));
}
value = (ushort)((*pbyte << 8) | *(pbyte + 1));
}
}
ReadPosition += 2;
return value;
}
public unsafe int ReadInt32()
{
int value = 0;
var value = 0;
fixed (byte* pbyte = &Buffer[ReadPosition])
{
if (ReadPosition % 4 == 0)
{
value = *((int*)pbyte);
value = *(int*)pbyte;
}
else
{
if (IsLittleEndian)
{
value = (int)((*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24));
}
value = *pbyte | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
else
{
value = (int)((*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3)));
}
value = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | *(pbyte + 3);
}
}
ReadPosition += 4;
return value;
}
public unsafe uint ReadUInt32()
{
uint value = 0;
@ -327,24 +391,22 @@ namespace BattleBitAPI.Common.Serialization
{
if (ReadPosition % 4 == 0)
{
value = *((uint*)pbyte);
value = *(uint*)pbyte;
}
else
{
if (IsLittleEndian)
{
value = (uint)((*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24));
}
value = (uint)(*pbyte | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24));
else
{
value = (uint)((*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3)));
}
value = (uint)((*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | *(pbyte + 3));
}
}
ReadPosition += 4;
return value;
}
public unsafe long ReadInt64()
{
long value = 0;
@ -352,28 +414,30 @@ namespace BattleBitAPI.Common.Serialization
{
if (ReadPosition % 8 == 0)
{
value = *((long*)pbyte);
value = *(long*)pbyte;
}
else
{
if (IsLittleEndian)
{
int i1 = (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
int i2 = (*(pbyte + 4)) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
var i1 = *pbyte | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
var i2 = *(pbyte + 4) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
value = (uint)i1 | ((long)i2 << 32);
}
else
{
int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
int i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | (*(pbyte + 7));
var i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | *(pbyte + 3);
var i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | *(pbyte + 7);
value = (uint)i2 | ((long)i1 << 32);
}
}
}
ReadPosition += 8;
return value;
}
public unsafe ulong ReadUInt64()
{
ulong value = 0;
@ -381,80 +445,82 @@ namespace BattleBitAPI.Common.Serialization
{
if (ReadPosition % 8 == 0)
{
value = *((ulong*)pbyte);
value = *(ulong*)pbyte;
}
else
{
if (IsLittleEndian)
{
int i1 = (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
int i2 = (*(pbyte + 4)) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
var i1 = *pbyte | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
var i2 = *(pbyte + 4) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
value = (uint)i1 | ((ulong)i2 << 32);
}
else
{
int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
int i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | (*(pbyte + 7));
var i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | *(pbyte + 3);
var i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | *(pbyte + 7);
value = (uint)i2 | ((ulong)i1 << 32);
}
}
}
ReadPosition += 8;
return value;
}
public unsafe decimal ReadInt128()
{
decimal value = 0;
fixed (byte* ptr = &Buffer[ReadPosition])
{
value = *((decimal*)ptr);
value = *(decimal*)ptr;
}
ReadPosition += 16;
return value;
}
public unsafe double ReadDouble()
{
double value = 0;
fixed (byte* ptr = &Buffer[ReadPosition])
{
value = *((double*)ptr);
value = *(double*)ptr;
}
ReadPosition += 8;
return value;
}
public unsafe float ReadFloat()
{
int value = 0;
var value = 0;
fixed (byte* pbyte = &Buffer[ReadPosition])
{
if (ReadPosition % 4 == 0)
{
value = *((int*)pbyte);
value = *(int*)pbyte;
}
else
{
if (IsLittleEndian)
{
value = (int)((*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24));
}
value = *pbyte | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
else
{
value = (int)((*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3)));
}
value = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | *(pbyte + 3);
}
}
ReadPosition += 4;
return *(float*)&value;
}
public DateTime ReadDateTime()
{
long value = ReadInt64();
var value = ReadInt64();
try
{
return new DateTime(value, DateTimeKind.Utc);
@ -464,31 +530,37 @@ namespace BattleBitAPI.Common.Serialization
return DateTime.MinValue;
}
}
public bool TryReadDateTime(out DateTime time)
{
long value = ReadInt64();
var value = ReadInt64();
try
{
time = new DateTime(value, DateTimeKind.Utc);
return true;
}
catch { }
catch
{
}
time = default;
return false;
}
public unsafe IPAddress ReadIPAddress()
public IPAddress ReadIPAddress()
{
uint ip = ReadUInt32();
var ip = ReadUInt32();
return new IPAddress(ip);
}
public unsafe IPEndPoint ReadIPEndPoint()
public IPEndPoint ReadIPEndPoint()
{
uint ip = ReadUInt32();
ushort port = ReadUInt16();
var ip = ReadUInt32();
var port = ReadUInt16();
return new IPEndPoint(ip, port);
}
public T Read<T>() where T : IStreamSerializable
{
T value = default;
@ -501,23 +573,27 @@ namespace BattleBitAPI.Common.Serialization
if (lenght == 0)
return new byte[0];
byte[] newBuffer = new byte[lenght];
System.Array.Copy(this.Buffer, this.ReadPosition, newBuffer, 0, lenght);
this.ReadPosition += lenght;
var newBuffer = new byte[lenght];
Array.Copy(Buffer, ReadPosition, newBuffer, 0, lenght);
ReadPosition += lenght;
return newBuffer;
}
public void ReadTo(byte[] buffer, int offset, int size)
{
System.Array.Copy(this.Buffer, this.ReadPosition, buffer, offset, size);
this.ReadPosition += size;
Array.Copy(Buffer, ReadPosition, buffer, offset, size);
ReadPosition += size;
}
public unsafe string ReadString(int size)
{
string str;
#if NETCOREAPP
fixed (byte* ptr = &Buffer[ReadPosition])
str = System.Text.Encoding.UTF8.GetString(ptr, size);
{
str = Encoding.UTF8.GetString(ptr, size);
}
#else
str = System.Text.Encoding.UTF8.GetString(Buffer, ReadPosition, size);
#endif
@ -525,6 +601,7 @@ namespace BattleBitAPI.Common.Serialization
return str;
}
public unsafe bool TryReadString(out string str)
{
if (!CanRead(2))
@ -534,9 +611,12 @@ namespace BattleBitAPI.Common.Serialization
}
int size = 0;
var size = 0;
fixed (byte* ptr = &Buffer[ReadPosition])
size = *((ushort*)ptr);
{
size = *(ushort*)ptr;
}
ReadPosition += 2;
if (!CanRead(size))
@ -547,7 +627,9 @@ namespace BattleBitAPI.Common.Serialization
#if NETCOREAPP
fixed (byte* ptr = &Buffer[ReadPosition])
str = System.Text.Encoding.UTF8.GetString(ptr, size);
{
str = Encoding.UTF8.GetString(ptr, size);
}
#else
str = System.Text.Encoding.UTF8.GetString(Buffer, ReadPosition, size);
#endif
@ -556,6 +638,7 @@ namespace BattleBitAPI.Common.Serialization
return true;
}
public unsafe bool TryReadString(out string str, int maximumSize = ushort.MaxValue)
{
if (!CanRead(2))
@ -565,9 +648,12 @@ namespace BattleBitAPI.Common.Serialization
}
int size = 0;
var size = 0;
fixed (byte* ptr = &Buffer[ReadPosition])
size = *((ushort*)ptr);
{
size = *(ushort*)ptr;
}
ReadPosition += 2;
if (size > maximumSize)
@ -584,7 +670,9 @@ namespace BattleBitAPI.Common.Serialization
#if NETCOREAPP
fixed (byte* ptr = &Buffer[ReadPosition])
str = System.Text.Encoding.UTF8.GetString(ptr, size);
{
str = Encoding.UTF8.GetString(ptr, size);
}
#else
str = System.Text.Encoding.UTF8.GetString(Buffer, ReadPosition, size);
#endif
@ -593,14 +681,18 @@ namespace BattleBitAPI.Common.Serialization
return true;
}
public unsafe bool TrySkipString()
{
if (!CanRead(2))
return false;
int size = 0;
var size = 0;
fixed (byte* ptr = &Buffer[ReadPosition])
size = *((ushort*)ptr);
{
size = *(ushort*)ptr;
}
ReadPosition += 2;
if (!CanRead(size))
@ -610,15 +702,14 @@ namespace BattleBitAPI.Common.Serialization
return true;
}
public int NumberOfBytesReadable
{
get => WritePosition - ReadPosition;
}
public int NumberOfBytesReadable => WritePosition - ReadPosition;
public void SkipWriting(int size)
{
EnsureWriteBufferSize(size);
WritePosition += size;
}
public void SkipReading(int size)
{
ReadPosition += size;
@ -627,15 +718,17 @@ namespace BattleBitAPI.Common.Serialization
// -------- Finalizing ------
public byte[] AsByteArrayData()
{
var data = new byte[this.WritePosition];
System.Array.Copy(this.Buffer, 0, data, 0, this.WritePosition);
var data = new byte[WritePosition];
Array.Copy(Buffer, 0, data, 0, WritePosition);
return data;
}
public void Reset()
{
this.ReadPosition = 0;
this.WritePosition = 0;
ReadPosition = 0;
WritePosition = 0;
}
public void Dispose()
{
if (InPool)
@ -643,11 +736,14 @@ namespace BattleBitAPI.Common.Serialization
InPool = true;
lock (mPool)
{
mPool.Enqueue(this);
}
}
// ------- Pool -----
private static Queue<Stream> mPool = new Queue<Stream>(1024 * 256);
private static readonly Queue<Stream> mPool = new(1024 * 256);
public static Stream Get()
{
lock (mPool)
@ -663,13 +759,12 @@ namespace BattleBitAPI.Common.Serialization
}
}
return new Stream()
return new Stream
{
Buffer = new byte[DefaultBufferSize],
InPool = false,
ReadPosition = 0,
WritePosition = 0,
WritePosition = 0
};
}
}
}

View File

@ -1,21 +1,25 @@
using System;
using System.Collections.Generic;
namespace BattleBitAPI.Common.Threading;
namespace BattleBitAPI.Common.Threading
public class ThreadSafe<T>
{
public class ThreadSafe<T>
{
private System.Threading.ReaderWriterLockSlim mLock;
private readonly ReaderWriterLockSlim mLock;
public T Value;
public ThreadSafe(T value)
{
this.Value = value;
this.mLock = new System.Threading.ReaderWriterLockSlim(System.Threading.LockRecursionPolicy.SupportsRecursion);
Value = value;
mLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
}
public SafeWriteHandle GetWriteHandle() => new SafeWriteHandle(this.mLock);
public SafeReadHandle GetReadHandle() => new SafeReadHandle(this.mLock);
public SafeWriteHandle GetWriteHandle()
{
return new SafeWriteHandle(mLock);
}
public SafeReadHandle GetReadHandle()
{
return new SafeReadHandle(mLock);
}
/// <summary>
/// Swaps current value with new value and returns old one.
@ -24,23 +28,26 @@ namespace BattleBitAPI.Common.Threading
/// <returns>Old value</returns>
public T SwapValue(T newValue)
{
using (new SafeWriteHandle(this.mLock))
using (new SafeWriteHandle(mLock))
{
var oldValue = this.Value;
this.Value = newValue;
var oldValue = Value;
Value = newValue;
return oldValue;
}
}
}
public class SafeWriteHandle : System.IDisposable
{
private System.Threading.ReaderWriterLockSlim mLock;
}
public class SafeWriteHandle : IDisposable
{
private bool mDisposed;
public SafeWriteHandle(System.Threading.ReaderWriterLockSlim mLock)
private readonly ReaderWriterLockSlim mLock;
public SafeWriteHandle(ReaderWriterLockSlim mLock)
{
this.mLock = mLock;
mLock.EnterWriteLock();
}
public void Dispose()
{
if (mDisposed)
@ -48,16 +55,19 @@ namespace BattleBitAPI.Common.Threading
mDisposed = true;
mLock.ExitWriteLock();
}
}
public class SafeReadHandle : System.IDisposable
{
private System.Threading.ReaderWriterLockSlim mLock;
}
public class SafeReadHandle : IDisposable
{
private bool mDisposed;
public SafeReadHandle(System.Threading.ReaderWriterLockSlim mLock)
private readonly ReaderWriterLockSlim mLock;
public SafeReadHandle(ReaderWriterLockSlim mLock)
{
this.mLock = mLock;
mLock.EnterReadLock();
}
public void Dispose()
{
if (mDisposed)
@ -66,5 +76,4 @@ namespace BattleBitAPI.Common.Threading
mLock.ExitReadLock();
}
}
}

View File

@ -1,42 +0,0 @@
namespace BattleBitAPI.Networking
{
public enum NetworkCommuncation : byte
{
None = 0,
Hail = 1,
Accepted = 2,
Denied = 3,
ExecuteCommand = 10,
SendPlayerStats = 11,
SpawnPlayer = 12,
SetNewRoomSettings = 13,
RespondPlayerMessage = 14,
SetNewRoundState = 15,
SetPlayerWeapon = 16,
SetPlayerGadget = 17,
PlayerConnected = 50,
PlayerDisconnected = 51,
OnPlayerTypedMessage = 52,
OnAPlayerDownedAnotherPlayer = 53,
OnPlayerJoining = 54,
SavePlayerStats = 55,
OnPlayerAskingToChangeRole = 56,
OnPlayerChangedRole = 57,
OnPlayerJoinedASquad = 58,
OnPlayerLeftSquad = 59,
OnPlayerChangedTeam = 60,
OnPlayerRequestingToSpawn = 61,
OnPlayerReport = 62,
OnPlayerSpawn = 63,
OnPlayerDie = 64,
NotifyNewMapRotation = 65,
NotifyNewGamemodeRotation = 66,
NotifyNewRoundState = 67,
OnPlayerAskingToChangeTeam = 68,
GameTick = 69,
OnPlayerGivenUp = 70,
OnPlayerRevivedAnother = 71,
}
}

View File

@ -0,0 +1,41 @@
namespace BattleBitAPI.Networking;
public enum NetworkCommunication : byte
{
None = 0,
Hail = 1,
Accepted = 2,
Denied = 3,
ExecuteCommand = 10,
SendPlayerStats = 11,
SpawnPlayer = 12,
SetNewRoomSettings = 13,
RespondPlayerMessage = 14,
SetNewRoundState = 15,
SetPlayerWeapon = 16,
SetPlayerGadget = 17,
PlayerConnected = 50,
PlayerDisconnected = 51,
OnPlayerTypedMessage = 52,
OnAPlayerDownedAnotherPlayer = 53,
OnPlayerJoining = 54,
SavePlayerStats = 55,
OnPlayerAskingToChangeRole = 56,
OnPlayerChangedRole = 57,
OnPlayerJoinedASquad = 58,
OnPlayerLeftSquad = 59,
OnPlayerChangedTeam = 60,
OnPlayerRequestingToSpawn = 61,
OnPlayerReport = 62,
OnPlayerSpawn = 63,
OnPlayerDie = 64,
NotifyNewMapRotation = 65,
NotifyNewGamemodeRotation = 66,
NotifyNewRoundState = 67,
OnPlayerAskingToChangeTeam = 68,
GameTick = 69,
OnPlayerGivenUp = 70,
OnPlayerRevivedAnother = 71
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,9 @@
using BattleBitAPI.Common;
using CommunityServerAPI.BattleBitAPI.Server;
namespace BattleBitAPI.Server;
namespace BattleBitAPI.Server
public class GamemodeRotation<TPlayer> where TPlayer : Player<TPlayer>
{
public class GamemodeRotation<TPlayer> where TPlayer : Player<TPlayer>
{
private GameServer<TPlayer>.Internal mResources;
private readonly GameServer<TPlayer>.Internal mResources;
public GamemodeRotation(GameServer<TPlayer>.Internal resources)
{
mResources = resources;
@ -14,29 +12,43 @@ namespace BattleBitAPI.Server
public IEnumerable<string> GetGamemodeRotation()
{
lock (mResources._GamemodeRotation)
{
return new List<string>(mResources._GamemodeRotation);
}
}
public bool InRotation(string gamemode)
{
lock (mResources._GamemodeRotation)
{
return mResources._GamemodeRotation.Contains(gamemode);
}
}
public bool RemoveFromRotation(string gamemode)
{
lock (mResources._GamemodeRotation)
{
if (!mResources._GamemodeRotation.Remove(gamemode))
return false;
}
mResources.IsDirtyGamemodeRotation = true;
return true;
}
public bool AddToRotation(string gamemode)
{
lock (mResources._GamemodeRotation)
{
if (!mResources._GamemodeRotation.Add(gamemode))
return false;
}
mResources.IsDirtyGamemodeRotation = true;
return true;
}
public void SetRotation(params string[] gamemodes)
{
lock (mResources._GamemodeRotation)
@ -45,8 +57,10 @@ namespace BattleBitAPI.Server
foreach (var item in gamemodes)
mResources._GamemodeRotation.Add(item);
}
mResources.IsDirtyGamemodeRotation = true;
}
public void ClearRotation()
{
lock (mResources._GamemodeRotation)
@ -56,11 +70,11 @@ namespace BattleBitAPI.Server
mResources._GamemodeRotation.Clear();
}
mResources.IsDirtyGamemodeRotation = true;
}
public void Reset()
{
}
}
}

View File

@ -1,10 +1,9 @@
using CommunityServerAPI.BattleBitAPI.Server;
namespace BattleBitAPI.Server;
namespace BattleBitAPI.Server
public class MapRotation<TPlayer> where TPlayer : Player<TPlayer>
{
public class MapRotation<TPlayer> where TPlayer : Player<TPlayer>
{
private GameServer<TPlayer>.Internal mResources;
private readonly GameServer<TPlayer>.Internal mResources;
public MapRotation(GameServer<TPlayer>.Internal resources)
{
mResources = resources;
@ -13,35 +12,49 @@ namespace BattleBitAPI.Server
public IEnumerable<string> GetMapRotation()
{
lock (mResources._MapRotation)
{
return new List<string>(mResources._MapRotation);
}
}
public bool InRotation(string map)
{
map = map.ToUpperInvariant();
lock (mResources._MapRotation)
{
return mResources._MapRotation.Contains(map);
}
}
public bool RemoveFromRotation(string map)
{
map = map.ToUpperInvariant();
lock (mResources._MapRotation)
{
if (!mResources._MapRotation.Remove(map))
return false;
}
mResources.IsDirtyMapRotation = true;
return true;
}
public bool AddToRotation(string map)
{
map = map.ToUpperInvariant();
lock (mResources._MapRotation)
{
if (!mResources._MapRotation.Add(map))
return false;
}
mResources.IsDirtyMapRotation = true;
return true;
}
public void SetRotation(params string[] maps)
{
lock (mResources._MapRotation)
@ -50,8 +63,10 @@ namespace BattleBitAPI.Server
foreach (var item in maps)
mResources._MapRotation.Add(item);
}
mResources.IsDirtyMapRotation = true;
}
public void ClearRotation()
{
lock (mResources._MapRotation)
@ -61,11 +76,11 @@ namespace BattleBitAPI.Server
mResources._MapRotation.Clear();
}
mResources.IsDirtyMapRotation = true;
}
public void Reset()
{
}
}
}

View File

@ -1,8 +1,9 @@
namespace BattleBitAPI.Server
namespace BattleBitAPI.Server;
public class PlayerModifications<TPlayer> where TPlayer : Player<TPlayer>
{
public class PlayerModifications<TPlayer> where TPlayer : Player<TPlayer>
{
private Player<TPlayer>.Internal @internal;
public PlayerModifications(Player<TPlayer>.Internal @internal)
{
this.@internal = @internal;
@ -24,5 +25,4 @@
public bool IsVoiceChatMuted { get; set; }
public float RespawnTime { get; set; }
public bool CanRespawn { get; set; }
}
}

View File

@ -1,69 +1,69 @@
using BattleBitAPI.Common;
using CommunityServerAPI.BattleBitAPI.Server;
namespace BattleBitAPI.Server
namespace BattleBitAPI.Server;
public class RoundSettings<TPlayer> where TPlayer : Player<TPlayer>
{
public class RoundSettings<TPlayer> where TPlayer : Player<TPlayer>
{
private GameServer<TPlayer>.Internal mResources;
private readonly GameServer<TPlayer>.Internal mResources;
public RoundSettings(GameServer<TPlayer>.Internal resources)
{
mResources = resources;
}
public GameState State
{
get => this.mResources._RoundSettings.State;
}
public GameState State => mResources._RoundSettings.State;
public double TeamATickets
{
get => this.mResources._RoundSettings.TeamATickets;
get => mResources._RoundSettings.TeamATickets;
set
{
this.mResources._RoundSettings.TeamATickets = value;
this.mResources.IsDirtyRoundSettings = true;
mResources._RoundSettings.TeamATickets = value;
mResources.IsDirtyRoundSettings = true;
}
}
public double TeamBTickets
{
get => this.mResources._RoundSettings.TeamBTickets;
get => mResources._RoundSettings.TeamBTickets;
set
{
this.mResources._RoundSettings.TeamBTickets = value;
this.mResources.IsDirtyRoundSettings = true;
mResources._RoundSettings.TeamBTickets = value;
mResources.IsDirtyRoundSettings = true;
}
}
public double MaxTickets
{
get => this.mResources._RoundSettings.MaxTickets;
get => mResources._RoundSettings.MaxTickets;
set
{
this.mResources._RoundSettings.MaxTickets = value;
this.mResources.IsDirtyRoundSettings = true;
mResources._RoundSettings.MaxTickets = value;
mResources.IsDirtyRoundSettings = true;
}
}
public int PlayersToStart
{
get => this.mResources._RoundSettings.PlayersToStart;
get => mResources._RoundSettings.PlayersToStart;
set
{
this.mResources._RoundSettings.PlayersToStart = value;
this.mResources.IsDirtyRoundSettings = true;
mResources._RoundSettings.PlayersToStart = value;
mResources.IsDirtyRoundSettings = true;
}
}
public int SecondsLeft
{
get => this.mResources._RoundSettings.SecondsLeft;
get => mResources._RoundSettings.SecondsLeft;
set
{
this.mResources._RoundSettings.SecondsLeft = value;
this.mResources.IsDirtyRoundSettings = true;
mResources._RoundSettings.SecondsLeft = value;
mResources.IsDirtyRoundSettings = true;
}
}
public void Reset()
{
}
}
}

View File

@ -1,10 +1,9 @@
using CommunityServerAPI.BattleBitAPI.Server;
namespace BattleBitAPI.Server;
namespace BattleBitAPI.Server
public class ServerSettings<TPlayer> where TPlayer : Player<TPlayer>
{
public class ServerSettings<TPlayer> where TPlayer : Player<TPlayer>
{
private GameServer<TPlayer>.Internal mResources;
private readonly GameServer<TPlayer>.Internal mResources;
public ServerSettings(GameServer<TPlayer>.Internal resources)
{
mResources = resources;
@ -19,6 +18,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool BleedingEnabled
{
get => mResources._RoomSettings.BleedingEnabled;
@ -28,6 +28,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool StamineEnabled
{
get => mResources._RoomSettings.StaminaEnabled;
@ -37,6 +38,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool FriendlyFireEnabled
{
get => mResources._RoomSettings.FriendlyFireEnabled;
@ -46,6 +48,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool OnlyWinnerTeamCanVote
{
get => mResources._RoomSettings.OnlyWinnerTeamCanVote;
@ -55,6 +58,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool HitMarkersEnabled
{
get => mResources._RoomSettings.HitMarkersEnabled;
@ -64,6 +68,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool PointLogEnabled
{
get => mResources._RoomSettings.PointLogEnabled;
@ -73,6 +78,7 @@ namespace BattleBitAPI.Server
mResources.IsDirtyRoomSettings = true;
}
}
public bool SpectatorEnabled
{
get => mResources._RoomSettings.SpectatorEnabled;
@ -85,7 +91,5 @@ namespace BattleBitAPI.Server
public void Reset()
{
}
}
}

View File

@ -1,12 +1,13 @@
using BattleBitAPI.Common;
using BattleBitAPI.Server;
using System.Net;
using System.Net;
using System.Numerics;
using BattleBitAPI.Common;
using BattleBitAPI.Server;
using Stream = BattleBitAPI.Common.Serialization.Stream;
namespace BattleBitAPI
namespace BattleBitAPI;
public class Player<TPlayer> where TPlayer : Player<TPlayer>
{
public class Player<TPlayer> where TPlayer : Player<TPlayer>
{
private Internal mInternal;
// ---- Variables ----
@ -14,6 +15,7 @@ namespace BattleBitAPI
public string Name => mInternal.Name;
public IPAddress IP => mInternal.IP;
public GameServer<TPlayer> GameServer => mInternal.GameServer;
public GameRole Role
{
get => mInternal.Role;
@ -24,6 +26,7 @@ namespace BattleBitAPI
SetNewRole(value);
}
}
public Team Team
{
get => mInternal.Team;
@ -33,6 +36,7 @@ namespace BattleBitAPI
ChangeTeam(value);
}
}
public Squads Squad
{
get => mInternal.Squad;
@ -46,6 +50,7 @@ namespace BattleBitAPI
JoinSquad(value);
}
}
public bool InSquad => mInternal.Squad != Squads.NoSquad;
public int PingMs => mInternal.PingMs;
@ -60,6 +65,7 @@ namespace BattleBitAPI
get => mInternal.Position;
set => Teleport(value);
}
public PlayerStand StandingState => mInternal.Standing;
public LeaningSide LeaningState => mInternal.Leaning;
public LoadoutIndex CurrentLoadoutIndex => mInternal.CurrentLoadoutIndex;
@ -72,56 +78,54 @@ namespace BattleBitAPI
// ---- Events ----
public virtual void OnCreated()
{
}
public virtual async Task OnConnected()
{
}
public virtual async Task OnSpawned()
{
}
public virtual async Task OnDowned()
{
}
public virtual async Task OnGivenUp()
{
}
public virtual async Task OnRevivedByAnotherPlayer()
{
}
public virtual async Task OnRevivedAnotherPlayer()
{
}
public virtual async Task OnDied()
{
}
public virtual async Task OnChangedTeam()
{
}
public virtual async Task OnChangedRole(GameRole newRole)
{
}
public virtual async Task OnJoinedSquad(Squads newSquad)
{
}
public virtual async Task OnLeftSquad(Squads oldSquad)
{
}
public virtual async Task OnDisconnected()
{
}
// ---- Functions ----
@ -129,110 +133,136 @@ namespace BattleBitAPI
{
GameServer.Kick(this, reason);
}
public void Kill()
{
GameServer.Kill(this);
}
public void ChangeTeam()
{
GameServer.ChangeTeam(this);
}
public void ChangeTeam(Team team)
{
GameServer.ChangeTeam(this, team);
}
public void KickFromSquad()
{
GameServer.KickFromSquad(this);
}
public void JoinSquad(Squads targetSquad)
{
GameServer.JoinSquad(this, targetSquad);
}
public void DisbandTheSquad()
{
GameServer.DisbandPlayerCurrentSquad(this);
}
public void PromoteToSquadLeader()
{
GameServer.PromoteSquadLeader(this);
}
public void WarnPlayer(string msg)
{
GameServer.WarnPlayer(this, msg);
}
public void Message(string msg)
{
GameServer.MessageToPlayer(this, msg);
}
public void Message(string msg, float fadeoutTime)
{
GameServer.MessageToPlayer(this, msg, fadeoutTime);
}
public void SetNewRole(GameRole role)
{
GameServer.SetRoleTo(this, role);
}
public void Teleport(Vector3 target)
{
}
public void SpawnPlayer(PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection)
{
GameServer.SpawnPlayer(this, loadout, wearings, position, lookDirection, stand, spawnProtection);
}
public void SetHP(float newHP)
{
GameServer.SetHP(this, newHP);
}
public void GiveDamage(float damage)
{
GameServer.GiveDamage(this, damage);
}
public void Heal(float hp)
{
GameServer.Heal(this, hp);
}
public void SetRunningSpeedMultiplier(float value)
{
GameServer.SetRunningSpeedMultiplier(this, value);
}
public void SetReceiveDamageMultiplier(float value)
{
GameServer.SetReceiveDamageMultiplier(this, value);
}
public void SetGiveDamageMultiplier(float value)
{
GameServer.SetGiveDamageMultiplier(this, value);
}
public void SetJumpMultiplier(float value)
{
GameServer.SetJumpMultiplier(this, value);
}
public void SetFallDamageMultiplier(float value)
{
GameServer.SetFallDamageMultiplier(this, value);
}
public void SetPrimaryWeapon(WeaponItem item, int extraMagazines, bool clear = false)
{
GameServer.SetPrimaryWeapon(this, item, extraMagazines, clear);
}
public void SetSecondaryWeapon(WeaponItem item, int extraMagazines, bool clear = false)
{
GameServer.SetSecondaryWeapon(this, item, extraMagazines, clear);
}
public void SetFirstAidGadget(string item, int extra, bool clear = false)
{
GameServer.SetFirstAid(this, item, extra, clear);
}
public void SetLightGadget(string item, int extra, bool clear = false)
{
GameServer.SetLightGadget(this, item, extra, clear);
}
public void SetHeavyGadget(string item, int extra, bool clear = false)
{
GameServer.SetHeavyGadget(this, item, extra, clear);
}
public void SetThrowable(string item, int extra, bool clear = false)
{
GameServer.SetThrowable(this, item, extra, clear);
@ -241,7 +271,7 @@ namespace BattleBitAPI
// ---- Static ----
public static TPlayer CreateInstance<TPlayer>(Player<TPlayer>.Internal @internal) where TPlayer : Player<TPlayer>
{
TPlayer player = (TPlayer)Activator.CreateInstance(typeof(TPlayer));
var player = (TPlayer)Activator.CreateInstance(typeof(TPlayer));
player.mInternal = @internal;
return player;
}
@ -255,33 +285,32 @@ namespace BattleBitAPI
// ---- Internal ----
public class Internal
{
public ulong SteamID;
public string Name;
public IPAddress IP;
public mPlayerModifications _Modifications;
public PlayerLoadout CurrentLoadout;
public LoadoutIndex CurrentLoadoutIndex;
public PlayerWearings CurrentWearings;
public GameServer<TPlayer> GameServer;
public GameRole Role;
public Team Team;
public Squads Squad;
public int PingMs = 999;
public float HP;
public bool InVehicle;
public IPAddress IP;
public bool IsAlive;
public float HP;
public Vector3 Position;
public PlayerStand Standing;
public LeaningSide Leaning;
public LoadoutIndex CurrentLoadoutIndex;
public bool InVehicle;
public bool IsBleeding;
public PlayerLoadout CurrentLoadout;
public PlayerWearings CurrentWearings;
public mPlayerModifications _Modifications;
public LeaningSide Leaning;
public PlayerModifications<TPlayer> Modifications;
public string Name;
public int PingMs = 999;
public Vector3 Position;
public GameRole Role;
public Squads Squad;
public PlayerStand Standing;
public ulong SteamID;
public Team Team;
public Internal()
{
this.Modifications = new PlayerModifications<TPlayer>(this);
this._Modifications = new mPlayerModifications();
Modifications = new PlayerModifications<TPlayer>(this);
_Modifications = new mPlayerModifications();
}
public void OnDie()
@ -298,67 +327,69 @@ namespace BattleBitAPI
CurrentWearings = new PlayerWearings();
}
}
public class mPlayerModifications
{
public float RunningSpeedMultiplier = 1f;
public float ReceiveDamageMultiplier = 1f;
public float GiveDamageMultiplier = 1f;
public float JumpHeightMultiplier = 1f;
public float FallDamageMultiplier = 1f;
public float ReloadSpeedMultiplier = 1f;
public bool CanUseNightVision = true;
public bool HasCollision = false;
public float DownTimeGiveUpTime = 60f;
public bool AirStrafe = true;
public bool CanRespawn = true;
public bool CanSpawn = true;
public bool CanSpectate = true;
public bool IsTextChatMuted = false;
public bool IsVoiceChatMuted = false;
public float RespawnTime = 10f;
public bool CanRespawn = true;
public bool CanUseNightVision = true;
public float DownTimeGiveUpTime = 60f;
public float FallDamageMultiplier = 1f;
public float GiveDamageMultiplier = 1f;
public bool HasCollision;
public bool IsDirtyFlag = false;
public void Write(BattleBitAPI.Common.Serialization.Stream ser)
{
ser.Write(this.RunningSpeedMultiplier);
ser.Write(this.ReceiveDamageMultiplier);
ser.Write(this.GiveDamageMultiplier);
ser.Write(this.JumpHeightMultiplier);
ser.Write(this.FallDamageMultiplier);
ser.Write(this.ReloadSpeedMultiplier);
ser.Write(this.CanUseNightVision);
ser.Write(this.HasCollision);
ser.Write(this.DownTimeGiveUpTime);
ser.Write(this.AirStrafe);
ser.Write(this.CanSpawn);
ser.Write(this.CanSpectate);
ser.Write(this.IsTextChatMuted);
ser.Write(this.IsVoiceChatMuted);
ser.Write(this.RespawnTime);
ser.Write(this.CanRespawn);
}
public void Read(BattleBitAPI.Common.Serialization.Stream ser)
{
this.RunningSpeedMultiplier = ser.ReadFloat();
if (this.RunningSpeedMultiplier <= 0f)
this.RunningSpeedMultiplier = 0.01f;
public bool IsTextChatMuted;
public bool IsVoiceChatMuted;
public float JumpHeightMultiplier = 1f;
public float ReceiveDamageMultiplier = 1f;
public float ReloadSpeedMultiplier = 1f;
public float RespawnTime = 10f;
public float RunningSpeedMultiplier = 1f;
this.ReceiveDamageMultiplier = ser.ReadFloat();
this.GiveDamageMultiplier = ser.ReadFloat();
this.JumpHeightMultiplier = ser.ReadFloat();
this.FallDamageMultiplier = ser.ReadFloat();
this.ReloadSpeedMultiplier = ser.ReadFloat();
this.CanUseNightVision = ser.ReadBool();
this.HasCollision = ser.ReadBool();
this.DownTimeGiveUpTime = ser.ReadFloat();
this.AirStrafe = ser.ReadBool();
this.CanSpawn = ser.ReadBool();
this.CanSpectate = ser.ReadBool();
this.IsTextChatMuted = ser.ReadBool();
this.IsVoiceChatMuted = ser.ReadBool();
this.RespawnTime = ser.ReadFloat();
this.CanRespawn = ser.ReadBool();
public void Write(Stream ser)
{
ser.Write(RunningSpeedMultiplier);
ser.Write(ReceiveDamageMultiplier);
ser.Write(GiveDamageMultiplier);
ser.Write(JumpHeightMultiplier);
ser.Write(FallDamageMultiplier);
ser.Write(ReloadSpeedMultiplier);
ser.Write(CanUseNightVision);
ser.Write(HasCollision);
ser.Write(DownTimeGiveUpTime);
ser.Write(AirStrafe);
ser.Write(CanSpawn);
ser.Write(CanSpectate);
ser.Write(IsTextChatMuted);
ser.Write(IsVoiceChatMuted);
ser.Write(RespawnTime);
ser.Write(CanRespawn);
}
public void Read(Stream ser)
{
RunningSpeedMultiplier = ser.ReadFloat();
if (RunningSpeedMultiplier <= 0f)
RunningSpeedMultiplier = 0.01f;
ReceiveDamageMultiplier = ser.ReadFloat();
GiveDamageMultiplier = ser.ReadFloat();
JumpHeightMultiplier = ser.ReadFloat();
FallDamageMultiplier = ser.ReadFloat();
ReloadSpeedMultiplier = ser.ReadFloat();
CanUseNightVision = ser.ReadBool();
HasCollision = ser.ReadBool();
DownTimeGiveUpTime = ser.ReadFloat();
AirStrafe = ser.ReadBool();
CanSpawn = ser.ReadBool();
CanSpectate = ser.ReadBool();
IsTextChatMuted = ser.ReadBool();
IsVoiceChatMuted = ser.ReadBool();
RespawnTime = ser.ReadFloat();
CanRespawn = ser.ReadBool();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +1,45 @@
using BattleBitAPI.Common;
namespace BattleBitAPI.Storage
namespace BattleBitAPI.Storage;
public class DiskStorage : IPlayerStatsDatabase
{
public class DiskStorage : IPlayerStatsDatabase
{
private string mDirectory;
private readonly string mDirectory;
public DiskStorage(string directory)
{
var info = new DirectoryInfo(directory);
if (!info.Exists)
info.Create();
this.mDirectory = info.FullName + Path.DirectorySeparatorChar;
mDirectory = info.FullName + Path.DirectorySeparatorChar;
}
public async Task<PlayerStats> GetPlayerStatsOf(ulong steamID)
{
var file = this.mDirectory + steamID + ".data";
var file = mDirectory + steamID + ".data";
if (File.Exists(file))
{
try
{
var data = await File.ReadAllBytesAsync(file);
return new PlayerStats(data);
}
catch { }
catch
{
}
return null;
}
public async Task SavePlayerStatsOf(ulong steamID, PlayerStats stats)
{
var file = this.mDirectory + steamID + ".data";
var file = mDirectory + steamID + ".data";
try
{
await File.WriteAllBytesAsync(file, stats.SerializeToByteArray());
}
catch { }
catch
{
}
}
}

View File

@ -1,10 +1,9 @@
using BattleBitAPI.Common;
namespace BattleBitAPI.Storage
namespace BattleBitAPI.Storage;
public interface IPlayerStatsDatabase
{
public interface IPlayerStatsDatabase
{
public Task<PlayerStats> GetPlayerStatsOf(ulong steamID);
public Task SavePlayerStatsOf(ulong steamID, PlayerStats stats);
}
}

View File

@ -1,28 +1,26 @@
using BattleBitAPI;
using BattleBitAPI.Common;
using BattleBitAPI.Server;
using System.Threading.Channels;
using System.Xml;
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
var listener = new ServerListener<MyPlayer, MyGameServer>();
listener.Start(29294);
Thread.Sleep(-1);
}
}
class MyPlayer : Player<MyPlayer>
internal class MyPlayer : Player<MyPlayer>
{
public override async Task OnConnected()
{
}
}
class MyGameServer : GameServer<MyPlayer>
internal class MyGameServer : GameServer<MyPlayer>
{
public override async Task OnConnected()
{
@ -36,26 +34,32 @@ class MyGameServer : GameServer<MyPlayer>
{
await Console.Out.WriteLineAsync("Connected: " + player);
}
public override async Task OnPlayerSpawned(MyPlayer player)
{
await Console.Out.WriteLineAsync("Spawned: " + player);
}
public override async Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
{
await Console.Out.WriteLineAsync("Downed: " + args.Victim);
}
public override async Task OnPlayerGivenUp(MyPlayer player)
{
await Console.Out.WriteLineAsync("Giveup: " + player);
}
public override async Task OnPlayerDied(MyPlayer player)
{
await Console.Out.WriteLineAsync("Died: " + player);
}
public override async Task OnAPlayerRevivedAnotherPlayer(MyPlayer from, MyPlayer to)
{
await Console.Out.WriteLineAsync(from + " revived " + to);
}
public override async Task OnPlayerDisconnected(MyPlayer player)
{
await Console.Out.WriteLineAsync("Disconnected: " + player);