elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Experimento de "truco" simple para Counter-strike en Java
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Experimento de "truco" simple para Counter-strike en Java  (Leído 2,307 veces)
snake_linux

Desconectado Desconectado

Mensajes: 70


Ver Perfil
Experimento de "truco" simple para Counter-strike en Java
« en: 1 Diciembre 2019, 22:04 pm »

Buenas, estoy escribiendo un "truco" para CSGO muy simple en Java, es para fines educativos exclusivamente, por cacharrear, no tengo intención de utilizarlo para ganar.

Básicamente lo que quiero es que cuando el enemigo se ponga en la mira (que siempre está justo en el centro de la pantalla) se produzca un disparo, para ello necesito que el programa haga una "captura" de una pequeña región en el centro de la pantalla y lo compare con otras capturas que hace constantemente para ver si se ha producido o no un cambio.

Además, utilizo una biblioteca externa para lanzar el evento (arrancar el bot para que se ponga a comparar), la comparación la hago pixel a pixel con una función que encontré en internet.

El problema es que creo que no se está centrando correctamente, ya que no me detecta el cambio en el centro de la pantalla pero si en otras areas.

Les dejo el código:

Código
  1.  
  2. import java.awt.AWTException;
  3. import java.awt.Dimension;
  4. import java.awt.Rectangle;
  5. import java.awt.Robot;
  6. import java.awt.Toolkit;
  7. import java.awt.image.BufferedImage;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11. import org.jnativehook.GlobalScreen;
  12. import org.jnativehook.NativeHookException;
  13. import org.jnativehook.keyboard.NativeKeyEvent;
  14. import org.jnativehook.keyboard.NativeKeyListener;
  15.  
  16. public class AutoBot  implements NativeKeyListener {
  17.  
  18. public static void main(String[] args) {
  19.  
  20.  
  21. // Get the logger for "org.jnativehook" and set the level to off.
  22. Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
  23. logger.setLevel(Level.OFF);
  24.  
  25. try {
  26. GlobalScreen.registerNativeHook();
  27. } catch (NativeHookException ex) {
  28. System.err.println("Error Nativehook");
  29. System.err.println(ex.getMessage());
  30.  
  31. System.exit(1);
  32. }
  33.  
  34.  
  35.  
  36. GlobalScreen.addNativeKeyListener(new AutoBot());
  37. System.out.println("Usa / para lanzar autobot");
  38.  
  39. }
  40.  
  41. public static boolean bufferedImagesEqual(BufferedImage img1, BufferedImage img2) {
  42.  
  43. int margen=0;
  44.  
  45.    if (img1.getWidth() == img2.getWidth() && img1.getHeight() == img2.getHeight()) {
  46.        for (int x = 0; x < img1.getWidth(); x++) {
  47.            for (int y = 0; y < img1.getHeight(); y++) {
  48.                if (img1.getRGB(x, y) != img2.getRGB(x, y))
  49.                    return false;
  50.            }
  51.        }
  52.    } else {
  53.        return false;
  54.    }
  55.    return true;
  56. }
  57.  
  58. public static void autoBot() throws AWTException {
  59.  
  60. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  61. Robot robot = new Robot();
  62.  
  63. double altura = screenSize.getHeight()/2;
  64. double ancho = screenSize.getWidth()/2;
  65.  
  66. Rectangle area = new Rectangle();
  67. area.setBounds((int)altura-20, (int)ancho-20, 20, 20);
  68. BufferedImage bufferedImage = robot.createScreenCapture(area);
  69. boolean noDisparar= false;
  70.  
  71. while(!noDisparar) {
  72.  
  73. Rectangle area2 = new Rectangle();
  74. area2.setBounds((int)altura-20, (int)ancho-20, 20, 20);
  75. BufferedImage bufferedImage2 = robot.createScreenCapture(area2);
  76.  
  77. if(!bufferedImagesEqual(bufferedImage, bufferedImage2)) {
  78. // robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  79. // robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  80. System.out.println("ha cambiado");
  81. noDisparar = true;
  82. }
  83. }
  84. }
  85.  
  86. @Override
  87. public void nativeKeyPressed(NativeKeyEvent e) {
  88.  
  89. }
  90.  
  91.  
  92. @Override
  93. public void nativeKeyReleased(NativeKeyEvent e) {
  94.  
  95. String tecla = NativeKeyEvent.getKeyText(e.getKeyCode());
  96.  
  97. if (tecla.equals("Barra")) {
  98. System.out.println("dale");
  99. try {
  100. autoBot();
  101. } catch (AWTException e1) {
  102. // TODO Auto-generated catch block
  103. e1.printStackTrace();
  104. }
  105. }
  106. }
  107.  
  108. @Override
  109. public void nativeKeyTyped(NativeKeyEvent e) {
  110.  
  111. }
  112. }
  113.  

Gracias, un saludo.


« Última modificación: 1 Diciembre 2019, 22:08 pm por snake_linux » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Error en la tarjeta grafica al jugar al "Counter Strike: source".
Juegos y Consolas
Firos 1 2,622 Último mensaje 21 Enero 2006, 20:55 pm
por SmopuiM
Error en "Counter Strike: source".
Juegos y Consolas
Firos 8 2,533 Último mensaje 5 Marzo 2006, 22:13 pm
por ||Ray||
Jugar en linea "Counter Strike Source"
Juegos y Consolas
LordKevin 0 1,502 Último mensaje 23 Julio 2007, 03:18 am
por LordKevin
Counter Strike 1.6 TRUCO
Juegos y Consolas
juan_dinio69 5 2,368 Último mensaje 18 Mayo 2008, 21:11 pm
por mim0x
Facebook manipuló el "news feed" de 689.000 usuarios para un experimento ....
Noticias
wolfbcn 1 2,372 Último mensaje 29 Junio 2014, 21:31 pm
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines