阿木申 申楠

热衷编程技术 | 申楠 : qq:38371354 | msn:amushen2005@hotmail.com

导航

[原创]网易泡泡游戏"找茬"的外挂

Posted on 2006-12-25 17:57  阿木申  阅读(6445)  评论(2编辑  收藏  举报
这几天跟老婆玩泡泡游戏"找茬",每次到最后都差一个找不到,很郁闷,所以研究了一天,做了这个外挂.
在游戏进行的时候点一下这个外挂,就自动显示出两张图片的差别了.成功率90%以上.呵呵.

  1package tools;
  2
  3import java.awt.Color;
  4import java.awt.Dimension;
  5
  6import java.awt.Rectangle;
  7import java.awt.Robot;
  8import java.awt.Toolkit;
  9import java.awt.event.ActionEvent;
 10import java.awt.event.ActionListener;
 11import java.awt.event.WindowAdapter;
 12import java.awt.event.WindowEvent;
 13import java.awt.image.BufferedImage;
 14
 15import java.util.ArrayList;
 16import java.util.List;
 17
 18import javax.swing.*;
 19
 20
 21public class ZhaoCha extends JFrame implements ActionListener{
 22    private static final long serialVersionUID = 19830620;
 23    
 24    private JButton jb=null;    
 25    Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 
 26    private ArrayList list1,list2;
 27    private BufferedImage image3=null;
 28    byte[] buffer;
 29        
 30    private int[][] m_rgb={{-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14116656,-14117688,-14119736,-12542760,-12016424,-12019496,-13594416,-13598520,-14122808,-14122808},
 31                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14116656,-14647104,-10967848,-8339224,-8864536,-10967848,-12019496,-13598520,-14122808,-13597496},
 32                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14117688,-12542760,-8339224,-8339224,-8864536,-10967848,-12019496,-13598520,-13598520,-13594408},
 33                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-15168312,-10967848,-8339224,-8339224,-8864536,-10967848,-12019496,-13598520,-13597496,-13594416},
 34                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14647104,-9913112,-8339224,-8339224,-8864536,-10967848,-12019496,-13594416,-13597496,-13594416},
 35                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14647104,-9913112,-8339224,-8339224,-9913112,-10967848,-12019496,-13594416,-13594408,-13067040},
 36                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14647104,-10967848,-8339224,-8339224,-9913112,-10967848,-12019496,-13594416,-13594416,-13067040},
 37                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-15168312,-12019496,-8339224,-8339224,-9913112,-10967848,-11494184,-12542760,-13067040,-13067040},
 38                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14118712,-14119736,-10967848,-8864536,-9913112,-9913112,-11494184,-13067040,-13067040,-13590312},
 39                {-16238536,-16762824,-10958624,-10959648,-12012320,-13590312,-14116656,-14116656,-14116656,-14116656,-14116656,-14647104,-13594416,-11492136,-9913112,-10967848,-12542760,-13067040,-13067040,-13589280}}
;
 40            
 41    
 42    private  JFrame frame = new JFrame("一起找茬");
 43    
 44    public ZhaoCha() {
 45       
 46        frame.addWindowListener(new WindowAdapter() {
 47            public void windowClosing(WindowEvent e) {System.exit(0);}}
);           
 48       
 49
 50        jb=new JButton("这个小工具送给你,希望你天天开心");
 51        jb.addActionListener(this);
 52
 53        frame.getContentPane().add(jb);
 54        
 55        frame.pack();
 56        frame.setSize(400380);
 57        frame.setVisible(true);
 58    }

 59
 60    public static void main(String[] args) {
 61       new ZhaoCha();
 62        
 63    }

 64   
 65   public void actionPerformed(ActionEvent arg0) 
 66       
 67       frame.setVisible(false);
 68       snop();
 69       if(image3!=null){
 70           jb.setIcon(null);
 71           jb.setText("");           
 72           jb.setIcon(new ImageIcon(image3));
 73       }
    
 74        //System.out.println("click!");
 75        
 76       frame.setVisible(true);
 77   }

 78
 79    
 80    /**
 81     * 判断两个区域是否相同
 82     * @param list1 区域1
 83     * @param list2 区域2
 84     * @return boolean
 85     */

 86   public boolean isSimilar(List list1,List list2){
 87       int i,j,s;
 88       Integer c1,c2;
 89       s=0;
 90       for(i=0;i<list1.size();i++){
 91           c1=(Integer)list1.get(i);
 92           for(j=0;j<list2.size();j++){
 93               c2=(Integer)list2.get(j);
 94               if(c1.equals(c2)){
 95                   s++;
 96                   list2.remove(j);
 97                   break;
 98               }

 99           }
    
100       }

101       //System.out.println("区域的相似度:"+s);
102       if(s>15)return true;
103       return false;
104   }

105    public void snop(){
106        try 
107            BufferedImage /*image1=null,*/image2=null;
108          //拷贝屏幕到一个BufferedImage对象screenshot 
109            BufferedImage screenshot = (new Robot()).createScreenCapture(new 
110                Rectangle(00, (int) d.getWidth(), (int) d.getHeight())); 
111
112            //开始从截屏上扫描标记,找到的第一个为准
113            boolean find=true;
114            outter:
115            for(int i=0;i<d.getWidth()-10;i++){                
116                for(int j=0;j<d.getHeight()-20;j++){
117                    find=true;
118                    for(int k=0;k<10&&find;k++){
119                        for(int l=0;l<20&&find;l++){
120                            if(screenshot.getRGB(i+k, j+l)!=m_rgb[k][l])find=false;                        
121                        }

122                    }

123                    if(find){
124                        //找到标志
125                        /*image1=(new Robot()).createScreenCapture(new 
126                                Rectangle(i+20, j+1, 370, 300));*/

127                        image2=(new Robot()).createScreenCapture(new 
128                                Rectangle(i+20+370+14, j+1370300));
129                        image3=(new Robot()).createScreenCapture(new 
130                                Rectangle(i+20, j+1370300));            
131                        
132                        break outter;
133                    }

134                }
            
135            }

136            if(!find)return;
137            list1=new ArrayList();
138            list2=new ArrayList();        
139           for(int i=0;i<370;i+=10)
140               for(int j=0;j<300;j+=10){
141                   //取区域数据
142                   list1.clear();
143                   list2.clear();
144                   for(int k=i;k<i+10;k++)
145                       for(int l=j;l<j+10;l++){
146                           list1.add(new Integer(image3.getRGB(k, l)));
147                           list2.add(new Integer(image2.getRGB(k, l)));               
148                       }

149                   if(!isSimilar(list1,list2)){
150                       for(int k=i;k<i+10;k++)
151                           for(int l=j;l<j+10;l++){
152                               image3.setRGB(k, l, Color.RED.getRGB());
153                           }
                       
154                   }

155               }

156            
157            
158            //根据文件前缀变量和文件格式变量,自动生成文件名 
159//            String name=fileName+"1."+imageFormat; 
160//            String name1=fileName+"2."+imageFormat;
161//            String name2=fileName+"3."+imageFormat;
162//            File f = new File(name); 
163//            //System.out.print("Save File "+name); 
164          //将screenshot对象写入图像文件 
165           // ImageIO.write(screenshot, imageFormat, f);
166//            ImageIO.write(image1, imageFormat, f);
167//            ImageIO.write(image2,imageFormat, new File(name1));
168            //ImageIO.write(image3,imageFormat, new File(name2));
169            
170           
171            
172            //System.out.print("..Finished!\n"); 
173          }
 
174          catch (Exception ex) 
175            System.out.println(ex); 
176          }
 
177    }

178
179}

180