Example #1
0
 public override void Deserialize(HazelBinaryReader reader, bool onSpawn)
 {
     if (onSpawn)
     {
         //Guid gameGuid = new Guid(reader.ReadBytesAndSize());
         AllPlayers = reader.ReadList(read =>
         {
             var playerInfo = new PlayerInfo(reader.ReadByte());
             playerInfo.Deserialize(reader);
             return(playerInfo);
         });
         if (reader.HasBytesLeft())
         {
             Console.WriteLine($"Unhandled Gamedata deserialize() on spawn size: {reader.GetBytesLeft()}");
         }
         return;
     }
     else
     {
         byte count = reader.ReadByte();
         for (int j = 0; j < count; j++)
         {
             byte       playerId    = reader.ReadByte();
             PlayerInfo playerInfo2 = AllPlayers.FirstOrDefault(p => p.PlayerId == playerId);
             if (playerInfo2 != null)
             {
                 playerInfo2.Deserialize(reader);
             }
             else
             {
                 playerInfo2 = new PlayerInfo(playerId);
                 playerInfo2.Deserialize(reader);
                 AllPlayers.Add(playerInfo2);
             }
         }
         if (reader.HasBytesLeft())
         {
             Console.WriteLine($"Unhandled Gamedata deserialize() size: {reader.GetBytesLeft()}");
         }
     }
 }
Example #2
0
        public override void Deserialize(HazelBinaryReader reader, bool onSpawn)
        {
            if (onSpawn)
            {
                for (int i = 0; i < 24; i++)
                {
                    var system = (SystemTypes)i;
                    if (systems.ContainsKey(system))
                    {
                        var systemObj = systems[system];
                        systemObj.Deserialize(reader, onSpawn);
                    }
                }
                if (reader.HasBytesLeft())
                {
                    Console.WriteLine($"Bytesleft in ShipStatus DeserializeOnSpawn: size: {reader.GetBytesLeft()}");
                }
                return;
            }

            uint systemFlags = reader.ReadPackedUInt32();

            for (int i = 0; i < 24; i++)
            {
                if ((systemFlags & (1 << i)) != 0)
                {
                    var system    = (SystemTypes)i;
                    var systemObj = systems[system];
                    systemObj.Deserialize(reader, onSpawn);
                }
            }
            if (reader.HasBytesLeft())
            {
                Console.WriteLine($"Bytesleft in ShipStatus Deserialize: size: {reader.GetBytesLeft()}");
            }
        }
Example #3
0
 public override void Deserialize(HazelBinaryReader reader, bool onSpawn)
 {
     Console.WriteLine($"Unhandled LobbyBehaviour deserialize() size: {reader.GetBytesLeft()}");
 }
Example #4
0
 public override void Deserialize(HazelBinaryReader reader, bool onSpawn)
 {
     Console.WriteLine($"Attempted Deserialize for DummyComponent: {name} size: {reader.GetBytesLeft()}");
 }
Example #5
0
        static void HandleGameData(HazelBinaryReader reader, GameDataType datatype, bool send)
        {
            var dir = send ? "SEND" : "RECV";

            switch (datatype)
            {
            case GameDataType.RpcCall:
                var RPC     = RpcCall.Deserialize(reader);
                var reciver = EntityTracker.Get(RPC.targetNetId);
                if (LogRPC)
                {
                    Console.WriteLine($"[RPC][{RPC.callId}]sent to {reciver?.GetType()?.Name ?? "unknown"} size: {reader.GetBytesLeft()}");
                }
                if (reciver != null)
                {
                    reciver.HandleRpcCall(RPC.callId, reader);
                }
                //DumpToConsole(RPC, LogRPC);
                //Console.WriteLine($"RPC for type: {RPC} size: {data.body.Length}");
                switch (RPC.callId)
                {
                case RpcCalls.CheckColor:
                    var CheckColor = CmdCheckColor.Deserialize(reader);
                    DumpToConsole(CheckColor, LogRPC);
                    break;

                case RpcCalls.CheckName:
                    var CheckName = CmdCheckName.Deserialize(reader);
                    DumpToConsole(CheckName, LogRPC);
                    break;

                case RpcCalls.CloseDoorsOfType:
                    var CloseDoorsOfType = RpcCloseDoorsOfType.Deserialize(reader);
                    DumpToConsole(CloseDoorsOfType, LogRPC);
                    break;

                case RpcCalls.EnterVent:
                    var EnterVent = RpcEnterVent.Deserialize(reader);
                    DumpToConsole(EnterVent, LogRPC);
                    break;

                case RpcCalls.ExitVent:
                    var ExitVent = RpcExitVent.Deserialize(reader);
                    DumpToConsole(ExitVent, LogRPC);
                    break;

                case RpcCalls.Exiled:
                    var exileid = reader.ReadPackedInt32();
                    Console.WriteLine("Exile id: " + exileid);
                    break;

                case RpcCalls.SendChat:
                    var chat = RpcSendChat.Deserialize(reader);
                    LogChatToConsole(RPC.targetNetId.ToString(), chat.text);
                    break;

                case RpcCalls.SendChatNote:
                    var chatnote = RpcSendChatNote.Deserialize(reader);
                    LogChatToConsole("server", "SendChatNote");
                    break;

                case RpcCalls.SetColor:
                    var SetColor = RpcSetColor.Deserialize(reader);
                    DumpToConsole(SetColor, LogRPC);
                    break;

                case RpcCalls.SetSkin:
                    var skin = RpcSetSkin.Deserialize(reader);
                    DumpToConsole(skin, LogRPC);
                    break;

                case RpcCalls.SetHat:
                    var hat = RpcSetHat.Deserialize(reader);
                    Console.WriteLine($"Set hat: [{(int)hat.hatId}]{hat.hatId}");
                    break;

                case RpcCalls.SetPet:
                    var setpet = RpcSetPet.Deserialize(reader);
                    DumpToConsole(setpet, LogRPC);
                    break;

                case RpcCalls.SetName:
                    var setname = RpcSetName.Deserialize(reader);
                    DumpToConsole(setname, LogRPC);
                    break;

                case RpcCalls.SetTasks:
                    var SetTasks = RpcSetTasks.Deserialize(reader);
                    DumpToConsole(SetTasks, LogRPC);
                    break;

                case RpcCalls.SetInfected:
                    var infected = RpcSetInfected.Deserialize(reader);
                    DumpToConsole(infected);
                    break;

                case RpcCalls.SetScanner:
                    var SetScanner = RpcSetScanner.Deserialize(reader);
                    DumpToConsole(SetScanner, LogRPC);
                    break;

                case RpcCalls.AddVote:
                    var addvote = RpcAddVote.Deserialize(reader);
                    DumpToConsole(addvote, LogRPC);
                    break;

                case RpcCalls.PlayAnimation:
                    var anim = RpcPlayAnimation.Deserialize(reader);
                    DumpToConsole(anim, LogRPC);
                    break;

                case RpcCalls.CastVote:
                    var castvote = CmdCastVote.Deserialize(reader);
                    DumpToConsole(castvote, LogRPC);
                    break;

                case RpcCalls.CompleteTask:
                    var complete = RpcCompleteTask.Deserialize(reader);
                    DumpToConsole(complete, LogRPC);
                    break;

                case RpcCalls.MurderPlayer:
                    var MurderPlayer = RpcMurderPlayer.Deserialize(reader);
                    var player       = EntityTracker.Get(MurderPlayer.netId);
                    DumpToConsole(MurderPlayer, LogRPC);
                    break;

                case RpcCalls.RepairSystem:
                    var RepairSystem = RpcRepairSystem.Deserialize(reader);
                    DumpToConsole(RepairSystem, LogRPC);
                    break;

                case RpcCalls.ReportDeadBody:
                    var ReportDeadBody = CmdReportDeadBody.Deserialize(reader);
                    DumpToConsole(ReportDeadBody, LogRPC);
                    break;

                case RpcCalls.SnapTo:
                    var SnapTo = RpcSnapTo.Deserialize(reader);
                    DumpToConsole(SnapTo, LogRPC);
                    break;

                case RpcCalls.StartMeeting:
                    var StartMeeting = RpcStartMeeting.Deserialize(reader);
                    DumpToConsole(StartMeeting, LogRPC);
                    break;

                case RpcCalls.VotingComplete:
                    var VotingComplete = RpcVotingComplete.Deserialize(reader);
                    DumpToConsole(VotingComplete, LogRPC);
                    break;

                case RpcCalls.SetStartCounter:
                    var startcounter = RpcSetStartCounter.Deserialize(reader);
                    DumpToConsole(startcounter, LogRPC);
                    break;

                case RpcCalls.SyncSettings:
                    var syncsettings = RpcSyncSettings.Deserialize(reader);
                    DumpToConsole(syncsettings, LogRPC);
                    break;

                //Dont have a message body
                case RpcCalls.Close:
                    break;

                //ComponentSpecific - it contains diffrent data depending on what component it's inteded for
                case RpcCalls.UpdateGameData:
                    var update = RpcUpdateGameData.Deserialize(reader);
                    DumpToConsole(update, LogRPC);
                    break;

                default:
                    Console.WriteLine($"Unhandled RPC command: " + RPC.callId);
                    break;
                }
                if (reader.GetBytesLeft() > 0 && LogNotConsumed)
                {
                    Console.WriteLine($"[{RPC.callId}]{reader.GetBytesLeft()} bytes not cunsumed");
                    reader.ReadBytesToEnd();
                }
                break;

            case GameDataType.Data:
                var            data = Data.Deserialize(reader);
                InnerNetObject entity;
                if (!EntityTracker.entities.TryGetValue(data.netId, out entity))
                {
                    Console.WriteLine($"Entity missing for id: {data.netId} size: {data.data.Length}");
                    return;
                }
                if (!(entity is CustomNetworkTransform))
                {
                    Console.WriteLine($"Recived Data for: {entity.GetType().Name} size: {data.data.Length}");
                }

                entity.Deserialize(new HazelBinaryReader(data.data), false);

                if (LogMoves && entity is CustomNetworkTransform move)
                {
                    Console.WriteLine($"[{dir}]Move command player: {move.OwnerId:0000} seq: {move.seq:0000} pos: {move.position} delta: {move.velocity}");
                }

                break;

            case GameDataType.Spawn:
                var spawn = Spawn.Deserialize(reader);
                Console.WriteLine("Spawning: " + spawn.spawnId);
                switch (spawn.spawnId)
                {
                case 0:
                    var shipStatus = new ShipStatus();
                    shipStatus.OwnerId = spawn.ownerId;
                    shipStatus.NetId   = spawn.children[0].netId;
                    shipStatus.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(shipStatus);
                    break;

                case 1:
                    var meeting = new MeetingHud();
                    meeting.OwnerId = spawn.ownerId;
                    meeting.NetId   = spawn.children[0].netId;
                    meeting.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(meeting);
                    break;

                case 2:
                    var lobby = new LobbyBehaviour();
                    lobby.OwnerId = spawn.ownerId;
                    lobby.NetId   = spawn.children[0].netId;
                    EntityTracker.Add(lobby);
                    break;

                case 3:
                    var gdc = new GameDataComponent();
                    gdc.OwnerId = spawn.ownerId;
                    gdc.NetId   = spawn.children[0].netId;
                    gdc.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(gdc);

                    var dummy2 = new DummyComponent();
                    dummy2.name    = "gamedata.dummy1";
                    dummy2.OwnerId = spawn.ownerId;
                    dummy2.NetId   = spawn.children[1].netId;
                    dummy2.Deserialize(new HazelBinaryReader(spawn.children[1].body), true);
                    EntityTracker.Add(dummy2);
                    break;

                case 4:        //player character
                    var player = new PlayerControl();
                    player.OwnerId = spawn.ownerId;
                    player.NetId   = spawn.children[0].netId;
                    player.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(player);

                    player.dummy1         = new DummyComponent();
                    player.dummy1.name    = "player.dummy1";
                    player.dummy1.OwnerId = spawn.ownerId;
                    player.dummy1.NetId   = spawn.children[1].netId;
                    player.dummy1.Deserialize(new HazelBinaryReader(spawn.children[1].body), true);
                    EntityTracker.Add(player.dummy1);

                    player.transform         = new CustomNetworkTransform();
                    player.transform.OwnerId = spawn.ownerId;
                    player.transform.NetId   = spawn.children[2].netId;
                    player.transform.Deserialize(new HazelBinaryReader(spawn.children[2].body), true);
                    EntityTracker.Add(player.transform);
                    DumpToConsole(player);
                    break;

                case 5:        //HeadQuarters
                    var hq = new ShipStatus();
                    hq.OwnerId = spawn.ownerId;
                    hq.NetId   = spawn.children[0].netId;
                    hq.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(hq);
                    break;

                case 6:        //PlanetMap
                    var polus = new ShipStatus();
                    polus.OwnerId = spawn.ownerId;
                    polus.NetId   = spawn.children[0].netId;
                    polus.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(polus);
                    break;

                case 7:        //AprilShipStatus
                default:
                    Console.WriteLine($"Unhandled spawnid: {spawn.spawnId}");
                    break;
                }
                break;

            case GameDataType.SceneChange:
                var scene = SceneChange.Deserialize(reader);
                if (scene.sceneName == "OnlineGame")
                {
                    //Starting game
                }
                DumpToConsole(scene);
                break;

            case GameDataType.Despawn:
                var despawn = Despawn.Deserialize(reader);
                EntityTracker.entities.Remove(despawn.netId);
                LogToConsole("Despawn Netid: " + despawn.netId);
                break;

            case GameDataType.Ready:
                var ready = Ready.Deserialize(reader);
                Console.WriteLine($"Ready: " + ready.playerId);
                break;

            case GameDataType.ChangeSettings:
                var changesettings = ChangeSettings.Deserialize(reader);
                DumpToConsole(changesettings);
                break;

            default:
                Console.WriteLine($"Unhandled Gamedatatype: {datatype}");
                break;
            }

            if (reader.GetBytesLeft() > 0 && LogNotConsumed)
            {
                Console.WriteLine($"[{datatype}]{reader.GetBytesLeft()} bytes not cunsumed");
                reader.ReadBytesToEnd();
            }
        }