Exemplo n.º 1
0
        public static void CrashReport(D2Profile profile)
        {
            ++profile.Crashed;
            profile.Stop();
            if (profile.Crashed >= 6)
            {
                return;
            }
            PrintMessage pm = new PrintMessage("Window crashed on load! Restarting.", "", "", 0);

            Program.GM.ConsolePrint(pm, (ProfileBase)profile);
            profile.Restart(false);
        }
Exemplo n.º 2
0
        public static void SaveProfiles()
        {
            if (Program.ProfileList.Count == 0)
            {
                return;
            }
            string[] strArray = new string[Program.ProfileList.Count];
            string[] contents = new string[Program.ProfileList.Count + 1];
            string   str1     = System.IO.File.ReadAllText(Application.StartupPath + "\\d2bs\\d2bs.ini");

            contents[0] = str1.Substring(0, str1.IndexOf("; gateway=") + 10);
            int index = 0;
            int num   = 0;

            Program.GM.objectLock.WaitOne();
            foreach (ProfileBase profileBase in Program.GM.objectProfileList.get_Objects())
            {
                if (profileBase != null)
                {
                    strArray[index] = JsonConvert.SerializeObject((object)profileBase);
                    ++index;
                    if (profileBase.Type != ProfileType.IRC)
                    {
                        D2Profile d2Profile = (D2Profile)profileBase;
                        string    str2      = "";
                        if (d2Profile.Difficulty.ToLower().Equals("highest"))
                        {
                            str2 = "3";
                        }
                        else if (d2Profile.Difficulty[1] == 'e')
                        {
                            str2 = "2";
                        }
                        else if (d2Profile.Difficulty[1] == 'i')
                        {
                            str2 = "1";
                        }
                        else if (d2Profile.Difficulty[1] == 'o')
                        {
                            str2 = "0";
                        }
                        contents[num + 1] = "[" + d2Profile.Name + "]\r\nMode=" + d2Profile.Mode + "\r\nUsername="******"\r\nPassword="******"\r\ngateway=" + d2Profile.Realm + "\r\ncharacter=" + d2Profile.Character + "\r\nScriptPath=" + Path.GetFileName(Program.BOT_LIB) + "\r\nDefaultGameScript=default.dbj\r\nDefaultStarterScript=" + Path.GetFileName(d2Profile.Entry) + "\r\nspdifficulty=" + str2 + "\r\n";
                        ++num;
                    }
                }
            }
            Program.GM.objectLock.ReleaseMutex();
            System.IO.File.WriteAllText(Program.CurrentProfile, string.Join("\n", strArray));
            System.IO.File.WriteAllLines(Application.StartupPath + "\\d2bs\\d2bs.ini", contents, Encoding.Unicode);
        }
Exemplo n.º 3
0
 public static void IRCEventMsg(string msg, IntPtr id)
 {
     foreach (ProfileBase profileBase in (IEnumerable <ProfileBase>)Program.ProfileList.Values)
     {
         if (profileBase.Type == ProfileType.D2)
         {
             D2Profile d2Profile = (D2Profile)profileBase;
             if (d2Profile.D2Process != null && d2Profile.D2Process != null && d2Profile.IRCEvent)
             {
                 Program.SendCopyData(d2Profile.MainWindowHandle, msg, id, 0, 1);
             }
         }
     }
 }
Exemplo n.º 4
0
        public static void LaunchClient(D2Profile client)
        {
            if (!System.IO.File.Exists(client.D2Path))
            {
                throw new Exception("Invalid Diablo II path!");
            }
            foreach (string file in Directory.GetFiles(Path.GetDirectoryName(client.D2Path), "*.dat*", SearchOption.AllDirectories))
            {
                try
                {
                    System.IO.File.Delete(file);
                }
                catch
                {
                }
            }
            CDKey  currentKey = client.CurrentKey;
            string str1       = "";

            if (currentKey != null && currentKey.Classic != null && currentKey.Classic.Length > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(" -d2c \"" + currentKey.Classic + "\"");
                stringBuilder.Append(" -d2x \"" + currentKey.Expansion + "\"");
                str1 = stringBuilder.ToString();
            }
            else if (currentKey != null)
            {
                str1 = currentKey.Name;
            }
            if (currentKey != null)
            {
                Program.GM.UpdateMPQ(client);
            }
            string parameters = client.Parameters;
            string str2       = " -handle \"" + Program.Handle.ToString() + "\" -cachefix -multi -title \"" + client.Name + "\" " + parameters;

            if (!str2.Contains(" -L"))
            {
                str2 = " -profile \"" + client.Name + "\"" + str2;
            }
            if (str1 != null && str1.ToLower().Contains("mpq"))
            {
                str2 = " -mpq \"" + str1 + "\"" + str2;
            }
            else if (str1.Length > 0)
            {
                str2 = str1 + str2;
            }
            ProcessStartInfo startInfo = new ProcessStartInfo(client.D2Path)
            {
                Arguments        = str2,
                UseShellExecute  = false,
                WorkingDirectory = Path.GetDirectoryName(client.D2Path)
            };

            client.D2Process = new Process()
            {
                StartInfo = startInfo
            };
            bool flag1 = false;

            if (System.IO.File.Exists(Application.StartupPath + "\\D2BS\\D2M.dll"))
            {
                flag1 = true;
            }
            client.D2Process = Kernel32.StartSuspended(client.D2Process, startInfo);
            try
            {
                if (flag1)
                {
                    Kernel32.LoadRemoteLibrary(client.D2Process, (object)(Application.StartupPath + "\\D2BS\\D2M.dll"));
                    flag1 = true;
                }
                else
                {
                    Kernel32.LoadRemoteLibrary(client.D2Process, (object)(Application.StartupPath + "\\d2bs\\D2BS.dll"));
                }
            }
            catch (Exception ex)
            {
                Program.GM.ConsolePrint(new PrintMessage("D2M.dll failed to load", "", "", 0), (ProfileBase)client);
                Program.CrashReport(client);
            }
            PatchData patchData1;
            bool      flag2 = Program.PatchList.TryGetValue("hidewin0" + Settings.Default.D2_Version, out patchData1);
            PatchData patchData2;
            bool      flag3 = Program.PatchList.TryGetValue("hidewin1" + Settings.Default.D2_Version, out patchData2);
            PatchData patchData3;
            bool      flag4  = Program.PatchList.TryGetValue("hidewin2" + Settings.Default.D2_Version, out patchData3);
            Patch     patch1 = (Patch)null;
            Patch     patch2 = (Patch)null;
            Patch     patch3 = (Patch)null;

            if (!client.Visible)
            {
                if (flag2)
                {
                    patch1 = new Patch(patchData1.Module, patchData1.Offset, patchData1.Data);
                    patch1.Install(client.D2Process);
                }
                if (flag3)
                {
                    patch2 = new Patch(patchData2.Module, patchData2.Offset, patchData2.Data);
                    patch2.Install(client.D2Process);
                }
                if (flag4)
                {
                    patch3 = new Patch(patchData3.Module, patchData3.Offset, patchData3.Data);
                    patch3.Install(client.D2Process);
                }
            }
            PatchData patchData4;

            if (client.BlockRD && Program.PatchList.TryGetValue("rdblock" + Settings.Default.D2_Version, out patchData4))
            {
                new Patch(patchData4.Module, patchData4.Offset, patchData4.Data).Install(client.D2Process);
            }
            Program.InstallPatches(client.D2Process);
            Kernel32.Resume(client.D2Process);
            client.D2Process.WaitForInputIdle();
            if (Program.Runtime.ContainsKey(client.MainWindowHandle))
            {
                ProfileBase profileBase;
                Program.Runtime.TryRemove(client.MainWindowHandle, out profileBase);
            }
            client.MainWindowHandle = client.D2Process.MainWindowHandle;
            if (flag1)
            {
                try
                {
                    Kernel32.LoadRemoteLibrary(client.D2Process, (object)(Application.StartupPath + "\\d2bs\\D2BS.dll"));
                }
                catch
                {
                    Program.GM.ConsolePrint(new PrintMessage("D2BS.dll failed to load", "", "", 0), (ProfileBase)client);
                    Program.CrashReport(client);
                }
            }
            if (!client.Visible)
            {
                if (Settings.Default.Start_Hidden)
                {
                    client.HideWindow();
                }
                else
                {
                    IntPtr result;
                    MessageHelper.SendMessageTimeout(client.MainWindowHandle, 28U, (IntPtr)0, IntPtr.Zero, MessageHelper.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 250U, out result);
                }
            }
            client.Crashed = 0;
            try
            {
                if (patch1 != null && patch1.IsInstalled() && !client.D2Process.HasExited)
                {
                    patch1.Remove(client.D2Process);
                }
                if (patch2 != null && patch2.IsInstalled() && !client.D2Process.HasExited)
                {
                    patch2.Remove(client.D2Process);
                }
                if (patch3 != null && patch3.IsInstalled() && !client.D2Process.HasExited)
                {
                    patch3.Remove(client.D2Process);
                }
                IntPtr result;
                MessageHelper.SendMessageTimeout(client.MainWindowHandle, 28U, (IntPtr)0, IntPtr.Zero, MessageHelper.SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 250U, out result);
            }
            catch
            {
            }
            Program.Runtime.TryAdd(client.MainWindowHandle, (ProfileBase)client);
            if (!client.Visible)
            {
                return;
            }
            client.ShowWindow();
        }