public void Read(ByteReader reader) { SessionId = reader.ReadInt32(); reader.MpContext().map = map; data = SyncSerialization.ReadSync <RitualData>(reader); data.assignments.session = this; }
private static Delegate ReadDelegate(ByteReader reader) { if (!reader.ReadBool()) { return(null); } var delegateType = SyncSerialization.ReadSync <Type>(reader); var type = SyncSerialization.ReadSync <Type>(reader); var methodName = SyncSerialization.ReadSync <string>(reader); object target = null; if (reader.ReadBool()) { var targetType = SyncSerialization.ReadSync <Type>(reader); var fieldPaths = GetFields(targetType).ToArray(); var fieldTypes = fieldPaths.Select(path => MpReflection.PathType(path)).ToArray(); target = Activator.CreateInstance(targetType); for (int i = 0; i < fieldPaths.Length; i++) { string path = fieldPaths[i]; string noTypePath = MpReflection.RemoveType(path); Type fieldType = fieldTypes[i]; object value; if (fieldType.IsCompilerGenerated()) { value = Activator.CreateInstance(fieldType); } else if (typeof(Delegate).IsAssignableFrom(fieldType)) { value = ReadDelegate(reader); } else { value = SyncSerialization.ReadSyncObject(reader, fieldType); } MpReflection.SetValue(target, path, value); } } return(Delegate.CreateDelegate( delegateType, target, AccessTools.Method(type, methodName) )); }
public static TempGameData SaveAndReload() { //SimpleProfiler.Start(); Multiplayer.reloading = true; var worldGridSaved = Find.WorldGrid; var worldRendererSaved = Find.World.renderer; var tweenedPos = new Dictionary <int, Vector3>(); var drawers = new Dictionary <int, MapDrawer>(); var localFactionId = Multiplayer.RealPlayerFaction.loadID; var mapCmds = new Dictionary <int, Queue <ScheduledCommand> >(); var planetRenderMode = Find.World.renderer.wantedMode; var chatWindow = ChatWindow.Opened; var selectedData = new ByteWriter(); SyncSerialization.WriteSync(selectedData, Find.Selector.selected.OfType <ISelectable>().ToList()); //Multiplayer.RealPlayerFaction = Multiplayer.DummyFaction; foreach (Map map in Find.Maps) { drawers[map.uniqueID] = map.mapDrawer; //RebuildRegionsAndRoomsPatch.copyFrom[map.uniqueID] = map.regionGrid; foreach (Pawn p in map.mapPawns.AllPawnsSpawned) { tweenedPos[p.thingIDNumber] = p.drawer.tweener.tweenedPos; } mapCmds[map.uniqueID] = map.AsyncTime().cmds; } mapCmds[ScheduledCommand.Global] = Multiplayer.WorldComp.cmds; DeepProfiler.Start("Multiplayer SaveAndReload: Save"); //WriteElementPatch.cachedVals = new Dictionary<string, object>(); //WriteElementPatch.id = 0; var gameData = SaveGameData(); DeepProfiler.End(); //Log.Message($"Saving took {WriteElementPatch.cachedVals.Count} {WriteElementPatch.cachedVals.FirstOrDefault()}"); MapDrawerRegenPatch.copyFrom = drawers; WorldGridCachePatch.copyFrom = worldGridSaved; WorldGridExposeDataPatch.copyFrom = worldGridSaved; WorldRendererCachePatch.copyFrom = worldRendererSaved; MusicManagerPlay musicManager = null; if (Find.MusicManagerPlay.gameObjectCreated) { var musicTransform = Find.MusicManagerPlay.audioSource.transform; if (musicTransform.parent == Find.Root.soundRoot.sourcePool.sourcePoolCamera.cameraSourcesContainer.transform) { musicTransform.parent = musicTransform.parent.parent; } musicManager = Find.MusicManagerPlay; } //SpawnSetupPatch.total = 0; //SpawnSetupPatch.total2 = new long[SpawnSetupPatch.total2.Length]; LoadInMainThread(gameData); if (musicManager != null) { Current.Root_Play.musicManagerPlay = musicManager; } Multiplayer.RealPlayerFaction = Find.FactionManager.GetById(localFactionId); foreach (Map m in Find.Maps) { foreach (Pawn p in m.mapPawns.AllPawnsSpawned) { if (tweenedPos.TryGetValue(p.thingIDNumber, out Vector3 v)) { p.drawer.tweener.tweenedPos = v; p.drawer.tweener.lastDrawFrame = Time.frameCount; } } m.AsyncTime().cmds = mapCmds[m.uniqueID]; } if (chatWindow != null) { Find.WindowStack.Add_KeepRect(chatWindow); } var selectedReader = new ByteReader(selectedData.ToArray()) { context = new MpContext() { map = Find.CurrentMap } }; Find.Selector.selected = SyncSerialization.ReadSync <List <ISelectable> >(selectedReader).AllNotNull().Cast <object>().ToList(); Find.World.renderer.wantedMode = planetRenderMode; Multiplayer.WorldComp.cmds = mapCmds[ScheduledCommand.Global]; Multiplayer.reloading = false; //SimpleProfiler.Pause(); //Log.Message($"allocs {(double)SpawnSetupPatch.total2.Sum() / Stopwatch.Frequency * 1000} ({SpawnSetupPatch.total2.Select((l,i) => $"{SpawnSetupPatch.methods[i]}: {(double)l / Stopwatch.Frequency * 1000}").Join(delimiter: "\n")}) {SpawnSetupPatch.total} {AllocsPrefixClass.allocs} {CustomXmlElement.n} {CustomXmlElement.m} {CustomXmlElement.n - CustomXmlElement.m} {(double)CustomXmlElement.n/CustomXmlElement.m}"); return(gameData); }