예제 #1
0
        public bool IncrementKey()
        {
            D2Bot.KeyList keyList = Program.GM.GetKeyList(this.KeyList);
            if (keyList == null)
            {
                return(false);
            }
            CDKey currentKey = this.CurrentKey;

            try
            {
                this.CurrentKey = keyList.GetAndIncrement();
                currentKey?.Set(false);
            }
            catch (Exception ex)
            {
                if (ex.ToString().ToLower().Contains("all keys"))
                {
                    currentKey?.Set(false);
                    int num = (int)MessageBox.Show("All keys in this keylist are in use or on hold. Please add more keys or resume paused keys.");
                }
                else
                {
                    int num1 = (int)MessageBox.Show(ex.ToString());
                }
                return(false);
            }
            return(true);
        }
예제 #2
0
        public async void TestActivate(
            Player player,
            List <Game> games,
            Dictionary <string, List <string> > cdkeys
            )
        {
            // prepare player + games
            CUDMessage addPlayerMessage = await playerService.Add(player);

            Assert.True(addPlayerMessage.OK);
            CUDMessage addGameMessage = await gameService.Add(games);

            Assert.True(addGameMessage.OK);

            // create CDK instances for the games according to the map (at this time: player is null)
            foreach (var pair in cdkeys)
            {
                foreach (var cdkValue in pair.Value)
                {
                    var cdkey = new CDKey()
                    {
                        Game        = pair.Key,
                        Value       = cdkValue,
                        IsActivated = false,
                    };
                    CUDMessage addCDKMessage = await cdkeyService.Add(cdkey);

                    Assert.True(addCDKMessage.OK);
                }
            }

            // Activate one cdk. Should be able to add, and player then has the game.
            // -> (player not null + appear in "games" field in player instance) We should get the cdk instance.
            InstanceCUDMessage <CDKey> activateMessage = await cdkeyService.Activate(player.DBName, cdkeys[games[0].DBName][0]);

            CDKey singleCDK = activateMessage.Instance;

            Assert.True(singleCDK.Player == player.DBName);
            Player playerInDB = await playerService.Get(player.DBName);

            Assert.NotNull(playerInDB.Games.Find(ele => ele == games[0].DBName));

            // Activate multiple cdks. Should be able to add, and player then has the list of games. We should get a list of cdk instance.
            var cdkValues = new List <string> {
                cdkeys[games[1].DBName][0],
                cdkeys[games[2].DBName][0],
            };

            activateMessage = await cdkeyService.Activate(player.DBName, cdkValues);

            List <CDKey> multipleCDKs = activateMessage.Instances;

            Assert.True(multipleCDKs[1].Player == player.DBName);
            playerInDB = await playerService.Get(player.DBName);

            Assert.True(playerInDB.Games.Count == 1 + 2);

            // Activate an invalid CDKey. Message should not be okay.
            activateMessage = await cdkeyService.Activate(player.DBName, "2GDH1-5BDK2-BILLY-3CDK4"); // 风暴英雄CDK

            Console.WriteLine(activateMessage.Message);
            Assert.False(activateMessage.OK);

            // Activate duplicate keys. Message should not be okay because:
            // 1. key already activated

            activateMessage = await cdkeyService.Activate(player.DBName, cdkeys[games[0].DBName][0]);

            Console.WriteLine(activateMessage.Message);
            Assert.False(activateMessage.OK);

            // 2. player already owns the game, activation should fail.
            activateMessage = await cdkeyService.Activate(player.DBName, cdkeys[games[1].DBName][1]);

            Console.WriteLine(activateMessage.Message);
            Assert.False(activateMessage.OK);
            CDKey cdkeyInDB = await cdkeyService.GetByValue(cdkeys[games[1].DBName][1]);

            //(await cdkeyService.Get(JsonDocument.Parse("{" + "\"value\": " + $"\"{cdkeys[games[1].DBName][1]}\"" + "}").RootElement))[0];
            Assert.False(cdkeyInDB.IsActivated);

            // Activate multiple keys contains duplications.
            // we should get a list of successfully added cdk instances,
            // and the games will only be added if player does not own those games
            cdkValues = new List <string> {
                cdkeys[games[2].DBName][0], // (key already activated)
                cdkeys[games[2].DBName][1], // duplicate game
                cdkeys[games[3].DBName][0], // good
            };

            activateMessage = await cdkeyService.Activate(player.DBName, cdkValues);

            multipleCDKs = activateMessage.Instances;
            Assert.True(multipleCDKs.Count == 1);

            // check game[2] should not be activated
            // "player" field of unsuccessfully added cdkeys should remain null
            cdkeyInDB = await cdkeyService.GetByValue(cdkeys[games[2].DBName][1]);

            // (await cdkeyService.Get(JsonDocument.Parse("{" + "\"value\": " + $"\"{cdkeys[games[2].DBName][1]}\"" + "}").RootElement))[0];
            Assert.False(cdkeyInDB.IsActivated);
            Assert.Null(cdkeyInDB.Player);

            // player should own game[3]
            playerInDB = await playerService.Get(player.DBName);

            Assert.NotNull(playerInDB.Games.Find(ele => ele == games[3].DBName));
        }
예제 #3
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();
        }