Esempio n. 1
0
 private bool InventoryEmpty(SaveComponent inventoryComponent)
 {
     for (int i = 0; i < inventoryComponent.DataFields.Count; i++)
     {
         if (inventoryComponent.DataFields[i].PropertyName == "mInventoryStacks")
         {
             ArrayProperty inventoryArray = (ArrayProperty)inventoryComponent.DataFields[i];
             for (int j = 0; j < ((ArrayProperty)inventoryComponent.DataFields[i]).Elements.Count; j++)
             {
                 StructProperty    inventoryStruct = (StructProperty)inventoryArray.Elements[j];
                 DynamicStructData inventoryItem   = (DynamicStructData)inventoryStruct.Data;
                 for (int k = 0; k < inventoryItem.Fields.Count; k++)
                 {
                     if (inventoryItem.Fields[k].PropertyName == "NumItems")
                     {
                         IntProperty itemCount = (IntProperty)inventoryItem.Fields[k];
                         if (itemCount.Value != 0)
                         {
                             return(false);
                         }
                     }
                 }
             }
             return(true);
         }
     }
     return(true);
 }
        public bool Apply(SaveObjectModel rootItem)
        {
            var players = rootItem.FindChild("Char_Player.Char_Player_C", false);

            if (players == null)
            {
                MessageBox.Show("This save does not contain a Player.\nThis means that the loaded save is probably corrupt. Aborting.", "Cannot find Player", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            int currentStorageID = 0;

            foreach (SaveObjectModel player in players.DescendantSelfViewModel)
            {
                string          inventoryPath      = player.FindField <ObjectPropertyViewModel>("mInventory").Str2;
                SaveObjectModel inventoryState     = rootItem.FindChild(inventoryPath, false);
                SaveComponent   inventoryComponent = (SaveComponent)inventoryState.Model;
                currentStorageID = GetNextStorageID(currentStorageID, rootItem);
                SaveComponent newInventory = new SaveComponent(inventoryComponent.TypePath, inventoryComponent.RootObject, $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
                {
                    ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                    DataFields       = inventoryComponent.DataFields
                };
                rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
                SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
                {
                    NeedTransform = true,
                    Rotation      = ((SaveEntity)player.Model).Rotation,
                    Position      = ((SaveEntity)player.Model).Position,
                    Scale         = new SatisfactorySaveParser.Structures.Vector3()
                    {
                        X = 1, Y = 1, Z = 1
                    },
                    WasPlacedInLevel = false,
                    ParentObjectName = "",
                    ParentObjectRoot = ""
                };
                newSaveObject.DataFields = new SerializedFields();
                newSaveObject.DataFields.Add(new ObjectProperty("mInventory", 0)
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                });
                rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(new SaveEntityModel(newSaveObject));
                rootItem.Remove(player);
                rootItem.Remove(inventoryState);
                MessageBox.Show($"Killed {player.Title}.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            return(true);
        }
Esempio n. 3
0
        public SaveManager(SceneManager sceneManager, SaveComponent saveComponent)
        {
            m_currentData    = new SaveData();
            m_sceneManager   = sceneManager;
            m_saveSlotPrefab = saveComponent.GetSaveSlotPrefab();
            m_savePanel      = saveComponent.GetSavePanel();
            m_saveContent    = saveComponent.GetSaveContent();

            int numberOfSaves = saveComponent.GetNumberOfSaves();

            m_gameData = LoadGameData();

            if (m_gameData == null)
            {
                m_gameData = new GameData(numberOfSaves);
            }

            InitSaveLoadSlots(numberOfSaves);
        }
            public SaveManager(SceneManager sceneManager, SaveComponent saveComponent)
            {
                m_sceneManager = sceneManager;

                m_saveSlotPrefab = saveComponent.GetSaveSlotPrefab();
                m_savePanel      = saveComponent.GetSavePanel();
                m_saveContent    = saveComponent.GetSaveContent();

                int numberOfSaves = saveComponent.GetNumberOfSaves();

                // load game data
                m_gameData = LoadGameData();

                // init game data if necessary
                if (m_gameData == null)
                {
                    m_gameData = new GameData(numberOfSaves);
                }

                InitSaveLoadSlots(numberOfSaves);
            }
Esempio n. 5
0
    // Start is called before the first frame update
    void Start()
    {
        uIEvent       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <UIEvent>();
        ui            = GameObject.FindGameObjectWithTag("ItemCells").GetComponent <UIManagaer>();
        life          = GetComponentInChildren <Life>();
        movement      = GetComponent <Movement>();
        pickableItems = new List <GameObject>();
        gameObject.SetActive(true);

        GameObject g_data   = GameObject.FindGameObjectWithTag("DataPool");
        DataPool   dataPool = g_data.GetComponent <DataPool>();

        dic_itemsIns = dataPool.dic_itemsIns;
        dic_items    = dataPool.dic_items;

        //初始化已有的背包装备
        sc = new SaveComponent();
        il = new List <Item>();
        for (int i = 0; i < bagVolume; i++)
        {
            il.Add(new Item("empty", i));
        }

        dic_myItem = new Dictionary <string, Item>();
        List <Item> originBag = sc.loadByJson <List <Item> >("a");

        foreach (Item item in originBag)
        {
            enterBag(item);
        }


        GameObject g = GameObject.FindGameObjectWithTag("tag");

        grid = g.GetComponent <Grid>();
        map  = g.GetComponentInChildren <Tilemap>();
        tm   = g.GetComponentInChildren <TileManager>();
    }
        public bool Apply(SaveObjectModel rootItem)
        {
            BuildPolygon();
            if (polygon.Length < 2)
            {
                MessageBox.Show("At least 2 points needed to mass dismantle", "Could not mass dismantle", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            ArrayProperty inventory = new ArrayProperty("mInventoryStacks")
            {
                Type = "StructProperty"
            };
            int countFactory = 0, countBuilding = 0, countCrate = 0;

            try
            {
                countFactory = MassDismantle(rootItem.FindChild("Buildable", true).FindChild("Factory", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            try
            {
                countBuilding = MassDismantle(rootItem.FindChild("Buildable", true).FindChild("Building", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            try
            {
                countCrate = MassDismantle(rootItem.FindChild("-Shared", true).FindChild("BP_Crate.BP_Crate_C", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            if (countFactory + countBuilding + countCrate == 0)
            {
                MessageBox.Show("Nothing was dismantled. Make sure the coordinates are correct and in clockwise order.", "Mass dismantle", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            MessageBoxResult result = MessageBox.Show($"Dismantled {countFactory} factory buildings, {countBuilding} foundations and {countCrate} crates. Drop the items (including items in storages) in a single crate?", "Dismantled", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                inventory = ArrangeInventory(inventory);
                int           currentStorageID = GetNextStorageID(0, rootItem);
                SaveComponent newInventory     = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
                {
                    ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                    DataFields       = new SerializedFields()
                    {
                        inventory,
                        new ArrayProperty("mArbitrarySlotSizes")
                        {
                            Type     = "IntProperty",
                            Elements = Enumerable.Repeat(new IntProperty("Element")
                            {
                                Value = 0
                            }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                        },
                        new ArrayProperty("mAllowedItemDescriptors")
                        {
                            Type     = "ObjectProperty",
                            Elements = Enumerable.Repeat(new ObjectProperty("Element")
                            {
                                LevelName = "", PathName = ""
                            }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                        },
                        new BoolProperty("mCanBeRearrange")
                        {
                            Value = false
                        }
                    }
                };
                rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
                SaveEntity player        = (SaveEntity)rootItem.FindChild("Char_Player.Char_Player_C", false).DescendantSelf[0];
                SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
                {
                    NeedTransform = true,
                    Rotation      = player.Rotation,
                    Position      = new Vector3()
                    {
                        X = player.Position.X, Y = player.Position.Y + 100, Z = player.Position.Z
                    },
                    Scale = new Vector3()
                    {
                        X = 1, Y = 1, Z = 1
                    },
                    WasPlacedInLevel = false,
                    ParentObjectName = "",
                    ParentObjectRoot = ""
                };
                newSaveObject.DataFields = new SerializedFields()
                {
                    new ObjectProperty("mInventory", 0)
                    {
                        LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                    }
                };
                if (rootItem.FindChild("Crate", false) == null)
                {
                    rootItem.FindChild("-Shared", false).Items.Add(new SaveObjectModel("Crate"));
                }
                if (rootItem.FindChild("BP_Crate.BP_Crate_C", false) == null)
                {
                    rootItem.FindChild("Crate", false).Items.Add(new SaveObjectModel("BP_Crate.BP_Crate_C"));
                }
                rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(new SaveEntityModel(newSaveObject));
            }
            return(true);
        }
        public static SaveEntityModel CreateCrateEntityFromInventory(SaveObjectModel rootItem, ArrayProperty inventory)
        {
            inventory = ArrangeInventory(inventory);
            int           currentStorageID = GetNextStorageID(0, rootItem);
            SaveComponent newInventory     = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
            {
                ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                DataFields       = new SerializedFields()
                {
                    inventory,
                    new ArrayProperty("mArbitrarySlotSizes")
                    {
                        Type     = "IntProperty",
                        Elements = Enumerable.Repeat(new IntProperty("Element")
                        {
                            Value = 0
                        }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                    },
                    new ArrayProperty("mAllowedItemDescriptors")
                    {
                        Type     = "ObjectProperty",
                        Elements = Enumerable.Repeat(new ObjectProperty("Element")
                        {
                            LevelName = "", PathName = ""
                        }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                    },
                    new BoolProperty("mCanBeRearrange")
                    {
                        Value = false
                    }
                }
            };

            rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
            SaveEntity player        = (SaveEntity)rootItem.FindChild("Char_Player.Char_Player_C", false).DescendantSelf[0];
            SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
            {
                NeedTransform = true,
                Rotation      = player.Rotation,
                Position      = new Vector3()
                {
                    X = player.Position.X, Y = player.Position.Y + 100, Z = player.Position.Z
                },
                Scale = new Vector3()
                {
                    X = 1, Y = 1, Z = 1
                },
                WasPlacedInLevel = false,
                ParentObjectName = "",
                ParentObjectRoot = ""
            };

            newSaveObject.DataFields = new SerializedFields()
            {
                new ObjectProperty("mInventory", 0)
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                }
            };
            if (rootItem.FindChild("Crate", false) == null)
            {
                rootItem.FindChild("-Shared", false).Items.Add(new SaveObjectModel("Crate"));
            }
            if (rootItem.FindChild("BP_Crate.BP_Crate_C", false) == null)
            {
                rootItem.FindChild("Crate", false).Items.Add(new SaveObjectModel("BP_Crate.BP_Crate_C"));
            }
            var crate = new SaveEntityModel(newSaveObject);

            rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(crate);
            return(crate);
        }
Esempio n. 8
0
        public bool AddDoggo(SaveObjectModel rootItem, SatisfactorySave saveGame)
        {
            currentDoggoID = GetNextDoggoID(currentDoggoID, rootItem);

            var hostPlayerModel = rootItem.FindChild("Char_Player.Char_Player_C", false);

            if (hostPlayerModel == null || hostPlayerModel.Items.Count < 1)
            {
                MessageBox.Show("This save does not contain a host player or it is corrupt.", "Cannot find host player", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            var player = (SaveEntityModel)hostPlayerModel.Items[0];

            SaveComponent healthComponent = new SaveComponent("/Script/FactoryGame.FGHealthComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent")
            {
                DataFields       = new SerializedFields(),
                ParentEntityName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}"
            };

            byte[]        bytes = PrepareForParse("", 0);
            SaveComponent inventoryComponent;

            using (BinaryReader reader = new BinaryReader(new MemoryStream(bytes)))
            {
                inventoryComponent = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.mInventory")
                {
                    DataFields = new SerializedFields()
                    {
                        new ArrayProperty("mInventoryStacks")
                        {
                            Type     = StructProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                SerializedProperty.Parse(reader, saveGame.Header.BuildVersion)
                            }
                        },
                        new ArrayProperty("mArbitrarySlotSizes")
                        {
                            Type     = IntProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                new IntProperty("Element")
                                {
                                    Value = 0
                                }
                            }
                        },
                        new ArrayProperty("mAllowedItemDescriptors")
                        {
                            Type     = ObjectProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                new ObjectProperty("Element")
                                {
                                    LevelName = "", PathName = ""
                                }
                            }
                        }
                    },
                    ParentEntityName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}"
                };
            }
            SaveEntity doggo = new SaveEntity("/Game/FactoryGame/Character/Creature/Wildlife/SpaceRabbit/Char_SpaceRabbit.Char_SpaceRabbit_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}")
            {
                NeedTransform = true,
                Rotation      = ((SaveEntity)player.Model).Rotation,
                Position      = new Vector3()
                {
                    X = ((SaveEntity)player.Model).Position.X,
                    Y = ((SaveEntity)player.Model).Position.Y + 100 + 10 * currentDoggoID, // so they don't glitch one into another like the tractors did
                    Z = ((SaveEntity)player.Model).Position.Z + 10
                },
                Scale = new Vector3()
                {
                    X = 1, Y = 1, Z = 1
                },
                WasPlacedInLevel = false,
                ParentObjectName = "",
                ParentObjectRoot = ""
            };

            doggo.Components = new System.Collections.Generic.List <SatisfactorySaveParser.Structures.ObjectReference>()
            {
                new SatisfactorySaveParser.Structures.ObjectReference()
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.mInventory"
                },
                new SatisfactorySaveParser.Structures.ObjectReference()
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent"
                }
            };
            byte[] emptyDynamicStructData = { 0x05, 0x00, 0x00, 0x00, 0x4e, 0x6f, 0x6e, 0x65 }; // Length prefixed "None"
            using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(emptyDynamicStructData)))
            {
                doggo.DataFields = new SerializedFields()
                {
                    new ObjectProperty("mFriendActor")
                    {
                        LevelName = "Persistent_Level", PathName = player.Title
                    },
                    new IntProperty("mLootTableIndex")
                    {
                        Value = 0
                    },
                    new StructProperty("mLootTimerHandle")
                    {
                        Data = new DynamicStructData(binaryReader, "TimerHandle", saveGame.Header.BuildVersion),
                        Unk1 = 0,
                        Unk2 = 0,
                        Unk3 = 0,
                        Unk4 = 0,
                        Unk5 = 0
                    },
                    new BoolProperty("mIsPersistent")
                    {
                        Value = true
                    },
                    new ObjectProperty("mHealthComponent")
                    {
                        LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent"
                    }
                };
            }
            FindOrCreatePath(rootItem, new string[] { "Character", "Creature", "Wildlife", "SpaceRabbit", "Char_SpaceRabbit.Char_SpaceRabbit_C" }).Items.Add(new SaveEntityModel(doggo));
            rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(inventoryComponent));
            rootItem.FindChild("FactoryGame.FGHealthComponent", false).Items.Add(new SaveComponentModel(healthComponent));
            return(true);
        }
Esempio n. 9
0
    void test1()
    {
        SaveComponent sc = new SaveComponent();

        sc.saveByJson <List <Item> >("a", wl);
    }