mirror of
https://github.com/badvision/jace.git
synced 2024-11-05 11:04:51 +00:00
Cheat load/save now works
This commit is contained in:
parent
8ff0987801
commit
0b68cc4a73
@ -28,7 +28,7 @@ public class DynamicCheat extends RAMListener {
|
||||
id = (int) (Math.random() * 10000000);
|
||||
addr = new SimpleIntegerProperty(address);
|
||||
expression = new SimpleStringProperty(expr);
|
||||
active = new SimpleBooleanProperty(true);
|
||||
active = new SimpleBooleanProperty(false);
|
||||
name = new SimpleStringProperty("Untitled");
|
||||
expression.addListener((param, oldValue, newValue) -> {
|
||||
expressionCallback = parseExpression(newValue);
|
||||
@ -95,5 +95,30 @@ public class DynamicCheat extends RAMListener {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String escape(String in) {
|
||||
return in.replaceAll(";", "~~").replaceAll("\n","\\n");
|
||||
}
|
||||
|
||||
public static String unescape(String in) {
|
||||
return in.replaceAll("~~", ";").replaceAll("\\n", "\n");
|
||||
}
|
||||
|
||||
public static final String DELIMITER = ";";
|
||||
public String serialize() {
|
||||
return escape(name.get()) + DELIMITER
|
||||
+ escape("$"+Integer.toHexString(addr.get())) + DELIMITER
|
||||
+ escape(expression.get());
|
||||
}
|
||||
|
||||
static public DynamicCheat deserialize(String in) {
|
||||
String[] parts = in.split(DELIMITER);
|
||||
String name = unescape(parts[0]);
|
||||
Integer addr = Integer.parseInt(parts[1].substring(1), 16);
|
||||
String expr = unescape(parts[2]);
|
||||
|
||||
DynamicCheat out = new DynamicCheat(addr, expr);
|
||||
out.name.set(name);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,15 @@ import jace.core.RAMEvent;
|
||||
import jace.core.RAMListener;
|
||||
import jace.state.State;
|
||||
import jace.ui.MetacheatUI;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
@ -128,7 +135,6 @@ public class MetaCheat extends Cheats {
|
||||
}
|
||||
|
||||
public void addCheat(DynamicCheat cheat) {
|
||||
cheat.activeProperty().set(true);
|
||||
cheatList.add(cheat);
|
||||
computer.getMemory().addListener(cheat);
|
||||
cheat.addressProperty().addListener((prop, oldVal, newVal) -> {
|
||||
@ -137,7 +143,7 @@ public class MetaCheat extends Cheats {
|
||||
computer.getMemory().addListener(cheat);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void removeCheat(DynamicCheat cheat) {
|
||||
cheat.active.set(false);
|
||||
computer.getMemory().removeListener(cheat);
|
||||
@ -347,4 +353,46 @@ public class MetaCheat extends Cheats {
|
||||
cell.value.set(e.getNewValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void saveCheats(File saveFile) {
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
writer = new FileWriter(saveFile);
|
||||
for (DynamicCheat cheat : cheatList) {
|
||||
writer.write(cheat.serialize());
|
||||
writer.write("\n");
|
||||
}
|
||||
writer.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MetaCheat.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MetaCheat.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCheats(File saveFile) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(saveFile));
|
||||
StringBuilder guts = new StringBuilder();
|
||||
String line;
|
||||
while ((line=in.readLine()) != null) {
|
||||
DynamicCheat cheat = DynamicCheat.deserialize(line);
|
||||
addCheat(cheat);
|
||||
}
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MetaCheat.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MetaCheat.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import jace.cheat.MetaCheat;
|
||||
import jace.cheat.MetaCheat.SearchChangeType;
|
||||
import jace.cheat.MetaCheat.SearchResult;
|
||||
import jace.cheat.MetaCheat.SearchType;
|
||||
import jace.core.RAMListener;
|
||||
import jace.state.State;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
@ -46,6 +46,7 @@ import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.TilePane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.util.converter.DefaultStringConverter;
|
||||
import javafx.util.converter.IntegerStringConverter;
|
||||
|
||||
@ -153,12 +154,24 @@ public class MetacheatUI {
|
||||
|
||||
@FXML
|
||||
void loadCheats(ActionEvent event) {
|
||||
|
||||
FileChooser chooser = new FileChooser();
|
||||
chooser.setTitle("Load cheats");
|
||||
chooser.setInitialFileName("cheat.txt");
|
||||
File saveFile = chooser.showOpenDialog(null);
|
||||
if (saveFile != null) {
|
||||
cheatEngine.loadCheats(saveFile);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void saveCheats(ActionEvent event) {
|
||||
|
||||
FileChooser chooser = new FileChooser();
|
||||
chooser.setTitle("Save current cheats");
|
||||
chooser.setInitialFileName("cheat.txt");
|
||||
File saveFile = chooser.showSaveDialog(null);
|
||||
if (saveFile != null) {
|
||||
cheatEngine.saveCheats(saveFile);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
Loading…
Reference in New Issue
Block a user