示例#1
0
        private void swap(ref List <file_list> a, int i, int j)
        {
            file_list tmp = a[i];

            a[i] = a[j];
            a[j] = tmp;
        }
示例#2
0
        private void quicksort(ref List <file_list> a, int left, int right)
        {
            if (left + 10 <= right)
            {
                file_list pivot = median3(ref a, left, right);// Begin partitioning
                int       i = left, j = right - 1;
                for (; ;)
                {
                    while (a[++i] < pivot)
                    {
                    }
                    while (pivot < a[--j])
                    {
                    }
                    if (i < j)
                    {
                        swap(ref a, i, j);
                    }
                    else
                    {
                        break;
                    }
                }
                swap(ref a, i, right - 1);      // Restore pivot

                quicksort(ref a, left, i - 1);  // Sort small elements
                quicksort(ref a, i + 1, right); // Sort large elements
            }
            else  // Do an insertion sort on the subarray
            {
                insertionSort(ref a, left, right);
            }
        }
示例#3
0
        private void thr_send_reqs(file_list file, int server, byte[] search_index, IPEndPoint who)
        {
            Socket serq = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            serq.Connect(file.fEndpoints[server]);
            text.WaitOne();
            outbox.AppendText("Tracker conncted to IP: " + file.fEndpoints[server].Address.ToString() + " on port " + file.fEndpoints[server].Port.ToString() + "\n");
            text.ReleaseMutex();
            byte[] pfcode = new byte[1];
            pfcode[0] = 123;
            serq.Send(pfcode);
            byte[] file_name_size = new byte[1];
            file_name_size[0] = (BitConverter.GetBytes(file.fName.Length))[0];
            serq.Send(file_name_size);
            byte[] name = Encoding.Default.GetBytes(file.fName);
            serq.Send(name);
            serq.Send(search_index);
            byte[] part_index = BitConverter.GetBytes(server);
            serq.Send(part_index);
            long mod = file.fSize % file.fEndpoints.Count();
            long sizeOfFileMod;

            if (mod != 0)
            {
                sizeOfFileMod = file.fSize + (file.fEndpoints.Count() - (mod));
            }
            else
            {
                sizeOfFileMod = file.fSize;
            }
            long startp  = server * sizeOfFileMod / file.fEndpoints.Count();             // start byte of the file for the specific server.
            long finishp = ((server + 1) * sizeOfFileMod / file.fEndpoints.Count()) - 1; // finish byte of the file for the specific server.

            if (server == file.fEndpoints.Count() - 1)
            {
                if (finishp != file.fSize - 1)          //means the last part!!
                {
                    finishp = file.fSize - 1;
                }
            }
            byte[] startb  = BitConverter.GetBytes(startp);
            byte[] finishb = BitConverter.GetBytes(finishp);
            serq.Send(startb);
            serq.Send(finishb);
            byte[] ip_length = new byte[1];
            ip_length[0] = (BitConverter.GetBytes(who.Address.ToString().Length))[0];
            byte[] get_ip   = Encoding.Default.GetBytes(who.Address.ToString());
            byte[] get_port = BitConverter.GetBytes(who.Port);
            serq.Send(ip_length);
            serq.Send(get_ip);
            serq.Send(get_port);
            text.WaitOne();
            outbox.AppendText("IP: " + who.Address.ToString() + ":" + who.Port.ToString() + " requests " + file.fName + " bytes: " + startp.ToString() + " - " + finishp.ToString() + " is sent to IP: " + file.fEndpoints[server].Address.ToString() + ":" + file.fEndpoints[server].Port.ToString() + "\n");
            text.ReleaseMutex();
            serq.Close();
            text.WaitOne();
            outbox.AppendText("Connection to IP: " + file.fEndpoints[server].Address.ToString() + " is closed\n");
            text.ReleaseMutex();
        }
示例#4
0
        private void insertionSort(ref List <file_list> a, int left, int right)
        {
            for (int p = left + 1; p <= right; p++)
            {
                file_list tmp = a[p];
                int       j;

                for (j = p; j > left && tmp < a[j - 1]; j--)
                {
                    a[j] = a[j - 1];
                }
                a[j] = tmp;
            }
        }
示例#5
0
 private void ApplyPatches(file_list files_to_patch, WebClient wc)
 {
     Directory.CreateDirectory(H2Ek_install_path + "backup");
     ForceMove(H2Ek_install_path + "Halo_2_Map_Editor_Launcher.exe", H2Ek_install_path + "backup\\Halo_2_Map_Editor_Launcher.exe");
     if (files_to_patch.HasFlag(file_list.tool))
     {
         patch_file("h2tool.exe", wc);
     }
     if (files_to_patch.HasFlag(file_list.guerilla))
     {
         patch_file("h2guerilla.exe", wc);
     }
     if (files_to_patch.HasFlag(file_list.sapien))
     {
         patch_file("h2sapien.exe", wc);
     }
 }
示例#6
0
            public int CompareTo(object obj)
            {
                file_list compareIt = (file_list)obj;
                int       ret;

                if (this.fName.CompareTo(compareIt.fName) > 1)
                {
                    ret = 1;
                }
                else if (this.fName == compareIt.fName)
                {
                    ret = 0;
                }
                else
                {
                    ret = -1;
                }
                return(ret);
            }
示例#7
0
        private bool check_files(ref file_list files_to_patch)
        {
            string h2tool = CalculateMD5(H2Ek_install_path + "h2tool.exe");

            if (h2tool == "dc221ca8c917a1975d6b3dd035d2f862")
            {
                files_to_patch |= file_list.tool;
            }
            else if (h2tool != "f81c24da93ce8d114caa8ba0a21c7a63")
            {
                return(false);
            }

            string h2sapien = CalculateMD5(H2Ek_install_path + "h2sapien.exe");

            if (h2sapien == "d86c488b7c8f64b86f90c732af01bf50")
            {
                files_to_patch |= file_list.sapien;
            }
            else if (h2sapien != "975c0d0ad45c1687d11d7d3fdfb778b8")
            {
                return(false);
            }

            string h2guerilla = CalculateMD5(H2Ek_install_path + "h2guerilla.exe");

            if (h2guerilla == "ce3803cc90e260b3dc59854d89b3ea88")
            {
                files_to_patch |= file_list.guerilla;
            }
            else if (h2guerilla != "55b09d5a6c8ecd86988a5c0f4d59d7ea")
            {
                return(false);
            }

            return(true);
        }
示例#8
0
        public MainWindow()
        {
            Application.Current.DispatcherUnhandledException += App_DispatcherUnhandledException;
            Settings.Default.Upgrade();
            Settings.Default.Save();
            H2Ek_install_path = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Halo 2", "tools_directory", H2Ek_install_path).ToString();
            InitializeComponent();
            large_addr_enabled.IsChecked     = Settings.Default.large_address_support;
            ignore_updates_enabled.IsChecked = Settings.Default.ignore_updates;
            // Delete any left over update files.
            try
            {
                File.Delete("H2CodezLauncher.exe.old");
            } catch // but don't crash if that fails.
            {
            }

            var wc = new WebClient();

            new Thread(delegate()
            {
                try
                {
                    updateLaucherCheck(wc);
                    file_list files_to_patch = file_list.none;
                    if (!check_files(ref files_to_patch))
                    {
                        MessageBox.Show("You are using a version of the toolkit not supported by H2Codez, features added by H2Codez will not be available.\nPlease install the orginal version of the toolkit that was distributed on the DVD, as that's the only version H2Codez can patch.",
                                        "Version Error!");
                        return;
                    }

                    if (!File.Exists(H2Ek_install_path + "H2Codez.dll") || files_to_patch != file_list.none)
                    {
                        MessageBoxResult user_answer = MessageBox.Show("Your have not installed H2Codez or your version is outdated.\nDo you want to installed H2Codez?",
                                                                       "H2Codez Install", MessageBoxButton.YesNo);
                        if (user_answer == MessageBoxResult.No)
                        {
                            return;
                        }

                        AllowReadWriteDir(H2Ek_install_path, true); // wipe permissions for install path and let all users access it
                        ApplyPatches(files_to_patch, wc);
                        patch_exes_for_large_address_support();
                        wc.DownloadFile(Settings.Default.h2codez_update_url, H2Ek_install_path + "H2Codez.dll");
                        AllowReadWriteFile(H2Ek_install_path + "H2Codez.dll");
                        MessageBox.Show("Successfully finished installing H2Codez!", "H2codez Install");
                        return;
                    }

                    patch_exes_for_large_address_support();
                    string h2codez_latest_hash = wc.DownloadString(Settings.Default.h2codez_lastest_hash);
                    string our_h2codes_hash    = CalculateMD5(H2Ek_install_path + "H2Codez.dll");
                    if (our_h2codes_hash != h2codez_latest_hash.ToLower() && !Settings.Default.ignore_updates)
                    {
                        MessageBoxResult user_answer = MessageBox.Show("You version of H2Codez is outdated, do you want to update?",
                                                                       "H2Codez Update", MessageBoxButton.YesNo);
                        if (user_answer == MessageBoxResult.Yes)
                        {
                            AllowReadWriteDir(H2Ek_install_path, true); // wipe permissions for install path and let all users access it
                            AllowReadWriteFile(H2Ek_install_path + "H2Codez.dll");
                            wc.DownloadFile(Settings.Default.h2codez_update_url, H2Ek_install_path + "H2Codez.dll");
                            MessageBox.Show("Successfully finished updating H2Codez!", "H2Codez Update");
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    RelaunchAsAdmin("");
                }
                catch (WebException ex) when(ex.InnerException is IOException)
                {
                    MessageBox.Show("Updating H2Codez failed because the launcher can't write the update data.\nPlease close all currently open modding tools and try again.", "Error!");
                }
                catch (WebException ex) when(ex.InnerException is UnauthorizedAccessException)
                {
                    RelaunchAsAdmin("");
                }
                catch (WebException)
                {
                    MessageBox.Show("Check your internet connection and try again,\nif the problem presists fill a bug report.", "Update check failed!");
                }
            }).Start();
        }
示例#9
0
 private void thr_ops(int index, int op)
 {
     if (op == 100)
     {
         byte[] many = new byte[4];
         inc_connections[index].Receive(many);
         int        file_nums = BitConverter.ToInt32(many, 0);
         IPEndPoint remote    = (IPEndPoint)inc_connections[index].RemoteEndPoint;
         byte[]     portN     = new byte[4];
         inc_connections[index].Receive(portN);
         int portnum = BitConverter.ToInt32(portN, 0);
         remote.Port = portnum;
         for (int i = 0; i < file_nums; i++)
         {
             byte[] file_name_size = new byte[1];    //a file name can be max 256 chars on NTFS, hence 1 byte is enough to state the number of bytes
             inc_connections[index].Receive(file_name_size);
             int    name_size = file_name_size[0];
             byte[] file_name = new byte[name_size];
             inc_connections[index].Receive(file_name);
             string file_name_string = Encoding.Default.GetString(file_name);
             byte[] file_size        = new byte[8];
             inc_connections[index].Receive(file_size);
             long      file_size_long = BitConverter.ToInt64(file_size, 0);
             file_list new_file       = new file_list();
             new_file.fName = file_name_string;
             file_acc.WaitOne();
             int ind = binarySFL(available_files, new_file.fName);
             if (ind >= 0)
             {
                 available_files[ind].fEndpoints.Add(remote);
                 string new3rdrow = "";
                 int    j;
                 for (j = 0; j < available_files[ind].fEndpoints.Count() - 1; j++)
                 {
                     new3rdrow += available_files[ind].fEndpoints[j].Address.ToString() + ":" + available_files[ind].fEndpoints[j].Port + ", ";
                 }
                 new3rdrow += available_files[ind].fEndpoints[j].Address.ToString() + ":" + available_files[ind].fEndpoints[j].Port;
                 fileListView.Rows[ind].SetValues(file_name_string, file_size_long.ToString(), new3rdrow);
             }
             else
             {
                 new_file.fSize      = file_size_long;
                 new_file.fEndpoints = new List <IPEndPoint>();
                 new_file.fEndpoints.Add(remote);
                 available_files.Add(new_file);
                 quicksort(ref available_files);
                 ind = binarySFL(available_files, new_file.fName);
                 fileListView.Rows.Add(file_name_string, file_size_long.ToString(), available_files[ind].fEndpoints[0].Address.ToString() + ":" + available_files[ind].fEndpoints[0].Port);
                 fileListView.Sort(Column1, ListSortDirection.Ascending);
             }
             file_acc.ReleaseMutex();
         }
         text.WaitOne();
         outbox.AppendText("List of shared files of IP: " + remote.Address.ToString() + " is recieved\n");
         text.ReleaseMutex();
         text.WaitOne();
         outbox.AppendText("Listening port of IP: " + remote.Address.ToString() + " is " + remote.Port.ToString() + "\n");
         text.ReleaseMutex();
         inc_connections[index].Close();
         text.WaitOne();
         outbox.AppendText("Connection to IP: " + remote.Address.ToString() + " is closed\n");
         text.ReleaseMutex();
     }
     else if (op == 200)
     {
         byte[] search_index = new byte[4];
         inc_connections[index].Receive(search_index);
         byte[] file_name_size = new byte[1];    //a file name can be max 256 chars on NTFS, hence 1 byte is enough to state the number of bytes
         inc_connections[index].Receive(file_name_size);
         int    name_size   = file_name_size[0];
         byte[] file_name_b = new byte[name_size];
         inc_connections[index].Receive(file_name_b);
         string file_name = Encoding.Default.GetString(file_name_b);
         text.WaitOne();
         outbox.AppendText("Download request for " + file_name + " is recieved from IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + "\n");
         text.ReleaseMutex();
         file_acc.WaitOne();
         int    found = binarySFL(available_files, file_name);
         byte[] answer;
         int    count = 0;
         if (found >= 0)
         {
             file_list tmp = available_files[found];
             file_acc.ReleaseMutex();
             List <ThreadStart> reqs;
             List <Thread>      req;
             count  = tmp.fEndpoints.Count();
             answer = BitConverter.GetBytes(count);
             inc_connections[index].Send(answer);
             byte[] sizeb = BitConverter.GetBytes(tmp.fSize);
             inc_connections[index].Send(sizeb);
             byte[] portToSend = new byte[4];
             inc_connections[index].Receive(portToSend);
             int rem_port = BitConverter.ToInt32(portToSend, 0);
             text.WaitOne();
             outbox.AppendText("Positive ack is sent to IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + " for " + file_name + "(" + tmp.fEndpoints.Count.ToString() + " FileSharerDownloader(s))" + "\n");
             text.ReleaseMutex();
             IPEndPoint who = ((IPEndPoint)inc_connections[index].RemoteEndPoint);
             who.Port = rem_port;
             text.WaitOne();
             outbox.AppendText(count.ToString() + " FileSharerDownloader(s) have " + tmp.fName + " of size: " + tmp.fSize.ToString() + " bytes - IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + "\n");
             text.ReleaseMutex();
             inc_connections[index].Disconnect(false);
             text.WaitOne();
             outbox.AppendText("Connection to IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + " is closed\n");
             text.ReleaseMutex();
             inc_connections[index].Close();
             reqs = new List <ThreadStart>();
             req  = new List <Thread>();
             for (int i = 0; i < count; i++)
             {
                 int a = i;
                 reqs.Add(delegate { thr_send_reqs(tmp, a, search_index, who); });
                 req.Add(new Thread(reqs[i]));
                 req[i].Start();
                 Thread.Sleep(50);
             }
         }
         else
         {
             file_acc.ReleaseMutex();
             answer = BitConverter.GetBytes(count);
             inc_connections[index].Send(answer);
             text.WaitOne();
             outbox.AppendText("Negative ack is sent to IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + " for " + file_name + "(0 FileSharerDownloader)" + "\n");
             text.ReleaseMutex();
             inc_connections[index].Disconnect(false);
             text.WaitOne();
             outbox.AppendText("Connection to IP: " + ((IPEndPoint)inc_connections[index].RemoteEndPoint).Address.ToString() + " is closed\n");
             text.ReleaseMutex();
             inc_connections[index].Close();
         }
     }
 }
        public MainWindow()
        {
            Application.Current.DispatcherUnhandledException += App_DispatcherUnhandledException;
            Settings.Default.Upgrade();
            Settings.Default.Save();

            string Launcher_Directory = AppDomain.CurrentDomain.BaseDirectory;
            bool   Use_Launcher_Path  = true;

            InitializeComponent();
            large_addr_enabled.IsChecked     = Settings.Default.large_address_support;
            ignore_updates_enabled.IsChecked = Settings.Default.ignore_updates;
            // Delete any left over update files.
            try
            {
                File.Delete("H2CodezLauncher.exe.old");
            } catch // but don't crash if that fails.
            {
            }

            var wc = new WebClient();

            new Thread(delegate()
            {
                try
                {
                    updateLaucherCheck(wc);
                    file_list files_to_patch = file_list.none;
                    if (!check_files(ref files_to_patch))
                    {
                        MessageBox.Show("You are using a version of the toolkit that is not supported by H2Codez, features added by H2Codez will not be available.\nPlease install the orginal version of the toolkit that was distributed on the DVD, as that's the only version H2Codez can patch.",
                                        "Version Error!");
                        return;
                    }
                    string H2Tool_Path = AppDomain.CurrentDomain.BaseDirectory;

                    Microsoft.Win32.RegistryKey H2EK_Install_Path_key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft Games\\Halo 2\\1.0");
                    Microsoft.Win32.RegistryKey Guerilla_Tag_key      = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Halo 2");

                    if (H2EK_Install_Path_key is null || Guerilla_Tag_key is null)
                    {
                        RegistryKey Test_Write_Access = RegistryKey
                                                        .OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                                                        .CreateSubKey("SOFTWARE\\Microsoft\\Microsoft Games\\Halo 2\\1.0", true);

                        MessageBox.Show("Missing Halo 2 Editing Kit related registry keys. Please select H2Tool.exe");
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Title          = "Selet H2Tool.exe";
                        dlg.Filter         = "H2Tool|*.exe";
                        if (dlg.ShowDialog() == true)
                        {
                            H2Tool_Path       = dlg.FileName;
                            Use_Launcher_Path = false;
                        }
                        else
                        {
                            MessageBox.Show("Failed to assign registry keys. Will default to using launcher location. This will break if the launcher is not located in the map editor folder");
                            Use_Launcher_Path = true;
                        }

                        H2Ek_install_path = new FileInfo(H2Tool_Path).Directory.FullName;
                    }

                    if (H2EK_Install_Path_key is null && Use_Launcher_Path == false)
                    {
                        RegistryKey registryKey32 = RegistryKey
                                                    .OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                                                    .CreateSubKey("SOFTWARE\\Microsoft\\Microsoft Games\\Halo 2\\1.0", true);
                        registryKey32.SetValue("ToolsInstallDir", H2Ek_install_path + "\\");
                    }

                    if (Guerilla_Tag_key is null && Use_Launcher_Path == false)
                    {
                        RegistryKey registryKey32 = RegistryKey
                                                    .OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                                                    .CreateSubKey("SOFTWARE\\Microsoft\\Halo 2", true);
                        registryKey32.SetValue("tools_directory", H2Ek_install_path + "\\");
                    }

                    if (Use_Launcher_Path == false)
                    {
                        MessageBox.Show("Repairs completed");
                    }

                    Microsoft.Win32.RegistryKey H2EK_Install_Path_key2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft Games\\Halo 2\\1.0");
                    Microsoft.Win32.RegistryKey Guerilla_Tag_key2      = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Halo 2");

                    if (H2EK_Install_Path_key2 is null || Guerilla_Tag_key2 is null)
                    {
                        MessageBox.Show("You are missing required registry keys to run H2EK. Defaulting to launcher path");
                        H2Ek_install_path = new FileInfo(Launcher_Directory).Directory.FullName;
                        Use_Launcher_Path = true;
                    }
                    else
                    {
                        H2Ek_install_path = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Halo 2", "tools_directory", H2Ek_install_path).ToString();
                        Use_Launcher_Path = false;
                    }


                    if (!File.Exists(H2Ek_install_path + "H2Codez.dll") || files_to_patch != file_list.none)
                    {
                        MessageBoxResult user_answer = MessageBox.Show("You have not installed H2Codez or the installation process is incomplete.\nDo you want to install H2Codez?",
                                                                       "H2Codez Install", MessageBoxButton.YesNo);
                        if (user_answer == MessageBoxResult.No)
                        {
                            return;
                        }

                        AllowReadWriteDir(H2Ek_install_path, true); // wipe permissions for install path and let all users access it
                        ApplyPatches(files_to_patch, wc);
                        patch_exes_for_large_address_support();
                        wc.DownloadFile(Settings.Default.h2codez_update_url, H2Ek_install_path + "H2Codez.dll");
                        AllowReadWriteFile(H2Ek_install_path + "H2Codez.dll");
                        MessageBox.Show("Successfully finished installing H2Codez!", "H2codez Install");
                        return;
                    }

                    patch_exes_for_large_address_support();
                    string h2codez_latest_hash = wc.DownloadString(Settings.Default.h2codez_lastest_hash);
                    string our_h2codes_hash    = CalculateMD5(H2Ek_install_path + "H2Codez.dll");
                    if (our_h2codes_hash != h2codez_latest_hash.ToLower() && !Settings.Default.ignore_updates)
                    {
                        MessageBoxResult user_answer = MessageBox.Show("Your version of H2Codez is outdated, do you want to update it?",
                                                                       "H2Codez Update", MessageBoxButton.YesNo);
                        if (user_answer == MessageBoxResult.Yes)
                        {
                            AllowReadWriteDir(H2Ek_install_path, true); // wipe permissions for install path and let all users access it
                            AllowReadWriteFile(H2Ek_install_path + "H2Codez.dll");
                            wc.DownloadFile(Settings.Default.h2codez_update_url, H2Ek_install_path + "H2Codez.dll");
                            MessageBox.Show("Successfully finished updating H2Codez!", "H2Codez Update");
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    RelaunchAsAdmin("");
                }