Compare commits

..

141 Commits

Author SHA1 Message Date
Martin Michelsen e27426dc16 delete unverified BB HTML drop tables
Docker / Build (push) Has been cancelled
2025-03-09 20:40:07 -07:00
Martin Michelsen 4cf650fb98 fix team member remove bug 2025-03-09 17:36:08 -07:00
Martin Michelsen 3857cda4e5 fix team member count updates 2025-03-09 16:11:34 -07:00
Martin Michelsen 99ebf96cb0 fix allowed version flags on Ep2 BB games; closes #619 2025-03-09 16:11:09 -07:00
Martin Michelsen 311af36632 add HTML drop tables 2025-03-09 00:55:32 -08:00
Martin Michelsen cf46a2cfc1 make salvage-gci --round2 21000x faster 2025-03-08 23:44:57 -08:00
Martin Michelsen 002a504418 describe a few more object params 2025-03-08 23:44:57 -08:00
Martin Michelsen ff9ff218bb fix help text 2025-03-08 23:04:48 -08:00
Martin Michelsen 5f838815ab fix team membership struct 2025-03-08 23:04:48 -08:00
Martin Michelsen c7d606247f describe some more object types 2025-03-05 22:37:50 -08:00
Martin Michelsen 546e8a3801 gcc should be able to handle this 2025-03-01 20:02:39 -08:00
Martin Michelsen f53604f49c start documenting map object types 2025-03-01 19:50:36 -08:00
Martin Michelsen 84c62b33a4 update comments on 6x93 and 6xB2 2025-03-01 19:50:36 -08:00
Martin Michelsen ddc52c06ae fix $where in the lobby 2025-03-01 19:50:36 -08:00
Martin Michelsen d02a3d7d64 add extract-ppk action 2025-03-01 19:50:36 -08:00
Martin Michelsen 21a0efa8ac update comment on get_random quest opcode 2025-03-01 19:50:36 -08:00
Martin Michelsen 4d7a3395ba refine quest header format; use metadata from .bin.txt file if present 2025-03-01 19:50:36 -08:00
Martin Michelsen 78fe4ebf98 refine 24 and 25 command structs 2025-02-27 23:14:46 -08:00
Martin Michelsen c596a18b3a support .include in quest scripts 2025-02-26 21:01:55 -08:00
Martin Michelsen f3b547f93c fix v1 itemrt conversion 2025-02-25 14:51:52 -08:00
Martin Michelsen ef53a3b269 fix signed comparison 2025-02-24 10:20:20 -08:00
Martin Michelsen 4f364f56d0 update html rare table generator 2025-02-24 10:14:37 -08:00
Martin Michelsen 4e77ff7ab1 add --decompress option in decode-qst 2025-02-24 10:14:15 -08:00
Martin Michelsen 81ad01891a update version code notes 2025-02-24 10:13:33 -08:00
Martin Michelsen 03d303b2bb add encode/decode options for bitmap fonts 2025-02-23 17:05:16 -08:00
Martin Michelsen 52bca977c3 fix enemy type conditions to match what the client does 2025-02-23 11:24:43 -08:00
Martin Michelsen f9cac45996 allow including shared files via .include_native 2025-02-23 11:20:55 -08:00
Martin Michelsen 04dbcef2cf recompile extended item info AR code for v1.2 2025-02-22 20:53:08 -08:00
Martin Michelsen 66e00d5136 add $nativecall command 2025-02-22 20:52:47 -08:00
Martin Michelsen 11d539042c fix ExtendedItemInfo patch and add AR code 2025-02-22 17:18:30 -08:00
Martin Michelsen 104e31028b fix incorrect box drop areas in rare tables 2025-02-22 16:50:18 -08:00
Martin Michelsen fa22c3563d add HTML rare table generator 2025-02-22 14:01:33 -08:00
Martin Michelsen 2cd4e5cf27 add file caches in non-server ServerState constructor 2025-02-20 22:31:39 -08:00
Martin Michelsen d9744a696e implement item translation table 2025-02-20 22:31:26 -08:00
Martin Michelsen 813bd2e0fa fix definition of give_s_rank_weapon opcode 2025-02-20 21:29:57 -08:00
Martin Michelsen 2d42d1ce07 update some item-related notes 2025-02-20 21:29:45 -08:00
Martin Michelsen 9001af38cd fix patch flags on BB 2025-02-20 21:29:02 -08:00
Martin Michelsen 67a56a369f fix corruption loader AR code 2025-02-17 23:16:18 -08:00
Martin Michelsen f4da9c8cb2 add enemy count generator 2025-02-17 19:34:36 -08:00
Martin Michelsen 963788af33 add enemy count computation in load-maps-test 2025-02-17 18:13:44 -08:00
Martin Michelsen d0e0e59762 add ReturnTokenX86 function 2025-02-17 10:36:53 -08:00
Martin Michelsen caf41c99de add stub for new address translator function 2025-02-17 00:19:03 -08:00
Martin Michelsen 9185dc0b62 fix overly long option names 2025-02-17 00:14:58 -08:00
Martin Michelsen 83990c6d5f construct supermaps on-demand instead of at startup 2025-02-17 00:14:58 -08:00
Martin Michelsen f53ca31b22 update 6x61 description 2025-02-17 00:14:58 -08:00
Martin Michelsen 44ea82771b update client functions for eventual pc v2 semantics 2025-02-17 00:14:58 -08:00
Martin Michelsen 984d8f0f31 update executable diff action 2025-02-17 00:14:58 -08:00
Martin Michelsen 7570c3ce34 add more ar codes 2025-02-17 00:14:58 -08:00
Martin Michelsen d24a535cd6 write 59NJ version of DisableIdleDisconnect patch 2025-02-17 00:14:58 -08:00
Martin Michelsen f2d36d589b add v1 ports of RaresInQuests patch 2025-02-17 00:14:58 -08:00
Martin Michelsen 2b31656661 update write opcode comments in QuestScript.cc 2025-02-17 00:14:54 -08:00
Martin Michelsen 6e8eecda8b document more of ItemMagEdit.prs format 2025-02-14 22:39:15 -08:00
Martin Michelsen 9ed01ede2d use mag evolution table for fixed-type cell evolution; fixes #608 2025-02-13 21:59:00 -08:00
Martin Michelsen 5ed2503491 fix ExtendedItemInfo in city 2025-02-13 21:00:34 -08:00
Martin Michelsen 2a34d64f00 add 2OJ5 version of RaresInQuests 2025-02-13 07:38:13 -08:00
Martin Michelsen fe4bd3d495 fix print-item-tables 2025-02-13 07:36:52 -08:00
Blst34 7ad5cbd28b Add files via upload 2025-02-13 07:36:36 -08:00
Martin Michelsen 775369345c use semantic hash index to fill in gaps in supermap 2025-02-11 09:37:53 -08:00
Martin Michelsen 17fe80cf85 abstract supermap construction across entity types 2025-02-10 22:44:13 -08:00
Martin Michelsen a3428d33ae update Ep3 Plus description 2025-02-09 23:32:37 -08:00
Martin Michelsen 4a1561ec55 add Ep3 Plus as a client function 2025-02-09 23:22:58 -08:00
Martin Michelsen 405399682f improve diff-dol-files 2025-02-09 23:08:16 -08:00
Martin Michelsen 01e6c5a8fb shorter version of ep3 chat filter code 2025-02-09 23:08:09 -08:00
Martin Michelsen 048b8ba09c fix mericarol type logic; closes #607 2025-02-09 10:40:57 -08:00
Martin Michelsen b451c82943 add GSL archive generation 2025-02-09 08:55:59 -08:00
Martin Michelsen 9d7c71fb26 rewrite common bank patch 2025-02-08 22:47:23 -08:00
Martin Michelsen 07c5a8a4b6 rewrite chat patch 2025-02-08 22:05:44 -08:00
Martin Michelsen 15f923a639 rewrite palette patch 2025-02-08 14:59:24 -08:00
Martin Michelsen 4c55551e12 fix 6xA4 and 6xA5 sizes; closes #605 2025-02-07 08:56:29 -08:00
Martin Michelsen 81d5b23d80 fix $next on proxy server 2025-02-06 22:59:52 -08:00
Martin Michelsen fa7c76b75b add more door types 2025-02-06 22:53:21 -08:00
Martin Michelsen 1a7f219158 write other versions of ExtendedItemInfo patch 2025-02-01 09:29:45 -08:00
Martin Michelsen 4b3bde01e4 add extended item info patch 2025-01-31 22:25:11 -08:00
Martin Michelsen a7fdfbf732 don't print supermap at lobby creation; closes #601 2025-01-31 21:53:43 -08:00
Martin Michelsen c0994b49e5 add change marker AR code 2025-01-31 21:51:17 -08:00
Martin Michelsen 03fc351a35 add 59NJ versions of some patches; closes #598 2025-01-29 23:20:51 -08:00
Martin Michelsen 24722f0a27 more patches 2025-01-28 23:26:12 -08:00
Martin Michelsen b7293e7cb0 write more patches 2025-01-27 23:29:07 -08:00
Martin Michelsen b5104a7bda document many unknown fields 2025-01-26 15:41:54 -08:00
Martin Michelsen 78b7bfac70 refine many subcommand formats 2025-01-26 09:47:19 -08:00
Martin Michelsen 65a1b97093 refine more commands 2025-01-23 09:51:48 -08:00
Martin Michelsen 2e6e1adcf3 refine more commands 2025-01-22 23:26:12 -08:00
Martin Michelsen 7da0da66f1 refine some command formats 2025-01-22 00:41:17 -08:00
Martin Michelsen 4038221d8c fix telepipe desync during BB joinable quest load 2025-01-22 00:00:06 -08:00
Martin Michelsen 5c807fa655 refine some xb voice chat structs 2025-01-22 00:00:03 -08:00
Martin Michelsen aa9e1e7305 enable dcv1 native battle mode 2025-01-20 21:27:09 -08:00
Martin Michelsen 721b01a294 rename section to room 2025-01-19 23:21:56 -08:00
Martin Michelsen aa08e3c183 write xbox draw distance patch 2025-01-19 14:56:53 -08:00
Martin Michelsen 63fb78cc9e use original draw distance patch with fixed callback 2025-01-18 22:54:32 -08:00
Martin Michelsen a39adc593b update link on draw distance patch 2025-01-18 20:25:06 -08:00
Martin Michelsen afc6c44bc6 fix incorrect proxy handler on BB 2025-01-18 11:02:00 -08:00
Martin Michelsen 6f26cf87b1 add comment in SuperMap::add_enemy_and_children 2025-01-18 11:02:00 -08:00
Martin Michelsen 6e9d86a6ca use disconnect_client for the kick and ban commands 2025-01-17 21:05:40 -08:00
Martin Michelsen e2caf81e4b use scrolling message for BB client announcements; closes #593 2025-01-17 10:03:44 -08:00
Martin Michelsen 823fb17f60 replace draw distance patch; fixes #470 2025-01-16 23:42:54 -08:00
Martin Michelsen a30e7438ff fix status icons in enemy HP bars patch 2025-01-16 22:00:12 -08:00
Martin Michelsen 269d2178fb add /y/accounts and /y/data/quests in API 2025-01-15 20:34:56 -08:00
Martin Michelsen 6564db437a update HTTP server section in readme 2025-01-13 10:47:48 -08:00
Martin Michelsen 732f1d5eb6 update cc shell command help text 2025-01-12 16:37:25 -08:00
Martin Michelsen 9033fb6a5d rewrite chat command system 2025-01-12 16:27:02 -08:00
Martin Michelsen b028532db3 add /y/shell-exec in HTTP server 2025-01-11 22:16:26 -08:00
Martin Michelsen 80dda2e1f9 fix slime child count in challenge mode 2025-01-11 20:47:09 -08:00
Martin Michelsen 4d3595640a document hardware_id in login commands 2025-01-10 22:13:57 -08:00
Martin Michelsen 0704590238 add kick command in shell 2025-01-09 20:39:45 -08:00
Martin Michelsen 7c48dc1ff5 add notes about interaction mode 2025-01-08 23:49:03 -08:00
Martin Michelsen 68003b2e2f unify menu item format 2025-01-08 23:35:12 -08:00
Martin Michelsen f6fbba5638 run the HTTP server on the event thread on Windows 2025-01-06 22:38:19 -08:00
Martin Michelsen 4bfe7218f7 update readme 2025-01-06 08:14:16 -08:00
Martin Michelsen 5dbb6c3a27 allow concurrent proxy sessions on the same account 2025-01-06 00:12:00 -08:00
Martin Michelsen 0be056adce factor out shell command execution 2025-01-06 00:12:00 -08:00
Martin Michelsen d51f7a0fe7 fix v2/v3 crossplay quest loading 2025-01-05 10:51:59 -08:00
Martin Michelsen a7b5ea5562 allow v2 and v3 clients to load quests in the same game 2025-01-04 22:53:54 -08:00
Martin Michelsen d833727074 fix issue that caused v3 players to be temporarily invisible to v2 players after joining 2025-01-04 22:53:54 -08:00
Martin Michelsen 149e746e3a support dynamic objects in map state; closes #589 2025-01-04 22:53:54 -08:00
Martin Michelsen 1c5b0e4667 make name-all-items more useful 2025-01-04 19:01:16 -08:00
Martin Michelsen 8508607c87 rename DC_V1_11_2000_PROTOTYPE to DC_11_2000 2025-01-01 20:58:28 -08:00
Martin Michelsen 0862b01770 add missing includes on linux 2025-01-01 18:03:35 -08:00
Martin Michelsen 72ac20e574 rewrite map data model 2025-01-01 17:47:50 -08:00
Martin Michelsen 69f7bb3db9 always send server time at login; closes #586 2024-12-26 16:17:47 -08:00
Martin Michelsen dc7368e4af fix qst file format bug 2024-12-23 00:03:38 -08:00
Martin Michelsen 79c7e5dcb4 add inventory items to API response 2024-12-15 21:44:03 -08:00
Martin Michelsen 56ac0a5057 add offline seasonal rappies code 2024-12-14 19:06:13 -08:00
Martin Michelsen 183e7dbf8a fix incorrect CharClass in API server 2024-12-14 19:06:13 -08:00
Martin Michelsen e3097c5578 update ep3 battle setup debug messages 2024-12-14 19:06:13 -08:00
Martin Michelsen aebc9293ad document api endpoints 2024-12-11 19:38:36 -08:00
Martin Michelsen 4b3dcbb6f4 add item pickup patch 2024-12-07 17:29:10 -08:00
Martin Michelsen 3424d6481b add more log messages around login commands; closes #583 2024-12-03 22:21:12 -08:00
Martin Michelsen 760cec9d1e don't check auxiliary data on XB accounts; fixes #584 2024-12-03 21:37:27 -08:00
Martin Michelsen 0196c866f6 fix namespace 2024-12-01 13:19:34 -08:00
Martin Michelsen 13ee74945b refine option_flags notes 2024-12-01 10:07:21 -08:00
Martin Michelsen c6266ff624 fix checksum in 6xBB/6xBC 2024-11-30 22:13:17 -08:00
Martin Michelsen 9a15433fbf fix error in item comments 2024-11-30 10:21:46 -08:00
Martin Michelsen db2bd9d08f refine quest opcode notes 2024-11-29 23:33:44 -08:00
Martin Michelsen f5ed347734 convert private word select messages to text chat messages 2024-11-29 22:19:05 -08:00
Martin Michelsen 483f6dd3fc add conversion functions for proto and v1 save files 2024-11-24 12:26:12 -08:00
Martin Michelsen 0e5837f79a more quest opcode notes 2024-11-17 18:53:57 -08:00
Martin Michelsen ab1a2373b9 refine quest opcode notes 2024-11-17 13:49:10 -08:00
Martin Michelsen aa2b94b7f5 refine more quest opcodes 2024-11-15 19:30:10 -08:00
Martin Michelsen 55a8207932 refine quest opcode docs 2024-11-14 23:07:04 -08:00
Martin Michelsen 484feed314 update some notes 2024-11-13 23:17:15 -08:00
Martin Michelsen 04a42dc627 update readme 2024-11-13 22:42:10 -08:00
318 changed files with 68166 additions and 50063 deletions
+4 -1
View File
@@ -84,8 +84,8 @@ set(SOURCES
src/FileContentsCache.cc
src/FunctionCompiler.cc
src/GSLArchive.cc
src/GVMEncoder.cc
src/HTTPServer.cc
src/ImageEncoder.cc
src/IntegralExpression.cc
src/IPFrameInfo.cc
src/IPStackSimulator.cc
@@ -94,6 +94,7 @@ set(SOURCES
src/ItemData.cc
src/ItemNameIndex.cc
src/ItemParameterTable.cc
src/ItemTranslationTable.cc
src/Items.cc
src/LevelTable.cc
src/Lobby.cc
@@ -106,6 +107,7 @@ set(SOURCES
src/PatchServer.cc
src/PlayerFilesManager.cc
src/PlayerSubordinates.cc
src/PPKArchive.cc
src/ProxyCommands.cc
src/ProxyServer.cc
src/PSOEncryption.cc
@@ -123,6 +125,7 @@ set(SOURCES
src/Server.cc
src/ServerShell.cc
src/ServerState.cc
src/ShellCommands.cc
src/SignalWatcher.cc
src/StaticGameData.cc
src/TeamIndex.cc
+171 -116
View File
@@ -12,8 +12,8 @@ See TODO.md for a list of known issues and future work I've curated, or go to th
* Background
* [History](#history)
* [Other server projects](#other-server-projects)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [Developer information](#developer-information)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [Compatibility](#compatibility)
* Setup
* [Server setup](#server-setup)
@@ -29,6 +29,7 @@ See TODO.md for a list of known issues and future work I've curated, or go to th
* [Memory patches, client functions, and DOL files](#memory-patches-client-functions-and-dol-files)
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
* [Chat commands](#chat-commands)
* [REST API](#rest-api)
* [Non-server features](#non-server-features)
# History
@@ -53,11 +54,11 @@ At the time of its inception, Aeon was also called newserv, and you may find som
Independently of this project, there are many other PSO servers out there. Those that I know of that are (or were) public are listed here in approximate chronological order:
* (Early 2000s) **[Schtserv](https://schtserv.com/)**: The first public-access PSO server; written in Delphi by Schthack. Still active and popular as of this writing (early 2024). Schtserv is also the only other unofficial server to support all versions of PSO, including Episode 3.
* (Early 2000s) **[Schtserv](https://schtserv.com/)**: The first public-access PSO server; written in Delphi by Schthack. Still active and popular as of early 2025. Schtserv is also the only other unofficial server to support all versions of PSO, including Episode 3. (Their implementation of Episode 3 is based on newserv's, which is itself based on Sega's.)
* (2005) **Khyller**: An early attempt of mine to support PSO PC, GC, and BB. See above for more details.
* (2006) **Aeon**: My second attempt. Better than Khyller, but still unreliable.
* (2008) **Tethealla**: A fairly extensive implementation of PSOBB, written in C by Sodaboy. The public version of Tethealla has been [officially disowned](https://www.pioneer2.net/community/threads/tethealla-server-forums-removal.26365/) (as it is now more than 15 years old), but closed-source development continues. [Ephinea](https://ephinea.pioneer2.net/), currently the most popular PSOBB server, is the continuation of this project. Several other modern PSOBB servers are forks of the initial public version of Tethealla as well.
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server; written in C by BlueCrab. Still active and popular as of this writing (early 2024).
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server; written in C by BlueCrab. Still active and popular as of early 2025.
* (2015) **[Archon](https://github.com/dcrodman/archon)**: A PSOBB server written in Go by Drew Rodman.
* (2015) **[Idola](https://github.com/HybridEidolon/idolapsoserv)**: A PSOBB server written in Rust by HybridEidolon. Functionality status unknown; the project has been archived.
* (2017) **[Aselia](https://github.com/Solybum/Aselia)**: A PSOBB server written written in C# by Soly. It seems this was planned to be open-source at some point, but that has not (yet) happened.
@@ -70,12 +71,14 @@ Independently of this project, there are many other PSO servers out there. Those
There is a lot of code in this project that could be useful as a reference. Some of the more notable files are:
* **src/CommandFormats.hh**: Complete listing of all network commands used in all known versions of the game, and their formats
* **src/CommonItemSet.hh/cc**: Format of ItemPT files, shop definition files, and tekker adjustment tables
* **src/DCSerialNumbers.hh/cc**: PSO DC serial number validation algorithm and serial number generator
* **src/ItemData.hh**: Item format reference
* **src/ItemCreator.hh/cc**: Reverse-engineered item generator from Episodes 1&2 (used for all versions)
* **src/ItemParameterTable.hh**: Format of many structures in ItemPMT.prs
* **src/Map.hh/cc**: Map file (.dat) structure and reverse-engineered Challenge Mode random enemy generation algorithm
* **src/QuestScript.cc**: Complete listing of all quest opcodes on all versions, along with their arguments and behavior
* **src/RareItemSet.hh/cc**: Format of ItemRT files (rare item drop tables)
* **src/SaveFileFormats.hh**: Definitions of save file structures for all versions
* **src/Episode3/DataIndexes.hh**: Episode 3 file structures, including card definition format and map/quest format
* **system/item-tables/names-v4.json**: Names of all items, indexed by the first 3 bytes of data1
@@ -90,7 +93,7 @@ If you want to use parts of newserv in your project, there are two easy ways to
# Compatibility
newserv supports all known versions of PSO, including development prototypes. This table lists all versions that newserv supports. (NTE stands for Network Trial Edition; the GameCube beta versions were called Trial Edition instead, but we use the NTE abbreviation anyway for consistency.)
newserv supports all known versions of PSO, including various development prototypes. This table lists all versions that newserv supports. (NTE stands for Network Trial Edition; the GameCube beta versions were called Trial Edition instead, but we use the NTE abbreviation anyway for consistency.)
| Version | Lobbies | Games | Proxy |
|-----------------|----------|----------|----------|
@@ -101,22 +104,21 @@ newserv supports all known versions of PSO, including development prototypes. Th
| DC V1 | Yes | Yes | Yes |
| DC 08/2001 | Yes | Yes | Yes |
| DC V2 | Yes | Yes | Yes |
| PC NTE | Yes (3) | Yes | No |
| PC NTE | Yes (1) | Yes | No |
| PC | Yes | Yes | Yes |
| GC Ep1&2 NTE | Yes | Yes | Yes |
| GC Ep1&2 | Yes | Yes | Yes |
| GC Ep1&2 Plus | Yes | Yes | Yes |
| GC Ep3 NTE | Yes | Yes (1) | Yes |
| GC Ep3 NTE | Yes | Yes (2) | Yes |
| GC Ep3 | Yes | Yes | Yes |
| Xbox Ep1&2 Beta | Yes | Yes | Yes |
| Xbox Ep1&2 | Yes | Yes | Yes |
| BB (vanilla) | Yes | Yes (2) | Yes |
| BB (Tethealla) | Yes | Yes (2) | Yes |
| BB (vanilla) | Yes | Yes | Yes |
| BB (Tethealla) | Yes | Yes | Yes |
*Notes:*
1. *Episode 3 NTE battles are not well-tested; some things may not work. See notes/ep3-nte-differences.txt for a list of known differences between NTE and the final version. NTE and non-NTE players cannot battle each other.*
2. *Some BB-specific features are not well-tested (for example, some quests that use rare commands may not work properly). Please submit a GitHub issue if you find something that doesn't work.*
3. *This is the only version of PSO that doesn't have any way to identify the player's account - there is no serial number or username. For this reason, AllowUnregisteredUsers must be enabled in config.json to support PC NTE, and PC NTE players receive a random Guild Card number every time they connect. To prevent abuse, PC NTE support can be disabled in config.json.*
1. *This is the only version of PSO that doesn't have any way to identify the player's account - there is no serial number or username. For this reason, AllowUnregisteredUsers must be enabled in config.json to support PC NTE, and PC NTE players receive a random Guild Card number every time they connect. To prevent abuse, PC NTE support can be disabled in config.json.*
2. *Episode 3 NTE battles are not well-tested; some things may not work. See notes/ep3-nte-differences.txt for a list of known differences between NTE and the final version. NTE and non-NTE players cannot battle each other.*
# Setup
@@ -233,28 +235,28 @@ Devolution includes modem emulation and is compatible with all PSO GameCube vers
### PSO GC on Dolphin
If you're using the HLE BBA type, set the BBA's DNS server address to newserv's IP address and it should work. (If newserv is on the same machine as Dolphin, you will need to use an action replay code directed at 127.0.0.1 to connect, as PSO rejects DNS queries from the same IP address.) Set PSO's network settings the same as listed below.
If you're using the HLE BBA type, set the BBA's DNS server address to newserv's IP address and it should work. (If newserv is on the same machine as Dolphin, you will need to use an Action Replay code directed at 127.0.0.1 to connect, as PSO rejects DNS queries from the same IP address.) Set PSO's network settings the same as listed below.
If you're using the TAP BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
If you're using the TAP (not tapserver) BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
If you're using the tapserver BBA or modem type, you can make it connect to a newserv instance running on the same machine via the tapserver interface. To do this:
1. In the GameCube pane of the Config window, set the SP1 device to Broadband Adapter (tapserver) or Modem Adapter (tapserver).
2. Set IPStackListen (for BBA) or PPPStackListen (for modem) according to the comments in config.json and start newserv.
2. Click the "..." button next to the SP1 menu. If you're using the tapserver BBA, enter `127.0.0.1:5059` in the box. If you're using the tapserver modem, enter `127.0.0.1:5058` in the box. (If newserv isn't running on the same machine as Dolphin, replace 127.0.0.1 with newserv's IP address.)
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
4. Start an online game.
### PSO BB
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the "Client patch directories" section for instructions on setting this up.)
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's common for various BB clients to have different map files. It's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the [client patch directories](#client-patch-directories) section for instructions on setting this up.)
The original Japanese and US versions of PSO BB work with newserv (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)). To get them to connect to your server, do one of the following:
* Use a drop-in patcher like [AzureFlare](https://github.com/Repflez/AzureFlare).
* Modify your hosts file to redirect the client's destination address to localhost or your server's address.
* Edit your hosts file to redirect the client's destination address to localhost or your server's address.
* Edit psobb.exe to point to your newserv instance. The original clients are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at offset 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
### Connecting external clients
### Allowing external players to connect
If you want to accept connections from outside your local network, you'll need to set ExternalAddress to your public IP address in the configuration file, and you'll likely need to open some ports in your router's NAT configuration - specifically, all the TCP ports listed in PortConfiguration in config.json.
@@ -291,12 +293,12 @@ Within the category directories, quest files should be named like `q###-VERSION-
For .dat files, the `LANGUAGE` token may be omitted. If it's present, then that .dat file will only be used for that language of the quest; if omitted, then that .dat file will be used for all languages of the quest.
Some quests (mostly battle and challenge mode quests) have additional JSON metadata files that describe how the server should handle them. This includes flags that can be used to hide the quest unless a preceding quest has been cleared, or to hide the quest unless purchased as a team reward. These metadata files are generally named similarly to their .bin and .dat counterparts, except the `VERSION` token may also be omitted if the metadata applies to all languages of the quest on all PSO versions. See system/quests/battle/b88001.json for documentation on the exact format of the JSON file.
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-gc-e.bin` and `q058-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, it knows this is the English version of the quest because the .bin filename ends with `-e` (even though the .dat filename does not), and it puts them in the Retrieval category because the files are within the retrieval/ directory within system/quests/.
Some quests (mostly battle and challenge mode quests) have additional JSON metadata files that describe how the server should handle them. These files include flags that can be used to hide the quest unless a preceding quest has been cleared, or to hide the quest unless purchased as a BB team reward. These metadata files are generally named similarly to their .bin and .dat counterparts, except the `VERSION` token may also be omitted if the metadata applies to all languages of the quest on all PSO versions. See system/quests/battle/b88001.json for documentation on the exact format of the JSON file.
Some quests may also include a .pvr file, which contains an image used in the quest. These files are named similarly to their .bin and .dat counterparts.
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-gc-e.bin` and `q058-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, it knows this is the English version of the quest because the .bin filename ends with `-e` (even though the .dat filename does not), and it puts them in the Retrieval category because the files are within the retrieval/ directory within system/quests/.
The GameCube and Xbox quest formats are very similar, but newserv treats them as different. If you want to use the same quest file for GameCube and Xbox clients, you can make one a symbolic link to the other.
There are multiple PSO quest formats out there; newserv supports all of them. It can also decode any known format to standard .bin/.dat format. Specifically:
@@ -324,7 +326,7 @@ There are multiple PSO quest formats out there; newserv supports all of them. It
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
3. *Use the decode action to convert these quests to .bin/.dat format before putting them into the server's quests directory. If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
4. *Episode 3 quests don't go in the system/quests directory. See the Episode 3 section below.*
4. *Episode 3 quests don't go in the system/quests directory. See the [Episode 3 section](#episode-3-features) section below.*
5. *Quest source can be assembled into a .bin or .bind file with `newserv assemble-quest-script FILENAME.txt`. See system/quests/retrieval/q058-gc-e.bin.txt for an annotated example; this is the English GameCube version of Lost HEAT SWORD.*
Episode 3 download quests consist only of a .bin file - there is no corresponding .dat file. Episode 3 download quest files may be named with the .mnm extension instead of .bin, since the format is the same as the standard map files (in system/ep3/). These files can be encoded in any of the formats described above, except .qst.
@@ -338,13 +340,13 @@ Quest contents are cached in memory, but if you've changed the contents of the q
newserv supports server-side item generation on all game versions, except for the earliest DC prototypes (NTE and 11/2000). By default, the game behaves as it did on the original servers - on all versions except BB, item drops are controlled by the leader client in each game, and on BB, item drops are controlled by the server.
There are five different available behaviors for item drops:
* `DISABLED` (or `NONE`): No items will drop from boxes or enemies.
* `CLIENT`: The game leader generates items, all items are visible to all players, and any player may pick up any item. This is the default mode for all game versions, except this mode cannot be used on BB.
* `SERVER_SHARED`: The server generates items, all items are visible to all players, and any player may pick up any item. This is the default mode for BB.
* `SERVER_PRIVATE`: The server generates items, but each player may get a different item from any box or enemy. If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are visible to everyone.
* `SERVER_DUPLICATE`: The server generates items, and each player will get the same item from any box or enemy, but there is one copy of each item for each player (and each player only sees their own copy of the item). If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are not duplicated and are visible to everyone.
* `disabled` (or `none`): No items will drop from boxes or enemies.
* `client`: The game leader generates items, all items are visible to all players, and any player may pick up any item. This is the default mode for all game versions, except this mode cannot be used if the game leader is on BB.
* `shared`: The server generates items, all items are visible to all players, and any player may pick up any item. This is the default mode if the game leader is on BB.
* `private`: The server generates items, but each player may get a different item from any box or enemy. If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are visible to everyone.
* `duplicate`: The server generates items, and each player will get the same item from any box or enemy, but there is one copy of each item for each player (and each player only sees their own copy of the item). If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are not duplicated and are visible to everyone.
In the `SERVER_PRIVATE` and `SERVER_DUPLICATE` modes, there is no incentive to pick up items before another player, since other players cannot pick up the items you see dropped from boxes and enemies. However, if you pick up an item and drop it later, it can then be seen and picked up by any player.
In the `private` and `duplicate` modes, there is no incentive to pick up items before another player, since other players cannot pick up the items you see dropped from boxes and enemies. However, if you pick up an item and drop it later, it can then be seen and picked up by any player.
The drop mode can be changed at any time during a game with the `$dropmode` chat command. If the mode is changed after some items have already been dropped, the existing items retain their visibility (that is, items dropped in private mode still can't be picked up by other players since they were dropped before the mode was changed). You can configure which drop modes are used by default, and which modes players are allowed to choose, in config.json. See the comments above the AllowedDropModes and DefaultDropMode keys.
@@ -352,13 +354,18 @@ In the server drop modes, the item tables used to generate common items are in t
## Cross-version play
All versions of PSO can see and interact with each other in the lobby. newserv also allows some versions to play in-game with each other:
* DC V1 players can join DC V2 games if the difficulty level isn't set to Ultimate and the creator chose to allow V1 players.
* DC V2 players can join DC V1 games.
* If AllowDCPCGames is enabled in config.json, PC and DC players can join each other's games. DC V1 players cannot join PC games with the Ultimate difficulty level.
* If AllowGCXBGames is enabled in config.json, GC and Xbox players can join each other's games.
All versions of PSO can see and interact with each other in the lobby. By default, newserv allows V1 and V2 players to play together, and allows GC and Xbox players to play together. You can change these rules to allow all versions to play together, or to prevent versions from playing together, with the CompatibilityGroups setting in config.json.
In V1/V2 cross-version play, when any of the server drop modes are used, the server uses the drop table corresponding to the version the game was created with. (For example, if a DC V1 player created the game, rare-table-v1.json will be used, even after V2 players join.)
There are several cross-version restrictions that always apply regardless of the compatibility groups setting:
* DC V1 players cannot join DC V2 games if the game creator didn't choose to allow them.
* DC V1 players cannot join games if the difficulty level is set to Ultimate or the game mode is Battle or Challenge.
* Only GC, Xbox, and BB players can join games in Episode 2.
* Only BB players can join games in Episode 4.
* Episode 3 players cannot join non-Episode 3 games, and vice versa.
V1/V2 compatibility and GC/Xbox compatibility are well-tested, but other situations are not. Not much attention has been given yet to how items should be handled across major versions; if you enable V2/GC compatibility, for example, there will likely be bugs. Please report such bugs as GitHub issues.
In cross-version play, when any of the server drop modes are used, the server uses the drop tables corresponding to the leader's version and section ID. (For example, if a DC V1 player is the game leader, rare-table-v1.json will be used, even after V2 players join.) If a BB player is the leader and the `client` drop mode is used, the server generates items as if it were in `shared` mode.
## Server-side saves
@@ -370,7 +377,7 @@ There is a third command, `$bbchar <username> <password> <slot>`, which behaves
Exactly which data is saved and loaded depends on the game version:
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/challenge |
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/Challenge |
|----------------------|-----------|-----------|---------------|-------------|------|------------------|
| PSO DC v1 prototypes | Yes | Yes | No | No | No | N/A |
| PSO DC v1 | Yes | Yes | No | No | No | N/A |
@@ -430,55 +437,56 @@ Like quests, Episode 3 card definitions, maps, and quests are cached in memory.
*Everything in this section requires resource_dasm to be installed, so newserv can use the assemblers and disassemblers from its libresource_file library. If resource_dasm is not installed, newserv will still build and run, but these features will not be available.*
You can put assembly files in the system/client-functions directory with filenames like PatchName.VERS.patch.s and they will appear in the Patches menu for clients that support client functions. Client functions are written in SH-4, PowerPC, or x86 assembly and are compiled when newserv is started. The assembly system's features are documented in the comments in system/client-functions/System/WriteMemory.ppc.s.
You can put assembly files in the system/client-functions directory with filenames like PatchName.VERS.patch.s and they will appear in the Patches menu for clients that support client functions. Client functions are written in SH-4, PowerPC, or x86 assembly and are compiled when newserv is started. The assembly system's features are documented in the comments in system/client-functions/System/WriteMemoryGC.ppc.s.
The VERS token in client function filenames refers to the specific version of the game that the client function applies to. Some versions do not support receiving client functions at all. *Note: newserv uses the shorter GameCube versioning convention, where discs labeled DOL-XXXX-0-0Y are version 1.Y. The PSO community seems to use the convention 1.0Y in some places instead, but these are the same version. For example, the version that newserv calls v1.4 is the same as v1.04, and is labeled DOL-GPOJ-0-04 on the underside of the disc.*
The specific versions are:
| Game | VERS | Architecture |
|-------------------|------|---------------|
| PSO DC NTE | 1OJ1 | Not supported |
| PSO DC 11/2000 | 1OJ2 | Not supported |
| PSO DC 12/2000 | 1OJ3 | Not supported |
| PSO DC 01/2001 | 1OJ4 | Not supported |
| PSO DC v1 JP | 1OJF | Not supported |
| PSO DC v1 US | 1OEF | Not supported |
| PSO DC v1 EU | 1OPF | Not supported |
| PSO DC 08/2001 | 2OJ5 | SH-4 |
| PSO DC v2 JP | 2OJF | SH-4 |
| PSO DC v2 US | 2OEF | SH-4 |
| PSO DC v2 EU | 2OPF | SH-4 |
| PSO PC (v2) | 2OJW | Not supported |
| PSO GC NTE | 3OJT | PowerPC |
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 JP | 3OJ4 | PowerPC |
| PSO GC v1.5 JP | 3OJ5 | PowerPC (1) |
| PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 US | 3OE2 | PowerPC (1) |
| PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 NTE | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | PowerPC (1) |
| PSO GC Ep3 EU | 3SP0 | PowerPC (1) |
| PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.13 | 59NL | x86 |
| PSO BB Tethealla | 59NL | x86 |
| Game | VERS | Architecture |
|------------------------------|------|---------------|
| PSO DC Network Trial Edition | 1OJ1 | Not supported |
| PSO DC 11/2000 prototype | 1OJ2 | Not supported |
| PSO DC 12/2000 prototype | 1OJ3 | Not supported |
| PSO DC 01/2001 prototype | 1OJ4 | Not supported |
| PSO DC v1 JP | 1OJF | Not supported |
| PSO DC v1 US | 1OEF | Not supported |
| PSO DC v1 EU | 1OPF | Not supported |
| PSO DC 08/2001 prototype | 2OJ5 | SH-4 |
| PSO DC v2 JP | 2OJF | SH-4 |
| PSO DC v2 US | 2OEF | SH-4 |
| PSO DC v2 EU | 2OPF | SH-4 |
| PSO PC (v2) | 2OJW | Not supported |
| PSO GC Trial Edition | 3OJT | PowerPC |
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 (Plus) JP | 3OJ4 | PowerPC |
| PSO GC v1.5 (Plus) JP | 3OJ5 | PowerPC (1) |
| PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 (Plus) US | 3OE2 | PowerPC (1) |
| PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 Trial Edition | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | PowerPC (1) |
| PSO GC Ep3 EU | 3SP0 | PowerPC (1) |
| PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.11 | 59NJ | x86 |
| PSO BB JP 1.25.13 | 59NL | x86 |
| PSO BB Tethealla | 59NL | x86 |
*Notes:*
1. *Client functions are only supported on these versions if EnableSendFunctionCallQuestNumbers is set in config.json. See the comments there for more information.*
newserv comes with a set of patches for many of the above versions, based on AR codes originally made by Ralf at GC-Forever and Aleron Ives. Many of them were originally posted in [this thread](https://www.gc-forever.com/forums/viewtopic.php?f=38&t=2050).
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.ppc.s, WriteMemory.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWordGC.ppc.s, WriteMemoryGC.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
@@ -508,7 +516,7 @@ There are many options available when starting a proxy session. All options are
* **Save files**: saves copies of several kinds of files when they're sent by the remote server. The files are written to the current directory (which is usually the directory containing the system/ directory). These kinds of files can be saved:
* Online quests and download quests (saved as .bin/.dat files)
* GBA games (saved as .gba files)
* Patches (saved as .bin files, and disassembled into PowerPC assembly if newserv is built with patch support)
* Patches (saved as .bin files, and disassembled to text files if newserv is built with patch support)
* Player data from BB sessions (saved as .bin files, which are not the same format as .nsc files)
* Episode 3 online quests and maps (saved as .mnmd files)
* Episode 3 download quests (saved as .mnm files)
@@ -543,11 +551,14 @@ Some commands only work on the game server and not on the proxy server. The chat
* Debugging commands
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
* You'll see in-game messages from the server when you take certain actions, like killing an enemy in BB.
* You'll see in-game messages from the server when you take some actions, like killing enemies, opening boxes, or flipping switches.
* You'll see the rare seed value and floor variations when you join a game.
* You'll be placed into the last available slot in lobbies and games instead of the first, unless you're joining a BB solo-mode game.
* You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above).
* You'll be able to join games with any PSO version, not only those for which cross-version play is normally enabled. See the "Cross-version play" section above for details on this.
* The rest of the commands in this section are enabled on the game server. (They are always enabled on the proxy server.)
* `$readmem <address>` (game server only): Read 4 bytes from the given address and show you the values.
* `$writemem <address> <data>` (game server only): Write data to the given address. Data is not required to be any specific size.
* `$nativecall <address> [arg1 ...]` (game server only, GC only): Call a native function on your client. Only arguments passed in registers are supported; calling functions that take many arguments is not supported.
* `$quest <number>` (game server only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. Debug is not required to be enabled if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
* `$qcall <function-id>`: Call a quest function on your client.
* `$qcheck <flag-num>` (game server only): Show the value of a quest flag. This command can be used without debug mode enabled. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only).
@@ -562,14 +573,11 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$sc <data>`: Send a command to yourself.
* `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server.
* `$sb <data>`: Send a command to yourself, and to the remote server or game server.
* `$meseta <amount>` (game server only; Episode 3 only): Add the given amount to your Meseta total.
* `$auction` (Episode 3 only): Bring up the CARD Auction menu, regardless of how many players are in the game or if you have a VIP card.
* `$ep3battledebug` (game server only; Episode 3 only): Enable or disable TCard00_Select. If enabled, the game will enter the debug menu when you start a battle.
* Personal state commands
* `$arrow <color-id>`: Change your lobby arrow color.
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$battle` (game server only; DC v1 only): After using this command, the next game you create will be in battle mode. (A chat command is required for this because DCv1 doesn't allow this natively.) On DCv1, the battle quests are not available, but free-roam is.
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy server, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
* `$swa`: Enable or disable switch assist. When enabled, the server will unlock two-player and four-player doors in non-quest games when you step on any of the required switches.
@@ -577,10 +585,10 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
* Character data commands (game server only)
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
* `$loadchar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the "Server-side saves" section for more details.
* `$edit <stat> <value>`: Modify your character data. See "Using $edit" below for details.
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$loadchar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the [server-side saves section](#server-side-saves) for more details.
* `$edit <stat> <value>`: Modify your character data. See the [using $edit](#using-edit) section for details.
* Blue Burst player commands (game server only)
* `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
@@ -590,7 +598,7 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$maxlevel <level>`: Set the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
* `$minlevel <level>`: Set the minimum level for players to join the current game.
* `$password <password>`: Set the game's join password. To unlock the game, run `$password` with nothing after it.
* `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the "Item tables and drop modes" section for more information.
* `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the [item tables and drop modes section](#item-tables-and-drop-modes) for more information.
* `$persist`: Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The states of enemies, objects, and switches will be saved, and items left on the floor will not be deleted. (But if you're in the private or duplicate drop mode, items dropped by enemies are deleted - to make sure a certain item won't be deleted, you can pick it up and drop it again.) If the game is empty for too long (15 minutes by default), it is then deleted.
* Episode 3 commands (game server only)
@@ -621,7 +629,6 @@ Some commands only work on the game server and not on the proxy server. The chat
* Administration commands (game server only)
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. On BB, the message appears in the scrolling top bar.
* `$ann!`, `$ann?`, `$ann?!`: Same as `$ann`, but with `?`, omits the sender's name, and with `!`, sends the message as a Simple Mail message instead of on-screen text.
* `$ax <message>`: Send a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
* `$silence <identifier>`: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number.
* `$kick <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
* `$ban <duration> <identifier>`: Ban a player. The duration should be of the form `10m` (minutes), `10h` (hours), `10d` (days), `10w` (weeks), `10M` (months), or `10y` (years). (Numbers other than 10 may be used, of course.) As with `$kick`, the identifier may be the player's name or Guild Card number.
@@ -647,7 +654,7 @@ Some subcommands are always available. They are:
* On all versions except DCv1 and early prototypes: `ninja`, `rico`, `sonic`, `knuckles`, `tails`
* On GC, Xbox, and BB: `flowen`, `elly`
* On BB only: `momoka`, `irene`, `guild`, `nurse`
* `$edit secid SECID-NAME`: Set your section ID (cheat mode is required for this unless your character is Level 1)
* `$edit secid SECID-NAME`: Set your section ID (cheat mode is required unless your character is Level 1)
The remaining subcommands are only available if cheat mode is enabled on the server. They are:
* `$edit atp N`: Set your ATP to N until stats are updated (e.g. by leveling up)
@@ -656,45 +663,94 @@ The remaining subcommands are only available if cheat mode is enabled on the ser
* `$edit dfp N`: Set your DFP to N until stats are updated
* `$edit ata N`: Set your ATA to N until stats are updated
* `$edit lck N`: Set your LCK to N until stats are updated
* `$edit hp N`: Set your MST to N until stats are updated
* `$edit hp N`: Set your HP to N until stats are updated
* `$edit meseta N`: Set the amount of Meseta in your inventory
* `$edit exp N`: Set your total amount of EXP (does not affect level)
* `$edit level N`: Set your current level (recomputes stats, but does not affect EXP)
* `$edit tech TECH-NAME LEVEL`: Set the level of one of your techniques
## REST API
newserv has an optional HTTP server that provides a way to programmatically get data from the server in realtime. This is intended for use with external integrations; for example, a web site could query this API to get the current player count to display on the home page.
The HTTP server is disabled by default, and you have to explicitly enable it in config.json if you want this functionality. **If you enable it, make sure that the HTTP port can't be accessed from the public Internet.** The API provides a lot of internal data about players and games, and it should only be accessed by programs that you've written or that you trust.
To enable the HTTP server, add a port number in the HTTPListen list in config.json. The HTTP server will listen on that port.
All returned data is JSON-encoded, and all request data (for POST requests) must also be JSON-encoded with the `Content-Type: application/json` header.
The HTTP server has the following endpoints:
* `GET /`: Returns the server's build date and revision.
* `GET /y/data/ep3-cards`: Returns the Episode 3 card definitions.
* `GET /y/data/ep3-cards-trial`: Returns the Episode 3 Trial Edition card definitions.
* `GET /y/data/common-tables`: Returns the parameters for generating common items (ItemPT files). This endpoint returns a lot of data and can be slow!
* `GET /y/data/rare-tables`: Returns a list of rare table names.
* `GET /y/data/rare-tables/<TABLE-NAME>` (for example, `/y/data/rare-tables/rare-table-v4`): Returns the contents of a rare item table.
* `GET /y/data/quests`: Returns metadata about all available quests and quest categories.
* `GET /y/data/config`: Returns the server's configuration file.
* `GET /y/accounts`: Returns information about all registered accounts.
* `GET /y/clients`: Returns information about all connected clients on the game server.
* `GET /y/proxy-clients`: Returns information about all connected clients on the proxy server.
* `GET /y/lobbies`: Returns information about all lobbies and games.
* `GET /y/server`: Returns information about the server.
* `GET /y/summary`: Returns a summary of the server's state, connected clients, active games, and proxy sessions.
* `WS /y/rare-drops/stream`: WebSocket endpoint that sends messages whenever an announceable rare item is dropped in any game. See below.
* `POST /y/shell-exec`: Runs a server shell command. Input should be a JSON dict of e.g. `{"command": "announce hello"}`; response will be a JSON dict of `{"result": "<result text>"}` or an HTTP error.
### Rare drop stream endpoint
The `/y/rare-drops/stream` endpoint provides a way to implement a drop log in e.g. Discord. For every announceable rare item, a message is sent to all connected clients on this endpoint. (Announceable rare items are items for which an in-game or server-wide text message is sent announcing the find.)
Upon connecting, you'll get the message `{"ServerType": "newserv"}`. After that, when a rare item announcement is sent, you'll get a message like this:
```
{
"PlayerAccountID", 12345,
"PlayerName", "SONIC",
"PlayerVersion", "GC_V3",
"GameName", "ttf",
"GameDropMode", "SERVER_PRIVATE",
"ItemData", "03000000 00010000 00000000 (0021002C) 00000000",
"ItemDescription", "Monomate x1",
"NotifyGame", true,
"NotifyServer", false,
}
```
# Non-server features
newserv has many CLI options, which can be used to access functionality other than the game and proxy server. Run `newserv help` to see a full list of the options and how to use each one.
The data formats that newserv can convert to/from are:
| Format | Encode/compress action | Decode/extract action |
|--------------------------------|---------------------------|------------------------------|
| PRS compression | `compress-prs` | `decompress-prs` |
| PR2/PRC compression | `compress-pr2` | `decompress-pr2` |
| BC0 compression | `compress-bc0` | `decompress-bc0` |
| Raw encrypted data | `encrypt-data` | `decrypt-data` |
| Episode 3 command mask | `encrypt-trivial-data` | `decrypt-trivial-data` |
| Challenge Mode rank text | `encrypt-challenge-data` | `decrypt-challenge-data` |
| PSO DC quest file (.vms) | None | `decode-vms` |
| PSO GC quest file (.gci) | None | `decode-gci` |
| Download quest file (.dlq) | None | `decode-dlq` |
| Server quest file (.qst) | `encode-qst` | `decode-qst` |
| PSO DC save file (.vms) | `encrypt-vms-save` | `decrypt-vms-save` |
| PSO PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive | None | `extract-afs` |
| BML archive | None | `extract-bml` |
| GSL archive | None | `extract-gsl` |
| GVM texture | `encode-gvm` | None |
| Text archive | `encode-text-archive` | `decode-text-archive` |
| Unicode text set | `encode-unicode-text-set` | `decode-unicode-text-set` |
| Word Select data set | None | `decode-word-select-set` |
| Set data table | None | `disassemble-set-data-table` |
| Rare item table (AFS/GSL/JSON) | `convert-rare-item-set` | `convert-rare-item-set` |
| Format | Encode/compress action | Decode/extract action |
|-------------------------------------|---------------------------|------------------------------|
| PRS compression | `compress-prs` | `decompress-prs` |
| PR2/PRC compression | `compress-pr2` | `decompress-pr2` |
| BC0 compression | `compress-bc0` | `decompress-bc0` |
| Raw encrypted data | `encrypt-data` | `decrypt-data` |
| Episode 3 command mask | `encrypt-trivial-data` | `decrypt-trivial-data` |
| Challenge Mode rank text | `encrypt-challenge-data` | `decrypt-challenge-data` |
| PSO DC quest file (.vms) | None | `decode-vms` |
| PSO GC quest file (.gci) | None | `decode-gci` |
| Download quest file (.dlq) | None | `decode-dlq` |
| Server quest file (.qst) | `encode-qst` | `decode-qst` |
| PSO DC save file (.vms) | `encrypt-vms-save` | `decrypt-vms-save` |
| PSO PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive (.afs) | None | `extract-afs` |
| BML archive (.bml) | None | `extract-bml` |
| PPK archive (.ppk) | None | `extract-ppk` |
| GSL archive (.gsl) | `generate-gsl` | `extract-gsl` |
| GVM texture (.gvm) | `encode-gvm` | None |
| Bitmap font (.fon) | `encode-bitmap-font` | `decode-bitmap-font` |
| Text archive | `encode-text-archive` | `decode-text-archive` |
| Unicode text set | `encode-unicode-text-set` | `decode-unicode-text-set` |
| Word Select data set | None | `decode-word-select-set` |
| Set data table | None | `disassemble-set-data-table` |
| Rare item table (AFS/GSL/JSON/HTML) | `convert-rare-item-set` | `convert-rare-item-set` |
There are several actions that don't fit well into the table above, which let you do other things:
@@ -703,7 +759,6 @@ There are several actions that don't fit well into the table above, which let yo
* Run a brute-force search for a decryption seed (`find-decryption-seed`)
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`, `generate-ep3-cards-html`)
* Format Blue Burst battle parameter files in a human-readable manner (`show-battle-params`)
* Search for rare enemy seeds that result in rare enemies on console versions (`find-rare-enemy-seeds`)
* Convert item data to a human-readable description, or vice versa (`describe-item`)
* Connect to another PSO server and pretend to be a client (`cat-client`)
* Generate or describe DC serial numbers (`generate-dc-serial-number`, `inspect-dc-serial-number`)
+644 -322
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -27,7 +27,7 @@ List of differences in Ep3 NTE compared to Final:
- - Ability Trap prevents all abnormal conditions
- Traps
- - Traps trigger as soon as you move into their tile; on Final, they trigger at the end of the Move phase
- - Traps may use any assist card, and this can be configured in the map definition (TODO: verify this last part)
- - Traps may use any assist card, and this can be configured in the map definition
- Rules
- - Dice Boost does not exist
- - ATK and DEF dice ranges can be set independently, but there are only 7 options for each: 1-6, 1-1, 2-2, 3-3, 4-4, 5-5, 6-6
+3 -13
View File
@@ -5,17 +5,7 @@ import sys
from dataclasses import dataclass
version_tokens = ("JP12", "JP13", "JP14", "JP15", "US10", "US11", "US12", "EU")
version_to_specific_version = {
"JP12": "3OJ2",
"JP13": "3OJ3",
"JP14": "3OJ4",
"JP15": "3OJ5",
"US10": "3OE0",
"US11": "3OE1",
"US12": "3OE2",
"EU": "3OP0",
}
version_tokens = ("3OJ2", "3OJ3", "3OJ4", "3OJ5", "3OE0", "3OE1", "3OE2", "3OP0")
@dataclass
@@ -60,7 +50,7 @@ def write_patches_for_code(
if write_regions:
filename = os.path.join(
out_dir,
f'{name.replace(" ", "")}.{version_to_specific_version[v]}.patch.s',
f'{name.replace(" ", "")}.{v}.patch.s',
)
with open(filename, "wt") as f:
if long_name is not None:
@@ -144,7 +134,7 @@ def main():
| (data[z + 2] << 8)
| (data[z + 3] << 0)
)
elif line.startswith("JP12------------"):
elif line.startswith("3OJ2------------"):
reading_code = True
else:
code_name = line
+7 -5
View File
@@ -1,5 +1,5 @@
Patch server handler table
PC BB MAX SIZE
PC BB12513J MAX SIZE
02 => 00404CA4 0070B870 0000004C
04 => 00404DDC 0070C004 00000004
05 => 00404C98 0070B8FC 00000004
@@ -489,16 +489,18 @@ SUBCMD GCEp3NTE GCEp3USA
6xB5x47 80234FBC 8022A314
Quest opcode dispatch
3OE0 => 801F2CE0
3OE1 => 801F2CE0
3OE2 => 801F2E64
3OJT => 80242F7C
3OJ2 => 801F287C
3OJ3 => 801F2E00
3OJ4 => 801F3568
3OJ5 => 801F2E10
3OE0 => 801F2CE0
3OE1 => 801F2CE0
3OE2 => 801F2E64
3OP0 => 801F33DC
3SE0 => 80109F78
3SJT => 8010D5D8
3SJ0 => 8010A138
3SE0 => 80109F78
3SP0 => 8010A404
Quest opcode handlers (format: GET_ARGS EXEC_FUN)
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+69 -69
View File
@@ -21,7 +21,7 @@ Common Bank Patch
CommonBank
*** name=Common bank
*** desc=Hold L and open\nthe bank to use a\ncommon bank stored\nin temp character\n3's data
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 8000BAB4 281B0002 cmplwi r27, 2
8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 8000BAB8 40820018 bne +0x00000018 /* 8000BAD0 */
8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 8000BABC 3C008000 lis r0, 0x8000
@@ -71,7 +71,7 @@ Item Loss Prevention
ItemLossPrevention
*** name=No item loss
*** desc=Don't lose items if\nyou don't log off\nnormally
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801D33E4 4800004C 801D38EC 4800004C 801D3CC4 4800004C 801D39B8 4800004C 801D381C 4800004C 801D381C 4800004C 801D3A1C 4800004C 801D3ED8 4800004C b +0x0000004C /* 801D3868 */
801FE900 60000000 801FF174 60000000 8020010C 60000000 801FF710 60000000 801FF0FC 60000000 801FF0FC 60000000 801FFA44 60000000 801FF9E0 60000000 nop
801FFE5C 60000000 802006D0 60000000 802016CC 60000000 80200C9C 60000000 80200658 60000000 80200658 60000000 80200FD0 60000000 80200F3C 60000000 nop
@@ -83,7 +83,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Palette
*** name=Palette
*** desc=Press Z to cycle\nthrough 4 customize\nconfigs instead of of\njust one
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 8000CD00 3C808000 lis r4, 0x8000
8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E 8000CD04 6084CF3E ori r4, r4, 0xCF3E
8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 8000CD08 3BE00000 li r31, 0x0000
@@ -123,7 +123,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
"Palette Patch" Part 2
Palette
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 8000CD8C 38600003 li r3, 0x0003
8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 8000CD90 3C808001 lis r4, 0x8001
8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 8000CD94 B064CF78 sth [r4 - 0x3088], r3
@@ -159,7 +159,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
"Palette Patch" Part 3 (this part adds PBs to the customize list)
Palette
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 8000CA40 28030000 cmplwi r3, 0
8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 8000CA44 40820008 bne +0x00000008 /* 8000CA4C */
8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 8000CA48 3BE00000 li r31, 0x0000
@@ -195,12 +195,12 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
"Palette Patch" Part 4 (this disables PBs from overtaking the back palette)
Palette
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801B55F8 38600000 801B5A4C 38600000 801B7BB8 38600000 801B5B18 38600000 801B59E4 38600000 801B59E4 38600000 801B5B7C 38600000 801B6038 38600000 li r3, 0x0000
"Palette Patch" Part 5 (saves palettes to temp slot 3)
Palette
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000B958 906DB93C 8000B958 906DB944 8000B958 906DB964 8000B958 906DB964 8000B958 906DB954 8000B958 906DB954 8000B958 906DB974 8000B958 906DB9B4 stw [r13 - 0x46AC], r3
8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C 8000B95C 1C63003C mulli r3, r3, 60
8000B960 808DB920 8000B960 808DB928 8000B960 808DB948 8000B960 808DB948 8000B960 808DB938 8000B960 808DB938 8000B960 808DB958 8000B960 808DB998 lwz r4, [r13 - 0x46C8]
@@ -244,7 +244,7 @@ Decoction Patch (makes the Decoction item wipe non-HP/TP materials)
Decoction
*** name=Decoction
*** desc=Make the Decoction\nitem reset your\nmaterial usage
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80350740 880300EE 80351B44 880300EE 803530A0 880300EE 80352E54 880300EE 803515F4 880300EE 80351638 880300EE 80353220 880300EE 80352614 880300EE lbz r0, [r3 + 0x00EE]
80350744 2800000B 80351B48 2800000B 803530A4 2800000B 80352E58 2800000B 803515F8 2800000B 8035163C 2800000B 80353224 2800000B 80352618 2800000B cmplwi r0, 11
80350748 40820144 80351B4C 40820144 803530A8 40820144 80352E5C 40820144 803515FC 40820144 80351640 40820144 80353228 40820144 8035261C 40820144 bne +0x00000144 /* 80351740 */
@@ -288,19 +288,19 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Movement
*** name=Movement
*** desc=Allow backsteps and\nmovement when\nenemies are\nnearby
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801CF69C 48000014 801CFBB0 48000014 801D1CEC 48000014 801CFC7C 48000014 801CFAE0 48000014 801CFAE0 48000014 801CFCE0 48000014 801D019C 48000014 b +0x00000014 /* 801CFAF4 */
"Movement Patch" Part 2 (restores backstep functionality on certain movements)
Movement
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801CE7AC 4800000C 801CECC0 4800000C 801D0D10 4800000C 801CED8C 4800000C 801CEBF0 4800000C 801CEBF0 4800000C 801CEDF0 4800000C 801CF2AC 4800000C b +0x0000000C /* 801CEBFC */
Olga Flow Barta Bug Fix (makes barta work on ice weakness Olga Flow instead of damaging player)
BugFixes
*** name=Bug fixes
*** desc=Fix many minor\ngameplay, sound,\nand graphical bugs
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 8000D980 807C0000 lwz r3, [r28]
8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 8000D984 2C030013 cmpwi r3, 19
8000D988 40820008 8000D988 40820008 8000D988 40820008 8000D988 40820008 8000D988 40820008 8000D988 40820008 8000D988 40820008 8000D988 40820008 bne +0x00000008 /* 8000D990 */
@@ -310,7 +310,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Morfos Frozen Player Bug Fix (stops Morfos Laser multi-hitting when player is frozen)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000D9A0 C042FC78 8000D9A0 C042FC80 8000D9A0 C042FC80 8000D9A0 C042FC80 8000D9A0 C042FC88 8000D9A0 C042FC88 8000D9A0 C042FC88 8000D9A0 C042FC88 lfs f2, [r2 - 0x0378]
8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 8000D9A4 807E0030 lwz r3, [r30 + 0x0030]
8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 8000D9A8 70630020 andi. r3, r3, 0x0020
@@ -321,18 +321,18 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Tiny Grass Assassins Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
800BC750 48000010 800BCA58 48000010 800BCBD0 48000010 800BCB80 48000010 800BC9E8 48000010 800BC9E8 48000010 800BCB90 48000010 800BCB58 48000010 b +0x00000010 /* 800BC9F8 */
Bulclaw HP Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80091528 4800024D 80091814 4800024D 8009198C 4800024D 8009193C 4800024D 800917B4 4800024D 800917B4 4800024D 8009194C 4800024D 80091914 4800024D bl +0x0000024C /* 80091A00 */
8009152C B3C3032C 80091818 B3C3032C 80091990 B3C3032C 80091940 B3C3032C 800917B8 B3C3032C 800917B8 B3C3032C 80091950 B3C3032C 80091918 B3C3032C sth [r3 + 0x032C], r30
Control Tower: Delbiter Death SFX Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80301600 48000020 803025CC 48000020 80303A1C 48000020 803037D0 48000020 80301F58 48000020 80301F9C 48000020 8030398C 48000020 80302D64 48000020 b +0x00000020 /* 80301F78 */
80301604 3863A830 803025D0 3863A830 80303A20 3863A830 803037D4 3863A830 80301F5C 3863A830 80301FA0 3863A830 80303990 3863A830 80302D68 3863A830 subi r3, r3, 0x57D0
80301608 800DB98C 803025D4 800DB994 80303A24 800DB9B4 803037D8 800DB9B4 80301F60 800DB9A4 80301FA4 800DB9A4 80303994 800DB9C4 80302D6C 800DBA04 lwz r0, [r13 - 0x465C]
@@ -344,7 +344,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Weapon Attributes Patch (allows attributes to work on minibosses and Olga Flow)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F 8000C8C0 7000000F andi. r0, r0, 0x000F
8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F 8000C8C4 7000004F andi. r0, r0, 0x004F
8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 8000C8C8 2C000004 cmpwi r0, 4
@@ -354,34 +354,34 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Ruins Laser Fence SFX Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80166324 3C604005 801666D8 3C604005 80166848 3C604005 8016679C 3C604005 801666E0 3C604005 801666E0 3C604005 80166800 3C604005 80166CC4 3C604005 lis r3, 0x4005
80166328 4800009C 801666DC 4800009C 8016684C 4800009C 801667A0 4800009C 801666E4 4800009C 801666E4 4800009C 80166804 4800009C 80166CC8 4800009C b +0x0000009C /* 80166780 */
801663C0 4800001C 80166774 4800001C 801668E4 4800001C 80166838 4800001C 8016677C 4800001C 8016677C 4800001C 8016689C 4800001C 80166D60 4800001C b +0x0000001C /* 80166798 */
SFX Cancellation Distance Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
805CB608 46AFC800 805D5C08 46AFC800 805DD0A8 46AFC800 805DCE48 46AFC800 805CBF10 46AFC800 805D2F30 46AFC800 805DC750 46AFC800 805D8990 46AFC800 .invalid sc
805CB8A8 43480000 805D5EA8 43480000 805DD348 43480000 805DD0E8 43480000 805CC1B0 43480000 805D31D0 43480000 805DC9F0 43480000 805D8C30 43480000 bc 26, 8, +0x00000000 /* 805CC1B0 */
Foie SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8022E2A8 3880FF00 8022EC44 3880FF00 8022FB30 3880FF00 8022F8E4 3880FF00 8022EB64 3880FF00 8022EB64 3880FF00 8022FC18 3880FF00 8022F4B0 3880FF00 li r4, 0xFFFFFF00
8022E2D8 3880FE80 8022EC74 3880FE80 8022FB60 3880FE80 8022F914 3880FE80 8022EB94 3880FE80 8022EB94 3880FE80 8022FC48 3880FE80 8022F4E0 3880FE80 li r4, 0xFFFFFE80
8022E308 3880FDB0 8022ECA4 3880FDB0 8022FB90 3880FDB0 8022F944 3880FDB0 8022EBC4 3880FDB0 8022EBC4 3880FDB0 8022FC78 3880FDB0 8022F510 3880FDB0 li r4, 0xFFFFFDB0
Gifoie SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802300B8 3880FF00 80230A54 3880FF00 80231940 3880FF00 802316F4 3880FF00 80230974 3880FF00 80230974 3880FF00 80231A28 3880FF00 802312C0 3880FF00 li r4, 0xFFFFFF00
802300E8 3880FE80 80230A84 3880FE80 80231970 3880FE80 80231724 3880FE80 802309A4 3880FE80 802309A4 3880FE80 80231A58 3880FE80 802312F0 3880FE80 li r4, 0xFFFFFE80
80230118 3880FDB0 80230AB4 3880FDB0 802319A0 3880FDB0 80231754 3880FDB0 802309D4 3880FDB0 802309D4 3880FDB0 80231A88 3880FDB0 80231320 3880FDB0 li r4, 0xFFFFFDB0
Rafoie SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802365AC 3880FF00 80236F68 3880FF00 80237E54 3880FF00 80237C08 3880FF00 80236E88 3880FF00 80236E88 3880FF00 80237F3C 3880FF00 802377D4 3880FF00 li r4, 0xFFFFFF00
802365DC 3880FE80 80236F98 3880FE80 80237E84 3880FE80 80237C38 3880FE80 80236EB8 3880FE80 80236EB8 3880FE80 80237F6C 3880FE80 80237804 3880FE80 li r4, 0xFFFFFE80
8023660C 3880FDB0 80236FC8 3880FDB0 80237EB4 3880FDB0 80237C68 3880FDB0 80236EE8 3880FDB0 80236EE8 3880FDB0 80237F9C 3880FDB0 80237834 3880FDB0 li r4, 0xFFFFFDB0
@@ -391,79 +391,79 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Barta SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80229B54 3880FF00 8022A4F0 3880FF00 8022B3E0 3880FF00 8022B190 3880FF00 8022A410 3880FF00 8022A410 3880FF00 8022B4C4 3880FF00 8022AD5C 3880FF00 li r4, 0xFFFFFF00
80229B84 3880FE80 8022A520 3880FE80 8022B410 3880FE80 8022B1C0 3880FE80 8022A440 3880FE80 8022A440 3880FE80 8022B4F4 3880FE80 8022AD8C 3880FE80 li r4, 0xFFFFFE80
80229BB4 3880FDB0 8022A550 3880FDB0 8022B440 3880FDB0 8022B1F0 3880FDB0 8022A470 3880FDB0 8022A470 3880FDB0 8022B524 3880FDB0 8022ADBC 3880FDB0 li r4, 0xFFFFFDB0
Gibarta SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8022EAB4 3880FF00 8022F450 3880FF00 80230340 3880FF00 802300F0 3880FF00 8022F370 3880FF00 8022F370 3880FF00 80230424 3880FF00 8022FCBC 3880FF00 li r4, 0xFFFFFF00
8022EAE4 3880FE80 8022F480 3880FE80 80230370 3880FE80 80230120 3880FE80 8022F3A0 3880FE80 8022F3A0 3880FE80 80230454 3880FE80 8022FCEC 3880FE80 li r4, 0xFFFFFE80
8022EB14 3880FDB0 8022F4B0 3880FDB0 802303A0 3880FDB0 80230150 3880FDB0 8022F3D0 3880FDB0 8022F3D0 3880FDB0 80230484 3880FDB0 8022FD1C 3880FDB0 li r4, 0xFFFFFDB0
Rabarta SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80235DD4 3880FF00 80236790 3880FF00 8023767C 3880FF00 80237430 3880FF00 802366B0 3880FF00 802366B0 3880FF00 80237764 3880FF00 80236FFC 3880FF00 li r4, 0xFFFFFF00
80235E10 3880FE80 802367CC 3880FE80 802376B8 3880FE80 8023746C 3880FE80 802366EC 3880FE80 802366EC 3880FE80 802377A0 3880FE80 80237038 3880FE80 li r4, 0xFFFFFE80
80235E4C 3880FDB0 80236808 3880FDB0 802376F4 3880FDB0 802374A8 3880FDB0 80236728 3880FDB0 80236728 3880FDB0 802377DC 3880FDB0 80237074 3880FDB0 li r4, 0xFFFFFDB0
Zonde SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8023B2C8 3880FF00 8023BC84 3880FF00 8023CB70 3880FF00 8023C924 3880FF00 8023BBA4 3880FF00 8023BBA4 3880FF00 8023CC58 3880FF00 8023C4F0 3880FF00 li r4, 0xFFFFFF00
8023B2F8 3880FE80 8023BCB4 3880FE80 8023CBA0 3880FE80 8023C954 3880FE80 8023BBD4 3880FE80 8023BBD4 3880FE80 8023CC88 3880FE80 8023C520 3880FE80 li r4, 0xFFFFFE80
8023B328 3880FDB0 8023BCE4 3880FDB0 8023CBD0 3880FDB0 8023C984 3880FDB0 8023BC04 3880FDB0 8023BC04 3880FDB0 8023CCB8 3880FDB0 8023C550 3880FDB0 li r4, 0xFFFFFDB0
Gizonde SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80230E08 3880FF00 802317C4 3880FF00 802326B0 3880FF00 80232464 3880FF00 802316E4 3880FF00 802316E4 3880FF00 80232798 3880FF00 80232030 3880FF00 li r4, 0xFFFFFF00
80230E38 3880FE80 802317F4 3880FE80 802326E0 3880FE80 80232494 3880FE80 80231714 3880FE80 80231714 3880FE80 802327C8 3880FE80 80232060 3880FE80 li r4, 0xFFFFFE80
80230E68 3880FDB0 80231824 3880FDB0 80232710 3880FDB0 802324C4 3880FDB0 80231744 3880FDB0 80231744 3880FDB0 802327F8 3880FDB0 80232090 3880FDB0 li r4, 0xFFFFFDB0
Razonde SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80237998 3880FF00 80238354 3880FF00 80239240 3880FF00 80238FF4 3880FF00 80238274 3880FF00 80238274 3880FF00 80239328 3880FF00 80238BC0 3880FF00 li r4, 0xFFFFFF00
802379C8 3880FE80 80238384 3880FE80 80239270 3880FE80 80239024 3880FE80 802382A4 3880FE80 802382A4 3880FE80 80239358 3880FE80 80238BF0 3880FE80 li r4, 0xFFFFFE80
802379F8 3880FDB0 802383B4 3880FDB0 802392A0 3880FDB0 80239054 3880FDB0 802382D4 3880FDB0 802382D4 3880FDB0 80239388 3880FDB0 80238C20 3880FDB0 li r4, 0xFFFFFDB0
Grants SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802316FC 3880FF00 802320B8 3880FF00 80232FA4 3880FF00 80232D58 3880FF00 80231FD8 3880FF00 80231FD8 3880FF00 8023308C 3880FF00 80232924 3880FF00 li r4, 0xFFFFFF00
80231734 3880FE80 802320F0 3880FE80 80232FDC 3880FE80 80232D90 3880FE80 80232010 3880FE80 80232010 3880FE80 802330C4 3880FE80 8023295C 3880FE80 li r4, 0xFFFFFE80
8023176C 3880FDB0 80232128 3880FDB0 80233014 3880FDB0 80232DC8 3880FDB0 80232048 3880FDB0 80232048 3880FDB0 802330FC 3880FDB0 80232994 3880FDB0 li r4, 0xFFFFFDB0
Megid SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802337A8 3880FF00 80234164 3880FF00 80235050 3880FF00 80234E04 3880FF00 80234084 3880FF00 80234084 3880FF00 80235138 3880FF00 802349D0 3880FF00 li r4, 0xFFFFFF00
802337D8 3880FE80 80234194 3880FE80 80235080 3880FE80 80234E34 3880FE80 802340B4 3880FE80 802340B4 3880FE80 80235168 3880FE80 80234A00 3880FE80 li r4, 0xFFFFFE80
80233808 3880FDB0 802341C4 3880FDB0 802350B0 3880FDB0 80234E64 3880FDB0 802340E4 3880FDB0 802340E4 3880FDB0 80235198 3880FDB0 80234A30 3880FDB0 li r4, 0xFFFFFDB0
Anti SFX Pitch Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80229354 2C000001 80229CF0 2C000001 8022ABDC 2C000001 8022A990 2C000001 80229C10 2C000001 80229C10 2C000001 8022ACC4 2C000001 8022A55C 2C000001 cmpwi r0, 1
Shield DFP/EVP Bug Fix (allows shields to reach true max DFP/EVP values)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801185B0 88040016 801187CC 88040016 8011885C 88040016 80118764 88040016 80118854 88040016 80118854 88040016 80118774 88040016 8011894C 88040016 lbz r0, [r4 + 0x0016]
801185BC 88040017 801187D8 88040017 80118868 88040017 80118770 88040017 80118860 88040017 80118860 88040017 80118780 88040017 80118958 88040017 lbz r0, [r4 + 0x0017]
VR Spaceship Item Drop Bug Fix (allows items to drop from enemies above a certain Y position)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
805C996C 435C0000 805D3F6C 435C0000 805DB40C 435C0000 805DB1AC 435C0000 805CA274 435C0000 805D1294 435C0000 805DAAB4 435C0000 805D6CF4 435C0000 bc 26, 28, +0x00000000 /* 805CA274 */
Invalid Items Bug Fix (something to do with making invalid items correctly display as ???? I think)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8011CA90 7C030378 8011CCD4 7C030378 8011CD0C 7C030378 8011CC6C 7C030378 8011CD34 7C030378 8011CD34 7C030378 8011CC7C 7C030378 8011CE54 7C030378 mr r3, r0
8011CA94 3863FFFF 8011CCD8 3863FFFF 8011CD10 3863FFFF 8011CC70 3863FFFF 8011CD38 3863FFFF 8011CD38 3863FFFF 8011CC80 3863FFFF 8011CE58 3863FFFF subi r3, r3, 0x0001
8011CA98 4BFFFFE8 8011CCDC 4BFFFFE8 8011CD14 4BFFFFE8 8011CC74 4BFFFFE8 8011CD3C 4BFFFFE8 8011CD3C 4BFFFFE8 8011CC84 4BFFFFE8 8011CE5C 4BFFFFE8 b -0x00000018 /* 8011CD24 */
@@ -476,7 +476,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Item Removal Maxed Stats Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 8000B088 7FA3EB78 mr r3, r29
8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 8000B08C 38800000 li r4, 0x0000
8000B090 481AE725 8000B090 481AEB91 8000B090 481B1C09 8000B090 481AEC5D 8000B090 481AEB11 8000B090 481AEB11 8000B090 481AECC1 8000B090 481AF17D bl +0x001AEB10 /* 801B9BA0 */
@@ -537,7 +537,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Unit Present Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C640 54800673 8000C640 54800673 8000C640 54800673 8000C640 54800673 8000C640 54800673 8000C640 54800673 8000C640 54800673 8000C640 54800673 rlwinm. r0, r4, 0, 25, 25
8000C644 41820008 8000C644 41820008 8000C644 41820008 8000C644 41820008 8000C644 41820008 8000C644 41820008 8000C644 41820008 8000C644 41820008 beq +0x00000008 /* 8000C64C */
8000C648 38800000 8000C648 38800000 8000C648 38800000 8000C648 38800000 8000C648 38800000 8000C648 38800000 8000C648 38800000 8000C648 38800000 li r4, 0x0000
@@ -547,7 +547,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Bank Item Stacking Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 8000C6D0 38000001 li r0, 0x0001
8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 8000C6D4 901D0054 stw [r29 + 0x0054], r0
8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 8000C6D8 807D0024 lwz r3, [r29 + 0x0024]
@@ -561,28 +561,28 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Dropped Mag Colour Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80114378 38000012 8011458C 38000012 80114634 38000012 80114524 38000012 8011461C 38000012 8011461C 38000012 80114534 38000012 8011470C 38000012 li r0, 0x0012
Meseta Drop System Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80107478 4800000C 80107654 4800000C 80107708 4800000C 801075D4 4800000C 8010771C 4800000C 8010771C 4800000C 801075E4 4800000C 801077D4 4800000C b +0x0000000C /* 80107728 */
8010748C 7C030378 80107668 7C030378 8010771C 7C030378 801075E8 7C030378 80107730 7C030378 80107730 7C030378 801075F8 7C030378 801077E8 7C030378 mr r3, r0
Present Colour Bug Fix (TODO: which versions need this?)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80101C14 60000000 60000000 60000000 60000000 80101EB8 60000000 80101EB8 60000000 60000000 60000000 nop
Offline Quests Drop Table Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80104B48 4182000C 80104D24 4182000C 80104DE0 4182000C 80104CA4 4182000C 80104DEC 4182000C 80104DEC 4182000C 80104CB4 4182000C 80104EA4 4182000C beq +0x0000000C /* 80104DF8 */
Mag Revival Priority Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A 8000C8A0 1C00000A mulli r0, r0, 10
8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD 8000C8A4 57E407BD rlwinm. r4, r31, 0, 30, 30
8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 8000C8A8 41820008 beq +0x00000008 /* 8000C8B0 */
@@ -592,22 +592,22 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Mag Revival Challenge & Quest Mode Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801CA1F4 48000010 801CA6E0 48000010 801CB5EC 48000010 801CA7AC 48000010 801CA610 48000010 801CA610 48000010 801CA810 48000010 801CACCC 48000010 b +0x00000010 /* 801CA620 */
Chat Bubble Window TAB Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80250264 60000000 80250CB0 60000000 80251CA4 60000000 802519A4 60000000 80250AEC 60000000 80250AEC 60000000 80251C68 60000000 802514B0 60000000 nop
Chat Log Window LF/Tab Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80267DDC 60000000 80268A88 60000000 80269AE4 60000000 80269898 60000000 80268788 60000000 80268788 60000000 80269B5C 60000000 802693A4 60000000 nop
Dark/Hell Special GFX Bug Fix (makes Dark/Hell display graphic on success like in PSO BB)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 8000E1E0 7FC802A6 mflr r30
8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 8000E1E4 38A00000 li r5, 0x0000
8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E 8000E1E8 38C0001E li r6, 0x001E
@@ -622,18 +622,18 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Gol Dragon Camera Bug Fix (makes the camera after Gol Dragon display "normally")
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802FB99C 2C030001 802FC968 2C030001 802FDE60 2C030001 802FDB6C 2C030001 802FC2F4 2C030001 802FC338 2C030001 802FDD28 2C030001 802FD100 2C030001 cmpwi r3, 1
Box/Fence Fadeout Bug Fix (stops boxes and other environmental objects fading in and out as you approach)
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80189A54 60000000 80189E2C 60000000 80189F90 60000000 80189EF0 60000000 80189E20 60000000 80189E20 60000000 80189F54 60000000 8018A418 60000000 nop
801933DC 60000000 801937B0 60000000 80193914 60000000 80193874 60000000 801937A8 60000000 801937A8 60000000 801938D8 60000000 80193D9C 60000000 nop
TP Bar Colour Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8026DA74 3884AAFA 8026E738 3884AAFA 8026F794 3884AAFA 8026F548 3884AAFA 8026E2D4 3884AAFA 8026E2D4 3884AAFA 8026F6FC 3884AAFA 8026EF44 3884AAFA subi r4, r4, 0x5506
8026DB88 3863AAFA 8026E84C 3863AAFA 8026F8A8 3863AAFA 8026F65C 3863AAFA 8026E3E8 3863AAFA 8026E3E8 3863AAFA 8026F810 3863AAFA 8026F058 3863AAFA subi r3, r3, 0x5506
8026DC10 3883AAFA 8026E8D4 3883AAFA 8026F930 3883AAFA 8026F6E4 3883AAFA 8026E470 3883AAFA 8026E470 3883AAFA 8026F898 3883AAFA 8026F0E0 3883AAFA subi r4, r3, 0x5506
@@ -641,12 +641,12 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Devil's and Demon's Special Damage Display Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8001306C 4BFFFCC0 8001309C 4BFFFCC0 80013364 4BFFFCC0 8001304C 4BFFFCC0 80013084 4BFFFCC0 80013084 4BFFFCC0 8001304C 4BFFFCC0 800130C4 4BFFFCC0 b -0x00000340 /* 80012D44 */
Christmas Trees Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 8000B5C8 80630098 lwz r3, [r3 + 0x0098]
8000B5CC 483D46F5 8000B5CC 483D70D1 8000B5CC 483D8F71 8000B5CC 483D8D21 8000B5CC 483D5999 8000B5CC 483D59F1 8000B5CC 483D90F1 8000B5CC 483D7BE1 bl +0x003D5998 /* 803E0F64 */
8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C 8000B5D0 807F042C lwz r3, [r31 + 0x042C]
@@ -657,25 +657,25 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Rain Drops Colour Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
804B3738 70808080 804B6E58 70808080 804B92F8 70808080 804B90B8 70808080 804B3EF0 70808080 804B43D0 70808080 804B8990 70808080 804B8E10 70808080 andi. r0, r4, 0x8080
804B373C 60707070 804B6E5C 60707070 804B92FC 60707070 804B90BC 60707070 804B3EF4 60707070 804B43D4 60707070 804B8994 60707070 804B8E14 60707070 ori r16, r3, 0x7070
Reverser Target Lock Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
801C5EA4 389F02FC 801C6360 389F02FC 801C6604 389F02FC 801C642C 389F02FC 801C62C0 389F02FC 801C62C0 389F02FC 801C6490 389F02FC 801C694C 389F02FC addi r4, r31, 0x02FC
Deband/Shifta/Resta Target Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8022CF84 41810630 8022D920 41810630 8022E85C 41810630 8022E5C0 41810630 8022D840 41810630 8022D840 41810630 8022E8F4 41810630 8022E18C 41810630 bgt +0x00000630 /* 8022DE70 */
8022D278 4181033C 4181033C 4181033C 4181033C 8022DB34 4181033C 8022DB34 4181033C 4181033C 4181033C bgt +0x0000033C /* 8022DE70 */
8022D36C 41810248 41810248 41810248 41810248 8022DC28 41810248 8022DC28 41810248 41810248 41810248 bgt +0x00000248 /* 8022DE70 */
Tech Auto Targetting Bug Fix
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8022C850 60000000 8022D1EC 60000000 8022E128 60000000 8022DE8C 60000000 8022D10C 60000000 8022D10C 60000000 8022E1C0 60000000 8022DA58 60000000 nop
804C6EE4 0000001E 804CA61C 0000001E 804CCB6C 0000001E 804CC90C 0000001E 804C76B4 0000001E 804C7B94 0000001E 804CC1E4 0000001E 804CC5D4 0000001E .invalid
804C6F3C 00000028 804CA674 00000028 804CCBC4 00000028 804CC964 00000028 804C770C 00000028 804C7BEC 00000028 804CC23C 00000028 804CC62C 00000028 .invalid
@@ -686,7 +686,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Enable Trap Animations
BugFixes
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 8000BBD0 809F0370 lwz r4, [r31 + 0x0370]
8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 8000BBD4 3884FC00 subi r4, r4, 0x0400
8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 8000BBD8 909F0370 stw [r31 + 0x0370], r4
@@ -702,12 +702,12 @@ Extended Word Select
ChatFeatures
*** name=Chat
*** desc=Enable extended\nWord Select and\nstop the Log Window\nfrom scrolling by\nholding L+R
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8034445C 38600000 803457AC 38600000 80346CCC 38600000 80346A80 38600000 8034525C 38600000 803452A0 38600000 80346E4C 38600000 8034627C 38600000 li r3, 0x0000
Chat Log Window: Lock Scrolling with L+R
ChatFeatures
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 8000D6A0 3C608051 lis r3, 0x8051
8000D6A4 A0638AD0 8000D6A4 A063C590 8000D6A4 A063EBD0 8000D6A4 A063E970 8000D6A4 A06393B0 8000D6A4 A0639890 8000D6A4 A063E270 8000D6A4 A063F290 lhz r3, [r3 - 0x6C50]
8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 8000D6A8 70600003 andi. r0, r3, 0x0003
@@ -721,7 +721,7 @@ Improved Draw Distance of most objects
Draw Distance
*** name=Draw Distance
*** desc=Extend the draw\ndistance of many\nobjects
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C200 8000DFA0 C3C2C200 8000DFA0 C3C2C200 8000DFA0 C3C2C200 lfs f30, [r2 - 0x3E00]
8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 8000DFA4 EFDE0072 fmuls f30, f30, f1
8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 8000DFA8 4E800020 blr
@@ -739,7 +739,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
8000DFD8 3C60804C 8000DFD8 3C60804C 8000DFD8 3C60804D 8000DFD8 3C60804D 8000DFD8 3C60804C 8000DFD8 3C60804C 8000DFD8 3C60804D 8000DFD8 3C60804D lis r3, 0x804C
8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 8000DFDC 4E800020 blr
801008E8 4BF0D6B9 80100AD0 4BF0D4D1 80100B74 4BF0D42D 80100A50 4BF0D551 80100B8C 4BF0D415 80100B8C 4BF0D415 80100A60 4BF0D541 80100C50 4BF0D351 bl -0x000F2BEC /* 8000DFA0 */
80156D00 4BEB72AD 801570B4 4BEB6EF9 80157218 4BEB6D95 80157178 4BEB6E35 801570BC 4BEB6EF1 801570BC 4BEB6EF1 801571DC 4BEB6DD1 801576A0 4BEB690D bl -0x00149110 /* 8000DFAC */
8015671C 4BEB7891 80156AD0 4BEB74DD 80156C34 4BEB7379 80156B94 4BEB7419 80156AD8 4BEB74D5 80156AD8 4BEB74D5 80156BF8 4BEB73B5 801570BC 4BEB6EF1 bl -0x00148C4C /* 8000DFAC */
801A1C64 4BE6C359 801A203C 4BE6BF81 801A21A0 4BE6BE1D 801A2100 4BE6BEBD 801A2040 4BE6BF7D 801A2040 4BE6BF7D 801A2164 4BE6BE59 801A2628 4BE6B995 bl -0x00194084 /* 8000DFBC */
801A1E64 4BE6C13D 801A223C 4BE6BD65 801A23A0 4BE6BC01 801A2300 4BE6BCA1 801A2240 4BE6BD61 801A2240 4BE6BD61 801A2364 4BE6BC3D 801A2828 4BE6B779 bl -0x001942A0 /* 8000DFA0 */
80205044 4BE08F85 802058B8 4BE08711 80206640 4BE07989 802063F4 4BE07BD5 80205840 4BE08789 80205840 4BE08789 80206728 4BE078A1 80206124 4BE07EA5 bl -0x001F7878 /* 8000DFC8 */
@@ -754,7 +754,7 @@ Show Enemy HP Bars
EnemyHPBars
*** name=Enemy HP bars
*** desc=Show HP bars in\nenemy info windows
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US12)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US12)
802612C4 4BFE1541 80261E9C 4BFE1349 80262EE4 4BFE0665 80262C98 4BFE1241 80261B9C 4BFE1545 80261B9C 4BFE1545 80262F5C 4BFE12B1 802627A4 4BFE12B1 bl -0x0001EABC /* 802430E0 */
804CAF00 42780000 804CE650 42780000 804D0BA0 42780000 804D0940 42780000 804CB6D0 42780000 804CBBB0 42780000 804D0218 42780000 804D0608 42780000
804CAF1C FF00FF15 804CE66C FF00FF15 804D0BBC FF00FF15 804D095C FF00FF15 804CB6EC FF00FF15 804CBBCC FF00FF15 804D0234 FF00FF15 804D0624 FF00FF15
@@ -798,7 +798,7 @@ PSO DC Reticle Colours
DCReticleColors
*** name=DC targets
*** desc=Change the target\nreticle colors to\nthose used on the\nDreamcast
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802AB3FC 3C8000FF 802AC2A4 3C8000FF 802AD3D0 3C8000FF 802AD184 3C8000FF 802ABDB8 3C8000FF 802ABDFC 3C8000FF 802AD338 3C8000FF 802ACACC 3C8000FF lis r4, 0x00FF
802AB410 388000FF 802AC2B8 388000FF 802AD3E4 388000FF 802AD198 388000FF 802ABDCC 388000FF 802ABE10 388000FF 802AD34C 388000FF 802ACAE0 388000FF li r4, 0x00FF
802AB424 3884FF00 802AC2CC 3884FF00 802AD3F8 3884FF00 802AD1AC 3884FF00 802ABDE0 3884FF00 802ABE24 3884FF00 802AD360 3884FF00 802ACAF4 3884FF00 subi r4, r4, 0x0100
@@ -819,7 +819,7 @@ PSOX / BB Reticle Colours
PSOXReticleColors
*** name=Xbox/BB targets
*** desc=Change the target\nreticle colors to\nthose used on the\nXbox and Blue Burst
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
802AB424 388000FF 802AC2CC 388000FF 802AD3F8 388000FF 802AD1AC 388000FF 802ABDE0 388000FF 802ABE24 388000FF 802AD360 388000FF 802ACAF4 388000FF li r4, 0x00FF
804A1F38 00000000 804A5658 00000000 804A7AF8 00000000 804A78B8 00000000 804A26E8 00000000 804A2BC8 00000000 804A7188 00000000 804A7608 00000000 .invalid
804A1F3C 00000000 804A565C 00000000 804A7AFC 00000000 804A78BC 00000000 804A26EC 00000000 804A2BCC 00000000 804A718C 00000000 804A760C 00000000 .invalid
@@ -829,7 +829,7 @@ Show Rare Items on Area & Radar Map
RareDropNotifications
*** name=Rare alerts
*** desc=Show rare items on\nthe map and play a\nsound when a rare\nitem drops
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF 8000C660 881F00EF lbz r0, [r31 + 0x00EF]
8000C664 28000004 8000C664 28000004 8000C664 28000004 8000C664 28000004 8000C664 28000004 8000C664 28000004 8000C664 28000004 8000C664 28000004 cmplwi r0, 4
8000C668 40820018 8000C668 40820018 8000C668 40820018 8000C668 40820018 8000C668 40820018 8000C668 40820018 8000C668 40820018 8000C668 40820018 bne +0x00000018 /* 8000C680 */
@@ -844,7 +844,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Rare Item Drops: Play SFX
RareDropNotifications
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000C690 28030000 8000C690 28030000 8000C690 28030000 8000C690 28030000 8000C690 28030000 8000C690 28030000 8000C690 28030000 8000C690 28030000 cmplwi r3, 0
8000C694 41820020 8000C694 41820020 8000C694 41820020 8000C694 41820020 8000C694 41820020 8000C694 41820020 8000C694 41820020 8000C694 41820020 beq +0x00000020 /* 8000C6B4 */
8000C698 880300EF 8000C698 880300EF 8000C698 880300EF 8000C698 880300EF 8000C698 880300EF 8000C698 880300EF 8000C698 880300EF 8000C698 880300EF lbz r0, [r3 + 0x00EF]
@@ -862,7 +862,7 @@ Play SFX for Hungry Mag
HungryMagSound
*** name=MAG alert
*** desc=Play a sound when\nyour MAG is hungry
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 8000BF30 9421FFF0 stwu [r1 - 0x0010], r1
8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 8000BF34 7C0802A6 mflr r0
8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 8000BF38 90010014 stw [r1 + 0x0014], r0
@@ -880,12 +880,12 @@ Invisible Mag
InvisibleMag
*** name=Invisible MAG
*** desc=Make MAGs invisible
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80114F04 480000D4 80115118 480000D4 8011521C 480000D4 801150B0 480000D4 801151A8 480000D4 801151A8 480000D4 801150C0 480000D4 80115298 480000D4 b +0x000000D4 /* 8011527C */
16:9 Aspect Ratio
169AspectRatioV1
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
80000088 C04210F0 80000088 C0421120 80000088 C0421130 80000088 C0421130 80000088 C0421108 80000088 C0421108 80000088 C0421138 80000088 C0421128 lfs f2, [r2 + 0x1108]
8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 8000008C EFBD00B2 fmuls f29, f29, f2
80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 80000090 FC40E890 fmr f2, f29
@@ -894,7 +894,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
16:9 Aspect Ratio V2
169AspectRatioV2
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 8000BE4C C01C0040 lfs f0, [r28 + 0x0040]
8000BE50 C062F7C0 8000BE50 C062F7C8 8000BE50 C062F7C8 8000BE50 C062F7C8 8000BE50 C062F7D0 8000BE50 C062F7D0 8000BE50 C062F7D0 8000BE50 C062F7D0 lfs f3, [r2 - 0x0830]
8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA 8000BE54 EC4100FA fmadds f2, f1, f0, f3
@@ -955,7 +955,7 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
Water & Light Effects Aspect Ratio Fix (for use with a 16:9 code)
169AmbientEffectsFix
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
3OJ2------------- 3OJ3------------- 3OJ4------------- 3OJ5------------- 3OE0------------- 3OE1------------- 3OE2------------- 3OP0------------- DISASSEMBLY (US10)
8000BDF0 C36210F0 8000BDF0 C3621120 8000BDF0 C3621130 8000BDF0 C3621130 8000BDF0 C3621108 8000BDF0 C3621108 8000BDF0 C3621138 8000BDF0 C3621128 lfs f27, [r2 + 0x1108]
8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 8000BDF4 EC4206F2 fmuls f2, f2, f27
8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 8000BDF8 FF601090 fmr f27, f2
+83 -40
View File
@@ -185,7 +185,7 @@ Account::Account(const phosg::JSON& json)
lic->gamertag = xb_gamertag;
lic->user_id = xb_user_id;
lic->account_id = xb_account_id;
this->xb_licenses.emplace(lic->gamertag, lic);
this->xb_licenses.emplace(lic->user_id, lic);
}
if (!bb_username.empty() && !bb_password.empty()) {
auto lic = make_shared<BBLicense>();
@@ -214,7 +214,7 @@ Account::Account(const phosg::JSON& json)
}
for (const auto& it : json.get_list("XBLicenses")) {
auto lic = XBLicense::from_json(*it);
this->xb_licenses.emplace(lic->gamertag, lic);
this->xb_licenses.emplace(lic->user_id, lic);
}
for (const auto& it : json.get_list("BBLicenses")) {
auto lic = BBLicense::from_json(*it);
@@ -291,8 +291,8 @@ phosg::JSON Account::json() const {
});
}
void Account::print(FILE* stream) const {
fprintf(stream, "Account: %010" PRIu32 "/%08" PRIX32 "\n", this->account_id, this->account_id);
string Account::str() const {
std::string ret = phosg::string_printf("Account: %010" PRIu32 "/%08" PRIX32 "\n", this->account_id, this->account_id);
if (this->flags) {
string flags_str = "";
@@ -339,7 +339,7 @@ void Account::print(FILE* stream) const {
} else if (phosg::ends_with(flags_str, ",")) {
flags_str.pop_back();
}
fprintf(stream, " Flags: %08" PRIX32 " (%s)\n", this->flags, flags_str.c_str());
ret += phosg::string_printf(" Flags: %08" PRIX32 " (%s)\n", this->flags, flags_str.c_str());
}
if (this->user_flags) {
@@ -352,53 +352,57 @@ void Account::print(FILE* stream) const {
} else if (phosg::ends_with(user_flags_str, ",")) {
user_flags_str.pop_back();
}
fprintf(stream, " User flags: %08" PRIX32 " (%s)\n", this->user_flags, user_flags_str.c_str());
ret += phosg::string_printf(" User flags: %08" PRIX32 " (%s)\n", this->user_flags, user_flags_str.c_str());
}
if (this->ban_end_time) {
string time_str = phosg::format_time(this->ban_end_time);
fprintf(stream, " Banned until: %" PRIu64 " (%s)\n", this->ban_end_time, time_str.c_str());
ret += phosg::string_printf(" Banned until: %" PRIu64 " (%s)\n", this->ban_end_time, time_str.c_str());
}
if (this->ep3_current_meseta || this->ep3_total_meseta_earned) {
fprintf(stream, " Episode 3 meseta: %" PRIu32 " (total earned: %" PRIu32 ")\n", this->ep3_current_meseta, this->ep3_total_meseta_earned);
ret += phosg::string_printf(" Episode 3 meseta: %" PRIu32 " (total earned: %" PRIu32 ")\n",
this->ep3_current_meseta, this->ep3_total_meseta_earned);
}
if (!this->last_player_name.empty()) {
fprintf(stream, " Last player name: \"%s\"\n", this->last_player_name.c_str());
ret += phosg::string_printf(" Last player name: \"%s\"\n", this->last_player_name.c_str());
}
if (!this->auto_reply_message.empty()) {
fprintf(stream, " Auto reply message: \"%s\"\n", this->auto_reply_message.c_str());
ret += phosg::string_printf(" Auto reply message: \"%s\"\n", this->auto_reply_message.c_str());
}
if (this->bb_team_id) {
fprintf(stream, " BB team ID: %08" PRIX32 "\n", this->bb_team_id);
ret += phosg::string_printf(" BB team ID: %08" PRIX32 "\n", this->bb_team_id);
}
if (this->is_temporary) {
fprintf(stream, " Is temporary license: true\n");
ret += phosg::string_printf(" Is temporary license: true\n");
}
for (const auto& it : this->dc_nte_licenses) {
fprintf(stream, " DC NTE license: serial_number=%s access_key=%s\n",
ret += phosg::string_printf(" DC NTE license: serial_number=%s access_key=%s\n",
it.second->serial_number.c_str(), it.second->access_key.c_str());
}
for (const auto& it : this->dc_licenses) {
fprintf(stream, " DC license: serial_number=%" PRIX32 " access_key=%s\n",
ret += phosg::string_printf(" DC license: serial_number=%" PRIX32 " access_key=%s\n",
it.second->serial_number, it.second->access_key.c_str());
}
for (const auto& it : this->pc_licenses) {
fprintf(stream, " PC license: serial_number=%" PRIX32 " access_key=%s\n",
ret += phosg::string_printf(" PC license: serial_number=%" PRIX32 " access_key=%s\n",
it.second->serial_number, it.second->access_key.c_str());
}
for (const auto& it : this->gc_licenses) {
fprintf(stream, " GC license: serial_number=%010" PRIu32 " access_key=%s password=%s\n",
ret += phosg::string_printf(" GC license: serial_number=%010" PRIu32 " access_key=%s password=%s\n",
it.second->serial_number, it.second->access_key.c_str(), it.second->password.c_str());
}
for (const auto& it : this->xb_licenses) {
fprintf(stream, " XB license: gamertag=%s user_id=%016" PRIX64 " account_id=%016" PRIX64 "\n",
ret += phosg::string_printf(" XB license: gamertag=%s user_id=%016" PRIX64 " account_id=%016" PRIX64 "\n",
it.second->gamertag.c_str(), it.second->user_id, it.second->account_id);
}
for (const auto& it : this->bb_licenses) {
fprintf(stream, " BB license: username=%s password=%s\n",
ret += phosg::string_printf(" BB license: username=%s password=%s\n",
it.second->username.c_str(), it.second->password.c_str());
}
phosg::strip_trailing_whitespace(ret);
return ret;
}
void Account::save() const {
@@ -415,6 +419,49 @@ void Account::delete_file() const {
remove(filename.c_str());
}
uint64_t Login::proxy_session_id() const {
uint64_t low_part = 0;
if (this->dc_nte_license) {
low_part = this->dc_nte_license->proxy_session_id_part();
} else if (this->dc_license) {
low_part = this->dc_license->proxy_session_id_part();
} else if (this->pc_license) {
low_part = this->pc_license->proxy_session_id_part();
} else if (this->gc_license) {
low_part = this->gc_license->proxy_session_id_part();
} else if (this->xb_license) {
low_part = this->xb_license->proxy_session_id_part();
} else if (this->bb_license) {
low_part = this->bb_license->proxy_session_id_part();
} else {
throw logic_error("none of the licenses in a Login were present");
}
return (static_cast<uint64_t>(this->account->account_id) << 32) | low_part;
}
string Login::str() const {
string ret = phosg::string_printf("Account:%08" PRIX32, this->account->account_id);
if (this->account_was_created) {
ret += " (new)";
}
if (this->dc_nte_license) {
ret += phosg::string_printf(" via DC NTE serial number %s", this->dc_nte_license->serial_number.c_str());
} else if (this->dc_license) {
ret += phosg::string_printf(" via DC serial number %08" PRIX32, this->dc_license->serial_number);
} else if (this->pc_license) {
ret += phosg::string_printf(" via PC serial number %08" PRIX32, this->pc_license->serial_number);
} else if (this->gc_license) {
ret += phosg::string_printf(" via GC serial number %010" PRIu32, this->gc_license->serial_number);
} else if (this->xb_license) {
ret += phosg::string_printf(" via XB user ID %016" PRIX64, this->xb_license->user_id);
} else if (this->bb_license) {
ret += phosg::string_printf(" via BB username %s", this->bb_license->username.c_str());
} else {
ret += phosg::string_printf(" artificially");
}
return ret;
}
size_t AccountIndex::count() const {
shared_lock g(this->lock);
return this->by_account_id.size();
@@ -660,14 +707,10 @@ shared_ptr<Login> AccountIndex::from_gc_credentials(
}
}
shared_ptr<Login> AccountIndex::from_xb_credentials_locked(const string& gamertag, uint64_t user_id, uint64_t account_id) {
shared_ptr<Login> AccountIndex::from_xb_credentials_locked(uint64_t user_id) {
auto login = make_shared<Login>();
login->account = this->by_xb_gamertag.at(gamertag);
login->xb_license = login->account->xb_licenses.at(gamertag);
if ((login->xb_license->user_id && (login->xb_license->user_id != user_id)) ||
(login->xb_license->account_id && (login->xb_license->account_id != account_id))) {
throw incorrect_access_key();
}
login->account = this->by_xb_user_id.at(user_id);
login->xb_license = login->account->xb_licenses.at(user_id);
if (login->account->ban_end_time && (login->account->ban_end_time >= phosg::now())) {
throw account_banned();
}
@@ -682,13 +725,13 @@ shared_ptr<Login> AccountIndex::from_xb_credentials(
try {
shared_lock g(this->lock);
return this->from_xb_credentials_locked(gamertag, user_id, account_id);
return this->from_xb_credentials_locked(user_id);
} catch (const out_of_range&) {
}
unique_lock g(this->lock);
try {
return this->from_xb_credentials_locked(gamertag, user_id, account_id);
return this->from_xb_credentials_locked(user_id);
} catch (const out_of_range&) {
}
@@ -701,7 +744,7 @@ shared_ptr<Login> AccountIndex::from_xb_credentials(
lic->gamertag = gamertag;
lic->user_id = user_id;
lic->account_id = account_id;
login->account->xb_licenses.emplace(lic->gamertag, lic);
login->account->xb_licenses.emplace(lic->user_id, lic);
login->xb_license = lic;
this->add_locked(login->account);
return login;
@@ -798,8 +841,8 @@ void AccountIndex::add_locked(shared_ptr<Account> a) {
}
}
for (const auto& it : a->xb_licenses) {
if (this->by_xb_gamertag.count(it.second->gamertag)) {
throw runtime_error("account already exists with this XB gamertag");
if (this->by_xb_user_id.count(it.second->user_id)) {
throw runtime_error("account already exists with this XB user ID");
}
}
for (const auto& it : a->bb_licenses) {
@@ -826,7 +869,7 @@ void AccountIndex::add_locked(shared_ptr<Account> a) {
this->by_gc_serial_number[it.second->serial_number] = a;
}
for (const auto& it : a->xb_licenses) {
this->by_xb_gamertag[it.second->gamertag] = a;
this->by_xb_user_id[it.second->user_id] = a;
}
for (const auto& it : a->bb_licenses) {
this->by_bb_username[it.second->username] = a;
@@ -855,7 +898,7 @@ void AccountIndex::remove(uint32_t account_id) {
this->by_gc_serial_number.erase(it.second->serial_number);
}
for (const auto& it : a->xb_licenses) {
this->by_xb_gamertag.erase(it.second->gamertag);
this->by_xb_user_id.erase(it.second->user_id);
}
for (const auto& it : a->bb_licenses) {
this->by_bb_username.erase(it.second->username);
@@ -903,12 +946,12 @@ void AccountIndex::add_gc_license(shared_ptr<Account> account, shared_ptr<GCLice
}
void AccountIndex::add_xb_license(shared_ptr<Account> account, shared_ptr<XBLicense> license) {
if (!this->by_xb_gamertag.emplace(license->gamertag, account).second) {
throw runtime_error("gamertag already registered");
if (!this->by_xb_user_id.emplace(license->user_id, account).second) {
throw runtime_error("user ID already registered");
}
if (!account->xb_licenses.emplace(license->gamertag, license).second) {
this->by_xb_gamertag.erase(license->gamertag);
throw logic_error("gamertag registered in account but not in account index");
if (!account->xb_licenses.emplace(license->user_id, license).second) {
this->by_xb_user_id.erase(license->user_id);
throw logic_error("user ID registered in account but not in account index");
}
}
@@ -966,12 +1009,12 @@ void AccountIndex::remove_gc_license(shared_ptr<Account> account, uint32_t seria
account->gc_licenses.erase(it);
}
void AccountIndex::remove_xb_license(shared_ptr<Account> account, const string& gamertag) {
auto it = account->xb_licenses.find(gamertag);
void AccountIndex::remove_xb_license(shared_ptr<Account> account, uint64_t user_id) {
auto it = account->xb_licenses.find(user_id);
if (it == account->xb_licenses.end()) {
throw runtime_error("license not registered to account");
}
if (!this->by_xb_gamertag.erase(it->second->gamertag)) {
if (!this->by_xb_user_id.erase(it->second->user_id)) {
throw runtime_error("license registered in account but not in account index");
}
account->xb_licenses.erase(it);
+30 -8
View File
@@ -2,6 +2,7 @@
#include <memory>
#include <mutex>
#include <phosg/Hash.hh>
#include <phosg/JSON.hh>
#include <shared_mutex>
#include <string>
@@ -16,6 +17,10 @@ struct DCNTELicense {
std::string serial_number;
std::string access_key;
inline uint64_t proxy_session_id_part() const {
return phosg::fnv1a32(this->serial_number);
}
static std::shared_ptr<DCNTELicense> from_json(const phosg::JSON& json);
phosg::JSON json() const;
};
@@ -24,6 +29,10 @@ struct V1V2License {
uint32_t serial_number = 0;
std::string access_key;
inline uint64_t proxy_session_id_part() const {
return this->serial_number;
}
static std::shared_ptr<V1V2License> from_json(const phosg::JSON& json);
phosg::JSON json() const;
};
@@ -33,6 +42,10 @@ struct GCLicense {
std::string access_key;
std::string password;
inline uint64_t proxy_session_id_part() const {
return this->serial_number;
}
static std::shared_ptr<GCLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const;
};
@@ -42,6 +55,10 @@ struct XBLicense {
uint64_t user_id = 0;
uint64_t account_id = 0;
inline uint64_t proxy_session_id_part() const {
return phosg::fnv1a32(this->gamertag);
}
static std::shared_ptr<XBLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const;
};
@@ -50,6 +67,10 @@ struct BBLicense {
std::string username;
std::string password;
inline uint64_t proxy_session_id_part() const {
return phosg::fnv1a32(this->username);
}
static std::shared_ptr<BBLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const;
};
@@ -101,7 +122,7 @@ struct Account {
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> dc_licenses;
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> pc_licenses;
std::unordered_map<uint32_t, std::shared_ptr<GCLicense>> gc_licenses;
std::unordered_map<std::string, std::shared_ptr<XBLicense>> xb_licenses;
std::unordered_map<uint64_t, std::shared_ptr<XBLicense>> xb_licenses;
std::unordered_map<std::string, std::shared_ptr<BBLicense>> bb_licenses;
Account() = default;
@@ -141,7 +162,7 @@ struct Account {
this->user_flags ^= static_cast<uint32_t>(flag);
}
void print(FILE* stream) const;
std::string str() const;
};
struct Login {
@@ -156,6 +177,10 @@ struct Login {
std::shared_ptr<GCLicense> gc_license;
std::shared_ptr<XBLicense> xb_license;
std::shared_ptr<BBLicense> bb_license;
uint64_t proxy_session_id() const;
std::string str() const;
};
class AccountIndex {
@@ -202,7 +227,7 @@ public:
void remove_dc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_pc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_gc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_xb_license(std::shared_ptr<Account> account, const std::string& gamertag);
void remove_xb_license(std::shared_ptr<Account> account, uint64_t user_id);
void remove_bb_license(std::shared_ptr<Account> account, const std::string& username);
std::shared_ptr<Account> from_account_id(uint32_t account_id) const;
@@ -253,7 +278,7 @@ protected:
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_dc_serial_number;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_pc_serial_number;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_gc_serial_number;
std::unordered_map<std::string, std::shared_ptr<Account>> by_xb_gamertag;
std::unordered_map<uint64_t, std::shared_ptr<Account>> by_xb_user_id;
std::unordered_map<std::string, std::shared_ptr<Account>> by_bb_username;
void add_locked(std::shared_ptr<Account> a);
@@ -274,10 +299,7 @@ protected:
const std::string& access_key,
const std::string* password,
const std::string& character_name);
std::shared_ptr<Login> from_xb_credentials_locked(
const std::string& gamertag,
uint64_t user_id,
uint64_t account_id);
std::shared_ptr<Login> from_xb_credentials_locked(uint64_t user_id);
std::shared_ptr<Login> from_bb_credentials_locked(
const std::string& username,
const std::string* password);
+11 -1
View File
@@ -5,10 +5,20 @@
#include <utility>
#include <vector>
struct DiffEntry {
uint32_t address;
std::string a_data;
std::string b_data;
};
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
inline std::vector<DiffEntry> diff_dol_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<DiffEntry> diff_xbe_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
+191 -13
View File
@@ -5,6 +5,7 @@
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <resource_file/ExecutableFormats/DOLFile.hh>
#include <resource_file/ExecutableFormats/PEFile.hh>
#include <resource_file/ExecutableFormats/XBEFile.hh>
using namespace std;
@@ -112,9 +113,13 @@ public:
this->directory.pop_back();
}
for (const auto& filename : phosg::list_directory(this->directory)) {
if (filename.size() < 4) {
continue;
}
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
if (phosg::ends_with(filename, ".dol")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
ResourceDASM::DOLFile dol(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
dol.load_into(mem);
@@ -122,16 +127,18 @@ public:
this->enable_ppc = true;
this->log.info("Loaded %s", name.c_str());
} else if (phosg::ends_with(filename, ".xbe")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
ResourceDASM::XBEFile xbe(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
xbe.load_into(mem);
this->mems.emplace(name, mem);
this->log.info("Loaded %s", name.c_str());
} else if (phosg::ends_with(filename, ".exe")) {
ResourceDASM::PEFile pe(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
pe.load_into(mem);
this->mems.emplace(name, mem);
this->log.info("Loaded %s", name.c_str());
} else if (phosg::ends_with(filename, ".bin")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
string data = phosg::load_file(path);
auto mem = make_shared<ResourceDASM::MemoryContext>();
mem->allocate_at(0x8C010000, data.size());
@@ -246,8 +253,8 @@ public:
phosg::StringReader src_r = this->src_mem->reader(src_section.first + src_offset - match_bytes_before, match_length);
for (const auto& dest_section : dest_mem->allocated_blocks()) {
for (size_t dest_match_offset = 0;
dest_match_offset + match_length < dest_section.second;
dest_match_offset += (is_ppc ? 4 : 1)) {
dest_match_offset + match_length < dest_section.second;
dest_match_offset += (is_ppc ? 4 : 1)) {
src_r.go(0);
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
size_t z;
@@ -428,6 +435,127 @@ public:
}
}
uint32_t find_be_to_le_data_match(
shared_ptr<const ResourceDASM::MemoryContext> dest_mem,
uint32_t src_addr,
uint32_t src_size) const {
if (src_size == 0) {
src_size = 4;
}
pair<uint32_t, uint32_t> src_section = make_pair(0, 0);
for (const auto& sec : this->src_mem->allocated_blocks()) {
if (src_addr >= sec.first && src_addr + src_size <= sec.first + sec.second) {
src_section = sec;
break;
}
}
if (!src_section.second) {
throw runtime_error("source address not within any section");
}
size_t src_offset = src_addr - src_section.first;
size_t src_bytes_available_before = src_offset;
size_t src_bytes_available_after = src_section.second - src_offset - 4;
size_t match_bytes_before = 0;
size_t match_bytes_after = 0;
while (match_bytes_before + match_bytes_after + 4 < 0x100) {
size_t num_matches = 0;
size_t last_match_address = 0;
size_t match_length = match_bytes_before + match_bytes_after + 4;
uint32_t src_addr = src_section.first + src_offset - match_bytes_before;
phosg::StringReader src_r = this->src_mem->reader(src_addr, match_length);
for (const auto& dest_section : dest_mem->allocated_blocks()) {
for (size_t dest_match_offset = 0;
dest_match_offset + match_length < dest_section.second;
dest_match_offset += 4) {
src_r.go(0);
phosg::StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
size_t z;
for (z = 0; z < match_length; z += 4) {
uint32_t src_v = src_r.get_u32b();
uint32_t dest_v = dest_r.get_u32l();
bool src_is_addr = ((src_v & 0xFE000003) == 0x80000000);
bool dest_is_addr = ((dest_v >= 0x00010000) && (dest_v <= 0x00800000));
if (src_is_addr != dest_is_addr) {
break;
} else if (src_v != dest_v) {
break;
}
}
if (z == match_length) {
num_matches++;
last_match_address = dest_section.first + dest_match_offset + match_bytes_before;
}
}
}
this->log.info("... For match length %zX, %zu matches found", match_length, num_matches);
if (num_matches == 1) {
return last_match_address;
} else if (num_matches == 0) {
throw runtime_error("did not find exactly one match");
}
bool can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
bool can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
if (!can_expand_backward && !can_expand_forward) {
throw runtime_error("no further expansion is allowed");
}
if (can_expand_backward) {
match_bytes_before += 4;
}
if (can_expand_forward) {
match_bytes_after += 4;
}
}
throw runtime_error("scan field too long; too many matches");
}
void find_all_be_to_le_data_matches(uint32_t src_addr, uint32_t src_size) const {
if (!this->src_mem) {
throw runtime_error("no source file selected");
}
map<string, uint32_t> results;
for (const auto& it : this->mems) {
if (it.second == this->src_mem) {
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
results.emplace(it.first, src_addr);
} else {
uint32_t ret = 0;
try {
ret = this->find_be_to_le_data_match(it.second, src_addr, src_size);
log.info("(%s) %08" PRIX32, it.first.c_str(), ret);
} catch (const exception& e) {
log.error("(%s) failed: %s", it.first.c_str(), e.what());
}
if (ret == 0) {
log.error("(%s) no match found", it.first.c_str());
} else {
results.emplace(it.first, ret);
}
}
}
for (const auto& it : results) {
fprintf(stdout, "%s => %08" PRIX32 "\n", it.first.c_str(), it.second);
}
}
void find_data(const std::string& data) const {
for (const auto& [name, mem] : this->mems) {
for (const auto& [sec_addr, sec_size] : mem->allocated_blocks()) {
uint32_t last_addr = sec_addr + sec_size - data.size();
for (uint32_t addr = sec_addr; addr < last_addr; addr++) {
if (!mem->memcmp(addr, data.data(), data.size())) {
fprintf(stderr, "%s => %08" PRIX32 "\n", name.c_str(), addr);
}
}
}
}
}
void handle_command(const string& command) {
auto tokens = phosg::split(command, ' ');
if (tokens.empty()) {
@@ -437,10 +565,16 @@ public:
if (tokens[0] == "use") {
this->set_source_file(tokens.at(1));
} else if (tokens[0] == "find") {
this->find_data(phosg::parse_data_string(tokens.at(1)));
} else if (tokens[0] == "match") {
this->find_all_matches(
stoul(tokens.at(1), nullptr, 16),
tokens.size() >= 3 ? stoul(tokens[2], nullptr, 16) : 0);
} else if (tokens[0] == "match-be-le") {
this->find_all_be_to_le_data_matches(
stoul(tokens.at(1), nullptr, 16),
tokens.size() >= 3 ? stoul(tokens[2], nullptr, 16) : 0);
} else if (tokens[0] == "find-ppc-globals") {
this->find_ppc_rtoc_global_regs();
} else if (!tokens[0].empty()) {
@@ -489,7 +623,7 @@ void run_address_translator(const std::string& directory, const std::string& use
}
}
vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const string& b_filename) {
vector<DiffEntry> diff_dol_files(const string& a_filename, const string& b_filename) {
ResourceDASM::DOLFile a(a_filename.c_str());
ResourceDASM::DOLFile b(b_filename.c_str());
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
@@ -508,7 +642,7 @@ vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const st
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
}
vector<pair<uint32_t, string>> ret;
vector<DiffEntry> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
bool a_exists = a_mem->exists(addr, 4);
bool b_exists = b_mem->exists(addr, 4);
@@ -516,10 +650,54 @@ vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const st
string a_value = a_mem->read(addr, 4);
string b_value = b_mem->read(addr, 4);
if (a_value != b_value) {
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
ret.back().second += b_value;
if (!ret.empty() && (ret.back().address + ret.back().b_data.size() == addr)) {
ret.back().a_data += a_value;
ret.back().b_data += b_value;
} else {
ret.emplace_back(make_pair(addr, b_value));
ret.emplace_back(DiffEntry{.address = addr, .a_data = a_value, .b_data = b_value});
}
}
}
}
return ret;
}
vector<DiffEntry> diff_xbe_files(const string& a_filename, const string& b_filename) {
ResourceDASM::XBEFile a(a_filename.c_str());
ResourceDASM::XBEFile b(b_filename.c_str());
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
auto b_mem = make_shared<ResourceDASM::MemoryContext>();
a.load_into(a_mem);
b.load_into(b_mem);
uint32_t min_addr = 0xFFFFFFFF;
uint32_t max_addr = 0x00000000;
for (const auto& sec : a.sections) {
min_addr = min<uint32_t>(min_addr, sec.addr);
max_addr = max<uint32_t>(max_addr, sec.addr + sec.size);
}
for (const auto& sec : b.sections) {
min_addr = min<uint32_t>(min_addr, sec.addr);
max_addr = max<uint32_t>(max_addr, sec.addr + sec.size);
}
vector<DiffEntry> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr++) {
bool a_exists = a_mem->exists(addr, 1);
bool b_exists = b_mem->exists(addr, 1);
if (a_exists && b_exists) {
uint8_t a_value = a_mem->read_u8(addr);
uint8_t b_value = b_mem->read_u8(addr);
if (a_value != b_value) {
if (!ret.empty() && (ret.back().address + ret.back().b_data.size() == addr)) {
auto& entry = ret.back();
entry.a_data.push_back(a_value);
entry.b_data.push_back(b_value);
} else {
auto& entry = ret.emplace_back();
entry.address = addr;
entry.a_data.push_back(a_value);
entry.b_data.push_back(b_value);
}
}
}
+8 -1
View File
@@ -6,5 +6,12 @@
#include <utility>
#include <vector>
struct DiffEntry {
uint32_t address;
std::string a_data;
std::string b_data;
};
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
std::vector<DiffEntry> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
std::vector<DiffEntry> diff_xbe_files(const std::string& a_filename, const std::string& b_filename);
+1 -1
View File
@@ -92,7 +92,7 @@ public:
private:
struct File {
std::shared_ptr<const std::string> data;
const Table* table;
const Table* table = nullptr;
};
// Indexed as [online/offline][episode]
+2 -2
View File
@@ -263,7 +263,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
size_t send_data_size = 0;
switch (this->version) {
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
case Version::GC_NTE:
@@ -274,7 +274,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
PSOCommandHeaderDCV3 header;
if (this->crypt_out.get() &&
(this->version != Version::DC_NTE) &&
(this->version != Version::DC_V1_11_2000_PROTOTYPE) &&
(this->version != Version::DC_11_2000) &&
(this->version != Version::DC_V1)) {
send_data_size = (sizeof(header) + size + 3) & ~3;
} else {
+2751 -2574
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -10,5 +10,5 @@
#include "ProxyServer.hh"
#include "ServerState.hh"
void on_chat_command(std::shared_ptr<Client> c, const std::string& text);
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::string& text);
void on_chat_command(std::shared_ptr<Client> c, const std::string& text, bool check_permissions);
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::string& text, bool check_permissions);
+1 -1
View File
@@ -108,7 +108,7 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
}
switch (target_c->version()) {
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
return (choice_id == 0x0001);
case Version::DC_V1:
return (choice_id == 0x0002);
+46 -18
View File
@@ -33,6 +33,7 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
this->set_flag(Flag::SAVE_ENABLED);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
return;
}
@@ -44,27 +45,30 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
this->set_flag(Flag::NO_D6);
break;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
this->set_flag(Flag::NO_D6);
break;
case Version::DC_V2:
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case Version::PC_NTE:
case Version::PC_V2:
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY);
// SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE not set here
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case Version::GC_NTE:
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
break;
case Version::GC_EP3_NTE:
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
break;
case Version::GC_V3:
@@ -76,6 +80,7 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
// TODO: Do all versions of XB need this flag? US does, at least.
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
default:
@@ -83,39 +88,44 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
}
break;
case 0x20: // DC NTE, 11/2000, possibly also DCv1 JP
case 0x20: // DC NTE, 11/2000, DCv1 JP
case 0x21: // DCv1 US
case 0x22: // DCv1 EU, 12/2000, and 01/2001, at 50Hz (presumably)
case 0x23: // DCv1 EU, 12/2000, and 01/2001, at 60Hz (presumably)
case 0x22: // DCv1 EU, 12/2000, and 01/2001, at 50Hz
case 0x23: // DCv1 EU, 12/2000, and 01/2001, at 60Hz
this->set_flag(Flag::NO_D6);
break;
case 0x25: // DCv2 JP
case 0x26: // DCv2 US and 08/2001
case 0x27: // DCv2 EU 50Hz (presumably)
case 0x28: // DCv2 EU 60Hz (presumably)
case 0x27: // DCv2 EU 50Hz
case 0x28: // DCv2 EU 60Hz
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case 0x29: // PC
case 0x29: // PCv2
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY);
// SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE not set here
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
this->set_flag(Flag::CAN_RECEIVE_ENABLE_B2_QUEST);
break;
case 0x30: // GC Ep1&2 GameJam demo, GC Ep1&2 Trial Edition, GC Ep1&2 JP v1.2, XB JP
case 0x31: // GC Ep1&2 US v1.0, GC US v1.1, XB US
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
break;
case 0x32: // GC Ep1&2 EU 50Hz
case 0x33: // GC Ep1&2 EU 60Hz
case 0x34: // GC Ep1&2 JP v1.3
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
break;
case 0x35: // GC Ep1&2 JP v1.4 (Plus)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
@@ -127,9 +137,10 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::CAN_RECEIVE_ENABLE_B2_QUEST);
break;
case 0x40: // GC Ep3 JP and Trial Edition (and BB)
case 0x40: // GC Ep3 JP and Trial Edition (and BB, but BB is handled above)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
// sub_version can't be used to tell JP final and Trial Edition apart; we
@@ -195,8 +206,6 @@ Client::Client(
bb_connection_phase(0xFF),
ping_start_time(0),
sub_version(-1),
x(0.0f),
z(0.0f),
floor(0),
lobby_client_id(0),
lobby_arrow_color(0),
@@ -274,10 +283,12 @@ void Client::update_channel_name() {
auto player = this->character(false, false);
if (player) {
string name_str = player->disp.name.decode(this->language());
this->channel.name = phosg::string_printf("C-%" PRIX64 " (%s) @ %s", this->id, name_str.c_str(), ip_str.c_str());
size_t level = player->disp.stats.level + 1;
this->channel.name = phosg::string_printf("C-%" PRIX64 " (%s Lv.%zu) @ %s", this->id, name_str.c_str(), level, ip_str.c_str());
} else {
this->channel.name = phosg::string_printf("C-%" PRIX64 " @ %s", this->id, ip_str.c_str());
}
this->log.info("Channel name updated from player data: %s", this->channel.name.c_str());
}
void Client::reschedule_save_game_data_event() {
@@ -405,6 +416,9 @@ bool Client::can_see_quest(
uint8_t difficulty,
size_t num_players,
bool v1_present) const {
if (!q->has_version_any_language(this->version())) {
return false;
}
return this->evaluate_quest_availability_expression(q->available_expression, game, event, difficulty, num_players, v1_present);
}
@@ -415,6 +429,12 @@ bool Client::can_play_quest(
uint8_t difficulty,
size_t num_players,
bool v1_present) const {
if (!q->has_version_any_language(this->version())) {
return false;
}
if (num_players >= q->max_players) {
return false;
}
return this->evaluate_quest_availability_expression(q->enabled_expression, game, event, difficulty, num_players, v1_present);
}
@@ -479,6 +499,14 @@ void Client::suspend_timeouts() {
this->log.info("Timeouts suspended");
}
void Client::set_login(shared_ptr<Login> login) {
this->login = login;
if (this->log.should_log(phosg::LogLevel::INFO)) {
string login_str = this->login->str();
this->log.info("Login: %s", login_str.c_str());
}
}
void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_ptr<const LevelTable> level_table) {
this->overlay_character_data = make_shared<PSOBBCharacterFile>(*this->character(true, false));
@@ -759,7 +787,7 @@ void Client::load_all_files() {
if (this->character_data) {
player_data_log.info("Using loaded character file %s", char_filename.c_str());
} else if (phosg::isfile(char_filename)) {
auto psochar = load_psochar(char_filename, !this->system_data);
auto psochar = PSOCHARFile::load_shared(char_filename, !this->system_data);
this->character_data = psochar.character_file;
files_manager->set_character(char_filename, this->character_data);
player_data_log.info("Loaded character data from %s", char_filename.c_str());
@@ -941,7 +969,7 @@ void Client::save_character_file(
const string& filename,
shared_ptr<const PSOBBBaseSystemFile> system,
shared_ptr<const PSOBBCharacterFile> character) {
save_psochar(filename, system, character);
PSOCHARFile::save(filename, system, character);
player_data_log.info("Saved character file %s", filename.c_str());
}
@@ -983,7 +1011,7 @@ void Client::save_guild_card_file() const {
void Client::load_backup_character(uint32_t account_id, size_t index) {
string filename = this->backup_character_filename(account_id, index, false);
this->character_data = load_psochar(filename, false).character_file;
this->character_data = PSOCHARFile::load_shared(filename, false).character_file;
this->update_character_data_after_load(this->character_data);
this->v1_v2_last_reported_disp.reset();
}
@@ -991,7 +1019,7 @@ void Client::load_backup_character(uint32_t account_id, size_t index) {
shared_ptr<PSOGCEp3CharacterFile::Character> Client::load_ep3_backup_character(uint32_t account_id, size_t index) {
string filename = this->backup_character_filename(account_id, index, true);
auto ch = make_shared<PSOGCEp3CharacterFile::Character>(phosg::load_object_file<PSOGCEp3CharacterFile::Character>(filename));
this->character_data = PSOBBCharacterFile::create_from_ep3(*ch);
this->character_data = PSOBBCharacterFile::create_from_file(*ch);
this->ep3_config = make_shared<Episode3::PlayerConfig>(ch->ep3_config);
this->update_character_data_after_load(this->character_data);
this->v1_v2_last_reported_disp.reset();
@@ -1071,7 +1099,7 @@ void Client::use_character_bank(int8_t index) {
this->external_bank_character_index = index;
player_data_log.info("Using loaded character file %s for external bank", filename.c_str());
} else if (phosg::isfile(filename)) {
this->external_bank_character = load_psochar(filename, false).character_file;
this->external_bank_character = PSOCHARFile::load_shared(filename, false).character_file;
this->update_character_data_after_load(this->external_bank_character);
this->external_bank_character_index = index;
files_manager->set_character(filename, this->external_bank_character);
+6 -9
View File
@@ -35,7 +35,7 @@ public:
// TODO: It'd be nice to use a pattern here (e.g. all server-side flags are
// in the high bits) but that would require re-recording or manually
// rewriting all the tests
CLIENT_SIDE_MASK = 0xE73CFFFF7C0BFFFB,
CLIENT_SIDE_MASK = 0xEF3CFFFF7C0BFFFB,
// Version-related flags
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
@@ -46,7 +46,7 @@ public:
// Flags describing the behavior for send_function_call
HAS_SEND_FUNCTION_CALL = 0x0000000000001000,
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE = 0x0000000000004000,
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
CAN_RECEIVE_ENABLE_B2_QUEST = 0x0000000000020000,
AWAITING_ENABLE_B2_QUEST = 0x0000000000040000, // Server-side only
@@ -81,7 +81,6 @@ public:
DEBUG_ENABLED = 0x0000000800000000,
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000,
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000,
FORCE_BATTLE_MODE_GAME = 0x0800000000000000, // Server-side only
// Proxy option flags
PROXY_SAVE_FILES = 0x0000001000000000,
@@ -206,10 +205,9 @@ public:
// Lobby/positioning
Config config;
Config synced_config;
std::unique_ptr<parray<le_uint32_t, 0x20>> override_variations;
std::unique_ptr<Variations> override_variations;
int32_t sub_version;
float x;
float z;
VectorXZF pos;
uint32_t floor;
std::weak_ptr<Lobby> lobby;
uint8_t lobby_client_id;
@@ -252,7 +250,7 @@ public:
std::unique_ptr<PendingItemTrade> pending_item_trade;
std::unique_ptr<PendingCardTrade> pending_card_trade;
uint32_t telepipe_lobby_id;
G_SetTelepipeState_6x68 telepipe_state;
TelepipeState telepipe_state;
std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3
int8_t bb_character_index;
ItemData bb_identify_result;
@@ -336,8 +334,7 @@ public:
void suspend_timeouts();
const std::string& get_bb_username() const;
void set_bb_username(const std::string& bb_username);
void set_login(std::shared_ptr<Login> login);
void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
+591 -601
View File
File diff suppressed because it is too large Load Diff
+136
View File
@@ -0,0 +1,136 @@
#pragma once
#include <phosg/Encoding.hh>
#include <phosg/Vector.hh>
#include "Text.hh"
struct VectorXZF {
le_float x = 0.0;
le_float z = 0.0;
inline VectorXZF operator-() const {
return VectorXZF{-this->x, -this->z};
}
inline VectorXZF operator+(const VectorXZF& other) const {
return VectorXZF{this->x + other.x, this->z + other.z};
}
inline VectorXZF operator-(const VectorXZF& other) const {
return VectorXZF{this->x - other.x, this->z - other.z};
}
inline bool operator==(const VectorXZF& other) const {
return ((this->x == other.x) && (this->z == other.z));
}
inline bool operator!=(const VectorXZF& other) const {
return !this->operator==(other);
}
inline double norm() const {
return sqrt(this->norm2());
}
inline double norm2() const {
return ((this->x * this->x) + (this->z * this->z));
}
inline std::string str() const {
return phosg::string_printf("[VectorXZF x=%g z=%g]", this->x.load(), this->z.load());
}
} __packed_ws__(VectorXZF, 0x08);
struct VectorXYZF {
le_float x = 0.0;
le_float y = 0.0;
le_float z = 0.0;
inline operator VectorXZF() const {
return VectorXZF{this->x, this->z};
}
inline VectorXYZF operator-() const {
return VectorXYZF{-this->x, -this->y, -this->z};
}
inline VectorXYZF operator+(const VectorXYZF& other) const {
return VectorXYZF{this->x + other.x, this->y + other.y, this->z + other.z};
}
inline VectorXYZF operator-(const VectorXYZF& other) const {
return VectorXYZF{this->x - other.x, this->y - other.y, this->z - other.z};
}
inline bool operator==(const VectorXYZF& other) const {
return ((this->x == other.x) && (this->y == other.y) && (this->z == other.z));
}
inline bool operator!=(const VectorXYZF& other) const {
return !this->operator==(other);
}
inline double norm() const {
return sqrt(this->norm2());
}
inline double norm2() const {
return ((this->x * this->x) + (this->y * this->y) + (this->z * this->z));
}
inline std::string str() const {
return phosg::string_printf("[VectorXYZF x=%g y=%g z=%g]", this->x.load(), this->y.load(), this->z.load());
}
} __packed_ws__(VectorXYZF, 0x0C);
struct VectorXYZTF {
le_float x = 0.0;
le_float y = 0.0;
le_float z = 0.0;
le_float t = 0.0;
} __packed_ws__(VectorXYZTF, 0x10);
struct VectorXYZI {
le_uint32_t x = 0;
le_uint32_t y = 0;
le_uint32_t z = 0;
} __packed_ws__(VectorXYZI, 0x0C);
template <bool BE>
struct ArrayRefT {
static constexpr bool IsBE = BE;
/* 00 */ U32T<BE> count;
/* 04 */ U32T<BE> offset;
/* 08 */
} __packed__;
using ArrayRef = ArrayRefT<false>;
using ArrayRefBE = ArrayRefT<true>;
check_struct_size(ArrayRef, 8);
check_struct_size(ArrayRefBE, 8);
template <bool BE>
struct RELFileFooterT {
static constexpr bool IsBE = BE;
// Relocations is a list of words (le_uint16_t on DC/PC/XB/BB, be_uint16_t on
// GC) containing the number of doublewords (uint32_t) to skip for each
// relocation. The relocation pointer starts immediately after the
// checksum_size field in the header, and advances by the value of one
// relocation word (times 4) before each relocation. At each relocated
// doubleword, the address of the first byte of the code (after checksum_size)
// is added to the existing value.
// For example, if the code segment contains the following data (where R
// specifies doublewords to relocate):
// RR RR RR RR ?? ?? ?? ?? ?? ?? ?? ?? RR RR RR RR
// RR RR RR RR ?? ?? ?? ?? RR RR RR RR
// then the relocation words should be 0000, 0003, 0001, and 0002.
// If there is a small number of relocations, they may be placed in the unused
// fields of this structure to save space and/or confuse reverse engineers.
// The game never accesses the last 12 bytes of this structure unless
// relocations_offset points there, so those 12 bytes may also be omitted
// entirely in situations (e.g. in the B2 command, without changing code_size,
// so code_size would technically extend beyond the end of the B2 command).
U32T<BE> relocations_offset = 0;
U32T<BE> num_relocations = 0;
parray<U32T<BE>, 2> unused1;
U32T<BE> root_offset = 0;
parray<U32T<BE>, 3> unused2;
} __attribute__((packed));
using RELFileFooter = RELFileFooterT<false>;
using RELFileFooterBE = RELFileFooterT<true>;
check_struct_size(RELFileFooter, 0x20);
check_struct_size(RELFileFooterBE, 0x20);
+9 -9
View File
@@ -1281,15 +1281,15 @@ string bc0_decompress(const void* data, size_t size) {
}
}
// Control bit 0 means to perform a backreference copy. The offset and
// size are stored in two bytes in the input stream, laid out as follows:
// a1 = 0bBBBBBBBB
// a2 = 0bAAAACCCC
// The offset is the concatenation of bits AAAABBBBBBBB, which refers to a
// position in the memo; the number of bytes to copy is (CCCC + 3). The
// decompressor copies that many bytes from that offset in the memo, and
// writes them to the output and to the current position in the memo.
if ((control_stream_bits & 1) == 0) {
// Control bit 0 means to perform a backreference copy. The offset and
// size are stored in two bytes in the input stream, laid out as follows:
// a1 = 0bBBBBBBBB
// a2 = 0bAAAACCCC
// The offset is the concatenation of bits AAAABBBBBBBB, which refers to
// a position in the memo; the number of bytes to copy is (CCCC + 3). The
// decompressor copies that many bytes from that offset in the memo, and
// writes them to the output and to the current position in the memo.
uint8_t a1 = r.get_u8();
if (r.eof()) {
break;
@@ -1304,9 +1304,9 @@ string bc0_decompress(const void* data, size_t size) {
memo_offset = (memo_offset + 1) & 0x0FFF;
}
} else {
// Control bit 1 means to write a byte directly from the input to the
// output. As above, the byte is also written to the memo.
} else {
uint8_t v = r.get_u8();
w.put_u8(v);
memo[memo_offset] = v;
+15 -8
View File
@@ -48,7 +48,7 @@ DownloadSession::DownloadSession(
Version version,
uint8_t language,
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file,
uint32_t hardware_id,
uint32_t serial_number2,
uint32_t serial_number,
const std::string& access_key,
const std::string& username,
@@ -63,7 +63,7 @@ DownloadSession::DownloadSession(
bool show_command_data)
: output_dir(output_dir),
bb_key_file(bb_key_file),
hardware_id(hardware_id),
serial_number2(serial_number2),
serial_number(serial_number),
access_key(access_key),
username(username),
@@ -86,6 +86,7 @@ DownloadSession::DownloadSession(
phosg::render_sockaddr_storage(remote),
show_command_data ? phosg::TerminalFormat::FG_GREEN : phosg::TerminalFormat::END,
show_command_data ? phosg::TerminalFormat::FG_YELLOW : phosg::TerminalFormat::END),
hardware_id(generate_random_hardware_id(this->channel.version)),
guild_card_number(0),
prev_cmd_data(0),
client_config(0),
@@ -103,7 +104,7 @@ DownloadSession::DownloadSession(
switch (this->channel.version) {
case Version::DC_V1:
case Version::DC_V2:
if (this->hardware_id == 0 || this->serial_number == 0 || this->access_key.empty()) {
if (this->serial_number2 == 0 || this->serial_number == 0 || this->access_key.empty()) {
throw runtime_error("missing credentials");
}
break;
@@ -163,12 +164,13 @@ void DownloadSession::send_93_9D_9E(bool extended) {
C_LoginExtendedV1_DC_93 ret;
ret.player_tag = this->guild_card_number ? 0xFFFF0000 : 0x00010000;
ret.guild_card_number = this->guild_card_number;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.is_extended = extended ? 1 : 0;
ret.language = this->channel.language;
ret.serial_number.encode(phosg::string_printf("%08" PRIX32, this->serial_number));
ret.access_key.encode(this->access_key);
ret.hardware_id.encode(phosg::string_printf("%08" PRIX32, this->hardware_id));
ret.serial_number2.encode(phosg::string_printf("%08" PRIX32, this->serial_number2));
ret.name.encode(this->character->disp.name.decode());
this->channel.send(0x93, 0x01, &ret, extended ? sizeof(ret) : sizeof(C_LoginV1_DC_93));
@@ -176,6 +178,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
C_LoginExtended_PC_9D ret;
ret.player_tag = this->guild_card_number ? 0xFFFF0000 : 0x00010000;
ret.guild_card_number = this->guild_card_number;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.is_extended = extended ? 1 : 0;
ret.language = this->channel.language;
@@ -193,6 +196,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
C_LoginExtended_GC_9E ret;
ret.player_tag = this->guild_card_number ? 0xFFFF0000 : 0x00010000;
ret.guild_card_number = this->guild_card_number;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.is_extended = extended ? 1 : 0;
ret.language = this->channel.language;
@@ -208,6 +212,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
C_LoginExtended_XB_9E ret;
ret.player_tag = this->guild_card_number ? 0xFFFF0000 : 0x00010000;
ret.guild_card_number = this->guild_card_number;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.is_extended = extended ? 1 : 0;
ret.language = this->channel.language;
@@ -377,13 +382,15 @@ void DownloadSession::on_channel_input(uint16_t command, uint32_t flag, std::str
if (flag == 1) {
if (is_v1(this->channel.version)) {
C_RegisterV1_DC_92 ret;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.language = this->channel.language;
ret.hardware_id.encode(phosg::string_printf("%08" PRIX32, this->hardware_id));
ret.serial_number2.encode(phosg::string_printf("%08" PRIX32, this->serial_number2));
this->channel.send(0x92, 0x00, ret);
} else if (!is_v4(this->channel.version)) {
C_Register_DC_PC_V3_9C ret;
ret.hardware_id = this->hardware_id;
ret.sub_version = default_sub_version_for_version(this->channel.version);
ret.language = this->channel.language;
if (this->channel.version == Version::XB_V3) {
@@ -484,7 +491,7 @@ void DownloadSession::on_channel_input(uint16_t command, uint32_t flag, std::str
this->log.info("Ship Select menu:");
for (item_index = 1; item_index <= flag; item_index++) {
const auto& item = items[item_index];
auto text = strip_color(item.text.decode());
auto text = strip_color(item.name.decode());
this->log.info("%zu: (%08" PRIX32 " %08" PRIX32 ") %s", item_index, item.menu_id.load(), item.item_id.load(), text.c_str());
if (this->ship_menu_selections.count(text)) {
break;
@@ -506,9 +513,9 @@ void DownloadSession::on_channel_input(uint16_t command, uint32_t flag, std::str
};
if (uses_utf16(this->channel.version)) {
handle_command.operator()<S_MenuEntry_PC_BB_07_1F>();
handle_command.operator()<S_MenuItem_PC_BB_08>();
} else {
handle_command.operator()<S_MenuEntry_DC_V3_07_1F>();
handle_command.operator()<S_MenuItem_DC_V3_08_Ep3_E6>();
}
this->channel.send(0x10, 0x00, ret);
+3 -2
View File
@@ -24,7 +24,7 @@ public:
Version version,
uint8_t language,
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file,
uint32_t hardware_id,
uint32_t serial_number2,
uint32_t serial_number,
const std::string& access_key,
const std::string& username,
@@ -47,7 +47,7 @@ protected:
// Config (must be set by caller)
std::string output_dir;
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
uint32_t hardware_id;
uint32_t serial_number2;
uint32_t serial_number;
std::string access_key;
std::string username;
@@ -64,6 +64,7 @@ protected:
phosg::PrefixedLogger log;
std::shared_ptr<struct event_base> base;
Channel channel;
uint64_t hardware_id;
uint32_t guild_card_number;
parray<uint8_t, 0x28> prev_cmd_data;
parray<uint8_t, 0x20> client_config;
+202 -1079
View File
File diff suppressed because it is too large Load Diff
+54 -22
View File
@@ -7,9 +7,9 @@
#include "StaticGameData.hh"
#include "Types.hh"
enum class EnemyType {
UNKNOWN = -1,
NONE = 0,
enum class EnemyType : uint8_t {
UNKNOWN = 0,
NONE,
NON_ENEMY_NPC,
AL_RAPPY,
ASTARK,
@@ -40,8 +40,8 @@ enum class EnemyType {
DE_ROL_LE_MINE,
DEATH_GUNNER,
DEL_LILY,
DEL_RAPPY,
DEL_RAPPY_ALT,
DEL_RAPPY_CRATER,
DEL_RAPPY_DESERT,
DELBITER,
DELDEPTH,
DELSABER,
@@ -54,10 +54,10 @@ enum class EnemyType {
DUBCHIC,
DUBWITCH, // Has no entry in battle params
EGG_RAPPY,
EPSIGUARD,
EPSIGARD,
EPSILON,
EVIL_SHARK,
GAEL,
GAEL_OR_GIEL,
GAL_GRYPHON,
GARANZ,
GEE,
@@ -80,6 +80,7 @@ enum class EnemyType {
KONDRIEU,
LA_DIMENIAN,
LOVE_RAPPY,
MERICARAND,
MERICAROL,
MERICUS,
MERIKLE,
@@ -97,8 +98,8 @@ enum class EnemyType {
OLGA_FLOW_2,
PAL_SHARK,
PAN_ARMS,
PAZUZU,
PAZUZU_ALT,
PAZUZU_CRATER,
PAZUZU_DESERT,
PIG_RAY,
POFUILLY_SLIME,
POUILLY_SLIME,
@@ -107,12 +108,12 @@ enum class EnemyType {
RAG_RAPPY,
RECOBOX,
RECON,
SAINT_MILLION,
SAINT_MILION,
SAINT_RAPPY,
SAND_RAPPY,
SAND_RAPPY_ALT,
SATELLITE_LIZARD,
SATELLITE_LIZARD_ALT,
SAND_RAPPY_CRATER,
SAND_RAPPY_DESERT,
SATELLITE_LIZARD_CRATER,
SATELLITE_LIZARD_DESERT,
SAVAGE_WOLF,
SHAMBERTIN,
SINOW_BEAT,
@@ -129,22 +130,53 @@ enum class EnemyType {
VOL_OPT_CORE,
VOL_OPT_MONITOR,
VOL_OPT_PILLAR,
YOWIE,
YOWIE_ALT,
YOWIE_CRATER,
YOWIE_DESERT,
ZE_BOOTA,
ZOL_GIBBON,
ZU,
ZU_ALT,
ZU_CRATER,
ZU_DESERT,
MAX_ENEMY_TYPE,
};
struct EnemyTypeDefinition {
enum Flag : uint8_t {
VALID_EP1 = 0x01,
VALID_EP2 = 0x02,
VALID_EP4 = 0x04,
IS_RARE = 0x08,
};
EnemyType type;
uint8_t flags;
uint8_t rt_index; // 0xFF if not valid (e.g. not an enemy)
uint8_t bp_index; // 0xFF if not valid (e.g. not an enemy)
const char* enum_name;
const char* in_game_name;
const char* ultimate_name; // May be null if same as in_game_name
inline bool valid_in_episode(Episode ep) const {
switch (ep) {
case Episode::EP1:
return (this->flags & Flag::VALID_EP1);
case Episode::EP2:
return (this->flags & Flag::VALID_EP2);
case Episode::EP4:
return (this->flags & Flag::VALID_EP4);
default:
throw std::logic_error("invalid episode number");
}
}
inline bool is_rare() const {
return (this->flags & Flag::IS_RARE);
}
EnemyType rare_type(Episode episode, uint8_t event, uint8_t floor) const;
};
const EnemyTypeDefinition& type_definition_for_enemy(EnemyType type);
template <>
const char* phosg::name_for_enum<EnemyType>(EnemyType type);
template <>
EnemyType phosg::enum_for_name<EnemyType>(const char* name);
bool enemy_type_valid_for_episode(Episode episode, EnemyType enemy_type);
uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type);
uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type);
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index);
bool enemy_type_is_rare(EnemyType type);
+3 -2
View File
@@ -717,7 +717,7 @@ int32_t Card::move_to_location(const Location& loc) {
G_EnqueueAnimation_Ep3_6xB4x2C cmd;
cmd.change_type = 1;
cmd.client_id = other_ps->client_id;
cmd.unknown_a2[0] = trap_card_id;
cmd.trap_card_id = trap_card_id;
s->send(cmd);
}
}
@@ -736,7 +736,8 @@ int32_t Card::move_to_location(const Location& loc) {
cmd.change_type = 0;
cmd.card_refs.clear(0xFFFF);
cmd.card_refs[0] = this->card_ref;
cmd.unknown_a2.clear(0xFFFFFFFF);
cmd.trap_card_id = 0xFFFFFFFF;
cmd.unknown_a3 = 0xFFFFFFFF;
s->send(cmd);
return 0;
}
+22 -15
View File
@@ -8,6 +8,7 @@
#include <phosg/Random.hh>
#include <phosg/Time.hh>
#include "../CommonFileFormats.hh"
#include "../Compression.hh"
#include "../Loggers.hh"
#include "../PSOEncryption.hh"
@@ -2452,28 +2453,34 @@ CardIndex::CardIndex(
this->compressed_card_definitions = phosg::load_file(filename);
decompressed_data = prs_decompress(this->compressed_card_definitions);
}
// The client can't handle files larger than this
if (decompressed_data.size() > 0x36EC0) {
throw runtime_error("decompressed card list data is too long");
}
// There's a footer after the card definitions (it's a standard-format REL
// file), but we ignore it
if (decompressed_data.size() % sizeof(CardDefinition) != sizeof(CardDefinitionsFooter)) {
throw runtime_error(phosg::string_printf(
"decompressed card update file size %zX is not aligned with card definition size %zX (%zX extra bytes)",
decompressed_data.size(), sizeof(CardDefinition), decompressed_data.size() % sizeof(CardDefinition)));
// The card definitions file is a standard REL file; the root offset points
// to an ArrayRef which specifies an array of CardDefinition structs
phosg::StringReader r(decompressed_data);
const auto& footer = r.pget<RELFileFooterBE>(r.size() - sizeof(RELFileFooterBE));
uint32_t offset = r.pget_u32b(footer.root_offset);
uint32_t count = r.pget_u32b(footer.root_offset + 4);
if (offset > decompressed_data.size() ||
((offset + count * sizeof(CardDefinition)) > decompressed_data.size())) {
throw runtime_error("definitions array reference out of bounds");
}
auto* defs = reinterpret_cast<CardDefinition*>(decompressed_data.data());
size_t max_cards = decompressed_data.size() / sizeof(CardDefinition);
for (size_t x = 0; x < max_cards; x++) {
CardDefinition* defs = reinterpret_cast<CardDefinition*>(decompressed_data.data() + offset);
for (size_t x = 0; x < count; x++) {
auto& def = defs[x];
// The last card entry has the build date and some other metadata (and
// isn't a real card, obviously), so skip it. The game detects this by
// checking for a negative value in type, which we also do here.
if (static_cast<int8_t>(defs[x].type) < 0) {
if (static_cast<int8_t>(def.type) < 0) {
continue;
}
auto entry = make_shared<CardEntry>(CardEntry{defs[x], "", "", "", {}});
auto entry = make_shared<CardEntry>(CardEntry{def, "", "", "", {}});
if (!this->card_definitions.emplace(entry->def.card_id, entry).second) {
throw runtime_error(phosg::string_printf(
"duplicate card id: %08" PRIX32, entry->def.card_id.load()));
@@ -2493,17 +2500,17 @@ CardIndex::CardIndex(
if (!text_filename.empty() || !decompressed_text_filename.empty()) {
try {
entry->text = std::move(card_text.at(defs[x].card_id));
entry->text = std::move(card_text.at(def.card_id));
} catch (const out_of_range&) {
}
try {
entry->debug_tags = std::move(card_tags.at(defs[x].card_id));
entry->debug_tags = std::move(card_tags.at(def.card_id));
} catch (const out_of_range&) {
}
}
if (!dice_text_filename.empty() || !decompressed_dice_text_filename.empty()) {
try {
auto& dice_text_it = card_dice_text.at(defs[x].card_id);
auto& dice_text_it = card_dice_text.at(def.card_id);
entry->dice_caption = std::move(dice_text_it.first);
entry->dice_text = std::move(dice_text_it.second);
} catch (const out_of_range&) {
@@ -2523,7 +2530,7 @@ CardIndex::CardIndex(
if (this->compressed_card_definitions.size() > 0x7BF8) {
// Try to reduce the compressed size by clearing out text
static_game_data_log.info("Compressed card list data is too long (0x%zX bytes); removing text", this->compressed_card_definitions.size());
for (size_t x = 0; x < max_cards; x++) {
for (size_t x = 0; x < count; x++) {
if (static_cast<int8_t>(defs[x].type) < 0) {
continue;
}
+2 -8
View File
@@ -13,6 +13,7 @@
#include <string>
#include <unordered_map>
#include "../CommonFileFormats.hh"
#include "../PlayerSubordinates.hh"
#include "../Text.hh"
#include "../TextIndex.hh"
@@ -814,18 +815,12 @@ struct CardDefinition {
} __packed_ws__(CardDefinition, 0x128);
struct CardDefinitionsFooter {
// Technically the card definitions file is a REL file, so the last 0x20 bytes
// here should be a separate structure.
/* 00 */ be_uint32_t num_cards1;
/* 04 */ be_uint32_t cards_offset; // == 0
/* 08 */ be_uint32_t num_cards2;
/* 0C */ parray<be_uint32_t, 3> unknown_a2;
/* 18 */ parray<be_uint16_t, 0x10> relocations;
/* 38 */ be_uint32_t relocations_offset;
/* 3C */ be_uint32_t num_relocations;
/* 40 */ parray<be_uint32_t, 2> unused1;
/* 48 */ be_uint32_t footer_offset;
/* 4C */ parray<be_uint32_t, 3> unused2;
/* 38 */ RELFileFooterBE rel_footer;
/* 58 */
} __packed_ws__(CardDefinitionsFooter, 0x58);
@@ -1219,7 +1214,6 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
// 19 = View Battle waiting room
// 1A = TCard00_Select (debug battle setup menu)
// 1B = nothing (softlocks at black screen)
// TCard00_Select is accessible on newserv with the $ep3battledebug command.
/* 000A */ uint8_t environment_number;
// This field specifies how many of the camera_zone_maps are used.
+4 -2
View File
@@ -617,7 +617,8 @@ void PlayerState::discard_and_redraw_hand() {
cmd.change_type = 3;
cmd.client_id = this->client_id;
cmd.card_refs.clear(0xFFFF);
cmd.unknown_a2.clear(0xFFFFFFFF);
cmd.trap_card_id = 0xFFFFFFFF;
cmd.unknown_a3 = 0xFFFFFFFF;
s->send(cmd);
}
@@ -721,7 +722,8 @@ bool PlayerState::do_mulligan() {
cmd.change_type = 3;
cmd.client_id = this->client_id;
cmd.card_refs.clear(0xFFFF);
cmd.unknown_a2.clear(0xFFFFFFFF);
cmd.trap_card_id = 0xFFFFFFFF;
cmd.unknown_a3 = 0xFFFFFFFF;
s->send(cmd);
}
+5 -5
View File
@@ -1164,8 +1164,8 @@ void Server::move_phase_after() {
cmd.loc.x = trap_x;
cmd.loc.y = trap_y;
cmd.loc.direction = static_cast<Direction>(trap_type);
cmd.unknown_a2[0] = trap_card_id;
cmd.unknown_a2[1] = 0xFFFFFFFF;
cmd.trap_card_id = trap_card_id;
cmd.unknown_a3 = 0xFFFFFFFF;
this->send(cmd);
}
}
@@ -1869,7 +1869,7 @@ void Server::handle_CAx0B_mulligan_hand(shared_ptr<Client>, const string& data)
void Server::handle_CAx0C_end_mulligan_phase(shared_ptr<Client>, const string& data) {
const auto& in_cmd = check_size_t<G_EndInitialRedrawPhase_Ep3_CAx0C>(data);
this->send_debug_command_received_message(in_cmd.client_id, in_cmd.header.subsubcommand, "SETUP ADV 2");
this->send_debug_command_received_message(in_cmd.client_id, in_cmd.header.subsubcommand, "HAND READY");
if (in_cmd.client_id >= 4) {
throw runtime_error("invalid client ID");
}
@@ -2335,7 +2335,7 @@ void Server::handle_CAx1D_start_battle(shared_ptr<Client>, const string& data) {
if (l) {
// Note: Sega's implementation doesn't set EX results values here; they
// did it at game join time instead. We do it here for code simplicity.
if ((l->base_version != Version::GC_EP3_NTE) && l->ep3_ex_result_values) {
if (!this->options.is_nte() && l->ep3_ex_result_values) {
this->send(*l->ep3_ex_result_values);
}
}
@@ -2495,7 +2495,7 @@ void Server::handle_CAx34_subtract_ally_atk_points(shared_ptr<Client>, const str
void Server::handle_CAx37_client_ready_to_advance_from_starter_roll_phase(shared_ptr<Client>, const string& data) {
const auto& in_cmd = check_size_t<G_AdvanceFromStartingRollsPhase_Ep3_CAx37>(data);
this->send_debug_command_received_message(in_cmd.client_id, in_cmd.header.subsubcommand, "SETUP ADV 1");
this->send_debug_command_received_message(in_cmd.client_id, in_cmd.header.subsubcommand, "CHOOSE ORDER");
if (in_cmd.client_id >= 4) {
throw runtime_error("invalid client ID");
}
+32 -27
View File
@@ -717,66 +717,71 @@ void Tournament::send_all_state_updates_on_deletion() const {
}
}
void Tournament::print_bracket(FILE* stream) const {
function<void(shared_ptr<Match>, size_t)> print_match = [&](shared_ptr<Match> m, size_t indent_level) -> void {
for (size_t z = 0; z < indent_level; z++) {
fputc(' ', stream);
fputc(' ', stream);
string Tournament::bracket_str() const {
string ret = phosg::string_printf("Tournament \"%s\"\n", this->name.c_str());
function<void(shared_ptr<Match>, size_t)> add_match = [&](shared_ptr<Match> m, size_t indent_level) -> void {
ret.append(2 * indent_level, ' ');
ret += m->str();
if (this->pending_matches.count(m)) {
ret += " (PENDING)";
}
string match_str = m->str();
fprintf(stream, "%s%s\n", match_str.c_str(), this->pending_matches.count(m) ? " (PENDING)" : "");
ret.push_back('\n');
if (m->preceding_a) {
print_match(m->preceding_a, indent_level + 1);
add_match(m->preceding_a, indent_level + 1);
}
if (m->preceding_b) {
print_match(m->preceding_b, indent_level + 1);
add_match(m->preceding_b, indent_level + 1);
}
};
fprintf(stream, "Tournament \"%s\"\n", this->name.c_str());
auto en_vm = this->map->version(1);
if (en_vm) {
string map_name = en_vm->map->name.decode(en_vm->language);
fprintf(stream, " Map: %08" PRIX32 " (%s)\n", this->map->map_number, map_name.c_str());
ret += phosg::string_printf(" Map: %08" PRIX32 " (%s)\n", this->map->map_number, map_name.c_str());
} else {
fprintf(stream, " Map: %08" PRIX32 "\n", this->map->map_number);
ret += phosg::string_printf(" Map: %08" PRIX32 "\n", this->map->map_number);
}
string rules_str = this->rules.str();
fprintf(stream, " Rules: %s\n", rules_str.c_str());
fprintf(stream, " Structure: %s, %zu entries\n", (this->flags & Flag::IS_2V2) ? "2v2" : "1v1", this->num_teams);
fprintf(stream, " COM teams: %s\n", (this->flags & Flag::HAS_COM_TEAMS) ? "allowed" : "forbidden");
fprintf(stream, " Shuffle entries: %s\n", (this->flags & Flag::SHUFFLE_ENTRIES) ? "yes" : "no");
fprintf(stream, " Resize on start: %s\n", (this->flags & Flag::RESIZE_ON_START) ? "yes" : "no");
ret += phosg::string_printf(" Rules: %s\n", rules_str.c_str());
ret += phosg::string_printf(" Structure: %s, %zu entries\n", (this->flags & Flag::IS_2V2) ? "2v2" : "1v1", this->num_teams);
ret += phosg::string_printf(" COM teams: %s\n", (this->flags & Flag::HAS_COM_TEAMS) ? "allowed" : "forbidden");
ret += phosg::string_printf(" Shuffle entries: %s\n", (this->flags & Flag::SHUFFLE_ENTRIES) ? "yes" : "no");
ret += phosg::string_printf(" Resize on start: %s\n", (this->flags & Flag::RESIZE_ON_START) ? "yes" : "no");
switch (this->current_state) {
case State::REGISTRATION:
fprintf(stream, " State: REGISTRATION\n");
ret += " State: REGISTRATION\n";
break;
case State::IN_PROGRESS:
fprintf(stream, " State: IN_PROGRESS\n");
ret += " State: IN_PROGRESS\n";
break;
case State::COMPLETE:
fprintf(stream, " State: COMPLETE\n");
ret += " State: COMPLETE\n";
break;
default:
fprintf(stream, " State: UNKNOWN\n");
ret += " State: UNKNOWN\n";
break;
}
if (this->final_match) {
fprintf(stream, " Standings:\n");
print_match(this->final_match, 2);
ret += " Standings:\n";
add_match(this->final_match, 2);
}
if (this->current_state == State::REGISTRATION) {
fprintf(stream, " Teams:\n");
ret += " Teams:\n";
for (const auto& team : this->teams) {
string team_str = team->str();
fprintf(stream, " %s\n", team_str.c_str());
ret += phosg::string_printf(" %s\n", team_str.c_str());
}
} else {
fprintf(stream, " Pending matches:\n");
ret += " Pending matches:\n";
for (const auto& match : this->pending_matches) {
string match_str = match->str();
fprintf(stream, " %s\n", match_str.c_str());
ret += phosg::string_printf(" %s\n", match_str.c_str());
}
}
phosg::strip_trailing_whitespace(ret);
return ret;
}
TournamentIndex::TournamentIndex(
+1 -1
View File
@@ -160,7 +160,7 @@ public:
void send_all_state_updates() const;
void send_all_state_updates_on_deletion() const;
void print_bracket(FILE* stream) const;
std::string bracket_str() const;
private:
void create_bracket_matches();
+30 -11
View File
@@ -1,5 +1,6 @@
#include "EventUtils.hh"
#include <event2/buffer.h>
#include <event2/event.h>
#include <deque>
@@ -7,37 +8,55 @@
#include <memory>
#include <stdexcept>
using namespace std;
static void dispatch_forward_to_event_thread(evutil_socket_t, short, void* ctx) {
auto* fn = reinterpret_cast<std::function<void()>*>(ctx);
auto* fn = reinterpret_cast<function<void()>*>(ctx);
(*fn)();
delete fn;
}
void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn) {
void forward_to_event_thread(shared_ptr<struct event_base> base, function<void()>&& fn) {
struct timeval tv = {0, 0};
std::function<void()>* new_fn = new std::function<void()>(std::move(fn));
function<void()>* new_fn = new function<void()>(std::move(fn));
event_base_once(base.get(), -1, EV_TIMEOUT, dispatch_forward_to_event_thread, new_fn, &tv);
}
template <>
void call_on_event_thread<void>(std::shared_ptr<struct event_base> base, std::function<void()>&& compute) {
void call_on_event_thread<void>(shared_ptr<struct event_base> base, function<void()>&& compute) {
bool succeeded = false;
std::string exc_what;
std::mutex ret_lock;
std::condition_variable ret_cv;
std::unique_lock<std::mutex> g(ret_lock);
string exc_what;
mutex ret_lock;
condition_variable ret_cv;
unique_lock<mutex> g(ret_lock);
forward_to_event_thread(base, [&]() -> void {
std::lock_guard<std::mutex> g(ret_lock);
lock_guard<mutex> g(ret_lock);
try {
compute();
succeeded = true;
} catch (const std::exception& e) {
} catch (const exception& e) {
exc_what = e.what();
}
ret_cv.notify_one();
});
ret_cv.wait(g);
if (!succeeded) {
throw std::runtime_error(exc_what);
throw runtime_error(exc_what);
}
}
string evbuffer_remove_str(struct evbuffer* buf, ssize_t size) {
if (!buf) {
return "";
}
if (size < 0) {
size = static_cast<size_t>(evbuffer_get_length(buf));
}
string ret(size, '\0');
ssize_t bytes_removed = evbuffer_remove(buf, ret.data(), ret.size());
if (bytes_removed < 0) {
throw std::runtime_error("can\'t remove data from buffer");
}
ret.resize(bytes_removed);
return ret;
}
+3
View File
@@ -8,6 +8,7 @@
#include <mutex>
#include <optional>
#include <stdexcept>
#include <string>
// Calls a function on the given base's event thread. This function returns
// when the call has been enqueued, not necessarily after it returns.
@@ -40,3 +41,5 @@ T call_on_event_thread(std::shared_ptr<struct event_base> base, std::function<T(
template <>
void call_on_event_thread<void>(std::shared_ptr<struct event_base> base, std::function<void()>&& compute);
std::string evbuffer_remove_str(struct evbuffer* buf, ssize_t size = -1);
+14 -9
View File
@@ -15,6 +15,7 @@
#endif
#include "CommandFormats.hh"
#include "CommonFileFormats.hh"
#include "Compression.hh"
#include "Loggers.hh"
@@ -47,16 +48,18 @@ const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
}
}
template <typename FooterT>
template <bool BE>
string CompiledFunctionCode::generate_client_command_t(
const unordered_map<string, uint32_t>& label_writes,
const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const {
using FooterT = RELFileFooterT<BE>;
FooterT footer;
footer.num_relocations = this->relocation_deltas.size();
footer.unused1.clear(0);
footer.entrypoint_addr_offset = this->entrypoint_offset_offset;
footer.root_offset = this->entrypoint_offset_offset;
footer.unused2.clear(0);
phosg::StringWriter w;
@@ -67,7 +70,7 @@ string CompiledFunctionCode::generate_client_command_t(
if (offset > modified_code.size() - 4) {
throw runtime_error("label out of range");
}
*reinterpret_cast<be_uint32_t*>(modified_code.data() + offset) = it.second;
*reinterpret_cast<U32T<FooterT::IsBE>*>(modified_code.data() + offset) = it.second;
}
w.write(modified_code);
} else {
@@ -108,10 +111,10 @@ string CompiledFunctionCode::generate_client_command(
size_t suffix_size,
uint32_t override_relocations_offset) const {
if (this->arch == Architecture::POWERPC) {
return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2>(
return this->generate_client_command_t<true>(
label_writes, suffix_data, suffix_size, override_relocations_offset);
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2>(
return this->generate_client_command_t<false>(
label_writes, suffix_data, suffix_size, override_relocations_offset);
} else {
throw logic_error("invalid architecture");
@@ -308,7 +311,9 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
arch = CompiledFunctionCode::Architecture::SH4;
} else if (specific_version_is_gc(specific_version)) {
arch = CompiledFunctionCode::Architecture::POWERPC;
} else if (specific_version_is_xb(specific_version) || specific_version_is_bb(specific_version)) {
} else if (specific_version_is_pc_v2(specific_version) ||
specific_version_is_xb(specific_version) ||
specific_version_is_bb(specific_version)) {
arch = CompiledFunctionCode::Architecture::X86;
} else {
throw runtime_error("unable to determine architecture from specific_version");
@@ -367,7 +372,7 @@ shared_ptr<const Menu> FunctionCodeIndex::patch_menu(uint32_t specific_version)
fn->menu_item_id,
fn->long_name.empty() ? fn->short_name : fn->long_name,
fn->description,
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
}
return ret;
}
@@ -386,7 +391,7 @@ shared_ptr<const Menu> FunctionCodeIndex::patch_switches_menu(
string name;
name.push_back(auto_patches_enabled.count(fn->short_name) ? '*' : '-');
name += fn->long_name.empty() ? fn->short_name : fn->long_name;
ret->items.emplace_back(fn->menu_item_id, name, fn->description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
ret->items.emplace_back(fn->menu_item_id, name, fn->description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
}
return ret;
}
@@ -476,7 +481,7 @@ DOLFileIndex::DOLFileIndex(const string& directory) {
this->name_to_file.emplace(dol->name, dol);
this->item_id_to_file.emplace_back(dol);
menu->items.emplace_back(dol->menu_item_id, dol->name, description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
menu->items.emplace_back(dol->menu_item_id, dol->name, description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
} catch (const exception& e) {
function_compiler_log.warning("Failed to load DOL file %s: %s", filename.c_str(), e.what());
+1 -1
View File
@@ -40,7 +40,7 @@ struct CompiledFunctionCode {
bool is_big_endian() const;
template <typename FooterT>
template <bool BE>
std::string generate_client_command_t(
const std::unordered_map<std::string, uint32_t>& label_writes,
const void* suffix_data = nullptr,
+104 -59
View File
@@ -13,7 +13,9 @@
#include "EventUtils.hh"
#include "Loggers.hh"
#include "ProxyServer.hh"
#include "Revision.hh"
#include "Server.hh"
#include "ShellCommands.hh"
using namespace std;
@@ -162,12 +164,18 @@ const string& HTTPServer::get_url_param(
return range.first->second;
}
HTTPServer::HTTPServer(shared_ptr<ServerState> state)
: state(state),
base(event_base_new(), event_base_free),
http(evhttp_new(this->base.get()), evhttp_free),
th(&HTTPServer::thread_fn, this) {
HTTPServer::HTTPServer(shared_ptr<ServerState> state, shared_ptr<struct event_base> shared_base)
: state(state) {
if (!shared_base) {
this->base.reset(event_base_new(), event_base_free);
} else {
this->base = shared_base;
}
this->http.reset(evhttp_new(this->base.get()), evhttp_free);
evhttp_set_gencb(this->http.get(), this->dispatch_handle_request, this);
if (!shared_base) {
this->th = thread(&HTTPServer::thread_fn, this);
}
}
void HTTPServer::listen(const string& socket_path) {
@@ -434,22 +442,12 @@ void HTTPServer::dispatch_handle_request(struct evhttp_request* req, void* ctx)
reinterpret_cast<HTTPServer*>(ctx)->handle_request(req);
}
phosg::JSON HTTPServer::generate_quest_json_st(shared_ptr<const Quest> q) {
if (!q) {
return nullptr;
}
auto battle_rules_json = q->battle_rules ? q->battle_rules->json() : nullptr;
auto challenge_template_index_json = (q->challenge_template_index >= 0)
? q->challenge_template_index
: phosg::JSON(nullptr);
phosg::JSON HTTPServer::generate_server_version_st() {
return phosg::JSON::dict({
{"Number", q->quest_number},
{"Episode", name_for_episode(q->episode)},
{"Joinable", q->joinable},
{"LockStatusRegister", (q->lock_status_register >= 0) ? q->lock_status_register : phosg::JSON(nullptr)},
{"Name", q->name},
{"BattleRules", std::move(battle_rules_json)},
{"ChallengeTemplateIndex", std::move(challenge_template_index_json)},
{"ServerType", "newserv"},
{"BuildTime", BUILD_TIMESTAMP},
{"BuildTimeStr", phosg::format_time(BUILD_TIMESTAMP)},
{"Revision", GIT_REVISION_HASH},
});
}
@@ -550,8 +548,8 @@ phosg::JSON HTTPServer::generate_game_client_json_st(shared_ptr<const Client> c,
{"SubVersion", c->sub_version},
{"Config", HTTPServer::generate_client_config_json_st(c->config)},
{"Language", name_for_language_code(c->language())},
{"LocationX", c->x},
{"LocationZ", c->z},
{"LocationX", c->pos.x.load()},
{"LocationZ", c->pos.z.load()},
{"LocationFloor", c->floor},
{"CanChat", c->can_chat},
});
@@ -567,9 +565,8 @@ phosg::JSON HTTPServer::generate_game_client_json_st(shared_ptr<const Client> c,
auto p = c->character(false, false);
if (p) {
if (!is_ep3(c->version())) {
ret.emplace("InventoryItems", p->inventory.num_items);
if (c->version() != Version::DC_NTE) {
ret.emplace("InventoryLanguage", p->inventory.language);
ret.emplace("InventoryLanguage", name_for_language_code(p->inventory.language));
ret.emplace("NumHPMaterialsUsed", p->get_material_usage(PSOBBCharacterFile::MaterialType::HP));
ret.emplace("NumTPMaterialsUsed", p->get_material_usage(PSOBBCharacterFile::MaterialType::TP));
if (!is_v1_or_v2(c->version())) {
@@ -593,6 +590,7 @@ phosg::JSON HTTPServer::generate_game_client_json_st(shared_ptr<const Client> c,
}
items_json.emplace_back(std::move(item_dict));
}
ret.emplace("InventoryItems", std::move(items_json));
ret.emplace("ATP", p->disp.stats.char_stats.atp.load());
ret.emplace("MST", p->disp.stats.char_stats.mst.load());
ret.emplace("EVP", p->disp.stats.char_stats.evp.load());
@@ -614,7 +612,7 @@ phosg::JSON HTTPServer::generate_game_client_json_st(shared_ptr<const Client> c,
ret.emplace("NameColor", p->disp.visual.name_color.load());
ret.emplace("ExtraModel", (p->disp.visual.validation_flags & 2) ? p->disp.visual.extra_model : phosg::JSON(nullptr));
ret.emplace("SectionID", name_for_section_id(p->disp.visual.section_id));
ret.emplace("CharClass", name_for_char_class(p->disp.visual.section_id));
ret.emplace("CharClass", name_for_char_class(p->disp.visual.char_class));
ret.emplace("Costume", p->disp.visual.costume.load());
ret.emplace("Skin", p->disp.visual.skin.load());
ret.emplace("Face", p->disp.visual.face.load());
@@ -728,15 +726,15 @@ phosg::JSON HTTPServer::generate_proxy_client_json_st(shared_ptr<const ProxyServ
{"Version", phosg::name_for_enum(ses->version())},
{"SubVersion", ses->sub_version},
{"Name", ses->character_name},
{"DCHardwareID", ses->hardware_id},
{"DCSerialNumber2", ses->serial_number2},
{"RemoteGuildCardNumber", ses->remote_guild_card_number},
{"RemoteClientConfigData", phosg::format_data_string(&ses->remote_client_config_data[0], ses->remote_client_config_data.size())},
{"Config", HTTPServer::generate_client_config_json_st(ses->config)},
{"Language", name_for_language_code(ses->language())},
{"LobbyClientID", ses->lobby_client_id},
{"LeaderClientID", ses->leader_client_id},
{"LocationX", ses->x},
{"LocationZ", ses->z},
{"LocationX", ses->pos.x.load()},
{"LocationZ", ses->pos.z.load()},
{"LocationFloor", ses->floor},
{"IsInGame", ses->is_in_game},
{"IsInQuest", ses->is_in_quest},
@@ -787,7 +785,6 @@ phosg::JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared
ret.emplace("CheatsEnabled", l->check_flag(Lobby::Flag::CHEATS_ENABLED));
ret.emplace("MinLevel", l->min_level + 1);
ret.emplace("MaxLevel", l->max_level + 1);
ret.emplace("BaseVersion", l->base_version);
ret.emplace("Episode", name_for_episode(l->episode));
ret.emplace("HasPassword", !l->password.empty());
ret.emplace("Name", l->name);
@@ -796,11 +793,7 @@ phosg::JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared
ret.emplace("QuestSelectionInProgress", l->check_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS));
ret.emplace("QuestInProgress", l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS));
ret.emplace("JoinableQuestInProgress", l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS));
auto variations_json = phosg::JSON::list();
for (size_t z = 0; z < l->variations.size(); z++) {
variations_json.emplace_back(l->variations[z].load());
}
ret.emplace("Variations", std::move(variations_json));
ret.emplace("Variations", l->variations.json());
ret.emplace("SectionID", name_for_section_id(l->effective_section_id()));
ret.emplace("Mode", name_for_mode(l->mode));
ret.emplace("Difficulty", name_for_difficulty(l->difficulty));
@@ -845,8 +838,8 @@ phosg::JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared
const auto& item = it.second;
auto item_dict = phosg::JSON::dict({
{"LocationFloor", floor},
{"LocationX", item->x},
{"LocationZ", item->z},
{"LocationX", item->pos.x.load()},
{"LocationZ", item->pos.z.load()},
{"DropNumber", item->drop_number},
{"Flags", item->flags},
{"Data", item->data.hex()},
@@ -859,7 +852,7 @@ phosg::JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared
}
}
ret.emplace("FloorItems", std::move(floor_items_json));
ret.emplace("Quest", HTTPServer::generate_quest_json_st(l->quest));
ret.emplace("Quest", l->quest ? l->quest->json() : phosg::JSON(nullptr));
} else {
ret.emplace("BattleInProgress", l->check_flag(Lobby::Flag::BATTLE_IN_PROGRESS));
@@ -964,6 +957,16 @@ phosg::JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared
return ret;
}
phosg::JSON HTTPServer::generate_accounts_json() const {
return call_on_event_thread<phosg::JSON>(this->state->base, [&]() {
auto res = phosg::JSON::list();
for (const auto& it : this->state->account_index->all()) {
res.emplace_back(it->json());
}
return res;
});
}
phosg::JSON HTTPServer::generate_game_server_clients_json() const {
return call_on_event_thread<phosg::JSON>(this->state->base, [&]() {
auto res = phosg::JSON::list();
@@ -1016,7 +1019,9 @@ phosg::JSON HTTPServer::generate_lobbies_json() const {
return call_on_event_thread<phosg::JSON>(this->state->base, [&]() {
phosg::JSON res = phosg::JSON::list();
for (const auto& it : this->state->id_to_lobby) {
res.emplace_back(this->generate_lobby_json_st(it.second, this->state->item_name_index_opt(it.second->base_version)));
auto leader = it.second->clients[it.second->leader_id];
Version v = leader ? leader->version() : Version::BB_V4;
res.emplace_back(this->generate_lobby_json_st(it.second, this->state->item_name_index_opt(v)));
}
return res;
});
@@ -1061,7 +1066,6 @@ phosg::JSON HTTPServer::generate_summary_json() const {
auto game_json = phosg::JSON::dict({
{"ID", l->lobby_id},
{"Name", l->name},
{"BaseVersion", phosg::name_for_enum(l->base_version)},
{"Players", l->count_clients()},
{"CheatsEnabled", l->check_flag(Lobby::Flag::CHEATS_ENABLED)},
{"Episode", name_for_episode(l->episode)},
@@ -1080,7 +1084,7 @@ phosg::JSON HTTPServer::generate_summary_json() const {
game_json.emplace("SectionID", name_for_section_id(l->effective_section_id()));
game_json.emplace("Mode", name_for_mode(l->mode));
game_json.emplace("Difficulty", name_for_difficulty(l->difficulty));
game_json.emplace("Quest", this->generate_quest_json_st(l->quest));
game_json.emplace("Quest", l->quest ? l->quest->json() : phosg::JSON(nullptr));
}
games_json.emplace_back(std::move(game_json));
}
@@ -1152,6 +1156,31 @@ phosg::JSON HTTPServer::generate_rare_table_json(const std::string& table_name)
}
}
phosg::JSON HTTPServer::generate_quest_list_json(std::shared_ptr<const QuestIndex> quest_index) {
return call_on_event_thread<phosg::JSON>(this->state->base, [&]() {
return quest_index->json();
});
}
void HTTPServer::require_GET(struct evhttp_request* req) {
if (evhttp_request_get_command(req) != EVHTTP_REQ_GET) {
throw HTTPServer::http_error(405, "GET method required for this endpoint");
}
}
phosg::JSON HTTPServer::require_POST(struct evhttp_request* req) {
if (evhttp_request_get_command(req) != EVHTTP_REQ_POST) {
throw HTTPServer::http_error(405, "POST method required for this endpoint");
}
const evkeyvalq* headers = evhttp_request_get_input_headers(req);
const char* content_type = evhttp_find_header(headers, "Content-Type");
if (!content_type || strcmp(content_type, "application/json")) {
throw HTTPServer::http_error(400, "POST requests must use the application/json content type");
}
struct evbuffer* in_buf = evhttp_request_get_input_buffer(req);
return phosg::JSON::parse(evbuffer_remove_str(in_buf));
}
void HTTPServer::handle_request(struct evhttp_request* req) {
shared_ptr<const phosg::JSON> ret;
uint32_t serialize_options = 0;
@@ -1175,58 +1204,70 @@ void HTTPServer::handle_request(struct evhttp_request* req) {
}
if (uri == "/") {
auto endpoints_json = phosg::JSON::list({
"/y/data/ep3-cards",
"/y/data/ep3-cards-trial",
"/y/data/common-tables",
"/y/data/rare-tables",
"/y/data/rare-tables/<TABLE-NAME>",
"/y/data/config",
"/y/clients",
"/y/proxy-clients",
"/y/lobbies",
"/y/server",
"/y/rare-drops/stream",
"/y/summary",
"/y/all",
});
ret = make_shared<phosg::JSON>(phosg::JSON::dict({{"endpoints", std::move(endpoints_json)}}));
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_server_version_st());
} else if (uri == "/y/shell-exec") {
auto json = this->require_POST(req);
auto command = json.get_string("command");
try {
ret = make_shared<phosg::JSON>(phosg::JSON::dict(
{{"result", phosg::join(ShellCommand::dispatch_str(this->state, command), "\n")}}));
} catch (const exception& e) {
throw http_error(400, e.what());
}
} else if (uri == "/y/rare-drops/stream") {
this->require_GET(req);
auto c = this->enable_websockets(req);
if (!c) {
throw http_error(400, "this path requires a websocket connection");
} else {
this->rare_drop_subscribers.emplace(c);
auto version_message = phosg::JSON::dict({{"ServerType", "newserv"}});
auto version_message = this->generate_server_version_st();
this->send_websocket_message(c, version_message.serialize());
return;
}
} else if (uri == "/y/data/ep3-cards") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_ep3_cards_json(false));
} else if (uri == "/y/data/ep3-cards-trial") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_ep3_cards_json(true));
} else if (uri == "/y/data/common-tables") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_common_tables_json());
} else if (uri == "/y/data/rare-tables") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_rare_tables_json());
} else if (!strncmp(uri.c_str(), "/y/data/rare-tables/", 20)) {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_rare_table_json(uri.substr(20)));
} else if (uri == "/y/data/quests") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_quest_list_json(this->state->quest_index(Version::GC_V3)));
} else if (uri == "/y/data/config") {
this->require_GET(req);
ret = call_on_event_thread<shared_ptr<const phosg::JSON>>(this->state->base, [this]() { return this->state->config_json; });
} else if (uri == "/y/accounts") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_accounts_json());
} else if (uri == "/y/clients") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_game_server_clients_json());
} else if (uri == "/y/proxy-clients") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_proxy_server_clients_json());
} else if (uri == "/y/lobbies") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_lobbies_json());
} else if (uri == "/y/server") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_server_info_json());
} else if (uri == "/y/summary") {
this->require_GET(req);
ret = make_shared<phosg::JSON>(this->generate_summary_json());
} else if (uri == "/y/all") {
ret = make_shared<phosg::JSON>(this->generate_all_json());
} else {
throw http_error(404, "unknown action");
@@ -1246,6 +1287,10 @@ void HTTPServer::handle_request(struct evhttp_request* req) {
return;
}
if (!ret) {
throw logic_error("ret was not set after HTTP handler completed");
}
uint64_t handler_end = phosg::now();
unique_ptr<struct evbuffer, void (*)(struct evbuffer*)> out_buffer(evbuffer_new(), evbuffer_free);
string* serialized = new string(ret->serialize(phosg::JSON::SerializeOption::ESCAPE_CONTROLS_ONLY | serialize_options));
+11 -3
View File
@@ -13,7 +13,10 @@
class HTTPServer {
public:
HTTPServer(std::shared_ptr<ServerState> state);
// shared_base should be null unless the HTTP server should run on the main
// thread (on Windows).
HTTPServer(std::shared_ptr<ServerState> state, std::shared_ptr<struct event_base> shared_base);
HTTPServer(const HTTPServer&) = delete;
HTTPServer(HTTPServer&&) = delete;
HTTPServer& operator=(const HTTPServer&) = delete;
@@ -57,12 +60,15 @@ protected:
std::shared_ptr<ServerState> state;
std::shared_ptr<struct event_base> base;
std::shared_ptr<struct evhttp> http;
std::thread th;
std::thread th; // Not used on Windows
std::unordered_set<std::shared_ptr<WebsocketClient>> rare_drop_subscribers;
std::unordered_map<struct bufferevent*, std::shared_ptr<WebsocketClient>> bev_to_websocket_client;
static void require_GET(struct evhttp_request* req);
static phosg::JSON require_POST(struct evhttp_request* req);
std::shared_ptr<WebsocketClient> enable_websockets(struct evhttp_request* req);
static void dispatch_on_websocket_read(struct bufferevent* bev, void* ctx);
@@ -94,12 +100,13 @@ protected:
const std::string& key,
const std::string* _default = nullptr);
static phosg::JSON generate_quest_json_st(std::shared_ptr<const Quest> q);
static phosg::JSON generate_server_version_st();
static phosg::JSON generate_client_config_json_st(const Client::Config& config);
static phosg::JSON generate_account_json_st(std::shared_ptr<const Account> a);
static phosg::JSON generate_game_client_json_st(std::shared_ptr<const Client> c, std::shared_ptr<const ItemNameIndex> item_name_index);
static phosg::JSON generate_proxy_client_json_st(std::shared_ptr<const ProxyServer::LinkedSession> ses);
static phosg::JSON generate_lobby_json_st(std::shared_ptr<const Lobby> l, std::shared_ptr<const ItemNameIndex> item_name_index);
phosg::JSON generate_accounts_json() const;
phosg::JSON generate_game_server_clients_json() const;
phosg::JSON generate_proxy_server_clients_json() const;
phosg::JSON generate_server_info_json() const;
@@ -111,4 +118,5 @@ protected:
phosg::JSON generate_common_tables_json() const;
phosg::JSON generate_rare_tables_json() const;
phosg::JSON generate_rare_table_json(const std::string& table_name) const;
phosg::JSON generate_quest_list_json(std::shared_ptr<const QuestIndex> q);
};
+48 -2
View File
@@ -1,5 +1,6 @@
#include "GVMEncoder.hh"
#include "ImageEncoder.hh"
#include <array>
#include <phosg/Encoding.hh>
#include <phosg/Image.hh>
#include <phosg/Strings.hh>
@@ -34,7 +35,7 @@ struct GVRHeader {
be_uint16_t height;
} __packed_ws__(GVRHeader, 0x10);
string encode_gvm(const phosg::Image& img, GVRDataFormat data_format, const std::string& internal_name, uint32_t global_index) {
string encode_gvm(const phosg::Image& img, GVRDataFormat data_format, const string& internal_name, uint32_t global_index) {
int8_t dimensions_field = -2;
{
size_t h = img.get_height();
@@ -111,3 +112,48 @@ string encode_gvm(const phosg::Image& img, GVRDataFormat data_format, const std:
return std::move(w.str());
}
static const array<uint32_t, 4> fon_colors = {0x000000FF, 0x555555FF, 0xAAAAAAFF, 0xFFFFFFFF};
phosg::Image decode_fon(const string& data, size_t width) {
size_t num_pixels = data.size() * 4;
size_t height = num_pixels / width;
phosg::Image ret(width, height);
phosg::BitReader r(data);
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
ret.write_pixel(x, y, fon_colors[r.read(2)]);
}
}
return ret;
}
constexpr size_t uabs(size_t a, size_t b) {
return (a > b) ? (a - b) : (b - a);
}
string encode_fon(const phosg::Image& img) {
phosg::BitWriter w;
for (size_t y = 0; y < img.get_height(); y++) {
for (size_t x = 0; x < img.get_width(); x++) {
uint32_t color = img.read_pixel(x, y);
size_t result_delta = 0x400;
size_t result_index = 0;
for (size_t z = 0; z < 4; z++) {
size_t delta = uabs((fon_colors[z] >> 24) & 0xFF, (color >> 24) & 0xFF) +
uabs((fon_colors[z] >> 16) & 0xFF, (color >> 16) & 0xFF) +
uabs((fon_colors[z] >> 8) & 0xFF, (color >> 8) & 0xFF) +
uabs(fon_colors[z] & 0xFF, color & 0xFF);
if (delta < result_delta) {
result_delta = delta;
result_index = z;
}
}
w.write(result_index & 2);
w.write(result_index & 1);
}
}
return w.str();
}
@@ -20,6 +20,8 @@ enum class GVRDataFormat : uint8_t {
};
std::string encode_gvm(const phosg::Image& img, GVRDataFormat data_format, const std::string& internal_name, uint32_t global_index);
phosg::Image decode_fon(const std::string& data, size_t width);
std::string encode_fon(const phosg::Image& img);
constexpr uint16_t encode_rgb565(uint8_t r, uint8_t g, uint8_t b) {
return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F);
+2 -2
View File
@@ -299,7 +299,7 @@ ItemData ItemCreator::check_rare_specs_and_create_rare_box_item(uint8_t area_nor
}
auto rare_specs = this->rare_item_set->get_box_specs(
this->mode, this->episode, this->difficulty, this->section_id, area_norm + 1);
this->mode, this->episode, this->difficulty, this->section_id, area_norm);
for (const auto& spec : rare_specs) {
item = this->check_rate_and_create_rare_item(spec, area_norm);
if (!item.empty()) {
@@ -869,7 +869,7 @@ void ItemCreator::generate_unit_stars_tables() {
star_base_index = 0x124;
num_units = 0x43;
break;
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
star_base_index = 0x128;
num_units = 0x44;
+53 -2
View File
@@ -8,13 +8,20 @@
using namespace std;
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_11_2000(
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_NTE(
{10});
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V1_V2(
{10, 10, 1, 10, 10, 10, 10, 10, 10, 1});
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4(
{10, 10, 1, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 99, 1});
const ItemData::StackLimits ItemData::StackLimits::DEFAULT_STACK_LIMITS_DC_NTE(
Version::DC_NTE, ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_NTE, 999999);
const ItemData::StackLimits ItemData::StackLimits::DEFAULT_STACK_LIMITS_V1_V2(
Version::DC_V1, ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V1_V2, 999999);
const ItemData::StackLimits ItemData::StackLimits::DEFAULT_STACK_LIMITS_V3_V4(
Version::GC_V3, ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4, 999999);
ItemData::StackLimits::StackLimits(
Version version, const vector<uint8_t>& max_tool_stack_sizes_by_data1_1, uint32_t max_meseta_stack_size)
: version(version),
@@ -126,6 +133,50 @@ uint32_t ItemData::primary_identifier() const {
}
}
void ItemData::change_primary_identifier(uint32_t primary_identifier) {
if (((primary_identifier >> 18) & 0xFF) != this->data1[0]) {
throw std::runtime_error("cannot change item class via change_primary_identifier");
}
switch (this->data1[0]) {
case 0x00: { // Weapon
bool was_s_rank_weapon = this->is_s_rank_weapon();
// Apply data1[1], and data1[2] if it's not an ES weapon
this->data1[1] = (primary_identifier >> 16) & 0xFF;
if (!this->is_s_rank_weapon()) {
this->data1[2] = (primary_identifier >> 8) & 0xFF;
} else if (!was_s_rank_weapon) {
// If it wasn't an S-rank weapon before and now is, clear its special
this->data1[2] = 0;
}
break;
}
case 0x01: // Armor/shield/unit
// Apply data1[1] and data1[2]
this->data1[1] = (primary_identifier >> 16) & 0xFF;
this->data1[2] = (primary_identifier >> 8) & 0xFF;
break;
case 0x02: // Mag
// Apply data1[1] only
this->data1[1] = (primary_identifier >> 16) & 0xFF;
break;
case 0x03: // Tool
// Apply data1[1] and data1[2] (or data1[4] if it's a tech disk)
this->data1[1] = (primary_identifier >> 16) & 0xFF;
if (this->data1[1] == 0x02) {
this->data1[4] = (primary_identifier >> 8) & 0xFF;
this->data1[2] = primary_identifier & 0xFF;
} else {
this->data1[2] = (primary_identifier >> 8) & 0xFF;
}
break;
case 0x04: // Meseta
// Nothing to apply
break;
default:
throw std::runtime_error("invalid item class");
}
}
bool ItemData::is_wrapped(const StackLimits& limits) const {
switch (this->data1[0]) {
case 0:
@@ -393,7 +444,6 @@ void ItemData::decode_for_version(Version from_version) {
this->data2[0] = this->data2w[1] & 0x7FFF; // Synchro
this->data2[2] = ((this->data2[3] >> 7) & 1) | ((this->data1w[2] >> 14) & 2) | ((this->data1w[3] >> 13) & 4); // PB flags
this->data2[3] = (this->data1w[2] & 1) | ((this->data1w[3] & 1) << 1) | ((this->data1w[4] & 1) << 2) | ((this->data1w[5] & 1) << 3); // Color
// 01000080
this->data1w[2] &= 0x7FFE;
this->data1w[3] &= 0x7FFE;
this->data1w[4] &= 0xFFFE;
@@ -757,6 +807,7 @@ string ItemData::short_hex() const {
size_t offset = ret.find_last_not_of('0');
if (offset != string::npos) {
offset += (offset & 1) ? 1 : 2;
offset = std::max<size_t>(offset, 6);
if (offset < ret.size()) {
ret.resize(offset);
}
+7 -2
View File
@@ -70,9 +70,13 @@ struct ItemData {
uint8_t get(uint8_t data1_0, uint8_t data1_1) const;
static const std::vector<uint8_t> DEFAULT_TOOL_LIMITS_DC_11_2000;
static const std::vector<uint8_t> DEFAULT_TOOL_LIMITS_DC_NTE; // Also for 11/2000
static const std::vector<uint8_t> DEFAULT_TOOL_LIMITS_V1_V2;
static const std::vector<uint8_t> DEFAULT_TOOL_LIMITS_V3_V4;
static const StackLimits DEFAULT_STACK_LIMITS_DC_NTE;
static const StackLimits DEFAULT_STACK_LIMITS_V1_V2;
static const StackLimits DEFAULT_STACK_LIMITS_V3_V4;
};
// QUICK ITEM FORMAT REFERENCE
@@ -89,7 +93,7 @@ struct ItemData {
// C = stack size (for tools)
// D = DEF bonus
// E = EVP bonus
// F = armor/shield/unit flags (40=present; low 16 bits are present color)
// F = armor/shield/unit flags (40=present; low 4 bits are present color)
// G = weapon grind
// H = mag DEF
// I = mag POW
@@ -150,6 +154,7 @@ struct ItemData {
std::string hex() const;
std::string short_hex() const;
uint32_t primary_identifier() const;
void change_primary_identifier(uint32_t primary_identifier);
bool is_wrapped(const StackLimits& limits) const;
void wrap(const StackLimits& limits, uint8_t present_color);
+5 -5
View File
@@ -97,7 +97,7 @@ const array<const char*, 0x11> name_for_s_rank_special = {
"King\'s",
};
std::string ItemNameIndex::describe_item(const ItemData& item, bool include_color_escapes) const {
std::string ItemNameIndex::describe_item(const ItemData& item, bool include_color_escapes, bool hide_mag_stats) const {
if (item.data1[0] == 0x04) {
return phosg::string_printf("%s%" PRIu32 " Meseta", include_color_escapes ? "$C7" : "", item.data2d.load());
}
@@ -166,8 +166,8 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
}
}
// For weapons, add the grind and bonuses, or S-rank name if applicable
if (item.data1[0] == 0x00) {
// For weapons, add the grind and bonuses, or S-rank name if applicable
if (item.data1[3] > 0) {
ret_tokens.emplace_back(phosg::string_printf("+%hhu", item.data1[3]));
}
@@ -232,8 +232,8 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
}
}
// For armors, add the slots, unit modifiers, and/or DEF/EVP bonuses
} else if (item.data1[0] == 0x01) {
// For armors, add the slots, unit modifiers, and/or DEF/EVP bonuses
if (item.data1[1] == 0x03) { // Units
int16_t modifier = item.data1w[3];
if (modifier == 1 || modifier == 2) {
@@ -266,8 +266,8 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
}
}
} else if (!hide_mag_stats && (item.data1[0] == 0x02)) {
// For mags, add tons of info
} else if (item.data1[0] == 0x02) {
ret_tokens.emplace_back(phosg::string_printf("LV%hhu", item.data1[2]));
uint16_t def = item.data1w[2];
@@ -327,8 +327,8 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
ret_tokens.emplace_back(phosg::string_printf("(!CL:%02hhX)", item.data2[3]));
}
// For tools, add the amount (if applicable)
} else if (item.data1[0] == 0x03) {
// For tools, add the amount (if applicable)
if (item.max_stack_size(*this->limits) > 1) {
ret_tokens.emplace_back(phosg::string_printf("x%hhu", item.data1[5]));
}
+4 -1
View File
@@ -35,7 +35,10 @@ public:
return this->name_index;
}
std::string describe_item(const ItemData& item, bool include_color_escapes = false) const;
inline bool exists(const ItemData& item) const {
return this->primary_identifier_index.count(item.primary_identifier());
}
std::string describe_item(const ItemData& item, bool include_color_escapes = false, bool hide_mag_stats = false) const;
ItemData parse_item_description(const std::string& description) const;
void print_table(FILE* stream) const;
+45 -9
View File
@@ -1,5 +1,7 @@
#include "ItemParameterTable.hh"
#include "CommonFileFormats.hh"
using namespace std;
ItemParameterTable::ItemParameterTable(shared_ptr<const string> data, Version version)
@@ -28,7 +30,7 @@ ItemParameterTable::ItemParameterTable(shared_ptr<const string> data, Version ve
// TODO: Check if first_rare_mag_index is the same on this version
break;
}
case Version::DC_V1_11_2000_PROTOTYPE: {
case Version::DC_11_2000: {
this->offsets_dc_protos = &this->r.pget<TableOffsetsDCProtos>(offset_table_offset);
this->num_weapon_classes = 0x27;
this->num_tool_classes = 0x0E;
@@ -416,15 +418,12 @@ ItemParameterTable::ToolV4 ItemParameterTable::ToolV3T<BE>::to_v4() const {
template <bool BE>
size_t indirect_lookup_2d_count(const phosg::StringReader& r, size_t root_offset, size_t co_index) {
using ArrayRefT = typename std::conditional_t<BE, ItemParameterTable::ArrayRefBE, ItemParameterTable::ArrayRef>;
return r.pget<ArrayRefT>(root_offset + sizeof(ArrayRefT) * co_index).count;
return r.pget<ArrayRefT<BE>>(root_offset + sizeof(ArrayRefT<BE>) * co_index).count;
}
template <typename T, bool BE>
const T& indirect_lookup_2d(const phosg::StringReader& r, size_t root_offset, size_t co_index, size_t item_index) {
using ArrayRefT = typename std::conditional_t<BE, ItemParameterTable::ArrayRefBE, ItemParameterTable::ArrayRef>;
const auto& co = r.pget<ArrayRefT>(root_offset + sizeof(ArrayRefT) * co_index);
const auto& co = r.pget<ArrayRefT<BE>>(root_offset + sizeof(ArrayRefT<BE>) * co_index);
if (item_index >= co.count) {
throw out_of_range("item ID out of range");
}
@@ -740,6 +739,40 @@ pair<uint8_t, uint8_t> ItemParameterTable::find_tool_by_id(uint32_t item_id) con
}
}
variant<
const ItemParameterTable::WeaponV4*,
const ItemParameterTable::ArmorOrShieldV4*,
const ItemParameterTable::UnitV4*,
const ItemParameterTable::MagV4*,
const ItemParameterTable::ToolV4*>
ItemParameterTable::definition_for_primary_identifier(uint32_t primary_identifier) const {
uint8_t data1_0 = (primary_identifier >> 24) & 0xFF;
uint8_t data1_1 = (primary_identifier >> 16) & 0xFF;
uint8_t data1_2 = (primary_identifier >> 8) & 0xFF;
switch (data1_0) {
case 0:
return &this->get_weapon(data1_1, data1_2);
case 1:
switch (data1_1) {
case 1:
case 2:
return &this->get_armor_or_shield(data1_1, data1_2);
case 3:
return &this->get_unit(data1_2);
default:
throw runtime_error("invalid primary identifier");
}
case 2:
return &this->get_mag(data1_1);
case 3:
// NOTE: Unlike in ItemData, the tech number comes first in primary
// identifiers, so we don't need to special-case 0302XXYY here
return &this->get_tool(data1_1, data1_2);
default:
throw runtime_error("invalid primary identifier");
}
}
template <bool BE, typename OffsetsT>
float ItemParameterTable::get_sale_divisor_t(const OffsetsT* offsets, uint8_t data1_0, uint8_t data1_1) const {
switch (data1_0) {
@@ -1255,14 +1288,17 @@ size_t ItemParameterTable::price_for_item(const ItemData& item) const {
throw logic_error("this should be impossible");
}
MagEvolutionTable::MagEvolutionTable(shared_ptr<const string> data)
MagEvolutionTable::MagEvolutionTable(shared_ptr<const string> data, size_t num_mags)
: data(data),
num_mags(num_mags),
r(*data) {
size_t offset_table_offset = this->r.pget_u32l(this->data->size() - 0x10);
this->offsets = &r.pget<TableOffsets>(offset_table_offset);
}
uint8_t MagEvolutionTable::get_evolution_number(uint8_t data1_1) const {
const auto& table = this->r.pget<EvolutionNumberTable>(this->offsets->evolution_number);
return table.values[data1_1];
if (data1_1 >= this->num_mags) {
throw runtime_error("invalid mag number");
}
return this->r.pget_u8(this->offsets->evolution_number + data1_1);
}
+77 -27
View File
@@ -2,16 +2,19 @@
#include <stdint.h>
#include <array>
#include <map>
#include <memory>
#include <phosg/Encoding.hh>
#include <set>
#include <string>
#include <variant>
#include <vector>
#include "ItemData.hh"
#include "Text.hh"
#include "Types.hh"
#include "Version.hh"
class ItemParameterTable {
public:
@@ -19,18 +22,6 @@ public:
// functions instead of manually branching on various offset table pointers
// being null or not in each public function. Rewrite this and make it better.
template <bool BE>
struct ArrayRefT {
/* 00 */ U32T<BE> count;
/* 04 */ U32T<BE> offset;
/* 08 */
} __packed__;
using ArrayRef = ArrayRefT<false>;
using ArrayRefBE = ArrayRefT<true>;
check_struct_size(ArrayRef, 8);
check_struct_size(ArrayRefBE, 8);
template <bool BE>
struct ItemBaseV2T {
// id specifies several things; notably, it doubles as the index of the
@@ -450,7 +441,6 @@ public:
ItemParameterTable(std::shared_ptr<const std::string> data, Version version);
~ItemParameterTable() = default;
void print(FILE* stream) const;
std::set<uint32_t> compute_all_valid_primary_identifiers() const;
size_t num_weapons_in_class(uint8_t data1_1) const;
@@ -465,6 +455,9 @@ public:
const ToolV4& get_tool(uint8_t data1_1, uint8_t data1_2) const;
std::pair<uint8_t, uint8_t> find_tool_by_id(uint32_t id) const;
std::variant<const WeaponV4*, const ArmorOrShieldV4*, const UnitV4*, const MagV4*, const ToolV4*>
definition_for_primary_identifier(uint32_t primary_identifier) const;
float get_sale_divisor(uint8_t data1_0, uint8_t data1_1) const;
const MagFeedResult& get_mag_feed_result(uint8_t table_index, uint8_t which) const;
uint8_t get_item_stars(uint32_t id) const;
@@ -496,7 +489,7 @@ public:
size_t num_specials;
size_t first_rare_mag_index;
private:
protected:
struct TableOffsetsDCProtos {
/* ## / NTE / 11/2000 */
/* 00 / 0013 / 0013 */ le_uint32_t unknown_a0;
@@ -635,27 +628,84 @@ private:
class MagEvolutionTable {
public:
// TODO: V1 format is different! Offsets are 0438 0440 0498 0520 054C
struct MotionReference {
struct Side {
// This specifies which entry in ItemMagMotion.dat is used. The file is
// just a list of 0x64-byte structures. 0xFF = no TItemMagSub is created
uint8_t motion_table_entry = 0xFF;
parray<uint8_t, 5> unknown_a1;
} __packed_ws__(Side, 0x06);
parray<Side, 2> sides; // [0] = right side, [1] = left side
} __packed_ws__(MotionReference, 0x0C);
struct MotionReferenceTables {
// It seems that there are two definition tables, but only the first is
// used on any version of PSO. On v3 and later, the two offsets point to
// the same table, but on v2 they don't and the second table contains
// different data.
// TODO: Figure out what the deal is with the different v2 tables.
le_uint32_t ref_table; // -> MotionReference[num_mags]
le_uint32_t unused_ref_table; // -> MotionReference[num_mags]
} __packed_ws__(MotionReferenceTables, 0x08);
struct ColorEntry {
// Colors are specified as 4 floats, each in the range [0, 1], for each
// color channel. The default colors are:
// alpha red green blue color (see StaticGameData.cc)
// 1.0 1.0 0.2 0.1 red
// 1.0 0.2 0.2 1.0 blue
// 1.0 1.0 0.9 0.1 yellow
// 1.0 0.1 1.0 0.1 green
// 1.0 0.8 0.1 1.0 purple
// 1.0 0.1 0.1 0.2 black
// 1.0 0.9 1.0 1.0 white
// 1.0 0.1 0.9 1.0 cyan
// 1.0 0.5 0.3 0.2 brown
// 1.0 1.0 0.4 0.0 orange (v3+)
// 1.0 0.502 0.545 0.977 light-blue (v3+)
// 1.0 0.502 0.502 0.0 olive (v3+)
// 1.0 0.0 0.941 0.714 turquoise (v3+)
// 1.0 0.8 0.098 0.392 fuchsia (v3+)
// 1.0 0.498 0.498 0.498 grey (v3+)
// 1.0 0.996 0.996 0.832 cream (v3+)
// 1.0 0.996 0.498 0.784 pink (v3+)
// 1.0 0.0 0.498 0.322 dark-green (v3+)
le_float alpha;
le_float red;
le_float green;
le_float blue;
} __packed_ws__(ColorEntry, 0x10);
struct UnknownA3Entry {
uint8_t flags;
uint8_t unknown_a2;
le_uint16_t unknown_a3;
le_uint16_t unknown_a4;
le_uint16_t unknown_a5;
} __packed_ws__(UnknownA3Entry, 0x08);
struct TableOffsets {
// num_mags = 0x53 in BB, 0x43 in V3
/* 00 / 0400 */ le_uint32_t unknown_a1; // -> [offset -> (0xC-byte struct)[num_mags], offset -> (same as first offset)]
/* 04 / 0408 */ le_uint32_t unknown_a2; // -> (2-byte struct, or single word)[num_mags]
/* 08 / 04AE */ le_uint32_t unknown_a3; // -> (0xA8 bytes; possibly (8-byte struct)[0x15])
/* 0C / 0556 */ le_uint32_t unknown_a4; // -> (uint8_t)[num_mags]
/* 10 / 05AC */ le_uint32_t unknown_a5; // -> (float)[0x48]
/* 14 / 06CC */ le_uint32_t evolution_number; // -> (uint8_t)[num_mags]
// num_mags = 0x3A in v2 and GC NTE, 0x43 in V3, 0x53 in BB
// num_colors = 0x09 in v2 and GC NTE, 0x12 in V3/BB
// TODO: GC NTE uses the v2 format but is big-endian
/* -- / V2 / V3 / BB */
/* 00 / 05BC / 0340 / 0400 */ le_uint32_t motion_tables; // -> MotionReferenceTables
/* 04 / 0594 / 0348 / 0408 */ le_uint32_t unknown_a2; // -> (uint8_t[2])[num_mags] (references into unknown_a3)
/* 08 / 0608 / 03CE / 04AE */ le_uint32_t unknown_a3; // -> UnknownA3Entry[max(unknown_a2) + 1]
/* 0C / 06B0 / 0476 / 0556 */ le_uint32_t unknown_a4; // -> (uint8_t)[num_mags]
/* 10 / 06EC / 04BC / 05AC */ le_uint32_t color_table; // -> ColorEntry[num_colors]
/* 14 / 077C / 05DC / 06CC */ le_uint32_t evolution_number; // -> uint8_t[num_mags]
} __packed_ws__(TableOffsets, 0x18);
struct EvolutionNumberTable {
parray<uint8_t, 0x53> values;
} __packed_ws__(EvolutionNumberTable, 0x53);
MagEvolutionTable(std::shared_ptr<const std::string> data);
MagEvolutionTable(std::shared_ptr<const std::string> data, size_t num_mags);
~MagEvolutionTable() = default;
uint8_t get_evolution_number(uint8_t data1_1) const;
private:
protected:
std::shared_ptr<const std::string> data;
size_t num_mags;
phosg::StringReader r;
const TableOffsets* offsets;
};
+110
View File
@@ -0,0 +1,110 @@
#include "ItemTranslationTable.hh"
using namespace std;
static constexpr bool is_canonical(uint32_t id) {
return !(id & 0x80000000);
}
static constexpr uint32_t make_canonical(uint32_t id) {
return (id & 0x7FFFFFFF);
}
ItemTranslationTable::ItemTranslationTable(
const phosg::JSON& json,
const std::array<std::shared_ptr<const ItemParameterTable>, NUM_VERSIONS>& item_parameter_tables) {
// Parse the table and build the indexes
const auto& l = json.as_list();
for (size_t z = 0; z < l.size(); z++) {
const auto& e = this->entries.emplace_back(*l[z]);
bool has_any_canonical_id = false;
for (size_t v_s = 0; v_s < NUM_NON_PATCH_VERSIONS; v_s++) {
uint32_t id = e.id_for_version[v_s];
if (is_canonical(id)) {
has_any_canonical_id = true;
if (!this->entry_index_for_version[v_s].emplace(id, z).second) {
throw runtime_error(phosg::string_printf("(row %zu) duplicate canonical ID %08" PRIX32, z, id));
}
}
}
if (!has_any_canonical_id) {
throw runtime_error(phosg::string_printf("(row %zu) no canonical ID present in row", z));
}
}
// Validate the table by checking that:
// - Each non-canonical ID points to an existing canonical ID
// - Each canonical ID has an entry in the item parameter table
// - All items in the parameter tables are represented in the translation table
for (size_t v_s = 0; v_s < NUM_NON_PATCH_VERSIONS; v_s++) {
Version v = static_cast<Version>(v_s + NUM_PATCH_VERSIONS);
auto item_parameter_table = item_parameter_tables.at(v_s + NUM_PATCH_VERSIONS);
auto remaining_identifiers = item_parameter_table->compute_all_valid_primary_identifiers();
const auto& entry_index = this->entry_index_for_version[v_s];
for (size_t z = 0; z < this->entries.size(); z++) {
uint32_t e_id = this->entries[z].id_for_version[v_s];
if (is_canonical(e_id)) {
if (!entry_index.count(e_id)) {
throw logic_error(phosg::string_printf("(row %zu version %s) canonical ID %" PRIX32 " is missing from the index", z, phosg::name_for_enum(v), e_id));
}
try {
item_parameter_table->definition_for_primary_identifier(e_id);
} catch (const out_of_range&) {
throw runtime_error(phosg::string_printf("(row %zu version %s) ID %" PRIX32 " not defined in item parameter table", z, phosg::name_for_enum(v), e_id));
}
if (!remaining_identifiers.erase(e_id)) {
throw runtime_error(phosg::string_printf("(row %zu version %s) ID %" PRIX32 " not in item parameter table's primary identifier list", z, phosg::name_for_enum(v), e_id));
}
} else if (!entry_index.count(make_canonical(e_id))) {
throw runtime_error(phosg::string_printf("(row %zu version %s) ID %" PRIX32 " refers to nonexistent canonical ID", z, phosg::name_for_enum(v), e_id));
}
}
if (!remaining_identifiers.empty()) {
string missing_str = phosg::string_printf("(version %s) not all identifiers in the item parameter table are defined in the translation table; missing:", phosg::name_for_enum(v));
for (uint32_t id : remaining_identifiers) {
missing_str += phosg::string_printf(" %08" PRIX32, id);
}
throw runtime_error(missing_str);
}
}
}
phosg::JSON ItemTranslationTable::json() const {
auto ret = phosg::JSON::list();
for (const auto& entry : this->entries) {
ret.emplace_back(entry.json());
}
return ret;
}
uint32_t ItemTranslationTable::translate(uint32_t primary_identifier, Version from_version, Version to_version) const {
if (from_version == to_version) {
return primary_identifier;
}
const auto& entry_index = this->entry_index_for_version.at(static_cast<size_t>(from_version) - NUM_PATCH_VERSIONS);
size_t entry_num = entry_index.at(primary_identifier);
const auto& entry = this->entries.at(entry_num);
return make_canonical(entry.id_for_version.at(static_cast<size_t>(to_version) - NUM_PATCH_VERSIONS));
}
ItemTranslationTable::Entry::Entry(const phosg::JSON& json) {
const auto& l = json.as_list();
if (l.size() != NUM_NON_PATCH_VERSIONS + 1) {
throw runtime_error("list length is incorrect");
}
for (size_t z = 0; z < NUM_NON_PATCH_VERSIONS; z++) {
this->id_for_version[z] = l[z]->as_int();
}
this->name = l[NUM_NON_PATCH_VERSIONS]->as_string();
}
phosg::JSON ItemTranslationTable::Entry::json() const {
auto ret = phosg::JSON::list();
for (size_t z = 0; z < NUM_NON_PATCH_VERSIONS; z++) {
ret.emplace_back(this->id_for_version[z]);
}
ret.emplace_back(this->name);
return ret;
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <stdint.h>
#include <array>
#include <memory>
#include <phosg/JSON.hh>
#include <string>
#include <unordered_map>
#include "ItemParameterTable.hh"
#include "Types.hh"
#include "Version.hh"
class ItemTranslationTable {
public:
ItemTranslationTable(
const phosg::JSON& json,
const std::array<std::shared_ptr<const ItemParameterTable>, NUM_VERSIONS>& item_parameter_tables);
~ItemTranslationTable() = default;
phosg::JSON json() const;
uint32_t translate(uint32_t primary_identifier, Version from_version, Version to_version) const;
private:
struct Entry {
std::array<uint32_t, NUM_NON_PATCH_VERSIONS> id_for_version;
std::string name;
explicit Entry(const phosg::JSON& json);
phosg::JSON json() const;
};
std::vector<Entry> entries;
std::array<std::unordered_map<uint32_t, size_t>, NUM_NON_PATCH_VERSIONS> entry_index_for_version;
};
+34 -31
View File
@@ -135,35 +135,32 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
item.flags &= (~8); // Unequip it
should_delete_item = false;
} else if (primary_identifier == 0x030C0000) {
// Cell of MAG 502
} else if ((primary_identifier & 0xFFFF0000) == 0x030C0000) { // Non-combo mag cells
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x1D : 0x21;
} else if (primary_identifier == 0x030C0100) {
// Cell of MAG 213
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x27 : 0x22;
} else if (primary_identifier == 0x030C0200) {
// Parts of RoboChao
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = 0x28;
} else if (primary_identifier == 0x030C0300) {
// Heart of Opa Opa
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = 0x29;
} else if (primary_identifier == 0x030C0400) {
// Heart of Pian
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = 0x2A;
} else if (primary_identifier == 0x030C0500) {
// Heart of Chao
auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)];
mag.data.data1[1] = 0x2B;
if (s->mag_evolution_table(c->version())->get_evolution_number(mag.data.data1[1]) < 4) {
switch (item.data.data1[2]) {
case 0x00: // Cell of MAG 502
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x1D : 0x21;
break;
case 0x01: // Cell of MAG 213
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x27 : 0x22;
break;
case 0x02: // Parts of RoboChao
mag.data.data1[1] = 0x28;
break;
case 0x03: // Heart of Opa Opa
mag.data.data1[1] = 0x29;
break;
case 0x04: // Heart of Pian
mag.data.data1[1] = 0x2A;
break;
case 0x05: // Heart of Chao
mag.data.data1[1] = 0x2B;
break;
default:
throw runtime_error("invalid mag cell used");
}
}
} else if ((primary_identifier & 0xFFFF0000) == 0x03150000) {
// Christmas Present, etc. - use unwrap_table + probabilities therein
@@ -176,6 +173,10 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
if (sum == 0) {
throw runtime_error("no unwrap results available for event");
}
// TODO: It seems that on non-BB, clients don't synchronize this at all, so
// they could end up thinking the unwrapped item is something completely
// different. (They don't even use a fixed random seed, like for rares;
// they just call rand().) How does this actually work on console PSO?
size_t det = random_from_optional_crypt(opt_rand_crypt) % sum;
for (size_t z = 0; z < table.second; z++) {
const auto& entry = table.first[z];
@@ -190,8 +191,10 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
should_delete_item = false;
auto l = c->require_lobby();
if (l->base_version == Version::BB_V4) {
send_create_inventory_item_to_lobby(c, c->lobby_client_id, item.data);
for (const auto& lc : l->clients) {
if (lc && (lc->version() == Version::BB_V4)) {
send_create_inventory_item_to_client(c, c->lobby_client_id, item.data);
}
}
break;
}
@@ -501,7 +504,7 @@ void player_feed_mag(std::shared_ptr<Client> c, size_t mag_item_index, size_t fe
player->inventory.items[mag_item_index].data,
player->inventory.items[fed_item_index].data,
s->item_parameter_table(c->version()),
s->mag_evolution_table,
s->mag_evolution_table(c->version()),
player->disp.visual.char_class,
player->disp.visual.section_id,
!is_v1_or_v2(c->version()));
+7 -3
View File
@@ -4,6 +4,7 @@
#include <phosg/Filesystem.hh>
#include "CommonFileFormats.hh"
#include "Compression.hh"
#include "PSOEncryption.hh"
@@ -63,7 +64,8 @@ LevelTableV2::LevelTableV2(const string& data, bool compressed) {
r = phosg::StringReader(data);
}
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
const auto& footer = r.pget<RELFileFooter>(r.size() - sizeof(RELFileFooter));
const auto& offsets = r.pget<Offsets>(footer.root_offset);
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.level_deltas);
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.base_stats);
for (size_t char_class = 0; char_class < 9; char_class++) {
@@ -112,7 +114,8 @@ LevelTableV3BE::LevelTableV3BE(const string& data, bool encrypted) {
// u32 offset:
// u32[12] offsets:
// LevelStatsDeltaBE[200] level_deltas
const auto& offsets = r.pget<parray<be_uint32_t, 12>>(r.pget_u32b(r.pget_u32b(r.size() - 0x10)));
const auto& footer = r.pget<RELFileFooterBE>(r.size() - sizeof(RELFileFooterBE));
const auto& offsets = r.pget<parray<be_uint32_t, 12>>(r.pget_u32b(footer.root_offset));
for (size_t char_class = 0; char_class < 12; char_class++) {
const auto& src_deltas = r.pget<parray<LevelStatsDeltaBE, 200>>(offsets[char_class]);
for (size_t level = 0; level < 200; level++) {
@@ -189,7 +192,8 @@ LevelTableV4::LevelTableV4(const string& data, bool compressed) {
r = phosg::StringReader(data);
}
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
const auto& footer = r.pget<RELFileFooter>(r.size() - sizeof(RELFileFooter));
const auto& offsets = r.pget<Offsets>(footer.root_offset);
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.level_deltas);
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.base_stats);
for (size_t char_class = 0; char_class < 12; char_class++) {
+67 -220
View File
@@ -27,12 +27,18 @@ shared_ptr<Lobby::FloorItem> Lobby::FloorItemManager::find(uint32_t item_id) con
return this->items.at(item_id);
}
void Lobby::FloorItemManager::add(const ItemData& item, float x, float z, uint16_t flags) {
void Lobby::FloorItemManager::add(
const ItemData& item,
const VectorXZF& pos,
shared_ptr<const MapState::ObjectState> from_obj,
shared_ptr<const MapState::EnemyState> from_ene,
uint16_t flags) {
auto fi = make_shared<FloorItem>();
fi->data = item;
fi->x = x;
fi->z = z;
fi->pos = pos;
fi->drop_number = this->next_drop_number++;
fi->from_obj = from_obj;
fi->from_ene = from_ene;
fi->flags = flags;
this->add(fi);
}
@@ -52,7 +58,7 @@ void Lobby::FloorItemManager::add(shared_ptr<Lobby::FloorItem> fi) {
}
}
this->log.info("Added floor item %08" PRIX32 " at %g, %g with drop number %" PRIu64 " with flags %03hX",
fi->data.id.load(), fi->x, fi->z, fi->drop_number, fi->flags);
fi->data.id.load(), fi->pos.x.load(), fi->pos.z.load(), fi->drop_number, fi->flags);
}
std::shared_ptr<Lobby::FloorItem> Lobby::FloorItemManager::remove(uint32_t item_id, uint8_t client_id) {
@@ -71,7 +77,7 @@ std::shared_ptr<Lobby::FloorItem> Lobby::FloorItemManager::remove(uint32_t item_
}
this->items.erase(item_it);
this->log.info("Removed floor item %08" PRIX32 " at %g, %g with drop number %" PRIu64 " with flags %03hX",
fi->data.id.load(), fi->x, fi->z, fi->drop_number, fi->flags);
fi->data.id.load(), fi->pos.x.load(), fi->pos.z.load(), fi->drop_number, fi->flags);
return fi;
}
@@ -142,7 +148,6 @@ Lobby::Lobby(shared_ptr<ServerState> s, uint32_t id, bool is_game)
min_level(0),
max_level(0xFFFFFFFF),
next_game_item_id(0xCC000000),
base_version(Version::GC_V3),
allowed_versions(0x0000),
override_section_id(0xFF),
episode(Episode::NONE),
@@ -196,31 +201,29 @@ shared_ptr<Lobby::ChallengeParameters> Lobby::require_challenge_params() const {
return this->challenge_params;
}
void Lobby::set_drop_mode(DropMode new_mode) {
this->drop_mode = new_mode;
bool should_have_item_creator = (this->base_version == Version::BB_V4) ||
((new_mode != DropMode::DISABLED) && (new_mode != DropMode::CLIENT));
if (should_have_item_creator && !this->item_creator) {
this->create_item_creator();
} else if (!should_have_item_creator && this->item_creator) {
void Lobby::create_item_creator(Version logic_version) {
if (!this->is_game() || this->episode == Episode::EP3) {
this->item_creator.reset();
return;
}
}
void Lobby::create_item_creator() {
auto s = this->require_server_state();
if (logic_version == Version::UNKNOWN) {
auto leader_c = this->clients[this->leader_id];
logic_version = leader_c ? leader_c->version() : Version::BB_V4;
}
shared_ptr<const RareItemSet> rare_item_set;
shared_ptr<const CommonItemSet> common_item_set;
switch (this->base_version) {
switch (logic_version) {
case Version::PC_PATCH:
case Version::BB_PATCH:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
throw runtime_error("cannot create item creator for this base version");
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
// TODO: We should probably have a v1 common item set at some point too
common_item_set = s->common_item_set_v2;
@@ -245,6 +248,7 @@ void Lobby::create_item_creator() {
default:
throw logic_error("invalid lobby base version");
}
this->item_creator = make_shared<ItemCreator>(
common_item_set,
rare_item_set,
@@ -252,8 +256,8 @@ void Lobby::create_item_creator() {
s->tool_random_set,
s->weapon_random_sets.at(this->difficulty),
s->tekker_adjustment_set,
s->item_parameter_table(this->base_version),
s->item_stack_limits(this->base_version),
s->item_parameter_table(logic_version),
s->item_stack_limits(logic_version),
this->episode,
(this->mode == GameMode::SOLO) ? GameMode::NORMAL : this->mode,
this->difficulty,
@@ -262,21 +266,6 @@ void Lobby::create_item_creator() {
this->quest ? this->quest->battle_rules : nullptr);
}
void Lobby::change_section_id() {
if (this->item_creator) {
uint8_t new_section_id = this->effective_section_id();
if (this->item_creator->get_section_id() != new_section_id) {
this->log.info("Changing section ID to %s", name_for_section_id(new_section_id));
this->item_creator->set_section_id(new_section_id);
for (const auto& c : this->clients) {
if (c && c->config.check_flag(Client::Flag::DEBUG_ENABLED)) {
send_text_message_printf(c, "$C5Section ID changed\nto %s (%hhu)", name_for_section_id(new_section_id), new_section_id);
}
}
}
}
}
uint8_t Lobby::effective_section_id() const {
if (this->override_section_id != 0xFF) {
return this->override_section_id;
@@ -291,199 +280,50 @@ uint8_t Lobby::effective_section_id() const {
return 0;
}
shared_ptr<Map> Lobby::load_maps(
Version version,
Episode episode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t random_seed,
shared_ptr<PSOLFGEncryption> opt_rand_crypt,
shared_ptr<const string> quest_dat_contents_decompressed) {
auto map = make_shared<Map>(version, lobby_id, random_seed, opt_rand_crypt);
map->add_entities_from_quest_data(episode, difficulty, event, quest_dat_contents_decompressed, rare_rates);
return map;
}
shared_ptr<Map> Lobby::load_maps(
Version version,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
shared_ptr<const SetDataTableBase> sdt,
function<shared_ptr<const string>(Version, const string&)> get_file_data,
shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t random_seed,
shared_ptr<PSOLFGEncryption> opt_rand_crypt,
const parray<le_uint32_t, 0x20>& variations,
const phosg::PrefixedLogger* log) {
auto enemy_filenames = sdt->map_filenames_for_variations(variations, episode, mode, SetDataTable::FilenameType::ENEMIES);
auto object_filenames = sdt->map_filenames_for_variations(variations, episode, mode, SetDataTable::FilenameType::OBJECTS);
auto event_filenames = sdt->map_filenames_for_variations(variations, episode, mode, SetDataTable::FilenameType::EVENTS);
return Lobby::load_maps(
enemy_filenames,
object_filenames,
event_filenames,
version,
episode,
mode,
difficulty,
event,
lobby_id,
get_file_data,
rare_rates,
random_seed,
opt_rand_crypt,
log);
}
shared_ptr<Map> Lobby::load_maps(
const vector<string>& enemy_filenames,
const vector<string>& object_filenames,
const vector<string>& event_filenames,
Version version,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
function<shared_ptr<const string>(Version, const string&)> get_file_data,
shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t rare_seed,
shared_ptr<PSOLFGEncryption> opt_rand_crypt,
const phosg::PrefixedLogger* log) {
auto map = make_shared<Map>(version, lobby_id, rare_seed, opt_rand_crypt);
// Don't load free-roam maps in Challenge mode, since players can't go to
// Ragol without a quest loaded
if (mode == GameMode::CHALLENGE) {
return map;
}
for (size_t floor = 0; floor < 0x12; floor++) {
const auto& floor_enemy_filename = enemy_filenames.at(floor);
if (!floor_enemy_filename.empty()) {
auto map_data = get_file_data(version, floor_enemy_filename);
if (map_data) {
map->add_enemies_from_map_data(
episode,
difficulty,
event,
floor,
map_data->data(),
map_data->size(),
rare_rates);
if (log) {
log->info("Loaded enemies map %s for floor %02zX", floor_enemy_filename.c_str(), floor);
}
} else if (log) {
log->info("Enemies map %s for floor %02zX cannot be used; skipping", floor_enemy_filename.c_str(), floor);
}
} else if (log) {
log->info("No enemies to load for floor %02zX", floor);
}
const auto& floor_object_filename = object_filenames.at(floor);
if (!floor_object_filename.empty()) {
auto map_data = get_file_data(version, floor_object_filename);
if (map_data) {
map->add_objects_from_map_data(floor, map_data);
if (log) {
log->info("Loaded objects map %s for floor %02zX", floor_object_filename.c_str(), floor);
}
} else if (log) {
log->info("Objects map %s for floor %02zX cannot be used; skipping", floor_object_filename.c_str(), floor);
}
} else if (log) {
log->info("No objects to load for floor %02zX", floor);
}
const auto& floor_event_filename = event_filenames.at(floor);
if (!floor_event_filename.empty()) {
auto map_data = get_file_data(version, floor_event_filename);
if (map_data) {
map->add_events_from_map_data(floor, map_data->data(), map_data->size());
if (log) {
log->info("Loaded events map %s for floor %02zX", floor_event_filename.c_str(), floor);
}
} else if (log) {
log->info("Events map %s for floor %02zX cannot be used; skipping", floor_event_filename.c_str(), floor);
}
} else if (log) {
log->info("No events to load for floor %02zX", floor);
uint16_t Lobby::quest_version_flags() const {
uint16_t ret = 0;
for (auto lc : this->clients) {
if (lc) {
ret |= (1 << static_cast<size_t>(lc->version()));
}
}
return map;
return ret;
}
void Lobby::load_maps() {
auto rare_rates = ((this->base_version == Version::BB_V4) && this->rare_enemy_rates)
? this->rare_enemy_rates
: Map::DEFAULT_RARE_ENEMIES;
auto rare_rates = this->rare_enemy_rates ? this->rare_enemy_rates : MapState::DEFAULT_RARE_ENEMIES;
if (this->quest) {
auto leader_c = this->clients.at(this->leader_id);
if (!leader_c) {
throw logic_error("lobby leader is missing");
}
auto vq = this->quest->version(this->base_version, leader_c->language());
if (!vq->dat_contents_decompressed) {
throw runtime_error("quest does not have DAT data");
}
this->map = this->load_maps(
this->base_version,
this->episode,
if (this->episode == Episode::EP3) {
this->map_state = make_shared<MapState>();
} else if (this->quest) {
this->map_state = make_shared<MapState>(
this->lobby_id,
this->difficulty,
this->event,
this->lobby_id,
rare_rates,
this->random_seed,
this->rare_enemy_rates,
this->opt_rand_crypt,
vq->dat_contents_decompressed);
} else if (this->mode != GameMode::CHALLENGE) {
auto s = this->require_server_state();
this->map = this->load_maps(
this->base_version,
this->episode,
this->mode,
this->difficulty,
this->event,
this->lobby_id,
s->set_data_table(this->base_version, this->episode, this->mode, this->difficulty),
bind(&ServerState::load_map_file, s.get(), placeholders::_1, placeholders::_2),
rare_rates,
this->random_seed,
this->opt_rand_crypt,
this->variations,
&this->log);
this->quest->get_supermap(this->random_seed));
} else {
this->map = make_shared<Map>(this->base_version, this->lobby_id, this->random_seed, this->opt_rand_crypt);
auto s = this->require_server_state();
this->map_state = make_shared<MapState>(
this->lobby_id,
this->difficulty,
this->event,
this->random_seed,
this->rare_enemy_rates,
this->opt_rand_crypt,
s->supermaps_for_variations(this->episode, this->mode, this->difficulty, this->variations));
}
}
this->log.info("Generated objects list (%zu entries):", this->map->objects.size());
for (size_t z = 0; z < this->map->objects.size(); z++) {
string o_str = this->map->objects[z].str();
this->log.info("(K-%zX) %s", z, o_str.c_str());
[[nodiscard]] bool Lobby::is_ep3_nte() const {
for (const auto& lc : this->clients) {
if (lc && (lc->version() != Version::GC_EP3_NTE)) {
return false;
}
}
this->log.info("Generated enemies list (%zu entries):", this->map->enemies.size());
for (size_t z = 0; z < this->map->enemies.size(); z++) {
string e_str = this->map->enemies[z].str();
this->log.info("(E-%zX) %s", z, e_str.c_str());
}
this->log.info("Generated events list (%zu entries):", this->map->events.size());
for (size_t z = 0; z < this->map->events.size(); z++) {
string e_str = this->map->events[z].str();
this->log.info("%s", e_str.c_str());
}
this->log.info("Loaded maps contain %zu object entries and %zu enemy entries overall (%zu as rares)",
this->map->objects.size(), this->map->enemies.size(), this->map->rare_enemy_indexes.size());
return true;
}
void Lobby::create_ep3_server() {
@@ -494,7 +334,8 @@ void Lobby::create_ep3_server() {
this->log.info("Recreating Episode 3 server state");
}
auto tourn = this->tournament_match ? this->tournament_match->tournament.lock() : nullptr;
bool is_nte = this->base_version == Version::GC_EP3_NTE;
bool is_nte = this->is_ep3_nte();
Episode3::Server::Options options = {
.card_index = is_nte ? s->ep3_card_index_trial : s->ep3_card_index,
.map_index = s->ep3_map_index,
@@ -504,7 +345,7 @@ void Lobby::create_ep3_server() {
.tournament = tourn,
.trap_card_ids = s->ep3_trap_card_ids,
};
if (this->base_version == Version::GC_EP3_NTE) {
if (is_nte) {
options.behavior_flags |= Episode3::BehaviorFlag::IS_TRIAL_EDITION;
} else {
options.behavior_flags &= (~Episode3::BehaviorFlag::IS_TRIAL_EDITION);
@@ -520,7 +361,7 @@ void Lobby::reassign_leader_on_client_departure(size_t leaving_client_index) {
}
if (this->clients[x]) {
this->leader_id = x;
this->change_section_id();
this->create_item_creator();
return;
}
}
@@ -611,7 +452,7 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
}
if (leader_index >= this->max_clients) {
this->leader_id = c->lobby_client_id;
this->change_section_id();
this->create_item_creator();
}
// If this is a lobby or no one was here before this, reassign all the floor
@@ -850,9 +691,15 @@ shared_ptr<Lobby::FloorItem> Lobby::find_item(uint8_t floor, uint32_t item_id) c
return this->floor_item_managers.at(floor).find(item_id);
}
void Lobby::add_item(uint8_t floor, const ItemData& data, float x, float z, uint16_t flags) {
void Lobby::add_item(
uint8_t floor,
const ItemData& data,
const VectorXZF& pos,
std::shared_ptr<const MapState::ObjectState> from_obj,
std::shared_ptr<const MapState::EnemyState> from_ene,
uint16_t flags) {
auto& m = this->floor_item_managers.at(floor);
m.add(data, x, z, flags);
m.add(data, pos, from_obj, from_ene, flags);
this->evict_items_from_floor(floor);
}
+28 -51
View File
@@ -26,9 +26,11 @@ struct ServerState;
struct Lobby : public std::enable_shared_from_this<Lobby> {
struct FloorItem {
ItemData data;
float x;
float z;
VectorXZF pos;
uint64_t drop_number;
// At most one of the following will be non-null
std::shared_ptr<const MapState::ObjectState> from_obj;
std::shared_ptr<const MapState::EnemyState> from_ene;
// The low 12 bits of flags are visibility flags, specifying which clients
// can see the item. (In practice, only the lowest 4 of these bits are used,
// but the game has fields for 12 players so we do too.)
@@ -52,7 +54,12 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
bool exists(uint32_t item_id) const;
std::shared_ptr<FloorItem> find(uint32_t item_id) const;
void add(const ItemData& item, float x, float z, uint16_t flags);
void add(
const ItemData& item,
const VectorXZF& pos,
std::shared_ptr<const MapState::ObjectState> from_obj,
std::shared_ptr<const MapState::EnemyState> from_ene,
uint16_t flags);
void add(std::shared_ptr<FloorItem> fi);
std::shared_ptr<FloorItem> remove(uint32_t item_id, uint8_t client_id);
std::unordered_set<std::shared_ptr<FloorItem>> evict();
@@ -65,6 +72,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
// clang-format off
GAME = 0x00000001,
PERSISTENT = 0x00000002,
DEBUG = 0x00000004,
// Flags used only for games
CHEATS_ENABLED = 0x00000100,
QUEST_SELECTION_IN_PROGRESS = 0x00000200,
@@ -103,15 +111,14 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
std::array<uint32_t, 12> next_item_id_for_client;
uint32_t next_game_item_id;
std::vector<FloorItemManager> floor_item_managers;
std::shared_ptr<const Map::RareEnemyRates> rare_enemy_rates;
std::shared_ptr<Map> map;
parray<le_uint32_t, 0x20> variations;
std::shared_ptr<const MapState::RareEnemyRates> rare_enemy_rates;
std::shared_ptr<MapState> map_state; // Always null for lobbies, never null for games
Variations variations;
std::unique_ptr<QuestFlags> quest_flags_known; // If null, ALL quest flags are known
std::unique_ptr<QuestFlags> quest_flag_values;
std::unique_ptr<SwitchFlags> switch_flags;
// Game config
Version base_version;
// Bits in allowed_versions specify who is allowed to join this game. The
// bits are indexed as (1 << version), where version is a value from the
// Version enum.
@@ -131,7 +138,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
uint8_t allowed_drop_modes;
DropMode drop_mode;
std::shared_ptr<ItemCreator> item_creator;
std::shared_ptr<ItemCreator> item_creator; // Always null for lobbies, never null for games
struct ChallengeParameters {
uint8_t stage_number = 0;
@@ -204,55 +211,16 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
std::shared_ptr<ServerState> require_server_state() const;
std::shared_ptr<ChallengeParameters> require_challenge_params() const;
void set_drop_mode(DropMode new_mode);
void create_item_creator();
void change_section_id();
void create_item_creator(Version logic_version = Version::UNKNOWN);
uint8_t effective_section_id() const;
static std::shared_ptr<Map> load_maps(
Version version,
Episode episode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t random_seed,
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
std::shared_ptr<const std::string> quest_dat_contents_decompressed);
static std::shared_ptr<Map> load_maps(
Version version,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
std::shared_ptr<const SetDataTableBase> sdt,
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t random_seed,
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
const parray<le_uint32_t, 0x20>& variations,
const phosg::PrefixedLogger* log = nullptr);
static std::shared_ptr<Map> load_maps(
const std::vector<std::string>& enemy_filenames,
const std::vector<std::string>& object_filenames,
const std::vector<std::string>& event_filenames,
Version version,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t event,
uint32_t lobby_id,
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
uint32_t random_seed,
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
const phosg::PrefixedLogger* log = nullptr);
uint16_t quest_version_flags() const;
void load_maps();
void create_ep3_server();
[[nodiscard]] inline bool is_game() const {
return this->check_flag(Flag::GAME);
}
[[nodiscard]] bool is_ep3_nte() const;
[[nodiscard]] inline bool is_ep3() const {
return this->episode == Episode::EP3;
}
@@ -263,6 +231,9 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
inline void allow_version(Version v) {
this->allowed_versions |= (1 << static_cast<size_t>(v));
}
inline void forbid_version(Version v) {
this->allowed_versions &= ~(1 << static_cast<size_t>(v));
}
void reassign_leader_on_client_departure(size_t leaving_client_id);
size_t count_clients() const;
@@ -297,7 +268,13 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
bool item_exists(uint8_t floor, uint32_t item_id) const;
std::shared_ptr<FloorItem> find_item(uint8_t floor, uint32_t item_id) const;
void add_item(uint8_t floor, const ItemData& item, float x, float z, uint16_t flags);
void add_item(
uint8_t floor,
const ItemData& item,
const VectorXZF& pos,
std::shared_ptr<const MapState::ObjectState> from_obj,
std::shared_ptr<const MapState::EnemyState> from_ene,
uint16_t flags);
void add_item(uint8_t floor, std::shared_ptr<FloorItem>);
void evict_items_from_floor(uint8_t floor);
std::shared_ptr<FloorItem> remove_item(uint8_t floor, uint32_t item_id, uint8_t requesting_client_id);
-2
View File
@@ -4,7 +4,6 @@
using namespace std;
phosg::PrefixedLogger ax_messages_log("[$ax message] ", phosg::LogLevel::USE_DEFAULT);
phosg::PrefixedLogger channel_exceptions_log("[Channel] ", phosg::LogLevel::USE_DEFAULT);
phosg::PrefixedLogger client_log("", phosg::LogLevel::USE_DEFAULT);
phosg::PrefixedLogger command_data_log("[Commands] ", phosg::LogLevel::USE_DEFAULT);
@@ -30,7 +29,6 @@ static void set_log_level_from_json(
}
void set_log_levels_from_json(const phosg::JSON& json) {
set_log_level_from_json(ax_messages_log, json, "AXMessages");
set_log_level_from_json(channel_exceptions_log, json, "ChannelExceptions");
set_log_level_from_json(client_log, json, "Clients");
set_log_level_from_json(command_data_log, json, "CommandData");
-1
View File
@@ -3,7 +3,6 @@
#include <phosg/JSON.hh>
#include <phosg/Strings.hh>
extern phosg::PrefixedLogger ax_messages_log;
extern phosg::PrefixedLogger channel_exceptions_log;
extern phosg::PrefixedLogger client_log;
extern phosg::PrefixedLogger command_data_log;
+473 -329
View File
File diff suppressed because it is too large Load Diff
+4697 -2140
View File
File diff suppressed because it is too large Load Diff
+893 -406
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -125,7 +125,7 @@ struct MenuItem {
XB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_BB,
BB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_XB,
REQUIRES_MESSAGE_BOXES = 0x100,
REQUIRES_SEND_FUNCTION_CALL = 0x200,
REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE = 0x200,
REQUIRES_SAVE_DISABLED = 0x400,
INVISIBLE_IN_INFO_MENU = 0x800,
};
+76
View File
@@ -0,0 +1,76 @@
#include "AFSArchive.hh"
#include <stdio.h>
#include <string.h>
#include <phosg/Encoding.hh>
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include "Compression.hh"
#include "Text.hh"
using namespace std;
struct Entry {
pstring<TextEncoding::ASCII, 0x80> filename;
le_uint32_t unknown_a1;
le_uint32_t decompressed_size;
le_uint32_t compressed_size;
le_uint32_t checksum;
// Data follows immediately here
// Trailer: le_uint32_t entry_size; //
};
static void decrypt_ppk_data(std::string& data, const std::string& filename, const std::string& password) {
if (password.size() > 0xFF) {
throw runtime_error("password is too long");
}
uint8_t key[0x100];
for (size_t z = 0; z < 0x100; z++) {
key[z] = z ^ filename[z % filename.size()];
}
for (size_t z = 0; z < password.size(); z++) {
key[z + 1] ^= password[z];
}
for (size_t z = 0; z < 0xFC; z++) {
key[z + 4] ^= key[z];
}
for (size_t z = 0; z < data.size(); z++) {
data[z] ^= key[z & 0xFF];
}
}
std::unordered_map<std::string, std::string> decode_ppk_file(const std::string& data, const std::string& password) {
phosg::StringReader r(data);
uint32_t signature = r.get_u32b();
if (signature != 0x50503130 && signature != 0x4D5A5000) { // 'PP10' or 'MZP\0'
throw runtime_error("file is not a ppk archive");
}
unordered_map<string, string> ret;
for (size_t offset = r.size() - 4; offset >= 4;) {
uint32_t size = r.pget_u32l(offset) ^ 0x12345678;
uint32_t entry_offset = offset - size;
const auto& entry = r.pget<Entry>(entry_offset);
string data = r.pread(entry_offset + sizeof(Entry), entry.compressed_size);
string filename = entry.filename.decode();
decrypt_ppk_data(data, phosg::tolower(filename), password);
uint32_t checksum = phosg::crc32(data.data(), data.size());
if (checksum != entry.checksum) {
throw runtime_error(phosg::string_printf(
"incorrect checksum for file %s (expected %08" PRIX32 "; received %08" PRIX32 ")",
filename.c_str(), entry.checksum.load(), checksum));
}
if (entry.compressed_size < entry.decompressed_size) {
data = prs_decompress(data);
}
if (!ret.emplace(filename, data).second) {
throw runtime_error(phosg::string_printf("archive contains multiple files with the same name (%s)", filename.c_str()));
}
offset = entry_offset - 4;
}
return ret;
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <string>
#include <unordered_map>
std::unordered_map<std::string, std::string> decode_ppk_file(const std::string& data, const std::string& password);
+2 -6
View File
@@ -885,19 +885,15 @@ uint32_t encrypt_challenge_time(uint16_t value) {
available_bits.erase(it);
}
uint32_t ret = (mask << 16) | (value ^ mask);
fprintf(stderr, "encrypt_challenge_time %04hX => %08" PRIX32 "\n", value, ret);
return ret;
return (mask << 16) | (value ^ mask);
}
uint16_t decrypt_challenge_time(uint32_t value) {
uint16_t mask = (value >> 0x10);
uint8_t mask_one_bits = count_one_bits(mask);
uint16_t ret = ((mask_one_bits < 4) || (mask_one_bits > 12))
return ((mask_one_bits < 4) || (mask_one_bits > 12))
? 0xFFFF
: ((mask ^ value) & 0xFFFF);
fprintf(stderr, "decrypt_challenge_time %08" PRIX32 " => %04hX\n", value, ret);
return ret;
}
string decrypt_v2_registry_value(const void* data, size_t size) {
+7 -7
View File
@@ -25,7 +25,7 @@ uint16_t PSOCommandHeader::command(Version version) const {
case Version::PC_V2:
return this->pc.command;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
return this->dc.command;
@@ -52,7 +52,7 @@ void PSOCommandHeader::set_command(Version version, uint16_t command) {
this->pc.command = command;
break;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
this->dc.command = command;
@@ -82,7 +82,7 @@ uint16_t PSOCommandHeader::size(Version version) const {
case Version::PC_V2:
return this->pc.size;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
return this->dc.size;
@@ -109,7 +109,7 @@ void PSOCommandHeader::set_size(Version version, uint32_t size) {
this->pc.size = size;
break;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
this->dc.size = size;
@@ -139,7 +139,7 @@ uint32_t PSOCommandHeader::flag(Version version) const {
case Version::PC_V2:
return this->pc.flag;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
return this->dc.flag;
@@ -166,7 +166,7 @@ void PSOCommandHeader::set_flag(Version version, uint32_t flag) {
this->pc.flag = flag;
break;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
this->dc.flag = flag;
@@ -213,7 +213,7 @@ std::string prepend_command_header(
phosg::StringWriter ret;
switch (version) {
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
case Version::GC_NTE:
-3
View File
@@ -74,9 +74,6 @@ private:
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
void idle_timeout();
const std::string& get_bb_username() const;
void set_bb_username(const std::string& bb_username);
};
struct ListeningSocket {
+4
View File
@@ -305,6 +305,10 @@ struct PlayerBankT {
/* 0008 */ parray<PlayerBankItemT<BE>, SlotCount> items;
/* 05A8 for 60 items (v1/v2), 12C8 for 200 items (v3/v4) */
uint32_t checksum() const {
return phosg::crc32(this, 2 * sizeof(U32T<BE>) + sizeof(PlayerBankItemT<BE>) * std::min<size_t>(SlotCount, this->num_items));
}
void add_item(const ItemData& item, const ItemData::StackLimits& limits) {
uint32_t primary_identifier = item.primary_identifier();
+60 -42
View File
@@ -324,6 +324,50 @@ QuestFlagsV1::operator QuestFlags() const {
return ret;
}
const QuestFlagsForDifficulty QuestFlagsForDifficulty::BB_QUEST_FLAG_APPLY_MASK{{
// clang-format off
/* 0000 */ 0x00, 0x3F, 0xFF, 0xE3, 0xE0, 0xFF, 0xFF, 0x00,
/* 0040 */ 0x03, 0xFF, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00,
/* 0080 */ 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00,
/* 00C0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0100 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x00,
/* 0140 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
/* 0180 */ 0xFE, 0x00, 0x7F, 0xFE, 0x0F, 0xFF, 0xFF, 0x80,
/* 01C0 */ 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xFF,
/* 0200 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00,
/* 0240 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0280 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
/* 02C0 */ 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0300 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0340 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0380 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 03C0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// clang-format on
// The flags in the above mask are:
// 000A 000B 000C 000D 000E 000F 0010 0011 0012 0013 0014 0015 0016 0017
// 0018 0019 001A 001E 001F 0020 0021 0022 0028 0029 002A 002B 002C 002D
// 002E 002F 0030 0031 0032 0033 0034 0035 0036 0037 0046 0047 0048 0049
// 004A 004B 004C 004D 004E 004F 0050 0051 0052 0053 0054 0055 0056 0057
// 0058 0059 005A 005B 005C 005D 005E 005F 0060 0061 0062 0063 0097 0098
// 0099 009A 012D 012E 012F 0130 0131 0132 0133 0134 0135 0140 0141 0142
// 0143 0144 0145 0146 0147 0148 0149 014A 014B 014C 014D 014E 014F 0150
// 0151 0152 0153 0154 0155 0156 0157 0158 0159 015A 015B 015C 015D 015E
// 015F 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 016A 016B 016C
// 016D 016E 016F 0170 0171 0172 0173 0174 0175 0176 0177 0178 0179 017A
// 017B 017C 017D 017E 017F 0180 0181 0182 0183 0184 0185 0186 0191 0192
// 0193 0194 0195 0196 0197 0198 0199 019A 019B 019C 019D 019E 01A4 01A5
// 01A6 01A7 01A8 01A9 01AA 01AB 01AC 01AD 01AE 01AF 01B0 01B1 01B2 01B3
// 01B4 01B5 01B6 01B7 01B8 01C2 01C3 01C4 01C5 01C6 01C7 01C8 01C9 01CA
// 01CB 01CC 01CD 01CE 01CF 01D0 01D1 01D2 01D3 01D4 01D5 01D6 01F4 01F5
// 01F6 01F7 01F8 01F9 01FA 01FB 01FC 01FD 01FE 01FF 0200 0201 0202 0203
// 0204 0205 0206 0207 0208 0209 020A 020B 020C 020D 020E 020F 0210 0211
// 0212 0213 0214 0215 0216 0217 0218 0219 021A 021B 021C 021D 021E 021F
// 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 022A 022B 022C 022D
// 022E 022F 0230 0231 0232 0233 0234 0235 02BD 02BE 02BF 02C0 02C1 02C2
// 02C3 02C4
}};
BattleRules::BattleRules(const phosg::JSON& json) {
static const phosg::JSON empty_list = phosg::JSON::list();
@@ -699,46 +743,20 @@ const ChallengeTemplateDefinition& get_challenge_template_definition(Version ver
}
}
const QuestFlagsForDifficulty bb_quest_flag_apply_mask{{
// clang-format off
/* 0000 */ 0x00, 0x3F, 0xFF, 0xE3, 0xE0, 0xFF, 0xFF, 0x00,
/* 0040 */ 0x03, 0xFF, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00,
/* 0080 */ 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00,
/* 00C0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0100 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x00,
/* 0140 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
/* 0180 */ 0xFE, 0x00, 0x7F, 0xFE, 0x0F, 0xFF, 0xFF, 0x80,
/* 01C0 */ 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xFF,
/* 0200 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00,
/* 0240 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0280 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
/* 02C0 */ 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0300 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0340 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0380 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 03C0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// clang-format on
NPCTalkState::NPCTalkState(const NPCTalkState_DCProtos& proto)
: unknown_a1(proto.unknown_a1),
unknown_a2(proto.unknown_a2),
unknown_a3(0),
unknown_a4(proto.unknown_a4),
unknown_a5(proto.unknown_a5),
unknown_a6(proto.unknown_a6) {}
// The flags in the above mask are:
// 000A 000B 000C 000D 000E 000F 0010 0011 0012 0013 0014 0015 0016 0017
// 0018 0019 001A 001E 001F 0020 0021 0022 0028 0029 002A 002B 002C 002D
// 002E 002F 0030 0031 0032 0033 0034 0035 0036 0037 0046 0047 0048 0049
// 004A 004B 004C 004D 004E 004F 0050 0051 0052 0053 0054 0055 0056 0057
// 0058 0059 005A 005B 005C 005D 005E 005F 0060 0061 0062 0063 0097 0098
// 0099 009A 012D 012E 012F 0130 0131 0132 0133 0134 0135 0140 0141 0142
// 0143 0144 0145 0146 0147 0148 0149 014A 014B 014C 014D 014E 014F 0150
// 0151 0152 0153 0154 0155 0156 0157 0158 0159 015A 015B 015C 015D 015E
// 015F 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 016A 016B 016C
// 016D 016E 016F 0170 0171 0172 0173 0174 0175 0176 0177 0178 0179 017A
// 017B 017C 017D 017E 017F 0180 0181 0182 0183 0184 0185 0186 0191 0192
// 0193 0194 0195 0196 0197 0198 0199 019A 019B 019C 019D 019E 01A4 01A5
// 01A6 01A7 01A8 01A9 01AA 01AB 01AC 01AD 01AE 01AF 01B0 01B1 01B2 01B3
// 01B4 01B5 01B6 01B7 01B8 01C2 01C3 01C4 01C5 01C6 01C7 01C8 01C9 01CA
// 01CB 01CC 01CD 01CE 01CF 01D0 01D1 01D2 01D3 01D4 01D5 01D6 01F4 01F5
// 01F6 01F7 01F8 01F9 01FA 01FB 01FC 01FD 01FE 01FF 0200 0201 0202 0203
// 0204 0205 0206 0207 0208 0209 020A 020B 020C 020D 020E 020F 0210 0211
// 0212 0213 0214 0215 0216 0217 0218 0219 021A 021B 021C 021D 021E 021F
// 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 022A 022B 022C 022D
// 022E 022F 0230 0231 0232 0233 0234 0235 02BD 02BE 02BF 02C0 02C1 02C2
// 02C3 02C4
}};
NPCTalkState::operator NPCTalkState_DCProtos() const {
NPCTalkState_DCProtos ret;
ret.unknown_a1 = this->unknown_a1;
ret.unknown_a2 = this->unknown_a2;
ret.unknown_a4 = this->unknown_a4;
ret.unknown_a5 = this->unknown_a5;
ret.unknown_a6 = this->unknown_a6;
return ret;
}
+46 -2
View File
@@ -11,6 +11,7 @@
#include <vector>
#include "ChoiceSearch.hh"
#include "CommonFileFormats.hh"
#include "FileContentsCache.hh"
#include "ItemData.hh"
#include "LevelTable.hh"
@@ -722,7 +723,8 @@ struct PlayerRecordsBattleT {
// On Episode 3, place_counts[0] is win count and [1] is loss count
/* 00 */ parray<U16T<BE>, 4> place_counts;
/* 08 */ U16T<BE> disconnect_count = 0;
/* 0A */ parray<U16T<BE>, 3> unknown_a1;
/* 0A */ parray<U16T<BE>, 2> unknown_a1;
/* 0E */ parray<uint8_t, 2> unused;
/* 10 */ parray<U32T<BE>, 2> unknown_a2;
/* 18 */
@@ -776,6 +778,8 @@ inline PlayerDispDataBB convert_player_disp_data<PlayerDispDataBB>(
}
struct QuestFlagsForDifficulty {
static const QuestFlagsForDifficulty BB_QUEST_FLAG_APPLY_MASK;
parray<uint8_t, 0x80> data;
inline bool get(uint16_t flag_index) const {
@@ -994,4 +998,44 @@ using SymbolChatBE = SymbolChatT<true>;
check_struct_size(SymbolChat, 0x3C);
check_struct_size(SymbolChatBE, 0x3C);
extern const QuestFlagsForDifficulty bb_quest_flag_apply_mask;
struct TelepipeState {
/* 00 */ le_uint16_t owner_client_id = 0xFFFF;
/* 02 */ le_uint16_t floor = 0;
/* 04 */ le_uint32_t room_id = 0;
/* 08 */ VectorXYZF pos;
/* 14 */ le_uint32_t angle_y = 0;
/* 18 */
} __packed_ws__(TelepipeState, 0x18);
struct NPCTalkState_DCProtos {
// This is used in all versions of this command except DCNTE and 11/2000.
/* 00 */ le_uint16_t unknown_a1 = 0;
/* 02 */ le_uint16_t unknown_a2 = 0;
// unknown_a3 is missing in this format, unlike the v1+ format below
/* 04 */ le_float unknown_a4 = 0.0f;
/* 08 */ le_float unknown_a5 = 0.0f;
/* 0C */ le_float unknown_a6 = 0.0f;
/* 10 */
} __packed_ws__(NPCTalkState_DCProtos, 0x10);
struct NPCTalkState {
// This is used in all versions of this command except DCNTE and 11/2000.
/* 00 */ le_uint16_t unknown_a1 = 0;
/* 02 */ le_uint16_t unknown_a2 = 0;
/* 04 */ le_uint32_t unknown_a3 = 0;
/* 08 */ le_float unknown_a4 = 0.0f;
/* 0C */ le_float unknown_a5 = 0.0f;
/* 10 */ le_float unknown_a6 = 0.0f;
/* 14 */
NPCTalkState() = default;
NPCTalkState(const NPCTalkState_DCProtos& proto);
operator NPCTalkState_DCProtos() const;
} __packed_ws__(NPCTalkState, 0x14);
struct StatusEffectState {
/* 00 */ le_uint32_t effect_type = 0;
/* 04 */ le_float multiplier = 0.0f;
/* 08 */ le_uint32_t remaining_frames = 0;
/* 0C */
} __packed_ws__(StatusEffectState, 0x0C);
+81 -74
View File
@@ -30,7 +30,7 @@
#include "ChatCommands.hh"
#include "Compression.hh"
#include "GVMEncoder.hh"
#include "ImageEncoder.hh"
#include "Loggers.hh"
#include "PSOProtocol.hh"
#include "ReceiveCommands.hh"
@@ -167,8 +167,7 @@ static HandlerResult S_G_9A(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t
cmd.player_tag = 0x00010000;
cmd.guild_card_number = ses->remote_guild_card_number;
}
cmd.unused1 = 0;
cmd.unused2 = 0;
cmd.hardware_id = ses->hardware_id;
cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0;
cmd.language = ses->language();
@@ -256,7 +255,7 @@ static HandlerResult S_V123P_02_17(
// TODO
throw runtime_error("DC NTE proxy is not implemented");
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
if (!ses->login->dc_license) {
throw runtime_error("DC license missing from login");
@@ -277,15 +276,14 @@ static HandlerResult S_V123P_02_17(
cmd.player_tag = 0x00010000;
cmd.guild_card_number = ses->remote_guild_card_number;
}
cmd.unknown_a1 = 0;
cmd.unknown_a2 = 0;
cmd.hardware_id = ses->hardware_id;
cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0;
cmd.language = ses->language();
cmd.serial_number.encode(phosg::string_printf("%08" PRIX32 "", ses->login->dc_license->serial_number));
cmd.access_key.encode(ses->login->dc_license->access_key);
cmd.access_key.clear_after_bytes(8);
cmd.hardware_id.encode(ses->hardware_id);
cmd.serial_number2.encode(ses->serial_number2);
cmd.name.encode(ses->character_name);
ses->server_channel.send(0x93, 0x00, &cmd, sizeof(cmd));
return HandlerResult::Type::SUPPRESS;
@@ -334,7 +332,7 @@ static HandlerResult S_V123P_02_17(
cmd.access_key.clear_after_bytes(8);
}
if (is_dc(ses->version())) {
cmd.serial_number2.encode(ses->hardware_id);
cmd.serial_number2.encode(ses->serial_number2);
} else {
cmd.serial_number2 = cmd.serial_number;
}
@@ -353,8 +351,7 @@ static HandlerResult S_V123P_02_17(
cmd.player_tag = 0x00010000;
cmd.guild_card_number = ses->remote_guild_card_number;
}
cmd.unused1 = 0;
cmd.unused2 = 0;
cmd.hardware_id = ses->hardware_id;
cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0;
cmd.language = ses->language();
@@ -364,7 +361,7 @@ static HandlerResult S_V123P_02_17(
cmd.access_key.clear_after_bytes(8);
}
if (is_dc(ses->version())) {
cmd.serial_number2.encode(ses->hardware_id);
cmd.serial_number2.encode(ses->serial_number2);
} else {
cmd.serial_number2 = cmd.serial_number;
}
@@ -417,8 +414,7 @@ static HandlerResult S_V123P_02_17(
C_LoginExtended_GC_9E cmd;
cmd.player_tag = 0x00010000;
cmd.guild_card_number = guild_card_number;
cmd.unused1 = 0;
cmd.unused2 = 0;
cmd.hardware_id = ses->hardware_id;
cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0;
cmd.language = ses->language();
@@ -453,8 +449,7 @@ static HandlerResult S_V123P_02_17(
cmd.player_tag = 0x00010000;
cmd.guild_card_number = ses->remote_guild_card_number;
}
cmd.unused1 = 0;
cmd.unused2 = 0;
cmd.hardware_id = ses->hardware_id;
cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0;
cmd.language = ses->language();
@@ -746,7 +741,7 @@ static HandlerResult S_B2(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
ses->log.info("Wrote code from server to file %s", output_filename.c_str());
#ifdef HAVE_RESOURCE_FILE
using FooterT = S_ExecuteCode_FooterT_B2<BE>;
using FooterT = RELFileFooterT<BE>;
// TODO: Support SH-4 disassembly too
bool is_ppc = ::is_ppc(ses->version());
@@ -770,9 +765,9 @@ static HandlerResult S_B2(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
reloc_offset += (r.get<U16T<BE>>() * 4);
labels.emplace(reloc_offset, phosg::string_printf("reloc%zu", x));
}
labels.emplace(footer.entrypoint_addr_offset.load(), "entry_ptr");
labels.emplace(footer.root_offset.load(), "entry_ptr");
labels.emplace(footer_offset, "footer");
labels.emplace(r.pget<U32T<BE>>(footer.entrypoint_addr_offset), "start");
labels.emplace(r.pget<U32T<BE>>(footer.root_offset), "start");
string disassembly;
if (is_ppc) {
@@ -1002,9 +997,9 @@ static HandlerResult SC_6x60_6xA2(shared_ptr<ProxyServer::LinkedSession> ses, co
G_SpecializableItemDropRequest_6xA2 cmd = normalize_drop_request(data.data(), data.size());
auto s = ses->require_server_state();
ses->next_drop_item.id = ses->next_item_id++;
bool is_box = (cmd.rt_index == 0x30);
send_drop_item_to_channel(s, ses->server_channel, ses->next_drop_item, !is_box, cmd.floor, cmd.x, cmd.z, cmd.entity_id);
send_drop_item_to_channel(s, ses->client_channel, ses->next_drop_item, !is_box, cmd.floor, cmd.x, cmd.z, cmd.entity_id);
uint8_t source_type = (cmd.rt_index == 0x30) ? 2 : 1;
send_drop_item_to_channel(s, ses->server_channel, ses->next_drop_item, source_type, cmd.floor, cmd.pos, cmd.entity_index);
send_drop_item_to_channel(s, ses->client_channel, ses->next_drop_item, source_type, cmd.floor, cmd.pos, cmd.entity_index);
ses->next_drop_item.clear();
return HandlerResult::Type::SUPPRESS;
}
@@ -1025,27 +1020,34 @@ static HandlerResult SC_6x60_6xA2(shared_ptr<ProxyServer::LinkedSession> ses, co
ses->log.warning("Session is in INTERCEPT drop mode, but item creator is missing");
return HandlerResult::Type::FORWARD;
}
if (!ses->map) {
ses->log.warning("Session is in INTERCEPT drop mode, but map is missing");
if (!ses->map_state) {
ses->log.warning("Session is in INTERCEPT drop mode, but map state is missing");
return HandlerResult::Type::FORWARD;
}
G_SpecializableItemDropRequest_6xA2 cmd = normalize_drop_request(data.data(), data.size());
auto rec = reconcile_drop_request_with_map(
ses->log, ses->client_channel, cmd, ses->version(), ses->lobby_episode, ses->config, ses->map, false);
ses->log,
ses->client_channel,
cmd,
ses->lobby_episode,
ses->lobby_event,
ses->config,
ses->map_state,
false);
ItemCreator::DropResult res;
if (rec.is_box) {
if (rec.obj_st) {
if (rec.ignore_def) {
ses->log.info("Creating item from box %04hX (area %02hX)", cmd.entity_id.load(), cmd.effective_area);
ses->log.info("Creating item from box %04hX (area %02hX)", cmd.entity_index.load(), cmd.effective_area);
res = ses->item_creator->on_box_item_drop(cmd.effective_area);
} else {
ses->log.info("Creating item from box %04hX (area %02hX; specialized with %g %08" PRIX32 " %08" PRIX32 " %08" PRIX32 ")",
cmd.entity_id.load(), cmd.effective_area, cmd.param3.load(), cmd.param4.load(), cmd.param5.load(), cmd.param6.load());
res = ses->item_creator->on_specialized_box_item_drop(cmd.effective_area, cmd.param3, cmd.param4, cmd.param5, cmd.param6);
cmd.entity_index.load(), cmd.effective_area, cmd.fparam3.load(), cmd.iparam4.load(), cmd.iparam5.load(), cmd.iparam6.load());
res = ses->item_creator->on_specialized_box_item_drop(cmd.effective_area, cmd.fparam3, cmd.iparam4, cmd.iparam5, cmd.iparam6);
}
} else {
ses->log.info("Creating item from enemy %04hX (area %02hX)", cmd.entity_id.load(), cmd.effective_area);
ses->log.info("Creating item from enemy %04hX (area %02hX)", cmd.entity_index.load(), cmd.effective_area);
res = ses->item_creator->on_monster_item_drop(rec.effective_rt_index, cmd.effective_area);
}
@@ -1054,12 +1056,12 @@ static HandlerResult SC_6x60_6xA2(shared_ptr<ProxyServer::LinkedSession> ses, co
} else {
auto s = ses->require_server_state();
string name = s->describe_item(ses->version(), res.item, false);
ses->log.info("Entity %04hX (area %02hX) created item %s", cmd.entity_id.load(), cmd.effective_area, name.c_str());
ses->log.info("Entity %04hX (area %02hX) created item %s", cmd.entity_index.load(), cmd.effective_area, name.c_str());
res.item.id = ses->next_item_id++;
ses->log.info("Creating item %08" PRIX32 " at %02hhX:%g,%g for all clients",
res.item.id.load(), cmd.floor, cmd.x.load(), cmd.z.load());
send_drop_item_to_channel(s, ses->client_channel, res.item, !rec.is_box, cmd.floor, cmd.x, cmd.z, cmd.entity_id);
send_drop_item_to_channel(s, ses->server_channel, res.item, !rec.is_box, cmd.floor, cmd.x, cmd.z, cmd.entity_id);
res.item.id.load(), cmd.floor, cmd.pos.x.load(), cmd.pos.z.load());
send_drop_item_to_channel(s, ses->client_channel, res.item, rec.obj_st ? 2 : 1, cmd.floor, cmd.pos, cmd.entity_index);
send_drop_item_to_channel(s, ses->server_channel, res.item, rec.obj_st ? 2 : 1, cmd.floor, cmd.pos, cmd.entity_index);
send_item_notification_if_needed(s, ses->client_channel, ses->config, res.item, res.is_from_rare_table);
}
return HandlerResult::Type::SUPPRESS;
@@ -1144,7 +1146,7 @@ static HandlerResult S_6x(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
const auto& cmd = check_size_t<G_AttackFinished_6x46>(data,
offsetof(G_AttackFinished_6x46, targets),
sizeof(G_AttackFinished_6x46));
if (cmd.count > min<size_t>(cmd.header.size - 2, cmd.targets.size())) {
if (cmd.target_count > min<size_t>(cmd.header.size - 2, cmd.targets.size())) {
ses->log.warning("Blocking subcommand 6x46 with invalid count");
return HandlerResult::Type::SUPPRESS;
}
@@ -1426,18 +1428,25 @@ static HandlerResult S_13_A7(shared_ptr<ProxyServer::LinkedSession> ses, uint16_
if (!sf->is_download && phosg::ends_with(sf->basename, ".dat")) {
auto quest_dat_data = make_shared<std::string>(prs_decompress(sf->data));
try {
ses->map = Lobby::load_maps(
ses->version(),
ses->lobby_episode,
auto map_file = make_shared<MapFile>(quest_dat_data);
auto materialized_map_file = map_file->materialize_random_sections(ses->lobby_random_seed);
array<shared_ptr<const MapFile>, NUM_VERSIONS> map_files;
map_files.at(static_cast<size_t>(ses->version())) = materialized_map_file;
auto supermap = make_shared<SuperMap>(ses->lobby_episode, map_files);
ses->map_state = make_shared<MapState>(
ses->id,
ses->lobby_difficulty,
ses->lobby_event,
ses->id,
Map::DEFAULT_RARE_ENEMIES,
ses->lobby_random_seed,
MapState::DEFAULT_RARE_ENEMIES,
make_shared<PSOV2Encryption>(ses->lobby_random_seed),
quest_dat_data);
supermap);
} catch (const exception& e) {
ses->log.warning("Failed to load quest map: %s", e.what());
ses->map_state.reset();
}
}
@@ -1578,7 +1587,7 @@ static HandlerResult S_65_67_68_EB(shared_ptr<ProxyServer::LinkedSession> ses, u
ses->lobby_episode = Episode::EP1;
ses->lobby_random_seed = 0;
ses->item_creator.reset();
ses->map.reset();
ses->map_state.reset();
// This command can cause the client to no longer send D6 responses when
// 1A/D5 large message boxes are closed. newserv keeps track of this
@@ -1720,7 +1729,7 @@ static HandlerResult S_64(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
} else {
ses->lobby_mode = GameMode::NORMAL;
}
ses->lobby_random_seed = cmd->rare_seed;
ses->lobby_random_seed = cmd->random_seed;
if (cmd_ep3) {
ses->lobby_episode = Episode::EP3;
} else {
@@ -1730,27 +1739,24 @@ static HandlerResult S_64(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
if (ses->version() == Version::GC_NTE) {
// GC NTE ignores the variations field entirely, so clear the array to
// ensure we'll load the correct maps
cmd->variations.clear(0);
cmd->variations = Variations();
}
// Recreate the item creator if needed, and load maps
auto s = ses->require_server_state();
ses->set_drop_mode(ses->drop_mode);
if (!is_ep3(ses->version())) {
ses->map = Lobby::load_maps(
ses->version(),
ses->lobby_episode,
ses->lobby_mode,
if (!is_ep3(ses->version()) && (ses->lobby_mode != GameMode::CHALLENGE)) {
auto s = ses->require_server_state();
ses->map_state = make_shared<MapState>(
ses->id,
ses->lobby_difficulty,
ses->lobby_event,
ses->id,
s->set_data_table(ses->version(), ses->lobby_episode, ses->lobby_mode, ses->lobby_difficulty),
bind(&ServerState::load_map_file, s.get(), placeholders::_1, placeholders::_2),
Map::DEFAULT_RARE_ENEMIES,
ses->lobby_random_seed,
MapState::DEFAULT_RARE_ENEMIES,
make_shared<PSOV2Encryption>(ses->lobby_random_seed),
cmd->variations,
&ses->log);
s->supermaps_for_variations(ses->lobby_episode, ses->lobby_mode, ses->lobby_difficulty, cmd->variations));
} else {
ses->map_state.reset();
}
bool modified = false;
@@ -1785,7 +1791,7 @@ static HandlerResult S_64(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
modified = true;
}
if (ses->config.check_flag(Client::Flag::USE_OVERRIDE_RANDOM_SEED)) {
cmd->rare_seed = ses->config.override_random_seed;
cmd->random_seed = ses->config.override_random_seed;
modified = true;
}
@@ -1812,7 +1818,7 @@ static HandlerResult S_E8(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
ses->lobby_random_seed = 0;
ses->lobby_episode = Episode::EP3;
ses->item_creator.reset();
ses->map.reset();
ses->map_state.reset();
bool modified = false;
@@ -1850,7 +1856,7 @@ static HandlerResult S_E8(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
modified = true;
}
if (ses->config.check_flag(Client::Flag::USE_OVERRIDE_RANDOM_SEED)) {
cmd.rare_seed = ses->config.override_random_seed;
cmd.random_seed = ses->config.override_random_seed;
modified = true;
}
@@ -1899,7 +1905,7 @@ static HandlerResult C_98(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t c
ses->lobby_mode = GameMode::NORMAL;
ses->lobby_random_seed = 0;
ses->item_creator.reset();
ses->map.reset();
ses->map_state.reset();
if (is_v3(ses->version()) || is_v4(ses->version())) {
return C_GXB_61(ses, command, flag, data);
@@ -1937,7 +1943,7 @@ static HandlerResult C_06(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
return HandlerResult::Type::SUPPRESS;
}
char command_sentinel = (ses->version() == Version::DC_V1_11_2000_PROTOTYPE) ? '@' : '$';
char command_sentinel = (ses->version() == Version::DC_11_2000) ? '@' : '$';
bool is_command = (text[0] == command_sentinel) ||
(text[0] == '\t' && text[1] != 'C' && text[2] == command_sentinel);
if (is_command && ses->config.check_flag(Client::Flag::PROXY_CHAT_COMMANDS_ENABLED)) {
@@ -1948,7 +1954,7 @@ static HandlerResult C_06(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
send_chat_message_from_client(ses->server_channel, text.substr(1), private_flags);
return HandlerResult::Type::SUPPRESS;
} else {
on_chat_command(ses, text);
on_chat_command(ses, text, true);
return HandlerResult::Type::SUPPRESS;
}
@@ -1999,9 +2005,7 @@ constexpr on_command_t C_B_81 = &C_81<SC_SimpleMail_BB_81>;
template <typename CmdT>
void C_6x_movement(shared_ptr<ProxyServer::LinkedSession> ses, const string& data) {
const auto& cmd = check_size_t<CmdT>(data);
ses->x = cmd.x;
ses->z = cmd.z;
ses->pos = check_size_t<CmdT>(data).pos;
}
template <typename SendGuildCardCmdT>
@@ -2029,20 +2033,23 @@ template <>
HandlerResult C_6x<void>(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t, uint32_t, string& data) {
if (!data.empty()) {
if ((data[0] == 0x05) && ses->config.check_flag(Client::Flag::SWITCH_ASSIST_ENABLED)) {
auto& cmd = check_size_t<G_SwitchStateChanged_6x05>(data);
if (ses->map && (cmd.flags & 1) && (cmd.header.object_id != 0xFFFF)) {
for (auto* door : ses->map->doors_for_switch_flag(cmd.switch_flag_floor, cmd.switch_flag_num)) {
if (door->game_flags & 0x0001) {
auto& cmd = check_size_t<G_WriteSwitchFlag_6x05>(data);
if (ses->map_state && (cmd.flags & 1) && (cmd.header.entity_id != 0xFFFF)) {
auto door_states = ses->map_state->door_states_for_switch_flag(
ses->version(), cmd.switch_flag_floor, cmd.switch_flag_num);
for (auto& door_state : door_states) {
if (door_state->game_flags & 0x0001) {
continue;
}
door->game_flags |= 1;
door_state->game_flags |= 1;
uint16_t object_index = ses->map_state->index_for_object_state(ses->version(), door_state);
G_UpdateObjectState_6x0B cmd0B;
cmd0B.header.subcommand = 0x0B;
cmd0B.header.size = sizeof(cmd0B) / 4;
cmd0B.header.client_id = door->object_id | 0x4000;
cmd0B.flags = door->game_flags;
cmd0B.object_index = door->object_id;
cmd0B.header.entity_id = object_index | 0x4000;
cmd0B.flags = door_state->game_flags;
cmd0B.object_index = object_index;
ses->client_channel.send(0x60, 0x00, &cmd0B, sizeof(cmd0B));
ses->server_channel.send(0x60, 0x00, &cmd0B, sizeof(cmd0B));
}
@@ -2075,8 +2082,8 @@ HandlerResult C_6x<void>(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t, u
} else if (data[0] == 0x40) {
C_6x_movement<G_WalkToPosition_6x40>(ses, data);
} else if (data[0] == 0x42) {
C_6x_movement<G_RunToPosition_6x42>(ses, data);
} else if ((data[0] == 0x41) || (data[0] == 0x42)) {
C_6x_movement<G_MoveToPosition_6x41_6x42>(ses, data);
} else if (data[0] == 0x48) {
if (ses->config.check_flag(Client::Flag::INFINITE_TP_ENABLED)) {
@@ -2121,7 +2128,7 @@ static on_command_t handlers[0x100][NUM_VERSIONS][2] = {
// clang-format off
// CMD S_PC_PATCH C S_BB_PATCH C S_DC_NTE C S_DC_V1_12_2000_PROTO C S_DC_V1 C S_DC_V2 C S_PC_NTE C S_PC_V2 C S_GC_NTE C S_GC_V3 C S_GC_EP3_NTE C S_GC_EP3 C S_XB_V3 C S_BB_V4 C
/* 00 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {nullptr, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}},
/* 01 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {S_invalid, nullptr}},
/* 01 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}},
/* 02 */ {{S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {nullptr, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {S_V123P_02_17, nullptr}, {nullptr, nullptr}},
/* 03 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {S_B_03, nullptr}},
/* 04 */ {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {S_V123_04, nullptr}, {nullptr, nullptr}},
+56 -38
View File
@@ -41,8 +41,8 @@ ProxyServer::ProxyServer(
: base(base),
destroy_sessions_ev(event_new(this->base.get(), -1, EV_TIMEOUT, &ProxyServer::dispatch_destroy_sessions, this), event_free),
state(state),
next_unlinked_session_id(this->MIN_UNLINKED_SESSION_ID),
next_logged_out_session_id(this->MIN_LINKED_LOGGED_OUT_SESSION_ID) {}
next_unlinked_session_id(this->FIRST_UNLINKED_SESSION_ID),
next_logged_out_session_id(this->FIRST_LINKED_LOGGED_OUT_SESSION_ID) {}
void ProxyServer::listen(const std::string& addr, uint16_t port, Version version, const struct sockaddr_storage* default_destination) {
auto socket_obj = make_shared<ListeningSocket>(this, addr, port, version, default_destination);
@@ -148,8 +148,8 @@ void ProxyServer::on_client_connect(
// server. This creates a direct session.
if (default_destination && is_patch(version)) {
uint64_t session_id = this->next_logged_out_session_id++;
if (this->next_logged_out_session_id == this->MIN_UNLINKED_SESSION_ID) {
this->next_logged_out_session_id = this->MIN_LINKED_LOGGED_OUT_SESSION_ID;
if (this->next_logged_out_session_id == this->FIRST_LINKED_LOGGED_OUT_SESSION_ID) {
this->next_logged_out_session_id = this->FIRST_LINKED_LOGGED_OUT_SESSION_ID;
}
auto emplace_ret = this->id_to_linked_session.emplace(session_id, make_shared<LinkedSession>(this->shared_from_this(), session_id, listen_port, version, *default_destination));
@@ -167,8 +167,8 @@ void ProxyServer::on_client_connect(
// create an unlinked session - we'll have to get the destination from the
// client's config, which we'll get via a 9E command soon.
uint64_t session_id = this->next_unlinked_session_id++;
if (this->next_unlinked_session_id == 0) {
this->next_unlinked_session_id = this->MIN_UNLINKED_SESSION_ID;
if (this->next_unlinked_session_id == this->FIRST_LINKED_LOGGED_OUT_SESSION_ID) {
this->next_unlinked_session_id = this->FIRST_UNLINKED_SESSION_ID;
}
auto emplace_ret = this->id_to_unlinked_session.emplace(
@@ -190,7 +190,7 @@ void ProxyServer::on_client_connect(
case Version::BB_PATCH:
throw logic_error("cannot create unlinked patch session");
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
case Version::PC_NTE:
@@ -278,6 +278,14 @@ std::shared_ptr<ServerState> ProxyServer::UnlinkedSession::require_server_state(
return this->require_server()->state;
}
void ProxyServer::UnlinkedSession::set_login(std::shared_ptr<Login> login) {
this->login = login;
if (this->log.should_log(phosg::LogLevel::INFO)) {
string login_str = this->login->str();
this->log.info("Login: %s", login_str.c_str());
}
}
void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint32_t, std::string& data) {
auto* ses = reinterpret_cast<UnlinkedSession*>(ch.context_obj);
auto server = ses->require_server();
@@ -288,7 +296,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
try {
switch (ses->version()) {
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
case Version::GC_NTE:
@@ -298,11 +306,13 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->log.info("Version changed to DC_NTE");
ses->config.specific_version = SPECIFIC_VERSION_DC_NTE;
const auto& cmd = check_size_t<C_Login_DCNTE_8B>(data, sizeof(C_LoginExtended_DCNTE_8B));
ses->login = s->account_index->from_dc_nte_credentials(cmd.serial_number.decode(), cmd.access_key.decode(), false);
ses->set_login(s->account_index->from_dc_nte_credentials(
cmd.serial_number.decode(), cmd.access_key.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
// TODO: Parse cmd.hardware_id
ses->hardware_id = cmd.hardware_id;
} else if (command == 0x93) { // 11/2000 proto through DC V1
ses->channel.version = Version::DC_V1;
ses->log.info("Version changed to DC_V1");
@@ -310,33 +320,37 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->config.specific_version = SPECIFIC_VERSION_DC_V1_INDETERMINATE;
}
const auto& cmd = check_size_t<C_LoginV1_DC_93>(data);
ses->login = s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
ses->hardware_id = cmd.hardware_id.decode();
ses->serial_number2 = cmd.serial_number2.decode();
ses->hardware_id = cmd.hardware_id;
} else if (command == 0x9D) {
const auto& cmd = check_size_t<C_Login_DC_PC_GC_9D>(data, sizeof(C_LoginExtended_DC_GC_9D));
if (cmd.sub_version >= 0x30) {
ses->log.info("Version changed to GC_NTE");
ses->channel.version = Version::GC_NTE;
ses->config.specific_version = SPECIFIC_VERSION_GC_NTE;
ses->login = s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false);
ses->set_login(s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false));
} else { // DC V2
ses->log.info("Version changed to DC_V2");
ses->channel.version = Version::DC_V2;
if (specific_version_is_indeterminate(ses->config.specific_version)) {
ses->config.specific_version = SPECIFIC_VERSION_DC_V2_INDETERMINATE;
}
ses->login = s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
}
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
ses->config.set_flags_for_version(ses->version(), cmd.sub_version);
ses->hardware_id = cmd.hardware_id;
} else {
throw runtime_error("command is not 93 or 9D");
}
@@ -349,11 +363,12 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
throw runtime_error("command is not 9D");
}
const auto& cmd = check_size_t<C_Login_DC_PC_GC_9D>(data, sizeof(C_LoginExtended_PC_9D));
ses->login = s->account_index->from_pc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_pc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
ses->hardware_id = cmd.hardware_id;
break;
}
@@ -363,11 +378,12 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
// We should only get a 9E while the session is unlinked
if (command == 0x9E) {
const auto& cmd = check_size_t<C_Login_GC_9E>(data, sizeof(C_LoginExtended_GC_9E));
ses->login = s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false);
ses->set_login(s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
ses->hardware_id = cmd.hardware_id;
ses->config.parse_from(cmd.client_config);
if (cmd.sub_version >= 0x40) {
ses->log.info("Version changed to GC_EP3");
@@ -388,12 +404,13 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
string xb_gamertag = cmd.serial_number.decode();
uint64_t xb_user_id = stoull(cmd.access_key.decode(), nullptr, 16);
uint64_t xb_account_id = cmd.netloc.account_id;
ses->login = s->account_index->from_xb_credentials(xb_gamertag, xb_user_id, xb_account_id, false);
ses->set_login(s->account_index->from_xb_credentials(xb_gamertag, xb_user_id, xb_account_id, false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
ses->xb_netloc = cmd.netloc;
ses->xb_9E_unknown_a1a = cmd.unknown_a1a;
ses->hardware_id = cmd.hardware_id;
ses->channel.send(0x9F, 0x00);
return;
} else if (command == 0x9F) {
@@ -412,7 +429,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
}
const auto& cmd = check_size_t<C_LoginBase_BB_93>(data, 0xFFFF);
string password = cmd.password.decode();
ses->login = s->account_index->from_bb_credentials(cmd.username.decode(), &password, s->allow_unregistered_users);
ses->set_login(s->account_index->from_bb_credentials(cmd.username.decode(), &password, s->allow_unregistered_users));
ses->login_command_bb = std::move(data);
break;
}
@@ -437,7 +454,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
// Look up the linked session for this account (if any)
shared_ptr<LinkedSession> linked_ses;
try {
linked_ses = server->id_to_linked_session.at(ses->login->account->account_id);
linked_ses = server->id_to_linked_session.at(ses->login->proxy_session_id());
linked_ses->log.info("Resuming linked session from unlinked session");
} catch (const out_of_range&) {
@@ -456,7 +473,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
}
if (linked_ses.get()) {
server->id_to_linked_session.emplace(ses->login->account->account_id, linked_ses);
server->id_to_linked_session.emplace(linked_ses->id, linked_ses);
// Resume the linked session using the unlinked session
try {
if (ses->version() == Version::BB_V4) {
@@ -470,6 +487,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->detector_crypt,
ses->sub_version,
ses->character_name,
ses->serial_number2,
ses->hardware_id,
ses->xb_netloc,
ses->xb_9E_unknown_a1a);
@@ -506,7 +524,7 @@ ProxyServer::LinkedSession::LinkedSession(
Version version)
: server(server),
id(id),
log(phosg::string_printf("[ProxyServer:LS-%" PRIX64 "] ", this->id), proxy_server_log.min_level),
log(phosg::string_printf("[ProxyServer:LS-%016" PRIX64 "] ", this->id), proxy_server_log.min_level),
timeout_event(event_new(server->base.get(), -1, EV_TIMEOUT, &LinkedSession::dispatch_on_timeout, this), event_free),
login(nullptr),
client_channel(
@@ -515,7 +533,7 @@ ProxyServer::LinkedSession::LinkedSession(
nullptr,
nullptr,
this,
phosg::string_printf("LS-%" PRIX64 "-C", this->id),
phosg::string_printf("LS-%016" PRIX64 "-C", this->id),
phosg::TerminalFormat::FG_YELLOW,
phosg::TerminalFormat::FG_GREEN),
server_channel(
@@ -524,7 +542,7 @@ ProxyServer::LinkedSession::LinkedSession(
nullptr,
nullptr,
this,
phosg::string_printf("LS-%" PRIX64 "-S", this->id),
phosg::string_printf("LS-%016" PRIX64 "-S", this->id),
phosg::TerminalFormat::FG_YELLOW,
phosg::TerminalFormat::FG_RED),
local_port(local_port),
@@ -539,8 +557,6 @@ ProxyServer::LinkedSession::LinkedSession(
lobby_client_id(0),
leader_client_id(0),
floor(0),
x(0.0),
z(0.0),
is_in_game(false),
is_in_quest(false),
lobby_event(0),
@@ -558,7 +574,7 @@ ProxyServer::LinkedSession::LinkedSession(
Version version,
shared_ptr<Login> login,
const Client::Config& config)
: LinkedSession(server, login->account->account_id, local_port, version) {
: LinkedSession(server, login->proxy_session_id(), local_port, version) {
this->login = login;
this->config = config;
memset(&this->next_destination, 0, sizeof(this->next_destination));
@@ -574,7 +590,7 @@ ProxyServer::LinkedSession::LinkedSession(
Version version,
std::shared_ptr<Login> login,
const struct sockaddr_storage& next_destination)
: LinkedSession(server, login->account->account_id, local_port, version) {
: LinkedSession(server, login->proxy_session_id(), local_port, version) {
this->login = login;
this->next_destination = next_destination;
}
@@ -611,11 +627,13 @@ void ProxyServer::LinkedSession::resume(
shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
uint32_t sub_version,
const string& character_name,
const string& hardware_id,
const string& serial_number2,
uint64_t hardware_id,
const XBNetworkLocation& xb_netloc,
const parray<le_uint32_t, 3>& xb_9E_unknown_a1a) {
this->sub_version = sub_version;
this->character_name = character_name;
this->serial_number2 = serial_number2;
this->hardware_id = hardware_id;
this->xb_netloc = xb_netloc;
this->xb_9E_unknown_a1a = xb_9E_unknown_a1a;
@@ -701,8 +719,8 @@ void ProxyServer::LinkedSession::update_channel_names() {
auto client_ip_str = s->format_address_for_channel_name(
this->client_channel.remote_addr, this->client_channel.virtual_network_id);
auto server_ip_str = s->format_address_for_channel_name(this->server_channel.remote_addr, 0);
this->client_channel.name = phosg::string_printf("LS-%08" PRIX64 "-C @ %s", this->id, client_ip_str.c_str());
this->server_channel.name = phosg::string_printf("LS-%08" PRIX64 "-S @ %s", this->id, server_ip_str.c_str());
this->client_channel.name = phosg::string_printf("LS-%016" PRIX64 "-C @ %s", this->id, client_ip_str.c_str());
this->server_channel.name = phosg::string_printf("LS-%016" PRIX64 "-S @ %s", this->id, server_ip_str.c_str());
}
ProxyServer::LinkedSession::SavingFile::SavingFile(
@@ -777,7 +795,7 @@ void ProxyServer::LinkedSession::set_drop_mode(DropMode new_mode) {
case Version::GC_EP3:
throw runtime_error("cannot create item creator for this base version");
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
// TODO: We should probably have a v1 common item set at some point too
common_item_set = s->common_item_set_v2;
@@ -985,9 +1003,9 @@ shared_ptr<ProxyServer::LinkedSession> ProxyServer::create_logged_in_session(
}
void ProxyServer::delete_session(uint64_t id) {
if (id < this->MIN_UNLINKED_SESSION_ID) {
if (id >= this->FIRST_LINKED_LOGGED_OUT_SESSION_ID) {
if (this->id_to_linked_session.erase(id)) {
proxy_server_log.info("Closed LS-%08" PRIX64, id);
proxy_server_log.info("Closed LS-%016" PRIX64, id);
}
} else {
auto it = this->id_to_unlinked_session.find(id);
+13 -8
View File
@@ -58,7 +58,8 @@ public:
uint32_t sub_version;
std::string character_name;
std::string hardware_id; // Only used for DC sessions
std::string serial_number2; // Only used for DC sessions
uint64_t hardware_id;
std::string login_command_bb;
XBNetworkLocation xb_netloc;
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
@@ -81,7 +82,7 @@ public:
DropMode drop_mode;
std::shared_ptr<std::string> quest_dat_data;
std::shared_ptr<ItemCreator> item_creator;
std::shared_ptr<Map> map;
std::shared_ptr<MapState> map_state;
struct LobbyPlayer {
uint32_t guild_card_number = 0;
@@ -95,8 +96,7 @@ public:
size_t lobby_client_id;
size_t leader_client_id;
uint16_t floor;
float x;
float z;
VectorXZF pos;
bool is_in_game;
bool is_in_quest;
uint8_t lobby_event;
@@ -171,7 +171,8 @@ public:
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
uint32_t sub_version,
const std::string& character_name,
const std::string& hardware_id,
const std::string& serial_number2,
uint64_t hardware_id,
const XBNetworkLocation& xb_netloc,
const parray<le_uint32_t, 3>& xb_9E_unknown_a1a);
void resume(
@@ -261,7 +262,8 @@ private:
std::string character_name;
Client::Config config;
std::string login_command_bb;
std::string hardware_id;
std::string serial_number2;
uint64_t hardware_id;
XBNetworkLocation xb_netloc;
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
@@ -280,6 +282,8 @@ private:
return this->channel.version;
}
void set_login(std::shared_ptr<Login> login);
void receive_and_process_commands();
static void on_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
@@ -306,6 +310,7 @@ private:
Version version,
const struct sockaddr_storage* default_destination);
static constexpr uint64_t MIN_UNLINKED_SESSION_ID = 0xC000000000000000;
static constexpr uint64_t MIN_LINKED_LOGGED_OUT_SESSION_ID = 0x1000000000000000;
static constexpr uint64_t FIRST_UNLINKED_SESSION_ID = 0x0000000000000001;
static constexpr uint64_t FIRST_LINKED_LOGGED_OUT_SESSION_ID = 0x0000000080000000;
static constexpr uint64_t FIRST_LINKED_LOGGED_IN_SESSION_ID = 0x00000000FFFFFFFF;
};
+451 -253
View File
@@ -192,150 +192,33 @@ struct PSODownloadQuestHeader {
le_uint32_t encryption_seed;
} __packed_ws__(PSODownloadQuestHeader, 8);
VersionedQuest::VersionedQuest(
uint32_t quest_number,
uint32_t category_id,
Version version,
uint8_t language,
std::shared_ptr<const std::string> bin_contents,
std::shared_ptr<const std::string> dat_contents,
std::shared_ptr<const std::string> pvr_contents,
std::shared_ptr<const BattleRules> battle_rules,
ssize_t challenge_template_index,
uint8_t description_flag,
std::shared_ptr<const IntegralExpression> available_expression,
std::shared_ptr<const IntegralExpression> enabled_expression,
bool allow_start_from_chat_command,
bool force_joinable,
int16_t lock_status_register)
: quest_number(quest_number),
category_id(category_id),
episode(Episode::NONE),
allow_start_from_chat_command(allow_start_from_chat_command),
joinable(force_joinable),
lock_status_register(lock_status_register),
version(version),
language(language),
is_dlq_encoded(false),
bin_contents(bin_contents),
dat_contents(dat_contents),
pvr_contents(pvr_contents),
battle_rules(battle_rules),
challenge_template_index(challenge_template_index),
description_flag(description_flag),
available_expression(available_expression),
enabled_expression(enabled_expression) {
if (this->dat_contents) {
this->dat_contents_decompressed = make_shared<string>(prs_decompress(*this->dat_contents));
void VersionedQuest::assert_valid() const {
if (this->category_id == 0xFFFFFFFF) {
throw runtime_error("category ID is not set");
}
auto bin_decompressed = prs_decompress(*this->bin_contents);
switch (this->version) {
case Version::DC_NTE: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderDCNTE)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderDCNTE*>(bin_decompressed.data());
this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = phosg::fnv1a32(header, sizeof(header)) & 0xFFFF;
}
this->name = header->name.decode(this->language);
break;
}
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1:
case Version::DC_V2: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderDC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderDC*>(bin_decompressed.data());
this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number;
}
this->name = header->name.decode(this->language);
this->short_description = header->short_description.decode(this->language);
this->long_description = header->long_description.decode(this->language);
break;
}
case Version::PC_NTE:
case Version::PC_V2: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderPC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderPC*>(bin_decompressed.data());
this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number;
}
this->name = header->name.decode(this->language);
this->short_description = header->short_description.decode(this->language);
this->long_description = header->long_description.decode(this->language);
break;
}
case Version::GC_EP3_NTE:
case Version::GC_EP3: {
// Note: This codepath handles Episode 3 download quests, which are not
// the same as Episode 3 quest scripts. The latter are only used offline
// in story mode, but can be disassembled with disassemble_quest_script.
// It's unfortunate that Version::GC_EP3 is used here for Episode 3
// download quests (maps) and there for offline story mode scripts, but
// it's probably not worth refactoring this logic, at least right now.
if (bin_decompressed.size() != sizeof(Episode3::MapDefinition)) {
throw invalid_argument("file is incorrect size");
}
auto* map = reinterpret_cast<const Episode3::MapDefinition*>(bin_decompressed.data());
this->episode = Episode::EP3;
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = map->map_number;
}
this->name = map->name.decode(this->language);
this->short_description = map->quest_name.decode(this->language);
this->long_description = map->description.decode(this->language);
break;
}
case Version::XB_V3:
case Version::GC_NTE:
case Version::GC_V3: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderGC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderGC*>(bin_decompressed.data());
this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version);
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number;
}
this->name = header->name.decode(this->language);
this->short_description = header->short_description.decode(this->language);
this->long_description = header->long_description.decode(this->language);
break;
}
case Version::BB_V4: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderBB)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderBB*>(bin_decompressed.data());
this->joinable |= header->joinable;
this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version);
if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number;
}
this->name = header->name.decode(this->language);
this->short_description = header->short_description.decode(this->language);
this->long_description = header->long_description.decode(this->language);
break;
}
default:
throw logic_error("invalid quest game version");
if (this->quest_number == 0xFFFFFFFF) {
throw runtime_error("quest number is not set");
}
if (this->version == Version::UNKNOWN) {
throw runtime_error("version is not set");
}
if (this->language == 0xFF) {
throw runtime_error("language is not set");
}
if (this->episode == Episode::NONE) {
throw runtime_error("episode is not set");
}
if (this->max_players == 0) {
throw runtime_error("max players is not set");
}
if (!this->bin_contents) {
throw runtime_error("bin file is missing");
}
if (!is_ep3(this->version) && !this->dat_contents) {
throw runtime_error("dat file is missing");
}
if (!is_ep3(this->version) && !this->map_file) {
throw runtime_error("parsed map file is missing");
}
}
@@ -388,14 +271,52 @@ Quest::Quest(shared_ptr<const VersionedQuest> initial_version)
episode(initial_version->episode),
allow_start_from_chat_command(initial_version->allow_start_from_chat_command),
joinable(initial_version->joinable),
max_players(initial_version->max_players),
lock_status_register(initial_version->lock_status_register),
name(initial_version->name),
supermap(nullptr),
battle_rules(initial_version->battle_rules),
challenge_template_index(initial_version->challenge_template_index),
description_flag(initial_version->description_flag),
available_expression(initial_version->available_expression),
enabled_expression(initial_version->enabled_expression) {
this->versions.emplace(this->versions_key(initial_version->version, initial_version->language), initial_version);
this->add_version(initial_version);
}
phosg::JSON Quest::json() const {
auto versions_json = phosg::JSON::list();
for (const auto& [_, vq] : this->versions) {
versions_json.emplace_back(phosg::JSON::dict({
{"Version", phosg::name_for_enum(vq->version)},
{"Language", name_for_language_code(vq->language)},
{"ShortDescription", vq->short_description},
{"LongDescription", vq->long_description},
{"BINFileSize", vq->bin_contents ? vq->bin_contents->size() : phosg::JSON(nullptr)},
{"DATFileSize", vq->dat_contents ? vq->dat_contents->size() : phosg::JSON(nullptr)},
{"PVRFileSize", vq->pvr_contents ? vq->pvr_contents->size() : phosg::JSON(nullptr)},
}));
}
auto battle_rules_json = this->battle_rules ? this->battle_rules->json() : nullptr;
auto challenge_template_index_json = (this->challenge_template_index >= 0)
? this->challenge_template_index
: phosg::JSON(nullptr);
return phosg::JSON::dict({
{"Number", this->quest_number},
{"CategoryID", this->category_id},
{"Episode", name_for_episode(this->episode)},
{"AllowStartFromChatCommand", this->allow_start_from_chat_command},
{"Joinable", this->joinable},
{"MaxPlayers", this->max_players},
{"LockStatusRegister", (this->lock_status_register >= 0) ? this->lock_status_register : phosg::JSON(nullptr)},
{"Name", this->name},
{"BattleRules", std::move(battle_rules_json)},
{"ChallengeTemplateIndex", std::move(challenge_template_index_json)},
{"DescriptionFlag", this->description_flag},
{"AvailableExpression", this->available_expression ? this->available_expression->str() : phosg::JSON(nullptr)},
{"EnabledExpression", this->available_expression ? this->available_expression->str() : phosg::JSON(nullptr)},
{"Versions", std::move(versions_json)},
});
}
uint32_t Quest::versions_key(Version v, uint8_t language) {
@@ -404,51 +325,128 @@ uint32_t Quest::versions_key(Version v, uint8_t language) {
void Quest::add_version(shared_ptr<const VersionedQuest> vq) {
if (this->quest_number != vq->quest_number) {
throw logic_error("incorrect versioned quest number");
throw logic_error(phosg::string_printf(
"incorrect versioned quest number (existing: %08" PRIX32 ", new: %08" PRIX32 ")",
this->quest_number, vq->quest_number));
}
if (this->category_id != vq->category_id) {
throw runtime_error("quest version is in a different category");
throw runtime_error(phosg::string_printf(
"quest version is in a different category (existing: %08" PRIX32 ", new: %08" PRIX32 ")",
this->category_id, vq->category_id));
}
if (this->episode != vq->episode) {
throw runtime_error("quest version is in a different episode");
throw runtime_error(phosg::string_printf(
"quest version is in a different episode (existing: %s, new: %s)",
name_for_episode(this->episode), name_for_episode(vq->episode)));
}
if (this->allow_start_from_chat_command != vq->allow_start_from_chat_command) {
throw runtime_error("quest version has a different allow_start_from_chat_command state");
throw runtime_error(phosg::string_printf(
"quest version has a different allow_start_from_chat_command state (existing: %s, new: %s)",
this->allow_start_from_chat_command ? "true" : "false", vq->allow_start_from_chat_command ? "true" : "false"));
}
if (this->joinable != vq->joinable) {
throw runtime_error("quest version has a different joinability state");
throw runtime_error(phosg::string_printf(
"quest version has a different joinability state (existing: %s, new: %s)",
this->joinable ? "true" : "false", vq->joinable ? "true" : "false"));
}
if (this->max_players != vq->max_players) {
throw runtime_error(phosg::string_printf(
"quest version has a different maximum player count (existing: %hhu, new: %hhu)",
this->max_players, vq->max_players));
}
if (this->lock_status_register != vq->lock_status_register) {
throw runtime_error("quest version has a different lock status register");
throw runtime_error(phosg::string_printf(
"quest version has a different lock status register (existing: %04hX, new: %04hX)",
this->lock_status_register, vq->lock_status_register));
}
if (!this->battle_rules != !vq->battle_rules) {
throw runtime_error("quest version has a different battle rules presence state");
throw runtime_error(phosg::string_printf(
"quest version has a different battle rules presence state (existing: %s, new: %s)",
this->battle_rules ? "present" : "absent", vq->battle_rules ? "present" : "absent"));
}
if (this->battle_rules && (*this->battle_rules != *vq->battle_rules)) {
throw runtime_error("quest version has different battle rules");
string existing_str = this->battle_rules->json().serialize();
string new_str = vq->battle_rules->json().serialize();
throw runtime_error(phosg::string_printf(
"quest version has different battle rules (existing: %s, new: %s)",
existing_str.c_str(), new_str.c_str()));
}
if (this->challenge_template_index != vq->challenge_template_index) {
throw runtime_error("quest version has different challenge template index");
throw runtime_error(phosg::string_printf(
"quest version has different challenge template index (existing: %zd, new: %zd)",
this->challenge_template_index, vq->challenge_template_index));
}
if (this->description_flag != vq->description_flag) {
throw runtime_error("quest version has different description flag");
throw runtime_error(phosg::string_printf(
"quest version has different description flag (existing: %02hhX, new: %02hhX)",
this->description_flag, vq->description_flag));
}
if (!this->available_expression != !vq->available_expression) {
throw runtime_error("quest version has available expression but root quest does not, or vice versa");
throw runtime_error(phosg::string_printf(
"quest version has available expression but root quest does not, or vice versa (existing: %s, new: %s)",
this->available_expression ? "present" : "absent", vq->available_expression ? "present" : "absent"));
}
if (this->available_expression && *this->available_expression != *vq->available_expression) {
throw runtime_error("quest version has a different available expression");
string existing_str = this->available_expression->str();
string new_str = vq->available_expression->str();
throw runtime_error(phosg::string_printf(
"quest version has a different available expression (existing: %s, new: %s)",
existing_str.c_str(), new_str.c_str()));
}
if (!this->enabled_expression != !vq->enabled_expression) {
throw runtime_error("quest version has enabled expression but root quest does not, or vice versa");
throw runtime_error(phosg::string_printf(
"quest version has enabled expression but root quest does not, or vice versa (existing: %s, new: %s)",
this->enabled_expression ? "present" : "absent", vq->enabled_expression ? "present" : "absent"));
}
if (this->enabled_expression && *this->enabled_expression != *vq->enabled_expression) {
throw runtime_error("quest version has a different enabled expression");
string existing_str = this->enabled_expression->str();
string new_str = vq->enabled_expression->str();
throw runtime_error(phosg::string_printf(
"quest version has a different enabled expression (existing: %s, new: %s)",
existing_str.c_str(), new_str.c_str()));
}
this->versions.emplace(this->versions_key(vq->version, vq->language), vq);
}
std::shared_ptr<const SuperMap> Quest::get_supermap(int64_t random_seed) const {
if (this->supermap) {
return this->supermap;
}
bool save_to_cache = true;
bool any_map_file_present = false;
array<shared_ptr<const MapFile>, NUM_VERSIONS> map_files;
for (Version v : ALL_ARPG_SEMANTIC_VERSIONS) {
auto vq = this->version(v, 1);
if (vq && vq->map_file) {
auto map_file = vq->map_file;
if (map_file->has_random_sections()) {
if (random_seed < 0) {
return nullptr;
}
save_to_cache = false;
map_file = map_file->materialize_random_sections(random_seed);
}
map_files.at(static_cast<size_t>(v)) = map_file;
any_map_file_present = true;
}
}
if (!any_map_file_present) {
return nullptr;
}
auto supermap = make_shared<SuperMap>(this->episode, map_files);
if (save_to_cache) {
this->supermap = supermap;
}
static_game_data_log.info("Constructed %s supermap for quest %" PRIu32 " (%s)",
save_to_cache ? "cacheable" : "temporary", this->quest_number, this->name.c_str());
return supermap;
}
bool Quest::has_version(Version v, uint8_t language) const {
return this->versions.count(this->versions_key(v, language));
}
@@ -482,17 +480,27 @@ shared_ptr<const VersionedQuest> Quest::version(Version v, uint8_t language) con
QuestIndex::QuestIndex(
const string& directory,
std::shared_ptr<const QuestCategoryIndex> category_index,
shared_ptr<const QuestCategoryIndex> category_index,
bool is_ep3)
: directory(directory),
category_index(category_index) {
struct FileData {
std::string filename;
string filename;
shared_ptr<const string> data;
};
map<string, FileData> bin_files;
map<string, FileData> dat_files;
struct BINFileData {
string filename;
unique_ptr<QuestMetadata> metadata;
shared_ptr<const string> data;
};
struct DATFileData {
string filename;
shared_ptr<const string> data;
shared_ptr<const MapFile> map_file;
};
map<string, BINFileData> bin_files;
map<string, DATFileData> dat_files;
map<string, FileData> pvr_files;
map<string, FileData> json_files;
map<string, uint32_t> categories;
@@ -519,6 +527,39 @@ QuestIndex::QuestIndex(
}
};
auto add_bin_file = [&](const string& basename, const string& filename, string&& data, const QuestMetadata* metadata) {
if (categories.emplace(basename, cat->category_id).first->second != cat->category_id) {
throw runtime_error("bin file " + basename + " exists in multiple categories");
}
auto data_ptr = make_shared<string>(std::move(data));
auto emplace_ret = bin_files.emplace(basename, BINFileData{});
if (!emplace_ret.second) {
throw runtime_error("bin file " + basename + " already exists");
}
auto& entry = emplace_ret.first->second;
entry.filename = filename;
entry.data = data_ptr;
if (metadata) {
entry.metadata = make_unique<QuestMetadata>(*metadata);
}
if (!(data_ptr->size() & 0x3FF)) {
data_ptr->push_back(0x00);
}
};
auto add_dat_file = [&](const string& basename, const string& filename, string&& data) {
if (categories.emplace(basename, cat->category_id).first->second != cat->category_id) {
throw runtime_error("dat file " + basename + " exists in multiple categories");
}
auto data_ptr = make_shared<string>(std::move(data));
auto map_file = make_shared<MapFile>(make_shared<string>(prs_decompress(*data_ptr)));
if (!dat_files.emplace(basename, DATFileData{filename, data_ptr, map_file}).second) {
throw runtime_error("dat file " + basename + " already exists");
}
if (!(data_ptr->size() & 0x3FF)) {
data_ptr->push_back(0x00);
}
};
string cat_path = directory + "/" + cat->directory_name;
if (!phosg::isdir(cat_path)) {
static_game_data_log.warning("Quest category directory %s is missing; skipping it", cat_path.c_str());
@@ -530,6 +571,7 @@ QuestIndex::QuestIndex(
}
string file_path = cat_path + "/" + filename;
unique_ptr<AssembledQuestScript> assembled;
try {
string orig_filename = filename;
string file_data;
@@ -542,9 +584,13 @@ QuestIndex::QuestIndex(
} else if (phosg::ends_with(filename, ".dlq")) {
file_data = decode_dlq_data(phosg::load_file(file_path));
filename.resize(filename.size() - 4);
} else if (phosg::ends_with(filename, ".txt")) {
} else if (phosg::ends_with(filename, ".bin.txt")) {
string include_dir = phosg::dirname(file_path);
file_data = assemble_quest_script(phosg::load_file(file_path), include_dir);
assembled = make_unique<AssembledQuestScript>(assemble_quest_script(
phosg::load_file(file_path),
{include_dir, "system/quests/includes"},
{include_dir, "system/quests/includes", "system/client-functions/System"}));
file_data = std::move(assembled->data);
filename.resize(filename.size() - 4);
if (phosg::ends_with(filename, ".bin")) {
filename.push_back('d');
@@ -566,22 +612,22 @@ QuestIndex::QuestIndex(
if (extension == "json") {
add_file(json_files, file_basename, orig_filename, std::move(file_data), false);
} else if (extension == "bin" || extension == "mnm") {
add_file(bin_files, file_basename, orig_filename, std::move(file_data), true);
add_bin_file(file_basename, orig_filename, std::move(file_data), assembled ? &assembled->metadata : nullptr);
} else if (extension == "bind" || extension == "mnmd") {
add_file(bin_files, file_basename, orig_filename, prs_compress_optimal(file_data), true);
add_bin_file(file_basename, orig_filename, prs_compress_optimal(file_data), assembled ? &assembled->metadata : nullptr);
} else if (extension == "dat") {
add_file(dat_files, file_basename, orig_filename, std::move(file_data), true);
add_dat_file(file_basename, orig_filename, std::move(file_data));
} else if (extension == "datd") {
add_file(dat_files, file_basename, orig_filename, prs_compress_optimal(file_data), true);
add_dat_file(file_basename, orig_filename, prs_compress_optimal(file_data));
} else if (extension == "pvr") {
add_file(pvr_files, file_basename, orig_filename, std::move(file_data), true);
} else if (extension == "qst") {
auto files = decode_qst_data(file_data);
for (auto& it : files) {
if (phosg::ends_with(it.first, ".bin")) {
add_file(bin_files, file_basename, orig_filename, std::move(it.second), true);
add_bin_file(file_basename, orig_filename, std::move(it.second), nullptr);
} else if (phosg::ends_with(it.first, ".dat")) {
add_file(dat_files, file_basename, orig_filename, std::move(it.second), true);
add_dat_file(file_basename, orig_filename, std::move(it.second));
} else if (phosg::ends_with(it.first, ".pvr")) {
add_file(pvr_files, file_basename, orig_filename, std::move(it.second), true);
} else {
@@ -599,11 +645,10 @@ QuestIndex::QuestIndex(
// All quests have a bin file (even in Episode 3, though its format is
// different), so we use bin_files as the primary list of all quests that
// should be indexed
for (auto& bin_it : bin_files) {
const string& basename = bin_it.first;
const auto* bin_filedata = &bin_it.second;
for (auto& [basename, entry] : bin_files) {
try {
auto vq = make_shared<VersionedQuest>();
// Quest .bin filenames are like K###-VERS-LANG.EXT, where:
// K can be any character (usually it's q)
// # = quest number (does not have to match the internal quest number)
@@ -622,42 +667,172 @@ QuestIndex::QuestIndex(
version_token = std::move(filename_tokens[1]);
language_token = std::move(filename_tokens[2]);
}
vq->category_id = categories.at(basename);
uint32_t category_id = categories.at(basename);
// Find the quest's metadata. If the quest was assembled (that is, if it
// came from a .bin.txt file), use the metadata from the source file;
// otherwise, figure it out from the already-assembled code
if (entry.metadata) {
vq->quest_number = entry.metadata->quest_number;
vq->version = ::is_ep3(entry.metadata->version) ? Version::GC_V3 : entry.metadata->version;
vq->language = entry.metadata->language;
vq->episode = entry.metadata->episode;
vq->joinable = entry.metadata->joinable;
vq->max_players = entry.metadata->max_players;
vq->name = entry.metadata->name;
vq->short_description = entry.metadata->short_description;
vq->long_description = entry.metadata->long_description;
// Get the number from the first token
if (quest_number_token.empty()) {
throw runtime_error("quest number token is missing");
} else {
// Get the number from the first token
if (quest_number_token.empty()) {
throw runtime_error("quest number token is missing");
}
vq->quest_number = strtoull(quest_number_token.c_str() + 1, nullptr, 10);
// Get the version from the second token
static const unordered_map<string, Version> name_to_version({
{"dn", Version::DC_NTE},
{"dp", Version::DC_11_2000},
{"d1", Version::DC_V1},
{"dc", Version::DC_V2},
{"pcn", Version::PC_NTE},
{"pc", Version::PC_V2},
{"gcn", Version::GC_NTE},
{"gc", Version::GC_V3},
{"gc3t", Version::GC_EP3_NTE},
{"gc3", Version::GC_EP3},
{"xb", Version::XB_V3},
{"bb", Version::BB_V4},
});
vq->version = name_to_version.at(version_token);
// Get the language from the last token
if (language_token.size() != 1) {
throw runtime_error("language token is not a single character");
}
vq->language = language_code_for_char(language_token[0]);
auto bin_decompressed = prs_decompress(*entry.data);
switch (vq->version) {
case Version::DC_NTE: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderDCNTE)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderDCNTE*>(bin_decompressed.data());
vq->episode = Episode::EP1;
vq->max_players = 4;
vq->name = header->name.decode(vq->language);
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = phosg::fnv1a64(vq->name);
}
break;
}
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderDC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderDC*>(bin_decompressed.data());
vq->episode = Episode::EP1;
vq->max_players = 4;
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = header->quest_number;
}
vq->name = header->name.decode(vq->language);
vq->short_description = header->short_description.decode(vq->language);
vq->long_description = header->long_description.decode(vq->language);
break;
}
case Version::PC_NTE:
case Version::PC_V2: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderPC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderPC*>(bin_decompressed.data());
vq->episode = Episode::EP1;
vq->max_players = 4;
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = header->quest_number;
}
vq->name = header->name.decode(vq->language);
vq->short_description = header->short_description.decode(vq->language);
vq->long_description = header->long_description.decode(vq->language);
break;
}
case Version::GC_EP3_NTE:
case Version::GC_EP3: {
// Note: This codepath handles Episode 3 download quests, which are not
// the same as Episode 3 quest scripts. The latter are only used offline
// in story mode, but can be disassembled with disassemble_quest_script.
// It's unfortunate that Version::GC_EP3 is used here for Episode 3
// download quests (maps) and there for offline story mode scripts, but
// it's probably not worth refactoring this logic, at least right now.
if (bin_decompressed.size() != sizeof(Episode3::MapDefinition)) {
throw invalid_argument("file is incorrect size");
}
auto* map = reinterpret_cast<const Episode3::MapDefinition*>(bin_decompressed.data());
vq->episode = Episode::EP3;
vq->max_players = 4;
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = map->map_number;
}
vq->name = map->name.decode(vq->language);
vq->short_description = map->quest_name.decode(vq->language);
vq->long_description = map->description.decode(vq->language);
break;
}
case Version::XB_V3:
case Version::GC_NTE:
case Version::GC_V3: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderGC)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderGC*>(bin_decompressed.data());
vq->episode = find_quest_episode_from_script(
bin_decompressed.data(), bin_decompressed.size(), vq->version);
vq->max_players = 4;
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = header->quest_number;
}
vq->name = header->name.decode(vq->language);
vq->short_description = header->short_description.decode(vq->language);
vq->long_description = header->long_description.decode(vq->language);
break;
}
case Version::BB_V4: {
if (bin_decompressed.size() < sizeof(PSOQuestHeaderBB)) {
throw invalid_argument("file is too small for header");
}
auto* header = reinterpret_cast<const PSOQuestHeaderBB*>(bin_decompressed.data());
vq->episode = find_quest_episode_from_script(
bin_decompressed.data(), bin_decompressed.size(), vq->version);
vq->joinable |= header->joinable;
vq->max_players = 4;
if (vq->quest_number == 0xFFFFFFFF) {
vq->quest_number = header->quest_number;
}
vq->name = header->name.decode(vq->language);
vq->short_description = header->short_description.decode(vq->language);
vq->long_description = header->long_description.decode(vq->language);
break;
}
default:
throw logic_error("invalid quest game version");
}
}
uint32_t quest_number = strtoull(quest_number_token.c_str() + 1, nullptr, 10);
// Get the version from the second token
static const unordered_map<string, Version> name_to_version({
{"dn", Version::DC_NTE},
{"dp", Version::DC_V1_11_2000_PROTOTYPE},
{"d1", Version::DC_V1},
{"dc", Version::DC_V2},
{"pcn", Version::PC_NTE},
{"pc", Version::PC_V2},
{"gcn", Version::GC_NTE},
{"gc", Version::GC_V3},
{"gc3t", Version::GC_EP3_NTE},
{"gc3", Version::GC_EP3},
{"xb", Version::XB_V3},
{"bb", Version::BB_V4},
});
auto version = name_to_version.at(version_token);
// Get the language from the last token
if (language_token.size() != 1) {
throw runtime_error("language token is not a single character");
}
uint8_t language = language_code_for_char(language_token[0]);
// Find the corresponding dat and pvr files
const FileData* dat_filedata = nullptr;
const DATFileData* dat_filedata = nullptr;
const FileData* pvr_filedata = nullptr;
if (!::is_ep3(version)) {
if (!::is_ep3(vq->version)) {
// Look for dat and pvr files with the same basename as the bin file; if
// not found, look for them without the language suffix
try {
@@ -680,17 +855,17 @@ QuestIndex::QuestIndex(
}
}
}
vq->bin_contents = entry.data;
if (dat_filedata) {
vq->dat_contents = dat_filedata->data;
vq->map_file = dat_filedata->map_file;
}
if (pvr_filedata) {
vq->pvr_contents = pvr_filedata->data;
}
// Load the quest's metadata phosg::JSON file, if it exists
// Load the quest's metadata JSON file, if it exists
const FileData* json_filedata = nullptr;
shared_ptr<BattleRules> battle_rules;
ssize_t challenge_template_index = -1;
uint8_t description_flag = 0;
shared_ptr<const IntegralExpression> available_expression;
shared_ptr<const IntegralExpression> enabled_expression;
bool allow_start_from_chat_command = false;
bool force_joinable = false;
int16_t lock_status_register = -1;
try {
json_filedata = &json_files.at(basename);
} catch (const out_of_range&) {
@@ -706,58 +881,43 @@ QuestIndex::QuestIndex(
if (json_filedata) {
auto metadata_json = phosg::JSON::parse(*json_filedata->data);
try {
battle_rules = make_shared<BattleRules>(metadata_json.at("BattleRules"));
vq->battle_rules = make_shared<BattleRules>(metadata_json.at("BattleRules"));
} catch (const out_of_range&) {
}
try {
challenge_template_index = metadata_json.at("ChallengeTemplateIndex").as_int();
vq->challenge_template_index = metadata_json.at("ChallengeTemplateIndex").as_int();
} catch (const out_of_range&) {
}
try {
description_flag = metadata_json.at("DescriptionFlag").as_int();
vq->description_flag = metadata_json.at("DescriptionFlag").as_int();
} catch (const out_of_range&) {
}
try {
available_expression = make_shared<IntegralExpression>(metadata_json.get_string("AvailableIf"));
vq->available_expression = make_shared<IntegralExpression>(metadata_json.get_string("AvailableIf"));
} catch (const out_of_range&) {
}
try {
enabled_expression = make_shared<IntegralExpression>(metadata_json.get_string("EnabledIf"));
vq->enabled_expression = make_shared<IntegralExpression>(metadata_json.get_string("EnabledIf"));
} catch (const out_of_range&) {
}
try {
allow_start_from_chat_command = metadata_json.get_bool("AllowStartFromChatCommand");
vq->allow_start_from_chat_command = metadata_json.get_bool("AllowStartFromChatCommand");
} catch (const out_of_range&) {
}
try {
force_joinable = metadata_json.get_bool("Joinable");
vq->joinable = metadata_json.get_bool("Joinable");
} catch (const out_of_range&) {
}
try {
lock_status_register = metadata_json.get_int("LockStatusRegister");
vq->lock_status_register = metadata_json.get_int("LockStatusRegister");
} catch (const out_of_range&) {
}
}
auto vq = make_shared<VersionedQuest>(
quest_number,
category_id,
version,
language,
bin_filedata->data,
dat_filedata ? dat_filedata->data : nullptr,
pvr_filedata ? pvr_filedata->data : nullptr,
battle_rules,
challenge_template_index,
description_flag,
available_expression,
enabled_expression,
allow_start_from_chat_command,
force_joinable,
lock_status_register);
vq->assert_valid();
auto category_name = this->category_index->at(vq->category_id)->name;
string filenames_str = bin_filedata->filename;
string filenames_str = entry.filename;
if (dat_filedata) {
filenames_str += phosg::string_printf("/%s", dat_filedata->filename.c_str());
}
@@ -793,11 +953,39 @@ QuestIndex::QuestIndex(
vq->joinable ? "joinable" : "not joinable");
}
} catch (const exception& e) {
static_game_data_log.warning("(%s) Failed to index quest file: (%s)", basename.c_str(), e.what());
static_game_data_log.warning("(%s) Failed to index quest file: %s", basename.c_str(), e.what());
}
}
}
phosg::JSON QuestIndex::json() const {
auto categories_json = phosg::JSON::dict();
for (const auto& cat : this->category_index->categories) {
auto dict = phosg::JSON::dict({
{"CategoryID", cat->category_id},
{"Flags", cat->enabled_flags},
{"DirectoryName", cat->directory_name},
{"Name", cat->name},
{"Description", cat->description},
});
categories_json.emplace(cat->name, std::move(dict));
}
auto quests_json = phosg::JSON::list();
for (const auto& [_, q] : this->quests_by_number) {
quests_json.emplace_back(q->json());
}
return phosg::JSON::dict({
{"Directory", this->directory},
{"Categories", std::move(categories_json)},
{"Quests", std::move(quests_json)},
});
// std::map<uint32_t, std::shared_ptr<Quest>> quests_by_number;
// std::map<std::string, std::shared_ptr<Quest>> quests_by_name;
// std::map<uint32_t, std::map<uint32_t, std::shared_ptr<Quest>>> quests_by_category_id_and_number;
}
shared_ptr<const Quest> QuestIndex::get(uint32_t quest_number) const {
try {
return this->quests_by_number.at(quest_number);
@@ -817,11 +1005,11 @@ shared_ptr<const Quest> QuestIndex::get(const std::string& name) const {
vector<shared_ptr<const QuestCategoryIndex::Category>> QuestIndex::categories(
QuestMenuType menu_type,
Episode episode,
Version version,
uint16_t version_flags,
IncludeCondition include_condition) const {
vector<shared_ptr<const QuestCategoryIndex::Category>> ret;
for (const auto& cat : this->category_index->categories) {
if (cat->check_flag(menu_type) && !this->filter(episode, version, cat->category_id, include_condition, 1).empty()) {
if (cat->check_flag(menu_type) && !this->filter(episode, version_flags, cat->category_id, include_condition, 1).empty()) {
ret.emplace_back(cat);
}
}
@@ -830,7 +1018,7 @@ vector<shared_ptr<const QuestCategoryIndex::Category>> QuestIndex::categories(
vector<pair<QuestIndex::IncludeState, shared_ptr<const Quest>>> QuestIndex::filter(
Episode episode,
Version version,
uint16_t version_flags,
uint32_t category_id,
IncludeCondition include_condition,
size_t limit) const {
@@ -843,17 +1031,27 @@ vector<pair<QuestIndex::IncludeState, shared_ptr<const Quest>>> QuestIndex::filt
return ret;
}
for (auto it : category_it->second) {
if (((effective_episode == Episode::NONE) || (it.second->episode == effective_episode)) &&
it.second->has_version_any_language(version)) {
IncludeState state = include_condition ? include_condition(it.second) : IncludeState::AVAILABLE;
if (state == IncludeState::HIDDEN) {
continue;
}
ret.emplace_back(make_pair(state, it.second));
if (limit && (ret.size() >= limit)) {
if ((effective_episode != Episode::NONE) && (it.second->episode != effective_episode)) {
continue;
}
bool all_required_versions_present = true;
for (size_t v_s = 0; v_s < NUM_VERSIONS; v_s++) {
if ((version_flags & (1 << v_s)) && !it.second->has_version_any_language(static_cast<Version>(v_s))) {
all_required_versions_present = false;
break;
}
}
if (!all_required_versions_present) {
continue;
}
IncludeState state = include_condition ? include_condition(it.second) : IncludeState::AVAILABLE;
if (state == IncludeState::HIDDEN) {
continue;
}
ret.emplace_back(make_pair(state, it.second));
if (limit && (ret.size() >= limit)) {
break;
}
}
return ret;
}
@@ -912,7 +1110,7 @@ shared_ptr<VersionedQuest> VersionedQuest::create_download_quest(uint8_t overrid
// There's no known language field in this version, so we don't write
// anything here
break;
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
if (decompressed_bin.size() < sizeof(PSOQuestHeaderDC)) {
@@ -1228,7 +1426,7 @@ unordered_map<string, string> decode_qst_data(const string& data) {
// the filename was shifted over by one byte. To detect this, we check if
// the V3 type field has a reasonable value, and if not, we assume the file
// is for PSO DC.
if (r.pget_u32l(sizeof(PSOCommandHeaderDCV3) + offsetof(S_OpenFile_PC_GC_44_A6, type)) > 3) {
if (r.pget_u16l(sizeof(PSOCommandHeaderDCV3) + offsetof(S_OpenFile_PC_GC_44_A6, type)) > 3) {
return decode_qst_data_t<PSOCommandHeaderDCV3, S_OpenFile_DC_44_A6>(data);
} else {
return decode_qst_data_t<PSOCommandHeaderDCV3, S_OpenFile_PC_GC_44_A6>(data);
@@ -1326,7 +1524,7 @@ string encode_qst_file(
// unfortunate abstraction-breaking.
switch (version) {
case Version::DC_NTE: // DC NTE doesn't support quests, but we support encoding QST files anyway
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_11_2000:
case Version::DC_V1:
case Version::DC_V2:
for (const auto& it : files) {

Some files were not shown because too many files have changed in this diff Show More