Example #1
0
 private static void HandleDestroyedZDO_Prefix(ZDOMan __instance, ZDOID uid)
 {
     // This will happen when a portal is actually destroyed, not when it is simply unloaded. In this case,
     // remove the entry from our dictionary because it is never coming back.
     // Note: Every ZDO getting destroyed will call this function. We only care about ZDOs we are tracking.
     sPortals.Remove(uid);
 }
Example #2
0
    // Token: 0x060007F4 RID: 2036 RVA: 0x0003EA27 File Offset: 0x0003CC27
    public static ZDO Create(ZDOMan man, ZDOID id, Vector3 position)
    {
        ZDO zdo = ZDOPool.Get();

        zdo.Initialize(man, id, position);
        return(zdo);
    }
Example #3
0
        private static void Prefix(ref Ship __instance, ref List <Player> ___m_players, ref float ___m_backwardForce)
        {
            if (__instance.HaveControllingPlayer())
            {
                Ship.Speed speed = __instance.GetSpeedSetting();
                // only when padding backwards/forwards
                if (speed == Ship.Speed.Back || speed == Ship.Speed.Slow)
                {
                    int rowersCount = 0;

                    // we don't want to count controlling player
                    ZDOID controllingPlayer = (ZDOID)__instance.m_shipControlls.GetType().GetMethod("GetUser", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance.m_shipControlls, new object[] { });

                    foreach (Player player in ___m_players)
                    {
                        if (player.IsSitting() && !player.GetZDOID().Equals(controllingPlayer))
                        {
                            rowersCount++;
                        }
                    }
                    if (___m_backwardForce != 0.5f)  // we don't want to boost raft since it doesn't have any sitting spots
                    {
                        ___m_backwardForce = 0.2f + (rowersCount * 0.05f);
                    }
                }
            }
        }
Example #4
0
    // Token: 0x06000F7A RID: 3962 RVA: 0x0006DBD0 File Offset: 0x0006BDD0
    public void Teleport(Player player)
    {
        if (!this.TargetFound())
        {
            return;
        }
        if (!player.IsTeleportable())
        {
            player.Message(MessageHud.MessageType.Center, "$msg_noteleport", 0, null);
            return;
        }
        ZLog.Log("Teleporting " + player.GetPlayerName());
        ZDOID zdoid = this.m_nview.GetZDO().GetZDOID("target");

        if (zdoid == ZDOID.None)
        {
            return;
        }
        ZDO        zdo      = ZDOMan.instance.GetZDO(zdoid);
        Vector3    position = zdo.GetPosition();
        Quaternion rotation = zdo.GetRotation();
        Vector3    a        = rotation * Vector3.forward;
        Vector3    pos      = position + a * this.m_exitDistance + Vector3.up;

        player.TeleportTo(pos, rotation, true);
    }
Example #5
0
        static bool ZNet_SetCharacterID(ZNet __instance, ZDOID id, ISocket ___m_hostSocket, List <ZNetPeer> ___m_peers)
        {
            ZPackage characterIdPackage = new ZPackage();

            characterIdPackage.Write(id);

            Player myPlayer = Player.m_localPlayer;

            if (myPlayer != null)
            {
                Inventory myInventory = myPlayer.GetInventory();
                if (myInventory != null)
                {
                    characterIdPackage.Write(Helper.PackageInventory(myPlayer.GetPlayerName(), myInventory));
                    if (Configs.ShowDebugMessages.Value)
                    {
                        UnityEngine.Debug.Log("Sent inventory to server.");
                    }
                }
                else if (Configs.ShowDebugMessages.Value)
                {
                    UnityEngine.Debug.Log("Player inventory was null!");
                }
            }
            else if (Configs.ShowDebugMessages.Value)
            {
                UnityEngine.Debug.Log("Player was null!");
            }

            ___m_peers[0].m_rpc.Invoke("CharacterIDX", new object[] { characterIdPackage });

            return(false);
        }
Example #6
0
    // Token: 0x060007D0 RID: 2000 RVA: 0x0003D640 File Offset: 0x0003B840
    private void HandleDestroyedZDO(ZDOID uid)
    {
        if (uid.userID == this.m_myid && uid.id >= this.m_nextUid)
        {
            this.m_nextUid = uid.id + 1U;
        }
        ZDO zdo = this.GetZDO(uid);

        if (zdo == null)
        {
            return;
        }
        if (this.m_onZDODestroyed != null)
        {
            this.m_onZDODestroyed(zdo);
        }
        this.RemoveFromSector(zdo, zdo.GetSector());
        this.m_objectsByID.Remove(zdo.m_uid);
        ZDOPool.Release(zdo);
        foreach (ZDOMan.ZDOPeer zdopeer in this.m_peers)
        {
            zdopeer.m_zdos.Remove(uid);
        }
        if (ZNet.instance.IsServer())
        {
            long ticks = ZNet.instance.GetTime().Ticks;
            this.m_deadZDOs[uid] = ticks;
        }
    }
Example #7
0
 // Token: 0x060007ED RID: 2029 RVA: 0x0003E8AE File Offset: 0x0003CAAE
 public void RequestZDO(ZDOID id)
 {
     ZRoutedRpc.instance.InvokeRoutedRPC("RequestZDO", new object[]
     {
         id
     });
 }
Example #8
0
        public bool ActivatePendingPieces()
        {
            if (!m_nview || m_nview.m_zdo == null)
            {
                return(false);
            }
#if DEBUG
            Jotunn.Logger.LogInfo("Activate pending pieces for " + m_nview.m_zdo.m_uid);
#endif
            ZDOID uid = m_nview.m_zdo.m_uid;
            if (!m_pendingPieces.TryGetValue(uid, out var value))
            {
                return(true);
            }
            foreach (Piece piece in value)
            {
                if (piece)
                {
                    ActivatePiece(piece);
                }
            }
            value.Clear();
            m_pendingPieces.Remove(uid);
            return(true);
        }
Example #9
0
 // Token: 0x060007F0 RID: 2032 RVA: 0x0003E954 File Offset: 0x0003CB54
 public void ForceSendZDO(ZDOID id)
 {
     foreach (ZDOMan.ZDOPeer zdopeer in this.m_peers)
     {
         zdopeer.ForceSendZDO(id);
     }
 }
Example #10
0
 private void FlashBlueprint(ZDOID blueprintID, Color color)
 {
     foreach (PlanPiece planPiece in GetPlanPiecesForBlueprint(blueprintID))
     {
         planPiece.m_wearNTear.Highlight(color);
     }
 }
Example #11
0
            private static void Process(ZNet __instance, ZDOID zdoID)
            {
                if (zdoID.IsNone())
                {
                    return;
                }

                var zdo = ZDOMan.instance.GetZDO(zdoID);

                if (zdo == null)
                {
                    return;
                }

                var dead = zdo.GetBool("dead", false);

                // If dead, and not in deadPlayers, add to deadPlayers and create event
                // If dead, and in deadPlayers, do nothing
                // If not dead, and in deadPlayers, remove
                // If not dead, and not in deadPlayers, do nothing
                if (dead)
                {
                    if (DeadPlayers.Contains(zdoID.userID))
                    {
                        return;
                    }
                    DeadPlayers.Add(zdoID.userID);
                    ValheimEventHandler.OnPlayerDeath(GetPlayerInfo(__instance, zdoID));
                }
                else if (DeadPlayers.Contains(zdoID.userID))
                {
                    DeadPlayers.Remove(zdoID.userID);
                }
            }
Example #12
0
        internal void PartOfBlueprint(ZDOID blueprintID, PieceEntry entry)
        {
            ZDO pieceZDO = m_nView.GetZDO();

            pieceZDO.Set(zdoBlueprintID, blueprintID);
            pieceZDO.Set(zdoAdditionalInfo, entry.additionalInfo);
        }
Example #13
0
        public void PlanPieceRemovedFromBlueprint(PlanPiece planPiece)
        {
            ZDOID blueprintID = planPiece.GetBlueprintID();

            if (blueprintID == ZDOID.None)
            {
                return;
            }

            ZDO blueprintZDO = ZDOMan.instance.GetZDO(blueprintID);

            if (blueprintZDO == null)
            {
                return;
            }
            ZDOIDSet planPieces = GetPlanPieces(blueprintZDO);

            planPieces?.Remove(planPiece.GetPlanPieceID());
            if (planPieces == null || planPieces.Count() == 0)
            {
                GameObject blueprintObject = ZNetScene.instance.FindInstance(blueprintID);
                if (blueprintObject)
                {
                    ZNetScene.instance.Destroy(blueprintObject);
                }
            }
            else
            {
                blueprintZDO.Set(PlanPiece.zdoBlueprintPiece, planPieces.ToZPackage().GetArray());
            }
        }
Example #14
0
 // Token: 0x060007EE RID: 2030 RVA: 0x0003E8D0 File Offset: 0x0003CAD0
 private void RPC_RequestZDO(long sender, ZDOID id)
 {
     ZDOMan.ZDOPeer peer = this.GetPeer(sender);
     if (peer != null)
     {
         peer.ForceSendZDO(id);
     }
 }
Example #15
0
 // Token: 0x06000443 RID: 1091 RVA: 0x00022A63 File Offset: 0x00020C63
 public void SetPeer(ZDOID zdoid)
 {
     if (!this.m_nview.IsValid())
     {
         return;
     }
     this.m_nview.GetZDO().Set(this.m_linePeerID, zdoid);
 }
Example #16
0
 // Token: 0x0600075A RID: 1882 RVA: 0x0003AC3F File Offset: 0x00038E3F
 public void Initialize(ZDOMan man, ZDOID id, Vector3 position)
 {
     this.m_zdoMan   = man;
     this.m_uid      = id;
     this.m_position = position;
     this.m_sector   = ZoneSystem.instance.GetZone(this.m_position);
     this.m_zdoMan.AddToSector(this, this.m_sector);
 }
Example #17
0
    // Token: 0x060007BD RID: 1981 RVA: 0x0003CF50 File Offset: 0x0003B150
    public ZDO CreateNewZDO(ZDOID uid, Vector3 position)
    {
        ZDO zdo = ZDOPool.Create(this, uid, position);

        zdo.m_owner       = this.m_myid;
        zdo.m_timeCreated = ZNet.instance.GetTime().Ticks;
        this.m_objectsByID.Add(uid, zdo);
        return(zdo);
    }
Example #18
0
    // Token: 0x06000F09 RID: 3849 RVA: 0x0006B864 File Offset: 0x00069A64
    public bool IsLocalUser()
    {
        if (!Player.m_localPlayer)
        {
            return(false);
        }
        ZDOID user = this.GetUser();

        return(!user.IsNone() && user == Player.m_localPlayer.GetZDOID());
    }
Example #19
0
    // Token: 0x060007CF RID: 1999 RVA: 0x0003D610 File Offset: 0x0003B810
    private void RPC_DestroyZDO(long sender, ZPackage pkg)
    {
        int num = pkg.ReadInt();

        for (int i = 0; i < num; i++)
        {
            ZDOID uid = pkg.ReadZDOID();
            this.HandleDestroyedZDO(uid);
        }
    }
Example #20
0
        public static void Postfix(ZNet __instance, ZRpc rpc, ZDOID characterID)
        {
            if (!__instance.IsDedicated() && !__instance.IsServer())
            {
                return;
            }

            SendModVersionToClient(__instance.GetPeer(rpc).m_uid, MapSharingMadeEasy.instance.PluginVersion);
            SendConfigToClient(__instance.GetPeer(rpc).m_uid);
        }
Example #21
0
        protected Player GetPlayer(ZDOID characterID)
        {
            GameObject gameObject = ZNetScene.instance.FindInstance(characterID);

            if ((bool)gameObject)
            {
                return(gameObject.GetComponent <Player>());
            }
            return(null);
        }
Example #22
0
 // Token: 0x06000F05 RID: 3845 RVA: 0x0006B743 File Offset: 0x00069943
 private void RPC_ReleaseControl(long sender, ZDOID playerID)
 {
     if (!this.m_nview.IsOwner())
     {
         return;
     }
     if (this.GetUser() == playerID)
     {
         this.m_nview.GetZDO().Set("user", ZDOID.None);
     }
 }
Example #23
0
            static void Postfix(TeleportWorld __instance, ref ZNetView ___m_nview, ref bool __result)
            {
                lastPortalInteracted = __instance;
                lastPortalZNetView   = ___m_nview;

                if (!__result)
                {
                    return;
                }

                if (dropdownHolder == null)
                {
                    InitializeDropdownHolder();
                }
                portalList.Clear();
                dropdown.onValueChanged.RemoveAllListeners();
                dropdown.onValueChanged.AddListener(delegate
                {
                    DropdownValueChanged(dropdown);
                });
                dropdown.options.Clear();
                ZDOID thisPortalZDOID = ___m_nview.GetZDO().m_uid;
                // If the portal currently has a target configured, make sure that is the value selected in the dropdown
                // Otherwise, set the dropdown value to 0 (No destination)
                ZDOID targetZDOID = ___m_nview.GetZDO().GetZDOID("target");

                dropdown.options.Add(new Dropdown.OptionData("No destination"));
                var tmpPortalList = new List <ZDO>();

                ZDOMan.instance.GetAllZDOsWithPrefab(Game.instance.m_portalPrefab.name, tmpPortalList);
                // Sort alphabetically by portal tag and exclude self
                portalList = tmpPortalList.OrderBy(zdo => zdo.GetString("tag")).Where(zdo => zdo.m_uid != thisPortalZDOID).ToList();
                int index = 0;

                foreach (ZDO portalZDO in portalList)
                {
                    float distance = Vector3.Distance(__instance.transform.position, portalZDO.GetPosition());
                    if (distance == 0f)
                    {
                        continue;
                    }
                    dropdown.options.Add(new Dropdown.OptionData($"\"{portalZDO.GetString("tag")}\"  --  Distance: " + (int)distance));
                    if (portalZDO.m_uid == targetZDOID)
                    {
                        dropdown.value = index + 1;
                    }
                    index += 1;
                }
                if (targetZDOID == ZDOID.None)
                {
                    dropdown.value = 0;
                }
                dropdownHolder.SetActive(true);
            }
Example #24
0
    // Token: 0x060007B9 RID: 1977 RVA: 0x0003CB88 File Offset: 0x0003AD88
    public void Load(BinaryReader reader, int version)
    {
        reader.ReadInt64();
        uint num  = reader.ReadUInt32();
        int  num2 = reader.ReadInt32();

        ZDOPool.Release(this.m_objectsByID);
        this.m_objectsByID.Clear();
        this.ResetSectorArray();
        ZLog.Log(string.Concat(new object[]
        {
            "Loading ",
            num2,
            " zdos , my id ",
            this.m_myid,
            " data version:",
            version
        }));
        ZPackage zpackage = new ZPackage();

        for (int i = 0; i < num2; i++)
        {
            ZDO zdo = ZDOPool.Create(this);
            zdo.m_uid = new ZDOID(reader);
            int    count = reader.ReadInt32();
            byte[] data  = reader.ReadBytes(count);
            zpackage.Load(data);
            zdo.Load(zpackage, version);
            zdo.SetOwner(0L);
            this.m_objectsByID.Add(zdo.m_uid, zdo);
            this.AddToSector(zdo, zdo.GetSector());
            if (zdo.m_uid.userID == this.m_myid && zdo.m_uid.id >= num)
            {
                num = zdo.m_uid.id + 1U;
            }
        }
        this.m_deadZDOs.Clear();
        int num3 = reader.ReadInt32();

        for (int j = 0; j < num3; j++)
        {
            ZDOID key   = new ZDOID(reader.ReadInt64(), reader.ReadUInt32());
            long  value = reader.ReadInt64();
            this.m_deadZDOs.Add(key, value);
            if (key.userID == this.m_myid && key.id >= num)
            {
                num = key.id + 1U;
            }
        }
        this.CapDeadZDOList();
        ZLog.Log("Loaded " + this.m_deadZDOs.Count + " dead zdos");
        this.RemoveOldGeneratedZDOS();
        this.m_nextUid = num;
    }
Example #25
0
        public static void OnGameStart()
        {
            Debug.Log($"OnGameStart: ZDOMan.instance: {ZDOMan.instance}");
            var zdoidHashes = ZDO.GetHashZDOID("EpicLoot");
            var zdoid       = new ZDOID(zdoidHashes.Key, (uint)zdoidHashes.Value);

            _zdo = ZDOMan.instance.GetZDO(zdoid);
            if (_zdo == null)
            {
                _zdo = ZDOMan.instance.CreateNewZDO(zdoid, Vector3.zero);
            }
        }
        public static void VTTeleportTo(this Player player, ZNet.PlayerInfo target)
        {
            if (player != null)
            {
                ZDOID characterID = target.m_characterID;

                if (!characterID.IsNone())
                {
                    player.TeleportTo(target.m_position, player.transform.rotation, true);
                }
            }
        }
    // Token: 0x060000EF RID: 239 RVA: 0x0000714C File Offset: 0x0000534C
    private void UpdateSpawner()
    {
        if (!this.m_nview.IsOwner())
        {
            return;
        }
        ZDOID zdoid = this.m_nview.GetZDO().GetZDOID("spawn_id");

        if (this.m_respawnTimeMinuts <= 0f && !zdoid.IsNone())
        {
            return;
        }
        if (!zdoid.IsNone() && ZDOMan.instance.GetZDO(zdoid) != null)
        {
            this.m_nview.GetZDO().Set("alive_time", ZNet.instance.GetTime().Ticks);
            return;
        }
        if (this.m_respawnTimeMinuts > 0f)
        {
            DateTime time = ZNet.instance.GetTime();
            DateTime d    = new DateTime(this.m_nview.GetZDO().GetLong("alive_time", 0L));
            if ((time - d).TotalMinutes < (double)this.m_respawnTimeMinuts)
            {
                return;
            }
        }
        if (!this.m_spawnAtDay && EnvMan.instance.IsDay())
        {
            return;
        }
        if (!this.m_spawnAtNight && EnvMan.instance.IsNight())
        {
            return;
        }
        bool requireSpawnArea = this.m_requireSpawnArea;

        if (!this.m_spawnInPlayerBase && EffectArea.IsPointInsideArea(base.transform.position, EffectArea.Type.PlayerBase, 0f))
        {
            return;
        }
        if (this.m_triggerNoise > 0f)
        {
            if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance, this.m_triggerNoise))
            {
                return;
            }
        }
        else if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance))
        {
            return;
        }
        this.Spawn();
    }
            private static bool Prefix(WearNTear __instance, HitData hit)
            {
                if (WorldofValheimZones.ServerMode)
                {
                    return(true);
                }

                bool isInArea = false;

                // Is the area we are searching in a Warded area.
                if (Client.Ward.Damage && PrivateArea.CheckInPrivateArea(__instance.transform.position, false))
                {
                    ZDOID attacker = hit.m_attacker;
                    bool  isplayer = false;
                    foreach (var character in Character.GetAllCharacters())
                    {
                        if (character.GetZDOID() == attacker)
                        {
                            if (character.GetComponent <Player>())
                            {
                                isplayer = true;
                            }
                        }
                    }
                    // It's a player so lets see if it has access.
                    if (isplayer)
                    {
                        if (!PrivateArea.CheckAccess(Player.m_localPlayer.transform.position, 0f, true, false))
                        {
                            Util.DoAreaEffectW(__instance.transform.position);
                            MessageHud.instance.ShowMessage(MessageHud.MessageType.TopLeft, "This is a Warded Area", 0, null);
                            isInArea = true;
                            return(!isInArea);
                        }
                    }
                    else
                    {
                        // It's not a player so lets send out a Ward notification and block the damage.
                        PrivateArea.CheckInPrivateArea(__instance.transform.position, true);
                        isInArea = true;
                        return(!isInArea);
                    }
                }
                // Is the user restricted by NoBuildDamage?
                if (Util.RestrictionCheck("nobuilddamage"))
                {
                    isInArea = true;
                    Util.DoAreaEffect(__instance.transform.position + Vector3.up * 0.5f);
                    MessageHud.instance.ShowMessage(MessageHud.MessageType.TopLeft, "This is a Private Area", 0, null);
                }
                return(!isInArea);
            }
Example #29
0
    // Token: 0x0600088A RID: 2186 RVA: 0x00041A98 File Offset: 0x0003FC98
    public GameObject FindInstance(ZDOID id)
    {
        ZDO zdo = ZDOMan.instance.GetZDO(id);

        if (zdo != null)
        {
            ZNetView znetView = this.FindInstance(zdo);
            if (znetView)
            {
                return(znetView.gameObject);
            }
        }
        return(null);
    }
Example #30
0
    // Token: 0x060007C1 RID: 1985 RVA: 0x0003D0B4 File Offset: 0x0003B2B4
    public ZDO GetZDO(ZDOID id)
    {
        if (id == ZDOID.None)
        {
            return(null);
        }
        ZDO result;

        if (this.m_objectsByID.TryGetValue(id, out result))
        {
            return(result);
        }
        return(null);
    }