Пример #1
0
        private bool ReceiveWorldState(ArraySegment <byte> rawData)
        {
            InMemDriver stream = DeserializeWorldState(rawData);

            if (stream == null)
            {
                Logger.Error("Error during world state serialization. Abort.");
                return(false);
            }

            LoadGameResult loadResult = SaveLoad.LoadSaveGameData(stream);

            if (loadResult == null)
            {
                Logger.Error("Unable to load world state. Abort.");
                return(false);
            }

            if (loadResult.LoadResult.Successful)
            {
                Logger.Info(loadResult.ToFriendlyString());
            }
            else
            {
                Logger.Error(loadResult.ToFriendlyString());
            }

            GameLoopRunner.RunOnMainThread(() => SaveLoad.LoadGame(loadResult.LoadResult));
            return(true);
        }
Пример #2
0
        public byte[] SerializeInitialWorldState()
        {
            CampaignEventDispatcher.Instance.OnBeforeSave();

            // Save to memory
            InMemDriver memStream = new InMemDriver();
            SaveOutput  save      = null;

            GameLoopRunner.RunOnMainThread(
                () => save = SaveLoad.SaveGame(TaleWorlds.Core.Game.Current, memStream));
            Logger.Info(save.ToFriendlyString());

            // Write packet
            ByteWriter writer = new ByteWriter();

            writer.Binary.Write((int)ECommand.InitialWorldState);
            writer.Binary.Write(save.Data.GetData());
            return(writer.ToArray());
        }