Compare commits
246 Commits
v2025-09-30
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
f05e68492d
|
|||
| 7f68d41bac | |||
| 75e7232096 | |||
| 7a29b39771 | |||
| cfcb56b13f | |||
| 9e6740b778 | |||
| 590f937959 | |||
| 31abc24e81 | |||
| 507fbf0451 | |||
| 1fa660129d | |||
| 67082f7b6b | |||
| b34c9a7c88 | |||
| 87e85932a4 | |||
| b704d827ed | |||
| 598ecf88e3 | |||
| a05971017d | |||
| b7819413b0 | |||
| 80e4b0e6fe | |||
| daee47b722 | |||
| 5724fb9a12 | |||
| 983753f840 | |||
| 53d2318873 | |||
| 83291d5501 | |||
| 55be92a56f | |||
| 6a23e5da0a | |||
| 4571cf7fdc | |||
| 4e3549ba6b | |||
| 3cbf64dda2 | |||
| 382bc6b7ce | |||
| e05991ffb3 | |||
| ffda97222d | |||
| 8f21604367 | |||
| 4045504b61 | |||
| 4aad1514c2 | |||
| a649a4a146 | |||
| 7e21d8a9a1 | |||
| c0fc3014cf | |||
| 08dff98948 | |||
| d1c1228308 | |||
| b5fd58722b | |||
| f0e8e35e2b | |||
| 68b495b4b4 | |||
| 1e459edfc4 | |||
| c6d7025f43 | |||
| ccf4b723f5 | |||
| 8717f00106 | |||
| 99630c999d | |||
| e8c262223b | |||
| 3d7215d591 | |||
| ba48236200 | |||
| 8065300fae | |||
| e9dfa5d1de | |||
| d38be2f360 | |||
| 2429c4d341 | |||
| ef2d9fae03 | |||
| 7016d65313 | |||
| bdd066edb2 | |||
| 1bd305d4e7 | |||
| 890014b223 | |||
| e4ef96fcc5 | |||
| 641b3a7bef | |||
| 6f9f684cc9 | |||
| 2602196279 | |||
| ec16cb0ae3 | |||
| 6da7b26c9f | |||
| 8663e6682a | |||
| 9b14e5d400 | |||
| a1e067cc52 | |||
| a469b4355e | |||
| 4aa206bd4b | |||
| d9540ba414 | |||
| cb7c45ef27 | |||
| f98db20618 | |||
| 8fbf2246e6 | |||
| 6b1726c1b5 | |||
| cac61e6763 | |||
| 227e88f906 | |||
| 7ab3175f80 | |||
| cd0d13e98c | |||
| 8eeb487bc7 | |||
| d79d551c68 | |||
| 4b43333ce9 | |||
| b228ea847f | |||
| 4d97bdec7f | |||
| 8133b20598 | |||
| 73ced9d229 | |||
| 6e765fe1ed | |||
| 26f9b90ef8 | |||
| 668c687d68 | |||
| 87b048dc15 | |||
| ea23f18aa2 | |||
| a0a7231d67 | |||
| e5a03b7e9b | |||
| a013b8c9d3 | |||
| 894ac6b8ff | |||
| a462a774f5 | |||
| a9fa138213 | |||
| 0a4c9a0a61 | |||
| f99bba67d0 | |||
| 849cca37c8 | |||
| 9ebaaacd46 | |||
| c1968dad27 | |||
| 2732f9c9f8 | |||
| 1bd2e6cf62 | |||
| 1ab7a851be | |||
| 342b4df8c4 | |||
| 8953ffc2b5 | |||
| af796a418a | |||
| 60203bdfba | |||
| 6677908354 | |||
| 96079700f7 | |||
| 976a281e93 | |||
| 6291e42ba9 | |||
| a89423e9f5 | |||
| 81169ba9d3 | |||
| e715a8461a | |||
| 1ee6b21398 | |||
| 9524020aaa | |||
| 194bb5b393 | |||
| 779ec9df3b | |||
| 82ed175a5c | |||
| 68f96129fe | |||
| c482324a97 | |||
| 800c70c401 | |||
| f26c543977 | |||
| 23e31749e9 | |||
| ad91b6f6b7 | |||
| 2c333b51d2 | |||
| 80f8ee1b09 | |||
| 1498a6e68d | |||
| 1fc313505a | |||
| 435ac82c18 | |||
| 7ec267a7c0 | |||
| 81293255b5 | |||
| 4fe225a302 | |||
| 3ef91b0159 | |||
| e02a006b60 | |||
| 23eb6b29a5 | |||
| afe48e7034 | |||
| bd1cdfdb97 | |||
| a783177420 | |||
| 9d42f849c5 | |||
| 566de06fd1 | |||
| 474ad99396 | |||
| b53847d1b5 | |||
| d827c1bf5d | |||
| 886daa5880 | |||
| cc72092b05 | |||
| c6f74e74c4 | |||
| 328980628a | |||
| 886e9b9f4f | |||
| 26d2ae416e | |||
| 62c4c82fcc | |||
| 11cc19fe3e | |||
| d1d045a70e | |||
| 54c790a63c | |||
| f1f5c1036a | |||
| 77d5436b15 | |||
| 678c60dd14 | |||
| d40d231584 | |||
| 00ddff7e46 | |||
| 5725af0f6b | |||
| 87248e7e67 | |||
| 712cfc9ac4 | |||
| 1d8befde8e | |||
| fb036cda37 | |||
| 136e2730de | |||
| ae47d92016 | |||
| b80ed0021b | |||
| 1d11879142 | |||
| a122b27b1f | |||
| cbba724ba1 | |||
| 2c51571ea4 | |||
| e1d774ce49 | |||
| b9e3973c76 | |||
| c878093c5f | |||
| 7210441878 | |||
| 36eeee5641 | |||
| 8d2ffba3e1 | |||
| 766d4e0c7a | |||
| a99f552e7c | |||
| 540a41a583 | |||
| 8cb7d2b2fe | |||
| 293f25d579 | |||
| 64763e76af | |||
| 69b7e7f998 | |||
| 5579bce5d9 | |||
| 0dd5e2ac10 | |||
| 155ed6bcf9 | |||
| 4e2f62bc73 | |||
| bf36a185a2 | |||
| 4c4c54c536 | |||
| e79e6944df | |||
| f6079e3078 | |||
| 31b49a71fb | |||
| 83260d5037 | |||
| 648da83aa1 | |||
| adf1db92c7 | |||
| 662ee48a64 | |||
| 446b521898 | |||
| d6db731149 | |||
| 9106a11be8 | |||
| 7bc58a757e | |||
| 27b5556e4b | |||
| b39b4197ed | |||
| a99647d4c7 | |||
| 10a6bafb2f | |||
| b4f7688b82 | |||
| 08e6b882f3 | |||
| 4adc174674 | |||
| 01b1f42bac | |||
| be4c7f80cb | |||
| 790363adb5 | |||
| 09b96a4a86 | |||
| 6ffa656ad4 | |||
| 3f2df68ac5 | |||
| a7f2ecefe5 | |||
| 46c2260d0f | |||
| 052dcf8c6e | |||
| cd5863fcde | |||
| 90de571457 | |||
| d9d33c2d65 | |||
| 09962696b7 | |||
| d143cbb461 | |||
| db7f7abfc4 | |||
| 6ba92d3a7a | |||
| 36a1e0dfae | |||
| 47f7e71ae9 | |||
| c2008f1f9c | |||
| 3c32a66064 | |||
| 41026fbd93 | |||
| d49750aa02 | |||
| 54f309030e | |||
| 093c25fce4 | |||
| a777dc8236 | |||
| 4044e4e5a6 | |||
| 036b4e9456 | |||
| 4074530a71 | |||
| 31eedd7e7e | |||
| df2dfd21e3 | |||
| 00b0f71bf4 | |||
| 1450a5acd3 | |||
| 2a138ea0b6 | |||
| 2534ff37de | |||
| d61cb1106d | |||
| d5f0c6aceb |
+25
-12
@@ -2,45 +2,58 @@
|
||||
.DS_Store
|
||||
|
||||
# Build products
|
||||
src/Revision.cc
|
||||
newserv
|
||||
newserv.exe
|
||||
src/Revision.cc
|
||||
|
||||
# CMake files
|
||||
build
|
||||
cmake_install.cmake
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CTestTestFile.cmake
|
||||
CTestTestfile.cmake
|
||||
CTestTestFile.cmake
|
||||
install_manifest.txt
|
||||
Makefile
|
||||
Testing
|
||||
build
|
||||
|
||||
# Files modified by the user and/or server that don't have defaults
|
||||
system/config.json
|
||||
system/ep3/battle-records/*.mzr
|
||||
system/ep3/battle-records/*.mzrd
|
||||
system/ep3/tournament-state.json
|
||||
system/licenses.nsi
|
||||
system/licenses/*.json
|
||||
system/patch-bb/.metadata-cache.json
|
||||
system/patch-pc/.metadata-cache.json
|
||||
system/players/*.nsa
|
||||
system/players/*.nsc
|
||||
system/players/*.psobank
|
||||
system/players/*.psocard
|
||||
system/players/*.psochar
|
||||
system/players/*.psosys
|
||||
system/players/*.psocard
|
||||
system/players/*.nsc
|
||||
system/players/*.nsa
|
||||
system/teams/*.json
|
||||
system/teams/*.bmp
|
||||
system/patch-pc/.metadata-cache.json
|
||||
system/patch-bb/.metadata-cache.json
|
||||
system/teams/*.json
|
||||
|
||||
# Files fuzziqersoftware uses that don't make sense to be committed to the main
|
||||
# repository
|
||||
*.dec
|
||||
*.WIP-s
|
||||
files
|
||||
make_release.py
|
||||
notes-private
|
||||
old-khyller
|
||||
old-newserv
|
||||
release
|
||||
release.zip
|
||||
system/patch-bb/data
|
||||
system/patch-bb/psobb.pat
|
||||
all-quests
|
||||
system/dol
|
||||
system/patch-bb/data
|
||||
system/client-functions/Debug-Private
|
||||
system/config.2.json
|
||||
system/ep3/banners
|
||||
system/ep3/cardtex
|
||||
system/ep3/cardtex-trial
|
||||
system/players
|
||||
system/quests/includes
|
||||
system/quests/private
|
||||
.vscode
|
||||
|
||||
+6
-4
@@ -101,6 +101,7 @@ set(SOURCES
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/PatchDownloadSession.cc
|
||||
src/PatchFileIndex.cc
|
||||
src/PlayerInventory.cc
|
||||
src/PlayerSubordinates.cc
|
||||
@@ -133,11 +134,12 @@ set(SOURCES
|
||||
|
||||
add_executable(newserv ${SOURCES})
|
||||
target_include_directories(newserv PUBLIC ${ASIO_INCLUDE_DIR} ${Iconv_INCLUDE_DIRS})
|
||||
target_link_libraries(newserv phosg::phosg ${Iconv_LIBRARIES} pthread resource_file::resource_file)
|
||||
target_link_libraries(newserv phosg::phosg ${Iconv_LIBRARIES} resource_file::resource_file)
|
||||
if (WIN32)
|
||||
target_compile_definitions(newserv PUBLIC -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00)
|
||||
target_link_libraries(newserv ws2_32 mswsock bcrypt iphlpapi -static -static-libgcc -static-libstdc++)
|
||||
target_compile_options(newserv PRIVATE -Wa,-mbig-obj)
|
||||
target_compile_definitions(newserv PUBLIC WINVER=0x0A00 _WIN32_WINNT=0x0A00)
|
||||
target_compile_options(newserv PRIVATE -Wa,-mbig-obj -Wno-mismatched-new-delete)
|
||||
target_link_options(newserv PRIVATE -static -static-libgcc -static-libstdc++)
|
||||
target_link_libraries(newserv ws2_32 mswsock bcrypt iphlpapi)
|
||||
endif()
|
||||
add_dependencies(newserv newserv-Revision-cc)
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ Some of the more likely useful files are:
|
||||
* **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, listing of object/enemy types and parameters, and reverse-engineered Challenge Mode random enemy generation algorithm
|
||||
* **src/Map.hh/cc**: Map file (.dat/.evt) structure, listing of object/enemy types and parameters, 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
|
||||
@@ -181,7 +181,7 @@ newserv implements a patch server for PSO PC and PSO BB game data. Any file or d
|
||||
For Blue Burst set up, the below is mandatory for a smooth experience:
|
||||
|
||||
1. Browse to your chosen client's data directory.
|
||||
2. Copy all the `map_*.dat` files, `unitxt_*` files and the `data.gsl` file and place them in `system/patch-bb/data`.
|
||||
2. Copy all the `map_*.dat` files, `map_*.evt`, `unitxt_*` files, and the `data.gsl` file and place them in `system/patch-bb/data`.
|
||||
3. If you're using game files from the Tethealla client, make a copy of `unitxt_j.prs` inside system/patch-bb/data and name it `unitxt_e.prs`. (If `unitxt_e.prs` already exists, replace it with the copied file.)
|
||||
|
||||
If you don't have a BB client, or if you're using a Tethealla client from another source, Tethealla clients that are compatible with newserv can be found here: [English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) / [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip). These clients connect to 127.0.0.1 (localhost) automatically.
|
||||
@@ -355,7 +355,7 @@ There are multiple PSO quest formats out there; newserv supports all of them. It
|
||||
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.
|
||||
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/maps/). These files can be encoded in any of the formats described above, except .qst.
|
||||
|
||||
When newserv indexes the quests during startup, it will warn (but not fail) if any quests are corrupt or in unrecognized formats.
|
||||
|
||||
@@ -452,9 +452,7 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i
|
||||
* card-text.mnr: Compressed card text archive. Generally only used for debugging.
|
||||
* card-text.mnrd: Decompressed card text archive; same format as TextCardE.bin. Generally only used for debugging.
|
||||
* com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time.
|
||||
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with the default online maps, as well as some fan-made variations and quests to help new players get up to speed.
|
||||
* maps-download/: Download maps and quests (.mnm/.bin/.mnmd/.bind files). There are two subcategories by default (download maps and Trial Edition download maps), but you can add more by editing QuestCategories in config.json. Categories that have flag 0x40 (Ep3 download) set are indexed from this directory; all others are indexed from system/quests/. Files in maps-download/ subdirectories have the same format as those in the maps/ directory, but should be named like `e###-gc3-LANGUAGE.EXT` (similar to how non-Episode 3 quests are named in the system/quests/ directory). If you want a map to be available for online play and for downloading, the file must exist in both maps/ and in a maps-download/ subdirectory (a symbolic link is acceptable).
|
||||
* maps-offline/: Offline map files. These are all the offline quests and free battle maps from the client, including some debugging/test maps that were inaccessible during normal play. To make them playable online, put the files in the maps/ directory.
|
||||
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with the default online maps, as well as some fan-made variations and quests to help new players get up to speed. Within the maps/ directory, each subdirectory is treated as a separate category and may be optionally downloadable or available at the battle setup counter. The category.json file in each subdirectory specifies the category's behavior; see system/ep3/maps/online/category.json for a documented example.
|
||||
* tournament-state.json: State of all active tournaments. This file is automatically written when any tournament changes state for any reason (e.g. a tournament is created/started/deleted or a match is resolved).
|
||||
|
||||
There is no public editor for Episode 3 maps and quests, but the format is described fairly thoroughly in src/Episode3/DataIndexes.hh (see the MapDefinition structure). You'll need to use `newserv decompress-prs ...` to decompress a .bin or .mnm file before editing it, but you don't need to compress it again to use it - just put the .bind or .mnmd file in the maps directory and newserv will make it available.
|
||||
@@ -478,10 +476,12 @@ The specific versions are:
|
||||
| PSO DC v1 JP | 1OJF | Client functions not supported |
|
||||
| PSO DC v1 US | 1OEF | Client functions not supported |
|
||||
| PSO DC v1 EU | 1OPF | Client functions not supported |
|
||||
| PSO DC 08/2001 prototype | 2OJ5 | SH-4 |
|
||||
| PSO DC 08/06/2001 prototype | 2OJ4 | SH-4 |
|
||||
| PSO DC 08/22/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) Trial Edition | 2OJT | Client functions not supported |
|
||||
| PSO PC (v2) 04/2002 | 2OJW | Client functions not supported |
|
||||
| PSO PC (v2) 02/2003 | 2OJZ | Client functions not supported |
|
||||
| PSO GC Trial Edition | 3OJT | PowerPC |
|
||||
@@ -546,7 +546,8 @@ There are many options available when starting a proxy session. All options are
|
||||
* Online quests and download quests (saved as .bin/.dat files)
|
||||
* GBA games (saved as .gba files)
|
||||
* Patches (saved as .bin files and disassembled as .txt files)
|
||||
* Player data from BB sessions (saved as .psochar files)
|
||||
* Player, system, and Guild Card data from BB sessions (saved as .psochar, .psosys, .psosysteam, and .psocard files)
|
||||
* Stream file data from BB sessions (saved as ItemPMT, BattleParamEntry, ItemMagEdit, and PlyLevelTbl files)
|
||||
* Episode 3 online quests and maps (saved as .mnmd files)
|
||||
* Episode 3 download quests (saved as .mnm files)
|
||||
* Episode 3 card definitions (saved as .mnr files)
|
||||
@@ -602,11 +603,14 @@ Some commands only work for clients not in proxy sessions. The chat commands are
|
||||
* `$qsyncall <reg-num> <value>`: Set a quest register's value for everyone in the game. `<reg-num>` should be either rXX (e.g. r60) or fXX (e.g. f60); if the latter, `<value>` is parsed as a floating-point value instead of as an integer.
|
||||
* `$swset [floor] <flag-num>` and `$swclear [floor] <flag-num>`: Set or clear a switch flag. If floor is not given, sets or clears the flag on your current floor.
|
||||
* `$swsetall`: Set all switch flags on your current floor. This unlocks all doors, disables all laser fences, triggers all light/poison switches, etc.
|
||||
* `$allrare`: Make all enemies and boxes drop their rare items every time.
|
||||
* `$gc` (non-proxy only): Send your own Guild Card to yourself.
|
||||
* `$sc <data>`: Send a command to yourself.
|
||||
* `$scp <data>`: Send a protected 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.
|
||||
* `$auction` (Episode 3 only): Bring up the CARD Auction menu, even if there are fewer than 4 players are in the game or you don't have a VIP card.
|
||||
* `$makeobj <type> [coords...] [angles...] [params...]`: Create a map object. This is only implemented for a few specific client versions. The type is an integer like `273` or `0x0107`. Coordinates are specified as e.g. `x:30 y:0 z:-25.5`; if coordinates are not specified, the object is created at the player's coordinates. Angles are specified as e.g. `r:0 p:0x1000 w:-0x400` (for roll, pitch, and yaw, respectively). Parameters are specified as e.g. `1:2.0 2:0.0 5:0x4000`; any unspecified parameters are set to zero. The object is only created for the calling player and is not added to the server's map state; if the object ever sends update commands (e.g. 6x0B), it will likely result in a disconnection.
|
||||
|
||||
* Personal state commands
|
||||
* `$arrow <color-id>`: Change your lobby arrow color. The color may be specified by number (0-12) or by name (red, blue, green, yellow, purple, cyan, orange, pink, white, white2, white3, or black).
|
||||
@@ -644,17 +648,32 @@ Some commands only work for clients not in proxy sessions. The chat commands are
|
||||
* `$stat <what>`: Show a statistic about your player or team in the current battle. `<what>` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`.
|
||||
* `$surrender`: Cause your team to immediately lose the current battle. If your story character is already defeated, you can't surrender - only your teammate can.
|
||||
* `$saverec <name>`: Save the recording of the last battle.
|
||||
* `$playrec <name>`: Play a battle recording. This command creates a spectator team immediately but the replay does not start automatically, to give other players a chance to join. To start the battle replay within the spectator team, run `$playrec` again (with no name). There is a bug in Dolphin that makes this command unstable in emulation (see the "Battle records" section above).
|
||||
* `$playrec <name>`: Play a battle recording. This command creates a spectator team and plays the specified recording as if it were happening in real time. By default, playback will start immediately when the spectator team is ready; you can delay this to allow others to join by prepending a `!` to the recording name. In that case, using `$playrec` again (with no argument) within the spectator team will start playback.
|
||||
|
||||
* Cheat mode commands
|
||||
* `$cheat` (non-proxy only): Enable or disable cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games. Cheat mode is always enabled on the proxy, unless cheat mode is disabled on the entire server.
|
||||
* `$infhp`: Enable or disable infinite HP mode. Applies to only you; does not affect other players. When enabled, one-hit KO attacks will still kill you, but on most versions of the game, the server will automatically revive you if you die. Infinite HP also automatically cures status ailments.
|
||||
* `$inftp`: Enable or disable infinite TP mode. Applies to only you; does not affect other players. Does not work on DCv1 or earlier versions.
|
||||
* `$fastkill`: Enable or disable fast kills. Applies to only you; does not affect other players. When enabled, the server will kill any enemy after you hit it once. Bosses are not affected by fast kills.
|
||||
* `$warpme <floor-id>` (or `$warp <floor-id>`): Warp yourself to the given floor.
|
||||
* `$warpall <floor-id>`: Warp everyone in the game to the given floor. You must be the leader to use this command, unless you're on the proxy.
|
||||
* `$next`: Warp yourself to the next floor.
|
||||
* `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item (e.g. "Hell Saber +5 0/10/25/0/10") or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions.
|
||||
* `$unset <index>` (non-proxy only): In an Episode 3 battle, removes one of your set cards from the field. `<index>` is the index of the set card as it appears on your screen - 1 is the card next to your SC's icon, 2 is the card to the right of 1, etc. This does not cause a Hunters-side SC to lose HP, as they normally do when their items are destroyed.
|
||||
* `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions. Here are some examples to illustrate the syntax (nothing is case-sensitive, and everything except the item name itself is optional):
|
||||
* `$item Saber +5 0/10/25/0/10` (weapon with special, grind and attributes)
|
||||
* `$item ???? Draw Autogun` (untekked weapon with special; can have grind/attributes too, as above)
|
||||
* `$item SEALED J-SWORD K:2000` (weapon with kill count)
|
||||
* `$item ES APHEX ZALURE TWIN +200` (ES weapon must be prefixed with "ES"; name comes before special)
|
||||
* `$item DF FIELD +10DEF +20EVP +4` (armor with DFP bonus, EVP bonus, and slot count)
|
||||
* `$item RED MERGE +10DFP +20EVP` (shield; same as armor except without slot count)
|
||||
* `$item Knight/Power +9` (unit with specific modifier)
|
||||
* `$item Knight/Power++` (unit with normal modifier; ++/-- are +4/-4 and +/- are +2/-2)
|
||||
* `$item LIMITER K:1000` (sealed unit with kill count)
|
||||
* `$item Tapas PB:F,G,M&Y 120% 200IQ 5/195/0/0 green` (mag with PBs, synchro, IO, stats, and color)
|
||||
* `$item Trimate x10` (tool with stack size)
|
||||
* `$item Disk:Reverser` (technique disk without level)
|
||||
* `$item Disk:Razonde Lv.30` (technique disk with level)
|
||||
* `$item 1000 Meseta`
|
||||
* `$unset <index>` (non-proxy only): In an Episode 3 battle, removes one of your set cards from the field. `<index>` is the index of the set card as it appears on your screen - 1 is the card next to your SC's icon, 2 is the card to the right of 1, etc. This does not cause a Hunters-side SC to lose HP, as they normally do when their items are destroyed. You can also destroy the assist card set on yourself with `$unset 0`.
|
||||
* `$dropmode [mode]` (proxy only): Change the way item drops behave in the current game, if you are not on BB. Unlike the game server version of this command, using this on the proxy requires cheats to be enabled. This works by intercepting the drop requests sent to and from the leader. (So, if you are the leader and not using server drop mode on the remote server, it affects the entire game; otherwise, it affects only items generated by your actions.) `mode` can be `none` (no drops), `default` (normal drops), or `proxy` (use newserv's drop tables instead of the remote server's). If `mode` is not given, tells you the current drop mode without changing it.
|
||||
|
||||
* Aesthetic commands
|
||||
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Callable
|
||||
|
||||
|
||||
def filter_directory(dir: str, predicate: Callable[[str], bool]):
|
||||
for filename in os.listdir(dir):
|
||||
if not predicate(filename):
|
||||
path = os.path.join(dir, filename)
|
||||
if os.path.isfile(path):
|
||||
os.remove(path)
|
||||
else:
|
||||
shutil.rmtree(path)
|
||||
|
||||
|
||||
def main():
|
||||
print("Deleting existing release directory")
|
||||
if os.path.exists("release"):
|
||||
shutil.rmtree("release")
|
||||
if os.path.exists("release.zip"):
|
||||
os.remove("release.zip")
|
||||
os.mkdir("release")
|
||||
|
||||
print("Adding executables")
|
||||
shutil.copy("newserv", "release/newserv-macos")
|
||||
shutil.copy("newserv.exe", "release/newserv-windows.exe")
|
||||
shutil.copy("README.md", "release/README.md")
|
||||
|
||||
print("Adding system directory")
|
||||
shutil.copytree("system", "release/system")
|
||||
|
||||
print("Removing instance-based and temporary files")
|
||||
filter_directory(
|
||||
"release/system",
|
||||
lambda filename: (not filename.endswith(".json"))
|
||||
or filename == "config.example.json",
|
||||
)
|
||||
filter_directory(
|
||||
"release/system/ep3", lambda filename: not filename.startswith("cardtex")
|
||||
)
|
||||
filter_directory(
|
||||
"release/system/client-functions",
|
||||
lambda filename: filename not in ("Debug-Private", "FastLoading", "notes.txt"),
|
||||
)
|
||||
filter_directory("release/system/dol", lambda filename: False)
|
||||
filter_directory("release/system/ep3/banners", lambda filename: False)
|
||||
filter_directory("release/system/ep3/battle-records", lambda filename: False)
|
||||
filter_directory("release/system/licenses", lambda filename: False)
|
||||
filter_directory("release/system/players", lambda filename: False)
|
||||
filter_directory(
|
||||
"release/system/quests",
|
||||
lambda filename: filename not in ("private", "includes"),
|
||||
)
|
||||
filter_directory("release/system/teams", lambda filename: filename == "base.json")
|
||||
subprocess.check_call(["find", "release", "-name", ".DS_Store", "-delete"])
|
||||
subprocess.check_call(["find", "release", "-name", "*.WIP-s", "-delete"])
|
||||
|
||||
print("Setting up configuration")
|
||||
os.rename("release/system/config.example.json", "release/system/config.json")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+326
-11
@@ -13,10 +13,12 @@ Version codes (from README.md):
|
||||
1OJF: PSO DC v1 JP
|
||||
1OEF: PSO DC v1 US
|
||||
1OPF: PSO DC v1 EU
|
||||
2OJ4: PSO DC 08/2001 prototype
|
||||
2OJ5: PSO DC 08/2001 prototype
|
||||
2OJF: PSO DC v2 JP
|
||||
2OEF: PSO DC v2 US
|
||||
2OPF: PSO DC v2 EU
|
||||
2OJT: PSO PC Trial Edition
|
||||
2OJW: PSO PC (v2) 04/2002
|
||||
2OJZ: PSO PC (v2) 02/2003
|
||||
3OJT: PSO GC Trial Edition
|
||||
@@ -81,6 +83,21 @@ Disable item equip restrictions ("God of equip")
|
||||
3OP0 => 041052D4 38000005
|
||||
59NL => 005C9F31 E9A7000000
|
||||
|
||||
All items visible in Pioneer 2
|
||||
3OE1 => 04102D88 38600000
|
||||
|
||||
Mags visible in Pioneer 2
|
||||
59NL => 005D8F4B EB04
|
||||
|
||||
Disable pause menu background + offset
|
||||
3OE1 => 0424BD5C 48000370
|
||||
0428735C 4800000C
|
||||
3OE2 => 0424CED8 48000370
|
||||
042887D8 4800000C
|
||||
59NL => 00719B54 9090
|
||||
00733BA7 9090
|
||||
00733A0E 90E9
|
||||
|
||||
All rareable enemies are rare
|
||||
3OE0 => 040AC944 60000000 // Hildeblue
|
||||
040C1B70 60000000 // Rappies
|
||||
@@ -196,6 +213,9 @@ Auto-press A as fast as possible during loading screens
|
||||
3SJT => 040C2C48 60000000
|
||||
3SJ0 => 042F8B74 60000000
|
||||
|
||||
CARD lobby battle tables react immediately
|
||||
3SE0 => 042C04D4 60000000
|
||||
|
||||
Change type of all loading screens
|
||||
Values for X: 0 = lobby/game join, 1 = quest load, 3 = pipe up, 4 = pipe down, anything else = silent black screen
|
||||
3OE1 => 0401CA04 3BE0000X
|
||||
@@ -235,16 +255,6 @@ Unlock all COM decks
|
||||
3SP0 => 042CB414 38600001
|
||||
3SE0 => 042CA908 38600001
|
||||
|
||||
Enable marker color menu in all lobbies
|
||||
3OJ2 => 04138200 3800000E
|
||||
3OJ3 => 04138508 3800000E
|
||||
3OJ4 => 041390AC 3800000E
|
||||
3OJ5 => 041385B0 3800000E
|
||||
3OE0 => 041384BC 3800000E
|
||||
3OE1 => 041384BC 3800000E
|
||||
3OE2 => 041385C0 3800000E
|
||||
3OP0 => 04138840 3800000E
|
||||
|
||||
Enable all lobby counter options in non-CARD lobbies
|
||||
3SE0 => 04096A8C 480000C0
|
||||
04096B4C 38800007
|
||||
@@ -260,6 +270,21 @@ Enable Change Marker option in all lobbies
|
||||
3OE2 => 041385C8 4800004C
|
||||
3OP0 => 04138848 4800004C
|
||||
|
||||
Lobby arrows rotation speed modifier
|
||||
3OE1 => 041C6B64 3804XXXX (default 0800)
|
||||
|
||||
Change lobby arrow colors
|
||||
Note: All values as floats in [0, 1]
|
||||
3OE1 => 04443780 AAAAAAAA (slot 0)
|
||||
04443784 RRRRRRRR (slot 0)
|
||||
04443788 GGGGGGGG (slot 0)
|
||||
0444378C BBBBBBBB (slot 0)
|
||||
04443790 AAAAAAAA (slot 1)
|
||||
04443794 RRRRRRRR (slot 1)
|
||||
04443798 GGGGGGGG (slot 1)
|
||||
0444379C BBBBBBBB (slot 1)
|
||||
...
|
||||
|
||||
Change HUD color mask
|
||||
3SE0 => 0438CA8C 3C00RRGG
|
||||
0438CA90 6000BBAA
|
||||
@@ -270,6 +295,23 @@ Disable lobby event music (but keep the visuals)
|
||||
3SJ0 => 040B7078 38000000
|
||||
3SP0 => 040B74A0 38000000
|
||||
|
||||
Disable rate limit for lobby chair movement
|
||||
3OJ2 => 041C73B0 60000000
|
||||
3OJ3 => 041C786C 60000000
|
||||
3OJ4 => 041C7DA8 60000000
|
||||
3OJ5 => 041C7938 60000000
|
||||
3OE0 => 041C77CC 60000000
|
||||
3OE1 => 041C77CC 60000000
|
||||
3OE2 => 041C799C 60000000
|
||||
3OP0 => 041C7E58 60000000
|
||||
3SJT => 040E290C 60000000
|
||||
3SJ0 => 040DE6C4 60000000
|
||||
3SE0 => 040DE6A8 60000000
|
||||
3SP0 => 040DEAEC 60000000
|
||||
|
||||
Make lobby chairs fast (client-side only)
|
||||
3SE0 => 0457E618 40000000
|
||||
|
||||
Enable Pinz's Shop Super Card Capsule Machine as a fourth option
|
||||
3SE0 => 043101C0 38800004
|
||||
04310238 2C1D0004
|
||||
@@ -316,8 +358,14 @@ Unlock all offline free battle maps
|
||||
This unlocks ALL maps, including a bunch of maps with garbage names that crash if you try to play them
|
||||
3SJT => 042BE538 38600001
|
||||
3SJ0 => 042C9C2C 38600001
|
||||
3SP0 => 042CB50C 38600001
|
||||
3SE0 => 042CAA00 38600001
|
||||
3SP0 => 042CB50C 38600001
|
||||
|
||||
Card auctions accessible with fewer than 4 players
|
||||
3SJT => 042DD618 38600004
|
||||
3SJ0 => 042F4F20 38600004
|
||||
3SE0 => 042F5D88 38600004
|
||||
3SP0 => 042F698C 38600004
|
||||
|
||||
Talk to auction counter offline to get all cards
|
||||
3SE0 => 042F5D18 4BD160E8
|
||||
@@ -530,6 +578,68 @@ Heaven Punisher's special always works
|
||||
3OE2 => 0412AD84 38800001
|
||||
3OP0 => 0412AF5C 38800001
|
||||
|
||||
Fast tekker (skips wind-up jingle)
|
||||
1OJ1 => 8C15B0CA mov r1, 1
|
||||
8C15B0E6 nop
|
||||
1OJ2 => 8C162302 mov r1, 1
|
||||
8C16231E nop
|
||||
1OJ3 => 8C175E66 mov r1, 1
|
||||
8C175E82 nop
|
||||
1OJ4 => 8C1780AE mov r1, 1
|
||||
8C1780CA nop
|
||||
1OJF => 8C17600E mov r1, 1
|
||||
8C17602A nop
|
||||
1OEF => 8C17863E mov r1, 1
|
||||
8C17865A nop
|
||||
1OPF => 8C1783FA mov r1, 1
|
||||
8C178416 nop
|
||||
2OJ5 => 8C19BD4A mov r1, 1
|
||||
8C19BD66 nop
|
||||
2OJF => 8C19ADB6 mov r1, 1
|
||||
8C19ADD2 nop
|
||||
2OEF => 8C19BD4A mov r1, 1
|
||||
8C19BD66 nop
|
||||
2OPF => 8C19B7E2 mov r1, 1
|
||||
8C19B7FE nop
|
||||
2OJW => 005B14A3 mov dword [ebx + 0x150], 1
|
||||
005B14BF jmp +0x0D
|
||||
2OJZ => 005B0193 mov dword [ebx + 0x150], 1
|
||||
005B01AF jmp +0x0D
|
||||
3OJT => 0426FAE8 38000001
|
||||
0426FB10 60000000
|
||||
3OJ2 => 0421F8CC 38000001
|
||||
0421F8F4 60000000
|
||||
3OJ3 => 04220250 38000001
|
||||
04220278 60000000
|
||||
3OJ4 => 04221154 38000001
|
||||
0422117C 60000000
|
||||
3OJ5 => 04220EF0 38000001
|
||||
04220F18 60000000
|
||||
3OE0 => 04220170 38000001
|
||||
04220198 60000000
|
||||
3OE1 => 04220170 38000001
|
||||
04220198 60000000
|
||||
3OE2 => 04221224 38000001
|
||||
0422124C 60000000
|
||||
3OP0 => 04220ABC 38000001
|
||||
04220AE4 60000000
|
||||
4OED => 0023EF3C mov dword [ebp + 0x14C], 1
|
||||
0023EF57 jmp +0x0A
|
||||
4OEU => 0023F0BC mov dword [ebp + 0x14C], 1
|
||||
0023F0D7 jmp +0x0A
|
||||
4OJB => 0023EC5C mov dword [ebp + 0x14C], 1
|
||||
0023EC77 jmp +0x0A
|
||||
4OJD => 0023EEAC mov dword [ebp + 0x14C], 1
|
||||
0023EEC7 jmp +0x0A
|
||||
4OJU => 0023F21C mov dword [ebp + 0x14C], 1
|
||||
0023F237 jmp +0x0A
|
||||
4OPD => 0023EF5C mov dword [ebp + 0x14C], 1
|
||||
0023EF77 jmp +0x0A
|
||||
4OPU => 0023F14C mov dword [ebp + 0x14C], 1
|
||||
0023F167 jmp +0x0A
|
||||
59NL => 006DA113 mov dword [edi + 0x14C], 1
|
||||
006DA130 jmp +0x0B
|
||||
|
||||
Allow loading corrupted save files
|
||||
3OJ2 => 041FC784 38600007
|
||||
041FC788 4E800020
|
||||
@@ -793,3 +903,208 @@ Disable save file signature validation (for moving Xbox saves across consoles)
|
||||
4OEU => 002F22DB 9090
|
||||
4OPD => 002F215B 9090
|
||||
4OPU => 002F234B 9090
|
||||
|
||||
Enable UDP test mode online
|
||||
3OE1 => 041A3D60 38600001
|
||||
|
||||
Main warp door opens in Challenge mode
|
||||
3OE1 => 041820A4 38600001
|
||||
041820A8 4E800020
|
||||
|
||||
Allow arbitrary tech disk levels
|
||||
3OE1 => 0410EBE8 60000000
|
||||
04100D18 60000000
|
||||
041D6C0C 60000000
|
||||
041D6C5C 60000000
|
||||
0422CB50 60000000
|
||||
042CD74C 4E800020
|
||||
|
||||
Change particle colors in quest loading screen
|
||||
3OE1 => 04472C20 AARRGGBB // Default color
|
||||
04472C24 AARRGGBB // Color after 1 A press
|
||||
04472C28 AARRGGBB // Color after 2 A presses
|
||||
04472C2C AARRGGBB // Color after 3 A presses
|
||||
04472C30 AARRGGBB // Color after 4 A presses
|
||||
04472C34 AARRGGBB // Color after 5 A presses
|
||||
|
||||
Floor warp loading screen speed modifier
|
||||
// XXXX = speed; default is 01B4; 0800 = very fast/wobbly; 0020 = very slow
|
||||
3OE1 => 0434A350 3863XXXX
|
||||
|
||||
Slow Gibbles fix
|
||||
3OJ2 => 042D6A48 C022FD98
|
||||
042D6A6C C022FD98
|
||||
3OJ3 => 042D7A00 C022FDA0
|
||||
042D7A24 C022FDA0
|
||||
3OJ4 => 042D8B34 C022FDA0
|
||||
042D8B58 C022FDA0
|
||||
3OJ5 => 042D88E0 C022FDA0
|
||||
042D8904 C022FDA0
|
||||
3OE0 => 042D7428 C022FDA8
|
||||
042D744C C022FDA8
|
||||
3OE1 => 042D746C C022FDA8
|
||||
042D7490 C022FDA8
|
||||
3OE2 => 042D8A94 C022FDA8
|
||||
042D8AB8 C022FDA8
|
||||
3OP0 => 042D8228 C022FDA8
|
||||
042D824C C022FDA8
|
||||
|
||||
Override Challenge mode random enemy location tables limit
|
||||
2OJ5 => 8C2501B2 XXE5 (count as byte)
|
||||
2OJF => 8C24E98E XXE5 (count as byte)
|
||||
2OEF => 8C2501A2 XXE5 (count as byte)
|
||||
2OPF => 8C244C7E XXE5 (count as byte)
|
||||
2OJW => 005AA2FE XXXXXXXX (count * 4 as little-endian dword)
|
||||
005AA30C XXXXXXXX (count as little-endian dword)
|
||||
2OJZ => 005A908E XXXXXXXX (count * 4 as little-endian dword)
|
||||
005A909D XXXXXXXX (count as little-endian dword)
|
||||
3OE0 => 04209448 3880XXXX (count as big-endian word)
|
||||
3OE1 => 04209448 3880XXXX (count as big-endian word)
|
||||
3OE2 => 0420A330 3880XXXX (count as big-endian word)
|
||||
3OJ2 => 04208C4C 3880XXXX (count as big-endian word)
|
||||
3OJ3 => 042094C0 3880XXXX (count as big-endian word)
|
||||
3OJ4 => 0420A5A8 3880XXXX (count as big-endian word)
|
||||
3OJ5 => 04209FFC 3880XXXX (count as big-endian word)
|
||||
3OP0 => 04209D2C 3880XXXX (count as big-endian word)
|
||||
4OJB => 002E527C XXXXXXXX (count as little-endian dword)
|
||||
4OJD => 002E5DFC XXXXXXXX (count as little-endian dword)
|
||||
4OJU => 002E740C XXXXXXXX (count as little-endian dword)
|
||||
4OED => 002E71DC XXXXXXXX (count as little-endian dword)
|
||||
4OEU => 002E742C XXXXXXXX (count as little-endian dword)
|
||||
4OPD => 002E720C XXXXXXXX (count as little-endian dword)
|
||||
4OPU => 002E745C XXXXXXXX (count as little-endian dword)
|
||||
59NL => 0080ECB7 XXXXXXXX (count * 4 as little-endian dword)
|
||||
0080ECD0 XXXXXXXX (count as little-endian dword)
|
||||
|
||||
Disable dust effect in CCA
|
||||
3OJT => 042F4EE8 48000010
|
||||
3OJ2 => 04297ECC 48000010
|
||||
3OJ3 => 04298C94 48000010
|
||||
3OJ4 => 04299DAC 48000010
|
||||
3OJ5 => 04299B60 48000010
|
||||
3OE0 => 042987EC 48000010
|
||||
3OE1 => 04298830 48000010
|
||||
3OE2 => 04299D14 48000010
|
||||
3OP0 => 042994BC 48000010
|
||||
|
||||
Inventory debugging code
|
||||
(makes a copy of player 1's inventory at 8000A04C, updated every frame)
|
||||
3OE2 => 0400A000 9421FFE0 // stwu [r1 - 0x20], r1
|
||||
0400A004 7C0802A6 // mflr r0
|
||||
0400A008 90010024 // stw [r1 + 0x24], r0
|
||||
0400A00C 3C608051 // lis r3, 0x8051
|
||||
0400A010 8063EA10 // lwz r3, [r3 - 0x15F0] // r3 = TObjPlayer_objs[0]
|
||||
0400A014 3C808000 // lis r4, 0x8000
|
||||
0400A018 6084A050 // ori r4, r4, 0xA050
|
||||
0400A01C 9064FFFC // stw [r4 - 4], r3 // 8000A04C = 0 (in case player is null)
|
||||
0400A020 28030000 // cmplwi r3, 0
|
||||
0400A024 41820014 // beq +0x10
|
||||
0400A028 481AE2E9 // bl TObjPlayer_export_inventory // (TObjPlayer_objs[0], 0x8000A050)
|
||||
0400A02C 3C808000 // lis r4, 0x8000
|
||||
0400A030 6084A04C // ori r4, r4, 0xA04C
|
||||
0400A034 90640000 // stw [r4], r3 // 8000A04C = inventory item count
|
||||
0400A038 80010024 // lwz r0, [r1 + 0x24]
|
||||
0400A03C 7C0803A6 // mtlr r0
|
||||
0400A040 38210020 // addi r1, r1, 0x20
|
||||
0400A044 4E800020 // blr
|
||||
041A39B8 4BE66648 // b 8000A000 // main_phase_0E_exec_frame return - chain to hook at 8000A000
|
||||
|
||||
Load qdefault.bin quest script from disk in offline free play
|
||||
(Don't use this on a disc image where qdefault.bin doesn't exist; there is a bug in the quest script environment constructor that will leave the current directory set incorrectly if the file doesn't exist, and the game will softlock)
|
||||
3OE1 => 041A3A30 4BE6656D
|
||||
041A3088 4BE66F1D
|
||||
04009F9C 38600002
|
||||
04009FA0 48000008
|
||||
04009FA4 38600000
|
||||
04009FA8 7C0802A6
|
||||
04009FAC 9421FFE0
|
||||
04009FB0 90010024
|
||||
04009FB4 90610008
|
||||
04009FB8 386001A4
|
||||
04009FBC 4821F581
|
||||
04009FC0 28030000
|
||||
04009FC4 41820018
|
||||
04009FC8 808DBD20
|
||||
04009FCC 3CA08000
|
||||
04009FD0 60A59FF0
|
||||
04009FD4 38C00000
|
||||
04009FD8 481EC171
|
||||
04009FDC 80610008
|
||||
04009FE0 80010024
|
||||
04009FE4 38210020
|
||||
04009FE8 7C0803A6
|
||||
04009FEC 4E800020
|
||||
04009FF0 71646566
|
||||
04009FF4 61756C74
|
||||
04009FF8 2E62696E
|
||||
04009FFC 00000000
|
||||
3OE2 => 041A3B5C 4BE66441
|
||||
041A31B0 4BE66DF5
|
||||
04009F9C 38600002
|
||||
04009FA0 48000008
|
||||
04009FA4 38600000
|
||||
04009FA8 7C0802A6
|
||||
04009FAC 9421FFE0
|
||||
04009FB0 90010024
|
||||
04009FB4 90610008
|
||||
04009FB8 386001A4
|
||||
04009FBC 48220635
|
||||
04009FC0 28030000
|
||||
04009FC4 41820018
|
||||
04009FC8 808DBD40
|
||||
04009FCC 3CA08000
|
||||
04009FD0 60A59FF0
|
||||
04009FD4 38C00000
|
||||
04009FD8 481EC309
|
||||
04009FDC 80610008
|
||||
04009FE0 80010024
|
||||
04009FE4 38210020
|
||||
04009FE8 7C0803A6
|
||||
04009FEC 4E800020
|
||||
04009FF0 71646566
|
||||
04009FF4 61756C74
|
||||
04009FF8 2E62696E
|
||||
04009FFC 00000000
|
||||
|
||||
Enable quest board menu in free play (for use with the above code)
|
||||
3OE0 => 04262B44 38600001
|
||||
3OE1 => 04262B44 38600001
|
||||
3OE2 => 04263F04 38600001
|
||||
3OJ2 => 0426226C 38600001
|
||||
3OJ3 => 04262E44 38600001
|
||||
3OJ4 => 04263EB8 38600001
|
||||
3OP0 => 0426374C 38600001
|
||||
|
||||
All classes' footsteps sound like RAcast's
|
||||
(Change the 2 in 38600002 to 0 for human/Newman, 1 for lighter androids, or 3 if you want to be annoyed)
|
||||
3OE0 => 041B3ED0 38600002
|
||||
041B3ED4 4E800020
|
||||
3OE1 => 041B3ED0 38600002
|
||||
041B3ED4 4E800020
|
||||
3OE2 => 041B4068 38600002
|
||||
041B406C 4E800020
|
||||
3OJ2 => 041B3AE4 38600002
|
||||
041B3AE8 4E800020
|
||||
3OJ3 => 041B3F38 38600002
|
||||
041B3F3C 4E800020
|
||||
3OJ4 => 041B552C 38600002
|
||||
041B5530 4E800020
|
||||
3OJ5 => 041B4004 38600002
|
||||
041B4008 4E800020
|
||||
3OJT => 0420A120 38600002
|
||||
0420A124 4E800020
|
||||
3OP0 => 041B4524 38600002
|
||||
041B4528 4E800020
|
||||
3SE0 => 040D0378 38600002
|
||||
040D037C 4E800020
|
||||
3SJ0 => 040D0394 38600002
|
||||
040D0398 4E800020
|
||||
3SJT => 040D431C 38600002
|
||||
040D4320 4E800020
|
||||
3SP0 => 040D07BC 38600002
|
||||
040D07C0 4E800020
|
||||
|
||||
Rappy size modifier
|
||||
3OE1 => 040C1E24 48000020 // Disable flag check in render
|
||||
045D0718 40800000 // X/Z scale as float (here, 4.0)
|
||||
045D071C 40800000 // Y scale as float (here, 4.0)
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
1OJ2 (11/2000): test1.st-pso.games.sega.net
|
||||
1OJ3 (12/2000): sg107634.csrd.sega.co.jp OR master.pso.dream-key.com
|
||||
1OJ4 (01/2001): master.pso.dream-key.com
|
||||
2OJ5 (08/2001; v2): game01.st-pso.games.sega.net
|
||||
2OJ4 (08/06/2001; v2): game01.st-pso.games.sega.net
|
||||
2OJ5 (08/22/2001; v2): game01.st-pso.games.sega.net
|
||||
|
||||
+972
-975
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,586 @@
|
||||
NOTE: The NNF descriptions are from Kayak's movement data notes: https://qedit.info/index.php?title=Get_movement_data
|
||||
|
||||
|
||||
|
||||
MOVEMENT DATA 00 (BOOTA)
|
||||
MOVEMENT DATA 01 (ZE_BOOTA)
|
||||
MOVEMENT DATA 03 (BA_BOOTA)
|
||||
MOVEMENT DATA 11 (GORAN)
|
||||
MOVEMENT DATA 12 (PYRO_GORAN)
|
||||
MOVEMENT DATA 13 (GORAN_DETONATOR)
|
||||
MOVEMENT DATA 4A (BOOMA, MERILLIA)
|
||||
MOVEMENT DATA 4B (GOBOOMA, MERILTAS)
|
||||
MOVEMENT DATA 4C (GIGOBOOMA)
|
||||
MOVEMENT DATA 4E (EVIL_SHARK, DOLMOLM)
|
||||
MOVEMENT DATA 4F (PAL_SHARK, DOLMDARL)
|
||||
MOVEMENT DATA 50 (GUIL_SHARK)
|
||||
MOVEMENT DATA 52 (DIMENIAN)
|
||||
MOVEMENT DATA 53 (LA_DIMENIAN)
|
||||
MOVEMENT DATA 54 (SO_DIMENIAN)
|
||||
fparam1 = idle move speed (when returning to initial position)
|
||||
fparam2 = idle walking animation speed
|
||||
fparam3 = engaged move speed (when approaching a player)
|
||||
fparam4 = engaged animation speed
|
||||
fparam5 = MERILLIA, MERILTAS; TODO: 3OE1:800D5750; poison cloud damage
|
||||
fparam5 = DOLMOLM, DOLMDARL; TODO: 3OE1:802FFA70; max distance to notice player?; NNF: Possibly frames before getting trapped
|
||||
fparam5 = BOOTA, ZE_BOOTA, BA_BOOTA; TODO: 59NL:005A56B5, 59NL:005A5361
|
||||
fparam5 = GORAN, PYRO_GORAN, GORAN_DETONATOR; TODO: 59NL:005ACDD2
|
||||
fparam6 = MERILLIA, MERILTAS; TODO: 3OE1:800D7074; NNF: run away speed
|
||||
fparam6 = GORAN, PYRO_GORAN, GORAN_DETONATOR; TODO: 59NL:005AD31E, 59NL:005ACC23, 59NL:005ACB4A; length of a vector (speed?)
|
||||
iparam1 = MERILLIA, MERILTAS; low HP threshold percentage (0-100); controls how often it runs away
|
||||
iparam1 = DOLMOLM, DOLMDARL; TODO: 3OE1:802FFFBC; NNF: Angle to use Trap (Cannot exceed Attack data angle)
|
||||
iparam1 = BOOTA, ZE_BOOTA, BA_BOOTA; TODO: 59NL:005A53D7, 59NL:005A531C, 59NL:005A5092 (special case for 01 only apparently?)
|
||||
iparam1 = GORAN, PYRO_GORAN, GORAN_DETONATOR; TODO: 59NL:005AD0CF, 59NL:005ACE95; looks like an angle in degrees (range [0, 359])
|
||||
iparam2 = DOLMOLM, DOLMDARL; TODO: 3OE1:80300154; NNF: Length of time in seconds Dolmolm trap lasts
|
||||
iparam2 = BOOTA, ZE_BOOTA, BA_BOOTA; TODO: 59NL:005A5580
|
||||
iparam2 = GORAN, PYRO_GORAN, GORAN_DETONATOR; TODO: 59NL:005ACD0F
|
||||
|
||||
MOVEMENT DATA 00 (MOTHMANT)
|
||||
fparam1 = speed when low to the ground (chase mode)
|
||||
iparam2 = delay before attack (applies when in chase mode and reached target, or between attacks when near target)
|
||||
|
||||
MOVEMENT DATA 01 (MONEST)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 02 (SAVAGE_WOLF)
|
||||
MOVEMENT DATA 03 (BARBAROUS_WOLF)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 04 (POISON_LILY)
|
||||
MOVEMENT DATA 05 (NAR_LILY)
|
||||
MOVEMENT DATA 25 (DEL_LILY)
|
||||
fparam1 = DEL_LILY; TODO: 3OE1:800C25C8; damage for some kind of attack
|
||||
iparam1 = POISON_LILY, NAR_LILY; Megid level, only used in Ultimate
|
||||
|
||||
MOVEMENT DATA 05 (SAND_RAPPY_CRATER)
|
||||
MOVEMENT DATA 06 (DEL_RAPPY_CRATER)
|
||||
MOVEMENT DATA 17 (SAND_RAPPY_DESERT)
|
||||
MOVEMENT DATA 18 (RAG_RAPPY, DEL_RAPPY_DESERT)
|
||||
MOVEMENT DATA 19 (AL_RAPPY, LOVE_RAPPY, SAINT_RAPPY, EGG_RAPPY, HALLO_RAPPY)
|
||||
fparam1 = hitbox radius
|
||||
fparam2 = TODO: 3OE1:TObjEneLappy_set_params_from_movement_data, 59NL:FUN_00526A7C; NNF: Flinch time (higher number is less flinch time)
|
||||
fparam3 = TODO: 3OE1:TObjEneLappy_set_params_from_movement_data, 59NL:FUN_00526A7C; NNF: Animation speed at which their legs move after getting hit once they fake die (negative values make them run underground, 0 makes it so their legs don't move along and they just slide across the ground lol.)
|
||||
|
||||
MOVEMENT DATA 06 (SINOW_BEAT, SINOW_BERILL)
|
||||
MOVEMENT DATA 10 (SINOW_GOLD, SINOW_SPIGELL)
|
||||
fparam1 = TODO: 3OE1:800E63F0, 3OE1:800F38D8; NNF: Movement speed
|
||||
fparam2 = SINOW_BEAT, SINOW_GOLD; TODO: 3OE1:800E6410; NNF: Clone movement speed (invisible flag must be set to 0 to get clones)
|
||||
fparam3 = TODO: 3OE1:800E5D0C, 3OE1:800F3234; NNF: The speed (and amount) it moves forward right when it is about to attack you
|
||||
fparam4 = TODO: 3OE1:800E7BA0, 3OE1:800E7DA8, 3OE1:800F53E4
|
||||
fparam5 = TODO: 3OE1:800E7BA8, 3OE1:800F53EC
|
||||
fparam6 = SINOW_BERILL, SINOW_SPIGELL; TODO: 3OE1:800F21D4, 3OE1:800F2E84; probability of something (0-1)
|
||||
iparam1 = Shifta/Deband/Resta level
|
||||
iparam2 = TODO: 3OE1:800E5200, 3OE1:800F2B8C
|
||||
iparam3 = TODO: 3OE1:800E5D78, 3OE1:800F32A0; NNF: Amount of time (in frames) that the sinow pauses after it attacks
|
||||
iparam4 = SINOW_BERILL, SINOW_SPIGELL; attack tech level (Rafoie in Ultimate, Gifoie otherwise)
|
||||
|
||||
MOVEMENT DATA 07 (CANADINE)
|
||||
MOVEMENT DATA 08 (CANADINE_RING)
|
||||
MOVEMENT DATA 09 (CANANE)
|
||||
fparam1 = TODO: 3OE1:8009CEF4; NNF: Movement speed of animation perfomed just before melee attack
|
||||
fparam2 = electrical attack damage
|
||||
fparam3 = explosion damage
|
||||
iparam1 = TODO: 3OE1:8009D4AC; NNF: Zonde attack charge time (higher is longer)
|
||||
iparam2 = TODO: 3OE1:8009D508; NNF: Delay after laser targetting ends before shooting Zonde
|
||||
iparam3 = TODO: 3OE1:8009D59C; NNF: Delay after casting Zonde
|
||||
iparam4 = TODO: 3OE1:8009D5B8; NNF: Number of times Zonde is cast before they go to the next cycle
|
||||
iparam5 = TODO: 3OE1:8009C5C8; NNF: stun frames after being hit
|
||||
iparam6 = CANANE; TODO: 3OE1:8009B148; number of out-fighters (see CANADINE description in Map.cc); NNF: How many of the 8 ring Canadines will cast Zonde (numbers greater than 8 are treated as 8). The remaining number out of 8 will perform melee attacks instead. Value of 0 causes FSOD.
|
||||
|
||||
MOVEMENT DATA 07 (GEE)
|
||||
iparam5 = TODO: 3OE1:800C9778; probably same as CANADINE (movement data 07 iparam5)
|
||||
|
||||
MOVEMENT DATA 07 (ZU_CRATER)
|
||||
MOVEMENT DATA 08 (PAZUZU_CRATER)
|
||||
MOVEMENT DATA 1B (ZU_CRATER)
|
||||
MOVEMENT DATA 1C (PAZUZU_CRATER)
|
||||
fparam1 = TODO: 59NL:005B4A3C
|
||||
|
||||
MOVEMENT DATA 08 (PIG_RAY)
|
||||
MOVEMENT DATA 09 (UL_RAY)
|
||||
fparam1 = TODO: 3OE1:803072B0, 3OE1:80307354; speed?
|
||||
iparam1 = TODO: 3OE1:803075FC; frame count for something
|
||||
|
||||
MOVEMENT DATA 09 (ASTARK)
|
||||
fparam1 = TODO: 59NL:005A2B8F
|
||||
fparam2 = TODO: 59NL:005A2E1E
|
||||
fparam3 = TODO: 59NL:005A31D1
|
||||
fparam4 = TODO: 59NL:005A3124
|
||||
fparam5 = TODO: 59NL:005A4992
|
||||
fparam6 = TODO: 59NL:005A2B79
|
||||
iparam1 = TODO: 59NL:005A4947
|
||||
iparam2 = TODO: 59NL:005A499D
|
||||
|
||||
MOVEMENT DATA 0A (CHAOS_SORCERER)
|
||||
iparam1 = attack tech 1 level (Grants in Ultimate, Gizonde in non-Ultimate Ep2, Rafoie in non-Ultimate Ep1)
|
||||
iparam2 = attack teck 2 level (Megid in Ultimate, Gibarta otherwise)
|
||||
iparam3 = Resta level
|
||||
|
||||
MOVEMENT DATA 0B (BEE_R)
|
||||
MOVEMENT DATA 0C (BEE_L)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 0D (SATELLITE_LIZARD_CRATER)
|
||||
MOVEMENT DATA 0E (YOWIE_CRATER)
|
||||
MOVEMENT DATA 1D (SATELLITE_LIZARD_DESERT)
|
||||
MOVEMENT DATA 1E (YOWIE_DESERT)
|
||||
fparam1 = TODO: 59NL:005AEBC5; looks like an angle in degrees (range [0, 359])
|
||||
fparam2 = TODO: 59NL:005AEBEE
|
||||
|
||||
MOVEMENT DATA 0D (DARK_BRINGER)
|
||||
fparam1 = TODO: 3OE1:FUN_80097F98; NNF: charge speed
|
||||
fparam2 = TODO: 3OE1:FUN_800983F8; NNF: movement speed
|
||||
fparam6 = TODO: 3OE1:80097F3C; NNF: Regular attack cooldown. Delay between going red and shooting.
|
||||
iparam2 = TODO: 3OE1:FUN_80097F98; NNF: cooldown time after shooting
|
||||
iparam3 = damage for charge attack; 3OE1:80099128
|
||||
iparam4 = TODO: 3OE1:80097A30; NNF: laser attack damage
|
||||
iparam5 = TODO: 3OE1:FUN_800983F8; NNF: swing attack radius
|
||||
iparam6 = TODO: 3OE1:FUN_800983F8; NNF: charge attack radius (if player is outside this range)
|
||||
|
||||
MOVEMENT DATA 0D (DELBITER)
|
||||
fparam1 = TODO: 3OE1:80302D1C, 3OE1:80302B38, 3OE1:803033C8, 3OE1:8030344C; NNF: Charge speed
|
||||
fparam2 = TODO: 3OE1:80303124; NNF: Walking speed
|
||||
fparam3 = TODO: 3OE1:80304F00
|
||||
fparam4 = TODO: 3OE1:80304F10
|
||||
fparam5 = TODO: 3OE1:80302E34
|
||||
fparam6 = TODO: 3OE1:80302FD8; NNF: Charge radius (how far away you have to be before it charges).
|
||||
iparam1 = TODO: 3OE1:80302A6C
|
||||
iparam2 = TODO: 3OE1:803042F8
|
||||
iparam3 = TODO: 3OE1:80304368; NNF: Charge damage.
|
||||
iparam4 = TODO: 3OE1:80302414; related to TP absorption; NNF: Laser damage.
|
||||
iparam5 = TODO: 3OE1:803030A4; NNF: Radius at which Delbiter attempts foot stomp attack (the range at which that attack can hit you, however, is not modified).
|
||||
iparam6 = TODO: 3OE1:8030267C
|
||||
|
||||
MOVEMENT DATA 0E (DARK_BELRA)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 0F (DE_ROL_LE, BARBA_RAY)
|
||||
fparam1 = DE_ROL_LE; TODO: damage amount; 3OE1:800304A4
|
||||
fparam1 = BARBA_RAY; TODO: 3OE1:802E7980; damage for some attack; NNF: laser damage
|
||||
fparam2 = DE_ROL_LE; TODO: TObjectV8047ec78 which has no constructor, so this is unused?; 3OE1:80038FD8
|
||||
fparam2 = BARBA_RAY; TODO: 3OE1:802EDA38; TBoss7PhotonBullet_update; NNF: missile damage
|
||||
fparam3 = DE_ROL_LE; TODO: TBoss2Mine, appears to be mine explosion damage; 3OE1:800385E4; NNF: Missile damage
|
||||
fparam4 = DE_ROL_LE; TODO: multiplied by a random number in range [-1, 1] and added to pos.x; only happens if param5 passes
|
||||
fparam5 = DE_ROL_LE; TODO: probability of some kind (range [0, 1]); 3OE1:80030C80
|
||||
iparam1 = total HP
|
||||
iparam2 = HP until armor on joints falls off
|
||||
iparam3 = HP until mask falls off
|
||||
iparam4 = DE_ROL_LE; TODO: only used in Ultimate, in other difficulties 180 is used instead
|
||||
iparam5 = DE_ROL_LE; TODO: only used in Ultimate, in other difficulties 120 is used instead
|
||||
|
||||
MOVEMENT DATA 0F (DORPHON)
|
||||
MOVEMENT DATA 10 (DORPHON_ECLAIR)
|
||||
fparam1 = TODO: 59NL:005A832F, 59NL:005A8364, 59NL:005A8388, 59NL:005A8A9A, 59NL:005A9643, 59NL:005A96E5
|
||||
fparam2 = TODO: 59NL:005A8EC2, 59NL:005A903D
|
||||
fparam3 = TODO: 59NL:FUN_005A9ADC; minimum 0.1
|
||||
fparam4 = TODO: 59NL:FUN_005A9ADC; minimum 0.1
|
||||
fparam5 = TODO: 59NL:005A85AB
|
||||
fparam6 = TODO: 59NL:005A8F2D
|
||||
iparam1 = TODO: 59NL:005A8082
|
||||
iparam2 = TODO: 59NL:005A89C6 and many others
|
||||
iparam3 = TODO: 59NL:005A8477 and many others
|
||||
iparam4 = TODO: 59NL:005A79E6; looks like same as for DELBITER
|
||||
iparam5 = TODO: 59NL:005A8E4D
|
||||
iparam6 = TODO: 59NL:005A71DA; multiplied by 30
|
||||
|
||||
MOVEMENT DATA 11 (DRAGON, GOL_DRAGON)
|
||||
fparam1 = DRAGON; TODO: TBoss1DragonEffBreath
|
||||
fparam1 = GOL_DRAGON; TODO: 3OE1:802F98EC; damage for some attack
|
||||
fparam2 = DRAGON; TODO: TObjBoss1Crater_update, multiplied by 0.666 internally; TBoss1Dragon @ 3OE1:800276E0
|
||||
fparam2 = GOL_DRAGON; TODO: 3OE1:802F987C; damage for some attack
|
||||
fparam3 = DRAGON; TODO: 3OE1:8002787C
|
||||
fparam3 = GOL_DRAGON; TODO: 3OE1:802F9810; damage for some attack
|
||||
fparam4 = DRAGON; TODO: hitbox radius for something
|
||||
fparam4 = GOL_DRAGON; TODO: 3OE1:802F9DBC; range for some attack
|
||||
fparam5 = DRAGON; TODO: only used in Ultimate, in other difficulties 0.8 is used instead
|
||||
fparam5 = GOL_DRAGON; TODO: 3OE1:802F2FDC, 3OE1:802F38A8, 3OE1:802F3AFC, 3OE1:802F8800
|
||||
fparam6 = DRAGON; TODO: only used in Ultimate, in other difficulties 2.0 is used instead
|
||||
fparam6 = GOL_DRAGON; TODO: 3OE1:802F7BBC, 3OE1:802F7C34
|
||||
iparam1 = TODO: 3OE1:TBoss8Dragon_v58; damage amount for 1 hitbox
|
||||
iparam2 = TODO: 3OE1:TBoss8Dragon_v58; damage amount for 2 hitboxes
|
||||
iparam3 = TODO: 3OE1:TBoss8Dragon_v58; damage amount for 4 hitboxes
|
||||
iparam4 = GOL_DRAGON; clone HP
|
||||
iparam5 = GOL_DRAGON; TODO: 3OE1:802F32C8; which clone to create? (should be in range [0, 5])
|
||||
|
||||
MOVEMENT DATA 12 (GOL_DRAGON)
|
||||
fparam1 = TODO: 3OE1:FUN_802FC22C
|
||||
fparam2 = TODO: 3OE1:FUN_802FC22C
|
||||
fparam3 = TODO: 3OE1:FUN_802FC22C
|
||||
fparam4 = TODO: 3OE1:FUN_802FC22C
|
||||
fparam5 = TODO: 3OE1:FUN_802FC22C; same function as fparam1 but used when no clones exist?
|
||||
fparam6 = TODO: 3OE1:FUN_802FC22C; same function as fparam2 but used when no clones exist?
|
||||
|
||||
MOVEMENT DATA 13 (GOL_DRAGON)
|
||||
fparam1 = TODO: 3OE1:FUN_802FC22C; same function as movement data 12 fparam3 but used when no clones exist?
|
||||
fparam2 = TODO: 3OE1:FUN_802FC22C; same function as movement data 12 fparam4 but used when no clones exist?
|
||||
fparam3 = TODO: 3OE1:802FBDBC; HP for phase 2 to begin?
|
||||
fparam4 = TODO: 3OE1:802F6F24; scaling factor for a vector (speed/range?)
|
||||
|
||||
MOVEMENT DATA 19 (MERISSA_A)
|
||||
MOVEMENT DATA 1A (MERISSA_AA)
|
||||
fparam1 = TODO: 59NL:005B70AC
|
||||
fparam2 = TODO: 59NL:005B70AC
|
||||
fparam3 = TODO: 59NL:005B70AC
|
||||
fparam4 = TODO: 59NL:005B5750, 59NL:005B6101
|
||||
iparam1 = TODO: 59NL:005B56F8, 59NL:005B61DE; looks like an angle in degrees (range [0, 359])
|
||||
iparam2 = TODO: 59NL:005B5824; looks like an angle in degrees (range [0, 359])
|
||||
|
||||
MOVEMENT DATA 1A (NANO_DRAGON)
|
||||
fparam1 = horizontal flight speed
|
||||
fparam2 = straight laser speed
|
||||
fparam3 = homing laser speed (if set too low, it will go backwards)
|
||||
fparam4 = TODO: 3OE1:800D9C70; NNF: Homing laser projectile count (projectile number = number given).
|
||||
fparam5 = TODO: 3OE1:800D9C70; NNF: Homing laser arc.
|
||||
iparam1 = straight laser damage
|
||||
iparam2 = homing laser damage
|
||||
|
||||
MOVEMENT DATA 1A (GI_GUE)
|
||||
fparam1 = TODO: 3OE1:802CA8F4, 3OE1:802CAA04; looks like a scape factor; NNF: Speed when flying away.
|
||||
fparam2 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC; NNF: missile speed
|
||||
fparam3 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC; NNF: confuse projectile speed
|
||||
fparam4 = TODO: 3OE1:802CCA18
|
||||
fparam5 = TODO: 3OE1:802CC640
|
||||
fparam6 = TODO: 3OE1:802CA274; probability in range [0, 1]
|
||||
iparam1 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC; minimum value 40; NNF: Rafoie bomb attack damage
|
||||
iparam2 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC; NNF: Confusion projectile damage (affected by EFR).
|
||||
iparam3 = Jellen/Zalure level
|
||||
iparam4 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC
|
||||
iparam5 = TODO: 3OE1:TObjEneMe1GiGue_FUN_802C98FC; minimum value 20 in one scenario, 40 in another
|
||||
|
||||
MOVEMENT DATA 1B (DUBCHIC)
|
||||
MOVEMENT DATA 1C (GILLCHIC)
|
||||
fparam1 = TODO: 3OE1:FUN_800A89D4; NNF: Punch speed. Higher values means faster punches.
|
||||
fparam2 = punch attack range when not damaged
|
||||
fparam3 = TODO: 3OE1:800A8B64, 3OE1:800A9E98; only used when damaged, values when not damaged are 0.37037036 for DUBCHIC, 0.57037038 for GILLCHIC (unused since GILLCHIC dies instead of being damaged)
|
||||
fparam4 = TODO: 3OE1:FUN_800A89D4
|
||||
fparam5 = TODO: 3OE1:FUN_800A89D4; NNF: Punch speed and movement speed when damaged
|
||||
fparam6 = punch attack range when damaged
|
||||
iparam1 = number of frames after kill before revive sequence starts (Dubchic only)
|
||||
iparam2 = TODO: 3OE1:800A8F9C; NNF: Laser charge time
|
||||
iparam3 = TODO: 3OE1:800A9B40; NNF: Number of invicibility frames after knockdown
|
||||
iparam4 = laser damage
|
||||
|
||||
MOVEMENT DATA 1D (GARANZ)
|
||||
fparam1 = TODO: 3OE1:800D320C; NNF: Distance travelled every movement phase. Speed is unaffected, so it can take a long time before it stops to shoot.
|
||||
fparam2 = TODO: 3OE1:TObjEneGyaranzo_set_movement_params; NNF: Movement speed. This not only makes the Garanz faster, but ends the movement phase sooner, so it gets around to shooting missiles faster too. Doesn't work well without a value in fparam1.
|
||||
fparam3 = TODO: 3OE1:TObjEneGyaranzo_set_movement_params; NNF: TODO
|
||||
fparam4 = missile speed
|
||||
fparam5 = TODO: 3OE1:TObjEneGyaranzo_set_movement_params; NNF: Missile launch arc. Defines how tight the downward curve of the missile (once launched) towards the player is. Set to 0, missiles travel straight into the ceiling and cannot hit the player.
|
||||
iparam1 = TODO: 3OE1:800D2C4C; NNF: Number of frames waited after shooting before commencing movement again. Garanz does have a lower limit and will not wait 0 frames before starting again.
|
||||
iparam2 = TODO: 3OE1:800D2254; NNF: Missile launch cooldown
|
||||
iparam3 = TODO: 3OE1:800D46A8; missile damage
|
||||
iparam4 = TODO: 3OE1:800D40FC; NNF: Mine Damage
|
||||
|
||||
MOVEMENT DATA 1E (DARK_GUNNER)
|
||||
fparam1 = TODO: 3OE1:800A0F44, 3OE1:800A11D0
|
||||
fparam2 = TODO: 3OE1:800A24F8
|
||||
fparam3 = TODO: 3OE1:800A1C4C; seems to be a distance limit / radius of some sort
|
||||
fparam4 = TODO: 3OE1:800A1104; NNF: laser speed
|
||||
iparam1 = charge time after windup sound and before laser shot
|
||||
iparam2 = TODO: 3OE1:800A12A4; NNF: Length of time vulnerability remains after being damaged (lower=shorter)
|
||||
iparam3 = TODO: 3OE1:800A3190; NNF: Duration of invincibility (close to 0 will be no invincibility).
|
||||
iparam4 = laser shot damage
|
||||
|
||||
MOVEMENT DATA 1E (GAL_GRYPHON)
|
||||
fparam1 = TODO: 3OE1:80065DEC; NNF: Y Value Camera adjustment when Gal lands
|
||||
fparam2 = TODO: 3OE1:80065DEC; NNF: X Value Camera adjustment when Gal lands
|
||||
fparam3 = TODO: 3OE1:80065DEC; NNF: Y Value Camera adjustment when Gal lands (cam location)
|
||||
fparam4 = TODO: 3OE1:80065DEC; NNF: Adjusts Camera near or far to player
|
||||
fparam5 = TODO: 3OE1:80065DEC; same as fparam1 but for a different situation (A); NNF: Lowers/Raises the Camera when Gal is flying
|
||||
fparam6 = TODO: 3OE1:80065DEC; same as fparam2 but for a different situation (A)
|
||||
|
||||
MOVEMENT DATA 1F (BULCLAW)
|
||||
iparam1 = TODO: 3OE1:8008F8C8; percentage (0-100) of max HP; NNF: % chance it does it's suicide attack once split into a Bulk, you need to attack it once
|
||||
|
||||
MOVEMENT DATA 1F (GAL_GRYPHON)
|
||||
fparam1 = TODO: 3OE1:80065DEC; same as data 1E fparam3 but for a different situation (A); NNF: (BULCLAW) Aggro Range?
|
||||
fparam2 = TODO: 3OE1:80065DEC; same as data 1E fparam4 but for a different situation (A)
|
||||
fparam3 = TODO: 3OE1:80065DEC; same as data 1E fparam1 but for a different situation (B)
|
||||
fparam4 = TODO: 3OE1:80065DEC; same as data 1E fparam2 but for a different situation (B)
|
||||
fparam5 = TODO: 3OE1:80065DEC; same as data 1E fparam3 but for a different situation (B)
|
||||
fparam6 = TODO: 3OE1:80065DEC; same as data 1E fparam4 but for a different situation (B)
|
||||
|
||||
MOVEMENT DATA 1F (GIRTABLULU)
|
||||
fparam1 = TODO: 59NL:005ABDBD
|
||||
fparam2 = TODO: 59NL:005ABDB1
|
||||
fparam4 = TODO: 59NL:005ABD3C
|
||||
fparam5 = TODO: 59NL:005ABD45
|
||||
fparam6 = TODO: 59NL:005ABD08; looks like an angle in degrees (range [0, 359])
|
||||
iparam1 = TODO: 59NL:005AAB66, 59NL:005AAD18
|
||||
iparam3 = TODO: 59NL:005AA9FA
|
||||
iparam4 = TODO: 59NL:005AA85B
|
||||
iparam5 = TODO: 59NL:005AAF20; length of time in frames?
|
||||
iparam6 = TODO: 59NL:005AA5FD
|
||||
|
||||
MOVEMENT DATA 20 (BULCLAW)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 20 (GAL_GRYPHON)
|
||||
fparam1 = TODO: 3OE1:FUN_80064064; damage scaling factor for some attack (TBoss5GryphonSnarl)
|
||||
fparam2 = TODO: 3OE1:80064130; damage amount for shock wave attack (TBoss5GryphonShockWave)
|
||||
fparam3 = TODO: 3OE1:80064130; damage amount for tornado attack (TBoss5GryphonTornado)
|
||||
fparam4 = TODO: 3OE1:80064044; damage amount for some attack
|
||||
fparam5 = TODO: 3OE1:8006475C; hitbox radius for some attack?
|
||||
iparam1 = TODO: 3OE1:TBoss5Gryphon_V58; damage amount for 1 hitbox
|
||||
iparam2 = TODO: 3OE1:TBoss5Gryphon_V58; damage amount for 4 hitboxes
|
||||
iparam3 = TODO: 3OE1:TBoss5Gryphon_V58; damage amount for 1 hitbox
|
||||
iparam4 = TODO: 3OE1:TBoss5Gryphon_V58; damage amount for 4 hitboxes
|
||||
iparam5 = TODO: 3OE1:TBoss5Gryphon_FUN_8005F0F0, 3OE1:800609D0
|
||||
|
||||
MOVEMENT DATA 20 (SAINT_MILLION_1)
|
||||
MOVEMENT DATA 22 (SAINT_MILLION_2)
|
||||
MOVEMENT DATA 24 (SHAMBERTIN_1)
|
||||
MOVEMENT DATA 26 (SHAMBERTIN_2)
|
||||
MOVEMENT DATA 28 (KONDRIEU_1)
|
||||
MOVEMENT DATA 2A (KONDRIEU_2)
|
||||
iparam1 = TODO: 59NL:00768990, 59NL:00768A84
|
||||
iparam2 = TODO: 59NL:00768990, 59NL:00768A84
|
||||
iparam3 = TODO: 59NL:00768990, 59NL:00768A84
|
||||
iparam4 = TODO: 59NL:00768990, 59NL:00768A84
|
||||
iparam5 = TODO: 59NL:00768990, 59NL:00768A84
|
||||
|
||||
MOVEMENT DATA 21 (SAINT_MILION_SPINNER, 0/4/8/12)
|
||||
MOVEMENT DATA 23 (SAINT_MILION_SPINNER, other indexes)
|
||||
MOVEMENT DATA 25 (SHAMBERTIN_SPINNER, 0/4/8/12)
|
||||
MOVEMENT DATA 27 (SHAMBERTIN_SPINNER, other indexes)
|
||||
MOVEMENT DATA 29 (KONDRIEU_SPINNER, 0/4/8/12)
|
||||
MOVEMENT DATA 2B (KONDRIEU_SPINNER, other indexes)
|
||||
iparam1 = TODO: 59NL:0076D40D
|
||||
|
||||
MOVEMENT DATA 21 (VOL_OPT_1)
|
||||
iparam1 = speed of moving around in the screens
|
||||
|
||||
MOVEMENT DATA 22 (VOL_OPT_1)
|
||||
iparam1 = damage for electrical attack
|
||||
|
||||
MOVEMENT DATA 23 (VOL_OPT_1)
|
||||
iparam1 = large monitors' HP
|
||||
iparam2 = small monitors' HP
|
||||
|
||||
MOVEMENT DATA 23 (EPSILON)
|
||||
fparam2 = TODO: 3OE1:8035FDB4; scale factor for vector; NNF: Laser tracking speed.
|
||||
fparam3 = TODO: 3OE1:8035FF08; NNF: Rafoie damage (based on MST).
|
||||
iparam1 = TODO: 3OE1:8035FD60; NNF: Controls how long the laser tracks players before casting Rafoie (number of Rafoies shot is tied to this - shorter tracking time means more Rafoies).
|
||||
iparam2 = TODO: 3OE1:8035FE40; NNF: Delay between when Rafoie stops and next laser begins.
|
||||
iparam3 = TODO: 3OE1:8035E44C, 3OE1:803608C0; NNF: Cooldown on Epsigard tech activation.
|
||||
iparam4 = TODO: 3OE1:8035F850; NNF: Epsigard attack radius.
|
||||
|
||||
MOVEMENT DATA 24 (VOL_OPT)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 24 (EPSIGARD)
|
||||
fparam1 = TODO: 3OE1:8035CB58, 3OE1:8035CD1C, 3OE1:8035D3B4; NNF: Epsigard circle radius.
|
||||
fparam2 = TODO: 3OE1:8035CD20; NNF: Speed at which Epsigards eject from Epsilon. Epsigards always eject for a second, so fast eject speeds will project them far. They will then spin come back in to fparam1 radius.
|
||||
fparam3 = TODO: 3OE1:8035CB50, 3OE1:8035CBFC; NNF: Epsigard rotation speed.
|
||||
fparam4 = TODO: 3OE1:8035D0CC; NNF: Damage dealt per Epsigard hit.
|
||||
iparam1 = TODO: 3OE1:8035CF28; NNF: Seems to affect Epsigard damage radius. At 120, can't get hit from the front, can only gt hit from a specific position from the back and to the side.
|
||||
|
||||
MOVEMENT DATA 25 (VOL_OPT_2)
|
||||
fparam1 = TODO: specifies length of a vector; NNF: missile speed; 3OE1:80049CB0
|
||||
fparam2 = TODO: specifies length of a vector; 3OE1:80049C94
|
||||
fparam3 = TODO: NNF: knockback distance when hit by pillar; player gets rotated in a random direction, and then moved backwards from that direction
|
||||
fparam4 = TODO: 3OE1:80049FE0; NNF: Homing pillar stomp: Affects cooldown of third pillar ('fast' pillar variants only).
|
||||
fparam5 = TODO: add param for random generation for pillar stomp; NNF: Homing pillar stomp: Affects cooldown of second pillar ('fast' pillar variants only).
|
||||
fparam6 = TODO: mult param for random generation for pillar stomp; final value is (random(0, 1) * fparam5) + fparam4; 3 values generated in total; NNF: Homing pillar stomp: Affects cooldown of first pillar ('fast' pillar variants only).
|
||||
iparam1 = TODO: NNF: missile damage
|
||||
iparam2 = TODO: NNF: pillar damage
|
||||
iparam3 = TODO: NNF: trap laser damage
|
||||
iparam4 = HP recovery amount * 5 (so e.g. 2500 here means 500HP)
|
||||
iparam5 = TODO: NNF: Charge time of trap laser attack; value used is max(10, iparam5 + 120); but used in multiple places! which is which? 3OE1:800490D0 3OE1:8004661C
|
||||
iparam6 = TODO: related to TObjVoloptPillar; 3OE1:80044ACC, 3OE1:80047110, 3OE1:8004A24C; NNF: Homing pillar stomp: Cooldown for each pillar drop. Longer is higher.
|
||||
|
||||
MOVEMENT DATA 26 (VOL_OPT_2)
|
||||
fparam1 = TODO: specifies length of a vector; 3OE1:80049778, 3OE1:800499E8; NNF: Ball speed for laser floor trap
|
||||
fparam2 = TODO: specifies length of a vector; 3OE1:8004975C
|
||||
iparam1 = TODO: looks like lifetime in frames for a subordinate; 3OE1:80049A14; NNF: Ball chase duration
|
||||
iparam2 = TODO: 3OE1:8004490C; looks like an angular velocity?; NNF: Amount of wait time taken for rotating pillars to first attack
|
||||
|
||||
MOVEMENT DATA 26 (ILL_GILL)
|
||||
fparam1 = TODO: 3OE1:803642E8, 3OE1:80363DBC, 3OE1:80363FCC; NNF: Affects charge speed and cooldown time.
|
||||
fparam2 = TODO: 3OE1:80364F3C; NNF: Scythe attack speed.
|
||||
iparam1 = TODO: 3OE1:80365324, 3OE1:803652CC; weapon special amount; NNF: Seems to affect how much damage the lightning scythe attack does, and how effective the megid scythe attack is (lower is less effective)
|
||||
iparam2 = TODO: 3OE1:8036537C; weapon special amount; NNF: Seems to affect how much damage the lightning scythe attack does, and how effective the megid scythe attack is (lower is less effective)
|
||||
|
||||
MOVEMENT DATA 27 (VOL_OPT; used in Vol Opt phase 1?)
|
||||
MOVEMENT DATA 28 (VOL_OPT; used when no player is caught by the Vol Opt cage)
|
||||
MOVEMENT DATA 29 (VOL_OPT; used when any player is caught by the Vol Opt cage)
|
||||
fparam1 = TODO: param to some camera logic
|
||||
fparam2 = TODO: param to some camera logic
|
||||
fparam3 = TODO: param to some camera logic
|
||||
fparam4 = TODO: param to some camera logic
|
||||
iparam1 = TODO: entire movement data is unused if this is zero; 3OE1:TBoss3Volopt_FUN_8003EB6C
|
||||
|
||||
MOVEMENT DATA 2A (VOL_OPT_2)
|
||||
iparam1 = TODO: only has effect if nonzero; 3OE1:80048074
|
||||
|
||||
MOVEMENT DATA 2B (OLGA_FLOW_1)
|
||||
fparam1 = TODO: 3OE1:802B6190, 3OE1:803547F4; must be >0, default 20; NNF: sword damage
|
||||
fparam2 = TODO: 3OE1:80320F84; NNF: Olga Flow 1 shot (ball) damage
|
||||
fparam3 = TODO: 3OE1:802B5DD0; must be >0, default 20; NNF: tail swipe damage
|
||||
fparam4 = TODO: 3OE1:802B5980; must be >0, default 20; NNF: shot (beam) damage
|
||||
fparam5 = TODO: 3OE1:802B5668; must be >0, default 20; NNF: gravity trap attack damage
|
||||
fparam6 = TODO: 3OE1:802B2620; must be >0, default 7; NNF: delay between attacks (lower is faster)
|
||||
iparam1 = TODO: 3OE1:802B4970; looks like damage threshold; must be >0, default 200; NNF: Docile Mode HP Threshold
|
||||
iparam2 = TODO: 3OE1:802B4A50; looks like damage threshold; must be >0, default 200; NNF: Sky/Floor Sword HP to trigger
|
||||
iparam3 = TODO: 3OE1:802B49C0; must be >0, default 200; NNF: Sky/Floor Sword HP to cancel
|
||||
iparam4 = TODO: 3OE1:802B4924; must be >0, default 200; NNF: Gravity Trap Attack HP Threshold
|
||||
iparam5 = TODO: 3OE1:802B694C; seems to not be read - missing label?; must be >0, default 90; NNF: Shot charge-up duration (lower is shorter)
|
||||
iparam6 = TODO: 3OE1:TBoss6Type1_FUN_802B1CA8; must be >0, default 180; NNF: Movement speed and duration during charge-up shot (lower is faster/shorter)
|
||||
|
||||
MOVEMENT DATA 2C (OLGA_FLOW_2)
|
||||
fparam1 = TODO: 3OE1:80354FBC; NNF: Olga Flow 2 sword damage (lower is less)
|
||||
fparam2 = TODO: 3OE1:802BB218; must be >0, default is 20; NNF: Foot damage
|
||||
fparam5 = TODO: 3OE1:802BB218; must be >0, default is 20; NNF: Wrong attribute damage dealt during soul steal (physical - lower is less)
|
||||
fparam3 = TODO: 3OE1:80354FEC, 3OE1:8035BF80; NNF: Olga Flow 2 Divine Punishment damage (lower is less)
|
||||
fparam4 = rock damage; must be > 0; default 20
|
||||
fparam6 = TODO: 3OE1:802BB218; must be >0, default is 60; NNF: Rock fall duration during soul steal (lower is less)
|
||||
iparam1 = TODO: 3OE1:802BB218; must be >0, default is 200; NNF: Amount of damage to trigger Divine Punishment
|
||||
iparam2 = TODO: 3OE1:802BB218; must be >0, default is 200; NNF: Amount of damage it takes to go into soul steal state
|
||||
iparam3 = TODO: 3OE1:802BB218; must be >0, default is 200; NNF: Amount of damage to knock Olga Flow out of soul steal state
|
||||
iparam4 = TODO: 3OE1:802BB218; must be >0, default is 60; NNF: Delay between attacks (lower is faster)
|
||||
iparam5 = TODO: 3OE1:802BB218; must be in range [0, 100] with iparam5 + iparam6 <= 100, default is 25, used as a probability along with iparam6; NNF: Form 1's Total HP% Trigger to halve Attack delays
|
||||
iparam6 = TODO: 3OE1:802BB218; must be in range [0, 100] with iparam5 + iparam6 <= 100, default is 10, used as a probability along with iparam5
|
||||
|
||||
MOVEMENT DATA 2D (OLGA_FLOW_1, OLGA_FLOW_2)
|
||||
fparam1 = OLGA_FLOW_1; TODO: 3OE1:80323128; TBoss6Mine; default 20; NNF: Trap damage Form 1
|
||||
fparam2 = OLGA_FLOW_2; TODO: 3OE1:8036773C; TBoss6MagMine; must be >0, default 20; NNF: Trap damage Form 2
|
||||
fparam3 = OLGA_FLOW_2; TODO: 3OE1:8036778C; TBoss6MagMine; must be in range [0, 100], default 0
|
||||
|
||||
MOVEMENT DATA 2E (OLGA_FLOW_2)
|
||||
fparam1 = TODO: 3OE1:8032EE24; TBoss6Mag; NNF: Amount of time Gael/Giel stays dead (lower is shorter)
|
||||
fparam2 = TODO: 3OE1:8032EE74; TBoss6Mag; NNF: Gael/Giel Chase speed during Divine Punishment
|
||||
fparam3 = TODO: 3OE1:802BB218; must be >0, default 1; used instead of movement data 2F fparam1 if a certain flag is set; NNF: Olga Flow's normal movement speed after some threshold
|
||||
fparam4 = TODO: 3OE1:802BB218; must be >0, default 1; used instead of movement data 2F fparam2 if a certain flag is set; NNF: Olga Flow's movement speed during soul steal after some threshold
|
||||
|
||||
MOVEMENT DATA 2F (OLGA_FLOW_1, OLGA_FLOW_2)
|
||||
fparam1 = OLGA_FLOW_2; TODO: 3OE1:802BB218; must be >0, default 1
|
||||
fparam2 = OLGA_FLOW_2; TODO: 3OE1:802BB218; must be >0, default 1
|
||||
fparam3 = OLGA_FLOW_2; TODO: 3OE1:802BB218, 3OE1:8035BFB0; must be >0, default 1; damage reduction for movement data 2C fparam2?, only applies if a certain flag is set
|
||||
fparam4 = OLGA_FLOW_2; TODO: 3OE1:802BB218; must be >0, default 120; looks like duration for something
|
||||
fparam5 = OLGA_FLOW_1; TODO: 3OE1:80320FB4; also related to shot/ball attack
|
||||
fparam6 = OLGA_FLOW_1; TODO: 3OE1:802B694C; must be >0, default 7; same as movement data 2B fparam6 but used when a certain flag is enabled
|
||||
|
||||
MOVEMENT DATA 30 (POFUILLY_SLIME)
|
||||
MOVEMENT DATA 34 (POUILLY_SLIME)
|
||||
fparam1 = spit attack damage * 5 (so e.g. 1000 here means 200 damange)
|
||||
|
||||
MOVEMENT DATA 30 (DELDEPTH)
|
||||
fparam1 = TODO: 3OE1:80312E04; NNF: Movement speed (Disk form).
|
||||
fparam2 = TODO: 3OE1:80312E1C; NNF: Distance travelled per movement (Disk form).
|
||||
iparam1 = attack tech level (Megid in Ultimate; Barta in other difficulties); also bomb power? (TODO: 3OE1:80312490)
|
||||
iparam2 = TODO: 3OE1:80312AE0; NNF: Rotation speed (Unfolded form) - lower is slower.
|
||||
|
||||
MOVEMENT DATA 31 (PAN_ARMS)
|
||||
fparam1 = TODO: 3OE1:800DF31C
|
||||
fparam2 = TODO: 3OE1:800E36DC; NNF: Blue laser damage
|
||||
fparam3 = TODO: 3OE1:800E36DC; NNF: Red laser damage
|
||||
iparam1 = TODO: 3OE1:800DF32C; value is max(iparam1, 5); NNF: spawn radius
|
||||
iparam2 = TODO: 3OE1:800DF350; value is max(iparam2, 0); NNF: spawn speed in frames
|
||||
|
||||
MOVEMENT DATA 32 (HIDOOM)
|
||||
MOVEMENT DATA 33 (MIGIUM)
|
||||
fparam1 = TODO: 3OE1:800E2640
|
||||
fparam2 = TODO: 3OE1:800E2650; NNF: stab damage
|
||||
fparam3 = MIGIUM; TODO: 3OE1:800E26AC
|
||||
iparam1 = MIGIUM; Resta level, must be in range [0, 14]; NNF: Jellen level
|
||||
iparam2 = MIGIUM; Jellen level, must be in range [0, 14]; NNF: Zalure level
|
||||
iparam3 = MIGIUM; Zalure level, must be in range [0, 14]; NNF: Resta level
|
||||
|
||||
MOVEMENT DATA 35 (DARVANT)
|
||||
fparam1 = TODO: must be in range [0.33333334, 5.833333]; 3OE1:8005D5E0; NNF: Attack speed
|
||||
iparam1 = number of Darvants that must be killed before phase ends (actual value is player count * iparam1); must be in range [1, 19]
|
||||
|
||||
MOVEMENT DATA 36 (DARK_FALZ_1)
|
||||
fparam1 = NNF: movement speed; must be in range [1, 60]; used as reciprocal (see 3OE1:80052F60) so lower is faster
|
||||
iparam1 = Rafoie level, expected to be in range [0, 14]
|
||||
iparam2 = Rabarta level, expected to be in range [0, 14]
|
||||
iparam3 = TODO: 3OE1:FUN_80054DE0; NNF: Dark Falz 1 Divine Punishment strength (Also based on MST)
|
||||
|
||||
MOVEMENT DATA 37 (DARK_FALZ_2)
|
||||
fparam1 = TODO: 3OE1:80057BE4; value used is clamp(floor(fparam1), 1, 25) * 75 - 7; appears angle-related; 3OE1:8005653C; NNF: Movement speed (backwards, lower is faster).
|
||||
iparam1 = TODO: must be in range [1, 4], chooses between 4 different actions in a certain situation, named MD_STOP1 through MD_STOP4; 3OE1:80056358
|
||||
iparam2 = TODO: Resta level; 3OE1:80056994
|
||||
|
||||
MOVEMENT DATA 38 (DARK_FALZ_3)
|
||||
fparam1 = TODO: 3OE1:80050CA4
|
||||
iparam1 = Grants level
|
||||
iparam2 = Megid level
|
||||
iparam3 = number of pairs of homing attacks (TObjDFHorming) to launch at once; must be in range [1, 8]
|
||||
iparam4 = TODO: 3OE1:8005B14C; NNF: HP threshold to soul steal
|
||||
iparam5 = TODO: 3OE1:80050C94; NNF: Ball attack damage. (with 3000/10 MST, does 700 Damage)
|
||||
|
||||
MOVEMENT DATA 39 (DARVANT, DARK_FALZ_1)
|
||||
fparam1 = DARVANT; TODO: must be in range [0.33333334, 10.208332]; 3OE1:8005D618; NNF: Attack speed
|
||||
iparam1 = DARK_FALZ_1; TODO: number of Darvants to spawn at a time?; clamped to [1, 6]; 3OE1:80054CF0
|
||||
|
||||
MOVEMENT DATA 3A (MERICAROL)
|
||||
MOVEMENT DATA 45 (MERIKLE)
|
||||
MOVEMENT DATA 46 (MERICUS)
|
||||
fparam1 = TODO: 3OE1:802CE110; NNF: rush damage
|
||||
fparam2 = poison cloud damage
|
||||
fparam3 = TODO: 3OE1:802CEAA8; NNF: Spit 'attack capability'. Set to 1, attack does nothing and does not register as a hit.
|
||||
fparam4 = TODO: 3OE1:802CEAB0; NNF: Projectile speed; also affects the cooldown time between each shot.
|
||||
fparam5 = poison cloud radius
|
||||
fparam6 = TODO: 3OE1:802CD890; probability in range [0, 1]; NNF: Level of 'Megidness'. Value of 1 treats the attack as megid, despite fparam3.
|
||||
iparam3 = TODO: 3OE1:802CED14; NNF: Projectile fire rate.
|
||||
iparam4 = TODO: 3OE1:802CD7FC; NNF: Charge up time for poison cloud attack.
|
||||
iparam5 = TODO: 3OE1:802CE850; NNF: Melee attack cooldown time.
|
||||
iparam6 = TODO: 3OE1:802CEA30
|
||||
|
||||
MOVEMENT DATA 3B (UL_GIBBON)
|
||||
MOVEMENT DATA 3C (ZOL_GIBBON)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 3D (GIBBLES)
|
||||
fparam2 = TODO: 3OE1:802D7F5C; NNF: Triple-punch attack cooldown.
|
||||
fparam3 = TODO: 3OE1:802D8BC0; NNF: Movement speed.
|
||||
fparam4 = TODO: 3OE1:802D7490; NNF: Jump cooldown time (Higher value = less waiting time).
|
||||
iparam1 = TODO: 3OE1:802D7484
|
||||
|
||||
MOVEMENT DATA 40 (MORFOS)
|
||||
fparam1 = laser speed; hitbox radius is fparam1 * 1.5
|
||||
fparam2 = laser damage
|
||||
iparam1 = TODO: 3OE1:80332298, 3OE1:803321C4; NNF: Firing rate of regular laser attack. Laser attack when aggressive (charging) is unaffected.
|
||||
iparam2 = TODO: 3OE1:8033161C, 3OE1:8033192C, 3OE1:80331B4C, 3OE1:80331D00, 3OE1:80331FA0; NNF: Speed at which Morphos spins after firing laser.
|
||||
iparam3 = TODO: 3OE1:80331F04; NNF: Interval in frames of attacks
|
||||
iparam4 = TODO: 3OE1:803318EC; NNF: Charge frames before attacking without hitstun.
|
||||
iparam5 = TODO: 3OE1:803318CC; NNF: Affects charge laser tracking. Too high and doesnt lock-on. Need Research
|
||||
|
||||
MOVEMENT DATA 41 (RECOBOX)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 42 (RECON)
|
||||
fparam1 = TODO: 3OE1:8031C31C; NNF: Chase speed for buzzsaw attack
|
||||
fparam2 = bomb explosion radius
|
||||
fparam3 = bomb damage
|
||||
fparam4 = TODO: 3OE1:8031A144; NNF: bomb throw distance
|
||||
iparam1 = TODO: 3OE1:80319DCC; bomb frames until explosion?; NNF: Speed recon comes out of the recobox. As it always takes the same amount of 'time' to come out, higher values make it go high up as well as fast.
|
||||
iparam2 = TODO: 3OE1:8031B68C; NNF: Frame delay from when Recon gets in position to when it activates buzzsaw.
|
||||
|
||||
MOVEMENT DATA 43 (SINOW_ZOA)
|
||||
MOVEMENT DATA 44 (SINOW_ZELE)
|
||||
fparam1 = TODO: 3OE1:80317B7C; NNF: Movement speed
|
||||
fparam3 = TODO: 3OE1:803173F4; NNF: Speed at which Sinow Zoa/Zele reappears after warping.
|
||||
fparam4 = TODO: 3OE1:80319960; NNF: Attack speed
|
||||
fparam5 = TODO: 3OE1:80319968
|
||||
fparam6 = TODO: 3OE1:80316F84
|
||||
iparam1 = Resta/Shifta/Deband/Jellen/Zalure level
|
||||
iparam2 = TODO: 3OE1:80316BE8
|
||||
iparam3 = TODO: 3OE1:80317458; NNF: Cooldown time for all attacks.
|
||||
iparam4 = attack tech level (Rabarta in Ultimate, Gibarta otherwise)
|
||||
|
||||
MOVEMENT DATA 48 (HILDEBEAR)
|
||||
MOVEMENT DATA 49 (HILDEBLUE)
|
||||
fparam1 = punch attack speed
|
||||
fparam2 = TODO: 3OE1:800ADBE0; NNF: tech range
|
||||
fparam3 = movement speed (does not affect animation speed)
|
||||
fparam4 = walking animation speed
|
||||
|
||||
MOVEMENT DATA 4D (GRASS_ASSASSIN)
|
||||
(loaded with assets but not used)
|
||||
|
||||
MOVEMENT DATA 51 (DELSABER)
|
||||
fparam1 = TODO: 3OE1:800A5454
|
||||
fparam2 = TODO: 3OE1:800A5708
|
||||
fparam3 = TODO: 3OE1:800A5CA4
|
||||
fparam4 = TODO: 3OE1:800A5D04
|
||||
@@ -557,7 +557,7 @@ BugFixes
|
||||
8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 8000C6E8 807F0024 lwz r3, [r31 + 0x0024]
|
||||
8000C6EC 48165AA0 8000C6EC 482147D4 8000C6EC 482156C0 8000C6EC 48215474 8000C6EC 482146F4 8000C6EC 482146F4 8000C6EC 482157A8 8000C6EC 48215040 b +0x002146F4 /* 80220DE0 */
|
||||
8021D098 4BDEF638 8021D9FC 4BDEECD4 8021E8E8 4BDEDDE8 8021E69C 4BDEE034 8021D91C 4BDEEDB4 8021D91C 4BDEEDB4 8021E9D0 4BDEDD00 8021E268 4BDEE468 b -0x0021124C /* 8000C6D0 */
|
||||
80172188 4BE9A558 80220EBC 4BDEB824 80221DA8 4BDEA938 80221B5C 4BDEAB84 80220DDC 4BDEB904 80220DDC 4BDEB904 80221E90 4BDEA850 80221728 4BDEAFB8 b -0x002146FC /* 8000C6E0 */
|
||||
80220528 4BE9A558 80220EBC 4BDEB824 80221DA8 4BDEA938 80221B5C 4BDEAB84 80220DDC 4BDEB904 80220DDC 4BDEB904 80221E90 4BDEA850 80221728 4BDEAFB8 b -0x002146FC /* 8000C6E0 */
|
||||
|
||||
Dropped Mag Colour Bug Fix
|
||||
BugFixes
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Binary file not shown.
Binary file not shown.
Executable → Regular
Binary file not shown.
Binary file not shown.
+2
-2
@@ -67,8 +67,8 @@ string AFSArchive::generate_t(const vector<string>& files) {
|
||||
w.put_u32b(0x41465300); // 'AFS\0'
|
||||
w.put<U32T<BE>>(files.size());
|
||||
|
||||
// It seems entries are aligned to 0x800-byte boundaries, and the file's
|
||||
// header is always 0x80000 (!) bytes, most of which is unused
|
||||
// It seems entries are aligned to 0x800-byte boundaries, and the file's header is always 0x80000 (!) bytes, most of
|
||||
// which is unused
|
||||
uint32_t data_offset = 0x80000;
|
||||
for (const auto& file : files) {
|
||||
w.put<U32T<BE>>(data_offset);
|
||||
|
||||
+16
-40
@@ -32,10 +32,7 @@ shared_ptr<DCNTELicense> DCNTELicense::from_json(const phosg::JSON& json) {
|
||||
}
|
||||
|
||||
phosg::JSON DCNTELicense::json() const {
|
||||
return phosg::JSON::dict({
|
||||
{"SerialNumber", this->serial_number},
|
||||
{"AccessKey", this->access_key},
|
||||
});
|
||||
return phosg::JSON::dict({{"SerialNumber", this->serial_number}, {"AccessKey", this->access_key}});
|
||||
}
|
||||
|
||||
shared_ptr<V1V2License> V1V2License::from_json(const phosg::JSON& json) {
|
||||
@@ -52,10 +49,7 @@ shared_ptr<V1V2License> V1V2License::from_json(const phosg::JSON& json) {
|
||||
}
|
||||
|
||||
phosg::JSON V1V2License::json() const {
|
||||
return phosg::JSON::dict({
|
||||
{"SerialNumber", this->serial_number},
|
||||
{"AccessKey", this->access_key},
|
||||
});
|
||||
return phosg::JSON::dict({{"SerialNumber", this->serial_number}, {"AccessKey", this->access_key}});
|
||||
}
|
||||
|
||||
shared_ptr<GCLicense> GCLicense::from_json(const phosg::JSON& json) {
|
||||
@@ -101,11 +95,7 @@ shared_ptr<XBLicense> XBLicense::from_json(const phosg::JSON& json) {
|
||||
}
|
||||
|
||||
phosg::JSON XBLicense::json() const {
|
||||
return phosg::JSON::dict({
|
||||
{"GamerTag", this->gamertag},
|
||||
{"UserID", this->user_id},
|
||||
{"AccountID", this->account_id},
|
||||
});
|
||||
return phosg::JSON::dict({{"GamerTag", this->gamertag}, {"UserID", this->user_id}, {"AccountID", this->account_id}});
|
||||
}
|
||||
|
||||
shared_ptr<BBLicense> BBLicense::from_json(const phosg::JSON& json) {
|
||||
@@ -128,10 +118,7 @@ shared_ptr<BBLicense> BBLicense::from_json(const phosg::JSON& json) {
|
||||
}
|
||||
|
||||
phosg::JSON BBLicense::json() const {
|
||||
return phosg::JSON::dict({
|
||||
{"UserName", this->username},
|
||||
{"Password", this->password},
|
||||
});
|
||||
return phosg::JSON::dict({{"UserName", this->username}, {"Password", this->password}});
|
||||
}
|
||||
|
||||
Account::Account(const phosg::JSON& json)
|
||||
@@ -329,6 +316,9 @@ string Account::str() const {
|
||||
flags_str += "CHEAT_ANYWHERE,";
|
||||
}
|
||||
if (this->check_flag(Flag::DISABLE_QUEST_REQUIREMENTS)) {
|
||||
flags_str += "DISABLE_QUEST_REQUIREMENTS,";
|
||||
}
|
||||
if (this->check_flag(Flag::ALWAYS_ENABLE_CHAT_COMMANDS)) {
|
||||
flags_str += "ALWAYS_ENABLE_CHAT_COMMANDS,";
|
||||
}
|
||||
if (this->check_flag(Flag::IS_SHARED_ACCOUNT)) {
|
||||
@@ -409,7 +399,8 @@ string Account::str() const {
|
||||
void Account::save() const {
|
||||
if (!this->is_temporary) {
|
||||
auto json = this->json();
|
||||
string json_data = json.serialize(phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS);
|
||||
string json_data = json.serialize(
|
||||
phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS);
|
||||
string filename = std::format("system/licenses/{:010}.json", this->account_id);
|
||||
phosg::save_file(filename, json_data);
|
||||
}
|
||||
@@ -420,26 +411,6 @@ 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 = std::format("Account:{:08X}", this->account->account_id);
|
||||
if (this->account_was_created) {
|
||||
@@ -673,7 +644,11 @@ shared_ptr<Login> AccountIndex::from_gc_credentials_locked(
|
||||
}
|
||||
|
||||
shared_ptr<Login> AccountIndex::from_gc_credentials(
|
||||
uint32_t serial_number, const string& access_key, const string* password, const string& character_name, bool allow_create) {
|
||||
uint32_t serial_number,
|
||||
const string& access_key,
|
||||
const string* password,
|
||||
const string& character_name,
|
||||
bool allow_create) {
|
||||
if (serial_number == 0) {
|
||||
throw no_username();
|
||||
}
|
||||
@@ -767,7 +742,8 @@ shared_ptr<Login> AccountIndex::from_bb_credentials_locked(const string& usernam
|
||||
return login;
|
||||
}
|
||||
|
||||
shared_ptr<Login> AccountIndex::from_bb_credentials(const string& username, const string* password, bool allow_create) {
|
||||
shared_ptr<Login> AccountIndex::from_bb_credentials(
|
||||
const string& username, const string* password, bool allow_create) {
|
||||
if (username.empty() || (password && password->empty())) {
|
||||
throw no_username();
|
||||
}
|
||||
|
||||
+12
-60
@@ -17,10 +17,6 @@ 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;
|
||||
};
|
||||
@@ -29,10 +25,6 @@ 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;
|
||||
};
|
||||
@@ -42,10 +34,6 @@ 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;
|
||||
};
|
||||
@@ -55,10 +43,6 @@ 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;
|
||||
};
|
||||
@@ -67,10 +51,6 @@ 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;
|
||||
};
|
||||
@@ -92,8 +72,7 @@ struct Account {
|
||||
ADMINISTRATOR = 0x000000FF,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
IS_SHARED_ACCOUNT = 0x80000000,
|
||||
// NOTE: When adding or changing license flags, don't forget to change the
|
||||
// documentation in the shell's help text.
|
||||
// NOTE: When adding or changing license flags, don't forget to change the documentation in the shell's help text.
|
||||
UNUSED_BITS = 0x70FFFF00,
|
||||
// clang-format on
|
||||
};
|
||||
@@ -169,8 +148,7 @@ struct Login {
|
||||
bool account_was_created = false;
|
||||
// This field will never be null
|
||||
std::shared_ptr<Account> account;
|
||||
// Exactly one of the following will be non-null, representing the license
|
||||
// that the client logged in with
|
||||
// Exactly one of the following will be non-null, representing the license that the client logged in with
|
||||
std::shared_ptr<DCNTELicense> dc_nte_license;
|
||||
std::shared_ptr<V1V2License> dc_license;
|
||||
std::shared_ptr<V1V2License> pc_license;
|
||||
@@ -178,8 +156,6 @@ struct Login {
|
||||
std::shared_ptr<XBLicense> xb_license;
|
||||
std::shared_ptr<BBLicense> bb_license;
|
||||
|
||||
uint64_t proxy_session_id() const;
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
@@ -232,22 +208,12 @@ public:
|
||||
|
||||
std::shared_ptr<Account> from_account_id(uint32_t account_id) const;
|
||||
std::shared_ptr<Login> from_dc_nte_credentials(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key,
|
||||
bool allow_create);
|
||||
const std::string& serial_number, const std::string& access_key, bool allow_create);
|
||||
std::shared_ptr<Login> from_dc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_nte_credentials(
|
||||
uint32_t guild_card_number,
|
||||
bool allow_create);
|
||||
uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_nte_credentials(uint32_t guild_card_number, bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create);
|
||||
std::shared_ptr<Login> from_gc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
@@ -255,14 +221,9 @@ public:
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_xb_credentials(
|
||||
const std::string& gamertag,
|
||||
uint64_t user_id,
|
||||
uint64_t account_id,
|
||||
bool allow_create);
|
||||
const std::string& gamertag, uint64_t user_id, uint64_t account_id, bool allow_create);
|
||||
std::shared_ptr<Login> from_bb_credentials(
|
||||
const std::string& username,
|
||||
const std::string* password,
|
||||
bool allow_create);
|
||||
const std::string& username, const std::string* password, bool allow_create);
|
||||
|
||||
std::shared_ptr<Account> create_temporary_account_for_shared_account(
|
||||
std::shared_ptr<const Account> src_a, const std::string& variation_data) const;
|
||||
@@ -270,8 +231,6 @@ public:
|
||||
protected:
|
||||
bool force_all_temporary;
|
||||
|
||||
// This class must be thread-safe because it's used by both the patch server
|
||||
// and game server threads
|
||||
mutable std::shared_mutex lock;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_account_id;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_dc_nte_serial_number;
|
||||
@@ -284,23 +243,16 @@ protected:
|
||||
void add_locked(std::shared_ptr<Account> a);
|
||||
|
||||
std::shared_ptr<Login> from_dc_nte_credentials_locked(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key);
|
||||
const std::string& serial_number, const std::string& access_key);
|
||||
std::shared_ptr<Login> from_dc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
uint32_t serial_number, const std::string& access_key, const std::string& character_name);
|
||||
std::shared_ptr<Login> from_pc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
uint32_t serial_number, const std::string& access_key, const std::string& character_name);
|
||||
std::shared_ptr<Login> from_gc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string* password,
|
||||
const std::string& character_name);
|
||||
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);
|
||||
std::shared_ptr<Login> from_bb_credentials_locked(const std::string& username, const std::string* password);
|
||||
};
|
||||
|
||||
+21
-20
@@ -247,9 +247,9 @@ public:
|
||||
static constexpr bool IsBE = BE;
|
||||
|
||||
U16T<BE> type;
|
||||
U16T<BE> unknown_a1;
|
||||
U16T<BE> unused;
|
||||
U32T<BE> constructor_addr;
|
||||
F32T<BE> unknown_a2;
|
||||
F32T<BE> max_dist2; // Only applies for objects
|
||||
U32T<BE> default_num_children;
|
||||
} __attribute__((packed));
|
||||
|
||||
@@ -259,28 +259,24 @@ public:
|
||||
|
||||
pstring<TextEncoding::ASCII, 0x10> debug_name;
|
||||
U16T<BE> type;
|
||||
U16T<BE> unknown_a1;
|
||||
U16T<BE> unused;
|
||||
U32T<BE> constructor_addr;
|
||||
F32T<BE> unknown_a2;
|
||||
F32T<BE> max_dist2; // Only applies for objects
|
||||
U32T<BE> default_num_children;
|
||||
} __attribute__((packed));
|
||||
|
||||
// Returns {type: {constructor_addr: [(start_area, end_area), ...]}}
|
||||
template <typename EntryT>
|
||||
map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>>
|
||||
parse_dat_constructor_table_t(
|
||||
shared_ptr<const ResourceDASM::MemoryContext>& mem,
|
||||
const ParseDATConstructorTableSpec& spec) {
|
||||
map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>> parse_dat_constructor_table_t(
|
||||
shared_ptr<const ResourceDASM::MemoryContext>& mem, const ParseDATConstructorTableSpec& spec) {
|
||||
if (!mem) {
|
||||
throw runtime_error("no file selected");
|
||||
}
|
||||
|
||||
// On some of the x86 builds of the game (PCv2 and Xbox), the constructor
|
||||
// tables aren't entirely static in the data sections - some parts are
|
||||
// written during static initialization instead. To handle this, we make a
|
||||
// copy of the immutable MemoryContext and run the static initialization
|
||||
// functions using resource_dasm's emulator before parsing the constructor
|
||||
// table.
|
||||
// On some of the x86 builds of the game (PCv2 and Xbox), the constructor tables aren't entirely static in the data
|
||||
// sections - some parts are written during static initialization instead. To handle this, we make a copy of the
|
||||
// immutable MemoryContext and run the static initialization functions using resource_dasm's emulator before
|
||||
// parsing the constructor table.
|
||||
shared_ptr<const ResourceDASM::MemoryContext> effective_mem = mem;
|
||||
if (!spec.x86_constructor_calls.empty()) {
|
||||
auto constructed_mem = make_shared<ResourceDASM::MemoryContext>(mem->duplicate());
|
||||
@@ -455,9 +451,7 @@ public:
|
||||
}
|
||||
}
|
||||
line.push_back(' ');
|
||||
line += is_enemies
|
||||
? MapFile::name_for_enemy_type(type)
|
||||
: MapFile::name_for_object_type(type);
|
||||
line += is_enemies ? MapFile::name_for_enemy_type(type) : MapFile::name_for_object_type(type);
|
||||
|
||||
if ((formatted_lines.size() % 40) == 0) {
|
||||
formatted_lines.emplace_back(header_line);
|
||||
@@ -732,9 +726,7 @@ 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 {
|
||||
shared_ptr<const ResourceDASM::MemoryContext> dest_mem, uint32_t src_addr, uint32_t src_size) const {
|
||||
if (src_size == 0) {
|
||||
src_size = 4;
|
||||
}
|
||||
@@ -863,6 +855,15 @@ public:
|
||||
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] == "only") {
|
||||
unordered_set<string> to_keep{tokens.begin() + 1, tokens.end()};
|
||||
for (auto it = this->mems.begin(); it != this->mems.end();) {
|
||||
if (to_keep.count(it->first)) {
|
||||
it++;
|
||||
} else {
|
||||
it = this->mems.erase(it);
|
||||
}
|
||||
}
|
||||
} else if (tokens[0] == "match") {
|
||||
this->find_all_matches(
|
||||
stoul(tokens.at(1), nullptr, 16),
|
||||
|
||||
+16
-18
@@ -163,7 +163,7 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
|
||||
} else if (method_token == "TRACE") {
|
||||
req.method = HTTPRequest::Method::TRACE;
|
||||
} else {
|
||||
throw HTTPError(400, "unknown request method");
|
||||
throw HTTPError(400, "Unknown request method");
|
||||
}
|
||||
|
||||
req.http_version = std::move(line_tokens[2]);
|
||||
@@ -237,26 +237,26 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
|
||||
size_t parse_offset = 0;
|
||||
size_t chunk_size = stoull(line, &parse_offset, 16);
|
||||
if (parse_offset != line.size()) {
|
||||
throw HTTPError(400, "invalid chunk header during chunked encoding");
|
||||
throw HTTPError(400, "Invalid chunk header during chunked encoding");
|
||||
}
|
||||
if (chunk_size == 0) {
|
||||
break;
|
||||
}
|
||||
total_data_bytes += chunk_size;
|
||||
if (total_data_bytes > max_body_size) {
|
||||
throw HTTPError(400, "request data size too large");
|
||||
throw HTTPError(400, "Request data size too large");
|
||||
}
|
||||
chunks.emplace_back(co_await this->r.read_data(chunk_size));
|
||||
auto after_chunk_data = co_await this->r.read_line("\r\n", 0x20);
|
||||
if (!after_chunk_data.empty()) {
|
||||
throw HTTPError(400, "incorrect trailing sequence after chunk data");
|
||||
throw HTTPError(400, "Incorrect trailing sequence after chunk data");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto content_length_header = req.get_header("content-length");
|
||||
size_t content_length = content_length_header ? stoull(*content_length_header) : 0;
|
||||
if (content_length > max_body_size) {
|
||||
throw HTTPError(400, "request data size too large");
|
||||
throw HTTPError(400, "Request data size too large");
|
||||
} else if (content_length > 0) {
|
||||
req.data = co_await this->r.read_data(content_length);
|
||||
}
|
||||
@@ -289,8 +289,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
||||
while (this->r.get_socket().is_open()) {
|
||||
WebSocketMessage msg;
|
||||
|
||||
// We need at most 10 bytes to determine if there's a valid frame, or as
|
||||
// little as 2
|
||||
// We need at most 10 bytes to determine if there's a valid frame, or as little as 2
|
||||
co_await this->r.read_data_into(msg.header, 2);
|
||||
|
||||
// Get the payload size
|
||||
@@ -325,8 +324,8 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
||||
|
||||
this->last_communication_time = phosg::now();
|
||||
|
||||
// If the current message is a control message, respond appropriately
|
||||
// (these can be sent in the middle of fragmented messages)
|
||||
// If the current message is a control message, respond appropriately (these can be sent in the middle of
|
||||
// fragmented messages)
|
||||
uint8_t opcode = msg.header[0] & 0x0F;
|
||||
if (opcode & 0x08) {
|
||||
if (opcode == 0x0A) {
|
||||
@@ -335,7 +334,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
||||
} else if (opcode == 0x08) {
|
||||
// Close message
|
||||
co_await this->send_websocket_message(msg.data, msg.opcode);
|
||||
this->r.get_socket().close();
|
||||
this->r.close();
|
||||
|
||||
} else if (opcode == 0x09) {
|
||||
// Ping message
|
||||
@@ -343,15 +342,15 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
||||
|
||||
} else {
|
||||
// Unknown control message type
|
||||
this->r.get_socket().close();
|
||||
this->r.close();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// If there's an existing fragment, the current message's opcode should be
|
||||
// zero; if there's no pending message, it must not be zero
|
||||
// If there's an existing fragment, the current message's opcode should be zero; if there's no pending message, it
|
||||
// must not be zero
|
||||
if (prev_msg_present == (opcode != 0)) {
|
||||
this->r.get_socket().close();
|
||||
this->r.close();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -373,10 +372,9 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
||||
prev_msg.data += msg.data;
|
||||
}
|
||||
|
||||
// If the FIN bit is set, then the frame is complete - append the payload
|
||||
// to any pending payloads and call the message handler. If the FIN bit
|
||||
// isn't set, we need to receive at least one continuation frame to
|
||||
// complete the message.
|
||||
// If the FIN bit is set, then the frame is complete - append the payload to any pending payloads and call the
|
||||
// message handler. If the FIN bit isn't set, we need to receive at least one continuation frame to complete the
|
||||
// message.
|
||||
if (prev_msg.header[0] & 0x80) {
|
||||
co_return prev_msg;
|
||||
}
|
||||
|
||||
+133
-15
@@ -9,6 +9,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <string>
|
||||
@@ -37,9 +38,8 @@ struct HTTPRequest {
|
||||
std::unordered_multimap<std::string, std::string> query_params;
|
||||
std::string data;
|
||||
|
||||
// Header name should be entirely lowercase for this function. Returns
|
||||
// nullptr if the header doesn't exist; throws http_error(400) if multiple
|
||||
// instances of it exist.
|
||||
// Header name should be entirely lowercase for this function. Returns nullptr if the header doesn't exist; throws
|
||||
// http_error(400) if multiple instances of it exist.
|
||||
const std::string* get_header(const std::string& name) const;
|
||||
|
||||
const std::string* get_query_param(const std::string& name) const;
|
||||
@@ -48,8 +48,7 @@ struct HTTPRequest {
|
||||
struct HTTPResponse {
|
||||
std::string http_version;
|
||||
int response_code = 200;
|
||||
// Content-Length should NOT be specified in headers; it is automatically
|
||||
// added in async_write() if data is not blank.
|
||||
// Content-Length should NOT be specified in headers; it is automatically added in async_write() if data isn't blank.
|
||||
std::unordered_multimap<std::string, std::string> headers;
|
||||
std::string data;
|
||||
};
|
||||
@@ -82,6 +81,106 @@ struct HTTPClient {
|
||||
asio::awaitable<void> send_websocket_message(const std::string& data, uint8_t opcode = 0x01);
|
||||
};
|
||||
|
||||
template <typename RetT>
|
||||
class HTTPRouter {
|
||||
public:
|
||||
struct Args {
|
||||
std::shared_ptr<HTTPClient> client;
|
||||
const HTTPRequest& req;
|
||||
std::unordered_map<std::string, std::string> params;
|
||||
phosg::JSON post_data;
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_integral_v<T>)
|
||||
T get_param(const char* name, bool hex = false) const {
|
||||
const auto& value_str = this->params.at(name);
|
||||
size_t conversion_end;
|
||||
int64_t v = std::stoull(value_str, &conversion_end, hex ? 16 : 0);
|
||||
if (conversion_end != value_str.size()) {
|
||||
throw HTTPError(400, "Invalid integer value");
|
||||
}
|
||||
|
||||
uint64_t uv = static_cast<uint64_t>(v);
|
||||
if constexpr (std::is_unsigned_v<T>) {
|
||||
if (uv & (~phosg::mask_for_type<T>)) {
|
||||
throw HTTPError(400, "Unsigned value out of range");
|
||||
}
|
||||
return uv;
|
||||
} else {
|
||||
if (((uv & (~(phosg::mask_for_type<T> >> 1))) != 0) && ((uv & (~(phosg::mask_for_type<T> >> 1))) != (~(phosg::mask_for_type<T> >> 1)))) {
|
||||
throw HTTPError(400, "Signed value out of range");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using Handler = std::function<asio::awaitable<RetT>(Args&&)>;
|
||||
|
||||
static std::vector<std::string> split_and_normalize_path(const std::string& path) {
|
||||
auto path_tokens = phosg::split(path, '/');
|
||||
while (!path_tokens.empty() && path_tokens.back().empty()) {
|
||||
path_tokens.pop_back();
|
||||
}
|
||||
return path_tokens;
|
||||
}
|
||||
|
||||
void add(HTTPRequest::Method method, const std::string& path_pattern, Handler handler) {
|
||||
this->routes.emplace_back(Route{
|
||||
.method = method, .path_tokens = this->split_and_normalize_path(path_pattern), .handler = handler});
|
||||
}
|
||||
|
||||
asio::awaitable<RetT> call_handler(std::shared_ptr<HTTPClient> c, const HTTPRequest& req) {
|
||||
Args args = {.client = c, .req = req, .params = {}, .post_data = phosg::JSON()};
|
||||
|
||||
auto tokens = this->split_and_normalize_path(req.path);
|
||||
for (const auto& route : this->routes) {
|
||||
if (route.path_tokens.size() != tokens.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool matched = true;
|
||||
args.params.clear();
|
||||
for (size_t z = 0; z < tokens.size(); z++) {
|
||||
if (route.path_tokens[z].starts_with(':')) {
|
||||
args.params.emplace(route.path_tokens[z].substr(1), tokens[z]);
|
||||
} else if (route.path_tokens[z] != tokens[z]) {
|
||||
matched = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
if (req.method != route.method) {
|
||||
throw HTTPError(405, "Incorrect HTTP method");
|
||||
}
|
||||
if (req.method == HTTPRequest::Method::POST) {
|
||||
auto* content_type = req.get_header("content-type");
|
||||
if (!content_type || (*content_type != "application/json")) {
|
||||
throw HTTPError(400, "POST requests must use the application/json content type");
|
||||
}
|
||||
try {
|
||||
args.post_data = phosg::JSON::parse(req.data);
|
||||
} catch (const std::exception& e) {
|
||||
throw HTTPError(400, std::format("Invalid JSON: {}", e.what()));
|
||||
}
|
||||
}
|
||||
co_return co_await route.handler(std::move(args));
|
||||
}
|
||||
}
|
||||
|
||||
throw HTTPError(404, "Request path did not match any route");
|
||||
}
|
||||
|
||||
private:
|
||||
struct Route {
|
||||
HTTPRequest::Method method;
|
||||
std::vector<std::string> path_tokens;
|
||||
Handler handler;
|
||||
};
|
||||
std::vector<Route> routes;
|
||||
};
|
||||
|
||||
struct HTTPServerLimits {
|
||||
size_t max_http_request_line_size = 0x1000; // 4KB
|
||||
size_t max_http_data_size = 0x200000; // 2MB
|
||||
@@ -120,9 +219,31 @@ public:
|
||||
protected:
|
||||
HTTPServerLimits limits;
|
||||
|
||||
// Attempts to switch the client to WebSockets. Returns true if this is done
|
||||
// successfully (and the caller should then receive/send WebSocket messages),
|
||||
// or false if this failed (and the caller should send an HTTP response).
|
||||
void require_GET(const HTTPRequest& req) {
|
||||
if (req.method != HTTPRequest::Method::GET) {
|
||||
throw HTTPError(405, "GET method required for this endpoint");
|
||||
}
|
||||
}
|
||||
|
||||
phosg::JSON require_JSON_POST(const HTTPRequest& req) {
|
||||
if (req.method != HTTPRequest::Method::POST) {
|
||||
throw HTTPError(405, "POST method required for this endpoint");
|
||||
}
|
||||
|
||||
auto* content_type = req.get_header("content-type");
|
||||
if (!content_type || (*content_type != "application/json")) {
|
||||
throw HTTPError(400, "POST requests must use the application/json content type");
|
||||
}
|
||||
|
||||
try {
|
||||
return phosg::JSON::parse(req.data);
|
||||
} catch (const std::exception& e) {
|
||||
throw HTTPError(400, std::format("Invalid JSON: {}", e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to switch the client to WebSockets. Returns true if this is done successfully (and the caller should then
|
||||
// receive/send WebSocket messages), or false if this failed (and the caller should send an HTTP response).
|
||||
asio::awaitable<bool> enable_websockets(std::shared_ptr<ClientT> c, const HTTPRequest& req) {
|
||||
if (req.method != HTTPRequest::Method::GET) {
|
||||
co_return false;
|
||||
@@ -163,13 +284,10 @@ protected:
|
||||
|
||||
// handle_request must do one of the following three things:
|
||||
// 1. Return an HTTP response.
|
||||
// 2. Call enable_websockets, and if it returns true, return nullptr. After
|
||||
// this point, handle_request will not be called again for this client;
|
||||
// handle_websocket_message will be called instead when any WebSocket
|
||||
// messages are received. If enable_websockets returns false,
|
||||
// handle_request must still return an HTTP response.
|
||||
// 3. Throw an exception. In this case, the client receives an HTTP 500
|
||||
// response.
|
||||
// 2. Call enable_websockets, and if it returns true, return nullptr. After this point, handle_request will not be
|
||||
// called again for this client; handle_websocket_message will be called instead when any WebSocket messages are
|
||||
// received. If enable_websockets returns false, handle_request must still return an HTTP response.
|
||||
// 3. Throw an exception. In this case, the client receives an HTTP 500 response.
|
||||
virtual asio::awaitable<std::unique_ptr<HTTPResponse>> handle_request(std::shared_ptr<ClientT> c, HTTPRequest&& req) = 0;
|
||||
virtual asio::awaitable<void> handle_websocket_message(std::shared_ptr<ClientT>, WebSocketMessage&&) {
|
||||
co_return;
|
||||
|
||||
+8
-6
@@ -13,15 +13,18 @@ AsyncEvent::AsyncEvent(asio::any_io_executor ex)
|
||||
: executor(ex), is_set(false) {}
|
||||
|
||||
void AsyncEvent::set() {
|
||||
lock_guard g(this->lock);
|
||||
this->is_set = true;
|
||||
for (auto& waiter : this->waiters) {
|
||||
std::vector<std::unique_ptr<asio::detail::awaitable_handler<asio::any_io_executor>>> waiters_to_resume;
|
||||
{
|
||||
lock_guard g(this->lock);
|
||||
this->is_set = true;
|
||||
this->waiters.swap(waiters_to_resume);
|
||||
}
|
||||
for (auto& waiter : waiters_to_resume) {
|
||||
asio::post(this->executor,
|
||||
[handler = std::move(waiter)]() mutable {
|
||||
(*handler)();
|
||||
});
|
||||
}
|
||||
this->waiters.clear();
|
||||
}
|
||||
|
||||
void AsyncEvent::clear() {
|
||||
@@ -70,8 +73,7 @@ asio::awaitable<string> AsyncSocketReader::read_line(const char* delimiter, size
|
||||
throw runtime_error("line exceeds max length");
|
||||
}
|
||||
|
||||
// TODO: It's not great that we copy the data here. There's probably a more
|
||||
// idiomatic and efficient way to do this.
|
||||
// TODO: It's not great that we copy the data here. There's probably a more idiomatic and efficient way to do this.
|
||||
string ret = this->pending_data.substr(0, delimiter_pos);
|
||||
this->pending_data = this->pending_data.substr(delimiter_pos + delimiter_size);
|
||||
co_return ret;
|
||||
|
||||
+20
-12
@@ -175,22 +175,27 @@ public:
|
||||
AsyncSocketReader& operator=(AsyncSocketReader&&) = delete;
|
||||
~AsyncSocketReader() = default;
|
||||
|
||||
// Reads one line from the socket, buffering any extra data read. The
|
||||
// delimiter is not included in the returned line. max_length = 0 means no
|
||||
// maximum length is enforced.
|
||||
// Reads one line from the socket, buffering any extra data read. The delimiter is not included in the returned line.
|
||||
// max_length = 0 means no maximum length is enforced.
|
||||
asio::awaitable<std::string> read_line(
|
||||
const char* delimiter = "\n", size_t max_length = 0);
|
||||
asio::awaitable<std::string> read_data(size_t size);
|
||||
asio::awaitable<void> read_data_into(void* data, size_t size);
|
||||
|
||||
// The caller cannot know what the socket's read state is, so this should
|
||||
// only be used when the caller intends to write to the socket, not read
|
||||
// The caller cannot know what the socket's read state is, so this should only be used when the caller intends to
|
||||
// write to the socket, not read
|
||||
inline asio::ip::tcp::socket& get_socket() {
|
||||
return this->sock;
|
||||
}
|
||||
|
||||
inline bool is_open() const {
|
||||
return this->sock.is_open();
|
||||
}
|
||||
|
||||
inline void close() {
|
||||
this->sock.close();
|
||||
if (this->sock.is_open()) {
|
||||
this->sock.close();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -209,8 +214,8 @@ public:
|
||||
|
||||
void add(std::string&& data);
|
||||
|
||||
// When using add_reference, it is the caller's responsibility to ensure that
|
||||
// the buffer is valid until *this is destroyed or write() returns.
|
||||
// When using add_reference, it is the caller's responsibility to ensure that the buffer is valid until *this is
|
||||
// destroyed or write() returns.
|
||||
void add_reference(const void* data, size_t size);
|
||||
|
||||
asio::awaitable<void> write(asio::ip::tcp::socket& sock);
|
||||
@@ -254,12 +259,15 @@ asio::awaitable<std::invoke_result_t<FnT, ArgTs...>> call_on_thread_pool(asio::t
|
||||
using ReturnT = std::invoke_result_t<FnT, ArgTs...>;
|
||||
auto bound = std::bind(std::forward<FnT>(f), std::forward<ArgTs>(args)...);
|
||||
|
||||
// We have to use a shared_ptr here in case call_on_thread_pool is canceled
|
||||
// (in that case, the posted callback will try to use promise after the
|
||||
// call_on_thread_pool coroutine has been destroyed)
|
||||
// We have to use a shared_ptr here in case call_on_thread_pool is canceled (in that case, the posted callback will
|
||||
// try to use promise after the call_on_thread_pool coroutine has been destroyed)
|
||||
auto promise = std::make_shared<AsyncPromise<ReturnT>>();
|
||||
asio::post(pool, [bound = std::move(bound), promise]() mutable {
|
||||
promise->set_value(bound());
|
||||
try {
|
||||
promise->set_value(bound());
|
||||
} catch (...) {
|
||||
promise->set_exception(std::current_exception());
|
||||
}
|
||||
});
|
||||
co_return co_await promise->get();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ struct BMLHeaderT {
|
||||
U32T<BE> num_entries;
|
||||
parray<uint8_t, 0x38> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
using BMLHeader = BMLHeaderT<false>;
|
||||
using BMLHeaderBE = BMLHeaderT<true>;
|
||||
check_struct_size(BMLHeader, 0x40);
|
||||
@@ -31,7 +30,6 @@ struct BMLHeaderEntryT {
|
||||
U32T<BE> decompressed_gvm_size;
|
||||
parray<uint8_t, 0x0C> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
using BMLHeaderEntry = BMLHeaderEntryT<false>;
|
||||
using BMLHeaderEntryBE = BMLHeaderEntryT<true>;
|
||||
check_struct_size(BMLHeaderEntry, 0x40);
|
||||
|
||||
+58
-26
@@ -10,35 +10,67 @@
|
||||
using namespace std;
|
||||
|
||||
void BattleParamsIndex::Table::print(FILE* stream, Episode episode) const {
|
||||
auto print_entry = [stream, episode](const PlayerStats& e, size_t z) {
|
||||
string names_str;
|
||||
for (auto type : enemy_types_for_battle_param_index(episode, z)) {
|
||||
if (!names_str.empty()) {
|
||||
names_str += ", ";
|
||||
}
|
||||
names_str += phosg::name_for_enum(type);
|
||||
}
|
||||
phosg::fwrite_fmt(stream,
|
||||
"{:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {}",
|
||||
e.char_stats.atp,
|
||||
e.char_stats.mst,
|
||||
e.char_stats.evp,
|
||||
e.char_stats.hp,
|
||||
e.char_stats.dfp,
|
||||
e.char_stats.ata,
|
||||
e.char_stats.lck,
|
||||
e.esp,
|
||||
e.experience,
|
||||
e.meseta,
|
||||
names_str);
|
||||
};
|
||||
|
||||
for (size_t diff = 0; diff < 4; diff++) {
|
||||
phosg::fwrite_fmt(stream, "========== STATS\n");
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
phosg::fwrite_fmt(stream, "{} ZZ ATP PSV EVP HP DFP ATA LCK ESP EXP DIFF NAMES\n",
|
||||
abbreviation_for_difficulty(diff));
|
||||
abbreviation_for_difficulty(difficulty));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
const auto& e = this->stats[static_cast<size_t>(difficulty)][z];
|
||||
phosg::fwrite_fmt(stream, " {:02X} ", z);
|
||||
print_entry(this->stats[diff][z], z);
|
||||
string names_str;
|
||||
for (auto type : enemy_types_for_battle_param_stats_index(episode, z)) {
|
||||
if (!names_str.empty()) {
|
||||
names_str += ", ";
|
||||
}
|
||||
names_str += phosg::name_for_enum(type);
|
||||
}
|
||||
phosg::fwrite_fmt(stream,
|
||||
"{:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {}",
|
||||
e.char_stats.atp, e.char_stats.mst, e.char_stats.evp, e.char_stats.hp, e.char_stats.dfp, e.char_stats.ata,
|
||||
e.char_stats.lck, e.esp, e.experience, e.meseta, names_str);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, "========== ATTACK DATA\n");
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
phosg::fwrite_fmt(stream, "{} ZZ ATP- ATP+ ATA- ATA+ -DIST-X- -ANGLE-- -DIST-Y- -A8- -A9- A10- A11- --A12--- --A13--- --A14--- --A15--- --A16---\n",
|
||||
abbreviation_for_difficulty(difficulty));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
const auto& e = this->attack_data[static_cast<size_t>(difficulty)][z];
|
||||
phosg::fwrite_fmt(stream,
|
||||
" {:02X} {:04X} {:04X} {:04X} {:04X} {:8.3f} {:08X} {:8.3f} {:04X} {:04X} {:04X} {:04X} {:08X} {:08X} {:08X} {:08X} {:08X}",
|
||||
z, e.min_atp, e.max_atp, e.min_ata, e.max_ata, e.distance_x, e.angle, e.distance_y, e.unknown_a8,
|
||||
e.unknown_a9, e.unknown_a10, e.unknown_a11, e.unknown_a12, e.unknown_a13, e.unknown_a14, e.unknown_a15,
|
||||
e.unknown_a16);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, "========== RESIST DATA\n");
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
phosg::fwrite_fmt(stream, "{} ZZ EVP- EFR- EIC- ETH- ELT- EDK- ---A6--- ---A7--- ---A8--- ---A9--- --DFP---\n",
|
||||
abbreviation_for_difficulty(difficulty));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
const auto& e = this->resist_data[static_cast<size_t>(difficulty)][z];
|
||||
phosg::fwrite_fmt(stream,
|
||||
" {:02X} {:04X} {:04X} {:04X} {:04X} {:04X} {:04X} {:08X} {:08X} {:08X} {:08X} {:08X}",
|
||||
z, e.evp_bonus, e.efr, e.eic, e.eth, e.elt, e.edk, e.unknown_a6, e.unknown_a7, e.unknown_a8, e.unknown_a9,
|
||||
e.dfp_bonus);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, "========== MOVEMENT DATA\n");
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
phosg::fwrite_fmt(stream, "{} ZZ FPARAM-1 FPARAM-2 FPARAM-3 FPARAM-4 FPARAM-5 FPARAM-6 IPARAM-1 IPARAM-2 IPARAM-3 IPARAM-4 IPARAM-5 IPARAM-6\n",
|
||||
abbreviation_for_difficulty(difficulty));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
const auto& e = this->movement_data[static_cast<size_t>(difficulty)][z];
|
||||
phosg::fwrite_fmt(stream,
|
||||
" {:02X} {:8.3f} {:8.3f} {:8.3f} {:8.3f} {:8.3f} {:8.3f} {:08X} {:08X} {:08X} {:08X} {:08X} {:08X}",
|
||||
z, e.fparam1, e.fparam2, e.fparam3, e.fparam4, e.fparam5, e.fparam6,
|
||||
e.iparam1, e.iparam2, e.iparam3, e.iparam4, e.iparam5, e.iparam6);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
|
||||
+34
-21
@@ -19,12 +19,12 @@ public:
|
||||
// These files are little-endian, even on PSO GC.
|
||||
|
||||
struct AttackData {
|
||||
/* 00 */ le_int16_t unknown_a1;
|
||||
/* 02 */ le_int16_t atp;
|
||||
/* 04 */ le_int16_t ata_bonus;
|
||||
/* 06 */ le_uint16_t unknown_a4;
|
||||
/* 00 */ le_int16_t min_atp;
|
||||
/* 02 */ le_int16_t max_atp;
|
||||
/* 04 */ le_int16_t min_ata;
|
||||
/* 06 */ le_int16_t max_ata;
|
||||
/* 08 */ le_float distance_x;
|
||||
/* 0C */ le_uint32_t angle_x; // Out of 0x10000 (high 16 bits are unused)
|
||||
/* 0C */ le_uint32_t angle; // Out of 0x10000 (high 16 bits are unused)
|
||||
/* 10 */ le_float distance_y;
|
||||
/* 14 */ le_uint16_t unknown_a8;
|
||||
/* 16 */ le_uint16_t unknown_a9;
|
||||
@@ -54,28 +54,41 @@ public:
|
||||
} __packed_ws__(ResistData, 0x20);
|
||||
|
||||
struct MovementData {
|
||||
/* 00 */ le_float idle_move_speed;
|
||||
/* 04 */ le_float idle_animation_speed;
|
||||
/* 08 */ le_float move_speed;
|
||||
/* 0C */ le_float animation_speed;
|
||||
/* 10 */ le_float unknown_a1;
|
||||
/* 14 */ le_float unknown_a2;
|
||||
/* 18 */ le_uint32_t unknown_a3;
|
||||
/* 1C */ le_uint32_t unknown_a4;
|
||||
/* 20 */ le_uint32_t unknown_a5;
|
||||
/* 24 */ le_uint32_t unknown_a6;
|
||||
/* 28 */ le_uint32_t unknown_a7;
|
||||
/* 2C */ le_uint32_t unknown_a8;
|
||||
/* 00 */ le_float fparam1;
|
||||
/* 04 */ le_float fparam2;
|
||||
/* 03 */ le_float fparam3;
|
||||
/* 0C */ le_float fparam4;
|
||||
/* 10 */ le_float fparam5;
|
||||
/* 14 */ le_float fparam6;
|
||||
/* 18 */ le_uint32_t iparam1;
|
||||
/* 1C */ le_uint32_t iparam2;
|
||||
/* 20 */ le_uint32_t iparam3;
|
||||
/* 24 */ le_uint32_t iparam4;
|
||||
/* 28 */ le_uint32_t iparam5;
|
||||
/* 2C */ le_uint32_t iparam6;
|
||||
/* 30 */
|
||||
} __packed_ws__(MovementData, 0x30);
|
||||
|
||||
struct Table {
|
||||
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats;
|
||||
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data;
|
||||
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data;
|
||||
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data;
|
||||
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats; // [difficulty][bp_index]
|
||||
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data; // [difficulty][bp_index]
|
||||
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data; // [difficulty][bp_index]
|
||||
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data; // [difficulty][bp_index]
|
||||
/* F600 */
|
||||
|
||||
const PlayerStats& stats_for_index(Difficulty difficulty, uint8_t index) const {
|
||||
return this->stats.at(static_cast<size_t>(difficulty)).at(index);
|
||||
}
|
||||
const AttackData& attack_data_for_index(Difficulty difficulty, uint8_t index) const {
|
||||
return this->attack_data.at(static_cast<size_t>(difficulty)).at(index);
|
||||
}
|
||||
const ResistData& resist_data_for_index(Difficulty difficulty, uint8_t index) const {
|
||||
return this->resist_data.at(static_cast<size_t>(difficulty)).at(index);
|
||||
}
|
||||
const MovementData& movement_data_for_index(Difficulty difficulty, uint8_t index) const {
|
||||
return this->movement_data.at(static_cast<size_t>(difficulty)).at(index);
|
||||
}
|
||||
|
||||
void print(FILE* stream, Episode episode) const;
|
||||
} __packed_ws__(Table, 0xF600);
|
||||
|
||||
|
||||
+20
-27
@@ -8,6 +8,7 @@
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
using namespace std;
|
||||
@@ -16,7 +17,7 @@ extern bool use_terminal_colors;
|
||||
|
||||
Channel::Channel(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color)
|
||||
@@ -31,7 +32,8 @@ void Channel::send(uint16_t cmd, uint32_t flag, bool silent) {
|
||||
this->send(cmd, flag, nullptr, 0, silent);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent) {
|
||||
void Channel::send(
|
||||
uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent) {
|
||||
if (!this->connected()) {
|
||||
channel_exceptions_log.warning_f("Attempted to send command on closed channel; dropping data");
|
||||
return;
|
||||
@@ -56,10 +58,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
|
||||
case Version::GC_EP3:
|
||||
case Version::XB_V3: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (this->crypt_out.get() &&
|
||||
(this->version != Version::DC_NTE) &&
|
||||
(this->version != Version::DC_11_2000) &&
|
||||
(this->version != Version::DC_V1)) {
|
||||
if (this->crypt_out.get() && !is_v1(this->version)) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
@@ -89,13 +88,11 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
|
||||
break;
|
||||
}
|
||||
case Version::BB_V4: {
|
||||
// BB has an annoying behavior here: command lengths must be multiples of
|
||||
// 4, but the actual data length must be a multiple of 8. If the size
|
||||
// field is not divisible by 8, 4 extra bytes are sent anyway. This
|
||||
// behavior only applies when encryption is enabled - any commands sent
|
||||
// before encryption is enabled have no size restrictions (except they
|
||||
// must include a full header and must fit in the client's receive
|
||||
// buffer), and no implicit extra bytes are sent.
|
||||
// BB has an annoying behavior here: command lengths must be multiples of 4, but the actual data length must be a
|
||||
// multiple of 8. If the size field is not divisible by 8, 4 extra bytes are sent anyway. This behavior only
|
||||
// applies when encryption is enabled - any commands sent before encryption is enabled have no size restrictions
|
||||
// (except they must include a full header and must fit in the client's receive buffer), and no implicit extra
|
||||
// bytes are sent.
|
||||
PSOCommandHeaderBB header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 7) & ~7;
|
||||
@@ -114,8 +111,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
|
||||
throw logic_error("unimplemented game version in send_command");
|
||||
}
|
||||
|
||||
// All versions of PSO I've seen (so far) have a receive buffer 0x7C00
|
||||
// bytes in size
|
||||
// All versions of PSO I've seen (so far) have a receive buffer 0x7C00 bytes in size
|
||||
if (send_data_size > 0x7C00) {
|
||||
throw runtime_error("outbound command too large");
|
||||
}
|
||||
@@ -131,8 +127,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
|
||||
print_color_escape(stderr, phosg::TerminalFormat::FG_YELLOW, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::END);
|
||||
}
|
||||
if (version == Version::BB_V4) {
|
||||
command_data_log.info_f("Sending to {} (version=BB command={:04X} flag={:08X})",
|
||||
this->name, cmd, flag);
|
||||
command_data_log.info_f("Sending to {} (version=BB command={:04X} flag={:08X})", this->name, cmd, flag);
|
||||
} else {
|
||||
command_data_log.info_f("Sending to {} (version={} command={:02X} flag={:02X})",
|
||||
this->name, phosg::name_for_enum(version), cmd, flag);
|
||||
@@ -186,9 +181,8 @@ asio::awaitable<Channel::Message> Channel::recv() {
|
||||
throw runtime_error("header size field is smaller than header");
|
||||
}
|
||||
|
||||
// If encryption is enabled, BB pads commands to 8-byte boundaries, and this
|
||||
// is not reflected in the size field. This logic does not occur if encryption
|
||||
// is not yet enabled.
|
||||
// If encryption is enabled, BB pads commands to 8-byte boundaries, and this is not reflected in the size field. This
|
||||
// logic does not occur if encryption is not yet enabled.
|
||||
size_t command_physical_size = (this->crypt_in.get() && (version == Version::BB_V4))
|
||||
? ((command_logical_size + 7) & ~7)
|
||||
: command_logical_size;
|
||||
@@ -197,10 +191,9 @@ asio::awaitable<Channel::Message> Channel::recv() {
|
||||
co_await this->recv_raw(command_data.data(), command_data.size());
|
||||
|
||||
if (this->crypt_in.get()) {
|
||||
// Some versions of PSO DC can send commands whose sizes are not a multiple
|
||||
// of 4, but the server is expected to always use a multiple of 4 bytes when
|
||||
// decrypting (the extra cipher bytes are lost). To emulate this behavior,
|
||||
// we have to round up the size for DC commands here.
|
||||
// Some versions of PSO DC can send commands whose sizes are not a multiple of 4, but the server is expected to
|
||||
// always use a multiple of 4 bytes when decrypting (the extra cipher bytes are lost). To emulate this behavior, we
|
||||
// have to round up the size for DC commands here.
|
||||
size_t orig_size = command_data.size();
|
||||
command_data.resize((orig_size + 3) & (~3), 0);
|
||||
this->crypt_in->decrypt(command_data.data(), command_data.size());
|
||||
@@ -249,7 +242,7 @@ shared_ptr<SocketChannel> SocketChannel::create(
|
||||
std::shared_ptr<asio::io_context> io_context,
|
||||
std::unique_ptr<asio::ip::tcp::socket>&& sock,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color) {
|
||||
@@ -263,7 +256,7 @@ SocketChannel::SocketChannel(
|
||||
std::shared_ptr<asio::io_context> io_context,
|
||||
std::unique_ptr<asio::ip::tcp::socket>&& sock,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color)
|
||||
@@ -331,7 +324,7 @@ asio::awaitable<void> SocketChannel::send_task() {
|
||||
PeerChannel::PeerChannel(
|
||||
std::shared_ptr<asio::io_context> io_context,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color)
|
||||
|
||||
+14
-21
@@ -12,7 +12,7 @@
|
||||
class Channel {
|
||||
public:
|
||||
Version version;
|
||||
uint8_t language;
|
||||
Language language;
|
||||
std::shared_ptr<PSOEncryption> crypt_in;
|
||||
std::shared_ptr<PSOEncryption> crypt_out;
|
||||
|
||||
@@ -60,9 +60,8 @@ public:
|
||||
// Returns whether the channel is connected or not.
|
||||
virtual bool connected() const = 0;
|
||||
|
||||
// Disconnects the channel. Any pending data will still be sent before the
|
||||
// underlying transport (e.g. socket) is closed, but further send calls will
|
||||
// do nothing.
|
||||
// Disconnects the channel. Any pending data will still be sent before the underlying transport (e.g. socket) is
|
||||
// closed, but further send calls will do nothing.
|
||||
virtual void disconnect() = 0;
|
||||
|
||||
// Sends a message with an automatically-constructed header.
|
||||
@@ -76,8 +75,7 @@ public:
|
||||
this->send(cmd, flag, &data, sizeof(data), silent);
|
||||
}
|
||||
|
||||
// Sends a message with a pre-existing header (as the first few bytes in the
|
||||
// data)
|
||||
// Sends a message with a pre-existing header (as the first few bytes in the data)
|
||||
void send(const void* data, size_t size, bool silent = false);
|
||||
void send(const std::string& data, bool silent = false);
|
||||
|
||||
@@ -87,7 +85,7 @@ public:
|
||||
protected:
|
||||
Channel(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name,
|
||||
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
|
||||
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
|
||||
@@ -96,31 +94,26 @@ protected:
|
||||
Channel& operator=(const Channel& other) = delete;
|
||||
Channel& operator=(Channel&& other) = delete;
|
||||
|
||||
// Sends raw data on the underlying transport. If the channel is already
|
||||
// disconnected, silently drops the data.
|
||||
// Sends raw data on the underlying transport. If the channel is already disconnected, silently drops the data.
|
||||
virtual void send_raw(std::string&& data) = 0;
|
||||
// Receives raw data on the underlying transport. Raises when the channel is
|
||||
// disconnected.
|
||||
// Receives raw data on the underlying transport. Raises when the channel is disconnected.
|
||||
virtual asio::awaitable<void> recv_raw(void* data, size_t size) = 0;
|
||||
};
|
||||
|
||||
// Standard channel type, used for most PSO clients. Represents an open TCP
|
||||
// socket.
|
||||
// Standard channel type, used for most PSO clients. Represents an open TCP socket.
|
||||
class SocketChannel : public Channel, public std::enable_shared_from_this<SocketChannel> {
|
||||
public:
|
||||
std::unique_ptr<asio::ip::tcp::socket> sock;
|
||||
asio::ip::tcp::endpoint local_addr;
|
||||
asio::ip::tcp::endpoint remote_addr;
|
||||
|
||||
// SocketChannel has a static constructor because it has an internal task,
|
||||
// which is necessary to support flushing before disconnection (for example)
|
||||
// and also to make send_raw not a coroutine, which keeps the rest of the
|
||||
// code cleaner. The task needs to hold a shared_ptr to the SocketChannel
|
||||
// whilc it's open
|
||||
// SocketChannel has a static constructor because it has an internal task, which is necessary to support flushing
|
||||
// before disconnection (for example) and also to make send_raw not a coroutine, which keeps the rest of the code
|
||||
// cleaner.
|
||||
static std::shared_ptr<SocketChannel> create(std::shared_ptr<asio::io_context> io_context,
|
||||
std::unique_ptr<asio::ip::tcp::socket>&& sock,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name = "",
|
||||
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
|
||||
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
|
||||
@@ -138,7 +131,7 @@ private:
|
||||
std::shared_ptr<asio::io_context> io_context,
|
||||
std::unique_ptr<asio::ip::tcp::socket>&& sock,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color);
|
||||
@@ -158,7 +151,7 @@ public:
|
||||
PeerChannel(
|
||||
std::shared_ptr<asio::io_context> io_context,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name = "",
|
||||
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
|
||||
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
|
||||
|
||||
+281
-124
@@ -1,5 +1,6 @@
|
||||
#include "ChatCommands.hh"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <filesystem>
|
||||
@@ -24,7 +25,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Tools
|
||||
|
||||
string str_for_flag_ranges(const vector<bool>& flags) {
|
||||
@@ -59,7 +60,7 @@ string str_for_flag_ranges(const vector<bool>& flags) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Checks
|
||||
|
||||
class precondition_failed {
|
||||
@@ -164,7 +165,7 @@ struct Args {
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Command definitions
|
||||
|
||||
struct ChatCommandDefinition {
|
||||
@@ -187,7 +188,7 @@ struct ChatCommandDefinition {
|
||||
|
||||
unordered_map<string, const ChatCommandDefinition*> ChatCommandDefinition::all_defs;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// All commands (in alphabetical order)
|
||||
|
||||
ChatCommandDefinition cc_allevent(
|
||||
@@ -264,8 +265,8 @@ ChatCommandDefinition cc_announce_rares(
|
||||
|
||||
a.c->login->account->toggle_user_flag(Account::UserFlag::DISABLE_DROP_NOTIFICATION_BROADCAST);
|
||||
a.c->login->account->save();
|
||||
send_text_message_fmt(a.c, "$C6Rare announcements\n{} for your\nitems",
|
||||
a.c->login->account->check_user_flag(Account::UserFlag::DISABLE_DROP_NOTIFICATION_BROADCAST) ? "disabled" : "enabled");
|
||||
bool enabled = a.c->login->account->check_user_flag(Account::UserFlag::DISABLE_DROP_NOTIFICATION_BROADCAST);
|
||||
send_text_message_fmt(a.c, "$C6Rare announcements\n{} for your\nitems", enabled ? "disabled" : "enabled");
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -369,9 +370,8 @@ ChatCommandDefinition cc_ban(
|
||||
throw precondition_failed("$C6You do not have\nsufficient privileges.");
|
||||
}
|
||||
if (a.c == target) {
|
||||
// This shouldn't be possible because you need BAN_USER to get here,
|
||||
// but the target can't have BAN_USER if we get here, so if a.c and
|
||||
// target are the same, one of the preceding conditions must be false.
|
||||
// This shouldn't be possible because you need BAN_USER to get here, but the target can't have BAN_USER if we
|
||||
// get here, so if a.c and target are the same, one of the preceding conditions must be false.
|
||||
throw logic_error("client attempts to ban themself");
|
||||
}
|
||||
|
||||
@@ -481,8 +481,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
dest_account = a.c->login->account;
|
||||
}
|
||||
|
||||
// If the client isn't BB, request the player info. (If they are BB, the
|
||||
// server already has it)
|
||||
// If the client isn't BB, request the player info. (If they are BB, the server already has it)
|
||||
GetPlayerInfoResult ch;
|
||||
if (a.c->version() == Version::BB_V4) {
|
||||
ch.character = a.c->character_file();
|
||||
@@ -515,8 +514,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
}
|
||||
|
||||
} else {
|
||||
// Client sent 61; generate a BB-format player from the information we have
|
||||
// and save that instead
|
||||
// Client sent 61; generate a BB-format player from the information we have and save that instead
|
||||
if (ch.character) {
|
||||
auto bb_player = PSOBBCharacterFile::create_from_config(
|
||||
a.c->login->account->account_id,
|
||||
@@ -527,9 +525,8 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
bb_player->disp.visual.version = 4;
|
||||
bb_player->disp.visual.name_color_checksum = 0x00000000;
|
||||
bb_player->inventory = ch.character->inventory;
|
||||
// Before V3, player stats can't be correctly computed from other fields
|
||||
// because material usage isn't stored anywhere. For these versions, we
|
||||
// have to trust the stats field from the player's data.
|
||||
// Before V3, player stats can't be correctly computed from other fields because material usage isn't stored
|
||||
// anywhere. For these versions, we have to trust the stats field from the player's data.
|
||||
auto level_table = s->level_table(a.c->version());
|
||||
if (is_v1_or_v2(a.c->version())) {
|
||||
bb_player->disp.stats = ch.character->disp.stats;
|
||||
@@ -921,7 +918,7 @@ ChatCommandDefinition cc_edit(
|
||||
p->disp.stats.experience = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "level" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.level = stoul(tokens.at(1)) - 1;
|
||||
p->recompute_stats(s->level_table(a.c->version()));
|
||||
p->recompute_stats(s->level_table(a.c->version()), true);
|
||||
} else if (((tokens.at(0) == "material") || (tokens.at(0) == "mat")) && !is_v1_or_v2(a.c->version()) && (cheats_allowed || !s->cheat_flags.reset_materials)) {
|
||||
if (tokens.at(1) == "reset") {
|
||||
const auto& which = tokens.at(2);
|
||||
@@ -959,14 +956,14 @@ ChatCommandDefinition cc_edit(
|
||||
} else {
|
||||
throw precondition_failed("$C6Invalid subcommand");
|
||||
}
|
||||
p->recompute_stats(s->level_table(a.c->version()));
|
||||
p->recompute_stats(s->level_table(a.c->version()), false);
|
||||
} else if (tokens.at(0) == "namecolor") {
|
||||
p->disp.visual.name_color = stoul(tokens.at(1), nullptr, 16);
|
||||
} else if (tokens.at(0) == "language" || tokens.at(0) == "lang") {
|
||||
if (tokens.at(1).size() != 1) {
|
||||
throw runtime_error("invalid language");
|
||||
}
|
||||
uint8_t new_language = language_code_for_char(tokens.at(1).at(0));
|
||||
Language new_language = language_for_char(tokens.at(1).at(0));
|
||||
a.c->channel->language = new_language;
|
||||
p->inventory.language = new_language;
|
||||
p->guild_card.language = new_language;
|
||||
@@ -985,7 +982,7 @@ ChatCommandDefinition cc_edit(
|
||||
p->disp.visual.section_id = secid;
|
||||
}
|
||||
} else if (tokens.at(0) == "name") {
|
||||
vector<string> orig_tokens = phosg::split(a.text, ' ');
|
||||
vector<string> orig_tokens = phosg::split(a.text, ' ', 1);
|
||||
p->disp.name.encode(orig_tokens.at(1), p->inventory.language);
|
||||
} else if (tokens.at(0) == "npc") {
|
||||
if (tokens.at(1) == "none") {
|
||||
@@ -1073,9 +1070,7 @@ ChatCommandDefinition cc_event(
|
||||
ChatCommandDefinition cc_exit(
|
||||
{"$exit"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
if (!(a.c->proxy_session
|
||||
? a.c->proxy_session->is_in_game
|
||||
: a.c->require_lobby()->is_game())) {
|
||||
if (!(a.c->proxy_session ? a.c->proxy_session->is_in_game : a.c->require_lobby()->is_game())) {
|
||||
// Client is in the lobby; send them to the login server (main menu)
|
||||
if (a.c->proxy_session) {
|
||||
if (is_v4(a.c->version())) {
|
||||
@@ -1103,14 +1098,12 @@ ChatCommandDefinition cc_exit(
|
||||
is_in_quest = a.c->proxy_session->is_in_quest;
|
||||
} else {
|
||||
auto l = a.c->require_lobby();
|
||||
is_in_quest = (l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS) ||
|
||||
l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS));
|
||||
is_in_quest = (l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS) || l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS));
|
||||
}
|
||||
if (is_in_quest) {
|
||||
// Client is in a quest; command 6x73 triggers game exit
|
||||
G_UnusedHeader cmd = {0x73, 0x01, 0x0000};
|
||||
a.c->channel->send(0x60, 0x00, cmd);
|
||||
a.c->floor = 0;
|
||||
co_return;
|
||||
}
|
||||
|
||||
@@ -1182,8 +1175,6 @@ ChatCommandDefinition cc_infhp(
|
||||
ChatCommandDefinition cc_inftime(
|
||||
{"$inftime"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
// TODO: We could implement this in proxy sessions by rewriting the rules
|
||||
// struct from the server in various 6xB4 commands.
|
||||
a.check_is_proxy(false);
|
||||
a.check_is_game(true);
|
||||
a.check_is_ep3(true);
|
||||
@@ -1233,17 +1224,25 @@ ChatCommandDefinition cc_item(
|
||||
a.check_cheats_enabled_or_allowed(s->cheat_flags.create_items);
|
||||
|
||||
ItemData item;
|
||||
bool was_enqueued = false;
|
||||
if (a.c->proxy_session) {
|
||||
if (a.c->version() == Version::BB_V4) {
|
||||
throw precondition_failed("$C6This command cannot\nbe used in proxy\nsessions in BB games");
|
||||
}
|
||||
a.check_is_leader();
|
||||
|
||||
item = s->parse_item_description(a.c->version(), a.text);
|
||||
item.id = phosg::random_object<uint32_t>() | 0x80000000;
|
||||
if (a.text.starts_with("!")) {
|
||||
item = s->parse_item_description(a.c->version(), a.text.substr(1));
|
||||
a.c->proxy_session->next_drop_item = item;
|
||||
was_enqueued = true;
|
||||
|
||||
send_drop_stacked_item_to_channel(s, a.c->channel, item, a.c->floor, a.c->pos);
|
||||
send_drop_stacked_item_to_channel(s, a.c->proxy_session->server_channel, item, a.c->floor, a.c->pos);
|
||||
} else {
|
||||
item = s->parse_item_description(a.c->version(), a.text);
|
||||
item.id = phosg::random_object<uint32_t>() | 0x80000000;
|
||||
|
||||
send_drop_stacked_item_to_channel(s, a.c->channel, item, a.c->floor, a.c->pos);
|
||||
send_drop_stacked_item_to_channel(s, a.c->proxy_session->server_channel, item, a.c->floor, a.c->pos);
|
||||
}
|
||||
|
||||
} else {
|
||||
auto l = a.c->require_lobby();
|
||||
@@ -1260,7 +1259,11 @@ ChatCommandDefinition cc_item(
|
||||
}
|
||||
|
||||
string name = s->describe_item(a.c->version(), item, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
send_text_message(a.c, "$C7Item created:\n" + name);
|
||||
if (was_enqueued) {
|
||||
send_text_message(a.c, "$C7Next item:\n" + name);
|
||||
} else {
|
||||
send_text_message(a.c, "$C7Item created:\n" + name);
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -1302,9 +1305,8 @@ ChatCommandDefinition cc_kick(
|
||||
throw precondition_failed("$C6You do not have\nsufficient privileges.");
|
||||
}
|
||||
if (a.c == target) {
|
||||
// This shouldn't be possible because you need KICK_USER to get here,
|
||||
// but the target can't have KICK_USER if we get here, so if a.c and
|
||||
// target are the same, one of the preceding conditions must be false.
|
||||
// This shouldn't be possible because you need KICK_USER to get here, but the target can't have KICK_USER if we
|
||||
// get here, so if a.c and target are the same, one of the preceding conditions must be false.
|
||||
throw logic_error("client attempts to kick themself off");
|
||||
}
|
||||
|
||||
@@ -1333,13 +1335,10 @@ ChatCommandDefinition cc_killcount(
|
||||
throw precondition_failed("No equipped items\nhave kill counts");
|
||||
|
||||
} else {
|
||||
// Kill counts are only accurate on the server side at all times on BB.
|
||||
// On other versions, we update the server's view of the client's
|
||||
// inventory during games, but we can't track kills because the client
|
||||
// doesn't inform the server whether it counted a kill for any
|
||||
// individual enemy. So, on non-BB versions, the kill count is accurate
|
||||
// at all times in the lobby (since kills can't occur there), or at the
|
||||
// beginning of a game.
|
||||
// Kill counts are only accurate on the server side at all times on BB. On other versions, we update the
|
||||
// server's view of the client's inventory during games, but we can't track kills because the client doesn't
|
||||
// inform the server whether it counted a kill for any individual enemy. So, on non-BB versions, the kill count
|
||||
// is accurate at all times in the lobby (since kills can't occur there), or at the beginning of a game.
|
||||
if ((a.c->version() == Version::BB_V4) || !a.c->require_lobby()->is_game()) {
|
||||
send_text_message(a.c, "As of now:");
|
||||
} else {
|
||||
@@ -1362,9 +1361,8 @@ ChatCommandDefinition cc_lobby_info(
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
if (a.c->proxy_session) {
|
||||
string msg;
|
||||
// On non-masked-GC sessions (BB), there is no remote Guild Card number, so we
|
||||
// don't show it. (The user can see it in the pause menu, unlike in masked-GC
|
||||
// sessions like GC.)
|
||||
// On non-masked-GC sessions (BB), there is no remote Guild Card number, so we don't show it. (The user can see
|
||||
// it in the pause menu, unlike in masked-GC sessions like GC.)
|
||||
if (a.c->proxy_session->remote_guild_card_number >= 0) {
|
||||
msg = std::format("$C7GC: $C6{}$C7\n", a.c->proxy_session->remote_guild_card_number);
|
||||
}
|
||||
@@ -1433,11 +1431,12 @@ ChatCommandDefinition cc_lobby_info(
|
||||
if (l->max_level == 0xFFFFFFFF) {
|
||||
lines.emplace_back(std::format("$C6{:08X}$C7 L$C6{}+$C7", l->lobby_id, l->min_level + 1));
|
||||
} else {
|
||||
lines.emplace_back(std::format(
|
||||
"$C6{:08X}$C7 L$C6{}-{}$C7", l->lobby_id, l->min_level + 1, l->max_level + 1));
|
||||
lines.emplace_back(std::format("$C6{:08X}$C7 L$C6{}-{}$C7", l->lobby_id, l->min_level + 1, l->max_level + 1));
|
||||
}
|
||||
uint8_t effective_section_id = l->effective_section_id();
|
||||
if (effective_section_id < 10) {
|
||||
lines.emplace_back(std::format("$C7Section ID: $C6{}$C7", name_for_section_id(effective_section_id)));
|
||||
}
|
||||
lines.emplace_back(std::format(
|
||||
"$C7Section ID: $C6{}$C7", name_for_section_id(l->effective_section_id())));
|
||||
|
||||
switch (l->drop_mode) {
|
||||
case ServerDropMode::DISABLED:
|
||||
@@ -1612,8 +1611,8 @@ ChatCommandDefinition cc_loadchar(
|
||||
}
|
||||
|
||||
} else {
|
||||
// On v1 and v2, the client will assign its character data from the lobby
|
||||
// join command, so it suffices to just resend the join notification.
|
||||
// On v1 and v2, the client will assign its character data from the lobby join command, so it suffices to just
|
||||
// resend the join notification.
|
||||
auto s = a.c->require_server_state();
|
||||
send_player_leave_notification(l, a.c->lobby_client_id);
|
||||
s->send_lobby_join_notifications(l, a.c);
|
||||
@@ -1621,6 +1620,97 @@ ChatCommandDefinition cc_loadchar(
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_makeobj(
|
||||
{"$makeobj"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_debug_enabled();
|
||||
|
||||
auto tokens = phosg::split(a.text, ' ');
|
||||
if (tokens.size() < 1) {
|
||||
throw runtime_error("not enough arguments");
|
||||
}
|
||||
|
||||
uint32_t base_type_high = stoul(tokens[0], nullptr, 0) << 16;
|
||||
VectorXYZF pos = a.c->pos;
|
||||
VectorXYZI angle{0, 0, 0};
|
||||
VectorXYZF param123{0, 0, 0};
|
||||
VectorXYZI param456{0, 0, 0};
|
||||
for (size_t z = 1; z < tokens.size(); z++) {
|
||||
auto subtokens = phosg::split(tokens[z], ':');
|
||||
if (subtokens.size() != 2 || subtokens[0].size() != 1) {
|
||||
throw runtime_error("invalid argument: " + tokens[z]);
|
||||
}
|
||||
switch (tolower(subtokens[0].front())) {
|
||||
case 'X':
|
||||
case 'x':
|
||||
pos.x = stof(subtokens[1]);
|
||||
break;
|
||||
case 'Y':
|
||||
case 'y':
|
||||
pos.y = stof(subtokens[1]);
|
||||
break;
|
||||
case 'Z':
|
||||
case 'z':
|
||||
pos.z = stof(subtokens[1]);
|
||||
break;
|
||||
case 'R':
|
||||
case 'r':
|
||||
angle.x = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
case 'P':
|
||||
case 'p':
|
||||
angle.y = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
case 'W':
|
||||
case 'w':
|
||||
angle.z = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
case '1':
|
||||
param123.x = stof(subtokens[1]);
|
||||
break;
|
||||
case '2':
|
||||
param123.y = stof(subtokens[1]);
|
||||
break;
|
||||
case '3':
|
||||
param123.z = stof(subtokens[1]);
|
||||
break;
|
||||
case '4':
|
||||
param456.x = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
case '5':
|
||||
param456.y = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
case '6':
|
||||
param456.z = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid argument: " + tokens[z]);
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> label_writes{
|
||||
{"base_type_high", base_type_high},
|
||||
{"floor_low", a.c->floor},
|
||||
{"pos_x", std::bit_cast<uint32_t>(pos.x.load())},
|
||||
{"pos_y", std::bit_cast<uint32_t>(pos.y.load())},
|
||||
{"pos_z", std::bit_cast<uint32_t>(pos.z.load())},
|
||||
{"angle_x", angle.x},
|
||||
{"angle_y", angle.y},
|
||||
{"angle_z", angle.z},
|
||||
{"param1", std::bit_cast<uint32_t>(param123.x.load())},
|
||||
{"param2", std::bit_cast<uint32_t>(param123.y.load())},
|
||||
{"param3", std::bit_cast<uint32_t>(param123.z.load())},
|
||||
{"param4", param456.x},
|
||||
{"param5", param456.y},
|
||||
{"param6", param456.z},
|
||||
};
|
||||
|
||||
co_await prepare_client_for_patches(a.c);
|
||||
auto s = a.c->require_server_state();
|
||||
auto fn = s->function_code_index->get_patch("CreateObject", a.c->specific_version);
|
||||
co_await send_function_call(a.c, fn, label_writes);
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_matcount(
|
||||
{"$matcount"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
@@ -1697,9 +1787,7 @@ ChatCommandDefinition cc_next(
|
||||
auto s = a.c->require_server_state();
|
||||
a.check_cheats_enabled_or_allowed(s->cheat_flags.warp);
|
||||
|
||||
auto episode = a.c->proxy_session
|
||||
? a.c->proxy_session->lobby_episode
|
||||
: a.c->require_lobby()->episode;
|
||||
auto episode = a.c->proxy_session ? a.c->proxy_session->lobby_episode : a.c->require_lobby()->episode;
|
||||
size_t limit = FloorDefinition::limit_for_episode(episode);
|
||||
if (limit > 0) {
|
||||
send_warp(a.c, (a.c->floor + 1) % limit, true);
|
||||
@@ -1738,16 +1826,33 @@ ChatCommandDefinition cc_patch(
|
||||
string patch_name = std::move(tokens[0]);
|
||||
unordered_map<string, uint32_t> label_writes;
|
||||
for (size_t z = 0; z < tokens.size() - 1; z++) {
|
||||
label_writes.emplace(std::format("arg{}", z), stoul(tokens[z + 1], nullptr, 0));
|
||||
const auto& token = tokens[z + 1];
|
||||
size_t equals_pos = token.find('=');
|
||||
string key, value;
|
||||
if (equals_pos == std::string::npos) {
|
||||
key = std::format("arg{}", z);
|
||||
value = token;
|
||||
} else {
|
||||
key = token.substr(0, equals_pos);
|
||||
value = token.substr(equals_pos + 1);
|
||||
}
|
||||
if (value.contains('.')) { // float
|
||||
label_writes.emplace(std::move(key), std::bit_cast<uint32_t>(stof(value, nullptr)));
|
||||
} else { // int
|
||||
label_writes.emplace(std::move(key), stoul(value, nullptr, 0));
|
||||
}
|
||||
}
|
||||
|
||||
co_await prepare_client_for_patches(a.c);
|
||||
try {
|
||||
auto s = a.c->require_server_state();
|
||||
// Note: We can't look this up before prepare_client_for_patches
|
||||
// because specific_version may not be set at that point
|
||||
// Note: We can't look this up before prepare_client_for_patches because specific_version may not be set
|
||||
auto fn = s->function_code_index->get_patch(patch_name, a.c->specific_version);
|
||||
co_await send_function_call(a.c, fn, label_writes);
|
||||
auto ret = co_await send_function_call(a.c, fn, label_writes);
|
||||
if (fn->show_return_value) {
|
||||
send_text_message_fmt(a.c, "$C6Return value:$C7\nInt: {}\nHex: {:08X}\nFloat: {:g}",
|
||||
ret.return_value.load(), ret.return_value.load(), std::bit_cast<float>(ret.return_value.load()));
|
||||
}
|
||||
} catch (const out_of_range&) {
|
||||
send_text_message(a.c, "$C6Invalid patch name");
|
||||
}
|
||||
@@ -1783,21 +1888,19 @@ ChatCommandDefinition cc_ping(
|
||||
if (a.c->proxy_session) {
|
||||
a.c->proxy_session->server_ping_start_time = a.c->ping_start_time;
|
||||
C_GuildCardSearch_40 cmd = {
|
||||
0x00010000,
|
||||
a.c->proxy_session->remote_guild_card_number,
|
||||
a.c->proxy_session->remote_guild_card_number};
|
||||
0x00010000, a.c->proxy_session->remote_guild_card_number, a.c->proxy_session->remote_guild_card_number};
|
||||
a.c->proxy_session->server_channel->send(0x40, 0x00, &cmd, sizeof(cmd));
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
|
||||
static string file_path_for_recording(const std::string& args, uint32_t account_id) {
|
||||
static string file_path_for_recording(const std::string& args, uint32_t account_id, bool compressed) {
|
||||
for (char ch : args) {
|
||||
if (ch <= 0x20 || ch > 0x7E || ch == '/') {
|
||||
throw runtime_error("invalid recording name");
|
||||
}
|
||||
}
|
||||
return std::format("system/ep3/battle-records/{:010}_{}.mzrd", account_id, args);
|
||||
return std::format("system/ep3/battle-records/{:010}_{}.mzr{}", account_id, args, compressed ? "" : "d");
|
||||
}
|
||||
|
||||
ChatCommandDefinition cc_playrec(
|
||||
@@ -1810,25 +1913,29 @@ ChatCommandDefinition cc_playrec(
|
||||
if (l->is_game() && l->battle_player) {
|
||||
l->battle_player->start();
|
||||
} else if (!l->is_game()) {
|
||||
string file_path = file_path_for_recording(a.text, a.c->login->account->account_id);
|
||||
|
||||
auto s = a.c->require_server_state();
|
||||
string filename = a.text;
|
||||
bool start_battle_player_immediately = (filename[0] == '!');
|
||||
if (start_battle_player_immediately) {
|
||||
bool start_battle_player_immediately = (filename.at(0) != '!');
|
||||
if (!start_battle_player_immediately) {
|
||||
filename = filename.substr(1);
|
||||
}
|
||||
|
||||
string data;
|
||||
try {
|
||||
data = phosg::load_file(file_path);
|
||||
data = phosg::load_file(file_path_for_recording(filename, a.c->login->account->account_id, false));
|
||||
} catch (const phosg::cannot_open_file&) {
|
||||
throw precondition_failed("$C4The recording does\nnot exist");
|
||||
try {
|
||||
data = prs_decompress(phosg::load_file(file_path_for_recording(
|
||||
filename, a.c->login->account->account_id, true)));
|
||||
} catch (const phosg::cannot_open_file&) {
|
||||
throw precondition_failed("$C4The recording does\nnot exist");
|
||||
}
|
||||
}
|
||||
auto record = make_shared<Episode3::BattleRecord>(data);
|
||||
auto battle_player = make_shared<Episode3::BattleRecordPlayer>(s->io_context, record);
|
||||
auto game = create_game_generic(
|
||||
s, a.c, a.text, "", Episode::EP3, GameMode::NORMAL, 0, false, nullptr, battle_player);
|
||||
s, a.c, filename, "", Episode::EP3, GameMode::NORMAL, Difficulty::NORMAL, false, nullptr, battle_player);
|
||||
if (game) {
|
||||
if (start_battle_player_immediately) {
|
||||
game->set_flag(Lobby::Flag::START_BATTLE_PLAYER_IMMEDIATELY);
|
||||
@@ -1919,8 +2026,8 @@ static void command_qset_qclear(const Args& a, bool should_set) {
|
||||
a.c->proxy_session->server_channel->send(0x60, 0x00, &cmd, sizeof(cmd));
|
||||
}
|
||||
} else {
|
||||
uint8_t difficulty = a.c->proxy_session ? a.c->proxy_session->lobby_difficulty : a.c->require_lobby()->difficulty;
|
||||
G_UpdateQuestFlag_V3_BB_6x75 cmd = {{{0x75, 0x03, 0x0000}, flag_num, should_set ? 0 : 1}, difficulty, 0x0000};
|
||||
Difficulty difficulty = a.c->proxy_session ? a.c->proxy_session->lobby_difficulty : a.c->require_lobby()->difficulty;
|
||||
G_UpdateQuestFlag_V3_BB_6x75 cmd = {{{0x75, 0x03, 0x0000}, flag_num, should_set ? 0 : 1}, static_cast<uint16_t>(difficulty), 0x0000};
|
||||
a.c->channel->send(0x60, 0x00, &cmd, sizeof(cmd));
|
||||
if (a.c->proxy_session) {
|
||||
a.c->proxy_session->server_channel->send(0x60, 0x00, &cmd, sizeof(cmd));
|
||||
@@ -2102,6 +2209,34 @@ ChatCommandDefinition cc_quest(
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_fastkill(
|
||||
{"$fastkill"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
if (!a.c->proxy_session) {
|
||||
a.check_is_game(true);
|
||||
}
|
||||
|
||||
if (a.c->check_flag(Client::Flag::FAST_KILLS_ENABLED)) {
|
||||
a.c->clear_flag(Client::Flag::FAST_KILLS_ENABLED);
|
||||
send_text_message(a.c, "$C6Fast kills disabled");
|
||||
} else {
|
||||
auto s = a.c->require_server_state();
|
||||
a.check_cheats_enabled_or_allowed(s->cheat_flags.fast_kills);
|
||||
a.c->set_flag(Client::Flag::FAST_KILLS_ENABLED);
|
||||
send_text_message(a.c, "$C6Fast kills enabled");
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
ChatCommandDefinition cc_allrare(
|
||||
{"$allrare"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_debug_enabled();
|
||||
a.c->toggle_flag(Client::Flag::ALL_RARES_ENABLED);
|
||||
send_text_message_fmt(
|
||||
a.c, "$C6All-rares {}", a.c->check_flag(Client::Flag::ALL_RARES_ENABLED) ? "enabled" : "disabled");
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_rand(
|
||||
{"$rand"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
@@ -2188,16 +2323,34 @@ ChatCommandDefinition cc_savechar(
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_savefiles(
|
||||
{"$savefiles"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_is_proxy(true);
|
||||
|
||||
auto s = a.c->require_server_state();
|
||||
if (!s->proxy_allow_save_files) {
|
||||
send_text_message(a.c, "$C6Save files is not\nallowed");
|
||||
} else if (a.c->check_flag(Client::Flag::PROXY_SAVE_FILES)) {
|
||||
a.c->clear_flag(Client::Flag::PROXY_SAVE_FILES);
|
||||
send_text_message(a.c, "$C6Save files disabled");
|
||||
} else {
|
||||
auto s = a.c->require_server_state();
|
||||
a.c->set_flag(Client::Flag::PROXY_SAVE_FILES);
|
||||
send_text_message(a.c, "$C6Save files enabled");
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_saverec(
|
||||
{"$saverec"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
// TODO: We can probably support this on the proxy server, but it would
|
||||
// only include CA commands from the local player
|
||||
// TODO: We can support this on the proxy server, but it would only include CA commands from the local player
|
||||
a.check_is_proxy(false);
|
||||
if (!a.c->ep3_prev_battle_record) {
|
||||
throw precondition_failed("$C4No finished\nrecording is\npresent");
|
||||
}
|
||||
string file_path = file_path_for_recording(a.text, a.c->login->account->account_id);
|
||||
string file_path = file_path_for_recording(a.text, a.c->login->account->account_id, false);
|
||||
string data = a.c->ep3_prev_battle_record->serialize();
|
||||
phosg::save_file(file_path, data);
|
||||
send_text_message(a.c, "$C7Recording saved");
|
||||
@@ -2205,14 +2358,18 @@ ChatCommandDefinition cc_saverec(
|
||||
co_return;
|
||||
});
|
||||
|
||||
static asio::awaitable<void> command_send_command(const Args& a, bool to_client, bool to_server) {
|
||||
static asio::awaitable<void> command_send_command(const Args& a, bool to_client, bool to_server, bool send_protected) {
|
||||
if (!a.c->proxy_session) {
|
||||
a.check_debug_enabled();
|
||||
}
|
||||
string data = phosg::parse_data_string(a.text);
|
||||
data.resize((data.size() + 3) & (~3));
|
||||
if (to_client) {
|
||||
a.c->channel->send(data);
|
||||
if (send_protected) {
|
||||
co_await send_protected_command(a.c, data.data(), data.size(), false);
|
||||
} else {
|
||||
a.c->channel->send(data);
|
||||
}
|
||||
}
|
||||
if (to_server) {
|
||||
if (a.c->proxy_session) {
|
||||
@@ -2227,13 +2384,19 @@ static asio::awaitable<void> command_send_command(const Args& a, bool to_client,
|
||||
ChatCommandDefinition cc_sb(
|
||||
{"$sb"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
return command_send_command(a, true, true);
|
||||
return command_send_command(a, true, true, false);
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_sc(
|
||||
{"$sc"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
return command_send_command(a, true, false);
|
||||
return command_send_command(a, true, false, false);
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_scp(
|
||||
{"$scp"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
return command_send_command(a, true, false, true);
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_secid(
|
||||
@@ -2339,7 +2502,7 @@ ChatCommandDefinition cc_silence(
|
||||
auto s = a.c->require_server_state();
|
||||
auto target = s->find_client(&a.text);
|
||||
if (!target->login) {
|
||||
// this should be impossible, but I'll bet it's not actually
|
||||
// This should be impossible, but I'll bet it's not actually
|
||||
throw precondition_failed("$C6Client not logged in");
|
||||
}
|
||||
|
||||
@@ -2374,7 +2537,7 @@ ChatCommandDefinition cc_sound(
|
||||
uint32_t sound_id = stoul(echo_to_all ? a.text.substr(1) : a.text, nullptr, 16);
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
uint8_t area = l->area_for_floor(a.c->version(), a.c->floor);
|
||||
uint8_t area = l->is_game() ? l->area_for_floor(a.c->version(), a.c->floor) : 0x0F;
|
||||
G_PlaySoundFromPlayer_6xB2 cmd = {{0xB2, 0x03, 0x0000}, area, 0x00, a.c->lobby_client_id, sound_id};
|
||||
if (!echo_to_all) {
|
||||
send_command_t(a.c, 0x60, 0x00, cmd);
|
||||
@@ -2399,9 +2562,8 @@ ChatCommandDefinition cc_spec(
|
||||
throw logic_error("Episode 3 client in non-Episode 3 game");
|
||||
}
|
||||
|
||||
// In non-tournament games, only the leader can do this; in a tournament
|
||||
// match, the players don't have control over who the leader is, so we allow
|
||||
// all players to use this command
|
||||
// In non-tournament games, only the leader can do this; in a tournament match, the players don't have control
|
||||
// over who the leader is, so we allow all players to use this command
|
||||
if (!l->tournament_match) {
|
||||
a.check_is_leader();
|
||||
}
|
||||
@@ -2428,7 +2590,7 @@ ChatCommandDefinition cc_spec(
|
||||
ChatCommandDefinition cc_ss(
|
||||
{"$ss"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
return command_send_command(a, false, true);
|
||||
return command_send_command(a, false, true, false);
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_stat(
|
||||
@@ -2549,8 +2711,8 @@ ChatCommandDefinition cc_swa(
|
||||
a.check_is_game(true);
|
||||
|
||||
a.c->toggle_flag(Client::Flag::SWITCH_ASSIST_ENABLED);
|
||||
send_text_message_fmt(a.c, "$C6Switch assist {}",
|
||||
a.c->check_flag(Client::Flag::SWITCH_ASSIST_ENABLED) ? "enabled" : "disabled");
|
||||
bool enabled = a.c->check_flag(Client::Flag::SWITCH_ASSIST_ENABLED);
|
||||
send_text_message_fmt(a.c, "$C6Switch assist {}", enabled ? "enabled" : "disabled");
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -2658,19 +2820,16 @@ ChatCommandDefinition cc_switchchar(
|
||||
throw precondition_failed("No character exists\nin that slot");
|
||||
}
|
||||
|
||||
a.c->save_and_unload_character();
|
||||
a.c->unload_character(true);
|
||||
a.c->bb_character_index = index;
|
||||
a.c->bb_bank_character_index = index;
|
||||
|
||||
// TODO: This can trigger a client bug where the previous character's
|
||||
// name label object isn't deleted if the leave and join notifications
|
||||
// are received on the same frame. This results in the receiving player
|
||||
// seeing both labels over the new character, with the latest one
|
||||
// appearing on top. We could fix this by requiring each recipient to
|
||||
// reply to a ping between the two commands, similar to how the 64 and
|
||||
// 6x6D commands are split during game joining, but implementing that
|
||||
// here seems not worth the effort given the low likelihood and impact of
|
||||
// this bug.
|
||||
// TODO: This can trigger a client bug where the previous character's name label object isn't deleted if the
|
||||
// leave and join notifications are received on the same frame. This results in the receiving player seeing both
|
||||
// labels over the new character, with the latest one appearing on top. We could fix this by requiring each
|
||||
// recipient to reply to a ping between the two commands, similar to how the 64 and 6x6D commands are split
|
||||
// during game joining, but implementing that here seems not worth the effort given the low likelihood and impact
|
||||
// of this bug.
|
||||
send_complete_player_bb(a.c);
|
||||
send_player_leave_notification(l, a.c->lobby_client_id);
|
||||
s->send_lobby_join_notifications(l, a.c);
|
||||
@@ -2697,17 +2856,19 @@ ChatCommandDefinition cc_unset(
|
||||
throw precondition_failed("$C6Battle has not\nyet begun");
|
||||
}
|
||||
|
||||
size_t index = stoull(a.text) - 1;
|
||||
l->ep3_server->force_destroy_field_character(a.c->lobby_client_id, index);
|
||||
size_t index = stoull(a.text);
|
||||
if (index == 0) {
|
||||
l->ep3_server->force_replace_assist_card(a.c->lobby_client_id, 0xFFFF);
|
||||
} else {
|
||||
l->ep3_server->force_destroy_field_character(a.c->lobby_client_id, index - 1);
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
|
||||
ChatCommandDefinition cc_variations(
|
||||
{"$variations"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
// Note: This command is intentionally undocumented, since it's primarily used
|
||||
// for testing. If we ever make it public, we should add some kind of user
|
||||
// feedback (currently it sends no message when it runs).
|
||||
// Note: This command is intentionally undocumented, since it's primarily used for testing
|
||||
a.check_is_proxy(false);
|
||||
a.check_is_game(false);
|
||||
auto s = a.c->require_server_state();
|
||||
@@ -2737,9 +2898,7 @@ static void command_warp(const Args& a, bool is_warpall) {
|
||||
return;
|
||||
}
|
||||
|
||||
Episode episode = a.c->proxy_session
|
||||
? a.c->proxy_session->lobby_episode
|
||||
: a.c->require_lobby()->episode;
|
||||
Episode episode = a.c->proxy_session ? a.c->proxy_session->lobby_episode : a.c->require_lobby()->episode;
|
||||
size_t limit = FloorDefinition::limit_for_episode(episode);
|
||||
if (limit == 0) {
|
||||
return;
|
||||
@@ -2805,15 +2964,16 @@ ChatCommandDefinition cc_what(
|
||||
throw precondition_failed("$C4No items are near you");
|
||||
} else {
|
||||
auto s = a.c->require_server_state();
|
||||
string name = s->describe_item(a.c->version(), nearest_fi->data, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
string name = s->describe_item(
|
||||
a.c->version(), nearest_fi->data, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
send_text_message(a.c, name);
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
|
||||
static void whatobj_whatene_fn(const Args& a, bool include_objs, bool include_enes) {
|
||||
// TODO: This probably wouldn't be too hard to implement for proxy sessions.
|
||||
// We already have the map and most of the lobby metadata (episode, etc.)
|
||||
// TODO: This probably wouldn't be too hard to implement for proxy sessions. We already have the map and most of the
|
||||
// lobby metadata (episode, etc.)
|
||||
a.check_is_proxy(false);
|
||||
a.check_is_game(true);
|
||||
auto l = a.c->require_lobby();
|
||||
@@ -2880,14 +3040,14 @@ static void whatobj_whatene_fn(const Args& a, bool include_objs, bool include_en
|
||||
}
|
||||
}
|
||||
|
||||
// Since we check all objects first, nearest_ene will only be set if
|
||||
// there is an enemy closer than all objects. So, we print that if it's
|
||||
// set, and print the object if not.
|
||||
// Since we check all objects first, nearest_ene will only be set if there is an enemy closer than all objects. So,
|
||||
// we print that if it's set, and print the object if not.
|
||||
if (nearest_ene) {
|
||||
const auto* set_entry = nearest_ene->super_ene->version(a.c->version()).set_entry;
|
||||
string type_name = MapFile::name_for_enemy_type(set_entry->base_type, a.c->version(), area);
|
||||
uint8_t area = l->area_for_floor(a.c->version(), a.c->floor);
|
||||
send_text_message_fmt(a.c, "$C5E-{:03X}\n$C6{}\n$C2{}\n$C7X:{:.2f} Z:{:.2f}",
|
||||
nearest_ene->e_id, phosg::name_for_enum(nearest_ene->type(a.c->version(), l->episode, l->event)),
|
||||
nearest_ene->e_id, phosg::name_for_enum(nearest_ene->type(a.c->version(), area, l->difficulty, l->event)),
|
||||
type_name, nearest_worldspace_pos.x, nearest_worldspace_pos.z);
|
||||
auto set_str = set_entry->str(a.c->version(), area);
|
||||
a.c->log.info_f("Enemy found via $whatobj: E-{:03X} {} at x={:g} y={:g} z={:g}",
|
||||
@@ -2998,10 +3158,9 @@ ChatCommandDefinition cc_nativecall(
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_debug_enabled();
|
||||
|
||||
// TODO: $nativecall is not implemented on x86 (yet) because there are
|
||||
// multiple calling conventions used within the executable (at least on
|
||||
// Xbox and BB), so we would need a way to specify which calling
|
||||
// convention to use, which would be annoying
|
||||
// TODO: $nativecall is not implemented on x86 (yet) because there are multiple calling conventions used within
|
||||
// the executable (at least on Xbox and BB), so we would need a way to specify which calling convention to use,
|
||||
// which would be annoying
|
||||
if (is_x86(a.c->version())) {
|
||||
throw precondition_failed("Command not supported\non x86 clients");
|
||||
}
|
||||
@@ -3038,7 +3197,7 @@ ChatCommandDefinition cc_nativecall(
|
||||
co_return;
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Dispatch methods
|
||||
|
||||
struct SplitCommand {
|
||||
@@ -3056,16 +3215,14 @@ struct SplitCommand {
|
||||
}
|
||||
};
|
||||
|
||||
// This function is called every time any player sends a chat beginning with a
|
||||
// dollar sign. It is this function's responsibility to see if the chat is a
|
||||
// command, and to execute the command and block the chat if it is.
|
||||
// This function is called every time any player sends a chat message beginning with $. It is this function's
|
||||
// responsibility to see if the chat is a command, and to execute the command and block the chat if it is.
|
||||
asio::awaitable<void> on_chat_command(std::shared_ptr<Client> c, const std::string& text, bool check_permissions) {
|
||||
SplitCommand cmd(text);
|
||||
|
||||
// This function is only called by on_06 if it looks like a chat command
|
||||
// (starts with $, or @ on 11/2000), so we just normalize all commands to $
|
||||
// here
|
||||
if (!cmd.name.empty() && cmd.name[0] == '@') {
|
||||
// This function is only called by on_06 if it looks like a chat command (starts with $, or @ on 11/2000, or
|
||||
// s->chat_command_sentinel if overridden), so we just normalize all commands to $ here
|
||||
if (!cmd.name.empty()) {
|
||||
cmd.name[0] = '$';
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ struct ChoiceSearchConfigT {
|
||||
return ret;
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
|
||||
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
|
||||
check_struct_size(ChoiceSearchConfig, 0x18);
|
||||
|
||||
+156
-126
@@ -25,8 +25,7 @@ static atomic<uint64_t> next_id(1);
|
||||
void Client::set_flags_for_version(Version version, int64_t sub_version) {
|
||||
this->set_flag(Flag::PROXY_CHAT_COMMANDS_ENABLED);
|
||||
|
||||
// BB shares some sub_version values with GC Episode 3, so we handle it
|
||||
// separately first.
|
||||
// BB shares some sub_version values with GC Episode 3, so we handle it separately first.
|
||||
if (version == Version::BB_V4) {
|
||||
this->set_flag(Flag::NO_D6);
|
||||
this->set_flag(Flag::SAVE_ENABLED);
|
||||
@@ -72,8 +71,8 @@ void Client::set_flags_for_version(Version version, int64_t sub_version) {
|
||||
break;
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3:
|
||||
// Some of these versions have send_function_call and some don't; we
|
||||
// have to set these flags later when we get sub_version
|
||||
// Some of these versions have send_function_call and some don't; we have to set these flags later when we
|
||||
// get sub_version
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
// TODO: Do all versions of XB need this flag? US does, at least.
|
||||
@@ -142,8 +141,8 @@ void Client::set_flags_for_version(Version version, int64_t sub_version) {
|
||||
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
|
||||
// instead look at header.flag in the 61 command and set the version then.
|
||||
// sub_version can't be used to tell JP final and Trial Edition apart; we instead look at header.flag in the 61
|
||||
// command and set the version then.
|
||||
break;
|
||||
case 0x41: // GC Ep3 US (and BB, but BB is handled above)
|
||||
case 0x42: // GC Ep3 EU 50Hz
|
||||
@@ -191,9 +190,8 @@ Client::Client(
|
||||
should_update_play_time(false) {
|
||||
this->update_channel_name();
|
||||
|
||||
// Don't print data sent to patch clients to the logs. The patch server
|
||||
// protocol is fully understood and data logs for patch clients are generally
|
||||
// more annoying than helpful at this point.
|
||||
// Don't print data sent to patch clients to the logs. The patch server protocol is fully understood and data logs
|
||||
// for patch clients are generally more annoying than helpful at this point.
|
||||
auto s = server->get_state();
|
||||
if (is_patch(this->version()) && s->hide_download_commands) {
|
||||
this->channel->terminal_recv_color = phosg::TerminalFormat::END;
|
||||
@@ -212,9 +210,8 @@ Client::Client(
|
||||
this->reschedule_save_game_data_timer();
|
||||
this->reschedule_ping_and_timeout_timers();
|
||||
|
||||
// Don't print data sent to patch clients to the logs. The patch server
|
||||
// protocol is fully understood and data logs for patch clients are generally
|
||||
// more annoying than helpful at this point.
|
||||
// Don't print data sent to patch clients to the logs. The patch server protocol is fully understood and data logs
|
||||
// for patch clients are generally more annoying than helpful at this point.
|
||||
if ((s->hide_download_commands) &&
|
||||
((this->version() == Version::PC_PATCH) || (this->version() == Version::BB_PATCH))) {
|
||||
this->channel->terminal_recv_color = phosg::TerminalFormat::END;
|
||||
@@ -262,7 +259,7 @@ void Client::reschedule_save_game_data_timer() {
|
||||
this->save_game_data_timer.expires_after(std::chrono::seconds(60));
|
||||
this->save_game_data_timer.async_wait([this](std::error_code ec) {
|
||||
if (!ec) {
|
||||
if (this->character_file(false)) {
|
||||
if (this->login && this->character_file(false)) {
|
||||
this->save_all();
|
||||
}
|
||||
this->reschedule_save_game_data_timer();
|
||||
@@ -298,9 +295,8 @@ void Client::reschedule_ping_and_timeout_timers() {
|
||||
}
|
||||
|
||||
void Client::convert_account_to_temporary_if_nte() {
|
||||
// If the session is a prototype version and the account was created and we
|
||||
// should use a temporary account instead, delete the permanent account and
|
||||
// replace it with a temporary account.
|
||||
// If the session is a prototype version and the account was created and we should use a temporary account instead,
|
||||
// delete the permanent account and replace it with a temporary account.
|
||||
auto s = this->require_server_state();
|
||||
if (s->use_temp_accounts_for_prototypes && this->login->account_was_created && is_any_nte(this->version())) {
|
||||
this->log.info_f("Client is a prototype version and the account was created during this session; converting permanent account to temporary account");
|
||||
@@ -353,8 +349,7 @@ shared_ptr<const TeamIndex::Team> Client::team() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The team membership is valid, but the player name may be different; update
|
||||
// the team membership if needed
|
||||
// The team membership is valid, but the player name may be different; update the team membership if needed
|
||||
if (p) {
|
||||
auto& m = member_it->second;
|
||||
string name = p->disp.name.decode(this->language());
|
||||
@@ -371,7 +366,7 @@ bool Client::evaluate_quest_availability_expression(
|
||||
shared_ptr<const IntegralExpression> expr,
|
||||
shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const {
|
||||
if (this->login && this->login->account->check_flag(Account::Flag::DISABLE_QUEST_REQUIREMENTS)) {
|
||||
@@ -385,7 +380,7 @@ bool Client::evaluate_quest_availability_expression(
|
||||
}
|
||||
auto p = this->character_file();
|
||||
IntegralExpression::Env env = {
|
||||
.flags = &p->quest_flags.data.at(difficulty),
|
||||
.flags = &p->quest_flags.data.at(static_cast<size_t>(difficulty)),
|
||||
.challenge_records = &p->challenge_records,
|
||||
.team = this->team(),
|
||||
.num_players = num_players,
|
||||
@@ -404,7 +399,7 @@ bool Client::can_see_quest(
|
||||
shared_ptr<const Quest> q,
|
||||
shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const {
|
||||
if (!q->has_version_any_language(this->version())) {
|
||||
@@ -418,13 +413,13 @@ bool Client::can_play_quest(
|
||||
shared_ptr<const Quest> q,
|
||||
shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const {
|
||||
if (!q->has_version_any_language(this->version())) {
|
||||
return false;
|
||||
}
|
||||
if (num_players > q->meta.max_players) {
|
||||
if ((q->meta.max_players > 0) && (num_players > q->meta.max_players)) {
|
||||
return false;
|
||||
}
|
||||
return this->evaluate_quest_availability_expression(
|
||||
@@ -563,6 +558,9 @@ shared_ptr<PSOBBCharacterFile> Client::character_file(bool allow_load, bool allo
|
||||
throw runtime_error("character index not specified");
|
||||
}
|
||||
this->load_all_files();
|
||||
if (!this->character_data) {
|
||||
throw std::runtime_error("none of the corresponding character files exist");
|
||||
}
|
||||
}
|
||||
return this->character_data;
|
||||
}
|
||||
@@ -598,8 +596,8 @@ void Client::save_character_file() {
|
||||
throw logic_error("no character file loaded");
|
||||
}
|
||||
if (this->should_update_play_time) {
|
||||
// This is slightly inaccurate, since fractions of a second are truncated
|
||||
// off each time we save. I'm lazy, so insert shrug emoji here.
|
||||
// This is slightly inaccurate, since fractions of a second are truncated off each time we save. I'm lazy, so
|
||||
// insert shrug emoji here
|
||||
uint64_t t = phosg::now();
|
||||
uint64_t seconds = (t - this->last_play_time_update) / 1000000;
|
||||
this->character_data->play_time_seconds += seconds;
|
||||
@@ -618,11 +616,15 @@ void Client::save_character_file() {
|
||||
|
||||
void Client::create_character_file(
|
||||
uint32_t guild_card_number,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const PlayerDispDataBBPreview& preview,
|
||||
shared_ptr<const LevelTable> level_table) {
|
||||
this->log.info_f("Creating new character file");
|
||||
this->character_data = PSOBBCharacterFile::create_from_preview(guild_card_number, language, preview, level_table);
|
||||
this->save_character_file();
|
||||
this->log.info_f("Deleting bank file");
|
||||
this->bank_data.reset();
|
||||
std::filesystem::remove(this->bank_filename());
|
||||
}
|
||||
|
||||
void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_ptr<const LevelTable> level_table) {
|
||||
@@ -639,8 +641,7 @@ void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_p
|
||||
this->overlay_character_data->inventory.remove_all_items_of_type(3);
|
||||
}
|
||||
if (rules->replace_char) {
|
||||
// TODO: Shouldn't we clear other material usage here? It looks like the
|
||||
// original code doesn't, but that seems wrong.
|
||||
// TODO: Shouldn't we clear other material usage here? Looks like the original code doesn't, but that seems wrong.
|
||||
this->overlay_character_data->inventory.hp_from_materials = 0;
|
||||
this->overlay_character_data->inventory.tp_from_materials = 0;
|
||||
|
||||
@@ -675,7 +676,8 @@ void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_p
|
||||
}
|
||||
}
|
||||
|
||||
void Client::create_challenge_overlay(Version version, size_t template_index, shared_ptr<const LevelTable> level_table) {
|
||||
void Client::create_challenge_overlay(
|
||||
Version version, size_t template_index, shared_ptr<const LevelTable> level_table) {
|
||||
auto p = this->character_file(true, false);
|
||||
const auto& tpl = get_challenge_template_definition(version, p->disp.visual.class_flags, template_index);
|
||||
|
||||
@@ -697,9 +699,11 @@ void Client::create_challenge_overlay(Version version, size_t template_index, sh
|
||||
level_table->reset_to_base(overlay->disp.stats, overlay->disp.visual.char_class);
|
||||
level_table->advance_to_level(overlay->disp.stats, tpl.level, overlay->disp.visual.char_class);
|
||||
|
||||
const auto& stats_delta = level_table->stats_delta_for_level(
|
||||
overlay->disp.visual.char_class, overlay->disp.stats.level);
|
||||
overlay->disp.stats.esp = 40;
|
||||
overlay->disp.stats.unknown_a3 = 10.0;
|
||||
overlay->disp.stats.experience = level_table->stats_delta_for_level(overlay->disp.visual.char_class, overlay->disp.stats.level).experience;
|
||||
overlay->disp.stats.attack_range = 10.0;
|
||||
overlay->disp.stats.experience = stats_delta.experience;
|
||||
overlay->disp.stats.meseta = 0;
|
||||
overlay->clear_all_material_usage();
|
||||
for (size_t z = 0; z < 0x13; z++) {
|
||||
@@ -759,14 +763,13 @@ std::shared_ptr<PlayerBank> Client::bank_file(bool allow_load) {
|
||||
this->bank_data->load(f.get());
|
||||
this->log.info_f("Loaded bank data from {}", filename);
|
||||
} catch (const phosg::cannot_open_file&) {
|
||||
// If there isn't a psobank file, use the loaded character data if the
|
||||
// bank character index matches the current character index (that is, we
|
||||
// should use the current character's bank); otherwise, load the
|
||||
// corresponding character and parse the bank from that character file
|
||||
// If there isn't a psobank file, use the loaded character data if the bank character index matches the current
|
||||
// character index (that is, we should use the current character's bank); otherwise, load the corresponding
|
||||
// character and parse the bank from that character file
|
||||
if (this->bb_bank_character_index == this->bb_character_index) {
|
||||
this->bank_data = std::make_shared<PlayerBank>(this->character_file(true, false)->bank);
|
||||
this->log.info_f("Using bank data from loaded character");
|
||||
} else {
|
||||
} else if (this->bb_bank_character_index >= 0) {
|
||||
if (!this->login || !this->login->bb_license) {
|
||||
throw logic_error("client is not logged in");
|
||||
}
|
||||
@@ -774,12 +777,17 @@ std::shared_ptr<PlayerBank> Client::bank_file(bool allow_load) {
|
||||
auto character = PSOCHARFile::load_shared(filename, false).character_file;
|
||||
this->bank_data = std::make_shared<PlayerBank>(character->bank);
|
||||
this->log.info_f("Using bank data from {}", filename);
|
||||
} else {
|
||||
// The shared bank doesn't exist; make a new one
|
||||
this->bank_data = make_shared<PlayerBank>();
|
||||
this->log.info_f("Created new shared bank");
|
||||
}
|
||||
}
|
||||
|
||||
auto s = this->require_server_state();
|
||||
this->bank_data->max_items = s->bb_max_bank_items;
|
||||
this->bank_data->max_meseta = s->bb_max_bank_meseta;
|
||||
this->update_bank_data_after_load(this->bank_data);
|
||||
}
|
||||
return this->bank_data;
|
||||
}
|
||||
@@ -867,28 +875,24 @@ void Client::load_all_files() {
|
||||
throw logic_error("cannot load BB player data until client is logged in");
|
||||
}
|
||||
|
||||
this->system_data.reset();
|
||||
this->character_data.reset();
|
||||
this->guild_card_data.reset();
|
||||
this->bank_data.reset();
|
||||
|
||||
string sys_filename = this->system_filename();
|
||||
if (std::filesystem::is_regular_file(sys_filename)) {
|
||||
this->system_data = make_shared<PSOBBBaseSystemFile>(phosg::load_object_file<PSOBBBaseSystemFile>(sys_filename, true));
|
||||
this->log.info_f("Loaded system data from {}", sys_filename);
|
||||
} else {
|
||||
this->log.info_f("System file is missing: {}", sys_filename);
|
||||
if (!this->system_data) {
|
||||
string sys_filename = this->system_filename();
|
||||
if (std::filesystem::is_regular_file(sys_filename)) {
|
||||
this->system_data = make_shared<PSOBBBaseSystemFile>(phosg::load_object_file<PSOBBBaseSystemFile>(sys_filename, true));
|
||||
this->log.info_f("Loaded system data from {}", sys_filename);
|
||||
} else {
|
||||
this->log.info_f("System file is missing: {}", sys_filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->bb_character_index >= 0) {
|
||||
if (!this->character_data && (this->bb_character_index >= 0)) {
|
||||
string char_filename = this->character_filename();
|
||||
if (std::filesystem::is_regular_file(char_filename)) {
|
||||
auto psochar = PSOCHARFile::load_shared(char_filename, !this->system_data);
|
||||
this->character_data = psochar.character_file;
|
||||
this->log.info_f("Loaded character data from {}", char_filename);
|
||||
|
||||
// If there was no .psosys file, use the system file from the .psochar
|
||||
// file instead
|
||||
// If there was no .psosys file, use the system file from the .psochar file instead
|
||||
if (!this->system_data) {
|
||||
if (!psochar.system_file) {
|
||||
throw logic_error("account system data not present, and also not loaded from psochar file");
|
||||
@@ -905,15 +909,18 @@ void Client::load_all_files() {
|
||||
}
|
||||
}
|
||||
|
||||
string card_filename = this->guild_card_filename();
|
||||
if (std::filesystem::is_regular_file(card_filename)) {
|
||||
this->guild_card_data = make_shared<PSOBBGuildCardFile>(phosg::load_object_file<PSOBBGuildCardFile>(card_filename));
|
||||
this->log.info_f("Loaded Guild Card data from {}", card_filename);
|
||||
} else {
|
||||
this->log.info_f("Guild Card file is missing: {}", card_filename);
|
||||
if (!this->guild_card_data) {
|
||||
string card_filename = this->guild_card_filename();
|
||||
if (std::filesystem::is_regular_file(card_filename)) {
|
||||
this->guild_card_data = make_shared<PSOBBGuildCardFile>(phosg::load_object_file<PSOBBGuildCardFile>(card_filename));
|
||||
this->guild_card_data->delete_duplicates();
|
||||
this->log.info_f("Loaded Guild Card data from {}", card_filename);
|
||||
} else {
|
||||
this->log.info_f("Guild Card file is missing: {}", card_filename);
|
||||
}
|
||||
}
|
||||
|
||||
// If any of the above files were missing, try to load from .nsa/.nsc files instead
|
||||
// If any of the above files are still missing, try to load from .nsa/.nsc files instead
|
||||
if (!this->system_data || (!this->character_data && (this->bb_character_index >= 0)) || !this->guild_card_data) {
|
||||
string nsa_filename = this->legacy_account_filename();
|
||||
shared_ptr<LegacySavedAccountDataBB> nsa_data;
|
||||
@@ -932,103 +939,122 @@ void Client::load_all_files() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->system_data) {
|
||||
this->system_data = make_shared<PSOBBBaseSystemFile>();
|
||||
auto s = this->require_server_state();
|
||||
if (s->bb_default_keyboard_config) {
|
||||
this->system_data->key_config = *s->bb_default_keyboard_config;
|
||||
}
|
||||
if (s->bb_default_joystick_config) {
|
||||
this->system_data->joystick_config = *s->bb_default_joystick_config;
|
||||
}
|
||||
this->log.info_f("Created new system data");
|
||||
}
|
||||
if (!this->guild_card_data) {
|
||||
this->guild_card_data = make_shared<PSOBBGuildCardFile>();
|
||||
this->log.info_f("Created new Guild Card data");
|
||||
}
|
||||
|
||||
if (!this->character_data && (this->bb_character_index >= 0)) {
|
||||
string nsc_filename = this->legacy_player_filename();
|
||||
auto nsc_data = phosg::load_object_file<LegacySavedPlayerDataBB>(nsc_filename);
|
||||
if (nsc_data.signature == LegacySavedPlayerDataBB::SIGNATURE_V0) {
|
||||
nsc_data.signature = LegacySavedPlayerDataBB::SIGNATURE_V0;
|
||||
nsc_data.unused.clear();
|
||||
nsc_data.battle_records.place_counts.clear(0);
|
||||
nsc_data.battle_records.disconnect_count = 0;
|
||||
nsc_data.battle_records.unknown_a1.clear(0);
|
||||
} else if (nsc_data.signature != LegacySavedPlayerDataBB::SIGNATURE_V1) {
|
||||
throw runtime_error("legacy player data has incorrect signature");
|
||||
}
|
||||
if (std::filesystem::is_regular_file(nsc_filename)) {
|
||||
auto nsc_data = phosg::load_object_file<LegacySavedPlayerDataBB>(nsc_filename);
|
||||
if (nsc_data.signature == LegacySavedPlayerDataBB::SIGNATURE_V0) {
|
||||
nsc_data.signature = LegacySavedPlayerDataBB::SIGNATURE_V0;
|
||||
nsc_data.unused.clear();
|
||||
nsc_data.battle_records.place_counts.clear(0);
|
||||
nsc_data.battle_records.disconnect_count = 0;
|
||||
nsc_data.battle_records.unknown_a1.clear(0);
|
||||
} else if (nsc_data.signature != LegacySavedPlayerDataBB::SIGNATURE_V1) {
|
||||
throw runtime_error("legacy player data has incorrect signature");
|
||||
}
|
||||
|
||||
this->character_data = make_shared<PSOBBCharacterFile>();
|
||||
this->character_data->inventory = nsc_data.inventory;
|
||||
this->character_data->disp = nsc_data.disp;
|
||||
this->character_data->play_time_seconds = 0;
|
||||
this->character_data->quest_flags = nsc_data.quest_flags;
|
||||
this->character_data->death_count = nsc_data.death_count;
|
||||
this->character_data->bank = nsc_data.bank;
|
||||
this->character_data->guild_card.guild_card_number = this->login->account->account_id;
|
||||
this->character_data->guild_card.name = nsc_data.disp.name;
|
||||
this->character_data->guild_card.description = nsc_data.guild_card_description;
|
||||
this->character_data->guild_card.present = 1;
|
||||
this->character_data->guild_card.language = nsc_data.inventory.language;
|
||||
this->character_data->guild_card.section_id = nsc_data.disp.visual.section_id;
|
||||
this->character_data->guild_card.char_class = nsc_data.disp.visual.char_class;
|
||||
this->character_data->auto_reply = nsc_data.auto_reply;
|
||||
this->character_data->info_board = nsc_data.info_board;
|
||||
this->character_data->battle_records = nsc_data.battle_records;
|
||||
this->character_data->challenge_records = nsc_data.challenge_records;
|
||||
this->character_data->tech_menu_shortcut_entries = nsc_data.tech_menu_shortcut_entries;
|
||||
this->character_data->quest_counters = nsc_data.quest_counters;
|
||||
if (nsa_data) {
|
||||
this->character_data->option_flags = nsa_data->option_flags;
|
||||
this->character_data->symbol_chats = nsa_data->symbol_chats;
|
||||
this->character_data->shortcuts = nsa_data->shortcuts;
|
||||
this->log.info_f("Loaded legacy player data from {} and {}", nsa_filename, nsc_filename);
|
||||
} else {
|
||||
this->log.info_f("Loaded legacy player data from {}", nsc_filename);
|
||||
this->character_data = make_shared<PSOBBCharacterFile>();
|
||||
this->character_data->inventory = nsc_data.inventory;
|
||||
this->character_data->disp = nsc_data.disp;
|
||||
this->character_data->play_time_seconds = 0;
|
||||
this->character_data->quest_flags = nsc_data.quest_flags;
|
||||
this->character_data->death_count = nsc_data.death_count;
|
||||
this->character_data->bank = nsc_data.bank;
|
||||
this->character_data->guild_card.guild_card_number = this->login->account->account_id;
|
||||
this->character_data->guild_card.name = nsc_data.disp.name;
|
||||
this->character_data->guild_card.description = nsc_data.guild_card_description;
|
||||
this->character_data->guild_card.present = 1;
|
||||
this->character_data->guild_card.language = nsc_data.inventory.language;
|
||||
this->character_data->guild_card.section_id = nsc_data.disp.visual.section_id;
|
||||
this->character_data->guild_card.char_class = nsc_data.disp.visual.char_class;
|
||||
this->character_data->auto_reply = nsc_data.auto_reply;
|
||||
this->character_data->info_board = nsc_data.info_board;
|
||||
this->character_data->battle_records = nsc_data.battle_records;
|
||||
this->character_data->challenge_records = nsc_data.challenge_records;
|
||||
this->character_data->tech_menu_shortcut_entries = nsc_data.tech_menu_shortcut_entries;
|
||||
this->character_data->quest_counters = nsc_data.quest_counters;
|
||||
if (nsa_data) {
|
||||
this->character_data->option_flags = nsa_data->option_flags;
|
||||
this->character_data->symbol_chats = nsa_data->symbol_chats;
|
||||
this->character_data->shortcuts = nsa_data->shortcuts;
|
||||
this->log.info_f("Loaded legacy player data from {} and {}", nsa_filename, nsc_filename);
|
||||
} else {
|
||||
this->log.info_f("Loaded legacy player data from {}", nsc_filename);
|
||||
}
|
||||
this->update_character_data_after_load(this->character_data);
|
||||
}
|
||||
this->update_character_data_after_load(this->character_data);
|
||||
}
|
||||
}
|
||||
|
||||
// The system and Guild Card files can be auto-created if they can't be loaded. After this, system_data and
|
||||
// guild_card_data are always non-null, but character_data may still be null
|
||||
if (!this->system_data) {
|
||||
this->system_data = make_shared<PSOBBBaseSystemFile>();
|
||||
auto s = this->require_server_state();
|
||||
if (s->bb_default_keyboard_config) {
|
||||
this->system_data->key_config = *s->bb_default_keyboard_config;
|
||||
}
|
||||
if (s->bb_default_joystick_config) {
|
||||
this->system_data->joystick_config = *s->bb_default_joystick_config;
|
||||
}
|
||||
this->log.info_f("Created new system data");
|
||||
}
|
||||
if (!this->guild_card_data) {
|
||||
this->guild_card_data = make_shared<PSOBBGuildCardFile>();
|
||||
this->log.info_f("Created new Guild Card data");
|
||||
}
|
||||
|
||||
auto s = this->require_server_state();
|
||||
auto stack_limits = s->item_stack_limits(this->version());
|
||||
|
||||
if (this->bb_character_index >= 0) {
|
||||
// bank_file() loads the bank data
|
||||
this->bank_file()->enforce_stack_limits(stack_limits);
|
||||
}
|
||||
|
||||
this->blocked_senders.clear();
|
||||
for (size_t z = 0; z < this->guild_card_data->blocked.size(); z++) {
|
||||
if (this->guild_card_data->blocked[z].present) {
|
||||
this->blocked_senders.emplace(this->guild_card_data->blocked[z].guild_card_number);
|
||||
for (size_t z = 0; z < this->guild_card_data->blocked_senders.size(); z++) {
|
||||
if (this->guild_card_data->blocked_senders[z].present) {
|
||||
this->blocked_senders.emplace(this->guild_card_data->blocked_senders[z].guild_card_number);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->character_data) {
|
||||
// Clear legacy play_time field
|
||||
this->character_data->disp.name.clear_after_bytes(0x18);
|
||||
|
||||
this->character_data->inventory.enforce_stack_limits(stack_limits);
|
||||
|
||||
this->login->account->auto_reply_message = this->character_data->auto_reply.decode();
|
||||
this->login->account->save();
|
||||
this->last_play_time_update = phosg::now();
|
||||
if (this->bb_character_index >= 0) {
|
||||
// Note that bank_file() can't recur infinitely here because character_file is already set; it will not call
|
||||
// load_all_files() again
|
||||
this->bank_file()->enforce_stack_limits(stack_limits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Client::update_character_data_after_load(shared_ptr<PSOBBCharacterFile> charfile) {
|
||||
charfile->import_tethealla_material_usage(this->require_server_state()->level_table(this->version()));
|
||||
|
||||
uint8_t lang = this->language();
|
||||
this->log.info_f("Overriding language fields in save files with {:02X} ({})", lang, char_for_language_code(lang));
|
||||
Language lang = this->language();
|
||||
this->log.info_f("Overriding language fields in save files with {}", name_for_language(lang));
|
||||
charfile->inventory.language = lang;
|
||||
charfile->guild_card.language = lang;
|
||||
}
|
||||
|
||||
void Client::update_bank_data_after_load(shared_ptr<PlayerBank> bank) {
|
||||
auto s = this->require_server_state();
|
||||
auto limits = s->item_stack_limits(this->version());
|
||||
for (auto& item : bank->items) {
|
||||
if (item.data.is_stackable(*limits)) {
|
||||
if (item.data.data1[5] != item.amount) {
|
||||
this->log.info_f("Updating item data stack count from bank stack count ({} -> {}) for {}",
|
||||
item.data.data1[5], item.amount, item.data.hex());
|
||||
item.data.data1[5] = item.amount;
|
||||
}
|
||||
} else if (item.amount != 1) {
|
||||
this->log.info_f("Clearing bank stack count ({}) for {}", item.amount, item.data.hex());
|
||||
item.amount = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Client::save_all() {
|
||||
if (this->system_data) {
|
||||
this->save_system_file();
|
||||
@@ -1061,13 +1087,17 @@ shared_ptr<PSOGCEp3CharacterFile::Character> Client::load_ep3_backup_character(u
|
||||
return ch;
|
||||
}
|
||||
|
||||
void Client::save_and_unload_character() {
|
||||
void Client::unload_character(bool save) {
|
||||
if (this->character_data) {
|
||||
this->save_character_file();
|
||||
if (save) {
|
||||
this->save_character_file();
|
||||
}
|
||||
this->character_data.reset();
|
||||
this->log.info_f("Unloaded character");
|
||||
if (this->bank_data) {
|
||||
this->save_bank_file();
|
||||
if (save) {
|
||||
this->save_bank_file();
|
||||
}
|
||||
this->bank_data.reset();
|
||||
this->log.info_f("Unloaded bank");
|
||||
}
|
||||
|
||||
+65
-68
@@ -39,57 +39,59 @@ public:
|
||||
// clang-format off
|
||||
|
||||
// Version-related flags
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
|
||||
NO_D6_AFTER_LOBBY = 0x0000000000000100,
|
||||
NO_D6 = 0x0000000000000200,
|
||||
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000001,
|
||||
NO_D6_AFTER_LOBBY = 0x0000000000000002,
|
||||
NO_D6 = 0x0000000000000004,
|
||||
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000008,
|
||||
|
||||
// Flags describing the behavior for send_function_call
|
||||
HAS_SEND_FUNCTION_CALL = 0x0000000000001000,
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
|
||||
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,
|
||||
HAS_SEND_FUNCTION_CALL = 0x0000000000000010,
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000000020,
|
||||
SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE = 0x0000000000000040,
|
||||
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000000080,
|
||||
CAN_RECEIVE_ENABLE_B2_QUEST = 0x0000000000000100,
|
||||
AWAITING_ENABLE_B2_QUEST = 0x0000000000000200,
|
||||
|
||||
// State flags
|
||||
LOADING = 0x0000000000100000,
|
||||
LOADING_QUEST = 0x0000000000200000,
|
||||
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000,
|
||||
LOADING_TOURNAMENT = 0x0000000000800000,
|
||||
IN_INFORMATION_MENU = 0x0000000001000000,
|
||||
AT_WELCOME_MESSAGE = 0x0000000002000000,
|
||||
SAVE_ENABLED = 0x0000000004000000,
|
||||
HAS_EP3_CARD_DEFS = 0x0000000008000000,
|
||||
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000,
|
||||
HAS_AUTO_PATCHES = 0x0000004000000000,
|
||||
AT_BANK_COUNTER = 0x0000000080000000,
|
||||
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000,
|
||||
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000,
|
||||
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0080000000000000,
|
||||
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000,
|
||||
SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0200000000000000,
|
||||
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
|
||||
SWITCH_ASSIST_ENABLED = 0x0000000100000000,
|
||||
IS_CLIENT_CUSTOMIZATION = 0x0100000000000000,
|
||||
EP3_ALLOW_6xBC = 0x1000000000000000,
|
||||
LOADING = 0x0000000000000400,
|
||||
LOADING_QUEST = 0x0000000000000800,
|
||||
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000001000,
|
||||
LOADING_TOURNAMENT = 0x0000000000002000,
|
||||
IN_INFORMATION_MENU = 0x0000000000004000,
|
||||
AT_WELCOME_MESSAGE = 0x0000000000008000,
|
||||
SAVE_ENABLED = 0x0000000000010000,
|
||||
HAS_EP3_CARD_DEFS = 0x0000000000020000,
|
||||
HAS_EP3_MEDIA_UPDATES = 0x0000000000040000,
|
||||
HAS_AUTO_PATCHES = 0x0000000000080000,
|
||||
AT_BANK_COUNTER = 0x0000000000100000,
|
||||
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0000000000200000,
|
||||
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0000000000400000,
|
||||
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0000000000800000,
|
||||
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0000000001000000,
|
||||
SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0000000002000000,
|
||||
SHOULD_SEND_ENABLE_SAVE = 0x0000000004000000,
|
||||
SWITCH_ASSIST_ENABLED = 0x0000000008000000,
|
||||
IS_CLIENT_CUSTOMIZATION = 0x0000000010000000,
|
||||
EP3_ALLOW_6xBC = 0x0000000020000000,
|
||||
|
||||
// Cheat mode and option flags
|
||||
INFINITE_HP_ENABLED = 0x0000000200000000,
|
||||
INFINITE_TP_ENABLED = 0x0000000400000000,
|
||||
DEBUG_ENABLED = 0x0000000800000000,
|
||||
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000,
|
||||
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000,
|
||||
HAS_ENEMY_DAMAGE_SYNC_PATCH = 0x2000000000000000, // Must be same as in EnemyDamageSync*.s
|
||||
INFINITE_HP_ENABLED = 0x0000000040000000,
|
||||
INFINITE_TP_ENABLED = 0x0000000080000000,
|
||||
FAST_KILLS_ENABLED = 0x0000000100000000,
|
||||
ALL_RARES_ENABLED = 0x0000100000000000,
|
||||
DEBUG_ENABLED = 0x0000000200000000,
|
||||
ITEM_DROP_NOTIFICATIONS_1 = 0x0000000400000000,
|
||||
ITEM_DROP_NOTIFICATIONS_2 = 0x0000000800000000,
|
||||
HAS_ENEMY_DAMAGE_SYNC_PATCH = 0x0000001000000000, // Must be same as in EnemyDamageSync*.s
|
||||
|
||||
// Proxy option flags
|
||||
PROXY_SAVE_FILES = 0x0000001000000000,
|
||||
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000,
|
||||
PROXY_SAVE_FILES = 0x0000002000000000,
|
||||
PROXY_CHAT_COMMANDS_ENABLED = 0x0000004000000000,
|
||||
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
|
||||
PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000080000000000,
|
||||
PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000100000000000,
|
||||
PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000,
|
||||
PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000,
|
||||
PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000010000000000,
|
||||
PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000020000000000,
|
||||
PROXY_BLOCK_FUNCTION_CALLS = 0x0000040000000000,
|
||||
PROXY_EP3_UNMASK_WHISPERS = 0x0000080000000000,
|
||||
// clang-format on
|
||||
};
|
||||
enum class ItemDropNotificationMode {
|
||||
@@ -138,6 +140,7 @@ public:
|
||||
std::shared_ptr<Channel> channel;
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> bb_detector_crypt;
|
||||
ServerBehavior server_behavior;
|
||||
uint16_t listener_port = 0;
|
||||
std::unordered_map<std::string, std::function<void()>> disconnect_hooks;
|
||||
uint64_t ping_start_time = 0;
|
||||
|
||||
@@ -148,8 +151,9 @@ public:
|
||||
uint8_t override_lobby_event = 0xFF; // FF = no override
|
||||
uint8_t override_lobby_number = 0x80; // 80 = no override
|
||||
int64_t override_random_seed = -1;
|
||||
int8_t selected_blueballz_tier = -1; // -1 = normal lobby/game; 0..10 = requested Blueballz tier
|
||||
std::unique_ptr<Variations> override_variations;
|
||||
VectorXZF pos;
|
||||
VectorXYZF pos;
|
||||
uint32_t floor = 0x0F;
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
uint8_t lobby_client_id = 0;
|
||||
@@ -188,8 +192,7 @@ public:
|
||||
std::unordered_set<uint32_t> blocked_senders;
|
||||
std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp;
|
||||
std::shared_ptr<Parsed6x70Data> last_reported_6x70;
|
||||
// These are null unless the client is within the trade sequence (D0-D4 or EE
|
||||
// commands)
|
||||
// These are null unless the client is within the trade sequence (D0-D4 or EE commands)
|
||||
std::unique_ptr<PendingItemTrade> pending_item_trade;
|
||||
std::unique_ptr<PendingCardTrade> pending_card_trade;
|
||||
uint32_t telepipe_lobby_id = 0;
|
||||
@@ -198,15 +201,14 @@ public:
|
||||
ItemData bb_identify_result;
|
||||
std::array<std::vector<ItemData>, 3> bb_shop_contents;
|
||||
|
||||
// Miscellaneous (used by chat commands)
|
||||
uint32_t next_exp_value = 0; // next EXP value to give
|
||||
// Miscellaneous (used by chat commands / quest opcodes)
|
||||
uint8_t schtserv_response_register = 0;
|
||||
uint32_t next_exp_value = 0;
|
||||
bool can_chat = true;
|
||||
// NOTE: If you add any new optional promises here, make sure to also add
|
||||
// them to cancel_pending_promises.
|
||||
// NOTE: Entries in this queue can be nullptr; that represents a B2 command
|
||||
// sent by the remote server during a proxy session. We can't just omit those
|
||||
// from the queue entirely, because if we did, we could end up sending the
|
||||
// wrong B3 response back.
|
||||
// NOTE: If you add any new optional promises here, make sure to also add them to cancel_pending_promises.
|
||||
// NOTE: Entries in this queue can be nullptr; that represents a B2 command sent by the remote server during a proxy
|
||||
// session. We can't just omit those from the queue entirely, because if we did, we could end up sending the wrong B3
|
||||
// response back.
|
||||
std::deque<std::shared_ptr<AsyncPromise<C_ExecuteCodeResult_B3>>> function_call_response_queue;
|
||||
std::shared_ptr<AsyncPromise<GetPlayerInfoResult>> character_data_ready_promise;
|
||||
std::shared_ptr<AsyncPromise<void>> enable_save_promise;
|
||||
@@ -214,10 +216,7 @@ public:
|
||||
// File loading state
|
||||
std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files;
|
||||
|
||||
Client(
|
||||
std::shared_ptr<GameServer> server,
|
||||
std::shared_ptr<Channel> channel,
|
||||
ServerBehavior server_behavior);
|
||||
Client(std::shared_ptr<GameServer> server, std::shared_ptr<Channel> channel, ServerBehavior server_behavior);
|
||||
~Client();
|
||||
|
||||
void update_channel_name();
|
||||
@@ -228,7 +227,7 @@ public:
|
||||
inline Version version() const {
|
||||
return this->channel->version;
|
||||
}
|
||||
inline uint8_t language() const {
|
||||
inline Language language() const {
|
||||
return this->channel->language;
|
||||
}
|
||||
|
||||
@@ -256,8 +255,6 @@ public:
|
||||
|
||||
void convert_account_to_temporary_if_nte();
|
||||
|
||||
void sync_config();
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<Lobby> require_lobby() const;
|
||||
|
||||
@@ -267,21 +264,21 @@ public:
|
||||
std::shared_ptr<const IntegralExpression> expr,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_see_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_play_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
|
||||
@@ -316,7 +313,7 @@ public:
|
||||
void save_character_file();
|
||||
void create_character_file(
|
||||
uint32_t guild_card_number,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const PlayerDispDataBBPreview& preview,
|
||||
std::shared_ptr<const LevelTable> level_table);
|
||||
void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
|
||||
@@ -343,7 +340,7 @@ public:
|
||||
|
||||
void load_backup_character(uint32_t account_id, size_t index);
|
||||
std::shared_ptr<PSOGCEp3CharacterFile::Character> load_ep3_backup_character(uint32_t account_id, size_t index);
|
||||
void save_and_unload_character();
|
||||
void unload_character(bool save);
|
||||
|
||||
void print_inventory() const;
|
||||
void print_bank() const;
|
||||
@@ -351,9 +348,8 @@ public:
|
||||
void cancel_pending_promises();
|
||||
|
||||
private:
|
||||
// The overlay character data is used in battle and challenge modes, when
|
||||
// character data is temporarily replaced in-game. In other play modes and in
|
||||
// lobbies, overlay_character_data is null.
|
||||
// The overlay character data is used in battle and challenge modes, when character data is temporarily replaced
|
||||
// in-game. In other play modes and in lobbies, overlay_character_data is null.
|
||||
std::shared_ptr<PSOBBBaseSystemFile> system_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> overlay_character_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> character_data;
|
||||
@@ -363,4 +359,5 @@ private:
|
||||
|
||||
void load_all_files();
|
||||
void update_character_data_after_load(std::shared_ptr<PSOBBCharacterFile> character_data);
|
||||
void update_bank_data_after_load(std::shared_ptr<PlayerBank> bank_data);
|
||||
};
|
||||
|
||||
+1752
-2194
File diff suppressed because it is too large
Load Diff
+22
-26
@@ -37,6 +37,14 @@ struct VectorXZF {
|
||||
inline double norm2() const {
|
||||
return ((this->x * this->x) + (this->z * this->z));
|
||||
}
|
||||
inline double dist(const VectorXZF& other) const {
|
||||
return sqrt(this->dist2(other));
|
||||
}
|
||||
inline double dist2(const VectorXZF& other) const {
|
||||
double x = this->x - other.x;
|
||||
double z = this->z - other.z;
|
||||
return ((x * x) + (z * z));
|
||||
}
|
||||
|
||||
inline VectorXZF rotate_y(double angle) const {
|
||||
double s = sin(angle);
|
||||
@@ -86,26 +94,17 @@ struct VectorXYZF {
|
||||
inline VectorXYZF rotate_x(double angle) const {
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
return VectorXYZF{
|
||||
this->x,
|
||||
this->y * c - this->z * s,
|
||||
this->y * s + this->z * c};
|
||||
return VectorXYZF{this->x, this->y * c - this->z * s, this->y * s + this->z * c};
|
||||
}
|
||||
inline VectorXYZF rotate_y(double angle) const {
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
return VectorXYZF{
|
||||
this->x * c + this->z * s,
|
||||
this->y,
|
||||
-this->x * s + this->z * c};
|
||||
return VectorXYZF{this->x * c + this->z * s, this->y, -this->x * s + this->z * c};
|
||||
}
|
||||
inline VectorXYZF rotate_z(double angle) const {
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
return VectorXYZF{
|
||||
this->x * c - this->y * s,
|
||||
this->x * s + this->y * c,
|
||||
this->z};
|
||||
return VectorXYZF{this->x * c - this->y * s, this->x * s + this->y * c, this->z};
|
||||
}
|
||||
|
||||
inline std::string str() const {
|
||||
@@ -141,23 +140,20 @@ 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 at the beginning of the file
|
||||
// data, 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 file is added to the existing value.
|
||||
// For example, if the file data contains the following data (where R
|
||||
// specifies doublewords to relocate):
|
||||
// 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 at the beginning of the file
|
||||
// data, 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 file is added to the existing value.
|
||||
//
|
||||
// For example, if the file data 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).
|
||||
//
|
||||
// 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 some 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;
|
||||
|
||||
+372
-239
@@ -96,65 +96,95 @@ void from_json_into(const phosg::JSON& json, parray<parray<CommonItemSet::Table:
|
||||
}
|
||||
}
|
||||
|
||||
CommonItemSet::Table::Table(const phosg::JSON& json, Episode episode)
|
||||
CommonItemSet::Table::Table(std::shared_ptr<const Table> prev_table, const phosg::JSON& json, Episode episode)
|
||||
: episode(episode) {
|
||||
from_json_into(json.at("BaseWeaponTypeProbTable"), this->base_weapon_type_prob_table);
|
||||
from_json_into(json.at("SubtypeBaseTable"), this->subtype_base_table);
|
||||
from_json_into(json.at("SubtypeAreaLengthTable"), this->subtype_area_length_table);
|
||||
from_json_into(json.at("GrindProbTable"), this->grind_prob_table);
|
||||
from_json_into(json.at("ArmorShieldTypeIndexProbTable"), this->armor_shield_type_index_prob_table);
|
||||
from_json_into(json.at("ArmorSlotCountProbTable"), this->armor_slot_count_prob_table);
|
||||
from_json_into(json.at("BoxMesetaRanges"), this->box_meseta_ranges);
|
||||
this->has_rare_bonus_value_prob_table = json.at("HasRareBonusValueProbTable").as_bool();
|
||||
from_json_into(json.at("BonusValueProbTable"), this->bonus_value_prob_table);
|
||||
from_json_into(json.at("NonRareBonusProbSpec"), this->nonrare_bonus_prob_spec);
|
||||
from_json_into(json.at("BonusTypeProbTable"), this->bonus_type_prob_table);
|
||||
from_json_into(json.at("SpecialMult"), this->special_mult);
|
||||
from_json_into(json.at("SpecialPercent"), this->special_percent);
|
||||
from_json_into(json.at("ToolClassProbTable"), this->tool_class_prob_table);
|
||||
from_json_into(json.at("TechniqueIndexProbTable"), this->technique_index_prob_table);
|
||||
from_json_into(json.at("TechniqueLevelRanges"), this->technique_level_ranges);
|
||||
this->armor_or_shield_type_bias = json.at("ArmorOrShieldTypeBias").as_int();
|
||||
from_json_into(json.at("UnitMaxStarsTable"), this->unit_max_stars_table);
|
||||
from_json_into(json.at("BoxItemClassProbTable"), this->box_item_class_prob_table);
|
||||
auto parse_field = [&]<typename T>(const std::string& key, T& field, const T* prev_field) {
|
||||
if (json.count(key)) {
|
||||
from_json_into(json.at(key), field);
|
||||
} else if (prev_field) {
|
||||
field = *prev_field;
|
||||
}
|
||||
};
|
||||
|
||||
const auto& enemy_meseta_ranges_json = json.at("EnemyMesetaRanges").as_dict();
|
||||
const auto& enemy_type_drop_probs_json = json.at("EnemyTypeDropProbs").as_dict();
|
||||
const auto& enemy_item_classes_json = json.at("EnemyItemClasses").as_dict();
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (Episode episode : episodes) {
|
||||
auto types = enemy_types_for_rare_table_index(episode, z);
|
||||
vector<string> names;
|
||||
if (types.empty()) {
|
||||
names.emplace_back(std::format("{}:!{:02X}", abbreviation_for_episode(episode), z));
|
||||
}
|
||||
for (auto type : enemy_types_for_rare_table_index(episode, z)) {
|
||||
names.emplace_back(std::format("{}:{}", abbreviation_for_episode(episode), phosg::name_for_enum(type)));
|
||||
}
|
||||
for (const auto& name : names) {
|
||||
from_json_into(*enemy_meseta_ranges_json.at(name), this->enemy_meseta_ranges[z]);
|
||||
this->enemy_type_drop_probs[z] = enemy_type_drop_probs_json.at(name)->as_int();
|
||||
this->enemy_item_classes[z] = enemy_item_classes_json.at(name)->as_int();
|
||||
parse_field("BaseWeaponTypeProbTable", this->base_weapon_type_prob_table, prev_table ? &prev_table->base_weapon_type_prob_table : nullptr);
|
||||
parse_field("SubtypeBaseTable", this->subtype_base_table, prev_table ? &prev_table->subtype_base_table : nullptr);
|
||||
parse_field("SubtypeAreaLengthTable", this->subtype_area_length_table, prev_table ? &prev_table->subtype_area_length_table : nullptr);
|
||||
parse_field("GrindProbTable", this->grind_prob_table, prev_table ? &prev_table->grind_prob_table : nullptr);
|
||||
parse_field("ArmorShieldTypeIndexProbTable", this->armor_shield_type_index_prob_table, prev_table ? &prev_table->armor_shield_type_index_prob_table : nullptr);
|
||||
parse_field("ArmorSlotCountProbTable", this->armor_slot_count_prob_table, prev_table ? &prev_table->armor_slot_count_prob_table : nullptr);
|
||||
parse_field("BoxMesetaRanges", this->box_meseta_ranges, prev_table ? &prev_table->box_meseta_ranges : nullptr);
|
||||
if (json.count("HasRareBonusValueProbTable")) {
|
||||
this->has_rare_bonus_value_prob_table = json.at("HasRareBonusValueProbTable").as_bool();
|
||||
} else if (prev_table) {
|
||||
this->has_rare_bonus_value_prob_table = prev_table->has_rare_bonus_value_prob_table;
|
||||
}
|
||||
parse_field("BonusValueProbTable", this->bonus_value_prob_table, prev_table ? &prev_table->bonus_value_prob_table : nullptr);
|
||||
parse_field("NonRareBonusProbSpec", this->nonrare_bonus_prob_spec, prev_table ? &prev_table->nonrare_bonus_prob_spec : nullptr);
|
||||
parse_field("BonusTypeProbTable", this->bonus_type_prob_table, prev_table ? &prev_table->bonus_type_prob_table : nullptr);
|
||||
parse_field("SpecialMult", this->special_mult, prev_table ? &prev_table->special_mult : nullptr);
|
||||
parse_field("SpecialPercent", this->special_percent, prev_table ? &prev_table->special_percent : nullptr);
|
||||
parse_field("ToolClassProbTable", this->tool_class_prob_table, prev_table ? &prev_table->tool_class_prob_table : nullptr);
|
||||
parse_field("TechniqueIndexProbTable", this->technique_index_prob_table, prev_table ? &prev_table->technique_index_prob_table : nullptr);
|
||||
parse_field("TechniqueLevelRanges", this->technique_level_ranges, prev_table ? &prev_table->technique_level_ranges : nullptr);
|
||||
if (json.count("ArmorOrShieldTypeBias")) {
|
||||
this->armor_or_shield_type_bias = json.at("ArmorOrShieldTypeBias").as_int();
|
||||
} else if (prev_table) {
|
||||
this->armor_or_shield_type_bias = prev_table->armor_or_shield_type_bias;
|
||||
}
|
||||
parse_field("UnitMaxStarsTable", this->unit_max_stars_table, prev_table ? &prev_table->unit_max_stars_table : nullptr);
|
||||
parse_field("BoxItemClassProbTable", this->box_item_class_prob_table, prev_table ? &prev_table->box_item_class_prob_table : nullptr);
|
||||
|
||||
if (json.count("EnemyMesetaRanges")) {
|
||||
const auto& dict = json.at("EnemyMesetaRanges").as_dict();
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
try {
|
||||
from_json_into(*dict.at(phosg::name_for_enum(enemy_type)), this->enemy_type_meseta_ranges[enemy_type]);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this->enemy_type_meseta_ranges = prev_table->enemy_type_meseta_ranges;
|
||||
}
|
||||
|
||||
if (json.count("EnemyTypeDropProbs")) {
|
||||
const auto& dict = json.at("EnemyTypeDropProbs").as_dict();
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
try {
|
||||
this->enemy_type_drop_probs[enemy_type] = dict.at(phosg::name_for_enum(enemy_type))->as_int();
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this->enemy_type_drop_probs = prev_table->enemy_type_drop_probs;
|
||||
}
|
||||
|
||||
if (json.count("EnemyItemClasses")) {
|
||||
const auto& dict = json.at("EnemyItemClasses").as_dict();
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
try {
|
||||
this->enemy_type_item_classes[enemy_type] = dict.at(phosg::name_for_enum(enemy_type))->as_int();
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this->enemy_type_item_classes = prev_table->enemy_type_item_classes;
|
||||
}
|
||||
}
|
||||
|
||||
static const char* name_for_common_item_class(uint8_t item_class) {
|
||||
switch (item_class) {
|
||||
case 0x00:
|
||||
return "WEAPON ";
|
||||
return "WEAPON";
|
||||
case 0x01:
|
||||
return "ARMOR ";
|
||||
return "ARMOR";
|
||||
case 0x02:
|
||||
return "SHIELD ";
|
||||
return "SHIELD";
|
||||
case 0x03:
|
||||
return "UNIT ";
|
||||
return "UNIT";
|
||||
case 0x04:
|
||||
return "TOOL ";
|
||||
return "TOOL";
|
||||
case 0x05:
|
||||
return "MESETA ";
|
||||
return "MESETA";
|
||||
case 0x06:
|
||||
return "NOTHING";
|
||||
default:
|
||||
@@ -163,42 +193,29 @@ static const char* name_for_common_item_class(uint8_t item_class) {
|
||||
}
|
||||
|
||||
void CommonItemSet::Table::print(FILE* stream) const {
|
||||
const auto& meseta_ranges = this->enemy_meseta_ranges;
|
||||
const auto& meseta_ranges = this->enemy_type_meseta_ranges;
|
||||
const auto& drop_probs = this->enemy_type_drop_probs;
|
||||
const auto& item_classes = this->enemy_item_classes;
|
||||
const auto& item_classes = this->enemy_type_item_classes;
|
||||
phosg::fwrite_fmt(stream, "Enemy tables:\n");
|
||||
phosg::fwrite_fmt(stream, " ## $LOW $HIGH DAR% ITEM ENEMIES\n");
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
string enemies_str;
|
||||
for (EnemyType enemy_type : enemy_types_for_rare_table_index(this->episode, z)) {
|
||||
if (!enemies_str.empty()) {
|
||||
enemies_str += ", ";
|
||||
}
|
||||
enemies_str += phosg::name_for_enum(enemy_type);
|
||||
}
|
||||
if (drop_probs[z]) {
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:5} {:5} {:3}% {:02X}:{} {}\n",
|
||||
z, meseta_ranges[z].min, meseta_ranges[z].max, drop_probs[z], item_classes[z],
|
||||
name_for_common_item_class(item_classes[z]), enemies_str);
|
||||
} else {
|
||||
phosg::fwrite_fmt(stream, " {:02X} ----- ----- 0% -- {}\n", z, enemies_str);
|
||||
phosg::fwrite_fmt(stream, " ##:ENEMY $LOW $HIGH DAR% ITEM\n");
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
const auto& def = type_definition_for_enemy(enemy_type);
|
||||
try {
|
||||
const auto& meseta_range = meseta_ranges.at(enemy_type);
|
||||
const auto& drop_prob = drop_probs.at(enemy_type);
|
||||
const auto& item_class = item_classes.at(enemy_type);
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{:<23} {:5} {:5} {:3}% {:02X}:{:<7}\n",
|
||||
def.rt_index, phosg::name_for_enum(enemy_type),
|
||||
meseta_range.min, meseta_range.max, drop_prob, item_class,
|
||||
name_for_common_item_class(item_class));
|
||||
} catch (const out_of_range&) {
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{:<23} ----- ----- ---- --:-------\n",
|
||||
def.rt_index, phosg::name_for_enum(enemy_type));
|
||||
}
|
||||
}
|
||||
|
||||
static const array<const char*, 12> base_weapon_type_names = {
|
||||
"SABER ",
|
||||
"SWORD ",
|
||||
"DAGGER ",
|
||||
"PARTISAN",
|
||||
"SLICER ",
|
||||
"HANDGUN ",
|
||||
"RIFLE ",
|
||||
"MECHGUN ",
|
||||
"SHOT ",
|
||||
"CANE ",
|
||||
"ROD ",
|
||||
"WAND ",
|
||||
};
|
||||
"SABER", "SWORD", "DAGGER", "PARTISAN", "SLICER", "HANDGUN", "RIFLE", "MECHGUN", "SHOT", "CANE", "ROD", "WAND"};
|
||||
phosg::fwrite_fmt(stream, "Base weapon config:\n");
|
||||
phosg::fwrite_fmt(stream, " TYPE PROB [SB AL] FLOORS\n");
|
||||
for (size_t z = 0; z < 12; z++) {
|
||||
@@ -216,7 +233,7 @@ void CommonItemSet::Table::print(FILE* stream) const {
|
||||
floor_to_class[x] = this->subtype_base_table[z] + (x / this->subtype_area_length_table[z]);
|
||||
}
|
||||
}
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{} {:3}% [{:02X} {:02X}] {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X}\n",
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{:<8} {:3}% [{:02X} {:02X}] {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X} {:02X}\n",
|
||||
z, base_weapon_type_names[z], this->base_weapon_type_prob_table[z],
|
||||
this->subtype_base_table[z], this->subtype_area_length_table[z],
|
||||
floor_to_class[0], floor_to_class[1], floor_to_class[2], floor_to_class[3], floor_to_class[4],
|
||||
@@ -268,10 +285,10 @@ void CommonItemSet::Table::print(FILE* stream) const {
|
||||
this->special_mult[z], this->special_percent[z]);
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, " Tool class table:\n");
|
||||
phosg::fwrite_fmt(stream, " CS A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
phosg::fwrite_fmt(stream, "Tool class table:\n");
|
||||
phosg::fwrite_fmt(stream, " CS A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
for (size_t tool_class = 0; tool_class < this->tool_class_prob_table.size(); tool_class++) {
|
||||
phosg::fwrite_fmt(stream, " {:02X}", tool_class);
|
||||
phosg::fwrite_fmt(stream, " {:02X}", tool_class);
|
||||
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
|
||||
phosg::fwrite_fmt(stream, " {:5}", this->tool_class_prob_table[tool_class][area_norm]);
|
||||
}
|
||||
@@ -300,10 +317,10 @@ void CommonItemSet::Table::print(FILE* stream) const {
|
||||
"MEGID ",
|
||||
};
|
||||
|
||||
phosg::fwrite_fmt(stream, " Technique table:\n");
|
||||
phosg::fwrite_fmt(stream, " TECH A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
phosg::fwrite_fmt(stream, "Technique table:\n");
|
||||
phosg::fwrite_fmt(stream, " TECH A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
for (size_t tech_num = 0; tech_num < this->technique_index_prob_table.size(); tech_num++) {
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{}", tech_num, technique_names[tech_num]);
|
||||
phosg::fwrite_fmt(stream, " {:02X}:{}", tech_num, technique_names[tech_num]);
|
||||
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
|
||||
uint16_t prob = this->technique_index_prob_table[tech_num][area_norm];
|
||||
if (prob) {
|
||||
@@ -318,24 +335,24 @@ void CommonItemSet::Table::print(FILE* stream) const {
|
||||
fputc('\n', stream);
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, " Armor/shield type bias: {}\n", this->armor_or_shield_type_bias);
|
||||
phosg::fwrite_fmt(stream, "Armor/shield type bias: {}\n", this->armor_or_shield_type_bias);
|
||||
|
||||
phosg::fwrite_fmt(stream, " Armor/shield type index table:\n");
|
||||
phosg::fwrite_fmt(stream, " TY PROB\n");
|
||||
phosg::fwrite_fmt(stream, "Armor/shield type index table:\n");
|
||||
phosg::fwrite_fmt(stream, " TY PROB\n");
|
||||
for (size_t z = 0; z < 5; z++) {
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}%\n", z, this->armor_shield_type_index_prob_table[z]);
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}%\n", z, this->armor_shield_type_index_prob_table[z]);
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, " Armor/shield slot count table:\n");
|
||||
phosg::fwrite_fmt(stream, " #S PROB\n");
|
||||
phosg::fwrite_fmt(stream, "Armor/shield slot count table:\n");
|
||||
phosg::fwrite_fmt(stream, " #S PROB\n");
|
||||
for (size_t z = 0; z < 5; z++) {
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}%\n", z, this->armor_slot_count_prob_table[z]);
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}%\n", z, this->armor_slot_count_prob_table[z]);
|
||||
}
|
||||
|
||||
phosg::fwrite_fmt(stream, " Unit maximum stars table:\n");
|
||||
phosg::fwrite_fmt(stream, " AR #*\n");
|
||||
phosg::fwrite_fmt(stream, "Unit maximum stars table:\n");
|
||||
phosg::fwrite_fmt(stream, " AR #*\n");
|
||||
for (size_t z = 0; z < 10; z++) {
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}\n", z, this->unit_max_stars_table[z]);
|
||||
phosg::fwrite_fmt(stream, " {:02X} {:3}\n", z, this->unit_max_stars_table[z]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,20 +390,50 @@ void CommonItemSet::Table::print_diff(FILE* stream, const Table& other) const {
|
||||
phosg::format_data_string(&this->armor_slot_count_prob_table, sizeof(this->armor_slot_count_prob_table)),
|
||||
phosg::format_data_string(&other.armor_slot_count_prob_table, sizeof(other.armor_slot_count_prob_table)));
|
||||
}
|
||||
if (this->enemy_meseta_ranges != other.enemy_meseta_ranges) {
|
||||
phosg::fwrite_fmt(stream, "> enemy_meseta_ranges: {} -> {}\n",
|
||||
phosg::format_data_string(&this->enemy_meseta_ranges, sizeof(this->enemy_meseta_ranges)),
|
||||
phosg::format_data_string(&other.enemy_meseta_ranges, sizeof(other.enemy_meseta_ranges)));
|
||||
|
||||
auto format_enemy_range_table = [&](const std::unordered_map<EnemyType, Range<uint16_t>>& table) -> std::string {
|
||||
string ret = "";
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
try {
|
||||
const auto& range = table.at(enemy_type);
|
||||
if (!ret.empty()) {
|
||||
ret += ",";
|
||||
}
|
||||
ret += std::format("{}=[{},{}]", phosg::name_for_enum(enemy_type), range.min, range.max);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
auto format_enemy_u8_table = [&](const std::unordered_map<EnemyType, uint8_t>& table) -> std::string {
|
||||
string ret = "";
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
try {
|
||||
uint8_t value = table.at(enemy_type);
|
||||
if (!ret.empty()) {
|
||||
ret += ",";
|
||||
}
|
||||
ret += std::format("{}={}", phosg::name_for_enum(enemy_type), value);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
if (this->enemy_type_meseta_ranges != other.enemy_type_meseta_ranges) {
|
||||
phosg::fwrite_fmt(stream, "> enemy_type_meseta_ranges: {} -> {}\n",
|
||||
format_enemy_range_table(this->enemy_type_meseta_ranges),
|
||||
format_enemy_range_table(other.enemy_type_meseta_ranges));
|
||||
}
|
||||
if (this->enemy_type_drop_probs != other.enemy_type_drop_probs) {
|
||||
phosg::fwrite_fmt(stream, "> enemy_type_drop_probs: {} -> {}\n",
|
||||
phosg::format_data_string(&this->enemy_type_drop_probs, sizeof(this->enemy_type_drop_probs)),
|
||||
phosg::format_data_string(&other.enemy_type_drop_probs, sizeof(other.enemy_type_drop_probs)));
|
||||
format_enemy_u8_table(this->enemy_type_drop_probs),
|
||||
format_enemy_u8_table(other.enemy_type_drop_probs));
|
||||
}
|
||||
if (this->enemy_item_classes != other.enemy_item_classes) {
|
||||
phosg::fwrite_fmt(stream, "> enemy_item_classes: {} -> {}\n",
|
||||
phosg::format_data_string(&this->enemy_item_classes, sizeof(this->enemy_item_classes)),
|
||||
phosg::format_data_string(&other.enemy_item_classes, sizeof(other.enemy_item_classes)));
|
||||
if (this->enemy_type_item_classes != other.enemy_type_item_classes) {
|
||||
phosg::fwrite_fmt(stream, "> enemy_type_item_classes: {} -> {}\n",
|
||||
format_enemy_u8_table(this->enemy_type_item_classes),
|
||||
format_enemy_u8_table(other.enemy_type_item_classes));
|
||||
}
|
||||
if (this->box_meseta_ranges != other.box_meseta_ranges) {
|
||||
phosg::fwrite_fmt(stream, "> box_meseta_ranges: {} -> {}\n",
|
||||
@@ -455,93 +502,145 @@ void CommonItemSet::Table::print_diff(FILE* stream, const Table& other) const {
|
||||
}
|
||||
}
|
||||
|
||||
phosg::JSON CommonItemSet::Table::json() const {
|
||||
phosg::JSON enemy_meseta_ranges_json = phosg::JSON::dict();
|
||||
phosg::JSON enemy_type_drop_probs_json = phosg::JSON::dict();
|
||||
phosg::JSON enemy_item_classes_json = phosg::JSON::dict();
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (Episode episode : episodes) {
|
||||
auto types = enemy_types_for_rare_table_index(episode, z);
|
||||
vector<string> names;
|
||||
if (types.empty()) {
|
||||
names.emplace_back(std::format("{}:!{:02X}", abbreviation_for_episode(episode), z));
|
||||
} else {
|
||||
for (auto type : types) {
|
||||
names.emplace_back(std::format("{}:{}", abbreviation_for_episode(episode), phosg::name_for_enum(type)));
|
||||
phosg::JSON CommonItemSet::Table::json(std::shared_ptr<const Table> prev_table) const {
|
||||
auto ret = phosg::JSON::dict();
|
||||
|
||||
if (!prev_table || (this->base_weapon_type_prob_table != prev_table->base_weapon_type_prob_table)) {
|
||||
ret.emplace("BaseWeaponTypeProbTable", to_json(this->base_weapon_type_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->subtype_base_table != prev_table->subtype_base_table)) {
|
||||
ret.emplace("SubtypeBaseTable", to_json(this->subtype_base_table));
|
||||
}
|
||||
if (!prev_table || (this->subtype_area_length_table != prev_table->subtype_area_length_table)) {
|
||||
ret.emplace("SubtypeAreaLengthTable", to_json(this->subtype_area_length_table));
|
||||
}
|
||||
if (!prev_table || (this->grind_prob_table != prev_table->grind_prob_table)) {
|
||||
ret.emplace("GrindProbTable", to_json(this->grind_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->armor_shield_type_index_prob_table != prev_table->armor_shield_type_index_prob_table)) {
|
||||
ret.emplace("ArmorShieldTypeIndexProbTable", to_json(this->armor_shield_type_index_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->armor_slot_count_prob_table != prev_table->armor_slot_count_prob_table)) {
|
||||
ret.emplace("ArmorSlotCountProbTable", to_json(this->armor_slot_count_prob_table));
|
||||
}
|
||||
|
||||
bool needs_enemy_type_meseta_ranges = (!prev_table ||
|
||||
(this->enemy_type_meseta_ranges != prev_table->enemy_type_meseta_ranges));
|
||||
bool needs_enemy_type_drop_probs = (!prev_table ||
|
||||
(this->enemy_type_drop_probs != prev_table->enemy_type_drop_probs));
|
||||
bool needs_enemy_type_item_classes = (!prev_table ||
|
||||
(this->enemy_type_item_classes != prev_table->enemy_type_item_classes));
|
||||
if (needs_enemy_type_meseta_ranges || needs_enemy_type_drop_probs || needs_enemy_type_item_classes) {
|
||||
phosg::JSON enemy_type_meseta_ranges_json = phosg::JSON::dict();
|
||||
phosg::JSON enemy_type_drop_probs_json = phosg::JSON::dict();
|
||||
phosg::JSON enemy_type_item_classes_json = phosg::JSON::dict();
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
auto name = phosg::name_for_enum(enemy_type);
|
||||
if (needs_enemy_type_meseta_ranges) {
|
||||
try {
|
||||
enemy_type_meseta_ranges_json.emplace(name, to_json(this->enemy_type_meseta_ranges.at(enemy_type)));
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
}
|
||||
for (const auto& name : names) {
|
||||
enemy_meseta_ranges_json.emplace(name, to_json(this->enemy_meseta_ranges[z]));
|
||||
enemy_type_drop_probs_json.emplace(name, this->enemy_type_drop_probs[z]);
|
||||
enemy_item_classes_json.emplace(name, this->enemy_item_classes[z]);
|
||||
if (needs_enemy_type_drop_probs) {
|
||||
try {
|
||||
enemy_type_drop_probs_json.emplace(name, this->enemy_type_drop_probs.at(enemy_type));
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
}
|
||||
if (needs_enemy_type_item_classes) {
|
||||
try {
|
||||
enemy_type_item_classes_json.emplace(name, this->enemy_type_item_classes.at(enemy_type));
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needs_enemy_type_meseta_ranges) {
|
||||
ret.emplace("EnemyMesetaRanges", std::move(enemy_type_meseta_ranges_json));
|
||||
}
|
||||
if (needs_enemy_type_drop_probs) {
|
||||
ret.emplace("EnemyTypeDropProbs", std::move(enemy_type_drop_probs_json));
|
||||
}
|
||||
if (needs_enemy_type_item_classes) {
|
||||
ret.emplace("EnemyItemClasses", std::move(enemy_type_item_classes_json));
|
||||
}
|
||||
}
|
||||
return phosg::JSON::dict({
|
||||
{"BaseWeaponTypeProbTable", to_json(this->base_weapon_type_prob_table)},
|
||||
{"SubtypeBaseTable", to_json(this->subtype_base_table)},
|
||||
{"SubtypeAreaLengthTable", to_json(this->subtype_area_length_table)},
|
||||
{"GrindProbTable", to_json(this->grind_prob_table)},
|
||||
{"ArmorShieldTypeIndexProbTable", to_json(this->armor_shield_type_index_prob_table)},
|
||||
{"ArmorSlotCountProbTable", to_json(this->armor_slot_count_prob_table)},
|
||||
{"EnemyMesetaRanges", std::move(enemy_meseta_ranges_json)},
|
||||
{"EnemyTypeDropProbs", std::move(enemy_type_drop_probs_json)},
|
||||
{"EnemyItemClasses", std::move(enemy_item_classes_json)},
|
||||
{"BoxMesetaRanges", to_json(this->box_meseta_ranges)},
|
||||
{"HasRareBonusValueProbTable", this->has_rare_bonus_value_prob_table},
|
||||
{"BonusValueProbTable", to_json(this->bonus_value_prob_table)},
|
||||
{"NonRareBonusProbSpec", to_json(this->nonrare_bonus_prob_spec)},
|
||||
{"BonusTypeProbTable", to_json(this->bonus_type_prob_table)},
|
||||
{"SpecialMult", to_json(this->special_mult)},
|
||||
{"SpecialPercent", to_json(this->special_percent)},
|
||||
{"ToolClassProbTable", to_json(this->tool_class_prob_table)},
|
||||
{"TechniqueIndexProbTable", to_json(this->technique_index_prob_table)},
|
||||
{"TechniqueLevelRanges", to_json(this->technique_level_ranges)},
|
||||
{"ArmorOrShieldTypeBias", this->armor_or_shield_type_bias},
|
||||
{"UnitMaxStarsTable", to_json(this->unit_max_stars_table)},
|
||||
{"BoxItemClassProbTable", to_json(this->box_item_class_prob_table)},
|
||||
});
|
||||
|
||||
if (!prev_table || (this->box_meseta_ranges != prev_table->box_meseta_ranges)) {
|
||||
ret.emplace("BoxMesetaRanges", to_json(this->box_meseta_ranges));
|
||||
}
|
||||
if (!prev_table || (this->has_rare_bonus_value_prob_table != prev_table->has_rare_bonus_value_prob_table)) {
|
||||
ret.emplace("HasRareBonusValueProbTable", this->has_rare_bonus_value_prob_table);
|
||||
}
|
||||
if (!prev_table || (this->bonus_value_prob_table != prev_table->bonus_value_prob_table)) {
|
||||
ret.emplace("BonusValueProbTable", to_json(this->bonus_value_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->nonrare_bonus_prob_spec != prev_table->nonrare_bonus_prob_spec)) {
|
||||
ret.emplace("NonRareBonusProbSpec", to_json(this->nonrare_bonus_prob_spec));
|
||||
}
|
||||
if (!prev_table || (this->bonus_type_prob_table != prev_table->bonus_type_prob_table)) {
|
||||
ret.emplace("BonusTypeProbTable", to_json(this->bonus_type_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->special_mult != prev_table->special_mult)) {
|
||||
ret.emplace("SpecialMult", to_json(this->special_mult));
|
||||
}
|
||||
if (!prev_table || (this->special_percent != prev_table->special_percent)) {
|
||||
ret.emplace("SpecialPercent", to_json(this->special_percent));
|
||||
}
|
||||
if (!prev_table || (this->tool_class_prob_table != prev_table->tool_class_prob_table)) {
|
||||
ret.emplace("ToolClassProbTable", to_json(this->tool_class_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->technique_index_prob_table != prev_table->technique_index_prob_table)) {
|
||||
ret.emplace("TechniqueIndexProbTable", to_json(this->technique_index_prob_table));
|
||||
}
|
||||
if (!prev_table || (this->technique_level_ranges != prev_table->technique_level_ranges)) {
|
||||
ret.emplace("TechniqueLevelRanges", to_json(this->technique_level_ranges));
|
||||
}
|
||||
if (!prev_table || (this->armor_or_shield_type_bias != prev_table->armor_or_shield_type_bias)) {
|
||||
ret.emplace("ArmorOrShieldTypeBias", this->armor_or_shield_type_bias);
|
||||
}
|
||||
if (!prev_table || (this->unit_max_stars_table != prev_table->unit_max_stars_table)) {
|
||||
ret.emplace("UnitMaxStarsTable", to_json(this->unit_max_stars_table));
|
||||
}
|
||||
if (!prev_table || (this->box_item_class_prob_table != prev_table->box_item_class_prob_table)) {
|
||||
ret.emplace("BoxItemClassProbTable", to_json(this->box_item_class_prob_table));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
phosg::JSON CommonItemSet::json() const {
|
||||
auto modes_dict = phosg::JSON::dict();
|
||||
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
|
||||
for (const auto& mode : modes) {
|
||||
auto episodes_dict = phosg::JSON::dict();
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (const auto& episode : episodes) {
|
||||
auto difficulty_dict = phosg::JSON::dict();
|
||||
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
auto section_id_dict = phosg::JSON::dict();
|
||||
auto ret = phosg::JSON::dict();
|
||||
for (const auto& episode : ALL_EPISODES_V4) {
|
||||
for (const auto& mode : ALL_GAME_MODES_V4) {
|
||||
for (const auto& difficulty : ALL_DIFFICULTIES_V234) {
|
||||
for (uint8_t section_id = 0; section_id < 10; section_id++) {
|
||||
auto json_key = this->json_key_for_table(episode, mode, difficulty, section_id);
|
||||
try {
|
||||
auto prev_table = this->get_prev_table(episode, mode, difficulty, section_id);
|
||||
auto table = this->get_table(episode, mode, difficulty, section_id);
|
||||
section_id_dict.emplace(name_for_section_id(section_id), table->json());
|
||||
ret.emplace(json_key, table->json(prev_table));
|
||||
} catch (const runtime_error&) {
|
||||
}
|
||||
}
|
||||
difficulty_dict.emplace(token_name_for_difficulty(difficulty), std::move(section_id_dict));
|
||||
}
|
||||
episodes_dict.emplace(token_name_for_episode(episode), std::move(difficulty_dict));
|
||||
}
|
||||
modes_dict.emplace(name_for_mode(mode), std::move(episodes_dict));
|
||||
}
|
||||
|
||||
return modes_dict;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CommonItemSet::print(FILE* stream) const {
|
||||
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
|
||||
for (const auto& mode : modes) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (const auto& episode : episodes) {
|
||||
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
for (const auto& episode : ALL_EPISODES_V4) {
|
||||
for (const auto& mode : ALL_GAME_MODES_V4) {
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
for (uint8_t section_id = 0; section_id < 10; section_id++) {
|
||||
try {
|
||||
auto table = this->get_table(episode, mode, difficulty, section_id);
|
||||
phosg::fwrite_fmt(stream, "============ {} {} {} {}\n",
|
||||
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
name_for_episode(episode),
|
||||
name_for_mode(mode),
|
||||
name_for_difficulty(difficulty),
|
||||
name_for_section_id(section_id));
|
||||
table->print(stream);
|
||||
} catch (const runtime_error&) {
|
||||
}
|
||||
@@ -552,11 +651,9 @@ void CommonItemSet::print(FILE* stream) const {
|
||||
}
|
||||
|
||||
void CommonItemSet::print_diff(FILE* stream, const CommonItemSet& other) const {
|
||||
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
|
||||
for (const auto& mode : modes) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (const auto& episode : episodes) {
|
||||
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
for (const auto& episode : ALL_EPISODES_V4) {
|
||||
for (const auto& mode : ALL_GAME_MODES_V4) {
|
||||
for (const auto& difficulty : ALL_DIFFICULTIES_V234) {
|
||||
for (uint8_t section_id = 0; section_id < 10; section_id++) {
|
||||
shared_ptr<const Table> this_table;
|
||||
shared_ptr<const Table> other_table;
|
||||
@@ -573,13 +670,22 @@ void CommonItemSet::print_diff(FILE* stream, const CommonItemSet& other) const {
|
||||
continue;
|
||||
} else if (!this_table) {
|
||||
phosg::fwrite_fmt(stream, "> Table present in other but not this: {} {} {} {}\n",
|
||||
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
name_for_episode(episode),
|
||||
name_for_mode(mode),
|
||||
name_for_difficulty(difficulty),
|
||||
name_for_section_id(section_id));
|
||||
} else if (!other_table) {
|
||||
phosg::fwrite_fmt(stream, "> Table present in this but not other: {} {} {} {}\n",
|
||||
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
name_for_episode(episode),
|
||||
name_for_mode(mode),
|
||||
name_for_difficulty(difficulty),
|
||||
name_for_section_id(section_id));
|
||||
} else if (*this_table != *other_table) {
|
||||
phosg::fwrite_fmt(stream, "> Tables do not match: {} {} {} {}\n",
|
||||
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
name_for_episode(episode),
|
||||
name_for_mode(mode),
|
||||
name_for_difficulty(difficulty),
|
||||
name_for_section_id(section_id));
|
||||
this_table->print_diff(stream, *other_table);
|
||||
}
|
||||
}
|
||||
@@ -607,12 +713,27 @@ void CommonItemSet::Table::parse_itempt_t(const phosg::StringReader& r, bool is_
|
||||
this->grind_prob_table = r.pget<parray<parray<uint8_t, 4>, 9>>(offsets.grind_prob_table_offset);
|
||||
this->armor_shield_type_index_prob_table = r.pget<parray<uint8_t, 0x05>>(offsets.armor_shield_type_index_prob_table_offset);
|
||||
this->armor_slot_count_prob_table = r.pget<parray<uint8_t, 0x05>>(offsets.armor_slot_count_prob_table_offset);
|
||||
const auto& data = r.pget<parray<Range<U16T<BE>>, 0x64>>(offsets.enemy_meseta_ranges_offset);
|
||||
for (size_t z = 0; z < data.size(); z++) {
|
||||
this->enemy_meseta_ranges[z] = Range<uint16_t>{data[z].min, data[z].max};
|
||||
const auto& enemy_rt_index_meseta_ranges = r.pget<parray<Range<U16T<BE>>, NUM_RT_INDEXES_V3>>(
|
||||
offsets.enemy_rt_index_meseta_ranges_offset);
|
||||
const auto& enemy_rt_index_drop_probs = r.pget<parray<uint8_t, NUM_RT_INDEXES_V3>>(
|
||||
offsets.enemy_rt_index_drop_probs_offset);
|
||||
const auto& enemy_rt_index_item_classes = r.pget<parray<uint8_t, NUM_RT_INDEXES_V3>>(
|
||||
offsets.enemy_rt_index_item_classes_offset);
|
||||
for (auto enemy_type : phosg::EnumRange<EnemyType>()) {
|
||||
const auto& def = type_definition_for_enemy(enemy_type);
|
||||
if (def.valid_in_episode(this->episode) && (def.rt_index < enemy_rt_index_meseta_ranges.size())) {
|
||||
const auto& meseta_range = enemy_rt_index_meseta_ranges[def.rt_index];
|
||||
if (meseta_range.max > 0) {
|
||||
this->enemy_type_meseta_ranges.emplace(enemy_type, Range<uint16_t>{meseta_range.min, meseta_range.max});
|
||||
}
|
||||
if (enemy_rt_index_drop_probs[def.rt_index] > 0) {
|
||||
this->enemy_type_drop_probs.emplace(enemy_type, enemy_rt_index_drop_probs[def.rt_index]);
|
||||
}
|
||||
if (enemy_rt_index_item_classes[def.rt_index] != 0xFF) {
|
||||
this->enemy_type_item_classes.emplace(enemy_type, enemy_rt_index_item_classes[def.rt_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
this->enemy_type_drop_probs = r.pget<parray<uint8_t, 0x64>>(offsets.enemy_type_drop_probs_offset);
|
||||
this->enemy_item_classes = r.pget<parray<uint8_t, 0x64>>(offsets.enemy_item_classes_offset);
|
||||
{
|
||||
const auto& data = r.pget<parray<Range<U16T<BE>>, 0x0A>>(offsets.box_meseta_ranges_offset);
|
||||
for (size_t z = 0; z < data.size(); z++) {
|
||||
@@ -654,7 +775,7 @@ void CommonItemSet::Table::parse_itempt_t(const phosg::StringReader& r, bool is_
|
||||
this->box_item_class_prob_table = r.pget<parray<parray<uint8_t, 10>, 7>>(offsets.box_item_class_prob_table_offset);
|
||||
}
|
||||
|
||||
uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) {
|
||||
uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, Difficulty difficulty, uint8_t secid) {
|
||||
// Bits: -----EEEMMDDSSSS
|
||||
return (((static_cast<uint16_t>(episode) << 8) & 0x0700) |
|
||||
((static_cast<uint16_t>(mode) << 6) & 0x00C0) |
|
||||
@@ -662,33 +783,59 @@ uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, uint8_t di
|
||||
(static_cast<uint16_t>(secid) & 0x000F));
|
||||
}
|
||||
|
||||
std::string CommonItemSet::json_key_for_table(
|
||||
Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id) {
|
||||
return std::format("{}:{}:{}:{}", abbreviation_for_episode(episode), name_for_mode(mode),
|
||||
token_name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
}
|
||||
|
||||
shared_ptr<const CommonItemSet::Table> CommonItemSet::get_table(
|
||||
Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const {
|
||||
Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id) const {
|
||||
try {
|
||||
return this->tables.at(this->key_for_table(episode, mode, difficulty, secid));
|
||||
return this->tables.at(this->key_for_table(episode, mode, difficulty, section_id));
|
||||
} catch (const out_of_range&) {
|
||||
throw runtime_error(std::format("common item table not available for episode={}, mode={}, difficulty={}, secid={}",
|
||||
name_for_episode(episode), name_for_mode(mode), difficulty, secid));
|
||||
name_for_episode(episode), name_for_mode(mode), name_for_difficulty(difficulty), section_id));
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<const CommonItemSet::Table> CommonItemSet::get_prev_table(
|
||||
Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id) const {
|
||||
if (section_id != 0) {
|
||||
// All section IDs are based on the previous, except Viridia
|
||||
return this->get_table(episode, mode, difficulty, section_id - 1);
|
||||
} else if (difficulty != Difficulty::NORMAL) {
|
||||
// All Viridia tables are based on the previous difficulty, except Normal
|
||||
auto prev_difficulty = static_cast<Difficulty>(static_cast<uint8_t>(difficulty) - 1);
|
||||
return this->get_table(episode, mode, prev_difficulty, 0);
|
||||
} else if (mode != GameMode::NORMAL) {
|
||||
// All Normal Viridia tables are based on the Normal game mode, except Normal itself
|
||||
return this->get_table(episode, GameMode::NORMAL, Difficulty::NORMAL, 0);
|
||||
} else {
|
||||
// There's no previous table
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
AFSV2CommonItemSet::AFSV2CommonItemSet(
|
||||
std::shared_ptr<const std::string> pt_afs_data, std::shared_ptr<const std::string> ct_afs_data) {
|
||||
// Each AFS file has 40 entries (30 on v1); the first 10 are for Normal, then
|
||||
// Hard, etc.
|
||||
// Each AFS file has 40 entries (30 on v1); the first 10 are for Normal, then Hard, etc.
|
||||
{
|
||||
AFSArchive pt_afs(pt_afs_data);
|
||||
size_t max_difficulty;
|
||||
bool include_ultimate;
|
||||
if (pt_afs.num_entries() >= 40) {
|
||||
max_difficulty = 4;
|
||||
include_ultimate = true;
|
||||
} else if (pt_afs.num_entries() >= 30) {
|
||||
max_difficulty = 3;
|
||||
include_ultimate = false;
|
||||
} else {
|
||||
throw std::runtime_error(std::format("PT AFS file has unexpected entry count ({})", pt_afs.num_entries()));
|
||||
}
|
||||
for (size_t difficulty = 0; difficulty < max_difficulty; difficulty++) {
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
if ((difficulty == Difficulty::ULTIMATE) && !include_ultimate) {
|
||||
continue;
|
||||
}
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
auto entry = pt_afs.get(difficulty * 10 + section_id);
|
||||
auto entry = pt_afs.get(static_cast<size_t>(difficulty) * 10 + section_id);
|
||||
phosg::StringReader r(entry.first, entry.second);
|
||||
auto table = make_shared<Table>(r, false, false, Episode::EP1);
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::NORMAL, difficulty, section_id), table);
|
||||
@@ -698,20 +845,22 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
|
||||
}
|
||||
}
|
||||
|
||||
// ItemCT AFS files also have 40 entries, but only the 0th, 10th, 20th, and
|
||||
// 30th are used (section_id is ignored)
|
||||
// ItemCT AFS files also have 40 entries, but only the 0th, 10th, 20th, and 30th are used (section_id is ignored)
|
||||
if (ct_afs_data) {
|
||||
AFSArchive ct_afs(ct_afs_data);
|
||||
size_t max_difficulty;
|
||||
bool include_ultimate;
|
||||
if (ct_afs.num_entries() >= 40) {
|
||||
max_difficulty = 4;
|
||||
include_ultimate = true;
|
||||
} else if (ct_afs.num_entries() >= 30) {
|
||||
max_difficulty = 3;
|
||||
include_ultimate = false;
|
||||
} else {
|
||||
throw std::runtime_error(std::format("CT AFS file has unexpected entry count ({})", ct_afs.num_entries()));
|
||||
}
|
||||
for (size_t difficulty = 0; difficulty < max_difficulty; difficulty++) {
|
||||
auto r = ct_afs.get_reader(difficulty * 10);
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
if ((difficulty == Difficulty::ULTIMATE) && !include_ultimate) {
|
||||
continue;
|
||||
}
|
||||
auto r = ct_afs.get_reader(static_cast<size_t>(difficulty) * 10);
|
||||
auto table = make_shared<Table>(r, false, false, Episode::EP1);
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::CHALLENGE, difficulty, section_id), table);
|
||||
@@ -723,7 +872,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
|
||||
GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gsl_data, bool is_big_endian) {
|
||||
GSLArchive gsl(gsl_data, is_big_endian);
|
||||
|
||||
auto filename_for_table = +[](Episode episode, uint8_t difficulty, uint8_t section_id, bool is_challenge) -> string {
|
||||
auto filename_for_table = +[](Episode episode, Difficulty difficulty, uint8_t section_id, bool is_challenge) -> string {
|
||||
const char* episode_token = "";
|
||||
switch (episode) {
|
||||
case Episode::EP1:
|
||||
@@ -746,9 +895,8 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
|
||||
section_id);
|
||||
};
|
||||
|
||||
vector<Episode> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (Episode episode : episodes) {
|
||||
for (size_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
for (Episode episode : ALL_EPISODES_V3) {
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
phosg::StringReader r;
|
||||
try {
|
||||
@@ -772,54 +920,42 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
|
||||
}
|
||||
}
|
||||
|
||||
if (episode != Episode::EP4) {
|
||||
for (size_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
try {
|
||||
auto r = gsl.get_reader(filename_for_table(episode, difficulty, 0, true));
|
||||
auto table = make_shared<Table>(r, is_big_endian, true, episode);
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table);
|
||||
}
|
||||
} catch (const out_of_range&) {
|
||||
// GC NTE doesn't have Ep2 challenge; just skip adding the table
|
||||
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
|
||||
try {
|
||||
auto r = gsl.get_reader(filename_for_table(episode, difficulty, 0, true));
|
||||
auto table = make_shared<Table>(r, is_big_endian, true, episode);
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table);
|
||||
}
|
||||
} catch (const out_of_range&) {
|
||||
// GC NTE doesn't have Ep2 challenge; just skip adding the table
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONCommonItemSet::JSONCommonItemSet(const phosg::JSON& json) {
|
||||
for (const auto& mode_it : json.as_dict()) {
|
||||
static const unordered_map<string, GameMode> mode_keys(
|
||||
{{"Normal", GameMode::NORMAL}, {"Battle", GameMode::BATTLE}, {"Challenge", GameMode::CHALLENGE}, {"Solo", GameMode::SOLO}});
|
||||
GameMode mode = mode_keys.at(mode_it.first);
|
||||
|
||||
for (const auto& episode_it : mode_it.second->as_dict()) {
|
||||
static const unordered_map<string, Episode> episode_keys(
|
||||
{{"Episode1", Episode::EP1}, {"Episode2", Episode::EP2}, {"Episode4", Episode::EP4}});
|
||||
Episode episode = episode_keys.at(episode_it.first);
|
||||
|
||||
for (const auto& difficulty_it : episode_it.second->as_dict()) {
|
||||
static const unordered_map<string, uint8_t> difficulty_keys(
|
||||
{{"Normal", 0}, {"Hard", 1}, {"VeryHard", 2}, {"Ultimate", 3}});
|
||||
uint8_t difficulty = difficulty_keys.at(difficulty_it.first);
|
||||
|
||||
for (const auto& section_id_it : difficulty_it.second->as_dict()) {
|
||||
uint8_t section_id = section_id_for_name(section_id_it.first);
|
||||
this->tables.emplace(
|
||||
this->key_for_table(episode, mode, difficulty, section_id),
|
||||
make_shared<Table>(*section_id_it.second, episode));
|
||||
for (const auto& episode : ALL_EPISODES_V4) {
|
||||
for (const auto& mode : ALL_GAME_MODES_V4) {
|
||||
for (const auto& difficulty : ALL_DIFFICULTIES_V234) {
|
||||
for (uint8_t section_id = 0; section_id < 10; section_id++) {
|
||||
try {
|
||||
auto prev_table = this->get_prev_table(episode, mode, difficulty, section_id);
|
||||
auto json_key = this->json_key_for_table(episode, mode, difficulty, section_id);
|
||||
auto key = this->key_for_table(episode, mode, difficulty, section_id);
|
||||
this->tables.emplace(key, make_shared<Table>(prev_table, json.at(json_key), episode));
|
||||
} catch (const runtime_error&) {
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data)
|
||||
: data(data), r(*this->data) {}
|
||||
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data) : data(data), r(*this->data) {}
|
||||
|
||||
ArmorRandomSet::ArmorRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
ArmorRandomSet::ArmorRandomSet(std::shared_ptr<const std::string> data) : RELFileSet(data) {
|
||||
// For some reason the footer tables are doubly indirect in this file
|
||||
uint32_t specs_offset_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
uint32_t specs_offset = this->r.pget_u32b(specs_offset_offset);
|
||||
@@ -841,8 +977,7 @@ ArmorRandomSet::get_unit_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(2), index);
|
||||
}
|
||||
|
||||
ToolRandomSet::ToolRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
ToolRandomSet::ToolRandomSet(std::shared_ptr<const std::string> data) : RELFileSet(data) {
|
||||
uint32_t specs_offset = r.pget_u32b(data->size() - 0x10);
|
||||
this->common_recovery_table_spec = &r.pget<TableSpec>(r.pget_u32b(specs_offset));
|
||||
this->rare_recovery_table_spec = &r.pget<TableSpec>(r.pget_u32b(specs_offset + sizeof(uint32_t)), 2 * sizeof(TableSpec));
|
||||
@@ -869,8 +1004,7 @@ ToolRandomSet::get_tech_disk_level_table(size_t index) const {
|
||||
return this->get_table<TechDiskLevelEntry>(*this->tech_disk_level_table_spec, index);
|
||||
}
|
||||
|
||||
WeaponRandomSet::WeaponRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
WeaponRandomSet::WeaponRandomSet(std::shared_ptr<const std::string> data) : RELFileSet(data) {
|
||||
uint32_t offsets_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
this->offsets = &this->r.pget<Offsets>(offsets_offset);
|
||||
}
|
||||
@@ -910,8 +1044,7 @@ WeaponRandomSet::get_favored_grind_range(size_t index) const {
|
||||
return &this->r.pget<RangeTableEntry>(this->offsets->favored_grind_range_table + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
TekkerAdjustmentSet::TekkerAdjustmentSet(std::shared_ptr<const std::string> data)
|
||||
: data(data), r(*data) {
|
||||
TekkerAdjustmentSet::TekkerAdjustmentSet(std::shared_ptr<const std::string> data) : data(data), r(*data) {
|
||||
this->offsets = &this->r.pget<Offsets>(this->r.pget_u32b(this->r.size() - 0x10));
|
||||
}
|
||||
|
||||
|
||||
+123
-143
@@ -4,6 +4,7 @@
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
|
||||
#include "EnemyType.hh"
|
||||
#include "GSLArchive.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
@@ -15,7 +16,7 @@ public:
|
||||
class Table {
|
||||
public:
|
||||
Table() = delete;
|
||||
Table(const phosg::JSON& json, Episode episode);
|
||||
Table(std::shared_ptr<const Table> prev_table, const phosg::JSON& json, Episode episode);
|
||||
Table(const phosg::StringReader& r, bool big_endian, bool is_v3, Episode episode);
|
||||
|
||||
bool operator==(const Table& other) const = default;
|
||||
@@ -23,11 +24,15 @@ public:
|
||||
|
||||
template <typename IntT>
|
||||
struct Range {
|
||||
IntT min;
|
||||
IntT max;
|
||||
IntT min = 0;
|
||||
IntT max = 0;
|
||||
|
||||
bool operator==(const Range& other) const = default;
|
||||
bool operator!=(const Range& other) const = default;
|
||||
|
||||
inline bool empty() const {
|
||||
return ((this->min | this->max) == 0);
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
Episode episode;
|
||||
@@ -37,9 +42,10 @@ public:
|
||||
parray<parray<uint8_t, 4>, 9> grind_prob_table;
|
||||
parray<uint8_t, 0x05> armor_shield_type_index_prob_table;
|
||||
parray<uint8_t, 0x05> armor_slot_count_prob_table;
|
||||
parray<Range<uint16_t>, 0x64> enemy_meseta_ranges;
|
||||
parray<uint8_t, 0x64> enemy_type_drop_probs;
|
||||
parray<uint8_t, 0x64> enemy_item_classes;
|
||||
// Note: PSO originally uses arrays indexed by rt_index here, but we index enemies by the EnemyType enum instead
|
||||
std::unordered_map<EnemyType, Range<uint16_t>> enemy_type_meseta_ranges;
|
||||
std::unordered_map<EnemyType, uint8_t> enemy_type_drop_probs;
|
||||
std::unordered_map<EnemyType, uint8_t> enemy_type_item_classes;
|
||||
parray<Range<uint16_t>, 0x0A> box_meseta_ranges;
|
||||
bool has_rare_bonus_value_prob_table;
|
||||
parray<parray<uint16_t, 6>, 0x17> bonus_value_prob_table;
|
||||
@@ -54,7 +60,7 @@ public:
|
||||
parray<uint8_t, 0x0A> unit_max_stars_table;
|
||||
parray<parray<uint8_t, 10>, 7> box_item_class_prob_table;
|
||||
|
||||
phosg::JSON json() const;
|
||||
phosg::JSON json(std::shared_ptr<const Table> prev_table) const;
|
||||
void print(FILE* stream) const;
|
||||
void print_diff(FILE* stream, const Table& other) const;
|
||||
|
||||
@@ -64,54 +70,43 @@ public:
|
||||
|
||||
template <bool BE>
|
||||
struct OffsetsT {
|
||||
// This data structure uses index probability tables in multiple places. An
|
||||
// index probability table is a table where each entry holds the probability
|
||||
// that that entry's index is used. For example, if the armor slot count
|
||||
// probability table contains [77, 17, 5, 1, 0], this means there is a 77%
|
||||
// chance of no slots, 17% chance of 1 slot, 5% chance of 2 slots, 1% chance
|
||||
// of 3 slots, and no chance of 4 slots. The values in index probability
|
||||
// tables do not have to add up to 100; the game sums all of them and
|
||||
// chooses a random number less than that maximum.
|
||||
// This data structure uses index probability tables in multiple places. An index probability table is a table
|
||||
// where each entry holds the probability that that entry's index is used. For example, if the armor slot count
|
||||
// probability table contains [77, 17, 5, 1, 0], this means there is a 77% chance of no slots, 17% chance of 1
|
||||
// slot, 5% chance of 2 slots, 1% chance of 3 slots, and no chance of 4 slots. The values in index probability
|
||||
// tables do not have to add up to 100; the game sums all of them and chooses a random number less than that
|
||||
// maximum.
|
||||
|
||||
// The area (floor) number is used in many places as well. Unlike the normal
|
||||
// area numbers, which start with Pioneer 2, the area numbers in this
|
||||
// structure start with Forest 1, and boss areas are treated as the first
|
||||
// area of the next section (so De Rol Le has Mines 1 drops, for example).
|
||||
// Final boss areas are treated as the last non-boss area (so Dark Falz
|
||||
// boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
|
||||
// (area - 1).
|
||||
// The area (floor) number is used in many places as well. Unlike the normal area numbers, which start with
|
||||
// Pioneer 2, the area numbers in this structure start with Forest 1, and boss areas are treated as the first
|
||||
// area of the next section (so De Rol Le has Mines 1 drops, for example). Final boss areas are treated as the
|
||||
// last non-boss area (so Dark Falz boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
|
||||
// (area - 1), or area_norm.
|
||||
|
||||
// This index probability table determines the types of non-rare weapons.
|
||||
// The indexes in this table correspond to the non-rare weapon types 01
|
||||
// through 0C (Saber through Wand).
|
||||
// This index probability table determines the types of non-rare weapons. The indexes in this table correspond to
|
||||
// the non-rare weapon types 01 through 0C (Saber through Wand).
|
||||
// V2/V3: -> parray<uint8_t, 0x0C>
|
||||
/* 00 */ U32T<BE> base_weapon_type_prob_table_offset;
|
||||
|
||||
// This table specifies the base subtype for each weapon type. Negative
|
||||
// values here mean that the weapon cannot be found in the first N areas (so
|
||||
// -2, for example, means that the weapon never appears in Forest 1 or 2 at
|
||||
// all). Nonnegative values here mean the subtype can be found in all areas,
|
||||
// and specify the base subtype (usually in the range [0, 4]). The subtype
|
||||
// of weapon that actually appears depends on this value and a value from
|
||||
// the following table.
|
||||
// This table specifies the base subtype for each weapon type. Negative values here mean that the weapon cannot
|
||||
// be found in the first N areas (so -2, for example, means that the weapon never appears in Forest 1 or 2 at
|
||||
// all). Nonnegative values here mean the subtype can be found in all areas, and specify the base subtype
|
||||
// (usually in the range [0, 4]). The subtype of weapon that actually appears depends on this value and a value
|
||||
// from the following table.
|
||||
// V2/V3: -> parray<int8_t, 0x0C>
|
||||
/* 04 */ U32T<BE> subtype_base_table_offset;
|
||||
|
||||
// This table specifies how many areas each weapon subtype appears in. For
|
||||
// example, if Sword (subtype 02, which is index 1 in this table and the
|
||||
// table above) has a subtype base of -2 and a subtype area length of 4,
|
||||
// then Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1
|
||||
// through Mine 1), and Gigush (the next sword subtype) can be found in Mine
|
||||
// 1 through Ruins 3.
|
||||
// This table specifies how many areas each weapon subtype appears in. For example, if Sword (subtype 02, which
|
||||
// is index 1 in this table and the table above) has a subtype base of -2 and a subtype area length of 4, then
|
||||
// Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1 through Mine 1), and Gigush (the next sword
|
||||
// subtype) can be found in Mine 1 through Ruins 3.
|
||||
// V2/V3: -> parray<uint8_t, 0x0C>
|
||||
/* 08 */ U32T<BE> subtype_area_length_table_offset;
|
||||
|
||||
// This index probability table specifies how likely each possible grind
|
||||
// value is. The table is indexed as [grind][subtype_area_index], where the
|
||||
// subtype area index is how many areas the player is beyond the first area
|
||||
// in which the subtype can first be found (clamped to [0, 3]). To continue
|
||||
// the example above, in Cave 3, subtype_area_index would be 2, since Swords
|
||||
// can first be found two areas earlier in Cave 1.
|
||||
// This index probability table specifies how likely each possible grind value is. The table is indexed as
|
||||
// [grind][subtype_area_index], where the subtype area index is how many areas the player is beyond the first
|
||||
// area in which the subtype can first be found (clamped to [0, 3]). To continue the example above, in Cave 3,
|
||||
// subtype_area_index would be 2, since Swords can first be found two areas earlier in Cave 1.
|
||||
// For example, this table could look like this:
|
||||
// [64 1E 19 14] // Chance of getting a grind +0
|
||||
// [00 1E 17 0F] // Chance of getting a grind +1
|
||||
@@ -121,74 +116,66 @@ public:
|
||||
// V2/V3: -> parray<parray<uint8_t, 4>, 9>
|
||||
/* 0C */ U32T<BE> grind_prob_table_offset;
|
||||
|
||||
// TODO: Figure out exactly how this table is used. Anchor: 80106D34
|
||||
// This index probability table specifies how likely each type of armor or shield is. The general formula is:
|
||||
// data1[2] = max((area_norm + (result from this table) + armor_or_shield_type_bias - 3), 0)
|
||||
// In this way, (armor_or_shield_type_bias + area_norm - 3) can be thought of as the "base" value for each area,
|
||||
// and this table specifies how likely the armor/shield is to be "upgraded" from that value.
|
||||
// V2/V3: -> parray<uint8_t, 0x05>
|
||||
/* 10 */ U32T<BE> armor_shield_type_index_prob_table_offset;
|
||||
|
||||
// This index probability table specifies how common each possible slot
|
||||
// count is for armor drops.
|
||||
// This index probability table specifies how common each possible slot count is for armor drops.
|
||||
// V2/V3: -> parray<uint8_t, 0x05>
|
||||
/* 14 */ U32T<BE> armor_slot_count_prob_table_offset;
|
||||
|
||||
// This array (indexed by enemy_type) specifies the range of meseta values
|
||||
// that each enemy can drop.
|
||||
// V2/V3: -> parray<Range<U16T>, 0x64>
|
||||
/* 18 */ U32T<BE> enemy_meseta_ranges_offset;
|
||||
// This array (indexed by rt_index) specifies the range of meseta values that each enemy can drop.
|
||||
// V2/V3: -> parray<Range<U16T>, NUM_RT_INDEXES_V3>
|
||||
/* 18 */ U32T<BE> enemy_rt_index_meseta_ranges_offset;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the percent
|
||||
// chance that the enemy drops anything at all. (This check is done before
|
||||
// the rare drop check, so the chance of getting a rare item from an enemy
|
||||
// is essentially this probability multiplied by the rare drop rate.)
|
||||
// V2/V3: -> parray<uint8_t, 0x64>
|
||||
/* 1C */ U32T<BE> enemy_type_drop_probs_offset;
|
||||
// Each byte in this table (indexed by rt_index) represents the percent chance that the enemy drops anything at
|
||||
// all. (This check is done before the rare drop check, so the chance of getting a rare item from an enemy is
|
||||
// essentially this probability multiplied by the rare drop rate.)
|
||||
// V2/V3: -> parray<uint8_t, NUM_RT_INDEXES_V3>
|
||||
/* 1C */ U32T<BE> enemy_rt_index_drop_probs_offset;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the class of
|
||||
// item that the enemy can drop. The values are:
|
||||
// 00 = weapon
|
||||
// 01 = armor
|
||||
// 02 = shield
|
||||
// 03 = unit
|
||||
// 04 = tool
|
||||
// 05 = meseta
|
||||
// Anything else = no item
|
||||
// V2/V3: -> parray<uint8_t, 0x64>
|
||||
/* 20 */ U32T<BE> enemy_item_classes_offset;
|
||||
// Each byte in this table (indexed by rt_index) represents the class of item that can drop. The values are:
|
||||
// 00 = weapon
|
||||
// 01 = armor
|
||||
// 02 = shield
|
||||
// 03 = unit
|
||||
// 04 = tool
|
||||
// 05 = meseta
|
||||
// Anything else = no item
|
||||
// V2/V3: -> parray<uint8_t, NUM_RT_INDEXES_V3>
|
||||
/* 20 */ U32T<BE> enemy_rt_index_item_classes_offset;
|
||||
|
||||
// This table (indexed by area - 1) specifies the ranges of meseta values
|
||||
// that can drop from boxes.
|
||||
// This table (indexed by area - 1) specifies the ranges of meseta values that can drop from boxes.
|
||||
// V2/V3: -> parray<Range<U16T>, 0x0A>
|
||||
/* 24 */ U32T<BE> box_meseta_ranges_offset;
|
||||
|
||||
// This array specifies the chance that a rare weapon will have each
|
||||
// possible bonus value. This is indexed as [(bonus_value - 10 / 5)][spec],
|
||||
// so the first row refers the probability of getting a -10% bonus, the next
|
||||
// row is the chance of getting -5%, etc., all the way up to +100%. For
|
||||
// non-rare items, spec is determined randomly based on the following field;
|
||||
// for rare items, spec is always 5.
|
||||
// This array specifies the chance that a rare weapon will have each possible bonus value. This is indexed as
|
||||
// [(bonus_value - 10 / 5)][spec], so the first row refers the probability of getting a -10% bonus, the next row
|
||||
// is the chance of getting -5%, etc., all the way up to +100%. For non-rare items (or all items on v1/v2), spec
|
||||
// is determined randomly based on the following field; for rare items on v3+, spec is always 5.
|
||||
// V2: -> parray<parray<uint8_t, 5>, 0x17>
|
||||
// V3: -> parray<parray<U16T, 6>, 0x17>
|
||||
/* 28 */ U32T<BE> bonus_value_prob_table_offset;
|
||||
|
||||
// This array specifies the value of spec to be used in the above lookup for
|
||||
// non-rare items. This is NOT an index probability table; this is a direct
|
||||
// lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte
|
||||
// of this array prevents any weapon from having a bonus in that slot.
|
||||
// For example, the array might look like this:
|
||||
// This array specifies the value of spec to be used in the above lookup for non-rare items. This is NOT an index
|
||||
// probability table; this is a direct lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte
|
||||
// of this array prevents any weapon from having a bonus in that slot. An example table might look like this:
|
||||
// [00 00 00 01 01 01 01 02 02 02]
|
||||
// [FF FF FF 00 00 00 01 01 01 01]
|
||||
// [FF FF FF FF FF FF FF FF FF 00]
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
// In this example, spec is 0, 1, or 2 in all cases where a weapon can have
|
||||
// a bonus. In Forest 1 and 2 and Cave 1, weapons may have at most one
|
||||
// bonus; in all other areas except Ruins 3, they can have at most two
|
||||
// bonuses, and in Ruins 3, they can have up to three bonuses.
|
||||
// In this example, spec is 0, 1, or 2 in all cases where a weapon can have a bonus. In Forest 1 and 2 and Cave
|
||||
// 1, weapons may have at most one bonus; in all other areas except Ruins 3, they can have at most two bonuses,
|
||||
// and in Ruins 3, they can have up to three bonuses.
|
||||
// V2/V3: // -> parray<parray<uint8_t, 10>, 3>
|
||||
/* 2C */ U32T<BE> nonrare_bonus_prob_spec_offset;
|
||||
|
||||
// This array specifies the chance that a weapon will have each bonus type.
|
||||
// The table is indexed as [bonus_type][area - 1] for non-rare items; for
|
||||
// rare items, a random value in the range [0, 9] is used instead of
|
||||
// (area - 1).
|
||||
// This array specifies the chance that a weapon will have each bonus type. The table is indexed as
|
||||
// [bonus_type][area - 1] for non-rare items; for rare items, a random value in the range [0, 9] is used instead
|
||||
// of (area - 1).
|
||||
// For example, the table might look like this:
|
||||
// [46 46 3F 3E 3E 3D 3C 3C 3A 3A] // Chance of getting no bonus
|
||||
// [14 14 0A 0A 09 02 02 04 05 05] // Chance of getting Native bonus
|
||||
@@ -200,54 +187,50 @@ public:
|
||||
// V2/V3: -> parray<parray<uint8_t, 10>, 6>
|
||||
/* 30 */ U32T<BE> bonus_type_prob_table_offset;
|
||||
|
||||
// This array (indexed by area - 1) specifies a multiplier of used in
|
||||
// special ability determination. It seems this uses the star values from
|
||||
// ItemPMT, but not yet clear exactly in what way.
|
||||
// TODO: Figure out exactly what this does. Anchor: 80106FEC
|
||||
// This array (indexed by area - 1) specifies a parameter used in weapon special generation. If the sampled value
|
||||
// from this table is 0, no special is generated. Otherwise, a random floating-point value W in the range [0,
|
||||
// special_mult] is generated and truncated to an integer. If this value is greater than 3, no special is
|
||||
// generated; otherwise, a random special worth (W + 1) stars is chosen. It seems Sega only intended special_mult
|
||||
// to be in the range [0, 4], but values greater than 4 will work, and will simply increase the probability of
|
||||
// getting no special.
|
||||
// V2/V3: -> parray<uint8_t, 0x0A>
|
||||
/* 34 */ U32T<BE> special_mult_offset;
|
||||
|
||||
// This array (indexed by area - 1) specifies the probability that any
|
||||
// non-rare weapon will have a special ability.
|
||||
// This array (indexed by area - 1) specifies the probability that a non-rare weapon will have a special ability.
|
||||
// V2/V3: -> parray<uint8_t, 0x0A>
|
||||
/* 38 */ U32T<BE> special_percent_offset;
|
||||
|
||||
// This index probability table is indexed by [tool_class][area - 1]. The
|
||||
// tool class refers to an entry in ItemPMT, which links it to the actual
|
||||
// item code.
|
||||
// This index probability table is indexed by [tool_class][area - 1]. The tool class refers to an entry in
|
||||
// ItemPMT, which links it to the actual item code.
|
||||
// V2/V3: -> parray<parray<U16T, 0x0A>, 0x1C>
|
||||
/* 3C */ U32T<BE> tool_class_prob_table_offset;
|
||||
|
||||
// This index probability table determines how likely each technique is to
|
||||
// appear. The table is indexed as [technique_num][area - 1].
|
||||
// This index probability table determines how likely each technique is to appear. The table is indexed as
|
||||
// [technique_num][area - 1].
|
||||
// V2/V3: -> parray<parray<uint8_t, 0x0A>, 0x13>
|
||||
/* 40 */ U32T<BE> technique_index_prob_table_offset;
|
||||
|
||||
// This table specifies the ranges for technique disk levels. The table is
|
||||
// indexed as [technique_num][area - 1]. If either min or max in the range
|
||||
// is 0xFF, or if max < min, technique disks are not dropped for that
|
||||
// technique and area pair.
|
||||
// This table specifies the ranges for technique disk levels. The table is indexed as [technique_num][area - 1].
|
||||
// If either min or max in the range is 0xFF, or if max < min, technique disks are not dropped for that technique
|
||||
// and area pair.
|
||||
// V2/V3: -> parray<parray<Range<uint8_t>, 0x0A>, 0x13>
|
||||
/* 44 */ U32T<BE> technique_level_ranges_offset;
|
||||
|
||||
// See comments on armor_shield_type_index_prob_table_offset for how this is used.
|
||||
/* 48 */ uint8_t armor_or_shield_type_bias;
|
||||
/* 49 */ parray<uint8_t, 3> unused1;
|
||||
|
||||
// These values specify the maximum number of stars any generated unit can
|
||||
// have in each area. The values here are not inclusive; that is, a value
|
||||
// of 7 means that only units with 1-6 stars can drop in that area. The
|
||||
// game uniformly chooses a random number of stars in the acceptable
|
||||
// range, then uniformly chooses a random unit with that many stars.
|
||||
// These values specify the maximum number of stars any generated unit can have in each area. The values here are
|
||||
// not inclusive; that is, a value of 7 means that only units with 1-6 stars can drop in that area. The game
|
||||
// uniformly chooses a random number of stars in the acceptable range, then uniformly chooses a random unit with
|
||||
// that many stars.
|
||||
// V2/V3: -> parray<uint8_t, 0x0A>
|
||||
/* 4C */ U32T<BE> unit_max_stars_offset;
|
||||
|
||||
// This index probability table determines which type of items drop from
|
||||
// boxes. The table is indexed as [item_class][area - 1], with item_class
|
||||
// as the result value (that is, in the example below, the game looks at a
|
||||
// single column and sums the values going down, then the chosen item
|
||||
// class is one of the row indexes based on the weight values in the
|
||||
// column.) The resulting item_class value has the same meaning as in
|
||||
// enemy_item_classes above.
|
||||
// This index probability table determines which type of items drop from boxes. The table is indexed as
|
||||
// [item_class][area - 1], with item_class as the result value (that is, in the example below, the game looks at
|
||||
// a single column and sums the values going down, then the chosen item class is one of the row indexes based on
|
||||
// the weight values in the column.) The resulting value has the same meaning as in enemy_rt_index_item_classes.
|
||||
// For example, this array might look like the following:
|
||||
// [07 07 08 08 06 07 08 09 09 0A] // Chances per area of a weapon drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of an armor drop
|
||||
@@ -271,7 +254,11 @@ public:
|
||||
bool operator==(const CommonItemSet& other) const = default;
|
||||
bool operator!=(const CommonItemSet& other) const = default;
|
||||
|
||||
std::shared_ptr<const Table> get_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const;
|
||||
std::shared_ptr<const Table> get_table(
|
||||
Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id) const;
|
||||
std::shared_ptr<const Table> get_prev_table(
|
||||
Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id) const;
|
||||
|
||||
phosg::JSON json() const;
|
||||
void print(FILE* stream) const;
|
||||
void print_diff(FILE* stream, const CommonItemSet& other) const;
|
||||
@@ -279,7 +266,8 @@ public:
|
||||
protected:
|
||||
CommonItemSet() = default;
|
||||
|
||||
static uint16_t key_for_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid);
|
||||
static uint16_t key_for_table(Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id);
|
||||
static std::string json_key_for_table(Episode episode, GameMode mode, Difficulty difficulty, uint8_t section_id);
|
||||
|
||||
std::unordered_map<uint16_t, std::shared_ptr<Table>> tables;
|
||||
};
|
||||
@@ -299,8 +287,8 @@ public:
|
||||
explicit JSONCommonItemSet(const phosg::JSON& json);
|
||||
};
|
||||
|
||||
// Note: There are clearly better ways of doing this, but this implementation
|
||||
// closely follows what the original code in the client does.
|
||||
// Note: There are clearly better ways of doing this, but this implementation closely follows what the original code in
|
||||
// the client does.
|
||||
template <typename ItemT, size_t MaxCount>
|
||||
struct ProbabilityTable {
|
||||
ItemT items[MaxCount];
|
||||
@@ -368,11 +356,9 @@ protected:
|
||||
RELFileSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
template <typename T>
|
||||
std::pair<const T*, size_t> get_table(
|
||||
const TableSpec& spec, size_t index) const {
|
||||
std::pair<const T*, size_t> get_table(const TableSpec& spec, size_t index) const {
|
||||
const T* entries = &r.pget<T>(
|
||||
spec.offset + index * spec.entries_per_table * sizeof(T),
|
||||
spec.entries_per_table * sizeof(T));
|
||||
spec.offset + index * spec.entries_per_table * sizeof(T), spec.entries_per_table * sizeof(T));
|
||||
return std::make_pair(entries, spec.entries_per_table);
|
||||
}
|
||||
};
|
||||
@@ -485,17 +471,14 @@ private:
|
||||
} __packed_ws__(LuckTableEntry, 2);
|
||||
|
||||
struct Offsets {
|
||||
// Each section ID's favored weapon class has different probabilities than
|
||||
// those used for all other weapons. The tables are labeled with (D) for the
|
||||
// default values and (F) for the favored-class values.
|
||||
// Each section ID's favored weapon class has different probabilities than those used for all other weapons. The
|
||||
// tables are labeled with (D) for the default values and (F) for the favored-class values.
|
||||
|
||||
// Note that the favored bonuses for Redria are all zero; these values are
|
||||
// unused because Redria does not have a favored weapon type. Curiously,
|
||||
// Yellowboze also does not have a favored weapon type, but the values for
|
||||
// Note that the favored bonuses for Redria are all zero; these values are unused because Redria does not have a
|
||||
// favored weapon type. Curiously, Yellowboze also does not have a favored weapon type, but the values for
|
||||
// Yellowboze are not all zero.
|
||||
|
||||
// This table specifies how likely a special is to be upgraded or
|
||||
// downgraded by one level.
|
||||
// This table specifies how likely a special is to be upgraded or downgraded by one level.
|
||||
// In PSO V3, the special upgrade table is:
|
||||
// Viridia => (D) +1=10%, 0=60%, -1=30%
|
||||
// Viridia => (F) +1=25%, 0=50%, -1=25%
|
||||
@@ -519,9 +502,8 @@ private:
|
||||
// Whitill => (F) +1=25%, 0=50%, -1=25%
|
||||
be_uint32_t special_upgrade_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's grind is to be upgraded or
|
||||
// downgraded, and by how much. The final grind value is clamped to the
|
||||
// range between 0 and the weapon's maximum grind from ItemPMT, inclusive.
|
||||
// This table specifies how likely a weapon's grind is to be upgraded or downgraded, and by how much. The final
|
||||
// grind value is clamped to the range between 0 and the weapon's maximum grind from ItemPMT, inclusive.
|
||||
// In PSO V3, the grind delta table is:
|
||||
// Viridia => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Viridia => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
@@ -545,9 +527,8 @@ private:
|
||||
// Whitill => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
be_uint32_t grind_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's bonuses are to be upgraded
|
||||
// or downgraded, and by how much. The final bonuses are capped above at
|
||||
// 100, but there is no lower limit (so negative results are possible).
|
||||
// This table specifies how likely a weapon's bonuses are to be upgraded or downgraded, and by how much. The final
|
||||
// bonuses are capped above at 100, but there is no lower limit (so negative results are possible).
|
||||
// In PSO V3, the bonus delta table is:
|
||||
// Viridia => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Viridia => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
@@ -571,11 +552,10 @@ private:
|
||||
// Whitill => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
be_uint32_t bonus_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// There is a secondary computation done during weapon adjustment that
|
||||
// appears to determine how "good" the resulting weapon is compared to its
|
||||
// original state. If the result of this computation is positive, the game
|
||||
// plays a jingle when the tekker result is accepted. These tables describe
|
||||
// how much each delta affects this value, which we call luck.
|
||||
// There is a secondary computation done during weapon adjustment that appears to determine how "good" the
|
||||
// resulting weapon is compared to its original state. If the result of this computation is positive, the game
|
||||
// plays a jingle when the tekker result is accepted. These tables describe how much each delta affects this value,
|
||||
// which we call luck.
|
||||
|
||||
// In PSO V3, the special upgrade luck table is:
|
||||
// +1 => +20, 0 => 0, -1 => -20
|
||||
|
||||
+89
-141
@@ -63,14 +63,11 @@ struct WindowIndex {
|
||||
return match_iter - match_offset;
|
||||
};
|
||||
|
||||
// The data structure we want is a binary-searchable set of all strings
|
||||
// starting at all possible offsets within the sliding window, and we need
|
||||
// to be able to search lexicographically but insert and delete by offset.
|
||||
// A std::map<std::string, size_t> would accomplish this, but would be
|
||||
// horrendously inefficient: we'd have to copy strings far too much. We can
|
||||
// solve this by instead storing the offset of each string as keys in a set
|
||||
// and using a custom comparator to treat them as references to binary
|
||||
// strings within the data.
|
||||
// The data structure we want is a binary-searchable set of all strings starting at all possible offsets within the
|
||||
// sliding window, and we need to be able to search lexicographically but insert and delete by offset. A
|
||||
// std::map<std::string, size_t> would accomplish this, but would be horrendously inefficient: we'd have to copy
|
||||
// strings far too much. We can solve this by instead storing the offset of each string as keys in a set and using a
|
||||
// custom comparator to treat them as references to binary strings within the data.
|
||||
bool set_comparator(size_t a, size_t b) const {
|
||||
size_t max_length = min<size_t>(MaxMatchLength, this->size - max<size_t>(a, b));
|
||||
size_t end_a = a + max_length;
|
||||
@@ -87,11 +84,9 @@ struct WindowIndex {
|
||||
};
|
||||
|
||||
pair<size_t, size_t> get_best_match() const {
|
||||
// Find the best match from the index. It's unlikely that we'll get an
|
||||
// exact match, so check the entry before the upper_bound result too.
|
||||
// Note: We use upper_bound rather than lower_bound because in PRS, a
|
||||
// backreference can be encoded with fewer bits if it's close to the
|
||||
// decompression offset, and this makes us pick the latest match by
|
||||
// Find the best match from the index. It's unlikely that we'll get an exact match, so check the entry before the
|
||||
// upper_bound result too. Note: We use upper_bound rather than lower_bound because in PRS, a backreference can be
|
||||
// encoded with fewer bits if it's close to the decompression offset, and this makes us pick the latest match by
|
||||
// default.
|
||||
size_t match_offset = 0;
|
||||
size_t match_size = 0;
|
||||
@@ -123,9 +118,7 @@ struct LZSSInterleavedWriter {
|
||||
uint8_t next_control_bit;
|
||||
uint8_t buf[0x19];
|
||||
|
||||
LZSSInterleavedWriter()
|
||||
: buf_offset(1),
|
||||
next_control_bit(1) {
|
||||
LZSSInterleavedWriter() : buf_offset(1), next_control_bit(1) {
|
||||
this->buf[0] = 0;
|
||||
}
|
||||
|
||||
@@ -166,9 +159,7 @@ struct LZSSInterleavedWriter {
|
||||
|
||||
class ControlStreamReader {
|
||||
public:
|
||||
ControlStreamReader(phosg::StringReader& r)
|
||||
: r(r),
|
||||
bits(0x0000) {}
|
||||
ControlStreamReader(phosg::StringReader& r) : r(r), bits(0x0000) {}
|
||||
|
||||
bool read() {
|
||||
if (!(this->bits & 0x0100)) {
|
||||
@@ -285,8 +276,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
|
||||
long_window_thread.join();
|
||||
extended_window_thread.join();
|
||||
|
||||
// For each node, populate the literal value, and the best ways to get to the
|
||||
// following nodes
|
||||
// For each node, populate the literal value, and the best ways to get to the following nodes
|
||||
for (size_t z = 0; z < in_size; z++) {
|
||||
if ((z & 0xFFF) == 0 && progress_fn) {
|
||||
progress_fn(CompressPhase::CONSTRUCT_PATHS, z, in_size, 0);
|
||||
@@ -441,9 +431,8 @@ string prs_compress_optimal(const string& data, ProgressCallback progress_fn) {
|
||||
string prs_compress_pessimal(const void* vdata, size_t size) {
|
||||
const uint8_t* in_data = reinterpret_cast<const uint8_t*>(vdata);
|
||||
|
||||
// The worst possible encoding we can do is a literal byte when no byte with
|
||||
// the same value is within the window, or an extended copy if there is a byte
|
||||
// with the same value in the window.
|
||||
// The worst possible encoding we can do is a literal byte when no byte with the same value is within the window, or
|
||||
// an extended copy if there is a byte with the same value in the window.
|
||||
WindowIndex<0x1FFF, 1> window(in_data, size);
|
||||
LZSSInterleavedWriter w;
|
||||
for (size_t z = 0; z < size; z++) {
|
||||
@@ -539,9 +528,8 @@ void PRSCompressor::advance() {
|
||||
match_size++;
|
||||
}
|
||||
|
||||
// If there are multiple matches of the longest length, use the latest one,
|
||||
// since it's more likely that it can be expressed as a short copy instead
|
||||
// of a long copy.
|
||||
// If there are multiple matches of the longest length, use the latest one, since it's more likely that it can be
|
||||
// expressed as a short copy instead of a long copy.
|
||||
if (match_size >= (best_match_size + best_match_literals)) {
|
||||
best_match_offset = match_offset;
|
||||
best_match_size = match_size;
|
||||
@@ -558,15 +546,13 @@ void PRSCompressor::advance() {
|
||||
this->advance_literal();
|
||||
}
|
||||
|
||||
// If there is a suitable match, write a backreference; otherwise, write a
|
||||
// literal. The backreference should be encoded:
|
||||
// If there is a match, write a backreference; otherwise, write a literal. The backreference should be encoded:
|
||||
// - As a short copy if offset in [-0x100, -1] and size in [2, 5]
|
||||
// - As a long copy if offset in [-0x1FFF, -1] and size in [3, 9]
|
||||
// - As an extended copy if offset in [-0x1FFF, -1] and size in [10, 0x100]
|
||||
// Technically an extended copy can be used for sizes 1-9 as well, but if
|
||||
// size is 1 or 2, writing literals is better (since it uses fewer data
|
||||
// bytes and control bits), and a long copy can cover sizes 3-9 (and also
|
||||
// uses fewer data bytes and control bits).
|
||||
// Technically an extended copy can be used for sizes 1-9 as well, but if size is 1 or 2, writing literals is better
|
||||
// (since it uses fewer data bytes and control bits), and a long copy can cover sizes 3-9 (and also uses fewer data
|
||||
// bytes and control bits).
|
||||
ssize_t backreference_offset = best_match_offset - this->reverse_log.end_offset();
|
||||
if (best_match_size < 2) {
|
||||
// The match is too small; a literal would use fewer bits
|
||||
@@ -576,8 +562,8 @@ void PRSCompressor::advance() {
|
||||
this->advance_short_copy(backreference_offset, best_match_size);
|
||||
|
||||
} else if (best_match_size < 3) {
|
||||
// We can't use a long copy for size 2, and it's not worth it to use an
|
||||
// extended copy for this either (as noted above), so write a literal
|
||||
// We can't use a long copy for size 2, and it's not worth it to use an extended copy for this either (as noted
|
||||
// above), so write a literal
|
||||
this->advance_literal();
|
||||
|
||||
} else if ((backreference_offset >= -0x1FFF) && (best_match_size <= 9)) {
|
||||
@@ -655,14 +641,12 @@ string& PRSCompressor::close() {
|
||||
|
||||
void PRSCompressor::write_control(bool z) {
|
||||
if (this->pending_control_bits & 0x0100) {
|
||||
this->output.pput_u8(
|
||||
this->control_byte_offset, this->pending_control_bits & 0xFF);
|
||||
this->output.pput_u8(this->control_byte_offset, this->pending_control_bits & 0xFF);
|
||||
this->control_byte_offset = this->output.size();
|
||||
this->output.put_u8(0);
|
||||
this->pending_control_bits = z ? 0x8080 : 0x8000;
|
||||
} else {
|
||||
this->pending_control_bits =
|
||||
(this->pending_control_bits >> 1) | (z ? 0x8080 : 0x8000);
|
||||
this->pending_control_bits = (this->pending_control_bits >> 1) | (z ? 0x8080 : 0x8000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,8 +655,7 @@ void PRSCompressor::flush_control() {
|
||||
while (!(this->pending_control_bits & 0x0100)) {
|
||||
this->pending_control_bits >>= 1;
|
||||
}
|
||||
this->output.pput_u8(
|
||||
this->control_byte_offset, this->pending_control_bits & 0xFF);
|
||||
this->output.pput_u8(this->control_byte_offset, this->pending_control_bits & 0xFF);
|
||||
} else {
|
||||
if (this->control_byte_offset != this->output.size() - 1) {
|
||||
throw logic_error("data written without control bits");
|
||||
@@ -681,25 +664,17 @@ void PRSCompressor::flush_control() {
|
||||
}
|
||||
}
|
||||
|
||||
string prs_compress(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ssize_t compression_level,
|
||||
ProgressCallback progress_fn) {
|
||||
string prs_compress(const void* vdata, size_t size, ssize_t compression_level, ProgressCallback progress_fn) {
|
||||
PRSCompressor prs(compression_level, progress_fn);
|
||||
prs.add(vdata, size);
|
||||
return std::move(prs.close());
|
||||
}
|
||||
|
||||
string prs_compress(
|
||||
const string& data,
|
||||
ssize_t compression_level,
|
||||
ProgressCallback progress_fn) {
|
||||
string prs_compress(const string& data, ssize_t compression_level, ProgressCallback progress_fn) {
|
||||
return prs_compress(data.data(), data.size(), compression_level, progress_fn);
|
||||
}
|
||||
|
||||
string prs_compress_indexed(
|
||||
const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
|
||||
string prs_compress_indexed(const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
|
||||
const uint8_t* in_data = reinterpret_cast<const uint8_t*>(in_data_v);
|
||||
|
||||
LZSSInterleavedWriter w;
|
||||
@@ -718,14 +693,11 @@ string prs_compress_indexed(
|
||||
auto m_long = w_long.get_best_match();
|
||||
auto m_extended = w_extended.get_best_match();
|
||||
|
||||
// Write the match that achieves the best ratio of output bytes to
|
||||
// compressed bits used. To do this without floating-point math, we multiply
|
||||
// the output byte count for each type of command by 468 / (command_bits),
|
||||
// since 468 is the least common multiple of the number of bits for each
|
||||
// command type. The command type with the highest score is the one we'll
|
||||
// use, breaking ties by choosing the shorter command type. Note that the
|
||||
// size of any copy type can be zero if no match was found; if no matches
|
||||
// were found at all, then we can always write a literal.
|
||||
// Write the match that achieves the best ratio of output bytes to compressed bits used. To do this without
|
||||
// floating-point math, we multiply the output byte count for each type of command by 468 / (command_bits), since
|
||||
// 468 is the least common multiple of the number of bits for each command type. The command type with the highest
|
||||
// score is the one we'll use, breaking ties by choosing the shorter command type. Note that the size of any copy
|
||||
// type can be zero if no match was found; if no matches were found at all, then we can always write a literal.
|
||||
size_t score_literal = 52;
|
||||
size_t score_short = m_short.second * 39;
|
||||
size_t score_long = m_long.second * 26;
|
||||
@@ -838,41 +810,30 @@ string prs_compress_indexed(const string& data, ProgressCallback progress_fn) {
|
||||
|
||||
PRSDecompressResult prs_decompress_with_meta(
|
||||
const void* data, size_t size, size_t max_output_size, bool allow_unterminated) {
|
||||
// PRS is an LZ77-based compression algorithm. Compressed data is split into
|
||||
// two streams: a control stream and a data stream. The control stream is read
|
||||
// one bit at a time, and the data stream is read one byte at a time. The
|
||||
// streams are interleaved such that the decompressor never has to move
|
||||
// backward in the input stream - when the decompressor needs a control bit
|
||||
// and there are no unused bits from the previous byte of the control stream,
|
||||
// it reads a byte from the input and treats it as the next 8 control bits.
|
||||
// PRS is an LZ77-based compression algorithm. Compressed data is split into two streams: a control stream and a data
|
||||
// stream. The control stream is read one bit at a time, and the data stream is read one byte at a time. The streams
|
||||
// are interleaved such that the decompressor never has to move backward in the input stream - when the decompressor
|
||||
// needs a control bit and there are no unused bits from the previous byte of the control stream, it reads a byte
|
||||
// from the input and treats it as the next 8 control bits.
|
||||
|
||||
// There are 3 distinct commands in PRS, labeled here with their control bits:
|
||||
// 1 - Literal byte. The decompressor copies one byte from the input data
|
||||
// stream to the output.
|
||||
// 00 - Short backreference. The decompressor reads two control bits and adds
|
||||
// 2 to this value to determine the number of bytes to copy, then reads
|
||||
// one byte from the data stream to determine how far back in the output
|
||||
// to copy from. This byte is treated as an 8-bit negative number - so
|
||||
// 0xF7, for example, means to start copying data from 9 bytes before the
|
||||
// end of the output. The range must start before the end of the output,
|
||||
// but the end of the range may be beyond the end of the output. In this
|
||||
// case, the bytes between the beginning of the range and original end of
|
||||
// the output are simply repeated.
|
||||
// 01 - Long backreference. The decompressor reads two bytes from the data and
|
||||
// byteswaps the resulting 16-bit value (that is, the low byte is read
|
||||
// first). The start offset (again, as a negative number) is the top 13
|
||||
// bits of this value; the size is the low 3 bits of this value, plus 2.
|
||||
// If the size bits are all zero, an additional byte is read from the
|
||||
// data stream and 1 is added to it to determine the backreference size
|
||||
// (we call this an extended backreference). Therefore, the maximum
|
||||
// backreference size is 256 bytes.
|
||||
// Decompression ends when either there are no more input bytes to read, or
|
||||
// when a long backreference is read with all zeroes in its offset field. The
|
||||
// original implementation stops decompression successfully when any attempt
|
||||
// to read from the input encounters the end of the stream, but newserv's
|
||||
// implementation only allows this at the end of an opcode - if end-of-stream
|
||||
// is encountered partway through an opcode, we throw instead, because it's
|
||||
// likely the input has been truncated or is malformed in some way.
|
||||
// 1 - Literal byte. The decompressor copies one byte from the input data stream to the output.
|
||||
// 00 - Short backreference. The decompressor reads two control bits and adds 2 to this value to determine the number
|
||||
// of bytes to copy, then reads one byte from the data stream to determine how far back in the output to copy
|
||||
// from. This byte is treated as an 8-bit negative number - so 0xF7, for example, means to start copying data
|
||||
// from 9 bytes before the end of the output. The range must start before the end of the output, but the end of
|
||||
// the range may be beyond the end of the output. In this case, the bytes between the beginning of the range and
|
||||
// original end of the output are simply repeated.
|
||||
// 01 - Long backreference. The decompressor reads two bytes from the data and byteswaps the resulting 16-bit value
|
||||
// (that is, the low byte is read first). The start offset (again, as a negative number) is the top 13 bits of
|
||||
// this value; the size is the low 3 bits of this value, plus 2. If the size bits are all zero, an additional
|
||||
// byte is read from the data stream and 1 is added to it to determine the backreference size (we call this an
|
||||
// extended backreference). Therefore, the maximum backreference size is 256 bytes.
|
||||
// Decompression ends when either there are no more input bytes to read, or when a long backreference is read with
|
||||
// all zeroes in its offset field. The original implementation stops decompression successfully when any attempt to
|
||||
// read from the input encounters the end of the stream, but newserv's implementation only allows this at the end of
|
||||
// an opcode - if end-of-stream is encountered partway through an opcode, we throw instead, because it's likely the
|
||||
// input has been truncated or is malformed in some way.
|
||||
|
||||
phosg::StringWriter w;
|
||||
phosg::StringReader r(data, size);
|
||||
@@ -894,10 +855,9 @@ PRSDecompressResult prs_decompress_with_meta(
|
||||
ssize_t offset;
|
||||
size_t count;
|
||||
|
||||
// Control 01 = long backreference
|
||||
if (cr.read()) {
|
||||
// The bits stored in the data stream are AAAAABBBCCCCCCCC, which we
|
||||
// rearrange into offset = CCCCCCCCAAAAA and size = BBB.
|
||||
// Control 01 = long backreference
|
||||
// The bits from the data stream are AAAAABBBCCCCCCCC, which we rearrange as offset=CCCCCCCCAAAAA and size=BBB.
|
||||
uint16_t a = r.get_u8();
|
||||
a |= (r.get_u8() << 8);
|
||||
offset = (a >> 3) | (~0x1FFF);
|
||||
@@ -905,24 +865,21 @@ PRSDecompressResult prs_decompress_with_meta(
|
||||
if (offset == ~0x1FFF) {
|
||||
break;
|
||||
}
|
||||
// If the size field is zero, it's an extended backreference (size comes
|
||||
// from another byte in the data stream)
|
||||
// If the size field is zero, it's an extended backreference (size comes from another byte in the data stream)
|
||||
count = (a & 7) ? ((a & 7) + 2) : (r.get_u8() + 1);
|
||||
|
||||
// Control 00 = short backreference
|
||||
} else {
|
||||
// Count comes from 2 bits in the control stream instead of from the
|
||||
// data stream (and 2 is added). Importantly, the control stream bits
|
||||
// are read first - this may involve reading another control stream
|
||||
// byte, which happens before the offset is read from the data stream.
|
||||
// Control 00 = short backreference
|
||||
// Count comes from 2 bits in the control stream instead of from the data stream (and 2 is added). Importantly,
|
||||
// the control stream bits are read first - this may involve reading another control stream byte, which happens
|
||||
// before the offset is read from the data stream.
|
||||
count = cr.read() << 1;
|
||||
count = (count | cr.read()) + 2;
|
||||
offset = r.get_u8() | (~0xFF);
|
||||
}
|
||||
|
||||
// Copy bytes from the referenced location in the output. Importantly,
|
||||
// copy only one byte at a time, in order to support ranges that cover the
|
||||
// current end of the output.
|
||||
// Copy bytes from the referenced location in the output. Importantly, copy only one byte at a time, in order to
|
||||
// support ranges that cover the current end of the output.
|
||||
size_t read_offset = w.size() + offset;
|
||||
if (read_offset >= w.size()) {
|
||||
throw runtime_error("backreference offset beyond beginning of output");
|
||||
@@ -1069,11 +1026,10 @@ void prs_disassemble(FILE* stream, const std::string& data) {
|
||||
return prs_disassemble(stream, data.data(), data.size());
|
||||
}
|
||||
|
||||
// BC0 is a compression algorithm fairly similar to PRS, but with a simpler set
|
||||
// of commands. Like PRS, there is a control stream, indicating when to copy a
|
||||
// literal byte from the input and when to copy from a backreference; unlike
|
||||
// PRS, there is only one type of backreference. Also, there is no stop opcode;
|
||||
// the decompressor simply stops when there are no more input bytes to read.
|
||||
// BC0 is a compression algorithm fairly similar to PRS, but with a simpler set of commands. Like PRS, there is a
|
||||
// control stream, indicating when to copy a literal byte from the input and when to copy from a backreference; unlike
|
||||
// PRS, there is only one type of backreference. Also, there is no stop opcode; the decompressor simply stops when
|
||||
// there are no more input bytes to read.
|
||||
|
||||
struct BC0PathNode {
|
||||
uint16_t memo_offset = 0;
|
||||
@@ -1112,8 +1068,7 @@ string bc0_compress_optimal(
|
||||
}
|
||||
}
|
||||
|
||||
// For each node, populate the literal value, and the best ways to get to the
|
||||
// following nodes
|
||||
// For each node, populate the literal value, and the best ways to get to the following nodes
|
||||
for (size_t z = 0; z < in_size; z++) {
|
||||
if ((z & 0xFFF) == 0 && progress_fn) {
|
||||
progress_fn(CompressPhase::CONSTRUCT_PATHS, z, in_size, 0);
|
||||
@@ -1238,11 +1193,9 @@ string bc0_encode(const void* in_data_v, size_t in_size) {
|
||||
return std::move(w.close());
|
||||
}
|
||||
|
||||
// The BC0 decompression implementation in PSO GC is vulnerable to overflow
|
||||
// attacks - there is no bounds checking on the output buffer. It is unlikely
|
||||
// that this can be usefully exploited (e.g. for RCE) because the output pointer
|
||||
// is loaded from memory before every byte is written, so we cannot change the
|
||||
// output pointer to any arbitrary address.
|
||||
// The BC0 decompression implementation in PSO GC is vulnerable to overflow attacks - there is no bounds checking on
|
||||
// the output buffer. It is unlikely that this can be usefully exploited (e.g. for RCE) because the output pointer is
|
||||
// loaded from memory before every byte is written, so we cannot change the output pointer to any arbitrary address.
|
||||
|
||||
string bc0_decompress(const string& data) {
|
||||
return bc0_decompress(data.data(), data.size());
|
||||
@@ -1252,22 +1205,18 @@ string bc0_decompress(const void* data, size_t size) {
|
||||
phosg::StringReader r(data, size);
|
||||
phosg::StringWriter w;
|
||||
|
||||
// Unlike PRS, BC0 uses a memo which "rolls over" every 0x1000 bytes. The
|
||||
// boundaries of these "memo pages" are offset by -0x12 bytes for some reason,
|
||||
// so the first output byte corresponds to position 0xFEE on the first memo
|
||||
// page. Backreferences refer to offsets based on the start of memo pages; for
|
||||
// example, if the current output offset is 0x1234, a backreference with
|
||||
// offset 0x123 refers to the byte that was written at offset 0x1111 (because
|
||||
// that byte is at offset 0x111 in the memo, because the memo rolls over every
|
||||
// 0x1000 bytes and the first memo byte was 0x12 bytes before the beginning of
|
||||
// the next page). The memo is initially zeroed from 0 to 0xFEE; it seems PSO
|
||||
// GC doesn't initialize the last 0x12 bytes of the first memo page.
|
||||
// Unlike PRS, BC0 uses a memo which "rolls over" every 0x1000 bytes. The boundaries of these "memo pages" are offset
|
||||
// by -0x12 bytes for some reason, so the first output byte corresponds to position 0xFEE on the first memo page.
|
||||
// Backreferences refer to offsets based on the start of memo pages; for example, if the current output offset is
|
||||
// 0x1234, a backreference with offset 0x123 refers to the byte that was written at offset 0x1111 (because that byte
|
||||
// is at offset 0x111 in the memo, because the memo rolls over every 0x1000 bytes and the first memo byte was 0x12
|
||||
// bytes before the beginning of the next page). The memo is initially zeroed from 0 to 0xFEE; it seems PSO GC
|
||||
// doesn't initialize the last 0x12 bytes of the first memo page.
|
||||
parray<uint8_t, 0x1000> memo;
|
||||
uint16_t memo_offset = 0x0FEE;
|
||||
|
||||
// The low byte of this value contains the control stream data; the high bits
|
||||
// specify which low bits are valid. When the last 1 is shifted out of the
|
||||
// high byte, we need to read a new control stream byte to get the next set of
|
||||
// The low byte of this value contains the control stream data; the high bits specify which low bits are valid. When
|
||||
// the last 1 is shifted out of the high byte, we need to read a new control stream byte to get the next set of
|
||||
// control bits.
|
||||
uint16_t control_stream_bits = 0x0000;
|
||||
|
||||
@@ -1282,14 +1231,13 @@ string bc0_decompress(const void* data, size_t size) {
|
||||
}
|
||||
|
||||
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.
|
||||
// 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;
|
||||
@@ -1305,8 +1253,8 @@ string bc0_decompress(const void* data, size_t size) {
|
||||
}
|
||||
|
||||
} 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.
|
||||
// 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.
|
||||
uint8_t v = r.get_u8();
|
||||
w.put_u8(v);
|
||||
memo[memo_offset] = v;
|
||||
|
||||
+35
-58
@@ -22,39 +22,32 @@ const char* phosg::name_for_enum<CompressPhase>(CompressPhase v);
|
||||
|
||||
typedef std::function<void(CompressPhase phase, size_t input_progress, size_t input_size, size_t output_size)> ProgressCallback;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PRS compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Use this class if you need to compress from multiple input buffers, or need
|
||||
// to compress multiple chunks and don't want to copy their contents
|
||||
// unnecessarily. (For most common use cases, use prs_compress, below, instead.)
|
||||
// To use this class, instantiate it, then call .add() one or more times, then
|
||||
// call .close() and use the returned string as the compressed result.
|
||||
// Use this class if you need to compress from multiple input buffers, or need to compress multiple chunks and don't
|
||||
// want to copy their contents unnecessarily. (For most common use cases, use prs_compress, below, instead.) To use
|
||||
// this class, instantiate it, then call .add() one or more times, then call .close() and use the returned string as
|
||||
// the compressed result.
|
||||
class PRSCompressor {
|
||||
public:
|
||||
// compression_level specifies how aggressively to search for alternate paths:
|
||||
// -1: Don't perform any compression at all, but produce output that can be
|
||||
// understood by prs_decompress. The output will be about 9/8 the size
|
||||
// of the input.
|
||||
// 0: Greedily search for the longest backreference at every point. Don't
|
||||
// consider any alternate paths. Generally offers a good balance between
|
||||
// speed and output size.
|
||||
// 1: Consider two paths at each point when a backreference is found: using
|
||||
// the backreference or ignoring it.
|
||||
// 2+: Consider further chains of paths at each point. Using values 2 or
|
||||
// greater for compression_level generally yields diminishing returns.
|
||||
// -1: Don't perform any compression at all, but produce output that can be understood by prs_decompress. The
|
||||
// output will be about 9/8 the size of the input.
|
||||
// 0: Greedily search for the longest backreference at every point. Don't consider any alternate paths. Generally
|
||||
// offers a good balance between speed and output size.
|
||||
// 1: Consider two paths at each point when a backreference is found: using the backreference or ignoring it.
|
||||
// 2+: Consider further chains of paths at each point. Using values 2 or greater for compression_level generally
|
||||
// yields diminishing returns.
|
||||
explicit PRSCompressor(ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
~PRSCompressor() = default;
|
||||
|
||||
// Adds more input data to be compressed, which logically comes after all
|
||||
// previous data provided via add() calls. Cannot be called after close() is
|
||||
// called.
|
||||
// Adds more input data to be compressed, which logically comes after all previous data provided via add() calls.
|
||||
// Cannot be called after close() is called.
|
||||
void add(const void* data, size_t size);
|
||||
void add(const std::string& data);
|
||||
|
||||
// Ends compression and returns the complete compressed result. It's OK to
|
||||
// std::move() from the returned string reference.
|
||||
// Ends compression and returns the complete compressed result. It's OK to std::move() from the returned reference.
|
||||
std::string& close();
|
||||
|
||||
// Returns the total number of bytes passed to add() calls so far.
|
||||
@@ -149,36 +142,24 @@ private:
|
||||
phosg::StringWriter output;
|
||||
};
|
||||
|
||||
// These functions use PRSCompressor to compress a buffer of data. This is
|
||||
// essentially a shortcut for constructing a PRSCompressor, calling .add() on
|
||||
// it once, then calling .close().
|
||||
// These functions use PRSCompressor to compress a buffer of data. This is essentially a shortcut for constructing a
|
||||
// PRSCompressor, calling .add() on it once, then calling .close().
|
||||
std::string prs_compress(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ssize_t compression_level = 0,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
const void* vdata, size_t size, ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress(
|
||||
const std::string& data,
|
||||
ssize_t compression_level = 0,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
const std::string& data, ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// A faster form of prs_compress that doesn't have a tunable compression level.
|
||||
std::string prs_compress_indexed(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress_indexed(
|
||||
const std::string& data,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress_indexed(const void* vdata, size_t size, ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress_indexed(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Compresses data using PRS to the smallest possible output size. This function
|
||||
// is slow, but produces results significantly smaller than even Sega's original
|
||||
// compressor.
|
||||
// Compresses data using PRS to the smallest possible output size. This function is slow, but produces results
|
||||
// significantly smaller than even Sega's original compressor.
|
||||
std::string prs_compress_optimal(const void* vdata, size_t size, ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress_optimal(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Compresses data using PRS to the LARGEST possible output size. There is no
|
||||
// practical use for this function except for amusement.
|
||||
// Compresses data using PRS to the LARGEST possible output size. There is no practical use for this function except
|
||||
// for amusement.
|
||||
std::string prs_compress_pessimal(const void* vdata, size_t size);
|
||||
|
||||
// Decompresses PRS-compressed data.
|
||||
@@ -186,13 +167,14 @@ struct PRSDecompressResult {
|
||||
std::string data;
|
||||
size_t input_bytes_used;
|
||||
};
|
||||
PRSDecompressResult prs_decompress_with_meta(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
PRSDecompressResult prs_decompress_with_meta(
|
||||
const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
PRSDecompressResult prs_decompress_with_meta(
|
||||
const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
// Returns the decompressed size of PRS-compressed data, without actually
|
||||
// decompressing it.
|
||||
// Returns the decompressed size of PRS-compressed data, without actually decompressing it.
|
||||
size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
size_t prs_decompress_size(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
@@ -200,21 +182,16 @@ size_t prs_decompress_size(const std::string& data, size_t max_output_size = 0,
|
||||
void prs_disassemble(FILE* stream, const void* data, size_t size);
|
||||
void prs_disassemble(FILE* stream, const std::string& data);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BC0 compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant
|
||||
// is slow, but produces the smallest possible output.
|
||||
std::string bc0_compress_optimal(
|
||||
const void* in_data_v,
|
||||
size_t in_size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant is slow, but produces the smallest
|
||||
// possible output.
|
||||
std::string bc0_compress(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
std::string bc0_compress(const void* in_data_v, size_t in_size, ProgressCallback progress_fn = nullptr);
|
||||
std::string bc0_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Encodes data in a BC0-compatible format without compression (similar to using
|
||||
// compression_level=-1 with prs_compress).
|
||||
// Encodes data in a BC0-compatible format without compression (similar to compression_level=-1 in prs_compress).
|
||||
std::string bc0_encode(const void* in_data_v, size_t in_size);
|
||||
|
||||
// Decompresses BC0-compressed data.
|
||||
|
||||
+724
-1106
File diff suppressed because it is too large
Load Diff
+8
-12
@@ -5,20 +5,16 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
// dc_serial_number_is_valid_slow is Sega's implementation;
|
||||
// dc_serial_number_is_valid_fast produces identical results but is between 3000
|
||||
// and 7500 times faster, depending on the compiler's optimization level.
|
||||
bool dc_serial_number_is_valid_slow(
|
||||
const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(
|
||||
const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(
|
||||
uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool decoded_dc_serial_number_is_valid_fast(
|
||||
uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
// dc_serial_number_is_valid_slow is Sega's implementation; dc_serial_number_is_valid_fast produces identical results
|
||||
// but is between 3000 and 7500 times faster, depending on the compiler's optimization level.
|
||||
bool dc_serial_number_is_valid_slow(const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool decoded_dc_serial_number_is_valid_fast(uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
|
||||
std::string generate_dc_serial_number(uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
std::unordered_map<uint32_t, std::string> generate_all_dc_serial_numbers(uint8_t domain = 0xFF, uint8_t subdomain = 0xFF);
|
||||
std::unordered_map<uint32_t, std::string> generate_all_dc_serial_numbers(
|
||||
uint8_t domain = 0xFF, uint8_t subdomain = 0xFF);
|
||||
|
||||
struct DCSerialNumberIterator {
|
||||
bool started = false;
|
||||
|
||||
+13
-15
@@ -40,7 +40,7 @@ DownloadSession::DownloadSession(
|
||||
uint16_t remote_port,
|
||||
const std::string& output_dir,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file,
|
||||
uint32_t serial_number2,
|
||||
uint32_t serial_number,
|
||||
@@ -222,13 +222,13 @@ void DownloadSession::send_61_98(bool is_98) {
|
||||
if (is_v1(this->version)) {
|
||||
C_CharacterData_DCv1_61_98 ret;
|
||||
ret.inventory = this->character->inventory;
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, 1, 1);
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, Language::ENGLISH, Language::ENGLISH);
|
||||
this->channel->send(command, 0x01, ret);
|
||||
|
||||
} else if (this->version == Version::DC_V2) {
|
||||
C_CharacterData_DCv2_61_98 ret;
|
||||
ret.inventory = this->character->inventory;
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, 1, 1);
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, Language::ENGLISH, Language::ENGLISH);
|
||||
ret.records.challenge = this->character->challenge_records;
|
||||
ret.records.battle = this->character->battle_records;
|
||||
ret.choice_search_config = this->character->choice_search_config;
|
||||
@@ -237,7 +237,7 @@ void DownloadSession::send_61_98(bool is_98) {
|
||||
} else if (this->version == Version::PC_V2) {
|
||||
C_CharacterData_PC_61_98 ret;
|
||||
ret.inventory = this->character->inventory;
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, 1, 1);
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, Language::ENGLISH, Language::ENGLISH);
|
||||
ret.records.challenge = this->character->challenge_records;
|
||||
ret.records.battle = this->character->battle_records;
|
||||
ret.choice_search_config = this->character->choice_search_config;
|
||||
@@ -246,7 +246,7 @@ void DownloadSession::send_61_98(bool is_98) {
|
||||
} else if (is_v3(this->version)) {
|
||||
C_CharacterData_V3_61_98 ret;
|
||||
ret.inventory = this->character->inventory;
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, 1, 1);
|
||||
ret.disp = convert_player_disp_data<PlayerDispDataDCPCV3, PlayerDispDataBB>(this->character->disp, Language::ENGLISH, Language::ENGLISH);
|
||||
ret.records.challenge = this->character->challenge_records;
|
||||
ret.records.battle = this->character->battle_records;
|
||||
ret.choice_search_config = this->character->choice_search_config;
|
||||
@@ -544,15 +544,15 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
|
||||
}
|
||||
|
||||
case 0x67: {
|
||||
// Technically we should assign item IDs here, but the server will never
|
||||
// be able to see that we didn't, so we don't bother
|
||||
// Technically we should assign item IDs here, but the server will never be able to see that we didn't, so we
|
||||
// don't bother
|
||||
|
||||
const auto& game_config = this->game_configs[this->current_game_config_index];
|
||||
if (this->version == Version::PC_V2) {
|
||||
C_CreateGame_PC_C1 ret;
|
||||
ret.name.encode(random_name());
|
||||
ret.password.encode(random_name());
|
||||
ret.difficulty = 0;
|
||||
ret.difficulty = Difficulty::NORMAL;
|
||||
ret.battle_mode = (game_config.mode == GameMode::BATTLE);
|
||||
ret.challenge_mode = (game_config.mode == GameMode::CHALLENGE);
|
||||
ret.episode = 1;
|
||||
@@ -562,7 +562,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
|
||||
C_CreateGame_DC_V3_0C_C1_Ep3_EC ret;
|
||||
ret.name.encode(random_name());
|
||||
ret.password.encode(random_name());
|
||||
ret.difficulty = 0;
|
||||
ret.difficulty = Difficulty::NORMAL;
|
||||
ret.battle_mode = (game_config.mode == GameMode::BATTLE);
|
||||
ret.challenge_mode = (game_config.mode == GameMode::CHALLENGE);
|
||||
if (is_v1(this->version)) {
|
||||
@@ -582,7 +582,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
|
||||
C_CreateGame_BB_C1 ret;
|
||||
ret.name.encode(random_name());
|
||||
ret.password.encode(random_name());
|
||||
ret.difficulty = 0;
|
||||
ret.difficulty = Difficulty::NORMAL;
|
||||
ret.battle_mode = (game_config.mode == GameMode::BATTLE);
|
||||
ret.challenge_mode = (game_config.mode == GameMode::CHALLENGE);
|
||||
if (game_config.episode == Episode::EP1) {
|
||||
@@ -651,12 +651,12 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
|
||||
filtered_name.push_back((isalnum(ch) || (ch == '-') || (ch == '.') || (ch == '_')) ? ch : '_');
|
||||
}
|
||||
string local_filename = std::format(
|
||||
"{}/{:016X}_{}_{}_{}_{}",
|
||||
"{}/{:016X}_{}_{}_{:c}_{}",
|
||||
this->output_dir,
|
||||
this->current_request,
|
||||
phosg::now(),
|
||||
phosg::name_for_enum(this->version),
|
||||
char_for_language_code(this->language),
|
||||
char_for_language(this->language),
|
||||
filtered_name);
|
||||
this->open_files.emplace(internal_name, OpenFile{.request = this->current_request, .filename = local_filename, .total_size = cmd.file_size, .data = ""});
|
||||
};
|
||||
@@ -688,9 +688,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
|
||||
}
|
||||
auto& f = this->open_files.at(cmd.filename.decode());
|
||||
size_t block_offset = msg.flag * 0x400;
|
||||
size_t allowed_block_size = (block_offset < f.total_size)
|
||||
? min<size_t>(f.total_size - block_offset, 0x400)
|
||||
: 0;
|
||||
size_t allowed_block_size = (block_offset < f.total_size) ? min<size_t>(f.total_size - block_offset, 0x400) : 0;
|
||||
size_t data_size = min<size_t>(cmd.data_size, allowed_block_size);
|
||||
size_t block_end_offset = block_offset + data_size;
|
||||
if (block_end_offset > f.data.size()) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
uint16_t remote_port,
|
||||
const std::string& output_dir,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file,
|
||||
uint32_t serial_number2,
|
||||
uint32_t serial_number,
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
uint16_t remote_port;
|
||||
std::string output_dir;
|
||||
Version version;
|
||||
uint8_t language;
|
||||
Language language;
|
||||
bool show_command_data;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
|
||||
uint32_t serial_number;
|
||||
|
||||
+173
-174
@@ -13,139 +13,145 @@ static constexpr uint8_t EP1 = EnemyTypeDefinition::Flag::VALID_EP1;
|
||||
static constexpr uint8_t EP2 = EnemyTypeDefinition::Flag::VALID_EP2;
|
||||
static constexpr uint8_t EP4 = EnemyTypeDefinition::Flag::VALID_EP4;
|
||||
static constexpr uint8_t RARE = EnemyTypeDefinition::Flag::IS_RARE;
|
||||
static constexpr uint8_t BOSS = EnemyTypeDefinition::Flag::IS_BOSS;
|
||||
|
||||
static constexpr uint8_t NONE = 0xFF;
|
||||
static const vector<EnemyTypeDefinition> type_defs{
|
||||
// clang-format off
|
||||
// TYPE FLAGS RT BP ENUM NAME IN-GAME NAME ULTIMATE NAME
|
||||
{EnemyType::UNKNOWN, 0, 0xFF, 0xFF, "UNKNOWN", "__UNKNOWN__", nullptr},
|
||||
{EnemyType::NONE, 0, 0xFF, 0xFF, "NONE", "__NONE__", nullptr},
|
||||
{EnemyType::NON_ENEMY_NPC, EP1 | EP2 | EP4, 0xFF, 0xFF, "NON_ENEMY_NPC", "__NPC__", nullptr},
|
||||
{EnemyType::AL_RAPPY, EP1 | RARE, 0x06, 0x19, "AL_RAPPY", "Al Rappy", "Pal Rappy"},
|
||||
{EnemyType::ASTARK, EP4, 0x41, 0x09, "ASTARK", "Astark", nullptr},
|
||||
{EnemyType::BA_BOOTA, EP4, 0x4F, 0x03, "BA_BOOTA", "Ba Boota", nullptr},
|
||||
{EnemyType::BARBA_RAY, EP2, 0x49, 0x0F, "BARBA_RAY", "Barba Ray", nullptr},
|
||||
{EnemyType::BARBAROUS_WOLF, EP1 | EP2, 0x08, 0x03, "BARBAROUS_WOLF", "Barbarous Wolf", "Gulgus-gue"},
|
||||
{EnemyType::BEE_L, EP1 | EP2, 0xFF, 0xFF, "BEE_L", "Bee L", "Gee L"},
|
||||
{EnemyType::BEE_R, EP1 | EP2, 0xFF, 0xFF, "BEE_R", "Bee R", "Gee R"},
|
||||
{EnemyType::BOOMA, EP1, 0x09, 0x4B, "BOOMA", "Booma", "Bartle"},
|
||||
{EnemyType::BOOTA, EP4, 0x4D, 0x00, "BOOTA", "Boota", nullptr},
|
||||
{EnemyType::BULCLAW, EP1, 0x28, 0x1F, "BULCLAW", "Bulclaw", nullptr},
|
||||
{EnemyType::BULK, EP1, 0x27, 0x1F, "BULK", "Bulk", nullptr},
|
||||
{EnemyType::CANADINE, EP1, 0x1C, 0x07, "CANADINE", "Canadine", "Canabin"},
|
||||
{EnemyType::CANADINE_GROUP, EP1, 0x1C, 0x08, "CANADINE_GROUP", "Canadine (group)", "Canabin (group)"},
|
||||
{EnemyType::CANANE, EP1, 0x1D, 0x09, "CANANE", "Canane", "Canune"},
|
||||
{EnemyType::CHAOS_BRINGER, EP1, 0x24, 0x0D, "CHAOS_BRINGER", "Chaos Bringer", "Dark Bringer"},
|
||||
{EnemyType::CHAOS_SORCERER, EP1 | EP2, 0x1F, 0x0A, "CHAOS_SORCERER", "Chaos Sorceror", "Gran Sorceror"},
|
||||
{EnemyType::CLAW, EP1, 0x26, 0x20, "CLAW", "Claw", nullptr},
|
||||
{EnemyType::DARK_BELRA, EP1 | EP2, 0x25, 0x0E, "DARK_BELRA", "Dark Belra", "Indi Belra"},
|
||||
{EnemyType::DARK_FALZ_1, EP1, 0xFF, 0x36, "DARK_FALZ_1", "Dark Falz (phase 1)", nullptr},
|
||||
{EnemyType::DARK_FALZ_2, EP1, 0x2F, 0x37, "DARK_FALZ_2", "Dark Falz (phase 2)", nullptr},
|
||||
{EnemyType::DARK_FALZ_3, EP1, 0x2F, 0x38, "DARK_FALZ_3", "Dark Falz (phase 3)", nullptr},
|
||||
{EnemyType::DARK_GUNNER, EP1, 0x22, 0x1E, "DARK_GUNNER", "Dark Gunner", nullptr},
|
||||
{EnemyType::DARK_GUNNER_CONTROL, EP1, 0xFF, 0xFF, "DARK_GUNNER_CONTROL", "Dark Gunner (control)", nullptr},
|
||||
{EnemyType::DARVANT, EP1, 0xFF, 0x35, "DARVANT", "Darvant", nullptr},
|
||||
{EnemyType::DARVANT_ULTIMATE, EP1, 0xFF, 0x39, "DARVANT_ULTIMATE", "Darvant (ultimate)", nullptr},
|
||||
{EnemyType::DE_ROL_LE, EP1, 0x2D, 0x0F, "DE_ROL_LE", "De Rol Le", "Dal Ral Lie"},
|
||||
{EnemyType::DE_ROL_LE_BODY, EP1, 0xFF, 0xFF, "DE_ROL_LE_BODY", "De Rol Le (body)", "Dal Ral Lie (body)"},
|
||||
{EnemyType::DE_ROL_LE_MINE, EP1, 0xFF, 0xFF, "DE_ROL_LE_MINE", "De Rol Le (mine)", "Dal Ral Lie (mine)"},
|
||||
{EnemyType::DEATH_GUNNER, EP1, 0x23, 0x1E, "DEATH_GUNNER", "Death Gunner", nullptr},
|
||||
{EnemyType::DEL_LILY, EP2, 0x53, 0x25, "DEL_LILY", "Del Lily", nullptr},
|
||||
{EnemyType::DEL_RAPPY_CRATER, EP4, 0x57, 0x06, "DEL_RAPPY_CRATER", "Del Rappy (crater)", nullptr},
|
||||
{EnemyType::DEL_RAPPY_DESERT, EP4, 0x58, 0x18, "DEL_RAPPY_DESERT", "Del Rappy (desert)", nullptr},
|
||||
{EnemyType::DELBITER, EP2, 0x48, 0x0D, "DELBITER", "Delbiter", nullptr},
|
||||
{EnemyType::DELDEPTH, EP2, 0x47, 0x30, "DELDEPTH", "Deldepth", nullptr},
|
||||
{EnemyType::DELSABER, EP1 | EP2, 0x1E, 0x52, "DELSABER", "Delsaber", nullptr},
|
||||
{EnemyType::DIMENIAN, EP1 | EP2, 0x29, 0x53, "DIMENIAN", "Dimenian", "Arlan"},
|
||||
{EnemyType::DOLMDARL, EP2, 0x41, 0x50, "DOLMDARL", "Dolmdarl", nullptr},
|
||||
{EnemyType::DOLMOLM, EP2, 0x40, 0x4F, "DOLMOLM", "Dolmolm", nullptr},
|
||||
{EnemyType::DORPHON, EP4, 0x50, 0x0F, "DORPHON", "Dorphon", nullptr},
|
||||
{EnemyType::DORPHON_ECLAIR, EP4 | RARE, 0x51, 0x10, "DORPHON_ECLAIR", "Dorphon Eclair", nullptr},
|
||||
{EnemyType::DRAGON, EP1, 0x2C, 0x12, "DRAGON", "Dragon", "Sil Dragon"},
|
||||
{EnemyType::DUBCHIC, EP1 | EP2, 0x18, 0x1B, "DUBCHIC", "Dubchic", "Dubchich"},
|
||||
{EnemyType::DUBWITCH, EP1 | EP2, 0xFF, 0xFF, "DUBWITCH", "Dubwitch", "Duvuik"},
|
||||
{EnemyType::EGG_RAPPY, EP2, 0x51, 0x19, "EGG_RAPPY", "Egg Rappy", nullptr},
|
||||
{EnemyType::EPSIGARD, EP2, 0xFF, 0xFF, "EPSIGARD", "Episgard", nullptr},
|
||||
{EnemyType::EPSILON, EP2, 0x54, 0x23, "EPSILON", "Epsilon", nullptr},
|
||||
{EnemyType::EVIL_SHARK, EP1, 0x10, 0x4F, "EVIL_SHARK", "Evil Shark", "Vulmer"},
|
||||
{EnemyType::GAEL_OR_GIEL, EP2, 0xFF, 0x2E, "GAEL", "Gael/Giel", nullptr},
|
||||
{EnemyType::GAL_GRYPHON, EP2, 0x4D, 0x1E, "GAL_GRYPHON", "Gal Gryphon", nullptr},
|
||||
{EnemyType::GARANZ, EP1 | EP2, 0x19, 0x1D, "GARANZ", "Garanz", "Baranz"},
|
||||
{EnemyType::GEE, EP2, 0x36, 0x07, "GEE", "Gee", nullptr},
|
||||
{EnemyType::GI_GUE, EP2, 0x37, 0x1A, "GI_GUE", "Gi Gue", nullptr},
|
||||
{EnemyType::GIBBLES, EP2, 0x3D, 0x3D, "GIBBLES", "Gibbles", nullptr},
|
||||
{EnemyType::GIGOBOOMA, EP1, 0x0B, 0x4D, "GIGOBOOMA", "Gigobooma", "Tollaw"},
|
||||
{EnemyType::GILLCHIC, EP1 | EP2, 0x32, 0x1C, "GILLCHIC", "Gillchic", "Gillchich"},
|
||||
{EnemyType::GIRTABLULU, EP4, 0x48, 0x1F, "GIRTABLULU", "Girtablulu", nullptr},
|
||||
{EnemyType::GOBOOMA, EP1, 0x0A, 0x4C, "GOBOOMA", "Gobooma", "Barble"},
|
||||
{EnemyType::GOL_DRAGON, EP2, 0x4C, 0x12, "GOL_DRAGON", "Gol Dragon", nullptr},
|
||||
{EnemyType::GORAN, EP4, 0x52, 0x11, "GORAN", "Goran", nullptr},
|
||||
{EnemyType::GORAN_DETONATOR, EP4, 0x53, 0x13, "GORAN_DETONATOR", "Goran Detonator", nullptr},
|
||||
{EnemyType::GRASS_ASSASSIN, EP1 | EP2, 0x0C, 0x4E, "GRASS_ASSASSIN", "Grass Assassin", "Crimson Assassin"},
|
||||
{EnemyType::GUIL_SHARK, EP1, 0x12, 0x51, "GUIL_SHARK", "Guil Shark", "Melqueek"},
|
||||
{EnemyType::HALLO_RAPPY, EP2, 0x50, 0x19, "HALLO_RAPPY", "Hallo Rappy", nullptr},
|
||||
{EnemyType::HIDOOM, EP1 | EP2, 0x17, 0x32, "HIDOOM", "Hidoom", nullptr},
|
||||
{EnemyType::HILDEBEAR, EP1 | EP2, 0x01, 0x49, "HILDEBEAR", "Hildebear", "Hildelt"},
|
||||
{EnemyType::HILDEBLUE, EP1 | EP2 | RARE, 0x02, 0x4A, "HILDEBLUE", "Hildeblue", "Hildetorr"},
|
||||
{EnemyType::ILL_GILL, EP2, 0x52, 0x26, "ILL_GILL", "Ill Gill", nullptr},
|
||||
{EnemyType::KONDRIEU, EP4 | RARE, 0x5B, 0x2A, "KONDRIEU", "Kondrieu", nullptr},
|
||||
{EnemyType::LA_DIMENIAN, EP1 | EP2, 0x2A, 0x54, "LA_DIMENIAN", "La Dimenian", "Merlan"},
|
||||
{EnemyType::LOVE_RAPPY, EP2, 0x33, 0x19, "LOVE_RAPPY", "Love Rappy", nullptr},
|
||||
{EnemyType::MERICARAND, EP2, 0x38, 0x3A, "MERICARAND", "Mericarand", nullptr},
|
||||
{EnemyType::MERICAROL, EP2, 0x38, 0x3A, "MERICAROL", "Mericarol", nullptr},
|
||||
{EnemyType::MERICUS, EP2 | RARE, 0x3A, 0x46, "MERICUS", "Mericus", nullptr},
|
||||
{EnemyType::MERIKLE, EP2 | RARE, 0x39, 0x45, "MERIKLE", "Merikle", nullptr},
|
||||
{EnemyType::MERILLIA, EP2, 0x34, 0x4B, "MERILLIA", "Merillia", nullptr},
|
||||
{EnemyType::MERILTAS, EP2, 0x35, 0x4C, "MERILTAS", "Meriltas", nullptr},
|
||||
{EnemyType::MERISSA_A, EP4, 0x46, 0x19, "MERISSA_A", "Merissa A", nullptr},
|
||||
{EnemyType::MERISSA_AA, EP4 | RARE, 0x47, 0x1A, "MERISSA_AA", "Merissa AA", nullptr},
|
||||
{EnemyType::MIGIUM, EP1 | EP2, 0x16, 0x33, "MIGIUM", "Migium", nullptr},
|
||||
{EnemyType::MONEST, EP1 | EP2, 0x04, 0x01, "MONEST", "Monest", "Mothvist"},
|
||||
{EnemyType::MORFOS, EP2, 0x42, 0x40, "MORFOS", "Morfos", nullptr},
|
||||
{EnemyType::MOTHMANT, EP1 | EP2, 0x03, 0x00, "MOTHMANT", "Mothmant", "Mothvert"},
|
||||
{EnemyType::NANO_DRAGON, EP1, 0x0F, 0x1A, "NANO_DRAGON", "Nano Dragon", nullptr},
|
||||
{EnemyType::NAR_LILY, EP1 | EP2 | RARE, 0x0E, 0x05, "NAR_LILY", "Nar Lily", "Mil Lily"},
|
||||
{EnemyType::OLGA_FLOW_1, EP2, 0xFF, 0x2B, "OLGA_FLOW_1", "Olga Flow (phase 1)", nullptr},
|
||||
{EnemyType::OLGA_FLOW_2, EP2, 0x4E, 0x2C, "OLGA_FLOW_2", "Olga Flow (phase 2)", nullptr},
|
||||
{EnemyType::PAL_SHARK, EP1, 0x11, 0x50, "PAL_SHARK", "Pal Shark", "Govulmer"},
|
||||
{EnemyType::PAN_ARMS, EP1 | EP2, 0x15, 0x31, "PAN_ARMS", "Pan Arms", nullptr},
|
||||
{EnemyType::PAZUZU_CRATER, EP4 | RARE, 0x4B, 0x08, "PAZUZU_CRATER", "Pazuzu (crater)", nullptr},
|
||||
{EnemyType::PAZUZU_DESERT, EP4 | RARE, 0x4C, 0x1C, "PAZUZU_DESERT", "Pazuzu (desert)", nullptr},
|
||||
{EnemyType::PIG_RAY, EP2, 0xFF, 0xFF, "PIG_RAY", "Pig Ray", nullptr},
|
||||
{EnemyType::POFUILLY_SLIME, EP1, 0x13, 0x30, "POFUILLY_SLIME", "Pofuilly Slime", nullptr},
|
||||
{EnemyType::POUILLY_SLIME, EP1 | RARE, 0x14, 0x2F, "POUILLY_SLIME", "Pouilly Slime", nullptr},
|
||||
{EnemyType::POISON_LILY, EP1 | EP2, 0x0D, 0x04, "POISON_LILY", "Poison Lily", "Ob Lily"},
|
||||
{EnemyType::PYRO_GORAN, EP4, 0x54, 0x12, "PYRO_GORAN", "Pyro Goran", nullptr},
|
||||
{EnemyType::RAG_RAPPY, EP1 | EP2, 0x05, 0x18, "RAG_RAPPY", "Rag Rappy", "El Rappy"},
|
||||
{EnemyType::RECOBOX, EP2, 0x43, 0x41, "RECOBOX", "Recobox", nullptr},
|
||||
{EnemyType::RECON, EP2, 0x44, 0x42, "RECON", "Recon", nullptr},
|
||||
{EnemyType::SAINT_MILION, EP4, 0x59, 0x22, "SAINT_MILION", "Saint-Milion", nullptr},
|
||||
{EnemyType::SAINT_RAPPY, EP2, 0x4F, 0x19, "SAINT_RAPPY", "Saint Rappy", nullptr},
|
||||
{EnemyType::SAND_RAPPY_CRATER, EP4, 0x55, 0x05, "SAND_RAPPY_CRATER", "Sand Rappy (crater)", nullptr},
|
||||
{EnemyType::SAND_RAPPY_DESERT, EP4, 0x56, 0x17, "SAND_RAPPY_DESERT", "Sand Rappy (desert)", nullptr},
|
||||
{EnemyType::SATELLITE_LIZARD_CRATER, EP4, 0x44, 0x0D, "SATELLITE_LIZARD_CRATER", "Satellite Lizard (crater)", nullptr},
|
||||
{EnemyType::SATELLITE_LIZARD_DESERT, EP4, 0x45, 0x1D, "SATELLITE_LIZARD_DESERT", "Satellite Lizard (desert)", nullptr},
|
||||
{EnemyType::SAVAGE_WOLF, EP1 | EP2, 0x07, 0x02, "SAVAGE_WOLF", "Savage Wolf", "Gulgus"},
|
||||
{EnemyType::SHAMBERTIN, EP4, 0x5A, 0x26, "SHAMBERTIN", "Shambertin", nullptr},
|
||||
{EnemyType::SINOW_BEAT, EP1, 0x1A, 0x06, "SINOW_BEAT", "Sinow Beat", "Sinow Blue"},
|
||||
{EnemyType::SINOW_BERILL, EP2, 0x3E, 0x06, "SINOW_BERILL", "Sinow Berill", nullptr},
|
||||
{EnemyType::SINOW_GOLD, EP1, 0x1B, 0x13, "SINOW_GOLD", "Sinow Gold", "Sinow Red"},
|
||||
{EnemyType::SINOW_SPIGELL, EP2, 0x3F, 0x13, "SINOW_SPIGELL", "Sinow Spigell", nullptr},
|
||||
{EnemyType::SINOW_ZELE, EP2, 0x46, 0x44, "SINOW_ZELE", "Sinow Zele", nullptr},
|
||||
{EnemyType::SINOW_ZOA, EP2, 0x45, 0x43, "SINOW_ZOA", "Sinow Zoa", nullptr},
|
||||
{EnemyType::SO_DIMENIAN, EP1 | EP2, 0x2B, 0x55, "SO_DIMENIAN", "So Dimenian", "Del-D"},
|
||||
{EnemyType::UL_GIBBON, EP2, 0x3B, 0x3B, "UL_GIBBON", "Ul Gibbon", nullptr},
|
||||
{EnemyType::VOL_OPT_1, EP1, 0xFF, 0xFF, "VOL_OPT_1", "Vol Opt (phase 1)", "Vol Opt ver.2 (phase 1)"},
|
||||
{EnemyType::VOL_OPT_2, EP1, 0x2E, 0x25, "VOL_OPT_2", "Vol Opt (phase 2)", "Vol Opt ver.2 (phase 2)"},
|
||||
{EnemyType::VOL_OPT_AMP, EP1, 0xFF, 0xFF, "VOL_OPT_AMP", "Vol Opt (amp)", "Vol Opt ver.2 (amp)"},
|
||||
{EnemyType::VOL_OPT_CORE, EP1, 0xFF, 0xFF, "VOL_OPT_CORE", "Vol Opt (core)", "Vol Opt ver.2 (core)"},
|
||||
{EnemyType::VOL_OPT_MONITOR, EP1, 0xFF, 0xFF, "VOL_OPT_MONITOR", "Vol Opt (monitor)", "Vol Opt ver.2 (monitor)"},
|
||||
{EnemyType::VOL_OPT_PILLAR, EP1, 0xFF, 0xFF, "VOL_OPT_PILLAR", "Vol Opt (pillar)", "Vol Opt ver.2 (pillar)"},
|
||||
{EnemyType::YOWIE_CRATER, EP4, 0x42, 0x0E, "YOWIE_CRATER", "Yowie (crater)", nullptr},
|
||||
{EnemyType::YOWIE_DESERT, EP4, 0x43, 0x1E, "YOWIE_DESERT", "Yowie (desert)", nullptr},
|
||||
{EnemyType::ZE_BOOTA, EP4, 0x4E, 0x01, "ZE_BOOTA", "Ze Boota", nullptr},
|
||||
{EnemyType::ZOL_GIBBON, EP2, 0x3C, 0x3C, "ZOL_GIBBON", "Zol Gibbon", nullptr},
|
||||
{EnemyType::ZU_CRATER, EP4, 0x49, 0x07, "ZU_CRATER", "Zu (crater)", nullptr},
|
||||
{EnemyType::ZU_DESERT, EP4, 0x4A, 0x1B, "ZU_DESERT", "Zu (desert)", nullptr},
|
||||
// TYPE FLAGS RT OLDRT BP-STATS BP-ATTACK BP-RESIST ENUM NAME IN-GAME NAME ULTIMATE NAME
|
||||
{EnemyType::UNKNOWN, 0, NONE, NONE, {}, {}, {}, "UNKNOWN", "__UNKNOWN__", nullptr},
|
||||
{EnemyType::NONE, 0, NONE, NONE, {}, {}, {}, "NONE", "__NONE__", nullptr},
|
||||
{EnemyType::NON_ENEMY_NPC, EP1 | EP2 | EP4, NONE, NONE, {}, {}, {}, "NON_ENEMY_NPC", "__NPC__", nullptr},
|
||||
{EnemyType::AL_RAPPY, EP1 | RARE, 0x06, 0x06, {0x19}, {0x19}, {0x19}, "AL_RAPPY", "Al Rappy", "Pal Rappy"},
|
||||
{EnemyType::ASTARK, EP4, 0x58, 0x41, {0x09}, {0x0B, 0x0A, 0x0C}, {0x09}, "ASTARK", "Astark", nullptr},
|
||||
{EnemyType::BA_BOOTA, EP4, 0x62, 0x4F, {0x03}, {0x03, 0x02, 0x04}, {0x03}, "BA_BOOTA", "Ba Boota", nullptr},
|
||||
{EnemyType::BARBA_RAY, EP2 | BOSS, 0x49, 0x49, {0x0F}, {0x0F}, {0x0F}, "BARBA_RAY", "Barba Ray", nullptr},
|
||||
{EnemyType::BARBA_RAY_JOINT, EP2 | BOSS, 0x49, 0x49, {0x10}, {0x0F}, {0x10}, "BARBA_RAY_JOINT", "Barba Ray (joint)", nullptr},
|
||||
{EnemyType::BARBAROUS_WOLF, EP1 | EP2, 0x08, 0x08, {0x03}, {0x03}, {0x03}, "BARBAROUS_WOLF", "Barbarous Wolf", "Gulgus-gue"},
|
||||
{EnemyType::BEE_L, EP1 | EP2, NONE, NONE, {0x0C}, {0x0C}, {0x0C}, "BEE_L", "Bee L", "Gee L"},
|
||||
{EnemyType::BEE_R, EP1 | EP2, NONE, NONE, {0x0B}, {0x0B}, {0x0B}, "BEE_R", "Bee R", "Gee R"},
|
||||
{EnemyType::BOOMA, EP1, 0x09, 0x09, {0x4B}, {0x4E}, {0x4A}, "BOOMA", "Booma", "Bartle"},
|
||||
{EnemyType::BOOTA, EP4, 0x60, 0x4D, {0x00}, {0x00, 0x02, 0x04}, {0x00}, "BOOTA", "Boota", nullptr},
|
||||
{EnemyType::BULCLAW, EP1, 0x28, 0x28, {0x1F}, {0x1F}, {0x1F}, "BULCLAW", "Bulclaw", nullptr},
|
||||
{EnemyType::BULK, EP1, 0x27, 0x27, {0x1F}, {0x1F}, {0x1F}, "BULK", "Bulk", nullptr},
|
||||
{EnemyType::CANADINE, EP1, 0x1C, 0x1C, {0x07}, {0x07}, {0x07}, "CANADINE", "Canadine", "Canabin"},
|
||||
{EnemyType::CANADINE_GROUP, EP1, 0x1C, 0x1C, {0x08}, {0x08}, {0x08}, "CANADINE_GROUP", "Canadine (group)", "Canabin (group)"},
|
||||
{EnemyType::CANANE, EP1, 0x1D, 0x1D, {0x09}, {0x09}, {0x09}, "CANANE", "Canane", "Canune"},
|
||||
{EnemyType::CHAOS_BRINGER, EP1, 0x24, 0x24, {0x0D}, {0x0D}, {0x0D}, "CHAOS_BRINGER", "Chaos Bringer", "Dark Bringer"},
|
||||
{EnemyType::CHAOS_SORCERER, EP1 | EP2, 0x1F, 0x1F, {0x0A}, {0x0A}, {0x0A}, "CHAOS_SORCERER", "Chaos Sorceror", "Gran Sorceror"},
|
||||
{EnemyType::CLAW, EP1, 0x26, 0x26, {0x20}, {0x20}, {0x20}, "CLAW", "Claw", nullptr},
|
||||
{EnemyType::DARK_BELRA, EP1 | EP2, 0x25, 0x25, {0x0E}, {0x0E, 0x13}, {0x0E}, "DARK_BELRA", "Dark Belra", "Indi Belra"},
|
||||
{EnemyType::DARK_FALZ_1, EP1 | BOSS, NONE, NONE, {0x36}, {0x36}, {0x36}, "DARK_FALZ_1", "Dark Falz (phase 1)", nullptr},
|
||||
{EnemyType::DARK_FALZ_2, EP1 | BOSS, 0x2F, 0x2F, {0x37}, {0x37}, {0x37}, "DARK_FALZ_2", "Dark Falz (phase 2)", nullptr},
|
||||
{EnemyType::DARK_FALZ_3, EP1 | BOSS, 0x2F, 0x2F, {0x38}, {0x38}, {0x38}, "DARK_FALZ_3", "Dark Falz (phase 3)", nullptr},
|
||||
{EnemyType::DARK_GUNNER, EP1, 0x22, 0x22, {0x1E}, {0x1E}, {0x1E}, "DARK_GUNNER", "Dark Gunner", nullptr},
|
||||
{EnemyType::DARK_GUNNER_CONTROL, EP1, NONE, NONE, {}, {}, {}, "DARK_GUNNER_CONTROL", "Dark Gunner (control)", nullptr},
|
||||
{EnemyType::DARVANT, EP1, NONE, NONE, {0x35}, {0x35}, {0x35}, "DARVANT", "Darvant", nullptr},
|
||||
{EnemyType::DE_ROL_LE, EP1 | BOSS, 0x2D, 0x2D, {0x0F}, {0x0F}, {0x0F}, "DE_ROL_LE", "De Rol Le", "Dal Ral Lie"},
|
||||
{EnemyType::DE_ROL_LE_BODY, EP1 | BOSS, NONE, NONE, {0x10}, {0x0F}, {0x10}, "DE_ROL_LE_BODY", "De Rol Le (body)", "Dal Ral Lie (body)"},
|
||||
{EnemyType::DE_ROL_LE_MINE, EP1 | BOSS, NONE, NONE, {0x11}, {0x0F}, {0x11}, "DE_ROL_LE_MINE", "De Rol Le (mine)", "Dal Ral Lie (mine)"},
|
||||
{EnemyType::DEATH_GUNNER, EP1, 0x23, 0x23, {0x1E}, {0x1E}, {0x1E}, "DEATH_GUNNER", "Death Gunner", nullptr},
|
||||
{EnemyType::DEL_LILY, EP2, 0x53, 0x53, {0x25}, {0x25}, {0x25}, "DEL_LILY", "Del Lily", nullptr},
|
||||
{EnemyType::DEL_RAPPY_CRATER, EP4, 0x69, 0x57, {0x06}, {0x06}, {0x06}, "DEL_RAPPY_CRATER", "Del Rappy (crater)", nullptr},
|
||||
{EnemyType::DEL_RAPPY_DESERT, EP4, 0x69, 0x58, {0x18}, {0x18}, {0x18}, "DEL_RAPPY_DESERT", "Del Rappy (desert)", nullptr},
|
||||
{EnemyType::DELBITER, EP2, 0x48, 0x48, {0x0D}, {0x0D}, {0x0D}, "DELBITER", "Delbiter", nullptr},
|
||||
{EnemyType::DELDEPTH, EP2, 0x47, 0x47, {0x30}, {0x30}, {0x30}, "DELDEPTH", "Deldepth", nullptr},
|
||||
{EnemyType::DELSABER, EP1 | EP2, 0x1E, 0x1E, {0x52}, {0x57, 0x58, 0x59}, {0x51}, "DELSABER", "Delsaber", nullptr},
|
||||
{EnemyType::DIMENIAN, EP1 | EP2, 0x29, 0x29, {0x53}, {0x5A}, {0x52}, "DIMENIAN", "Dimenian", "Arlan"},
|
||||
{EnemyType::DOLMDARL, EP2, 0x41, 0x41, {0x50}, {0x55}, {0x4F}, "DOLMDARL", "Dolmdarl", nullptr},
|
||||
{EnemyType::DOLMOLM, EP2, 0x40, 0x40, {0x4F}, {0x54}, {0x4E}, "DOLMOLM", "Dolmolm", nullptr},
|
||||
{EnemyType::DORPHON, EP4, 0x63, 0x50, {0x0F}, {0x0F}, {0x0F}, "DORPHON", "Dorphon", nullptr},
|
||||
{EnemyType::DORPHON_ECLAIR, EP4 | RARE, 0x64, 0x51, {0x10}, {0x10}, {0x10}, "DORPHON_ECLAIR", "Dorphon Eclair", nullptr},
|
||||
{EnemyType::DRAGON, EP1 | BOSS, 0x2C, 0x2C, {0x12}, {0x12, 0x14, 0x15, 0x16, 0x17}, {0x12}, "DRAGON", "Dragon", "Sil Dragon"},
|
||||
{EnemyType::DUBCHIC, EP1 | EP2, 0x18, 0x18, {0x1B}, {0x1B}, {0x1B}, "DUBCHIC", "Dubchic", "Dubchich"},
|
||||
{EnemyType::DUBWITCH, EP1 | EP2, NONE, NONE, {}, {}, {}, "DUBWITCH", "Dubwitch", "Duvuik"},
|
||||
{EnemyType::EGG_RAPPY, EP2, 0x51, 0x51, {0x19}, {0x19}, {0x19}, "EGG_RAPPY", "Egg Rappy", nullptr},
|
||||
{EnemyType::EPSIGARD, EP2, NONE, NONE, {0x24}, {0x24}, {0x24}, "EPSIGARD", "Episgard", nullptr},
|
||||
{EnemyType::EPSILON, EP2, 0x54, 0x54, {0x23}, {0x23}, {0x23}, "EPSILON", "Epsilon", nullptr},
|
||||
{EnemyType::EVIL_SHARK, EP1, 0x10, 0x10, {0x4F}, {0x54}, {0x4E}, "EVIL_SHARK", "Evil Shark", "Vulmer"},
|
||||
{EnemyType::GAEL_OR_GIEL, EP2, NONE, NONE, {0x2E}, {0x2E}, {0x2E}, "GAEL_OR_GIEL", "Gael/Giel", nullptr},
|
||||
{EnemyType::GAL_GRYPHON, EP2 | BOSS, 0x4D, 0x4D, {0x1E}, {0x1E, 0x1F, 0x20, 0x21, 0x22}, {0x1E}, "GAL_GRYPHON", "Gal Gryphon", nullptr},
|
||||
{EnemyType::GARANZ, EP1 | EP2, 0x19, 0x19, {0x1D}, {0x1D}, {0x1D}, "GARANZ", "Garanz", "Baranz"},
|
||||
{EnemyType::GEE, EP2, 0x36, 0x36, {0x07}, {0x07}, {0x07}, "GEE", "Gee", nullptr},
|
||||
{EnemyType::GI_GUE, EP2, 0x37, 0x37, {0x1A}, {0x1A}, {0x1A}, "GI_GUE", "Gi Gue", nullptr},
|
||||
{EnemyType::GIBBLES, EP2, 0x3D, 0x3D, {0x3D}, {0x3D, 0x3E, 0x3F}, {0x3D}, "GIBBLES", "Gibbles", nullptr},
|
||||
{EnemyType::GIGOBOOMA, EP1, 0x0B, 0x0B, {0x4D}, {0x50}, {0x4C}, "GIGOBOOMA", "Gigobooma", "Tollaw"},
|
||||
{EnemyType::GILLCHIC, EP1 | EP2, 0x32, 0x32, {0x1C}, {0x1C}, {0x1C}, "GILLCHIC", "Gillchic", "Gillchich"},
|
||||
{EnemyType::GIRTABLULU, EP4, 0x5D, 0x48, {0x1F}, {0x1F}, {0x1F}, "GIRTABLULU", "Girtablulu", nullptr},
|
||||
{EnemyType::GOBOOMA, EP1, 0x0A, 0x0A, {0x4C}, {0x4F}, {0x4B}, "GOBOOMA", "Gobooma", "Barble"},
|
||||
{EnemyType::GOL_DRAGON, EP2 | BOSS, 0x4C, 0x4C, {0x12}, {0x12, 0x14, 0x15, 0x16, 0x17}, {0x12}, "GOL_DRAGON", "Gol Dragon", nullptr},
|
||||
{EnemyType::GORAN, EP4, 0x65, 0x52, {0x11}, {0x11, 0x14}, {0x11}, "GORAN", "Goran", nullptr},
|
||||
{EnemyType::GORAN_DETONATOR, EP4, 0x66, 0x53, {0x13}, {0x13, 0x16}, {0x13}, "GORAN_DETONATOR", "Goran Detonator", nullptr},
|
||||
{EnemyType::GRASS_ASSASSIN, EP1 | EP2, 0x0C, 0x0C, {0x4E}, {0x51, 0x52, 0x53}, {0x4D}, "GRASS_ASSASSIN", "Grass Assassin", "Crimson Assassin"},
|
||||
{EnemyType::GUIL_SHARK, EP1, 0x12, 0x12, {0x51}, {0x56}, {0x50}, "GUIL_SHARK", "Guil Shark", "Melqueek"},
|
||||
{EnemyType::HALLO_RAPPY, EP2, 0x50, 0x50, {0x19}, {0x19}, {0x19}, "HALLO_RAPPY", "Hallo Rappy", nullptr},
|
||||
{EnemyType::HIDOOM, EP1 | EP2, 0x17, 0x17, {0x32}, {0x32}, {0x32}, "HIDOOM", "Hidoom", nullptr},
|
||||
{EnemyType::HILDEBEAR, EP1 | EP2, 0x01, 0x01, {0x49}, {0x48, 0x49, 0x4A}, {0x48}, "HILDEBEAR", "Hildebear", "Hildelt"},
|
||||
{EnemyType::HILDEBLUE, EP1 | EP2 | RARE, 0x02, 0x02, {0x4A}, {0x4B, 0x4C, 0x4D}, {0x49}, "HILDEBLUE", "Hildeblue", "Hildetorr"},
|
||||
{EnemyType::ILL_GILL, EP2, 0x52, 0x52, {0x26}, {0x26, 0x27, 0x28, 0x29}, {0x26}, "ILL_GILL", "Ill Gill", nullptr},
|
||||
{EnemyType::KONDRIEU, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x28, 0x2A}, {0x28, 0x2A}, {0x28, 0x2A}, "KONDRIEU", "Kondrieu", nullptr},
|
||||
{EnemyType::KONDRIEU_SPINNER, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x29, 0x2B}, {0x29, 0x2B}, {0x29, 0x2B}, "KONDRIEU_SPINNER", "Kondrieu (spinner)", nullptr},
|
||||
{EnemyType::LA_DIMENIAN, EP1 | EP2, 0x2A, 0x2A, {0x54}, {0x5B}, {0x53}, "LA_DIMENIAN", "La Dimenian", "Merlan"},
|
||||
{EnemyType::LOVE_RAPPY, EP2, 0x33, 0x33, {0x19}, {0x19}, {0x19}, "LOVE_RAPPY", "Love Rappy", nullptr},
|
||||
{EnemyType::MERICARAND, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, "MERICARAND", "Mericarand", nullptr},
|
||||
{EnemyType::MERICAROL, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, "MERICAROL", "Mericarol", nullptr},
|
||||
{EnemyType::MERICUS, EP2 | RARE, 0x3A, 0x3A, {0x46}, {0x46}, {0x46}, "MERICUS", "Mericus", nullptr},
|
||||
{EnemyType::MERIKLE, EP2 | RARE, 0x39, 0x39, {0x45}, {0x45}, {0x45}, "MERIKLE", "Merikle", nullptr},
|
||||
{EnemyType::MERILLIA, EP2, 0x34, 0x34, {0x4B}, {0x4E}, {0x4A}, "MERILLIA", "Merillia", nullptr},
|
||||
{EnemyType::MERILTAS, EP2, 0x35, 0x35, {0x4C}, {0x4F}, {0x4B}, "MERILTAS", "Meriltas", nullptr},
|
||||
{EnemyType::MERISSA_A, EP4, 0x5B, 0x46, {0x19}, {0x19}, {0x19}, "MERISSA_A", "Merissa A", nullptr},
|
||||
{EnemyType::MERISSA_AA, EP4 | RARE, 0x5C, 0x47, {0x1A}, {0x1A}, {0x1A}, "MERISSA_AA", "Merissa AA", nullptr},
|
||||
{EnemyType::MIGIUM, EP1 | EP2, 0x16, 0x16, {0x33}, {0x33}, {0x33}, "MIGIUM", "Migium", nullptr},
|
||||
{EnemyType::MONEST, EP1 | EP2, 0x04, 0x04, {0x01}, {0x01}, {0x01}, "MONEST", "Monest", "Mothvist"},
|
||||
{EnemyType::MORFOS, EP2, 0x42, 0x42, {0x40}, {0x40, 0x50}, {0x40}, "MORFOS", "Morfos", nullptr},
|
||||
{EnemyType::MOTHMANT, EP1 | EP2, 0x03, 0x03, {0x00}, {0x00}, {0x00}, "MOTHMANT", "Mothmant", "Mothvert"},
|
||||
{EnemyType::NANO_DRAGON, EP1, 0x0F, 0x0F, {0x1A}, {0x1A}, {0x1A}, "NANO_DRAGON", "Nano Dragon", nullptr},
|
||||
{EnemyType::NAR_LILY, EP1 | EP2 | RARE, 0x0E, 0x0E, {0x05}, {0x05}, {0x05}, "NAR_LILY", "Nar Lily", "Mil Lily"},
|
||||
{EnemyType::OLGA_FLOW_1, EP2 | BOSS, NONE, NONE, {0x2B}, {0x2B}, {0x2B}, "OLGA_FLOW_1", "Olga Flow (phase 1)", nullptr},
|
||||
{EnemyType::OLGA_FLOW_2, EP2 | BOSS, 0x4E, 0x4E, {0x2C}, {0x2C}, {0x2C}, "OLGA_FLOW_2", "Olga Flow (phase 2)", nullptr},
|
||||
{EnemyType::PAL_SHARK, EP1, 0x11, 0x11, {0x50}, {0x55}, {0x4F}, "PAL_SHARK", "Pal Shark", "Govulmer"},
|
||||
{EnemyType::PAN_ARMS, EP1 | EP2, 0x15, 0x15, {0x31}, {0x31}, {0x31}, "PAN_ARMS", "Pan Arms", nullptr},
|
||||
{EnemyType::PAZUZU_CRATER, EP4 | RARE, 0x5F, 0x4B, {0x08}, {0x08}, {0x08}, "PAZUZU_CRATER", "Pazuzu (crater)", nullptr},
|
||||
{EnemyType::PAZUZU_DESERT, EP4 | RARE, 0x5F, 0x4C, {0x1C}, {0x1C}, {0x1C}, "PAZUZU_DESERT", "Pazuzu (desert)", nullptr},
|
||||
{EnemyType::PIG_RAY, EP2, 0x4A, NONE, {0x08}, {0x08}, {0x08}, "PIG_RAY", "Pig Ray", nullptr},
|
||||
{EnemyType::POFUILLY_SLIME, EP1, 0x13, 0x13, {0x30}, {0x30}, {0x30}, "POFUILLY_SLIME", "Pofuilly Slime", nullptr},
|
||||
{EnemyType::POUILLY_SLIME, EP1 | RARE, 0x14, 0x14, {0x34}, {0x34}, {0x34}, "POUILLY_SLIME", "Pouilly Slime", nullptr},
|
||||
{EnemyType::POISON_LILY, EP1 | EP2, 0x0D, 0x0D, {0x04}, {0x04}, {0x04}, "POISON_LILY", "Poison Lily", "Ob Lily"},
|
||||
{EnemyType::PYRO_GORAN, EP4, 0x67, 0x54, {0x12}, {0x12, 0x15}, {0x12}, "PYRO_GORAN", "Pyro Goran", nullptr},
|
||||
{EnemyType::RAG_RAPPY, EP1 | EP2, 0x05, 0x05, {0x18}, {0x18}, {0x18}, "RAG_RAPPY", "Rag Rappy", "El Rappy"},
|
||||
{EnemyType::RECOBOX, EP2, 0x43, 0x43, {0x41}, {0x41}, {0x41}, "RECOBOX", "Recobox", nullptr},
|
||||
{EnemyType::RECON, EP2, 0x44, 0x44, {0x42}, {0x42}, {0x42}, "RECON", "Recon", nullptr},
|
||||
{EnemyType::SAINT_MILION, EP4 | BOSS, 0x6A, 0x59, {0x20, 0x22}, {0x20, 0x22}, {0x20, 0x22}, "SAINT_MILION", "Saint-Milion", nullptr},
|
||||
{EnemyType::SAINT_MILION_SPINNER, EP4 | BOSS, 0x6A, 0x59, {0x21, 0x23}, {0x21, 0x23}, {0x21, 0x23}, "SAINT_MILION_SPINNER", "Saint-Milion (spinner)", nullptr},
|
||||
{EnemyType::SAINT_RAPPY, EP2, 0x4F, 0x4F, {0x19}, {0x19}, {0x19}, "SAINT_RAPPY", "Saint Rappy", nullptr},
|
||||
{EnemyType::SAND_RAPPY_CRATER, EP4, 0x68, 0x55, {0x05}, {0x05}, {0x05}, "SAND_RAPPY_CRATER", "Sand Rappy (crater)", nullptr},
|
||||
{EnemyType::SAND_RAPPY_DESERT, EP4, 0x68, 0x56, {0x17}, {0x17}, {0x17}, "SAND_RAPPY_DESERT", "Sand Rappy (desert)", nullptr},
|
||||
{EnemyType::SATELLITE_LIZARD_CRATER, EP4, 0x5A, 0x44, {0x0D}, {0x0D}, {0x0D}, "SATELLITE_LIZARD_CRATER", "Satellite Lizard (crater)", nullptr},
|
||||
{EnemyType::SATELLITE_LIZARD_DESERT, EP4, 0x5A, 0x45, {0x1D}, {0x1D}, {0x1D}, "SATELLITE_LIZARD_DESERT", "Satellite Lizard (desert)", nullptr},
|
||||
{EnemyType::SAVAGE_WOLF, EP1 | EP2, 0x07, 0x07, {0x02}, {0x02}, {0x02}, "SAVAGE_WOLF", "Savage Wolf", "Gulgus"},
|
||||
{EnemyType::SHAMBERTIN, EP4 | BOSS, 0x6B, 0x5A, {0x24, 0x26}, {0x24, 0x26}, {0x24, 0x26}, "SHAMBERTIN", "Shambertin", nullptr},
|
||||
{EnemyType::SHAMBERTIN_SPINNER, EP4 | BOSS, 0x6B, 0x5A, {0x25, 0x27}, {0x25, 0x27}, {0x25, 0x27}, "SHAMBERTIN_SPINNER", "Shambertin (spinner)", nullptr},
|
||||
{EnemyType::SINOW_BEAT, EP1, 0x1A, 0x1A, {0x06}, {0x06}, {0x06}, "SINOW_BEAT", "Sinow Beat", "Sinow Blue"},
|
||||
{EnemyType::SINOW_BERILL, EP2, 0x3E, 0x3E, {0x06}, {0x06}, {0x06}, "SINOW_BERILL", "Sinow Berill", nullptr},
|
||||
{EnemyType::SINOW_GOLD, EP1, 0x1B, 0x1B, {0x13}, {0x47}, {0x13}, "SINOW_GOLD", "Sinow Gold", "Sinow Red"},
|
||||
{EnemyType::SINOW_SPIGELL, EP2, 0x3F, 0x3F, {0x13}, {0x47}, {0x13}, "SINOW_SPIGELL", "Sinow Spigell", nullptr},
|
||||
{EnemyType::SINOW_ZELE, EP2, 0x46, 0x46, {0x44}, {0x44}, {0x44}, "SINOW_ZELE", "Sinow Zele", nullptr},
|
||||
{EnemyType::SINOW_ZOA, EP2, 0x45, 0x45, {0x43}, {0x43}, {0x43}, "SINOW_ZOA", "Sinow Zoa", nullptr},
|
||||
{EnemyType::SO_DIMENIAN, EP1 | EP2, 0x2B, 0x2B, {0x55}, {0x5C}, {0x54}, "SO_DIMENIAN", "So Dimenian", "Del-D"},
|
||||
{EnemyType::UL_GIBBON, EP2, 0x3B, 0x3B, {0x3B}, {0x3B}, {0x3B}, "UL_GIBBON", "Ul Gibbon", nullptr},
|
||||
{EnemyType::UL_RAY, EP2, 0x4B, NONE, {0x09}, {0x09}, {0x09}, "UL_RAY", "Ul Ray", nullptr},
|
||||
{EnemyType::VOL_OPT_1, EP1 | BOSS, NONE, NONE, {0x21}, {0x21}, {0x21}, "VOL_OPT_1", "Vol Opt (phase 1)", "Vol Opt ver.2 (phase 1)"},
|
||||
{EnemyType::VOL_OPT_2, EP1 | BOSS, 0x2E, 0x2E, {0x25}, {0x25}, {0x25}, "VOL_OPT_2", "Vol Opt (phase 2)", "Vol Opt ver.2 (phase 2)"},
|
||||
{EnemyType::VOL_OPT_AMP, EP1 | BOSS, NONE, NONE, {0x24}, {0x24}, {0x24}, "VOL_OPT_AMP", "Vol Opt (amp)", "Vol Opt ver.2 (amp)"},
|
||||
{EnemyType::VOL_OPT_CORE, EP1 | BOSS, NONE, NONE, {0x26}, {0x26}, {0x26}, "VOL_OPT_CORE", "Vol Opt (core)", "Vol Opt ver.2 (core)"},
|
||||
{EnemyType::VOL_OPT_MONITOR, EP1 | BOSS, NONE, NONE, {0x23}, {0x23}, {0x23}, "VOL_OPT_MONITOR", "Vol Opt (monitor)", "Vol Opt ver.2 (monitor)"},
|
||||
{EnemyType::VOL_OPT_PILLAR, EP1 | BOSS, NONE, NONE, {0x22}, {0x22}, {0x22}, "VOL_OPT_PILLAR", "Vol Opt (pillar)", "Vol Opt ver.2 (pillar)"},
|
||||
{EnemyType::YOWIE_CRATER, EP4, 0x59, 0x42, {0x0E}, {0x0E}, {0x0E}, "YOWIE_CRATER", "Yowie (crater)", nullptr},
|
||||
{EnemyType::YOWIE_DESERT, EP4, 0x59, 0x43, {0x1E}, {0x1E}, {0x1E}, "YOWIE_DESERT", "Yowie (desert)", nullptr},
|
||||
{EnemyType::ZE_BOOTA, EP4, 0x61, 0x4E, {0x01}, {0x01, 0x02, 0x04}, {0x01}, "ZE_BOOTA", "Ze Boota", nullptr},
|
||||
{EnemyType::ZOL_GIBBON, EP2, 0x3C, 0x3C, {0x3C}, {0x3C}, {0x3C}, "ZOL_GIBBON", "Zol Gibbon", nullptr},
|
||||
{EnemyType::ZU_CRATER, EP4, 0x5E, 0x49, {0x07}, {0x07}, {0x07}, "ZU_CRATER", "Zu (crater)", nullptr},
|
||||
{EnemyType::ZU_DESERT, EP4, 0x5E, 0x4A, {0x1B}, {0x1B}, {0x1B}, "ZU_DESERT", "Zu (desert)", nullptr},
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
@@ -172,23 +178,20 @@ EnemyType phosg::enum_for_name<EnemyType>(const char* name) {
|
||||
}
|
||||
|
||||
const vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index) {
|
||||
const auto& generate_table = +[](Episode episode) -> vector<vector<EnemyType>> {
|
||||
vector<vector<EnemyType>> ret;
|
||||
static array<vector<vector<EnemyType>>, 5> data;
|
||||
auto& ret = data.at(static_cast<size_t>(episode));
|
||||
if (ret.empty()) {
|
||||
for (const auto& def : type_defs) {
|
||||
if (def.valid_in_episode(episode) && (def.rt_index != 0xFF)) {
|
||||
if (!def.valid_in_episode(episode)) {
|
||||
continue;
|
||||
}
|
||||
if (def.rt_index != 0xFF) {
|
||||
if (def.rt_index >= ret.size()) {
|
||||
ret.resize(def.rt_index + 1);
|
||||
}
|
||||
ret[def.rt_index].emplace_back(def.type);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
static array<vector<vector<EnemyType>>, 5> data;
|
||||
auto& ret = data.at(static_cast<size_t>(episode));
|
||||
if (ret.empty()) {
|
||||
ret = generate_table(episode);
|
||||
}
|
||||
try {
|
||||
return ret.at(rt_index);
|
||||
@@ -198,24 +201,21 @@ const vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8
|
||||
}
|
||||
}
|
||||
|
||||
const vector<EnemyType>& enemy_types_for_battle_param_index(Episode episode, uint8_t bp_index) {
|
||||
const auto& generate_table = +[](Episode episode) -> vector<vector<EnemyType>> {
|
||||
vector<vector<EnemyType>> ret;
|
||||
for (const auto& def : type_defs) {
|
||||
if (def.valid_in_episode(episode) && (def.bp_index != 0xFF)) {
|
||||
if (def.bp_index >= ret.size()) {
|
||||
ret.resize(def.bp_index + 1);
|
||||
}
|
||||
ret[def.bp_index].emplace_back(def.type);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
const vector<EnemyType>& enemy_types_for_battle_param_stats_index(Episode episode, uint8_t bp_index) {
|
||||
static array<vector<vector<EnemyType>>, 5> data;
|
||||
auto& ret = data.at(static_cast<size_t>(episode));
|
||||
if (ret.empty()) {
|
||||
ret = generate_table(episode);
|
||||
for (const auto& def : type_defs) {
|
||||
if (def.valid_in_episode(episode) && !def.bp_stats_indexes.empty()) {
|
||||
// Some enemies (e.g. Ep4 bosses) have multiple stats structures; we use the last one, since that's the only
|
||||
// one used when giving EXP
|
||||
size_t bp_index = def.bp_stats_indexes.back();
|
||||
if (bp_index >= ret.size()) {
|
||||
ret.resize(bp_index + 1);
|
||||
}
|
||||
ret[bp_index].emplace_back(def.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
return ret.at(bp_index);
|
||||
@@ -225,29 +225,28 @@ const vector<EnemyType>& enemy_types_for_battle_param_index(Episode episode, uin
|
||||
}
|
||||
}
|
||||
|
||||
EnemyType EnemyTypeDefinition::rare_type(Episode episode, uint8_t event, uint8_t floor) const {
|
||||
EnemyType EnemyTypeDefinition::rare_type(uint8_t area, uint8_t event) const {
|
||||
switch (this->type) {
|
||||
case EnemyType::HILDEBEAR:
|
||||
return EnemyType::HILDEBLUE;
|
||||
case EnemyType::RAG_RAPPY:
|
||||
switch (episode) {
|
||||
case Episode::EP1:
|
||||
return EnemyType::AL_RAPPY;
|
||||
case Episode::EP2:
|
||||
switch (event) {
|
||||
case 0x01: // rappy_type 1
|
||||
return EnemyType::SAINT_RAPPY;
|
||||
case 0x04: // rappy_type 2
|
||||
return EnemyType::EGG_RAPPY;
|
||||
case 0x05: // rappy_type 3
|
||||
return EnemyType::HALLO_RAPPY;
|
||||
default:
|
||||
return EnemyType::LOVE_RAPPY;
|
||||
}
|
||||
case Episode::EP4:
|
||||
return (floor > 0x05) ? EnemyType::DEL_RAPPY_DESERT : EnemyType::DEL_RAPPY_CRATER;
|
||||
default:
|
||||
throw logic_error("invalid episode");
|
||||
if (area < 0x12) {
|
||||
return EnemyType::AL_RAPPY;
|
||||
} else if (area < 0x24) {
|
||||
switch (event) {
|
||||
case 0x01: // rappy_type 1
|
||||
return EnemyType::SAINT_RAPPY;
|
||||
case 0x04: // rappy_type 2
|
||||
return EnemyType::EGG_RAPPY;
|
||||
case 0x05: // rappy_type 3
|
||||
return EnemyType::HALLO_RAPPY;
|
||||
default:
|
||||
return EnemyType::LOVE_RAPPY;
|
||||
}
|
||||
} else if (area <= 0x28) {
|
||||
return EnemyType::DEL_RAPPY_CRATER;
|
||||
} else {
|
||||
return EnemyType::DEL_RAPPY_DESERT;
|
||||
}
|
||||
case EnemyType::POISON_LILY:
|
||||
return EnemyType::NAR_LILY;
|
||||
|
||||
+25
-6
@@ -7,7 +7,13 @@
|
||||
#include "StaticGameData.hh"
|
||||
#include "Types.hh"
|
||||
|
||||
// We don't know what the actual maximum was, since it was presumably only stored server-side on Sega's servers. The
|
||||
// client uses values up to 0x6C (Kondrieu), so we just choose a value larger than that.
|
||||
static constexpr size_t NUM_RT_INDEXES_V3 = 0x64;
|
||||
static constexpr size_t NUM_RT_INDEXES_V4 = 0x70;
|
||||
|
||||
enum class EnemyType : uint8_t {
|
||||
MIN_VALUE = 0,
|
||||
UNKNOWN = 0,
|
||||
NONE,
|
||||
NON_ENEMY_NPC,
|
||||
@@ -15,6 +21,7 @@ enum class EnemyType : uint8_t {
|
||||
ASTARK,
|
||||
BA_BOOTA,
|
||||
BARBA_RAY,
|
||||
BARBA_RAY_JOINT,
|
||||
BARBAROUS_WOLF,
|
||||
BEE_L,
|
||||
BEE_R,
|
||||
@@ -35,7 +42,6 @@ enum class EnemyType : uint8_t {
|
||||
DARK_GUNNER,
|
||||
DARK_GUNNER_CONTROL,
|
||||
DARVANT,
|
||||
DARVANT_ULTIMATE,
|
||||
DE_ROL_LE,
|
||||
DE_ROL_LE_BODY,
|
||||
DE_ROL_LE_MINE,
|
||||
@@ -79,6 +85,7 @@ enum class EnemyType : uint8_t {
|
||||
HILDEBLUE,
|
||||
ILL_GILL,
|
||||
KONDRIEU,
|
||||
KONDRIEU_SPINNER,
|
||||
LA_DIMENIAN,
|
||||
LOVE_RAPPY,
|
||||
MERICARAND,
|
||||
@@ -110,6 +117,7 @@ enum class EnemyType : uint8_t {
|
||||
RECOBOX,
|
||||
RECON,
|
||||
SAINT_MILION,
|
||||
SAINT_MILION_SPINNER,
|
||||
SAINT_RAPPY,
|
||||
SAND_RAPPY_CRATER,
|
||||
SAND_RAPPY_DESERT,
|
||||
@@ -117,6 +125,7 @@ enum class EnemyType : uint8_t {
|
||||
SATELLITE_LIZARD_DESERT,
|
||||
SAVAGE_WOLF,
|
||||
SHAMBERTIN,
|
||||
SHAMBERTIN_SPINNER,
|
||||
SINOW_BEAT,
|
||||
SINOW_BERILL,
|
||||
SINOW_GOLD,
|
||||
@@ -125,6 +134,7 @@ enum class EnemyType : uint8_t {
|
||||
SINOW_ZOA,
|
||||
SO_DIMENIAN,
|
||||
UL_GIBBON,
|
||||
UL_RAY,
|
||||
VOL_OPT_1,
|
||||
VOL_OPT_2,
|
||||
VOL_OPT_AMP,
|
||||
@@ -137,7 +147,7 @@ enum class EnemyType : uint8_t {
|
||||
ZOL_GIBBON,
|
||||
ZU_CRATER,
|
||||
ZU_DESERT,
|
||||
MAX_ENEMY_TYPE,
|
||||
MAX_VALUE,
|
||||
};
|
||||
|
||||
struct EnemyTypeDefinition {
|
||||
@@ -146,11 +156,17 @@ struct EnemyTypeDefinition {
|
||||
VALID_EP2 = 0x02,
|
||||
VALID_EP4 = 0x04,
|
||||
IS_RARE = 0x08,
|
||||
IS_BOSS = 0x10,
|
||||
};
|
||||
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)
|
||||
uint8_t rt_index; // 0xFF if not valid (e.g. not an enemy, or has no drops)
|
||||
uint8_t legacy_rt_index; // Index used by Schtserv in their Ep4 .rel format
|
||||
std::vector<uint8_t> bp_stats_indexes;
|
||||
std::vector<uint8_t> bp_attack_data_indexes;
|
||||
std::vector<uint8_t> bp_resist_data_indexes;
|
||||
// Note: movement data isn't bound as strongly to the enemy types; some enemies use many entries and some use none at
|
||||
// all, so we don't list them here. See notes/movement-data.txt for a listing of which enemies use which entries.
|
||||
const char* enum_name;
|
||||
const char* in_game_name;
|
||||
const char* ultimate_name; // May be null if same as in_game_name
|
||||
@@ -170,7 +186,10 @@ struct EnemyTypeDefinition {
|
||||
inline bool is_rare() const {
|
||||
return (this->flags & Flag::IS_RARE);
|
||||
}
|
||||
EnemyType rare_type(Episode episode, uint8_t event, uint8_t floor) const;
|
||||
inline bool is_boss() const {
|
||||
return (this->flags & Flag::IS_BOSS);
|
||||
}
|
||||
EnemyType rare_type(uint8_t area, uint8_t event) const;
|
||||
};
|
||||
|
||||
const EnemyTypeDefinition& type_definition_for_enemy(EnemyType type);
|
||||
@@ -181,4 +200,4 @@ template <>
|
||||
EnemyType phosg::enum_for_name<EnemyType>(const char* name);
|
||||
|
||||
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index);
|
||||
const std::vector<EnemyType>& enemy_types_for_battle_param_index(Episode episode, uint8_t bp_index);
|
||||
const std::vector<EnemyType>& enemy_types_for_battle_param_stats_index(Episode episode, uint8_t bp_index);
|
||||
|
||||
@@ -11,24 +11,19 @@ const vector<uint16_t>& all_assist_card_ids(bool is_nte) {
|
||||
// code. This is relevant for consistency of results when choosing a random card
|
||||
// (for God Whim).
|
||||
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_TRIAL = {
|
||||
0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD,
|
||||
0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106,
|
||||
0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, 0x010F,
|
||||
0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C,
|
||||
0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135,
|
||||
0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D, 0x013E,
|
||||
0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148,
|
||||
0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F, 0x0240, 0x0241, 0x0242};
|
||||
0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102,
|
||||
0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, 0x010F, 0x0121,
|
||||
0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
|
||||
0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D, 0x013E, 0x013F, 0x0140,
|
||||
0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F, 0x0240,
|
||||
0x0241, 0x0242};
|
||||
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_FINAL = {
|
||||
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA,
|
||||
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103,
|
||||
0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C,
|
||||
0x010D, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129,
|
||||
0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
|
||||
0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B,
|
||||
0x013C, 0x013D, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144,
|
||||
0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F,
|
||||
0x0240, 0x0241, 0x0242};
|
||||
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D,
|
||||
0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F,
|
||||
0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D,
|
||||
0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D,
|
||||
0x014E, 0x023F, 0x0240, 0x0241, 0x0242};
|
||||
return is_nte ? ALL_ASSIST_CARD_IDS_TRIAL : ALL_ASSIST_CARD_IDS_FINAL;
|
||||
}
|
||||
|
||||
@@ -174,13 +169,11 @@ uint32_t AssistServer::compute_num_assist_effects_for_client(uint16_t client_id)
|
||||
if (ce->def.target_mode == TargetMode::TEAM) {
|
||||
auto this_deck_entry = this->deck_entries[client_id];
|
||||
auto other_deck_entry = this->deck_entries[z];
|
||||
if (this_deck_entry && other_deck_entry &&
|
||||
(this_deck_entry->team_id == other_deck_entry->team_id)) {
|
||||
if (this_deck_entry && other_deck_entry && (this_deck_entry->team_id == other_deck_entry->team_id)) {
|
||||
affected = true;
|
||||
}
|
||||
} else if ((ce->def.target_mode == TargetMode::SELF) && (z == client_id)) {
|
||||
affected = true;
|
||||
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
|
||||
} else if (((ce->def.target_mode == TargetMode::SELF) && (z == client_id)) ||
|
||||
(ce->def.target_mode == TargetMode::EVERYONE)) {
|
||||
affected = true;
|
||||
}
|
||||
if (affected) {
|
||||
@@ -226,9 +219,8 @@ bool AssistServer::should_block_assist_effects_for_client(uint16_t client_id) co
|
||||
(this->deck_entries[client_id]->team_id == this->deck_entries[z]->team_id)) {
|
||||
return true;
|
||||
}
|
||||
} else if ((ce->def.target_mode == TargetMode::SELF) && (client_id == z)) {
|
||||
return true;
|
||||
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
|
||||
} else if (((ce->def.target_mode == TargetMode::SELF) && (client_id == z)) ||
|
||||
(ce->def.target_mode == TargetMode::EVERYONE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -237,10 +229,7 @@ bool AssistServer::should_block_assist_effects_for_client(uint16_t client_id) co
|
||||
}
|
||||
|
||||
AssistEffect AssistServer::get_active_assist_by_index(size_t index) const {
|
||||
if (index < this->num_active_assists) {
|
||||
return this->active_assist_effects[index];
|
||||
}
|
||||
return AssistEffect::NONE;
|
||||
return (index < this->num_active_assists) ? this->active_assist_effects[index] : AssistEffect::NONE;
|
||||
}
|
||||
|
||||
void AssistServer::populate_effects() {
|
||||
|
||||
@@ -174,21 +174,6 @@ string BattleRecord::serialize() const {
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
bool BattleRecord::writable() const {
|
||||
return this->is_writable;
|
||||
}
|
||||
|
||||
bool BattleRecord::battle_in_progress() const {
|
||||
return (this->battle_start_timestamp != 0);
|
||||
}
|
||||
|
||||
const BattleRecord::Event* BattleRecord::get_first_event() const {
|
||||
if (this->events.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &this->events.front();
|
||||
}
|
||||
|
||||
void BattleRecord::add_player(
|
||||
const PlayerLobbyDataDCGC& lobby_data,
|
||||
const PlayerInventory& inventory,
|
||||
@@ -256,16 +241,6 @@ void BattleRecord::add_random_data(const void* data, size_t size) {
|
||||
this->random_stream.append(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
|
||||
vector<string> BattleRecord::get_all_server_data_commands() const {
|
||||
vector<string> ret;
|
||||
for (const auto& event : this->events) {
|
||||
if (event.type == Event::Type::SERVER_DATA_COMMAND) {
|
||||
ret.emplace_back(event.data);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const string& BattleRecord::get_random_stream() const {
|
||||
return this->random_stream;
|
||||
}
|
||||
|
||||
@@ -62,10 +62,25 @@ public:
|
||||
explicit BattleRecord(const std::string& data);
|
||||
std::string serialize() const;
|
||||
|
||||
bool writable() const;
|
||||
bool battle_in_progress() const;
|
||||
inline bool writable() const {
|
||||
return this->is_writable;
|
||||
}
|
||||
|
||||
const Event* get_first_event() const;
|
||||
inline uint32_t get_behavior_flags() const {
|
||||
return this->behavior_flags;
|
||||
}
|
||||
|
||||
inline bool battle_in_progress() const {
|
||||
return (this->battle_start_timestamp != 0);
|
||||
}
|
||||
|
||||
inline const Event* get_first_event() const {
|
||||
return this->events.empty() ? nullptr : &this->events.front();
|
||||
}
|
||||
|
||||
inline std::deque<Event> get_all_events() const {
|
||||
return this->events;
|
||||
}
|
||||
|
||||
void add_player(
|
||||
const PlayerLobbyDataDCGC& lobby_data,
|
||||
@@ -86,7 +101,6 @@ public:
|
||||
|
||||
void print(FILE* stream) const;
|
||||
|
||||
std::vector<std::string> get_all_server_data_commands() const;
|
||||
const std::string& get_random_stream() const;
|
||||
|
||||
private:
|
||||
|
||||
+31
-50
@@ -7,11 +7,7 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
Card::Card(
|
||||
uint16_t card_id,
|
||||
uint16_t card_ref,
|
||||
uint16_t client_id,
|
||||
shared_ptr<Server> server)
|
||||
Card::Card(uint16_t card_id, uint16_t card_ref, uint16_t client_id, shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
w_player_state(server->get_player_state(client_id)),
|
||||
client_id(client_id),
|
||||
@@ -132,8 +128,7 @@ ssize_t Card::apply_abnormal_condition(
|
||||
if (cond.type == eff.type) {
|
||||
existing_cond_index = z;
|
||||
if ((!is_nte && eff.type == ConditionType::MV_BONUS) ||
|
||||
((cond.card_definition_effect_index == def_effect_index) &&
|
||||
(cond.card_ref == target_card_ref))) {
|
||||
((cond.card_definition_effect_index == def_effect_index) && (cond.card_ref == target_card_ref))) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -173,11 +168,7 @@ ssize_t Card::apply_abnormal_condition(
|
||||
cond.condition_giver_card_ref = sc_card_ref;
|
||||
cond.card_definition_effect_index = def_effect_index;
|
||||
cond.order = 10;
|
||||
if (dice_roll_value < 0) {
|
||||
cond.dice_roll_value = this->player_state()->roll_dice_with_effects(1);
|
||||
} else {
|
||||
cond.dice_roll_value = dice_roll_value;
|
||||
}
|
||||
cond.dice_roll_value = (dice_roll_value < 0) ? this->player_state()->roll_dice_with_effects(1) : dice_roll_value;
|
||||
cond.flags = 0;
|
||||
cond.value = value + existing_cond_value;
|
||||
cond.value8 = value + existing_cond_value;
|
||||
@@ -309,8 +300,7 @@ void Card::commit_attack(
|
||||
size_t num_assists = s->assist_server->compute_num_assist_effects_for_client(this->client_id);
|
||||
for (size_t z = 0; z < num_assists; z++) {
|
||||
auto eff = s->assist_server->get_active_assist_by_index(z);
|
||||
if ((eff == AssistEffect::RANSOM) &&
|
||||
(attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL)) {
|
||||
if ((eff == AssistEffect::RANSOM) && (attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL)) {
|
||||
uint8_t team_id = this->player_state()->get_team_id();
|
||||
int16_t exp_amount = clamp<int16_t>(s->team_exp[team_id], 0, effective_damage);
|
||||
s->team_exp[team_id] -= exp_amount;
|
||||
@@ -339,8 +329,7 @@ void Card::commit_attack(
|
||||
this->current_hp = clamp<int16_t>(this->current_hp - effective_damage, 0, this->max_hp);
|
||||
log.debug_f("hp set to {}", this->current_hp);
|
||||
|
||||
if ((effective_damage > 0) &&
|
||||
(attacker_ps->stats.max_attack_damage < effective_damage)) {
|
||||
if ((effective_damage > 0) && (attacker_ps->stats.max_attack_damage < effective_damage)) {
|
||||
attacker_ps->stats.max_attack_damage = effective_damage;
|
||||
log.debug_f("attacker new max damage {}", effective_damage);
|
||||
}
|
||||
@@ -396,8 +385,10 @@ int16_t Card::compute_defense_power_for_attacker_card(shared_ptr<const Card> att
|
||||
}
|
||||
}
|
||||
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x08, nullptr);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x10, nullptr);
|
||||
s->card_special->apply_action_conditions(
|
||||
EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x08, nullptr);
|
||||
s->card_special->apply_action_conditions(
|
||||
EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x10, nullptr);
|
||||
return this->action_metadata.defense_power + this->action_metadata.defense_bonus;
|
||||
}
|
||||
|
||||
@@ -439,8 +430,7 @@ void Card::destroy_set_card(shared_ptr<Card> attacker_card) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((s->map_and_rules->rules.hp_type == HPType::DEFEAT_TEAM) &&
|
||||
(ps->get_sc_card().get() == this)) {
|
||||
if ((s->map_and_rules->rules.hp_type == HPType::DEFEAT_TEAM) && (ps->get_sc_card().get() == this)) {
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = ps->get_set_card(set_index);
|
||||
if (card) {
|
||||
@@ -464,7 +454,7 @@ void Card::destroy_set_card(shared_ptr<Card> attacker_card) {
|
||||
uint8_t other_team_id = s->player_states[client_id]->get_team_id();
|
||||
uint8_t this_team_id = ps->get_team_id();
|
||||
if (this_team_id == other_team_id) {
|
||||
s->add_team_exp(team_id, this->max_hp);
|
||||
s->add_team_exp(this_team_id, this->max_hp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,8 +478,7 @@ int32_t Card::error_code_for_move_to_location(const Location& loc) const {
|
||||
if (this->card_flags & 2) {
|
||||
return -0x60;
|
||||
}
|
||||
if (!this->server()->ruler_server->card_ref_can_move(
|
||||
this->client_id, this->card_ref, 1)) {
|
||||
if (!this->server()->ruler_server->card_ref_can_move(this->client_id, this->card_ref, 1)) {
|
||||
return -0x7B;
|
||||
}
|
||||
// Note: The original code passes non-null pointers here but ignores the
|
||||
@@ -529,9 +518,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
|
||||
if (attacker_card->action_chain.chain.attack_medium == AttackMedium::UNKNOWN_03) {
|
||||
// Probably Resta
|
||||
for (size_t strike_num = 0; strike_num < attacker_card->action_chain.chain.strike_count; strike_num++) {
|
||||
this->current_hp = min<int16_t>(
|
||||
this->current_hp + attacker_card->action_chain.chain.effective_tp,
|
||||
this->max_hp);
|
||||
this->current_hp = min<int16_t>(this->current_hp + attacker_card->action_chain.chain.effective_tp, this->max_hp);
|
||||
}
|
||||
this->propagate_shared_hp_if_needed();
|
||||
cmd.effect.tp = attacker_card->action_chain.chain.effective_tp;
|
||||
@@ -613,11 +600,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
|
||||
}
|
||||
|
||||
bool Card::get_condition_value(
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const {
|
||||
ConditionType cond_type, uint16_t card_ref, uint8_t def_effect_index, uint16_t value, uint16_t* out_value) const {
|
||||
return this->action_chain.get_condition_value(cond_type, card_ref, def_effect_index, value, out_value);
|
||||
}
|
||||
|
||||
@@ -697,9 +680,7 @@ int32_t Card::move_to_location(const Location& loc) {
|
||||
this->card_flags = this->card_flags | 0x80;
|
||||
|
||||
// On NTE, traps happen now, not after the Move phase
|
||||
if (s->options.is_nte() &&
|
||||
this->def_entry->def.is_sc() &&
|
||||
((s->overlay_state.tiles[loc.y][loc.x] & 0xF0) == 0x40)) {
|
||||
if (s->options.is_nte() && this->def_entry->def.is_sc() && ((s->overlay_state.tiles[loc.y][loc.x] & 0xF0) == 0x40)) {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto other_ps = s->player_states[z];
|
||||
if (!other_ps) {
|
||||
@@ -752,8 +733,7 @@ void Card::propagate_shared_hp_if_needed() {
|
||||
((this->def_entry->def.type == CardType::HUNTERS_SC) || (this->def_entry->def.type == CardType::ARKZ_SC))) {
|
||||
for (size_t other_client_id = 0; other_client_id < 4; other_client_id++) {
|
||||
auto other_ps = this->server()->player_states[other_client_id];
|
||||
if ((other_client_id != this->client_id) && other_ps &&
|
||||
(other_ps->get_team_id() == this->team_id)) {
|
||||
if ((other_client_id != this->client_id) && other_ps && (other_ps->get_team_id() == this->team_id)) {
|
||||
other_ps->get_sc_card()->set_current_hp(this->current_hp, false);
|
||||
}
|
||||
}
|
||||
@@ -906,7 +886,8 @@ void Card::clear_action_chain_and_metadata_and_most_flags() {
|
||||
|
||||
void Card::compute_action_chain_results(bool apply_action_conditions, bool ignore_this_card_ap_tp) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(std::format("compute_action_chain_results(@{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id()));
|
||||
auto log = s->log_stack(std::format(
|
||||
"compute_action_chain_results(@{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id()));
|
||||
bool is_nte = s->options.is_nte();
|
||||
|
||||
this->action_chain.compute_attack_medium(s);
|
||||
@@ -930,7 +911,8 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
} else {
|
||||
stat_swap_type = s->card_special->compute_stat_swap_type(this->shared_from_this());
|
||||
log.debug_f("stat_swap_type = {} (0=none, 1=a/t, 2=a/h)", static_cast<size_t>(stat_swap_type));
|
||||
s->card_special->get_effective_ap_tp(stat_swap_type, &effective_ap, &effective_tp, this->get_current_hp(), this->ap, this->tp);
|
||||
s->card_special->get_effective_ap_tp(
|
||||
stat_swap_type, &effective_ap, &effective_tp, this->get_current_hp(), this->ap, this->tp);
|
||||
log.debug_f("effective_ap = {}, effective_tp = {}", effective_ap, effective_tp);
|
||||
}
|
||||
|
||||
@@ -1008,7 +990,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
break;
|
||||
case AssistEffect::INFLUENCE:
|
||||
if (!is_nte && this->card_type_is_sc_or_creature()) {
|
||||
int16_t count = ps->count_set_refs();
|
||||
int16_t count = ps->count_hand_refs();
|
||||
this->action_chain.chain.ap_effect_bonus += (count >> 1);
|
||||
}
|
||||
break;
|
||||
@@ -1082,8 +1064,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
}
|
||||
auto other_sc_card = other_ps->get_sc_card();
|
||||
if (other_sc_card &&
|
||||
(abs(this->loc.x - other_sc_card->loc.x) < 2) &&
|
||||
(abs(this->loc.y - other_sc_card->loc.y) < 2)) {
|
||||
(abs(this->loc.x - other_sc_card->loc.x) < 2) && (abs(this->loc.y - other_sc_card->loc.y) < 2)) {
|
||||
num_scs_in_range++;
|
||||
}
|
||||
}
|
||||
@@ -1106,10 +1087,12 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
int16_t damage = 0;
|
||||
if (this->action_chain.chain.attack_medium == AttackMedium::TECH) {
|
||||
damage = this->action_chain.chain.effective_tp + this->action_chain.chain.tp_effect_bonus;
|
||||
log.debug_f("(tech) damage = {} (eff) + {} (bonus) = {}", this->action_chain.chain.effective_tp, this->action_chain.chain.tp_effect_bonus, damage);
|
||||
log.debug_f("(tech) damage = {} (eff) + {} (bonus) = {}",
|
||||
this->action_chain.chain.effective_tp, this->action_chain.chain.tp_effect_bonus, damage);
|
||||
} else if (this->action_chain.chain.attack_medium == AttackMedium::PHYSICAL) {
|
||||
damage = this->action_chain.chain.effective_ap + this->action_chain.chain.ap_effect_bonus;
|
||||
log.debug_f("(physical) damage = {} (eff) + {} (bonus) = {}", this->action_chain.chain.effective_ap, this->action_chain.chain.ap_effect_bonus, damage);
|
||||
log.debug_f("(physical) damage = {} (eff) + {} (bonus) = {}",
|
||||
this->action_chain.chain.effective_ap, this->action_chain.chain.ap_effect_bonus, damage);
|
||||
} else {
|
||||
log.debug_f("(unknown attack medium) damage = 0");
|
||||
}
|
||||
@@ -1117,7 +1100,8 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
this->action_chain.chain.damage = is_nte
|
||||
? (damage * this->action_chain.chain.damage_multiplier)
|
||||
: min<int16_t>(damage * this->action_chain.chain.damage_multiplier, 99);
|
||||
log.debug_f("overall chain damage = {} (base) * {} (mult) = {}", damage, this->action_chain.chain.damage_multiplier, this->action_chain.chain.damage);
|
||||
log.debug_f("overall chain damage = {} (base) * {} (mult) = {}",
|
||||
damage, this->action_chain.chain.damage_multiplier, this->action_chain.chain.damage);
|
||||
|
||||
if (apply_action_conditions) {
|
||||
auto this_sh = this->shared_from_this();
|
||||
@@ -1271,8 +1255,7 @@ void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as)
|
||||
}
|
||||
|
||||
void Card::unknown_802379BC(uint16_t card_ref) {
|
||||
this->action_chain.chain.unknown_card_ref_a3 =
|
||||
(card_ref == 0xFFFF) ? this->card_ref : card_ref;
|
||||
this->action_chain.chain.unknown_card_ref_a3 = (card_ref == 0xFFFF) ? this->card_ref : card_ref;
|
||||
}
|
||||
|
||||
void Card::unknown_802379DC(const ActionState& pa) {
|
||||
@@ -1359,8 +1342,7 @@ void Card::dice_phase_before() {
|
||||
cond.remaining_turns--;
|
||||
}
|
||||
if (cond.remaining_turns < 1) {
|
||||
s->card_special->apply_stat_deltas_to_card_from_condition_and_clear_cond(
|
||||
cond, this->shared_from_this());
|
||||
s->card_special->apply_stat_deltas_to_card_from_condition_and_clear_cond(cond, this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1382,8 +1364,7 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
|
||||
: std::format("unknown_80236554(@{:04X} #{:04X}, null): ", this->get_card_ref(), this->get_card_id()));
|
||||
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
|
||||
if (as) {
|
||||
string as_str = as->str(s);
|
||||
log.debug_f("as = {}", as_str);
|
||||
log.debug_f("as = {}", as->str(s));
|
||||
} else {
|
||||
log.debug_f("as = null");
|
||||
}
|
||||
|
||||
+195
-289
@@ -84,7 +84,8 @@ void CardSpecial::AttackEnvStats::clear() {
|
||||
this->target_current_hp = 0;
|
||||
}
|
||||
uint32_t CardSpecial::AttackEnvStats::at(size_t index) const {
|
||||
static_assert(sizeof(parray<uint32_t, 39>) == sizeof(AttackEnvStats), "CardSpecial::AttackEnvStats does not have exactly 39 entries");
|
||||
static_assert(sizeof(parray<uint32_t, 39>) == sizeof(AttackEnvStats),
|
||||
"CardSpecial::AttackEnvStats does not have exactly 39 entries");
|
||||
return reinterpret_cast<const parray<uint32_t, 39>*>(this)->at(index);
|
||||
}
|
||||
|
||||
@@ -454,10 +455,7 @@ bool CardSpecial::apply_defense_condition(
|
||||
}
|
||||
|
||||
bool CardSpecial::apply_defense_conditions(
|
||||
const ActionState& as,
|
||||
EffectWhen when,
|
||||
shared_ptr<Card> defender_card,
|
||||
uint32_t flags) {
|
||||
const ActionState& as, EffectWhen when, shared_ptr<Card> defender_card, uint32_t flags) {
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
this->apply_defense_condition(when, &defender_card->action_chain.conditions[z], z, as, defender_card, flags, 0);
|
||||
}
|
||||
@@ -474,14 +472,12 @@ bool CardSpecial::apply_stat_deltas_to_all_cards_from_all_conditions_with_card_r
|
||||
}
|
||||
auto sc_card = ps->get_sc_card();
|
||||
if (sc_card) {
|
||||
ret |= this->apply_stats_deltas_to_card_from_all_conditions_with_card_ref(
|
||||
card_ref, sc_card);
|
||||
ret |= this->apply_stats_deltas_to_card_from_all_conditions_with_card_ref(card_ref, sc_card);
|
||||
}
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto set_card = ps->get_set_card(set_index);
|
||||
if (set_card) {
|
||||
ret |= this->apply_stats_deltas_to_card_from_all_conditions_with_card_ref(
|
||||
card_ref, set_card);
|
||||
ret |= this->apply_stats_deltas_to_card_from_all_conditions_with_card_ref(card_ref, set_card);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,8 +490,7 @@ bool CardSpecial::apply_stat_deltas_to_card_from_condition_and_clear_cond(Condit
|
||||
auto log = s->log_stack(std::format("apply_stat_deltas_to_card_from_condition_and_clear_cond(@{:04X} #{:04X}): ", card->get_card_ref(), card->get_card_id()));
|
||||
bool is_nte = s->options.is_nte();
|
||||
|
||||
string cond_str = cond.str(s);
|
||||
log.debug_f("cond: {}", cond_str);
|
||||
log.debug_f("cond: {}", cond.str(s));
|
||||
|
||||
ConditionType cond_type = cond.type;
|
||||
int16_t cond_value = is_nte ? cond.value.load() : clamp<int16_t>(cond.value, -99, 99);
|
||||
@@ -643,10 +638,7 @@ bool CardSpecial::apply_stats_deltas_to_card_from_all_conditions_with_card_ref(
|
||||
}
|
||||
|
||||
bool CardSpecial::card_has_condition_with_ref(
|
||||
shared_ptr<const Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint16_t match_card_ref) const {
|
||||
shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref, uint16_t match_card_ref) const {
|
||||
size_t z = 0;
|
||||
while ((z < 9) &&
|
||||
((card->action_chain.conditions[z].type != cond_type) ||
|
||||
@@ -666,14 +658,11 @@ bool CardSpecial::card_is_destroyed(shared_ptr<const Card> card) const {
|
||||
if (card->get_current_hp() > 0) {
|
||||
return false;
|
||||
}
|
||||
return !this->server()->ruler_server->card_ref_or_any_set_card_has_condition_46(
|
||||
card->get_card_ref());
|
||||
return !this->server()->ruler_server->card_ref_or_any_set_card_has_condition_46(card->get_card_ref());
|
||||
}
|
||||
|
||||
void CardSpecial::compute_attack_ap(
|
||||
shared_ptr<const Card> target_card,
|
||||
int16_t* out_value,
|
||||
uint16_t attacker_card_ref) {
|
||||
shared_ptr<const Card> target_card, int16_t* out_value, uint16_t attacker_card_ref) {
|
||||
auto s = this->server();
|
||||
auto is_nte = s->options.is_nte();
|
||||
|
||||
@@ -773,9 +762,7 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
}
|
||||
ast.total_num_set_cards = ps_num_set_cards;
|
||||
|
||||
uint8_t target_card_team_id = target_card
|
||||
? target_card->player_state()->get_team_id()
|
||||
: 0xFF;
|
||||
uint8_t target_card_team_id = target_card ? target_card->player_state()->get_team_id() : 0xFF;
|
||||
|
||||
size_t target_team_num_set_cards = 0;
|
||||
size_t non_target_team_num_set_cards = 0;
|
||||
@@ -831,13 +818,16 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
ast.max_hp = card->get_max_hp();
|
||||
ast.team_dice_bonus = card ? s->team_dice_bonus[card->get_team_id()] : 0;
|
||||
|
||||
ast.effective_ap_if_not_tech = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
ast.effective_ap_if_not_tech =
|
||||
(!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.effective_ap_if_not_tech2 = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
ast.effective_ap_if_not_tech2 =
|
||||
(!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.effective_ap_if_not_physical = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL))
|
||||
ast.effective_ap_if_not_physical =
|
||||
(!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL))
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.sc_effective_ap = attacker_card ? attacker_card->action_chain.chain.damage : 0;
|
||||
@@ -870,9 +860,7 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
uint16_t z_ref = pa.attacker_card_ref;
|
||||
// Note: The (z < 8) conditions in these two loops are not present in the
|
||||
// original code.
|
||||
for (z = 0;
|
||||
((target_card_ref != z_ref) && (z < 8) && ((z_ref = pa.action_card_refs[z]) != 0xFFFF));
|
||||
z++) {
|
||||
for (z = 0; ((target_card_ref != z_ref) && (z < 8) && ((z_ref = pa.action_card_refs[z]) != 0xFFFF)); z++) {
|
||||
}
|
||||
|
||||
ast.action_cards_ap = 0;
|
||||
@@ -1012,8 +1000,7 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
if (num_candidates > 0) {
|
||||
uint8_t a = target_ps->roll_dice_with_effects(2);
|
||||
uint8_t b = target_ps->roll_dice_with_effects(1);
|
||||
return s->card_for_set_card_ref(
|
||||
candidate_card_refs[(a + b) - ((a + b) / num_candidates) * num_candidates]);
|
||||
return s->card_for_set_card_ref(candidate_card_refs[(a + b) - ((a + b) / num_candidates) * num_candidates]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1290,8 +1277,7 @@ size_t CardSpecial::count_action_cards_with_condition_for_all_current_attacks(
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->server()->get_player_state(client_id);
|
||||
if (ps) {
|
||||
ret += this->count_action_cards_with_condition_for_current_attack(
|
||||
ps->get_sc_card(), cond_type, card_ref);
|
||||
ret += this->count_action_cards_with_condition_for_current_attack(ps->get_sc_card(), cond_type, card_ref);
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
ret += this->count_action_cards_with_condition_for_current_attack(
|
||||
ps->get_set_card(set_index), cond_type, card_ref);
|
||||
@@ -1338,8 +1324,7 @@ size_t CardSpecial::count_action_cards_with_condition_for_current_attack(
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t CardSpecial::count_cards_with_card_id_except_card_ref(
|
||||
uint16_t card_id, uint16_t card_ref) const {
|
||||
size_t CardSpecial::count_cards_with_card_id_except_card_ref(uint16_t card_id, uint16_t card_ref) const {
|
||||
size_t ret = 0;
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->server()->get_player_state(client_id);
|
||||
@@ -1348,9 +1333,7 @@ size_t CardSpecial::count_cards_with_card_id_except_card_ref(
|
||||
}
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = ps->get_set_card(set_index);
|
||||
if (card &&
|
||||
(card->get_card_ref() != card_ref) &&
|
||||
(card->get_definition()->def.card_id == card_id)) {
|
||||
if (card && (card->get_card_ref() != card_ref) && (card->get_definition()->def.card_id == card_id)) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
@@ -1393,8 +1376,7 @@ ActionState CardSpecial::create_attack_state_from_card_action_chain(
|
||||
shared_ptr<const Card> attacker_card) const {
|
||||
ActionState ret;
|
||||
if (attacker_card) {
|
||||
ret.attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(
|
||||
attacker_card->get_card_ref(), 4);
|
||||
ret.attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(attacker_card->get_card_ref(), 4);
|
||||
for (size_t z = 0; z < attacker_card->action_chain.chain.attack_action_card_ref_count; z++) {
|
||||
ret.action_card_refs[z] = this->send_6xB4x06_if_card_ref_invalid(
|
||||
attacker_card->action_chain.chain.attack_action_card_refs[z], 5);
|
||||
@@ -1408,8 +1390,7 @@ ActionState CardSpecial::create_attack_state_from_card_action_chain(
|
||||
}
|
||||
|
||||
ActionState CardSpecial::create_defense_state_for_card_pair_action_chains(
|
||||
shared_ptr<const Card> attacker_card,
|
||||
shared_ptr<const Card> defender_card) const {
|
||||
shared_ptr<const Card> attacker_card, shared_ptr<const Card> defender_card) const {
|
||||
ActionState ret;
|
||||
if (defender_card && attacker_card) {
|
||||
size_t count = 0;
|
||||
@@ -1422,18 +1403,15 @@ ActionState CardSpecial::create_defense_state_for_card_pair_action_chains(
|
||||
}
|
||||
}
|
||||
if (defender_card) {
|
||||
ret.target_card_refs[0] = this->send_6xB4x06_if_card_ref_invalid(
|
||||
defender_card->get_card_ref(), 8);
|
||||
ret.target_card_refs[0] = this->send_6xB4x06_if_card_ref_invalid(defender_card->get_card_ref(), 8);
|
||||
}
|
||||
if (attacker_card) {
|
||||
ret.original_attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(
|
||||
attacker_card->get_card_ref(), 9);
|
||||
ret.original_attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(attacker_card->get_card_ref(), 9);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CardSpecial::destroy_card_if_hp_zero(
|
||||
shared_ptr<Card> card, uint16_t attacker_card_ref) {
|
||||
void CardSpecial::destroy_card_if_hp_zero(shared_ptr<Card> card, uint16_t attacker_card_ref) {
|
||||
if (card && (card->get_current_hp() <= 0)) {
|
||||
card->destroy_set_card(this->server()->card_for_set_card_ref(attacker_card_ref));
|
||||
}
|
||||
@@ -1462,9 +1440,15 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
bool is_nte = s->options.is_nte();
|
||||
auto set_card = s->card_for_set_card_ref(set_card_ref);
|
||||
bool set_card_has_ability_trap =
|
||||
(!is_nte && set_card && this->card_has_condition_with_ref(set_card, ConditionType::ABILITY_TRAP, 0xFFFF, 0xFFFF));
|
||||
(!is_nte && set_card &&
|
||||
this->card_has_condition_with_ref(set_card, ConditionType::ABILITY_TRAP, 0xFFFF, 0xFFFF));
|
||||
|
||||
switch (arg2_text[0]) {
|
||||
case 'b': {
|
||||
auto attacker_card = s->card_for_set_card_ref(attacker_card_ref);
|
||||
return (attacker_card && (attacker_card->action_chain.chain.damage <= atoi(arg2_text + 1)));
|
||||
}
|
||||
|
||||
case 'C':
|
||||
if (is_nte) {
|
||||
return false;
|
||||
@@ -1515,11 +1499,6 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
return false;
|
||||
}
|
||||
|
||||
case 'b': {
|
||||
auto attacker_card = s->card_for_set_card_ref(attacker_card_ref);
|
||||
return (attacker_card && (attacker_card->action_chain.chain.damage <= atoi(arg2_text + 1)));
|
||||
}
|
||||
|
||||
case 'd': {
|
||||
if (set_card_has_ability_trap) {
|
||||
return false;
|
||||
@@ -1596,7 +1575,8 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
auto ce = card->get_definition();
|
||||
return ((ce->def.card_class() == CardClass::GUARD_ITEM) ||
|
||||
(!is_nte && (ce->def.card_class() == CardClass::MAG_ITEM)) ||
|
||||
s->ruler_server->find_condition_on_card_ref(card->get_card_ref(), ConditionType::GUARD_CREATURE, 0, 0, 0));
|
||||
s->ruler_server->find_condition_on_card_ref(
|
||||
card->get_card_ref(), ConditionType::GUARD_CREATURE, 0, 0, 0));
|
||||
}
|
||||
case 0x0E: // n14
|
||||
return card->get_definition()->def.is_sc();
|
||||
@@ -1674,8 +1654,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
return (!set_card_has_ability_trap || is_nte) && (random_percent < atoi(arg2_text + 1));
|
||||
case 's': {
|
||||
auto ce = card->get_definition();
|
||||
return ((ce->def.self_cost >= arg2_text[1] - '0') &&
|
||||
(ce->def.self_cost <= arg2_text[2] - '0'));
|
||||
return ((ce->def.self_cost >= arg2_text[1] - '0') && (ce->def.self_cost <= arg2_text[2] - '0'));
|
||||
}
|
||||
case 't': {
|
||||
auto set_card = s->card_for_set_card_ref(set_card_ref);
|
||||
@@ -1689,14 +1668,12 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
return (v < set_card->unknown_a9);
|
||||
} else if (when == EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN) {
|
||||
uint32_t y = set_card->unknown_a9 & 0xFFFFFFFE;
|
||||
if ((set_card->unknown_a9 > 0) &&
|
||||
(y == (y / (v & 0xFFFFFFFE)) * (v & 0xFFFFFFFE))) {
|
||||
if ((set_card->unknown_a9 > 0) && (y == (y / (v & 0xFFFFFFFE)) * (v & 0xFFFFFFFE))) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
uint32_t y = set_card->unknown_a9;
|
||||
if ((set_card->unknown_a9 > 0) &&
|
||||
(y == (y / (v + 1)) * (v + 1))) {
|
||||
if ((set_card->unknown_a9 > 0) && (y == (y / (v + 1)) * (v + 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1708,85 +1685,81 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
throw logic_error("this should be impossible");
|
||||
}
|
||||
|
||||
int32_t CardSpecial::evaluate_effect_expr(
|
||||
const AttackEnvStats& ast,
|
||||
const char* expr,
|
||||
DiceRoll& dice_roll) const {
|
||||
int32_t CardSpecial::evaluate_effect_expr(const AttackEnvStats& ast, const char* expr, DiceRoll& dice_roll) const {
|
||||
using ExprToken = CardDefinition::Effect::ExprToken;
|
||||
|
||||
auto log = this->server()->log_stack("evaluate_effect_expr: ");
|
||||
if (log.min_level == phosg::LogLevel::L_DEBUG) {
|
||||
log.debug_f("ast, expr=\"{}\", dice_roll=(client_id={:02X}, a2={:02X}, value={:02X}, value_used_in_expr={}, a5={:04X})", expr, dice_roll.client_id, dice_roll.unknown_a2, dice_roll.value, dice_roll.value_used_in_expr ? "true" : "false", dice_roll.unknown_a5);
|
||||
log.debug_f(
|
||||
"ast, expr=\"{}\", dice_roll=(client_id={:02X}, a2={:02X}, value={:02X}, value_used_in_expr={}, a5={:04X})",
|
||||
expr,
|
||||
dice_roll.client_id,
|
||||
dice_roll.unknown_a2,
|
||||
dice_roll.value,
|
||||
dice_roll.value_used_in_expr ? "true" : "false",
|
||||
dice_roll.unknown_a5);
|
||||
ast.print(stderr);
|
||||
}
|
||||
|
||||
// Note: This implementation is not based on the original code because the
|
||||
// original code was hard to follow - it used a look-behind approach with lots
|
||||
// of local variables instead of the look-ahead approach that this
|
||||
// implementation uses. Hopefully this implementation is easier to follow.
|
||||
vector<pair<ExpressionTokenType, int32_t>> tokens;
|
||||
while (expr) {
|
||||
ExpressionTokenType type;
|
||||
int32_t value = 0;
|
||||
expr = this->get_next_expr_token(expr, &type, &value);
|
||||
if (expr) {
|
||||
if (type == ExpressionTokenType::SPACE) {
|
||||
throw runtime_error("expression contains space token");
|
||||
}
|
||||
// Turn references into numbers, so only numbers and operators can appear
|
||||
// in the tokens vector
|
||||
if (type == ExpressionTokenType::REFERENCE) {
|
||||
if ((value == 1) || (value == 11)) {
|
||||
dice_roll.value_used_in_expr = true;
|
||||
}
|
||||
tokens.emplace_back(make_pair(ExpressionTokenType::NUMBER, ast.at(value)));
|
||||
} else {
|
||||
tokens.emplace_back(make_pair(type, value));
|
||||
// Note: This implementation is not based on the original code because the original code was hard to follow - it used
|
||||
// look-behind approach with lots of local variables instead of the look-ahead approach that this implementation
|
||||
// uses. Hopefully this implementation is easier to follow.
|
||||
auto tokens = ExprToken::parse(expr);
|
||||
for (auto& token : tokens) {
|
||||
if (token.type == ExprToken::Type::SPACE) {
|
||||
throw runtime_error("expression contains space token");
|
||||
}
|
||||
// Turn references into numbers, so only numbers and operators can appear in the tokens vector
|
||||
if (token.type == ExprToken::Type::REFERENCE) {
|
||||
if ((token.value == 1) || (token.value == 11)) {
|
||||
dice_roll.value_used_in_expr = true;
|
||||
}
|
||||
token.type = ExprToken::Type::NUMBER;
|
||||
token.value = ast.at(token.value);
|
||||
}
|
||||
}
|
||||
|
||||
// Operators are evaluated left-to-right - there are no operator precedence
|
||||
// rules
|
||||
// Operators are evaluated left-to-right - there are no operator precedence rules
|
||||
int32_t value = 0;
|
||||
log.debug_f("value={} (start)", value);
|
||||
for (size_t token_index = 0; token_index < tokens.size(); token_index++) {
|
||||
auto token_type = tokens[token_index].first;
|
||||
int32_t token_value = tokens[token_index].second;
|
||||
if ((token_type == ExpressionTokenType::SPACE) || (token_type == ExpressionTokenType::REFERENCE)) {
|
||||
const auto& token = tokens[token_index];
|
||||
if ((token.type == ExprToken::Type::SPACE) || (token.type == ExprToken::Type::REFERENCE)) {
|
||||
throw logic_error("space or reference token present in expr evaluation phase 2");
|
||||
}
|
||||
if (token_type == ExpressionTokenType::NUMBER) {
|
||||
value = token_value;
|
||||
log.debug_f("value={} (token_type=NUMBER, token_value={})", value, token_value);
|
||||
if (token.type == ExprToken::Type::NUMBER) {
|
||||
value = token.value;
|
||||
log.debug_f("value={} (token_type=NUMBER, token_value={})", value, token.value);
|
||||
} else {
|
||||
if (token_index >= tokens.size() - 1) {
|
||||
throw runtime_error("no token on right side of binary operator");
|
||||
}
|
||||
token_index++;
|
||||
auto right_token_type = tokens[token_index].first;
|
||||
auto right_value = tokens[token_index].second;
|
||||
if (right_token_type != ExpressionTokenType::NUMBER) {
|
||||
const auto& right_token = tokens[token_index];
|
||||
if (right_token.type != ExprToken::Type::NUMBER) {
|
||||
// REFERENCE was converted to NUMBER after parsing, based on the attack env stats
|
||||
throw runtime_error("non-number, non-reference token on right side of operator");
|
||||
}
|
||||
switch (token_type) {
|
||||
case ExpressionTokenType::ROUND_DIVIDE:
|
||||
value = lround(static_cast<double>(value) / right_value);
|
||||
log.debug_f("value={} (token_type=ROUND_DIVIDE, right_token_value={})", value, right_value);
|
||||
switch (token.type) {
|
||||
case ExprToken::Type::ROUND_DIVIDE:
|
||||
value = lround(static_cast<double>(value) / right_token.value);
|
||||
log.debug_f("value={} (token_type=ROUND_DIVIDE, right_token_value={})", value, right_token.value);
|
||||
break;
|
||||
case ExpressionTokenType::SUBTRACT:
|
||||
value -= right_value;
|
||||
log.debug_f("value={} (token_type=SUBTRACT, right_token_value={})", value, right_value);
|
||||
case ExprToken::Type::SUBTRACT:
|
||||
value -= right_token.value;
|
||||
log.debug_f("value={} (token_type=SUBTRACT, right_token_value={})", value, right_token.value);
|
||||
break;
|
||||
case ExpressionTokenType::ADD:
|
||||
value += right_value;
|
||||
log.debug_f("value={} (token_type=ADD, right_token_value={})", value, right_value);
|
||||
case ExprToken::Type::ADD:
|
||||
value += right_token.value;
|
||||
log.debug_f("value={} (token_type=ADD, right_token_value={})", value, right_token.value);
|
||||
break;
|
||||
case ExpressionTokenType::MULTIPLY:
|
||||
value *= right_value;
|
||||
log.debug_f("value={} (token_type=MULTIPLY, right_token_value={})", value, right_value);
|
||||
case ExprToken::Type::MULTIPLY:
|
||||
value *= right_token.value;
|
||||
log.debug_f("value={} (token_type=MULTIPLY, right_token_value={})", value, right_token.value);
|
||||
break;
|
||||
case ExpressionTokenType::FLOOR_DIVIDE:
|
||||
value = floor(value / right_value);
|
||||
log.debug_f("value={} (token_type=FLOOR_DIVIDE, right_token_value={})", value, right_value);
|
||||
case ExprToken::Type::FLOOR_DIVIDE:
|
||||
value = floor(value / right_token.value);
|
||||
log.debug_f("value={} (token_type=FLOOR_DIVIDE, right_token_value={})", value, right_token.value);
|
||||
break;
|
||||
default:
|
||||
throw logic_error("invalid binary operator");
|
||||
@@ -1835,8 +1808,7 @@ bool CardSpecial::execute_effect(
|
||||
}
|
||||
|
||||
} else if (card->action_metadata.check_flag(0x10) &&
|
||||
(cond.card_ref != card->get_card_ref()) &&
|
||||
(cond.condition_giver_card_ref != card->get_card_ref())) {
|
||||
(cond.card_ref != card->get_card_ref()) && (cond.condition_giver_card_ref != card->get_card_ref())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1916,7 +1888,9 @@ bool CardSpecial::execute_effect(
|
||||
case ConditionType::GIVE_DAMAGE:
|
||||
if ((unknown_p7 & 4) != 0) {
|
||||
int16_t current_hp = is_nte ? card->get_current_hp() : clamp<int16_t>(card->get_current_hp(), -99, 99);
|
||||
int16_t new_hp = is_nte ? (current_hp - positive_expr_value) : clamp<int16_t>(current_hp - positive_expr_value, -99, 99);
|
||||
int16_t new_hp = is_nte
|
||||
? (current_hp - positive_expr_value)
|
||||
: clamp<int16_t>(current_hp - positive_expr_value, -99, 99);
|
||||
this->send_6xB4x06_for_stat_delta(card, attacker_card_ref, 0x20, -positive_expr_value, 0, 1);
|
||||
new_hp = max<int16_t>(new_hp, 0);
|
||||
if (new_hp != current_hp) {
|
||||
@@ -2226,8 +2200,7 @@ bool CardSpecial::execute_effect(
|
||||
if (hand_size > 0) {
|
||||
uint8_t a = ps->roll_dice_with_effects(2);
|
||||
uint8_t b = ps->roll_dice_with_effects(1);
|
||||
uint16_t card_ref = ps->card_ref_for_hand_index(
|
||||
(a + b) - ((a + b) / hand_size) * hand_size);
|
||||
uint16_t card_ref = ps->card_ref_for_hand_index((a + b) - ((a + b) / hand_size) * hand_size);
|
||||
if (card_ref != 0xFFFF) {
|
||||
ps->discard_ref_from_hand(card_ref);
|
||||
}
|
||||
@@ -2264,7 +2237,8 @@ bool CardSpecial::execute_effect(
|
||||
card->action_metadata.defense_card_ref_count = 0;
|
||||
} else {
|
||||
for (size_t z = 0; z < card->action_chain.chain.attack_action_card_ref_count; z++) {
|
||||
this->apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(card->action_chain.chain.attack_action_card_refs[z]);
|
||||
this->apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(
|
||||
card->action_chain.chain.attack_action_card_refs[z]);
|
||||
}
|
||||
}
|
||||
card->action_chain.chain.attack_action_card_ref_count = 0;
|
||||
@@ -2418,7 +2392,13 @@ bool CardSpecial::execute_effect(
|
||||
auto& cond = attacker_card->action_chain.conditions[z];
|
||||
if (cond.type != ConditionType::UNKNOWN_49) {
|
||||
this->execute_effect(
|
||||
cond, attacker_card, positive_expr_value, clamped_unknown_p5, cond.type, unknown_p7, attacker_card_ref);
|
||||
cond,
|
||||
attacker_card,
|
||||
positive_expr_value,
|
||||
clamped_unknown_p5,
|
||||
cond.type,
|
||||
unknown_p7,
|
||||
attacker_card_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2428,18 +2408,14 @@ bool CardSpecial::execute_effect(
|
||||
case ConditionType::AP_GROWTH:
|
||||
if (unknown_p7 & 4) {
|
||||
this->send_6xB4x06_for_stat_delta(card, attacker_card_ref, 0xA0, positive_expr_value, 0, 1);
|
||||
card->ap = is_nte
|
||||
? (card->ap + positive_expr_value)
|
||||
: clamp<int16_t>(card->ap + positive_expr_value, -99, 99);
|
||||
card->ap = is_nte ? (card->ap + positive_expr_value) : clamp<int16_t>(card->ap + positive_expr_value, -99, 99);
|
||||
}
|
||||
return true;
|
||||
|
||||
case ConditionType::TP_GROWTH:
|
||||
if (unknown_p7 & 4) {
|
||||
this->send_6xB4x06_for_stat_delta(card, attacker_card_ref, 0x80, positive_expr_value, 0, 1);
|
||||
card->tp = is_nte
|
||||
? (card->tp + positive_expr_value)
|
||||
: clamp<int16_t>(card->tp + positive_expr_value, -99, 99);
|
||||
card->tp = is_nte ? (card->tp + positive_expr_value) : clamp<int16_t>(card->tp + positive_expr_value, -99, 99);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -2593,8 +2569,7 @@ bool CardSpecial::execute_effect(
|
||||
if (is_nte) {
|
||||
return false;
|
||||
}
|
||||
if ((unknown_p7 & 0x40) &&
|
||||
(static_cast<uint16_t>(attack_medium) == ((s->get_round_num() >> 1) & 1) + 1)) {
|
||||
if ((unknown_p7 & 0x40) && (static_cast<uint16_t>(attack_medium) == ((s->get_round_num() >> 1) & 1) + 1)) {
|
||||
card->action_metadata.attack_bonus = 0;
|
||||
}
|
||||
return true;
|
||||
@@ -2668,10 +2643,7 @@ bool CardSpecial::execute_effect(
|
||||
}
|
||||
|
||||
const Condition* CardSpecial::find_condition_with_parameters(
|
||||
shared_ptr<const Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const {
|
||||
shared_ptr<const Card> card, ConditionType cond_type, uint16_t set_card_ref, uint8_t def_effect_index) const {
|
||||
|
||||
if (this->server()->options.is_nte()) {
|
||||
// The NTE version of this function returns a boolean instead of a pointer;
|
||||
@@ -2711,18 +2683,13 @@ const Condition* CardSpecial::find_condition_with_parameters(
|
||||
}
|
||||
|
||||
Condition* CardSpecial::find_condition_with_parameters(
|
||||
shared_ptr<Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const {
|
||||
shared_ptr<Card> card, ConditionType cond_type, uint16_t set_card_ref, uint8_t def_effect_index) const {
|
||||
return const_cast<Condition*>(this->find_condition_with_parameters(
|
||||
static_cast<shared_ptr<const Card>>(card), cond_type, set_card_ref, def_effect_index));
|
||||
}
|
||||
|
||||
void CardSpecial::get_card1_loc_with_card2_opposite_direction(
|
||||
Location* out_loc,
|
||||
shared_ptr<const Card> card1,
|
||||
shared_ptr<const Card> card2) {
|
||||
Location* out_loc, shared_ptr<const Card> card1, shared_ptr<const Card> card2) {
|
||||
if (card1) {
|
||||
if (!card2 || (static_cast<uint8_t>(card2->facing_direction) & 0x80)) {
|
||||
*out_loc = card1->loc;
|
||||
@@ -2749,12 +2716,7 @@ uint16_t CardSpecial::get_card_id_with_effective_range(
|
||||
}
|
||||
|
||||
void CardSpecial::get_effective_ap_tp(
|
||||
StatSwapType type,
|
||||
int16_t* effective_ap,
|
||||
int16_t* effective_tp,
|
||||
int16_t hp,
|
||||
int16_t ap,
|
||||
int16_t tp) {
|
||||
StatSwapType type, int16_t* effective_ap, int16_t* effective_tp, int16_t hp, int16_t ap, int16_t tp) {
|
||||
switch (type) {
|
||||
case StatSwapType::NONE:
|
||||
*effective_ap = ap;
|
||||
@@ -2773,67 +2735,6 @@ void CardSpecial::get_effective_ap_tp(
|
||||
}
|
||||
}
|
||||
|
||||
const char* CardSpecial::get_next_expr_token(
|
||||
const char* expr, ExpressionTokenType* out_type, int32_t* out_value) const {
|
||||
switch (*expr) {
|
||||
case '\0':
|
||||
*out_type = ExpressionTokenType::SPACE;
|
||||
return nullptr;
|
||||
case ' ':
|
||||
*out_type = ExpressionTokenType::SPACE;
|
||||
return expr + 1;
|
||||
case '+':
|
||||
*out_type = ExpressionTokenType::ADD;
|
||||
return expr + 1;
|
||||
case '-':
|
||||
*out_type = ExpressionTokenType::SUBTRACT;
|
||||
return expr + 1;
|
||||
case '*':
|
||||
*out_type = ExpressionTokenType::MULTIPLY;
|
||||
return expr + 1;
|
||||
case '/':
|
||||
if (expr[1] == '/') {
|
||||
*out_type = ExpressionTokenType::FLOOR_DIVIDE;
|
||||
return expr + 2;
|
||||
} else {
|
||||
*out_type = ExpressionTokenType::ROUND_DIVIDE;
|
||||
return expr + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*expr >= 'a') && (*expr <= 'z')) {
|
||||
string token_buf;
|
||||
for (; (*expr >= 'a') && (*expr <= 'z'); expr++) {
|
||||
token_buf.push_back(*expr);
|
||||
}
|
||||
|
||||
*out_type = ExpressionTokenType::SPACE;
|
||||
*out_value = 0x27;
|
||||
|
||||
static const vector<const char*> tokens = {
|
||||
"f", "d", "ap", "tp", "hp", "mhp", "dm", "tdm", "tf", "ac", "php",
|
||||
"dc", "cs", "a", "kap", "ktp", "dn", "hf", "df", "ff", "ef", "bi",
|
||||
"ab", "mc", "dk", "sa", "gn", "wd", "tt", "lv", "adm", "ddm", "sat",
|
||||
"edm", "ldm", "rdm", "fdm", "ndm", "ehp"};
|
||||
for (size_t z = 0; z < tokens.size(); z++) {
|
||||
if (token_buf == tokens[z]) {
|
||||
*out_type = ExpressionTokenType::REFERENCE;
|
||||
*out_value = z;
|
||||
return expr;
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
if ((*expr >= '0') && (*expr <= '9')) {
|
||||
*out_type = ExpressionTokenType::NUMBER;
|
||||
*out_value = strtol(expr, const_cast<char**>(&expr), 10);
|
||||
return expr;
|
||||
}
|
||||
|
||||
throw runtime_error("invalid card effect expression");
|
||||
}
|
||||
|
||||
vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
@@ -2842,8 +2743,11 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
int16_t p_target_type,
|
||||
bool apply_usability_filters) const {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(std::format("get_targeted_cards_for_condition(@{:04X}, {}, @{:04X}): ", card_ref, def_effect_index, setter_card_ref));
|
||||
log.debug_f("card_ref=@{:04X}, def_effect_index={:02X}, setter_card_ref=@{:04X}, as, p_target_type={}, apply_usability_filters={}", card_ref, def_effect_index, setter_card_ref, p_target_type, apply_usability_filters ? "true" : "false");
|
||||
auto log = s->log_stack(std::format(
|
||||
"get_targeted_cards_for_condition(@{:04X}, {}, @{:04X}): ", card_ref, def_effect_index, setter_card_ref));
|
||||
log.debug_f(
|
||||
"card_ref=@{:04X}, def_effect_index={:02X}, setter_card_ref=@{:04X}, as, p_target_type={}, apply_usability_filters={}",
|
||||
card_ref, def_effect_index, setter_card_ref, p_target_type, apply_usability_filters ? "true" : "false");
|
||||
|
||||
vector<shared_ptr<const Card>> ret;
|
||||
|
||||
@@ -2871,9 +2775,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
log.debug_f("card1_loc={}", card1_loc_str);
|
||||
}
|
||||
|
||||
AttackMedium attack_medium = card2
|
||||
? card2->action_chain.chain.attack_medium
|
||||
: AttackMedium::UNKNOWN;
|
||||
AttackMedium attack_medium = card2 ? card2->action_chain.chain.attack_medium : AttackMedium::UNKNOWN;
|
||||
log.debug_f("attack_medium={}", phosg::name_for_enum(attack_medium));
|
||||
|
||||
auto add_card_refs = [&](const vector<uint16_t>& result_card_refs) -> void {
|
||||
@@ -3053,9 +2955,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, card1->get_team_id());
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = s->card_for_set_card_ref(result_card_ref);
|
||||
if (result_card &&
|
||||
(result_card->get_definition()->def.type != CardType::ITEM) &&
|
||||
(card1 != result_card)) {
|
||||
if (result_card && (result_card->get_definition()->def.type != CardType::ITEM) && (card1 != result_card)) {
|
||||
ret.emplace_back(result_card);
|
||||
}
|
||||
}
|
||||
@@ -3140,15 +3040,11 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
if (as.original_attacker_card_ref == 0xFFFF) {
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto result_card = s->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (result_card &&
|
||||
result_card->get_definition() &&
|
||||
!result_card->get_definition()->def.is_sc()) {
|
||||
if (result_card && result_card->get_definition() && !result_card->get_definition()->def.is_sc()) {
|
||||
ret.emplace_back(result_card);
|
||||
}
|
||||
}
|
||||
} else if (card2 &&
|
||||
card2->get_definition() &&
|
||||
!card2->get_definition()->def.is_sc()) {
|
||||
} else if (card2 && card2->get_definition() && !card2->get_definition()->def.is_sc()) {
|
||||
ret.emplace_back(card2);
|
||||
}
|
||||
break;
|
||||
@@ -3250,8 +3146,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
case 0x28: { // p40
|
||||
auto log3940 = log.sub("(p39/p40) ");
|
||||
ret = this->find_all_set_cards_with_cost_in_range(
|
||||
(p_target_type == 0x27) ? 4 : 0,
|
||||
(p_target_type == 0x27) ? 99 : 3);
|
||||
(p_target_type == 0x27) ? 4 : 0, (p_target_type == 0x27) ? 99 : 3);
|
||||
if (log3940.should_log(phosg::LogLevel::L_DEBUG)) {
|
||||
for (const auto& card : ret) {
|
||||
log3940.debug_f("found target @{:04X} #{:04X}", card->get_card_ref(), card->get_card_id());
|
||||
@@ -3290,8 +3185,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
if (!s->options.is_nte()) {
|
||||
for (size_t z = 0; z < 8; z++) {
|
||||
auto result_card = ps->get_set_card(z);
|
||||
if (result_card && (card1 != result_card) &&
|
||||
(result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
if (result_card && (card1 != result_card) && (result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
bool already_in_ret = false;
|
||||
for (auto c : ret) {
|
||||
if (c == result_card) {
|
||||
@@ -3473,8 +3367,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto result_card = ps->get_set_card(set_index);
|
||||
if (result_card && (card1 != result_card) &&
|
||||
(result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
if (result_card && (card1 != result_card) && (result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
bool should_add = true;
|
||||
for (auto c : ret) {
|
||||
if (c == result_card) {
|
||||
@@ -3520,9 +3413,7 @@ vector<shared_ptr<Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
}
|
||||
|
||||
bool CardSpecial::is_card_targeted_by_condition(
|
||||
const Condition& cond,
|
||||
const ActionState& as,
|
||||
shared_ptr<const Card> card) const {
|
||||
const Condition& cond, const ActionState& as, shared_ptr<const Card> card) const {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack("is_card_targeted_by_condition: ");
|
||||
|
||||
@@ -3609,10 +3500,7 @@ bool CardSpecial::card_ref_has_ability_trap(const Condition& cond) const {
|
||||
}
|
||||
|
||||
void CardSpecial::send_6xB4x06_for_exp_change(
|
||||
shared_ptr<const Card> card,
|
||||
uint16_t attacker_card_ref,
|
||||
uint8_t dice_roll_value,
|
||||
bool unknown_p5) const {
|
||||
shared_ptr<const Card> card, uint16_t attacker_card_ref, uint8_t dice_roll_value, bool unknown_p5) const {
|
||||
G_ApplyConditionEffect_Ep3_6xB4x06 cmd;
|
||||
cmd.effect.flags = 0x02;
|
||||
cmd.effect.attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(attacker_card_ref, 10);
|
||||
@@ -3636,8 +3524,7 @@ void CardSpecial::send_6xB4x06_for_card_destroyed(
|
||||
auto s = this->server();
|
||||
G_ApplyConditionEffect_Ep3_6xB4x06 cmd;
|
||||
cmd.effect.flags = 0x04;
|
||||
cmd.effect.attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(
|
||||
attacker_card_ref, 0x13);
|
||||
cmd.effect.attacker_card_ref = this->send_6xB4x06_if_card_ref_invalid(attacker_card_ref, 0x13);
|
||||
cmd.effect.target_card_ref = destroyed_card->get_card_ref();
|
||||
cmd.effect.value = 0;
|
||||
cmd.effect.operation = s->options.is_nte() ? 0x78 : 0x7E;
|
||||
@@ -3776,9 +3663,7 @@ bool CardSpecial::should_return_card_ref_to_hand_on_destruction(
|
||||
continue;
|
||||
}
|
||||
auto cond_type = card->action_chain.conditions[cond_index].type;
|
||||
if ((cond_type == ConditionType::RETURN) &&
|
||||
!(card->card_flags & 1) &&
|
||||
(card->get_card_ref() == card_ref)) {
|
||||
if ((cond_type == ConditionType::RETURN) && !(card->card_flags & 1) && (card->get_card_ref() == card_ref)) {
|
||||
return true;
|
||||
} else if ((cond_type == ConditionType::REBORN) &&
|
||||
!(card->card_flags & 3) &&
|
||||
@@ -3798,9 +3683,7 @@ bool CardSpecial::should_return_card_ref_to_hand_on_destruction(
|
||||
}
|
||||
|
||||
size_t CardSpecial::sum_last_attack_damage(
|
||||
vector<shared_ptr<const Card>>* out_cards,
|
||||
int32_t* out_damage_sum,
|
||||
size_t* out_damage_count) const {
|
||||
vector<shared_ptr<const Card>>* out_cards, int32_t* out_damage_sum, size_t* out_damage_count) const {
|
||||
auto log = this->server()->log_stack("sum_last_attack_damage: ");
|
||||
|
||||
size_t damage_count = 0;
|
||||
@@ -3924,9 +3807,7 @@ void CardSpecial::apply_effects_after_card_move(shared_ptr<Card> card) {
|
||||
}
|
||||
|
||||
void CardSpecial::check_for_defense_interference(
|
||||
shared_ptr<const Card> attacker_card,
|
||||
shared_ptr<Card> target_card,
|
||||
int16_t* inout_unknown_p4) {
|
||||
shared_ptr<const Card> attacker_card, shared_ptr<Card> target_card, int16_t* inout_unknown_p4) {
|
||||
auto s = this->server();
|
||||
|
||||
// Note: This check is not part of the original implementation.
|
||||
@@ -3941,8 +3822,7 @@ void CardSpecial::check_for_defense_interference(
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t ally_sc_card_ref = s->ruler_server->get_ally_sc_card_ref(
|
||||
target_card->get_card_ref());
|
||||
uint16_t ally_sc_card_ref = s->ruler_server->get_ally_sc_card_ref(target_card->get_card_ref());
|
||||
if (ally_sc_card_ref == 0xFFFF) {
|
||||
return;
|
||||
}
|
||||
@@ -3963,7 +3843,8 @@ void CardSpecial::check_for_defense_interference(
|
||||
}
|
||||
|
||||
auto ally_hes = s->ruler_server->get_hand_and_equip_state_for_client_id(target_ally_client_id);
|
||||
if (!ally_hes || (!(s->options.behavior_flags & BehaviorFlag::ALLOW_NON_COM_INTERFERENCE) && !ally_hes->is_cpu_player)) {
|
||||
if (!ally_hes ||
|
||||
(!(s->options.behavior_flags & BehaviorFlag::ALLOW_NON_COM_INTERFERENCE) && !ally_hes->is_cpu_player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3984,8 +3865,7 @@ void CardSpecial::check_for_defense_interference(
|
||||
if (target_ps->unknown_a17 >= 1) {
|
||||
return;
|
||||
}
|
||||
auto entry = get_interference_probability_entry(
|
||||
target_card_id, ally_sc_card_id, false);
|
||||
auto entry = get_interference_probability_entry(target_card_id, ally_sc_card_id, false);
|
||||
if (!entry || (s->get_random(99) >= entry->defense_probability)) {
|
||||
return;
|
||||
}
|
||||
@@ -4019,7 +3899,12 @@ void CardSpecial::evaluate_and_apply_effects(
|
||||
{
|
||||
string as_str = as.str(s);
|
||||
log.debug_f("when={}, set_card_ref=@{:04X}, as={}, sc_card_ref=@{:04X}, apply_defense_condition_to_all_cards={}, apply_defense_condition_to_card_ref=@{:04X}",
|
||||
phosg::name_for_enum(when), set_card_ref, as_str, sc_card_ref, apply_defense_condition_to_all_cards ? "true" : "false", apply_defense_condition_to_card_ref);
|
||||
phosg::name_for_enum(when),
|
||||
set_card_ref,
|
||||
as_str,
|
||||
sc_card_ref,
|
||||
apply_defense_condition_to_all_cards ? "true" : "false",
|
||||
apply_defense_condition_to_card_ref);
|
||||
}
|
||||
|
||||
if (!is_nte) {
|
||||
@@ -4076,13 +3961,15 @@ void CardSpecial::evaluate_and_apply_effects(
|
||||
dice_roll.unknown_a2 = 3;
|
||||
dice_roll.value_used_in_expr = false;
|
||||
|
||||
log.debug_f("inputs: dice_roll={:02X}, random_percent={}, unknown_v1={}", dice_roll.value, random_percent, unknown_v1 ? "true" : "false");
|
||||
log.debug_f("inputs: dice_roll={:02X}, random_percent={}, unknown_v1={}",
|
||||
dice_roll.value, random_percent, unknown_v1 ? "true" : "false");
|
||||
|
||||
for (size_t def_effect_index = 0; (def_effect_index < 3) && !unknown_v1 && (ce->def.effects[def_effect_index].type != ConditionType::NONE); def_effect_index++) {
|
||||
for (size_t def_effect_index = 0;
|
||||
(def_effect_index < 3) && !unknown_v1 && (ce->def.effects[def_effect_index].type != ConditionType::NONE);
|
||||
def_effect_index++) {
|
||||
auto effect_log = log.sub(std::format("(effect:{}) ", def_effect_index));
|
||||
const auto& card_effect = ce->def.effects[def_effect_index];
|
||||
string card_effect_str = card_effect.str();
|
||||
effect_log.debug_f("effect: {}", card_effect_str);
|
||||
effect_log.debug_f("effect: {}", card_effect.str());
|
||||
if (card_effect.when != when) {
|
||||
effect_log.debug_f("does not apply (effect.when={}, when={})", phosg::name_for_enum(card_effect.when), phosg::name_for_enum(when));
|
||||
continue;
|
||||
@@ -4199,9 +4086,16 @@ void CardSpecial::evaluate_and_apply_effects(
|
||||
target_card->action_chain.conditions[applied_cond_index].flags |= 1;
|
||||
}
|
||||
|
||||
if (apply_defense_condition_to_all_cards || (apply_defense_condition_to_card_ref == targeted_cards[z]->get_card_ref())) {
|
||||
if (apply_defense_condition_to_all_cards ||
|
||||
(apply_defense_condition_to_card_ref == targeted_cards[z]->get_card_ref())) {
|
||||
this->apply_defense_condition(
|
||||
when, &target_card->action_chain.conditions[applied_cond_index], applied_cond_index, as, target_card, 4, 1);
|
||||
when,
|
||||
&target_card->action_chain.conditions[applied_cond_index],
|
||||
applied_cond_index,
|
||||
as,
|
||||
target_card,
|
||||
4,
|
||||
1);
|
||||
target_log.debug_f("applied defense condition");
|
||||
}
|
||||
}
|
||||
@@ -4472,8 +4366,7 @@ const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
const auto& entry = entries[z];
|
||||
uint16_t current_column_card_id = entry.card_id;
|
||||
if ((entry.attack_probability != 0xFF) || (entry.defense_probability != 0xFF)) {
|
||||
if ((row_card_id == current_row_card_id) &&
|
||||
(column_card_id == current_column_card_id)) {
|
||||
if ((row_card_id == current_row_card_id) && (column_card_id == current_column_card_id)) {
|
||||
uint8_t v = is_attack ? entry.attack_probability : entry.defense_probability;
|
||||
if (current_max <= v) {
|
||||
ret_entry = &entry;
|
||||
@@ -4488,11 +4381,9 @@ const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
return ret_entry;
|
||||
}
|
||||
|
||||
void CardSpecial::on_card_destroyed(
|
||||
shared_ptr<Card> attacker_card, shared_ptr<Card> destroyed_card) {
|
||||
void CardSpecial::on_card_destroyed(shared_ptr<Card> attacker_card, shared_ptr<Card> destroyed_card) {
|
||||
ActionState attack_as = this->create_attack_state_from_card_action_chain(attacker_card);
|
||||
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(
|
||||
attacker_card, destroyed_card);
|
||||
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(attacker_card, destroyed_card);
|
||||
|
||||
uint16_t destroyed_card_ref = destroyed_card->get_card_ref();
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_DESTROYED, destroyed_card_ref, defense_as, 0xFFFF);
|
||||
@@ -4513,8 +4404,7 @@ void CardSpecial::on_card_destroyed(
|
||||
this->send_6xB4x06_for_card_destroyed(destroyed_card, attack_as.attacker_card_ref);
|
||||
}
|
||||
|
||||
vector<shared_ptr<const Card>> CardSpecial::find_cards_in_hp_range(
|
||||
int16_t min, int16_t max) const {
|
||||
vector<shared_ptr<const Card>> CardSpecial::find_cards_in_hp_range(int16_t min, int16_t max) const {
|
||||
vector<shared_ptr<const Card>> ret;
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->server()->get_player_state(client_id);
|
||||
@@ -4786,8 +4676,7 @@ vector<shared_ptr<const Card>> CardSpecial::filter_cards_by_range(
|
||||
void CardSpecial::apply_effects_after_attack_target_resolution(const ActionState& as) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack("apply_effects_after_attack_target_resolution: ");
|
||||
string as_str = as.str(s);
|
||||
log.debug_f("as={}", as_str);
|
||||
log.debug_f("as={}", as.str(s));
|
||||
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.action_card_refs[z], 0x1E);
|
||||
@@ -4878,7 +4767,12 @@ void CardSpecial::dice_phase_before_for_card(shared_ptr<Card> card) {
|
||||
template <EffectWhen When1, EffectWhen When2>
|
||||
void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(std::format("apply_effects_on_phase_change_t<{}, {}>(@{:04X} #{:04X}): ", phosg::name_for_enum(When1), phosg::name_for_enum(When2), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
auto log = s->log_stack(std::format(
|
||||
"apply_effects_on_phase_change_t<{}, {}>(@{:04X} #{:04X}): ",
|
||||
phosg::name_for_enum(When1),
|
||||
phosg::name_for_enum(When2),
|
||||
unknown_p2->get_card_ref(),
|
||||
unknown_p2->get_card_id()));
|
||||
bool is_nte = s->options.is_nte();
|
||||
|
||||
ActionState as;
|
||||
@@ -4904,8 +4798,7 @@ void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, c
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto card = s->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (card) {
|
||||
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(
|
||||
unknown_p2, card);
|
||||
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
|
||||
this->evaluate_and_apply_effects(When2, as.target_card_refs[z], target_as, unknown_p2->get_card_ref());
|
||||
for (size_t w = 0; (w < 8) && (target_as.action_card_refs[w] != 0xFFFF); w++) {
|
||||
this->evaluate_and_apply_effects(When1, target_as.action_card_refs[w], target_as, card->get_card_ref());
|
||||
@@ -4925,11 +4818,13 @@ void CardSpecial::action_phase_before_for_card(shared_ptr<Card> unknown_p2) {
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024945C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
this->apply_effects_on_phase_change_t<EffectWhen::UNKNOWN_0A, EffectWhen::UNKNOWN_0A>(unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as);
|
||||
this->apply_effects_on_phase_change_t<EffectWhen::UNKNOWN_0A, EffectWhen::UNKNOWN_0A>(
|
||||
unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as);
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
auto log = this->server()->log_stack(std::format("unknown_8024966C(@{:04X} #{:04X}): ", unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
auto log = this->server()->log_stack(std::format("unknown_8024966C(@{:04X} #{:04X}): ",
|
||||
unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
|
||||
ActionState as;
|
||||
if (!existing_as) {
|
||||
@@ -4966,16 +4861,20 @@ void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionStat
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
EffectWhen::ATTACK_STAT_OVERRIDES, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
card = this->server()->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (card) {
|
||||
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
EffectWhen::ATTACK_STAT_OVERRIDES, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4987,7 +4886,8 @@ shared_ptr<Card> CardSpecial::sc_card_for_card(shared_ptr<Card> unknown_p2) {
|
||||
|
||||
void CardSpecial::unknown_8024A9D8(const ActionState& pa, uint16_t action_card_ref) {
|
||||
for (size_t z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
if (this->server()->options.is_nte() || (action_card_ref == 0xFFFF) || (action_card_ref == pa.action_card_refs[z])) {
|
||||
if (this->server()->options.is_nte() ||
|
||||
(action_card_ref == 0xFFFF) || (action_card_ref == pa.action_card_refs[z])) {
|
||||
if (pa.original_attacker_card_ref == 0xFFFF) {
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_29, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_2A, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
@@ -5009,8 +4909,7 @@ void CardSpecial::check_for_attack_interference(shared_ptr<Card> unknown_p2) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t ally_sc_card_ref = this->server()->ruler_server->get_ally_sc_card_ref(
|
||||
unknown_p2->get_card_ref());
|
||||
uint16_t ally_sc_card_ref = this->server()->ruler_server->get_ally_sc_card_ref(unknown_p2->get_card_ref());
|
||||
if (ally_sc_card_ref == 0xFFFF) {
|
||||
return;
|
||||
}
|
||||
@@ -5081,7 +4980,12 @@ template <
|
||||
void CardSpecial::apply_effects_before_or_after_attack(shared_ptr<Card> unknown_p2) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(std::format("apply_effects_before_or_after_attack<{}, {}, {}, {}>(@{:04X} #{:04X}): ",
|
||||
phosg::name_for_enum(WhenAllCards), phosg::name_for_enum(WhenAttackerAndActionCards), phosg::name_for_enum(WhenAttackerOrHunterSCCard), phosg::name_for_enum(WhenTargetsAndActionCards), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
phosg::name_for_enum(WhenAllCards),
|
||||
phosg::name_for_enum(WhenAttackerAndActionCards),
|
||||
phosg::name_for_enum(WhenAttackerOrHunterSCCard),
|
||||
phosg::name_for_enum(WhenTargetsAndActionCards),
|
||||
unknown_p2->get_card_ref(),
|
||||
unknown_p2->get_card_id()));
|
||||
|
||||
ActionState as = this->create_attack_state_from_card_action_chain(unknown_p2);
|
||||
|
||||
@@ -5119,17 +5023,21 @@ void CardSpecial::apply_effects_before_or_after_attack(shared_ptr<Card> unknown_
|
||||
}
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(WhenAllCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenAttackerAndActionCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
WhenAttackerAndActionCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
}
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (set_card) {
|
||||
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card);
|
||||
this->evaluate_and_apply_effects(WhenAllCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenTargetsAndActionCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
WhenTargetsAndActionCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
for (size_t z = 0; (z < 8) && (target_as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(WhenAllCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenTargetsAndActionCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
WhenAllCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(
|
||||
WhenTargetsAndActionCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5182,16 +5090,14 @@ bool CardSpecial::client_has_atk_dice_boost_condition(uint8_t client_id) {
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024A6DC(shared_ptr<Card> unknown_p2, shared_ptr<Card> unknown_p3) {
|
||||
ActionState as = this->create_defense_state_for_card_pair_action_chains(
|
||||
unknown_p2, unknown_p3);
|
||||
ActionState as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, unknown_p3);
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_SET, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_15, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
}
|
||||
}
|
||||
|
||||
vector<shared_ptr<const Card>> CardSpecial::find_all_sc_cards_of_class(
|
||||
CardClass card_class) const {
|
||||
vector<shared_ptr<const Card>> CardSpecial::find_all_sc_cards_of_class(CardClass card_class) const {
|
||||
vector<shared_ptr<const Card>> ret;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ps = this->server()->get_player_state(z);
|
||||
|
||||
+34
-94
@@ -17,23 +17,10 @@ struct InterferenceProbabilityEntry {
|
||||
};
|
||||
|
||||
const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
uint16_t row_card_id,
|
||||
uint16_t column_card_id,
|
||||
bool is_attack);
|
||||
uint16_t row_card_id, uint16_t column_card_id, bool is_attack);
|
||||
|
||||
class CardSpecial {
|
||||
public:
|
||||
enum class ExpressionTokenType {
|
||||
SPACE = 0, // Also used for end of string (get_next_expr_token returns null)
|
||||
REFERENCE = 1, // Reference to a value from the env stats (e.g. hp)
|
||||
NUMBER = 2, // Constant value (e.g. 2)
|
||||
SUBTRACT = 3, // "-" in input string
|
||||
ADD = 4, // "+" in input string
|
||||
ROUND_DIVIDE = 5, // "/" in input string
|
||||
FLOOR_DIVIDE = 6, // "//" in input string
|
||||
MULTIPLY = 7, // "*" in input string
|
||||
};
|
||||
|
||||
struct DiceRoll {
|
||||
uint8_t client_id;
|
||||
uint8_t unknown_a2;
|
||||
@@ -77,9 +64,8 @@ public:
|
||||
/* 70 */ uint32_t effective_ap_if_not_tech2; // "tt" in expr
|
||||
/* 74 */ uint32_t team_dice_bonus; // "lv" in expr
|
||||
/* 78 */ uint32_t sc_effective_ap; // "adm" in expr
|
||||
// The following fields do not exist in Trial Edition. Because this struct
|
||||
// is never sent to the client, we use the full struct even when playing
|
||||
// Trial Edition, just for simplicity.
|
||||
// The following fields do not exist in Trial Edition. Because this struct is never sent to the client, we use the
|
||||
// full struct even when playing Trial Edition, just for simplicity.
|
||||
/* 7C */ uint32_t attack_bonus; // "ddm" in expr
|
||||
/* 80 */ uint32_t num_sword_type_items_on_team; // "sat" in expr
|
||||
/* 84 */ uint32_t target_attack_bonus; // "edm" in expr
|
||||
@@ -126,26 +112,14 @@ public:
|
||||
uint32_t flags,
|
||||
bool unknown_p8);
|
||||
bool apply_defense_conditions(
|
||||
const ActionState& as,
|
||||
EffectWhen when,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags);
|
||||
bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(
|
||||
uint16_t card_ref);
|
||||
bool apply_stat_deltas_to_card_from_condition_and_clear_cond(
|
||||
Condition& cond, std::shared_ptr<Card> card);
|
||||
bool apply_stats_deltas_to_card_from_all_conditions_with_card_ref(
|
||||
uint16_t card_ref, std::shared_ptr<Card> card);
|
||||
const ActionState& as, EffectWhen when, std::shared_ptr<Card> defender_card, uint32_t flags);
|
||||
bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(uint16_t card_ref);
|
||||
bool apply_stat_deltas_to_card_from_condition_and_clear_cond(Condition& cond, std::shared_ptr<Card> card);
|
||||
bool apply_stats_deltas_to_card_from_all_conditions_with_card_ref(uint16_t card_ref, std::shared_ptr<Card> card);
|
||||
bool card_has_condition_with_ref(
|
||||
std::shared_ptr<const Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint16_t match_card_ref) const;
|
||||
std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref, uint16_t match_card_ref) const;
|
||||
bool card_is_destroyed(std::shared_ptr<const Card> card) const;
|
||||
void compute_attack_ap(
|
||||
std::shared_ptr<const Card> target_card,
|
||||
int16_t* out_value,
|
||||
uint16_t attacker_card_ref);
|
||||
void compute_attack_ap(std::shared_ptr<const Card> target_card, int16_t* out_value, uint16_t attacker_card_ref);
|
||||
AttackEnvStats compute_attack_env_stats(
|
||||
const ActionState& pa,
|
||||
std::shared_ptr<const Card> card,
|
||||
@@ -166,21 +140,16 @@ public:
|
||||
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
|
||||
void compute_team_dice_bonus(uint8_t team_id);
|
||||
bool condition_applies_on_sc_or_item_attack(const Condition& cond) const;
|
||||
size_t count_action_cards_with_condition_for_all_current_attacks(
|
||||
ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_action_cards_with_condition_for_all_current_attacks(ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_action_cards_with_condition_for_current_attack(
|
||||
std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_cards_with_card_id_except_card_ref(
|
||||
uint16_t card_id, uint16_t card_ref) const;
|
||||
size_t count_cards_with_card_id_except_card_ref(uint16_t card_id, uint16_t card_ref) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_all_set_cards_by_team_and_class(
|
||||
CardClass card_class, uint8_t team_id, bool exclude_destroyed_cards) const;
|
||||
ActionState create_attack_state_from_card_action_chain(
|
||||
std::shared_ptr<const Card> attacker_card) const;
|
||||
ActionState create_attack_state_from_card_action_chain(std::shared_ptr<const Card> attacker_card) const;
|
||||
ActionState create_defense_state_for_card_pair_action_chains(
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<const Card> defender_card) const;
|
||||
void destroy_card_if_hp_zero(
|
||||
std::shared_ptr<Card> card, uint16_t attacker_card_ref);
|
||||
std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> defender_card) const;
|
||||
void destroy_card_if_hp_zero(std::shared_ptr<Card> card, uint16_t attacker_card_ref);
|
||||
bool evaluate_effect_arg2_condition(
|
||||
const ActionState& as,
|
||||
std::shared_ptr<const Card> card,
|
||||
@@ -190,10 +159,7 @@ public:
|
||||
uint16_t sc_card_ref,
|
||||
uint8_t random_percent,
|
||||
EffectWhen when) const;
|
||||
int32_t evaluate_effect_expr(
|
||||
const AttackEnvStats& ast,
|
||||
const char* expr,
|
||||
DiceRoll& dice_roll) const;
|
||||
int32_t evaluate_effect_expr(const AttackEnvStats& ast, const char* expr, DiceRoll& dice_roll) const;
|
||||
bool execute_effect(
|
||||
Condition& cond,
|
||||
std::shared_ptr<Card> card,
|
||||
@@ -208,25 +174,13 @@ public:
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const;
|
||||
Condition* find_condition_with_parameters(
|
||||
std::shared_ptr<Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const;
|
||||
std::shared_ptr<Card> card, ConditionType cond_type, uint16_t set_card_ref, uint8_t def_effect_index) const;
|
||||
static void get_card1_loc_with_card2_opposite_direction(
|
||||
Location* out_loc,
|
||||
std::shared_ptr<const Card> card1,
|
||||
std::shared_ptr<const Card> card2);
|
||||
Location* out_loc, std::shared_ptr<const Card> card1, std::shared_ptr<const Card> card2);
|
||||
uint16_t get_card_id_with_effective_range(
|
||||
std::shared_ptr<const Card> card1, uint16_t default_card_id, std::shared_ptr<const Card> card2) const;
|
||||
static void get_effective_ap_tp(
|
||||
StatSwapType type,
|
||||
int16_t* effective_ap,
|
||||
int16_t* effective_tp,
|
||||
int16_t hp,
|
||||
int16_t ap,
|
||||
int16_t tp);
|
||||
const char* get_next_expr_token(
|
||||
const char* expr, ExpressionTokenType* out_type, int32_t* out_value) const;
|
||||
StatSwapType type, int16_t* effective_ap, int16_t* effective_tp, int16_t hp, int16_t ap, int16_t tp);
|
||||
std::vector<std::shared_ptr<const Card>> get_targeted_cards_for_condition(
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
@@ -244,18 +198,12 @@ public:
|
||||
bool is_card_targeted_by_condition(
|
||||
const Condition& cond, const ActionState& as, std::shared_ptr<const Card> card) const;
|
||||
void on_card_set(std::shared_ptr<PlayerState> ps, uint16_t card_ref);
|
||||
const CardDefinition::Effect* original_definition_for_condition(
|
||||
const Condition& cond) const;
|
||||
const CardDefinition::Effect* original_definition_for_condition(const Condition& cond) const;
|
||||
bool card_ref_has_ability_trap(const Condition& eff) const;
|
||||
void send_6xB4x06_for_exp_change(
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t attacker_card_ref,
|
||||
uint8_t dice_roll_value,
|
||||
bool unknown_p5) const;
|
||||
void send_6xB4x06_for_card_destroyed(
|
||||
std::shared_ptr<const Card> destroyed_card, uint16_t attacker_card_ref) const;
|
||||
uint16_t send_6xB4x06_if_card_ref_invalid(
|
||||
uint16_t card_ref, int16_t value) const;
|
||||
std::shared_ptr<const Card> card, uint16_t attacker_card_ref, uint8_t dice_roll_value, bool unknown_p5) const;
|
||||
void send_6xB4x06_for_card_destroyed(std::shared_ptr<const Card> destroyed_card, uint16_t attacker_card_ref) const;
|
||||
uint16_t send_6xB4x06_if_card_ref_invalid(uint16_t card_ref, int16_t value) const;
|
||||
void send_6xB4x06_for_stat_delta(
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t attacker_card_ref,
|
||||
@@ -268,19 +216,14 @@ public:
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t target_card_ref,
|
||||
uint16_t sc_card_ref) const;
|
||||
bool should_return_card_ref_to_hand_on_destruction(
|
||||
uint16_t card_ref) const;
|
||||
bool should_return_card_ref_to_hand_on_destruction(uint16_t card_ref) const;
|
||||
size_t sum_last_attack_damage(
|
||||
std::vector<std::shared_ptr<const Card>>* out_cards,
|
||||
int32_t* out_damage_sum,
|
||||
size_t* out_damage_count) const;
|
||||
std::vector<std::shared_ptr<const Card>>* out_cards, int32_t* out_damage_sum, size_t* out_damage_count) const;
|
||||
void update_condition_orders(std::shared_ptr<Card> card);
|
||||
int16_t max_all_attack_bonuses(size_t* out_count) const;
|
||||
void apply_effects_after_card_move(std::shared_ptr<Card> card);
|
||||
void check_for_defense_interference(
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<Card> target_card,
|
||||
int16_t* inout_unknown_p4);
|
||||
std::shared_ptr<const Card> attacker_card, std::shared_ptr<Card> target_card, int16_t* inout_unknown_p4);
|
||||
void evaluate_and_apply_effects(
|
||||
EffectWhen when,
|
||||
uint16_t set_card_ref,
|
||||
@@ -294,20 +237,19 @@ public:
|
||||
ConditionType exclude_cond = ConditionType::NONE,
|
||||
AssistEffect include_eff = AssistEffect::NONE,
|
||||
AssistEffect exclude_eff = AssistEffect::NONE) const;
|
||||
void clear_invalid_conditions_on_card(
|
||||
std::shared_ptr<Card> card, const ActionState& as);
|
||||
void on_card_destroyed(
|
||||
std::shared_ptr<Card> attacker_card, std::shared_ptr<Card> destroyed_card);
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_in_hp_range(
|
||||
int16_t min, int16_t max) const;
|
||||
void clear_invalid_conditions_on_card(std::shared_ptr<Card> card, const ActionState& as);
|
||||
void on_card_destroyed(std::shared_ptr<Card> attacker_card, std::shared_ptr<Card> destroyed_card);
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_in_hp_range(int16_t min, int16_t max) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_cards_by_aerial_attribute(bool is_aerial) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_damaged_by_at_least(int16_t damage) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_set_cards_on_client_team(uint8_t client_id) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_cards_on_same_or_other_team(uint8_t client_id, bool same_team) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_cards_on_same_or_other_team(
|
||||
uint8_t client_id, bool same_team) const;
|
||||
std::shared_ptr<const Card> sc_card_for_client_id(uint8_t client_id) const;
|
||||
std::shared_ptr<const Card> get_attacker_card(const ActionState& as) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_attacker_card_and_sc_if_item(const ActionState& as) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_set_cards_with_cost_in_range(uint8_t min_cost, uint8_t max_cost) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_set_cards_with_cost_in_range(
|
||||
uint8_t min_cost, uint8_t max_cost) const;
|
||||
std::vector<std::shared_ptr<const Card>> filter_cards_by_range(
|
||||
const std::vector<std::shared_ptr<const Card>>& cards,
|
||||
std::shared_ptr<const Card> card1,
|
||||
@@ -334,10 +276,8 @@ public:
|
||||
void apply_effects_before_attack(std::shared_ptr<Card> card);
|
||||
void apply_effects_after_attack(std::shared_ptr<Card> card);
|
||||
bool client_has_atk_dice_boost_condition(uint8_t client_id);
|
||||
void unknown_8024A6DC(
|
||||
std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3);
|
||||
std::vector<std::shared_ptr<const Card>> find_all_sc_cards_of_class(
|
||||
CardClass card_class) const;
|
||||
void unknown_8024A6DC(std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3);
|
||||
std::vector<std::shared_ptr<const Card>> find_all_sc_cards_of_class(CardClass card_class) const;
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
|
||||
+523
-249
File diff suppressed because it is too large
Load Diff
+492
-507
File diff suppressed because it is too large
Load Diff
+15
-22
@@ -92,8 +92,7 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
|
||||
|
||||
auto& entry = this->entries[index];
|
||||
if (entry.state == CardState::DISCARDED) {
|
||||
// If the card is discarded, then it should be before the draw index, and we
|
||||
// can just change its state.
|
||||
// If the card is discarded, then it should be before the draw index, and we can just change its state.
|
||||
entry.state = CardState::IN_HAND;
|
||||
return true;
|
||||
}
|
||||
@@ -102,9 +101,8 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the card is still drawable, we need to move it so it's just in front of
|
||||
// the draw index, then immediately draw it. Ep3 NTE does not handle this
|
||||
// case, but we do even when playing NTE.
|
||||
// If the card is still drawable, we need to move it so it's just in front of the draw index, then immediately draw
|
||||
// it. Ep3 NTE does not handle this case, but we do even when playing NTE.
|
||||
size_t ref_index;
|
||||
for (ref_index = 0; ref_index < this->card_refs.size(); ref_index++) {
|
||||
if (this->card_refs[ref_index] == card_ref) {
|
||||
@@ -131,13 +129,8 @@ uint16_t DeckState::card_id_for_card_ref(uint16_t card_ref) const {
|
||||
if (card_ref == 0xFFFF) {
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (index < this->entries.size()) {
|
||||
return this->entries[index].card_id;
|
||||
} else {
|
||||
return 0xFFFF;
|
||||
}
|
||||
return (index < this->entries.size()) ? this->entries[index].card_id : 0xFFFF;
|
||||
}
|
||||
|
||||
uint16_t DeckState::sc_card_id() const {
|
||||
@@ -167,8 +160,7 @@ void DeckState::restart() {
|
||||
}
|
||||
}
|
||||
|
||||
// For any cards that are still in hand or still in play, move their refs to
|
||||
// the already-drawn part of the deck
|
||||
// For any cards that are still in hand or still in play, move their refs to the already-drawn part of the deck
|
||||
this->draw_index = 0;
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].state != CardState::DRAWABLE) {
|
||||
@@ -196,8 +188,7 @@ void DeckState::redraw_initial_hand(bool is_nte) {
|
||||
this->draw_index = 1;
|
||||
|
||||
if (is_nte || this->shuffle_enabled) {
|
||||
// Get the next 5 cards from the deck, and put the previous 5 cards after
|
||||
// them (so they will be shuffled back in).
|
||||
// Get the next 5 cards from the deck, and put the previous 5 cards after them (so they will be shuffled back in).
|
||||
for (uint8_t z = 0; z < 5; z++) {
|
||||
uint8_t index = z + this->draw_index;
|
||||
uint16_t temp_ref = this->card_refs[index];
|
||||
@@ -274,11 +265,9 @@ void DeckState::shuffle() {
|
||||
|
||||
size_t max = this->num_drawable_cards();
|
||||
for (size_t z = 0; z < this->card_refs.size(); z++) {
|
||||
// Note: This is the way Sega originally implemented shuffling - they just
|
||||
// do N swaps on the entire array. A more uniform way to do it would be to
|
||||
// instead swap each item with another random item (possibly itself) that
|
||||
// doesn't appear earlier than it in the array, but this is not what Sega
|
||||
// did.
|
||||
// Note: This is the way Sega originally implemented shuffling - they just do N swaps on the entire array. A more
|
||||
// uniform way to do it would be to instead swap each item with another random item (possibly itself) that
|
||||
// doesn't appear earlier than it in the array, but this is not what Sega did.
|
||||
uint8_t index1 = this->draw_index + s->get_random(max);
|
||||
uint8_t index2 = this->draw_index + s->get_random(max);
|
||||
uint16_t temp_ref = this->card_refs[index1];
|
||||
@@ -309,7 +298,11 @@ static const char* name_for_card_state(DeckState::CardState st) {
|
||||
|
||||
void DeckState::print(FILE* stream, std::shared_ptr<const CardIndex> card_index) const {
|
||||
phosg::fwrite_fmt(stream, "DeckState: client_id={} draw_index={} card_ref_base=@{:04X} shuffle={} loop={}\n",
|
||||
this->client_id, this->draw_index, this->card_ref_base, this->shuffle_enabled ? "true" : "false", this->loop_enabled ? "true" : "false");
|
||||
this->client_id,
|
||||
this->draw_index,
|
||||
this->card_ref_base,
|
||||
this->shuffle_enabled ? "true" : "false",
|
||||
this->loop_enabled ? "true" : "false");
|
||||
for (size_t z = 0; z < 31; z++) {
|
||||
const auto& e = this->entries[z];
|
||||
shared_ptr<const CardIndex::CardEntry> ce;
|
||||
@@ -320,7 +313,7 @@ void DeckState::print(FILE* stream, std::shared_ptr<const CardIndex> card_index)
|
||||
}
|
||||
}
|
||||
if (ce) {
|
||||
string name = ce->def.en_name.decode(1);
|
||||
string name = ce->def.en_name.decode(Language::ENGLISH);
|
||||
phosg::fwrite_fmt(stream, " ({:02}) index={:02X} ref=@{:04X} card_id=#{:04X} \"{}\" {}\n",
|
||||
z, e.deck_index, this->card_refs[z], e.card_id, name, name_for_card_state(e.state));
|
||||
} else {
|
||||
|
||||
@@ -28,9 +28,8 @@ struct DeckEntry {
|
||||
/* 00 */ pstring<TextEncoding::MARKED, 0x10> name;
|
||||
/* 10 */ le_uint32_t team_id;
|
||||
/* 14 */ parray<le_uint16_t, 31> card_ids;
|
||||
// If the following flag is not set to 3, then the God Whim assist effect can
|
||||
// use cards that are hidden from the player during deck building. The client
|
||||
// always sets this to 3, and it's not clear why this even exists.
|
||||
// If the following flag is not set to 3, then the God Whim assist effect can use cards that are hidden from the
|
||||
// player during deck building. The client always sets this to 3, and it's not clear why this even exists.
|
||||
/* 52 */ uint8_t god_whim_flag;
|
||||
/* 53 */ uint8_t unused1;
|
||||
/* 54 */ le_uint16_t player_level;
|
||||
@@ -56,10 +55,7 @@ public:
|
||||
};
|
||||
|
||||
template <typename CardIDT>
|
||||
DeckState(
|
||||
uint8_t client_id,
|
||||
const parray<CardIDT, 0x1F>& card_ids,
|
||||
std::shared_ptr<Server> server)
|
||||
DeckState(uint8_t client_id, const parray<CardIDT, 0x1F>& card_ids, std::shared_ptr<Server> server)
|
||||
: server(server),
|
||||
client_id(client_id),
|
||||
draw_index(1),
|
||||
|
||||
+43
-90
@@ -110,9 +110,7 @@ void PlayerState::init() {
|
||||
this->set_card_action_chains,
|
||||
this->set_card_action_metadatas);
|
||||
s->ruler_server->set_client_team_id(this->client_id, this->team_id);
|
||||
|
||||
s->card_special->on_card_set(this->shared_from_this(), this->sc_card_ref);
|
||||
|
||||
this->god_whim_can_use_hidden_cards = (s->deck_entries[this->client_id]->god_whim_flag != 3);
|
||||
}
|
||||
|
||||
@@ -153,8 +151,7 @@ bool PlayerState::draw_cards_allowed() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerState::apply_assist_card_effect_on_set(
|
||||
shared_ptr<PlayerState> setter_ps) {
|
||||
void PlayerState::apply_assist_card_effect_on_set(shared_ptr<PlayerState> setter_ps) {
|
||||
auto s = this->server();
|
||||
|
||||
uint16_t assist_card_id = this->set_assist_card_id;
|
||||
@@ -163,8 +160,7 @@ void PlayerState::apply_assist_card_effect_on_set(
|
||||
}
|
||||
|
||||
auto assist_effect = assist_effect_number_for_card_id(assist_card_id, s->options.is_nte());
|
||||
if ((assist_effect == AssistEffect::RESISTANCE) ||
|
||||
(assist_effect == AssistEffect::INDEPENDENT)) {
|
||||
if ((assist_effect == AssistEffect::RESISTANCE) || (assist_effect == AssistEffect::INDEPENDENT)) {
|
||||
this->assist_card_set_number = 0;
|
||||
}
|
||||
|
||||
@@ -314,8 +310,7 @@ void PlayerState::apply_assist_card_effect_on_set(
|
||||
auto other_ps = s->get_player_state(client_id);
|
||||
if (other_ps.get() != this) {
|
||||
other_ps->deck_state->draw_card_by_ref(this->card_refs[7]);
|
||||
other_ps->set_card_from_hand(
|
||||
this->card_refs[7], 0xF, nullptr, client_id, 1);
|
||||
other_ps->set_card_from_hand(this->card_refs[7], 0xF, nullptr, client_id, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -362,9 +357,7 @@ void PlayerState::apply_assist_card_effect_on_set(
|
||||
}
|
||||
|
||||
for (ssize_t set_index = is_nte ? 0 : -1; set_index < 8; set_index++) {
|
||||
auto card = (set_index == -1)
|
||||
? other_ps->get_sc_card()
|
||||
: other_ps->get_set_card(set_index);
|
||||
auto card = (set_index == -1) ? other_ps->get_sc_card() : other_ps->get_set_card(set_index);
|
||||
if (card) {
|
||||
for (size_t cond_index = 0; cond_index < 9; cond_index++) {
|
||||
auto& cond = card->action_chain.conditions[cond_index];
|
||||
@@ -404,9 +397,7 @@ void PlayerState::apply_assist_card_effect_on_set(
|
||||
}
|
||||
|
||||
for (ssize_t set_index = is_nte ? 0 : -1; set_index < 8; set_index++) {
|
||||
auto card = (set_index == -1)
|
||||
? other_ps->get_sc_card()
|
||||
: other_ps->get_set_card(set_index);
|
||||
auto card = (set_index == -1) ? other_ps->get_sc_card() : other_ps->get_set_card(set_index);
|
||||
if (card) {
|
||||
for (size_t cond_index = 0; cond_index < 9; cond_index++) {
|
||||
auto& cond = card->action_chain.conditions[cond_index];
|
||||
@@ -537,9 +528,9 @@ size_t PlayerState::count_set_cards() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t PlayerState::count_set_refs() const {
|
||||
size_t PlayerState::count_hand_refs() const {
|
||||
size_t ret = 0;
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
for (size_t set_index = 8; set_index < 16; set_index++) {
|
||||
if (this->card_refs[set_index] != 0xFFFF) {
|
||||
ret++;
|
||||
}
|
||||
@@ -577,8 +568,7 @@ void PlayerState::discard_all_attack_action_cards_from_hand() {
|
||||
for (size_t hand_index = 0; hand_index < 6; hand_index++) {
|
||||
uint16_t card_ref = temp_card_refs[hand_index];
|
||||
auto ce = s->definition_for_card_ref(card_ref);
|
||||
if (ce && (ce->def.type == CardType::ACTION) &&
|
||||
(ce->def.card_class() != CardClass::DEFENSE_ACTION)) {
|
||||
if (ce && (ce->def.type == CardType::ACTION) && (ce->def.card_class() != CardClass::DEFENSE_ACTION)) {
|
||||
this->discard_ref_from_hand(card_ref);
|
||||
}
|
||||
}
|
||||
@@ -771,9 +761,8 @@ void PlayerState::draw_hand(ssize_t override_count) {
|
||||
}
|
||||
|
||||
void PlayerState::draw_initial_hand() {
|
||||
// Note: The original code called this->deck_state->init_card_states here, but
|
||||
// we don't because that logic is now in the DeckState constructor, and this
|
||||
// function should only be called during PlayerState construction (so, shortly
|
||||
// Note: The original code called this->deck_state->init_card_states here, but we don't because that logic is now in
|
||||
// the DeckState constructor, and this function should only be called during PlayerState construction (so, shortly
|
||||
// after DeckState construction as well).
|
||||
this->deck_state->restart();
|
||||
this->card_refs.clear(0xFFFF);
|
||||
@@ -782,10 +771,7 @@ void PlayerState::draw_initial_hand() {
|
||||
}
|
||||
|
||||
int32_t PlayerState::error_code_for_client_setting_card(
|
||||
uint16_t card_ref,
|
||||
uint8_t card_index,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id) const {
|
||||
uint16_t card_ref, uint8_t card_index, const Location* loc, uint8_t assist_target_client_id) const {
|
||||
auto s = this->server();
|
||||
|
||||
int32_t code = s->ruler_server->error_code_for_client_setting_card(
|
||||
@@ -816,8 +802,7 @@ int32_t PlayerState::error_code_for_client_setting_card(
|
||||
if (this->card_refs[card_index + 1] != 0xFFFF) {
|
||||
return -0x7E;
|
||||
}
|
||||
if ((ce->def.type == CardType::CREATURE) &&
|
||||
!s->map_and_rules->tile_is_vacant(loc->x, loc->y)) {
|
||||
if ((ce->def.type == CardType::CREATURE) && !s->map_and_rules->tile_is_vacant(loc->x, loc->y)) {
|
||||
return -0x7A;
|
||||
}
|
||||
return 0;
|
||||
@@ -834,9 +819,7 @@ int32_t PlayerState::error_code_for_client_setting_card(
|
||||
}
|
||||
|
||||
vector<uint16_t> PlayerState::get_all_cards_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
uint8_t target_team_id) const {
|
||||
const parray<uint8_t, 9 * 9>& range, const Location& loc, uint8_t target_team_id) const {
|
||||
auto s = this->server();
|
||||
|
||||
auto log = s->log_stack("get_all_cards_within_range: ");
|
||||
@@ -846,8 +829,7 @@ vector<uint16_t> PlayerState::get_all_cards_within_range(
|
||||
vector<uint16_t> ret;
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto other_ps = s->player_states[client_id];
|
||||
if (other_ps &&
|
||||
((target_team_id == 0xFF) || (target_team_id == other_ps->get_team_id()))) {
|
||||
if (other_ps && ((target_team_id == 0xFF) || (target_team_id == other_ps->get_team_id()))) {
|
||||
auto card_refs = get_card_refs_within_range(range, loc, *other_ps->card_short_statuses, &log);
|
||||
ret.insert(ret.end(), card_refs.begin(), card_refs.end());
|
||||
}
|
||||
@@ -945,9 +927,8 @@ bool PlayerState::is_hand_redraw_allowed() const {
|
||||
|
||||
bool PlayerState::is_team_turn() const {
|
||||
auto s = this->server();
|
||||
// Note: The original code checks if this->w_server is null before doing this.
|
||||
// We don't check because that should never happen, and server() will throw if
|
||||
// it does.
|
||||
// Note: The original code checks if this->w_server is null before doing this. We don't check because that should
|
||||
// never happen, and server() will throw if it does.
|
||||
return s->get_current_team_turn() == this->team_id;
|
||||
}
|
||||
|
||||
@@ -961,9 +942,8 @@ void PlayerState::log_discard(uint16_t card_ref, uint16_t reason) {
|
||||
}
|
||||
|
||||
uint16_t PlayerState::pop_from_discard_log(uint16_t) {
|
||||
// NTE appears to have a bug here (or some obviated code): it searches for an
|
||||
// entry with the given reason, then ignores the result of that search and
|
||||
// always returns the first entry instead.
|
||||
// NTE appears to have a bug here (or some obviated code): it searches for an entry with the given reason, then
|
||||
// ignores the result of that search and always returns the first entry instead. That code is:
|
||||
// size_t z;
|
||||
// for (size_t z = 0; z < this->discard_log_card_refs.size(); z++) {
|
||||
// if ((this->discard_log_card_refs[z] != 0xFFFF) && (this->discard_log_reasons[z] == reason)) {
|
||||
@@ -1030,9 +1010,7 @@ void PlayerState::move_null_hand_refs_to_end() {
|
||||
void PlayerState::on_cards_destroyed() {
|
||||
auto s = this->server();
|
||||
|
||||
// {card_ref: should_return_to_hand}
|
||||
unordered_multimap<uint16_t, bool> card_refs_map;
|
||||
|
||||
unordered_multimap<uint16_t, bool> card_refs_map; // {card_ref: should_return_to_hand}
|
||||
for (size_t z = 0; z < 8; z++) {
|
||||
auto card = this->set_cards[z];
|
||||
if (!card || !(card->card_flags & 2)) {
|
||||
@@ -1106,8 +1084,7 @@ void PlayerState::replace_all_set_assists_with_random_assists() {
|
||||
const auto& assist_card_ids = all_assist_card_ids(is_nte);
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto other_ps = s->get_player_state(client_id);
|
||||
if (other_ps &&
|
||||
((other_ps->card_refs[6] != 0xFFFF) || (!is_nte && (other_ps->set_assist_card_id != 0xFFFF)))) {
|
||||
if (other_ps && ((other_ps->card_refs[6] != 0xFFFF) || (!is_nte && (other_ps->set_assist_card_id != 0xFFFF)))) {
|
||||
uint16_t card_id = 0x0130;
|
||||
while (card_id == 0x0130) { // God Whim
|
||||
size_t index = s->get_random(assist_card_ids.size());
|
||||
@@ -1355,8 +1332,7 @@ bool PlayerState::set_card_from_hand(
|
||||
return 0;
|
||||
}
|
||||
this->card_refs[card_index + 1] = card_ref;
|
||||
// Note: NTE doesn't call the destructor on the existing card, if there is
|
||||
// one. Is that a bug?
|
||||
// Note: NTE doesn't call the destructor on the existing card, if there is one. Is that a bug?
|
||||
this->set_cards[card_index - 7] = make_shared<Card>(s->card_id_for_card_ref(card_ref), card_ref, this->client_id, s);
|
||||
auto new_card = this->set_cards[card_index - 7];
|
||||
new_card->init();
|
||||
@@ -1365,8 +1341,7 @@ bool PlayerState::set_card_from_hand(
|
||||
new_card->loc.x = loc->x;
|
||||
new_card->loc.y = loc->y;
|
||||
}
|
||||
// Note: NTE doesn't track this, but NTE can't use it anyway, so we don't
|
||||
// check for NTE here.
|
||||
// Note: NTE doesn't track this, but NTE can't use it anyway, so we don't check for NTE here.
|
||||
this->stats.num_item_or_creature_cards_set++;
|
||||
|
||||
} else if (ce->def.type == CardType::ASSIST) {
|
||||
@@ -1436,7 +1411,6 @@ bool PlayerState::set_card_from_hand(
|
||||
|
||||
void PlayerState::set_initial_location() {
|
||||
auto s = this->server();
|
||||
|
||||
auto mr = s->map_and_rules;
|
||||
|
||||
uint8_t num_team_players;
|
||||
@@ -1485,8 +1459,7 @@ void PlayerState::set_initial_location() {
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerState::set_map_occupied_bit_for_card_on_warp_tile(
|
||||
shared_ptr<const Card> card) {
|
||||
void PlayerState::set_map_occupied_bit_for_card_on_warp_tile(shared_ptr<const Card> card) {
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
@@ -1498,8 +1471,7 @@ void PlayerState::set_map_occupied_bit_for_card_on_warp_tile(
|
||||
if ((s->warp_positions[warp_type][warp_end][0] == card->loc.x) &&
|
||||
(s->warp_positions[warp_type][warp_end][1] == card->loc.y)) {
|
||||
s->map_and_rules->set_occupied_bit_for_tile(
|
||||
s->warp_positions[warp_type][warp_end ^ 1][0],
|
||||
s->warp_positions[warp_type][warp_end ^ 1][1]);
|
||||
s->warp_positions[warp_type][warp_end ^ 1][0], s->warp_positions[warp_type][warp_end ^ 1][1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1509,8 +1481,7 @@ void PlayerState::set_map_occupied_bits_for_sc_and_creatures() {
|
||||
auto s = this->server();
|
||||
|
||||
if (this->sc_card && !(this->sc_card->card_flags & 2)) {
|
||||
s->map_and_rules->set_occupied_bit_for_tile(
|
||||
this->sc_card->loc.x, this->sc_card->loc.y);
|
||||
s->map_and_rules->set_occupied_bit_for_tile(this->sc_card->loc.x, this->sc_card->loc.y);
|
||||
this->set_map_occupied_bit_for_card_on_warp_tile(this->sc_card);
|
||||
}
|
||||
|
||||
@@ -1518,8 +1489,7 @@ void PlayerState::set_map_occupied_bits_for_sc_and_creatures() {
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = this->set_cards[set_index];
|
||||
if (card) {
|
||||
s->map_and_rules->set_occupied_bit_for_tile(
|
||||
card->loc.x, card->loc.y);
|
||||
s->map_and_rules->set_occupied_bit_for_tile(card->loc.x, card->loc.y);
|
||||
this->set_map_occupied_bit_for_card_on_warp_tile(card);
|
||||
}
|
||||
}
|
||||
@@ -1530,8 +1500,7 @@ void PlayerState::subtract_def_points(uint8_t cost) {
|
||||
this->def_points -= cost;
|
||||
}
|
||||
|
||||
bool PlayerState::subtract_or_check_atk_or_def_points_for_action(
|
||||
const ActionState& pa, bool deduct_points) {
|
||||
bool PlayerState::subtract_or_check_atk_or_def_points_for_action(const ActionState& pa, bool deduct_points) {
|
||||
auto s = this->server();
|
||||
|
||||
int16_t cost = this->compute_attack_or_defense_atk_costs(pa);
|
||||
@@ -1580,9 +1549,7 @@ G_UpdateHand_Ep3_6xB4x02 PlayerState::prepare_6xB4x02() const {
|
||||
cmd.state.assist_card_ref = this->card_refs[6];
|
||||
cmd.state.sc_card_ref = this->sc_card_ref;
|
||||
cmd.state.assist_card_ref2 = this->card_refs[6];
|
||||
cmd.state.assist_card_set_number = (this->card_refs[6] == 0xFFFF)
|
||||
? 0
|
||||
: this->assist_card_set_number;
|
||||
cmd.state.assist_card_set_number = (this->card_refs[6] == 0xFFFF) ? 0 : this->assist_card_set_number;
|
||||
cmd.state.assist_card_id = this->set_assist_card_id;
|
||||
cmd.state.assist_remaining_turns = this->assist_remaining_turns;
|
||||
cmd.state.assist_delay_turns = this->assist_delay_turns;
|
||||
@@ -1591,8 +1558,7 @@ G_UpdateHand_Ep3_6xB4x02 PlayerState::prepare_6xB4x02() const {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
void PlayerState::update_hand_and_equip_state_and_send_6xB4x02_if_needed(
|
||||
bool always_send) {
|
||||
void PlayerState::update_hand_and_equip_state_and_send_6xB4x02_if_needed(bool always_send) {
|
||||
auto cmd = this->prepare_6xB4x02();
|
||||
if (always_send || memcmp(&this->hand_and_equip, &cmd.state, sizeof(this->hand_and_equip))) {
|
||||
*this->hand_and_equip = cmd.state;
|
||||
@@ -1618,8 +1584,7 @@ void PlayerState::set_random_assist_card_from_hand_for_free() {
|
||||
if (!candidate_card_refs.empty()) {
|
||||
this->discard_set_assist_card();
|
||||
size_t index = s->get_random(candidate_card_refs.size());
|
||||
this->set_card_from_hand(
|
||||
candidate_card_refs[index], 15, nullptr, this->client_id, 1);
|
||||
this->set_card_from_hand(candidate_card_refs[index], 15, nullptr, this->client_id, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1641,11 +1606,9 @@ G_UpdateShortStatuses_Ep3_6xB4x04 PlayerState::prepare_6xB4x04() const {
|
||||
}
|
||||
|
||||
for (size_t hand_index = 0; hand_index < 6; hand_index++) {
|
||||
this->get_short_status_for_card_index_in_hand(
|
||||
hand_index + 1, &cmd.card_statuses[hand_index + 1]);
|
||||
// This write is required to mimic memset()'s effect from the original code.
|
||||
// This field is probably ignored for hand refs anyway, but we might as well
|
||||
// be as consistent as possible.
|
||||
this->get_short_status_for_card_index_in_hand(hand_index + 1, &cmd.card_statuses[hand_index + 1]);
|
||||
// This write is required to mimic memset()'s effect from the original code. This field is probably ignored for
|
||||
// hand refs anyway, but we might as well be as consistent as possible.
|
||||
cmd.card_statuses[hand_index + 1].unused1 = 0;
|
||||
}
|
||||
|
||||
@@ -1674,9 +1637,7 @@ void PlayerState::send_6xB4x04_if_needed(bool always_send) {
|
||||
}
|
||||
|
||||
vector<uint16_t> PlayerState::get_card_refs_within_range_from_all_players(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
CardType type) const {
|
||||
const parray<uint8_t, 9 * 9>& range, const Location& loc, CardType type) const {
|
||||
auto s = this->server();
|
||||
|
||||
vector<uint16_t> ret;
|
||||
@@ -1726,8 +1687,7 @@ void PlayerState::move_phase_before() {
|
||||
void PlayerState::handle_before_turn_assist_effects() {
|
||||
auto s = this->server();
|
||||
|
||||
if ((this->assist_delay_turns > 0) &&
|
||||
(--this->assist_delay_turns == 0)) {
|
||||
if ((this->assist_delay_turns > 0) && (--this->assist_delay_turns == 0)) {
|
||||
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
size_t num_assists = s->assist_server->compute_num_assist_effects_for_client(this->client_id);
|
||||
for (size_t z = 0; z < num_assists; z++) {
|
||||
@@ -1736,8 +1696,7 @@ void PlayerState::handle_before_turn_assist_effects() {
|
||||
s->execute_bomb_assist_effect();
|
||||
break;
|
||||
case AssistEffect::ATK_DICE_2:
|
||||
// Note: This behavior doesn't match the card description. Is it
|
||||
// supposed to add 2 or multiply by 2?
|
||||
// Note: This behavior doesn't match the card description. Is it supposed to add 2 or multiply by 2?
|
||||
this->atk_points = min<int16_t>(this->atk_points + 2, 9);
|
||||
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
break;
|
||||
@@ -1885,9 +1844,7 @@ void PlayerState::dice_phase_before() {
|
||||
|
||||
this->compute_total_set_cards_cost();
|
||||
this->unknown_a14 = 0;
|
||||
if ((this->assist_remaining_turns > 0) &&
|
||||
(this->assist_remaining_turns < 90) &&
|
||||
(this->assist_delay_turns == 0)) {
|
||||
if ((this->assist_remaining_turns > 0) && (this->assist_remaining_turns < 90) && (this->assist_delay_turns == 0)) {
|
||||
this->assist_remaining_turns--;
|
||||
if (this->assist_remaining_turns < 1) {
|
||||
this->discard_set_assist_card();
|
||||
@@ -1984,12 +1941,10 @@ void PlayerState::roll_main_dice_or_apply_after_effects() {
|
||||
auto s = this->server();
|
||||
const auto& rules = s->map_and_rules->rules;
|
||||
|
||||
// In NTE, the dice behave differently - there is no minimum, and instead the
|
||||
// player can specify a fixed value for each die or a random value (1-6). The
|
||||
// implementation of this function is therefore quite different on NTE, but
|
||||
// since we already support custom ranges for ATK and DEF dice, we just use
|
||||
// the non-NTE logic and assign the dice ranges at battle start time to yield
|
||||
// the NTE behavior. (See RulesTrial in DataIndexes.cc for how this is done.)
|
||||
// In NTE, the dice behave differently - there is no minimum, and instead the player can specify a fixed value for
|
||||
// each die or a random value (1-6). The implementation of this function is therefore quite different on NTE, but
|
||||
// since we already support custom ranges for ATK and DEF dice, we just use the non-NTE logic and assign the dice
|
||||
// ranges at battle start time to yield the NTE behavior. (See RulesTrial in DataIndexes.cc for how this is done.)
|
||||
|
||||
bool is_1p_2v1 = (s->team_client_count.at(this->get_team_id()) < s->team_client_count[this->get_team_id() ^ 1]);
|
||||
|
||||
@@ -2079,10 +2034,8 @@ void PlayerState::compute_team_dice_bonus_after_draw_phase() {
|
||||
}
|
||||
|
||||
uint8_t current_team_turn = s->get_current_team_turn();
|
||||
uint8_t dice_boost = s->get_team_exp(current_team_turn) /
|
||||
(s->team_client_count[current_team_turn] * 12);
|
||||
s->card_special->adjust_dice_boost_if_team_has_condition_52(
|
||||
current_team_turn, &dice_boost, 0);
|
||||
uint8_t dice_boost = s->get_team_exp(current_team_turn) / (s->team_client_count[current_team_turn] * 12);
|
||||
s->card_special->adjust_dice_boost_if_team_has_condition_52(current_team_turn, &dice_boost, 0);
|
||||
s->team_dice_bonus[current_team_turn] = clamp<int16_t>(dice_boost, 0, 8);
|
||||
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
}
|
||||
|
||||
+16
-24
@@ -15,9 +15,8 @@ namespace Episode3 {
|
||||
class Server;
|
||||
|
||||
enum AssistFlag : uint32_t {
|
||||
// Note: This enum is a uint32_t even though only 16 bits are used because
|
||||
// the corresponding field in the protocol is a 32-bit field. There may also
|
||||
// be bits used only by the client which are not documented here.
|
||||
// Note: This enum is a uint32_t even though only 16 bits are used because the corresponding field in the protocol is
|
||||
// a 32-bit field. There may also be bits used only by the client which are not documented here.
|
||||
|
||||
// clang-format off
|
||||
NONE = 0x0000,
|
||||
@@ -57,7 +56,7 @@ public:
|
||||
void compute_total_set_cards_cost();
|
||||
size_t count_set_cards_for_env_stats_nte() const;
|
||||
size_t count_set_cards() const;
|
||||
size_t count_set_refs() const;
|
||||
size_t count_hand_refs() const;
|
||||
void discard_all_assist_cards_from_hand();
|
||||
void discard_all_attack_action_cards_from_hand();
|
||||
void discard_all_item_and_creature_cards_from_hand();
|
||||
@@ -70,14 +69,9 @@ public:
|
||||
void draw_hand(ssize_t override_count = 0);
|
||||
void draw_initial_hand();
|
||||
int32_t error_code_for_client_setting_card(
|
||||
uint16_t card_ref,
|
||||
uint8_t card_index,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id) const;
|
||||
uint16_t card_ref, uint8_t card_index, const Location* loc, uint8_t assist_target_client_id) const;
|
||||
std::vector<uint16_t> get_all_cards_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
uint8_t target_team_id) const;
|
||||
const parray<uint8_t, 9 * 9>& range, const Location& loc, uint8_t target_team_id) const;
|
||||
uint8_t get_atk_points() const;
|
||||
void get_short_status_for_card_index_in_hand(size_t hand_index, CardShortStatus* stat) const;
|
||||
std::shared_ptr<DeckState> get_deck();
|
||||
@@ -128,9 +122,7 @@ public:
|
||||
G_UpdateShortStatuses_Ep3_6xB4x04 prepare_6xB4x04() const;
|
||||
void send_6xB4x04_if_needed(bool always_send = false);
|
||||
std::vector<uint16_t> get_card_refs_within_range_from_all_players(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
CardType type) const;
|
||||
const parray<uint8_t, 9 * 9>& range, const Location& loc, CardType type) const;
|
||||
void draw_phase_before();
|
||||
void action_phase_before();
|
||||
void move_phase_before();
|
||||
@@ -169,10 +161,10 @@ public:
|
||||
uint16_t sc_card_ref;
|
||||
|
||||
// This array is unfortunately heterogeneous; specifically:
|
||||
// [0] through [5] are hand refs
|
||||
// [6] is the current assist card ref (which may belong to another player)
|
||||
// [7] is the previous assist card ref
|
||||
// [8] through [15] are set refs
|
||||
// [0] through [5] are hand refs
|
||||
// [6] is the current assist card ref (which may belong to another player)
|
||||
// [7] is the previous assist card ref
|
||||
// [8] through [15] are set refs
|
||||
parray<uint16_t, 0x10> card_refs;
|
||||
|
||||
std::shared_ptr<DeckState> deck_state;
|
||||
@@ -190,12 +182,12 @@ public:
|
||||
Direction start_facing_direction;
|
||||
std::shared_ptr<HandAndEquipState> hand_and_equip;
|
||||
|
||||
// Like card_refs above, these arrays are also heterogeneous, but the indices
|
||||
// are not the same as for card_refs! THe indices here are:
|
||||
// [0] is the SC card status
|
||||
// [1] through [6] are hand cards
|
||||
// [7] through [14] are set cards
|
||||
// [15] is the assist card
|
||||
// Like card_refs above, these arrays are also heterogeneous, but the indices are not the same as for card_refs! The
|
||||
// indices here are:
|
||||
// [0] is the SC card status
|
||||
// [1] through [6] are hand cards
|
||||
// [7] through [14] are set cards
|
||||
// [15] is the assist card
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> card_short_statuses;
|
||||
parray<CardShortStatus, 0x10> prev_card_short_statuses;
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ void Condition::clear_FF() {
|
||||
}
|
||||
|
||||
std::string Condition::str(shared_ptr<const Server> s) const {
|
||||
auto card_ref_str = s->debug_str_for_card_ref(this->card_ref);
|
||||
auto giver_ref_str = s->debug_str_for_card_ref(this->condition_giver_card_ref);
|
||||
return std::format(
|
||||
"Condition[type={}, turns={}, a_arg={}, dice={}, flags={:02X}, "
|
||||
"def_eff_index={}, ref={}, value={}, giver_ref={} "
|
||||
@@ -74,9 +72,9 @@ std::string Condition::str(shared_ptr<const Server> s) const {
|
||||
this->dice_roll_value,
|
||||
this->flags,
|
||||
this->card_definition_effect_index,
|
||||
card_ref_str,
|
||||
s->debug_str_for_card_ref(this->card_ref),
|
||||
this->value,
|
||||
giver_ref_str,
|
||||
s->debug_str_for_card_ref(this->condition_giver_card_ref),
|
||||
this->random_percent,
|
||||
this->value8,
|
||||
this->order,
|
||||
@@ -101,14 +99,10 @@ void EffectResult::clear() {
|
||||
}
|
||||
|
||||
std::string EffectResult::str(shared_ptr<const Server> s) const {
|
||||
string attacker_ref_str = s->debug_str_for_card_ref(this->attacker_card_ref);
|
||||
string target_ref_str = s->debug_str_for_card_ref(this->target_card_ref);
|
||||
return std::format(
|
||||
"EffectResult[att_ref={}, target_ref={}, value={}, "
|
||||
"cur_hp={}, ap={}, tp={}, flags={:02X}, op={}, "
|
||||
"cond_index={}, dice={}]",
|
||||
attacker_ref_str,
|
||||
target_ref_str,
|
||||
"EffectResult[att_ref={}, target_ref={}, value={}, cur_hp={}, ap={}, tp={}, flags={:02X}, op={}, cond_index={}, dice={}]",
|
||||
s->debug_str_for_card_ref(this->attacker_card_ref),
|
||||
s->debug_str_for_card_ref(this->target_card_ref),
|
||||
this->value,
|
||||
this->current_hp,
|
||||
this->ap,
|
||||
@@ -137,15 +131,12 @@ bool CardShortStatus::operator!=(const CardShortStatus& other) const {
|
||||
}
|
||||
|
||||
std::string CardShortStatus::str(shared_ptr<const Server> s) const {
|
||||
string loc_s = this->loc.str();
|
||||
string ref_str = s->debug_str_for_card_ref(this->card_ref);
|
||||
return std::format(
|
||||
"CardShortStatus[ref={}, cur_hp={}, flags={:08X}, loc={}, "
|
||||
"u1={:04X}, max_hp={}, u2={}]",
|
||||
ref_str,
|
||||
"CardShortStatus[ref={}, cur_hp={}, flags={:08X}, loc={}, u1={:04X}, max_hp={}, u2={}]",
|
||||
s->debug_str_for_card_ref(this->card_ref),
|
||||
this->current_hp,
|
||||
this->card_flags,
|
||||
loc_s,
|
||||
this->loc.str(),
|
||||
this->unused1,
|
||||
this->max_hp,
|
||||
this->unused2);
|
||||
@@ -188,23 +179,16 @@ void ActionState::clear() {
|
||||
}
|
||||
|
||||
std::string ActionState::str(shared_ptr<const Server> s) const {
|
||||
string attacker_ref_s = s->debug_str_for_card_ref(this->attacker_card_ref);
|
||||
string defense_ref_s = s->debug_str_for_card_ref(this->defense_card_ref);
|
||||
string original_attacker_ref_s = s->debug_str_for_card_ref(this->original_attacker_card_ref);
|
||||
string target_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
|
||||
string action_refs_s = s->debug_str_for_card_refs(this->action_card_refs);
|
||||
return std::format(
|
||||
"ActionState[client={:X}, u={}, facing={}, attacker_ref={}, "
|
||||
"def_ref={}, target_refs={}, action_refs={}, "
|
||||
"orig_attacker_ref={}]",
|
||||
"ActionState[client={:X}, u={}, facing={}, attacker_ref={}, def_ref={}, target_refs={}, action_refs={}, orig_attacker_ref={}]",
|
||||
this->client_id,
|
||||
this->unused,
|
||||
phosg::name_for_enum(this->facing_direction),
|
||||
attacker_ref_s,
|
||||
defense_ref_s,
|
||||
target_refs_s,
|
||||
action_refs_s,
|
||||
original_attacker_ref_s);
|
||||
s->debug_str_for_card_ref(this->attacker_card_ref),
|
||||
s->debug_str_for_card_ref(this->defense_card_ref),
|
||||
s->debug_str_for_card_refs(this->target_card_refs),
|
||||
s->debug_str_for_card_refs(this->action_card_refs),
|
||||
s->debug_str_for_card_ref(this->original_attacker_card_ref));
|
||||
}
|
||||
|
||||
ActionChain::ActionChain() {
|
||||
@@ -239,24 +223,17 @@ bool ActionChain::operator!=(const ActionChain& other) const {
|
||||
}
|
||||
|
||||
std::string ActionChain::str(shared_ptr<const Server> s) const {
|
||||
string acting_card_ref_s = s->debug_str_for_card_ref(this->acting_card_ref);
|
||||
string unknown_card_ref_a3_s = s->debug_str_for_card_ref(this->unknown_card_ref_a3);
|
||||
string attack_action_card_refs_s = s->debug_str_for_card_refs(this->attack_action_card_refs);
|
||||
string target_card_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
|
||||
return std::format(
|
||||
"ActionChain[eff_ap={}, eff_tp={}, ap_bonus={}, damage={}, "
|
||||
"acting_ref={}, unknown_ref_a3={}, attack_action_refs={}, "
|
||||
"attack_action_ref_count={}, medium={}, target_ref_count={}, "
|
||||
"subphase={}, strikes={}, damage_mult={}, attack_num={}, "
|
||||
"tp_bonus={}, phys_bonus_nte={}, tech_bonus_nte={}, card_ap={}, "
|
||||
"card_tp={}, flags={:08X}, target_refs={}]",
|
||||
"ActionChain[eff_ap={}, eff_tp={}, ap_bonus={}, damage={}, acting_ref={}, unknown_ref_a3={}, attack_action_refs={}, "
|
||||
"attack_action_ref_count={}, medium={}, target_ref_count={}, subphase={}, strikes={}, damage_mult={}, attack_num={}, "
|
||||
"tp_bonus={}, phys_bonus_nte={}, tech_bonus_nte={}, card_ap={}, card_tp={}, flags={:08X}, target_refs={}]",
|
||||
this->effective_ap,
|
||||
this->effective_tp,
|
||||
this->ap_effect_bonus,
|
||||
this->damage,
|
||||
acting_card_ref_s,
|
||||
unknown_card_ref_a3_s,
|
||||
attack_action_card_refs_s,
|
||||
s->debug_str_for_card_ref(this->acting_card_ref),
|
||||
s->debug_str_for_card_ref(this->unknown_card_ref_a3),
|
||||
s->debug_str_for_card_refs(this->attack_action_card_refs),
|
||||
this->attack_action_card_ref_count,
|
||||
phosg::name_for_enum(this->attack_medium),
|
||||
this->target_card_ref_count,
|
||||
@@ -270,7 +247,7 @@ std::string ActionChain::str(shared_ptr<const Server> s) const {
|
||||
this->card_ap,
|
||||
this->card_tp,
|
||||
this->flags,
|
||||
target_card_refs_s);
|
||||
s->debug_str_for_card_refs(this->target_card_refs));
|
||||
}
|
||||
|
||||
void ActionChain::clear() {
|
||||
@@ -406,8 +383,7 @@ void ActionChainWithConds::set_flags(uint32_t flags) {
|
||||
this->chain.flags |= flags;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::add_attack_action_card_ref(
|
||||
uint16_t card_ref, shared_ptr<Server> server) {
|
||||
void ActionChainWithConds::add_attack_action_card_ref(uint16_t card_ref, shared_ptr<Server> server) {
|
||||
if (card_ref != 0xFFFF) {
|
||||
this->chain.attack_action_card_refs[this->chain.attack_action_card_ref_count++] = card_ref;
|
||||
}
|
||||
@@ -416,8 +392,7 @@ void ActionChainWithConds::add_attack_action_card_ref(
|
||||
}
|
||||
|
||||
void ActionChainWithConds::add_target_card_ref(uint16_t card_ref) {
|
||||
if (card_ref != 0xFFFF &&
|
||||
this->chain.target_card_ref_count < this->chain.target_card_refs.size()) {
|
||||
if (card_ref != 0xFFFF && this->chain.target_card_ref_count < this->chain.target_card_refs.size()) {
|
||||
this->chain.target_card_refs[this->chain.target_card_ref_count++] = card_ref;
|
||||
}
|
||||
}
|
||||
@@ -440,11 +415,7 @@ void ActionChainWithConds::compute_attack_medium(shared_ptr<Server> server) {
|
||||
}
|
||||
|
||||
bool ActionChainWithConds::get_condition_value(
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const {
|
||||
ConditionType cond_type, uint16_t card_ref, uint8_t def_effect_index, uint16_t value, uint16_t* out_value) const {
|
||||
bool any_found = false;
|
||||
uint8_t max_order = 10;
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
@@ -466,8 +437,7 @@ bool ActionChainWithConds::get_condition_value(
|
||||
return any_found;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::set_action_subphase_from_card(
|
||||
shared_ptr<const Card> card) {
|
||||
void ActionChainWithConds::set_action_subphase_from_card(shared_ptr<const Card> card) {
|
||||
this->chain.action_subphase = card->server()->get_current_action_subphase();
|
||||
}
|
||||
|
||||
@@ -576,16 +546,10 @@ bool ActionMetadata::operator!=(const ActionMetadata& other) const {
|
||||
}
|
||||
|
||||
std::string ActionMetadata::str(shared_ptr<const Server> s) const {
|
||||
string card_ref_s = s->debug_str_for_card_ref(this->card_ref);
|
||||
string target_card_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
|
||||
string defense_card_refs_s = s->debug_str_for_card_refs(this->defense_card_refs);
|
||||
string original_attacker_card_refs_s = s->debug_str_for_card_refs(this->original_attacker_card_refs);
|
||||
return std::format(
|
||||
"ActionMetadata[ref={}, target_ref_count={}, def_ref_count={}, "
|
||||
"subphase={}, def_power={}, def_bonus={}, "
|
||||
"att_bonus={}, flags={:08X}, target_refs={}, "
|
||||
"defense_refs={}, original_attacker_refs={}]",
|
||||
card_ref_s,
|
||||
"ActionMetadata[ref={}, target_ref_count={}, def_ref_count={}, subphase={}, def_power={}, def_bonus={}, "
|
||||
"att_bonus={}, flags={:08X}, target_refs={}, defense_refs={}, original_attacker_refs={}]",
|
||||
s->debug_str_for_card_ref(this->card_ref),
|
||||
this->target_card_ref_count,
|
||||
this->defense_card_ref_count,
|
||||
phosg::name_for_enum(this->action_subphase),
|
||||
@@ -593,9 +557,9 @@ std::string ActionMetadata::str(shared_ptr<const Server> s) const {
|
||||
this->defense_bonus,
|
||||
this->attack_bonus,
|
||||
this->flags,
|
||||
target_card_refs_s,
|
||||
defense_card_refs_s,
|
||||
original_attacker_card_refs_s);
|
||||
s->debug_str_for_card_refs(this->target_card_refs),
|
||||
s->debug_str_for_card_refs(this->defense_card_refs),
|
||||
s->debug_str_for_card_refs(this->original_attacker_card_refs));
|
||||
}
|
||||
|
||||
void ActionMetadata::clear() {
|
||||
@@ -605,8 +569,7 @@ void ActionMetadata::clear() {
|
||||
this->action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->defense_power = 0;
|
||||
this->defense_bonus = 0;
|
||||
// TODO: Ep3 NTE doesn't set attack_bonus to zero here. Is the field just
|
||||
// unused in NTE?
|
||||
// TODO: Ep3 NTE doesn't set attack_bonus to zero here. Is the field just unused in NTE?
|
||||
this->attack_bonus = 0;
|
||||
this->flags = 0;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
@@ -652,16 +615,13 @@ void ActionMetadata::clear_target_card_refs() {
|
||||
}
|
||||
|
||||
void ActionMetadata::add_target_card_ref(uint16_t card_ref) {
|
||||
if (card_ref != 0xFFFF &&
|
||||
this->target_card_ref_count < this->target_card_refs.size()) {
|
||||
if ((card_ref != 0xFFFF) && (this->target_card_ref_count < this->target_card_refs.size())) {
|
||||
this->target_card_refs[this->target_card_ref_count++] = card_ref;
|
||||
}
|
||||
}
|
||||
|
||||
void ActionMetadata::add_defense_card_ref(
|
||||
uint16_t defense_card_ref,
|
||||
shared_ptr<Card> card,
|
||||
uint16_t original_attacker_card_ref) {
|
||||
uint16_t defense_card_ref, shared_ptr<Card> card, uint16_t original_attacker_card_ref) {
|
||||
if ((defense_card_ref != 0xFFFF) && (this->defense_card_ref_count < 8)) {
|
||||
this->defense_card_refs[this->defense_card_ref_count] = defense_card_ref;
|
||||
this->original_attacker_card_refs[this->defense_card_ref_count] = original_attacker_card_ref;
|
||||
@@ -675,21 +635,10 @@ HandAndEquipState::HandAndEquipState() {
|
||||
}
|
||||
|
||||
std::string HandAndEquipState::str(shared_ptr<const Server> s) const {
|
||||
string assist_card_ref_s = s->debug_str_for_card_ref(this->assist_card_ref);
|
||||
string assist_card_ref2_s = s->debug_str_for_card_ref(this->assist_card_ref2);
|
||||
string assist_card_id_s = s->debug_str_for_card_id(this->assist_card_id);
|
||||
string sc_card_ref_s = s->debug_str_for_card_ref(this->sc_card_ref);
|
||||
string hand_card_refs_s = s->debug_str_for_card_refs(this->hand_card_refs);
|
||||
string set_card_refs_s = s->debug_str_for_card_refs(this->set_card_refs);
|
||||
string hand_card_refs2_s = s->debug_str_for_card_refs(this->hand_card_refs2);
|
||||
string set_card_refs2_s = s->debug_str_for_card_refs(this->set_card_refs2);
|
||||
return std::format(
|
||||
"HandAndEquipState[dice=[{}, {}], atk={}, def={}, atk2={}, "
|
||||
"a1={}, total_set_cost={}, is_cpu={}, assist_flags={:08X}, "
|
||||
"hand_refs={}, assist_ref={}, set_refs={}, sc_ref={}, hand_refs2={}, "
|
||||
"set_refs2={}, assist_ref2={}, assist_set_num={}, assist_card_id={}, "
|
||||
"assist_turns={}, assist_delay={}, atk_bonus={}, def_bonus={}, "
|
||||
"u2=[{}, {}]]",
|
||||
"HandAndEquipState[dice=[{}, {}], atk={}, def={}, atk2={}, a1={}, total_set_cost={}, is_cpu={}, assist_flags={:08X}, "
|
||||
"hand_refs={}, assist_ref={}, set_refs={}, sc_ref={}, hand_refs2={}, set_refs2={}, assist_ref2={}, assist_set_num={}, assist_card_id={}, "
|
||||
"assist_turns={}, assist_delay={}, atk_bonus={}, def_bonus={}, u2=[{}, {}]]",
|
||||
this->dice_results[0],
|
||||
this->dice_results[1],
|
||||
this->atk_points,
|
||||
@@ -699,15 +648,15 @@ std::string HandAndEquipState::str(shared_ptr<const Server> s) const {
|
||||
this->total_set_cards_cost,
|
||||
this->is_cpu_player,
|
||||
this->assist_flags,
|
||||
hand_card_refs_s,
|
||||
assist_card_ref_s,
|
||||
set_card_refs_s,
|
||||
sc_card_ref_s,
|
||||
hand_card_refs2_s,
|
||||
set_card_refs2_s,
|
||||
assist_card_ref2_s,
|
||||
s->debug_str_for_card_refs(this->hand_card_refs),
|
||||
s->debug_str_for_card_ref(this->assist_card_ref),
|
||||
s->debug_str_for_card_refs(this->set_card_refs),
|
||||
s->debug_str_for_card_ref(this->sc_card_ref),
|
||||
s->debug_str_for_card_refs(this->hand_card_refs2),
|
||||
s->debug_str_for_card_refs(this->set_card_refs2),
|
||||
s->debug_str_for_card_ref(this->assist_card_ref2),
|
||||
this->assist_card_set_number,
|
||||
assist_card_id_s,
|
||||
s->debug_str_for_card_id(this->assist_card_id),
|
||||
this->assist_remaining_turns,
|
||||
this->assist_delay_turns,
|
||||
this->atk_bonuses,
|
||||
@@ -795,17 +744,15 @@ void PlayerBattleStats::clear() {
|
||||
|
||||
float PlayerBattleStats::score(size_t num_rounds) const {
|
||||
// Note: This formula doesn't match the formula on PSO-World, which is:
|
||||
// 35
|
||||
// + (Attack Damage - Damage Taken)
|
||||
// + (Max Card Combo x 3)
|
||||
// - (Story Character Damage x 1.8)
|
||||
// - (Turns x 2.7)
|
||||
// + (Action Card Negated Damage x 0.8)
|
||||
// I don't know where that formula came from, but this one came from the USA
|
||||
// Ep3 PsoV3.dol, so it's presumably correct. Is the PSO-World formula simply
|
||||
// incorrect, or is it from e.g. the Japanese version, which may have a
|
||||
// 35 + (Attack Damage - Damage Taken)
|
||||
// + (Max Card Combo x 3)
|
||||
// - (Story Character Damage x 1.8)
|
||||
// - (Turns x 2.7)
|
||||
// + (Action Card Negated Damage x 0.8)
|
||||
// I don't know where that formula came from, but this one came from the USA Ep3 PsoV3.dol, so it's presumably
|
||||
// correct. Is the PSO-World formula simply incorrect, or is it from e.g. the Japanese version, which may have a
|
||||
// different rank calculation function?
|
||||
return 38.0f + 0.8f * this->action_card_negated_damage - 2.3f * num_rounds - 1.8f * this->sc_damage_taken + 3.0f * this->max_attack_combo_size + (this->damage_given - this->damage_taken);
|
||||
return 38.0f + (0.8f * this->action_card_negated_damage) - (2.3f * num_rounds) - (1.8f * this->sc_damage_taken) + (3.0f * this->max_attack_combo_size) + (this->damage_given - this->damage_taken);
|
||||
}
|
||||
|
||||
uint8_t PlayerBattleStats::rank(size_t num_rounds) const {
|
||||
@@ -817,10 +764,8 @@ const char* PlayerBattleStats::rank_name(size_t num_rounds) const {
|
||||
}
|
||||
|
||||
constexpr size_t RANK_THRESHOLD_COUNT = 9;
|
||||
static const float RANK_THRESHOLDS[RANK_THRESHOLD_COUNT] = {
|
||||
15.0f, 25.0f, 30.0f, 40.0f, 50.0f, 60.0f, 65.0f, 75.0f, 85.0f};
|
||||
static const char* RANK_NAMES[RANK_THRESHOLD_COUNT + 1] = {
|
||||
"E", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S"};
|
||||
static const float RANK_THRESHOLDS[RANK_THRESHOLD_COUNT] = {15, 25, 30, 40, 50, 60, 65, 75, 85};
|
||||
static const char* RANK_NAMES[RANK_THRESHOLD_COUNT + 1] = {"E", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S"};
|
||||
|
||||
uint8_t PlayerBattleStats::rank_for_score(float score) {
|
||||
size_t rank = 0;
|
||||
@@ -874,13 +819,15 @@ static bool is_card_within_range(
|
||||
|
||||
if ((ss.loc.x < anchor_loc.x - 4) || (ss.loc.x > anchor_loc.x + 4)) {
|
||||
if (log) {
|
||||
log->debug_f("is_card_within_range: (false) outside x range (ss.loc.x={}, anchor_loc.x={})", ss.loc.x, anchor_loc.x);
|
||||
log->debug_f(
|
||||
"is_card_within_range: (false) outside x range (ss.loc.x={}, anchor_loc.x={})", ss.loc.x, anchor_loc.x);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ((ss.loc.y < anchor_loc.y - 4) || (ss.loc.y > anchor_loc.y + 4)) {
|
||||
if (log) {
|
||||
log->debug_f("is_card_within_range: (false) outside y range (ss.loc.y={}, anchor_loc.y={})", ss.loc.y, anchor_loc.y);
|
||||
log->debug_f(
|
||||
"is_card_within_range: (false) outside y range (ss.loc.y={}, anchor_loc.y={})", ss.loc.y, anchor_loc.y);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -102,8 +102,7 @@ struct ActionState {
|
||||
} __packed_ws__(ActionState, 0x64);
|
||||
|
||||
struct ActionChain {
|
||||
// Note: Episode 3 Trial Edition has a different format for this structure.
|
||||
// See ActionChainWithCondsTrial for details.
|
||||
// Note: Trial Edition has a different format for this structure. See ActionChainWithCondsTrial for details.
|
||||
/* 00 */ int8_t effective_ap;
|
||||
/* 01 */ int8_t effective_tp;
|
||||
/* 02 */ int8_t ap_effect_bonus;
|
||||
@@ -196,8 +195,7 @@ struct ActionChainWithCondsTrial {
|
||||
/* 0022 */ int8_t card_ap;
|
||||
/* 0023 */ int8_t card_tp;
|
||||
/* 0024 */ le_uint32_t flags;
|
||||
// The only difference between this structure and ActionChainWithConds is that
|
||||
// these two fields are in the opposite order.
|
||||
// The only difference between this structure and ActionChainWithConds is that these two fields are swapped.
|
||||
/* 0028 */ parray<Condition, 9> conditions;
|
||||
/* 00B8 */ parray<le_uint16_t, 4 * 9> target_card_refs;
|
||||
/* 0100 */
|
||||
@@ -236,9 +234,7 @@ struct ActionMetadata {
|
||||
void clear_target_card_refs();
|
||||
void add_target_card_ref(uint16_t card_ref);
|
||||
void add_defense_card_ref(
|
||||
uint16_t defense_card_ref,
|
||||
std::shared_ptr<Card> card,
|
||||
uint16_t original_attacker_card_ref);
|
||||
uint16_t defense_card_ref, std::shared_ptr<Card> card, uint16_t original_attacker_card_ref);
|
||||
|
||||
std::string str(std::shared_ptr<const Server> s) const;
|
||||
} __packed_ws__(ActionMetadata, 0x74);
|
||||
|
||||
+82
-135
@@ -25,8 +25,7 @@ void compute_effective_range(
|
||||
ret.clear(0);
|
||||
|
||||
parray<uint32_t, 6> range_def;
|
||||
if (card_id == 0xFFFE) {
|
||||
// Heavy Fog: one tile directly in front
|
||||
if (card_id == 0xFFFE) { // Heavy Fog: one tile directly in front
|
||||
range_def[3] = 0x00000100;
|
||||
} else {
|
||||
shared_ptr<const CardIndex::CardEntry> ce;
|
||||
@@ -40,11 +39,11 @@ void compute_effective_range(
|
||||
}
|
||||
}
|
||||
if (log) {
|
||||
log->debug_f("compute_effective_range: range_def: {:05X} {:05X} {:05X} {:05X} {:05X} {:05X}", range_def[0], range_def[1], range_def[2], range_def[3], range_def[4], range_def[5]);
|
||||
log->debug_f("compute_effective_range: range_def: {:05X} {:05X} {:05X} {:05X} {:05X} {:05X}",
|
||||
range_def[0], range_def[1], range_def[2], range_def[3], range_def[4], range_def[5]);
|
||||
}
|
||||
|
||||
if (range_def[0] == 0x000FFFFF) {
|
||||
// Entire field
|
||||
if (range_def[0] == 0x000FFFFF) { // Entire field
|
||||
ret.clear(2);
|
||||
if (log) {
|
||||
log->debug_f("compute_effective_range: entire field (2)");
|
||||
@@ -65,7 +64,9 @@ void compute_effective_range(
|
||||
if (log) {
|
||||
for (size_t y = 0; y < 9; y++) {
|
||||
log->debug_f("compute_effective_range: decoded_range: {:X} {:X} {:X} {:X} {:X} {:X} {:X} {:X} {:X}",
|
||||
decoded_range[y * 9 + 0], decoded_range[y * 9 + 1], decoded_range[y * 9 + 2], decoded_range[y * 9 + 3], decoded_range[y * 9 + 4], decoded_range[y * 9 + 5], decoded_range[y * 9 + 6], decoded_range[y * 9 + 7], decoded_range[y * 9 + 8]);
|
||||
decoded_range[y * 9 + 0], decoded_range[y * 9 + 1], decoded_range[y * 9 + 2],
|
||||
decoded_range[y * 9 + 3], decoded_range[y * 9 + 4], decoded_range[y * 9 + 5],
|
||||
decoded_range[y * 9 + 6], decoded_range[y * 9 + 7], decoded_range[y * 9 + 8]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +99,8 @@ void compute_effective_range(
|
||||
}
|
||||
ret[y * 9 + x] = decoded_range[up_y * 9 + up_x];
|
||||
if (log) {
|
||||
log->debug_f("compute_effective_range: x={} y={} up_x={} up_y={} v={:X}", x, y, up_x, up_y, ret[y * 9 + x]);
|
||||
log->debug_f(
|
||||
"compute_effective_range: x={} y={} up_x={} up_y={} v={:X}", x, y, up_x, up_y, ret[y * 9 + x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,7 +110,8 @@ void compute_effective_range(
|
||||
if (log) {
|
||||
for (size_t y = 0; y < 9; y++) {
|
||||
log->debug_f("compute_effective_range: ret: {:X} {:X} {:X} {:X} {:X} {:X} {:X} {:X} {:X}",
|
||||
ret[y * 9 + 0], ret[y * 9 + 1], ret[y * 9 + 2], ret[y * 9 + 3], ret[y * 9 + 4], ret[y * 9 + 5], ret[y * 9 + 6], ret[y * 9 + 7], ret[y * 9 + 8]);
|
||||
ret[y * 9 + 0], ret[y * 9 + 1], ret[y * 9 + 2], ret[y * 9 + 3], ret[y * 9 + 4],
|
||||
ret[y * 9 + 5], ret[y * 9 + 6], ret[y * 9 + 7], ret[y * 9 + 8]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,9 +127,7 @@ bool card_linkage_is_valid(
|
||||
|
||||
bool sc_is_named_android_without_permission_effect = false;
|
||||
bool sc_is_named_android = sc_ce->def.is_named_android_sc();
|
||||
if (sc_is_named_android &&
|
||||
!has_permission_effect &&
|
||||
(left_ce->def.type == CardType::ITEM)) {
|
||||
if (sc_is_named_android && !has_permission_effect && (left_ce->def.type == CardType::ITEM)) {
|
||||
sc_is_named_android_without_permission_effect = true;
|
||||
}
|
||||
|
||||
@@ -136,8 +137,7 @@ bool card_linkage_is_valid(
|
||||
|
||||
for (size_t x = 0; x < 8; x++) {
|
||||
uint8_t right_color = left_ce->def.right_colors[x];
|
||||
if ((right_color != 0) &&
|
||||
(!sc_is_named_android_without_permission_effect || (right_color != 3))) {
|
||||
if ((right_color != 0) && (!sc_is_named_android_without_permission_effect || (right_color != 3))) {
|
||||
for (size_t y = 0; y < 8; y++) {
|
||||
if (right_color == right_ce->def.left_colors[y]) {
|
||||
return true;
|
||||
@@ -146,15 +146,13 @@ bool card_linkage_is_valid(
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, then the linkage does not make sense based only on the
|
||||
// cards' left/right colors. It may still be allowed if Permission is in
|
||||
// effect, though.
|
||||
// If we get here, then the linkage does not make sense based only on the cards' left/right colors. It may still be
|
||||
// allowed if Permission is in effect, though.
|
||||
|
||||
// Ignore Permission effect if the left card is another action card (the Tech
|
||||
// color linkage must make sense in that case). (The way they do this is kind
|
||||
// of dumb - they should have checked that type == ACTION, but instead they
|
||||
// checked that type *isn't* most of the other types... but curiously, ASSIST
|
||||
// is not checked. This is probably just an oversight.)
|
||||
// Ignore Permission effect if the left card is another action card (the Tech color linkage must make sense in that
|
||||
// case). (The way they do this is kind of dumb - they should have checked that type == ACTION, but instead they
|
||||
// checked that type *isn't* most of the other types... but curiously, ASSIST is not checked. This is probably just
|
||||
// an oversight.)
|
||||
if (has_permission_effect &&
|
||||
(left_ce->def.type != CardType::HUNTERS_SC) &&
|
||||
(left_ce->def.type != CardType::ARKZ_SC) &&
|
||||
@@ -198,17 +196,14 @@ shared_ptr<const Server> RulerServer::server() const {
|
||||
return s;
|
||||
}
|
||||
|
||||
ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(
|
||||
uint16_t card_ref) {
|
||||
ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(uint16_t card_ref) {
|
||||
return const_cast<ActionChainWithConds*>(as_const(*this).action_chain_with_conds_for_card_ref(card_ref));
|
||||
}
|
||||
|
||||
const ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(
|
||||
uint16_t card_ref) const {
|
||||
const ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(uint16_t card_ref) const {
|
||||
uint8_t client_id = client_id_for_card_ref(card_ref);
|
||||
if (client_id != 0xFF) {
|
||||
// There appears to be a bug in Trial Edition: the bound on this loop is
|
||||
// 0x10, not 9.
|
||||
// There appears to be a bug in Trial Edition: the bound on this loop is 0x10, not 9.
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
const auto* chain = &this->set_card_action_chains[client_id]->at(z);
|
||||
if (card_ref == chain->chain.acting_card_ref) {
|
||||
@@ -219,8 +214,7 @@ const ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool RulerServer::any_attack_action_card_is_support_tech_or_support_pb(
|
||||
const ActionState& pa) const {
|
||||
bool RulerServer::any_attack_action_card_is_support_tech_or_support_pb(const ActionState& pa) const {
|
||||
if (pa.attacker_card_ref != 0xFFFF) {
|
||||
for (size_t z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
uint16_t card_id = this->card_id_for_card_ref(pa.action_card_refs[z]);
|
||||
@@ -292,8 +286,7 @@ bool RulerServer::card_has_pierce_or_rampage(
|
||||
const auto& sc_status = short_statuses->at(0);
|
||||
auto ce = this->definition_for_card_ref(sc_status.card_ref);
|
||||
// This appears to be an NTE bug: Major Pierce doesn't work on Arkz SCs.
|
||||
if (ce &&
|
||||
(!is_nte || (ce->def.type == CardType::HUNTERS_SC)) &&
|
||||
if (ce && (!is_nte || (ce->def.type == CardType::HUNTERS_SC)) &&
|
||||
(this->get_card_ref_max_hp(sc_status.card_ref) <= sc_status.current_hp * 2)) {
|
||||
return ret;
|
||||
}
|
||||
@@ -354,8 +347,7 @@ bool RulerServer::attack_action_has_rampage_and_not_pierce(const ActionState& pa
|
||||
}
|
||||
}
|
||||
|
||||
const auto* chain = this->action_chain_with_conds_for_card_ref(
|
||||
pa.attacker_card_ref);
|
||||
const auto* chain = this->action_chain_with_conds_for_card_ref(pa.attacker_card_ref);
|
||||
if (chain) {
|
||||
for (ssize_t z = 8; z >= 0; z--) {
|
||||
bool has_rampage = this->check_pierce_and_rampage(
|
||||
@@ -396,7 +388,8 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(const ActionState& pa
|
||||
}
|
||||
if ((card_ref1 != 0xFFFF) &&
|
||||
(card_ref1 != pa.attacker_card_ref) &&
|
||||
!this->check_usability_or_apply_condition_for_card_refs(card_ref1, pa.attacker_card_ref, stat->at(0).card_ref, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
!this->check_usability_or_apply_condition_for_card_refs(
|
||||
card_ref1, pa.attacker_card_ref, stat->at(0).card_ref, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -433,8 +426,7 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(const ActionState& pa
|
||||
}
|
||||
|
||||
for (; last_action_card_index >= 0; last_action_card_index--) {
|
||||
auto ce = this->definition_for_card_ref(
|
||||
pa.action_card_refs[last_action_card_index]);
|
||||
auto ce = this->definition_for_card_ref(pa.action_card_refs[last_action_card_index]);
|
||||
if (!ce) {
|
||||
continue;
|
||||
}
|
||||
@@ -560,8 +552,7 @@ bool RulerServer::card_ref_can_attack(uint16_t card_ref) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(
|
||||
client_id);
|
||||
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(client_id);
|
||||
for (size_t z = 0; z < num_assists; z++) {
|
||||
if (this->assist_server->get_active_assist_by_index(z) == AssistEffect::PERMISSION) {
|
||||
return true;
|
||||
@@ -571,8 +562,7 @@ bool RulerServer::card_ref_can_attack(uint16_t card_ref) {
|
||||
return !ce->def.cannot_attack;
|
||||
}
|
||||
|
||||
bool RulerServer::card_ref_can_move(
|
||||
uint8_t client_id, uint16_t card_ref, bool ignore_atk_points) const {
|
||||
bool RulerServer::card_ref_can_move(uint8_t client_id, uint16_t card_ref, bool ignore_atk_points) const {
|
||||
if (client_id == 0xFF) {
|
||||
return false;
|
||||
}
|
||||
@@ -644,8 +634,7 @@ bool RulerServer::card_ref_can_move(
|
||||
}
|
||||
}
|
||||
|
||||
bool RulerServer::card_ref_has_class_usability_condition(
|
||||
uint16_t card_ref) const {
|
||||
bool RulerServer::card_ref_has_class_usability_condition(uint16_t card_ref) const {
|
||||
auto ce = this->definition_for_card_ref(card_ref);
|
||||
if (ce) {
|
||||
uint8_t criterion = static_cast<uint8_t>(ce->def.usable_criterion);
|
||||
@@ -685,8 +674,7 @@ bool RulerServer::card_ref_is_aerial(uint16_t card_ref) const {
|
||||
return this->find_condition_on_card_ref(card_ref, ConditionType::AERIAL);
|
||||
}
|
||||
|
||||
bool RulerServer::card_ref_is_aerial_or_has_free_maneuver(
|
||||
uint16_t card_ref) const {
|
||||
bool RulerServer::card_ref_is_aerial_or_has_free_maneuver(uint16_t card_ref) const {
|
||||
return (this->card_ref_has_free_maneuver(card_ref) || this->card_ref_is_aerial(card_ref));
|
||||
}
|
||||
|
||||
@@ -694,8 +682,7 @@ bool RulerServer::card_ref_is_boss_sc(uint32_t card_ref) const {
|
||||
return this->card_id_is_boss_sc(this->card_id_for_card_ref(card_ref));
|
||||
}
|
||||
|
||||
bool RulerServer::card_ref_or_any_set_card_has_condition_46(
|
||||
uint16_t card_ref) const {
|
||||
bool RulerServer::card_ref_or_any_set_card_has_condition_46(uint16_t card_ref) const {
|
||||
uint16_t card_id = this->card_id_for_card_ref(card_ref);
|
||||
if (card_id == 0xFFFF) {
|
||||
return false;
|
||||
@@ -752,8 +739,7 @@ bool RulerServer::card_ref_or_sc_has_fixed_range(uint16_t card_ref) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->find_condition_on_card_ref(
|
||||
this->short_statuses[client_id]->at(0).card_ref, ConditionType::FIXED_RANGE);
|
||||
return this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::FIXED_RANGE);
|
||||
}
|
||||
|
||||
bool RulerServer::check_move_path_and_get_cost(
|
||||
@@ -772,9 +758,8 @@ bool RulerServer::check_move_path_and_get_cost(
|
||||
}
|
||||
|
||||
uint8_t atk = this->hand_and_equip_states[client_id]->atk_points;
|
||||
// Note: In the original code, it seems atk was signed, which doesn't make
|
||||
// much sense. We've fixed that here.
|
||||
// if (atk < 0) { // Uhhh what? This is supposed to be impossible
|
||||
// Note: In the original code, it seems atk was signed, which doesn't make much sense.
|
||||
// if (atk < 0) { // This is supposed to be impossible
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@@ -833,8 +818,7 @@ bool RulerServer::check_pierce_and_rampage(
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((card_ref != 0xFFFF) &&
|
||||
(!card_short_status || !this->card_exists_by_status(*card_short_status))) {
|
||||
if ((card_ref != 0xFFFF) && (!card_short_status || !this->card_exists_by_status(*card_short_status))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -971,8 +955,7 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
}
|
||||
log.debug_f("criterion_code={}", phosg::name_for_enum(criterion_code));
|
||||
|
||||
// For item usability checks, prevent criteria that depend on player
|
||||
// positioning/team setup
|
||||
// For item usability checks, prevent criteria that depend on player positioning/team setup
|
||||
if (is_item_usability_check &&
|
||||
((criterion_code == CriterionCode::SAME_TEAM) ||
|
||||
(criterion_code == CriterionCode::SAME_PLAYER) ||
|
||||
@@ -984,13 +967,11 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
criterion_code = CriterionCode::NONE;
|
||||
}
|
||||
|
||||
// Presumably this odd-looking expression here is used to handle two different
|
||||
// cases. When checking for a condition, def_effect_index should be non-0xFF,
|
||||
// so we'd return true if the criterion passes. When checking if an item or
|
||||
// creature card is usable, the two client IDs should be the same or the
|
||||
// second should not be given, so we'd return true if the criterion passes. If
|
||||
// neither of these cases apply, we should return false as a failsafe even if
|
||||
// the criterion passes. NTE did not have such a check.
|
||||
// Presumably this odd-looking expression here is used to handle two different cases. When checking for a condition,
|
||||
// def_effect_index should be non-0xFF, so we'd return true if the criterion passes. When checking if an item or
|
||||
// creature card is usable, the two client IDs should be the same or the second should not be given, so we'd return
|
||||
// true if the criterion passes. If neither of these cases apply, we should return false as a failsafe even if the
|
||||
// criterion passes. NTE did not have such a check.
|
||||
bool ret = is_nte || (!(def_effect_index & 0x80) || (client_id1 == client_id2)) || (client_id2 == 0xFF);
|
||||
switch (criterion_code) {
|
||||
case CriterionCode::NONE:
|
||||
@@ -1359,9 +1340,7 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
}
|
||||
|
||||
uint16_t RulerServer::compute_attack_or_defense_costs(
|
||||
const ActionState& pa,
|
||||
bool allow_mighty_knuckle,
|
||||
uint8_t* out_ally_cost) const {
|
||||
const ActionState& pa, bool allow_mighty_knuckle, uint8_t* out_ally_cost) const {
|
||||
int16_t final_cost = 1;
|
||||
bool has_mighty_knuckle = false;
|
||||
int16_t cost_bias = 0;
|
||||
@@ -1383,8 +1362,7 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
|
||||
uint8_t client_id = client_id_for_card_ref(pa.attacker_card_ref);
|
||||
|
||||
uint16_t sc_card_ref_if_item = 0xFFFF;
|
||||
if ((client_id != 0xFF) && ce && (ce->def.type == CardType::ITEM) &&
|
||||
this->short_statuses[client_id]) {
|
||||
if ((client_id != 0xFF) && ce && (ce->def.type == CardType::ITEM) && this->short_statuses[client_id]) {
|
||||
sc_card_ref_if_item = this->short_statuses[client_id]->at(0).card_ref;
|
||||
}
|
||||
|
||||
@@ -1514,8 +1492,7 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
|
||||
if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) {
|
||||
target_mode = sc_ce->def.target_mode;
|
||||
const char* target_mode_name = name_for_target_mode(target_mode);
|
||||
log.debug_f("sc_ce overrides target mode with {} ({})",
|
||||
target_mode_name, static_cast<uint8_t>(target_mode));
|
||||
log.debug_f("sc_ce overrides target mode with {} ({})", target_mode_name, static_cast<uint8_t>(target_mode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1568,9 +1545,7 @@ size_t RulerServer::count_rampage_targets_for_attack(const ActionState& pa, uint
|
||||
}
|
||||
|
||||
bool RulerServer::defense_card_can_apply_to_attack(
|
||||
uint16_t defense_card_ref,
|
||||
uint16_t attacker_card_ref,
|
||||
uint16_t attacker_sc_card_ref) const {
|
||||
uint16_t defense_card_ref, uint16_t attacker_card_ref, uint16_t attacker_sc_card_ref) const {
|
||||
uint16_t defense_card_id = this->card_id_for_card_ref(defense_card_ref);
|
||||
uint16_t attacker_sc_card_id = this->card_id_for_card_ref(attacker_sc_card_ref);
|
||||
uint16_t attacker_card_id = this->card_id_for_card_ref(attacker_card_ref);
|
||||
@@ -1654,8 +1629,7 @@ bool RulerServer::defense_card_matches_any_attack_card_top_color(const ActionSta
|
||||
if (!ce) {
|
||||
throw runtime_error("defense card definition is missing");
|
||||
}
|
||||
const auto* chain = this->action_chain_with_conds_for_card_ref(
|
||||
pa.original_attacker_card_ref);
|
||||
const auto* chain = this->action_chain_with_conds_for_card_ref(pa.original_attacker_card_ref);
|
||||
if (chain->chain.attack_action_card_ref_count < 1) {
|
||||
auto other_ce = this->definition_for_card_ref(pa.original_attacker_card_ref);
|
||||
if (other_ce && other_ce->def.any_top_color_matches(ce->def)) {
|
||||
@@ -1681,10 +1655,7 @@ shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_ref(uint
|
||||
}
|
||||
|
||||
int32_t RulerServer::error_code_for_client_setting_card(
|
||||
uint8_t client_id,
|
||||
uint16_t card_ref,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id) const {
|
||||
uint8_t client_id, uint16_t card_ref, const Location* loc, uint8_t assist_target_client_id) const {
|
||||
if (client_id > 3) {
|
||||
return -0x7D;
|
||||
}
|
||||
@@ -1843,8 +1814,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
|
||||
if (!this->get_creature_summon_area(client_id, &summon_area_loc, &summon_area_size)) {
|
||||
if (team_id != 1) {
|
||||
if ((loc->x > 0) && (loc->x < this->map_and_rules->map.width - 1)) {
|
||||
if ((loc->y < this->map_and_rules->map.height - summon_cost - 1) &&
|
||||
(loc->y > 0)) {
|
||||
if ((loc->y < this->map_and_rules->map.height - summon_cost - 1) && (loc->y > 0)) {
|
||||
return 0;
|
||||
}
|
||||
if (loc->y == 1) {
|
||||
@@ -1852,8 +1822,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((loc->x > 0) &&
|
||||
(loc->x < this->map_and_rules->map.width - 1)) {
|
||||
if ((loc->x > 0) && (loc->x < this->map_and_rules->map.width - 1)) {
|
||||
if ((summon_cost + 1 <= loc->y) && (loc->y < this->map_and_rules->map.height - 1)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1965,8 +1934,7 @@ bool RulerServer::flood_fill_move_path(
|
||||
size_t num_occupied_tiles,
|
||||
size_t num_vacant_tiles) const {
|
||||
auto state = this->map_and_rules;
|
||||
if ((x < 1) || (x >= state->map.width - 1) ||
|
||||
(y < 1) || (y >= state->map.height - 1)) {
|
||||
if ((x < 1) || (x >= state->map.width - 1) || (y < 1) || (y >= state->map.height - 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1979,15 +1947,12 @@ bool RulerServer::flood_fill_move_path(
|
||||
|
||||
} else {
|
||||
uint32_t cost = this->get_path_cost(
|
||||
chain,
|
||||
num_vacant_tiles + num_occupied_tiles + 1,
|
||||
is_aerial ? num_occupied_tiles : 0);
|
||||
chain, num_vacant_tiles + num_occupied_tiles + 1, is_aerial ? num_occupied_tiles : 0);
|
||||
if (max_atk_points < cost) {
|
||||
return 0;
|
||||
}
|
||||
visited_map->at(x * 0x10 + y) = 1;
|
||||
if (path && (path->end_loc.x == x) && (path->end_loc.y == y) &&
|
||||
((path->length == -1) || (cost < path->cost))) {
|
||||
if (path && (path->end_loc.x == x) && (path->end_loc.y == y) && ((path->length == -1) || (cost < path->cost))) {
|
||||
ret = true;
|
||||
path->reset_totals();
|
||||
path->remaining_distance = max_distance;
|
||||
@@ -2005,8 +1970,7 @@ bool RulerServer::flood_fill_move_path(
|
||||
|
||||
int16_t new_max_distance = max_distance - 1;
|
||||
if (new_max_distance > 0) {
|
||||
static const int8_t offsets[4][2] = {
|
||||
{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
|
||||
static const int8_t offsets[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
|
||||
Direction dirs[3] = {direction, turn_left(direction), turn_right(direction)};
|
||||
for (size_t dir_index = 0; dir_index < 3; dir_index++) {
|
||||
if (static_cast<uint8_t>(dirs[dir_index]) > 3) {
|
||||
@@ -2061,9 +2025,7 @@ uint32_t RulerServer::get_card_id_with_effective_range(
|
||||
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const {
|
||||
auto log = this->server()->log_stack(std::format("get_card_id_with_effective_range(@{:04X}, #{:04X}): ", card_ref, card_id_override));
|
||||
|
||||
uint16_t card_id = (card_id_override == 0xFFFF)
|
||||
? this->card_id_for_card_ref(card_ref)
|
||||
: card_id_override;
|
||||
uint16_t card_id = (card_id_override == 0xFFFF) ? this->card_id_for_card_ref(card_ref) : card_id_override;
|
||||
log.debug_f("card_id=#{:04X}", card_id);
|
||||
|
||||
if (card_id != 0xFFFF) {
|
||||
@@ -2079,7 +2041,8 @@ uint32_t RulerServer::get_card_id_with_effective_range(
|
||||
card_id = this->card_id_for_card_ref(card_ref);
|
||||
auto orig_ce = this->definition_for_card_id(card_id);
|
||||
if (orig_ce && (static_cast<uint8_t>(effective_target_mode) < 6)) {
|
||||
log.debug_f("ce valid for #{:04X} with effective target mode {}; overriding to {}", card_id, name_for_target_mode(effective_target_mode), name_for_target_mode(orig_ce->def.target_mode));
|
||||
log.debug_f("ce valid for #{:04X} with effective target mode {}; overriding to {}",
|
||||
card_id, name_for_target_mode(effective_target_mode), name_for_target_mode(orig_ce->def.target_mode));
|
||||
effective_target_mode = orig_ce->def.target_mode;
|
||||
}
|
||||
}
|
||||
@@ -2123,8 +2086,7 @@ uint8_t RulerServer::get_card_ref_max_hp(uint16_t card_ref) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool RulerServer::get_creature_summon_area(
|
||||
uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const {
|
||||
bool RulerServer::get_creature_summon_area(uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const {
|
||||
if (!this->map_and_rules || (client_id > 3)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2155,8 +2117,7 @@ bool RulerServer::get_creature_summon_area(
|
||||
region_size = this->map_and_rules->map.height - 3;
|
||||
break;
|
||||
default:
|
||||
// This case isn't in the original code; probably it fell through to one
|
||||
// of the above
|
||||
// This case isn't in the original code; probably it fell through to one of the above
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2169,27 +2130,20 @@ bool RulerServer::get_creature_summon_area(
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_ptr<HandAndEquipState> RulerServer::get_hand_and_equip_state_for_client_id(
|
||||
uint8_t client_id) {
|
||||
shared_ptr<HandAndEquipState> RulerServer::get_hand_and_equip_state_for_client_id(uint8_t client_id) {
|
||||
return (client_id < 4) ? this->hand_and_equip_states[client_id] : nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<const HandAndEquipState> RulerServer::get_hand_and_equip_state_for_client_id(
|
||||
uint8_t client_id) const {
|
||||
shared_ptr<const HandAndEquipState> RulerServer::get_hand_and_equip_state_for_client_id(uint8_t client_id) const {
|
||||
return (client_id < 4) ? this->hand_and_equip_states[client_id] : nullptr;
|
||||
}
|
||||
|
||||
bool RulerServer::get_move_path_length_and_cost(
|
||||
uint32_t client_id,
|
||||
uint32_t card_ref,
|
||||
const Location& loc,
|
||||
uint32_t* out_length,
|
||||
uint32_t* out_cost) const {
|
||||
uint32_t client_id, uint32_t card_ref, const Location& loc, uint32_t* out_length, uint32_t* out_cost) const {
|
||||
MovePath path;
|
||||
parray<uint8_t, 0x100> visited_map;
|
||||
path.end_loc = loc;
|
||||
if (!this->check_move_path_and_get_cost(
|
||||
client_id, card_ref, &visited_map, &path, out_cost)) {
|
||||
if (!this->check_move_path_and_get_cost(client_id, card_ref, &visited_map, &path, out_cost)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2206,9 +2160,7 @@ bool RulerServer::get_move_path_length_and_cost(
|
||||
}
|
||||
|
||||
ssize_t RulerServer::get_path_cost(
|
||||
const ActionChainWithConds& chain,
|
||||
ssize_t path_length,
|
||||
ssize_t cost_penalty) const {
|
||||
const ActionChainWithConds& chain, ssize_t path_length, ssize_t cost_penalty) const {
|
||||
for (size_t x = 0; x < 9; x++) {
|
||||
const auto& cond = chain.conditions[x];
|
||||
if (cond.type == ConditionType::SET_MV_COST_TO_0) {
|
||||
@@ -2253,13 +2205,11 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: The original code has a case here that results in error code -0x5E,
|
||||
// triggered by a function returning false. However, that function always
|
||||
// returns true and has no side effects, so we've omitted the case here.
|
||||
// Note: The original code has a case here that results in error code -0x5E, triggered by a function returning false.
|
||||
// However, that function always returns true and has no side effects, so we've omitted the case here.
|
||||
|
||||
const auto* attacker_card_status = this->short_status_for_card_ref(attacker_card_ref);
|
||||
if (!attacker_card_status ||
|
||||
!this->card_ref_can_attack(attacker_card_ref) ||
|
||||
if (!attacker_card_status || !this->card_ref_can_attack(attacker_card_ref) ||
|
||||
(attacker_card_status->card_flags & 0x500)) {
|
||||
this->error_code3 = -0x6F;
|
||||
return false;
|
||||
@@ -2272,9 +2222,7 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
|
||||
auto attacker_ce = this->definition_for_card_ref(attacker_card_ref);
|
||||
auto attacker_chain = this->action_chain_with_conds_for_card_ref(attacker_card_ref);
|
||||
if (!attacker_chain ||
|
||||
(attacker_chain->chain.acting_card_ref != attacker_card_ref) ||
|
||||
!attacker_ce ||
|
||||
if (!attacker_chain || (attacker_chain->chain.acting_card_ref != attacker_card_ref) || !attacker_ce ||
|
||||
((attacker_ce->def.type != CardType::HUNTERS_SC &&
|
||||
(attacker_ce->def.type != CardType::ARKZ_SC) &&
|
||||
(attacker_ce->def.type != CardType::CREATURE) &&
|
||||
@@ -2313,7 +2261,9 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto left_card_ce = (z == 0) ? this->definition_for_card_ref(card_ref) : this->definition_for_card_ref(pa.action_card_refs[z - 1]);
|
||||
auto left_card_ce = (z == 0)
|
||||
? this->definition_for_card_ref(card_ref)
|
||||
: this->definition_for_card_ref(pa.action_card_refs[z - 1]);
|
||||
auto right_card_ce = this->definition_for_card_ref(right_card_ref);
|
||||
|
||||
if (right_card_ce->def.type != CardType::ACTION) {
|
||||
@@ -2326,7 +2276,9 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
}
|
||||
|
||||
uint8_t attacker_client_id = client_id_for_card_ref(pa.attacker_card_ref);
|
||||
auto sc_ce = (attacker_client_id != 0xFF) ? this->definition_for_card_ref(this->set_card_action_chains[attacker_client_id]->at(0).chain.acting_card_ref) : nullptr;
|
||||
auto sc_ce = (attacker_client_id != 0xFF)
|
||||
? this->definition_for_card_ref(this->set_card_action_chains[attacker_client_id]->at(0).chain.acting_card_ref)
|
||||
: nullptr;
|
||||
|
||||
if (!card_linkage_is_valid(right_card_ce, left_card_ce, sc_ce, has_permission_effect)) {
|
||||
this->error_code3 = -0x6B;
|
||||
@@ -2363,8 +2315,7 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
}
|
||||
|
||||
bool RulerServer::is_attack_or_defense_valid(const ActionState& pa) {
|
||||
// This error code is present in the original code, but is no longer possible
|
||||
// since we require pa instead of using a pointer.
|
||||
// This error code is present in the original code, but is no longer possible since we require pa instead.
|
||||
// if (!pa) {
|
||||
// this->error_code3 = -0x78;
|
||||
// return false;
|
||||
@@ -2450,9 +2401,8 @@ bool RulerServer::is_defense_valid(const ActionState& pa) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: The original code has a case here that results in error code -0x5E,
|
||||
// triggered by a function returning false. However, that function always
|
||||
// returns true and has no side effects, so we've omitted the case here.
|
||||
// Note: The original code has a case here that results in error code -0x5E, triggered by a function returning false.
|
||||
// However, that function always returns true and has no side effects, so we've omitted the case here.
|
||||
|
||||
const auto* stat = this->short_status_for_card_ref(pa.target_card_refs[0]);
|
||||
if ((!stat || !this->card_exists_by_status(*stat)) || (stat->card_flags & 0x800)) {
|
||||
@@ -2590,9 +2540,8 @@ bool RulerServer::MovePath::is_valid() const {
|
||||
|
||||
void RulerServer::offsets_for_direction(
|
||||
const Location& loc, int32_t* out_x_offset, int32_t* out_y_offset) {
|
||||
// Note: This function has opposite behavior for the UP and DOWN directions
|
||||
// as compared to the global array of the same name.
|
||||
// TODO: Figure out why this difference exists and document it.
|
||||
// Note: This function has opposite behavior for the UP and DOWN directions as compared to the global array of the
|
||||
// same name. TODO: Figure out why this difference exists and document it.
|
||||
switch (loc.direction) {
|
||||
case Direction::LEFT:
|
||||
*out_x_offset = -1;
|
||||
@@ -2629,8 +2578,7 @@ void RulerServer::register_player(
|
||||
this->set_card_action_metadatas[client_id] = set_card_action_metadatas;
|
||||
}
|
||||
|
||||
void RulerServer::replace_D1_D2_rank_cards_with_Attack(
|
||||
parray<le_uint16_t, 0x1F>& card_ids) const {
|
||||
void RulerServer::replace_D1_D2_rank_cards_with_Attack(parray<le_uint16_t, 0x1F>& card_ids) const {
|
||||
for (size_t z = 0; z < card_ids.size(); z++) {
|
||||
auto ce = this->definition_for_card_id(card_ids[z]);
|
||||
if (ce && ((ce->def.rank == CardRank::D1) || (ce->def.rank == CardRank::D2))) {
|
||||
@@ -2737,8 +2685,7 @@ bool RulerServer::should_allow_attacks_on_current_turn() const {
|
||||
}
|
||||
|
||||
int32_t RulerServer::verify_deck(
|
||||
const parray<le_uint16_t, 0x1F>& card_ids,
|
||||
const parray<uint8_t, 0x2F0>* owned_card_counts) const {
|
||||
const parray<le_uint16_t, 0x1F>& card_ids, const parray<uint8_t, 0x2F0>* owned_card_counts) const {
|
||||
for (size_t z = 0; z < card_ids.size(); z++) {
|
||||
if (!this->definition_for_card_id(card_ids.at(z))) {
|
||||
return -0x7C;
|
||||
|
||||
@@ -152,8 +152,7 @@ public:
|
||||
uint32_t get_card_id_with_effective_range(
|
||||
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const;
|
||||
uint8_t get_card_ref_max_hp(uint16_t card_ref) const;
|
||||
bool get_creature_summon_area(
|
||||
uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const;
|
||||
bool get_creature_summon_area(uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const;
|
||||
std::shared_ptr<HandAndEquipState> get_hand_and_equip_state_for_client_id(uint8_t client_id);
|
||||
std::shared_ptr<const HandAndEquipState> get_hand_and_equip_state_for_client_id(uint8_t client_id) const;
|
||||
bool get_move_path_length_and_cost(
|
||||
@@ -191,8 +190,7 @@ public:
|
||||
const CardShortStatus* short_status_for_card_ref(uint16_t card_ref) const;
|
||||
bool should_allow_attacks_on_current_turn() const;
|
||||
int32_t verify_deck(
|
||||
const parray<le_uint16_t, 0x1F>& card_ids,
|
||||
const parray<uint8_t, 0x2F0>* owned_card_counts = nullptr) const;
|
||||
const parray<le_uint16_t, 0x1F>& card_ids, const parray<uint8_t, 0x2F0>* owned_card_counts = nullptr) const;
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
|
||||
+109
-141
@@ -12,12 +12,10 @@ using namespace std;
|
||||
namespace Episode3 {
|
||||
|
||||
// This is (obviously) not the original string. The original string is:
|
||||
// "03/05/29 18:00 by K.Toya" (NTE)
|
||||
// "[V1][FINAL2.0] 03/09/13 15:30 by K.Toya" (Final)
|
||||
static const char* VERSION_SIGNATURE =
|
||||
"newserv Ep3 based on [V1][FINAL2.0] 03/09/13 15:30 by K.Toya";
|
||||
static const char* VERSION_SIGNATURE_NTE =
|
||||
"newserv Ep3 NTE based on 03/05/29 18:00 by K.Toya";
|
||||
// NTE: "03/05/29 18:00 by K.Toya"
|
||||
// Final: "[V1][FINAL2.0] 03/09/13 15:30 by K.Toya"
|
||||
static const char* VERSION_SIGNATURE = "newserv Ep3 based on [V1][FINAL2.0] 03/09/13 15:30 by K.Toya";
|
||||
static const char* VERSION_SIGNATURE_NTE = "newserv Ep3 NTE based on 03/05/29 18:00 by K.Toya";
|
||||
|
||||
Server::PresenceEntry::PresenceEntry() {
|
||||
this->clear();
|
||||
@@ -103,10 +101,9 @@ void Server::init() {
|
||||
|
||||
this->card_special = make_shared<CardSpecial>(this->shared_from_this());
|
||||
|
||||
// Note: The original implementation calls the default PSOV2Encryption
|
||||
// constructor for random_crypt, which just uses 0 as the seed. It then
|
||||
// re-seeds the generator later. We instead expect the caller to provide a
|
||||
// seeded generator, and we don't re-seed it at all.
|
||||
// Note: The original implementation calls the default PSOV2Encryption constructor for random_crypt, which just uses
|
||||
// 0 as the seed. It then re-seeds the generator later. We instead expect the caller to provide a seeded generator,
|
||||
// and we don't re-seed it at all.
|
||||
// this->random_crypt = make_shared<PSOV2Encryption>(0);
|
||||
|
||||
this->state_flags = make_shared<StateFlags>();
|
||||
@@ -231,6 +228,11 @@ int8_t Server::get_winner_team_id() const {
|
||||
|
||||
void Server::send(const void* data, size_t size, uint8_t command, bool enable_masking) const {
|
||||
// Note: This function is (obviously) not part of the original implementation.
|
||||
|
||||
if (this->options.output_queue) {
|
||||
this->options.output_queue->emplace_back(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
|
||||
if (this->has_lobby) {
|
||||
auto l = this->lobby.lock();
|
||||
if (!l) {
|
||||
@@ -249,10 +251,6 @@ void Server::send(const void* data, size_t size, uint8_t command, bool enable_ma
|
||||
size = masked_data.size();
|
||||
}
|
||||
|
||||
// Note: Sega's servers sent battle commands with the 60 command. The handlers
|
||||
// for 60, 62, and C9 on the client are identical, so we choose to use C9
|
||||
// instead because it's unique to Episode 3, and therefore seems more
|
||||
// appropriate to convey battle commands.
|
||||
send_command(l, command, 0x00, data, size);
|
||||
for (auto watcher_l : l->watcher_lobbies) {
|
||||
send_command_if_not_loading(watcher_l, command, 0x00, data, size);
|
||||
@@ -268,49 +266,45 @@ void Server::send(const void* data, size_t size, uint8_t command, bool enable_ma
|
||||
}
|
||||
|
||||
void Server::send_6xB4x46() const {
|
||||
// Note: This function is not part of the original implementation; it was
|
||||
// factored out from its callsites in this file and the strings were changed.
|
||||
// Note: This function is not part of the original implementation; it was factored out from its callsites in this
|
||||
// file and the strings were changed.
|
||||
|
||||
// NTE doesn't have the date_str2 field, but we send it anyway to make
|
||||
// debugging easier.
|
||||
// NTE doesn't have the date_str2 field, but we send it anyway to make debugging easier.
|
||||
G_ServerVersionStrings_Ep3_6xB4x46 cmd;
|
||||
cmd.version_signature.encode(this->options.is_nte() ? VERSION_SIGNATURE_NTE : VERSION_SIGNATURE, 1);
|
||||
cmd.date_str1.encode(std::format("Card definitions: {:016X}", this->options.card_index->definitions_hash()), 1);
|
||||
cmd.version_signature.encode(this->options.is_nte() ? VERSION_SIGNATURE_NTE : VERSION_SIGNATURE, Language::ENGLISH);
|
||||
cmd.date_str1.encode(
|
||||
std::format("Card definitions: {:016X}", this->options.card_index->definitions_hash()),
|
||||
Language::ENGLISH);
|
||||
string build_date = phosg::format_time(BUILD_TIMESTAMP);
|
||||
cmd.date_str2.encode(std::format("newserv {} compiled at {}", GIT_REVISION_HASH, build_date), 1);
|
||||
cmd.date_str2.encode(std::format("newserv {} compiled at {}", GIT_REVISION_HASH, build_date), Language::ENGLISH);
|
||||
this->send(cmd);
|
||||
}
|
||||
|
||||
string Server::prepare_6xB6x41_map_definition(shared_ptr<const MapIndex::Map> map, uint8_t language, bool is_nte) {
|
||||
string Server::prepare_6xB6x41_map_definition(shared_ptr<const MapIndex::Map> map, Language language, bool is_nte) {
|
||||
auto vm = map->version(language);
|
||||
|
||||
const auto& compressed = vm->compressed(is_nte);
|
||||
|
||||
phosg::StringWriter w;
|
||||
uint32_t subcommand_size = (compressed->size() + sizeof(G_MapData_Ep3_6xB6x41) + 3) & (~3);
|
||||
w.put<G_MapData_Ep3_6xB6x41>({{{{0xB6, 0, 0}, subcommand_size}, 0x41, {}}, vm->map->map_number.load(), compressed->size(), 0});
|
||||
w.put<G_MapData_Ep3_6xB6x41>(
|
||||
{{{{0xB6, 0, 0}, subcommand_size}, 0x41, {}}, vm->map->map_number.load(), compressed->size(), 0});
|
||||
w.write(*compressed);
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
void Server::send_commands_for_joining_spectator(std::shared_ptr<Channel> ch) const {
|
||||
bool should_send_state = true;
|
||||
if (this->setup_phase == SetupPhase::REGISTRATION) {
|
||||
// If registration is still in progress, we only need to send the map data
|
||||
// (if a map is even chosen yet)
|
||||
if ((this->registration_phase != RegistrationPhase::REGISTERED) &&
|
||||
(this->registration_phase != RegistrationPhase::BATTLE_STARTED)) {
|
||||
should_send_state = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->last_chosen_map) {
|
||||
string data = this->prepare_6xB6x41_map_definition(this->last_chosen_map, ch->language, this->options.is_nte());
|
||||
this->log().info_f("Sending {} version of map {:08X}", char_for_language_code(ch->language), this->last_chosen_map->map_number);
|
||||
this->log().info_f(
|
||||
"Sending {} version of map {:08X}", name_for_language(ch->language), this->last_chosen_map->map_number);
|
||||
ch->send(0x6C, 0x00, data);
|
||||
}
|
||||
|
||||
if (should_send_state) {
|
||||
// If registration is still in progress, we don't need to send the battle state
|
||||
if ((this->setup_phase != SetupPhase::REGISTRATION) ||
|
||||
(this->registration_phase == RegistrationPhase::REGISTERED) ||
|
||||
(this->registration_phase == RegistrationPhase::BATTLE_STARTED)) {
|
||||
ch->send(0xC9, 0x00, this->prepare_6xB4x03());
|
||||
for (uint8_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->player_states[client_id];
|
||||
@@ -334,8 +328,8 @@ void Server::send_commands_for_joining_spectator(std::shared_ptr<Channel> ch) co
|
||||
// (send 6xB4x4F for client_id)
|
||||
// }
|
||||
ch->send(0xC9, 0x00, this->prepare_6xB4x07_decks_update());
|
||||
// TODO: Sega sends 6xB4x05 here again; why? Is that necessary? They also
|
||||
// send 6xB4x02 again for each player after that (but not 6xB4x04)
|
||||
// TODO: Sega sends 6xB4x05 here again; why? Is that necessary? They also send 6xB4x02 again for each player after
|
||||
// that (but not 6xB4x04)
|
||||
ch->send(0xC9, 0x00, this->prepare_6xB4x1C_names_update());
|
||||
ch->send(0xC9, 0x00, this->prepare_6xB4x50_trap_tile_locations());
|
||||
{
|
||||
@@ -592,7 +586,14 @@ void Server::force_replace_assist_card(uint8_t client_id, uint16_t card_id) {
|
||||
if (!ps) {
|
||||
throw runtime_error("player does not exist");
|
||||
}
|
||||
ps->replace_assist_card_by_id(card_id);
|
||||
if (card_id == 0xFFFF) {
|
||||
ps->discard_set_assist_card();
|
||||
this->check_for_destroyed_cards_and_send_6xB4x05_6xB4x02();
|
||||
this->check_for_battle_end();
|
||||
|
||||
} else {
|
||||
ps->replace_assist_card_by_id(card_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Server::force_destroy_field_character(uint8_t client_id, size_t visible_index) {
|
||||
@@ -601,8 +602,8 @@ void Server::force_destroy_field_character(uint8_t client_id, size_t visible_ind
|
||||
throw runtime_error("player does not exist");
|
||||
}
|
||||
|
||||
// TODO: Is it possible for there to be gaps in the set cards array? If not,
|
||||
// we could just do a direct array lookup here instead of this loop
|
||||
// TODO: Is it possible for there to be gaps in the set cards array? If not, we could just do a direct array lookup
|
||||
// here instead of this loop
|
||||
shared_ptr<Card> set_card = nullptr;
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
if (!ps->set_cards[set_index]) {
|
||||
@@ -651,9 +652,7 @@ void Server::check_for_destroyed_cards_and_send_6xB4x05_6xB4x02() {
|
||||
}
|
||||
|
||||
bool Server::check_presence_entry(uint8_t client_id) const {
|
||||
return (client_id < 4)
|
||||
? this->presence_entries[client_id].player_present
|
||||
: false;
|
||||
return (client_id < 4) ? this->presence_entries[client_id].player_present : false;
|
||||
}
|
||||
|
||||
void Server::clear_player_flags_after_dice_phase() {
|
||||
@@ -814,9 +813,8 @@ void Server::draw_phase_after() {
|
||||
|
||||
if (this->current_team_turn1 == this->first_team_turn) {
|
||||
if (this->map_and_rules->rules.overall_time_limit > 0) {
|
||||
// Battle time limits are specified in increments of 5 minutes.
|
||||
// Note: This part is not based on the original code because the timing
|
||||
// facilities used are different.
|
||||
// Battle time limits are specified in increments of 5 minutes. This part is not based on the original code
|
||||
// because the timing facilities used are different.
|
||||
uint64_t limit_5mins = this->map_and_rules->rules.overall_time_limit;
|
||||
uint64_t end_usecs = this->battle_start_usecs + (limit_5mins * 300 * 1000 * 1000);
|
||||
if (phosg::now() >= end_usecs) {
|
||||
@@ -912,9 +910,8 @@ void Server::end_attack_list_for_client(uint8_t client_id) {
|
||||
void Server::end_action_phase() {
|
||||
this->num_pending_attacks = 0;
|
||||
this->unknown_a15 = 1;
|
||||
// Annoyingly, this is the original logic. We use an enum because it appears
|
||||
// that this can only ever be 0 or 2, but we may have to delete the enum if
|
||||
// that turns out to be false.
|
||||
// Annoyingly, this is the original logic. We use an enum because it appears that this can only ever be 0 or 2, but
|
||||
// we may have to delete the enum if that turns out to be false.
|
||||
this->action_subphase = static_cast<ActionSubphase>(static_cast<uint8_t>(this->action_subphase) + 2);
|
||||
if (this->options.is_nte()) {
|
||||
this->unknown_8023EEF4();
|
||||
@@ -993,8 +990,7 @@ bool Server::enqueue_attack_or_defense(uint8_t client_id, ActionState* pa) {
|
||||
card_ps->send_6xB4x04_if_needed();
|
||||
}
|
||||
}
|
||||
card = this->card_for_set_card_ref(this->send_6xB4x06_if_card_ref_invalid(
|
||||
pa->original_attacker_card_ref, 2));
|
||||
card = this->card_for_set_card_ref(this->send_6xB4x06_if_card_ref_invalid(pa->original_attacker_card_ref, 2));
|
||||
if (card) {
|
||||
card = this->card_for_set_card_ref(pa->target_card_refs[0]);
|
||||
if (card) {
|
||||
@@ -1088,8 +1084,7 @@ void Server::move_phase_after() {
|
||||
auto ps = this->player_states[client_id];
|
||||
if (ps) {
|
||||
auto sc_card = ps->get_sc_card();
|
||||
if (sc_card && (sc_card->card_flags & 0x80) &&
|
||||
(sc_card->loc.x == trap_x) && (sc_card->loc.y == trap_y)) {
|
||||
if (sc_card && (sc_card->card_flags & 0x80) && (sc_card->loc.x == trap_x) && (sc_card->loc.y == trap_y)) {
|
||||
should_trigger = true;
|
||||
break;
|
||||
}
|
||||
@@ -1099,7 +1094,7 @@ void Server::move_phase_after() {
|
||||
continue;
|
||||
}
|
||||
|
||||
static const array<vector<uint16_t>, 5> default_trap_card_ids = {
|
||||
static const array<vector<uint16_t>, 5> DEFAULT_TRAP_CARD_IDS = {
|
||||
// Red: Dice Fever, Heavy Fog, Muscular, Immortality, Snail Pace
|
||||
vector<uint16_t>{0x00F7, 0x010F, 0x012E, 0x013B, 0x013C},
|
||||
// Blue: Gold Rush, Charity, Requiem
|
||||
@@ -1113,7 +1108,7 @@ void Server::move_phase_after() {
|
||||
|
||||
const vector<uint16_t>* trap_card_ids = &this->options.trap_card_ids.at(trap_type);
|
||||
if (trap_card_ids->empty()) {
|
||||
trap_card_ids = &default_trap_card_ids.at(trap_type);
|
||||
trap_card_ids = &DEFAULT_TRAP_CARD_IDS.at(trap_type);
|
||||
}
|
||||
|
||||
// This is the original implementation. We do something smarter instead.
|
||||
@@ -1133,9 +1128,7 @@ void Server::move_phase_after() {
|
||||
auto ps = this->player_states[client_id];
|
||||
if (ps) {
|
||||
auto sc_card = ps->get_sc_card();
|
||||
if (sc_card &&
|
||||
(abs(sc_card->loc.x - trap_x) < 2) &&
|
||||
(abs(sc_card->loc.y - trap_y) < 2) &&
|
||||
if (sc_card && (abs(sc_card->loc.x - trap_x) < 2) && (abs(sc_card->loc.y - trap_y) < 2) &&
|
||||
ps->replace_assist_card_by_id(trap_card_id)) {
|
||||
G_EnqueueAnimation_Ep3_6xB4x2C cmd;
|
||||
cmd.change_type = 0x01;
|
||||
@@ -1161,14 +1154,12 @@ void Server::move_phase_after() {
|
||||
// this->chosen_trap_tile_index_of_type[trap_type] = new_index;
|
||||
// this->send_6xB4x50();
|
||||
// }
|
||||
// We instead use an implementation that consumes a constant amount of
|
||||
// randomness per pass.
|
||||
// We instead use an implementation that consumes a constant amount of randomness per pass.
|
||||
if (this->num_trap_tiles_of_type[trap_type] == 2) {
|
||||
this->chosen_trap_tile_index_of_type[trap_type] ^= 1;
|
||||
this->send_6xB4x50_trap_tile_locations();
|
||||
} else if (this->num_trap_tiles_of_type[trap_type] > 2) {
|
||||
// Generate a new random index, but forbid it from matching the existing
|
||||
// index
|
||||
// Generate a new random index, but forbid it from matching the existing index
|
||||
uint8_t new_index = this->get_random(this->num_trap_tiles_of_type[trap_type] - 1);
|
||||
if (new_index >= this->chosen_trap_tile_index_of_type[trap_type]) {
|
||||
new_index++;
|
||||
@@ -1237,8 +1228,7 @@ int8_t Server::send_6xB4x33_remove_ally_atk_if_needed(const ActionState& pa) {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ally_ps = this->get_player_state(z);
|
||||
if ((z != setter_client_id) && ally_ps) {
|
||||
if ((ally_ps->get_team_id() == setter_ps->get_team_id()) &&
|
||||
(ally_ps->get_atk_points() >= ally_cost)) {
|
||||
if ((ally_ps->get_team_id() == setter_ps->get_team_id()) && (ally_ps->get_atk_points() >= ally_cost)) {
|
||||
ally_has_sufficient_atk = true;
|
||||
}
|
||||
}
|
||||
@@ -1364,11 +1354,10 @@ void Server::set_client_id_ready_to_advance_phase(uint8_t client_id, BattlePhase
|
||||
ps->assist_flags |= AssistFlag::ELIGIBLE_FOR_DICE_BOOST;
|
||||
}
|
||||
} else {
|
||||
// TODO: It'd be nice to do this in a constant-randomness way, but I'm
|
||||
// lazy, and this matches Sega's original implementation. The less-lazy
|
||||
// way to do it would be to roll three dice: one in the range [1, N],
|
||||
// one in the range [3, N], and one in the range [1, 2] to decide
|
||||
// whether to swap the first two results.
|
||||
// TODO: It'd be nice to do this in a constant-randomness way, but I'm lazy, and this matches Sega's original
|
||||
// implementation. The less-lazy way to do it would be to roll three dice: one in the range [1, 2] to decide
|
||||
// which of ATK or DEF will be boosted, then roll the ATK die in range [1, N] (or [3, N] if it's boosted), and
|
||||
// do the same for the DEF die.
|
||||
for (size_t z = 0; z < 200; z++) {
|
||||
ps->roll_main_dice_or_apply_after_effects();
|
||||
if ((ps->get_atk_points() >= 3) || (ps->get_def_points() >= 3)) {
|
||||
@@ -1419,12 +1408,14 @@ void Server::set_phase_after() {
|
||||
if (ps) {
|
||||
auto card = ps->get_sc_card();
|
||||
if (card) {
|
||||
this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
this->card_special->apply_action_conditions(
|
||||
EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
}
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = ps->get_set_card(set_index);
|
||||
if (card) {
|
||||
this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
this->card_special->apply_action_conditions(
|
||||
EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1482,9 +1473,7 @@ void Server::set_phase_after() {
|
||||
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->player_states[client_id];
|
||||
if (ps &&
|
||||
(ps->get_assist_turns_remaining() == 90) &&
|
||||
(ps->assist_delay_turns < 1)) {
|
||||
if (ps && (ps->get_assist_turns_remaining() == 90) && (ps->assist_delay_turns < 1)) {
|
||||
ps->discard_set_assist_card();
|
||||
ps->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
}
|
||||
@@ -1618,8 +1607,7 @@ void Server::setup_and_start_battle() {
|
||||
size_t num_trap_tiles = 0;
|
||||
for (size_t y = 0; y < 0x10; y++) {
|
||||
for (size_t x = 0; x < 0x10; x++) {
|
||||
if ((this->overlay_state.tiles[y][x] == (trap_type | 0x40)) &&
|
||||
(num_trap_tiles < 8)) {
|
||||
if ((this->overlay_state.tiles[y][x] == (trap_type | 0x40)) && (num_trap_tiles < 8)) {
|
||||
this->trap_tile_locs[trap_type][num_trap_tiles][0] = x;
|
||||
this->trap_tile_locs[trap_type][num_trap_tiles][1] = y;
|
||||
num_trap_tiles++;
|
||||
@@ -1627,7 +1615,6 @@ void Server::setup_and_start_battle() {
|
||||
}
|
||||
}
|
||||
this->num_trap_tiles_of_type[trap_type] = num_trap_tiles;
|
||||
|
||||
if (num_trap_tiles > 0) {
|
||||
this->chosen_trap_tile_index_of_type[trap_type] = this->get_random(num_trap_tiles);
|
||||
}
|
||||
@@ -1672,8 +1659,7 @@ void Server::setup_and_start_battle() {
|
||||
|
||||
this->send_6xB4x46();
|
||||
|
||||
// Re-send game metadata to spectator teams, since loading the battle scene
|
||||
// seems to delete it
|
||||
// Re-send game metadata to spectator teams, since loading the battle scene seems to delete it
|
||||
auto l = this->lobby.lock();
|
||||
if (l) {
|
||||
send_ep3_update_game_metadata(l);
|
||||
@@ -1697,11 +1683,7 @@ G_SetStateFlags_Ep3_6xB4x03 Server::prepare_6xB4x03() const {
|
||||
cmd.state.tournament_flag = this->options.tournament ? 1 : 0;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ps = this->player_states[z];
|
||||
if (!ps) {
|
||||
cmd.state.client_sc_card_types[z] = CardType::INVALID_FF;
|
||||
} else {
|
||||
cmd.state.client_sc_card_types[z] = ps->get_sc_card_type();
|
||||
}
|
||||
cmd.state.client_sc_card_types[z] = ps ? ps->get_sc_card_type() : CardType::INVALID_FF;
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
@@ -1714,9 +1696,8 @@ void Server::update_battle_state_flags_and_send_6xB4x03_if_needed(bool always_se
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the battle can begin
|
||||
bool Server::update_registration_phase() {
|
||||
// Returns true if the battle can begin
|
||||
|
||||
auto log = this->log_stack("update_registration_phase: ");
|
||||
|
||||
if (this->setup_phase != SetupPhase::REGISTRATION) {
|
||||
@@ -1789,7 +1770,8 @@ void Server::on_server_data_input(shared_ptr<Client> sender_c, const string& dat
|
||||
size_t expected_size = header.size * 4;
|
||||
if (expected_size < data.size()) {
|
||||
phosg::print_data(stderr, data);
|
||||
throw runtime_error(std::format("command is incomplete: expected {:X} bytes, received {:X} bytes", expected_size, data.size()));
|
||||
throw runtime_error(std::format(
|
||||
"command is incomplete: expected {:X} bytes, received {:X} bytes", expected_size, data.size()));
|
||||
}
|
||||
if (header.subcommand != 0xB3) {
|
||||
throw runtime_error("server data command is not 6xB3");
|
||||
@@ -1855,8 +1837,7 @@ void Server::handle_CAx0C_end_redraw_initial_hand_phase(shared_ptr<Client>, cons
|
||||
}
|
||||
|
||||
int32_t error_code = 0;
|
||||
if ((this->setup_phase != SetupPhase::HAND_REDRAW_OPTION) &&
|
||||
(this->setup_phase != SetupPhase::STARTER_ROLLS)) {
|
||||
if ((this->setup_phase != SetupPhase::HAND_REDRAW_OPTION) && (this->setup_phase != SetupPhase::STARTER_ROLLS)) {
|
||||
error_code = -0x5D;
|
||||
}
|
||||
|
||||
@@ -2126,15 +2107,14 @@ void Server::handle_CAx13_update_map_during_setup_t(shared_ptr<Client> c, const
|
||||
(this->registration_phase != RegistrationPhase::REGISTERED) &&
|
||||
(this->registration_phase != RegistrationPhase::BATTLE_STARTED)) {
|
||||
*this->map_and_rules = in_cmd.map_and_rules_state;
|
||||
// The client will likely send incorrect values for the extended rules (or
|
||||
// in the case of NTE, no values at all, since the Rules structure is
|
||||
// smaller). So, use the values from the last chosen map if applicable, or
|
||||
// the values from the $dicerange command if available.
|
||||
uint8_t language = c ? c->language() : 1;
|
||||
// The client will likely send incorrect values for the extended rules (or in the case of NTE, no values at all,
|
||||
// since the Rules structure is smaller). So, use the values from the last chosen map if applicable, or the values
|
||||
// from the $dicerange command if available.
|
||||
Language language = c ? c->language() : Language::ENGLISH;
|
||||
const Rules* map_rules = this->last_chosen_map ? &this->last_chosen_map->version(language)->map->default_rules : nullptr;
|
||||
auto& server_rules = this->map_and_rules->rules;
|
||||
// NTE can specify the DEF dice value range in its Rules struct, so we use
|
||||
// that unless the map or $dicerange overrides it.
|
||||
// NTE can specify the DEF dice value range in its Rules struct, so we use that unless the map or $dicerange
|
||||
// overrides it.
|
||||
server_rules.def_dice_value_range = (map_rules && (map_rules->def_dice_value_range != 0xFF))
|
||||
? map_rules->def_dice_value_range
|
||||
: (this->def_dice_value_range_override != 0xFF)
|
||||
@@ -2153,8 +2133,7 @@ void Server::handle_CAx13_update_map_during_setup_t(shared_ptr<Client> c, const
|
||||
? this->def_dice_value_range_2v1_override
|
||||
: 0;
|
||||
|
||||
// If this match is part of a tournament, ignore the rules sent by the
|
||||
// client and use the tournament rules instead.
|
||||
// If this match is part of a tournament, ignore the rules sent by the client and use the tournament rules instead.
|
||||
if (this->options.tournament) {
|
||||
this->map_and_rules->rules = this->options.tournament->get_rules();
|
||||
}
|
||||
@@ -2236,10 +2215,9 @@ void Server::handle_CAx15_unused_hard_reset_server_state(shared_ptr<Client>, con
|
||||
const auto& in_cmd = check_size_t<G_HardResetServerState_Ep3_CAx15>(data);
|
||||
this->send_debug_command_received_message(in_cmd.header.subsubcommand, "HARD RESET");
|
||||
|
||||
// In the original implementation, this command recreates the server object.
|
||||
// This is possible because the dispatch function is not part of the server
|
||||
// object in the original implementation; however, in our implementation, it
|
||||
// is, so we don't support this. The original implementation did this:
|
||||
// In the original implementation, this command recreates the server object. This is possible because the dispatch
|
||||
// function is not part of the server object in the original implementation; however, in our implementation, it is,
|
||||
// so we don't support this. The original implementation did this:
|
||||
// this->base()->recreate_server(); // Destroys *this, which we can't do
|
||||
// root_card_server = this->server;
|
||||
// *this->map_and_rules = *this->initial_map_and_rules;
|
||||
@@ -2259,8 +2237,8 @@ void Server::handle_CAx1B_update_player_name(shared_ptr<Client>, const string& d
|
||||
this->name_entries_valid[in_cmd.entry.client_id] = false;
|
||||
}
|
||||
|
||||
// Note: This check is not part of the original code. This replaces a
|
||||
// disconnecting player with a CPU if the battle is in progress.
|
||||
// Note: This check is not part of the original code. This replaces a disconnecting player with a CPU if the battle
|
||||
// is in progress.
|
||||
auto l = this->lobby.lock();
|
||||
if (l && !l->clients[in_cmd.entry.client_id]) {
|
||||
this->name_entries[in_cmd.entry.client_id].is_cpu_player = 1;
|
||||
@@ -2313,8 +2291,8 @@ void Server::handle_CAx1D_start_battle(shared_ptr<Client>, const string& data) {
|
||||
|
||||
auto l = this->lobby.lock();
|
||||
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.
|
||||
// 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 (!this->options.is_nte() && l->ep3_ex_result_values) {
|
||||
this->send(*l->ep3_ex_result_values);
|
||||
}
|
||||
@@ -2358,8 +2336,7 @@ void Server::handle_CAx28_end_defense_list(shared_ptr<Client>, const string& dat
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ps = this->player_states[z];
|
||||
if (ps && (this->current_team_turn1 != ps->get_team_id())) {
|
||||
if (!ps->get_sc_card()->check_card_flag(2) &&
|
||||
(this->defense_list_ended_for_client[z] == 0)) {
|
||||
if (!ps->get_sc_card()->check_card_flag(2) && (this->defense_list_ended_for_client[z] == 0)) {
|
||||
all_defense_lists_ended = false;
|
||||
break;
|
||||
}
|
||||
@@ -2505,8 +2482,7 @@ void Server::handle_CAx37_client_ready_to_advance_from_starter_roll_phase(shared
|
||||
void Server::handle_CAx3A_time_limit_expired(shared_ptr<Client>, const string& data) {
|
||||
const auto& in_cmd = check_size_t<G_OverallTimeLimitExpired_Ep3_CAx3A>(data);
|
||||
this->send_debug_command_received_message(in_cmd.header.subsubcommand, "TIME EXPIRED");
|
||||
// We don't need to do anything here because the overall time limit is tracked
|
||||
// server-side instead.
|
||||
// We don't need to do anything here because the overall time limit is tracked server-side instead.
|
||||
}
|
||||
|
||||
void Server::handle_CAx40_map_list_request(shared_ptr<Client> sender_c, const string& data) {
|
||||
@@ -2519,8 +2495,8 @@ void Server::handle_CAx40_map_list_request(shared_ptr<Client> sender_c, const st
|
||||
}
|
||||
|
||||
size_t num_players = l ? l->count_clients() : 1;
|
||||
uint8_t language = sender_c ? sender_c->language() : 1;
|
||||
const auto& list_data = this->options.map_index->get_compressed_list(num_players, language);
|
||||
Language language = sender_c ? sender_c->language() : Language::ENGLISH;
|
||||
const auto& list_data = this->options.map_index->get_compressed_list(num_players, language, this->options.is_nte());
|
||||
|
||||
phosg::StringWriter w;
|
||||
uint32_t subcommand_size = (list_data.size() + sizeof(G_MapList_Ep3_6xB6x40) + 3) & (~3);
|
||||
@@ -2546,15 +2522,16 @@ void Server::send_6xB6x41_to_all_clients() const {
|
||||
if (!c) {
|
||||
return;
|
||||
}
|
||||
if (map_commands_by_language.size() <= c->language()) {
|
||||
map_commands_by_language.resize(c->language() + 1);
|
||||
size_t lang_index = static_cast<size_t>(c->language());
|
||||
if (map_commands_by_language.size() <= lang_index) {
|
||||
map_commands_by_language.resize(lang_index + 1);
|
||||
}
|
||||
if (map_commands_by_language[c->language()].empty()) {
|
||||
map_commands_by_language[c->language()] = this->prepare_6xB6x41_map_definition(
|
||||
if (map_commands_by_language[lang_index].empty()) {
|
||||
map_commands_by_language[lang_index] = this->prepare_6xB6x41_map_definition(
|
||||
this->last_chosen_map, c->language(), this->options.is_nte());
|
||||
}
|
||||
this->log().info_f("Sending {} version of map {:08X}", char_for_language_code(c->language()), this->last_chosen_map->map_number);
|
||||
send_command(c, 0x6C, 0x00, map_commands_by_language[c->language()]);
|
||||
this->log().info_f("Sending {} version of map {:08X}", name_for_language(c->language()), this->last_chosen_map->map_number);
|
||||
send_command(c, 0x6C, 0x00, map_commands_by_language[lang_index]);
|
||||
};
|
||||
for (const auto& c : l->clients) {
|
||||
send_to_client(c);
|
||||
@@ -2566,20 +2543,18 @@ void Server::send_6xB6x41_to_all_clients() const {
|
||||
}
|
||||
|
||||
if (this->battle_record && this->battle_record->writable()) {
|
||||
// TODO: It's not great that we just pick the first one; ideally we'd put
|
||||
// all of them in the recording and send the appropriate one to the client
|
||||
// in the playback lobby
|
||||
// TODO: It's not great that we just pick the first one; ideally we'd put all of them in the recording and send
|
||||
// the appropriate one to the client in the playback lobby
|
||||
for (string& data : map_commands_by_language) {
|
||||
if (!data.empty()) {
|
||||
this->battle_record->add_command(
|
||||
BattleRecord::Event::Type::BATTLE_COMMAND, std::move(data));
|
||||
this->battle_record->add_command(BattleRecord::Event::Type::BATTLE_COMMAND, std::move(data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
auto out_data = this->prepare_6xB6x41_map_definition(this->last_chosen_map, 1, false);
|
||||
auto out_data = this->prepare_6xB6x41_map_definition(this->last_chosen_map, Language::ENGLISH, false);
|
||||
this->send(out_data.data(), out_data.size(), 0x6C, false);
|
||||
}
|
||||
}
|
||||
@@ -2588,7 +2563,7 @@ void Server::handle_CAx41_map_request(shared_ptr<Client>, const string& data) {
|
||||
const auto& cmd = check_size_t<G_MapDataRequest_Ep3_CAx41>(data);
|
||||
this->send_debug_command_received_message(cmd.header.subsubcommand, "MAP DATA");
|
||||
if (!this->options.tournament || (this->options.tournament->get_map()->map_number == cmd.map_number)) {
|
||||
this->last_chosen_map = this->options.map_index->get(cmd.map_number);
|
||||
this->last_chosen_map = this->options.map_index->map_for_id(cmd.map_number);
|
||||
this->send_6xB6x41_to_all_clients();
|
||||
}
|
||||
}
|
||||
@@ -2614,8 +2589,7 @@ void Server::handle_CAx49_card_counts(shared_ptr<Client>, const string& data) {
|
||||
const auto& in_cmd = check_size_t<G_CardCounts_Ep3_CAx49>(data);
|
||||
this->send_debug_command_received_message(in_cmd.header.sender_client_id, in_cmd.header.subsubcommand, "CARD COUNTS");
|
||||
|
||||
// Note: Sega's implmentation completely ignores this command. This
|
||||
// implementation is not based on the original code.
|
||||
// Note: Sega's implmentation completely ignores this command. This implementation is not based on the original code.
|
||||
auto& dest_counts = this->client_card_counts[in_cmd.header.sender_client_id];
|
||||
dest_counts = in_cmd.card_id_to_count;
|
||||
decrypt_trivial_gci_data(dest_counts.data(), dest_counts.bytes(), in_cmd.basis);
|
||||
@@ -2872,10 +2846,9 @@ void Server::execute_bomb_assist_effect() {
|
||||
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->player_states[client_id];
|
||||
// Possible bug: shouldn't we check should_block_assist_effects_for_client
|
||||
// here too? If the player has a card with the same HP as another one that
|
||||
// would be destroyed, it looks like the card can be destroyed even if the
|
||||
// client should be immune to assist effects here.
|
||||
// Possible bug: shouldn't we check should_block_assist_effects_for_client here too? If the player has a card with
|
||||
// the same HP as another one that would be destroyed, it looks like the card can be destroyed even if the client
|
||||
// should be immune to assist effects here.
|
||||
if (ps) {
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = ps->get_set_card(set_index);
|
||||
@@ -2905,10 +2878,7 @@ void Server::replace_targets_due_to_destruction_nte(ActionState* as) {
|
||||
shared_ptr<Card> found_guard_item;
|
||||
for (size_t z = 0; z < 8; z++) {
|
||||
auto set_card = ps->get_set_card(z);
|
||||
if (set_card &&
|
||||
(set_card != target_card) &&
|
||||
!(set_card->card_flags & 2) &&
|
||||
set_card->is_guard_item()) {
|
||||
if (set_card && (set_card != target_card) && !(set_card->card_flags & 2) && set_card->is_guard_item()) {
|
||||
found_guard_item = set_card;
|
||||
break;
|
||||
}
|
||||
@@ -3027,8 +2997,8 @@ void Server::replace_targets_due_to_destruction_or_conditions(ActionState* as) {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: The original code only writes a single FFFF after the last card ref
|
||||
// in this array; we instead clear the entire array.
|
||||
// Note: The original code only writes a single FFFF after the last card ref in this array; we instead clear the
|
||||
// entire array.
|
||||
as->target_card_refs.clear(0xFFFF);
|
||||
for (size_t z = 0; z < phase1_replaced_card_refs.size(); z++) {
|
||||
as->target_card_refs[z] = this->send_6xB4x06_if_card_ref_invalid(phase1_replaced_card_refs[z], 4);
|
||||
@@ -3050,8 +3020,7 @@ void Server::replace_targets_due_to_destruction_or_conditions(ActionState* as) {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: This is different from the original code in the same way as above: we
|
||||
// clear the entire array first.
|
||||
// Note: This is different from the original code in the same way as above: we clear the entire array first.
|
||||
as->target_card_refs.clear(0xFFFF);
|
||||
for (size_t z = 0; z < phase2_replaced_card_refs.size(); z++) {
|
||||
as->target_card_refs[z] = this->send_6xB4x06_if_card_ref_invalid(phase2_replaced_card_refs[z], 4);
|
||||
@@ -3136,8 +3105,7 @@ void Server::unknown_802402F4() {
|
||||
}
|
||||
}
|
||||
|
||||
vector<shared_ptr<Card>> Server::const_cast_set_cards_v(
|
||||
const vector<shared_ptr<const Card>>& cards) {
|
||||
vector<shared_ptr<Card>> Server::const_cast_set_cards_v(const vector<shared_ptr<const Card>>& cards) {
|
||||
// TODO: This is dumb. Figure out a not-dumb way to do this.
|
||||
vector<shared_ptr<Card>> ret;
|
||||
for (auto const_card : cards) {
|
||||
|
||||
+46
-52
@@ -20,53 +20,43 @@ struct Lobby;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
/**
|
||||
* This implementation of Episode 3 battles is derived from Sega's original
|
||||
* server implementation, reverse-engineered from the Episode 3 client
|
||||
* executable. The control flow, function breakdown, and structure definitions
|
||||
* in these files map very closely to how their server implementation was
|
||||
* written; notable differences (due to necessary environment differences or bug
|
||||
* fixes) are described in the comments therein.
|
||||
*
|
||||
* The following files are direct reverse-engineerings of Sega's original code,
|
||||
* except where noted in the comments:
|
||||
* AssistServer.hh/cc
|
||||
* Card.hh/cc
|
||||
* CardSpecial.hh/cc
|
||||
* DeckState.hh/cc
|
||||
* MapState.hh/cc
|
||||
* PlayerState.hh/cc
|
||||
* PlayerStateSubordinates.hh/cc
|
||||
* RulerServer.hh/cc
|
||||
* Server.hh/cc
|
||||
*
|
||||
* There are likely undiscovered bugs in this code, some originally written by
|
||||
* Sega, but more written by me as I manually transcribed and updated this code.
|
||||
*
|
||||
* Class ownership levels (classes may only contain weak_ptrs, not shared_ptrs,
|
||||
* to classes at the same or higher level):
|
||||
* - Server
|
||||
* - - RulerServer
|
||||
* - - - AssistServer
|
||||
* - - - CardSpecial
|
||||
* - - - - StateFlags
|
||||
* - - - - DeckEntry
|
||||
* - - - - PlayerState
|
||||
* - - - - - Card
|
||||
* - - - - - - CardShortStatus
|
||||
* - - - - - - DeckState
|
||||
* - - - - - - HandAndEquipState
|
||||
* - - - - - - MapAndRulesState / OverlayState
|
||||
* - - - - - - - Everything within DataIndexes
|
||||
*/
|
||||
// This implementation of Episode 3 battles is derived from Sega's original server implementation, reverse-engineered
|
||||
// from the Episode 3 client executable. The control flow, function breakdown, and structure definitions in these files
|
||||
// map very closely to how their server implementation was written; notable differences (due to necessary environment
|
||||
// differences or bug fixes) are described in the comments therein. There are likely undiscovered bugs in this code,
|
||||
// some originally written by Sega, but more written by me as I manually transcribed and updated this code.
|
||||
|
||||
// The following files are direct reverse-engineerings of Sega's original code, except where noted in the comments:
|
||||
// AssistServer.hh/cc
|
||||
// Card.hh/cc
|
||||
// CardSpecial.hh/cc
|
||||
// DeckState.hh/cc
|
||||
// MapState.hh/cc
|
||||
// PlayerState.hh/cc
|
||||
// PlayerStateSubordinates.hh/cc
|
||||
// RulerServer.hh/cc
|
||||
// Server.hh/cc
|
||||
|
||||
// Class ownership levels (classes may contain weak_ptrs but not shared_ptrs to classes at the same or higher level):
|
||||
// - Server
|
||||
// - - RulerServer
|
||||
// - - - AssistServer
|
||||
// - - - CardSpecial
|
||||
// - - - - StateFlags
|
||||
// - - - - DeckEntry
|
||||
// - - - - PlayerState
|
||||
// - - - - - Card
|
||||
// - - - - - - CardShortStatus
|
||||
// - - - - - - DeckState
|
||||
// - - - - - - HandAndEquipState
|
||||
// - - - - - - MapAndRulesState / OverlayState
|
||||
// - - - - - - - Everything within DataIndexes
|
||||
|
||||
class Server : public std::enable_shared_from_this<Server> {
|
||||
// In the original code, there is a TCardServerBase class and a TCardServer
|
||||
// class, with the former containing some basic parts of the game state and
|
||||
// a pointer to the latter. It seems these two classes exist (instead of one
|
||||
// big class) so that the force reset command could be implemented; however,
|
||||
// it appears that that command is never sent by the client, so we combine
|
||||
// the two classes into one in our implementation.
|
||||
// In the original code, there is a TCardServerBase class and a TCardServer class, with the former containing some
|
||||
// basic parts of the game state and a pointer to the latter. It seems these two classes exist (instead of one big
|
||||
// class) so that the force reset command could be implemented; however, it appears that that command is never sent
|
||||
// by the client, so we combine the two classes into one in our implementation.
|
||||
public:
|
||||
struct Options {
|
||||
std::shared_ptr<const CardIndex> card_index;
|
||||
@@ -76,6 +66,7 @@ public:
|
||||
std::shared_ptr<RandomGenerator> rand_crypt;
|
||||
std::shared_ptr<const Tournament> tournament;
|
||||
std::array<std::vector<uint16_t>, 5> trap_card_ids;
|
||||
std::shared_ptr<std::deque<std::string>> output_queue; // For replay testing
|
||||
|
||||
inline bool is_nte() const {
|
||||
return (this->behavior_flags & BehaviorFlag::IS_TRIAL_EDITION);
|
||||
@@ -130,6 +121,9 @@ public:
|
||||
|
||||
int8_t get_winner_team_id() const;
|
||||
|
||||
// Note: Sega's servers sent battle commands with the 60 command. The handlers for 60, 62, and C9 on the client are
|
||||
// identical, so we choose to use C9 instead because it's unique to Episode 3, and therefore seems more appropriate
|
||||
// to convey Episode 3 battle commands.
|
||||
template <typename T>
|
||||
void send(const T& cmd, uint8_t command = 0xC9, bool enable_masking = true) const {
|
||||
if (cmd.header.size != sizeof(cmd) / 4) {
|
||||
@@ -240,7 +234,8 @@ public:
|
||||
void handle_CAx28_end_defense_list(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx2B_legacy_set_card(std::shared_ptr<Client> sender_c, const std::string&);
|
||||
void handle_CAx34_subtract_ally_atk_points(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx37_client_ready_to_advance_from_starter_roll_phase(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx37_client_ready_to_advance_from_starter_roll_phase(
|
||||
std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx3A_time_limit_expired(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx40_map_list_request(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx41_map_request(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
@@ -265,12 +260,12 @@ public:
|
||||
|
||||
G_UpdateDecks_Ep3_6xB4x07 prepare_6xB4x07_decks_update() const;
|
||||
G_SetPlayerNames_Ep3_6xB4x1C prepare_6xB4x1C_names_update() const;
|
||||
static std::string prepare_6xB6x41_map_definition(std::shared_ptr<const MapIndex::Map> map, uint8_t language, bool is_nte);
|
||||
static std::string prepare_6xB6x41_map_definition(
|
||||
std::shared_ptr<const MapIndex::Map> map, Language language, bool is_nte);
|
||||
void send_6xB6x41_to_all_clients() const;
|
||||
G_SetTrapTileLocations_Ep3_6xB4x50 prepare_6xB4x50_trap_tile_locations() const;
|
||||
|
||||
std::vector<std::shared_ptr<Card>> const_cast_set_cards_v(
|
||||
const std::vector<std::shared_ptr<const Card>>& cards);
|
||||
std::vector<std::shared_ptr<Card>> const_cast_set_cards_v(const std::vector<std::shared_ptr<const Card>>& cards);
|
||||
|
||||
private:
|
||||
typedef void (Server::*handler_t)(std::shared_ptr<Client>, const std::string&);
|
||||
@@ -325,9 +320,8 @@ public:
|
||||
parray<uint8_t, 4> player_ready_to_end_phase;
|
||||
uint32_t unknown_a10;
|
||||
uint32_t overall_time_expired;
|
||||
// Note: In the original implementation, this is a uint32_t and is measured in
|
||||
// seconds. In our environment, the simplest implementation uses now(), which
|
||||
// returns microseconds, so we use a uint64_t instead.
|
||||
// Note: In the original implementation, this is a uint32_t and is measured in seconds. In our environment, the
|
||||
// simplest implementation uses now(), which returns microseconds, so we use a uint64_t instead.
|
||||
uint64_t battle_start_usecs;
|
||||
uint32_t should_copy_prev_states_to_current_states;
|
||||
std::shared_ptr<CardSpecial> card_special;
|
||||
|
||||
+40
-75
@@ -67,10 +67,7 @@ string Tournament::Team::str() const {
|
||||
return ret + "]";
|
||||
}
|
||||
|
||||
void Tournament::Team::register_player(
|
||||
shared_ptr<Client> c,
|
||||
const string& team_name,
|
||||
const string& password) {
|
||||
void Tournament::Team::register_player(shared_ptr<Client> c, const string& team_name, const string& password) {
|
||||
if (this->players.size() >= this->max_players) {
|
||||
throw runtime_error("team is full");
|
||||
}
|
||||
@@ -104,8 +101,7 @@ void Tournament::Team::register_player(
|
||||
bool Tournament::Team::unregister_player(uint32_t account_id) {
|
||||
size_t index;
|
||||
for (index = 0; index < this->players.size(); index++) {
|
||||
if (this->players[index].is_human() &&
|
||||
(this->players[index].account_id == account_id)) {
|
||||
if (this->players[index].is_human() && (this->players[index].account_id == account_id)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -123,12 +119,10 @@ bool Tournament::Team::unregister_player(uint32_t account_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the tournament has already started, make the team forfeit their game.
|
||||
// If any player withdraws from a team after the registration phase, the
|
||||
// entire team essentially forfeits their entry.
|
||||
// If the tournament has already started, make the team forfeit their game. If any player withdraws from a team
|
||||
// after the registration phase, the entire team essentially forfeits their entry.
|
||||
if (tournament->get_state() != Tournament::State::REGISTRATION) {
|
||||
// Look through the pending matches to see if this team is involved in any
|
||||
// of them
|
||||
// Look through the pending matches to see if this team is involved in any of them
|
||||
for (auto match : tournament->pending_matches) {
|
||||
if (!match->preceding_a || !match->preceding_b) {
|
||||
throw logic_error("zero-round match is pending after tournament registration phase");
|
||||
@@ -142,9 +136,8 @@ bool Tournament::Team::unregister_player(uint32_t account_id) {
|
||||
}
|
||||
}
|
||||
|
||||
// If the tournament has not started yet, just remove the player from the
|
||||
// team
|
||||
} else {
|
||||
// If the tournament has not started yet, just remove the player from the team
|
||||
if (!tournament->all_player_account_ids.erase(account_id)) {
|
||||
throw logic_error("player removed from team but not from tournament");
|
||||
}
|
||||
@@ -183,9 +176,7 @@ size_t Tournament::Team::num_com_players() const {
|
||||
}
|
||||
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Match> preceding_a,
|
||||
shared_ptr<Match> preceding_b)
|
||||
shared_ptr<Tournament> tournament, shared_ptr<Match> preceding_a, shared_ptr<Match> preceding_b)
|
||||
: tournament(tournament),
|
||||
preceding_a(preceding_a),
|
||||
preceding_b(preceding_b),
|
||||
@@ -197,9 +188,7 @@ Tournament::Match::Match(
|
||||
this->round_num = this->preceding_a->round_num + 1;
|
||||
}
|
||||
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Team> winner_team)
|
||||
Tournament::Match::Match(shared_ptr<Tournament> tournament, shared_ptr<Team> winner_team)
|
||||
: tournament(tournament),
|
||||
preceding_a(nullptr),
|
||||
preceding_b(nullptr),
|
||||
@@ -228,9 +217,8 @@ bool Tournament::Match::resolve_if_skippable() {
|
||||
this->set_winner_team(winner_a->players.empty() ? winner_b : winner_a);
|
||||
return true;
|
||||
}
|
||||
// If neither preceding winner team has any humans on it, skip this match
|
||||
// entirely and just make one team advance arbitrarily (note that this also
|
||||
// handles the case where both preceding winner teams are empty)
|
||||
// If neither preceding winner team has any humans on it, skip this match entirely and just make one team advance
|
||||
// arbitrarily (note that this also handles the case where both preceding winner teams are empty)
|
||||
if (!winner_a->has_any_human_players() && !winner_b->has_any_human_players()) {
|
||||
this->set_winner_team((phosg::random_object<uint8_t>() & 1) ? winner_b : winner_a);
|
||||
return true;
|
||||
@@ -247,8 +235,8 @@ void Tournament::Match::on_winner_team_set() {
|
||||
|
||||
tournament->pending_matches.erase(this->shared_from_this());
|
||||
|
||||
// Resolve the following match if possible (this skips CPU-only matches). If
|
||||
// the following match can't be resolved, mark it pending.
|
||||
// Resolve the following match if possible (this skips CPU-only matches). If the following match can't be resolved,
|
||||
// mark it pending.
|
||||
auto following = this->following.lock();
|
||||
if (following && !following->resolve_if_skippable()) {
|
||||
tournament->pending_matches.emplace(following);
|
||||
@@ -259,8 +247,8 @@ void Tournament::Match::on_winner_team_set() {
|
||||
tournament->current_state = Tournament::State::COMPLETE;
|
||||
}
|
||||
|
||||
// Unlink the losing team's players (if any) - this allows them to enter
|
||||
// another tournament before this tournament has ended
|
||||
// Unlink the losing team's players (if any) - this allows them to enter another tournament before this tournament
|
||||
// has ended
|
||||
if (this->preceding_a && this->preceding_b) {
|
||||
auto losing_team = (this->winner_team == this->preceding_a->winner_team)
|
||||
? this->preceding_b->winner_team
|
||||
@@ -278,8 +266,7 @@ void Tournament::Match::set_winner_team_without_triggers(shared_ptr<Team> team)
|
||||
if (!this->preceding_a || !this->preceding_b) {
|
||||
throw logic_error("set_winner_team called on zero-round match");
|
||||
}
|
||||
if ((team != this->preceding_a->winner_team) &&
|
||||
(team != this->preceding_b->winner_team)) {
|
||||
if ((team != this->preceding_a->winner_team) && (team != this->preceding_b->winner_team)) {
|
||||
throw logic_error("winner team did not participate in match");
|
||||
}
|
||||
|
||||
@@ -298,8 +285,7 @@ void Tournament::Match::set_winner_team(shared_ptr<Team> team) {
|
||||
this->on_winner_team_set();
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(
|
||||
shared_ptr<Team> team) const {
|
||||
shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(shared_ptr<Team> team) const {
|
||||
if (!this->preceding_a || !this->preceding_b) {
|
||||
throw logic_error("zero-round matches do not have opponents");
|
||||
}
|
||||
@@ -342,9 +328,7 @@ Tournament::Tournament(
|
||||
}
|
||||
|
||||
Tournament::Tournament(
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const phosg::JSON& json)
|
||||
shared_ptr<const MapIndex> map_index, shared_ptr<const COMDeckIndex> com_deck_index, const phosg::JSON& json)
|
||||
: log(std::format("[Tournament:{}] ", json.get_string("name"))),
|
||||
map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
@@ -357,7 +341,7 @@ void Tournament::init() {
|
||||
bool is_registration_complete;
|
||||
if (!this->source_json.is_null()) {
|
||||
this->name = this->source_json.get_string("name");
|
||||
this->map = this->map_index->get(this->source_json.get_int("map_number"));
|
||||
this->map = this->map_index->map_for_id(this->source_json.get_int("map_number"));
|
||||
this->rules = Rules(this->source_json.at("rules"));
|
||||
this->flags = this->source_json.get_int("flags", 0x02);
|
||||
if (this->source_json.get_bool("is_2v2", false)) {
|
||||
@@ -394,8 +378,7 @@ void Tournament::init() {
|
||||
} else {
|
||||
// Create empty teams
|
||||
while (this->teams.size() < this->num_teams) {
|
||||
auto t = make_shared<Team>(
|
||||
this->shared_from_this(), this->teams.size(), (this->flags & Flag::IS_2V2) ? 2 : 1);
|
||||
auto t = make_shared<Team>(this->shared_from_this(), this->teams.size(), (this->flags & Flag::IS_2V2) ? 2 : 1);
|
||||
this->teams.emplace_back(t);
|
||||
}
|
||||
is_registration_complete = false;
|
||||
@@ -444,9 +427,7 @@ void Tournament::init() {
|
||||
// If both preceding matches of the following match are resolved, put
|
||||
// the following match on the queue since it may be resolvable as well
|
||||
auto following = match->following.lock();
|
||||
if (following &&
|
||||
following->preceding_a->winner_team &&
|
||||
following->preceding_b->winner_team) {
|
||||
if (following && following->preceding_a->winner_team && following->preceding_b->winner_team) {
|
||||
match_queue.emplace(following);
|
||||
}
|
||||
}
|
||||
@@ -477,8 +458,7 @@ void Tournament::create_bracket_matches() {
|
||||
throw logic_error("tournaments team count is not a power of 2");
|
||||
}
|
||||
|
||||
// Create the zero-round matches, and make them all pending if registration
|
||||
// is still open
|
||||
// Create the zero-round matches, and make them all pending if registration is still open
|
||||
this->zero_round_matches.clear();
|
||||
for (const auto& team : this->teams) {
|
||||
auto m = make_shared<Match>(this->shared_from_this(), team);
|
||||
@@ -493,10 +473,7 @@ void Tournament::create_bracket_matches() {
|
||||
while (current_round_matches.size() > 1) {
|
||||
vector<shared_ptr<Match>> next_round_matches;
|
||||
for (size_t z = 0; z < current_round_matches.size(); z += 2) {
|
||||
auto m = make_shared<Match>(
|
||||
this->shared_from_this(),
|
||||
current_round_matches[z],
|
||||
current_round_matches[z + 1]);
|
||||
auto m = make_shared<Match>(this->shared_from_this(), current_round_matches[z], current_round_matches[z + 1]);
|
||||
current_round_matches[z]->following = m;
|
||||
current_round_matches[z + 1]->following = m;
|
||||
next_round_matches.emplace_back(std::move(m));
|
||||
@@ -552,8 +529,7 @@ shared_ptr<Tournament::Team> Tournament::get_winner_team() const {
|
||||
return this->final_match->winner_team;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Match> Tournament::next_match_for_team(
|
||||
shared_ptr<Team> team) const {
|
||||
shared_ptr<Tournament::Match> Tournament::next_match_for_team(shared_ptr<Team> team) const {
|
||||
if (this->current_state == Tournament::State::REGISTRATION) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -561,8 +537,7 @@ shared_ptr<Tournament::Match> Tournament::next_match_for_team(
|
||||
if (!match->preceding_a || !match->preceding_b) {
|
||||
throw logic_error("zero-round match is pending after tournament registration phase");
|
||||
}
|
||||
if ((team == match->preceding_a->winner_team) ||
|
||||
(team == match->preceding_b->winner_team)) {
|
||||
if ((team == match->preceding_a->winner_team) || (team == match->preceding_b->winner_team)) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
@@ -573,8 +548,7 @@ shared_ptr<Tournament::Match> Tournament::get_final_match() const {
|
||||
return this->final_match;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::team_for_account_id(
|
||||
uint32_t account_id) const {
|
||||
shared_ptr<Tournament::Team> Tournament::team_for_account_id(uint32_t account_id) const {
|
||||
if (!this->all_player_account_ids.count(account_id)) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -601,9 +575,8 @@ void Tournament::start() {
|
||||
|
||||
bool has_com_teams = (this->flags & Flag::HAS_COM_TEAMS);
|
||||
|
||||
// If there aren't enough entrants (1 if has_com_teams is false, else 2),
|
||||
// don't allow the tournament to start (because it would enter the COMPLETE
|
||||
// state immediately)
|
||||
// If there aren't enough entrants (1 if has_com_teams is false, else 2), don't allow the tournament to start
|
||||
// (because it would enter the COMPLETE state immediately)
|
||||
size_t num_human_teams = 0;
|
||||
for (size_t z = 0; z < this->teams.size(); z++) {
|
||||
if (this->teams[z]->has_any_human_players()) {
|
||||
@@ -615,9 +588,8 @@ void Tournament::start() {
|
||||
}
|
||||
|
||||
if ((this->flags & Flag::SHUFFLE_ENTRIES) && (this->flags & Flag::RESIZE_ON_START)) {
|
||||
// If both of these flags are set, pack the human teams into the lowest part
|
||||
// of the teams list so we can resize the tournament to the smallest
|
||||
// possible size. This is OK since we're going to shuffle them later anyway
|
||||
// If both of these flags are set, pack the human teams into the lowest part of the teams list so we can resize the
|
||||
// tournament to the smallest possible size. This is OK since we're going to shuffle them later anyway
|
||||
size_t r_offset = 0, w_offset = 0;
|
||||
for (; r_offset < this->teams.size(); r_offset++) {
|
||||
if (this->teams[r_offset]->has_any_human_players()) {
|
||||
@@ -630,8 +602,8 @@ void Tournament::start() {
|
||||
}
|
||||
|
||||
if (this->flags & Flag::RESIZE_ON_START) {
|
||||
// Resize the tournament by repeatedly deleting the second half of it, until
|
||||
// the second half contains human players or the tournament size is 4
|
||||
// Resize the tournament by repeatedly deleting the second half of it, until the second half contains human players
|
||||
// or the tournament size is 4
|
||||
while (this->teams.size() > 4) {
|
||||
size_t z;
|
||||
for (z = this->teams.size() >> 1; z < this->teams.size(); z++) {
|
||||
@@ -661,8 +633,7 @@ void Tournament::start() {
|
||||
this->current_state = State::IN_PROGRESS;
|
||||
this->create_bracket_matches();
|
||||
|
||||
// Assign names to COM teams, and assign COM decks to all empty slots unless
|
||||
// has_com_teams is false
|
||||
// Assign names to COM teams, and assign COM decks to all empty slots unless has_com_teams is false
|
||||
for (size_t z = 0; z < this->zero_round_matches.size(); z++) {
|
||||
auto m = this->zero_round_matches[z];
|
||||
auto t = m->winner_team;
|
||||
@@ -677,11 +648,9 @@ void Tournament::start() {
|
||||
if (this->com_deck_index->num_decks() < t->max_players - t->players.size()) {
|
||||
throw runtime_error("not enough COM decks to complete team");
|
||||
}
|
||||
// If we allow all-COM teams, or this is a 2v2 tournament and the team has
|
||||
// only one human on it, add a COM
|
||||
// If we allow all-COM teams, or this is a 2v2 tournament and the team has only one human on it, add a COM
|
||||
if (has_com_teams || !t->players.empty()) {
|
||||
// TODO: Don't allow duplicate COM decks, nor duplicate COM SCs on the
|
||||
// same team
|
||||
// TODO: Don't allow duplicate COM decks, nor duplicate COM SCs on the same team
|
||||
while (t->players.size() < t->max_players) {
|
||||
t->players.emplace_back(this->com_deck_index->random_deck());
|
||||
}
|
||||
@@ -698,9 +667,8 @@ void Tournament::send_all_state_updates() const {
|
||||
for (const auto& team : this->teams) {
|
||||
for (const auto& player : team->players) {
|
||||
auto c = player.client.lock();
|
||||
// Note: The last check here is to make sure the client is still linked
|
||||
// with this instance of the tournament - an intervening shell command
|
||||
// `reload ep3` could have changed the client's linkage
|
||||
// Note: The last check here is to make sure the client is still linked with this instance of the tournament - an
|
||||
// intervening shell command `reload ep3` could have changed the client's linkage
|
||||
if (c && (c->version() == Version::GC_EP3) && (c->ep3_tournament_team.lock() == team)) {
|
||||
send_ep3_confirm_tournament_entry(c, this->shared_from_this());
|
||||
}
|
||||
@@ -737,7 +705,7 @@ string Tournament::bracket_str() const {
|
||||
}
|
||||
};
|
||||
|
||||
auto en_vm = this->map->version(1);
|
||||
auto en_vm = this->map->version(Language::ENGLISH);
|
||||
if (en_vm) {
|
||||
string map_name = en_vm->map->name.decode(en_vm->language);
|
||||
ret += std::format(" Map: {:08X} ({})\n", this->map->map_number, map_name);
|
||||
@@ -828,8 +796,7 @@ TournamentIndex::TournamentIndex(
|
||||
auto tourn = make_shared<Tournament>(this->map_index, this->com_deck_index, *it.second);
|
||||
tourn->init();
|
||||
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
|
||||
// This is logic_error instead of runtime_error because phosg::JSON dicts are
|
||||
// supposed to already have unique keys
|
||||
// This is logic_error instead of runtime_error because phosg::JSON dicts already have unique keys
|
||||
throw logic_error("multiple tournaments have the same name: " + tourn->get_name());
|
||||
}
|
||||
tourn->set_menu_item_id(this->menu_item_id_to_tournament.size());
|
||||
@@ -862,8 +829,7 @@ shared_ptr<Tournament> TournamentIndex::create_tournament(
|
||||
throw runtime_error("there can be at most 32 tournaments at a time");
|
||||
}
|
||||
|
||||
auto t = make_shared<Tournament>(
|
||||
this->map_index, this->com_deck_index, name, map, rules, num_teams, flags);
|
||||
auto t = make_shared<Tournament>(this->map_index, this->com_deck_index, name, map, rules, num_teams, flags);
|
||||
t->init();
|
||||
if (!this->name_to_tournament.emplace(t->get_name(), t).second) {
|
||||
throw runtime_error("a tournament with the same name already exists");
|
||||
@@ -942,8 +908,7 @@ void TournamentIndex::link_client(shared_ptr<Client> c) {
|
||||
}
|
||||
|
||||
void TournamentIndex::link_all_clients(std::shared_ptr<ServerState> s) {
|
||||
// This can be called before the game server exists, so do nothing in that
|
||||
// case
|
||||
// This can be called before the game server exists, so do nothing in that case
|
||||
if (s->game_server) {
|
||||
for (const auto& c : s->game_server->all_clients()) {
|
||||
this->link_client(c);
|
||||
|
||||
@@ -62,16 +62,10 @@ public:
|
||||
size_t num_rounds_cleared;
|
||||
bool is_active;
|
||||
|
||||
Team(
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
size_t index,
|
||||
size_t max_players);
|
||||
Team(std::shared_ptr<Tournament> tournament, size_t index, size_t max_players);
|
||||
std::string str() const;
|
||||
|
||||
void register_player(
|
||||
std::shared_ptr<Client> c,
|
||||
const std::string& team_name,
|
||||
const std::string& password);
|
||||
void register_player(std::shared_ptr<Client> c, const std::string& team_name, const std::string& password);
|
||||
bool unregister_player(uint32_t account_id);
|
||||
|
||||
bool has_any_human_players() const;
|
||||
@@ -91,9 +85,7 @@ public:
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
std::shared_ptr<Match> preceding_a,
|
||||
std::shared_ptr<Match> preceding_b);
|
||||
Match(
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
std::shared_ptr<Team> winner_team);
|
||||
Match(std::shared_ptr<Tournament> tournament, std::shared_ptr<Team> winner_team);
|
||||
std::string str() const;
|
||||
|
||||
bool resolve_if_skippable();
|
||||
@@ -180,14 +172,12 @@ private:
|
||||
std::set<uint32_t> all_player_account_ids;
|
||||
std::unordered_set<std::shared_ptr<Match>> pending_matches;
|
||||
|
||||
// This vector contains all teams in the original starting order of the
|
||||
// tournament (that is, all teams in the first round). The order within this
|
||||
// vector determines which team will play against which other team in the
|
||||
// first round: [0] will play against [1], [2] will play against [3], etc.
|
||||
// This vector contains all teams in the original starting order of the tournament (that is, all teams in the first
|
||||
// round). The order within this vector determines which team will play against which other team in the first round:
|
||||
// [0] will play against [1], [2] will play against [3], etc.
|
||||
std::vector<std::shared_ptr<Team>> teams;
|
||||
// The tournament begins with a "zero round", in which each team automatically
|
||||
// "wins" a match, putting them into the first round. This is just to make the
|
||||
// data model easier to manage, so we don't have to have a type of match with
|
||||
// The tournament begins with a "zero round", in which each team automatically "wins" a match, putting them into the
|
||||
// first round. This is just to make the data model easier to manage, so we don't have to have a type of match with
|
||||
// no preceding round.
|
||||
std::vector<std::shared_ptr<Match>> zero_round_matches;
|
||||
std::shared_ptr<Match> final_match;
|
||||
|
||||
@@ -44,16 +44,14 @@ FileContentsCache::GetResult FileContentsCache::get_or_load(const char* name) {
|
||||
return this->get_or_load(string(name));
|
||||
}
|
||||
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(
|
||||
const std::string& name) {
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(const std::string& name) {
|
||||
auto throw_fn = +[](const std::string&) -> string {
|
||||
throw out_of_range("file missing from cache");
|
||||
};
|
||||
return this->get(name, throw_fn).file;
|
||||
}
|
||||
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(
|
||||
const char* name) {
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(const char* name) {
|
||||
return this->get_or_throw(string(name));
|
||||
}
|
||||
|
||||
|
||||
@@ -114,9 +114,9 @@ public:
|
||||
ThreadSafeFileCache& operator=(ThreadSafeFileCache&&) = delete;
|
||||
~ThreadSafeFileCache() = default;
|
||||
|
||||
// Warning: generate() is called while the lock is held for writing, so it
|
||||
// will block other threads.
|
||||
std::shared_ptr<const std::string> get(const std::string& name, std::function<std::shared_ptr<const std::string>(const std::string&)> generate);
|
||||
// generate() is called while the lock is held for writing, so it will block other threads.
|
||||
std::shared_ptr<const std::string> get(
|
||||
const std::string& name, std::function<std::shared_ptr<const std::string>(const std::string&)> generate);
|
||||
|
||||
private:
|
||||
std::shared_mutex lock;
|
||||
|
||||
+128
-76
@@ -105,7 +105,119 @@ string CompiledFunctionCode::generate_client_command(
|
||||
}
|
||||
|
||||
bool CompiledFunctionCode::is_big_endian() const {
|
||||
return this->arch == Architecture::POWERPC;
|
||||
return (this->arch == Architecture::POWERPC);
|
||||
}
|
||||
|
||||
static unordered_map<uint32_t, std::string> preprocess_function_code(const std::string& text) {
|
||||
auto parse_specific_version_list = +[](std::string&& text) -> vector<uint32_t> {
|
||||
phosg::strip_whitespace(text);
|
||||
vector<uint32_t> ret;
|
||||
for (auto& vers_token : phosg::split(text, ' ')) {
|
||||
phosg::strip_whitespace(vers_token);
|
||||
if (vers_token.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (vers_token.size() != 4) {
|
||||
throw std::runtime_error("invalid specific_version: " + vers_token);
|
||||
}
|
||||
ret.emplace_back(*reinterpret_cast<const be_uint32_t*>(vers_token.data()));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
// Find a .versions directive and populate specific_versions
|
||||
vector<uint32_t> specific_versions;
|
||||
auto lines = phosg::split(text, '\n');
|
||||
for (auto& line : lines) {
|
||||
if (line.starts_with(".versions ")) {
|
||||
if (!specific_versions.empty()) {
|
||||
throw std::runtime_error("multiple .versions directives in file");
|
||||
}
|
||||
specific_versions = parse_specific_version_list(line.substr(10));
|
||||
if (specific_versions.empty()) {
|
||||
throw std::runtime_error(".versions directive does not specify any versions");
|
||||
}
|
||||
line.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no .versions directive, just return the text as-is
|
||||
if (specific_versions.empty()) {
|
||||
return {{0, std::move(text)}};
|
||||
}
|
||||
|
||||
vector<deque<string>> version_lines;
|
||||
version_lines.resize(specific_versions.size());
|
||||
|
||||
size_t line_num = 1;
|
||||
vector<uint32_t> current_only_versions;
|
||||
unordered_set<uint32_t> current_only_versions_set;
|
||||
auto add_blank_line = [&]() -> void {
|
||||
for (size_t vers_index = 0; vers_index < specific_versions.size(); vers_index++) {
|
||||
version_lines[vers_index].emplace_back("");
|
||||
}
|
||||
};
|
||||
for (auto& line : lines) {
|
||||
phosg::strip_whitespace(line);
|
||||
if (line.starts_with(".only_versions ")) {
|
||||
current_only_versions = parse_specific_version_list(line.substr(15));
|
||||
current_only_versions_set.clear();
|
||||
for (uint32_t specific_version : current_only_versions) {
|
||||
current_only_versions_set.emplace(specific_version);
|
||||
}
|
||||
add_blank_line();
|
||||
|
||||
} else if (line == ".all_versions") {
|
||||
current_only_versions.clear();
|
||||
current_only_versions_set.clear();
|
||||
add_blank_line();
|
||||
|
||||
} else {
|
||||
size_t vers_offset = line.find("<VERS ");
|
||||
if (vers_offset == string::npos) {
|
||||
for (size_t vers_index = 0; vers_index < specific_versions.size(); vers_index++) {
|
||||
if (current_only_versions.empty() || current_only_versions_set.count(specific_versions[vers_index])) {
|
||||
version_lines[vers_index].emplace_back(line);
|
||||
} else {
|
||||
version_lines[vers_index].emplace_back("");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
size_t token_index = 0;
|
||||
for (size_t vers_index = 0; vers_index < specific_versions.size(); vers_index++) {
|
||||
if (current_only_versions.empty() || current_only_versions_set.count(specific_versions[vers_index])) {
|
||||
string version_line = line;
|
||||
size_t vers_offset = line.find("<VERS ");
|
||||
while (vers_offset != string::npos) {
|
||||
size_t end_offset = version_line.find('>', vers_offset + 6);
|
||||
if (end_offset == string::npos) {
|
||||
throw runtime_error(std::format("(line {}) unterminated <VERS> replacement", line_num));
|
||||
}
|
||||
auto tokens = phosg::split(version_line.substr(vers_offset + 6, end_offset - vers_offset - 6), ' ');
|
||||
if (tokens.size() <= token_index) {
|
||||
throw runtime_error(std::format("(line {}) invalid <VERS> replacement", line_num));
|
||||
}
|
||||
version_line = version_line.substr(0, vers_offset) + tokens.at(token_index) + version_line.substr(end_offset + 1);
|
||||
vers_offset = version_line.find("<VERS ");
|
||||
}
|
||||
version_lines[vers_index].emplace_back(version_line);
|
||||
token_index++;
|
||||
} else {
|
||||
version_lines[vers_index].emplace_back("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
line_num++;
|
||||
}
|
||||
|
||||
unordered_map<uint32_t, string> ret;
|
||||
for (size_t z = 0; z < specific_versions.size(); z++) {
|
||||
ret.emplace(specific_versions[z], phosg::join(version_lines.at(z), "\n"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
@@ -113,7 +225,8 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
const string& function_directory,
|
||||
const string& system_directory,
|
||||
const string& name,
|
||||
const string& text) {
|
||||
const string& text,
|
||||
bool raise_on_any_failure) {
|
||||
unordered_set<string> get_include_stack;
|
||||
function<string(const string&)> get_include = [&](const string& name) -> string {
|
||||
const char* arch_name_token;
|
||||
@@ -169,78 +282,10 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
throw runtime_error("data not found for include: " + name + " (from " + asm_filename + " or " + bin_filename + ")");
|
||||
};
|
||||
|
||||
// Handle VERS tokens
|
||||
vector<uint32_t> specific_versions;
|
||||
auto lines = phosg::split(text, '\n');
|
||||
for (auto& line : lines) {
|
||||
if (line.starts_with(".versions ")) {
|
||||
if (!specific_versions.empty()) {
|
||||
throw std::runtime_error("multiple .versions directives in file");
|
||||
}
|
||||
for (auto& vers_token : phosg::split(line.substr(10), ' ')) {
|
||||
phosg::strip_whitespace(vers_token);
|
||||
if (vers_token.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (vers_token.size() != 4) {
|
||||
throw std::runtime_error("invalid token in .version directive: " + vers_token);
|
||||
}
|
||||
specific_versions.emplace_back(*reinterpret_cast<const be_uint32_t*>(vers_token.data()));
|
||||
}
|
||||
line.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Preprocess <VERS> tokens in the text if a .versions directive was given
|
||||
vector<string> version_texts;
|
||||
if (specific_versions.empty()) {
|
||||
specific_versions.emplace_back(0);
|
||||
version_texts.emplace_back(text);
|
||||
|
||||
} else {
|
||||
vector<deque<string>> version_lines;
|
||||
version_lines.resize(specific_versions.size());
|
||||
|
||||
size_t line_num = 1;
|
||||
for (const auto& line : lines) {
|
||||
size_t vers_offset = line.find("<VERS ");
|
||||
if (vers_offset == string::npos) {
|
||||
for (auto& lines : version_lines) {
|
||||
lines.emplace_back(line);
|
||||
}
|
||||
|
||||
} else {
|
||||
for (size_t vers_index = 0; vers_index < specific_versions.size(); vers_index++) {
|
||||
string version_line = line;
|
||||
size_t vers_offset = line.find("<VERS ");
|
||||
while (vers_offset != string::npos) {
|
||||
size_t end_offset = version_line.find('>', vers_offset + 6);
|
||||
if (end_offset == string::npos) {
|
||||
throw runtime_error(std::format("(line {}) unterminated <VERS> replacement", line_num));
|
||||
}
|
||||
auto tokens = phosg::split(version_line.substr(vers_offset + 6, end_offset - vers_offset - 6), ' ');
|
||||
if (tokens.size() != specific_versions.size()) {
|
||||
throw runtime_error(std::format("(line {}) invalid <VERS> replacement", line_num));
|
||||
}
|
||||
version_line = version_line.substr(0, vers_offset) + tokens.at(vers_index) + version_line.substr(end_offset + 1);
|
||||
vers_offset = version_line.find("<VERS ");
|
||||
}
|
||||
version_lines[vers_index].emplace_back(version_line);
|
||||
}
|
||||
}
|
||||
line_num++;
|
||||
}
|
||||
|
||||
for (const auto& lines : version_lines) {
|
||||
version_texts.emplace_back(phosg::join(lines, "\n"));
|
||||
}
|
||||
}
|
||||
auto version_texts = preprocess_function_code(text);
|
||||
|
||||
vector<shared_ptr<CompiledFunctionCode>> ret;
|
||||
for (size_t vers_index = 0; vers_index < specific_versions.size(); vers_index++) {
|
||||
uint32_t specific_version = specific_versions[vers_index];
|
||||
const auto& version_text = version_texts.at(vers_index);
|
||||
|
||||
for (const auto& [specific_version, version_text] : version_texts) {
|
||||
try {
|
||||
ResourceDASM::EmulatorBase::AssembleResult assembled;
|
||||
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
|
||||
@@ -268,6 +313,8 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
compiled->description = it.second;
|
||||
} else if (it.first == "client_flag") {
|
||||
compiled->client_flag = stoull(it.second, nullptr, 0);
|
||||
} else if (it.first == "show_return_value") {
|
||||
compiled->show_return_value = true;
|
||||
} else {
|
||||
throw runtime_error("unknown metadata key: " + it.first);
|
||||
}
|
||||
@@ -298,6 +345,9 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
|
||||
} catch (const exception& e) {
|
||||
string version_str = specific_version ? (" (" + str_for_specific_version(specific_version) + ")") : "";
|
||||
if (raise_on_any_failure) {
|
||||
throw;
|
||||
}
|
||||
function_compiler_log.warning_f("Failed to compile function {}{}: {}", name, version_str, e.what());
|
||||
}
|
||||
}
|
||||
@@ -305,7 +355,7 @@ static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
|
||||
return ret;
|
||||
}
|
||||
|
||||
FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
FunctionCodeIndex::FunctionCodeIndex(const string& directory, bool raise_on_any_failure) {
|
||||
string system_dir_path = directory.ends_with("/") ? (directory + "System") : (directory + "/System");
|
||||
|
||||
uint32_t next_menu_item_id = 1;
|
||||
@@ -367,7 +417,7 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
|
||||
string path = subdir_path + "/" + filename;
|
||||
string text = phosg::load_file(path);
|
||||
for (auto code : compile_function_code(arch, subdir_path, system_dir_path, name, text)) {
|
||||
for (auto code : compile_function_code(arch, subdir_path, system_dir_path, name, text, raise_on_any_failure)) {
|
||||
if (code->specific_version == 0) {
|
||||
code->specific_version = specific_version;
|
||||
}
|
||||
@@ -388,6 +438,9 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
}
|
||||
|
||||
} catch (const exception& e) {
|
||||
if (raise_on_any_failure) {
|
||||
throw runtime_error(format("({}) {}", filename, e.what()));
|
||||
}
|
||||
function_compiler_log.warning_f("Failed to compile function {}: {}", filename, e.what());
|
||||
}
|
||||
};
|
||||
@@ -439,8 +492,7 @@ bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
|
||||
|
||||
std::shared_ptr<const CompiledFunctionCode> FunctionCodeIndex::get_patch(
|
||||
const std::string& name, uint32_t specific_version) const {
|
||||
return this->name_and_specific_version_to_patch_function.at(
|
||||
std::format("{}-{:08X}", name, specific_version));
|
||||
return this->name_and_specific_version_to_patch_function.at(std::format("{}-{:08X}", name, specific_version));
|
||||
}
|
||||
|
||||
DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
|
||||
@@ -33,6 +33,7 @@ struct CompiledFunctionCode {
|
||||
uint64_t client_flag = 0; // From .meta client_flag directive
|
||||
uint32_t menu_item_id = 0;
|
||||
bool hide_from_patches_menu = false;
|
||||
bool show_return_value = false;
|
||||
uint32_t specific_version = 0; // 0 = not a client-selectable patch
|
||||
|
||||
bool is_big_endian() const;
|
||||
@@ -54,7 +55,7 @@ const char* name_for_architecture(CompiledFunctionCode::Architecture arch);
|
||||
|
||||
struct FunctionCodeIndex {
|
||||
FunctionCodeIndex() = default;
|
||||
explicit FunctionCodeIndex(const std::string& directory);
|
||||
FunctionCodeIndex(const std::string& directory, bool raise_on_any_failure);
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_function;
|
||||
std::unordered_map<uint8_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
|
||||
|
||||
+2
-4
@@ -39,8 +39,7 @@ void GSLArchive::load_t() {
|
||||
}
|
||||
}
|
||||
|
||||
GSLArchive::GSLArchive(shared_ptr<const string> data, bool big_endian)
|
||||
: data(data) {
|
||||
GSLArchive::GSLArchive(shared_ptr<const string> data, bool big_endian) : data(data) {
|
||||
if (big_endian) {
|
||||
this->load_t<true>();
|
||||
} else {
|
||||
@@ -87,8 +86,7 @@ template <bool BE>
|
||||
string GSLArchive::generate_t(const unordered_map<string, string>& files) {
|
||||
phosg::StringWriter w;
|
||||
|
||||
// Make sure there's enough space for a blank header entry before any file's
|
||||
// data pages begin
|
||||
// Make sure there's enough space for a blank header entry before any file's data pages begin
|
||||
uint32_t data_start_offset = ((sizeof(GSLHeaderEntryT<BE>) * (files.size() + 1)) + 0x7FF) & (~0x7FF);
|
||||
uint32_t data_offset = data_start_offset;
|
||||
for (const auto& file : files) {
|
||||
|
||||
+14
-12
@@ -21,8 +21,7 @@
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
GameServer::GameServer(shared_ptr<ServerState> state)
|
||||
: Server(state->io_context, "[GameServer] "), state(state) {}
|
||||
GameServer::GameServer(shared_ptr<ServerState> state) : Server(state->io_context, "[GameServer] "), state(state) {}
|
||||
|
||||
void GameServer::listen(
|
||||
const std::string& name,
|
||||
@@ -45,6 +44,7 @@ void GameServer::listen(
|
||||
|
||||
shared_ptr<Client> GameServer::connect_channel(shared_ptr<Channel> ch, uint16_t port, ServerBehavior initial_state) {
|
||||
auto c = make_shared<Client>(this->shared_from_this(), ch, initial_state);
|
||||
c->listener_port = port;
|
||||
|
||||
this->log.info_f("Client connected: C-{:X} via TSI-{}-{}-{}",
|
||||
c->id, port, phosg::name_for_enum(ch->version), phosg::name_for_enum(initial_state));
|
||||
@@ -75,8 +75,8 @@ vector<shared_ptr<Client>> GameServer::get_clients_by_identifier(const string& i
|
||||
} catch (const invalid_argument&) {
|
||||
}
|
||||
|
||||
// TODO: It's kind of not great that we do a linear search here, but this is
|
||||
// only used in the shell, so it should be pretty rare.
|
||||
// TODO: It's kind of not great that we do a linear search here, but this is only used in the shell, so it should be
|
||||
// pretty rare.
|
||||
vector<shared_ptr<Client>> results;
|
||||
for (const auto& c : this->clients) {
|
||||
if (c->login && c->login->account->account_id == account_id_hex) {
|
||||
@@ -115,10 +115,13 @@ vector<shared_ptr<Client>> GameServer::get_clients_by_identifier(const string& i
|
||||
return results;
|
||||
}
|
||||
|
||||
shared_ptr<Client> GameServer::create_client(shared_ptr<GameServerSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
||||
shared_ptr<Client> GameServer::create_client(
|
||||
shared_ptr<GameServerSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
||||
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
||||
if (this->state->banned_ipv4_ranges->check(addr)) {
|
||||
client_sock.close();
|
||||
if (client_sock.is_open()) {
|
||||
client_sock.close();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -126,11 +129,12 @@ shared_ptr<Client> GameServer::create_client(shared_ptr<GameServerSocket> listen
|
||||
this->io_context,
|
||||
make_unique<asio::ip::tcp::socket>(std::move(client_sock)),
|
||||
listen_sock->version,
|
||||
1,
|
||||
Language::ENGLISH,
|
||||
"",
|
||||
phosg::TerminalFormat::FG_YELLOW,
|
||||
phosg::TerminalFormat::FG_GREEN);
|
||||
auto c = make_shared<Client>(this->shared_from_this(), channel, listen_sock->behavior);
|
||||
c->listener_port = listen_sock->endpoint.port();
|
||||
this->log.info_f("Client connected: C-{:X} via {}", c->id, listen_sock->name);
|
||||
|
||||
return c;
|
||||
@@ -164,8 +168,7 @@ asio::awaitable<void> GameServer::handle_client(shared_ptr<Client> c) {
|
||||
asio::awaitable<void> GameServer::destroy_client(std::shared_ptr<Client> c) {
|
||||
this->log.info_f("Running cleanup tasks for {}", c->channel->name);
|
||||
|
||||
// The client may not actually be disconnected yet if an uncaught exception
|
||||
// occurred in a handler task
|
||||
// The client may not actually be disconnected yet if an uncaught exception occurred in a handler task
|
||||
c->channel->disconnect();
|
||||
|
||||
// Close the proxy session, if any
|
||||
@@ -182,9 +185,8 @@ asio::awaitable<void> GameServer::destroy_client(std::shared_ptr<Client> c) {
|
||||
this->log.warning_f("Error during client disconnect cleanup: {}", e.what());
|
||||
}
|
||||
|
||||
// Note: It's important to move the disconnect hooks out of the client here
|
||||
// because the hooks could modify c->disconnect_hooks while it's being
|
||||
// iterated here, which would invalidate these iterators.
|
||||
// Note: It's important to move the disconnect hooks out of the client here because the hooks could modify
|
||||
// c->disconnect_hooks while it's being iterated here, which would invalidate these iterators.
|
||||
unordered_map<string, function<void()>> hooks = std::move(c->disconnect_hooks);
|
||||
for (auto h_it : hooks) {
|
||||
try {
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@ public:
|
||||
explicit GameServer(std::shared_ptr<ServerState> state);
|
||||
virtual ~GameServer() = default;
|
||||
|
||||
void listen(const std::string& name, const std::string& addr, uint16_t port, Version version, ServerBehavior initial_state);
|
||||
void listen(
|
||||
const std::string& name, const std::string& addr, uint16_t port, Version version, ServerBehavior initial_state);
|
||||
|
||||
std::shared_ptr<Client> connect_channel(std::shared_ptr<Channel> ch, uint16_t port, ServerBehavior initial_state);
|
||||
|
||||
|
||||
+936
-784
File diff suppressed because it is too large
Load Diff
+8
-21
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "AsyncHTTPServer.hh"
|
||||
#include "ServerState.hh"
|
||||
@@ -20,32 +21,18 @@ public:
|
||||
asio::awaitable<void> send_rare_drop_notification(std::shared_ptr<const phosg::JSON> message);
|
||||
|
||||
protected:
|
||||
struct RawResponse {
|
||||
std::string content_type;
|
||||
std::string data;
|
||||
};
|
||||
std::shared_ptr<ServerState> state;
|
||||
std::unordered_set<std::shared_ptr<HTTPClient>> rare_drop_subscribers;
|
||||
|
||||
std::shared_ptr<phosg::JSON> generate_server_version() const;
|
||||
std::shared_ptr<phosg::JSON> generate_account_json(std::shared_ptr<const Account> a) const;
|
||||
std::shared_ptr<phosg::JSON> generate_client_json(
|
||||
std::shared_ptr<const Client> c, std::shared_ptr<const ItemNameIndex> item_name_index) const;
|
||||
std::shared_ptr<phosg::JSON> generate_lobby_json(
|
||||
std::shared_ptr<const Lobby> l, std::shared_ptr<const ItemNameIndex> item_name_index) const;
|
||||
std::shared_ptr<phosg::JSON> generate_accounts_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_clients_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_server_info_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_lobbies_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_summary_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_all_json() const;
|
||||
|
||||
asio::awaitable<std::shared_ptr<phosg::JSON>> generate_ep3_cards_json(bool trial) const;
|
||||
std::shared_ptr<phosg::JSON> generate_common_table_list_json() const;
|
||||
std::shared_ptr<phosg::JSON> generate_rare_table_list_json() const;
|
||||
asio::awaitable<std::shared_ptr<phosg::JSON>> generate_common_table_json(const std::string& table_name) const;
|
||||
asio::awaitable<std::shared_ptr<phosg::JSON>> generate_rare_table_json(const std::string& table_name) const;
|
||||
asio::awaitable<std::shared_ptr<phosg::JSON>> generate_quest_list_json();
|
||||
HTTPRouter<std::variant<RawResponse, std::shared_ptr<const phosg::JSON>>> router;
|
||||
|
||||
void require_GET(const HTTPRequest& req);
|
||||
phosg::JSON require_POST(const HTTPRequest& req);
|
||||
|
||||
virtual asio::awaitable<std::unique_ptr<HTTPResponse>> handle_request(std::shared_ptr<HTTPClient> c, HTTPRequest&& req);
|
||||
virtual asio::awaitable<std::unique_ptr<HTTPResponse>> handle_request(
|
||||
std::shared_ptr<HTTPClient> c, HTTPRequest&& req);
|
||||
virtual asio::awaitable<void> destroy_client(std::shared_ptr<HTTPClient> c);
|
||||
};
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@
|
||||
using namespace std;
|
||||
|
||||
static inline uint16_t collapse_checksum(uint32_t sum) {
|
||||
// It's impossible for this to be necessary more than twice: the first
|
||||
// addition can carry out at most a single bit.
|
||||
// It's impossible for this to be necessary more than twice: the first addition can carry out at most a single bit.
|
||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||
return (sum & 0xFFFF) + (sum >> 16);
|
||||
}
|
||||
|
||||
+84
-115
@@ -78,9 +78,8 @@ static string escape_hdlc_frame(const string& data, uint32_t escape_control_char
|
||||
return escape_hdlc_frame(data.data(), data.size(), escape_control_character_flags);
|
||||
}
|
||||
|
||||
// Note: these functions exist because seq nums are allowed to wrap around the
|
||||
// 32-bit integer space by design. We have to do the subtraction before the
|
||||
// comparison to allow integer overflow to occur if needed.
|
||||
// Note: these functions exist because seq nums are allowed to wrap around the 32-bit integer space by design. We have
|
||||
// to do the subtraction before the comparison to allow integer overflow to occur if needed.
|
||||
|
||||
static inline bool seq_num_less(uint32_t a, uint32_t b) {
|
||||
return (a - b) & 0x80000000;
|
||||
@@ -129,10 +128,7 @@ void IPSSClient::TCPConnection::linearize_outbound_data(size_t size) {
|
||||
}
|
||||
|
||||
IPSSClient::IPSSClient(
|
||||
shared_ptr<IPStackSimulator> sim,
|
||||
uint64_t network_id,
|
||||
VirtualNetworkProtocol protocol,
|
||||
asio::ip::tcp::socket&& sock)
|
||||
shared_ptr<IPStackSimulator> sim, uint64_t network_id, VirtualNetworkProtocol protocol, asio::ip::tcp::socket&& sock)
|
||||
: io_context(sim->get_io_context()),
|
||||
sim(sim),
|
||||
network_id(network_id),
|
||||
@@ -154,7 +150,9 @@ void IPSSClient::reschedule_idle_timeout() {
|
||||
this->idle_timeout_timer.async_wait([this, sim](std::error_code ec) {
|
||||
if (!ec) {
|
||||
sim->log.info_f("Idle timeout expired on N-{:X}", this->network_id);
|
||||
this->sock.close();
|
||||
if (this->sock.is_open()) {
|
||||
this->sock.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -164,7 +162,7 @@ IPSSChannel::IPSSChannel(
|
||||
std::weak_ptr<IPSSClient> ipss_client,
|
||||
std::weak_ptr<IPSSClient::TCPConnection> tcp_conn,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name,
|
||||
phosg::TerminalFormat terminal_send_color,
|
||||
phosg::TerminalFormat terminal_recv_color)
|
||||
@@ -177,8 +175,7 @@ IPSSChannel::IPSSChannel(
|
||||
std::string IPSSChannel::default_name() const {
|
||||
auto ipc = this->ipss_client.lock();
|
||||
if (ipc) {
|
||||
string addr_str = str_for_endpoint(ipc->sock.remote_endpoint());
|
||||
return std::format("ipss:N-{}:{}", ipc->network_id, addr_str);
|
||||
return std::format("ipss:N-{}:{}", ipc->network_id, str_for_endpoint(ipc->sock.remote_endpoint()));
|
||||
} else {
|
||||
return std::format("ipss:N-{}:__unknown_address__", ipc->network_id);
|
||||
}
|
||||
@@ -202,22 +199,18 @@ void IPSSChannel::disconnect() {
|
||||
}
|
||||
|
||||
void IPSSChannel::add_inbound_data(const void* data, size_t size) {
|
||||
// If recv_buf is not null, there is a coroutine waiting to receive data, and
|
||||
// inbound_data must be empty. Copy the data directly to the waiting
|
||||
// coroutine's buffer, and put the rest in this->inbound_data if needed.
|
||||
// If recv_buf is not null, there is a coroutine waiting to receive data, and inbound_data must be empty. Copy the
|
||||
// data directly to the waiting coroutine's buffer, and put the rest in this->inbound_data if needed.
|
||||
if (this->recv_buf) {
|
||||
size_t direct_size = min<size_t>(this->recv_buf_size, size);
|
||||
memcpy(this->recv_buf, data, direct_size);
|
||||
data = reinterpret_cast<const uint8_t*>(data) + direct_size;
|
||||
size -= direct_size;
|
||||
this->recv_buf_size -= direct_size;
|
||||
this->recv_buf = this->recv_buf_size
|
||||
? reinterpret_cast<uint8_t*>(this->recv_buf) + direct_size
|
||||
: nullptr;
|
||||
this->recv_buf = this->recv_buf_size ? (reinterpret_cast<uint8_t*>(this->recv_buf) + direct_size) : nullptr;
|
||||
}
|
||||
|
||||
// If there is still data left after the above, add it to the pending inbound
|
||||
// data buffer
|
||||
// If there is still data left after the above, add it to the pending inbound data buffer
|
||||
if (size > 0) {
|
||||
this->inbound_data.emplace_back(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
@@ -243,10 +236,9 @@ void IPSSChannel::send_raw(string&& data) {
|
||||
conn->outbound_data_bytes += data.size();
|
||||
conn->outbound_data.emplace_back(std::move(data));
|
||||
|
||||
// If we're already waiting for an ACK from the remote client, don't send
|
||||
// another PSH right now - we will either send another PSH when we receive
|
||||
// the ACK or will retry sending the PSH soon (which will then include the
|
||||
// new data, if it's within the MTU from the last acked sequence number).
|
||||
// If we're already waiting for an ACK from the remote client, don't send another PSH right now - we will either send
|
||||
// another PSH when we receive the ACK or will retry sending the PSH soon (which will then include the new data, if
|
||||
// it's within the MTU from the last acked sequence number).
|
||||
if (!conn->awaiting_ack) {
|
||||
sim->schedule_send_pending_push_frame(conn, 0);
|
||||
}
|
||||
@@ -274,8 +266,7 @@ asio::awaitable<void> IPSSChannel::recv_raw(void* data, size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
// If there's still more data to read, block until it's available
|
||||
// (add_inbound_data is responsible for waking this coroutine)
|
||||
// If there's still more data to read, block until it's available (add_inbound_data will wake this coroutine)
|
||||
if (size > 0) {
|
||||
this->recv_buf = data;
|
||||
this->recv_buf_size = size;
|
||||
@@ -308,9 +299,8 @@ void IPStackSimulator::listen(const std::string& name, const string& addr, int p
|
||||
}
|
||||
|
||||
uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_addr) {
|
||||
// Use an address not on the same subnet as the client, so that PSO Plus and
|
||||
// Episode III will think they're talking to a remote network and won't
|
||||
// reject the connection.
|
||||
// Use an address not on the same subnet as the client, so that PSO Plus and Episode III will think they're talking
|
||||
// to a remote network and won't reject the connection.
|
||||
return ((remote_addr & 0xFF000000) == 0x23000000) ? 0x24242424 : 0x23232323;
|
||||
}
|
||||
|
||||
@@ -336,6 +326,7 @@ uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(const FrameInfo& fi) {
|
||||
string IPStackSimulator::str_for_ipv4_netloc(uint32_t addr, uint16_t port) {
|
||||
be_uint32_t be_addr = addr;
|
||||
char addr_str[INET_ADDRSTRLEN];
|
||||
memset(addr_str, 0, sizeof(addr_str));
|
||||
if (!inet_ntop(AF_INET, &be_addr, addr_str, INET_ADDRSTRLEN)) {
|
||||
return std::format("<UNKNOWN>:{}", port);
|
||||
} else {
|
||||
@@ -354,11 +345,12 @@ string IPStackSimulator::str_for_tcp_connection(
|
||||
asio::awaitable<void> IPStackSimulator::send_ethernet_tapserver_frame(
|
||||
shared_ptr<IPSSClient> c, FrameInfo::Protocol proto, const void* data, size_t size) const {
|
||||
|
||||
struct {
|
||||
struct TapServerEthernetHeader {
|
||||
phosg::le_uint16_t frame_size;
|
||||
EthernetHeader ether;
|
||||
} header;
|
||||
static_assert(sizeof(header) == 0x10, "Ethernet tapserver header size is incorrect");
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(TapServerEthernetHeader) == 0x10, "Ethernet tapserver header size is incorrect");
|
||||
TapServerEthernetHeader header;
|
||||
|
||||
header.ether.dest_mac = c->mac_addr;
|
||||
header.ether.src_mac = this->host_mac_address_bytes;
|
||||
@@ -378,9 +370,7 @@ asio::awaitable<void> IPStackSimulator::send_ethernet_tapserver_frame(
|
||||
}
|
||||
header.frame_size = size + sizeof(EthernetHeader);
|
||||
|
||||
array<asio::const_buffer, 2> bufs{
|
||||
asio::buffer(static_cast<const void*>(&header), sizeof(header)),
|
||||
asio::buffer(data, size)};
|
||||
array<asio::const_buffer, 2> bufs{asio::buffer(static_cast<const void*>(&header), sizeof(header)), asio::buffer(data, size)};
|
||||
co_await asio::async_write(c->sock, bufs, asio::use_awaitable);
|
||||
}
|
||||
|
||||
@@ -462,8 +452,7 @@ asio::awaitable<void> IPStackSimulator::on_client_frame(shared_ptr<IPSSClient> c
|
||||
|
||||
FrameInfo fi(link_type, data, size);
|
||||
if (this->log.should_log(phosg::LogLevel::L_DEBUG)) {
|
||||
string fi_header = fi.header_str();
|
||||
this->log.debug_f("Frame header: {}", fi_header);
|
||||
this->log.debug_f("Frame header: {}", fi.header_str());
|
||||
}
|
||||
|
||||
if (fi.ether) {
|
||||
@@ -477,8 +466,7 @@ asio::awaitable<void> IPStackSimulator::on_client_frame(shared_ptr<IPSSClient> c
|
||||
uint16_t stored_checksum = fi.stored_hdlc_checksum();
|
||||
if (expected_checksum != stored_checksum) {
|
||||
throw runtime_error(std::format(
|
||||
"HDLC checksum is incorrect ({:04X} expected, {:04X} received)",
|
||||
expected_checksum, stored_checksum));
|
||||
"HDLC checksum is incorrect ({:04X} expected, {:04X} received)", expected_checksum, stored_checksum));
|
||||
}
|
||||
} else {
|
||||
throw runtime_error("frame is not Ethernet or HDLC");
|
||||
@@ -500,8 +488,7 @@ asio::awaitable<void> IPStackSimulator::on_client_frame(shared_ptr<IPSSClient> c
|
||||
uint16_t expected_ipv4_checksum = fi.computed_ipv4_header_checksum();
|
||||
if (fi.ipv4->checksum != expected_ipv4_checksum) {
|
||||
throw runtime_error(std::format(
|
||||
"IPv4 header checksum is incorrect ({:04X} expected, {:04X} received)",
|
||||
expected_ipv4_checksum, fi.ipv4->checksum));
|
||||
"IPv4 header checksum is incorrect ({:04X} expected, {:04X} received)", expected_ipv4_checksum, fi.ipv4->checksum));
|
||||
}
|
||||
|
||||
if ((fi.ipv4->src_addr != c->ipv4_addr) && (fi.ipv4->src_addr != 0)) {
|
||||
@@ -512,8 +499,7 @@ asio::awaitable<void> IPStackSimulator::on_client_frame(shared_ptr<IPSSClient> c
|
||||
uint16_t expected_udp_checksum = fi.computed_udp4_checksum();
|
||||
if (fi.udp->checksum != expected_udp_checksum) {
|
||||
throw runtime_error(std::format(
|
||||
"UDP checksum is incorrect ({:04X} expected, {:04X} received)",
|
||||
expected_udp_checksum, fi.udp->checksum));
|
||||
"UDP checksum is incorrect ({:04X} expected, {:04X} received)", expected_udp_checksum, fi.udp->checksum));
|
||||
}
|
||||
co_await this->on_client_udp_frame(c, fi);
|
||||
|
||||
@@ -521,8 +507,7 @@ asio::awaitable<void> IPStackSimulator::on_client_frame(shared_ptr<IPSSClient> c
|
||||
uint16_t expected_tcp_checksum = fi.computed_tcp4_checksum();
|
||||
if (fi.tcp->checksum != expected_tcp_checksum) {
|
||||
throw runtime_error(std::format(
|
||||
"TCP checksum is incorrect ({:04X} expected, {:04X} received)",
|
||||
expected_tcp_checksum, fi.tcp->checksum));
|
||||
"TCP checksum is incorrect ({:04X} expected, {:04X} received)", expected_tcp_checksum, fi.tcp->checksum));
|
||||
}
|
||||
co_await this->on_client_tcp_frame(c, fi);
|
||||
|
||||
@@ -564,10 +549,9 @@ asio::awaitable<void> IPStackSimulator::on_client_lcp_frame(shared_ptr<IPSSClien
|
||||
throw runtime_error("unknown LCP option");
|
||||
}
|
||||
}
|
||||
// Technically, we should implement the LCP state machine, but I'm too
|
||||
// lazy to do this right now. In our situation, it should suffice to
|
||||
// simply always send a Configure-Request to the client with a magic
|
||||
// number not equal to the one we received.
|
||||
// Technically, we should implement the LCP state machine, but I'm too lazy to do this right now. In our
|
||||
// situation, it should suffice to simply always send a Configure-Request to the client with a magic number not
|
||||
// equal to the one we received.
|
||||
phosg::StringWriter opts_w;
|
||||
opts_w.put_u8(0x01); // Maximum receive unit
|
||||
opts_w.put_u8(0x04);
|
||||
@@ -709,8 +693,7 @@ asio::awaitable<void> IPStackSimulator::on_client_ipcp_frame(shared_ptr<IPSSClie
|
||||
} else if ((remote_ip != 0x1E1E1E1E) ||
|
||||
(remote_primary_dns != 0x23232323) ||
|
||||
(remote_secondary_dns != 0x24242424)) {
|
||||
// Send a Configure-Nak if the client's request doesn't exactly match
|
||||
// what we want them to use.
|
||||
// Send a Configure-Nak if the client's request doesn't exactly match what we want them to use.
|
||||
phosg::StringWriter opts_w;
|
||||
opts_w.put_u8(0x03); // IP address
|
||||
opts_w.put_u8(0x06);
|
||||
@@ -734,8 +717,7 @@ asio::awaitable<void> IPStackSimulator::on_client_ipcp_frame(shared_ptr<IPSSClie
|
||||
} else { // Options OK
|
||||
c->ipv4_addr = remote_ip;
|
||||
|
||||
// As with LCP, we technically should implement the state machine, but I
|
||||
// continue to be lazy.
|
||||
// As with LCP, we technically should implement the state machine, but I continue to be lazy.
|
||||
phosg::StringWriter opts_w;
|
||||
opts_w.put_u8(0x03); // IP address
|
||||
opts_w.put_u8(0x06);
|
||||
@@ -815,15 +797,15 @@ asio::awaitable<void> IPStackSimulator::on_client_arp_frame(shared_ptr<IPSSClien
|
||||
});
|
||||
|
||||
// The incoming payload is:
|
||||
// uint8_t src_mac[6]; // MAC address of client
|
||||
// uint8_t src_ip[4]; // IP address of client
|
||||
// uint8_t dest_mac[6]; // MAC address of host (all zeroes)
|
||||
// uint8_t dest_ip[4]; // IP address of host
|
||||
// uint8_t src_mac[6]; // MAC address of client
|
||||
// uint8_t src_ip[4]; // IP address of client
|
||||
// uint8_t dest_mac[6]; // MAC address of host (all zeroes)
|
||||
// uint8_t dest_ip[4]; // IP address of host
|
||||
// The outgoing payload is:
|
||||
// uint8_t dest_mac[6]; // MAC address of host (from configuration)
|
||||
// uint8_t dest_ip[4]; // IP address of host
|
||||
// uint8_t src_mac[6]; // MAC address of client
|
||||
// uint8_t src_ip[4]; // IP address of client
|
||||
// uint8_t dest_mac[6]; // MAC address of host (from configuration)
|
||||
// uint8_t dest_ip[4]; // IP address of host
|
||||
// uint8_t src_mac[6]; // MAC address of client
|
||||
// uint8_t src_ip[4]; // IP address of client
|
||||
const char* payload_bytes = reinterpret_cast<const char*>(fi.payload);
|
||||
w.write(this->host_mac_address_bytes.data(), 6);
|
||||
w.write(payload_bytes + 16, 4);
|
||||
@@ -835,9 +817,7 @@ asio::awaitable<void> IPStackSimulator::on_client_arp_frame(shared_ptr<IPSSClien
|
||||
asio::awaitable<void> IPStackSimulator::on_client_udp_frame(shared_ptr<IPSSClient> c, const FrameInfo& fi) {
|
||||
// We only implement DHCP and newserv's DNS server here.
|
||||
|
||||
// Every received UDP packet will elicit exactly one UDP response from
|
||||
// newserv, so we prepare the response headers in advance
|
||||
|
||||
// Every received UDP packet will elicit exactly one UDP response from newserv, so we prepare the headers in advance
|
||||
IPv4Header r_ipv4;
|
||||
r_ipv4.version_ihl = 0x45;
|
||||
r_ipv4.tos = 0;
|
||||
@@ -897,8 +877,8 @@ asio::awaitable<void> IPStackSimulator::on_client_udp_frame(shared_ptr<IPSSClien
|
||||
// Populate the client's addresses
|
||||
c->mac_addr = dhcp.client_hardware_address.data();
|
||||
c->ipv4_addr = 0x0A000105; // 10.0.1.5
|
||||
// In this case, the client doesn't know its IPv4 address or ours yet,
|
||||
// so we overwrite the existing fields with the appropriate addresses.
|
||||
// In this case, the client doesn't know its IPv4 address or ours yet, so we overwrite the existing fields with
|
||||
// the appropriate addresses.
|
||||
r_ipv4.src_addr = 0x0A000101; // 10.0.1.1
|
||||
r_ipv4.dest_addr = c->ipv4_addr;
|
||||
|
||||
@@ -988,8 +968,7 @@ asio::awaitable<void> IPStackSimulator::on_client_udp_frame(shared_ptr<IPSSClien
|
||||
r_ipv4.size = sizeof(IPv4Header) + sizeof(UDPHeader) + r_data.size();
|
||||
r_udp.size = sizeof(UDPHeader) + r_data.size();
|
||||
r_ipv4.checksum = FrameInfo::computed_ipv4_header_checksum(r_ipv4);
|
||||
r_udp.checksum = FrameInfo::computed_udp4_checksum(
|
||||
r_ipv4, r_udp, r_data.data(), r_data.size());
|
||||
r_udp.checksum = FrameInfo::computed_udp4_checksum(r_ipv4, r_udp, r_data.data(), r_data.size());
|
||||
|
||||
if (this->log.should_log(phosg::LogLevel::L_DEBUG)) {
|
||||
string remote_str = this->str_for_ipv4_netloc(fi.ipv4->src_addr, fi.udp->src_port);
|
||||
@@ -1015,8 +994,8 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
}
|
||||
|
||||
if (fi.tcp->flags & TCPHeader::Flag::SYN) {
|
||||
// We never make connections back to the client, so we should never receive
|
||||
// a SYN+ACK. Essentially, no other flags should be set in any received SYN.
|
||||
// We never make connections back to the client, so we should never receive a SYN+ACK. Essentially, no other flags
|
||||
// should be set in any received SYN.
|
||||
if ((fi.tcp->flags & 0x0FFF) != TCPHeader::Flag::SYN) {
|
||||
throw runtime_error("TCP SYN contains extra flags");
|
||||
}
|
||||
@@ -1091,8 +1070,7 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
if (!conn->awaiting_first_ack) {
|
||||
throw logic_error("SYN received on already-open connection after initial phase");
|
||||
}
|
||||
// TODO: We should check the syn/ack numbers here instead of just assuming
|
||||
// they're correct
|
||||
// TODO: We should check the syn/ack numbers here instead of just assuming they're correct
|
||||
conn_str = this->str_for_tcp_connection(c, conn);
|
||||
this->log.debug_f("Client resent SYN for TCP connection {}", conn_str);
|
||||
}
|
||||
@@ -1103,11 +1081,14 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
conn_str, conn->acked_server_seq, conn->next_client_seq);
|
||||
|
||||
} else {
|
||||
// This frame isn't a SYN, so a connection object should already exist
|
||||
// This frame isn't a SYN, so a connection object should already exist; ignore the frame if there's no connection
|
||||
uint64_t key = this->tcp_conn_key_for_client_frame(fi);
|
||||
auto conn_it = c->tcp_connections.find(key);
|
||||
if (conn_it == c->tcp_connections.end()) {
|
||||
throw runtime_error("non-SYN frame does not correspond to any open TCP connection");
|
||||
if (this->log.debug_f("Ignoring non-SYN TCP frame with no active connection")) {
|
||||
phosg::print_data(stderr, fi.payload, fi.payload_size);
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
auto& conn = conn_it->second;
|
||||
bool conn_valid = true;
|
||||
@@ -1164,24 +1145,20 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
conn->server_channel.reset();
|
||||
}
|
||||
|
||||
// TODO: Are we supposed to send a response to an RST? Here we do, and the
|
||||
// client probably just ignores it anyway
|
||||
// TODO: Are we supposed to send a response to an RST? Here we do, and the client probably just ignores it anyway
|
||||
co_await this->send_tcp_frame(c, conn, fi.tcp->flags & (TCPHeader::Flag::RST | TCPHeader::Flag::FIN));
|
||||
|
||||
// Delete the connection object. The unique_ptr destructor flushes the
|
||||
// bufferevent, and thereby sends an EOF to the server's end.
|
||||
// Delete the connection object. The unique_ptr destructor flushes the bufferevent, and thereby sends an EOF to
|
||||
// the server's end.
|
||||
c->tcp_connections.erase(key);
|
||||
conn_valid = false;
|
||||
|
||||
} else if (fi.payload_size != 0) {
|
||||
// Note: The PSH flag isn't required to be set on all packets that
|
||||
// contain data. The PSH flag just means "tell the application that data
|
||||
// is available", so some senders only set the PSH flag on the last frame
|
||||
// of a large segment of data, since the application wouldn't be able to
|
||||
// process the segment until all of it is available. newserv can handle
|
||||
// incomplete commands, so we just ignore the PSH flag and forward any
|
||||
// data to the server immediately (hence the lack of a flag check in the
|
||||
// above condition).
|
||||
// Note: The PSH flag isn't required to be set on all packets that contain data. The PSH flag just means "tell
|
||||
// the application that data is available", so some senders only set the PSH flag on the last frame of a large
|
||||
// segment of data, since the application wouldn't be able to process the segment until all of it is available.
|
||||
// newserv can handle incomplete commands, so we just ignore the PSH flag and forward any data to the server
|
||||
// immediately (hence the lack of a flag check in the above condition).
|
||||
|
||||
string conn_str = this->log.should_log(phosg::LogLevel::L_WARNING)
|
||||
? this->str_for_tcp_connection(c, conn)
|
||||
@@ -1192,8 +1169,8 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
payload_skip_bytes = 0;
|
||||
|
||||
} else if (seq_num_less(fi.tcp->seq_num, conn->next_client_seq)) {
|
||||
// If the frame overlaps an existing boundary, we'll accept some of the
|
||||
// data; otherwise we'll ignore it entirely (but still send an ACK)
|
||||
// If the frame overlaps an existing boundary, we'll accept some of the data; otherwise we'll ignore it
|
||||
// entirely (but still send an ACK)
|
||||
uint32_t end_seq = fi.tcp->seq_num + fi.payload_size;
|
||||
if (seq_num_less_or_equal(end_seq, conn->next_client_seq)) { // Fully "in the past"
|
||||
payload_skip_bytes = fi.payload_size;
|
||||
@@ -1202,9 +1179,8 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
}
|
||||
|
||||
} else {
|
||||
// Payload is in the future - we must have missed a data frame. We'll
|
||||
// ignore it (but warn) and send an ACK later, and the client should
|
||||
// retransmit the lost data
|
||||
// Payload is in the future - we must have missed a data frame. We'll ignore it (but warn) and send an ACK
|
||||
// later, and the client should retransmit the lost data
|
||||
this->log.warning_f(
|
||||
"Client sent out-of-order sequence number (expected {:08X}, received {:08X}, 0x{:X} data bytes)",
|
||||
conn->next_client_seq, fi.tcp->seq_num, fi.payload_size);
|
||||
@@ -1233,11 +1209,9 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
|
||||
// Send the new data to the server
|
||||
if (!conn->server_channel) {
|
||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is missing",
|
||||
conn_str);
|
||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is missing", conn_str);
|
||||
} else if (!conn->server_channel->connected()) {
|
||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is disconnected",
|
||||
conn_str);
|
||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is disconnected", conn_str);
|
||||
} else {
|
||||
conn->server_channel->add_inbound_data(payload, payload_size);
|
||||
}
|
||||
@@ -1246,8 +1220,7 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
||||
conn->next_client_seq += payload_size;
|
||||
conn->bytes_received += payload_size;
|
||||
if (conn->next_client_seq < payload_size) {
|
||||
this->log.warning_f("Client sequence number has wrapped (next={:08X}, bytes={:X})",
|
||||
fi.tcp->seq_num, payload_size);
|
||||
this->log.warning_f("Client sequence number has wrapped (next={:08X}, bytes={:X})", fi.tcp->seq_num, payload_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,10 +1270,8 @@ asio::awaitable<void> IPStackSimulator::send_pending_push_frame(
|
||||
|
||||
size_t bytes_to_send = min<size_t>(conn->outbound_data_bytes, conn->next_push_max_frame_size);
|
||||
if (c->protocol == VirtualNetworkProtocol::HDLC_TAPSERVER) {
|
||||
// There is a bug in Dolphin's modem implementation (which I wrote, so it's
|
||||
// my fault) that causes commands to be dropped when too much data is sent
|
||||
// at once. To work around this, we only send up to 200 bytes in each push
|
||||
// frame.
|
||||
// There is a bug in Dolphin's modem implementation (which I wrote, so it's my fault) that causes commands to be
|
||||
// dropped when too much data is sent. To work around this, we only send up to 200 bytes in each push frame.
|
||||
bytes_to_send = min<size_t>(bytes_to_send, 200);
|
||||
}
|
||||
|
||||
@@ -1309,23 +1280,20 @@ asio::awaitable<void> IPStackSimulator::send_pending_push_frame(
|
||||
|
||||
conn->linearize_outbound_data(bytes_to_send);
|
||||
if (conn->outbound_data.empty() || conn->outbound_data.front().size() < bytes_to_send) {
|
||||
// This should never happen because bytes_to_send should always be less
|
||||
// than or equal to conn->outbound_data_bytes, which itself should be equal
|
||||
// to the number of bytes that can be linearized
|
||||
// This should never happen because bytes_to_send should always be less than or equal to conn->outbound_data_bytes,
|
||||
// which itself should be equal to the number of bytes that can be linearized
|
||||
throw logic_error("failed to linearize enough bytes before sending TCP PSH");
|
||||
}
|
||||
co_await this->send_tcp_frame(c, conn, TCPHeader::Flag::PSH, conn->outbound_data.front().data(), bytes_to_send);
|
||||
conn->awaiting_ack = true;
|
||||
|
||||
// Schedule the timer for sending another PSH, in case the client doesn't
|
||||
// respond quickly enough
|
||||
// Schedule the timer for sending another PSH, in case the client doesn't respond quickly enough
|
||||
this->schedule_send_pending_push_frame(conn, conn->resend_push_usecs);
|
||||
|
||||
// If the client isn't responding to our PSHes, back off exponentially up to
|
||||
// a limit of 5 seconds between PSH frames. This window is reset when
|
||||
// acked_server_seq changes (that is, when the client has acknowledged any new
|
||||
// data). It seems some situations cause GameCube clients to drop packets more
|
||||
// often; to alleviate this, we also try to resend less data.
|
||||
// If the client isn't responding to our PSHes, back off exponentially up to a limit of 5 seconds between PSH frames.
|
||||
// This window is reset when acked_server_seq changes (that is, when the client has acknowledged any new data). It
|
||||
// seems some situations cause GameCube clients to drop packets more often; to alleviate this, we also try to resend
|
||||
// less data.
|
||||
conn->resend_push_usecs *= 2;
|
||||
if (conn->resend_push_usecs > 5000000) {
|
||||
conn->resend_push_usecs = 5000000;
|
||||
@@ -1396,7 +1364,7 @@ asio::awaitable<void> IPStackSimulator::open_server_connection(
|
||||
}
|
||||
const auto& port_config = port_config_it->second;
|
||||
|
||||
conn->server_channel = make_shared<IPSSChannel>(this->shared_from_this(), c, conn, port_config->version, 1);
|
||||
conn->server_channel = make_shared<IPSSChannel>(this->shared_from_this(), c, conn, port_config->version, Language::ENGLISH);
|
||||
|
||||
if (!this->state->game_server.get()) {
|
||||
this->log.error_f("No server available for TCP connection {}", conn_str);
|
||||
@@ -1410,9 +1378,8 @@ asio::awaitable<void> IPStackSimulator::open_server_connection(
|
||||
|
||||
asio::awaitable<void> IPStackSimulator::close_tcp_connection(
|
||||
shared_ptr<IPSSClient> c, shared_ptr<IPSSClient::TCPConnection> conn) {
|
||||
// Send an RST to the client. This is kind of rude (we really should use FIN)
|
||||
// but the PSO network stack always sends an RST to us when disconnecting, so
|
||||
// whatever
|
||||
// Send an RST to the client. This is kind of rude (we really should use FIN) but the PSO network stack always sends
|
||||
// an RST to us when disconnecting, so whatever
|
||||
co_await this->send_tcp_frame(c, conn, TCPHeader::Flag::RST);
|
||||
|
||||
// Delete the connection object
|
||||
@@ -1425,7 +1392,9 @@ std::shared_ptr<IPSSClient> IPStackSimulator::create_client(
|
||||
std::shared_ptr<IPSSSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
||||
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
||||
if (this->state->banned_ipv4_ranges->check(addr)) {
|
||||
client_sock.close();
|
||||
if (client_sock.is_open()) {
|
||||
client_sock.close();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
std::weak_ptr<IPSSClient> ipss_client,
|
||||
std::weak_ptr<IPSSClient::TCPConnection> tcp_conn,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
Language language,
|
||||
const std::string& name = "",
|
||||
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
|
||||
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ string encode_gvm(const phosg::ImageRGBA8888N& img, GVRDataFormat data_format, c
|
||||
w.put<GVMFileHeader>({.signature = 0x47564D48, .header_size = 0x48, .flags = 0x000F, .num_files = 1});
|
||||
GVMFileEntry file_entry;
|
||||
file_entry.file_num = 0;
|
||||
file_entry.name.encode(internal_name, 1);
|
||||
file_entry.name.encode(internal_name, Language::ENGLISH);
|
||||
file_entry.data_format = data_format;
|
||||
file_entry.format_flags = 0;
|
||||
file_entry.dimensions = (dimensions_field << 4) | dimensions_field;
|
||||
|
||||
+4
-1
@@ -20,7 +20,10 @@ enum class GVRDataFormat : uint8_t {
|
||||
};
|
||||
|
||||
std::string encode_gvm(
|
||||
const phosg::ImageRGBA8888N& img, GVRDataFormat data_format, const std::string& internal_name, uint32_t global_index);
|
||||
const phosg::ImageRGBA8888N& img,
|
||||
GVRDataFormat data_format,
|
||||
const std::string& internal_name,
|
||||
uint32_t global_index);
|
||||
phosg::ImageRGB888 decode_fon(const std::string& data, size_t width);
|
||||
std::string encode_fon(const phosg::ImageRGB888& img);
|
||||
|
||||
|
||||
@@ -164,8 +164,7 @@ string IntegralExpression::UnaryOperatorNode::str() const {
|
||||
}
|
||||
}
|
||||
|
||||
IntegralExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index)
|
||||
: flag_index(flag_index) {}
|
||||
IntegralExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index) : flag_index(flag_index) {}
|
||||
|
||||
bool IntegralExpression::FlagLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
@@ -187,10 +186,8 @@ string IntegralExpression::FlagLookupNode::str() const {
|
||||
return std::format("F_{:04X}", this->flag_index);
|
||||
}
|
||||
|
||||
IntegralExpression::ChallengeCompletionLookupNode::ChallengeCompletionLookupNode(
|
||||
Episode episode, uint8_t stage_index)
|
||||
: episode(episode),
|
||||
stage_index(stage_index) {}
|
||||
IntegralExpression::ChallengeCompletionLookupNode::ChallengeCompletionLookupNode(Episode episode, uint8_t stage_index)
|
||||
: episode(episode), stage_index(stage_index) {}
|
||||
|
||||
bool IntegralExpression::ChallengeCompletionLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
@@ -217,8 +214,7 @@ string IntegralExpression::ChallengeCompletionLookupNode::str() const {
|
||||
return std::format("CC_{}_{}", abbreviation_for_episode(this->episode), static_cast<uint8_t>(this->stage_index + 1));
|
||||
}
|
||||
|
||||
IntegralExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name)
|
||||
: reward_name(reward_name) {}
|
||||
IntegralExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name) : reward_name(reward_name) {}
|
||||
|
||||
bool IntegralExpression::TeamRewardLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
@@ -310,9 +306,8 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
|
||||
text = text.substr(0, text.size() - 1);
|
||||
}
|
||||
if (text.at(0) == '(' && text.at(text.size() - 1) == ')') {
|
||||
// It doesn't suffice to just check the first ant last characters, since
|
||||
// text could be like "(a) && (b)". Instead, we ignore the first and last
|
||||
// characters, and don't strip anything if the internal parentheses are
|
||||
// It doesn't suffice to just check the first and last characters, since text could be like "(a) && (b)".
|
||||
// Instead, we ignore the first and last characters, and don't strip anything if the internal parentheses are
|
||||
// unbalanced.
|
||||
size_t paren_level = 1;
|
||||
for (size_t z = 1; z < text.size() - 1; z++) {
|
||||
@@ -363,10 +358,8 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
|
||||
}
|
||||
if (!paren_level) {
|
||||
for (const auto& oper : operators) {
|
||||
// Awful hack (because I'm too lazy to add a tokenization step): if
|
||||
// the operator is followed or preceded by another copy of itself,
|
||||
// don't match it (this prevents us from matching & when the token is
|
||||
// actually &&)
|
||||
// Awful hack (because I'm too lazy to add a tokenization step): if the operator is followed or preceded by
|
||||
// another copy of itself, don't match it (this prevents us from matching & when the token is actually &&)
|
||||
if ((text.size() > z + oper.first.size()) &&
|
||||
((z < oper.first.size()) || (text.compare(z - oper.first.size(), oper.first.size(), oper.first) != 0)) &&
|
||||
(text.compare(z, oper.first.size(), oper.first) == 0) &&
|
||||
|
||||
+402
-445
File diff suppressed because it is too large
Load Diff
+58
-55
@@ -9,6 +9,11 @@
|
||||
#include "RareItemSet.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
// This file and ItemCreator.cc are essentially a direct reverse-engineering of the item creation algorithm in PSO GC.
|
||||
// Only minor changes have been made to support BB (as described in the comments in the implementation) and to support
|
||||
// cross-episode quests. The latter consists mostly of delaying table_index lookups and ItemPT table lookups until much
|
||||
// later than in the original implementation; the actual logic for generating item data is the same.
|
||||
|
||||
class ItemCreator {
|
||||
public:
|
||||
ItemCreator(
|
||||
@@ -20,9 +25,8 @@ public:
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
std::shared_ptr<const ItemData::StackLimits> stack_limits,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
Difficulty difficulty,
|
||||
uint8_t section_id,
|
||||
std::shared_ptr<RandomGenerator> rand_crypt,
|
||||
std::shared_ptr<const BattleRules> restrictions = nullptr);
|
||||
@@ -33,13 +37,21 @@ public:
|
||||
bool is_from_rare_table = false;
|
||||
};
|
||||
|
||||
DropResult on_monster_item_drop(uint32_t enemy_type, uint8_t area);
|
||||
DropResult on_box_item_drop(uint8_t area);
|
||||
inline void set_legacy_replay() {
|
||||
this->is_legacy_replay = true;
|
||||
}
|
||||
inline void set_rare_drop_rate_multiplier(double multiplier) {
|
||||
this->rare_drop_rate_multiplier = multiplier;
|
||||
}
|
||||
|
||||
DropResult on_monster_item_drop(EnemyType enemy_type, uint8_t area, bool force_rare);
|
||||
DropResult on_box_item_drop(uint8_t area, bool force_rare);
|
||||
// Note: param3-6 refer to the corresponding fields of the object definition
|
||||
DropResult on_specialized_box_item_drop(uint8_t area, float param3, uint32_t param4, uint32_t param5, uint32_t param6);
|
||||
DropResult on_specialized_box_item_drop(
|
||||
uint8_t area, float param3, uint32_t param4, uint32_t param5, uint32_t param6);
|
||||
ItemData base_item_for_specialized_box(uint32_t param4, uint32_t param5, uint32_t param6) const;
|
||||
|
||||
std::vector<ItemData> generate_armor_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_armor_shop_contents(Episode episode, size_t player_level);
|
||||
std::vector<ItemData> generate_tool_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_weapon_shop_contents(size_t player_level);
|
||||
|
||||
@@ -56,12 +68,20 @@ public:
|
||||
void set_section_id(uint8_t new_section_id);
|
||||
|
||||
private:
|
||||
inline std::shared_ptr<const CommonItemSet::Table> pt(Episode episode) const {
|
||||
return this->common_item_set->get_table(episode, this->mode, this->difficulty, this->section_id);
|
||||
}
|
||||
inline std::shared_ptr<const CommonItemSet::Table> pt(uint8_t area) const {
|
||||
return this->pt(episode_for_area(area));
|
||||
}
|
||||
|
||||
phosg::PrefixedLogger log;
|
||||
Version logic_version;
|
||||
bool is_legacy_replay;
|
||||
double rare_drop_rate_multiplier = 1.0;
|
||||
std::shared_ptr<const ItemData::StackLimits> stack_limits;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty;
|
||||
Difficulty difficulty;
|
||||
uint8_t section_id;
|
||||
std::shared_ptr<const RareItemSet> rare_item_set;
|
||||
std::shared_ptr<const ArmorRandomSet> armor_random_set;
|
||||
@@ -70,7 +90,6 @@ private:
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set;
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table;
|
||||
std::shared_ptr<const CommonItemSet> common_item_set;
|
||||
std::shared_ptr<const CommonItemSet::Table> pt;
|
||||
std::shared_ptr<const BattleRules> restrictions;
|
||||
|
||||
struct UnitResult {
|
||||
@@ -102,42 +121,38 @@ private:
|
||||
std::shared_ptr<RandomGenerator> rand_crypt;
|
||||
|
||||
bool are_rare_drops_allowed() const;
|
||||
uint8_t normalize_area_number(uint8_t area) const;
|
||||
|
||||
DropResult on_monster_item_drop_with_area_norm(uint32_t enemy_type, uint8_t area_norm);
|
||||
DropResult on_box_item_drop_with_area_norm(uint8_t area_norm);
|
||||
uint8_t table_index_for_area(uint8_t area) const;
|
||||
|
||||
uint32_t rand_int(uint64_t max);
|
||||
float rand_float_0_1_from_crypt();
|
||||
|
||||
template <size_t NumRanges>
|
||||
uint32_t choose_meseta_amount(
|
||||
const parray<CommonItemSet::Table::Range<uint16_t>, NumRanges> ranges,
|
||||
size_t table_index);
|
||||
uint32_t choose_meseta_amount(const CommonItemSet::Table::Range<uint16_t>& range);
|
||||
|
||||
bool should_allow_meseta_drops() const;
|
||||
|
||||
ItemData check_rare_spec_and_create_rare_enemy_item(uint32_t enemy_type, uint8_t area_norm);
|
||||
ItemData check_rare_specs_and_create_rare_box_item(uint8_t area_norm);
|
||||
ItemData check_rate_and_create_rare_item(const RareItemSet::ExpandedDrop& drop, uint8_t area_norm);
|
||||
ItemData check_rare_spec_and_create_rare_enemy_item(EnemyType enemy_type, uint8_t area, bool force_rare);
|
||||
ItemData check_rare_specs_and_create_rare_box_item(uint8_t area, bool force_rare);
|
||||
ItemData check_rare_specs_and_create_rare_item(
|
||||
const std::vector<RareItemSet::ExpandedDrop>& specs, uint8_t area, bool force_rare);
|
||||
ItemData create_rare_item(const ItemData& drop_item, uint8_t area);
|
||||
|
||||
void generate_rare_weapon_bonuses(ItemData& item, uint32_t random_sample);
|
||||
void generate_rare_weapon_bonuses(ItemData& item, Episode episode, uint32_t random_sample);
|
||||
void deduplicate_weapon_bonuses(ItemData& item) const;
|
||||
void set_item_kill_count_if_unsealable(ItemData& item) const;
|
||||
void set_item_unidentified_flag_if_not_challenge(ItemData& item) const;
|
||||
void set_tool_item_amount_to_1(ItemData& item) const;
|
||||
|
||||
void generate_common_item_variances(uint32_t area_norm, ItemData& item);
|
||||
void generate_common_armor_slots_and_bonuses(ItemData& item);
|
||||
void generate_common_armor_slot_count(ItemData& item);
|
||||
void generate_common_armor_or_shield_type_and_variances(char area_norm, ItemData& item);
|
||||
void generate_common_tool_variances(uint32_t area_norm, ItemData& item);
|
||||
uint8_t generate_tech_disk_level(uint32_t tech_num, uint32_t area_norm);
|
||||
void generate_common_item_variances(ItemData& item, uint8_t area);
|
||||
void generate_common_armor_slots_and_bonuses(ItemData& item, Episode episode);
|
||||
void generate_common_armor_slot_count(ItemData& item, Episode episode);
|
||||
void generate_common_armor_or_shield_type_and_variances(ItemData& item, uint8_t area);
|
||||
void generate_common_tool_variances(ItemData& item, uint8_t area);
|
||||
uint8_t generate_tech_disk_level(uint32_t tech_num, uint8_t area);
|
||||
void generate_common_mag_variances(ItemData& item);
|
||||
void generate_common_weapon_variances(uint8_t area_norm, ItemData& item);
|
||||
void generate_common_weapon_grind(ItemData& item, uint8_t offset_within_subtype_range);
|
||||
void generate_common_weapon_bonuses(ItemData& item, uint8_t area_norm);
|
||||
void generate_common_weapon_special(ItemData& item, uint8_t area_norm);
|
||||
void generate_common_weapon_variances(ItemData& item, uint8_t area);
|
||||
void generate_common_weapon_grind(ItemData& item, uint8_t area, uint8_t offset_within_subtype_range);
|
||||
void generate_common_weapon_bonuses(ItemData& item, uint8_t area);
|
||||
void generate_common_weapon_special(ItemData& item, uint8_t area);
|
||||
uint8_t choose_weapon_special(uint8_t det);
|
||||
void generate_unit_stars_tables();
|
||||
void generate_common_unit_variances(uint8_t stars, ItemData& item);
|
||||
@@ -146,28 +161,18 @@ private:
|
||||
void clear_item_if_restricted(ItemData& item) const;
|
||||
|
||||
static size_t get_table_index_for_armor_shop(size_t player_level);
|
||||
static bool shop_does_not_contain_duplicate_armor(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_tech_disk(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_or_too_many_similar_weapons(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_item_by_data1_0_1_2(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
void generate_armor_shop_armors(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_shields(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_units(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
static bool shop_does_not_contain_duplicate_armor(const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_tech_disk(const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_or_too_many_similar_weapons(const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_item_by_data1_0_1_2(const std::vector<ItemData>& shop, const ItemData& item);
|
||||
void generate_armor_shop_armors(std::vector<ItemData>& shop, Episode episode, size_t player_level);
|
||||
void generate_armor_shop_shields(std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_units(std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
static size_t get_table_index_for_tool_shop(size_t player_level);
|
||||
void generate_common_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_rare_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_tool_shop_tech_disks(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_common_tool_shop_recovery_items(std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_rare_tool_shop_recovery_items(std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_tool_shop_tech_disks(std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
void generate_weapon_shop_item_grind(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_special(ItemData& item, size_t player_level);
|
||||
@@ -175,11 +180,9 @@ private:
|
||||
void generate_weapon_shop_item_bonus2(ItemData& item, size_t player_level);
|
||||
|
||||
template <typename IntT>
|
||||
IntT get_rand_from_weighted_tables(
|
||||
const IntT* tables, size_t offset, size_t num_values, size_t stride);
|
||||
IntT get_rand_from_weighted_tables(const IntT* tables, size_t offset, size_t num_values, size_t stride);
|
||||
template <typename IntT, size_t X>
|
||||
IntT get_rand_from_weighted_tables_1d(const parray<IntT, X>& tables);
|
||||
template <typename IntT, size_t X, size_t Y>
|
||||
IntT get_rand_from_weighted_tables_2d_vertical(
|
||||
const parray<parray<IntT, X>, Y>& tables, size_t offset);
|
||||
IntT get_rand_from_weighted_tables_2d_vertical(const parray<parray<IntT, X>, Y>& tables, size_t offset);
|
||||
};
|
||||
|
||||
+14
-29
@@ -8,10 +8,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
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_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});
|
||||
|
||||
@@ -28,8 +26,7 @@ ItemData::StackLimits::StackLimits(
|
||||
max_tool_stack_sizes_by_data1_1(max_tool_stack_sizes_by_data1_1),
|
||||
max_meseta_stack_size(max_meseta_stack_size) {}
|
||||
|
||||
ItemData::StackLimits::StackLimits(Version version, const phosg::JSON& json)
|
||||
: version(version) {
|
||||
ItemData::StackLimits::StackLimits(Version version, const phosg::JSON& json) : version(version) {
|
||||
this->max_tool_stack_sizes_by_data1_1.clear();
|
||||
for (const auto& limit_json : json.at("ToolLimits").as_list()) {
|
||||
this->max_tool_stack_sizes_by_data1_1.emplace_back(limit_json->as_int());
|
||||
@@ -116,8 +113,7 @@ uint32_t ItemData::primary_identifier() const {
|
||||
// - 03TTSS00 = tool
|
||||
// - 04000000 = meseta
|
||||
|
||||
// The game treats any item starting with 04 as Meseta, and ignores the rest
|
||||
// of data1 (the value is in data2)
|
||||
// The game treats any item starting with 04 as Meseta, and ignores the rest of data1 (the value is in data2)
|
||||
if (this->data1[0] == 0x04) {
|
||||
return 0x04000000;
|
||||
}
|
||||
@@ -150,17 +146,14 @@ void ItemData::change_primary_identifier(uint32_t primary_identifier) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0x01: // Armor/shield/unit
|
||||
// Apply data1[1] and data1[2]
|
||||
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
|
||||
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)
|
||||
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;
|
||||
@@ -169,8 +162,7 @@ void ItemData::change_primary_identifier(uint32_t primary_identifier) {
|
||||
this->data1[2] = (primary_identifier >> 8) & 0xFF;
|
||||
}
|
||||
break;
|
||||
case 0x04: // Meseta
|
||||
// Nothing to apply
|
||||
case 0x04: // Meseta; nothing to apply
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("invalid item class");
|
||||
@@ -298,10 +290,7 @@ void ItemData::clear_mag_stats() {
|
||||
}
|
||||
|
||||
uint16_t ItemData::compute_mag_level() const {
|
||||
return (this->data1w[2] / 100) +
|
||||
(this->data1w[3] / 100) +
|
||||
(this->data1w[4] / 100) +
|
||||
(this->data1w[5] / 100);
|
||||
return (this->data1w[2] / 100) + (this->data1w[3] / 100) + (this->data1w[4] / 100) + (this->data1w[5] / 100);
|
||||
}
|
||||
|
||||
uint16_t ItemData::compute_mag_strength_flags() const {
|
||||
@@ -432,8 +421,7 @@ void ItemData::decode_for_version(Version from_version) {
|
||||
}
|
||||
|
||||
if (is_v1(from_version) || is_v2(from_version)) {
|
||||
// PSO PC and GC NTE encode mags in a tediously annoying manner. The
|
||||
// first four bytes are the same, but then...
|
||||
// PSO PC and GC NTE encode mags in a tediously annoying manner. The first four bytes are the same, but then:
|
||||
// V2: pHHHHHHHHHHHHHHc pIIIIIIIIIIIIIIc JJJJJJJJJJJJJJJc KKKKKKKKKKKKKKKc QQQQQQQQ QQQQQQQQ YYYYYYYY pYYYYYYY
|
||||
// V3: HHHHHHHHHHHHHHHH IIIIIIIIIIIIIIII JJJJJJJJJJJJJJJJ KKKKKKKKKKKKKKKK YYYYYYYY QQQQQQQQ PPPPPPPP CCCCCCCC
|
||||
// c = color in V2 (4 bits; low bit first)
|
||||
@@ -455,10 +443,8 @@ void ItemData::decode_for_version(Version from_version) {
|
||||
this->data1w[5] &= 0xFFFE;
|
||||
|
||||
} else if (is_big_endian(from_version)) {
|
||||
// PSO GC (but not GC NTE, which uses the above logic) byteswaps the
|
||||
// data2d field, since internally it's actually a uint32_t. We treat it
|
||||
// as individual bytes instead, so we correct for the client's
|
||||
// byteswapping here.
|
||||
// PSO GC (but not GC NTE, which uses the above logic) byteswaps the data2d field, since internally it's
|
||||
// actually a uint32_t. We treat it as individual bytes, so we correct for the client's byteswapping here.
|
||||
this->data2d = phosg::bswap32(this->data2d);
|
||||
}
|
||||
break;
|
||||
@@ -529,9 +515,8 @@ void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParam
|
||||
this->data1[1] = 0x00;
|
||||
}
|
||||
|
||||
// This logic is the inverse of the corresponding logic in
|
||||
// decode_for_version; see that function for a description of what's
|
||||
// going on here.
|
||||
// This logic is the inverse of the corresponding logic in decode_for_version; see that function for a
|
||||
// description of what's going on here.
|
||||
if (is_v1(to_version) || is_v2(to_version)) {
|
||||
this->data1w[2] = (this->data1w[2] & 0x7FFE) | ((this->data2[2] << 14) & 0x8000) | (this->data2[3] & 1);
|
||||
this->data1w[3] = (this->data1w[3] & 0x7FFE) | ((this->data2[2] << 13) & 0x8000) | ((this->data2[3] >> 1) & 1);
|
||||
|
||||
+23
-25
@@ -10,13 +10,11 @@
|
||||
class ItemParameterTable;
|
||||
|
||||
enum class EquipSlot {
|
||||
// When equipping items through the Item Pack pause menu, the client sends
|
||||
// UNKNOWN for the slot. The receiving client (and server, in our case) have
|
||||
// to analyze the item being equipped and put it in the appropriate slot in
|
||||
// this case. See ItemData::default_equip_slot() for this computation.
|
||||
// When equipping items through the Item Pack pause menu, the client sends UNKNOWN for the slot. The receiving client
|
||||
// (and server, in our case) have to analyze the item being equipped and put it in the appropriate slot in this case.
|
||||
// See ItemData::default_equip_slot() for this computation.
|
||||
UNKNOWN = 0x00,
|
||||
// When equipping items through the quick menu or Equip pause menu, the client
|
||||
// sends one of the slots below.
|
||||
// When equipping items through the quick menu or Equip pause menu, the client sends one of the slots below.
|
||||
MAG = 0x01,
|
||||
ARMOR = 0x02,
|
||||
SHIELD = 0x03,
|
||||
@@ -80,20 +78,21 @@ struct ItemData {
|
||||
};
|
||||
|
||||
// QUICK ITEM FORMAT REFERENCE
|
||||
// data1/0 data1/4 data1/8 data2
|
||||
// Weapon: 00ZZZZGG SSNNAABB AABBAABB 00000000
|
||||
// Armor: 0101ZZ00 FFTTDDDD EEEEXXXX 00000000
|
||||
// Shield: 0102ZZ00 FFTTDDDD EEEEXXXX 00000000
|
||||
// Unit: 0103ZZ00 FF00RRRR 0000XXXX 00000000
|
||||
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
|
||||
// Tool: 03ZZZZUU 00CC0000 0000XXXX 00000000
|
||||
// Meseta: 04000000 00000000 00000000 MMMMMMMM
|
||||
// data1/0 data1/4 data1/8 data2
|
||||
// Weapon: 00ZZZZGG SSNNAABB AABBAABB 00000000
|
||||
// Armor: 0101ZZ00 FFTTDDDD EEEEXXXX 00000000
|
||||
// Shield: 0102ZZ00 FFTTDDDD EEEEXXXX 00000000
|
||||
// Unit: 0103ZZ00 FF00RRRR 0000XXXX 00000000
|
||||
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
|
||||
// Tool: 03ZZZZUU 00CC0000 0000XXXX 00000000
|
||||
// Tech disk: 0302&&UU %%CC0000 0000XXXX 00000000
|
||||
// Meseta: 04000000 00000000 00000000 MMMMMMMM
|
||||
// A = attribute type (for S-ranks, custom name; last pair is kill count for some weapons)
|
||||
// B = attribute amount (for S-ranks, custom name; last pair is kill count for some weapons)
|
||||
// C = stack size (for tools)
|
||||
// D = DEF bonus
|
||||
// E = EVP bonus
|
||||
// F = armor/shield/unit flags (40=present; low 4 bits are present color)
|
||||
// F = armor/shield/unit flags (40=wrapped; low 4 bits are present color)
|
||||
// G = weapon grind
|
||||
// H = mag DEF
|
||||
// I = mag POW
|
||||
@@ -102,24 +101,23 @@ struct ItemData {
|
||||
// L = mag level
|
||||
// M = meseta amount
|
||||
// N = present color (weapon only; for other types this is in the flags field)
|
||||
// P = mag flags (40=present, 04=has left pb, 02=has right pb, 01=has center pb)
|
||||
// P = mag flags (40=wrapped, 04=has left pb, 02=has right pb, 01=has center pb)
|
||||
// Q = mag IQ
|
||||
// R = unit modifier (little-endian)
|
||||
// S = weapon flags (80=unidentified, 40=present) and special (low 6 bits)
|
||||
// S = weapon flags (80=unidentified, 40=wrapped) and special (low 6 bits)
|
||||
// T = slot count
|
||||
// U = tool flags (40=present; unused if item is stackable)
|
||||
// U = tool flags (40=wrapped; unused if item is stackable)
|
||||
// V = mag color
|
||||
// W = photon blasts
|
||||
// X = kill count (big-endian; high bit always set)
|
||||
// Y = mag synchro
|
||||
// Z = item ID
|
||||
// Note: PSO GC erroneously byteswaps data2 even when the item is a mag. This
|
||||
// makes it incompatible with little-endian versions of PSO (i.e. all other
|
||||
// versions). We manually byteswap data2 upon receipt and immediately before
|
||||
// sending where needed.
|
||||
// Related note: PSO V2 has an annoyingly complicated format for mags that
|
||||
// doesn't match the above table. We decode this upon receipt and encode it
|
||||
// immediately before sending when interacting with V2 clients; see the
|
||||
// & = technique level
|
||||
// % = technique number
|
||||
// Note: PSO GC byteswaps data2 even when the item is a mag. This makes it incompatible with little-endian versions
|
||||
// of PSO (i.e. all other versions). We manually byteswap data2 upon receipt and before sending where needed.
|
||||
// Related note: PSO V2 has an annoyingly complicated format for mags that doesn't match the above table. We decode
|
||||
// this upon receipt and encode it immediately before sending when interacting with V2 clients; see the
|
||||
// implementation of decode_for_version() for details.
|
||||
|
||||
union {
|
||||
|
||||
+160
-53
@@ -12,9 +12,16 @@ ItemNameIndex::ItemNameIndex(
|
||||
limits(limits) {
|
||||
|
||||
for (uint32_t primary_identifier : item_parameter_table->compute_all_valid_primary_identifiers()) {
|
||||
// 00000000 is a valid primary identifier but not a valid weapon; skip it
|
||||
if (primary_identifier == 0x00000000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const string* name = nullptr;
|
||||
bool is_es_weapon = false;
|
||||
try {
|
||||
ItemData item = ItemData::from_primary_identifier(*this->limits, primary_identifier);
|
||||
is_es_weapon = item.is_s_rank_weapon();
|
||||
name = &name_coll.at(item_parameter_table->get_item_id(item));
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
@@ -25,11 +32,14 @@ ItemNameIndex::ItemNameIndex(
|
||||
meta->name = *name;
|
||||
this->primary_identifier_index.emplace(meta->primary_identifier, meta);
|
||||
this->name_index.emplace(phosg::tolower(meta->name), meta);
|
||||
if (is_es_weapon && ((primary_identifier & 0x0000FFFF) == 0x00000000)) {
|
||||
this->es_name_index.emplace(phosg::tolower(meta->name), meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char* s_rank_name_characters = "\0ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
|
||||
static std::string s_rank_name_characters("\0ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", 0x20);
|
||||
|
||||
// clang-format off
|
||||
static const array<const char*, 0x29> name_for_weapon_special = {
|
||||
@@ -136,9 +146,8 @@ std::string ItemNameIndex::describe_item(const ItemData& item, uint8_t flags) co
|
||||
}
|
||||
}
|
||||
|
||||
// Armors, shields, and units (0x01) can be wrapped, as can mags (0x02) and
|
||||
// non-stackable tools (0x03). However, each of these item classes has its
|
||||
// flags in a different location.
|
||||
// Armors, shields, and units (0x01) can be wrapped, as can mags (0x02) and non-stackable tools (0x03). However, each
|
||||
// of these item classes has its flags in a different location.
|
||||
if (!name_only &&
|
||||
(((item.data1[0] == 0x01) && (item.data1[4] & 0x40)) ||
|
||||
((item.data1[0] == 0x02) && (item.data2[2] & 0x40)) ||
|
||||
@@ -178,12 +187,10 @@ std::string ItemNameIndex::describe_item(const ItemData& item, uint8_t flags) co
|
||||
}
|
||||
|
||||
if (item.is_s_rank_weapon()) {
|
||||
// S-rank weapons have names instead of percent bonuses. The name is
|
||||
// encoded as 9 5-bit characters in the bytes where the bonuses usually
|
||||
// go. The first character does not appear when the name is rendered;
|
||||
// instead, it's used to determine if the weapon type name should appear
|
||||
// or not. Unlike the client, we check the first character directly and
|
||||
// don't bother decoding it.
|
||||
// S-rank weapons have names instead of percent bonuses. The name is encoded as 9 5-bit characters in the bytes
|
||||
// where the bonuses usually go. The first character does not appear when the name is rendered; instead, it's
|
||||
// used to determine if the weapon type name should appear or not. Unlike the client, we check the first
|
||||
// character directly and don't bother decoding it.
|
||||
uint16_t be_data1w3 = phosg::bswap16(item.data1w[3]);
|
||||
uint16_t be_data1w4 = phosg::bswap16(item.data1w[4]);
|
||||
uint16_t be_data1w5 = phosg::bswap16(item.data1w[5]);
|
||||
@@ -201,7 +208,7 @@ std::string ItemNameIndex::describe_item(const ItemData& item, uint8_t flags) co
|
||||
|
||||
string name;
|
||||
for (size_t x = 0; x < 8; x++) {
|
||||
char ch = s_rank_name_characters[char_indexes[x]];
|
||||
char ch = s_rank_name_characters.at(char_indexes[x]);
|
||||
if (ch == 0) {
|
||||
break;
|
||||
}
|
||||
@@ -309,13 +316,12 @@ std::string ItemNameIndex::describe_item(const ItemData& item, uint8_t flags) co
|
||||
}
|
||||
};
|
||||
ret_tokens.emplace_back(format_stat(def) + "/" + format_stat(pow) + "/" + format_stat(dex) + "/" + format_stat(mind));
|
||||
ret_tokens.emplace_back(std::format("{}%", item.data2[0]));
|
||||
ret_tokens.emplace_back(std::format("{}{}", item.data2[0], include_color_escapes ? "%%" : "%"));
|
||||
ret_tokens.emplace_back(std::format("{}IQ", item.data2[1]));
|
||||
|
||||
uint8_t flags = item.data2[2];
|
||||
if (flags & 7) {
|
||||
static const vector<const char*> pb_shortnames = {
|
||||
"F", "E", "G", "P", "L", "M&Y", "MG", "GR"};
|
||||
static const vector<const char*> pb_shortnames = {"F", "E", "G", "P", "L", "M&Y", "MG", "GR"};
|
||||
|
||||
const char* pb_names[3] = {nullptr, nullptr, nullptr};
|
||||
uint8_t left_pb = item.mag_photon_blast_for_slot(2);
|
||||
@@ -413,6 +419,112 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (desc.starts_with("es ")) {
|
||||
auto parse_name = [&](const std::string& token) -> void {
|
||||
if (token.size() > 8) {
|
||||
throw runtime_error("s-rank name too long");
|
||||
}
|
||||
|
||||
uint8_t char_indexes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
for (size_t z = 0; z < token.size(); z++) {
|
||||
char ch = toupper(token[z]);
|
||||
size_t pos = s_rank_name_characters.find(ch);
|
||||
if (pos == std::string::npos) {
|
||||
throw runtime_error(std::format("s-rank name contains invalid character {:02X} ({})", ch, ch));
|
||||
}
|
||||
char_indexes[z] = pos;
|
||||
}
|
||||
|
||||
ret.data1w[3] = phosg::bswap16(0x8000 | (char_indexes[1] & 0x1F) | ((char_indexes[0] & 0x1F) << 5));
|
||||
ret.data1w[4] = phosg::bswap16(0x8000 | (char_indexes[4] & 0x1F) | ((char_indexes[3] & 0x1F) << 5) | ((char_indexes[2] & 0x1F) << 10));
|
||||
ret.data1w[5] = phosg::bswap16(0x8000 | (char_indexes[7] & 0x1F) | ((char_indexes[6] & 0x1F) << 5) | ((char_indexes[5] & 0x1F) << 10));
|
||||
};
|
||||
auto parse_special = [&](const std::string& token) -> bool {
|
||||
for (size_t z = 0; z < name_for_s_rank_special.size(); z++) {
|
||||
if (name_for_s_rank_special[z] && (token == phosg::tolower(name_for_s_rank_special[z]))) {
|
||||
ret.data1[2] = z;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto parse_grind = [&](const std::string& token) -> bool {
|
||||
if (token.starts_with('+')) {
|
||||
ret.data1[3] = stoul(token.substr(1), nullptr, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto parse_type = [&](const std::string& token) -> void {
|
||||
const auto& meta = this->es_name_index.at(token);
|
||||
if (meta->primary_identifier & 0xFF00FFFF) {
|
||||
throw std::runtime_error("ES weapon has invalid bits in primary identifier");
|
||||
}
|
||||
ret.data1[1] = meta->primary_identifier >> 16;
|
||||
};
|
||||
|
||||
// Syntax: ES [NAME] [SPECIAL] TYPE [+GRIND]
|
||||
auto tokens = phosg::split(desc, ' ');
|
||||
switch (tokens.size()) {
|
||||
case 0:
|
||||
case 1:
|
||||
throw std::runtime_error("ES weapon type is missing");
|
||||
|
||||
case 2:
|
||||
// Must be ES TYPE
|
||||
parse_name(tokens[1]);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Any of the following:
|
||||
// ES TYPE +N
|
||||
// ES SPECIAL TYPE
|
||||
// ES NAME TYPE
|
||||
if (parse_grind(tokens[2])) {
|
||||
parse_type(tokens[1]);
|
||||
} else if (parse_special(tokens[1])) {
|
||||
parse_type(tokens[2]);
|
||||
} else {
|
||||
parse_name(tokens[1]);
|
||||
parse_type(tokens[2]);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
// Any of the following:
|
||||
// ES SPECIAL TYPE +N
|
||||
// ES NAME TYPE +N
|
||||
// ES NAME SPECIAL TYPE
|
||||
if (parse_grind(tokens[3])) {
|
||||
if (!parse_special(tokens[1])) {
|
||||
parse_name(tokens[1]);
|
||||
}
|
||||
parse_type(tokens[2]);
|
||||
} else {
|
||||
parse_name(tokens[1]);
|
||||
if (!parse_special(tokens[2])) {
|
||||
throw std::runtime_error("invalid ES special");
|
||||
}
|
||||
parse_type(tokens[3]);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
// Must be ES NAME SPECIAL TYPE +N
|
||||
parse_name(tokens[1]);
|
||||
if (!parse_special(tokens[2])) {
|
||||
throw std::runtime_error("invalid ES special");
|
||||
}
|
||||
parse_type(tokens[3]);
|
||||
if (!parse_grind(tokens[4])) {
|
||||
throw std::runtime_error("invalid grind");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("too many ES weapon tokens");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (desc.starts_with("disk:")) {
|
||||
auto tokens = phosg::split(desc, ' ');
|
||||
tokens[0] = tokens[0].substr(5); // Trim off "disk:"
|
||||
@@ -454,7 +566,6 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
desc = desc.substr(z);
|
||||
}
|
||||
|
||||
// TODO: It'd be nice to be able to parse S-rank weapon specials here too.
|
||||
uint8_t weapon_special = 0;
|
||||
if (!skip_special) {
|
||||
for (size_t z = 0; z < name_for_weapon_special.size(); z++) {
|
||||
@@ -472,9 +583,8 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
}
|
||||
|
||||
auto name_it = this->name_index.lower_bound(desc);
|
||||
// Look up to 3 places before the lower bound. We have to do this to catch
|
||||
// cases like Sange vs. Sange & Yasha - if the input is like "Sange 0/...",
|
||||
// then we'll see Sange & Yasha first, which we should skip.
|
||||
// Look up to 3 places before the lower bound. We have to do this to catch cases like Sange vs. Sange & Yasha - if
|
||||
// the input is like "Sange 0/...", then we'll see Sange & Yasha first, which we should skip.
|
||||
size_t lookback = 0;
|
||||
while (lookback < 4) {
|
||||
if (name_it != this->name_index.end() && desc.starts_with(name_it->first)) {
|
||||
@@ -495,18 +605,17 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
desc = desc.substr(1);
|
||||
}
|
||||
|
||||
// Tech disks should have already been handled above, so we don't need to
|
||||
// special-case 0302xxxx identifiers here.
|
||||
// Tech disks should have already been handled above, so we don't need to special-case 0302xxxx identifiers here.
|
||||
uint32_t primary_identifier = name_it->second->primary_identifier;
|
||||
ret.data1[0] = (primary_identifier >> 24) & 0xFF;
|
||||
ret.data1[1] = (primary_identifier >> 16) & 0xFF;
|
||||
ret.data1[2] = (primary_identifier >> 8) & 0xFF;
|
||||
|
||||
if (ret.data1[0] == 0x00) {
|
||||
// Weapons: add special, grind and percentages (or name, if S-rank) and
|
||||
// kill count if unsealable
|
||||
// Weapons: add special, grind and percentages (or name, if S-rank) and kill count if unsealable
|
||||
ret.data1[4] = weapon_special | (is_wrapped ? 0x40 : 0x00) | (is_unidentified ? 0x80 : 0x00);
|
||||
|
||||
bool kill_count_set = false;
|
||||
auto tokens = phosg::split(desc, ' ');
|
||||
for (auto& token : tokens) {
|
||||
if (token.empty()) {
|
||||
@@ -517,26 +626,11 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
ret.data1[3] = stoul(token, nullptr, 10);
|
||||
|
||||
} else if (ret.is_s_rank_weapon()) {
|
||||
if (token.size() > 8) {
|
||||
throw runtime_error("s-rank name too long");
|
||||
}
|
||||
|
||||
uint8_t char_indexes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
for (size_t z = 0; z < token.size(); z++) {
|
||||
char ch = toupper(token[z]);
|
||||
const char* pos = strchr(s_rank_name_characters, ch);
|
||||
if (!pos) {
|
||||
throw runtime_error(std::format("s-rank name contains invalid character {:02X} ({})", ch, ch));
|
||||
}
|
||||
char_indexes[z] = (pos - s_rank_name_characters);
|
||||
}
|
||||
|
||||
ret.data1w[3] = phosg::bswap16(0x8000 | (char_indexes[1] & 0x1F) | ((char_indexes[0] & 0x1F) << 5));
|
||||
ret.data1w[4] = phosg::bswap16(0x8000 | (char_indexes[4] & 0x1F) | ((char_indexes[3] & 0x1F) << 5) | ((char_indexes[2] & 0x1F) << 10));
|
||||
ret.data1w[5] = phosg::bswap16(0x8000 | (char_indexes[7] & 0x1F) | ((char_indexes[6] & 0x1F) << 5) | ((char_indexes[5] & 0x1F) << 10));
|
||||
throw std::runtime_error("ES weapon must be prefixed with \"ES\"");
|
||||
|
||||
} else if (token.starts_with("k:")) {
|
||||
ret.set_kill_count(stoul(token.substr(2), nullptr, 0));
|
||||
kill_count_set = true;
|
||||
|
||||
} else {
|
||||
auto p_tokens = phosg::split(token, '/');
|
||||
@@ -560,7 +654,7 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
}
|
||||
}
|
||||
|
||||
if (this->item_parameter_table->is_unsealable_item(ret)) {
|
||||
if (this->item_parameter_table->is_unsealable_item(ret) && !kill_count_set) {
|
||||
ret.set_kill_count(0);
|
||||
}
|
||||
|
||||
@@ -573,7 +667,29 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
{"+", 0x0002},
|
||||
{"++", 0x0004},
|
||||
});
|
||||
ret.data1w[3] = modifiers.at(desc);
|
||||
bool kill_count_set = false;
|
||||
for (const auto& token : phosg::split(desc, ' ')) {
|
||||
if (token == "--") {
|
||||
ret.data1w[3] = 0xFFFC;
|
||||
} else if (token == "-") {
|
||||
ret.data1w[3] = 0xFFFE;
|
||||
} else if (token == "+") {
|
||||
ret.data1w[3] = 0x0002;
|
||||
} else if (token == "++") {
|
||||
ret.data1w[3] = 0x0004;
|
||||
} else if (token.starts_with('+')) {
|
||||
ret.data1w[3] = stoul(token.substr(1), nullptr, 0);
|
||||
} else if (token.starts_with('-')) {
|
||||
ret.data1w[3] = static_cast<uint16_t>(stol(token, nullptr, 0));
|
||||
} else if (token.starts_with("k:")) {
|
||||
ret.set_kill_count(stoul(token.substr(2), nullptr, 0));
|
||||
kill_count_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->item_parameter_table->is_unsealable_item(ret) && !kill_count_set) {
|
||||
ret.set_kill_count(0);
|
||||
}
|
||||
|
||||
} else { // Armor/shield
|
||||
for (const auto& token : phosg::split(desc, ' ')) {
|
||||
@@ -605,16 +721,8 @@ ItemData ItemNameIndex::parse_item_description_phase(const std::string& descript
|
||||
if (pb_tokens.size() > 3) {
|
||||
throw runtime_error("too many photon blasts specified");
|
||||
}
|
||||
static const unordered_map<string, uint8_t> name_to_pb_num({
|
||||
{"f", 0},
|
||||
{"e", 1},
|
||||
{"g", 2},
|
||||
{"p", 3},
|
||||
{"l", 4},
|
||||
{"m", 5},
|
||||
{"my", 5},
|
||||
{"m&y", 5},
|
||||
});
|
||||
static const unordered_map<string, uint8_t> name_to_pb_num(
|
||||
{{"f", 0}, {"e", 1}, {"g", 2}, {"p", 3}, {"l", 4}, {"m", 5}, {"my", 5}, {"m&y", 5}});
|
||||
for (const auto& pb_token : pb_tokens) {
|
||||
ret.add_mag_photon_blast(name_to_pb_num.at(pb_token));
|
||||
}
|
||||
@@ -921,8 +1029,7 @@ void ItemNameIndex::print_table(FILE* stream) const {
|
||||
phosg::fwrite_fmt(stream, "MAG FEED TABLES\n");
|
||||
for (size_t table_index = 0; table_index < 8; table_index++) {
|
||||
static const char* names[11] = {
|
||||
"Monomate", "Dimate", "Trimate", "Monofluid",
|
||||
"Difluid", "Trifluid", "Antidote", "Antiparalysis",
|
||||
"Monomate", "Dimate", "Trimate", "Monofluid", "Difluid", "Trifluid", "Antidote", "Antiparalysis",
|
||||
"Sol Atomizer", "Moon Atomizer", "Star Atomizer"};
|
||||
phosg::fwrite_fmt(stream, " TABLE {:02X} => -DEF -POW -DEX MIND -IQ- SYNC\n", table_index);
|
||||
for (size_t which = 0; which < 11; which++) {
|
||||
|
||||
@@ -56,4 +56,5 @@ private:
|
||||
|
||||
std::unordered_map<uint32_t, std::shared_ptr<const ItemMetadata>> primary_identifier_index;
|
||||
std::map<std::string, std::shared_ptr<const ItemMetadata>> name_index;
|
||||
std::map<std::string, std::shared_ptr<const ItemMetadata>> es_name_index;
|
||||
};
|
||||
|
||||
@@ -164,7 +164,7 @@ set<uint32_t> ItemParameterTable::compute_all_valid_primary_identifiers() const
|
||||
};
|
||||
auto find_items_2d = [&](uint64_t data1) {
|
||||
for (size_t x = 0; x < 0x100; x++) {
|
||||
size_t effective_data1 = data1 | (static_cast<uint64_t>(x) << 48);
|
||||
uint64_t effective_data1 = data1 | (static_cast<uint64_t>(x) << 48);
|
||||
size_t data2_position = (effective_data1 == 0x0302000000000000) ? 4 : 2;
|
||||
if (find_items_1d(effective_data1, data2_position) == 0) {
|
||||
break;
|
||||
@@ -791,8 +791,8 @@ ItemParameterTable::definition_for_primary_identifier(uint32_t primary_identifie
|
||||
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
|
||||
// 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");
|
||||
@@ -908,9 +908,7 @@ uint8_t ItemParameterTable::get_item_stars(uint32_t item_id) const {
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_special_stars(uint8_t special) const {
|
||||
return ((special & 0x3F) && !(special & 0x80))
|
||||
? this->get_item_stars(special + this->special_stars_begin_index)
|
||||
: 0;
|
||||
return ((special & 0x3F) && !(special & 0x80)) ? this->get_item_stars(special + this->special_stars_begin_index) : 0;
|
||||
}
|
||||
|
||||
const ItemParameterTable::Special& ItemParameterTable::get_special(uint8_t special) const {
|
||||
@@ -1029,9 +1027,7 @@ uint8_t ItemParameterTable::get_weapon_v1_replacement(uint8_t data1_1) const {
|
||||
throw logic_error("table is not v2, v3, or v4");
|
||||
}
|
||||
|
||||
return (data1_1 < this->num_weapon_classes)
|
||||
? this->r.pget_u8(offset + data1_1)
|
||||
: 0x00;
|
||||
return (data1_1 < this->num_weapon_classes) ? this->r.pget_u8(offset + data1_1) : 0x00;
|
||||
}
|
||||
|
||||
uint32_t ItemParameterTable::get_item_id(const ItemData& item) const {
|
||||
@@ -1157,9 +1153,7 @@ bool ItemParameterTable::is_unsealable_item(uint8_t data1_0, uint8_t data1_1, ui
|
||||
|
||||
const auto* defs = &this->r.pget<UnsealableItem>(offset, count * sizeof(UnsealableItem));
|
||||
for (size_t z = 0; z < count; z++) {
|
||||
if ((defs[z].item[0] == data1_0) &&
|
||||
(defs[z].item[1] == data1_1) &&
|
||||
(defs[z].item[2] == data1_2)) {
|
||||
if ((defs[z].item[0] == data1_0) && (defs[z].item[1] == data1_1) && (defs[z].item[2] == data1_2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+40
-49
@@ -18,8 +18,8 @@
|
||||
#include "Types.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
// TODO: These don't really belong here, but putting them anywhere else creates
|
||||
// annoying dependency cycles. Find or make a better place for these.
|
||||
// TODO: These don't really belong here, but putting them anywhere else creates annoying dependency cycles. Find or
|
||||
// make a better place for these.
|
||||
enum class ServerDropMode {
|
||||
DISABLED = 0,
|
||||
CLIENT = 1, // Not allowed for BB games
|
||||
@@ -40,14 +40,13 @@ const char* phosg::name_for_enum<ServerDropMode>(ServerDropMode value);
|
||||
|
||||
class ItemParameterTable {
|
||||
public:
|
||||
// TODO: This implementation is ugly. We should use real classes and virtual
|
||||
// functions instead of manually branching on various offset table pointers
|
||||
// being null or not in each public function. Rewrite this and make it better.
|
||||
// TODO: This implementation is ugly. We should use real classes and virtual 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 ItemBaseV2T {
|
||||
// id specifies several things; notably, it doubles as the index of the
|
||||
// item's name in the text archive (e.g. TextEnglish) collection 0.
|
||||
// id specifies several things; notably, it doubles as the index of the item's name in the text archive (e.g.
|
||||
// TextEnglish) collection 0.
|
||||
/* 00 */ U32T<BE> id = 0xFFFFFFFF;
|
||||
/* 04 */
|
||||
} __attribute__((packed));
|
||||
@@ -291,15 +290,13 @@ public:
|
||||
/* 09 */ uint8_t on_low_hp = 0;
|
||||
/* 0A */ uint8_t on_death = 0;
|
||||
/* 0B */ uint8_t on_boss = 0;
|
||||
// These flags control how likely each effect is to activate. First, the
|
||||
// game computes step_synchro as follows:
|
||||
// These flags control how likely each effect is to activate. First, the game computes step_synchro as follows:
|
||||
// if synchro in [0, 30], step_synchro = 0
|
||||
// if synchro in [31, 60], step_synchro = 15
|
||||
// if synchro in [61, 80], step_synchro = 25
|
||||
// if synchro in [81, 100], step_synchro = 30
|
||||
// if synchro in [101, 120], step_synchro = 35
|
||||
// Then, the percent chance of the effect occurring upon its trigger (e.g.
|
||||
// entering a boss arena) is:
|
||||
// Then, the percent chance of the effect occurring upon its trigger (e.g. entering a boss arena) is:
|
||||
// flag == 0 => activation
|
||||
// flag == 1 => activation + step_synchro
|
||||
// flag == 2 => step_synchro
|
||||
@@ -407,10 +404,9 @@ public:
|
||||
|
||||
template <bool BE>
|
||||
struct StatBoostT {
|
||||
// Only the first of these stat/amount pairs is used in most versions of
|
||||
// the game. In DC 11/2000 Sega apparently changed the loop from
|
||||
// `for (z = 0; z != 2; z++)` to `for (z = 0; z != 1; z++)`, so only the
|
||||
// first stat/amount pair is used on all versions after DC NTE.
|
||||
// Only the first of these stat/amount pairs is used in most versions of the game. In DC 11/2000 Sega apparently
|
||||
// changed the loop from `for (z = 0; z != 2; z++)` to `for (z = 0; z != 1; z++)`, so only the first stat/amount
|
||||
// pair is used on all versions after DC NTE.
|
||||
// Values for stats:
|
||||
// 01 = ATP bonus
|
||||
// 02 = ATA bonus
|
||||
@@ -565,8 +561,7 @@ protected:
|
||||
} __packed_ws__(TableOffsetsDCProtos, 0x50);
|
||||
|
||||
struct TableOffsetsV1V2 {
|
||||
// TODO: Is weapon count 0x89 or 0x8A? It could be that the last entry in
|
||||
// weapon_table is used for ???? items.
|
||||
// TODO: Is weapon count 0x89 or 0x8A? It could be that the last entry in weapon_table is used for ???? items.
|
||||
/* ## / V1 / V2*/
|
||||
/* 00 / 0013 / 0013 */ le_uint32_t unknown_a0;
|
||||
/* 04 / 32E8 / 5AFC */ le_uint32_t weapon_table; // -> [{count, offset -> [WeaponV2]}](0x89)
|
||||
@@ -652,8 +647,7 @@ protected:
|
||||
const TableOffsetsV3V4BE* offsets_v3_be;
|
||||
const TableOffsetsV3V4* offsets_v4;
|
||||
|
||||
// These are unused if offsets_v4 is not null (in that case, we just return
|
||||
// references pointing inside the data string)
|
||||
// These are unused if offsets_v4 is not null (in that case, we just return references to within the data string)
|
||||
mutable std::unordered_map<uint16_t, WeaponV4> parsed_weapons;
|
||||
mutable std::vector<ArmorOrShieldV4> parsed_armors;
|
||||
mutable std::vector<ArmorOrShieldV4> parsed_shields;
|
||||
@@ -663,8 +657,8 @@ protected:
|
||||
mutable std::vector<Special> parsed_specials;
|
||||
mutable std::vector<StatBoost> parsed_stat_boosts;
|
||||
|
||||
// Key is used_item. We can't index on (used_item, equipped_item) because
|
||||
// equipped_item may contain wildcards, and the matching order matters.
|
||||
// Key is used_item. We can't index on (used_item, equipped_item) because equipped_item may contain wildcards, and
|
||||
// the matching order matters.
|
||||
mutable std::map<uint32_t, std::vector<ItemCombination>> item_combination_index;
|
||||
|
||||
template <typename ToolDefT, bool BE>
|
||||
@@ -682,8 +676,8 @@ 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
|
||||
// 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 = 0;
|
||||
} __packed_ws__(Side, 0x06);
|
||||
@@ -691,37 +685,34 @@ public:
|
||||
} __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.
|
||||
// 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+)
|
||||
// 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;
|
||||
|
||||
+31
-45
@@ -9,9 +9,8 @@ using namespace std;
|
||||
void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomGenerator> rand_crypt) {
|
||||
auto s = c->require_server_state();
|
||||
|
||||
// On PC (and presumably DC), the client sends a 6x29 after this to delete the
|
||||
// used item. On GC and later versions, this does not happen, so we should
|
||||
// delete the item here.
|
||||
// On PC (and presumably DC), the client sends a 6x29 after this to delete the used item. On GC and later versions,
|
||||
// this does not happen, so we should delete the item here.
|
||||
bool is_v4 = ::is_v4(c->version());
|
||||
bool is_v3_or_later = is_v3(c->version()) || is_v4;
|
||||
bool should_delete_item = is_v3_or_later;
|
||||
@@ -37,8 +36,7 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
}
|
||||
|
||||
auto& weapon = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::WEAPON)];
|
||||
// Only enforce grind limits on BB, since the server doesn't have direct
|
||||
// control over players' inventories on other versions
|
||||
// Only enforce grind limits on BB, since the server doesn't have direct control over inventories on other versions
|
||||
auto item_parameter_table = s->item_parameter_table(c->version());
|
||||
auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]);
|
||||
if (is_v4 && (weapon.data.data1[3] >= weapon_def.max_grind)) {
|
||||
@@ -77,8 +75,6 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
case 6: // Hit Material (v1/v2) or Luck Material (v3/v4)
|
||||
type = Type::LUCK;
|
||||
if (!is_v3_or_later && (c->version() != Version::GC_NTE)) {
|
||||
// Hit material doesn't exist on v3/v4, but we'll ignore type anyway
|
||||
// in this case because track_non_hp_tp_materials is false
|
||||
p->disp.stats.char_stats.ata += 2;
|
||||
} else {
|
||||
p->disp.stats.char_stats.lck += 2;
|
||||
@@ -173,10 +169,9 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
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?
|
||||
// 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 = rand_crypt->next() % sum;
|
||||
for (size_t z = 0; z < table.second; z++) {
|
||||
const auto& entry = table.first[z];
|
||||
@@ -200,6 +195,16 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
}
|
||||
}
|
||||
|
||||
} else if (primary_identifier == 0x03170000) { // Unopened Hunters Report
|
||||
// The unopened Hunters Report's rank is stored in the kill count field; using the unopened report copies the rank
|
||||
// to data1[2] and replaces the inventory item with a new item with the same ID. The game also moves the item to
|
||||
// the end of the inventory, so we do the same.
|
||||
const auto& stack_limits = *s->item_stack_limits(c->version());
|
||||
auto report_item = player->remove_item(item.data.id, 1, stack_limits);
|
||||
report_item.data1[2] = report_item.get_kill_count();
|
||||
player->add_item(report_item, stack_limits);
|
||||
should_delete_item = false;
|
||||
|
||||
} else {
|
||||
// Use item combinations table from ItemPMT
|
||||
bool combo_applied = false;
|
||||
@@ -254,8 +259,8 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<RandomG
|
||||
}
|
||||
|
||||
if (should_delete_item) {
|
||||
// Allow overdrafting meseta if the client is not BB, since the server isn't
|
||||
// informed when meseta is added or removed from the bank.
|
||||
// Allow overdrafting meseta if the client is not BB, since the server isn't informed when meseta is added or
|
||||
// removed from the bank.
|
||||
player->remove_item(item.data.id, 1, *s->item_stack_limits(c->version()));
|
||||
}
|
||||
}
|
||||
@@ -313,8 +318,8 @@ void apply_mag_feed_result(
|
||||
uint8_t evolution_number = mag_evolution_table->get_evolution_number(mag_item.data1[1]);
|
||||
uint8_t mag_number = mag_item.data1[1];
|
||||
|
||||
// Note: Sega really did just hardcode all these rules into the client. There
|
||||
// is no data file describing these evolutions, unfortunately.
|
||||
// Note: Sega really did just hardcode all these rules into the client. There is no data file describing these
|
||||
// evolutions, unfortunately.
|
||||
|
||||
if (mag_level < 10) {
|
||||
// Nothing to do
|
||||
@@ -398,9 +403,8 @@ void apply_mag_feed_result(
|
||||
throw logic_error("char class is not any of the top-level classes");
|
||||
}
|
||||
|
||||
// Note: The original code checks the class (hunter/ranger/force) again
|
||||
// here, and goes into 3 branches that each do these same checks.
|
||||
// However, the result of all 3 branches is exactly the same!
|
||||
// Note: The original code checks the class (hunter/ranger/force) again here, and goes into 3 branches that
|
||||
// each do these same checks. However, the result of all 3 branches is exactly the same!
|
||||
if (((section_id_group == 0) && (pow + mind == def + dex)) ||
|
||||
((section_id_group == 1) && (pow + dex == mind + def)) ||
|
||||
((section_id_group == 2) && (pow + def == mind + dex))) {
|
||||
@@ -433,54 +437,36 @@ void apply_mag_feed_result(
|
||||
|
||||
if (is_hunter) {
|
||||
if (flags & 0x108) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((dex < mind) ? 0x08 : 0x06)
|
||||
: ((dex < mind) ? 0x0C : 0x05);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((dex < mind) ? 0x08 : 0x06) : ((dex < mind) ? 0x0C : 0x05);
|
||||
} else if (flags & 0x010) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x10)
|
||||
: ((mind < pow) ? 0x17 : 0x13);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((mind < pow) ? 0x12 : 0x10) : ((mind < pow) ? 0x17 : 0x13);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((pow < dex) ? 0x16 : 0x24)
|
||||
: ((pow < dex) ? 0x07 : 0x1E);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((pow < dex) ? 0x16 : 0x24) : ((pow < dex) ? 0x07 : 0x1E);
|
||||
}
|
||||
} else if (is_ranger) {
|
||||
if (flags & 0x110) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((mind < pow) ? 0x0A : 0x05)
|
||||
: ((mind < pow) ? 0x0C : 0x06);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((mind < pow) ? 0x0A : 0x05) : ((mind < pow) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x008) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((dex < mind) ? 0x0A : 0x26)
|
||||
: ((dex < mind) ? 0x0C : 0x06);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((dex < mind) ? 0x0A : 0x26) : ((dex < mind) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((pow < dex) ? 0x18 : 0x1E)
|
||||
: ((pow < dex) ? 0x08 : 0x05);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((pow < dex) ? 0x18 : 0x1E) : ((pow < dex) ? 0x08 : 0x05);
|
||||
}
|
||||
} else if (is_force) {
|
||||
if (flags & 0x120) {
|
||||
if (def < 45) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((pow < dex) ? 0x17 : 0x09)
|
||||
: ((pow < dex) ? 0x1E : 0x1C);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((pow < dex) ? 0x17 : 0x09) : ((pow < dex) ? 0x1E : 0x1C);
|
||||
} else {
|
||||
mag_item.data1[1] = 0x24;
|
||||
}
|
||||
} else if (flags & 0x008) {
|
||||
if (def < 45) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((dex < mind) ? 0x1C : 0x20)
|
||||
: ((dex < mind) ? 0x1F : 0x25);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((dex < mind) ? 0x1C : 0x20) : ((dex < mind) ? 0x1F : 0x25);
|
||||
} else {
|
||||
mag_item.data1[1] = 0x23;
|
||||
}
|
||||
} else if (flags & 0x010) {
|
||||
if (def < 45) {
|
||||
mag_item.data1[1] = (section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x0C)
|
||||
: ((mind < pow) ? 0x15 : 0x11);
|
||||
mag_item.data1[1] = (section_id & 1) ? ((mind < pow) ? 0x12 : 0x0C) : ((mind < pow) ? 0x15 : 0x11);
|
||||
} else {
|
||||
mag_item.data1[1] = 0x24;
|
||||
}
|
||||
|
||||
+5
-6
@@ -19,24 +19,23 @@ void LevelTable::reset_to_base(PlayerStats& stats, uint8_t char_class) const {
|
||||
void LevelTable::advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const {
|
||||
for (; stats.level < level; stats.level++) {
|
||||
const auto& level_stats = this->stats_delta_for_level(char_class, stats.level + 1);
|
||||
// The original code clamps the resulting stat values to [0, max_stat]; we
|
||||
// don't have max_stat handy so we just allow them to be unbounded
|
||||
// The original code clamps the resulting stat values to [0, max_stat]; we don't have max_stat handy so we just
|
||||
// allow them to be unbounded
|
||||
stats.char_stats.atp += level_stats.atp;
|
||||
stats.char_stats.mst += level_stats.mst;
|
||||
stats.char_stats.evp += level_stats.evp;
|
||||
stats.char_stats.hp += level_stats.hp;
|
||||
stats.char_stats.dfp += level_stats.dfp;
|
||||
stats.char_stats.ata += level_stats.ata;
|
||||
// Note: It is not a bug that lck is ignored here; the original code
|
||||
// ignores it too.
|
||||
// Note: It is not a bug that lck is ignored here; the original code ignores it too.
|
||||
stats.experience = level_stats.experience;
|
||||
}
|
||||
}
|
||||
|
||||
LevelTableV2::LevelTableV2(const string& data, bool compressed) {
|
||||
struct Offsets {
|
||||
// TODO: The overall format of this file on V2 has much more data than we
|
||||
// actually use. What's known of the structure so far:
|
||||
// TODO: The overall format of this file on V2 has much more data than we actually use. What's known of the
|
||||
// structure so far:
|
||||
le_uint32_t level_deltas; // (5468) -> u32[9] -> LevelStatsDelta[200]
|
||||
le_uint32_t unknown_a1; // (548C) -> float[6]
|
||||
le_uint32_t max_stats; // (54A4) -> PlayerStats[9]
|
||||
|
||||
+9
-11
@@ -43,19 +43,19 @@ template <bool BE>
|
||||
struct PlayerStatsT {
|
||||
/* 00 */ CharacterStatsT<BE> char_stats;
|
||||
/* 0E */ U16T<BE> esp = 0;
|
||||
/* 10 */ F32T<BE> height = 0.0;
|
||||
/* 14 */ F32T<BE> unknown_a3 = 0.0;
|
||||
/* 18 */ U32T<BE> level = 0;
|
||||
/* 10 */ F32T<BE> attack_range = 0.0;
|
||||
/* 14 */ F32T<BE> knockback_range = 0.0;
|
||||
/* 18 */ U32T<BE> level = 0; // Qedit specifies this as tech level when used for enemies
|
||||
/* 1C */ U32T<BE> experience = 0;
|
||||
/* 20 */ U32T<BE> meseta = 0;
|
||||
/* 20 */ U32T<BE> meseta = 0; // Qedit specifies this as TP when used for enemies
|
||||
/* 24 */
|
||||
|
||||
operator PlayerStatsT<!BE>() const {
|
||||
PlayerStatsT<!BE> ret;
|
||||
ret.char_stats = this->char_stats;
|
||||
ret.esp = this->esp;
|
||||
ret.height = this->height;
|
||||
ret.unknown_a3 = this->unknown_a3;
|
||||
ret.attack_range = this->attack_range;
|
||||
ret.knockback_range = this->knockback_range;
|
||||
ret.level = this->level;
|
||||
ret.experience = this->experience;
|
||||
ret.meseta = this->meseta;
|
||||
@@ -96,11 +96,9 @@ check_struct_size(LevelStatsDelta, 0x0C);
|
||||
check_struct_size(LevelStatsDeltaBE, 0x0C);
|
||||
|
||||
class LevelTable {
|
||||
// This is the base class for all the LevelTable implementations. The public
|
||||
// interface here only defines functions that the server needs to handle
|
||||
// requests, but some subclasses implement more functionality. See the
|
||||
// comments and Offsets structures inside the subclasses' constructor
|
||||
// implementations for more details on the file formats.
|
||||
// This is the base class for all the LevelTable implementations. The public interface here only defines functions
|
||||
// that the server needs to handle requests, but some subclasses implement more functionality. See the comments and
|
||||
// Offsets structures inside the subclasses' constructor implementations for more details on the file formats.
|
||||
public:
|
||||
virtual ~LevelTable() = default;
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const = 0;
|
||||
|
||||
+42
-53
@@ -145,27 +145,11 @@ uint32_t Lobby::FloorItemManager::reassign_all_item_ids(uint32_t next_item_id) {
|
||||
Lobby::Lobby(shared_ptr<ServerState> s, uint32_t id, bool is_game)
|
||||
: server_state(s),
|
||||
log(std::format("[{}:{:X}] ", is_game ? "Game" : "Lobby", id), lobby_log.min_level),
|
||||
creation_time(phosg::now()),
|
||||
lobby_id(id),
|
||||
min_level(0),
|
||||
max_level(0xFFFFFFFF),
|
||||
next_game_item_id(0xCC000000),
|
||||
allowed_versions(0x0000),
|
||||
override_section_id(0xFF),
|
||||
episode(Episode::NONE),
|
||||
mode(GameMode::NORMAL),
|
||||
difficulty(0),
|
||||
base_exp_multiplier(1.0f),
|
||||
exp_share_multiplier(0.5f),
|
||||
challenge_exp_multiplier(1.0f),
|
||||
random_seed(phosg::random_object<uint32_t>()),
|
||||
rand_crypt(make_shared<DisabledRandomGenerator>()),
|
||||
drop_mode(ServerDropMode::CLIENT),
|
||||
event(0),
|
||||
block(0),
|
||||
leader_id(0),
|
||||
max_clients(12),
|
||||
enabled_flags(0),
|
||||
idle_timeout_usecs(0),
|
||||
idle_timeout_timer(*s->io_context) {
|
||||
this->log.info_f("Created");
|
||||
if (is_game) {
|
||||
@@ -188,10 +172,10 @@ void Lobby::reset_next_item_ids() {
|
||||
|
||||
uint8_t Lobby::area_for_floor(Version version, uint8_t floor) const {
|
||||
if (this->quest) {
|
||||
return this->quest->meta.area_for_floor.at(floor);
|
||||
return this->quest->meta.floor_assignments.at(floor).area;
|
||||
}
|
||||
auto sdt = this->require_server_state()->set_data_table(version, this->episode, this->mode, this->difficulty);
|
||||
return sdt->default_area_for_floor(this->episode, floor);
|
||||
return sdt->default_floor_to_area(this->episode).at(floor);
|
||||
}
|
||||
|
||||
shared_ptr<ServerState> Lobby::require_server_state() const {
|
||||
@@ -228,21 +212,32 @@ void Lobby::create_item_creator(Version logic_version) {
|
||||
} else {
|
||||
rand_crypt = make_shared<MT19937Generator>(this->rand_crypt->seed());
|
||||
}
|
||||
uint8_t effective_section_id = this->effective_section_id();
|
||||
if (effective_section_id >= 10) {
|
||||
effective_section_id = 0x00;
|
||||
}
|
||||
this->item_creator = make_shared<ItemCreator>(
|
||||
s->common_item_set(logic_version, this->quest),
|
||||
s->rare_item_set(logic_version, this->quest),
|
||||
s->armor_random_set,
|
||||
s->tool_random_set,
|
||||
s->weapon_random_sets.at(this->difficulty),
|
||||
s->weapon_random_set(this->difficulty),
|
||||
s->tekker_adjustment_set,
|
||||
s->item_parameter_table(logic_version),
|
||||
s->item_stack_limits(logic_version),
|
||||
this->episode,
|
||||
(this->mode == GameMode::SOLO) ? GameMode::NORMAL : this->mode,
|
||||
this->difficulty,
|
||||
this->effective_section_id(),
|
||||
effective_section_id,
|
||||
rand_crypt,
|
||||
this->quest ? this->quest->meta.battle_rules : nullptr);
|
||||
if (this->blueballz_tier >= 0) {
|
||||
double rare_mult = 1.25 + (static_cast<double>(this->blueballz_tier) * 0.25);
|
||||
this->item_creator->set_rare_drop_rate_multiplier(rare_mult);
|
||||
this->log.info_f("Blueballz +{} rare drop rate multiplier set to {:g}x", this->blueballz_tier, rare_mult);
|
||||
}
|
||||
if (s->use_legacy_item_random_behavior) {
|
||||
this->item_creator->set_legacy_replay();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Lobby::effective_section_id() const {
|
||||
@@ -256,7 +251,7 @@ uint8_t Lobby::effective_section_id() const {
|
||||
if (leader) {
|
||||
return leader->character_file()->disp.visual.section_id;
|
||||
}
|
||||
return 0;
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
uint16_t Lobby::quest_version_flags() const {
|
||||
@@ -326,6 +321,7 @@ void Lobby::create_ep3_server() {
|
||||
.rand_crypt = this->rand_crypt,
|
||||
.tournament = tourn,
|
||||
.trap_card_ids = s->ep3_trap_card_ids,
|
||||
.output_queue = nullptr,
|
||||
};
|
||||
if (is_nte) {
|
||||
options.behavior_flags |= Episode3::BehaviorFlag::IS_TRIAL_EDITION;
|
||||
@@ -343,6 +339,12 @@ void Lobby::reassign_leader_on_client_departure(size_t leaving_client_index) {
|
||||
}
|
||||
if (this->clients[x]) {
|
||||
this->leader_id = x;
|
||||
// PSO GC's behavior is to reload the ItemPT and ItemRT tables only when the player returns to the city (Pioneer
|
||||
// 2 or Lab). This means the game's effective section ID should only change after the new leader is assigned, and
|
||||
// that new leader returns to the city. On BB, however, there is no evidence that this behavior was preserved;
|
||||
// it's more likely that Sega's server either switched drop tables instantly when the leader changed, or never
|
||||
// switched drop tables after game creation. We implement both of these behaviors (via the USE_CREATOR_SECTION_ID
|
||||
// lobby flag), and we intentionally don't implement the more complex pre-BB behavior.
|
||||
this->create_item_creator();
|
||||
return;
|
||||
}
|
||||
@@ -437,8 +439,7 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
this->create_item_creator();
|
||||
}
|
||||
|
||||
// If this is a lobby or no one was here before this, reassign all the floor
|
||||
// item IDs and reset the next item IDs
|
||||
// If this is a lobby or no one was here before this, reassign all the floor item IDs and reset the next item IDs
|
||||
if (!this->is_game() || (leader_index >= this->max_clients)) {
|
||||
this->reset_next_item_ids();
|
||||
for (auto& m : this->floor_item_managers) {
|
||||
@@ -446,19 +447,15 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
}
|
||||
}
|
||||
|
||||
// If this is not a game or the joining client is the leader, they will assign
|
||||
// their item IDs BEFORE they process any inbound commands (therefore a 6x6D
|
||||
// command, which we will send during loading, should reflect the item state
|
||||
// AFTER their IDs are assigned). If the joining client is not the leader,
|
||||
// they will not assign their item IDs until they receive a 6x71 command,
|
||||
// which is sent AFTER the 6x6D command, so the 6x6D should reflect the item
|
||||
// state BEFORE their IDs are assigned. (In the latter case, we'll assign the
|
||||
// IDs for real when they send a 6F command, or 6x1F equivalent in the case of
|
||||
// DC NTE and 11/2000.)
|
||||
// If this is not a game or the joining client is the leader, they will assign their item IDs BEFORE they process any
|
||||
// inbound commands (therefore a 6x6D command, which we will send during loading, should reflect the item state AFTER
|
||||
// their IDs are assigned). If the joining client is not the leader, they will not assign their item IDs until they
|
||||
// receive a 6x71 command, which is sent AFTER the 6x6D command, so the 6x6D should reflect the item state BEFORE
|
||||
// their IDs are assigned. (In the latter case, we'll assign the IDs for real when they send a 6F command, or 6x1F
|
||||
// equivalent in the case of DC NTE and 11/2000.)
|
||||
this->assign_inventory_and_bank_item_ids(c, (!this->is_game() || (c->lobby_client_id == this->leader_id)));
|
||||
|
||||
// On BB, we send artificial flag state to fix an Episode 2 bug where the
|
||||
// CCA door lock state is overwritten by quests.
|
||||
// On BB, we send flag state to fix an Episode 2 bug where the CCA door lock state is overwritten by quests.
|
||||
if (this->is_game() && (c->version() == Version::BB_V4)) {
|
||||
c->set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_FLAG_STATE);
|
||||
}
|
||||
@@ -505,9 +502,8 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
}
|
||||
this->clients[c->lobby_client_id] = nullptr;
|
||||
|
||||
// Unassign the client's lobby if it matches the current lobby (it may not
|
||||
// match if the client was already added to another lobby - this can happen
|
||||
// during the lobby change procedure)
|
||||
// Unassign the client's lobby if it matches the current lobby (it may not match if the client was already added to
|
||||
// another lobby - this can happen during the lobby change procedure)
|
||||
{
|
||||
auto c_lobby = c->lobby.lock();
|
||||
if (c_lobby.get() == this) {
|
||||
@@ -534,9 +530,8 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
}
|
||||
}
|
||||
|
||||
// If there are still players left in the lobby, delete all items that only
|
||||
// the leaving player could see. Don't do this if no one is left in the lobby,
|
||||
// since that would mean items could not persist in empty lobbies.
|
||||
// If there are still players left in the lobby, delete all items that only the leaving player could see. Don't do
|
||||
// this if no one is left in the lobby, since that would mean items could not persist in empty lobbies.
|
||||
uint16_t remaining_clients_mask = 0;
|
||||
for (size_t z = 0; z < 12; z++) {
|
||||
if (this->clients[z]) {
|
||||
@@ -557,8 +552,7 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
this->check_flag(Flag::PERSISTENT) &&
|
||||
!this->check_flag(Flag::DEFAULT) &&
|
||||
(this->idle_timeout_usecs > 0)) {
|
||||
// If the lobby is persistent but has an idle timeout, make it expire after
|
||||
// the specified time
|
||||
// If the lobby is persistent but has an idle timeout, make it expire after the specified time
|
||||
this->idle_timeout_timer.expires_after(std::chrono::microseconds(this->idle_timeout_usecs));
|
||||
this->idle_timeout_timer.async_wait([this](std::error_code ec) {
|
||||
if (!ec) {
|
||||
@@ -574,10 +568,7 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::move_client_to_lobby(
|
||||
shared_ptr<Lobby> dest_lobby,
|
||||
shared_ptr<Client> c,
|
||||
ssize_t required_client_id) {
|
||||
void Lobby::move_client_to_lobby(shared_ptr<Lobby> dest_lobby, shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
if (dest_lobby.get() == this) {
|
||||
return;
|
||||
}
|
||||
@@ -661,8 +652,7 @@ Lobby::JoinError Lobby::join_error_for_client(std::shared_ptr<Client> c, const s
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only prevent joining during loading if the client is actually trying to
|
||||
// join (not just loading the game list)
|
||||
// Only prevent joining during loading if the client is actually trying to join (not just loading the game list)
|
||||
if (password && this->any_client_loading()) {
|
||||
return JoinError::LOADING;
|
||||
}
|
||||
@@ -727,9 +717,8 @@ uint32_t Lobby::generate_item_id(uint8_t client_id) {
|
||||
}
|
||||
|
||||
void Lobby::on_item_id_generated_externally(uint32_t item_id) {
|
||||
// Note: The client checks for the range (0x00010000, 0x02010000) here, but
|
||||
// server-side item drop logic uses 0x00810000 as its base ID, so we restrict
|
||||
// the range further here.
|
||||
// Note: The client checks for the range (0x00010000, 0x02010000) here, but server-side item drop logic uses
|
||||
// 0x00810000 as its base ID, so we restrict the range further here.
|
||||
if ((item_id > 0x00010000) && (item_id < 0x00810000)) {
|
||||
uint16_t item_client_id = (item_id >> 21) & 0x7FF;
|
||||
uint32_t& next_item_id = this->next_item_id_for_client.at(item_client_id);
|
||||
|
||||
+42
-47
@@ -30,12 +30,10 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
// 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.)
|
||||
// The 13th bit (0x1000) specifies whether a rare item notification should
|
||||
// be sent to all players when the item is picked up. This has no effect for
|
||||
// non-rare items.
|
||||
// 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.) The 13th bit (0x1000)
|
||||
// specifies whether a rare item notification should be sent to all players when the item is picked up. This has no
|
||||
// effect for non-rare items.
|
||||
uint16_t flags;
|
||||
|
||||
bool visible_to_client(uint8_t client_id) const;
|
||||
@@ -43,8 +41,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
struct FloorItemManager {
|
||||
phosg::PrefixedLogger log;
|
||||
uint64_t next_drop_number;
|
||||
// It's important that this is a map and not an unordered_map. See the
|
||||
// comment in send_game_item_state for more details.
|
||||
// It's important that this is a map and not an unordered_map. See the comment in send_game_item_state for details.
|
||||
std::map<uint32_t, std::shared_ptr<FloorItem>> items; // Keyed on item_id
|
||||
std::array<std::map<uint64_t, std::shared_ptr<FloorItem>>, 12> queue_for_client;
|
||||
|
||||
@@ -84,6 +81,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00010000,
|
||||
CANNOT_CHANGE_CHEAT_MODE = 0x00020000,
|
||||
USE_CREATOR_SECTION_ID = 0x00040000,
|
||||
BLUEBALLZ_PLUS0 = 0x00080000,
|
||||
// Flags used only for lobbies
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
@@ -94,14 +92,16 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
std::weak_ptr<ServerState> server_state;
|
||||
phosg::PrefixedLogger log;
|
||||
|
||||
uint64_t creation_time;
|
||||
|
||||
uint32_t lobby_id;
|
||||
|
||||
uint32_t min_level;
|
||||
uint32_t max_level;
|
||||
uint32_t min_level = 0;
|
||||
uint32_t max_level = 0xFFFFFFFF;
|
||||
|
||||
// Game state
|
||||
std::array<uint32_t, 12> next_item_id_for_client;
|
||||
uint32_t next_game_item_id;
|
||||
uint32_t next_game_item_id = 0xCC000000;
|
||||
std::vector<FloorItemManager> floor_item_managers;
|
||||
std::shared_ptr<const MapState::RareEnemyRates> rare_enemy_rates;
|
||||
std::shared_ptr<MapState> map_state; // Always null for lobbies, never null for games
|
||||
@@ -111,25 +111,25 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
std::unique_ptr<SwitchFlags> switch_flags;
|
||||
|
||||
// Game config
|
||||
// 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.
|
||||
uint16_t allowed_versions;
|
||||
uint8_t creator_section_id;
|
||||
uint8_t override_section_id;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty; // 0-3
|
||||
float base_exp_multiplier;
|
||||
float exp_share_multiplier;
|
||||
float challenge_exp_multiplier;
|
||||
// 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.
|
||||
uint16_t allowed_versions = 0x0000;
|
||||
uint8_t creator_section_id = 0xFF;
|
||||
uint8_t override_section_id = 0xFF;
|
||||
Episode episode = Episode::NONE;
|
||||
GameMode mode = GameMode::NORMAL;
|
||||
Difficulty difficulty = Difficulty::NORMAL;
|
||||
int8_t blueballz_tier = -1; // -1 = disabled; 0..10 = Blueballz +0..+10
|
||||
float base_exp_multiplier = 1.0f;
|
||||
float exp_share_multiplier = 0.5f;
|
||||
float challenge_exp_multiplier = 1.0f;
|
||||
std::string password;
|
||||
std::string name;
|
||||
// This seed is also sent to the client for rare enemy generation
|
||||
uint32_t random_seed;
|
||||
uint32_t random_seed = 0;
|
||||
std::shared_ptr<RandomGenerator> rand_crypt;
|
||||
uint8_t allowed_drop_modes;
|
||||
ServerDropMode drop_mode;
|
||||
uint8_t allowed_drop_modes = 0x1F;
|
||||
ServerDropMode drop_mode = ServerDropMode::CLIENT;
|
||||
std::shared_ptr<ItemCreator> item_creator; // Always null for lobbies, never null for games
|
||||
|
||||
struct ChallengeParameters {
|
||||
@@ -145,16 +145,14 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
std::shared_ptr<ChallengeParameters> challenge_params;
|
||||
|
||||
// Ep3 stuff
|
||||
// There are three kinds of Episode 3 games. All of these types have episode
|
||||
// set to EP3; types 2 and 3 additionally have the IS_SPECTATOR_TEAM flag.
|
||||
// There are three kinds of Episode 3 games. All of these types have episode set to EP3; types 2 and 3 additionally
|
||||
// have the IS_SPECTATOR_TEAM flag.
|
||||
// 1. Primary games. These are the lobbies where battles may take place.
|
||||
// 2. Watcher games. These lobbies receive all the battle and chat commands
|
||||
// from a primary game. (This the implementation of spectator teams.)
|
||||
// 3. Replay games. These lobbies replay a sequence of battle commands and
|
||||
// chat commands from a previous primary game.
|
||||
// Types 2 and 3 may be distinguished by the presence of the battle_record
|
||||
// field - in replay games, it will be present; in watcher games it will be
|
||||
// absent.
|
||||
// 2. Watcher games. These lobbies receive all the battle and chat commands from a primary game. (This the
|
||||
// implementation of spectator teams.)
|
||||
// 3. Replay games. These lobbies replay a sequence of battle and chat commands from a previous primary game.
|
||||
// Types 2 and 3 are distinguished by the presence of the battle_record field - in replay games, it will be present;
|
||||
// in watcher games it will be absent.
|
||||
std::shared_ptr<Episode3::Server> ep3_server; // Only used in primary games
|
||||
std::weak_ptr<Lobby> watched_lobby; // Only used in watcher games
|
||||
std::unordered_set<std::shared_ptr<Lobby>> watcher_lobbies; // Only used in primary games
|
||||
@@ -164,19 +162,18 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_ex_result_values;
|
||||
|
||||
// Lobby stuff
|
||||
uint8_t event;
|
||||
uint8_t block;
|
||||
uint8_t leader_id;
|
||||
uint8_t max_clients;
|
||||
uint32_t enabled_flags;
|
||||
uint8_t event = 0;
|
||||
uint8_t block = 0;
|
||||
uint8_t leader_id = 0;
|
||||
uint8_t max_clients = 12;
|
||||
uint32_t enabled_flags = 0;
|
||||
std::shared_ptr<const Quest> quest;
|
||||
std::array<std::shared_ptr<Client>, 12> clients;
|
||||
// Keys in this map are client_id
|
||||
std::unordered_map<size_t, std::weak_ptr<Client>> clients_to_add;
|
||||
|
||||
// This is only used when the PERSISTENT flag is set and idle_timeout_usecs
|
||||
// is not zero
|
||||
uint64_t idle_timeout_usecs;
|
||||
// This is only used when the PERSISTENT flag is set and idle_timeout_usecs is not zero
|
||||
uint64_t idle_timeout_usecs = 0;
|
||||
asio::steady_timer idle_timeout_timer;
|
||||
|
||||
Lobby(std::shared_ptr<ServerState> s, uint32_t id, bool is_game);
|
||||
@@ -206,7 +203,7 @@ 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 create_item_creator(Version logic_version = Version::UNKNOWN);
|
||||
uint8_t effective_section_id() const;
|
||||
uint8_t effective_section_id() const; // Returns 0xFF if not assigned (e.g. empty persistent game)
|
||||
uint16_t quest_version_flags() const;
|
||||
uint8_t client_extension_flags() const;
|
||||
void load_maps();
|
||||
@@ -239,9 +236,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
void remove_client(std::shared_ptr<Client> c);
|
||||
|
||||
void move_client_to_lobby(
|
||||
std::shared_ptr<Lobby> dest_lobby,
|
||||
std::shared_ptr<Client> c,
|
||||
ssize_t required_client_id = -1);
|
||||
std::shared_ptr<Lobby> dest_lobby, std::shared_ptr<Client> c, ssize_t required_client_id = -1);
|
||||
|
||||
std::shared_ptr<Client> find_client(const std::string* identifier = nullptr, uint64_t account_id = 0);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user