Exemple #1
0
        private static bool Prefix(ref ZNet __instance, ZRpc rpc, ZPackage pkg)
        {
            if (__instance.IsServer())
            {
                string self = "";
                if (pkg.Size() > 32)
                {
                    pkg.SetPos(pkg.Size() - 32 - 1);
                    if (pkg.ReadByte() == (byte)32)
                    {
                        pkg.SetPos(pkg.GetPos() - 1);
                        self = pkg.ReadString();
                    }
                }

                ZLog.Log((object)("[AntiMods]: Got client hash: " + self + "\nmine: " + VACPlugin.PluginsHash));
                ZLog.LogWarning("Plugins Hash is Equals: " + !self.Equals(VACPlugin.PluginsHash) + " ForceMods: " + VACPlugin.forcesamemods.Value);
                ZLog.LogWarning("Is in Admin List: " + !ZNet.instance.m_adminList.Contains(rpc.GetSocket().GetHostName()) + "Admin Bypass: "******"[AntiMods]: Kicking Client: " + rpc.GetSocket().GetEndPointString() + " (incompatible mods)"));
                    rpc.Invoke("Error", (object)num);
                    return(false);
                }

                ZLog.Log((object)("[AntiMods]: Accepting Client: " + rpc.GetSocket().GetEndPointString()));
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        ///     Receive and handle an incoming package
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="package"></param>
        internal void ReceivePackage(long sender, ZPackage package)
        {
            if (package == null || package.Size() <= 0)
            {
                return;
            }

            Logger.LogDebug($"[{ID}] Received package");
            try
            {
                CacheExpirations.RemoveAll(kv =>
                {
                    if (kv.Key < DateTimeOffset.Now.Ticks)
                    {
                        PackageCache.Remove(kv.Value);
                        return(true);
                    }

                    return(false);
                });

                byte packageFlags = package.ReadByte();

                if ((packageFlags & FRAGMENTED_PACKAGE) != 0)
                {
                    long   uniqueIdentifier = package.ReadLong();
                    string cacheKey         = sender.ToString() + uniqueIdentifier;
                    int    fragment         = package.ReadInt();
                    int    fragments        = package.ReadInt();

                    if (!PackageCache.TryGetValue(cacheKey, out SortedDictionary <int, byte[]> dataFragments))
                    {
                        dataFragments          = new SortedDictionary <int, byte[]>();
                        PackageCache[cacheKey] = dataFragments;
                        CacheExpirations.Add(new KeyValuePair <long, string>(DateTimeOffset.Now.AddSeconds(60).Ticks, cacheKey));
                    }

                    dataFragments.Add(fragment, package.ReadByteArray());

                    if (dataFragments.Count < fragments)
                    {
                        return;
                    }

                    PackageCache.Remove(cacheKey);

                    package      = new ZPackage(dataFragments.Values.SelectMany(a => a).ToArray());
                    packageFlags = package.ReadByte();
                }

                ZNet.instance.StartCoroutine(HandlePackageRoutine(sender, package, packageFlags));
            }
            catch (Exception e)
            {
                Logger.LogWarning($"[{ID}] Error caught while applying package: {e}");
            }
        }
Exemple #3
0
        private IEnumerator HandlePackageRoutine(long sender, ZPackage package, byte packageFlags)
        {
            Logger.LogDebug($"[{ID}] Processing package");
            try
            {
                ++ProcessingCount;

                if ((packageFlags & COMPRESSED_PACKAGE) != 0)
                {
                    byte[] data = package.ReadByteArray();

                    MemoryStream input  = new MemoryStream(data);
                    MemoryStream output = new MemoryStream();
                    using (DeflateStream deflateStream = new DeflateStream(input, CompressionMode.Decompress))
                    {
                        deflateStream.CopyTo(output);
                    }

                    package      = new ZPackage(output.ToArray());
                    packageFlags = package.ReadByte();

                    Logger.LogDebug($"[{ID}] Decompressed package to length {output.Length}");
                }

                if ((packageFlags & JOTUNN_PACKAGE) != JOTUNN_PACKAGE)
                {
                    Logger.LogWarning($"[{ID}] Package flag does not equal {JOTUNN_PACKAGE} ({packageFlags:X4})");
                    yield break;
                }

                byte[]   finalBytes   = package.ReadByteArray();
                ZPackage finalPackage = new ZPackage(finalBytes);
                package = finalPackage;

                if (!ZNet.instance.IsServer())
                {
                    yield return(OnClientReceive(sender, package));
                }
                else
                {
                    yield return(OnServerReceive(sender, package));
                }
            }
            finally
            {
                --ProcessingCount;
            }
        }
Exemple #4
0
        public static bool[] UnpackBoolArray(ZPackage z, int length)
        {
            var arr = new bool[length];

            for (var i = 0; i < length; i += 8)
            {
                var b = z.ReadByte();

                arr[i]     = (b & (1 << 0)) != 0;
                arr[i + 1] = (b & (1 << 1)) != 0;
                arr[i + 2] = (b & (1 << 2)) != 0;
                arr[i + 3] = (b & (1 << 3)) != 0;
                arr[i + 4] = (b & (1 << 4)) != 0;
                arr[i + 5] = (b & (1 << 5)) != 0;
                arr[i + 6] = (b & (1 << 6)) != 0;
                arr[i + 7] = (b & (1 << 7)) != 0;
            }

            // Utility.Log("Decompressed exploration array:  " + z.Size() + ":" + arr.Length);
            return(arr);
        }
Exemple #5
0
    // Token: 0x06000791 RID: 1937 RVA: 0x0003B918 File Offset: 0x00039B18
    public void Deserialize(ZPackage pkg)
    {
        this.m_persistent  = pkg.ReadBool();
        this.m_distant     = pkg.ReadBool();
        this.m_timeCreated = pkg.ReadLong();
        this.m_pgwVersion  = pkg.ReadInt();
        this.m_type        = (ZDO.ObjectType)pkg.ReadSByte();
        this.m_prefab      = pkg.ReadInt();
        this.m_rotation    = pkg.ReadQuaternion();
        int num = pkg.ReadInt();

        if ((num & 1) != 0)
        {
            this.InitFloats();
            int num2 = (int)pkg.ReadByte();
            for (int i = 0; i < num2; i++)
            {
                int key = pkg.ReadInt();
                this.m_floats[key] = pkg.ReadSingle();
            }
        }
        else
        {
            this.ReleaseFloats();
        }
        if ((num & 2) != 0)
        {
            this.InitVec3();
            int num3 = (int)pkg.ReadByte();
            for (int j = 0; j < num3; j++)
            {
                int key2 = pkg.ReadInt();
                this.m_vec3[key2] = pkg.ReadVector3();
            }
        }
        else
        {
            this.ReleaseVec3();
        }
        if ((num & 4) != 0)
        {
            this.InitQuats();
            int num4 = (int)pkg.ReadByte();
            for (int k = 0; k < num4; k++)
            {
                int key3 = pkg.ReadInt();
                this.m_quats[key3] = pkg.ReadQuaternion();
            }
        }
        else
        {
            this.ReleaseQuats();
        }
        if ((num & 8) != 0)
        {
            this.InitInts();
            int num5 = (int)pkg.ReadByte();
            for (int l = 0; l < num5; l++)
            {
                int key4 = pkg.ReadInt();
                this.m_ints[key4] = pkg.ReadInt();
            }
        }
        else
        {
            this.ReleaseInts();
        }
        if ((num & 64) != 0)
        {
            this.InitLongs();
            int num6 = (int)pkg.ReadByte();
            for (int m = 0; m < num6; m++)
            {
                int key5 = pkg.ReadInt();
                this.m_longs[key5] = pkg.ReadLong();
            }
        }
        else
        {
            this.ReleaseLongs();
        }
        if ((num & 16) != 0)
        {
            this.InitStrings();
            int num7 = (int)pkg.ReadByte();
            for (int n = 0; n < num7; n++)
            {
                int key6 = pkg.ReadInt();
                this.m_strings[key6] = pkg.ReadString();
            }
            return;
        }
        this.ReleaseStrings();
    }
Exemple #6
0
    public void Deserialize(ZPackage pkg)
    {
        this.m_persistent  = pkg.ReadBool();
        this.m_distant     = pkg.ReadBool();
        this.m_timeCreated = pkg.ReadLong();
        this.m_pgwVersion  = pkg.ReadInt();
        this.m_type        = (ZDO.ObjectType)pkg.ReadSByte();
        this.m_prefab      = pkg.ReadInt();
        this.m_rotation    = pkg.ReadQuaternion();
        int num1 = pkg.ReadInt();

        if ((num1 & 1) != 0)
        {
            this.InitFloats();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_floats[pkg.ReadInt()] = pkg.ReadSingle();
            }
        }
        else
        {
            this.ReleaseFloats();
        }
        if ((num1 & 2) != 0)
        {
            this.InitVec3();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_vec3[pkg.ReadInt()] = pkg.ReadVector3();
            }
        }
        else
        {
            this.ReleaseVec3();
        }
        if ((num1 & 4) != 0)
        {
            this.InitQuats();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_quats[pkg.ReadInt()] = pkg.ReadQuaternion();
            }
        }
        else
        {
            this.ReleaseQuats();
        }
        if ((num1 & 8) != 0)
        {
            this.InitInts();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_ints[pkg.ReadInt()] = pkg.ReadInt();
            }
        }
        else
        {
            this.ReleaseInts();
        }
        if ((num1 & 64) != 0)
        {
            this.InitLongs();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_longs[pkg.ReadInt()] = pkg.ReadLong();
            }
        }
        else
        {
            this.ReleaseLongs();
        }
        if ((num1 & 16) != 0)
        {
            this.InitStrings();
            int num2 = (int)pkg.ReadByte();
            for (int index = 0; index < num2; ++index)
            {
                this.m_strings[pkg.ReadInt()] = pkg.ReadString();
            }
        }
        else
        {
            this.ReleaseStrings();
        }
    }