Ejemplo n.º 1
0
        internal override void Init()
        {
            // Create GUI container
            GUIContainer = new GameObject("GUI");
            GUIContainer.transform.SetParent(VeilheimPlugin.RootObject.transform);
            var canvas = GUIContainer.AddComponent <Canvas>();

            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            GUIContainer.AddComponent <GraphicRaycaster>();

            // Load assets
            AssetBundle assetBundle;

            assetBundle = AssetUtils.LoadAssetBundleFromResources("configurationgui", typeof(VeilheimPlugin).Assembly);
            LoadGUIPrefab(assetBundle, "ConfigurationEntry");
            LoadGUIPrefab(assetBundle, "ConfigurationSection");
            LoadGUIPrefab(assetBundle, "ConfigurationGUIRoot");
            assetBundle.Unload(false);

            assetBundle = AssetUtils.LoadAssetBundleFromResources("portalselectiongui", typeof(VeilheimPlugin).Assembly);
            LoadGUIPrefab(assetBundle, "PortalButtonBox");
            assetBundle.Unload(false);

            // Done
            Logger.LogInfo("Initialized GUIManager");
        }
Ejemplo n.º 2
0
        public void Destroy()
        {
            if (m_prefab == null)
            {
                return;
            }

            // Remove from PieceTable
            var table = PieceManager.Instance.GetPieceTable("_BlueprintPieceTable");

            if (table == null)
            {
                Logger.LogWarning("BlueprintPieceTable not found");
                return;
            }

            if (table.m_pieces.Contains(m_prefab))
            {
                Logger.LogInfo($"Removing {m_prefabname} from BlueprintRune");

                table.m_pieces.Remove(m_prefab);
            }

            // Remove from prefabs
            PieceManager.Instance.RemovePiece(m_prefabname);
            PrefabManager.Instance.DestroyPrefab(m_prefabname);
        }
Ejemplo n.º 3
0
            public IEnumerator AddBlueprint()
            {
                bool oldHud = DisableHud();

                yield return(new WaitForEndOfFrame());

                yield return(new WaitForEndOfFrame());

                newbp.RecordFrame();

                Hud.instance.m_userHidden = oldHud;
                Hud.instance.SetVisible(true);
                Hud.instance.Update();
                yield return(new WaitForEndOfFrame());

                yield return(new WaitForEndOfFrame());

                newbp.CreatePrefab();

                newbp.AddToPieceTable();

                newbp.CreateKeyHint();

                Player.m_localPlayer.UpdateKnownRecipesList();
                Player.m_localPlayer.UpdateAvailablePiecesList();
                BlueprintManager.Instance.m_blueprints.Add(newbp.m_name, newbp);

                Logger.LogInfo("Blueprint created");

                newbp = null;
            }
Ejemplo n.º 4
0
        /// <summary>
        ///     Apply sent exploration data to local map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mapData"></param>
        public static void RPC_Veilheim_ReceiveExploration(long sender, ZPackage mapData)
        {
            if (mapData == null)
            {
                return;
            }

            if (ZNet.instance.IsServerInstance())
            {
                Logger.LogInfo($"Received map data from client #{sender}");
                ApplyMapData(mapData);

                var tempPlayerInfos = new List <ZNet.PlayerInfo>();
                ZNet.instance.GetOtherPublicPlayers(tempPlayerInfos);

                var newMapData = new ZPackage(CreateExplorationData());

                foreach (var player in tempPlayerInfos)
                {
                    Logger.LogInfo($"Sending map data to player {player.m_name} #{ZNet.instance.GetPeerByPlayerName(player.m_name)}");
                    ZRoutedRpc.instance.InvokeRoutedRPC(ZNet.instance.GetPeerByPlayerName(player.m_name).m_uid, nameof(RPC_Veilheim_ReceiveExploration),
                                                        newMapData);
                }
            }

            if (ZNet.instance.IsClientInstance())
            {
                Logger.LogInfo("Received map data from server");

                // Set flag to prevent enqueuing again for sending, since it can be new
                ApplyMapData(mapData);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Before ZNet destroy, save data to file on server
        /// </summary>
        private static void SaveExplorationData(On.ZNet.orig_Shutdown orig, ZNet self)
        {
            // Save exploration data only on the server
            if (ZNet.instance.IsServerInstance() && ConfigUtil.Get <bool>("MapServer", "shareMapProgression"))
            {
                Logger.LogInfo($"Saving shared exploration data");
                var mapData = new ZPackage(CreateExplorationData().ToArray());
                mapData.WriteToFile(Path.Combine(ConfigUtil.GetConfigPath(), ZNet.instance.GetWorldUID().ToString(), "Explorationdata.bin"));
            }

            orig(self);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     After SetMapData is done, send it to the server
        ///     TODO: Check if configuration is loaded already, data should not be sent if map sharing is disabled
        /// </summary>
        private static void InitialSendRequest(On.Minimap.orig_SetMapData orig, Minimap self, byte[] data)
        {
            // Prevent queueing up loaded data
            isInSetMapData = true;

            orig(self, data);

            if (ConfigUtil.Get <bool>("MapServer", "shareMapProgression"))
            {
                Logger.LogInfo("Sending Map data initially to server");
                // After login, send map data to server (and get new map data back)
                var pkg = new ZPackage(CreateExplorationData().ToArray());
                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_ReceiveExploration), pkg);
            }

            isInSetMapData = false;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     CLIENT SIDE: React to setting tag on portal
        /// </summary>
        private static void ResyncAfterTagChange(On.TeleportWorld.orig_RPC_SetTag orig, TeleportWorld self, long sender, string tag)
        {
            orig(self, sender, tag);

            if (ZNet.instance.IsServerInstance())
            {
                return;
            }

            Logger.LogInfo("Portal tag changed");

            if (ZNet.instance.IsLocalInstance())
            {
                Logger.LogInfo("Sending portal sync request to server");

                // Send trigger to server
                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
            }

            if (ZNet.instance.IsClientInstance())
            {
                Logger.LogInfo("Forcing ZDO to server");

                // Force sending ZDO to server
                var temp = self.m_nview.GetZDO();

                ZDOMan.instance.GetZDO(temp.m_uid);

                ZDOMan.instance.GetPeer(ZRoutedRpc.instance.GetServerPeerID()).ForceSendZDO(temp.m_uid);

                Logger.LogInfo("Sending deferred portal sync request to server");

                Task.Factory.StartNew(() =>
                {
                    // Wait for ZDO to be sent else server won't have accurate information to send back
                    Thread.Sleep(5000);

                    // Send trigger to server
                    ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
                });
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     RPC to receive new exploration data from client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mapData"></param>
        public static void RPC_Veilheim_ReceiveExploration_OnExplore(long sender, ZPackage mapData)
        {
            if (mapData == null)
            {
                return;
            }

            if (ZNet.instance.IsServerInstance())
            {
                var numberOfEntries = mapData.ReadInt();
                Logger.LogInfo($"Received exploration diff data from client #{sender}, {numberOfEntries} items");

                while (numberOfEntries > 0)
                {
                    var toExplore = mapData.ReadInt();
                    Minimap.instance.m_explored[toExplore] = true;
                    numberOfEntries--;
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     RPC to handle sync to all peers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="teleporterZPackage"></param>
        public static void RPC_Veilheim_TeleporterSync(long sender, ZPackage teleporterZPackage)
        {
            // SERVER SIDE
            if (ZNet.instance.IsServerInstance() || ZNet.instance.IsLocalInstance())
            {
                Logger.LogMessage("Sending portal data to all peers");

                var portals = PortalList.GetPortals();

                if (ZNet.instance.IsLocalInstance())
                {
                    UpdatePins(portals);
                }

                var package = portals.ToZPackage();

                foreach (var peer in ZNet.instance.m_peers)
                {
                    if (!peer.m_server)
                    {
                        Logger.LogInfo($"Sending portal data to peer #{peer.m_uid}");

                        ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, nameof(RPC_Veilheim_TeleporterSync), package);
                    }
                }
            }

            // CLIENT SIDE
            if (ZNet.instance.IsClientInstance())
            {
                if (teleporterZPackage != null && teleporterZPackage.Size() > 0 && sender == ZRoutedRpc.instance.GetServerPeerID())
                {
                    // Read package and create pins from portal list
                    Logger.LogMessage("Received portal data from server");

                    portalsFromServer = PortalList.FromZPackage(teleporterZPackage);

                    UpdatePins(portalsFromServer);
                }
            }
        }
Ejemplo n.º 10
0
        public void AddToPieceTable()
        {
            if (m_prefab == null)
            {
                return;
            }

            var table = PieceManager.Instance.GetPieceTable("_BlueprintPieceTable");

            if (table == null)
            {
                Logger.LogWarning("BlueprintPieceTable not found");
                return;
            }

            if (!table.m_pieces.Contains(m_prefab))
            {
                Logger.LogInfo($"Adding {m_prefabname} to BlueprintRune");

                table.m_pieces.Add(m_prefab);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     CLIENT SIDE: React to a placement of a portal
        /// </summary>
        private static bool AfterPlacingPortal(On.Player.orig_PlacePiece orig, Player self, Piece piece)
        {
            bool successful = orig(self, piece);

            if (ZNet.instance.IsServerInstance())
            {
                return(successful);
            }

            if (successful && !piece.IsCreator() && piece.m_name == "$piece_portal")
            {
                Logger.LogInfo("Portal created");

                if (ZNet.instance.IsLocalInstance())
                {
                    Logger.LogInfo("Sending portal sync request to server");

                    ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
                }

                if (ZNet.instance.IsClientInstance())
                {
                    Logger.LogInfo("Sending deferred portal sync request to server");

                    Task.Factory.StartNew(() =>
                    {
                        // Wait for ZDO to be sent else server won't have accurate information to send back
                        Thread.Sleep(5000);

                        // Send trigger to server
                        ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
                    });
                }
            }

            return(successful);
        }
Ejemplo n.º 12
0
        public static void OpenPortalSelection()
        {
            if (TextInput.instance.m_panel.activeSelf)
            {
                Logger.LogInfo("Generating portal selection");

                // set position of textinput (a bit higher)
                TextInput.instance.m_panel.transform.localPosition = new Vector3(0, 270.0f, 0);

                // Get name of portal
                var currentTag = TextInput.instance.m_textField.text;
                if (string.IsNullOrEmpty(currentTag))
                {
                    currentTag = "<unnamed>";
                    TextInput.instance.m_textField.text = currentTag;
                }

                CreatePortalGUI(currentTag);

                // release mouselock
                GameCamera.instance.m_mouseCapture = false;
                GameCamera.instance.UpdateMouseCapture();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     CLIENT SIDE: React to setting tag on portal
        /// </summary>
        private static void OnPortalDestroy(On.WearNTear.orig_Destroy orig, WearNTear self)
        {
            if (ZNet.instance.IsServerInstance())
            {
                orig(self);
                return;
            }

            if (self.m_piece && self.m_piece.m_name == "$piece_portal")
            {
                Logger.LogInfo("Portal destroyed");

                if (ZNet.instance.IsLocalInstance())
                {
                    Logger.LogInfo("Sending portal sync request to server");

                    ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
                }

                if (ZNet.instance.IsClientInstance())
                {
                    Logger.LogInfo("Sending deferred portal sync request to server");

                    Task.Factory.StartNew(() =>
                    {
                        // Wait for ZDO to be sent else server won't have accurate information to send back
                        Thread.Sleep(5000);

                        // Send trigger to server
                        ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), nameof(RPC_Veilheim_TeleporterSync), new ZPackage());
                    });
                }
            }

            orig(self);
        }
Ejemplo n.º 14
0
        public GameObject CreatePrefab()
        {
            if (m_prefab != null)
            {
                return(m_prefab);
            }

            Logger.LogInfo($"Creating dynamic prefab {m_prefabname}");

            if (m_pieceEntries == null)
            {
                Logger.LogWarning("No pieces loaded");
                return(null);
            }

            // Get Stub from PrefabManager
            var stub = PrefabManager.Instance.GetPrefab("piece_blueprint");

            if (stub == null)
            {
                Logger.LogWarning("Could not load blueprint stub from prefabs");
                return(null);
            }

            // Instantiate clone from stub
            ZNetView.m_forceDisableInit = true;
            m_prefab = Object.Instantiate(stub);
            ZNetView.m_forceDisableInit = false;
            m_prefab.name = m_prefabname;

            var piece = m_prefab.GetComponent <Piece>();

            if (File.Exists(Path.Combine(BlueprintManager.BlueprintPath, m_name + ".png")))
            {
                var tex = new Texture2D(2, 2);
                tex.LoadImage(File.ReadAllBytes(Path.Combine(BlueprintManager.BlueprintPath, m_name + ".png")));

                piece.m_icon = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
            }

            piece.m_name    = m_name;
            piece.m_enabled = true;

            // Instantiate child objects
            if (!GhostInstantiate(m_prefab))
            {
                Logger.LogWarning("Could not create prefab");
                Object.DestroyImmediate(m_prefab);
                return(null);
            }

            // Instantiate plan objects
            if (!PlanInstantiate())
            {
                Logger.LogWarning("Could not create plan");
                Object.DestroyImmediate(m_prefab);
                return(null);
            }

            // Add to known prefabs
            CustomPiece CP = new CustomPiece(m_prefab, new PieceConfig
            {
                PieceTable = "_BlueprintPieceTable"
            });

            PieceManager.Instance.AddPiece(CP);

            return(m_prefab);
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Add and remove pins in internal list based on a list of portals
        /// </summary>
        /// <param name="portals"></param>
        public static void UpdatePins(PortalList portals)
        {
            Logger.LogInfo("Updating pins of portals on minimap");

            // prevent MT crashing
            lock (portalPins)
            {
                // Add connected portals (separated connected and unconnected, maybe show another icon?)
                foreach (var portal in portals.FindAll(x => x.m_con))
                {
                    // Was pin already added?
                    var foundPin = portalPins.FirstOrDefault(x => x.m_pos == portal.m_pos);
                    if (foundPin != null)
                    {
                        // Did the pin's name change?
                        if (foundPin.m_name != portal.m_tag)
                        {
                            // Remove pin at location and readd with new name
                            portalPins.Remove(foundPin);
                            portalPins.Add(CreatePinData(portal.m_pos, Minimap.PinType.Icon4, portal.m_tag, false, false));
                        }
                    }
                    else
                    {
                        // Add new pin
                        portalPins.Add(CreatePinData(portal.m_pos, Minimap.PinType.Icon4, portal.m_tag, false, false));
                    }
                }

                // Add unconnected portals (maybe show another icon / text?)
                foreach (var portal in portals.FindAll(x => !x.m_con))
                {
                    // Was pin already added?
                    var foundPin = portalPins.FirstOrDefault(x => x.m_pos == portal.m_pos);
                    if (foundPin != null)
                    {
                        // Did the pin's name change?
                        if (foundPin.m_name != portal.m_tag)
                        {
                            // Remove pin at location and readd with new name
                            portalPins.Remove(foundPin);
                            portalPins.Add(CreatePinData(portal.m_pos, Minimap.PinType.Icon4, portal.m_tag, false, false));
                        }
                    }
                    else
                    {
                        // Add new pin
                        portalPins.Add(CreatePinData(portal.m_pos, Minimap.PinType.Icon4, portal.m_tag, false, false));
                    }
                }

                // Remove destroyed portals from map
                // doesn't really react on portal destruction, only works if after a portal was destroyed, someone set the name on another portal
                foreach (var kv in portalPins.ToList())
                {
                    if (portals.All(x => x.m_pos != kv.m_pos))
                    {
                        portalPins.Remove(kv);
                    }
                }
            }

            Logger.LogInfo("Portal pins updated succesfully");
        }