diff --git a/.gitignore b/.gitignore index 03a74bf..3748367 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /jinput-raw.dll /jinput-raw_64.dll /jinput-wintab.dll +/memoryDump.txt diff --git a/sigIRCv2.jar b/sigIRCv2.jar index 4ce9a6e..b66c692 100644 Binary files a/sigIRCv2.jar and b/sigIRCv2.jar differ diff --git a/src/sig/modules/ChatLog/ChatLogMessage.java b/src/sig/modules/ChatLog/ChatLogMessage.java index d86bd64..b6e9feb 100644 --- a/src/sig/modules/ChatLog/ChatLogMessage.java +++ b/src/sig/modules/ChatLog/ChatLogMessage.java @@ -225,12 +225,14 @@ public class ChatLogMessage { } public static void importMessages(String...logContents) { - for (String s : logContents) { - if (s!=null) { - if (ChatLogModule.chatlogmodule.messageHistory.size()>=ChatLogModule.messageHistoryCount) { - ChatLogModule.chatlogmodule.messageHistory.remove(0).cleanup(); + if (sigIRC.chatlogmodule_enabled) { + for (String s : logContents) { + if (s!=null) { + if (ChatLogModule.chatlogmodule.messageHistory.size()>=ChatLogModule.messageHistoryCount) { + ChatLogModule.chatlogmodule.messageHistory.remove(0).cleanup(); + } + ChatLogModule.chatlogmodule.messageHistory.add(new ChatLogMessage(s)); } - ChatLogModule.chatlogmodule.messageHistory.add(new ChatLogMessage(s)); } } } diff --git a/src/sig/modules/RabiRibi/Entity.java b/src/sig/modules/RabiRibi/Entity.java new file mode 100644 index 0000000..49ab461 --- /dev/null +++ b/src/sig/modules/RabiRibi/Entity.java @@ -0,0 +1,144 @@ +package sig.modules.RabiRibi; + +import java.awt.Point; +import java.lang.reflect.Field; + +import com.sun.jna.Memory; +import com.sun.jna.Pointer; +import com.sun.jna.platform.win32.Kernel32; + +import sig.modules.RabiRibiModule; +import sig.modules.RabiRibi.SmoothObjects.EntityMarker; +import sig.utils.ReflectUtils; + +public class Entity { + int id = 0; + int uuid = 0; + int hp = 0; + int maxhp = 0; + boolean active = false; + int animation = 0; + float x = 0; + float y = 0; + RabiRibiModule parent = null; + int lastTookDamage = 0; + long pointer; + int color = 0; + public EntityMarker marker; + + public Entity(long memoryOffset, int uuid, RabiRibiModule parent) { + this.parent=parent; + pointer = memoryOffset; + this.uuid = uuid; + this.marker = new EntityMarker((int)x,(int)y,(int)x,(int)y,this,parent); + UpdateValues(); + this.active = readIntFromMemoryOffset(MemoryOffset.ENTITY_ISACTIVE, pointer)==1 && + id!=0 && id!=1 && maxhp!=0; + if (this.active) { + parent.overlay.objects.add(this.marker); + } + } + + public boolean run() { + this.active = readIntFromMemoryOffset(MemoryOffset.ENTITY_ISACTIVE, pointer)==1 && + id!=0 && id!=1 && maxhp!=0; + + if (!active) { + return false; + } + + if (readIntFromMemoryOffset(MemoryOffset.ENTITY_HP, pointer) objects = new ArrayList(); + + ErinaMarker ERINA_MARKER; + + public Overlay(RabiRibiModule parent){ + this.parent = parent; + /*this.xcoord = (int)(parent.readFloatFromErinaData(MemoryOffset.ERINA_XPOS)/1280); + this.ycoord = (int)(parent.readFloatFromErinaData(MemoryOffset.ERINA_YPOS)/720);*/ + ERINA_MARKER = new ErinaMarker(0,0,0,0,parent); + + objects.add(ERINA_MARKER); + } + + public void run() { + camera_xpos = parent.readIntFromMemory(MemoryOffset.CAMERA_XPOS); + camera_ypos = parent.readIntFromMemory(MemoryOffset.CAMERA_YPOS); + + float prev_camera_xpos = camera_xpos; + float prev_camera_ypos = camera_ypos; + xpos = parent.readFloatFromErinaData(MemoryOffset.ERINA_XPOS); + ypos = parent.readFloatFromErinaData(MemoryOffset.ERINA_YPOS); + + xspd = camera_xpos-prev_camera_xpos; + yspd = camera_ypos-prev_camera_ypos; + for (SmoothObject so : objects) { + so.run(); + } + /*int new_xcoord,new_ycoord; + + float prev_xpos = xpos; + float prev_ypos = ypos; + float prev_camera_xpos = camera_xpos; + float prev_camera_ypos = camera_ypos; + + xpos = parent.readFloatFromErinaData(MemoryOffset.ERINA_XPOS)/1280; + ypos = parent.readFloatFromErinaData(MemoryOffset.ERINA_YPOS)/720; + camera_xpos = parent.readIntFromMemory(MemoryOffset.CAMERA_XPOS); + camera_ypos = parent.readIntFromMemory(MemoryOffset.CAMERA_YPOS); + + if (Math.abs(parent.readFloatFromErinaData(MemoryOffset.ERINA_XSPEED))>0.5f) { + if ((Math.abs(prev_xpos-xpos)>0.005 && xpos%1>0.01 && xpos%1<0.99) || (Math.abs(prev_ypos-ypos)>0.005 && ypos%1>0.01 && ypos%1<0.99)) { + if (Math.abs(prev_xpos-xpos)>0.005) { + if (edgeOfScreenX) { + if (prev_camera_xpos!=camera_xpos) { + edgeOfScreenX = false; + //System.out.println("Not on edge of X screen anymore."); + } + } else { + if (prev_camera_xpos==camera_xpos) { + edgeOfScreenX = true; + //System.out.println("Now on edge of X screen."); + } + } + } + if (Math.abs(prev_ypos-ypos)>0.005) { + if (edgeOfScreenY) { + if (prev_camera_ypos!=camera_ypos) { + edgeOfScreenY = false; + //System.out.println("Not on edge of Y screen anymore."); + } + } else { + if (prev_camera_ypos==camera_ypos) { + edgeOfScreenY = true; + //System.out.println("Now on edge of Y screen."); + } + } + } + } + } + + + new_xcoord = (int)(xpos); + new_ycoord = (int)(ypos); + int xchange = (int)Math.signum(xcoord-new_xcoord); //-1 = Moving Right (Left edge), 1 = Moving Left(Right edge) + int ychange = (int)Math.signum(ycoord-new_ycoord); //-1 = Moving Down(Top edge), 1 = Moving Up (Bottom edge) + if (xchange!=0 || ychange!=0) { + //Re-orient the camera, there has been a room change. + float pct_xroom = xpos%1 + ((edgeOfScreenX)?0:0.5f); + float pct_yroom = ypos%1 + ((edgeOfScreenY)?0:0.5f); + camera_offset_x = -(pct_xroom*20); + camera_offset_y = -(pct_yroom*11.25f); + System.out.println(pct_xroom+"%,"+pct_yroom+"%. Change detected. Camera is offset by ("+camera_offset_x+","+camera_offset_y+")"); + this.xcoord = new_xcoord; + this.ycoord = new_ycoord; + camera_x = parent.readFloatFromErinaData(MemoryOffset.ERINA_XPOS) + camera_offset_x*64; + camera_y = parent.readFloatFromErinaData(MemoryOffset.ERINA_YPOS) + camera_offset_y*64; + System.out.println("Camera position is ("+camera_x+","+camera_y+")"); + starting_camera_x = camera_xpos; + starting_camera_y = camera_ypos; + }*/ + } + + public Point.Double getScreenPosition(float xpos, float ypos) { + /*float diffx = xpos-camera_x; + float diffy = ypos-camera_y; + + double screen_blocksize_x = parent.getPosition().getWidth()/20; + double screen_blocksize_y = parent.getPosition().getHeight()/11.25; + + float camera_diffx = starting_camera_x-parent.readIntFromMemory(MemoryOffset.CAMERA_XPOS); + float camera_diffy = starting_camera_y-parent.readIntFromMemory(MemoryOffset.CAMERA_YPOS); + + //System.out.println("Block size is ("+screen_blocksize_x+","+screen_blocksize_y+"). Diff is ("+diffx+","+diffy+")."); + /*System.out.println("Starting Camera: ("+starting_camera_x+","+starting_camera_y+")"); + System.out.println("Camera: ("+camera_diffx+","+camera_diffy+")"); + System.out.println("Block Coords: ("+(camera_diffx/64)+","+(camera_diffy/64)+")");*/ + + double screen_blocksize_x = parent.getPosition().getWidth()/20; + double screen_blocksize_y = parent.getPosition().getHeight()/11.25; + + return new Point.Double(((xpos-(-camera_xpos)+xspd*2)/64)*screen_blocksize_x, + ((ypos-(-camera_ypos)+yspd*2)/64)*screen_blocksize_y); + } + + public void draw(Graphics g) { + if (parent.readIntFromMemory(MemoryOffset.TRANSITION_COUNTER)<300) { + for (SmoothObject so : objects) { + so.draw(g); + } + } + } +} diff --git a/src/sig/modules/RabiRibi/SmoothObject.java b/src/sig/modules/RabiRibi/SmoothObject.java new file mode 100644 index 0000000..9c2b969 --- /dev/null +++ b/src/sig/modules/RabiRibi/SmoothObject.java @@ -0,0 +1,51 @@ +package sig.modules.RabiRibi; + +import java.awt.Graphics; +import java.awt.Point; + +import sig.modules.RabiRibiModule; + +public class SmoothObject { + protected int x,y; + int targetx,targety; + protected RabiRibiModule parent; + + public SmoothObject(int x, int y, int targetx, int targety, RabiRibiModule parent) { + this.x=x; + this.y=y; + this.targetx=targetx; + this.targety=targety; + this.parent=parent; + } + + public void setTarget(Point target) { + targetx = (int)target.getX(); + targety = (int)target.getY(); + } + + public void setTarget(Point.Double target) { + targetx = (int)target.getX(); + targety = (int)target.getY(); + } + + public Point getTarget() { + return new Point(targetx,targety); + } + + public void setPosition(Point position) { + x = (int)position.getX(); + y = (int)position.getY(); + } + + public void run() { + int xdiff = targetx-x; + int ydiff = targety-y; + x+=xdiff/1.3; + y+=ydiff/1.3; + //System.out.println("X:"+x+", Y:"+y+" TargetX:"+targetx+" TargetY:"+targety); + } + + public void draw(Graphics g) { + + } +} diff --git a/src/sig/modules/RabiRibi/SmoothObjects/EntityMarker.java b/src/sig/modules/RabiRibi/SmoothObjects/EntityMarker.java new file mode 100644 index 0000000..e0d4aaa --- /dev/null +++ b/src/sig/modules/RabiRibi/SmoothObjects/EntityMarker.java @@ -0,0 +1,37 @@ +package sig.modules.RabiRibi.SmoothObjects; + +import java.awt.Color; +import java.awt.Graphics; + +import sig.modules.RabiRibiModule; +import sig.modules.RabiRibi.Entity; +import sig.modules.RabiRibi.MemoryOffset; +import sig.modules.RabiRibi.SmoothObject; + +public class EntityMarker extends SmoothObject{ + Entity ent; + + public EntityMarker(int x, int y, int targetx, int targety, Entity ent, RabiRibiModule parent) { + super(x, y, targetx, targety, parent); + this.ent=ent; + } + + public void draw(Graphics g) { + super.draw(g); + int alphaval = (ent.getLastHitTime()>parent.readIntFromMemory(MemoryOffset.PLAYTIME)-180)?255:110; + float pct = ent.getHealth()/(float)ent.getMaxHealth(); + if (pct>=0.66) { + g.setColor(new Color(64,255,64,alphaval)); + } else + if (pct>=0.33) { + g.setColor(new Color(255,255,64,alphaval)); + } else { + g.setColor(new Color(255,64,64,alphaval)); + } + g.fillRect(x, y-56, (int)(48*pct), 16); + g.setColor(new Color(0,0,0,alphaval)); + g.drawRect(x, y-56, 48, 16); + g.setColor(Color.BLACK); + } + +} diff --git a/src/sig/modules/RabiRibi/SmoothObjects/ErinaMarker.java b/src/sig/modules/RabiRibi/SmoothObjects/ErinaMarker.java new file mode 100644 index 0000000..3f8b783 --- /dev/null +++ b/src/sig/modules/RabiRibi/SmoothObjects/ErinaMarker.java @@ -0,0 +1,23 @@ +package sig.modules.RabiRibi.SmoothObjects; + +import java.awt.Graphics; +import java.awt.Point; +import java.awt.geom.Point2D; + +import sig.modules.RabiRibiModule; +import sig.modules.RabiRibi.SmoothObject; + +public class ErinaMarker extends SmoothObject{ + + + public ErinaMarker(int x, int y, int targetx, int targety, RabiRibiModule parent) { + super(x, y, targetx, targety, parent); + } + + public void draw(Graphics g) { + super.draw(g); + Point2D.Double erina_pos = parent.overlay.getScreenPosition(parent.overlay.xpos, parent.overlay.ypos); + setTarget(new Point((int)erina_pos.getX(),(int)erina_pos.getY()-72)); + g.fillOval(x, y, 16, 16); + } +} diff --git a/src/sig/modules/RabiRibiModule.java b/src/sig/modules/RabiRibiModule.java index 593d30c..3e13558 100644 --- a/src/sig/modules/RabiRibiModule.java +++ b/src/sig/modules/RabiRibiModule.java @@ -2,8 +2,12 @@ package sig.modules; import java.awt.Color; import java.awt.Graphics; +import java.awt.event.KeyEvent; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import com.sun.jna.Memory; @@ -14,17 +18,26 @@ import com.sun.jna.platform.win32.WinNT.HANDLE; import sig.Module; import sig.sigIRC; +import sig.modules.RabiRibi.Entity; import sig.modules.RabiRibi.MemoryOffset; import sig.modules.RabiRibi.MemoryType; +import sig.modules.RabiRibi.Overlay; import sig.modules.utils.PsapiTools; import sig.utils.DrawUtils; +import sig.utils.FileUtils; +import sig.utils.TextUtils; public class RabiRibiModule extends Module{ final int PROCESS_PERMISSIONS = WinNT.PROCESS_QUERY_INFORMATION | WinNT.PROCESS_VM_READ; boolean foundRabiRibi = false; int rabiRibiPID = -1; long rabiRibiMemOffset = 0; - HANDLE rabiribiProcess = null; + public HANDLE rabiribiProcess = null; + HashMap entities = new HashMap(); + final static int MAX_ENTITIES_TO_UPDATE = 500; + final static int ENTITY_ARRAY_ELEMENT_SIZE = 0x704; + + public Overlay overlay; public RabiRibiModule(Rectangle2D bounds, String moduleName) { super(bounds, moduleName); @@ -67,6 +80,8 @@ public class RabiRibiModule extends Module{ } catch (Exception e) { e.printStackTrace(); } + + this.overlay = new Overlay(this); } public void ApplyConfigWindowProperties() { @@ -78,68 +93,179 @@ public class RabiRibiModule extends Module{ public void run() { super.run(); + updateEntities(); + overlay.run(); + } + + public HashMap getEntities() { + return entities; } + private void updateEntities() { + + //System.out.println("Size is "+size); + List idsToRemove = new ArrayList(); + for (Integer i : entities.keySet()) { + Entity ent = entities.get(i); + if (!ent.run()) { + idsToRemove.add(i); + } + } + for (Integer i : idsToRemove) { + if (!overlay.objects.remove(entities.get(i).marker)) { + System.out.println("WARNING! Could not remove overlay EntityMarker. Possible memory leak occurring!"); + } + entities.remove(i); + } + + //System.out.println("Starting address is 0x"+Long.toHexString(readIntFromMemory(MemoryOffset.ENTITY_ARRAY))); + long arrayPtr = readIntFromMemory(MemoryOffset.ENTITY_ARRAY); + //System.out.println("Array Pointer starts at 0x"+Long.toHexString(arrayPtr)); + for (int i=0;i0.5f) { + g.setColor(Color.RED); + } + DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, g.getColor(), Color.WHITE, "XSPD "+readFloatFromErinaData(MemoryOffset.ERINA_XSPEED)); + g.setColor(Color.BLACK); + /*DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, + "Sunny Beam: "+Arrays.toString( + new int[]{ + readIntFromMemory(0xD63304), + readIntFromMemory(0xD63D0C), + })); + */ + /* + for (String s : TextUtils.WrapText(("Entities: "+entities).replaceAll(",", ", "), sigIRC.panel.programFont, position.getWidth()-20)) { + DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX()+20, position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, + s); + }*/ + for (Integer numb : entities.keySet()) { + Entity ent = entities.get(numb); + if (ent.getLastHitTime()>readIntFromMemory(MemoryOffset.PLAYTIME)-180) { + for (String s : TextUtils.WrapText("Entity "+ent.getID()+": "+ent.getHealth()+"/"+ent.getMaxHealth()+" HP "+((ent.getHealth()/(float)ent.getMaxHealth())*100)+"%".replaceAll(",", ", "), sigIRC.panel.programFont, position.getWidth()-20)) { + DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX()+20, position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, + s); + } + } + } + } + } + + public void keypressed(KeyEvent ev) { + super.keypressed(ev); + /*if (ev.getKeyCode()==KeyEvent.VK_HOME) { + String memFile = sigIRC.BASEDIR+"memoryDump.txt"; + FileUtils.logToFile("Memory Dump of All Loaded Entities:", memFile); + for (Integer numb : entities.keySet()) { + Entity ent = entities.get(numb); + FileUtils.logToFile(ent.toString(), memFile); + for (int i=0;i WrapText(String msg, Font font, double width) { + List displayMessage = new ArrayList(); + String rawmessage = msg; + int textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, font).getWidth(); + int maxWidth = (int)width; + do { + rawmessage = BreakTextAtNextSection(rawmessage+" ",font,displayMessage,maxWidth); + textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, font).getWidth(); + } while (textWidth>maxWidth); + if (rawmessage.length()>0) { + displayMessage.add(rawmessage); + } + return displayMessage; + //System.out.println(displayMessage+": "+messageDisplaySize); + } + + private static String BreakTextAtNextSection(String msg, Font font, List list, int maxWidth) { + int marker = 1; + int textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, marker), font).getWidth(); + while (textWidth