Skip to content

Commit

Permalink
difficulty support
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-zerocool authored and boazy committed Aug 3, 2020
1 parent 45eb7b6 commit 668cd06
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 142 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The 'Inventory' tab allows you to modify Geralt's inventory.

The 'Quests' tab shows the game quests (Started, Completed, Failed and Not Started). The 'Examine' button will display a description of the current quest stage (if the stage has a description).

The 'Difficulty' tab allows you to modify difficulty level.

Installation
============
Expand Down Expand Up @@ -99,6 +100,10 @@ Version 2.1:
============
Support equipped items.

Version 2.2:
============
Difficulty support.

Version 3.0.1
=============
Provide a JAR and DMG file
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ plugins {
id 'edu.sc.seis.macAppBundle' version "2.3.0"
}

dependencies {
implementation 'com.google.guava:guava:29.0-jre'
}

mainClassName = "TWEditor.Main"
version = "3.0.1"

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/app/tweditor/DBList.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ public boolean addElement(DBElement element)
return true;
}

public boolean insertElement(int index,DBElement element) {
String label = element.getLabel();
if (label.length() == 0) {
this.elementList.add(index, element);
return true;
}

if (this.labelMap.get(label) != null) {
return false;
}
this.elementList.add(index, element);
this.labelMap.put(label, element);
return true;
}

public DBElement removeElement(int index)
{
DBElement element = (DBElement)this.elementList.get(index);
Expand Down
183 changes: 183 additions & 0 deletions src/main/java/app/tweditor/DifficultyPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package app.tweditor;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DifficultyPanel extends JPanel
implements ActionListener
{
private final String EASY = "Easy";
private final String MEDIUM = "Medium";
private final String HARD = "Hard";

private final String EASY_DIFF = "Difficulty_easy";
private final String MEDIUM_DIFF = "Difficulty_normal";

private final int EASY_INT = 0;
private final int MEDIUM_INT = 1;
private final int HARD_INT = 2;

private JRadioButton easyButton, mediumButton, hardButton;
private String level;

public DifficultyPanel()
{
easyButton = new JRadioButton(EASY);
easyButton.setActionCommand(EASY);
easyButton.addActionListener(this);

mediumButton = new JRadioButton(MEDIUM);
mediumButton.setActionCommand(MEDIUM);
mediumButton.addActionListener(this);

hardButton = new JRadioButton(HARD);
hardButton.setActionCommand(HARD);
hardButton.addActionListener(this);

ButtonGroup group = new ButtonGroup();
group.add(easyButton);
group.add(mediumButton);
group.add(hardButton);

JPanel panel = new JPanel(new GridLayout(0, 3, 5, 5));
panel.add(easyButton);
panel.add(mediumButton);
panel.add(hardButton);

panel.setBorder(BorderFactory.createTitledBorder("Level"));

add(panel);
}

private void processCharAbilities(DBList list, String cmd) {
try {
DBList abilityList = (DBList)list.getElement("CharAbilities").getValue();

if(level.equals(EASY) || level.equals(MEDIUM)) {
for (int i = 0; i < abilityList.getElementCount(); i++) {
DBList fieldList = (DBList)abilityList.getElement(i).getValue();

DBElement e = fieldList.getElement(0);
Object value = e.getValue();
if(value.equals(EASY_DIFF) || value.equals(MEDIUM_DIFF)) {
if(cmd.equals(EASY)) {
fieldList.setString("RnAbName", EASY_DIFF);
} else if(cmd.equals(MEDIUM)) {
fieldList.setString("RnAbName", MEDIUM_DIFF);
} else {
abilityList.removeElement(i);
}

break;
}
}
} else {
for (int i = 0; i < abilityList.getElementCount(); i++) {
DBList fieldList = (DBList)abilityList.getElement(i).getValue();

DBElement e = fieldList.getElement(0);
Object value = e.getValue();
if(value.equals("StyleSilverGroup1")) {
DBList levelList = new DBList(2);
if(cmd.equals(EASY)) {
levelList.addElement(new DBElement(10, 0, "RnAbName", EASY_DIFF));
} else if(cmd.equals(MEDIUM)) {
levelList.addElement(new DBElement(10, 0, "RnAbName", MEDIUM_DIFF));
}
levelList.addElement(new DBElement(0, 0, "RnAbStk", new Integer(0)));

abilityList.insertElement(i + 1, new DBElement(14, 48879, "", levelList));
break;
}
}
}

level = cmd;
Main.dataModified = true;
} catch (DBException exc) {
Main.logException("Unable to update database field", exc);
} catch (Throwable exc) {
Main.logException("Exception while processing action event", exc);
}
}

private void processGameDiffSetting(DBList list, String cmd) {
try {
if(cmd.equals(EASY)) {
list.setInteger("GameDiffSetting", EASY_INT);
} else if(cmd.equals(MEDIUM)) {
list.setInteger("GameDiffSetting", MEDIUM_INT);
} else {
list.setInteger("GameDiffSetting", HARD_INT);
}
} catch (DBException exc) {
Main.logException("Unable to update database field", exc);
} catch (Throwable exc) {
Main.logException("Exception while processing action event", exc);
}
}

public void actionPerformed(ActionEvent ae)
{
if ((!(ae.getSource() instanceof JRadioButton)) || (Main.dataChanging)) {
return;
}

String cmd = ae.getActionCommand();

if(cmd.equals(level)) {
return;
}

DBList top = (DBList)Main.database.getTopLevelStruct().getValue();
DBList mod = (DBList)top.getElement("Mod_PlayerList").getValue();
DBList modPlayerList = (DBList)mod.getElement(0).getValue();
processCharAbilities(modPlayerList, cmd);

DBList playerList = (DBList)Main.playerDatabase.getTopLevelStruct().getValue();
processCharAbilities(playerList, cmd);

DBList smm = (DBList)Main.smmDatabase.getTopLevelStruct().getValue();
processGameDiffSetting(smm, cmd);
}

private void print(DBElement e) {
System.out.println(e.getType() + " " + e.getLabel() + " " + e.getID());
}

public void setFields(DBList list)
throws DBException
{
level = HARD;
hardButton.setSelected(true);

DBElement element = list.getElement("CharAbilities");
if (element == null) {
throw new DBException("CharAbilities field not found");
}
DBList abilityList = (DBList)element.getValue();
for (int i = 0; i < abilityList.getElementCount(); i++) {
DBList fieldList = (DBList)abilityList.getElement(i).getValue();

DBElement e = fieldList.getElement(0);
Object value = e.getValue();
if(value.equals(EASY_DIFF)) {
level = EASY;
easyButton.setSelected(true);
break;
} else if(value.equals(MEDIUM_DIFF)) {
level = MEDIUM;
mediumButton.setSelected(true);
break;
}
}
}

public void getFields(DBList list)
throws DBException
{
}
}

61 changes: 48 additions & 13 deletions src/main/java/app/tweditor/LoadFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.util.ArrayList;
import javax.swing.SwingUtilities;

Expand Down Expand Up @@ -35,19 +36,30 @@ public void run()
if ((sep != 6) || (!Character.isDigit(saveName.charAt(0)))) {
throw new DBException("Save name is not formatted correctly");
}
String fileName = "save_" + saveName.substring(0, 6) + ".smm";
SaveEntry saveEntry = saveDatabase.getEntry(fileName);
Main.smmName = "save_" + saveName.substring(0, 6) + ".smm";
SaveEntry saveEntry = saveDatabase.getEntry(Main.smmName);
if (saveEntry == null) {
throw new DBException("Save does not contain " + fileName);
throw new DBException("Save does not contain " + Main.smmName);
}
in = saveEntry.getInputStream();
Database database = new Database();
database.load(in);
if (Main.smmFile.exists()) {
Main.smmFile.delete();
}
byte[] buffer = new byte[4096];
out = new FileOutputStream(Main.smmFile);
int count;
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
in.close();
in = null;
out.close();
out = null;
Database smmDatabase = new Database(Main.smmFile);
smmDatabase.load();
this.progressDialog.updateProgress(35);

DBList list = (DBList)database.getTopLevelStruct().getValue();
DBList list = (DBList)smmDatabase.getTopLevelStruct().getValue();
String startingMod = list.getString("StartingMod");
if (startingMod.length() == 0) {
throw new DBException("StartingMod not found in SMM database");
Expand Down Expand Up @@ -76,9 +88,8 @@ public void run()
Main.modFile.delete();
}

byte[] buffer = new byte[4096];
buffer = new byte[4096];
out = new FileOutputStream(Main.modFile);
int count;
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
Expand Down Expand Up @@ -110,7 +121,7 @@ public void run()
out = null;
this.progressDialog.updateProgress(75);

database = new Database(Main.databaseFile);
Database database = new Database(Main.databaseFile);
database.load();
list = (DBList)database.getTopLevelStruct().getValue();
element = list.getElement("Mod_PlayerList");
Expand All @@ -123,7 +134,7 @@ public void run()
}
this.progressDialog.updateProgress(80);

fileName = questDBName + ".qdb";
String fileName = questDBName + ".qdb";
saveEntry = saveDatabase.getEntry(fileName);
if (saveEntry == null) {
throw new DBException("Save does not contain " + fileName);
Expand Down Expand Up @@ -161,11 +172,35 @@ public void run()
Main.quests.add(quest);
}
}

Main.playerName = "player.utc";
saveEntry = saveDatabase.getEntry(Main.playerName);
if (saveEntry == null) {
throw new DBException("Save does not contain " + Main.playerName);
}
in = saveEntry.getInputStream();
if (Main.playerFile.exists()) {
Main.playerFile.delete();
}
out = new FileOutputStream(Main.playerFile);
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
in.close();
in = null;
out.close();
out = null;

Database playerDatabase = new Database(Main.playerFile);
playerDatabase.load();

this.progressDialog.updateProgress(100);

Main.saveDatabase = saveDatabase;
Main.modDatabase = modDatabase;
Main.database = database;
Main.saveDatabase = saveDatabase; //.TheWitcherSave
Main.modDatabase = modDatabase; //.sav
Main.database = database; //.sav -> 'module.ifo'
Main.playerDatabase = playerDatabase; //player.utc
Main.smmDatabase = smmDatabase; //.smm
this.loadSuccessful = true;
} catch (DBException exc) {
Main.logException("Save file structure is not valid", exc);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/app/tweditor/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class Main
public static File modFile;
public static ResourceDatabase modDatabase;
public static List<Quest> quests;
public static String playerName;
public static File playerFile;
public static Database playerDatabase;
public static String smmName;
public static File smmFile;
public static Database smmDatabase;
public static boolean dataModified = false;

public static boolean dataChanging = false;
Expand All @@ -63,8 +69,10 @@ public static void main(String[] args)
tmpDir = tmpDir + "/";
}

smmFile = new File(new StringBuilder().append(tmpDir).append("TWEditor.smm").toString());
databaseFile = new File(new StringBuilder().append(tmpDir).append("TWEditor.ifo").toString());
modFile = new File(new StringBuilder().append(tmpDir).append("TWEditor.mod").toString());
playerFile = new File(new StringBuilder().append(tmpDir).append("TWEditor.player").toString());

String option = System.getProperty("UseShellFolder");
if ((option != null) && (option.equals("0"))) {
Expand Down
Loading

0 comments on commit 668cd06

Please sign in to comment.