public void InitializeLot() { CleanupLastWorld(); if (FSOEnvironment.Enable3D) { World = new FSO.LotView.RC.WorldRC(GameFacade.GraphicsDevice); } else { World = new FSO.LotView.World(GameFacade.GraphicsDevice); } World.Opacity = 1; GameFacade.Scenes.Add(World); var globalLink = new VMTSOGlobalLinkStub(); Driver = new VMServerDriver(globalLink); vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider()); vm.ListenBHAVChanges(); vm.Init(); LotControl = new UILotControl(vm, World); this.AddAt(0, LotControl); Frontend = new UISimitoneFrontend(this); this.Add(Frontend); var time = DateTime.UtcNow; var tsoTime = TSOTime.FromUTC(time); vm.Context.Clock.Hours = tsoTime.Item1; vm.Context.Clock.Minutes = tsoTime.Item2; if (m_ZoomLevel > 3) { World.Visible = false; LotControl.Visible = false; } ZoomLevel = Math.Max(ZoomLevel, 4); if (IDEHook.IDE != null) { IDEHook.IDE.StartIDE(vm); } vm.OnFullRefresh += VMRefreshed; //vm.OnEODMessage += LotControl.EODs.OnEODMessage; vm.OnRequestLotSwitch += VMLotSwitch; vm.OnGenericVMEvent += Vm_OnGenericVMEvent; }
public static FSOF RenderFSOF(byte[] fsov, GraphicsDevice gd) { var marshal = new VMMarshal(); using (var mem = new MemoryStream(fsov)) { marshal.Deserialize(new BinaryReader(mem)); } var world = new FSO.LotView.RC.WorldRC(gd); world.Opacity = 1; Layer.Add(world); var globalLink = new VMTSOGlobalLinkStub(); var driver = new VMServerDriver(globalLink); var vm = new VM(new VMContext(world), driver, new VMNullHeadlineProvider()); vm.Init(); vm.Load(marshal); SetOutsideTime(gd, vm, world, 0.5f, false); world.State.PrepareLighting(); var facade = new LotFacadeGenerator(); facade.FLOOR_TILES = 64; facade.GROUND_SUBDIV = 5; facade.FLOOR_RES_PER_TILE = 2; SetAllLights(vm, world, 0.5f, 0); var result = facade.GetFSOF(gd, world, vm.Context.Blueprint, () => { SetAllLights(vm, world, 0.0f, 100); }, true); Layer.Remove(world); world.Dispose(); vm.Context.Ambience.Kill(); foreach (var ent in vm.Entities) { //stop object sounds var threads = ent.SoundThreads; for (int i = 0; i < threads.Count; i++) { threads[i].Sound.RemoveOwner(ent.ObjectID); } threads.Clear(); } return(result); }
public VMServerDriver(int port, VMServerClosedHandler onShutdown) { listener = new Listener(EncryptionMode.NoEncryption); listener.Initialize(new IPEndPoint(IPAddress.Any, port)); listener.OnConnected += SendLotState; listener.OnDisconnected += LotDC; GlobalLink = new VMTSOGlobalLinkStub(); //final server will use DB hooked class ClientsToDC = new HashSet <NetworkClient>(); ClientsToSync = new HashSet <NetworkClient>(); QueuedCmds = new List <VMNetCommand>(); TickBuffer = new List <VMNetTick>(); ClientToUID = new Dictionary <NetworkClient, uint>(); UIDtoClient = new Dictionary <uint, NetworkClient>(); if (onShutdown != null) { OnShutdown += onShutdown; } SandboxBans = new BanList(); }
public FSOF RenderFSOF(byte[] fsov) { var marshal = new VMMarshal(); using (var mem = new MemoryStream(fsov)) { marshal.Deserialize(new BinaryReader(mem)); } var world = new FSO.LotView.RC.WorldRC(GameFacade.GraphicsDevice); world.Opacity = 1; GameFacade.Scenes.Add(world); var globalLink = new VMTSOGlobalLinkStub(); var driver = new VMServerDriver(globalLink); var vm = new VM(new VMContext(world), driver, new UIHeadlineRendererProvider()); vm.Init(); vm.Load(marshal); SetOutsideTime(GameFacade.GraphicsDevice, vm, world, 0.5f, false); world.State.PrepareLighting(); var facade = new LotFacadeGenerator(); facade.FLOOR_TILES = 64; facade.GROUND_SUBDIV = 5; facade.FLOOR_RES_PER_TILE = 2; SetAllLights(vm, world, 0.5f, 0); var result = facade.GetFSOF(GameFacade.GraphicsDevice, world, vm.Context.Blueprint, () => { SetAllLights(vm, world, 0.0f, 100); }, true); GameFacade.Scenes.Remove(world); world.Dispose(); return(result); }
public void InitializeLot(string lotName, bool external) { if (lotName == "") { return; } var recording = lotName.ToLowerInvariant().EndsWith(".fsor"); CleanupLastWorld(); Content.Content.Get().Upgrades.LoadJSONTuning(); if (FSOEnvironment.Enable3D) { var rc = new LotView.RC.WorldRC(GameFacade.GraphicsDevice); World = rc; } else { World = new World(GameFacade.GraphicsDevice); } World.Opacity = 1; GameFacade.Scenes.Add(World); var settings = GlobalSettings.Default; var myState = new VMNetAvatarPersistState() { Name = settings.LastUser, DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender), BodyOutfit = settings.DebugBody, HeadOutfit = settings.DebugHead, PersistID = (uint)(new Random()).Next(), SkinTone = (byte)settings.DebugSkin, Gender = (short)(settings.DebugGender ? 0 : 1), Permissions = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin, //CustomGUID = 0x396CD3D1, Budget = 1000000, }; if (recording) { var stream = new FileStream(lotName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var rd = new VMFSORDriver(stream); Driver = rd; } else if (external) { var cd = new VMClientDriver(ClientStateChange); SandCli = new FSOSandboxClient(); cd.OnClientCommand += (msg) => { SandCli.Write(new VMNetMessage(VMNetMessageType.Command, msg)); }; cd.OnShutdown += (reason) => SandCli.Disconnect(); SandCli.OnMessage += cd.ServerMessage; SandCli.Connect(lotName); Driver = cd; var dat = new MemoryStream(); var str = new BinaryWriter(dat); myState.SerializeInto(str); var ava = new VMNetMessage(VMNetMessageType.AvatarData, dat.ToArray()); dat.Close(); SandCli.OnConnectComplete += () => { SandCli.Write(ava); }; } else { var globalLink = new VMTSOGlobalLinkStub(); globalLink.Database = new SimAntics.Engine.TSOGlobalLink.VMTSOStandaloneDatabase(); var sd = new VMServerDriver(globalLink); SandServer = new FSOSandboxServer(); Driver = sd; sd.OnDropClient += SandServer.ForceDisconnect; sd.OnTickBroadcast += SandServer.Broadcast; sd.OnDirectMessage += SandServer.SendMessage; SandServer.OnConnect += sd.ConnectClient; SandServer.OnDisconnect += sd.DisconnectClient; SandServer.OnMessage += sd.HandleMessage; SandServer.Start((ushort)37564); } //Driver.OnClientCommand += VMSendCommand; //Driver.OnShutdown += VMShutdown; vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider()); vm.ListenBHAVChanges(); vm.Init(); LotControl = new UILotControl(vm, World); this.AddAt(0, LotControl); var time = DateTime.UtcNow; var tsoTime = TSOTime.FromUTC(time); vm.Context.Clock.Hours = tsoTime.Item1; vm.Context.Clock.Minutes = tsoTime.Item2; if (m_ZoomLevel > 3) { World.Visible = false; LotControl.Visible = false; } if (IDEHook.IDE != null) { IDEHook.IDE.StartIDE(vm); } vm.OnFullRefresh += VMRefreshed; vm.OnChatEvent += Vm_OnChatEvent; vm.OnEODMessage += LotControl.EODs.OnEODMessage; vm.OnRequestLotSwitch += VMLotSwitch; vm.OnGenericVMEvent += Vm_OnGenericVMEvent; if (!external && !recording) { if (!Downtown && ActiveFamily != null) { ActiveFamily.SelectWholeFamily(); vm.TS1State.ActivateFamily(vm, ActiveFamily); } BlueprintReset(lotName); var experimentalTuning = new Common.Model.DynamicTuning(new List <Common.Model.DynTuningEntry> { new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 15, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 5, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 6, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 7, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 8, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "overfill", tuning_table = 255, tuning_index = 9, value = 200 }, new Common.Model.DynTuningEntry() { tuning_type = "feature", tuning_table = 0, tuning_index = 0, value = 1 }, //ts1/tso engine animation timings (1.2x faster) }); vm.ForwardCommand(new VMNetTuningCmd { Tuning = experimentalTuning }); vm.TSOState.PropertyCategory = 255; //11 is community vm.TSOState.ActivateValidator(vm); vm.Context.Clock.Hours = 0; vm.TSOState.Size &= unchecked ((int)0xFFFF0000); vm.TSOState.Size |= (10) | (3 << 8); vm.Context.UpdateTSOBuildableArea(); if (vm.GetGlobalValue(11) > -1) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { vm.TSOState.Terrain.Roads[x, y] = 0xF; //crossroads everywhere } } VMLotTerrainRestoreTools.RestoreTerrain(vm); } var myClient = new VMNetClient { PersistID = myState.PersistID, RemoteIP = "local", AvatarState = myState }; var server = (VMServerDriver)Driver; server.ConnectClient(myClient); GameFacade.Cursor.SetCursor(CursorType.Normal); ZoomLevel = 1; } vm.MyUID = myState.PersistID; ZoomLevel = 1; }
public void InitializeLot(string lotName, bool external) { if (lotName == "") { return; } CleanupLastWorld(); World = new LotView.World(GameFacade.GraphicsDevice); World.Opacity = 1; GameFacade.Scenes.Add(World); if (external) { //external not yet implemented Driver = new VMClientDriver(ClientStateChange); } else { var globalLink = new VMTSOGlobalLinkStub(); Driver = new VMServerDriver(globalLink); } //Driver.OnClientCommand += VMSendCommand; //Driver.OnShutdown += VMShutdown; vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider()); vm.ListenBHAVChanges(); vm.Init(); LotControl = new UILotControl(vm, World); this.AddAt(0, LotControl); var time = DateTime.UtcNow; var tsoTime = TSOTime.FromUTC(time); vm.Context.Clock.Hours = tsoTime.Item1; vm.Context.Clock.Minutes = tsoTime.Item2; if (m_ZoomLevel > 3) { World.Visible = false; LotControl.Visible = false; } ZoomLevel = Math.Max(ZoomLevel, 4); if (IDEHook.IDE != null) { IDEHook.IDE.StartIDE(vm); } vm.OnFullRefresh += VMRefreshed; vm.OnChatEvent += Vm_OnChatEvent; vm.OnEODMessage += LotControl.EODs.OnEODMessage; vm.OnRequestLotSwitch += VMLotSwitch; vm.OnGenericVMEvent += Vm_OnGenericVMEvent; if (!external) { vm.ActivateFamily(ActiveFamily); BlueprintReset(lotName); vm.Context.Clock.Hours = 0; vm.TSOState.Size = (10) | (3 << 8); vm.Context.UpdateTSOBuildableArea(); vm.MyUID = 1; var settings = GlobalSettings.Default; var myClient = new VMNetClient { PersistID = 1, RemoteIP = "local", AvatarState = new VMNetAvatarPersistState() { Name = settings.LastUser, DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender), BodyOutfit = settings.DebugBody, HeadOutfit = settings.DebugHead, PersistID = 1, SkinTone = (byte)settings.DebugSkin, Gender = (short)(settings.DebugGender ? 1 : 0), Permissions = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin, Budget = 100000 } }; var server = (VMServerDriver)Driver; server.ConnectClient(myClient); GameFacade.Cursor.SetCursor(CursorType.Normal); ZoomLevel = 1; } }
public void InitializeLot(string lotName, bool external) { if (lotName == "") { return; } var recording = lotName.ToLowerInvariant().EndsWith(".fsor"); CleanupLastWorld(); if (FSOEnvironment.Enable3D) { var rc = new LotView.RC.WorldRC(GameFacade.GraphicsDevice); World = rc; } else { World = new World(GameFacade.GraphicsDevice); } World.Opacity = 1; GameFacade.Scenes.Add(World); var settings = GlobalSettings.Default; var myState = new VMNetAvatarPersistState() { Name = settings.LastUser, DefaultSuits = new VMAvatarDefaultSuits(settings.DebugGender), BodyOutfit = settings.DebugBody, HeadOutfit = settings.DebugHead, PersistID = (uint)(new Random()).Next(), SkinTone = (byte)settings.DebugSkin, Gender = (short)(settings.DebugGender ? 0 : 1), Permissions = SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin, Budget = 1000000, }; if (recording) { var stream = new FileStream(lotName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var rd = new VMFSORDriver(stream); Driver = rd; } else if (external) { var cd = new VMClientDriver(ClientStateChange); SandCli = new FSOSandboxClient(); cd.OnClientCommand += (msg) => { SandCli.Write(new VMNetMessage(VMNetMessageType.Command, msg)); }; cd.OnShutdown += (reason) => SandCli.Disconnect(); SandCli.OnMessage += cd.ServerMessage; SandCli.Connect(lotName); Driver = cd; var dat = new MemoryStream(); var str = new BinaryWriter(dat); myState.SerializeInto(str); var ava = new VMNetMessage(VMNetMessageType.AvatarData, dat.ToArray()); dat.Close(); SandCli.OnConnectComplete += () => { SandCli.Write(ava); }; } else { var globalLink = new VMTSOGlobalLinkStub(); var sd = new VMServerDriver(globalLink); SandServer = new FSOSandboxServer(); Driver = sd; sd.OnDropClient += SandServer.ForceDisconnect; sd.OnTickBroadcast += SandServer.Broadcast; sd.OnDirectMessage += SandServer.SendMessage; SandServer.OnConnect += sd.ConnectClient; SandServer.OnDisconnect += sd.DisconnectClient; SandServer.OnMessage += sd.HandleMessage; SandServer.Start((ushort)37564); } //Driver.OnClientCommand += VMSendCommand; //Driver.OnShutdown += VMShutdown; vm = new VM(new VMContext(World), Driver, new UIHeadlineRendererProvider()); vm.ListenBHAVChanges(); vm.Init(); LotControl = new UILotControl(vm, World); this.AddAt(0, LotControl); var time = DateTime.UtcNow; var tsoTime = TSOTime.FromUTC(time); vm.Context.Clock.Hours = tsoTime.Item1; vm.Context.Clock.Minutes = tsoTime.Item2; if (m_ZoomLevel > 3) { World.Visible = false; LotControl.Visible = false; } if (IDEHook.IDE != null) { IDEHook.IDE.StartIDE(vm); } vm.OnFullRefresh += VMRefreshed; vm.OnChatEvent += Vm_OnChatEvent; vm.OnEODMessage += LotControl.EODs.OnEODMessage; vm.OnRequestLotSwitch += VMLotSwitch; vm.OnGenericVMEvent += Vm_OnGenericVMEvent; if (!external && !recording) { if (!Downtown && ActiveFamily != null) { ActiveFamily.SelectWholeFamily(); vm.ActivateFamily(ActiveFamily); } BlueprintReset(lotName); vm.TSOState.PropertyCategory = 255; vm.Context.Clock.Hours = 0; vm.TSOState.Size = (10) | (3 << 8); vm.Context.UpdateTSOBuildableArea(); var myClient = new VMNetClient { PersistID = myState.PersistID, RemoteIP = "local", AvatarState = myState }; var server = (VMServerDriver)Driver; server.ConnectClient(myClient); GameFacade.Cursor.SetCursor(CursorType.Normal); ZoomLevel = 1; } vm.MyUID = myState.PersistID; ZoomLevel = 1; }