예제 #1
0
        public static void ModifyVectorZAxis(SaveLoadRoot layerTarget)
        {
            if (layerTarget == null)
            {
                return;
            }

            SolidConduit component = layerTarget.GetComponent <SolidConduit>();

            if (!(UnityEngine.Object)component != (UnityEngine.Object)null)
            {
                return;
            }

            Vector3 position = layerTarget.transform.GetPosition();
            float   desired  = Grid.GetLayerZ(Grid.SceneLayer.Move);

            if (position.z != desired)
            {
                if (!InitialZValues.ContainsKey(layerTarget))
                {
                    InitialZValues.Add(layerTarget, position.z);
                }

                position.z = desired;
                layerTarget.transform.SetPosition(position);
                RefreshKbacForLayerTarget(layerTarget);
            }
        }
예제 #2
0
    public static SaveLoadRoot Load(GameObject prefab, Vector3 position, Quaternion rotation, Vector3 scale, IReader reader)
    {
        SaveLoadRoot saveLoadRoot = null;

        if ((UnityEngine.Object)prefab != (UnityEngine.Object)null)
        {
            GameObject gameObject = Util.KInstantiate(prefab, position, rotation, null, null, false, 0);
            gameObject.transform.localScale = scale;
            gameObject.SetActive(true);
            saveLoadRoot = gameObject.GetComponent <SaveLoadRoot>();
            if ((UnityEngine.Object)saveLoadRoot != (UnityEngine.Object)null)
            {
                try
                {
                    LoadInternal(gameObject, reader);
                    return(saveLoadRoot);
                }
                catch (ArgumentException ex)
                {
                    DebugUtil.LogErrorArgs(gameObject, "Failed to load SaveLoadRoot ", ex.Message, "\n", ex.StackTrace);
                    return(saveLoadRoot);
                }
            }
            Debug.Log("missing SaveLoadRoot", gameObject);
        }
        else
        {
            LoadInternal(null, reader);
        }
        return(saveLoadRoot);
    }
예제 #3
0
        GameObject convert_to_gameobject(string base64)
        {
            byte[]       compression  = System.Convert.FromBase64String(base64);
            MemoryStream stream       = new MemoryStream(compression);
            MemoryStream other_stream = new MemoryStream(4096); // ughhhh

            using (DeflateStream inflater = new DeflateStream(stream, CompressionMode.Decompress)) {
                inflater.CopyTo(other_stream);
            }
            byte[] object_info = other_stream.ToArray();
            // Magic voodoo
            IReader reader = new FastReader(object_info);
            Tag     tag    = TagManager.Create(reader.ReadKleiString());

            // Blood sacrifice -SB
            KSerialization.Manager.Clear();
            KSerialization.Manager.DeserializeDirectory(reader);

            Transform transform = this.transform;

            // Even more magic voodoo
            // The first argument gets us a blank prefab for an object defined
            //   in the base64 string, put there by the sender
            // Arugments 2-4 get the position, rotation, and localScale of the
            //   current 'this' kmonobehavior
            // Lastly is the Reader which is above
            // And finally, because its a SaveLoadRoot, that just loaded an
            //   object, we need to get that object
            return(SaveLoadRoot.Load(SaveLoader.Instance.saveManager.GetPrefab(tag),
                                     transform.GetPosition(),
                                     transform.rotation,
                                     transform.localScale,
                                     reader).gameObject);
        }
예제 #4
0
 public void Unregister(SaveLoadRoot root)
 {
     if (this.onRegister != null)
     {
         this.onUnregister(root);
     }
     GetSaveLoadRootList(root)?.Remove(root);
 }
예제 #5
0
            static void Postfix(SaveLoadRoot root)
            {
                var go = root.gameObject;

                if (go.GetComponent <LogicLabelSetting>() is LogicLabelSetting dispComp)
                {
                    logicSettingUIs.Add(go, new LogicSettingUIInfo(uiGOPool.GetFreeElement(GameScreenManager.Instance.worldSpaceCanvas), dispComp));
                }
            }
예제 #6
0
            static void Postfix(SaveLoadRoot root)
            {
                var go = root.gameObject;

                if (logicSettingUIs.TryGetValue(go, out LogicSettingUIInfo logicSettingUIInfo))
                {
                    logicSettingUIs.Remove(go);
                    uiGOPool.ClearElement(logicSettingUIInfo.cachedLocText);
                }
            }
예제 #7
0
 /// <summary>
 /// A replacement for the particular AddTargetIfVisible version using SaveLoadRoot.
 /// </summary>
 /// <param name="instance">The object under test.</param>
 /// <param name="visMin">The minimum visible cell coordinate.</param>
 /// <param name="visMax">The maximum visible cell coordinate.</param>
 /// <param name="targets">The location to add the target if it matches.</param>
 /// <param name="layer">The layer to move the target if it matches.</param>
 /// <param name="onAdded">The callback to invoke if it matches.</param>
 /// <param name="shouldAdd">The callback to invoke and check if it matches.</param>
 private static void AddTargetIfVisible(OverlayModes.Mode _, SaveLoadRoot instance,
                                        Vector2I visMin, Vector2I visMax, ICollection <SaveLoadRoot> targets, int layer,
                                        Action <SaveLoadRoot> onAdded, Func <KMonoBehaviour, bool> shouldAdd)
 {
     if (instance != null)
     {
         Vector2 min = instance.PosMin(), max = instance.PosMax();
         int     xMin = (int)min.x, yMin = (int)min.y, yMax = (int)max.y, xMax = (int)max.x;
         if (xMax >= visMin.x && yMax >= visMin.y && xMin <= visMax.x && yMin <= visMax.
             y && !targets.Contains(instance))
         {
             bool found = !PropertyTextures.IsFogOfWarEnabled;
             int  curWorld = ClusterManager.Instance.activeWorldId, w = Grid.
                                                                        WidthInCells, cell = w * yMin + xMin;
             int width = xMax - xMin + 1, height = yMax - yMin + 1;
             // Iterate the extents of the object to see if any cell is visible
             w -= width;
             for (int y = height; y > 0 && !found; y--)
             {
                 for (int x = width; x > 0 && !found; x--)
                 {
                     // 20 is hardcoded in original method
                     if (Grid.IsValidCell(cell) && Grid.Visible[cell] > 20 &&
                         Grid.WorldIdx[cell] == curWorld)
                     {
                         found = true;
                     }
                     cell++;
                 }
                 cell += w;
             }
             if (found)
             {
                 var kmb = instance as KMonoBehaviour;
                 if (shouldAdd == null || kmb == null || shouldAdd(kmb))
                 {
                     // Add to list and trigger overlay mode update
                     if (kmb != null)
                     {
                         if (kmb.TryGetComponent(out KBatchedAnimController kbac))
                         {
                             kbac.SetLayer(layer);
                         }
                         if (kmb.TryGetComponent(out UpdateGraphIfEntombed updateGraph))
                         {
                             updateGraph.UpdateOverlay(true);
                         }
                     }
                     targets.Add(instance);
                     onAdded?.Invoke(instance);
                 }
             }
         }
     }
 }
예제 #8
0
        public static void RefreshKbacForLayerTarget(SaveLoadRoot layerTarget)
        {
            KBatchedAnimController kbac = layerTarget.GetComponent <KBatchedAnimController>();

            if ((UnityEngine.Object)kbac == (UnityEngine.Object)null)
            {
                return;
            }

            kbac.enabled = false;
            kbac.enabled = true;
        }
예제 #9
0
    public void Register(SaveLoadRoot root)
    {
        List <SaveLoadRoot> saveLoadRootList = GetSaveLoadRootList(root);

        if (saveLoadRootList != null)
        {
            saveLoadRootList.Add(root);
            if (this.onRegister != null)
            {
                this.onRegister(root);
            }
        }
    }
예제 #10
0
            //Change the overlay tint for the pipe if it is a pressurized pipe.
            private static Color32 PatchThermalColor(Color32 original, SaveLoadRoot layerTarget)
            {
                Pressurized pressurized = layerTarget.GetComponent <Pressurized>();

                if (pressurized != null && pressurized.Info != null && !pressurized.Info.IsDefault)
                {
                    return(pressurized.Info.OverlayTint);
                }
                else
                {
                    return(original);
                }
            }
예제 #11
0
 protected override void OnSaveLoadRootUnregistered(SaveLoadRoot root)
 {
     // Remove plants from partitioner if they die
     if (root != null && root.gameObject != null)
     {
         var uprootable = root.GetComponent <Uprootable>();
         if (uprootable != null)
         {
             layerTargets.Remove(uprootable);
             partition.Remove(uprootable);
         }
     }
 }
예제 #12
0
        protected override void OnSaveLoadRootRegistered(SaveLoadRoot root)
        {
            // Add new plants to partitioner
            var tag = root.GetComponent <KPrefabID>().GetSaveLoadTag();

            if (plants.Contains(tag))
            {
                var uprootable = root.GetComponent <Uprootable>();
                if (uprootable != null)
                {
                    partition.Add(uprootable);
                }
            }
        }
예제 #13
0
    private List <SaveLoadRoot> GetSaveLoadRootList(SaveLoadRoot saver)
    {
        KPrefabID component = saver.GetComponent <KPrefabID>();

        if ((UnityEngine.Object)component == (UnityEngine.Object)null)
        {
            DebugUtil.LogErrorArgs(saver.gameObject, "All savers must also have a KPrefabID on them but", saver.gameObject.name, "does not have one.");
            return(null);
        }
        if (!sceneObjects.TryGetValue(component.GetSaveLoadTag(), out List <SaveLoadRoot> value))
        {
            value = new List <SaveLoadRoot>();
            sceneObjects[component.GetSaveLoadTag()] = value;
        }
        return(value);
    }
예제 #14
0
	public void OnStore(object data)
	{
		storage = (data as Storage);
		bool flag = data is Storage || (data != null && (bool)data);
		SaveLoadRoot component = GetComponent<SaveLoadRoot>();
		if ((UnityEngine.Object)carryAnimOverride != (UnityEngine.Object)null && (UnityEngine.Object)lastCarrier != (UnityEngine.Object)null)
		{
			lastCarrier.RemoveAnimOverrides(carryAnimOverride);
			lastCarrier = null;
		}
		KSelectable component2 = GetComponent<KSelectable>();
		if ((bool)component2)
		{
			component2.IsSelectable = !flag;
		}
		if (flag)
		{
			int cachedCell = this.cachedCell;
			RefreshStorageTags(data);
			if ((object)storage != null)
			{
				if ((UnityEngine.Object)carryAnimOverride != (UnityEngine.Object)null && (UnityEngine.Object)storage.GetComponent<Navigator>() != (UnityEngine.Object)null)
				{
					lastCarrier = storage.GetComponent<KBatchedAnimController>();
					if ((UnityEngine.Object)lastCarrier != (UnityEngine.Object)null)
					{
						lastCarrier.AddAnimOverrides(carryAnimOverride, 0f);
					}
				}
				UpdateCachedCell(Grid.PosToCell(storage));
			}
			NotifyChanged(cachedCell);
			if ((UnityEngine.Object)component != (UnityEngine.Object)null)
			{
				component.SetRegistered(false);
			}
		}
		else
		{
			if ((UnityEngine.Object)component != (UnityEngine.Object)null)
			{
				component.SetRegistered(true);
			}
			RemovedFromStorage();
		}
	}
예제 #15
0
        public static void RestoreInitialZAxis(SaveLoadRoot layerTarget)
        {
            if (layerTarget == null)
            {
                return;
            }

            if (!InitialZValues.ContainsKey(layerTarget))
            {
                return;
            }

            Vector3 position = layerTarget.transform.GetPosition();

            position.z = InitialZValues[layerTarget];

            layerTarget.transform.SetPosition(position);
            RefreshKbacForLayerTarget(layerTarget);
        }
예제 #16
0
    protected override void OnCleanUp()
    {
        if (IsReplacementTile && building.Def.isKAnimTile)
        {
            int        cell       = Grid.PosToCell(base.transform.GetPosition());
            GameObject gameObject = Grid.Objects[cell, (int)building.Def.ReplacementLayer];
            if ((UnityEngine.Object)gameObject == (UnityEngine.Object)base.gameObject && (UnityEngine.Object)gameObject.GetComponent <SimCellOccupier>() != (UnityEngine.Object)null)
            {
                World.Instance.blockTileRenderer.RemoveBlock(building.Def, IsReplacementTile, SimHashes.Void, cell);
            }
        }
        GameScenePartitioner.Instance.Free(ref solidPartitionerEntry);
        GameScenePartitioner.Instance.Free(ref digPartitionerEntry);
        GameScenePartitioner.Instance.Free(ref ladderParititonerEntry);
        SaveLoadRoot component = GetComponent <SaveLoadRoot>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            SaveLoader.Instance.saveManager.Unregister(component);
        }
        if (fetchList != null)
        {
            fetchList.Cancel("Constructable destroyed");
        }
        UnmarkArea();
        int[] placementCells = building.PlacementCells;
        foreach (int cell2 in placementCells)
        {
            Diggable diggable = Diggable.GetDiggable(cell2);
            if ((UnityEngine.Object)diggable != (UnityEngine.Object)null)
            {
                diggable.gameObject.DeleteObject();
            }
        }
        base.OnCleanUp();
    }
예제 #17
0
    public bool Load(IReader reader)
    {
        char[] array = reader.ReadChars(SAVE_HEADER.Length);
        if (array == null || array.Length != SAVE_HEADER.Length)
        {
            return(false);
        }
        for (int i = 0; i < SAVE_HEADER.Length; i++)
        {
            if (array[i] != SAVE_HEADER[i])
            {
                return(false);
            }
        }
        int num  = reader.ReadInt32();
        int num2 = reader.ReadInt32();

        if (num != 7 || num2 > 11)
        {
            DebugUtil.LogWarningArgs($"SAVE FILE VERSION MISMATCH! Expected {7}.{11} but got {num}.{num2}");
            return(false);
        }
        ClearScene();
        try
        {
            int num3 = reader.ReadInt32();
            for (int j = 0; j < num3; j++)
            {
                string text = reader.ReadKleiString();
                int    num4 = reader.ReadInt32();
                int    num5 = 0;
                num5 = reader.ReadInt32();
                Tag key = TagManager.Create(text);
                if (!prefabMap.TryGetValue(key, out GameObject value))
                {
                    DebugUtil.LogWarningArgs("Could not find prefab '" + text + "'");
                    reader.SkipBytes(num5);
                }
                else
                {
                    List <SaveLoadRoot> value2 = new List <SaveLoadRoot>(num4);
                    sceneObjects[key] = value2;
                    for (int k = 0; k < num4; k++)
                    {
                        SaveLoadRoot x = SaveLoadRoot.Load(value, reader);
                        if ((UnityEngine.Object)x == (UnityEngine.Object)null)
                        {
                            Debug.LogError("Error loading data [" + text + "]");
                            return(false);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            DebugUtil.LogErrorArgs("Error deserializing prefabs\n\n", ex.ToString());
            throw ex;
        }
        return(true);
    }
예제 #18
0
 private void PlaceDiggables()
 {
     if (waitForFetchesBeforeDigging && fetchList != null && !hasLadderNearby)
     {
         OnDiggableReachabilityChanged(null);
     }
     else
     {
         bool digs_complete = true;
         if (!solidPartitionerEntry.IsValid())
         {
             Extents validPlacementExtents = building.GetValidPlacementExtents();
             solidPartitionerEntry = GameScenePartitioner.Instance.Add("Constructable.OnFetchListComplete", base.gameObject, validPlacementExtents, GameScenePartitioner.Instance.solidChangedLayer, OnSolidChangedOrDigDestroyed);
             digPartitionerEntry   = GameScenePartitioner.Instance.Add("Constructable.OnFetchListComplete", base.gameObject, validPlacementExtents, GameScenePartitioner.Instance.digDestroyedLayer, OnSolidChangedOrDigDestroyed);
         }
         if (!IsReplacementTile)
         {
             building.RunOnArea(delegate(int offset_cell)
             {
                 PrioritySetting masterPriority = GetComponent <Prioritizable>().GetMasterPriority();
                 if (Diggable.IsDiggable(offset_cell))
                 {
                     digs_complete     = false;
                     Diggable diggable = Diggable.GetDiggable(offset_cell);
                     if ((UnityEngine.Object)diggable == (UnityEngine.Object)null)
                     {
                         diggable = GameUtil.KInstantiate(Assets.GetPrefab(new Tag("DigPlacer")), Grid.SceneLayer.Move, null, 0).GetComponent <Diggable>();
                         diggable.gameObject.SetActive(true);
                         diggable.transform.SetPosition(Grid.CellToPosCBC(offset_cell, Grid.SceneLayer.Move));
                         diggable.Subscribe(-1432940121, OnDiggableReachabilityChanged);
                         Grid.Objects[offset_cell, 7] = diggable.gameObject;
                     }
                     else
                     {
                         diggable.Unsubscribe(-1432940121, OnDiggableReachabilityChanged);
                         diggable.Subscribe(-1432940121, OnDiggableReachabilityChanged);
                     }
                     diggable.choreTypeIdHash = Db.Get().ChoreTypes.BuildDig.IdHash;
                     diggable.GetComponent <Prioritizable>().SetMasterPriority(masterPriority);
                     RenderUtil.EnableRenderer(diggable.transform, false);
                     SaveLoadRoot component = diggable.GetComponent <SaveLoadRoot>();
                     if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                     {
                         UnityEngine.Object.Destroy(component);
                     }
                 }
             });
             OnDiggableReachabilityChanged(null);
         }
         bool flag = building.Def.IsValidBuildLocation(base.gameObject, base.transform.GetPosition(), building.Orientation);
         if (flag)
         {
             notifier.Remove(invalidLocation);
         }
         else
         {
             notifier.Add(invalidLocation, string.Empty);
         }
         GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.InvalidBuildingLocation, !flag, this);
         bool flag2 = digs_complete && flag && fetchList == null;
         if (flag2 && buildChore == null)
         {
             buildChore = new WorkChore <Constructable>(Db.Get().ChoreTypes.Build, this, null, true, UpdateBuildState, UpdateBuildState, UpdateBuildState, true, null, false, true, null, true, true, true, PriorityScreen.PriorityClass.basic, 5, false, true);
             UpdateBuildState(buildChore);
         }
         else if (!flag2 && buildChore != null)
         {
             buildChore.Cancel("Need to dig");
             buildChore = null;
         }
     }
 }