Implemented basic Rabi-Ribi overlay to include healthbars that appear
in-game. More data and overlay info can be added later.
This commit is contained in:
parent
dc79351730
commit
4868ccdb0f
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@
|
||||
/jinput-raw.dll
|
||||
/jinput-raw_64.dll
|
||||
/jinput-wintab.dll
|
||||
/memoryDump.txt
|
||||
|
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -225,6 +225,7 @@ public class ChatLogMessage {
|
||||
}
|
||||
|
||||
public static void importMessages(String...logContents) {
|
||||
if (sigIRC.chatlogmodule_enabled) {
|
||||
for (String s : logContents) {
|
||||
if (s!=null) {
|
||||
if (ChatLogModule.chatlogmodule.messageHistory.size()>=ChatLogModule.messageHistoryCount) {
|
||||
@ -234,6 +235,7 @@ public class ChatLogMessage {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
active=false;
|
||||
|
144
src/sig/modules/RabiRibi/Entity.java
Normal file
144
src/sig/modules/RabiRibi/Entity.java
Normal file
@ -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)<hp) {
|
||||
lastTookDamage = parent.readIntFromMemory(MemoryOffset.PLAYTIME);
|
||||
}
|
||||
|
||||
UpdateValues();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*public Point getScreenPosition() {
|
||||
//The screen supports 20x11.5 tiles per map tile.
|
||||
//A map tile is 1280x720
|
||||
//float xtile = x
|
||||
}*/
|
||||
|
||||
public int getHealth() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMaxHealth() {
|
||||
return maxhp;
|
||||
}
|
||||
|
||||
public int getLastHitTime() {
|
||||
return lastTookDamage;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void UpdateValues() {
|
||||
this.id = readIntFromMemoryOffset(MemoryOffset.ENTITY_ID, pointer);
|
||||
this.animation = readIntFromMemoryOffset(MemoryOffset.ENTITY_ANIMATION, pointer);
|
||||
if (this.animation!=-9999) {
|
||||
this.hp = readIntFromMemoryOffset(MemoryOffset.ENTITY_HP, pointer);
|
||||
} else {
|
||||
this.hp = 0;
|
||||
}
|
||||
this.maxhp = readIntFromMemoryOffset(MemoryOffset.ENTITY_MAXHP, pointer);
|
||||
this.x = readFloatFromMemoryOffset(MemoryOffset.ENTITY_XPOS, pointer);
|
||||
this.y = readFloatFromMemoryOffset(MemoryOffset.ENTITY_YPOS, pointer);
|
||||
this.color = readIntFromMemoryOffset(MemoryOffset.ENTITY_COLOR, pointer);
|
||||
this.marker.setTarget(parent.overlay.getScreenPosition(x,y));
|
||||
}
|
||||
|
||||
public int getUniqueID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public float readFloatFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
public int readIntFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(this.getClass().getName()+"(");
|
||||
boolean first=false;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
//if (!ReflectUtils.isCloneable(f)) {
|
||||
if (!first) {
|
||||
try {
|
||||
sb.append(f.getName()+"="+f.get(this));
|
||||
first=true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
sb.append(","+f.getName()+"="+f.get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -14,12 +14,26 @@ public enum MemoryOffset {
|
||||
REGENUP_END(0xD63828),
|
||||
PACKUP_START(0xD6382C),
|
||||
PACKUP_END(0xD63928),
|
||||
ERINA(0x0096DA3C), //Erina Data Pointer.
|
||||
ENTITY_ARRAY(0x0096DA3C), //Erina Data Pointer.
|
||||
ERINA_HP(0x4D8),
|
||||
ERINA_MAXHP(0x4E8),
|
||||
ERINA_XPOS(0xC),
|
||||
ERINA_YPOS(0x10),
|
||||
ERINA_XSPEED(0x470), //Relative to Entity Array.
|
||||
ERINA_YSPEED(0x474), //Relative to Entity Array.
|
||||
MAPID(0xA600AC),
|
||||
CAMERA_XPOS(0x991AF4),
|
||||
CAMERA_YPOS(0xABD0A4),
|
||||
//ENTITY_SIZE(0x704),
|
||||
ENTITY_ID(0x4F4),
|
||||
ENTITY_HP(0x4D8),
|
||||
ENTITY_MAXHP(0x4E8),
|
||||
ENTITY_ISACTIVE(0x674),
|
||||
ENTITY_ANIMATION(0x678),
|
||||
ENTITY_XPOS(0xC),
|
||||
ENTITY_YPOS(0x10),
|
||||
ENTITY_COLOR(0x1C),
|
||||
TRANSITION_COUNTER(0xA7661C)
|
||||
;
|
||||
|
||||
long offset;
|
||||
|
163
src/sig/modules/RabiRibi/MemoryValue.java
Normal file
163
src/sig/modules/RabiRibi/MemoryValue.java
Normal file
@ -0,0 +1,163 @@
|
||||
package sig.modules.RabiRibi;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Kernel32;
|
||||
|
||||
import sig.modules.RabiRibiModule;
|
||||
import sig.utils.DebugUtils;
|
||||
|
||||
public class MemoryValue {
|
||||
RabiRibiModule parent;
|
||||
MemoryValueType type;
|
||||
long offset=-1;
|
||||
long pointer=-1;
|
||||
public boolean needsUpdating=false;
|
||||
int lastIntValue;
|
||||
float lastFloatValue;
|
||||
|
||||
public MemoryValue(MemoryValueType type, long offset, RabiRibiModule parent) {
|
||||
this.type=type;
|
||||
this.offset=offset;
|
||||
this.parent=parent;
|
||||
}
|
||||
|
||||
public MemoryValue(long offset, long pointer, RabiRibiModule parent) {
|
||||
this(MemoryValueType.POINTER,offset, parent);
|
||||
this.pointer=pointer;
|
||||
}
|
||||
|
||||
public MemoryValue(MemoryValueType type, MemoryOffset offset, RabiRibiModule parent) {
|
||||
this(type,offset.getOffset(),parent);
|
||||
}
|
||||
|
||||
public MemoryValue(MemoryOffset offset, MemoryOffset pointer, RabiRibiModule parent) {
|
||||
this(offset.getOffset(),pointer.getOffset(),parent);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
if (needsUpdating) {
|
||||
switch (type) {
|
||||
case ABSOLUTE:
|
||||
lastIntValue = readDirectIntFromMemoryLocation(offset);
|
||||
break;
|
||||
case LOCAL:
|
||||
lastIntValue = readIntFromMemory(offset);
|
||||
break;
|
||||
case POINTER:
|
||||
lastIntValue = readIntFromPointer(offset,pointer);
|
||||
break;
|
||||
}
|
||||
needsUpdating=false;
|
||||
}
|
||||
return lastIntValue;
|
||||
}
|
||||
|
||||
public float getFloat() {
|
||||
if (needsUpdating) {
|
||||
switch (type) {
|
||||
case ABSOLUTE:
|
||||
lastFloatValue = readDirectFloatFromMemoryLocation(offset);
|
||||
break;
|
||||
case LOCAL:
|
||||
lastFloatValue = readFloatFromMemory(offset);
|
||||
break;
|
||||
case POINTER:
|
||||
lastFloatValue = readFloatFromPointer(offset,pointer);
|
||||
break;
|
||||
}
|
||||
needsUpdating=false;
|
||||
}
|
||||
return lastFloatValue;
|
||||
}
|
||||
|
||||
int readIntFromErinaData(MemoryOffset val) {
|
||||
return readIntFromPointer(val,MemoryOffset.ENTITY_ARRAY);
|
||||
}
|
||||
|
||||
float readFloatFromErinaData(MemoryOffset val) {
|
||||
return readFloatFromPointer(val,MemoryOffset.ENTITY_ARRAY);
|
||||
}
|
||||
|
||||
int readIntFromMemory(long offset) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(parent.rabiRibiMemOffset+offset), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
float readFloatFromMemory(long offset) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(parent.rabiRibiMemOffset+offset), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
float readFloatFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
int readIntFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
float readDirectFloatFromMemoryLocation(long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
int readDirectIntFromMemoryLocation(long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(pointer), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
int readIntFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(readIntFromMemory(pointer.getOffset())+val.getOffset()), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
int readIntFromPointer(long val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(readIntFromMemory(pointer)+val), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
float readFloatFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(readIntFromMemory(pointer.getOffset())+val.getOffset()), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
float readFloatFromPointer(long val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(readIntFromMemory(pointer)+val), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
int readIntFromMemory(MemoryOffset val) {
|
||||
return (int)readFromMemory(val,MemoryType.INTEGER);
|
||||
}
|
||||
|
||||
float readFloatFromMemory(MemoryOffset val) {
|
||||
return (float)readFromMemory(val,MemoryType.FLOAT);
|
||||
}
|
||||
|
||||
Object readFromMemory(MemoryOffset val, MemoryType type) {
|
||||
Memory mem = new Memory(type.getSize());
|
||||
Kernel32.INSTANCE.ReadProcessMemory(parent.rabiribiProcess, new Pointer(parent.rabiRibiMemOffset+val.getOffset()), mem, type.getSize(), null);
|
||||
switch (type) {
|
||||
case FLOAT:
|
||||
return mem.getFloat(0);
|
||||
case INTEGER:
|
||||
return mem.getInt(0);
|
||||
default:
|
||||
System.out.println("WARNING! Type "+type+" does not have a defined value.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
7
src/sig/modules/RabiRibi/MemoryValueType.java
Normal file
7
src/sig/modules/RabiRibi/MemoryValueType.java
Normal file
@ -0,0 +1,7 @@
|
||||
package sig.modules.RabiRibi;
|
||||
|
||||
public enum MemoryValueType {
|
||||
LOCAL, //Memory offset found relative to base address.
|
||||
ABSOLUTE, //Memory found absolute in the memory table.
|
||||
POINTER; //A value that points to a memory address.
|
||||
}
|
141
src/sig/modules/RabiRibi/Overlay.java
Normal file
141
src/sig/modules/RabiRibi/Overlay.java
Normal file
@ -0,0 +1,141 @@
|
||||
package sig.modules.RabiRibi;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import sig.modules.RabiRibiModule;
|
||||
import sig.modules.RabiRibi.SmoothObjects.ErinaMarker;
|
||||
|
||||
public class Overlay {
|
||||
float xcoord=-1f,ycoord=-1f;
|
||||
boolean changedRooms=false;
|
||||
RabiRibiModule parent;
|
||||
public float xpos,ypos,xspd,yspd;
|
||||
public float camera_xpos,camera_ypos;
|
||||
public List<SmoothObject> objects = new ArrayList<SmoothObject>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
src/sig/modules/RabiRibi/SmoothObject.java
Normal file
51
src/sig/modules/RabiRibi/SmoothObject.java
Normal file
@ -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) {
|
||||
|
||||
}
|
||||
}
|
37
src/sig/modules/RabiRibi/SmoothObjects/EntityMarker.java
Normal file
37
src/sig/modules/RabiRibi/SmoothObjects/EntityMarker.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
23
src/sig/modules/RabiRibi/SmoothObjects/ErinaMarker.java
Normal file
23
src/sig/modules/RabiRibi/SmoothObjects/ErinaMarker.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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<Integer,Entity> entities = new HashMap<Integer,Entity>();
|
||||
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,10 +93,50 @@ public class RabiRibiModule extends Module{
|
||||
|
||||
public void run() {
|
||||
super.run();
|
||||
updateEntities();
|
||||
overlay.run();
|
||||
}
|
||||
|
||||
public HashMap<Integer,Entity> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
private void updateEntities() {
|
||||
|
||||
//System.out.println("Size is "+size);
|
||||
List<Integer> idsToRemove = new ArrayList<Integer>();
|
||||
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;i<MAX_ENTITIES_TO_UPDATE;i++) {
|
||||
if (!entities.containsKey(i)) {
|
||||
Entity ent = new Entity(arrayPtr,i,this);
|
||||
if (ent.isActive()) {
|
||||
//System.out.println("Found entity at index "+i);
|
||||
//entities.add(ent);
|
||||
entities.put(i, ent);
|
||||
}
|
||||
}
|
||||
arrayPtr += ENTITY_ARRAY_ELEMENT_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
super.draw(g);
|
||||
if (readIntFromMemory(MemoryOffset.TRANSITION_COUNTER)<300) {
|
||||
int i=32;
|
||||
/*DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "Money: "+readIntFromMemory(MemoryOffset.MONEY));
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "H-Ups: "+readItemCountFromMemory(MemoryOffset.HEALTHUP_START,MemoryOffset.HEALTHUP_END));
|
||||
@ -92,54 +147,125 @@ public class RabiRibiModule extends Module{
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "HP: "+readIntFromErinaData(MemoryOffset.ERINA_HP)+"/"+readIntFromErinaData(MemoryOffset.ERINA_MAXHP));
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "POS ("+(int)readFloatFromErinaData(MemoryOffset.ERINA_XPOS)/1280+","+(int)readFloatFromErinaData(MemoryOffset.ERINA_YPOS)/720+")");
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "MAP: "+readIntFromMemory(MemoryOffset.MAPID));*/
|
||||
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE,
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "POS ("+(readFloatFromErinaData(MemoryOffset.ERINA_XPOS))+","+(readFloatFromErinaData(MemoryOffset.ERINA_YPOS))+")");
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "POS ("+(readFloatFromErinaData(MemoryOffset.ERINA_XPOS)/1280)+","+(readFloatFromErinaData(MemoryOffset.ERINA_YPOS)/720)+")");
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "CAMERA ("+(readIntFromMemory(MemoryOffset.CAMERA_XPOS))+","+(readIntFromMemory(MemoryOffset.CAMERA_YPOS))+")");
|
||||
//DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE, "SCREENPOS ("+overlay.getScreenPosition(readFloatFromErinaData(MemoryOffset.ERINA_XPOS), readFloatFromErinaData(MemoryOffset.ERINA_YPOS))+")");
|
||||
overlay.draw(g);
|
||||
if (Math.abs(readFloatFromErinaData(MemoryOffset.ERINA_XSPEED))>0.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),
|
||||
}));
|
||||
DrawUtils.drawOutlineText(g, sigIRC.panel.programFont, position.getX(), position.getY()+(i+=24), 3, Color.BLACK, Color.WHITE,
|
||||
"Rainbow Eggs: "+readIntFromMemory(0xD65FD4));
|
||||
*/
|
||||
/*
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int readIntFromErinaData(MemoryOffset val) {
|
||||
return readIntFromPointer(val,MemoryOffset.ERINA);
|
||||
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<ENTITY_ARRAY_ELEMENT_SIZE/4;i++) {
|
||||
Long ptrArray = (long)(readIntFromMemory(MemoryOffset.ENTITY_ARRAY)+(numb*ENTITY_ARRAY_ELEMENT_SIZE)+i*4);
|
||||
FileUtils.logToFile(" +"+Integer.toHexString(i*4)+": "+readDirectIntFromMemoryLocation(ptrArray)+" / "+readDirectFloatFromMemoryLocation(ptrArray)+"f", memFile);
|
||||
}
|
||||
}
|
||||
} else
|
||||
if (ev.getKeyCode()==KeyEvent.VK_END) {
|
||||
String memFile = sigIRC.BASEDIR+"memoryDump.txt";
|
||||
FileUtils.logToFile("Memory Dump of All Erina Values:", memFile);
|
||||
for (int i=0;i<ENTITY_ARRAY_ELEMENT_SIZE/4;i++) {
|
||||
Long ptrArray = (long)(MemoryOffset.CAMERA_XPOS.getOffset()+i*4);
|
||||
FileUtils.logToFile(" +"+Integer.toHexString(i*4)+": "+readIntFromMemory(ptrArray)+" / "+readFloatFromMemory(ptrArray)+"f", memFile);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
float readFloatFromErinaData(MemoryOffset val) {
|
||||
return readFloatFromPointer(val,MemoryOffset.ERINA);
|
||||
public int readIntFromErinaData(MemoryOffset val) {
|
||||
return readIntFromPointer(val,MemoryOffset.ENTITY_ARRAY);
|
||||
}
|
||||
|
||||
int readIntFromMemory(long offset) {
|
||||
public float readFloatFromErinaData(MemoryOffset val) {
|
||||
return readFloatFromPointer(val,MemoryOffset.ENTITY_ARRAY);
|
||||
}
|
||||
|
||||
public int readIntFromMemory(long offset) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(rabiRibiMemOffset+offset), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
float readFloatFromMemory(long offset) {
|
||||
public float readFloatFromMemory(long offset) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(rabiRibiMemOffset+offset), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
int readIntFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
public float readFloatFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
public int readIntFromMemoryOffset(MemoryOffset val, long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(pointer+val.getOffset()), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
public float readDirectFloatFromMemoryLocation(long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(pointer), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
public int readDirectIntFromMemoryLocation(long pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(pointer), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
public int readIntFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(readIntFromMemory(pointer.getOffset())+val.getOffset()), mem, 4, null);
|
||||
return mem.getInt(0);
|
||||
}
|
||||
|
||||
float readFloatFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
public float readFloatFromPointer(MemoryOffset val, MemoryOffset pointer) {
|
||||
Memory mem = new Memory(4);
|
||||
Kernel32.INSTANCE.ReadProcessMemory(rabiribiProcess, new Pointer(readIntFromMemory(pointer.getOffset())+val.getOffset()), mem, 4, null);
|
||||
return mem.getFloat(0);
|
||||
}
|
||||
|
||||
int readIntFromMemory(MemoryOffset val) {
|
||||
public int readIntFromMemory(MemoryOffset val) {
|
||||
return (int)readFromMemory(val,MemoryType.INTEGER);
|
||||
}
|
||||
|
||||
float readFloatFromMemory(MemoryOffset val) {
|
||||
public float readFloatFromMemory(MemoryOffset val) {
|
||||
return (float)readFromMemory(val,MemoryType.FLOAT);
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class sigIRC{
|
||||
static String touhoumotherConsoleFont="Agency FB Bold";
|
||||
static boolean touhoumothermodule_enabled=false;
|
||||
static boolean twitchmodule_enabled=true;
|
||||
static boolean chatlogmodule_enabled=true;
|
||||
public static boolean chatlogmodule_enabled=true;
|
||||
static boolean downloadsComplete=false;
|
||||
static boolean hardwareAcceleration=true;
|
||||
static boolean playedoAuthSoundOnce=false;
|
||||
|
13
src/sig/utils/DebugUtils.java
Normal file
13
src/sig/utils/DebugUtils.java
Normal file
@ -0,0 +1,13 @@
|
||||
package sig.utils;
|
||||
|
||||
|
||||
public class DebugUtils {
|
||||
public static void showStackTrace() {
|
||||
StackTraceElement[] stacktrace = new Throwable().getStackTrace();
|
||||
StringBuilder stack = new StringBuilder("Mini stack tracer:");
|
||||
for (int i=0;i<Math.min(10, stacktrace.length);i++) {
|
||||
stack.append("\n"+stacktrace[i].getClassName()+": **"+stacktrace[i].getFileName()+"** "+stacktrace[i].getMethodName()+"():"+stacktrace[i].getLineNumber());
|
||||
}
|
||||
System.out.println("Trace:"+stack);
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import sig.sigIRC;
|
||||
import sig.modules.ChatLog.ChatLogMessage;
|
||||
|
||||
public class FileUtils {
|
||||
@ -256,7 +257,7 @@ public class FileUtils {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (outputToChatLog) {
|
||||
if (outputToChatLog && sigIRC.chatlogmodule_enabled) {
|
||||
ChatLogMessage.importMessages(message);
|
||||
}
|
||||
}
|
||||
|
50
src/sig/utils/JavaUtils.java
Normal file
50
src/sig/utils/JavaUtils.java
Normal file
@ -0,0 +1,50 @@
|
||||
package sig.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class JavaUtils {
|
||||
public JavaUtils clone() {
|
||||
JavaUtils newpos = new JavaUtils();
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
if (ReflectUtils.isCloneable(f)) {
|
||||
try {
|
||||
f.set(newpos, f.get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return newpos;
|
||||
}
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(this.getClass().getName()+"(");
|
||||
boolean first=false;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
if (!ReflectUtils.isCloneable(f)) {
|
||||
if (!first) {
|
||||
try {
|
||||
sb.append(f.getName()+"="+f.get(this));
|
||||
first=true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
sb.append(","+f.getName()+"="+f.get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
10
src/sig/utils/ReflectUtils.java
Normal file
10
src/sig/utils/ReflectUtils.java
Normal file
@ -0,0 +1,10 @@
|
||||
package sig.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ReflectUtils {
|
||||
public static boolean isCloneable(Field f) {
|
||||
int mods = f.getModifiers();
|
||||
return mods<8;
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package sig.utils;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Point;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import sig.sigIRC;
|
||||
|
||||
@ -82,4 +85,45 @@ public class TextUtils {
|
||||
String[] split = col.split(",");
|
||||
return new Color(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2]));
|
||||
}
|
||||
|
||||
public static List<String> WrapText(String msg, Font font, double width) {
|
||||
List<String> displayMessage = new ArrayList<String>();
|
||||
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<String> list, int maxWidth) {
|
||||
int marker = 1;
|
||||
int textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, marker), font).getWidth();
|
||||
while (textWidth<maxWidth) {
|
||||
if (marker<msg.length()) {
|
||||
int tempmarker = msg.indexOf(' ', marker);
|
||||
if (tempmarker!=-1) {
|
||||
textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, tempmarker), font).getWidth();
|
||||
if (textWidth<maxWidth) {
|
||||
marker = tempmarker+1;
|
||||
}
|
||||
//System.out.println(msg.substring(0, marker)+" | "+textWidth);
|
||||
} else {
|
||||
marker=msg.length();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
String currentText = msg.substring(0, marker);
|
||||
list.add(currentText);
|
||||
return msg.substring(marker, msg.length());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user