Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int GetPid()
- {
- Process iPokerProcess = null;
- foreach (var proc in Process.GetProcesses())
- {
- if (proc.ProcessName == "pokerclient")
- {
- iPokerProcess = proc;
- break;
- }
- }
- if (iPokerProcess == null)
- {
- MessageBox.Show("Poker client not detected. Please check that the client is running", "Oops! Something has gone wrong", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return -1;
- }
- return iPokerProcess.Id;
- }
- private void startHook_CheckedChanged(object sender, EventArgs e)
- {
- var checkbox = sender as CheckBox;
- var exitProg = true;
- if (checkbox.Checked)
- {
- Int32 TargetPID = GetPid();
- Console.WriteLine("WTF");
- if (TargetPID == -1)
- {
- infoBox.AppendText("Poker Client not detectedn");
- checkbox.Checked = false;
- }
- else
- {
- try
- {
- try
- {
- Config.Register(
- "IPoker BB Modification",
- "IPokerBBMod.exe",
- "LunaInject.dll");
- }
- catch (ApplicationException)
- {
- MessageBox.Show("This is an administrative task!", "Permission denied...", MessageBoxButtons.OK);
- System.Diagnostics.Process.GetCurrentProcess().Kill();
- }
- RemoteHooking.IpcCreateServer<IPokerModInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
- RemoteHooking.Inject(
- TargetPID,
- "LunaInject.dll",
- "LunaInject.dll",
- ChannelName);
- clientName = Regex.Match(Process.GetProcessById(TargetPID).MainModule.FileName, @".+(?=\PokerClient.exe)").Value;
- clientName = clientName.Substring(0, clientName.LastIndexOf('\'));
- clientName = clientName.Substring(clientName.LastIndexOf('\'));
- clientName = clientName.Replace("\", "");
- infoBox.AppendText(string.Format("Attached to Poker Client: {0}n", clientName));
- }
- catch (Exception ExtInfo)
- {
- Console.WriteLine("There was an error while connecting to target:rn{0}", ExtInfo.ToString());
- }
- checkbox.Text = "Exit";
- checkbox.ForeColor = Color.Red;
- }
- }
- // Intercept function that is called whenever the ipoker client draws text to its graphical area.
- // IPoker draws text in a convuluted way, and it is extremely difficult to tell which window a piece of text is being drawn on hence the messy workaround
- static int DrawText_Hooked(IntPtr hdc, [In, Out, MarshalAs(UnmanagedType.LPTStr)] string lpString, int cchText, [In, Out, MarshalAs(UnmanagedType.Struct)] ref RECT lprc, uint dwDTFormat, [In, Out, MarshalAs(UnmanagedType.Struct)] ref DRAWTEXTPARAMS dparams)
- {
- double bigBlindAmount;
- double m;
- // If detect a call to DrawTextEx with a new hdc and dwDTFormat 0x0800, check to see if the text being draw matches a limit regex (ie: it is a table title)
- // If so find the value of the big blind and add it to our dictionary of hdc/big blind pair values.
- if (dwDTFormat == 0x0800 && !hdcList.ContainsKey(hdc))
- {
- Match tableTitle = limit.Match(lpString);
- if (tableTitle.Success)
- {
- double.TryParse(bigBlind.Match(tableTitle.Value).Value.Substring(2), out bigBlindAmount);
- hdcList.Add(hdc, Convert.ToDouble(bigBlindAmount));
- InvalidateRect((IntPtr)null, (IntPtr)null, true);
- }
- }
- // Match the string being drawn to a money regex, if it matches the client is trying to write text that is money values
- else if (money.IsMatch(lpString) && Double.TryParse(lpString.Substring(1), out m))
- {
- // Get the big blind value for the money value and convert to big blinds
- if (dwDTFormat == 0x0800 && hdcList.ContainsKey(hdc))
- {
- bigBlindAmount = hdcList[hdc];
- m = m / bigBlindAmount;
- string stringOut = m.ToString("N");
- //if (colorStacks)
- //{
- // SetTextColor(hdc, ColorTranslator.ToWin32(Color.Gold));
- //}
- // Pass this new value to the underlying Win32 system function to draw to the screen
- return DrawTextExW(hdc, stringOut, -1, ref lprc, dwDTFormat, ref dparams);
- }
- // Work around to align text properly
- else
- {
- return DrawTextExW(hdc, "999.99", 6, ref lprc, dwDTFormat, ref dparams);
- }
- }
- // Otherwise just call the system DrawTextExW function with the original parameters without modification
- return DrawTextExW(hdc, lpString, cchText, ref lprc, dwDTFormat, ref dparams);
- }
Add Comment
Please, Sign In to add comment