public void DoNetwork()
        {
            if (((network_0 != null) && network_0.Connected) && (packet_0 = network_0.Receive(0L)).Received)
            {
                if (ProtectLoader.Debug)
                {
                    UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x36a), packet_0.Type, Class3.smethod_10(0x37e), packet_0.Received.ToString(), Class3.smethod_10(920), packet_0.Length, Class3.smethod_10(0x3ae), packet_0.RemainingBytes, Class3.smethod_10(970), packet_0.Flags, Class3.smethod_10(0x3dc) }));
                }
                if (((verifyFile_0.Length != 0) || (packet_0.Type == NetLink.Network.PacketType.Response)) && ((packet_0.Type != NetLink.Network.PacketType.Response) || packet_0.Flags.Has <NetLink.Network.PacketFlag>(NetLink.Network.PacketFlag.Compressed)))
                {
                    NetLink.Network.PacketType type = packet_0.Type;
                    switch (type)
                    {
                    case NetLink.Network.PacketType.Pingpong:
                        network_0.SendPacket(NetLink.Network.PacketType.Pingpong, NetLink.Network.PacketFlag.None, null);
                        return;

                    case NetLink.Network.PacketType.Disconnect:
                        smethod_8(Class3.smethod_10(0x3e2));
                        network_0.Dispose();
                        UnityEngine.Object.DestroyImmediate(base.gameObject);
                        return;
                    }
                    if ((type == NetLink.Network.PacketType.DataStream) && packet_0.Flags.Has <NetLink.Network.PacketFlag>(NetLink.Network.PacketFlag.Compressed))
                    {
                        MessageType message = (MessageType)((short)packet_0.Read <ushort>());
                        this.DoNetworkMessageData(packet_0, message);
                    }
                }
            }
        }
 private void LateUpdate()
 {
     if ((NetCull.isClientRunning && (network_0 != null)) && network_0.Connected)
     {
         if ((playerClient == null) && (PlayerClient.GetLocalPlayer() != null))
         {
             playerClient = PlayerClient.GetLocalPlayer();
             UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(820), playerClient.userName, Class3.smethod_10(840), playerClient.userID, Class3.smethod_10(0x34e) }));
             NetLink.Network.Packet packet = new NetLink.Network.Packet(NetLink.Network.PacketType.Firstpass, NetLink.Network.PacketFlag.Compressed, null);
             packet.Write <ushort>(MessageType.Approve);
             packet.Write <string>(SystemInfo.operatingSystem);
             packet.Write <string>(string_4);
             network_0.Send(packet);
             thread_0 = new Thread(new ThreadStart(Protection.smethod_7));
             thread_0.Start();
             base.InvokeRepeating(Class3.smethod_10(0x290), 0f, 0.1f);
             base.InvokeRepeating(Class3.smethod_10(0x2a6), 0f, 1f);
         }
     }
     else
     {
         base.CancelInvoke();
         smethod_8(null);
         if (network_0 != null)
         {
             network_0.Dispose();
         }
         UnityEngine.Object.DestroyImmediate(this);
         UnityEngine.Debug.Log(Class3.smethod_10(0x2fe));
     }
 }
 public void DoSnapshot()
 {
     if ((network_0.Connected && base.IsInvoking()) && (Screenshot != null))
     {
         base.CancelInvoke(Class3.smethod_10(0x4a4));
         NetLink.Network.Packet packet = new NetLink.Network.Packet(NetLink.Network.PacketType.DataStream, NetLink.Network.PacketFlag.Compressed, null);
         packet.Write <ushort>(MessageType.Screenshot);
         packet.Write <string>(Steam_ID.ToString());
         packet.Write(Screenshot, 0, Screenshot.Length);
         network_0.Send(packet);
         Screenshot = null;
     }
 }
 private static void smethod_0(string string_5, [Optional, DefaultParameterValue("")] string string_6, [Optional, DefaultParameterValue(false)] bool bool_2)
 {
     if (((network_0 != null) && network_0.Connected) && (Time.time > float_0))
     {
         float_0 = Time.time + 1f;
         if (string.IsNullOrEmpty(string_6))
         {
             string_6 = "";
         }
         if (string.IsNullOrEmpty(string_5))
         {
             string_5 = Class3.smethod_10(0x4bc);
         }
         NetLink.Network.Packet packet = new NetLink.Network.Packet(NetLink.Network.PacketType.DataStream, NetLink.Network.PacketFlag.Compressed, null);
         packet.Write <ushort>(MessageType.KickMessage);
         packet.Write <bool>(bool_2);
         packet.Write <string>(string_6);
         packet.Write <string>(string_5);
         network_0.Send(packet);
     }
 }
Exemplo n.º 5
0
 public static void OnConnect(string url, int port)
 {
     try
     {
         ProtectLoader.Enabled       = false;
         ProtectLoader.NetCrypt      = null;
         ProtectLoader.EncryptionKey = null;
         ProtectLoader.Debug         = Environment.CommandLine.Contains("-debug");
         ProtectLoader.Netlog        = Environment.CommandLine.Contains("-netlog");
         ProtectLoader.NetClient     = new NetLink.Network(url, port);
         if (ProtectLoader.NetClient.Connected)
         {
             ProtectLoader.NetClient.SendPacket(NetLink.Network.PacketType.Firstpass, NetLink.Network.PacketFlag.None, null);
             ProtectLoader.NetPacket = ProtectLoader.NetClient.Receive(2000L);
             if (ProtectLoader.NetPacket.Received && ProtectLoader.NetPacket.Type == NetLink.Network.PacketType.Response && (byte)(ProtectLoader.NetPacket.Flags & NetLink.Network.PacketFlag.Compressed) == 1)
             {
                 ProtectLoader.Enabled = ProtectLoader.NetPacket.Read <bool>();
                 if (ProtectLoader.NetPacket.Length > 0L && ProtectLoader.Enabled)
                 {
                     ProtectLoader.Encryption = ProtectLoader.NetPacket.Read <bool>();
                     byte[] array;
                     string file = ProtectLoader.NetPacket.GetFile(out array);
                     if (file.Equals("RustProtect.Core", StringComparison.CurrentCultureIgnoreCase))
                     {
                         try
                         {
                             if (array != null && array.Length > 0 && Method.Initialize(Assembly.Load(array)))
                             {
                                 object[] args = new object[]
                                 {
                                     url,
                                     port,
                                     array
                                 };
                                 Method.Invoke("RustProtect.Protection.Initialize", args);
                                 if (ProtectLoader.Encryption)
                                 {
                                     ProtectLoader.EncryptionKey = Method.Invoke("RustProtect.Protection.EncryptionKey").AsByteArray;
                                 }
                                 if (ProtectLoader.EncryptionKey != null && ProtectLoader.EncryptionKey.Length == 64)
                                 {
                                     ProtectLoader.NetCrypt = new Network.NetEncryption(EncryptionKey);
                                 }
                                 ProtectLoader.Enabled = true;
                             }
                         }
                         catch (Exception)
                         {
                             ProtectLoader.Enabled = false;
                         }
                     }
                 }
             }
             ProtectLoader.NetClient.Dispose();
         }
     }
     catch (Exception ex)
     {
         UnityEngine.Debug.LogError(ex.ToString());
     }
 }
 public void DoNetworkMessageData(NetLink.Network.Packet packet, MessageType message)
 {
     if (ProtectLoader.Debug)
     {
         UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x418), network_0.RemoteEndPoint, Class3.smethod_10(0x456), message }));
     }
     if (message == MessageType.Checksum)
     {
         int num2 = packet_0.Read <int>();
         verifyFile_0 = new VerifyFile[num2];
         for (int i = 0; i < num2; i++)
         {
             verifyFile_0[i] = new VerifyFile {
                 Filename = packet_0.Read <string>(), Filesize = packet_0.Read <long>()
             };
         }
         thread_1 = new Thread(new ThreadStart(Protection.smethod_6));
         thread_1.Start();
     }
     else if (message == MessageType.Screenshot)
     {
         RustProtect.Snapshot.Singleton.CaptureSnapshot();
         base.InvokeRepeating(Class3.smethod_10(0x4a4), 0f, 0.1f);
     }
     else if (message == MessageType.OverrideItems)
     {
         int num4 = packet.Read <int>();
         for (int j = 0; j < num4; j++)
         {
             try
             {
                 BlueprintDataBlock block2;
                 ItemDataBlock      byName = DatablockDictionary.GetByName(packet.Read <string>());
                 if (byName == null)
                 {
                     throw new Exception();
                 }
                 byName.itemDescriptionOverride = packet.Read <string>();
                 byName.isResearchable          = packet.Read <bool>();
                 byName.isRecycleable           = packet.Read <bool>();
                 byName.isRepairable            = packet.Read <bool>();
                 byName._splittable             = packet.Read <bool>();
                 byName.doesLoseCondition       = packet.Read <bool>();
                 byName._maxCondition           = packet.Read <float>();
                 byName._minUsesForDisplay      = packet.Read <int>();
                 byName._spawnUsesMin           = packet.Read <int>();
                 byName._spawnUsesMax           = packet.Read <int>();
                 if (packet.Read <bool>() && smethod_9(byName, out block2))
                 {
                     block2.numResultItem    = packet.Read <int>();
                     block2.craftingDuration = packet.Read <float>();
                     block2.RequireWorkbench = packet.Read <bool>();
                     int num5 = packet.Read <int>();
                     System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry> list = new System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry>();
                     for (int k = 0; k < num5; k++)
                     {
                         BlueprintDataBlock.IngredientEntry item = new BlueprintDataBlock.IngredientEntry {
                             amount     = packet.Read <int>(),
                             Ingredient = DatablockDictionary.GetByName(packet.Read <string>())
                         };
                         if ((item.amount > 0) && (item.Ingredient != null))
                         {
                             list.Add(item);
                         }
                     }
                     block2.ingredients = list.ToArray();
                 }
             }
             catch (Exception)
             {
                 UnityEngine.Debug.Log(Class3.smethod_10(0x460));
                 return;
             }
         }
     }
 }
 private static void smethod_6()
 {
     if (verifyFile_0.Length != 0)
     {
         try
         {
             string contents = "";
             ulong  maxValue = ulong.MaxValue;
             MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
             IntPtr processHandle = Process32.OpenProcess(Process32.PROCESS_QUERY_INFORMATION | Process32.PROCESS_VM_READ, 0, (uint)process_0.Id);
             if (processHandle == IntPtr.Zero)
             {
                 ulong_0 = ulong.MaxValue;
             }
             else
             {
                 Dictionary <string, MemoryAssemblyEntry> dictionary = new Dictionary <string, MemoryAssemblyEntry>();
                 uint num2 = Process32.smethod_3(processHandle, (long)(process_0.MainModule.BaseAddress.ToInt32() + 0xa1f9cc));
                 uint num3 = 0;
                 bool flag = false;
                 int  num4 = 0;
                 uint num5 = 0;
                 uint num6 = num2;
                 while (num3 < 0x800)
                 {
                     if (num4 >= Assemblies.Length)
                     {
                         break;
                     }
                     try
                     {
                         num3 += 4;
                         if (!flag)
                         {
                             num5 = Process32.smethod_3(processHandle, (long)(num2 + num3));
                             if (num5 == 0)
                             {
                                 continue;
                             }
                             num6 = Process32.smethod_3(processHandle, (long)(num5 + 20));
                             if (num6 == 0)
                             {
                                 continue;
                             }
                             string path = Process32.ReadString(processHandle, (long)num6);
                             if (!path.ToLower().EndsWith(Class3.smethod_10(0x714)) || !File.Exists(path))
                             {
                                 continue;
                             }
                             if (ProtectLoader.Debug)
                             {
                                 UnityEngine.Debug.Log(Class3.smethod_10(0x736) + num5.ToString(Class3.smethod_10(0x758)));
                             }
                             flag = true;
                         }
                         num6 = Process32.smethod_3(processHandle, (long)(num2 + num3));
                         uint num8 = Process32.smethod_3(processHandle, (long)(num6 + 12));
                         if (num8 > 0)
                         {
                             uint num7  = Process32.smethod_3(processHandle, (long)(num6 + 8));
                             uint num9  = Process32.smethod_3(processHandle, (long)(num6 + 20));
                             uint num10 = Process32.smethod_3(processHandle, (long)(num6 + 0x20));
                             if (((num7 > 0) && (num9 > 0)) && (num10 > 0))
                             {
                                 MemoryAssemblyEntry entry2 = new MemoryAssemblyEntry {
                                     Pointer       = (long)num7,
                                     Filesize      = num8,
                                     Filepath      = Process32.ReadString(processHandle, (long)num9),
                                     TargetRuntime = Process32.ReadString(processHandle, (long)num10)
                                 };
                                 if (File.Exists(entry2.Filepath))
                                 {
                                     string str2 = entry2.Filepath.Replace(string_0, "");
                                     dictionary[str2] = entry2;
                                     num4++;
                                     if (ProtectLoader.Debug)
                                     {
                                         UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x760), entry2.Pointer.ToString(Class3.smethod_10(0x758)), Class3.smethod_10(0x78c), entry2.Filesize, Class3.smethod_10(0x7b8), str2, Class3.smethod_10(0x7e4), entry2.Filepath, Class3.smethod_10(0x810), entry2.TargetRuntime }));
                                     }
                                 }
                             }
                         }
                         continue;
                     }
                     catch (Exception exception)
                     {
                         ulong_0 = ulong.MaxValue;
                         if (ProtectLoader.Debug)
                         {
                             UnityEngine.Debug.LogError(exception.ToString());
                         }
                         return;
                     }
                 }
                 if (!flag)
                 {
                     ulong_0 = ulong.MaxValue;
                     if (ProtectLoader.Debug)
                     {
                         UnityEngine.Debug.LogError(Class3.smethod_10(0x848));
                     }
                 }
                 else
                 {
                     foreach (VerifyFile file in verifyFile_0)
                     {
                         MemoryAssemblyEntry entry3;
                         if (!File.Exists(file.Filename))
                         {
                             break;
                         }
                         contents = contents + file.Filename + Class3.smethod_10(0x8a4);
                         string str4 = Path.GetFileName(file.Filename).Replace(Class3.smethod_10(0x8ac), Class3.smethod_10(0x8b2));
                         if (dictionary.TryGetValue(file.Filename, out entry3))
                         {
                             if (file.Filesize != entry3.Filesize)
                             {
                                 break;
                             }
                             byte[] buffer = Process32.ReadBytes(processHandle, entry3.Pointer, (int)entry3.Filesize);
                             if ((buffer == null) || (buffer.Length != entry3.Filesize))
                             {
                                 break;
                             }
                             maxValue ^= BitConverter.ToUInt64(provider.ComputeHash(buffer), 0);
                             maxValue ^= BitConverter.ToUInt64(provider.ComputeHash(Encoding.UTF8.GetBytes(file.Filename)), 0);
                         }
                         else if ((str4.Contains(Class3.smethod_10(0x8b8)) && !(str4 == Class3.smethod_10(0x8ce))) && !(Path.GetExtension(str4).ToLower() != Class3.smethod_10(0x8f0)))
                         {
                             UnityEngine.Debug.LogError(Class3.smethod_10(0x8fc) + str4);
                         }
                         else
                         {
                             maxValue ^= BitConverter.ToUInt64(provider.ComputeHash(File.ReadAllBytes(file.Filename)), 0);
                             maxValue ^= BitConverter.ToUInt64(provider.ComputeHash(Encoding.UTF8.GetBytes(file.Filename)), 0);
                         }
                     }
                     Process32.CloseHandle(processHandle);
                     ulong_0 = maxValue;
                     if (ProtectLoader.Debug)
                     {
                         contents = contents + Class3.smethod_10(0x93e) + ulong_0.ToString(Class3.smethod_10(0x5fe));
                         File.WriteAllText(Path.Combine(Application.dataPath, Class3.smethod_10(0x95c)), contents);
                         System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
                         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                         {
                             list.Add(assembly.GetName().Name);
                         }
                         File.WriteAllLines(Path.Combine(Application.dataPath, Class3.smethod_10(0x984)), list.ToArray());
                     }
                     if ((network_0 != null) && network_0.Connected)
                     {
                         Assembly[]             assemblies = Assemblies;
                         NetLink.Network.Packet packet     = new NetLink.Network.Packet(NetLink.Network.PacketType.DataStream, NetLink.Network.PacketFlag.Compressed, null);
                         packet.Write <ushort>(MessageType.Checksum);
                         packet.Write <ulong>(ulong_0);
                         packet.Write <int>(assemblies.Length);
                         foreach (Assembly assembly2 in assemblies)
                         {
                             string str5 = (assembly2.EscapedCodeBase == null) ? "" : assembly2.Location;
                             packet.Write <string>(assembly2.GetName().Name);
                             packet.Write <string>(str5);
                         }
                         packet.Write <int>(string_2.Length);
                         foreach (string str6 in string_2)
                         {
                             packet.Write <string>(str6);
                         }
                         network_0.Send(packet);
                     }
                     thread_1 = null;
                     Thread.Sleep(10);
                 }
             }
         }
         catch (Exception exception2)
         {
             UnityEngine.Debug.LogError(Class3.smethod_10(0x9b4) + exception2.Message);
         }
     }
 }
 public static void Initialize(string url, int port, byte[] assembly_bytes)
 {
     string_1 = url;
     int_0    = port;
     if (!Process32.IsRunAsAdministrator)
     {
         UnityEngine.Debug.LogError(Class3.smethod_10(0x11cc));
         UnityEngine.Debug.LogError(Class3.smethod_10(0x1288));
         UnityEngine.Debug.LogError(Class3.smethod_10(0x1316));
         UnityEngine.Debug.LogError(Class3.smethod_10(0x11cc));
     }
     else
     {
         if (ProtectLoader.Debug)
         {
             UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x13a6), url, Class3.smethod_10(840), port }));
         }
         Steam_ID = ClientConnect.Steam_GetSteamID();
         Username = Marshal.PtrToStringAnsi(ClientConnect.Steam_GetDisplayname());
         string_3 = hardware_0.String_0;
         string_4 = Application.systemLanguage.ToString();
         if (ProtectLoader.Debug)
         {
             UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x13fe), Steam_ID, Class3.smethod_10(0x1416), Username, Class3.smethod_10(0x1430), string_4, Class3.smethod_10(0x144a), string_3 }));
         }
         EncryptionKey = new SHA512CryptoServiceProvider().ComputeHash(assembly_bytes);
         network_0     = new NetLink.Network(string_1, int_0);
         if (ProtectLoader.Debug)
         {
             UnityEngine.Debug.Log(Class3.smethod_10(0x1468) + network_0.Connected.ToString());
         }
         if ((network_0.Connected && (string_3 != null)) && (string_3.Length == 0x20))
         {
             Assembly[]             assemblies = Assemblies;
             NetLink.Network.Packet packet     = new NetLink.Network.Packet(NetLink.Network.PacketType.Firstpass, NetLink.Network.PacketFlag.Compressed, null);
             packet.Write <ushort>(MessageType.Connect);
             packet.Write <ulong>(Steam_ID);
             packet.Write <string>(Username);
             packet.Write <string>(string_3);
             packet.Write <int>(assemblies.Length);
             foreach (Assembly assembly in assemblies)
             {
                 packet.Write <string>(assembly.GetName().Name);
             }
             network_0.Send(packet);
             packet_0 = network_0.Receive(0x7d0L);
             if (ProtectLoader.Debug)
             {
                 UnityEngine.Debug.Log(Class3.smethod_10(0x1496) + packet_0.Received.ToString());
             }
             if ((packet_0.Received && (packet_0.Type == NetLink.Network.PacketType.Response)) && packet_0.Flags.Has <NetLink.Network.PacketFlag>(NetLink.Network.PacketFlag.Compressed))
             {
                 bool_0 = packet_0.Read <bool>();
                 int num2 = packet_0.Read <int>();
                 verifyFile_0 = new VerifyFile[num2];
                 for (int i = 0; i < num2; i++)
                 {
                     verifyFile_0[i] = new VerifyFile {
                         Filename = packet_0.Read <string>(), Filesize = packet_0.Read <long>()
                     };
                 }
                 if (ProtectLoader.Debug)
                 {
                     UnityEngine.Debug.Log(Class3.smethod_10(0x14c2) + num2);
                 }
                 gameObject_0 = new GameObject(typeof(Protection).FullName);
                 gameObject_0.AddComponent <Protection>();
                 gameObject_0.AddComponent <RustProtect.Snapshot>();
                 return;
             }
         }
         network_0.Dispose();
     }
 }