Esempio n. 1
0
 static bool Prefix(ZSteamSocket __instance, Queue <byte[]> ___m_sendQueue, ref int ___m_totalSent, HSteamNetConnection ___m_con)
 {
     if (!__instance.IsConnected())
     {
         return(false);
     }
     while (___m_sendQueue.Count > 0)
     {
         byte[] source = ___m_sendQueue.Peek();
         IntPtr num    = Marshal.AllocHGlobal(source.Length);
         Marshal.Copy(source, 0, num, source.Length);
         // This was k_nSteamNetworkingSend_ReliableNoNagle before
         EResult connection = SteamNetworkingSockets.SendMessageToConnection(___m_con, num, (uint)source.Length, Constants.k_nSteamNetworkingSend_Reliable, out long _);
         Marshal.FreeHGlobal(num);
         if (connection == EResult.k_EResultOK)
         {
             ___m_totalSent += source.Length;
             ___m_sendQueue.Dequeue();
         }
         else
         {
             ZLog.Log("Failed to send data " + connection);
             break;
         }
     }
     return(false);
 }
Esempio n. 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);
            }
        }
Esempio n. 3
0
            public static void Post_Update(ZSteamSocket __instance, float dt)
            {
                return;

                CompStats cs;

                if (!CompStatsMan.compStats.TryGetValue(__instance, out cs))
                {
                    cs = new CompStats();
                    CompStatsMan.compStats.Add(__instance, cs);
                }

                if (cs.timeElapsed >= 5f)
                {
                    ZLog.Log(String.Concat(new[] {
                        $"Data sent\n" +
                        $"Uncompressed: {cs.dataSent}\n" +
                        $"Deflate: {cs.dataSentCompressed} | Ratio {((cs.dataSentCompressed > 0 && cs.dataSent > 0) ? ((float)cs.dataSentCompressed / (float)cs.dataSent * 100f) : 0f)}\n",
                        $"ZStd 3: {cs.dataSentZstd} | Ratio {((cs.dataSentZstd> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstd / (float)cs.dataSent * 100f) : 0f)}\n",
                        $"ZStd 1: {cs.dataSentZstdSlow} | Ratio {((cs.dataSentZstdSlow> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstdSlow / (float)cs.dataSent * 100f) : 0f)} "
                        //$"ZStd Dict: {cs.dataSentZstdStream} | Ratio {((cs.dataSentZstdStream> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstdStream / (float)cs.dataSent * 100f) : 0f)} "
                    }));
                    cs.dataSent           = 0L;
                    cs.dataSentCompressed = 0L;
                    cs.dataSentZstd       = 0L;
                    cs.dataSentZstdStream = 0L;
                    cs.dataSentZstdSlow   = 0L;
                    cs.timeElapsed        = 0f;
                }
                cs.timeElapsed += dt;
            }
        public static bool ParseServerArguments_modded(FejdStartup __instance, ref bool __result)
        {
            __instance.m_minimumPasswordLength = -1;

            string location = config.Location;

            if (!location.IsNullOrWhiteSpace())
            {
                Utils.SetSaveDataPath(location);
            }

            World createWorld = World.GetCreateWorld(config.WorldName);

            string serverName = config.ServerName;
            string password   = config.Password;

            if (!helper.isPasswordValid(password, createWorld, serverName))
            {
                ZLog.LogError("Error bad password because its displayd in server/map name or seed");
                Application.Quit();

                __result = false;
                return(false);
            }

            bool publiclyVisable = config.Visable;

            ZNet.SetServer(true, true, publiclyVisable, serverName, password, createWorld);
            ZNet.ResetServerHost();
            ZSteamSocket.SetDataPort(config.ServerPort);
            SteamManager.SetServerPort(config.ServerPort);

            __result = true;
            return(false);
        }
Esempio n. 5
0
 public static byte[] ProcessForDecompression(byte[] data, ZSteamSocket socket)
 {
     // TODO: Check if data is compressed
     //if (IsZstdCompressed(data)) {
     //}
     return(decompressor.Unwrap(data));
 }
Esempio n. 6
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) { }
            }
        }
Esempio n. 7
0
 // Token: 0x0600097F RID: 2431 RVA: 0x00045AF0 File Offset: 0x00043CF0
 public ZSteamSocket(CSteamID peerID)
 {
     ZSteamSocket.RegisterGlobalCallbacks();
     this.m_peerID.SetSteamID(peerID);
     this.m_con = SteamNetworkingSockets.ConnectP2P(ref this.m_peerID, 0, 0, null);
     ZLog.Log("Connecting to " + this.m_peerID.GetSteamID().ToString());
     ZSteamSocket.m_sockets.Add(this);
 }
Esempio n. 8
0
    // Token: 0x0600097E RID: 2430 RVA: 0x00045A6C File Offset: 0x00043C6C
    public ZSteamSocket(SteamNetworkingIPAddr host)
    {
        ZSteamSocket.RegisterGlobalCallbacks();
        string str;

        host.ToString(out str, true);
        ZLog.Log("Starting to connect to " + str);
        this.m_con = SteamNetworkingSockets.ConnectByIPAddress(ref host, 0, null);
        ZSteamSocket.m_sockets.Add(this);
    }
Esempio n. 9
0
    // Token: 0x06000980 RID: 2432 RVA: 0x00045B94 File Offset: 0x00043D94
    public ZSteamSocket(HSteamNetConnection con)
    {
        ZSteamSocket.RegisterGlobalCallbacks();
        this.m_con = con;
        SteamNetConnectionInfo_t steamNetConnectionInfo_t;

        SteamNetworkingSockets.GetConnectionInfo(this.m_con, out steamNetConnectionInfo_t);
        this.m_peerID = steamNetConnectionInfo_t.m_identityRemote;
        ZLog.Log("Connecting to " + this.m_peerID.ToString());
        ZSteamSocket.m_sockets.Add(this);
    }
Esempio n. 10
0
 // Token: 0x06000983 RID: 2435 RVA: 0x00045D30 File Offset: 0x00043F30
 private static void OnStatusChanged(SteamNetConnectionStatusChangedCallback_t data)
 {
     ZLog.Log("Got status changed msg " + data.m_info.m_eState);
     if (data.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connected && data.m_eOldState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connecting)
     {
         ZLog.Log("Connected");
         ZSteamSocket zsteamSocket = ZSteamSocket.FindSocket(data.m_hConn);
         if (zsteamSocket != null)
         {
             SteamNetConnectionInfo_t steamNetConnectionInfo_t;
             if (SteamNetworkingSockets.GetConnectionInfo(data.m_hConn, out steamNetConnectionInfo_t))
             {
                 zsteamSocket.m_peerID = steamNetConnectionInfo_t.m_identityRemote;
             }
             ZLog.Log("Got connection SteamID " + zsteamSocket.m_peerID.GetSteamID().ToString());
         }
     }
     if (data.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connecting && data.m_eOldState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_None)
     {
         ZLog.Log("New connection");
         ZSteamSocket listner = ZSteamSocket.GetListner();
         if (listner != null)
         {
             listner.OnNewConnection(data.m_hConn);
         }
     }
     if (data.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally)
     {
         ZLog.Log(string.Concat(new object[]
         {
             "Got problem ",
             data.m_info.m_eEndReason,
             ":",
             data.m_info.m_szEndDebug
         }));
         ZSteamSocket zsteamSocket2 = ZSteamSocket.FindSocket(data.m_hConn);
         if (zsteamSocket2 != null)
         {
             ZLog.Log("  Closing socket " + zsteamSocket2.GetHostName());
             zsteamSocket2.Close();
         }
     }
     if (data.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer)
     {
         ZLog.Log("Socket closed by peer " + data);
         ZSteamSocket zsteamSocket3 = ZSteamSocket.FindSocket(data.m_hConn);
         if (zsteamSocket3 != null)
         {
             ZLog.Log("  Closing socket " + zsteamSocket3.GetHostName());
             zsteamSocket3.Close();
         }
     }
 }
Esempio n. 11
0
 // Token: 0x06000985 RID: 2437 RVA: 0x00045F34 File Offset: 0x00044134
 public void Dispose()
 {
     ZLog.Log("Disposing socket");
     this.Close();
     this.m_pkgQueue.Clear();
     ZSteamSocket.m_sockets.Remove(this);
     if (ZSteamSocket.m_sockets.Count == 0)
     {
         ZLog.Log("Last socket, unregistering callback");
         ZSteamSocket.UnregisterGlobalCallbacks();
     }
 }
Esempio n. 12
0
        public static CompressionStream GetCompStream(ZSteamSocket socket)
        {
            CompressionStream compStream;

            if (!compStreams.TryGetValue(socket, out compStream))
            {
                var stream = new MemoryStream();
                compStream = new CompressionStream(new MemoryStream());
                compStreams.Add(socket, compStream);
                compStreamsData.Add(socket, stream);
            }
            return(compStream);
        }
Esempio n. 13
0
        public static byte[] ProcessForCompression(byte[] data, ZSteamSocket socket)
        {
            return(compressor.Wrap(data));

            byte[] dataClone = data.ToArray();
            //buffer.Add(dataClone);

            /*using (var stream = new FileStream("C:\\Users\\jayess\\code\\ValheimCompressionDictData.dat", FileMode.Append))
             * {
             *  stream.Write(data, 0, data.Length);
             * }*/

            CompStats cs;

            if (!CompStatsMan.compStats.TryGetValue(socket, out cs))
            {
                cs = new CompStats();
                CompStatsMan.compStats.Add(socket, cs);
            }
            cs.dataSent += dataClone.Length;

            MemoryStream output = new MemoryStream();

            using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Optimal))
            {
                dstream.Write(dataClone.ToArray(), 0, dataClone.Length);
            }
            cs.dataSentCompressed += output.ToArray().Length;


            cs.dataSentZstd += CompressionMan.compressor.Wrap(data.ToArray()).Length;
            //cs.dataSentZstdSlow += CompressionMan.slowCompressor.Wrap(data.ToArray()).Length;

            //using (var compressor = new Compressor(new CompressionOptions(File.ReadAllBytes("C:\\Users\\jayess\\code\\ValheimCompressionDict.dat"))))
            //{
            //    cs.dataSentZstdStream += compressor.Wrap(data.ToArray()).Length;
            //}
        }
Esempio n. 14
0
    // Token: 0x06000989 RID: 2441 RVA: 0x000460C8 File Offset: 0x000442C8
    private void QueuePendingConnection(HSteamNetConnection con)
    {
        ZSteamSocket item = new ZSteamSocket(con);

        this.m_pendingConnections.Enqueue(item);
    }
Esempio n. 15
0
 private static void ZSteamSocket_Send(ZSteamSocket __instance, ZPackage pkg) => instance.ZSteamSocket_Send(__instance, pkg);
Esempio n. 16
0
 // Token: 0x0600097D RID: 2429 RVA: 0x00045A10 File Offset: 0x00043C10
 public ZSteamSocket()
 {
     ZSteamSocket.RegisterGlobalCallbacks();
     ZSteamSocket.m_sockets.Add(this);
 }
Esempio n. 17
0
 private static void ZSteamSocket_Recv(ZSteamSocket __instance, ref ZPackage __result) => instance.ZSteamSocket_Recv(__instance, __result);