public void ExitLot()
 {
     CleanupLastWorld();
     NeighSelection(NeighSelectionMode.Normal);
     Downtown = false;
     SavedLot = null;
 }
Example #2
0
 public override void Deserialize(BinaryReader reader)
 {
     State = new VMMarshal();
     State.Deserialize(reader);
     if (reader.ReadBoolean())
     {
         Trace = new VMSyncTraceTick();
         Trace.Deserialize(reader);
     }
 }
        public override bool Execute(VM vm)
        {
            //the client should ignore these. Can be sent before state sync when joining job lots (by accident)
            if (!vm.BlueprintRestore)
            {
                return(true);
            }

            vm.SetGlobalValue(11, JobLevel); //set job level beforehand

            if (IffData)
            {
                var iff = new IffFile();
                using (var stream = new MemoryStream(XMLData))
                {
                    iff.Read(stream);
                }
                var fsov = iff.List <FSOV>()?.FirstOrDefault();
                if (fsov != null)
                {
                    var marshal = new VMMarshal();
                    using (var read = new BinaryReader(new MemoryStream(fsov.Data)))
                        marshal.Deserialize(read);
                    vm.Load(marshal);
                }
                else
                {
                    var activator = new VMTS1Activator(vm, vm.Context.World, JobLevel);
                    var blueprint = activator.LoadFromIff(iff);
                }
                vm.TS1State.VerifyFamily(vm);
            }
            else
            {
                XmlHouseData lotInfo;
                using (var stream = new MemoryStream(XMLData))
                {
                    lotInfo = XmlHouseData.Parse(stream);
                }

                var activator = new VMWorldActivator(vm, vm.Context.World);
                activator.FloorClip  = new Microsoft.Xna.Framework.Rectangle(FloorClipX, FloorClipY, FloorClipWidth, FloorClipHeight);
                activator.Offset     = new Microsoft.Xna.Framework.Point(OffsetX, OffsetY);
                activator.TargetSize = TargetSize;
                var blueprint = activator.LoadFromXML(lotInfo);
            }

            /*if (VM.UseWorld)
             * {
             *  vm.Context.World.InitBlueprint(blueprint);
             *  vm.Context.Blueprint = blueprint;
             * }*/

            return(true);
        }
Example #4
0
 public void LoadState(VM vm, string path)
 {
     using (var file = new BinaryReader(File.OpenRead(path)))
     {
         var marshal = new VMMarshal();
         marshal.Deserialize(file);
         vm.Load(marshal);
         CleanLot();
         vm.Reset();
     }
 }
Example #5
0
 public override void Deserialize(BinaryReader reader)
 {
     State = new VMMarshal();
     using (var decomp = new GZipStream(reader.BaseStream, CompressionMode.Decompress))
     {
         using (var bin = new BinaryReader(decomp))
         {
             State.Deserialize(bin);
         }
     }
 }
Example #6
0
        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);
        }
Example #7
0
 public override void Deserialize(BinaryReader reader)
 {
     State = new VMMarshal();
     State.Deserialize(reader);
     if (reader.ReadBoolean())
     {
         Traces = new List <VMSyncTraceTick>();
         var total = reader.ReadInt32();
         for (int i = 0; i < total; i++)
         {
             var trace = new VMSyncTraceTick();
             trace.Deserialize(reader);
             Traces.Add(trace);
         }
     }
 }
Example #8
0
        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);
        }
Example #9
0
        public void InitializeLot(VMMarshal marshal)
        {
            InitializeLot();
            vm.MyUID = 1;
            vm.Load(marshal);

            vm.TS1State.ActivateFamily(vm, ActiveFamily);

            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  = FSO.SimAntics.Model.TSOPlatform.VMTSOAvatarPermissions.Admin,
                    Budget       = 1000000
                }
            };

            var server = (VMServerDriver)Driver;

            server.ConnectClient(myClient);

            GameFacade.Cursor.SetCursor(CursorType.Normal);
            ZoomLevel = 1;

            Frontend = new UISimitoneFrontend(this);
            this.Add(Frontend);
        }
Example #10
0
        public void Load(VMMarshal input)
        {
            var clientJoin = (Context.Architecture == null);
            var oldWorld   = Context.World;

            Context         = new VMContext(input.Context, Context);
            Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
            Context.VM      = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            var oldSounds = new List <VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null)
                    {
                        obj.HeadlineRenderer.Dispose();
                    }
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            Entities    = new List <VMEntity>();
            ObjectsById = new Dictionary <short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.GenerateTreeByName(Context);
                Entities.Add(realEnt);
                Context.SetToNextCache.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            GlobalState   = input.GlobalState;
            PlatformState = input.PlatformState;
            ObjectId      = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.WallDirtyState(input.Context.Architecture);

            foreach (var snd in oldSounds)
            {
                //find new owners
                var obj = GetObjectById(snd.SourceID);
                if (obj == null || obj.Object.GUID != snd.SourceGUID)
                {
                    snd.SFX.Sound.RemoveOwner(snd.SourceID);
                }
                else
                {
                    obj.SoundThreads.Add(snd.SFX);  // successfully transfer sound to new object
                }
            }

            if (clientJoin)
            {
                //run clientJoin functions to play object sounds, update some gfx.
                foreach (var obj in Entities)
                {
                    obj.ExecuteEntryPoint(30, Context, true);
                }
            }

            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }
Example #11
0
        //variables for rotation transform

        public VMLotRotate(VMMarshal marshal)
        {
            Arch = marshal.Context.Architecture;
            Ents = marshal.Entities;
        }
 public override void Deserialize(BinaryReader reader)
 {
     State = new VMMarshal();
     State.Deserialize(reader);
 }
Example #13
0
        public void LoadAsync(VMMarshal input)
        {
            FSOVAsyncLoading = true;
            var lastBp = Context.Blueprint; //try keep this alive I suppose

            //var oldWorld = Context.World;
            //TS1 = input.TS1;
            Context    = new VMContext(input.Context, Context);
            Context.VM = this;
            var idMap = input.Context.Architecture.IDMap;

            if (idMap != null)
            {
                idMap.Apply(this);
            }
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.Terrain.RegenerateCenters();

            if (VM.UseWorld)
            {
                Context.Blueprint.Altitude        = Context.Architecture.Terrain.Heights;
                Context.Blueprint.AltitudeCenters = Context.Architecture.Terrain.Centers;
            }

            var oldSounds = new List <VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null)
                    {
                        if (UseWorld)
                        {
                            GameThread.InUpdate(() =>
                            {
                                obj.HeadlineRenderer.Dispose();
                            });
                        }
                    }
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            SoundEntities = new HashSet <VMEntity>();
            Entities      = new List <VMEntity>();
            Scheduler.Reset();
            ObjectsById  = new Dictionary <short, VMEntity>();
            FSOVObjTotal = input.Entities.Length;
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (objDefinition == null)
                {
                    LoadErrors.Add(new VMLoadError(VMLoadErrorCode.MISSING_OBJECT,
                                                   "0x" + ent.GUID.ToString("X8") + " " + input.MultitileGroups.FirstOrDefault(x => x.Objects.Contains(ent.ObjectID))?.Name ?? "(unknown name)", (ushort)ent.ObjectID));
                    ent.LoadFailed = true;
                    continue;
                }
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = Context.MakeObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                        Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    }
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.FetchTreeByName(Context);
                Entities.Add(realEnt);
                Context.ObjectQueries.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
                FSOVObjLoaded++;
            }

            int i = 0;
            int j = 0;

            foreach (var ent in input.Entities)
            {
                if (ent.LoadFailed)
                {
                    i++;
                    continue;
                }
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[j++];
                i++;

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);
                Scheduler.ScheduleTickIn(realEnt, 1);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                var grp = new VMMultitileGroup(multi, Context); //should self register
                if (VM.UseWorld)
                {
                    var b      = grp.BaseObject;
                    var avgPos = new LotTilePos();
                    foreach (var obj in grp.Objects)
                    {
                        avgPos += obj.Position;
                    }
                    avgPos /= Math.Max(grp.Objects.Count, 1);

                    foreach (var obj in grp.Objects)
                    {
                        var off = obj.Position - avgPos;
                        obj.WorldUI.MTOffset = new Vector3(off.x, off.y, 0);
                        obj.Position         = obj.Position;
                    }
                }
                var persist = grp.BaseObject?.PersistID ?? 0;
                if (persist != 0 && grp.BaseObject is VMGameObject)
                {
                    Context.ObjectQueries.RegisterMultitilePersist(grp, persist);
                }
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            GlobalState = input.GlobalState;
            if (TS1)
            {
                ((VMTS1LotState)input.PlatformState).CurrentFamily = TS1State.CurrentFamily;
            }
            var lastPlatformState = PlatformState;

            PlatformState = input.PlatformState;
            PlatformState.ActivateValidator(this);
            if (lastPlatformState != null && lastPlatformState is VMTSOLotState)
            {
                TSOState.Names = ((VMTSOLotState)lastPlatformState).Names;
            }
            ObjectId = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay();

            Context.Architecture.SignalAllDirty();
            Context.DisableRouteInvalidation = true;
            Context.Architecture.Tick();
            Context.DisableRouteInvalidation = false;

            Context.Architecture.WallDirtyState(input.Context.Architecture);

            if (oldSounds.Count > 0)
            {
                GameThread.InUpdate(() =>
                {
                    foreach (var snd in oldSounds)
                    {
                        //find new owners
                        var obj = GetObjectById(snd.SourceID);
                        if (obj == null || obj.Object.GUID != snd.SourceGUID)
                        {
                            snd.SFX.Sound.RemoveOwner(snd.SourceID);
                        }
                        else
                        {
                            SoundEntities.Add(obj);
                            obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object
                        }
                    }
                });
            }

            Context.UpdateTSOBuildableArea();
            Tuning = input.Tuning;
            UpdateTuning();
            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }
Example #14
0
        public int Run()
        {
            if (Options.RestoreFolder == null)
            {
                Console.WriteLine("Please pass: <shard id> <lot folder path>");
                return(1);
            }
            Console.WriteLine("Scanning content, please wait...");

            VMContext.InitVMConfig(false);
            Content.Content.Init(Config.GameLocation, Content.ContentMode.SERVER);

            Console.WriteLine($"Starting property restore - scanning { Options.RestoreFolder }...");

            if (!Directory.Exists(Options.RestoreFolder))
            {
                Console.WriteLine($"Could not find the given directory: { Options.RestoreFolder }");
                return(1);
            }

            var files = Directory.EnumerateFiles(Options.RestoreFolder).Where(x => x.ToLowerInvariant().EndsWith(".fsov")).ToList();

            if (files.Count == 0)
            {
                Console.WriteLine($"Specified folder did not contain any lot saves (*.fsov). Note that blueprint .xmls are not supported.");
                return(1);
            }

            using (var da = DAFactory.Get())
            {
                foreach (var file in files)
                {
                    Console.WriteLine($"===== { Path.GetFileName(file) } =====");

                    var data = File.ReadAllBytes(file);

                    var           vm = new VMMarshal();
                    VMTSOLotState state;
                    try
                    {
                        using (var mem = new MemoryStream(data))
                        {
                            vm.Deserialize(new BinaryReader(mem));
                        }
                        state = (VMTSOLotState)vm.PlatformState;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Could not read FSOV. ({e.Message}) Continuing...");
                        continue;
                    }

                    var lot = new DbLot();
                    lot.name        = state.Name;
                    lot.location    = state.LotID;
                    lot.description = "Restored from FSOV";
                    if (state.PropertyCategory == 255)
                    {
                        state.PropertyCategory = 11;
                    }
                    lot.category        = (LotCategory)state.PropertyCategory;
                    lot.owner_id        = RemapAvatarID(da, state.OwnerID);
                    lot.neighborhood_id = state.NhoodID;
                    lot.ring_backup_num = 0;
                    lot.shard_id        = Options.ShardId;
                    lot.skill_mode      = state.SkillMode;
                    var random = new Random();

                    OwnerID = lot.owner_id ?? 0;
                    if (lot.owner_id == 0)
                    {
                        lot.owner_id = null;
                    }

                    Console.WriteLine($"Attempting to restore '{state.Name}', at location {lot.location}.");
                    var originalName = lot.name;
                    int addedOffset  = 1;
                    var existingName = da.Lots.GetByName(lot.shard_id, lot.name);
                    while (existingName != null)
                    {
                        lot.name = originalName + " (" + (addedOffset++) + ")";
                        Console.WriteLine($"Lot already exists with name {originalName}. Trying with name {lot.name}.");
                        existingName = da.Lots.GetByName(lot.shard_id, lot.name);
                    }

                    var existingLocation = da.Lots.GetByLocation(Options.ShardId, lot.location);
                    while (existingLocation != null)
                    {
                        lot.location = (uint)(random.Next(512) | (random.Next(512) << 16));
                        Console.WriteLine($"Lot already exists at location {existingLocation.location}. Placing at random location {lot.location}.");
                        existingLocation = da.Lots.GetByLocation(Options.ShardId, lot.location);
                    }

                    var objectFromInventory = 0;
                    var objectFromLot       = 0;
                    var objectCreate        = 0;
                    var objectIgnore        = 0;

                    string lotFolder = "./";
                    if (!Options.Report)
                    {
                        Console.WriteLine($"Creating database entry for lot...");
                        try
                        {
                            lot.lot_id = (int)da.Lots.Create(lot);
                            Console.WriteLine($"Database entry for lot created! (ID {lot.lot_id})");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("FATAL! Could not create lot in database.");
                            Console.WriteLine(e.ToString());
                            continue;
                        }

                        Console.WriteLine($"Creating and populating data folder for lot...");
                        try
                        {
                            lotFolder = Path.Combine(Config.SimNFS, $"Lots/{lot.lot_id.ToString("x8")}/");
                            Directory.CreateDirectory(lotFolder);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("FATAL! Could not create lot data in NFS.");
                            Console.WriteLine(e.ToString());
                            continue;
                        }
                    }

                    foreach (var obj in vm.Entities)
                    {
                        var estate = obj.PlatformState as VMTSOObjectState;
                        if (estate != null)
                        {
                            estate.OwnerID = RemapAvatarID(da, estate.OwnerID); //make sure the owners exist
                        }
                    }

                    //check the objects
                    var processed = new HashSet <uint>();
                    foreach (var obj in vm.Entities)
                    {
                        if (obj.PersistID == 0 || processed.Contains(obj.PersistID) || obj is VMAvatarMarshal)
                        {
                            if (PersistRemap.ContainsKey(obj.PersistID))
                            {
                                obj.PersistID = PersistRemap[obj.PersistID];
                            }
                            continue;
                        }
                        processed.Add(obj.PersistID);

                        try
                        {
                            //does this object exist in the database?
                            var dbObj = da.Objects.Get(obj.PersistID);
                            var guid  = (obj.MasterGUID == 0) ? obj.GUID : obj.MasterGUID;
                            if (dbObj == null)
                            {
                                Console.Write("++");
                                Console.Write(guid);
                                Console.Write(": Does not exist in DB. Creating new entry...");
                                objectCreate++;
                                CreateDbObject(da, obj, lot);
                                Done();
                            }
                            else
                            {
                                if (dbObj.lot_id != null)
                                {
                                    Console.Write("!!");
                                    Console.Write(dbObj.dyn_obj_name ?? dbObj.type.ToString());
                                    Console.Write(": In another property! ");
                                    if (Options.Safe || Options.Objects)
                                    {
                                        if (Options.Objects)
                                        {
                                            Console.Write("Creating a new entry...");
                                            objectCreate++;
                                            CreateDbObject(da, obj, lot);
                                            Done();
                                        }
                                        else
                                        {
                                            Console.WriteLine("Object will be ignored.");
                                            objectIgnore++;
                                        }
                                    }
                                    else
                                    {
                                        Console.Write("Taking the object back...");
                                        objectFromLot++;
                                        if (!Options.Report)
                                        {
                                            da.Objects.SetInLot(obj.PersistID, (uint)lot.lot_id);
                                        }
                                        Done();
                                    }
                                }
                                else
                                {
                                    Console.Write("~~");
                                    Console.Write(dbObj.dyn_obj_name ?? dbObj.type.ToString());
                                    Console.Write(": In a user's inventory. ");
                                    if (dbObj.type != guid)
                                    {
                                        Console.Write("(WRONG GUID - MAKING NEW OBJECT) ");
                                    }
                                    if (Options.Objects || dbObj.type != guid)
                                    {
                                        Console.Write("Creating a new entry...");
                                        objectCreate++;
                                        CreateDbObject(da, obj, lot);
                                        Done();
                                    }
                                    else
                                    {
                                        Console.Write("Taking the object back...");
                                        objectFromInventory++;
                                        if (!Options.Report)
                                        {
                                            da.Objects.SetInLot(obj.PersistID, (uint)lot.lot_id);
                                        }
                                        Done();
                                    }
                                }
                            }
                        } catch (Exception e)
                        {
                            Console.WriteLine($"Failed - {e.Message}. Continuing...");
                        }
                    }

                    Console.WriteLine($"Objects created: {objectCreate}, Objects from inventory: {objectFromInventory}, Objects from other lot: {objectFromLot}, Objects ignored: {objectIgnore}");
                    Console.WriteLine($"Object/lot owner avatars missing (replaced with lot owner): {AvatarIDs.Count(x => x.Key != x.Value)}");
                    Console.WriteLine("Object scan complete! Serializing restored state...");
                    byte[] newData;
                    using (var mem = new MemoryStream())
                    {
                        using (var writer = new BinaryWriter(mem))
                        {
                            vm.SerializeInto(writer);
                            newData = mem.ToArray();
                        }
                    }
                    Console.WriteLine("New FSOV created. Finalizing restore...");

                    if (!Options.Report)
                    {
                        File.WriteAllBytes(Path.Combine(lotFolder, "state_0.fsov"), newData);
                        Console.WriteLine($"Restoring {Path.GetFileName(file)} complete!");
                        da.Lots.UpdateRingBackup(lot.lot_id, 0);
                    }
                    else
                    {
                        Console.WriteLine($"Report for {Path.GetFileName(file)} complete!");
                    }
                }
            }
            Console.WriteLine("All properties processed. Press any key to exit.");
            Console.ReadKey();
            return(0);
        }
Example #15
0
        public void Load(VMMarshal input)
        {
            var clientJoin = (Context.Architecture == null);

            //var oldWorld = Context.World;
            Context    = new VMContext(input.Context, Context);
            Context.VM = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.Terrain.RegenerateCenters();

            if (VM.UseWorld)
            {
                Context.Blueprint.Altitude        = Context.Architecture.Terrain.Heights;
                Context.Blueprint.AltitudeCenters = Context.Architecture.Terrain.Centers;
            }

            var oldSounds = new List <VMSoundTransfer>();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    obj.Dead = true;
                    if (obj.HeadlineRenderer != null)
                    {
                        obj.HeadlineRenderer.Dispose();
                    }
                    oldSounds.AddRange(obj.GetActiveSounds());
                }
            }

            Entities = new List <VMEntity>();
            Scheduler.Reset();
            ObjectsById = new Dictionary <short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = Context.MakeObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                        Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    }
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.FetchTreeByName(Context);
                Entities.Add(realEnt);
                Context.ObjectQueries.NewObject(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);
                Scheduler.ScheduleTickIn(realEnt, 1);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                var grp = new VMMultitileGroup(multi, Context); //should self register
                if (VM.UseWorld)
                {
                    var b      = grp.BaseObject;
                    var avgPos = new LotTilePos();
                    foreach (var obj in grp.Objects)
                    {
                        avgPos += obj.Position;
                    }
                    avgPos /= grp.Objects.Count;

                    foreach (var obj in grp.Objects)
                    {
                        var off = obj.Position - avgPos;
                        obj.WorldUI.MTOffset = new Vector3(off.x, off.y, 0);
                        obj.Position         = obj.Position;
                    }
                }
                var persist = grp.BaseObject?.PersistID ?? 0;
                if (persist != 0 && grp.BaseObject is VMGameObject)
                {
                    Context.ObjectQueries.RegisterMultitilePersist(grp, persist);
                }
            }

            foreach (var ent in Entities)
            {
                if (ent.Container == null)
                {
                    ent.PositionChange(Context, true);                        //called recursively for contained objects.
                }
            }

            GlobalState   = input.GlobalState;
            PlatformState = input.PlatformState;
            ObjectId      = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.SignalAllDirty();
            Context.DisableRouteInvalidation = true;
            Context.Architecture.Tick();
            Context.DisableRouteInvalidation = false;

            Context.Architecture.WallDirtyState(input.Context.Architecture);

            foreach (var snd in oldSounds)
            {
                //find new owners
                var obj = GetObjectById(snd.SourceID);
                if (obj == null || obj.Object.GUID != snd.SourceGUID)
                {
                    snd.SFX.Sound.RemoveOwner(snd.SourceID);
                }
                else
                {
                    obj.SoundThreads.Add(snd.SFX);  // successfully transfer sound to new object
                }
            }

            if (clientJoin)
            {
                //run clientJoin functions to play object sounds, update some gfx.
                foreach (var obj in Entities)
                {
                    obj.ExecuteEntryPoint(30, Context, true);
                }
            }
            Context.UpdateTSOBuildableArea();
            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }
Example #16
0
        public void Load(VMMarshal input)
        {
            var oldWorld = Context.World;

            Context         = new VMContext(input.Context, Context);
            Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global");
            Context.VM      = this;
            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();

            if (Entities != null) //free any object resources here.
            {
                foreach (var obj in Entities)
                {
                    if (obj.HeadlineRenderer != null)
                    {
                        obj.HeadlineRenderer.Dispose();
                    }
                }
            }

            Entities    = new List <VMEntity>();
            ObjectsById = new Dictionary <short, VMEntity>();
            foreach (var ent in input.Entities)
            {
                VMEntity realEnt;
                var      objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID);
                if (ent is VMAvatarMarshal)
                {
                    var avatar = new VMAvatar(objDefinition);
                    avatar.Load((VMAvatarMarshal)ent);
                    if (UseWorld)
                    {
                        Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI);
                    }
                    realEnt = avatar;
                }
                else
                {
                    var worldObject = new ObjectComponent(objDefinition);
                    var obj         = new VMGameObject(objDefinition, worldObject);
                    obj.Load((VMGameObjectMarshal)ent);
                    Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI);
                    Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position);
                    obj.Position = obj.Position;
                    realEnt      = obj;
                }
                realEnt.GenerateTreeByName(Context);
                Entities.Add(realEnt);
                ObjectsById.Add(ent.ObjectID, realEnt);
            }

            int i = 0;

            foreach (var ent in input.Entities)
            {
                var threadMarsh = input.Threads[i];
                var realEnt     = Entities[i++];

                realEnt.Thread = new VMThread(threadMarsh, Context, realEnt);

                if (realEnt is VMAvatar)
                {
                    ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context);
                }
                else
                {
                    ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context);
                }
            }

            foreach (var multi in input.MultitileGroups)
            {
                new VMMultitileGroup(multi, Context); //should self register
            }

            foreach (var ent in Entities)
            {
                ent.PositionChange(Context, true);
            }

            GlobalState = input.GlobalState;
            ObjectId    = input.ObjectId;

            //just a few final changes to refresh everything, and avoid signalling objects
            var clock = Context.Clock;

            Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60));

            Context.Architecture.RegenRoomMap();
            Context.RegeneratePortalInfo();
            Context.Architecture.WallDirtyState(input.Context.Architecture);

            if (OnFullRefresh != null)
            {
                OnFullRefresh();
            }
        }