diff options
author | metaphysicsIO <103212704+metaphysicsIO@users.noreply.github.com> | 2023-12-05 13:41:23 -0600 |
---|---|---|
committer | metaphysicsIO <103212704+metaphysicsIO@users.noreply.github.com> | 2023-12-05 13:41:23 -0600 |
commit | 211369a126af84b5771e346ca5a3811a053ed172 (patch) | |
tree | c7c8007f2392adaa3fbfc158856a09ef958f38d4 | |
parent | a1f7155a1ea42fd7afa1c1546d11a6412dbd06bd (diff) | |
download | PSE-211369a126af84b5771e346ca5a3811a053ed172.tar.gz |
Can now edit the party, loops properly, makes edits to player, rival, money, and party.
-rw-r--r-- | Database.cpp | 88 | ||||
-rw-r--r-- | PartyEdit.cpp | 70 | ||||
-rw-r--r-- | Pokemon - Red Version (USA, Europe) (SGB Enhanced).sav | bin | 0 -> 32768 bytes | |||
-rwxr-xr-x | SE.o | bin | 132272 -> 132376 bytes | |||
-rw-r--r-- | SavEdit.h | 2 | ||||
-rw-r--r-- | UserOptions.cpp | 28 | ||||
-rwxr-xr-x | a.out | bin | 0 -> 23960 bytes | |||
-rw-r--r-- | database.py | 102 | ||||
-rw-r--r-- | main.cpp | 42 |
9 files changed, 242 insertions, 90 deletions
diff --git a/Database.cpp b/Database.cpp new file mode 100644 index 0000000..baeb5e6 --- /dev/null +++ b/Database.cpp @@ -0,0 +1,88 @@ +/* Programmer's name: Ashton + * Contact info: [HIDDEN] + * Date Created: Nov 20, 2023 + * Version: 1.0.0 + * Purpose: Handles the python-C++ connection + * Issues: None noticed at the moment + * + */ +#include <iostream> +#include <cstdlib> +#include <cstring> + +void Create(std::string hex, std::string val) +{ + /* + * Calls the python file to insert the given values into the MySQL + * database. + */ + std::string cmd = "python database.py CREATE "; + cmd += hex; + cmd += " "; + cmd += val; + + system(cmd.c_str()); +} + +void Read(std::string col, std::string val) +{ + /* + * Find and print out searched val in a given col. + */ + std::string cmd = "python database.py READ "; + cmd += col; + cmd += " "; + cmd += val; + + system(cmd.c_str()); +} + +void Update(std::string u_col, std::string u_val, std::string u_loc, std::string u_loc_val) +{ + /* + * Update column (u_col) with new value (u_val) at a given location (u_loc) + * that contains the value u_loc_val. + */ + std::string cmd = "python database.py UPDATE "; + cmd += u_col; + cmd += " "; + cmd += u_val; + cmd += " "; + cmd += u_loc; + cmd += " "; + cmd += u_loc_val; + + system(cmd.c_str()); +} + +void Delete(std::string col, std::string val) +{ + /* + * Deletes an entry with a given value at a given column. + */ + std::string cmd = "python database.py DELETE "; + cmd += col; + cmd += " "; + cmd += val; + + system(cmd.c_str()); +} + + +int main() +{ + /* + * This is a test file, I will connect it to the program later, + * but for now it's just going to be it's own separate file. + */ + + // Tested each of the below. It works fine. + //Create("95", "Alakazam"); + //Read("hex", "95"); + //Update("name", "alakazam", "hex", "95"); + //Delete("hex", "95"); + + // TODO: I should probably put Read into a variable. + + return 0; +} diff --git a/PartyEdit.cpp b/PartyEdit.cpp index 16b4a29..e635ef2 100644 --- a/PartyEdit.cpp +++ b/PartyEdit.cpp @@ -1,3 +1,11 @@ +/* Programmer's name: Ashton + * Contact info: [HIDDEN] + * Date Created: Nov 18, 2023 + * Version: 1.0.0 + * Purpose: Edit the user's party and their individual attributes. + * Issues: None noticed at the moment. + */ + #include <iostream> #include <cstring> #include <iomanip> @@ -6,38 +14,6 @@ #include "SavEdit.h" -/* - * NOTES FOR MYSELF: DELETE LATER. - * - * Noticed a big difference between Party 1 and Party 2 ID when compared - * to their respective attributes. - * - * The range between Party #2's ID and MOVE 1 is 3A. - * The range between Party #1's ID and MOVE 1 is F. - * - * That is 2B, or 43 spaces between them. - * - * There is also a possibly 2nd ID for P#2 at 0x2F4C - * which would come out to 1C. I suspect this isn't correc.t - * - * But I may have solved it - * - * Let's see the difference between P1.ATK, P2.ATK and P1.DEF, P2.DEF: - * P1.ATK - P2.ATK is |0x2f59 - 0x2F85| = 2C (44) - * P1.DEF - P2.DEF is |0x2F5B - 0x2F87| = 2C (44) - * - * So for stats, we can simply add 44(n) where n is the party #-1. - * What about for moves? - * - * P1.MOVE1 - P2.MOVE1 is |0x2F3C - 0x2F68| = 2C (44) - * - * This is fine. This means the identification change will be - * 0x2F2C + n, where n is the party number and the stats will - * be changed with the memory offset + 44(n-1), where n is the party number. - * - * - */ - void SavEdit::pkmnMap() { /* @@ -349,12 +325,32 @@ int SavEdit::selectStat() std::cout << "Try again." << std::endl; break; } - + // clear buf + std::cin.clear(); + std::cin.ignore(); } return stat_val_offset; } +void SavEdit::printParty() +{ + /* + * Iterates through current party. + */ + for(int i = 0; i < 6; ++i) + { + std::stringstream mem_to_hex; + mem_to_hex << std::hex << mem.at(0x2F2C + (i + 1) + 0x01); + std::string char_loc(mem_to_hex.str()); + std::cout << i + 1 << ": " << pkmn[char_loc] << std::endl; + //std::cout << i + 1 << ": " << mem.at(0x2F2C + (i+1) + 0x01) << std::endl; + //std::string party_mem = mem.at(0x2F2C + (i+1)); + //std::string party_name = mem.at(party_mem + 0x01); // Name offset. + //std::cout << i+1 << ": " << party_name << std::endl; + } +} + void SavEdit::modMainMenu() { /* @@ -369,7 +365,9 @@ void SavEdit::modMainMenu() // Create the pkmn name map pkmnMap(); - //TODO: Display party list + stats + // Print a list of party members for the user to edit + printParty(); + std::cout << "Select party member: " << std::endl; @@ -390,7 +388,7 @@ void SavEdit::modMainMenu() // First we need to convert deci -> hex before searching. std::stringstream mem_to_hex; // The addr has to be hard coded. - mem_to_hex << std::hex << mem.at(0x2F2C + (party_member +0x01)); + mem_to_hex << std::hex << mem.at(0x2F2C + (party_member + 0x01)); // Convert to a string. std::string char_loc(mem_to_hex.str()); std::cout << "[EDITING: " << pkmn[char_loc] << "]" << std::endl; @@ -416,7 +414,7 @@ void SavEdit::modMainMenu() }else if (stat_val_offset == 0x01){ // The only value not in the +44(n-1), where n is party pos, block is // the pkmn id. - party_member_offset = party_member; + party_member_offset = party_member+1; printPkmnlist(); // Pokemon list requires hex. std::cin >> std::hex >> state_value; diff --git a/Pokemon - Red Version (USA, Europe) (SGB Enhanced).sav b/Pokemon - Red Version (USA, Europe) (SGB Enhanced).sav Binary files differBinary files differnew file mode 100644 index 0000000..8d29567 --- /dev/null +++ b/Pokemon - Red Version (USA, Europe) (SGB Enhanced).sav @@ -35,7 +35,7 @@ class SavEdit int selectStat(); void modMainMenu(); void modStats(int, int, int); - + void printParty(); private: std::string filename; std::vector<int> mem; diff --git a/UserOptions.cpp b/UserOptions.cpp index c86beb5..67e9613 100644 --- a/UserOptions.cpp +++ b/UserOptions.cpp @@ -29,7 +29,6 @@ void SavEdit::modify(const int BEGIN, const int END) // Prevent the user from breaking limits. while(!correct) { - // TODO: Clear / Redraw screen std::cout << "input: "; std::cin >> s; @@ -114,11 +113,12 @@ bool SavEdit::select() { /* * A giant switch for determining which offsets to edit. - * - * TODO: May want to break this down into something else. */ - // For the loop. I might not keep it like this. + // Make room. + clear(); + + // For the loop. bool finished = false; // Check for correct input. @@ -131,15 +131,12 @@ bool SavEdit::select() // Check if supported. while(!correct) { - // TODO: translate + create subroutine - // TODO: Clear / Redraw Screen - // TODO: Create a better menu + // TODO: Add party edit option std::cout << "EDIT: " << std::endl; - std::cout << "\t1. Player Name" << std::endl; + std::cout << "\t1. PLAYER Name" << std::endl; std::cout << "\t2. RIVAL Name" << std::endl; std::cout << "\t3. MONEY" << std::endl; - //std::cout << "\t4. QUIT, DO NOT SAVE" << std::endl; - std::cout << "\t4. EDIT ITEM #0." << std::endl; + std::cout << "\t4. PARTY." << std::endl; std::cout << "\t0. SAVE AND QUIT" << std::endl; std::cout << "YOUR INPUT: "; @@ -155,8 +152,6 @@ bool SavEdit::select() } - // TODO: Allow for custom edits? - switch(selection) { case 0: @@ -175,16 +170,11 @@ bool SavEdit::select() break; case 3: std::cout << "EDITING MONEY:" << std::endl; - //std::cout << "SETTING TO 999,999 POKEDOLLARS." << std::endl; - //mem.at(0x25F3) = 99; - //mem.at(0x25F4) = 99; - //mem.at(0x25F5) = 99; cashModify(); - //modify(0x25F3, 0x25F5); break; case 4: - std::cout << "Quitting without saving." << std::endl; - finished = true; + std::cout << "EDITING PARTY:" << std::endl; + modMainMenu(); break; default: std::cout << "NOT AN OPTION" << std::endl; Binary files differdiff --git a/database.py b/database.py new file mode 100644 index 0000000..847b617 --- /dev/null +++ b/database.py @@ -0,0 +1,102 @@ +''' +Programmer's Name: Ashton +Contact info: [HIDDEN] +Date Created: Nov 20, 2023 +Version: 1.0.0 +Purpose: CRUD for editing the database. +ISSUES: None noticed at the moment. +''' +import mysql.connector +import sys + +# CHANGE AS NEEDED +HOST="localhost" +USER="root" +PASSWD="" +DATABASE="pokemon" +TABLE = "pkmn" + +# This connects to the database +database = mysql.connector.connect(host=HOST,user=USER,password=PASSWD,database=DATABASE) +selection = database.cursor() + + + +# Populate the database +def mk(): + ''' + Creates the database and table. + ''' + selection.execute("CREATE DATABASE pokemon") + selection.execute("CREATE TABLE pkmn (hex VARCHAR(2), name VARCHAR(255))") + +# CREATE +def CREATE(one, two, val_one, val_two): + ''' + This creates an entry, inserting it into the given table using the + column names (one, two) and the values (val_one, val_two). + ''' + command = "INSERT INTO " + TABLE + " (" + one + "," + two + ") VALUES (%s, %s)" + values = (val_one, val_two) + selection.execute(command, values) + database.commit() + print(selection.rowcount,"record inserted.") + exit + +# READ +def READ(column, val): + ''' + Finds all entries of a given value from a given colum. + ''' + command = "SELECT * FROM " + TABLE + " WHERE " + column + " = '" + val + "'" + selection.execute(command) + results = selection.fetchall() + for x in results: + print(x) + exit + +# UPDATE +def UPDATE(fix_col, fix_val, location, val): + ''' + Corrects an entry from at a given value with a given coumn + ''' + command = "UPDATE " + TABLE + " SET " + fix_col + " = '" + fix_val + "' WHERE " + location + " = '" + val + "'" + selection.execute(command) + database.commit() + print(selection.rowcount, "record(s) modified.") + exit + +# DELETE +def DELETE(column, val): + ''' + Removes an entry based on the given column and respective value. + ''' + command = "DELETE FROM " + TABLE + " WHERE " + column + " = '" + val + "'" + selection.execute(command) + database.commit() + print(selection.rowcount, "record(s) deleted.") + exit + +if sys.argv[1] == "CREATE": + user_hex = sys.argv[2] + user_name = sys.argv[3] + CREATE("hex", "name", user_hex, user_name) + +if sys.argv[1] == "READ": + user_col = sys.argv[2] + user_val = sys.argv[3] + READ(user_col, user_val) + +if sys.argv[1] == "UPDATE": + user_col = sys.argv[2] + user_val = sys.argv[3] + user_loc = sys.argv[4] + user_loc_val = sys.argv[5] + UPDATE(user_col, user_val, user_loc, user_loc_val) + +if sys.argv[1] == "DELETE": + user_col = sys.argv[2] + user_val = sys.argv[3] + DELETE(user_col, user_val) + + @@ -4,6 +4,9 @@ int main(int argc, char *argv[]) { + // boolean for keeping the main loop going + bool done = false; + // Create obj SavEdit save; @@ -13,49 +16,20 @@ int main(int argc, char *argv[]) save.setFilename(argv[1]); } - - // Select language. - //save.languageForm(); - - // Send greeting. - //save.greeting(); - - // store file in vector + // Open the file save.open(); - // print vector - //save.read(); - - // create the backup + // Create the backup save.backup(); - // Test OT - //save.modify(0x2598, 0x259E); - - // TEST OPTIONS - bool done = true; //false; + // Start the main loop. while(!done) done = save.select(); - // To make things faster. - //save.debug(); - - // testing modStats - //save.modStats(); - save.modMainMenu(); - std::cout << "stats modified." << std::endl; - - // Print testing - //save.printPkmnlist(); - //save.printMovelist(); - - // Test the rival. - //save.modify(0x25F6, 0x25FC); - - // Update the checksum. + // Update the checksum save.checksum(); - // Save the new file + // Save and close the file. save.saveNewFile(); return 0; |