Cleaned up redundant method calls by putting address at the end of the parameter list (to support 1 address or 2 addresses specifying a range). Promoted aux memory check to main ram observation method for use outside of cheat engine code.

This commit is contained in:
Brendan Robert 2015-08-15 15:06:01 -05:00
parent 9985f096e4
commit 5c0855d966
4 changed files with 92 additions and 58 deletions

View File

@ -19,7 +19,6 @@
package jace.cheat; package jace.cheat;
import jace.apple2e.MOS65C02; import jace.apple2e.MOS65C02;
import jace.apple2e.SoftSwitches;
import jace.core.Computer; import jace.core.Computer;
import jace.core.Device; import jace.core.Device;
import jace.core.RAMEvent; import jace.core.RAMEvent;
@ -42,40 +41,32 @@ public abstract class Cheats extends Device {
} }
public void bypassCode(int address, int addressEnd) { public void bypassCode(int address, int addressEnd) {
addCheat(RAMEvent.TYPE.READ, address, addressEnd, (e) -> { int noOperation = MOS65C02.COMMAND.NOP.ordinal();
e.setNewValue(MOS65C02.COMMAND.NOP.ordinal()); addCheat(RAMEvent.TYPE.READ, (e) -> {e.setNewValue(noOperation);}, address, addressEnd);
});
} }
public void forceValue(int address, int value) { public void forceValue(int value, int... address) {
addCheat(RAMEvent.TYPE.READ, address, (e) -> { addCheat(RAMEvent.TYPE.READ, (e) -> {e.setNewValue(value);}, address);
e.setNewValue(value);
});
} }
public void forceValue(int address, boolean auxFlag, int value) { public void forceValue(int value, boolean auxFlag, int... address) {
addCheat(RAMEvent.TYPE.READ, address, (e) -> { addCheat(RAMEvent.TYPE.READ, auxFlag, (e) -> {e.setNewValue(value);}, address);
if (address < 0x0100) {
if (SoftSwitches.AUXZP.getState() != auxFlag) {
return;
}
} else {
if (SoftSwitches.RAMRD.getState() != auxFlag) {
return;
}
}
e.setNewValue(value);
});
} }
public void addCheat(RAMEvent.TYPE type, int address, RAMEvent.RAMEventHandler handler) { public void addCheat(RAMEvent.TYPE type, RAMEvent.RAMEventHandler handler, int... address) {
RAMListener l = computer.getMemory().observe(type, address, handler); if (address.length == 1) {
listeners.add(l); listeners.add(computer.getMemory().observe(type, address[0], handler));
} else {
listeners.add(computer.getMemory().observe(type, address[0], address[1], handler));
}
} }
public void addCheat(RAMEvent.TYPE type, int addressStart, int addressEnd, RAMEvent.RAMEventHandler handler) { public void addCheat(RAMEvent.TYPE type, boolean auxFlag, RAMEvent.RAMEventHandler handler, int... address) {
RAMListener l = computer.getMemory().observe(type, addressStart, addressEnd, handler); if (address.length == 1) {
listeners.add(l); listeners.add(computer.getMemory().observe(type, address[0], auxFlag, handler));
} else {
listeners.add(computer.getMemory().observe(type, address[0], address[1], auxFlag, handler));
}
} }
@Override @Override

View File

@ -1,7 +1,6 @@
package jace.cheat; package jace.cheat;
import jace.EmulatorUILogic; import jace.EmulatorUILogic;
import jace.apple2e.MOS65C02;
import jace.config.ConfigurableField; import jace.config.ConfigurableField;
import jace.core.Computer; import jace.core.Computer;
import jace.core.RAMEvent; import jace.core.RAMEvent;
@ -65,17 +64,17 @@ public class MontezumasRevengeCheats extends Cheats {
@Override @Override
void registerListeners() { void registerListeners() {
if (repulsiveHack) { if (repulsiveHack) {
addCheat(RAMEvent.TYPE.WRITE, 0x1508, 0x1518, this::repulsiveBehavior); addCheat(RAMEvent.TYPE.WRITE, this::repulsiveBehavior, 0x1508, 0x1518);
} }
if (featherFall) { if (featherFall) {
addCheat(RAMEvent.TYPE.WRITE, PLAYER_Y, this::featherFallBehavior); addCheat(RAMEvent.TYPE.WRITE, this::featherFallBehavior, PLAYER_Y);
// Bypass the part that realizes you should die when you hit the floor // Bypass the part that realizes you should die when you hit the floor
bypassCode(0x6bb3, 0x6bb4); bypassCode(0x6bb3, 0x6bb4);
} }
if (moonJump) { if (moonJump) {
addCheat(RAMEvent.TYPE.WRITE, Y_VELOCITY, this::moonJumpBehavior); addCheat(RAMEvent.TYPE.WRITE, this::moonJumpBehavior, Y_VELOCITY);
} }
if (infiniteLives) { if (infiniteLives) {
@ -84,9 +83,9 @@ public class MontezumasRevengeCheats extends Cheats {
if (scoreHack) { if (scoreHack) {
// Score: 900913 // Score: 900913
forceValue(SCORE, 0x90); forceValue(0x90, SCORE);
forceValue(SCORE + 1, 0x09); forceValue(0x09, SCORE + 1);
forceValue(SCORE + 2, 0x13); forceValue(0x13, SCORE + 2);
} }
if (snakeCharmer) { if (snakeCharmer) {

View File

@ -173,19 +173,19 @@ public class PrinceOfPersiaCheats extends Cheats {
@Override @Override
public void registerListeners() { public void registerListeners() {
if (velocityHack) { if (velocityHack) {
addCheat(RAMEvent.TYPE.READ_DATA, CharYVel, this::velocityHackBehavior); addCheat(RAMEvent.TYPE.READ_DATA, true, this::velocityHackBehavior, CharYVel);
} }
if (invincibilityHack) { if (invincibilityHack) {
forceValue(KidStrength, true, 3); forceValue(3, true, KidStrength);
} }
if (sleepHack) { if (sleepHack) {
forceValue(EnemyAlert, true, 0); forceValue(0, true, EnemyAlert);
} }
if (swordHack) { if (swordHack) {
forceValue(hasSword, true, 1); forceValue(1, true, hasSword);
} }
if (timeHack) { if (timeHack) {
forceValue(MinLeft, true, 0x069); forceValue(0x69, true, MinLeft);
} }
if (mouseHack) { if (mouseHack) {
EmulatorUILogic.addMouseListener(listener); EmulatorUILogic.addMouseListener(listener);
@ -201,15 +201,12 @@ public class PrinceOfPersiaCheats extends Cheats {
} }
public static int BlueType = 0x0b700; public static int BlueType = 0x0b700;
private void velocityHackBehavior(RAMEvent e) { private void velocityHackBehavior(RAMEvent velocityChangeEvent) {
if (!SoftSwitches.AUXZP.getState()) { int newVel = velocityChangeEvent.getNewValue();
return;
}
int newVel = e.getNewValue();
if (newVel > 5) { if (newVel > 5) {
newVel = 1; newVel = 1;
} }
e.setNewValue(newVel & 0x0ff); velocityChangeEvent.setNewValue(newVel & 0x0ff);
} }
public void mouseClicked(MouseButton button) { public void mouseClicked(MouseButton button) {

View File

@ -34,6 +34,7 @@ import java.util.Optional;
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com * @author Brendan Robert (BLuRry) brendan.robert@gmail.com
*/ */
public abstract class RAM implements Reconfigurable { public abstract class RAM implements Reconfigurable {
public PagedMemory activeRead; public PagedMemory activeRead;
public PagedMemory activeWrite; public PagedMemory activeWrite;
public List<RAMListener> listeners; public List<RAMListener> listeners;
@ -46,13 +47,14 @@ public abstract class RAM implements Reconfigurable {
/** /**
* Creates a new instance of RAM * Creates a new instance of RAM
*
* @param computer * @param computer
*/ */
public RAM(Computer computer) { public RAM(Computer computer) {
this.computer = computer; this.computer = computer;
listeners = new ArrayList<>(); listeners = new ArrayList<>();
cards = new Optional[8]; cards = new Optional[8];
for (int i=0; i < 8; i ++) { for (int i = 0; i < 8; i++) {
cards[i] = Optional.empty(); cards[i] = Optional.empty();
} }
refreshListenerMap(); refreshListenerMap();
@ -217,6 +219,22 @@ public abstract class RAM implements Reconfigurable {
}); });
} }
public RAMListener observe(RAMEvent.TYPE type, int address, boolean auxFlag, RAMEvent.RAMEventHandler handler) {
return addListener(new RAMListener(type, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY) {
@Override
protected void doConfig() {
setScopeStart(address);
}
@Override
protected void doEvent(RAMEvent e) {
if (isAuxFlagCorrect(e, auxFlag)) {
handler.handleEvent(e);
}
}
});
}
public RAMListener observe(RAMEvent.TYPE type, int addressStart, int addressEnd, RAMEvent.RAMEventHandler handler) { public RAMListener observe(RAMEvent.TYPE type, int addressStart, int addressEnd, RAMEvent.RAMEventHandler handler) {
return addListener(new RAMListener(type, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY) { return addListener(new RAMListener(type, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY) {
@Override @Override
@ -232,6 +250,34 @@ public abstract class RAM implements Reconfigurable {
}); });
} }
public RAMListener observe(RAMEvent.TYPE type, int addressStart, int addressEnd, boolean auxFlag, RAMEvent.RAMEventHandler handler) {
return addListener(new RAMListener(type, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY) {
@Override
protected void doConfig() {
setScopeStart(addressStart);
setScopeEnd(addressEnd);
}
@Override
protected void doEvent(RAMEvent e) {
if (isAuxFlagCorrect(e, auxFlag)) {
handler.handleEvent(e);
}
}
});
}
private boolean isAuxFlagCorrect(RAMEvent e, boolean auxFlag) {
if (e.getAddress() < 0x0100) {
if (SoftSwitches.AUXZP.getState() != auxFlag) {
return false;
}
} else if (SoftSwitches.RAMRD.getState() != auxFlag) {
return false;
}
return true;
}
public RAMListener addListener(final RAMListener l) { public RAMListener addListener(final RAMListener l) {
boolean restart = computer.pause(); boolean restart = computer.pause();
if (listeners.contains(l)) { if (listeners.contains(l)) {
@ -323,5 +369,6 @@ public abstract class RAM implements Reconfigurable {
} }
abstract public void attach(); abstract public void attach();
abstract public void detach(); abstract public void detach();
} }