Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 2.67 KB  |  hits: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.FontFormatException;
  4. import java.awt.Graphics;
  5. import java.awt.GraphicsEnvironment;
  6. import java.awt.font.FontRenderContext;
  7. import java.awt.geom.Rectangle2D;
  8. import java.awt.image.BufferedImage;
  9. import java.io.File;
  10. import java.io.IOException;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import org.runedream.api.Script;
  15. import org.runedream.api.ScriptManifest;
  16. import org.runedream.api.methods.Environment;
  17. import org.runedream.api.methods.Game;
  18. import org.runedream.api.util.Log;
  19. @ScriptManifest(
  20.                 authors = { "TBT" },
  21.                 name = "Debugger",
  22.                 version = 1.0,
  23.                 description = "Debugs my shit",
  24.                 keywords = { ""},
  25.                 language = { true, true, true, true })
  26. public class Debugger extends Script {
  27.        
  28.         @Override
  29.         public boolean onStart() {                     
  30.                         return true;
  31.         }
  32.                
  33.         @Override
  34.         public int loop() {                    
  35.                         Font font = null;
  36.                         try {
  37.                                 font = Font.createFont(Font.TRUETYPE_FONT, new File(Environment.getStorageDirectoryPath() + "/chat.ttf"));
  38.                         } catch (FontFormatException e) {
  39.                                 // TODO Auto-generated catch block
  40.                                 e.printStackTrace();
  41.                         } catch (IOException e) {
  42.                                 // TODO Auto-generated catch block
  43.                                 e.printStackTrace();
  44.                         }
  45.                         final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  46.                         ge.registerFont(font);
  47.                         final Font chatFont = new Font(font.getName(), Font.PLAIN, 16);                
  48.                         final FontRenderContext frc = new FontRenderContext(null, false, false);
  49.                         final Rectangle2D bounds = chatFont.getStringBounds("Hola", frc);
  50.                         int bw = (int)bounds.getWidth();
  51.                         int bh = (int)bounds.getHeight();
  52.                         haha: for(int x = 9; x < 490-bw; x++) {
  53.                                 for(int y = 440; y < 490-bh; y++) {
  54.                                         BufferedImage copy = Game.getImage();                  
  55.                                         Graphics g = copy.getGraphics();               
  56.                                         g.setFont(chatFont);
  57.                                         g.setColor(new Color(0, 0, 255));                              
  58.                                         g.drawString("Hola", x, y);                                    
  59.                                         BufferedImage c1 = Game.getImage().getSubimage(x, y-bh, bw, bh);                               
  60.                                         BufferedImage c2 = copy.getSubimage(x, y-bh, bw, bh);                                  
  61.                                         for(int i = 0; i < c1.getWidth(); i++) {
  62.                                                 for(int i2 = 0; i2 < c1.getHeight(); i2++) {                                           
  63.                                                         if(c1.getRGB(i, i2) != c2.getRGB(i, i2))
  64.                                                                 continue haha;
  65.                                                 }                              
  66.                                         }      
  67.                                         g.setColor(new Color(255,0,0,100));
  68.                                         g.fillRect(x, y-bh, bw, bh);
  69.                                         try {
  70.                                                 ImageIO.write(copy, "png", new File("done.png"));
  71.                                         } catch (IOException e) {
  72.                                                 // TODO Auto-generated catch block
  73.                                                 e.printStackTrace();
  74.                                         }
  75.                                         Log.log(x + ", " +y);
  76.                                         break haha;
  77.                                 }
  78.                         }              
  79.             return -1;
  80.         }
  81. }