UNPKG

@infernus/raknet

Version:

A wrapper of the popular open.mp raknet plugin for samp-node.

2 lines (1 loc) 33.1 kB
"use strict";var u=require("@infernus/core");samp.defined||(samp.defined={}),samp.defined.PAWNRAKNET_INC_=!0;const H=256,b=13,x=e=>Math.ceil(e/8),K=e=>e*8;var k=(e=>(e[e.IncomingPacket=0]="IncomingPacket",e[e.IncomingRpc=1]="IncomingRpc",e[e.OutgoingPacket=2]="OutgoingPacket",e[e.OutgoingRpc=3]="OutgoingRpc",e[e.IncomingCustomRpc=4]="IncomingCustomRpc",e[e.NumberOfEventTypes=5]="NumberOfEventTypes",e))(k||{}),a=(e=>(e[e.Int8=0]="Int8",e[e.Int16=1]="Int16",e[e.Int32=2]="Int32",e[e.UInt8=3]="UInt8",e[e.UInt16=4]="UInt16",e[e.UInt32=5]="UInt32",e[e.Float=6]="Float",e[e.Bool=7]="Bool",e[e.String=8]="String",e[e.CInt8=9]="CInt8",e[e.CInt16=10]="CInt16",e[e.CInt32=11]="CInt32",e[e.CUInt8=12]="CUInt8",e[e.CUInt16=13]="CUInt16",e[e.CUInt32=14]="CUInt32",e[e.CFloat=15]="CFloat",e[e.CBool=16]="CBool",e[e.CString=17]="CString",e[e.Bits=18]="Bits",e[e.Float3=19]="Float3",e[e.Float4=20]="Float4",e[e.Vector=21]="Vector",e[e.NormQuat=22]="NormQuat",e[e.String8=23]="String8",e[e.String32=24]="String32",e[e.IgnoreBits=25]="IgnoreBits",e))(a||{}),m=(e=>(e[e.System=0]="System",e[e.High=1]="High",e[e.Medium=2]="Medium",e[e.Low=3]="Low",e))(m||{}),P=(e=>(e[e.Unreliable=6]="Unreliable",e[e.UnreliableSequenced=7]="UnreliableSequenced",e[e.Reliable=8]="Reliable",e[e.ReliableOrdered=9]="ReliableOrdered",e[e.ReliableSequenced=10]="ReliableSequenced",e))(P||{}),c=(e=>(e[e.SendPacket=0]="SendPacket",e[e.SendRpc=1]="SendRpc",e[e.EmulateIncomingPacket=2]="EmulateIncomingPacket",e[e.EmulateIncomingRpc=3]="EmulateIncomingRpc",e[e.New=4]="New",e[e.NewCopy=5]="NewCopy",e[e.Delete=6]="Delete",e[e.Reset=7]="Reset",e[e.ResetReadPointer=8]="ResetReadPointer",e[e.ResetWritePointer=9]="ResetWritePointer",e[e.IgnoreBits=10]="IgnoreBits",e[e.SetWriteOffset=11]="SetWriteOffset",e[e.GetWriteOffset=12]="GetWriteOffset",e[e.SetReadOffset=13]="SetReadOffset",e[e.GetReadOffset=14]="GetReadOffset",e[e.GetNumberOfBitsUsed=15]="GetNumberOfBitsUsed",e[e.GetNumberOfBytesUsed=16]="GetNumberOfBytesUsed",e[e.GetNumberOfUnreadBits=17]="GetNumberOfUnreadBits",e[e.GetNumberOfBitsAllocated=18]="GetNumberOfBitsAllocated",e))(c||{}),I=(e=>(e[e.DriverSync=200]="DriverSync",e[e.RconCommand=201]="RconCommand",e[e.AimSync=203]="AimSync",e[e.WeaponsUpdate=204]="WeaponsUpdate",e[e.StatsUpdate=205]="StatsUpdate",e[e.BulletSync=206]="BulletSync",e[e.OnFootSync=207]="OnFootSync",e[e.MarkersSync=208]="MarkersSync",e[e.UnoccupiedSync=209]="UnoccupiedSync",e[e.TrailerSync=210]="TrailerSync",e[e.PassengerSync=211]="PassengerSync",e[e.SpectatingSync=212]="SpectatingSync",e[e.InternalPing=6]="InternalPing",e[e.ConnectedPong=9]="ConnectedPong",e[e.RequestStaticData=10]="RequestStaticData",e[e.ConnectionRequest=11]="ConnectionRequest",e[e.AuthKey=12]="AuthKey",e[e.RpcMapping=17]="RpcMapping",e[e.DetectLostConnections=23]="DetectLostConnections",e[e.NewIncomingConnection=30]="NewIncomingConnection",e[e.NoFreeIncomingConnections=31]="NoFreeIncomingConnections",e[e.DisconnectionNotification=32]="DisconnectionNotification",e[e.ConnectionLost=33]="ConnectionLost",e[e.ConnectionRequestAccepted=34]="ConnectionRequestAccepted",e[e.ConnectionAttemptFailed=35]="ConnectionAttemptFailed",e[e.ConnectionBanned=36]="ConnectionBanned",e[e.InvalidPassword=37]="InvalidPassword",e[e.ModifiedPacket=38]="ModifiedPacket",e))(I||{}),v=(e=>(e[e.ShowActor=171]="ShowActor",e[e.HideActor=172]="HideActor",e[e.ApplyActorAnimation=173]="ApplyActorAnimation",e[e.ClearActorAnimation=174]="ClearActorAnimation",e[e.SetActorFacingAngle=175]="SetActorFacingAngle",e[e.SetActorPos=176]="SetActorPos",e[e.SetActorHealth=178]="SetActorHealth",e[e.SetPlayerAttachedObject=113]="SetPlayerAttachedObject",e[e.ChatBubble=59]="ChatBubble",e[e.GiveActorDamage=177]="GiveActorDamage",e[e.DisableCheckpoint=37]="DisableCheckpoint",e[e.SetRaceCheckpoint=38]="SetRaceCheckpoint",e[e.DisableRaceCheckpoint=39]="DisableRaceCheckpoint",e[e.SetCheckpoint=107]="SetCheckpoint",e[e.ShowDialog=61]="ShowDialog",e[e.AddGangZone=108]="AddGangZone",e[e.GangZoneDestroy=120]="GangZoneDestroy",e[e.GangZoneFlash=121]="GangZoneFlash",e[e.GangZoneStopFlash=85]="GangZoneStopFlash",e[e.ShowGameText=73]="ShowGameText",e[e.SetGravity=146]="SetGravity",e[e.SetMapIcon=56]="SetMapIcon",e[e.RemoveMapIcon=144]="RemoveMapIcon",e[e.InitMenu=76]="InitMenu",e[e.ShowMenu=77]="ShowMenu",e[e.HideMenu=78]="HideMenu",e[e.ShowPlayerNameTag=80]="ShowPlayerNameTag",e[e.CreateObject=44]="CreateObject",e[e.SetPlayerObjectMaterialText=84]="SetPlayerObjectMaterialText",e[e.AttachObjectToPlayer=75]="AttachObjectToPlayer",e[e.AttachCameraToObject=81]="AttachCameraToObject",e[e.EditAttachedObject=116]="EditAttachedObject",e[e.EditObject=117]="EditObject",e[e.EnterEditObject=27]="EnterEditObject",e[e.CancelEdit=28]="CancelEdit",e[e.SetObjectPos=45]="SetObjectPos",e[e.SetObjectRotation=46]="SetObjectRotation",e[e.DestroyObject=47]="DestroyObject",e[e.MoveObject=99]="MoveObject",e[e.StopObject=122]="StopObject",e[e.CreatePickup=95]="CreatePickup",e[e.DestroyPickup=63]="DestroyPickup",e[e.ServerJoin=137]="ServerJoin",e[e.ServerQuit=138]="ServerQuit",e[e.InitGame=139]="InitGame",e[e.ConnectionRejected=130]="ConnectionRejected",e[e.UpdateScoresAndPings=155]="UpdateScoresAndPings",e[e.ClientJoin=25]="ClientJoin",e[e.NpcJoin=54]="NpcJoin",e[e.ClientCheck=103]="ClientCheck",e[e.GameModeRestart=40]="GameModeRestart",e[e.ApplyPlayerAnimation=86]="ApplyPlayerAnimation",e[e.ClearPlayerAnimation=87]="ClearPlayerAnimation",e[e.DeathBroadcast=166]="DeathBroadcast",e[e.SetPlayerName=11]="SetPlayerName",e[e.SetPlayerPos=12]="SetPlayerPos",e[e.SetPlayerPosFindZ=13]="SetPlayerPosFindZ",e[e.SetPlayerFacingAngle=19]="SetPlayerFacingAngle",e[e.SetPlayerSkillLevel=34]="SetPlayerSkillLevel",e[e.SetPlayerSkin=153]="SetPlayerSkin",e[e.SetPlayerTime=29]="SetPlayerTime",e[e.SetPlayerSpecialAction=88]="SetPlayerSpecialAction",e[e.SetWeather=152]="SetWeather",e[e.SetWorldBounds=17]="SetWorldBounds",e[e.SetPlayerVelocity=90]="SetPlayerVelocity",e[e.TogglePlayerControllable=15]="TogglePlayerControllable",e[e.TogglePlayerSpectating=124]="TogglePlayerSpectating",e[e.ToggleClock=30]="ToggleClock",e[e.SetPlayerTeam=69]="SetPlayerTeam",e[e.PlaySound=16]="PlaySound",e[e.GivePlayerMoney=18]="GivePlayerMoney",e[e.ResetPlayerMoney=20]="ResetPlayerMoney",e[e.ResetPlayerWeapons=21]="ResetPlayerWeapons",e[e.GivePlayerWeapon=22]="GivePlayerWeapon",e[e.PlayAudioStream=41]="PlayAudioStream",e[e.PlayCrimeReport=112]="PlayCrimeReport",e[e.StopAudioStream=42]="StopAudioStream",e[e.RemoveBuilding=43]="RemoveBuilding",e[e.SetPlayerHealth=14]="SetPlayerHealth",e[e.SetPlayerArmour=66]="SetPlayerArmour",e[e.SetWeaponAmmo=145]="SetWeaponAmmo",e[e.SetCameraBehind=162]="SetCameraBehind",e[e.SetArmedWeapon=67]="SetArmedWeapon",e[e.WorldPlayerAdd=32]="WorldPlayerAdd",e[e.WorldPlayerRemove=163]="WorldPlayerRemove",e[e.InterpolateCamera=82]="InterpolateCamera",e[e.CreateExplosion=79]="CreateExplosion",e[e.SendDeathMessage=55]="SendDeathMessage",e[e.SendGameTimeUpdate=60]="SendGameTimeUpdate",e[e.SendClientMessage=93]="SendClientMessage",e[e.SetShopName=33]="SetShopName",e[e.SetPlayerDrunkLevel=35]="SetPlayerDrunkLevel",e[e.SetPlayerFightingStyle=89]="SetPlayerFightingStyle",e[e.SetInterior=156]="SetInterior",e[e.SetPlayerColor=72]="SetPlayerColor",e[e.ForceClassSelection=74]="ForceClassSelection",e[e.ToggleWidescreen=111]="ToggleWidescreen",e[e.SetPlayerWantedLevel=133]="SetPlayerWantedLevel",e[e.SetCameraPos=157]="SetCameraPos",e[e.SetCameraLookAt=158]="SetCameraLookAt",e[e.SetSpawnInfo=68]="SetSpawnInfo",e[e.RequestClass=128]="RequestClass",e[e.RequestSpawn=129]="RequestSpawn",e[e.SpectatePlayer=126]="SpectatePlayer",e[e.SpectateVehicle=127]="SpectateVehicle",e[e.EnableStuntBonus=104]="EnableStuntBonus",e[e.ToggleSelectTextDraw=83]="ToggleSelectTextDraw",e[e.TextDrawSetString=105]="TextDrawSetString",e[e.ShowTextDraw=134]="ShowTextDraw",e[e.HideTextDraw=135]="HideTextDraw",e[e.PlayerEnterVehicle=26]="PlayerEnterVehicle",e[e.PlayerExitVehicle=154]="PlayerExitVehicle",e[e.RemoveVehicleComponent=57]="RemoveVehicleComponent",e[e.AttachTrailerToVehicle=148]="AttachTrailerToVehicle",e[e.DetachTrailerFromVehicle=149]="DetachTrailerFromVehicle",e[e.LinkVehicleToInterior=65]="LinkVehicleToInterior",e[e.PutPlayerInVehicle=70]="PutPlayerInVehicle",e[e.RemovePlayerFromVehicle=71]="RemovePlayerFromVehicle",e[e.UpdateVehicleDamageStatus=106]="UpdateVehicleDamageStatus",e[e.SetVehicleTireStatus=98]="SetVehicleTireStatus",e[e.ScmEvent=96]="ScmEvent",e[e.SetVehicleNumberPlate=123]="SetVehicleNumberPlate",e[e.DisableVehicleCollisions=167]="DisableVehicleCollisions",e[e.SetVehicleHealth=147]="SetVehicleHealth",e[e.SetVehicleVelocity=91]="SetVehicleVelocity",e[e.SetVehiclePos=159]="SetVehiclePos",e[e.SetVehicleZAngle=160]="SetVehicleZAngle",e[e.SetVehicleParams=161]="SetVehicleParams",e[e.SetVehicleParamsEx=24]="SetVehicleParamsEx",e[e.WorldVehicleAdd=164]="WorldVehicleAdd",e[e.WorldVehicleRemove=165]="WorldVehicleRemove",e[e.Create3DTextLabel=36]="Create3DTextLabel",e[e.Delete3DTextLabel=58]="Delete3DTextLabel",e[e.SetWorldTime=94]="SetWorldTime",e[e.ToggleCameraTarget=170]="ToggleCameraTarget",e[e.EnterVehicle=26]="EnterVehicle",e[e.ExitVehicle=154]="ExitVehicle",e[e.VehicleDamaged=106]="VehicleDamaged",e[e.VehicleDestroyed=136]="VehicleDestroyed",e[e.SendSpawn=52]="SendSpawn",e[e.ChatMessage=101]="ChatMessage",e[e.InteriorChangeNotification=118]="InteriorChangeNotification",e[e.DeathNotification=53]="DeathNotification",e[e.SendCommand=50]="SendCommand",e[e.ClickPlayer=23]="ClickPlayer",e[e.DialogResponse=62]="DialogResponse",e[e.ClientCheckResponse=103]="ClientCheckResponse",e[e.GiveTakeDamage=115]="GiveTakeDamage",e[e.MapMarker=119]="MapMarker",e[e.MenuSelect=132]="MenuSelect",e[e.MenuQuit=140]="MenuQuit",e[e.SelectTextDraw=83]="SelectTextDraw",e[e.PickedUpPickup=131]="PickedUpPickup",e[e.SelectObject=27]="SelectObject",e[e.CameraTarget=168]="CameraTarget",e[e.SetPlayerVirtualWorld=48]="SetPlayerVirtualWorld",e[e.ModelInfo=179]="ModelInfo",e[e.ModelFile=183]="ModelFile",e[e.SrcFinishedDownloading=185]="SrcFinishedDownloading",e[e.FinishedDownloading=184]="FinishedDownloading",e[e.RequestDffFile=181]="RequestDffFile",e[e.RequestTxdFile=182]="RequestTxdFile",e))(v||{}),E=(e=>(e[e.INTERNAL_PING=6]="INTERNAL_PING",e[e.CONNECTED_PONG=9]="CONNECTED_PONG",e[e.REQUEST_STATIC_DATA=10]="REQUEST_STATIC_DATA",e[e.CONNECTION_REQUEST=11]="CONNECTION_REQUEST",e[e.AUTH_KEY=12]="AUTH_KEY",e[e.RPC_MAPPING=17]="RPC_MAPPING",e[e.DETECT_LOST_CONNECTIONS=23]="DETECT_LOST_CONNECTIONS",e[e.NEW_INCOMING_CONNECTION=30]="NEW_INCOMING_CONNECTION",e[e.NO_FREE_INCOMING_CONNECTIONS=31]="NO_FREE_INCOMING_CONNECTIONS",e[e.DISCONNECTION_NOTIFICATION=32]="DISCONNECTION_NOTIFICATION",e[e.CONNECTION_LOST=33]="CONNECTION_LOST",e[e.CONNECTION_REQUEST_ACCEPTED=34]="CONNECTION_REQUEST_ACCEPTED",e[e.CONNECTION_ATTEMPT_FAILED=35]="CONNECTION_ATTEMPT_FAILED",e[e.CONNECTION_BANNED=36]="CONNECTION_BANNED",e[e.INVALID_PASSWORD=37]="INVALID_PASSWORD",e[e.MODIFIED_PACKET=38]="MODIFIED_PACKET",e[e.RECEIVED_STATIC_DATA=41]="RECEIVED_STATIC_DATA",e))(E||{});const g=(e,t,r="utf8")=>(typeof e=="string"?u.I18n.encodeToBuf(e,r):e).slice(0,t),C=(e,t,r,n)=>{const i=e.readValue([r,t]),l=u.I18n.getValidStr(i);return u.I18n.decodeFromBuf(l,n)},d=(...e)=>samp.callPublic("RakNetNatives","a",e),q=(e,t,r=0)=>{switch(t){case a.Bool:case a.CBool:return!!samp.callPublic("RakNetReadInt","i",e);case a.Float:return samp.callPublicFloat("RakNetReadFloat","i",e);case a.CFloat:return samp.callPublicFloat("RakNetReadCompressedFloat","i",e);case a.Bits:return samp.callPublic("RakNetReadBits","ii",e,r);case a.Float3:{samp.callPublic("RakNetReadFloat3","i",e);const n=[];for(let i=0;i<3;i++)n[i]=samp.callPublicFloat("RakNetReadFloat3Array","i",i);return n}case a.Float4:{samp.callPublic("RakNetReadFloat4","i",e);const n=[];for(let i=0;i<4;i++)n[i]=samp.callPublicFloat("RakNetReadFloat4Array","i",i);return n}case a.Vector:{samp.callPublic("RakNetReadVector","i",e);const n=[];for(let i=0;i<3;i++)n[i]=samp.callPublicFloat("RakNetReadFloat3Array","i",i);return n}case a.NormQuat:{samp.callPublic("RakNetReadNormQuat","i",e);const n=[];for(let i=0;i<4;i++)n[i]=samp.callPublicFloat("RakNetReadFloat4Array","i",i);return n}case a.String8:{samp.callPublic("RakNetReadString8","i",e);const n=[];for(let i=0;i<8;i++)n[i]=samp.callPublic("RakNetReadString8Array","i",i);return n}case a.String32:{samp.callPublic("RakNetReadString32","i",e);const n=[];for(let i=0;i<32;i++)n[i]=samp.callPublic("RakNetReadString32Array","i",i);return n}case a.String:{samp.callPublic("RakNetReadString","ii",e,r);const n=[];for(let i=0;i<r;i++)n[i]=samp.callPublic("RakNetReadStringArray","i",i);return n}case a.CString:{samp.callPublic("RakNetReadCompressedString","ii",e,r);const n=[];for(let i=0;i<r;i++)n[i]=samp.callPublic("RakNetReadStringArray","i",i);return n}default:return samp.callPublic("RakNetReadInt","ii",e,t)}},Q=(e,t,r,n=0)=>{switch(t){case a.Bool:case a.CBool:return Array.isArray(r)?!1:!!samp.callPublic("RakNetWriteInt","ii",e,+r);case a.Float:return typeof r!="number"?!1:!!samp.callPublicFloat("RakNetWriteFloat","if",e,r);case a.CFloat:return typeof r!="number"?!1:!!samp.callPublicFloat("RakNetWriteCompressedFloat","if",e,r);case a.Bits:return typeof r!="number"?!1:!!samp.callPublic("RakNetWriteBits","iii",e,r,n);case a.Float3:return!Array.isArray(r)||r.length!==3?!1:!!samp.callPublicFloat("RakNetWriteFloat3","iv",e,r);case a.Float4:return!Array.isArray(r)||r.length!==4?!1:!!samp.callPublicFloat("RakNetWriteFloat4","iv",e,r);case a.Vector:return!Array.isArray(r)||r.length!==3?!1:!!samp.callPublicFloat("RakNetWriteVector","iv",e,r);case a.NormQuat:return!Array.isArray(r)||r.length!==4?!1:!!samp.callPublicFloat("RakNetWriteNormQuat","iv",e,r);case a.String8:return Array.isArray(r)?!!samp.callPublicFloat("RakNetWriteString8","ia",e,r):!1;case a.String32:return Array.isArray(r)?!!samp.callPublicFloat("RakNetWriteString32","ia",e,r):!1;case a.String:return Array.isArray(r)?!!samp.callPublicFloat("RakNetWriteString","iai",e,r,n||r.length):!1;case a.CString:return Array.isArray(r)?!!samp.callPublicFloat("RakNetWriteCompressedString","iai",e,r,n||r.length):!1;default:return typeof r!="number"?!1:!!samp.callPublic("RakNetWriteInt","iii",e,t,r)}};class o{id;constructor(t){t?t instanceof o?this.id=t.id:this.id=t:this.id=d(c.New)}sendPacket(t,r=m.High,n=P.ReliableOrdered,i=0){const l=typeof t=="number"?t:t.id;d(c.SendPacket,this.id,l,r,n,i)}sendRPC(t,r,n=m.High,i=P.ReliableOrdered,l=0){const s=typeof t=="number"?t:t.id;d(c.SendRpc,this.id,s,r,n,i,l)}emulateIncomingPacket(t){const r=typeof t=="number"?t:t.id;d(c.EmulateIncomingPacket,this.id,r)}emulateIncomingRPC(t,r){const n=typeof t=="number"?t:t.id;d(c.EmulateIncomingRpc,this.id,n,r)}newCopy(){return new o(d(c.NewCopy,this.id))}delete(){return d(c.Delete,this.id),this.id}reset(){d(c.Reset,this.id)}resetReadPointer(){d(c.ResetReadPointer,this.id)}resetWritePointer(){d(c.ResetWritePointer,this.id)}ignoreBits(t){d(c.IgnoreBits,this.id,t)}setWriteOffset(t){d(c.SetWriteOffset,this.id,t)}getWriteOffset(){return d(c.GetWriteOffset,this.id)}setReadOffset(t){d(c.SetReadOffset,this.id,t)}getReadOffset(){return d(c.GetReadOffset,this.id)}getNumberOfBitsUsed(){return d(c.GetNumberOfBitsUsed,this.id)}getNumberOfBytesUsed(){return d(c.GetNumberOfBytesUsed,this.id)}getNumberOfUnreadBits(){return d(c.GetNumberOfUnreadBits,this.id)}getNumberOfBitsAllocated(){return d(c.GetNumberOfBitsAllocated,this.id)}readValue(...t){const r=[];return t.forEach(n=>{const i=Array.isArray(n),l=i?n[0]:n,s=q(this.id,l,i?n[1]:0);r.push(s)}),r.length===1?r[0]:r}writeValue(...t){const r=[];return t.forEach(n=>{const[i,l,s=0]=n,y=Q(this.id,i,l,s);r.push(y)}),r.length===1?r[0]:r}readInt8(){return this.readValue(a.Int8)}readInt16(){return this.readValue(a.Int16)}readInt32(){return this.readValue(a.Int32)}readUint8(){return this.readValue(a.UInt8)}readUint16(){return this.readValue(a.UInt16)}readUint32(){return this.readValue(a.UInt32)}readFloat(){return this.readValue(a.Float)}readBool(){return this.readValue(a.Bool)}readString(t=1024){return C(this,t,a.String)}readCompressedInt8(){return this.readValue(a.CInt8)}readCompressedInt16(){return this.readValue(a.CInt16)}readCompressedInt32(){return this.readValue(a.CInt32)}readCompressedUint8(){return this.readValue(a.CUInt8)}readCompressedUint16(){return this.readValue(a.CUInt16)}readCompressedUint32(){return this.readValue(a.CUInt32)}readCompressedFloat(){return this.readValue(a.CFloat)}readCompressedBool(){return this.readValue(a.CBool)}readCompressedString(t,r){return C(this,t,a.CString,r)}readBits(t){return this.readValue([a.Bits,t])}readFloat3(){return this.readValue(a.Float3)}readFloat4(){return this.readValue(a.Float4)}readVector(){return this.readValue(a.Vector)}readNormQuat(){return this.readValue(a.NormQuat)}readString8(t){return C(this,8,a.String8,t)}readString32(t){return C(this,32,a.String32,t)}writeInt8(t){return this.writeValue([a.Int8,t])}writeInt16(t){return this.writeValue([a.Int16,t])}writeInt32(t){return this.writeValue([a.Int32,t])}writeUint8(t){return this.writeValue([a.UInt8,t])}writeUint16(t){return this.writeValue([a.UInt16,t])}writeUint32(t){return this.writeValue([a.UInt32,t])}writeFloat(t){return this.writeValue([a.Float,t])}writeBool(t){return this.writeValue([a.Bool,t])}writeString(t,r=1024){return this.writeValue([a.String,g(t,r)])}writeCompressedInt8(t){return this.writeValue([a.CInt8,t])}writeCompressedInt16(t){return this.writeValue([a.CInt16,t])}writeCompressedInt32(t){return this.writeValue([a.CInt32,t])}writeCompressedUint8(t){return this.writeValue([a.CUInt8,t])}writeCompressedUint16(t){return this.writeValue([a.CUInt16,t])}writeCompressedUint32(t){return this.writeValue([a.CUInt32,t])}writeCompressedFloat(t){return this.writeValue([a.CFloat,t])}writeCompressedBool(t){return this.writeValue([a.CBool,t])}writeCompressedString(t,r=1024){return this.writeValue([a.CString,g(t,r)])}writeBits(t,r){return this.writeValue([a.Bits,t,r])}writeFloat3(t){return this.writeValue([a.Float3,t])}writeFloat4(t){return this.writeValue([a.Float4,t])}writeVector(t){return this.writeValue([a.Vector,t])}writeNormQuat(t){return this.writeValue([a.NormQuat,t])}writeString8(t){return this.writeValue([a.String8,g(t,8)])}writeString32(t){return this.writeValue([a.String32,g(t,32)])}static packAspectRatio(t){return Math.round((t-1)*255)}static unpackAspectRatio(t){return t/255+1}static packCameraZoom(t){return Math.round((t-35)/35*63)}static unpackCameraZoom(t){return t/63*35+35}static packHealthArmour(t,r){let n;return t>0&&t<100?n=t/7<<4:t>=100?n=240:n=0,r>0&&r<100?n|=r/7:r>=100&&(n|=15),n}static unpackHealthArmour(t){let r,n;return r=t>>4,r===15?r=100:r*=7,n=t&15,n===15?n=100:n*=7,{health:r,armour:n}}readWeaponsUpdate(){const t={};t.slotWeaponId=[],t.slotWeaponAmmo=[],t.slotUpdated=[];let r=0;const n=this.getNumberOfBytesUsed();for(n>5&&(r=(n-5)/4),[t.targetId,t.targetActorId]=this.readValue(a.UInt16,a.UInt16);r--;){const[i,l,s]=this.readValue(a.UInt8,a.UInt8,a.UInt16);i<b&&(t.slotWeaponId[i]=l,t.slotWeaponAmmo[i]=s,t.slotUpdated[i]=!0)}return t}readStatsUpdate(){const t={};return[t.money,t.drunkLevel]=this.readValue(a.Int32,a.Int32),t}readRconCommand(){const t={},r=this.readValue(a.String32);if(!Array.isArray(r))throw new Error("Failed to read RCON command: expected array");return t.command=r,t}writeWeaponsUpdate(t){this.writeValue([a.UInt16,t.targetId],[a.UInt16,t.targetActorId]);for(let r=0;r<b;r++)t.slotUpdated[r]&&this.writeValue([a.UInt8,r],[a.UInt8,t.slotWeaponId[r]],[a.UInt16,t.slotWeaponAmmo[r]])}writeStatsUpdate(t){this.writeValue([a.Int32,t.money],[a.Int32,t.drunkLevel])}writeRconCommand(t){this.writeValue([a.String32,t.command])}sendPacketToPlayerStream(t,r,n=m.High,i=P.ReliableOrdered,l=0){t.forEach(s=>{s.isStreamedIn(r)&&this.sendPacket(s.id,n,i,l)})}sendRPCToPlayerStream(t,r,n,i=m.High,l=P.ReliableOrdered,s=0){t.forEach(y=>{y.isStreamedIn(r)&&this.sendRPC(y.id,n,i,l,s)})}sendPacketToVehicleStream(t,r,n=u.InvalidEnum.PLAYER_ID,i=m.High,l=P.ReliableOrdered,s=0){t.forEach(y=>{n!==u.InvalidEnum.PLAYER_ID&&(y===n||!r.isStreamedIn(y))||this.sendPacket(y.id,i,l,s)})}sendRPCToVehicleStream(t,r,n,i=u.InvalidEnum.PLAYER_ID,l=m.High,s=P.ReliableOrdered,y=0){t.forEach(R=>{i!==u.InvalidEnum.PLAYER_ID&&(R===i||!r.isStreamedIn(R))||this.sendRPC(R.id,n,l,s,y)})}}const[B]=u.defineEvent({name:"OnIncomingPacket",identifier:"iii",beforeEach(e,t,r){return{playerId:e,packetId:t,bs:new o(r)}}}),[D]=u.defineEvent({name:"OnIncomingRPC",identifier:"iii",beforeEach(e,t,r){return{playerId:e,rpcId:t,bs:new o(r)}}}),[_]=u.defineEvent({name:"OnOutgoingPacket",identifier:"iii",beforeEach(e,t,r){return{playerId:e,packetId:t,bs:new o(r)}}}),[M]=u.defineEvent({name:"OnOutgoingRPC",identifier:"iii",beforeEach(e,t,r){return{playerId:e,rpcId:t,bs:new o(r)}}}),W=(e,t)=>B(r=>r.packetId===e?t(r):r.next()),G=(e,t)=>D(r=>r.rpcId===e?t(r):r.next()),L=(e,t)=>_(r=>r.packetId===e?t(r):r.next()),j=(e,t)=>M(r=>r.rpcId===e?t(r):r.next()),Z=W,Y=G,$=L,X=j,p=e=>t=>{Object.defineProperty(t.prototype,"_packetId",{configurable:!1,enumerable:!1,writable:!1,value:e})},S=(e,t,r)=>{const n=r.value;r.value=function(...i){const l=this.bs;return l.resetReadPointer(),l.readBits(8)!==this._packetId?null:n.apply(this,i)}},h=(e,t,r)=>{const n=r.value;r.value=function(...i){const l=this.bs;l.resetWritePointer(),l.writeBits(this._packetId,8),n.apply(this,i)}};var J=Object.defineProperty,z=Object.getOwnPropertyDescriptor,O=(e,t,r,n)=>{for(var i=n>1?void 0:n?z(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&J(t,r,i),i};exports.AimSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.camMode,t.camFrontVec,t.camPos,t.aimZ,t.weaponState,t.camZoom,t.aspectRatio]=this.bs.readValue(a.UInt8,a.Float3,a.Float3,a.Float,[a.Bits,2],[a.Bits,6],a.UInt8),t}writeSync(t){this.bs.writeValue([a.UInt8,t.camMode],[a.Float3,t.camFrontVec],[a.Float3,t.camPos],[a.Float,t.aimZ],[a.Bits,t.weaponState,2],[a.Bits,t.camZoom,6],[a.UInt8,t.aspectRatio])}},O([S],exports.AimSync.prototype,"readSync",1),O([h],exports.AimSync.prototype,"writeSync",1),exports.AimSync=O([p(I.AimSync)],exports.AimSync);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,N=(e,t,r,n)=>{for(var i=n>1?void 0:n?te(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ee(t,r,i),i};exports.BulletSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.fromId,t.hitType,t.hitId,t.origin,t.hitPos,t.offsets,t.weaponId]=this.bs.readValue(a.UInt16,a.UInt8,a.UInt16,a.Float3,a.Float3,a.Float3,a.UInt8),t}writeSync(t){this.bs.writeValue([a.UInt16,t.fromId],[a.UInt8,t.hitType],[a.UInt16,t.hitId],[a.Float3,t.origin],[a.Float3,t.hitPos],[a.Float3,t.offsets],[a.UInt8,t.weaponId])}},N([S],exports.BulletSync.prototype,"readSync",1),N([h],exports.BulletSync.prototype,"writeSync",1),exports.BulletSync=N([p(I.BulletSync)],exports.BulletSync);var ae=Object.defineProperty,re=Object.getOwnPropertyDescriptor,f=(e,t,r,n)=>{for(var i=n>1?void 0:n?re(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ae(t,r,i),i};exports.InCarSync=class extends o{constructor(t){super(t),this.bs=t}readSync(t=!1){const r={trainSpeed:0,trailerId:0};if(t){let n;[r.vehicleId,r.lrKey,r.udKey,r.keys,r.quaternion,r.position,r.velocity,r.vehicleHealth,n,r.weaponId,r.sirenState,r.landingGearState]=this.bs.readValue(a.UInt16,a.UInt16,a.UInt16,a.UInt16,a.NormQuat,a.Float3,a.Vector,a.UInt16,a.UInt8,a.UInt8,a.Bool,a.Bool),r.vehicleHealth=r.vehicleHealth?+r.vehicleHealth:0;const{health:i,armour:l}=o.unpackHealthArmour(n);r.playerHealth=i,r.armour=l,this.bs.readValue(a.Bool)&&(r.trainSpeed=this.bs.readValue(a.Float)),this.bs.readValue(a.Bool)&&(r.trailerId=this.bs.readValue(a.UInt16))}else[r.vehicleId,r.lrKey,r.udKey,r.keys,r.quaternion,r.position,r.velocity,r.vehicleHealth,r.playerHealth,r.armour,r.additionalKey,r.weaponId,r.sirenState,r.landingGearState,r.trailerId,r.trainSpeed]=this.bs.readValue(a.UInt16,a.UInt16,a.UInt16,a.UInt16,a.Float4,a.Float3,a.Float3,a.Float,a.UInt8,a.UInt8,[a.Bits,2],[a.Bits,6],a.UInt8,a.UInt8,a.UInt16,a.Float);return r}writeSync(t,r=!1){if(r){const n=o.packHealthArmour(t.playerHealth,t.armour);this.bs.writeValue([a.UInt16,t.vehicleId],[a.UInt16,t.lrKey],[a.UInt16,t.udKey],[a.UInt16,t.keys],[a.NormQuat,t.quaternion],[a.Float3,t.position],[a.Vector,t.velocity],[a.UInt16,Math.round(t.vehicleHealth)],[a.UInt8,n],[a.UInt8,t.weaponId],[a.Bool,t.sirenState],[a.Bool,t.landingGearState]),t.trainSpeed?this.bs.writeValue([a.Bool,!0],[a.Float,t.trainSpeed]):this.bs.writeValue([a.Bool,!1]),t.trailerId?this.bs.writeValue([a.Bool,!0],[a.UInt16,t.trailerId]):this.bs.writeValue([a.Bool,!1])}else this.bs.writeValue([a.UInt16,t.vehicleId],[a.UInt16,t.lrKey],[a.UInt16,t.udKey],[a.UInt16,t.keys],[a.Float4,t.quaternion],[a.Float3,t.position],[a.Float3,t.velocity],[a.Float,t.vehicleHealth],[a.UInt8,t.playerHealth],[a.UInt8,t.armour],[a.Bits,t.additionalKey,2],[a.Bits,t.weaponId,6],[a.UInt8,t.sirenState],[a.UInt8,t.landingGearState],[a.UInt16,t.trailerId],[a.Float,t.trainSpeed])}},f([S],exports.InCarSync.prototype,"readSync",1),f([h],exports.InCarSync.prototype,"writeSync",1),exports.InCarSync=f([p(I.DriverSync)],exports.InCarSync);var ie=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,U=(e,t,r,n)=>{for(var i=n>1?void 0:n?ne(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ie(t,r,i),i};exports.MarkersSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};t.playerPositionX=[],t.playerPositionY=[],t.playerPositionZ=[],t.playerIsParticipant=[],t.playerIsActive=[];const r=this.bs.readInt32();if(r<0||r>u.LimitsEnum.MAX_PLAYERS)return null;t.numberOfPlayers=r;for(let n=0;n<r;n++){const i=this.bs.readUint16();if(i>=u.LimitsEnum.MAX_PLAYERS)return null;if(t.playerIsParticipant[i]=!0,this.bs.readCompressedBool()){t.playerIsActive[i]=!0;const[l,s,y]=this.bs.readValue(a.Int16,a.Int16,a.Int16);t.playerPositionX[i]=l,t.playerPositionY[i]=s,t.playerPositionZ[i]=y}}return t}writeSync(t){this.bs.writeInt32(t.numberOfPlayers);for(let r=0;r<u.LimitsEnum.MAX_PLAYERS;r++)t.playerIsParticipant[r]&&(this.bs.writeValue([a.UInt16,r],[a.CBool,t.playerIsActive[r]]),t.playerIsActive[r]&&this.bs.writeValue([a.Int16,t.playerPositionX[r]],[a.Int16,t.playerPositionY[r]],[a.Int16,t.playerPositionZ[r]]))}},U([S],exports.MarkersSync.prototype,"readSync",1),U([h],exports.MarkersSync.prototype,"writeSync",1),exports.MarkersSync=U([p(I.MarkersSync)],exports.MarkersSync);var le=Object.defineProperty,se=Object.getOwnPropertyDescriptor,V=(e,t,r,n)=>{for(var i=n>1?void 0:n?se(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&le(t,r,i),i};exports.OnFootSync=class extends o{constructor(t){super(t),this.bs=t}readSync(t=!1){const r={lrKey:0,udKey:0,surfingVehicleId:0,animationId:0,animationFlags:0};if(t){this.bs.readValue(a.Bool)&&(r.lrKey=this.bs.readValue(a.UInt16)),this.bs.readValue(a.Bool)&&(r.udKey=this.bs.readValue(a.UInt16));let n,i;[r.keys,r.position,r.quaternion,n,r.weaponId,r.specialAction,r.velocity,i]=this.bs.readValue(a.UInt16,a.Float3,a.NormQuat,a.UInt8,a.UInt8,a.UInt8,a.Vector,a.Bool);const{health:l,armour:s}=o.unpackHealthArmour(n);r.health=l,r.armour=s,i&&([r.surfingVehicleId,r.surfingOffsets]=this.bs.readValue(a.UInt16,a.Float3)),this.bs.readValue(a.Bool)&&([r.animationId,r.animationFlags]=this.bs.readValue(a.Int16,a.Int16))}else[r.lrKey,r.udKey,r.keys,r.position,r.quaternion,r.health,r.armour,r.additionalKey,r.weaponId,r.specialAction,r.velocity,r.surfingOffsets,r.surfingVehicleId,r.animationId,r.animationFlags]=this.bs.readValue(a.UInt16,a.UInt16,a.UInt16,a.Float3,a.Float4,a.UInt8,a.UInt8,[a.Bits,2],[a.Bits,6],a.UInt8,a.Float3,a.Float3,a.UInt16,a.Int16,a.Int16);return r}writeSync(t,r=!1){if(this.bs.resetWritePointer(),this.bs.writeBits(I.OnFootSync,8),r){t.lrKey?this.bs.writeValue([a.Bool,!0],[a.UInt16,t.lrKey]):this.bs.writeValue([a.Bool,!1]),t.udKey?this.bs.writeValue([a.Bool,!0],[a.UInt16,t.udKey]):this.bs.writeValue([a.Bool,!1]);const n=o.packHealthArmour(t.health,t.armour);this.bs.writeValue([a.UInt16,t.keys],[a.Float3,t.position],[a.NormQuat,t.quaternion],[a.UInt8,n],[a.UInt8,t.weaponId],[a.UInt8,t.specialAction],[a.Vector,t.velocity]),t.surfingVehicleId?this.bs.writeValue([a.Bool,!0],[a.UInt16,t.surfingVehicleId],[a.Float3,t.surfingOffsets]):this.bs.writeValue([a.Bool,!1]),t.animationId||t.animationFlags?this.bs.writeValue([a.Bool,!0],[a.Int16,t.animationId],[a.Int16,t.animationFlags]):this.bs.writeValue([a.Bool,!1])}else this.bs.writeValue([a.UInt16,t.lrKey],[a.UInt16,t.udKey],[a.UInt16,t.keys],[a.Float3,t.position],[a.Float4,t.quaternion],[a.UInt8,t.health],[a.UInt8,t.armour],[a.Bits,t.additionalKey,2],[a.Bits,t.weaponId,6],[a.UInt8,t.specialAction],[a.Float3,t.velocity],[a.Float3,t.surfingOffsets],[a.UInt16,t.surfingVehicleId],[a.Int16,t.animationId],[a.Int16,t.animationFlags])}},V([S],exports.OnFootSync.prototype,"readSync",1),V([h],exports.OnFootSync.prototype,"writeSync",1),exports.OnFootSync=V([p(I.OnFootSync)],exports.OnFootSync);var ce=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,A=(e,t,r,n)=>{for(var i=n>1?void 0:n?oe(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ce(t,r,i),i};exports.PassengerSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.vehicleId,t.driveBy,t.seatId,t.additionalKey,t.weaponId,t.playerHealth,t.playerArmour,t.lrKey,t.udKey,t.keys,t.position]=this.bs.readValue(a.UInt16,[a.Bits,2],[a.Bits,6],[a.Bits,2],[a.Bits,6],a.UInt8,a.UInt8,a.UInt16,a.UInt16,a.UInt16,a.Float3),t}writeSync(t){this.bs.writeValue([a.UInt16,t.vehicleId],[a.Bits,t.driveBy,2],[a.Bits,t.seatId,6],[a.Bits,t.additionalKey,2],[a.Bits,t.weaponId,6],[a.UInt8,t.playerHealth],[a.UInt8,t.playerArmour],[a.UInt16,t.lrKey],[a.UInt16,t.udKey],[a.UInt16,t.keys],[a.Float3,t.position])}},A([S],exports.PassengerSync.prototype,"readSync",1),A([h],exports.PassengerSync.prototype,"writeSync",1),exports.PassengerSync=A([p(I.PassengerSync)],exports.PassengerSync);var de=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,F=(e,t,r,n)=>{for(var i=n>1?void 0:n?ue(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&de(t,r,i),i};exports.SpectatingSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.lrKey,t.udKey,t.keys,t.position]=this.bs.readValue(a.UInt16,a.UInt16,a.UInt16,a.Float3),t}writeSync(t){this.bs.writeValue([a.UInt16,t.lrKey],[a.UInt16,t.udKey],[a.UInt16,t.keys],[a.Float3,t.position])}},F([S],exports.SpectatingSync.prototype,"readSync",1),F([h],exports.SpectatingSync.prototype,"writeSync",1),exports.SpectatingSync=F([p(I.SpectatingSync)],exports.SpectatingSync);var ye=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,w=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ie(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&ye(t,r,i),i};exports.TrailerSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.trailerId,t.position,t.quaternion,t.velocity,t.angularVelocity]=this.bs.readValue(a.UInt16,a.Float3,a.Float4,a.Float3,a.Float3),t}writeSync(t){this.bs.writeValue([a.UInt16,t.trailerId],[a.Float3,t.position],[a.Float4,t.quaternion],[a.Float3,t.velocity],[a.Float3,t.angularVelocity])}},w([S],exports.TrailerSync.prototype,"readSync",1),w([h],exports.TrailerSync.prototype,"writeSync",1),exports.TrailerSync=w([p(I.TrailerSync)],exports.TrailerSync);var pe=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,T=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,l=e.length-1,s;l>=0;l--)(s=e[l])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&pe(t,r,i),i};exports.UnoccupiedSync=class extends o{constructor(t){super(t),this.bs=t}readSync(){const t={};return[t.vehicleId,t.seatId,t.roll,t.direction,t.position,t.velocity,t.angularVelocity,t.vehicleHealth]=this.bs.readValue(a.UInt16,a.UInt8,a.Float3,a.Float3,a.Float3,a.Float3,a.Float3,a.Float),t}writeSync(t){this.bs.writeValue([a.UInt16,t.vehicleId],[a.UInt8,t.seatId],[a.Float3,t.roll],[a.Float3,t.direction],[a.Float3,t.position],[a.Float3,t.velocity],[a.Float3,t.angularVelocity],[a.Float,t.vehicleHealth])}},T([S],exports.UnoccupiedSync.prototype,"readSync",1),T([h],exports.UnoccupiedSync.prototype,"writeSync",1),exports.UnoccupiedSync=T([p(I.UnoccupiedSync)],exports.UnoccupiedSync),exports.BitStream=o,exports.IPacket=W,exports.IRPC=G,exports.IncomingPacket=Z,exports.IncomingRPC=Y,exports.InternalPacketIdList=E,exports.OPacket=L,exports.ORPC=j,exports.OutgoingPacket=$,exports.OutgoingRPC=X,exports.PR_BITS_TO_BYTES=x,exports.PR_BYTES_TO_BITS=K,exports.PR_MAX_HANDLERS=H,exports.PR_MAX_WEAPON_SLOTS=b,exports.PacketIdList=I,exports.PacketRpcEventType=k,exports.PacketRpcPriority=m,exports.PacketRpcReliability=P,exports.PacketRpcValueType=a,exports.RPCIdList=v,exports.RakNetNatives=c,exports.onIncomingPacket=B,exports.onIncomingRPC=D,exports.onOutgoingPacket=_,exports.onOutgoingRPC=M;