Exemple #1
0
        private void ZSteamSocket_Send(ZSteamSocket self, ZPackage pkg)
        {
            if (!(_isModEnabled.Value && _isOutputEnabled.Value))
            {
                return;
            }

            pkg.SetPos(0);
            int methodHash = pkg.ReadInt();

            if (methodHash == 0)
            {
                Logger.LogMessage($"Sending RPC Ping to {self.GetHostName()}");
            }
            else
            {
                try
                {
                    string method = pkg.ReadString();

                    if (method == "RoutedRPC")
                    {
                        ZPackage wrapped = pkg.ReadPackage();
                        _      = wrapped.ReadInt();
                        method = pkg.ReadString();
                    }

                    Logger.LogMessage($"Sending RPC {method} to {self.GetHostName()}");
                }
                catch (Exception) { }
            }
        }
Exemple #2
0
        private void ZSteamSocket_Recv(ZSteamSocket self, ZPackage pkg)
        {
            if (!(_isModEnabled.Value && _isOutputEnabled.Value))
            {
                return;
            }

            if (pkg != null)
            {
                int methodHash = pkg.ReadInt();
                if (methodHash == 0)
                {
                    Logger.LogMessage($"Received RPC Ping");
                }
                else
                {
                    try
                    {
                        string method = pkg.ReadString();

                        if (method == "RoutedRPC")
                        {
                            ZPackage wrapped = pkg.ReadPackage();
                            _      = wrapped.ReadInt();
                            method = pkg.ReadString();
                        }

                        Logger.LogMessage($"Received RPC {method}");
                    }
                    catch (Exception) { }
                }
                pkg.SetPos(0);
            }
        }
Exemple #3
0
 // Token: 0x06001161 RID: 4449 RVA: 0x00078784 File Offset: 0x00076984
 public void Deserialize(ZPackage pkg)
 {
     this.m_msgID        = pkg.ReadLong();
     this.m_senderPeerID = pkg.ReadLong();
     this.m_targetPeerID = pkg.ReadLong();
     this.m_targetZDO    = pkg.ReadZDOID();
     this.m_methodHash   = pkg.ReadInt();
     this.m_parameters   = pkg.ReadPackage();
 }
Exemple #4
0
        public static void LoadServerKnownRecipes(Dictionary <long, HashSet <string> > dict, ZPackage pkg)
        {
            var numEntries = pkg.ReadInt();

            for (var i = 0; i < numEntries; i++)
            {
                var pkg2     = pkg.ReadPackage();
                var playerID = pkg2.ReadInt();
                LoadKnownRecipes(playerID, pkg2, dict);
            }
        }
Exemple #5
0
        public static int LoadKnownMats(long sender, ZPackage pkg, Dictionary <long, HashSet <string> > outDict)
        {
            var pkgKnown  = pkg.ReadPackage();
            var tempKnown = new HashSet <string>();
            var numKnown  = pkgKnown.ReadInt();

            for (var i = 0; i < numKnown; i++)
            {
                tempKnown.Add(pkgKnown.ReadString());
            }
            SetKnownMats(sender, tempKnown, outDict);
            return(tempKnown.Count);
        }
Exemple #6
0
        public static int LoadKnownFromPkg(long sender, ZPackage pkg, Dictionary <long, HashSet <string> > outDict)
        {
            ZPackage pkgKnown  = pkg.ReadPackage();
            var      tempKnown = new HashSet <string>();
            int      numKnown  = pkgKnown.ReadInt();

            for (int i = 0; i < numKnown; i++)
            {
                tempKnown.Add(pkgKnown.ReadString());
            }
            if (outDict.ContainsKey(sender))
            {
                outDict.Remove(sender);
            }
            outDict.Add(sender, tempKnown);
            return(tempKnown.Count);
        }
Exemple #7
0
 // Token: 0x06000918 RID: 2328 RVA: 0x0004377C File Offset: 0x0004197C
 public static void Deserialize(ParameterInfo[] paramInfo, ZPackage pkg, ref List <object> parameters)
 {
     for (int i = 1; i < paramInfo.Length; i++)
     {
         ParameterInfo parameterInfo = paramInfo[i];
         if (parameterInfo.ParameterType == typeof(int))
         {
             parameters.Add(pkg.ReadInt());
         }
         else if (parameterInfo.ParameterType == typeof(uint))
         {
             parameters.Add(pkg.ReadUInt());
         }
         else if (parameterInfo.ParameterType == typeof(long))
         {
             parameters.Add(pkg.ReadLong());
         }
         else if (parameterInfo.ParameterType == typeof(float))
         {
             parameters.Add(pkg.ReadSingle());
         }
         else if (parameterInfo.ParameterType == typeof(double))
         {
             parameters.Add(pkg.ReadDouble());
         }
         else if (parameterInfo.ParameterType == typeof(bool))
         {
             parameters.Add(pkg.ReadBool());
         }
         else if (parameterInfo.ParameterType == typeof(string))
         {
             parameters.Add(pkg.ReadString());
         }
         else if (parameterInfo.ParameterType == typeof(ZPackage))
         {
             parameters.Add(pkg.ReadPackage());
         }
         else if (parameterInfo.ParameterType == typeof(List <string>))
         {
             int           num  = pkg.ReadInt();
             List <string> list = new List <string>(num);
             for (int j = 0; j < num; j++)
             {
                 list.Add(pkg.ReadString());
             }
             parameters.Add(list);
         }
         else if (parameterInfo.ParameterType == typeof(Vector3))
         {
             Vector3 vector = new Vector3(pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle());
             parameters.Add(vector);
         }
         else if (parameterInfo.ParameterType == typeof(Quaternion))
         {
             Quaternion quaternion = new Quaternion(pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle(), pkg.ReadSingle());
             parameters.Add(quaternion);
         }
         else if (parameterInfo.ParameterType == typeof(ZDOID))
         {
             parameters.Add(pkg.ReadZDOID());
         }
         else if (parameterInfo.ParameterType == typeof(HitData))
         {
             HitData hitData = new HitData();
             hitData.Deserialize(ref pkg);
             parameters.Add(hitData);
         }
     }
 }
Exemple #8
0
    // Token: 0x060007D3 RID: 2003 RVA: 0x0003D98C File Offset: 0x0003BB8C
    private void RPC_ZDOData(ZRpc rpc, ZPackage pkg)
    {
        ZDOMan.ZDOPeer zdopeer = this.FindPeer(rpc);
        if (zdopeer == null)
        {
            ZLog.Log("ZDO data from unkown host, ignoring");
            return;
        }
        float    time = Time.time;
        int      num  = 0;
        ZPackage pkg2 = new ZPackage();
        int      num2 = pkg.ReadInt();

        for (int i = 0; i < num2; i++)
        {
            ZDOID id  = pkg.ReadZDOID();
            ZDO   zdo = this.GetZDO(id);
            if (zdo != null)
            {
                zdo.InvalidateSector();
            }
        }
        for (;;)
        {
            ZDOID zdoid = pkg.ReadZDOID();
            if (zdoid.IsNone())
            {
                break;
            }
            num++;
            uint    num3   = pkg.ReadUInt();
            uint    num4   = pkg.ReadUInt();
            long    owner  = pkg.ReadLong();
            Vector3 vector = pkg.ReadVector3();
            pkg.ReadPackage(ref pkg2);
            ZDO  zdo2 = this.GetZDO(zdoid);
            bool flag = false;
            if (zdo2 != null)
            {
                if (num4 <= zdo2.m_dataRevision)
                {
                    if (num3 > zdo2.m_ownerRevision)
                    {
                        zdo2.m_owner          = owner;
                        zdo2.m_ownerRevision  = num3;
                        zdopeer.m_zdos[zdoid] = new ZDOMan.ZDOPeer.PeerZDOInfo(num4, num3, time);
                        continue;
                    }
                    continue;
                }
            }
            else
            {
                zdo2 = this.CreateNewZDO(zdoid, vector);
                flag = true;
            }
            zdo2.m_ownerRevision = num3;
            zdo2.m_dataRevision  = num4;
            zdo2.m_owner         = owner;
            zdo2.InternalSetPosition(vector);
            zdopeer.m_zdos[zdoid] = new ZDOMan.ZDOPeer.PeerZDOInfo(zdo2.m_dataRevision, zdo2.m_ownerRevision, time);
            zdo2.Deserialize(pkg2);
            if (ZNet.instance.IsServer() && flag && this.m_deadZDOs.ContainsKey(zdoid))
            {
                zdo2.SetOwner(this.m_myid);
                this.DestroyZDO(zdo2);
            }
        }
        this.m_zdosRecv += num;
    }
Exemple #9
0
        //CALLED ON SERVER, Should contain ZDOID and Inventory
        public static void RPC_CharacterIDX(ZRpc rpc, ZPackage pkg)
        {
            ZDOID characterID = pkg.ReadZDOID();

            ZNetPeer peer = (ZNetPeer)_GetPeerMethod.Invoke(ZNet.instance, new object[] { rpc });

            if (peer != null)
            {
                peer.m_characterID = characterID;
                if (Configs.ShowDebugMessages.Value)
                {
                    ZLog.Log($"Got character ZDOID with inventory from {peer.m_playerName} : {characterID}!");
                }
            }

            ZPackage inventoryPackage = pkg.ReadPackage();

            String characterName = inventoryPackage.ReadString();
            int    itemsCount    = inventoryPackage.ReadInt();

            String steamId = rpc.GetSocket().GetEndPointString();

            if (Configs.ShowDebugMessages.Value)
            {
                Instance.Logger.LogInfo($"Getting player {characterName}'s ({steamId}) inventory...");
            }

            List <Server_ItemData> playerItems = new List <Server_ItemData>();

            for (int i = 0; i < itemsCount; i++)
            {
                Server_ItemData data = new Server_ItemData
                {
                    Name    = inventoryPackage.ReadString(),
                    Stack   = inventoryPackage.ReadInt(),
                    Quality = inventoryPackage.ReadInt(),
                    Variant = inventoryPackage.ReadInt()
                };

                playerItems.Add(data);
            }

            if (Configs.ShowDebugMessages.Value)
            {
                Instance.Logger.LogInfo($"Found {playerItems.Count} items in {characterName}'s inventory.");
            }


            String dbId = $"{steamId}_{characterName}";

            var dbPlayer = Instance.DB.GetPlayerById(dbId);

            if (dbPlayer == null)
            {
                if (Configs.ShowDebugMessages.Value)
                {
                    Instance.Logger.LogInfo($"{characterName} is a new character!");
                }

                DBClasses.DBPlayer[] characters = Instance.DB.GetPlayersBySteamId(steamId);

                if (characters.Length >= Configs.MaxCharactersPerPlayer.Value)
                {
                    rpc.Invoke("Error", new object[] { (int)ZNet.ConnectionStatus.ErrorVersion });
                    return;
                }

                dbPlayer = new DBClasses.DBPlayer()
                {
                    DBPlayerId    = dbId,
                    SteamId       = steamId,
                    CharacterName = characterName,
                    Items         = new List <DBClasses.DBItem>()
                };

                foreach (var item in playerItems)
                {
                    dbPlayer.Items.Add(new DBClasses.DBItem()
                    {
                        ItemName = item.Name, PlayerId = dbPlayer.DBPlayerId, StackCount = item.Stack, Quality = item.Quality, Variant = item.Variant
                    });
                }

                Instance.DB.InsertPlayer(dbPlayer);
            }
            else
            {
                bool isSame = true;

                if (dbPlayer.Items.Count != playerItems.Count)
                {
                    isSame = false;
                }
                else
                {
                    for (int i = 0; i < dbPlayer.Items.Count; i++)
                    {
                        if (dbPlayer.Items[i].ItemName != playerItems[i].Name || dbPlayer.Items[i].StackCount != playerItems[i].Stack || dbPlayer.Items[i].Quality != playerItems[i].Quality || dbPlayer.Items[i].Variant != playerItems[i].Variant)
                        {
                            isSame = false;
                            break;
                        }
                    }
                }

                if (isSame)
                {
                    if (Configs.ShowDebugMessages.Value)
                    {
                        Instance.Logger.LogInfo($"{characterName} is still the same");
                    }
                    dbPlayer.LastLoggedIn = DateTime.Now;
                    Instance.DB.UpdatePlayer(dbPlayer);
                }
                else
                {
                    if (Configs.ShowDebugMessages.Value)
                    {
                        Instance.Logger.LogWarning($"{characterName} is NOT the same!");
                    }

                    rpc.Invoke("Error", new object[] { (int)ZNet.ConnectionStatus.ErrorVersion });
                }
            }
        }
Exemple #10
0
            static void Prefix(RoutedRPCData data)
            {
                var targetName = "";
                ZDO targetZDO;

                if (!data.m_targetZDO.IsNone())
                {
                    try
                    {
                        targetZDO  = ZDOMan.instance.GetZDO(data.m_targetZDO);
                        targetName = targetZDO.m_type.ToString();
                    }
                    catch { }
                }


                ZNetPeer peer    = ZNet.instance.GetPeer(data.m_senderPeerID);
                var      steamid = "";

                try {
                    steamid = peer.m_rpc.GetSocket().GetHostName();
                } catch {}

                if (data?.m_methodHash == "Say".GetStableHashCode())
                {
                    // private void RPC_Say(long sender, int ctype, string user, string text)

                    try
                    {
                        var      zdoData     = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos         = zdoData.GetPosition();
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        string   message     = package.ReadString();
                        message = (message == null ? "" : message).Trim();

                        if (message.StartsWith("/pin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinType      = "dot";
                            var startIdx     = 1;
                            if (messageParts.Length > 1 && ALLOWED_PINS.Contains(messageParts[1]))
                            {
                                pinType  = messageParts[1];
                                startIdx = 2;
                            }
                            var pinText = "";
                            if (startIdx < messageParts.Length)
                            {
                                pinText = String.Join(" ", messageParts, startIdx, messageParts.Length - startIdx);
                            }
                            if (pinText.Length > 40)
                            {
                                pinText = pinText.Substring(0, 40);
                            }
                            var safePinsText = Regex.Replace(pinText, @"[^a-zA-Z0-9 ]", "");
                            var uuId         = Guid.NewGuid();
                            var pinId        = uuId.ToString();
                            mapDataServer.AddPin(steamid, pinId, pinType, userName, pos, safePinsText);

                            var usersPins = mapDataServer.pins.FindAll(pin => pin.StartsWith(steamid));

                            var numOverflowPins = usersPins.Count - WebMapConfig.MAX_PINS_PER_USER;
                            for (var t = numOverflowPins; t > 0; t--)
                            {
                                var pinIdx = mapDataServer.pins.FindIndex(pin => pin.StartsWith(steamid));
                                // mapDataServer.RemovePin(pinIdx);
                                harmonyLog.LogInfo($"To many pins, deleting oldest one (ONLY DEBUG; WILL NOT DO)");
                            }

                            SavePins();
                        }
                        else if (message.StartsWith("/undoPin"))
                        {
                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => pin.StartsWith(steamid));
                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        else if (message.StartsWith("/deletePin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinText      = "";
                            if (messageParts.Length > 1)
                            {
                                pinText = String.Join(" ", messageParts, 1, messageParts.Length - 1);
                            }

                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => {
                                var pinParts = pin.Split(',');
                                return(pinParts[0] == steamid && pinParts[pinParts.Length - 1] == pinText);
                            });

                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        else if (!message.StartsWith("/"))
                        {
                            mapDataServer.Broadcast($"say\n{messageType}\n{userName}\n{message}");
                            harmonyLog.LogInfo($"say\n{messageType}\n{userName}\n{message} / target={targetName}");
                        }
                    }
                    catch
                    {
                        harmonyLog.LogError($"Say() exception");
                    }
                }
                else if (data?.m_methodHash == "ChatMessage".GetStableHashCode())
                {
                    // private void RPC_ChatMessage(long sender, Vector3 position, int type, string name, string text)
                    try
                    {
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        Vector3  pos         = package.ReadVector3();
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        string   message     = package.ReadString();
                        message = (message == null ? "" : message).Trim();

                        if (messageType == (int)Talker.Type.Ping)
                        {
                            mapDataServer.BroadcastPing(data.m_senderPeerID, userName, pos);
                        }
                        else
                        {
                            mapDataServer.Broadcast($"chat\n{messageType}\n{userName}\n{pos}\n{message}");
                            harmonyLog.LogInfo($"ChatMessage() chat\n{messageType}\n{userName}\n{pos}\n{message} / target={targetName}");
                        }
                    }
                    catch
                    {
                        harmonyLog.LogError($"ChatMessage() exception");
                    }
                }
                else if (data?.m_methodHash == "OnDeath".GetStableHashCode())
                {
                    // private void RPC_OnDeath(long sender)
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        mapDataServer.Broadcast($"ondeath\n{peer.m_playerName}");
                        harmonyLog.LogInfo($"RPC_OnDeath() -- {peer.m_playerName} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_OnDeath() exception");
                    }
                }
                else if (data?.m_methodHash == "Message".GetStableHashCode())
                {
                    // private void RPC_Message(long sender, int type, string msg, int amount)
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        int    messageType = package.ReadInt();
                        string msg         = package.ReadString();
                        int    amount      = package.ReadInt();

                        mapDataServer.Broadcast($"message\n{peer.m_playerName}\n{messageType}\n{msg}\n{amount}");
                        harmonyLog.LogInfo($"RPC_Message() -- {peer.m_playerName} / {msg} - {amount} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_Message() exception");
                    }
                }

                else if (data?.m_methodHash == "DamageText".GetStableHashCode())
                {
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        //float v = package.Read();
                        //bool alerted = package.ReadBool();
                        var pkg = package.ReadPackage();

                        DamageText.TextType type   = (DamageText.TextType)pkg.ReadInt();
                        Vector3             vector = pkg.ReadVector3();
                        float dmg  = pkg.ReadSingle();
                        bool  flag = pkg.ReadBool();

                        harmonyLog.LogInfo($"RPC_DamageText() -- {peer.m_playerName} / type={type} / pos={vector} / dmg={dmg} / flag={flag} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_DamageText() exception");
                    }
                }
                else if (data?.m_methodHash == "Damage".GetStableHashCode())
                {
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        harmonyLog.LogInfo($"RPC_Damage() -- {peer.m_playerName} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_Damage() exception");
                    }
                }
                else if (data?.m_methodHash == "DestroyZDO".GetStableHashCode())
                {
                    try
                    {
                        // supress
                        //ZPackage pkg = new ZPackage(data.m_parameters.GetArray());
                        //var pkg2 = pkg.ReadPackage();
                        //var numberofitems = pkg2.ReadInt();
                        //for (int i = 0; i < numberofitems; i++)
                        //{
                        //    ZDOID uid = pkg.ReadZDOID();

                        //}
                        //harmonyLog.LogInfo($"DestroyZDO() -- {peer.m_playerName} / numberofitems={numberofitems} / target={targetName}");
                    }
                    catch (Exception e)
                    {
                        harmonyLog.LogError($"DestroyZDO() exception " + e);
                    }
                }
                else if (data?.m_methodHash == "SetEvent".GetStableHashCode())
                {
                    try
                    {
                        //   var zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        //   var pos = zdoData.GetPosition();

                        ZPackage pkg = new ZPackage(data.m_parameters.GetArray());

                        var eventName = pkg.ReadString();
                        var time      = pkg.ReadSingle();
                        var eventPos  = pkg.ReadVector3();


                        if (!eventName.IsNullOrEmpty())
                        {
                            harmonyLog.LogInfo($"SetEvent() -- eventName={eventName} / time={time} / eventPos={eventPos} / target={targetName}");
                        }
                    }
                    catch (Exception e)
                    {
                        harmonyLog.LogError($"SetEvent() exception " + e);
                    }
                }
                else
                {
                    // Debug


                    //var methods = new List<string>() { "Jump", "OnJump", "SetMoveDir", "AddDPS", "AddFire", "BlockAttack", "UseStamina", "OnTargeted", "SetHealth", "SetCrouch",
                    //    "SetLookDir","SetRun", "Stagger", "Grow", "Shake", "CreateFragments", "RemotePrint","Pickup","Move","Die","Destroy","Awake","Loot","AddOre","EmptyProcessed",
                    //    "Interact","Hit","Create","Start","UseItem","UpdateTeleport","UseDoor","DropItem","AddNoise","Alert","Pick","Forward","Stop","OnHit","AddStatusEffect",
                    //    "Heal","AddFuel","OnNearProjectileHit","SleepStop","SleepStart","Ping", "Pong","DiscoverLocationRespons", "DiscoverClosestLocation",
                    //    "DestroyZDO","RequestZDO","SpawnObject","SetGlobalKey","GlobalKeys","LocationIcons","SetOwner","Extract","ResetCloth","SetTamed","RequestOpen","OpenRespons",
                    //    "RequestTakeAll", "TakeAllRespons","RequestOpen","SetSlotVisual","RemoveDoneItem","AddItem","Tap","Pickup","RequestPickup","Nibble","Step","SetPicked",
                    //    "ApplyOperation"


                    //};
                    //bool found = false;
                    //foreach (string method in methods)
                    //{
                    //    if (data?.m_methodHash == method.GetStableHashCode())
                    //    {
                    //        found = true;
                    //        harmonyLog.LogInfo($" -> DEBUG: {method}() ");
                    //    }

                    //}

                    //if (!found)
                    //{
                    //    // Unknown RPC message
                    //    harmonyLog.LogInfo($"<unknown rpc message> hash={data.m_methodHash}");
                    //}
                }
            }