Compare commits

...

555 Commits

Author SHA1 Message Date
James Osborne cab3de3ff4 upstream-master-20260614
CMake / build (macos-latest) (push) Has been cancelled
CMake / build (ubuntu-latest) (push) Has been cancelled
upstream master 20260614
2026-06-14 19:12:29 -04:00
Your Name 9150e85442 Merge remote-tracking branch 'upstream/master' into feature/upstream-master-20260614
# Conflicts:
#	src/Client.cc
#	src/IPStackSimulator.cc
#	src/ReceiveCommands.cc
#	src/ReceiveSubcommands.cc
#	src/SendCommands.cc
#	src/ServerState.cc
#	src/ServerState.hh
2026-06-14 18:30:38 -04:00
Martin Michelsen 3cdb5e91a8 name Root structures appropriately 2026-06-14 10:03:55 -07:00
Martin Michelsen 629e2bb4cd make replay tests run in parallel and share immutable data 2026-06-14 09:27:55 -07:00
James Osborne ce39dfc66a Update README.md 2026-06-14 12:14:22 -04:00
James Osborne 448d212aea Update README.md 2026-06-14 12:13:31 -04:00
James Osborne 0208bf26d9 Send account lock session-end on logout
Send account lock session-end on logout
2026-06-14 03:40:52 -04:00
Your Name 1951506dd6 Send account lock session-end on logout 2026-06-14 03:32:25 -04:00
James Osborne d5e429b86a Gate BB login lock before character select
Gate BB login lock before character select
2026-06-14 00:24:33 -04:00
Your Name 6dacf2c152 Gate BB login lock before character select 2026-06-14 00:15:23 -04:00
Martin Michelsen 1737d8abc8 add more options in IntegralExpression 2026-06-13 20:07:23 -07:00
Martin Michelsen 554fc5d208 make check-quests parallel 2026-06-13 17:16:04 -07:00
Martin Michelsen 0dbb34b9f9 don't share iconv_t objects between threads 2026-06-13 17:16:04 -07:00
Your Name 4219eb84c7 Revert "Ignore local source artifacts"
This reverts commit 46c365fda0.
2026-06-13 19:59:01 -04:00
Your Name 46c365fda0 Ignore local source artifacts 2026-06-13 19:57:53 -04:00
Martin Michelsen 5739f99912 port 60 FPS code to all GC versions 2026-06-13 15:55:02 -07:00
Martin Michelsen 9647fe4d63 make $item command use game item ID space 2026-06-13 10:25:25 -07:00
Martin Michelsen 7c007d1b1e fix payment item handling in 6xDA 2026-06-13 10:25:25 -07:00
Martin Michelsen 45b33a3c3a add timing in check-quests 2026-06-13 10:25:25 -07:00
James Osborne a611462655 team sync team chat relay fix
team sync team chat relay fix
2026-06-12 22:06:32 -04:00
Your Name 4e8253c38f Log TeamSync chat exchange flow 2026-06-12 21:50:54 -04:00
Your Name 15266e0ef9 Log TeamSync team chat relay attempts 2026-06-12 21:36:16 -04:00
Your Name 133041f09b Relay TeamSync team chat events 2026-06-12 20:40:15 -04:00
James Osborne 989eabe3a0 Merge pull request #36 from incentivebeats/feature/team-sync-phase3-team-management
Add TeamSync team management events
2026-06-12 18:02:28 -04:00
Your Name f883367eaa Add TeamSync team management events 2026-06-12 16:39:46 -04:00
James Osborne 91c4711c48 Merge pull request #35 from incentivebeats/feature/team-sync-phase2-points-names
Add TeamSync member name and points updates
2026-06-12 16:08:22 -04:00
Your Name f4af1a73f1 Add TeamSync member name and points updates 2026-06-12 15:46:36 -04:00
James Osborne b450a04be4 team sync chat relay
Feature/team sync chat relay
2026-06-12 15:32:48 -04:00
Your Name 23015614ed Harden TeamSync canonical state application 2026-06-12 14:39:07 -04:00
Your Name cf380e93d2 Guard unsupported TeamSync team mutations 2026-06-12 13:02:06 -04:00
incentive 21bceac1e3 Route TeamSync member mutations through coordinator 2026-06-12 01:26:18 -04:00
incentive b578c1cbbe Apply TeamSync team membership to account records 2026-06-12 01:23:59 -04:00
incentive 44650179f0 Route TeamSync team creation through coordinator 2026-06-12 01:07:12 -04:00
incentive 7526176bb3 Add TeamSync outbound team create queue 2026-06-12 01:02:13 -04:00
incentive 4d893607c2 Add TeamSync canonical team state apply scaffold 2026-06-12 00:57:17 -04:00
incentive 6995e5b7f4 Improve TeamSync coordinator error logging 2026-06-11 22:34:47 -04:00
incentive e9187609ae Add TeamSync exchange task scaffold 2026-06-11 22:28:35 -04:00
incentive bf3c9c08e6 Harden TeamSync config parsing 2026-06-11 22:00:23 -04:00
incentive c4fb18b3b4 Add TeamSync configuration scaffold 2026-06-11 21:59:00 -04:00
James Osborne fe412ebd84 merge upstream master 20260611
Feature/merge upstream master 20260611
2026-06-11 20:02:10 -04:00
incentive ee5ee49d22 Use EmulatorBase DisassembleResult for DOL semantic diff 2026-06-11 19:18:07 -04:00
incentive 12481996b8 Merge upstream master
# Conflicts:
#	README.md
2026-06-11 18:31:23 -04:00
James Osborne aae7e64018 Add BB license update admin endpoint
Add BB license update admin endpoint
2026-06-11 18:28:17 -04:00
incentive ed47fdc5d1 Add BB license update admin endpoint 2026-06-11 13:13:27 -04:00
James Osborne 021cb9b176 account login locks
Feature/account login locks
2026-06-11 12:19:25 -04:00
incentive 3d37aacc06 Add login lock coordinator heartbeat 2026-06-11 02:06:07 -04:00
incentive 56084c736f Add coordinator login lock acquire request 2026-06-11 01:28:23 -04:00
incentive 6a4789b248 Add login lock session plumbing 2026-06-11 01:22:32 -04:00
James Osborne f18d5a468c Allow account concurrency across client sources
Allow account concurrency across client sources
2026-06-10 15:35:53 -04:00
incentive 79fa456365 Allow account concurrency across client sources 2026-06-10 15:27:17 -04:00
James Osborne 98e338046c Add account admin mutation endpoints
Add account admin mutation endpoints
2026-06-09 23:01:51 -04:00
incentive 3c9240e7d8 Add account admin mutation endpoints 2026-06-09 20:52:47 -04:00
James Osborne 40689c0690 Skip BB auth gate for PC patch login
Skip BB auth gate for PC patch login
2026-06-09 19:58:21 -04:00
incentive e433b0c663 Skip BB auth gate for PC patch login 2026-06-09 16:29:47 -04:00
Martin Michelsen bb70390fd8 fix TODO comments 2026-06-09 07:18:29 -07:00
Martin Michelsen c98f88f5c0 add basic semantic diff for DOL files 2026-06-09 07:02:50 -07:00
James Osborne e3c223f979 account sync hooks
Feature/account sync hooks
2026-06-08 12:48:08 -04:00
incentive 127288c349 Add explicit account sync source identity 2026-06-08 06:06:20 -04:00
incentive cfbe1fda27 Spool account sync events to disk 2026-06-08 05:59:55 -04:00
incentive 8f80005cb1 Move account sync implementation out of header 2026-06-08 05:55:11 -04:00
incentive 70dd22ee8c Make account sync hooks config-aware 2026-06-08 04:43:21 -04:00
incentive 94250d21eb Add log-only BB account sync logout hook 2026-06-08 04:02:11 -04:00
incentive fe97a0dda4 Add log-only BB account sync login hook 2026-06-08 03:59:27 -04:00
incentive f8d50b3ab7 Add log-only account sync save hooks 2026-06-08 03:56:50 -04:00
James Osborne 1d162bb723 brutal peeps labeling in room list
brutal peeps labeling in room list
2026-06-08 03:33:27 -04:00
incentive e802752836 Clarify Brutal Peeps room join warnings 2026-06-07 18:10:45 -04:00
incentive 2e38c4b12f Split BB and PC Brutal Peeps patch timing 2026-06-07 17:31:48 -04:00
incentive 75653f155c Show Brutal Peeps tier in BB game list 2026-06-07 16:56:44 -04:00
incentive b9cd17d9dc Do not use BB color tokens in game list names 2026-06-07 16:53:41 -04:00
incentive 672a6575a7 Restrict Brutal Peeps rooms to matching client versions 2026-06-07 15:54:21 -04:00
incentive 7d609b6a40 Restrict PC Brutal Peeps rooms to PC clients 2026-06-07 15:48:38 -04:00
incentive 9183c1e362 Mark Brutal Peeps rooms in game list 2026-06-07 15:39:33 -04:00
Martin Michelsen c329418f30 reconcile 6xE0 prize list with old records and Ephinea's list 2026-06-07 12:02:33 -07:00
James Osborne 2dba843cb2 writecodeblocks noop clean
Feature/pc writecodeblocks noop clean
2026-06-07 13:00:51 -04:00
incentive 1f9ef0c3b6 Fix Dragon Visual Fix source encoding 2026-06-07 12:24:05 -04:00
incentive 0bf07a882c Log Dragon client function loading 2026-06-07 12:18:15 -04:00
incentive 52087e50a3 Fix PC client function probe version type 2026-06-07 12:13:26 -04:00
incentive 2c66407e8b Probe Dragon client function indexing 2026-06-07 11:58:44 -04:00
incentive eb7457a436 Log PC patch menu function filtering 2026-06-07 11:49:46 -04:00
incentive 943bb20cec Shorten Dragon Visual Fix menu label 2026-06-07 06:54:41 -04:00
incentive ea2d87cacb Rename Dragon Visual Fix patch 2026-06-07 06:52:43 -04:00
incentive 3e527bf979 Encode PC Dragon Visual Fix bytes directly 2026-06-07 06:47:55 -04:00
incentive e8b80a3ede Add PC Dragon Visual Fix patch 2026-06-07 06:33:21 -04:00
incentive c1a5063ba8 Use VirtualProtect for PC WriteCodeBlocks 2026-06-07 06:18:51 -04:00
incentive b9a621e7cc Use VirtualProtect for PC WriteCodeBlocks 2026-06-07 06:12:32 -04:00
incentive 41f05b1fe5 Test PC WriteCodeBlocks against writable data 2026-06-07 06:01:21 -04:00
incentive 5d58c2467c Add PC WriteCodeBlocks no-op test 2026-06-07 05:56:52 -04:00
James Osborne 621691b369 Brutal Peeps PC client memory patch
Add Brutal Peeps PC client memory patch
2026-06-07 04:56:13 -04:00
incentive 3c779b9e1f Track PC Brutal Peeps BattleParam patch tier 2026-06-07 04:30:47 -04:00
incentive 892b12535c Keep retrying PC Brutal Peeps patch after room load 2026-06-07 04:12:44 -04:00
incentive fc1fe53b63 Only patch PC Brutal Peeps after combat floor event 2026-06-07 04:00:35 -04:00
incentive b80cf85f48 Patch PC Brutal Peeps after entering combat floor 2026-06-07 03:54:55 -04:00
incentive f0bc3639c9 Force-send PC Brutal Peeps dynamic patch 2026-06-07 03:43:25 -04:00
incentive 17ddfe4945 Retry PC Brutal Peeps memory patch after load 2026-06-07 03:37:45 -04:00
incentive e3c7f77440 Compact PC Brutal Peeps memory patch payload 2026-06-07 03:32:00 -04:00
incentive 1ef2a7e1e2 Defer PC Brutal Peeps memory patch until room load 2026-06-07 03:24:53 -04:00
incentive 58efb41957 Allow PC to create Brutal Peeps rooms 2026-06-07 03:18:24 -04:00
incentive a1c3beafac Allow Brutal Peeps menu for PC 2026-06-07 03:06:09 -04:00
incentive 30e645fdeb Add Brutal Peeps PC client memory patch 2026-06-07 02:57:26 -04:00
Martin Michelsen 77d31cd3b5 add more logs to 6xE0 handler 2026-06-06 21:51:15 -07:00
Martin Michelsen 5f7032f920 add symlinks for DC V1 battle mode city maps; closes #772 2026-06-06 21:51:15 -07:00
Martin Michelsen 0c9cd57329 fix 6xDA attribute computation; closes #775 2026-06-06 21:51:15 -07:00
Martin Michelsen b301df96f2 add TreeWindowIndex 2026-06-06 21:51:15 -07:00
Martin Michelsen 708d2a9fb0 convert shop random sets to JSON 2026-06-06 21:51:15 -07:00
Martin Michelsen efe7401d7b convert TekkerAdjustmentSet to JSON 2026-06-06 21:51:15 -07:00
Martin Michelsen 3f33b94e8f more work on ItemMagEdit 2026-06-06 21:51:15 -07:00
James Osborne a5307ccb1a brutal peeps bb atp scaling
Feature/brutal peeps bb atp scaling
2026-06-07 00:33:22 -04:00
incentive 9dbb19972f Retune Brutal Peeps ATP scaling 2026-06-07 00:21:14 -04:00
incentive 61ff0de929 Use gentler Brutal Peeps ATP tier table 2026-06-07 00:13:46 -04:00
James Osborne af8e1ccb91 brutal peeps bb episode hp tables
Feature/brutal peeps bb episode hp tables
2026-06-06 23:42:36 -04:00
incentive 8dd966a5d7 Patch all BB online BattleParam tables before Brutal Peeps rooms 2026-06-06 23:33:11 -04:00
incentive 98dd6b8913 Select BB Brutal Peeps HP table by episode 2026-06-06 23:24:39 -04:00
James Osborne 6492dbf879 brutal peeps hp scaling
Feature/brutal peeps hp scaling
2026-06-06 22:54:24 -04:00
incentive 5feffea722 Use raw BattleParam HP offsets for Brutal Peeps patch 2026-06-06 22:18:52 -04:00
incentive 672be0b6b8 Patch Brutal Peeps HP before BB room load 2026-06-06 22:11:31 -04:00
incentive c7fb0cf5f6 Use raw HP diffs with simple BattleParam scanner 2026-06-06 22:06:06 -04:00
incentive eba565c381 Use table-offset signature for Brutal Peeps HP patch 2026-06-06 21:59:05 -04:00
incentive 942dbbc5b9 Patch matching BB battle param tables with raw HP diffs 2026-06-06 21:52:42 -04:00
incentive b4a7374fae Apply Brutal Peeps HP patch after BB area load 2026-06-06 21:35:22 -04:00
incentive 976cb132a2 Pass Brutal Peeps HP patch config in suffix 2026-06-06 21:24:29 -04:00
incentive f424d6ed3c Avoid coroutine ICE in Brutal Peeps HP patch 2026-06-06 21:15:13 -04:00
incentive e44dad8344 Add Brutal Peeps HP client patch 2026-06-06 21:07:52 -04:00
Corrine 989fc8f0ec Fix ClearUnreleasedItemList.s for 50YJ 2026-06-06 17:12:27 -07:00
James Osborne 46ddcb64a9 Feature/brutal peeps
Feature/brutal peeps live
2026-06-05 20:24:09 -04:00
incentive b27e0b8351 Retune Brutal Peeps EXP and HP scaling 2026-06-05 20:09:32 -04:00
incentive 563f84d87a Remove Brutal Peeps global unlock config 2026-06-05 19:27:07 -04:00
incentive 507a0ef9f0 Use Brutal Peeps tier table for rewards and enemy HP 2026-06-05 19:25:14 -04:00
incentive 2493173052 Gate Brutal Peeps tiers by character level 2026-06-05 19:23:49 -04:00
incentive 9d4636f386 Add Brutal Peeps tier table 2026-06-05 19:21:14 -04:00
incentive 08c897cbea Rename Blueballz mode to Brutal Peeps 2026-06-05 19:19:48 -04:00
James Osborne 108eee0154 Upstream/2026 05 31
Upstream/2026 05 31
2026-05-31 18:10:09 -04:00
incentive bde24db224 Merge upstream changes from 2026-05-31 2026-05-31 11:23:38 -04:00
James Osborne e7c3eec58f Fix BB EP4 solo quest unlocks
Fix BB EP4 solo quest unlocks and ship-state marking
2026-05-31 10:45:49 -04:00
incentive 55744dfc9d Fix BB EP4 solo access and ship-state marking 2026-05-31 10:02:53 -04:00
incentive 6d9d7cfb95 Fix BB EP4 solo access and ship-state marking 2026-05-31 09:54:02 -04:00
incentive 1cf5b210ca Unlock BB EP4 solo areas 2026-05-31 09:08:41 -04:00
incentive a030983b61 Fix BB EP4 solo quest unlocks and ship-state marking 2026-05-31 08:42:39 -04:00
Martin Michelsen 93bad47c03 more quest flag notes 2026-05-30 21:56:40 -07:00
Martin Michelsen f9ff902d35 update solo quest unlock conditions 2026-05-30 13:44:38 -07:00
Martin Michelsen 1dee20713b explain quest counters more clearly 2026-05-30 09:52:19 -07:00
Martin Michelsen 9187a3ceb0 update PlayerVisualConfigV4 struct to match client implementation 2026-05-30 09:47:52 -07:00
Martin Michelsen e4054d95d9 rewrite BB EXP generation to handle non-player kills properly 2026-05-29 07:43:05 -07:00
Martin Michelsen c09ee2da85 handle missing block indexes in qst decoder 2026-05-29 06:56:56 -07:00
Martin Michelsen bb0ead8650 fix Dal Ra Lie Ultimate name 2026-05-28 08:29:49 -07:00
Martin Michelsen 3aa58e24b4 add minor notes from Challenge RE 2026-05-28 08:29:37 -07:00
Martin Michelsen c3aacc2352 add Challenge warning chime code 2026-05-28 08:29:20 -07:00
Martin Michelsen 077a4b91d0 update to-do list 2026-05-28 08:29:12 -07:00
James Osborne 7099045ea1 Feature/room crossplay opt in
Feature/room crossplay opt in
2026-05-25 20:45:15 -04:00
Martin Michelsen e9c2ac34a3 eliminate using namespace 2026-05-25 16:44:37 -07:00
Martin Michelsen 4503d09c77 fix DC NTE map file 2026-05-25 16:44:37 -07:00
Martin Michelsen e5b3abd49f remove unnecessary config var 2026-05-25 16:44:37 -07:00
Martin Michelsen b59dde53b2 delete unnecessary file caches 2026-05-25 16:44:36 -07:00
Martin Michelsen b8efd730f9 fix incorrect game duration in info window 2026-05-25 16:44:36 -07:00
Martin Michelsen f13c4df946 style updates 2026-05-25 16:44:36 -07:00
Martin Michelsen 62a9da9ed3 update game join procedure implementation 2026-05-25 16:44:36 -07:00
incentive 356abb6698 Treat tab-padded BB room names as crossplay opt-in 2026-05-25 18:57:00 -04:00
incentive d40dbec9f0 Log room name bytes for crossplay opt-in 2026-05-25 18:49:45 -04:00
incentive 5ec3028316 Handle padded BB room names for crossplay opt-in 2026-05-25 18:45:40 -04:00
incentive bf52bfb291 Recognize BB x-prefixed crossplay rooms 2026-05-25 18:37:30 -04:00
incentive fa543b842e Log room crossplay opt-in decisions 2026-05-25 18:23:42 -04:00
incentive 7e9c6c185a Add opt-in room crossplay compatibility 2026-05-25 18:13:50 -04:00
James Osborne 0789f04d6a Make DC V2 EXP boost config-driven
Make DC V2 EXP boost config-driven
2026-05-24 12:34:41 -04:00
incentive 3e9cb883f4 Disable GC V3 XP patch menu for now 2026-05-24 12:33:43 -04:00
incentive e3ad3c505f Limit GC V3 XP patch to USA Plus 2026-05-24 12:13:08 -04:00
incentive a292956151 Match GC EP1 EXP patch row coverage to disc 2026-05-24 12:10:32 -04:00
incentive 5e94f2eac0 Expand GC V3 EP1 EXP denylist 2026-05-24 11:28:58 -04:00
incentive 114fe642fc Skip problematic GC V3 EP1 EXP rows 2026-05-24 11:20:12 -04:00
incentive c6ee7aa08b Fix GC V3 EXP runtime byte order 2026-05-24 10:36:11 -04:00
incentive 48d32214c0 Merge master into DC/GC XP boost branch 2026-05-24 10:30:09 -04:00
incentive 0b3464b4fc Make GC V3 EXP boost config-driven 2026-05-24 01:19:02 -04:00
incentive f8ebc67c90 Make GC V3 EXP boost config-driven 2026-05-24 00:38:10 -04:00
incentive e6b7ed7e24 Make DC V2 EXP boost config-driven 2026-05-23 23:50:10 -04:00
Corrine fffd2c3e62 Added notes on 50YJ 2026-05-23 19:27:33 -07:00
Corrine ea74b4ac07 Port all 59NL/59NJ patches to 50YJ (US 1.24.3) 2026-05-23 19:27:33 -07:00
James Osborne 059011ddda exp dispatch rate aware / bb char locks
Fix dcv2/gc exp dispatch rate aware
2026-05-23 04:57:11 -04:00
incentive 6910c90fe6 Lock BB test characters to test ship 2026-05-22 22:20:48 -04:00
incentive ab245d1b70 Lock BB test characters to test ship and hide ship transfers 2026-05-22 22:11:38 -04:00
incentive 57f3e1e5f2 Lock BB test characters to test ship 2026-05-22 21:49:38 -04:00
Martin Michelsen 6f9c442e7a fix missing login in send_client_init_bb 2026-05-21 06:42:24 -07:00
Martin Michelsen a21b09d7b9 minor notes updates 2026-05-21 06:41:52 -07:00
incentive 6bb5bb8496 Resolve GC EXP patches to US-only addresses 2026-05-21 04:50:27 -04:00
incentive 243098c98c Restore exact May 16 GC EXP patches 2026-05-21 04:40:23 -04:00
incentive 9ff1934b2f Fix GC EXP patch metadata descriptions 2026-05-21 04:11:17 -04:00
incentive 6b3669dfd6 Restore GC EXP direct menu patches 2026-05-21 03:43:48 -04:00
incentive 7c7ecf0383 Use awaited path for GC EXP dispatch 2026-05-21 03:26:40 -04:00
incentive 2615ce46eb Dispatch GC EXP before game loading 2026-05-21 03:08:41 -04:00
incentive 9e746a63d9 Fix GC EXP enable shim assembly 2026-05-21 02:47:09 -04:00
incentive 1849d9d13d Make GC EXP enable shim inert and dedupe dispatch 2026-05-21 02:32:12 -04:00
incentive b9c9b877d2 Add GC V3 EXP dispatcher 2026-05-21 01:50:06 -04:00
incentive 07d04a761e Restore GC EXP patches without XP client flag 2026-05-21 01:40:31 -04:00
incentive 2b81f4d1d3 Add PC V2 EXP patch assets 2026-05-20 23:04:38 -04:00
incentive da8466c432 Make DC V2 EXP dispatcher rate-aware 2026-05-20 09:46:25 -04:00
James Osborne 7b0bdbd1ce Upstream sync 2026 05 19
Upstream sync 2026 05 19
2026-05-19 18:23:04 -04:00
incentive 47e9fe5f16 Merge upstream newserv master 2026-05-19 16:56:33 -04:00
James Osborne d7862426ac align proxy boost gates with upstream cleanup
align proxy boost gates with upstream cleanup
2026-05-19 16:13:01 -04:00
incentive 4cf5974c7d Fix BB live ship menu reconnect port 2026-05-19 16:11:05 -04:00
incentive e7ea471ec5 PSO Peeps: align proxy boost gates with upstream cleanup 2026-05-19 15:50:37 -04:00
Martin Michelsen 86227c0026 fix GC NoRareSelling patch; closes #763 2026-05-17 19:42:39 -07:00
Martin Michelsen 7b9b44c191 add option to prevent concurrent logins; closes #511 2026-05-17 15:00:32 -07:00
James Osborne f73dbf5a96 Skip auto patches for checksum-only clients
Skip auto patches for checksum-only clients
2026-05-17 13:21:43 -04:00
Martin Michelsen cb69dc9c14 more notes on PlayerInventoryItem 2026-05-17 07:59:41 -07:00
Martin Michelsen d31fb5b084 fix battle level up on BB 2026-05-17 07:59:32 -07:00
incentive f7fff5c82b Skip auto patches for checksum-only clients 2026-05-17 09:35:32 -04:00
James Osborne 6b99ce49e8 bb lobby defaults 2026-05-17 02:28:25 -04:00
incentive e7cdce9a3d Force BB clients to repatch default lobby assets 2026-05-17 02:21:41 -04:00
incentive e78da0e19e Restore default BB city02 lobby assets 2026-05-17 02:10:39 -04:00
incentive 0c50c664af Restore default BB city02 map assets 2026-05-17 02:02:02 -04:00
James Osborne a5bfb25854 Add BB stream diagnostics and event guard | Restore DC V2 EXP dispatcher
Devnet/v0.2.1 bb stream diag 20260517 t041446 z
2026-05-17 01:10:47 -04:00
incentive 7bd2fba177 Restore DC V2 EXP dispatcher 2026-05-17 01:04:21 -04:00
Martin Michelsen ef3a6575ab demote ignore_def message from warning 2026-05-16 22:02:57 -07:00
Martin Michelsen 57de5a71a3 fix mismatched enemy type order 2026-05-16 22:02:41 -07:00
Martin Michelsen 53bc0641a9 delete compatibility table 2026-05-16 22:02:11 -07:00
incentive 21884bf109 Add BB stream diagnostics and event guard 2026-05-17 00:15:50 -04:00
Martin Michelsen 0d5cfc6ccc censor user credentials in logs by default 2026-05-16 17:20:09 -07:00
James Osborne 4f7e353daa Add Dreamcast V2 EXP dispatcher
Dc xp fix
2026-05-16 05:49:50 -04:00
incentive ca6a07a151 Add Dreamcast V2 EXP dispatcher 2026-05-16 05:24:26 -04:00
incentive e384477594 Add Dreamcast V2 EXP dispatcher 2026-05-16 05:19:20 -04:00
incentive 50332d2f1e Add internal Dreamcast V2 EXP tables 2026-05-16 04:50:30 -04:00
incentive 48c25159bc Restore working Dreamcast V2 EXP patch state 2026-05-16 04:03:57 -04:00
incentive 28a113657b Fix Dreamcast V2 EXP factor load 2026-05-16 03:45:07 -04:00
incentive f3681d79f9 Fix Dreamcast V2 EXP resend behavior 2026-05-16 03:23:36 -04:00
incentive e29231356b Resend Dreamcast V2 patches after floor changes 2026-05-16 03:13:58 -04:00
incentive 781800a36e Make Dreamcast V2 EXP patches difficulty-aware 2026-05-16 02:57:56 -04:00
incentive e3fd155e0e Temporarily restore fixed Dreamcast V2 EXP patches 2026-05-16 02:48:23 -04:00
incentive c043bbc909 Fix Dreamcast V2 EXP patch sentinel load 2026-05-16 02:43:00 -04:00
incentive e4a758284c Make Dreamcast V2 EXP patches difficulty-aware 2026-05-16 02:38:10 -04:00
Martin Michelsen ecc61b7d1f document usability flags in ItemParameterTable 2026-05-15 21:22:09 -07:00
James Osborne 447fef0574 Dc xp fix
Dc xp fix
2026-05-15 23:52:35 -04:00
incentive 0063384144 Resend selected patch-menu functions after loading 2026-05-15 23:43:47 -04:00
incentive fdbad0a044 Write Dreamcast V2 EXP patches to third table copy 2026-05-15 23:28:28 -04:00
incentive b29360f066 Write Dreamcast V2 EXP patches to both table copies 2026-05-15 23:20:18 -04:00
incentive b238d7f26a Fix Dreamcast V2 EXP patch addresses 2026-05-15 23:14:04 -04:00
James Osborne 8ef0623605 Sync from and adapt to upstream 20260514
Sync/upstream 20260514
2026-05-15 22:19:52 -04:00
incentive d5df5eec5a Add Dreamcast V2 EXP client patches 2026-05-15 19:39:21 -04:00
incentive 9dfcf57bbf Split EP2 GC EXP patches by version 2026-05-15 18:19:13 -04:00
incentive 566b36d611 Add 3OJ5 support for GC client functions 2026-05-15 17:24:20 -04:00
incentive e8323989d3 Remove tentative 3OP0 GC patch mappings 2026-05-15 16:18:34 -04:00
incentive 08bb9b8a10 Shorten PSO Peeps GC patch menu names 2026-05-15 15:35:13 -04:00
incentive 19294a50a5 Add tentative 3OP0 mappings for PSO Peeps GC patches 2026-05-15 15:24:03 -04:00
incentive 6de7db4765 Add IP stack port remapping 2026-05-15 15:06:32 -04:00
incentive b2b8fd2cec Retarget PSO Peeps GC patches to US Plus 2026-05-15 13:27:11 -04:00
incentive 096831ac1b Convert PSO Peeps client functions to new format 2026-05-15 11:52:45 -04:00
Martin Michelsen 645590d03f fix S_14 definition 2026-05-14 19:20:40 -07:00
James Osborne b873a62772 Restore upstream savechar and loadchar proxy restrictions
Restore upstream savechar and loadchar proxy restrictions
2026-05-14 15:03:16 -04:00
incentive 78878ad276 Merge upstream newserv master 2026-05-14 14:23:00 -04:00
incentive 58d7f23ace Restore upstream savechar and loadchar proxy restrictions 2026-05-14 14:02:30 -04:00
Martin Michelsen b4f83c32de don't suppress 1D in proxy sessions; BB server may have customized it 2026-05-13 21:33:56 -07:00
Martin Michelsen 800b55cb04 add GC rare mag feed test 2026-05-13 21:28:20 -07:00
Martin Michelsen a6c25568ba support multiple replays in the same session 2026-05-13 21:25:55 -07:00
Martin Michelsen 2e667bbe50 support multiple aliases for quest opcodes 2026-05-13 20:32:44 -07:00
Martin Michelsen b1edf00efc update readme 2026-05-13 10:37:15 -07:00
Martin Michelsen 9d0abbce7f fix patch menu visibility 2026-05-12 17:58:37 -07:00
Martin Michelsen 563e601441 update comments in WriteMemory.s 2026-05-12 07:37:50 -07:00
Martin Michelsen c315b828ad sort DOL files by name 2026-05-12 07:37:36 -07:00
Martin Michelsen 21eae36c8f update readme for new client function compiler 2026-05-12 07:18:56 -07:00
Martin Michelsen e78e2ba887 rewrite client function compiler 2026-05-11 21:33:35 -07:00
incentive 74bfe9683d Merge remote-tracking branch 'origin/sync/upstream-20260507'
CMake / build (macos-latest) (push) Has been cancelled
CMake / build (ubuntu-latest) (push) Has been cancelled
2026-05-11 09:10:04 -04:00
Martin Michelsen 2f2a0bcf2b update logo 2026-05-10 13:38:11 -07:00
Martin Michelsen 6da72c7323 make unsealable table ordered 2026-05-10 11:20:36 -07:00
Martin Michelsen fc70919c94 reorganize game tables 2026-05-10 11:09:35 -07:00
Martin Michelsen 554bef0de4 more details on MagEvolutionTable 2026-05-09 17:05:23 -07:00
Martin Michelsen 7ce3ce5b65 add level table JSON format 2026-05-09 17:05:23 -07:00
Martin Michelsen 9915422ae6 clean up rel helpers 2026-05-08 22:22:41 -07:00
incentive e88ed98318 Merge upstream newserv master 2026-05-09 01:02:34 -04:00
Martin Michelsen e342915505 fix invalid dereference 2026-05-08 20:09:19 -07:00
Martin Michelsen e617385425 move all_start_offsets to CommonFileFormats 2026-05-08 19:50:53 -07:00
Martin Michelsen 211d08710b add default item parameter tables 2026-05-08 18:25:57 -07:00
Martin Michelsen ee40425393 add ItemParameterTable binary serialization; make JSON the default format 2026-05-08 09:23:53 -07:00
Corrine 12f9a045ca Same treatment to AR Codes. 2026-05-07 19:35:21 -07:00
Corrine 8134243fb1 Prevent confusion. 2026-05-07 19:35:21 -07:00
Corrine c869ed27f1 Fixed a mistake with NoRareSelling 2026-05-07 19:35:21 -07:00
Corrine 321ba64016 Finished. 2026-05-07 19:35:21 -07:00
Corrine a8606d26a8 Added MoreSaveSlots.59NJ 2026-05-07 19:35:21 -07:00
Corrine a57cca6c12 Port 59NL server patches to 59NJ (pt. 1) 2026-05-07 19:35:21 -07:00
incentive 86a46df442 Treat proxy A0 lobby exit as intentional
CMake / build (macos-latest) (push) Has been cancelled
CMake / build (ubuntu-latest) (push) Has been cancelled
2026-05-06 02:03:51 -04:00
incentive cdb397f5ea Add GC EP1 and EP2 EXP client patches 2026-05-05 22:34:44 -04:00
incentive 2b73d58033 Add GC Normal Dragon HP client patch 2026-05-05 22:21:33 -04:00
incentive 5abd47ff72 Align BB Normal Dragon HP with V2 2026-05-05 19:39:05 -04:00
incentive 261cb5c76f Log Dragon boss action state 2026-05-05 19:12:20 -04:00
incentive ea1044c271 Merge boss flags when blocking damage rollback 2026-05-05 18:51:10 -04:00
incentive a1c358e13a Preserve boss flags when blocking damage rollback 2026-05-05 18:28:46 -04:00
incentive 1f00bf1d9b Clamp boss damage rollback from 6x0A 2026-05-05 18:12:36 -04:00
incentive 8bc602012e Allow DC V2 Falz death-drop pickup recovery 2026-05-05 16:52:25 -04:00
incentive e0c34fe700 PSO Peeps: block boosted clients from Vanilla and Hardcore
Add HAS_PSO_PEEPS_XP_PATCH for future V2/GC client-function XP patches.

Unify boosted-client proxy blocking so Vanilla/Hardcore reject:
- PC v2 clients using boosted BattleParams
- legacy boosted-disc listener ports
- future clients with the PSO Peeps XP patch flag

Normal unpatched V2/GC clients remain allowed.
2026-05-05 15:52:11 -04:00
incentive cbe9747fd4 PSO Peeps: block PC v2 from Vanilla/Hardcore ships
PC v2 clients receive boosted BattleParams via the patch server.
Vanilla and Hardcore run base XP rates and are incompatible.
Block Version::PC_V2 from proxy destinations on ports 19230/19530.
2026-05-05 15:52:08 -04:00
incentive de0104eec8 Forward in-game proxy command 1D 2026-05-05 14:13:11 -04:00
incentive c454068715 Merge preferred lobbies and mag feed fix 2026-05-04 14:29:52 -04:00
Martin Michelsen b8e7d81a22 add check for invalid defensive item type 2026-05-04 10:32:08 -07:00
Martin Michelsen d98e1f7478 fix mag evolution table reference 2026-05-04 13:31:59 -04:00
Martin Michelsen d384cf4f11 fix mag evolution table reference 2026-05-04 09:51:57 -07:00
Martin Michelsen 681ce135f8 add JSON encoding for ItemPMT 2026-05-03 22:55:53 -07:00
incentive c497f64376 Fix proxy savechar character backup 2026-05-03 22:21:45 -04:00
incentive 5d43acd9a2 Fix proxy savechar character backup 2026-05-03 22:21:37 -04:00
incentive 90a1f0f938 Allow loadchar in proxy sessions 2026-05-03 21:04:59 -04:00
incentive db52a15888 Allow loadchar in proxy sessions 2026-05-03 21:04:55 -04:00
incentive 71fc272133 Allow savechar in proxy sessions 2026-05-03 18:13:32 -04:00
incentive bef656077c Allow savechar in proxy sessions 2026-05-03 18:13:01 -04:00
incentive fff0f3a71d Fix README formatting on branch 2026-05-02 23:07:46 -04:00
incentive e94fcf035e Fix README formatting 2026-05-02 23:06:00 -04:00
incentive 0abdb50eca Add PSO Peeps README and preserve upstream README 2026-05-02 23:05:25 -04:00
incentive a0306ecaee Update README for PSO Peeps 2026-05-02 23:03:43 -04:00
incentive ce0aea1518 Add PSO Peeps README and preserve upstream README 2026-05-02 23:03:03 -04:00
incentive 1c3e8ca53c Merge upstream newserv preferred lobby changes 2026-05-02 22:46:20 -04:00
Martin Michelsen e19c0b8bc9 add 11/2000 mag table 2026-05-02 10:50:55 -07:00
Martin Michelsen 6b636c4694 rewrite MagEvolutionTable 2026-05-02 10:48:22 -07:00
Martin Michelsen 1fa3d18430 rewrite ItemParameterTable 2026-05-02 09:36:16 -07:00
Martin Michelsen 2f4a9462ea fix 6x17 filter in proxy 2026-05-01 21:56:21 -07:00
incentive f05e68492d PSO Peeps Start
Docker / Build (push) Has been cancelled
2026-05-01 23:14:17 -04:00
Martin Michelsen 826eb88e2e add __packed_ws_be__ 2026-04-26 17:57:59 -07:00
Martin Michelsen 80391df8b7 implement lobby assignment at login 2026-04-26 09:28:10 -07:00
Martin Michelsen 7f68d41bac fix port name in game server lookup 2026-04-25 22:21:46 -07:00
Martin Michelsen 75e7232096 handle BB not sending C6 after 08E8 2026-04-25 12:06:43 -07:00
Martin Michelsen 7a29b39771 allow 6xCB in free-play 2026-04-24 20:36:45 -07:00
Martin Michelsen cfcb56b13f update command notes 2026-04-24 20:17:48 -07:00
Martin Michelsen 9e6740b778 update 6x30 notes 2026-04-20 20:00:11 -07:00
Martin Michelsen 590f937959 add release script 2026-04-19 13:32:26 -07:00
Martin Michelsen 31abc24e81 don't allow players to pick up items if they are too far away 2026-04-19 09:35:20 -07:00
Martin Michelsen 507fbf0451 add another useless AR code 2026-04-19 08:57:49 -07:00
Martin Michelsen 1fa660129d add last-hit tracking for target subcommands 2026-04-11 08:28:40 -07:00
Martin Michelsen 67082f7b6b update static 2026-04-11 08:14:12 -07:00
Martin Michelsen b34c9a7c88 improve error message for missing quest common/rare item sets 2026-04-05 21:50:53 -07:00
Martin Michelsen 87e85932a4 switch rare drops to stacked space logic 2026-04-03 19:52:42 -07:00
Martin Michelsen b704d827ed add support for direct Xbox connections 2026-04-01 21:47:21 -07:00
Martin Michelsen 598ecf88e3 revise death_flags notes 2026-04-01 08:48:19 -07:00
Martin Michelsen a05971017d explain a few of the unknown player_flags bits 2026-03-30 19:38:15 -07:00
Martin Michelsen b7819413b0 handle missing DAR entries in HTML generator 2026-03-27 07:55:44 -07:00
Martin Michelsen 80e4b0e6fe clean up formatting on Ep3 drop rates comment 2026-03-23 20:39:44 -07:00
Martin Michelsen daee47b722 use new phosg parallel functions 2026-03-22 21:37:52 -07:00
Martin Michelsen 5724fb9a12 add $allrare debug command; closes #739 2026-03-22 21:37:43 -07:00
Martin Michelsen 983753f840 add FogDebug patch 2026-03-21 09:30:59 -07:00
Martin Michelsen 53d2318873 more details on player_flags 2026-03-20 22:21:21 -07:00
Martin Michelsen 83291d5501 more details on player_flags 2026-03-19 23:01:30 -07:00
Martin Michelsen 55be92a56f add game duration to info window 2026-03-19 10:42:01 -07:00
Martin Michelsen 6a23e5da0a make some sense out of game_flags and player_flags 2026-03-18 22:44:02 -07:00
Martin Michelsen 4571cf7fdc fix attribute count check in 6xDA 2026-03-11 07:19:53 -07:00
Martin Michelsen 4e3549ba6b use EnemyType in ItemCreator; fix incorrect drop tables 2026-03-08 20:40:15 -07:00
Martin Michelsen 3cbf64dda2 update quest collision opcode docs 2026-03-08 12:55:57 -07:00
Martin Michelsen 382bc6b7ce don't allow error cases for bb_exchange_pd_percent to destroy items 2026-03-04 21:37:54 -08:00
Martin Michelsen e05991ffb3 add test for trade window sequence 2026-03-03 20:43:46 -08:00
Martin Michelsen ffda97222d document --language option in disassemble-quest-script 2026-03-02 08:46:38 -08:00
Martin Michelsen 8f21604367 clean up CMakeLists a bit 2026-03-02 08:46:25 -08:00
Martin Michelsen 4045504b61 also send combatant info board entries in spectator teams 2026-02-28 20:49:36 -08:00
Martin Michelsen 4aad1514c2 port a few more bug fix patches to Xbox 2026-02-28 20:49:19 -08:00
Martin Michelsen a649a4a146 add WIP Xbox BugFixes patch
Docker / Build (push) Has been cancelled
2026-02-26 21:47:53 -08:00
Martin Michelsen 7e21d8a9a1 enable color codes in info-board proxy shell command 2026-02-26 21:47:31 -08:00
Martin Michelsen c0fc3014cf move C9 comment 2026-02-22 20:33:02 -08:00
Martin Michelsen 08dff98948 fix Influence assist effect 2026-02-22 07:36:11 -08:00
Martin Michelsen d1c1228308 track hits from TargetEntry commands instead of 6x0A 2026-02-16 20:44:21 -08:00
Martin Michelsen b5fd58722b delete bank file when creating new character 2026-02-16 20:39:20 -08:00
Martin Michelsen f0e8e35e2b fix typos in error messages 2026-02-16 20:20:11 -08:00
Martin Michelsen 68b495b4b4 make --restrict-room floor-specific 2026-02-15 10:50:16 -08:00
Martin Michelsen 1e459edfc4 add --restrict-room in random enemy optimizer 2026-02-15 08:32:27 -08:00
Martin Michelsen c6d7025f43 add more debug info to EXP computation 2026-02-15 08:31:59 -08:00
Martin Michelsen ccf4b723f5 add --pessimize option in optimize-materialized-map 2026-02-14 19:58:54 -08:00
Martin Michelsen 8717f00106 add param filtering in materialize optimizer 2026-02-12 21:37:33 -08:00
Martin Michelsen 99630c999d add optimize-materialized-map 2026-02-12 21:12:57 -08:00
Martin Michelsen e8c262223b simplify Ep3 spectator join logic 2026-02-09 21:20:22 -08:00
Martin Michelsen 3d7215d591 add only command in address translator 2026-02-09 21:20:11 -08:00
Martin Michelsen ba48236200 add 2OJ4 2026-02-09 21:19:44 -08:00
Martin Michelsen 8065300fae replace item names with IDs in config.json 2026-02-07 22:34:45 -08:00
Martin Michelsen e9dfa5d1de fail on unknown quest directives 2026-02-05 19:58:57 -08:00
Martin Michelsen d38be2f360 add default4 BB key 2026-02-05 19:58:57 -08:00
Martin Michelsen 2429c4d341 add decoder/encoder for AdEnding.rel 2026-02-01 17:32:04 -08:00
Martin Michelsen ef2d9fae03 add qdefault codes in ar-codes.txt 2026-02-01 16:38:41 -08:00
Martin Michelsen 7016d65313 make gsl commands easier to use 2026-01-27 20:01:50 -08:00
Martin Michelsen bdd066edb2 fix notes for npc_param regsA[2] 2026-01-18 22:53:39 -08:00
Martin Michelsen 1bd305d4e7 add client function for debugging movement data 2026-01-14 22:06:06 -08:00
Martin Michelsen 890014b223 add findings from first pass on movement data 2026-01-12 22:03:37 -08:00
Martin Michelsen e4ef96fcc5 add inventory debugging AR code 2026-01-12 22:03:37 -08:00
Martin Michelsen 641b3a7bef fix formatting in proxy handler table 2026-01-12 22:03:37 -08:00
Martin Michelsen 6f9f684cc9 add AR code to disable CCA dust 2026-01-05 10:06:20 -08:00
Martin Michelsen 2602196279 make downloading a quest not end the proxy session 2026-01-05 00:12:37 -08:00
Martin Michelsen ec16cb0ae3 rename fields in battle param structs 2026-01-04 21:08:38 -08:00
Martin Michelsen 6da7b26c9f add comment about common table JSON formats 2026-01-04 10:51:18 -08:00
Martin Michelsen 8663e6682a slightly more fanciness in AccurateKillCount patch 2026-01-04 10:07:06 -08:00
Martin Michelsen 9b14e5d400 don't let SuperMap's edit-distance allow subtypes of the same base_type to merge 2026-01-04 10:07:06 -08:00
Martin Michelsen a1e067cc52 add a few learnings from enemy RE 2026-01-04 10:07:06 -08:00
Martin Michelsen a469b4355e add option to change chat command character 2026-01-04 00:59:39 -08:00
Martin Michelsen 4aa206bd4b add all BP indexes and fix incorrect RT indexes 2026-01-04 00:59:39 -08:00
Martin Michelsen d9540ba414 add comment about game section ID changes 2026-01-01 11:14:27 -08:00
Martin Michelsen cb7c45ef27 reformat ItemCreator.cc 2026-01-01 11:14:17 -08:00
Martin Michelsen f98db20618 implement BB system, guild card, and stream files in proxy save files option 2026-01-01 10:58:47 -08:00
Martin Michelsen 8fbf2246e6 fix change_event applying when it shouldn't on BB 2026-01-01 10:58:47 -08:00
Martin Michelsen 6b1726c1b5 add $savefiles command 2026-01-01 10:58:47 -08:00
Martin Michelsen cac61e6763 add ability to delay $item until next drop on proxy 2026-01-01 10:58:47 -08:00
Martin Michelsen 227e88f906 add warning about ItemPT/RT not reloading at quest start 2025-12-30 21:17:38 -08:00
Martin Michelsen 7ab3175f80 make quest item exchange implementations more complete 2025-12-26 19:54:22 -08:00
Martin Michelsen cd0d13e98c update notes on 0122 command 2025-12-26 09:44:44 -08:00
Martin Michelsen 8eeb487bc7 make item data stack count consistent with bank item stack count at load time 2025-12-25 23:21:32 -08:00
Martin Michelsen d79d551c68 fix Momoka item exchange via menu object 2025-12-25 22:19:54 -08:00
Martin Michelsen 4b43333ce9 fix data race between save timer and client disconnect 2025-12-25 22:19:35 -08:00
Martin Michelsen b228ea847f show enemy type on proxy if debug and fast kills are both on 2025-12-25 14:58:47 -08:00
Martin Michelsen 4d97bdec7f fix type in compute_all_valid_primary_identifiers 2025-12-25 14:57:41 -08:00
Martin Michelsen 8133b20598 add battle param reload bugfix 2025-12-23 09:09:49 -08:00
Martin Michelsen 73ced9d229 print bank when team reward is given 2025-12-23 09:09:38 -08:00
Martin Michelsen 6e765fe1ed clarify comment in PSOV2Encryption::single 2025-12-23 09:09:20 -08:00
Martin Michelsen 26f9b90ef8 fix line numbers around .only_versions 2025-12-23 09:08:51 -08:00
Martin Michelsen 668c687d68 remove unused argument 2025-12-22 00:46:56 -08:00
Martin Michelsen 87b048dc15 implement PSOV2Encryption::single 2025-12-22 00:14:22 -08:00
Martin Michelsen ea23f18aa2 use amount in 6xCC handler 2025-12-21 21:22:28 -08:00
Martin Michelsen a0a7231d67 reformat remaining files 2025-12-21 21:15:49 -08:00
Martin Michelsen e5a03b7e9b move weights sum out of loops in materialize_random_sections 2025-12-21 14:58:10 -08:00
Martin Michelsen a013b8c9d3 reformat more files 2025-12-21 14:57:53 -08:00
Martin Michelsen 894ac6b8ff reformat more files; add Ep3 map endpoint in HTTP server 2025-12-21 10:35:41 -08:00
Martin Michelsen a462a774f5 reformat more files 2025-12-20 21:55:32 -08:00
Martin Michelsen a9fa138213 add MapFile::serialize 2025-12-20 18:52:45 -08:00
Martin Michelsen 0a4c9a0a61 document sorted restriction on random enemy room entries 2025-12-19 21:44:55 -08:00
Martin Michelsen f99bba67d0 update TObjAreaWarpQuest notes 2025-12-19 01:14:14 -08:00
Martin Michelsen 849cca37c8 add explanation in expr field in cards.html 2025-12-19 00:11:09 -08:00
Martin Michelsen 9ebaaacd46 reformat DCSerialNumbers 2025-12-19 00:10:36 -08:00
Martin Michelsen c1968dad27 document TObjRoomId 2025-12-17 23:49:09 -08:00
Martin Michelsen 2732f9c9f8 document materialize-map command 2025-12-17 23:48:00 -08:00
Martin Michelsen 1bd2e6cf62 add challenge location limit override patch 2025-12-12 14:51:43 -08:00
Martin Michelsen 1ab7a851be simulate arithmetic opcodes in quest script analysis 2025-12-11 00:20:55 -08:00
Martin Michelsen 342b4df8c4 add action for debugging random enemy sections 2025-12-11 00:20:39 -08:00
Martin Michelsen 8953ffc2b5 add slow gibbles fix code 2025-12-08 20:10:15 -08:00
Martin Michelsen af796a418a add another AR code 2025-12-08 20:10:15 -08:00
Martin Michelsen 60203bdfba fix formatting in EnemyType.cc 2025-12-07 18:07:23 -08:00
Martin Michelsen 6677908354 reformat Map.cc/hh 2025-12-07 16:44:08 -08:00
Martin Michelsen 96079700f7 fix SetDataTable formatting 2025-12-06 22:05:35 -08:00
Martin Michelsen 976a281e93 update formatting in src/Episode3 2025-12-06 00:18:53 -08:00
Martin Michelsen 6291e42ba9 make 04E8 handler match the client's logic 2025-12-05 19:53:09 -08:00
Martin Michelsen a89423e9f5 reformat CommandFormats and DataIndexes 2025-12-05 19:52:49 -08:00
Martin Michelsen 81169ba9d3 add lobby arrow AR codes 2025-12-05 19:51:58 -08:00
Martin Michelsen e715a8461a fix comment in EnableRandomEnemies include 2025-12-05 15:39:34 -08:00
Martin Michelsen 1ee6b21398 add warning if random enemy location count is too large 2025-12-05 15:39:25 -08:00
Martin Michelsen 9524020aaa improve disassembly for random enemy sections 2025-12-03 21:49:44 -08:00
Martin Michelsen 194bb5b393 actually enforce NOCOMMIT tags finally 2025-12-02 21:46:58 -08:00
Martin Michelsen 779ec9df3b add EnableRandomEnemies include 2025-12-02 21:07:47 -08:00
Martin Michelsen 82ed175a5c add param5 note for TObjCityMapWarp 2025-12-02 00:03:57 -08:00
Martin Michelsen 68f96129fe remove stray debug print 2025-12-02 00:03:31 -08:00
Martin Michelsen c482324a97 use area instead of floor during map construction 2025-11-30 23:12:55 -08:00
Martin Michelsen 800c70c401 skip non-BB clients in 6xC8 handler 2025-11-30 17:31:13 -08:00
Martin Michelsen f26c543977 handle extra data after quest label table 2025-11-30 11:56:20 -08:00
Martin Michelsen 23e31749e9 add transcode-text action 2025-11-30 11:56:20 -08:00
Martin Michelsen ad91b6f6b7 update some boss command notes 2025-11-30 08:50:11 -08:00
Martin Michelsen 2c333b51d2 add $fastkill command 2025-11-29 12:12:34 -08:00
Martin Michelsen 80f8ee1b09 fix flags in Account::str 2025-11-29 09:47:36 -08:00
Martin Michelsen 1498a6e68d fix meta.quest_number check 2025-11-28 15:02:28 -08:00
Martin Michelsen 1fc313505a use test config for quest compiler test 2025-11-28 14:47:51 -08:00
Martin Michelsen 435ac82c18 define most of the remining fields in BB extended quest header 2025-11-28 14:36:13 -08:00
Martin Michelsen 7ec267a7c0 fix solo quest unlock flags 2025-11-28 14:22:16 -08:00
Martin Michelsen 81293255b5 fix more quest metadata 2025-11-28 14:22:07 -08:00
Martin Michelsen 4fe225a302 fix multiple bugs in quest assembler 2025-11-28 12:41:42 -08:00
Martin Michelsen 3ef91b0159 allow whitespace in create item masks 2025-11-28 12:41:42 -08:00
Martin Michelsen e02a006b60 add support for cross-episode quests 2025-11-28 12:40:14 -08:00
Martin Michelsen 23eb6b29a5 fix metadata on more quests 2025-11-28 12:33:28 -08:00
Martin Michelsen afe48e7034 ignore .dec files 2025-11-27 21:06:00 -08:00
Martin Michelsen bd1cdfdb97 further improve quest assembler/disassembler matching 2025-11-26 23:06:04 -08:00
Martin Michelsen a783177420 rewrite quest disassembler for better consistency with assembler 2025-11-25 23:41:46 -08:00
Martin Michelsen 9d42f849c5 fix metadata in solo quest headers 2025-11-25 23:26:24 -08:00
Martin Michelsen 566de06fd1 rewrite quest disassembler 2025-11-24 01:03:24 -08:00
Martin Michelsen 474ad99396 document how wave events work 2025-11-23 17:35:52 -08:00
Martin Michelsen b53847d1b5 update .gitignore 2025-11-23 17:35:38 -08:00
Martin Michelsen d827c1bf5d fix random enemy definitions count check; closes #723 2025-11-20 08:31:43 -08:00
Martin Michelsen 886daa5880 add .evt to patch instructions in readme 2025-11-20 08:29:50 -08:00
Martin Michelsen cc72092b05 write 59NJ version of MomokaItemExchangeFix 2025-11-19 22:27:26 -08:00
Martin Michelsen c6f74e74c4 hide other players' EXP values in ServerEXPDisplay
Docker / Build (push) Has been cancelled
2025-11-18 17:29:22 -08:00
Martin Michelsen 328980628a fix $edit level 2025-11-18 17:28:48 -08:00
Martin Michelsen 886e9b9f4f fix 5% payment type in 6xDA 2025-11-18 10:27:31 -08:00
Martin Michelsen 26d2ae416e delete unused arguments 2025-11-16 22:37:13 -08:00
Martin Michelsen 62c4c82fcc rewrite HTTP interface 2025-11-16 15:09:28 -08:00
Martin Michelsen 11cc19fe3e update last player name when sending E7; closes #706 2025-11-16 11:01:06 -08:00
Martin Michelsen d1d045a70e fix rare enemy rate inheritance; closes #719 2025-11-16 10:56:39 -08:00
Martin Michelsen 54c790a63c fix notes on get_slot_meseta 2025-11-16 10:48:02 -08:00
Martin Michelsen f1f5c1036a fix invalid range check 2025-11-16 00:05:47 -08:00
Martin Michelsen 77d5436b15 implement quest item creation masks 2025-11-15 23:54:49 -08:00
Martin Michelsen 678c60dd14 update some notes; fix quest assembler bugs 2025-11-15 22:36:18 -08:00
Martin Michelsen d40d231584 add some new AR codes 2025-11-14 19:13:15 -08:00
Martin Michelsen 00ddff7e46 update notes on loading into games/lobbies 2025-11-14 19:13:15 -08:00
Blst34 5725af0f6b Add files via upload 2025-11-12 19:55:11 -08:00
Martin Michelsen 87248e7e67 fix enemy alias lookup logic 2025-11-11 00:04:55 -08:00
Martin Michelsen 712cfc9ac4 fix JSON common table parser 2025-11-10 22:56:23 -08:00
Martin Michelsen 1d8befde8e add fix for TJS rapid-switch crash on GC 2025-11-09 18:01:57 -08:00
Martin Michelsen fb036cda37 fix null pointer dereference in episode 4 free play; closes #717 2025-11-09 16:01:10 -08:00
Martin Michelsen 136e2730de rename Ep4 test door 2025-11-09 16:00:41 -08:00
Martin Michelsen ae47d92016 update notes on delayed_switch_episode 2025-11-08 10:30:39 -08:00
Martin Michelsen b80ed0021b add method to override enemy EXP in quests 2025-11-07 22:53:36 -08:00
Martin Michelsen 1d11879142 demote IPSS unhandled frames to debug logs; closes #713 2025-11-07 21:10:40 -08:00
Martin Michelsen a122b27b1f don't use client's floor for 6x0A and 6x0B 2025-11-07 21:02:08 -08:00
Martin Michelsen cbba724ba1 add pause menu UI code 2025-11-07 20:25:42 -08:00
Martin Michelsen 2c51571ea4 add some misc codes 2025-11-07 14:28:21 -08:00
Martin Michelsen e1d774ce49 fix quest name in HTTP API; closes #714 2025-11-07 11:01:43 -08:00
Martin Michelsen b9e3973c76 document specialized item box format 2025-11-06 22:47:07 -08:00
Martin Michelsen c878093c5f ignore map_designate, etc. if floor number isn't valid 2025-11-06 21:18:42 -08:00
Martin Michelsen 7210441878 allow 6x17 for enemies and objects 2025-11-05 23:06:17 -08:00
Martin Michelsen 36eeee5641 clean up character load function 2025-11-05 22:29:43 -08:00
Martin Michelsen 8d2ffba3e1 add unit specific modifiers 2025-11-05 22:29:18 -08:00
Martin Michelsen 766d4e0c7a fix many edge cases in item name parsing 2025-11-05 21:45:15 -08:00
Martin Michelsen a99f552e7c fix synchro description in mag creation 2025-11-05 19:14:37 -08:00
Martin Michelsen 540a41a583 add Ep3 battle replay test 2025-11-05 09:02:22 -08:00
Martin Michelsen 8cb7d2b2fe fix $playrec behavior 2025-11-04 09:12:48 -08:00
Martin Michelsen 293f25d579 add print-free-supermap 2025-11-04 09:12:40 -08:00
Martin Michelsen 64763e76af fix floor tracking on $exit 2025-11-04 09:12:27 -08:00
Martin Michelsen 69b7e7f998 more object notes 2025-11-02 22:38:02 -08:00
Martin Michelsen 5579bce5d9 delete proxy_session_id 2025-11-02 20:40:30 -08:00
Martin Michelsen 0dd5e2ac10 use bit_cast now that resource_dasm is required 2025-11-02 18:19:06 -08:00
Martin Michelsen 155ed6bcf9 add $makeobj; update some object notes 2025-11-02 17:14:38 -08:00
Martin Michelsen 4e2f62bc73 update notes on TObjDoor 2025-10-30 10:07:56 -07:00
Martin Michelsen bf36a185a2 document TContainerAncient01 2025-10-29 21:27:15 -07:00
Martin Michelsen 4c4c54c536 document TOSparkMachine01 2025-10-29 19:50:09 -07:00
Martin Michelsen e79e6944df update more object notes 2025-10-29 10:27:48 -07:00
Martin Michelsen f6079e3078 update notes for TOSensorAncient01 2025-10-29 10:11:01 -07:00
Martin Michelsen 31b49a71fb add fast tekker patch 2025-10-28 22:35:38 -07:00
Martin Michelsen 83260d5037 fix $sound in lobby 2025-10-28 22:24:38 -07:00
Martin Michelsen 648da83aa1 add new patch file 2025-10-28 10:00:43 -07:00
Martin Michelsen adf1db92c7 fix Ep3 quest download test 2025-10-28 09:50:07 -07:00
Martin Michelsen 662ee48a64 add patch to show EXP gains from the server 2025-10-28 09:50:07 -07:00
Martin Michelsen 446b521898 fix player levels on HTTP server 2025-10-27 22:20:22 -07:00
Martin Michelsen d6db731149 fix uninitialized memory in IPStackSimulator 2025-10-27 22:20:14 -07:00
Martin Michelsen 9106a11be8 add test for Ep3 download quests and map loader 2025-10-27 22:19:58 -07:00
Martin Michelsen 7bc58a757e reimplement Episode 3 map categories 2025-10-26 23:07:47 -07:00
Martin Michelsen 27b5556e4b fix EnemyDamageSync crash on Xbox at connect time 2025-10-26 21:13:20 -07:00
Martin Michelsen b39b4197ed add 59NJ version of CallProtectedHandler 2025-10-25 22:15:06 -07:00
Martin Michelsen a99647d4c7 fix two off-parity offsets in BankSize patch 2025-10-25 21:57:03 -07:00
Repflez 10a6bafb2f Add 59NJ version of BankSize function 2025-10-25 21:57:03 -07:00
Martin Michelsen b4f7688b82 add some new AR codes 2025-10-22 23:41:41 -07:00
Martin Michelsen 08e6b882f3 fix incorrect game metadata logic in proxy
update
2025-10-22 23:30:26 -07:00
Martin Michelsen 4adc174674 merge Ep3 tables in handler-tables 2025-10-22 23:30:26 -07:00
Martin Michelsen 01b1f42bac add some Ep3 command notes 2025-10-22 19:47:23 -07:00
Martin Michelsen be4c7f80cb add tests for quest indexes and function compiler 2025-10-21 22:54:48 -07:00
Martin Michelsen 790363adb5 clean up some patches 2025-10-20 23:11:18 -07:00
Martin Michelsen 09b96a4a86 add BB-DR in handler-tables 2025-10-18 01:03:00 -07:00
Martin Michelsen 6ffa656ad4 implement Hunters Report item behavior 2025-10-18 01:03:00 -07:00
Martin Michelsen 3f2df68ac5 fix flags check on Xbox EnemyDamageSync 2025-10-18 01:03:00 -07:00
Martin Michelsen a7f2ecefe5 don't use under-stack space in EnemyDamageSync 2025-10-18 01:03:00 -07:00
Martin Michelsen 46c2260d0f use enums for difficulty and language; fix enemy state aliases; closes #694 2025-10-18 01:03:00 -07:00
Martin Michelsen 052dcf8c6e update 6xB6 notes 2025-10-18 01:03:00 -07:00
Martin Michelsen cd5863fcde fix $edit for names with spaces 2025-10-18 01:03:00 -07:00
Martin Michelsen 90de571457 document contents of BugFixes patch 2025-10-18 01:03:00 -07:00
Martin Michelsen d9d33c2d65 add patch downloader 2025-10-18 01:03:00 -07:00
Repflez 09962696b7 Assemble the fleti instruction properly 2025-10-17 08:47:04 -07:00
Martin Michelsen d143cbb461 document GC RareItemNotifications patch 2025-10-12 09:48:09 -07:00
Martin Michelsen db7f7abfc4 update HTML drop table notes in command info 2025-10-12 09:48:09 -07:00
Martin Michelsen 6ba92d3a7a skip EXP computation for Level 200 characters 2025-10-12 09:48:09 -07:00
Martin Michelsen 36a1e0dfae fix common tables on GC NTE 2025-10-12 09:48:09 -07:00
Martin Michelsen 47f7e71ae9 display quest names in client's native language in game info window 2025-10-12 09:48:09 -07:00
Martin Michelsen c2008f1f9c handle Ep1&2 NTE protected commands properly 2025-10-12 09:48:09 -07:00
Martin Michelsen 3c32a66064 hide section ID for empty persistent games 2025-10-12 09:48:09 -07:00
Martin Michelsen 41026fbd93 add ep3 auction code 2025-10-12 09:48:09 -07:00
nolrinale d49750aa02 Added missing Coren map files 2025-10-10 21:26:57 -07:00
Martin Michelsen 54f309030e fix exact rate hint in drop tables 2025-10-08 21:37:30 -07:00
Martin Michelsen 093c25fce4 include DAR in generated drop tables 2025-10-08 21:29:55 -07:00
Martin Michelsen a777dc8236 make AsyncEvent resumption faster 2025-10-08 21:29:36 -07:00
Martin Michelsen 4044e4e5a6 fix battle table + $exit edge case 2025-10-05 20:38:44 -07:00
Martin Michelsen 036b4e9456 assign a specific_version for PC NTE 2025-10-05 11:27:59 -07:00
Martin Michelsen 4074530a71 disable EXP share during battle and challenge quests 2025-10-05 11:02:56 -07:00
Martin Michelsen 31eedd7e7e work around 6xD9 client bug 2025-10-05 10:49:07 -07:00
Martin Michelsen df2dfd21e3 fix 88 command during loading on proxy 2025-10-05 10:49:07 -07:00
Martin Michelsen 00b0f71bf4 update some notes 2025-10-05 10:47:20 -07:00
Martin Michelsen 1450a5acd3 allow 6x25 to overwrite slots on all versions 2025-10-04 09:55:00 -07:00
Martin Michelsen 2a138ea0b6 update some command notes 2025-10-04 09:54:37 -07:00
Martin Michelsen 2534ff37de fix potential race in socket closure 2025-10-04 09:54:21 -07:00
Martin Michelsen d61cb1106d allow $unset to remove assist cards too 2025-10-04 09:53:26 -07:00
Martin Michelsen d5f0c6aceb fix shared bank creation 2025-10-03 08:41:45 -07:00
1571 changed files with 284638 additions and 37751 deletions
+25 -12
View File
@@ -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
+25 -20
View File
@@ -50,6 +50,8 @@ add_custom_target(
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc
src/Account.cc
src/AccountSync.cc
src/TeamSync.cc
src/AddressTranslator.cc
src/AFSArchive.cc
src/AsyncHTTPServer.cc
@@ -60,10 +62,14 @@ set(SOURCES
src/ChatCommands.cc
src/ChoiceSearch.cc
src/Client.cc
src/ClientFunctionIndex.cc
src/CommandCensorData.cc
src/CommonItemSet.cc
src/Compression.cc
src/DCSerialNumbers.cc
src/DNSServer.cc
src/DOLFileIndex.cc
src/DataIndex.cc
src/DownloadSession.cc
src/EnemyType.cc
src/Episode3/AssistServer.cc
@@ -78,8 +84,6 @@ set(SOURCES
src/Episode3/RulerServer.cc
src/Episode3/Server.cc
src/Episode3/Tournament.cc
src/FileContentsCache.cc
src/FunctionCompiler.cc
src/GameServer.cc
src/GSLArchive.cc
src/HTTPServer.cc
@@ -97,10 +101,12 @@ set(SOURCES
src/LevelTable.cc
src/Lobby.cc
src/Loggers.cc
src/MagMetadataTable.cc
src/Main.cc
src/Map.cc
src/Menu.cc
src/NetworkAddresses.cc
src/PatchDownloadSession.cc
src/PatchFileIndex.cc
src/PlayerInventory.cc
src/PlayerSubordinates.cc
@@ -122,9 +128,11 @@ set(SOURCES
src/ServerShell.cc
src/ServerState.cc
src/ShellCommands.cc
src/ShopRandomSets.cc
src/SignalWatcher.cc
src/StaticGameData.cc
src/TeamIndex.cc
src/TekkerAdjustmentSet.cc
src/Text.cc
src/TextIndex.cc
src/Version.cc
@@ -133,11 +141,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)
@@ -150,23 +159,19 @@ add_dependencies(newserv newserv-Revision-cc)
enable_testing()
file(GLOB LogTestCases ${CMAKE_SOURCE_DIR}/tests/*.test.txt)
file(GLOB LogRDTestCases ${CMAKE_SOURCE_DIR}/tests/*.rdtest.txt)
file(GLOB LOG_TEST_CASES ${CMAKE_SOURCE_DIR}/tests/*.test.txt)
list(TRANSFORM LOG_TEST_CASES PREPEND "--replay-log=" OUTPUT_VARIABLE LOG_REPLAY_ARGS)
add_test(
NAME "log-replays"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_BINARY_DIR}/newserv --parallel --config=${CMAKE_SOURCE_DIR}/tests/config.json ${LOG_REPLAY_ARGS})
foreach(LogTestCase IN ITEMS ${LogTestCases})
file(GLOB SCRIPT_TEST_CASES ${CMAKE_SOURCE_DIR}/tests/*.test.sh)
foreach(SCRIPT_TEST_CASE IN ITEMS ${SCRIPT_TEST_CASES})
add_test(
NAME ${LogTestCase}
NAME ${SCRIPT_TEST_CASE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_BINARY_DIR}/newserv --replay-log=${LogTestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json)
endforeach()
file(GLOB ScriptTestCases ${CMAKE_SOURCE_DIR}/tests/*.test.sh)
foreach(ScriptTestCase IN ITEMS ${ScriptTestCases})
add_test(
NAME ${ScriptTestCase}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${ScriptTestCase} ${CMAKE_BINARY_DIR}/newserv)
COMMAND ${SCRIPT_TEST_CASE} ${CMAKE_BINARY_DIR}/newserv)
endforeach()
+17 -894
View File
@@ -1,907 +1,30 @@
# newserv <img align="right" src="static/s-newserv.png" />
# psopeeps-newserv
PSO Peeps is a private multi-platform Phantasy Star Online server supporting DC V2, PC V2, GC V3, and Blue Burst. Our ships feature XP boosts, optional experimental crossplay between all versions, increased difficulty tiers, and a hardcore mode.
This is the PSO Peeps maintained version of [newserv](https://github.com/fuzziqersoftware/newserv), a game server, proxy, and reverse-engineering tool for Phantasy Star Online.
newserv is a game server, proxy, and reverse-engineering tool for Phantasy Star Online (PSO). **To quickly get started using newserv, just read the [server setup](#server-setup) and [how to connect](#how-to-connect) sections.**
The original project was created by fuzziqersoftware and contains years of reverse-engineering, documentation, and implementation work for PSO. This repository keeps that work as the foundation while carrying local changes used by PSO Peeps.
This project includes code that was reverse-engineered by the community in ages long past, and has been included in many projects since then. It also includes some game data from Phantasy Star Online itself, which was originally created by Sega.
For the original upstream project, see:
Feel free to submit GitHub issues if you find bugs or have feature requests. I'd like to make the server as stable and complete as possible, but I can't promise that I'll respond to issues in a timely manner, because this is a personal project undertaken primarily for the fun of reverse-engineering. If you want to contribute to newserv yourself, pull requests are welcome as well.
https://github.com/fuzziqersoftware/newserv
See TODO.md for a list of known issues and future work I've curated, or go to the GitHub issue tracker for issues and requests submitted by the community.
## About this repository
**Table of contents**
* Background
* [History](#history)
* [Other server projects](#other-server-projects)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [Contributing to newserv](#contributing-to-newserv)
* [Compatibility](#compatibility)
* Setup
* [Server setup](#server-setup)
* [Client patch directories for PC and BB](#client-patch-directories)
* [How to connect](#how-to-connect)
* Features and configuration
* [User accounts](#user-accounts)
* [Installing quests](#installing-quests)
* [Item tables and drop modes](#item-tables-and-drop-modes)
* [Cross-version play](#cross-version-play)
* [Server-side saves](#server-side-saves)
* [Episode 3 features](#episode-3-features)
* [Memory patches, client functions, and DOL files](#memory-patches-and-client-functions)
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
* [Chat commands](#chat-commands)
* [REST API](#rest-api)
* [Non-server features](#non-server-features)
This repository is used for PSO Peeps server development and deployment. Changes here may include server configuration support, compatibility fixes, event behavior, gameplay experiments, operational tooling, and other changes specific to PSO Peeps.
# History
Some changes may not be appropriate for upstream newserv or for general newserv deployments.
The history of this project essentially mirrors my development as a software engineer from the beginning of my hobby until now. If you don't care about the story, skip to the "Compatibility" or "Setup" sections below.
## Original README
I originally purchased PSO GC when I heard about PSUL, and wanted to play around with running homebrew on my GameCube. This pathway eventually led to [GCARS-CS](https://github.com/fuzziqersoftware/gcars-cs), but that's another story.
A copy of the upstream README is preserved here:
<img align="left" src="static/s-khyps.png" /> After playing PSO for a while, both offline and online, I wrote a proxy called Khyps sometime in 2003. This was back in the days of the official Sega servers, where vulnerabilities weren't addressed in a timely manner or at all. It was common for malicious players using their own proxies or Action Replay codes (a story for another time) to send invalid commands that the servers would blindly forward, and cause the receiving clients to crash. These crashes were more than simply inconvenient; they could also corrupt your save data, destroying the hours of work you may have put into hunting items and leveling up your character.
[docs/upstream-README.md](docs/upstream-README.md)
For a while it was essentially necessary to use a proxy to go online at all, so the proxy could block these invalid commands. Khyps was designed primarily with this function in mind, though it also implemented some convenient cheats, like the ability to give yourself or other players infinite HP and allow you to teleport to different places without using an in-game teleporter.
That document contains the original newserv history, setup notes, compatibility information, connection instructions, feature documentation, and technical reference material.
<img align="left" src="static/s-khyller.png" /> After Khyps I took on the larger challenge of writing a server, which resulted in Khyller sometime in 2005. This was the first server of any type I had ever written. This project eventually evolved into a full-featured environment supporting all versions of the game that I had access to - at the time, PC, GC, and BB. (However, I suspect from reading the ancient source files that Khyller's BB support was very buggy.) As Khyller evolved, the code became increasingly cumbersome, littered with debugging filth that I never cleaned up and odd coding patterns I had picked up over the years. My understanding of the C++ language was woefully incomplete as well (as opposed to now, when it is still incomplete but not woefully so), which resulted in Khyller being essentially a C project that had a couple of classes in it.
## License and attribution
<img align="left" src="static/s-aeon.png" /> Sometime in 2006 or 2007, I abandoned Khyller and rebuilt the entire thing from scratch, resulting in Aeon. Aeon was substantially cleaner in code than Khyller but still fairly hard to work with, and it lacked a few of the more arcane features I had originally written (for example, the ability to convert any quest into a download quest). In addition, the code still had some stability problems... it turns out that Aeon's concurrency primitives were simply incorrect. I had derived the concept of a mutex myself, before taking any real computer engineering classes, but had implemented it incorrectly. I made the race window as small as possible, but Aeon would still randomly crash after running seemingly fine for a few days.
This project remains based on newserv by fuzziqersoftware.
At the time of its inception, Aeon was also called newserv, and you may find some beta releases floating around the Internet with filenames like `newserv-b3.zip`. I had released betas 1, 2, and 3 before I released the entire source of beta 5 and stopped working on the project when I went to college. This was around the time when I switched from writing software primarily on Windows to primarily on macOS and Linux, so Aeon beta 5 was the last server I wrote that specifically targeted Windows. (newserv, which you're looking at now, is difficult to compile on Windows but does work.)
<img align="left" src="static/s-newserv.png" /> After a long hiatus from PSO and much professional and personal development in my technical abilities, I was reminiscing sometime in October 2018 by reading my old code archives. Somehow inspired when I came across Aeon, I spent a weekend and a couple more evenings rewriting the entire project again, cleaning up ancient patterns I had used eleven years ago, replacing entire modules with simple STL containers, and eliminating even more support files in favor of configuration autodetection. The code is now suitably modern and stable, and I'm not embarrassed by its existence, as I am by Aeon beta 5's source code and my archive of Khyller (which, thankfully, no one else ever saw).
## Other server projects
Independently of this project, there are many other PSO servers out there. Those that I know of that are (or were) public are listed here in approximate chronological order:
* (Early 2000s) **[Schtserv](https://schtserv.com/)**: The first public-access PSO server, written in Delphi by Schthack. Schtserv is the only other unofficial server to support Episode 3, their implementation of which is based on newserv's (which is based on Sega's).
* (2005) **Khyller**: An early attempt of mine to support PSO PC, GC, and BB. See above for more details.
* (2006) **Aeon**: My second attempt. Better than Khyller, but still unreliable.
* (2008) **Tethealla**: A fairly extensive implementation of PSOBB, written in C by Sodaboy. The public version of Tethealla has been [officially disowned](https://www.pioneer2.net/community/threads/tethealla-server-forums-removal.26365/) as it is now more than 15 years old, but closed-source development continues. [Ephinea](https://ephinea.pioneer2.net/) is the continuation of this project. Several other modern PSOBB servers are forks of the initial public version of Tethealla as well.
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server, written in C by BlueCrab.
* (2015) **[Archon](https://github.com/dcrodman/archon)**: A PSOBB server written in Go by Drew Rodman.
* (2015) **[Idola](https://github.com/HybridEidolon/idolapsoserv)**: A PSOBB server written in Rust by HybridEidolon. Functionality status unknown; the project has been archived.
* (2017) **[Aselia](https://github.com/Solybum/Aselia)**: A PSOBB server written in C# by Soly. It seems this was planned to be open-source at some point, but that has not (yet) happened.
* (2018) **newserv**: This project right here.
* (2019) **[Mechonis](https://gitlab.com/sora3087/mechonis)**: A PSOBB server with a microservice architecture written in TypeScript by TrueVision.
* (2020) **[Booma.Server](https://github.com/HelloKitty/Booma.Server)**: A PSOBB server written in C# by Glader, with Soly's help.
* (2021) **[Phantasmal World](https://github.com/DaanVandenBosch/phantasmal-world)**: A set of PSO tools, including a web-based model viewer and quest builder, and a PSO server, written by Daan Vanden Bosch.
* (2021) **[Elseware](http://git.sharnoth.com/jake/elseware)**: A PSOBB server written in Rust by Jake.
## Using newserv in other projects
You are free to use code from newserv in your own open-source projects; the only condition is that the contents of the LICENSE file must be included in your project if you use code from newserv. Your project does not also have to use the MIT license; you can use any license you want.
If you want to use parts of newserv in your project, there are two easy ways to do so with proper licensing:
* If you're using a lot of code from newserv, you can put a copy of newserv's LICENSE file in your repository alongside your own license file, or include the contents of newserv's license in your own license file.
* If you're only using a few files from newserv, you can copy and paste the contents of the LICENSE file into a comment at the beginning of each copied file.
Some of the more likely useful files are:
* **src/CommandFormats.hh**: Complete listing of all network commands used in all known versions of the game, and their formats
* **src/CommonItemSet.hh/cc**: Format of ItemPT files, shop definition files, and tekker adjustment tables
* **src/DCSerialNumbers.hh/cc**: PSO DC serial number validation algorithm and serial number generator
* **src/ItemData.hh**: Item format reference
* **src/ItemCreator.hh/cc**: Reverse-engineered item generator from Episodes 1&2 (used for all versions)
* **src/ItemParameterTable.hh**: Format of many structures in ItemPMT.prs
* **src/Map.hh/cc**: Map file (.dat) structure, 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
* **src/Episode3/DataIndexes.hh**: Episode 3 file structures, including card definition format and map/quest format
* **system/item-tables/names-v4.json**: Names of all items, indexed by the first 3 bytes of data1
## Contributing to newserv
The goals of this project are:
* Build stable, extensible PSO server software that includes all vanilla functionality as well as optional modern conveniences, features, and cheats.
* Document the internals of PSO's network protocol, file formats, and game mechanics. This is mainly done through comments in the code.
This is a personal project; there is no official development team, official website, or official instance of newserv. Issues and pull requests are certainly welcome, but please only add content (e.g. quests or patches) that you've created, is already public, or you have permission to release publicly.
# Compatibility
newserv supports all known versions of PSO, including various development prototypes. This table lists all versions that newserv supports. (NTE stands for Network Trial Edition; the GameCube beta versions were called Trial Edition instead, but we use the NTE abbreviation anyway for consistency.)
| Version | Lobbies | Games | Proxy |
|-----------------|----------|----------|----------|
| DC NTE | Yes | Yes | Yes |
| DC 11/2000 | Yes | Yes | Yes |
| DC 12/2000 | Yes | Yes | Yes |
| DC 01/2001 | Yes | Yes | Yes |
| DC V1 | Yes | Yes | Yes |
| DC 08/2001 | Yes | Yes | Yes |
| DC V2 | Yes | Yes | Yes |
| PC NTE | Yes (1) | Yes | Yes |
| PC | Yes | Yes | Yes |
| GC Ep1&2 NTE | Yes | Yes | Yes |
| GC Ep1&2 | Yes | Yes | Yes |
| GC Ep1&2 Plus | Yes | Yes | Yes |
| GC Ep3 NTE | Yes | Yes (2) | Yes |
| GC Ep3 | Yes | Yes | Yes |
| Xbox Ep1&2 Beta | Yes (3) | Yes (3) | Yes (3) |
| Xbox Ep1&2 | Yes (3) | Yes (3) | Yes (3) |
| BB (vanilla) | Yes | Yes | Yes |
| BB (Tethealla) | Yes | Yes | Yes |
*Notes:*
1. *This is the only version of PSO that doesn't have any way to identify the player's account - there is no serial number or username. For this reason, AllowUnregisteredUsers must be enabled in config.json to support PC NTE, and PC NTE players receive a random Guild Card number every time they connect. To prevent abuse, PC NTE support can be disabled in config.json.*
2. *Episode 3 NTE battles are not well-tested; some things may not work. See notes/ep3-nte-differences.txt for a list of known differences between NTE and the final version. NTE and non-NTE players cannot battle each other.*
3. *PSO Xbox connects through Xbox Live, so you can't easily host a private server for this version of the game. See the [How to connect](#pso-xbox) section.*
# Setup
## Server setup
Currently newserv works on macOS, Windows, and Ubuntu Linux. It will likely work on other Linux flavors too.
### Windows/macOS
1. Download the latest release.zip file from the [releases page](https://github.com/fuzziqersoftware/newserv/releases).
2. Extract the contents of the archive to some location on your computer.
3. Go into the system/ folder, open config.json in a text editor, and edit it to your liking. There are comments in the file that describe what all the options do. Most of the options can be left alone if you want default behavior, but on Windows, you must change LocalAddress and ExternalAddress.
4. (Optional) If you plan to play Blue Burst on newserv, set up the patch directory. See [client patch directories](#client-patch-directories) for details.
5. Run the newserv executable.
### Linux
There are currently no precompiled releases for Linux. To run newserv on Linux, you'll have to build it from source - see the section below.
### Building from source (macOS/Linux)
To build on macOS or Linux:
1. Install the dependencies needed for your platform:
* macOS: `brew install cmake asio libiconv`
* Linux: `sudo apt-get install cmake libasio-dev` (or use your Linux distribution's package manager)
2. Build and install [phosg](https://github.com/fuzziqersoftware/phosg) and [resource_dasm](https://github.com/fuzziqersoftware/resource_dasm).
3. Run `cmake . && make` in the newserv directory.
After building newserv, edit system/config.example.json as needed **and rename it to system/config.json** (note that this step is not necessary for the precompiled releases), set up [client patch directories](#client-patch-directories) if you're planning to play Blue Burst, then run `./newserv` in newserv's directory.
The server has an interactive shell which can be used to make changes, such as managing user accounts, updating the server's configuration, managing Episode 3 tournaments, and more. Type `help` and press Enter to see all the commands.
On Linux and macOS, the server also responds to SIGUSR1 and SIGUSR2. SIGUSR1 does the equivalent of the shell's `reload config` command, which reloads config.json but not any dependent files (so quests, Episode 3 maps, etc. will not be reloaded). SIGUSR2 does the equivalent of the shell's `reload all` command, which reloads everything.
To use newserv in other ways (e.g. for translating data), see the end of this document.
### Building from source (Windows)
The current version of newserv is cross-compiled using mingw-w64 on a macOS build machine, with the necessary libraries manually installed. Setting up such a build environment is tedious and not recommended; it's recommended to just use a release version instead.
Here is a rough outline of the Windows build process. You should only attempt this yourself if you're familiar with setting up build environments and can deal with issues you may encounter along the way.
1. Install recent versions of MinGW and CMake.
2. Build and install zlib, libiconv, asio, phosg, and resource_dasm into your MinGW environment.
3. Clone the newserv repository with symlinks enabled: `git clone -c core.symlinks=true https://github.com/fuzziqersoftware/newserv.git`
4. Build newserv via CMake.
## Client patch directories
newserv implements a patch server for PSO PC and PSO BB game data. Any file or directory you put in the system/patch-bb or system/patch-pc directories will be synced to clients when they connect to the patch server.
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`.
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.
For BB clients, newserv reads some files out of the patch data to implement game logic, so it's important that certain game files are synchronized between the server and the client. newserv contains defaults for these files in the system/maps/bb-v4 directory, but if these don't match the client's copies of the files, odd behavior will occur in games.
To make server startup faster, newserv caches the modification times, sizes, and checksums of the files in the patch directories. If the patch server appears to be misbehaving, try deleting the .metadata-cache.json file in the relevant patch directory to force newserv to recompute all the checksums. Also, in the case when checksums are cached, newserv may not actually load the data for a patch file until it's needed by a client. Therefore, modifying any part of the patch tree while newserv is running can cause clients to see an inconsistent view of it.
Patch directory contents are cached in memory. If you've changed any of these files, you can run `reload patch-indexes` in the interactive shell to make the changes take effect without restarting the server.
## How to connect
### PSO DC
Depending on the version of PSO DC that you have, the instructions to connect to a newserv instance will vary.
If you have NTE, USv1, EUv1, or EUv2 and a Broadband Adapter, edit the broadband DNS address to newserv's IP address with newserv's DNS server running. Otherwise, it is necessary to patch the disc or use a codebreaker code to remove the Hunter License server check and/or redirect PSO to the newserv instance. Patching the disc or creating a codebreaker code is beyond the scope of this document.
### PSO DC on Flycast
If you're emulating PSO DC, the NTE, USv1, EUv1, and EUv2 versions will connect to newserv by setting the following options in Flycast's `emu.cfg` file under `[network]`:
- DNS = Your newserv's server address (newserv's DNS server must be running on port 53)
- EmulateBBA = yes
- Enable = yes
It is also necessary to save any DNS information to the flash memory of the Dreamcast to use the BBA - the easiest way to do this is to use the website option in USv2 and then choose the save to flash option.
If the server is running on the same machine as Flycast, this might not work, even if you point Flycast's DNS queries at your local IP address (instead of 127.0.0.1). In this case, you can modify the loaded executable in memory to make it connect anywhere you want. There is a script included with newserv that can do this on macOS; a similar technique could be done manually using scanmem on Linux or Cheat Engine on Windows. To use the script, do this:
1. Build and install [memwatch](https://github.com/fuzziqersoftware/memwatch).
2. Start Flycast and run PSO. (You must start PSO before running the script; it won't work if you run the script before loading the game.)
3. Run `sudo patch_flycast_memory.py <original-destination>`. Replace `<original-destination>` with the hostname that PSO wants to connect to (you can find this out by using Wireshark and looking for DNS queries). The script may take up to a minute; you can continue using Flycast while it runs, but don't start an online game until the script is done.
4. Run newserv and start an online game in PSO.
If you use this method, you'll have to run the script every time you start PSO in Flycast, but you won't have to run it again if you start another online game without restarting emulation.
If using JPv1, JPv2, or USv2, it is also necessary to remove the Hunter Licence server check, either with a disc patch or codebreaker code. Patching the disc or creating a codebreaker code is beyond the scope of this document.
### PSO PC
PSO PC has its connection addresses in `pso.exe`. Hex edit the executable with the connection address you want to connect to. Common server addresses to search for to replace are:
- pso20.sonic.isao.net
- sg207634.sonicteam.com
- pso-mp01.sonic.isao.net
- gsproduc.ath.cx
- sylverant.net
The version of PSO PC I have has the server addresses starting at offset 0x29CB34 in pso.exe. Change those addresses to "localhost" (without quotes) if you just want to connect to a locally-running newserv instance. Alternatively, you can add an entry to the Windows hosts file (C:\Windows\System32\drivers\etc\hosts) to redirect the connection to 127.0.0.1 (localhost) or any other IP address.
### PSO GC on a real GameCube
You can make PSO connect to newserv by setting the default gateway and DNS server addresses in the game's network settings to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube. If you're not playing PSO Plus or Episode III, this should be all you need to do, assuming you already set LocalAddress in config.json to your PC's private IP address.
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. There are a couple of ways to get around this.
Sodaboy described a fairly easy method, which is to forward the PSO and DNS ports in your router's configuration to your PC's private IP address (the PSO ports are in config.json, and are all TCP; the DNS port is 53 and is UDP). Then, set LocalAddress and ExternalAddress in config.json to your external IP address (from e.g. whatismyip.com). Most routers will let you connect to your public IP address even from within the local network, but the GameCube will think it's connecting to a different network, so it won't reject the connection. If you're concerned about security and don't want your server to be publicly accessible, you can use Windows Firewall or UFW on Linux block incoming connections on the ports you opened, except for connections from the IP addresses you specify.
Another method is to use two network interfaces on the same PC, and tell the GameCube to connect to the one that appears to be on a different network. For example, if your GameCube is on the 10.0.0.x subnet and your PC's address is 10.0.0.5, you can create a fake network adapter on your PC (or use an existing real one) that has an IP address on a different subnet than the GameCube, such as 192.168.0.8. Then, in PSO's network config, set the default gateway and DNS server addresses to 192.168.0.8, and set LocalAddress in config.json to 192.168.0.8, and PSO should connect. This is what I did back in the old days when I primarily developed software on Windows, but I haven't tried it in many years.
### PSO GC on a Wii or Wii U
Using a Wii or Wii U to connect to newserv requires the Wii or vWii to be softmodded. How to do this is beyond the scope of this document.
Nintendont includes BBA emulation and is compatible with all PSO GameCube versions except Episodes I&II Trial Edition. To use Nintendont, enable BBA emulation in Nintendont's settings and follow the instructions in the above section (PSO GC on a real GameCube).
Devolution includes modem emulation and is compatible with all PSO GameCube versions including Episodes I&II Trial Edition. newserv can act as a PPP server, which Devolution can directly connect to. To do this:
1. Enable the PPPRawListen option according to the comments in config.json.
2. Start newserv.
3. In the game's network settings, set the username and password to anything (they cannot be blank), and set the phone number to the number that newserv outputs to the console during startup. (It will be near the end of all the startup log messages.) If your Wii is on the same network as newserv, use the local number; otherwise, use the external number.
### PSO GC on Dolphin
If you're using the HLE BBA type, set the BBA's DNS server address to newserv's IP address and it should work. (If newserv is on the same machine as Dolphin, you will need to use an Action Replay code directed at 127.0.0.1 to connect, as PSO rejects DNS queries from the same IP address.) Set PSO's network settings the same as listed below.
If you're using the TAP (not tapserver) BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
If you're using the tapserver BBA or modem type, you can make it connect to a newserv instance running on the same machine via the tapserver interface. To do this:
1. In the GameCube pane of the Config window, set the SP1 device to Broadband Adapter (tapserver) or Modem Adapter (tapserver).
2. Click the "..." button next to the SP1 menu. If you're using the tapserver BBA, enter `127.0.0.1:5059` in the box. If you're using the tapserver modem, enter `127.0.0.1:5058` in the box. (If newserv isn't running on the same machine as Dolphin, replace 127.0.0.1 with newserv's IP address.)
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
4. Start an online game.
### PSO Xbox
Unfortunately, you can't easily host a private server for PSO Xbox because the Xbox version of the game tunnels its connections through Xbox Live. There is a modern replacement for Xbox Live named [Insignia](https://insignia.live/), which supports the three main PSO Xbox servers, but as of now does not support other private PSO servers.
### PSO BB
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's common for various BB clients to have different map files. It's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the [client patch directories](#client-patch-directories) section for instructions on setting this up.)
The original Japanese and US versions of PSO BB work with newserv (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)). To get them to connect to your server, do one of the following:
* Use a drop-in patcher like [AzureFlare](https://github.com/Repflez/AzureFlare).
* Edit your hosts file to redirect the client's destination address to localhost or your server's address.
* Edit psobb.exe to point to your newserv instance. The original clients are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at offset 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
### Allowing external players to connect
If you want to accept connections from outside your local network, you'll need to set ExternalAddress to your public IP address in the configuration file, and you'll likely need to open some ports in your router's NAT configuration - specifically, all the TCP ports listed in PortConfiguration in config.json.
For GC clients, you'll have to use newserv's built-in DNS server or set up your own DNS server as well. If you want external clients to be able to use your DNS server, you'll have to forward UDP port 53 to your newserv instance. Remote players can then connect to your server by entering your DNS server's IP address in their client's network configuration.
# Server feature configuration
## User accounts
By default, newserv does not require users to pre-register before playing; the server will instead automatically create an account the first time each player connects. These accounts have no special permissions. You can view, create, edit, and delete user accounts in the server's shell (run `help` in the shell to see how to do this).
A license is a set of credentials that a player can use to log in. There are six types of licenses:
* *DC NTE licenses* consist of a 16-character serial number and 16-character access key.
* *DC licenses* consist of an 8-character hex serial number and an 8-character access key.
* *PC licenses* are the same format as DC licenses, but are used for PC v2.
* *GC licenses* consist of a 10-digit decimal serial number, a 12-character access key, and a password of up to 8 characters.
* *XB licenses* consist of a gamertag of up to 16 characters, a 16-character hex user ID, and a 16-character hex account ID.
* *BB licenses* consist of a username of up to 16 characters and a password of up to 16 characters.
Each account may have multiple licenses. To add a license to an existing account, use `add-license` in the shell.
On BB, character data is scoped to the license, but system and Guild Card data is scoped to the account. That is, an account with multiple BB licenses can have more than 4 characters (up to 4 per license), but they will all share the same team membership and Guild Card lists.
You may want to give your account elevated privileges. To do so, run `update-account ACCOUNT-ID flags=root` (replacing ACCOUNT-ID with your actual account-id). You can also use update-account to edit other parts of the account; see the help text for more information.
## Installing quests
newserv automatically finds quests in the subdirectories of the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's Save Files option, just put them in one of the subdirectories there and name them appropriately. The subdirectories and their behaviors (e.g. in which game modes they should appear and for which PSO versions) is defined in the QuestCategories field in config.json.
Within the category directories, quest files should be named like `q###-VERSION-LANGUAGE.EXT` (although the `q` is ignored, and can be any letter). The fields in each filename are:
- `###`: quest number (this doesn't really matter; it should just be unique across the PSO version)
- `VERSION`: dn = Dreamcast NTE, dp = Dreamcast 11/2000 prototype, d1 = Dreamcast v1, dc = Dreamcast v2, pcn = PC NTE, pc = PC, gcn = GameCube NTE, gc = GameCube Episodes 1 & 2, gc3 = Episode 3 (see below), xb = Xbox, bb = Blue Burst
- `LANGUAGE`: j = Japanese, e = English, g = German, f = French, s = Spanish
- `EXT`: file extension (see table below)
For .dat files, the `LANGUAGE` token may be omitted. If it's present, then that .dat file will only be used for that language of the quest; if omitted, then that .dat file will be used for all languages of the quest.
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-gc-e.bin` and `q058-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, it knows this is the English version of the quest because the .bin filename ends with `-e` (even though the .dat filename does not), and it puts them in the Retrieval category because the files are within the retrieval/ directory within system/quests/.
Some quests have additional JSON metadata files that describe how the server should handle them. These metadata files are generally named similarly to their .bin and .dat counterparts, except the `VERSION` token may also be omitted if the metadata applies to all languages of the quest on all PSO versions. See the comments in system/quests/retrieval/q058.json for all of the available options and how to use them. Some of the options are:
- Disable or hide the quest if certain preceding quests aren't cleared or other conditions aren't met
- Enable the quest to be joined while in progress
- Override the common and/or rare item tables and set the allowed drop modes
Some quests may also include a .pvr file, which contains an image used in the quest. These files are named similarly to their .bin and .dat counterparts.
The GameCube and Xbox quest formats are very similar, but newserv treats them as different. If you want to use the same quest file for GameCube and Xbox clients, you can make one a symbolic link to the other.
There are multiple PSO quest formats out there; newserv supports all of them. It can also decode any known format to standard .bin/.dat format. Specifically:
| Format | Extension | Supported | Decode action |
|------------------|-----------------------|------------|------------------|
| Compressed | .bin and .dat | Yes | None (1) |
| Compressed Ep3 | .bin or .mnm | Yes (4) | None (1) |
| Uncompressed | .bind and .datd | Yes | compress-prs (2) |
| Uncompressed Ep3 | .bind or .mnmd | Yes (4) | compress-prs (2) |
| Source | .bin.txt and .dat | Yes | None (5) |
| VMS (DCv1) | .bin.vms and .dat.vms | Yes | decode-vms |
| VMS (DCv2) | .bin.vms and .dat.vms | Decode (3) | decode-vms (3) |
| GCI (decrypted) | .bin.gci and .dat.gci | Yes | decode-gci |
| GCI (with key) | .bin.gci and .dat.gci | Yes | decode-gci |
| GCI (no key) | .bin.gci and .dat.gci | Decode (3) | decode-gci (3) |
| GCI (Ep3 NTE) | .bin.gci or .mnm.gci | Decode (3) | decode-gci (3) |
| GCI (Ep3) | .bin.gci or .mnm.gci | Yes | decode-gci |
| DLQ | .bin.dlq and .dat.dlq | Yes | decode-dlq |
| DLQ (Ep3) | .bin.dlq or .mnm.dlq | Yes | decode-dlq |
| QST (online) | .qst | Yes | decode-qst |
| QST (download) | .qst | Yes | decode-qst |
*Notes:*
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
3. *Use the decode action to convert these quests to .bin/.dat format before putting them into the server's quests directory. If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
4. *Episode 3 quests don't go in the system/quests directory. See the [Episode 3 section](#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.
When newserv indexes the quests during startup, it will warn (but not fail) if any quests are corrupt or in unrecognized formats.
Quest contents are cached in memory, but if you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quest-index` in the interactive shell. The new quests will be available immediately, but any games with quests already in progress will continue using the old versions of the quests until those quests end.
## Item tables and drop modes
newserv supports server-side item generation on all game versions, except for the earliest DC prototypes (NTE and 11/2000). By default, the game behaves as it did on the original servers - on all versions except BB, item drops are controlled by the leader client in each game, and on BB, item drops are controlled by the server.
There are five different available behaviors for item drops:
* `disabled` (or `none`): No items will drop from boxes or enemies.
* `client`: The game leader generates items, all items are visible to all players, and any player may pick up any item. This is the default mode for all game versions, except this mode cannot be used if the game leader is on BB.
* `shared`: The server generates items, all items are visible to all players, and any player may pick up any item. This is the default mode if the game leader is on BB.
* `private`: The server generates items, but each player may get a different item from any box or enemy. If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are visible to everyone.
* `duplicate`: The server generates items, and each player will get the same item from any box or enemy, but there is one copy of each item for each player (and each player only sees their own copy of the item). If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are not duplicated and are visible to everyone.
In the `private` and `duplicate` modes, there is no incentive to pick up items before another player, since other players cannot pick up the items you see dropped from boxes and enemies. However, if you pick up an item and drop it later, it can then be seen and picked up by any player.
The drop mode can be changed at any time during a game with the `$dropmode` chat command. If the mode is changed after some items have already been dropped, the existing items retain their visibility (that is, items dropped in private mode still can't be picked up by other players since they were dropped before the mode was changed). You can configure which drop modes are used by default, and which modes players are allowed to choose, in config.json. See the comments above the AllowedDropModes and DefaultDropMode keys.
In the server drop modes, the item tables used to generate common items are in the `system/item-tables/ItemPT-*` files. (The V2 files are used for V1 as well.) The rare item tables are in the `rare-table-*.json` files. Unlike the original formats, it's possible to make each enemy drop multiple different rare items at different rates, though the default tables never do this.
## Cross-version play
All versions of PSO can see and interact with each other in the lobby. By default, newserv allows V1 and V2 players to play in games together, and allows GC and Xbox players to play in games together. You can change these rules to allow all versions to play in games together, or to prevent versions from playing in games together, with the CompatibilityGroups setting in config.json.
There are several cross-version restrictions that always apply regardless of the compatibility groups setting:
* DC V1 players cannot join DC V2 games if the game creator didn't choose to allow them.
* DC V1 players cannot join games if the difficulty level is set to Ultimate or the game mode is Battle or Challenge.
* Only GC, Xbox, and BB players can join games in Episode 2.
* Only BB players can join games in Episode 4.
* Episode 3 players cannot join non-Episode 3 games, and vice versa.
V1/V2 compatibility and GC/Xbox compatibility are well-tested, but other situations are not. Not much attention has been given yet to how items should be handled across major versions; if you enable V2/GC compatibility, for example, there will likely be bugs. Please report such bugs as GitHub issues.
In cross-version play, when any of the server drop modes are used, the server uses the drop tables corresponding to the leader's version and section ID. (For example, if a DC V1 player is the game leader, rare-table-v1.json will be used, even after V2 players join.) If a BB player is the leader and the `client` drop mode is used, the server generates items as if it were in `shared` mode.
## Server-side saves
newserv has the ability to save character data on the server side. For PSO BB, this is required of course, but this feature can also be used on other PSO versions.
Each account has 4 BB character slots and 16 non-BB character file slots. The non-BB slots are independent of the BB slots, and can be accessed with the `$savechar <slot>` and `$loadchar <slot>` commands (slots are numbered 1 through 16). `$savechar` copies the character you're currently playing as and saves the data on the server, and `$loadchar` does the reverse, overwriting your current character with the data saved on the server. Note that you can load a character that was saved from a different version of PSO, which allows you to easily transfer characters between games. On v1 and v2, changes done by `$loadchar` will be undone if you join a game; to permanently save your changes, disconnect from the lobby after using the command.
You can see basic information about a character saved on the server (without affecting your current character) by using `$checkchar <slot>`. You can delete a previously-saved character with `$deletechar <slot>`.
There is also the command `$bbchar <username> <password> <slot>`, which behaves similarly to `$savechar` but writes the character data to a BB character slot in a different account instead (slots are numbered 1 through 4). This can be used to "upgrade" a character to BB from an earlier version.
Exactly which data is saved and loaded depends on the game version:
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/Challenge |
|----------------------|-----------|-----------|---------------|-------------|------|------------------|
| PSO DC v1 prototypes | Yes | Yes | No | No | No | N/A |
| PSO DC v1 | Yes | Yes | No | No | No | N/A |
| PSO DC v2 | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO PC (v2) | Yes | Yes | No | No | No | Save only |
| PSO GC NTE | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC (not Plus) | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC Plus (1) | Save only | Save only | No | No | No | Save only |
| PSO GC Ep3 (1) | No | Save only | No | No | No | Save only |
| PSO Xbox | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO BB | Yes | Yes | Yes | Yes | Yes | Yes |
*Notes*:
1. *If EnableSendFunctionCallQuestNumber is enabled in config.json, then $savechar and $loadchar can save and restore all character data on these versions, just like on GC non-Plus. Episode 3 characters exist in a separate namespace; that is, you can't use $savechar and $loadchar to convert an Ep3 character to non-Ep3, or vice versa.*
## Episode 3 features
newserv supports many features unique to Episode 3:
* CARD battles. Not every combination of abilities has been tested yet, so if you find a feature or card ability that doesn't work like it's supposed to, please make a GitHub issue and describe the situation (the attacking card(s), defending card(s), and ability or condition that didn't work).
* Spectator teams.
* Tournaments. (But they work differently than Sega's tournaments did - see below)
* Downloading quests.
* Trading cards.
* Participating in card auctions. (The auction contents must be configured in config.json.)
* Decorations in lobbies. Currently only images are supported; the game also supports loading custom 3D models in lobbies, but newserv does not implement this (yet).
### Battle records
After playing a battle, you can save the record of the battle with the `$saverec` command. You can then replay the battle later by using the `$playrec` command in a lobby - this will create a spectator team and play the recording of the battle as if it were happening in realtime. Note that there is a bug in older versions of Dolphin that seems to be frequently triggered when playing battle records, which causes the emulator to crash with the message `QObject::~QObject: Timers cannot be stopped from another thread`. To avoid this, use the latest version of Dolphin.
### Tournaments
Tournaments work differently than they did on Sega's servers. Tournaments can be created with the `create-tournament` shell command, which enables players to register for them. (Use `help` to see all the arguments - there are many!) The `start-tournament` shell command starts the tournament (and prevents further registrations), but this doesn't schedule any matches. Instead, players who are ready to play their next match can all stand at the 4-player battle table near the lobby warp in the same CARD lobby, and the tournament match will start automatically.
These tournament semantics mean that there can be multiple matches in the same tournament in play simultaneously, and not all matches in a round must be complete before the next round can begin - only the matches preceding each individual match must be complete for that match to be playable.
The Meseta rewards for winning tournament matches can be configured in config.json.
### Episode 3 files
Episode 3 state and game data is stored in the system/ep3 directory. The files in there are:
* card-definitions.mnr: Compressed card definition list, sent to Episode 3 clients at connect time. Card stats and abilities can be changed by editing this file.
* card-definitions.mnrd: Decompressed version of the above. If present, newserv will use this instead of the compressed version, since this is easier to edit.
* 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.
* 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.
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3-cards` or `reload ep3-maps` in the interactive shell to make the changes take effect without restarting the server.
## Memory patches and client functions
You can put assembly files in the system/client-functions directory with filenames like PatchName.VERS.patch.s and they will appear in the Patches menu for clients that support client functions. Client functions are written in SH-4, PowerPC, or x86 assembly and are compiled when newserv is started. The assembly system's features are documented in the comments in system/client-functions/System/WriteMemoryGC.ppc.s.
The VERS token in client function filenames refers to the specific version of the game that the client function applies to. Some versions do not support receiving client functions at all. *Note: newserv uses the shorter GameCube versioning convention, where discs labeled DOL-XXXX-0-0Y are version 1.Y. The PSO community seems to use the convention 1.0Y in some places instead, but these are the same version. For example, the version that newserv calls v1.4 is the same as v1.04, and is labeled DOL-GPOJ-0-04 on the underside of the disc.*
The specific versions are:
| Game | VERS | CPU architecture |
|------------------------------|------|--------------------------------|
| PSO DC Network Trial Edition | 1OJ1 | Client functions not supported |
| PSO DC 11/2000 prototype | 1OJ2 | Client functions not supported |
| PSO DC 12/2000 prototype | 1OJ3 | Client functions not supported |
| PSO DC 01/2001 prototype | 1OJ4 | Client functions not supported |
| 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 v2 JP | 2OJF | SH-4 |
| PSO DC v2 US | 2OEF | SH-4 |
| PSO DC v2 EU | 2OPF | SH-4 |
| 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 |
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 (Plus) JP | 3OJ4 | PowerPC |
| PSO GC v1.5 (Plus) JP | 3OJ5 | PowerPC (1) |
| PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 (Plus) US | 3OE2 | PowerPC (1) |
| PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 Trial Edition | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | PowerPC (1) |
| PSO GC Ep3 EU | 3SP0 | PowerPC (1) |
| PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.11 | 59NJ | x86 |
| PSO BB JP 1.25.13 | 59NL | x86 |
| PSO BB Tethealla | 59NL | x86 |
*Notes:*
1. *Client functions are only supported on these versions if EnableSendFunctionCallQuestNumbers is set in config.json. See the comments there for more information.*
newserv comes with a set of patches for many of the above versions. These are organized in subdirectories within system/client-functions/.
### DOL loader
You can put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWordGC.ppc.s, WriteMemoryGC.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
I mainly built the DOL loading functionality for documentation purposes. By now, there are many better ways to load homebrew code on an unmodified GameCube, but to my knowledge there isn't another open-source implementation of this method in existence.
## Using newserv as a proxy
If you want to play online on remote servers rather than running your own server, newserv also includes a PSO proxy. Currently this works with PSO GC and may work with PC and DC; it also works with some BB clients in specific situations.
To use the proxy for PSO DC, PC, or GC, add an entry to the corresponding ProxyDestinations dictionary in config.json, then run newserv and connect to it as normal (see below). You'll see a "Proxy server" option in the main menu, and you can pick which remote server to connect to.
To use the proxy for PSO BB, set the ProxyDestination-BB entry in config.json. If this option is set, it essentially disables the game server for all BB clients - all BB clients will be proxied to the specified destination instead. Unfortunately, because PSO BB uses a different set of handlers for the data server phase and character selection, there's no in-game way to present the player with a list of options, like there is on PSO PC and PSO GC.
When you're on PSO DC, PC, GC, or Xbox and are connected to a remote server through newserv's proxy, choosing the Change Ship or Change Block action from the lobby counter will send you back to newserv's main menu instead of the remote server's ship or block select menu. You can go back to the server you were just on by choosing it from the proxy server menu again.
There are many options available when starting a proxy session. All options are off by default unless otherwise noted. The options are:
* **Chat commands**: enables chat commands in the proxy session (on by default).
* **Chat filter**: enables escape sequences in chat messages and info board (on by default).
* **Player notifications**: shows a message when any player joins or leaves the game or lobby you're in.
* **Block pings**: blocks automatic pings sent by the client, and responds to ping commands from the server automatically.
* **Infinite HP**: automatically heals you whenever you get hit. An attack that kills you in one hit will still kill you, however.
* **Infinite TP**: automatically restores your TP whenever you use any technique.
* **Switch assist**: unlocks doors that require two or four players in a one-player game, when you step on one of the switches.
* **Infinite Meseta** (Episode 3 only): gives you 1,000,000 Meseta, regardless of the value sent by the remote server.
* **Block events**: disables holiday events sent by the remote server.
* **Block patches**: prevents any B2 (patch) commands from reaching the client.
* **Save files**: saves copies of several kinds of files when they're sent by the remote server. The files are written to the current directory (which is usually the directory containing the system/ directory). Saved files can then be used with newserv by just moving the file into the appropriate place in the system/ directory and renaming it appropriately. These kinds of files can be saved:
* Online quests and download quests (saved as .bin/.dat files)
* GBA games (saved as .gba files)
* Patches (saved as .bin files and disassembled as .txt files)
* Player data from BB sessions (saved as .psochar 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)
* Episode 3 media updates (saved as .gvm, .bml, or .bin files)
The remote server will probably try to assign you a Guild Card number that doesn't match the one you have on newserv. The proxy rewrites the commands in transit to make it look like the remote server assigned you the same Guild Card number as you have on newserv, but if the remote server has some external integrations (e.g. forum or Discord bots), they will use the Guild Card number that the remote server believes it has assigned to you. The number assigned by the remote server is shown to you when you first connect to the remote server, and you can retrieve it in lobbies or during games with the `$li` command.
Some chat commands (see below) have the same basic function on the proxy but have different effects or conditions. In addition, there are some server shell commands that affect clients on the proxy (run `help` in the shell to see what they are). If there's only one proxy session open, the shell's proxy commands will affect that session. Otherwise, you'll have to specify which session to affect with the `on` prefix - to send a chat message in C-17's session, for example, you would run `on C-17 chat ...`.
## Chat commands
newserv supports a variety of commands players can use by chatting in-game. Any chat message that begins with `$` is treated as a chat command. (If you actually want to send a chat message starting with `$`, type `$$` instead.) On the DC 11/2000 prototype, `@` is used instead of `$` for all chat commands, since `$` does not appear on the English virtual keyboard.
Some commands only work for clients not in proxy sessions. The chat commands are:
* Information commands
* `$li`: Show basic information about the lobby or game you're in. If you're on the proxy, show information about your connection instead (remote Guild Card number, client ID, etc.).
* `$si`: Show basic information about the server.
* `$ping`: Show round-trip ping time from the server to you. On the proxy, show the ping time from you to the proxy and from the proxy to the server.
* `$matcount` (non-proxy only): Show how many of each type of material you've used.
* `$killcount` (non-proxy only): Show the kill count on your currently-equipped weapon. If you're in a game and not on BB, the value is only accurate at the time the item enters the game.
* `$itemnotifs <mode>`: Enable item drop notification messages. If the game has private drops enabled, you will only see a notification if the dropped item is visible to you; you won't be notified of other players' drops. The modes are:
* `off`: No notifications are shown.
* `rare`: You are notified when a rare item drops.
* `on`: You are notified when any item drops, except Meseta.
* `every`: You are notified when any item drops, including Meseta.
* `$announcerares`: Enable or disable announcements for your rare item finds. This determines whether rare items you find will be announced to the game and server, not whether you will see announcements for others finding rare items.
* `$what` (non-proxy only): Show the type, name, and stats of the nearest item on the ground.
* `$where`: Show your current floor number and coordinates. Mainly useful for debugging.
* `$qfread <field-name>` (non-proxy only): Show the value of a quest counter in your player data. The field names are defined in config.json.
* Basic debugging commands (special permissions not required)
* `$whatobj` and `$whatene` (non-proxy only): Tells you what the closest object or enemy spawn point is to your position, along with its coordinates and object or enemy ID. The full definition is also printed to the server's log.
* `$qcheck <flag-num>` (non-proxy only): Show the value of a quest flag. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only).
* `$qgread <flag-num>` (non-proxy only): Show the value of a quest counter ("global flag").
* `$sound <sound-id>`: Play the given sound (GC only).
* Restricted debugging commands (`$debug` permission required)
* `$debug`: Enable debug mode. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
* You'll be able to use the rest of the commands in this section.
* You'll see in-game messages from the server when you take some actions, like killing enemies, opening boxes, or flipping switches.
* You'll see the rare seed value and floor variations when you join a game.
* You'll be placed into the last available slot in lobbies and games instead of the first, unless you're joining a BB solo-mode game.
* You'll be able to join games with any PSO version, not only those for which cross-version play is normally enabled. See the "Cross-version play" section above for details on this.
* `$readmem <address>`: Read 4 bytes from the given address and show you the values.
* `$writemem <address> <data>`: Write data to the given address. Data is not required to be any specific size.
* `$nativecall <address> [arg1 ...]` (GC only): Call a native function on your client. Only arguments passed in registers are supported; calling functions that take many arguments is not supported.
* `$quest <number>` (non-proxy only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. `$debug` is not required for this command if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
* `$qcall <function-id>`: Call a quest function on your client.
* `$qset <flag-num>` or `$qclear <flag-num>`: Set or clear a quest flag for everyone in the game. If you're in the lobby and on BB, set or clear the saved value of a quest flag in your character file.
* `$qgwrite <flag-num> <value>` (non-proxy only): Set the value of a quest counter ("global flag") for yourself.
* `$qsync <reg-num> <value>`: Set a quest register's value for yourself only. `<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.
* `$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.
* `$gc` (non-proxy only): Send your own Guild Card to yourself.
* `$sc <data>`: Send a command to yourself.
* `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server.
* `$sb <data>`: Send a command to yourself, and to the remote server or game server.
* `$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.
* 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).
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy, this will not work if the remote server controls item drops. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies and item drops. On the proxy, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
* `$swa`: Enable or disable switch assist. When enabled, the server will unlock two-player and four-player doors in non-quest games when you step on any of the required switches.
* `$exit`: If you're in a lobby, send you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, send you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
* Character data commands (non-proxy only)
* `$switchchar <slot>` (BB only): Switch to a different character from your account without logging out.
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$loadchar <slot>`: Load character data from the specified slot on the server, and replace your current character with it. See the [server-side saves section](#server-side-saves) for more details.
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the [server-side saves section](#server-side-saves) for more details.
* `$checkchar [slot]`: Tells you basic information about a server-side character previously saved using `$savechar`. If `slot` is not given, tells you which slots are used and which are free.
* `$deletechar <slot>`: Deletes a server-side character previously saved using `$savechar`.
* `$edit <stat> <value>`: Modify your character data. See the [using $edit](#using-edit) section for details.
* Blue Burst player commands (non-proxy only)
* `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
* `$save`: Save your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
* Game state commands (non-proxy only)
* `$maxlevel <level>`: Set the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
* `$minlevel <level>`: Set the minimum level for players to join the current game.
* `$password <password>`: Set the game's join password. To unlock the game, run `$password` with nothing after it.
* `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the [item tables and drop modes section](#item-tables-and-drop-modes) for more information.
* `$persist`: Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The states of enemies, objects, and switches will be saved, and items left on the floor will not be deleted. (But if you're in the private or duplicate drop mode, items dropped by enemies are deleted - to make sure a certain item won't be deleted, you can pick it up and drop it again.) If the game is empty for too long (15 minutes by default), it is then deleted.
* Episode 3 commands (non-proxy only)
* `$spec`: Toggle the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they are sent back to the lobby.
* `$inftime`: Toggle infinite-time mode. Must be used before starting a battle. If infinite-time mode is on, the overall and per-phase time limits will be disabled regardless of the values chosen during battle rules setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Set override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them.
* `$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).
* 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.
* `$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.
* `$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
* `$event <event>`: Set the current holiday event in the current lobby. Holiday events are documented in the "Using $event" item in the information menu. If you're on the proxy, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
* `$allevent <event>` (non-proxy only): Set the current holiday event in all lobbies.
* `$song <song-id>` (Episode 3 only): Play a specific song in the current lobby.
* Administration commands (non-proxy only)
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. On BB, the message appears in the scrolling top bar.
* `$ann!`, `$ann?`, `$ann?!`: Same as `$ann`, but with `?`, omits the sender's name, and with `!`, sends the message as a Simple Mail message instead of on-screen text.
* `$silence <identifier>`: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number.
* `$kick <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
* `$ban <duration> <identifier>`: Ban a player. The duration should be of the form `10m` (minutes), `10h` (hours), `10d` (days), `10w` (weeks), `10M` (months), or `10y` (years). (Numbers other than 10 may be used, of course.) As with `$kick`, the identifier may be the player's name or Guild Card number.
### Using $edit
The $edit command modifies your character data. This command doesn't work on V3 (GameCube/Xbox). If you are on V1 or V2 (DC or PC, not BB), your changes will be undone if you join a game - to save your changes, disconnect from the lobby.
Some subcommands are always available. They are:
* `$edit mat reset power`: Clear your usage of power materials (BB only)
* `$edit mat reset mind`: Clear your usage of mind materials (BB only)
* `$edit mat reset evade`: Clear your usage of evade materials (BB only)
* `$edit mat reset def`: Clear your usage of def materials (BB only)
* `$edit mat reset luck`: Clear your usage of luck materials (BB only)
* `$edit mat reset hp`: Clear your usage of HP materials (BB only)
* `$edit mat reset tp`: Clear your usage of TP materials (BB only)
* `$edit mat reset all`: Clear your usage of all materials except HP and TP (BB only)
* `$edit mat reset every`: Clear your usage of all materials including HP and TP (BB only)
* `$edit namecolor AARRGGBB`: Set your name color (AARRGGBB specified in hex)
* `$edit language L`: Set your language (Generally only useful on BB; values for L: J = Japanese, E = English, G = German, F = French, S = Spanish, B = Simplified Chinese, T = Traditional Chinese, K = Korean)
* `$edit name NAME`: Set your character name
* `$edit npc NPC-NAME`: Set or remove an NPC skin on your character (use `none` to remove a skin). The NPC names are:
* On all versions except DCv1 and early prototypes: `ninja`, `rico`, `sonic`, `knuckles`, `tails`
* On GC, Xbox, and BB: `flowen`, `elly`
* On BB only: `momoka`, `irene`, `guild`, `nurse`
* `$edit secid SECID-NAME`: Set your section ID (cheat mode is required unless your character is Level 1)
The remaining subcommands are only available if cheat mode is enabled on the server. They are:
* `$edit atp N`: Set your ATP to N until stats are updated (e.g. by leveling up)
* `$edit mst N`: Set your MST to N until stats are updated
* `$edit evp N`: Set your EVP to N until stats are updated
* `$edit dfp N`: Set your DFP to N until stats are updated
* `$edit ata N`: Set your ATA to N until stats are updated
* `$edit lck N`: Set your LCK to N until stats are updated
* `$edit hp N`: Set your HP to N until stats are updated
* `$edit meseta N`: Set the amount of Meseta in your inventory
* `$edit exp N`: Set your total amount of EXP (does not affect level)
* `$edit level N`: Set your current level (recomputes stats, but does not affect EXP)
* `$edit tech TECH-NAME LEVEL`: Set the level of one of your techniques
## REST API
newserv has an optional HTTP server that provides a way to programmatically get data from the server in realtime. This is intended for use with external integrations; for example, a web site could query this API to get the current player count to display on the home page.
The HTTP server is disabled by default, and you have to explicitly enable it in config.json if you want this functionality. **If you enable it, make sure that the HTTP port can't be accessed from the public Internet.** The API provides a lot of internal data about players and games, and it should only be accessed by programs that you've written or that you trust.
To enable the HTTP server, add a port number in the HTTPListen list in config.json. The HTTP server will listen on that port.
All returned data is JSON-encoded, and all request data (for POST requests) must also be JSON-encoded with the `Content-Type: application/json` header.
The HTTP server has the following endpoints:
* `GET /`: Returns the server's build date and revision.
* `GET /y/data/ep3-cards`: Returns the Episode 3 card definitions.
* `GET /y/data/ep3-cards-trial`: Returns the Episode 3 Trial Edition card definitions.
* `GET /y/data/common-tables`: Returns the parameters for generating common items (ItemPT files). This endpoint returns a lot of data and can be slow!
* `GET /y/data/rare-tables`: Returns a list of rare table names.
* `GET /y/data/rare-tables/<TABLE-NAME>` (for example, `/y/data/rare-tables/rare-table-v4`): Returns the contents of a rare item table.
* `GET /y/data/quests`: Returns metadata about all available quests and quest categories.
* `GET /y/data/config`: Returns the server's configuration file.
* `GET /y/accounts`: Returns information about all registered accounts.
* `GET /y/clients`: Returns information about all connected clients on the game server.
* `GET /y/proxy-clients`: Returns information about all connected clients on the proxy.
* `GET /y/lobbies`: Returns information about all lobbies and games.
* `GET /y/server`: Returns information about the server.
* `GET /y/summary`: Returns a summary of the server's state, connected clients, active games, and proxy sessions.
* `WS /y/rare-drops/stream`: WebSocket endpoint that sends messages whenever an announceable rare item is dropped in any game. See below.
* `POST /y/shell-exec`: Runs a server shell command. Input should be a JSON dict of e.g. `{"command": "announce hello"}`; response will be a JSON dict of `{"result": "<result text>"}` or an HTTP error.
### Rare drop stream endpoint
The `/y/rare-drops/stream` endpoint provides a way to implement a drop log in e.g. Discord. For every announceable rare item, a message is sent to all connected clients on this endpoint. (Announceable rare items are items for which an in-game or server-wide text message is sent announcing the find.)
Upon connecting, you'll get the message `{"ServerType": "newserv"}`. After that, when a rare item announcement is sent, you'll get a message like this:
```
{
"PlayerAccountID", 12345,
"PlayerName", "SONIC",
"PlayerVersion", "GC_V3",
"GameName", "ttf",
"GameDropMode", "SERVER_PRIVATE",
"ItemData", "03000000 00010000 00000000 (0021002C) 00000000",
"ItemDescription", "Monomate x1",
"NotifyGame", true,
"NotifyServer", false,
}
```
# Non-server features
newserv has many CLI options, which can be used to access functionality other than the game server and proxy. Run `newserv help` to see a full list of the options and how to use each one.
The data formats that newserv can convert to/from are:
| Format | Encode/compress action | Decode/extract action |
|-------------------------------------|---------------------------|------------------------------|
| PRS compression | `compress-prs` | `decompress-prs` |
| PR2/PRC compression | `compress-pr2` | `decompress-pr2` |
| BC0 compression | `compress-bc0` | `decompress-bc0` |
| Raw encrypted data | `encrypt-data` | `decrypt-data` |
| Episode 3 command mask | `encrypt-trivial-data` | `decrypt-trivial-data` |
| Challenge Mode rank text | `encrypt-challenge-data` | `decrypt-challenge-data` |
| PSO DC quest file (.vms) | None | `decode-vms` |
| PSO GC quest file (.gci) | None | `decode-gci` |
| Download quest file (.dlq) | None | `decode-dlq` |
| Server quest file (.qst) | `encode-qst` | `decode-qst` |
| PSO DC save file (.vms) | `encrypt-vms-save` | `decrypt-vms-save` |
| PSO PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO Xbox save file | None | `decrypt-xbox-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive (.afs) | None | `extract-afs` |
| BML archive (.bml) | None | `extract-bml` |
| PPK archive (.ppk) | None | `extract-ppk` |
| GSL archive (.gsl) | `generate-gsl` | `extract-gsl` |
| GVM texture (.gvm) | `encode-gvm` | None |
| Bitmap font (.fon) | `encode-bitmap-font` | `decode-bitmap-font` |
| Text archive | `encode-text-archive` | `decode-text-archive` |
| Unicode text set | `encode-unicode-text-set` | `decode-unicode-text-set` |
| Word Select data set | None | `decode-word-select-set` |
| Set data table | None | `disassemble-set-data-table` |
| Rare item table (AFS/GSL/JSON/HTML) | `convert-rare-item-set` | `convert-rare-item-set` |
There are several actions that don't fit well into the table above, which let you do other things:
* Compute the decompressed size of compressed PRS data without decompressing it (`prs-size`)
* Find the likely round1 or round2 seed for a corrupt save file (`salvage-gci`)
* Run a brute-force search for a decryption seed (`find-decryption-seed`)
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`, `generate-ep3-cards-html`)
* Format Blue Burst battle parameter files in a human-readable manner (`show-battle-params`)
* Convert item data to a human-readable description, or vice versa (`describe-item`)
* Show the server's item and level tables (`show-item-tables`, `show-level-tables`)
* Connect to another PSO server and pretend to be a client (`cat-client`)
* Generate or describe DC serial numbers (`generate-dc-serial-number`, `inspect-dc-serial-number`)
# Docker
Docker is new and mostly unsupported at this time. However, here are some best-effort steps to build and run in a docker container on Ubuntu Linux.
Tested on Ubuntu 22.04.4 LTS.
Note: You cannot have anything except this docker container using port 53 (DNS) on your server.
Install prerequisites
```
sudo apt install -y git
sudo apt install -y cmake. ## minimum version is 3.10. Check installed version with "cmake --version"
```
Clone repository
```
cd ~
git clone https://github.com/fuzziqersoftware/newserv/
cd ~/newserv
```
Build newserv. This will take a while. Don't forget the period at the end!
```
sudo docker build -t newserv .
```
Create persistent directories. Assuming you want to store the persistent data in your home directory
```
mkdir ~/newservPersist
mkdir ~/newservPersist/players
mkdir ~/newservPersist/teams
mkdir ~/newservPersist/licenses
```
Copy config file to config dir
```
cp ~/newserv/system/config.example.json ~/newservPersist/config.json
```
Edit config.json
```
nano ~/newservPersist/config.json
```
Pro tip:
Set "LocalAddress" to the static, LAN IP address of your server. If your server LAN IP is "192.168.0.10":
"LocalAddress": "192.168.0.10",
Set "ExternalAddress" to the WAN IP address of your network. If your WAN IP is "8.8.8.8":
"ExternalAddress": "8.8.8.8",
For Dolphin > Settings. Set SP1 to "Broadband Adapter (HLE)" Click [...] next to this, and set the DNS to the IP address of your server. Then start the game. Changes will not take affect if the game is running.
Docker run. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
docker run --name newserv -p 53:53/udp -p 5100:5100 -p 5110:5110 -p 5111:5111 -p 5112:5112 -p 9064:9064 -p 9100:9100 -p 9103:9103 -p 9300:9300 -p 11000:11000 -p 12000:12000 -p 12004:12004 -p 12005:12005 -v /etc/localtime:/etc/localtime:ro -v /home/changeme/newservPersist/config.json:/newserv/system/config.json -v /home/changeme/newservPersist/players:/newserv/system/players -v /home/changeme/newservPersist/teams:/newserv/system/teams -v /home/changeme/newservPersist/licenses:/newserv/system/licenses --restart no newserv:latest
```
Docker run host network mode. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
docker run --net host --name newserv -v /etc/localtime:/etc/localtime:ro -v /home/changeme/newservPersist/config.json:/newserv/system/config.json -v /home/changeme/newservPersist/players:/newserv/system/players -v /home/changeme/newservPersist/teams:/newserv/system/teams -v /home/changeme/newservPersist/licenses:/newserv/system/licenses --restart no newserv:latest
```
Docker compose. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
name: psonewserv
services:
newserv:
container_name: newserv
ports:
- 53:53/udp
- 5100:5100
- 5110:5110
- 5111:5111
- 5112:5112
- 9064:9064
- 9100:9100
- 9103:9103
- 9300:9300
- 11000:11000
- 12000:12000
- 12004:12004
- 12005:12005
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/changeme/newservPersist/config.json:/newserv/system/config.json
- /home/changeme/newservPersist/players:/newserv/system/players
- /home/changeme/newservPersist/teams:/newserv/system/teams
- /home/changeme/newservPersist/licenses:/newserv/system/licenses
restart: no ## Set to whatever you want.
image: newserv:latest
```
Docker compose host network mode. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
name: psonewserv
services:
newserv:
container_name: newserv
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/changeme/newservPersist/config.json:/newserv/system/config.json
- /home/changeme/newservPersist/players:/newserv/system/players
- /home/changeme/newservPersist/teams:/newserv/system/teams
- /home/changeme/newservPersist/licenses:/newserv/system/licenses
restart: no ## Set to whatever you want.
network_mode: host
image: newserv:latest
```
See `LICENSE` for license details. Any copied or modified upstream code retains the original license attribution.
+1 -6
View File
@@ -1,13 +1,11 @@
## General
- Make a server patch version of story flag fixer quest
- Fix enemy flag mapping in v2/v3 crossplay and test
- Handle items in crossplay - use the replacement table
- Make proxy server handle all login commands on non-BB, including sending 9C when needed
- Add $switchit command (activates switch flag(s) for nearest object, e.g. laser fence, door, fog collision)
- Add a way to persist flags across connections, at least on v3, because of Meet User + B2 enable quest interactions - maybe update the quest to patch one of the login commands so the server can tell it's enabled
- Handle MeetUserExtensions properly in 41 and C4 commands on the proxy (rewrite the embedded 19 command and put some metadata in the persistent config, perhaps)
- Clean up ItemParameterTable implementation (see comment at the top of the class definition)
- Make UI strings localizable (e.g. entries in menus, welcome message, etc.)
## PSO DC
@@ -30,8 +28,5 @@
## PSOBB
- Figure out why Pouilly Slime EXP doesn't work
- Make server-specified rare enemies work with maps loaded by the proxy
- Implement serialization for various table types (ItemPMT, ItemPT, etc.)
- Record some BB tests
- Add all necessary Guild Card number rewrites in BB commands on the proxy
- Implement BB replay tests properly and record some
+99
View File
@@ -0,0 +1,99 @@
Subject: [PATCH] DC V2 EXP: server-side per-difficulty dispatcher hooked into set-events
Adds a `dispatch_dc_v2_exp_patch` helper that:
- no-ops unless the client is DC V2, supports send_function_call, has
`PsoPeepsV2EXP_enabled` in `auto_patches_enabled`, and is in an actual game
- reads the lobby's current difficulty
- looks up `PsoPeepsV2EXP_internal_{10|5}x_{normal|hard|vh|ult}` (10x preferred
if both deployed; falls back to 5x)
- sends it via the existing send_function_call coroutine
Hooks the dispatcher at the end of `on_trigger_set_event`, which fires on every
6x67 the client emits (i.e. every area transition that triggers map events).
This survives all difficulty/area cycling because the patch is re-applied on
every trigger.
The menu-visible shim `PsoPeepsV2EXP_enabled` uses a fixed key across both 5x
week and 10x weekend deploys, so a player's selection survives the systemd
file swap.
---
src/ReceiveSubcommands.cc | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc
--- a/src/ReceiveSubcommands.cc
+++ b/src/ReceiveSubcommands.cc
@@ -- (around line 3637 — directly before the existing `on_trigger_set_event`) --
+// Dispatch the right per-difficulty DC V2 EXP table when the player has the
+// universal EXP shim enabled. The shim's body covers Normal; this corrects to
+// the actual loaded difficulty on every set-events trigger. No-op for non-DC-V2
+// clients, clients without the shim toggled on, or when the right internal
+// patch isn't currently deployed.
+static asio::awaitable<void> dispatch_dc_v2_exp_patch(std::shared_ptr<Client> c) {
+ if (c->version() != Version::DC_V2) {
+ co_return;
+ }
+ if (!c->check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
+ co_return;
+ }
+ if (!c->login || !c->login->account) {
+ co_return;
+ }
+ if (!c->login->account->auto_patches_enabled.contains("PsoPeepsV2EXP_enabled")) {
+ co_return;
+ }
+
+ auto l = c->require_lobby();
+ if (!l->is_game()) {
+ co_return;
+ }
+
+ const char* diff_str;
+ switch (l->difficulty) {
+ case Difficulty::NORMAL: diff_str = "normal"; break;
+ case Difficulty::HARD: diff_str = "hard"; break;
+ case Difficulty::VERY_HARD: diff_str = "vh"; break;
+ case Difficulty::ULTIMATE: diff_str = "ult"; break;
+ default: co_return;
+ }
+
+ auto s = c->require_server_state();
+ // Try 10x first; fall back to 5x. The active multiplier is whichever set is
+ // deployed by the current week's systemd timer state.
+ for (int mult : {10, 5}) {
+ std::string key = std::format("PsoPeepsV2EXP_internal_{}x_{}", mult, diff_str);
+ std::shared_ptr<Function> fn;
+ try {
+ fn = s->client_functions->get(key, c->specific_version);
+ } catch (...) {
+ continue;
+ }
+ if (fn) {
+ co_await send_function_call(c, fn);
+ co_return;
+ }
+ }
+}
+
static asio::awaitable<void> on_trigger_set_event(shared_ptr<Client> c, SubcommandMessage& msg) {
auto l = c->require_lobby();
if (!l->is_game()) {
co_return;
}
const auto& cmd = msg.check_size_t<G_TriggerSetEvent_6x67>();
auto event_sts = l->map_state->event_states_for_id(c->version(), cmd.floor, cmd.event_id);
l->log.info_f("Client triggered set events with floor {:02X} and ID {:X} ({} events)",
cmd.floor, cmd.event_id, event_sts.size());
for (auto ev_st : event_sts) {
ev_st->flags |= 0x04;
if (c->check_flag(Client::Flag::DEBUG_ENABLED)) {
send_text_message_fmt(c, "$C5W-{:03X} START", ev_st->w_id);
}
}
forward_subcommand(c, msg);
+
+ co_await dispatch_dc_v2_exp_patch(c);
}
+913
View File
@@ -0,0 +1,913 @@
# newserv <img align="right" src="static/s-newserv.png" />
newserv is a game server, proxy, and reverse-engineering tool for Phantasy Star Online (PSO). **To quickly get started using newserv, just read the [server setup](#server-setup) and [how to connect](#how-to-connect) sections.**
This project includes code that was reverse-engineered by the community in ages long past, and has been included in many projects since then. It also includes some game data from Phantasy Star Online itself, which was originally created by Sega.
Feel free to submit GitHub issues if you find bugs or have feature requests. I'd like to make the server as stable and complete as possible, but I can't promise that I'll respond to issues in a timely manner, because this is a personal project undertaken primarily for the fun of reverse-engineering. If you want to contribute to newserv yourself, pull requests are welcome as well.
See TODO.md for a list of known issues and future work I've curated, or go to the GitHub issue tracker for issues and requests submitted by the community.
**Table of contents**
* Background
* [History](#history)
* [Other server projects](#other-server-projects)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [Contributing to newserv](#contributing-to-newserv)
* [Compatibility](#compatibility)
* Setup
* [Server setup](#server-setup)
* [Client patch directories for PC and BB](#client-patch-directories)
* [How to connect](#how-to-connect)
* Features and configuration
* [User accounts](#user-accounts)
* [Installing quests](#installing-quests)
* [Item tables and drop modes](#item-tables-and-drop-modes)
* [Cross-version play](#cross-version-play)
* [Server-side saves](#server-side-saves)
* [Episode 3 features](#episode-3-features)
* [Memory patches and client functions](#memory-patches-and-client-functions)
* [DOL loader](#dol-loader)
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
* [Chat commands](#chat-commands)
* [REST API](#rest-api)
* [Non-server features](#non-server-features)
# History
The history of this project essentially mirrors my development as a software engineer from the beginning of my hobby until now. If you don't care about the story, skip to the "Compatibility" or "Setup" sections below.
I originally purchased PSO GC when I heard about PSUL, and wanted to play around with running homebrew on my GameCube. This pathway eventually led to [GCARS-CS](https://github.com/fuzziqersoftware/gcars-cs), but that's another story.
<img align="left" src="static/s-khyps.png" /> After playing PSO for a while, both offline and online, I wrote a proxy called Khyps sometime in 2003. This was back in the days of the official Sega servers, where vulnerabilities weren't addressed in a timely manner or at all. It was common for malicious players using their own proxies or Action Replay codes (a story for another time) to send invalid commands that the servers would blindly forward, and cause the receiving clients to crash. These crashes were more than simply inconvenient; they could also corrupt your save data, destroying the hours of work you may have put into hunting items and leveling up your character.
For a while it was essentially necessary to use a proxy to go online at all, so the proxy could block these invalid commands. Khyps was designed primarily with this function in mind, though it also implemented some convenient cheats, like the ability to give yourself or other players infinite HP and allow you to teleport to different places without using an in-game teleporter.
<img align="left" src="static/s-khyller.png" /> After Khyps I took on the larger challenge of writing a server, which resulted in Khyller sometime in 2005. This was the first server of any type I had ever written. This project eventually evolved into a full-featured environment supporting all versions of the game that I had access to - at the time, PC, GC, and BB. (However, I suspect from reading the ancient source files that Khyller's BB support was very buggy.) As Khyller evolved, the code became increasingly cumbersome, littered with debugging filth that I never cleaned up and odd coding patterns I had picked up over the years. My understanding of the C++ language was woefully incomplete as well (as opposed to now, when it is still incomplete but not woefully so), which resulted in Khyller being essentially a C project that had a couple of classes in it.
<img align="left" src="static/s-aeon.png" /> Sometime in 2006 or 2007, I abandoned Khyller and rebuilt the entire thing from scratch, resulting in Aeon. Aeon was substantially cleaner in code than Khyller but still fairly hard to work with, and it lacked a few of the more arcane features I had originally written (for example, the ability to convert any quest into a download quest). In addition, the code still had some stability problems... it turns out that Aeon's concurrency primitives were simply incorrect. I had derived the concept of a mutex myself, before taking any real computer engineering classes, but had implemented it incorrectly. I made the race window as small as possible, but Aeon would still randomly crash after running seemingly fine for a few days.
At the time of its inception, Aeon was also called newserv, and you may find some beta releases floating around the Internet with filenames like `newserv-b3.zip`. I had released betas 1, 2, and 3 before I released the entire source of beta 5 and stopped working on the project when I went to college. This was around the time when I switched from writing software primarily on Windows to primarily on macOS and Linux, so Aeon beta 5 was the last server I wrote that specifically targeted Windows. (newserv, which you're looking at now, is difficult to compile on Windows but does work.)
<img align="left" src="static/s-newserv.png" /> After a long hiatus from PSO and much professional and personal development in my technical abilities, I was reminiscing sometime in October 2018 by reading my old code archives. Somehow inspired when I came across Aeon, I spent a weekend and a couple more evenings rewriting the entire project again, cleaning up ancient patterns I had used eleven years ago, replacing entire modules with simple STL containers, and eliminating even more support files in favor of configuration autodetection. The code is now suitably modern and stable, and I'm not embarrassed by its existence, as I am by Aeon beta 5's source code and my archive of Khyller (which, thankfully, no one else ever saw).
## Other server projects
Independently of this project, there are many other PSO servers out there. Those that I know of that are (or were) public are listed here in approximate chronological order:
* (Early 2000s) **[Schtserv](https://schtserv.com/)**: The first public-access PSO server, written in Delphi by Schthack. Schtserv is the only other unofficial server to support Episode 3, their implementation of which is based on newserv's (which is based on Sega's).
* (2005) **Khyller**: An early attempt of mine to support PSO PC, GC, and BB. See above for more details.
* (2006) **Aeon**: My second attempt. Better than Khyller, but still unreliable.
* (2008) **Tethealla**: A fairly extensive implementation of PSOBB, written in C by Sodaboy. The public version of Tethealla has been [officially disowned](https://www.pioneer2.net/community/threads/tethealla-server-forums-removal.26365/) as it is now more than 15 years old, but closed-source development continues. [Ephinea](https://ephinea.pioneer2.net/) is the continuation of this project. Several other modern PSOBB servers are forks of the initial public version of Tethealla as well.
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server, written in C by BlueCrab.
* (2015) **[Archon](https://github.com/dcrodman/archon)**: A PSOBB server written in Go by Drew Rodman.
* (2015) **[Idola](https://github.com/HybridEidolon/idolapsoserv)**: A PSOBB server written in Rust by HybridEidolon. Functionality status unknown; the project has been archived.
* (2017) **[Aselia](https://github.com/Solybum/Aselia)**: A PSOBB server written in C# by Soly. It seems this was planned to be open-source at some point, but that has not (yet) happened.
* (2018) **newserv**: This project right here.
* (2019) **[Mechonis](https://gitlab.com/sora3087/mechonis)**: A PSOBB server with a microservice architecture written in TypeScript by TrueVision.
* (2020) **[Booma.Server](https://github.com/HelloKitty/Booma.Server)**: A PSOBB server written in C# by Glader, with Soly's help.
* (2021) **[Phantasmal World](https://github.com/DaanVandenBosch/phantasmal-world)**: A set of PSO tools, including a web-based model viewer and quest builder, and a PSO server, written by Daan Vanden Bosch.
* (2021) **[Elseware](http://git.sharnoth.com/jake/elseware)**: A PSOBB server written in Rust by Jake.
## Using newserv in other projects
You are free to use code from newserv in your own open-source projects; the only condition is that the contents of the LICENSE file must be included in your project if you use code from newserv. Your project does not also have to use the MIT license; you can use any license you want.
If you want to use parts of newserv in your project, there are two easy ways to do so with proper licensing:
* If you're using a lot of code from newserv, you can put a copy of newserv's LICENSE file in your repository alongside your own license file, or include the contents of newserv's license in your own license file.
* If you're only using a few files from newserv, you can copy and paste the contents of the LICENSE file into a comment at the beginning of each copied file.
Some of the more likely useful files are:
* **src/BattleParamsIndex.hh**: Format of BattleParamEntry files
* **src/CommandFormats.hh**: Complete listing of all network commands used in all known versions of the game, and their formats
* **src/CommonItemSet.hh/cc**: Format of ItemPT files, shop definition files, and tekker adjustment tables
* **src/Compression.hh/cc**: PRS and BC0 compression and decompression algorithms
* **src/DCSerialNumbers.hh/cc**: PSO DC serial number validation algorithm and serial number generator
* **src/ItemData.hh**: Item format reference
* **src/ItemCreator.hh/cc**: Reverse-engineered item generator from Episodes 1&2 (used for all versions)
* **src/ItemParameterTable.cc**: Format of many structures in ItemPMT.prs (see BinaryItemParameterTableT)
* **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/MagEvolutionTable.cc**: Format of ItemMagEdit.prs
* **src/QuestScript.cc**: Complete listing of all quest opcodes on all versions, along with their arguments and behavior
* **src/RareItemSet.hh/cc**: Format of ItemRT files (rare item drop tables)
* **src/SaveFileFormats.hh**: Definitions of save file structures for all versions
* **src/Episode3/DataIndexes.hh**: Episode 3 file structures, including card definition format and map/quest format
* **system/tables/names-v4.json**: Names of all items, indexed by the first 3 bytes of data1
## Contributing to newserv
The goals of this project are:
* Build stable, extensible PSO server software that includes all vanilla functionality as well as optional modern conveniences, features, and cheats.
* Document the internals of PSO's network protocol, file formats, and game mechanics. This is mainly done through comments in the code.
This is a personal project; there is no official development team, official website, or official instance of newserv. Issues and pull requests are certainly welcome, but please only add content (e.g. quests, patches, client functions) that you've created, is already public, or you have permission to release publicly.
No AI agents have been used in building, documenting, testing, or debugging this project, and any PRs authored by AI agents will be rejected.
# Compatibility
newserv is compatible with all versions of PSO, including all known development prototypes. For a full list of versions, see the [memory patches and client functions](#memory-patches-and-client-functions) section.
There are a few version-specific quirks to be aware of:
* PC NTE is the only version of PSO that doesn't have any way to identify the player's account - there is no serial number or username. For this reason, AllowUnregisteredUsers must be enabled in config.json to support PC NTE, and PC NTE players receive a random Guild Card number every time they connect. To prevent abuse, PC NTE support can be disabled in config.json.
* Episode 3 Trial Edition battles are not well-tested; some things may not work. See notes/ep3-nte-differences.txt for a list of known differences between Trial Edition and the final version. Trial Edition and non-Trial-Edition players cannot battle each other.
* PSO Xbox connects through Xbox Live, so you can't easily host a private server for the Xbox version of the game. See the [how to connect](#pso-xbox) section.
# Setup
## Server setup
Currently newserv works on macOS, Windows, and Ubuntu Linux. It will likely work on other Linux flavors too.
### Windows/macOS
1. Download the latest release.zip file from the [releases page](https://github.com/fuzziqersoftware/newserv/releases).
2. Extract the contents of the archive to some location on your computer.
3. Go into the system/ folder, open config.json in a text editor, and edit it to your liking. There are comments in the file that describe what all the options do. Most of the options can be left alone if you want default behavior, but on Windows, you must change LocalAddress and ExternalAddress.
4. (Optional) If you plan to play Blue Burst on newserv, set up the patch directory. See [client patch directories](#client-patch-directories) for details.
5. Run the newserv executable.
### Linux
There are currently no precompiled releases for Linux. To run newserv on Linux, you'll have to build it from source - see the section below.
### Building from source (macOS/Linux)
To build on macOS or Linux:
1. Install the dependencies needed for your platform:
* macOS: `brew install cmake asio libiconv`
* Linux: `sudo apt-get install cmake libasio-dev` (or use your Linux distribution's package manager)
2. Build and install [phosg](https://github.com/fuzziqersoftware/phosg) and [resource_dasm](https://github.com/fuzziqersoftware/resource_dasm).
3. Run `cmake . && make` in the newserv directory.
After building newserv, edit system/config.example.json as needed **and rename it to system/config.json** (note that this step is not necessary for the precompiled releases), set up [client patch directories](#client-patch-directories) if you're planning to play Blue Burst, then run `./newserv` in newserv's directory.
The server has an interactive shell which can be used to make changes, such as managing user accounts, updating the server's configuration, managing Episode 3 tournaments, and more. Type `help` and press Enter to see all the commands.
On Linux and macOS, the server also responds to SIGUSR1 and SIGUSR2. SIGUSR1 does the equivalent of the shell's `reload config` command, which reloads config.json but not any dependent files (so quests, Episode 3 maps, etc. will not be reloaded). SIGUSR2 does the equivalent of the shell's `reload all` command, which reloads everything.
To use newserv in other ways (e.g. for translating data), see the end of this document.
### Building from source (Windows)
The current version of newserv is cross-compiled using mingw-w64 on a macOS build machine, with the necessary libraries manually installed. Setting up such a build environment is tedious and not recommended; it's recommended to just use a release version instead.
Here is a rough outline of the Windows build process. You should only attempt this yourself if you're familiar with setting up build environments and can deal with issues you may encounter along the way.
1. Install recent versions of MinGW and CMake.
2. Build and install zlib, libiconv, asio, phosg, and resource_dasm into your MinGW environment.
3. Clone the newserv repository with symlinks enabled: `git clone -c core.symlinks=true https://github.com/fuzziqersoftware/newserv.git`
4. Build newserv via CMake.
## Client patch directories
newserv implements a patch server for PSO PC and PSO BB game data. Any file or directory you put in the system/patch-bb or system/patch-pc directories will be synced to clients when they connect to the patch server.
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, `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.
For BB clients, newserv reads some files out of the patch data to implement game logic, so it's important that certain game files are synchronized between the server and the client. newserv contains defaults for these files in the system/maps/bb-v4 directory, but if these don't match the client's copies of the files, odd behavior will occur in games.
To make server startup faster, newserv caches the modification times, sizes, and checksums of the files in the patch directories. If the patch server appears to be misbehaving, try deleting the .metadata-cache.json file in the relevant patch directory to force newserv to recompute all the checksums. Also, in the case when checksums are cached, newserv may not actually load the data for a patch file until it's needed by a client. Therefore, modifying any part of the patch tree while newserv is running can cause clients to see an inconsistent view of it.
Patch directory contents are cached in memory. If you've changed any of these files, you can run `reload patch-indexes` in the interactive shell to make the changes take effect without restarting the server.
## How to connect
### PSO DC
Depending on the version of PSO DC that you have, the instructions to connect to a newserv instance will vary.
If you have NTE, USv1, EUv1, or EUv2 and a Broadband Adapter, edit the broadband DNS address to newserv's IP address with newserv's DNS server running. Otherwise, it is necessary to patch the disc or use a codebreaker code to remove the Hunter License server check and/or redirect PSO to the newserv instance. Patching the disc or creating a codebreaker code is beyond the scope of this document.
### PSO DC on Flycast
If you're emulating PSO DC, the NTE, USv1, EUv1, and EUv2 versions will connect to newserv by setting the following options in Flycast's `emu.cfg` file under `[network]`:
- DNS = Your newserv's server address (newserv's DNS server must be running on port 53)
- EmulateBBA = yes
- Enable = yes
It is also necessary to save any DNS information to the flash memory of the Dreamcast to use the BBA - the easiest way to do this is to use the website option in USv2 and then choose the save to flash option.
If the server is running on the same machine as Flycast, this might not work, even if you point Flycast's DNS queries at your local IP address (instead of 127.0.0.1). In this case, you can modify the loaded executable in memory to make it connect anywhere you want. There is a script included with newserv that can do this on macOS; a similar technique could be done manually using scanmem on Linux or Cheat Engine on Windows. To use the script, do this:
1. Build and install [memwatch](https://github.com/fuzziqersoftware/memwatch).
2. Start Flycast and run PSO. (You must start PSO before running the script; it won't work if you run the script before loading the game.)
3. Run `sudo patch_flycast_memory.py <original-destination>`. Replace `<original-destination>` with the hostname that PSO wants to connect to (you can find this out by using Wireshark and looking for DNS queries). The script may take up to a minute; you can continue using Flycast while it runs, but don't start an online game until the script is done.
4. Run newserv and start an online game in PSO.
If you use this method, you'll have to run the script every time you start PSO in Flycast, but you won't have to run it again if you start another online game without restarting emulation.
If using JPv1, JPv2, or USv2, it is also necessary to remove the Hunter Licence server check, either with a disc patch or codebreaker code. Patching the disc or creating a codebreaker code is beyond the scope of this document.
### PSO PC
PSO PC has its connection addresses in `pso.exe`. Hex edit the executable with the connection address you want to connect to. Common server addresses to search for to replace are:
- pso20.sonic.isao.net
- sg207634.sonicteam.com
- pso-mp01.sonic.isao.net
- gsproduc.ath.cx
- sylverant.net
The version of PSO PC I have has the server addresses starting at offset 0x29CB34 in pso.exe. Change those addresses to "localhost" (without quotes) if you just want to connect to a locally-running newserv instance. Alternatively, you can add an entry to the Windows hosts file (C:\Windows\System32\drivers\etc\hosts) to redirect the connection to 127.0.0.1 (localhost) or any other IP address.
### PSO GC on a real GameCube
You can make PSO connect to newserv by setting the default gateway and DNS server addresses in the game's network settings to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube. If you're not playing PSO Plus or Episode III, this should be all you need to do, assuming you already set LocalAddress in config.json to your PC's private IP address.
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. There are a couple of ways to get around this.
Sodaboy described a fairly easy method, which is to forward the PSO and DNS ports in your router's configuration to your PC's private IP address (the PSO ports are in config.json, and are all TCP; the DNS port is 53 and is UDP). Then, set LocalAddress and ExternalAddress in config.json to your external IP address (from e.g. whatismyip.com). Most routers will let you connect to your public IP address even from within the local network, but the GameCube will think it's connecting to a different network, so it won't reject the connection. If you're concerned about security and don't want your server to be publicly accessible, you can use Windows Firewall or UFW on Linux block incoming connections on the ports you opened, except for connections from the IP addresses you specify.
Another method is to use two network interfaces on the same PC, and tell the GameCube to connect to the one that appears to be on a different network. For example, if your GameCube is on the 10.0.0.x subnet and your PC's address is 10.0.0.5, you can create a fake network adapter on your PC (or use an existing real one) that has an IP address on a different subnet than the GameCube, such as 192.168.0.8. Then, in PSO's network config, set the default gateway and DNS server addresses to 192.168.0.8, and set LocalAddress in config.json to 192.168.0.8, and PSO should connect. This is what I did back in the old days when I primarily developed software on Windows, but I haven't tried it in many years.
### PSO GC on a Wii or Wii U
Using a Wii or Wii U to connect to newserv requires the Wii or vWii to be softmodded. How to do this is beyond the scope of this document.
Nintendont includes BBA emulation and is compatible with all PSO GameCube versions except Episodes I&II Trial Edition. To use Nintendont, enable BBA emulation in Nintendont's settings and follow the instructions in the above section (PSO GC on a real GameCube).
Devolution includes modem emulation and is compatible with all PSO GameCube versions including Episodes I&II Trial Edition. newserv can act as a PPP server, which Devolution can directly connect to. To do this:
1. Enable the PPPRawListen option according to the comments in config.json.
2. Start newserv.
3. In the game's network settings, set the username and password to anything (they cannot be blank), and set the phone number to the number that newserv outputs to the console during startup. (It will be near the end of all the startup log messages.) If your Wii is on the same network as newserv, use the local number; otherwise, use the external number.
### PSO GC on Dolphin
If you're using the HLE BBA type, set the BBA's DNS server address to newserv's IP address and it should work. (If newserv is on the same machine as Dolphin, you will need to use an Action Replay code directed at 127.0.0.1 to connect, as PSO rejects DNS queries from the same IP address.) Set PSO's network settings the same as listed below.
If you're using the TAP (not tapserver) BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
If you're using the tapserver BBA or modem type, you can make it connect to a newserv instance running on the same machine via the tapserver interface. To do this:
1. In the GameCube pane of the Config window, set the SP1 device to Broadband Adapter (tapserver) or Modem Adapter (tapserver).
2. Click the "..." button next to the SP1 menu. If you're using the tapserver BBA, enter `127.0.0.1:5059` in the box. If you're using the tapserver modem, enter `127.0.0.1:5058` in the box. (If newserv isn't running on the same machine as Dolphin, replace 127.0.0.1 with newserv's IP address.)
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
4. Start an online game.
### PSO Xbox
Unfortunately, you can't easily host a private server for PSO Xbox because the Xbox version of the game tunnels its connections through Xbox Live. There is a modern replacement for Xbox Live named [Insignia](https://insignia.live/), which supports the three main PSO Xbox servers, but as of now does not support other private PSO servers.
### PSO BB
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's common for various BB clients to have different map files. It's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the [client patch directories](#client-patch-directories) section for instructions on setting this up.)
The original Japanese and US versions of PSO BB work with newserv (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)). To get them to connect to your server, do one of the following:
* Use a drop-in patcher like [AzureFlare](https://github.com/Repflez/AzureFlare).
* Edit your hosts file to redirect the client's destination address to localhost or your server's address.
* Edit psobb.exe to point to your newserv instance. The original clients are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at offset 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
### Allowing external players to connect
If you want to accept connections from outside your local network, you'll need to set ExternalAddress to your public IP address in the configuration file, and you'll likely need to open some ports in your router's NAT configuration - specifically, all the TCP ports listed in PortConfiguration in config.json.
For GC clients, you'll have to use newserv's built-in DNS server or set up your own DNS server as well. If you want external clients to be able to use your DNS server, you'll have to forward UDP port 53 to your newserv instance. Remote players can then connect to your server by entering your DNS server's IP address in their client's network configuration.
# Server feature configuration
## User accounts
By default, newserv does not require users to pre-register before playing; the server will instead automatically create an account the first time each player connects. These accounts have no special permissions. You can view, create, edit, and delete user accounts in the server's shell (run `help` in the shell to see how to do this).
A license is a set of credentials that a player can use to log in. There are six types of licenses:
* *DC NTE licenses* consist of a 16-character serial number and 16-character access key.
* *DC licenses* consist of an 8-character hex serial number and an 8-character access key.
* *PC licenses* are the same format as DC licenses, but are used for PC v2.
* *GC licenses* consist of a 10-digit decimal serial number, a 12-character access key, and a password of up to 8 characters.
* *XB licenses* consist of a gamertag of up to 16 characters, a 16-character hex user ID, and a 16-character hex account ID.
* *BB licenses* consist of a username of up to 16 characters and a password of up to 16 characters.
Each account may have multiple licenses. To add a license to an existing account, use `add-license` in the shell.
On BB, character data is scoped to the license, but system and Guild Card data is scoped to the account. That is, an account with multiple BB licenses can have more than 4 characters (up to 4 per license), but they will all share the same team membership and Guild Card lists.
You may want to give your account elevated privileges. To do so, run `update-account ACCOUNT-ID flags=root` (replacing ACCOUNT-ID with your actual account-id). You can also use update-account to edit other parts of the account; see the help text for more information.
## Installing quests
newserv automatically finds quests in the subdirectories of the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's Save Files option, just put them in one of the subdirectories there and name them appropriately. The subdirectories and their behaviors (e.g. in which game modes they should appear and for which PSO versions) is defined in the QuestCategories field in config.json.
Within the category directories, quest files should be named like `q###-VERSION-LANGUAGE.EXT` (although the `q` is ignored, and can be any letter). The fields in each filename are:
- `###`: quest number (this doesn't really matter; it should just be unique across the PSO version)
- `VERSION`: dn = Dreamcast NTE, dp = Dreamcast 11/2000 prototype, d1 = Dreamcast v1, dc = Dreamcast v2, pcn = PC NTE, pc = PC, gcn = GameCube NTE, gc = GameCube Episodes 1 & 2, gc3 = Episode 3 (see below), xb = Xbox, bb = Blue Burst
- `LANGUAGE`: j = Japanese, e = English, g = German, f = French, s = Spanish
- `EXT`: file extension (see table below)
For .dat files, the `LANGUAGE` token may be omitted. If it's present, then that .dat file will only be used for that language of the quest; if omitted, then that .dat file will be used for all languages of the quest.
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-gc-e.bin` and `q058-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, it knows this is the English version of the quest because the .bin filename ends with `-e` (even though the .dat filename does not), and it puts them in the Retrieval category because the files are within the retrieval/ directory within system/quests/.
Some quests have additional JSON metadata files that describe how the server should handle them. These metadata files are generally named similarly to their .bin and .dat counterparts, except the `VERSION` token may also be omitted if the metadata applies to all languages of the quest on all PSO versions. See the comments in system/quests/retrieval/q058.json for all of the available options and how to use them. Some of the options are:
- Disable or hide the quest if certain preceding quests aren't cleared or other conditions aren't met
- Enable the quest to be joined while in progress
- Override the common and/or rare item tables and set the allowed drop modes
Some quests may also include a .pvr file, which contains an image used in the quest. These files are named similarly to their .bin and .dat counterparts.
The GameCube and Xbox quest formats are very similar, but newserv treats them as different. If you want to use the same quest file for GameCube and Xbox clients, you can make one a symbolic link to the other.
There are multiple PSO quest formats out there; newserv supports all of them. It can also decode any known format to standard .bin/.dat format. Specifically:
| Format | Extension | Supported | Decode action |
|------------------|-----------------------|------------|------------------|
| Compressed | .bin and .dat | Yes | None (1) |
| Compressed Ep3 | .bin or .mnm | Yes (4) | None (1) |
| Uncompressed | .bind and .datd | Yes | compress-prs (2) |
| Uncompressed Ep3 | .bind or .mnmd | Yes (4) | compress-prs (2) |
| Source | .bin.txt and .dat | Yes | None (5) |
| VMS (DCv1) | .bin.vms and .dat.vms | Yes | decode-vms |
| VMS (DCv2) | .bin.vms and .dat.vms | Decode (3) | decode-vms (3) |
| GCI (decrypted) | .bin.gci and .dat.gci | Yes | decode-gci |
| GCI (with key) | .bin.gci and .dat.gci | Yes | decode-gci |
| GCI (no key) | .bin.gci and .dat.gci | Decode (3) | decode-gci (3) |
| GCI (Ep3 NTE) | .bin.gci or .mnm.gci | Decode (3) | decode-gci (3) |
| GCI (Ep3) | .bin.gci or .mnm.gci | Yes | decode-gci |
| DLQ | .bin.dlq and .dat.dlq | Yes | decode-dlq |
| DLQ (Ep3) | .bin.dlq or .mnm.dlq | Yes | decode-dlq |
| QST (online) | .qst | Yes | decode-qst |
| QST (download) | .qst | Yes | decode-qst |
*Notes:*
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
3. *Use the decode action to convert these quests to .bin/.dat format before putting them into the server's quests directory. If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
4. *Episode 3 quests don't go in the system/quests directory. See the [Episode 3 section](#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/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.
Quest contents are cached in memory, but if you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quest-index` in the interactive shell. The new quests will be available immediately, but any games with quests already in progress will continue using the old versions of the quests until those quests end.
## Item tables and drop modes
newserv supports server-side item generation on all game versions, except for the earliest DC prototypes (NTE and 11/2000). By default, the game behaves as it did on the original servers - on all versions except BB, item drops are controlled by the leader client in each game, and on BB, item drops are controlled by the server.
There are five different available behaviors for item drops:
* `disabled` (or `none`): No items will drop from boxes or enemies.
* `client`: The game leader generates items, all items are visible to all players, and any player may pick up any item. This is the default mode for all game versions, except this mode cannot be used if the game leader is on BB.
* `shared`: The server generates items, all items are visible to all players, and any player may pick up any item. This is the default mode if the game leader is on BB.
* `private`: The server generates items, but each player may get a different item from any box or enemy. If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are visible to everyone.
* `duplicate`: The server generates items, and each player will get the same item from any box or enemy, but there is one copy of each item for each player (and each player only sees their own copy of the item). If a player isn't in the same area as an enemy at the time it's defeated, they won't get any item from it. Items dropped by players are not duplicated and are visible to everyone.
In the `private` and `duplicate` modes, there is no incentive to pick up items before another player, since other players cannot pick up the items you see dropped from boxes and enemies. However, if you pick up an item and drop it later, it can then be seen and picked up by any player.
The drop mode can be changed at any time during a game with the `$dropmode` chat command. If the mode is changed after some items have already been dropped, the existing items retain their visibility (that is, items dropped in private mode still can't be picked up by other players since they were dropped before the mode was changed). You can configure which drop modes are used by default, and which modes players are allowed to choose, in config.json. See the comments above the AllowedDropModes and DefaultDropMode keys.
In the server drop modes, the item tables used to generate common items are in the `system/tables/common-table-*` files. The rare item tables are in the `rare-table-*.json` files. Unlike the original formats, it's possible to make each enemy drop multiple different rare items at different rates, though the default tables never do this.
## Cross-version play
All versions of PSO can see and interact with each other in the lobby. By default, newserv allows V1 and V2 players to play in games together, and allows GC and Xbox players to play in games together. You can change these rules to allow all versions to play in games together, or to prevent versions from playing in games together, with the CompatibilityGroups setting in config.json.
There are several cross-version restrictions that always apply regardless of the compatibility groups setting:
* DC V1 players cannot join DC V2 games if the game creator didn't choose to allow them.
* DC V1 players cannot join games if the difficulty level is set to Ultimate or the game mode is Battle or Challenge.
* Only GC, Xbox, and BB players can join games in Episode 2.
* Only BB players can join games in Episode 4.
* Episode 3 players cannot join non-Episode 3 games, and vice versa.
V1/V2 compatibility and GC/Xbox compatibility are well-tested, but other situations are not. Not much attention has been given yet to how items should be handled across major versions; if you enable V2/GC compatibility, for example, there will likely be bugs. Please report such bugs as GitHub issues.
In cross-version play, when any of the server drop modes are used, the server uses the drop tables corresponding to the leader's version and section ID. (For example, if a DC V1 player is the game leader, rare-table-v1.json will be used, even after V2 players join.) If a BB player is the leader and the `client` drop mode is used, the server generates items as if it were in `shared` mode.
## Server-side saves
newserv has the ability to save character data on the server side. For PSO BB, this is required of course, but this feature can also be used on other PSO versions.
Each account has 4 BB character slots and 16 non-BB character file slots. The non-BB slots are independent of the BB slots, and can be accessed with the `$savechar <slot>` and `$loadchar <slot>` commands (slots are numbered 1 through 16). `$savechar` copies the character you're currently playing as and saves the data on the server, and `$loadchar` does the reverse, overwriting your current character with the data saved on the server. Note that you can load a character that was saved from a different version of PSO, which allows you to easily transfer characters between games. On v1 and v2, changes done by `$loadchar` will be undone if you join a game; to permanently save your changes, disconnect from the lobby after using the command.
You can see basic information about a character saved on the server (without affecting your current character) by using `$checkchar <slot>`. You can delete a previously-saved character with `$deletechar <slot>`.
There is also the command `$bbchar <username> <password> <slot>`, which behaves similarly to `$savechar` but writes the character data to a BB character slot in a different account instead (slots are numbered 1 through 4). This can be used to "upgrade" a character to BB from an earlier version.
Exactly which data is saved and loaded depends on the game version:
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/Challenge |
|----------------------|-----------|-----------|---------------|-------------|------|------------------|
| PSO DC v1 prototypes | Yes | Yes | No | No | No | N/A |
| PSO DC v1 | Yes | Yes | No | No | No | N/A |
| PSO DC v2 | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO PC (v2) | Yes | Yes | No | No | No | Save only |
| PSO GC NTE | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC (not Plus) | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC Plus (1) | Save only | Save only | No | No | No | Save only |
| PSO GC Ep3 (1) | No | Save only | No | No | No | Save only |
| PSO Xbox | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO BB | Yes | Yes | Yes | Yes | Yes | Yes |
*Notes*:
1. *If EnableSendFunctionCallQuestNumber is enabled in config.json, then $savechar and $loadchar can save and restore all character data on these versions, just like on GC non-Plus. Episode 3 characters exist in a separate namespace; that is, you can't use $savechar and $loadchar to convert an Ep3 character to non-Ep3, or vice versa.*
## Episode 3 features
newserv supports many features unique to Episode 3:
* CARD battles. Not every combination of abilities has been tested yet, so if you find a feature or card ability that doesn't work like it's supposed to, please make a GitHub issue and describe the situation (the attacking card(s), defending card(s), and ability or condition that didn't work).
* Spectator teams.
* Tournaments. (But they work differently than Sega's tournaments did - see below)
* Downloading quests.
* Trading cards.
* Participating in card auctions. (The auction contents must be configured in config.json.)
* Decorations in lobbies. Currently only images are supported; the game also supports loading custom 3D models in lobbies, but newserv does not implement this (yet).
### Battle records
After playing a battle, you can save the record of the battle with the `$saverec` command. You can then replay the battle later by using the `$playrec` command in a lobby - this will create a spectator team and play the recording of the battle as if it were happening in realtime. Note that there is a bug in older versions of Dolphin that seems to be frequently triggered when playing battle records, which causes the emulator to crash with the message `QObject::~QObject: Timers cannot be stopped from another thread`. To avoid this, use the latest version of Dolphin.
### Tournaments
Tournaments work differently than they did on Sega's servers. Tournaments can be created with the `create-tournament` shell command, which enables players to register for them. (Use `help` to see all the arguments - there are many!) The `start-tournament` shell command starts the tournament (and prevents further registrations), but this doesn't schedule any matches. Instead, players who are ready to play their next match can all stand at the 4-player battle table near the lobby warp in the same CARD lobby, and the tournament match will start automatically.
These tournament semantics mean that there can be multiple matches in the same tournament in play simultaneously, and not all matches in a round must be complete before the next round can begin - only the matches preceding each individual match must be complete for that match to be playable.
The Meseta rewards for winning tournament matches can be configured in config.json.
### Episode 3 files
Episode 3 state and game data is stored in the system/ep3 directory. The files in there are:
* card-definitions.mnr: Compressed card definition list, sent to Episode 3 clients at connect time. Card stats and abilities can be changed by editing this file.
* card-definitions.mnrd: Decompressed version of the above. If present, newserv will use this instead of the compressed version, since this is easier to edit.
* 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. 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.
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3-cards` or `reload ep3-maps` in the interactive shell to make the changes take effect without restarting the server.
## Memory patches and client functions
newserv supports sending compiled functions to run on the client, for most PSO versions. These functions are written in SH-4, PowerPC, or x86 assembly and compiled during server startup. This is generally used for applying code patches to the client, but can also be used to implement new functionality, since the functions may be run at any time. There are many options that control client function behavior (including whether they appear in the Patches menu or can be run via the `$patch` chat command); see system/client-functions/System/WriteMemory.s for full documentation.
In these files, you'll see `.versions` lines specifying which specific versions of the game the client function is compatible with. Some versions do not support receiving client functions at all. *Note: newserv uses the shorter GameCube versioning convention, where discs labeled DOL-XXXX-0-0Y are version 1.Y. The PSO community seems to use the convention 1.0Y in some places instead, but these are the same version. For example, the version that newserv calls v1.4 is the same as v1.04, and is labeled DOL-GPOJ-0-04 on the underside of the disc.*
The specific versions are:
| Game | VERS | CPU architecture |
|------------------------------|------|--------------------------------|
| PSO DC Network Trial Edition | 1OJ1 | Client functions not supported |
| PSO DC 11/2000 prototype | 1OJ2 | Client functions not supported |
| PSO DC 12/2000 prototype | 1OJ3 | Client functions not supported |
| PSO DC 01/2001 prototype | 1OJ4 | Client functions not supported |
| 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/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 |
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 (Plus) JP | 3OJ4 | PowerPC |
| PSO GC v1.5 (Plus) JP | 3OJ5 | PowerPC (1) |
| PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 (Plus) US | 3OE2 | PowerPC (1) |
| PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 Trial Edition | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | PowerPC (1) |
| PSO GC Ep3 EU | 3SP0 | PowerPC (1) |
| PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.11 | 59NJ | x86 |
| PSO BB JP 1.25.13 | 59NL | x86 |
| PSO BB Tethealla | 59NL | x86 |
*Notes:*
1. *Client functions are only supported on these versions if EnableSendFunctionCallQuestNumbers is set in config.json. See the comments there for more information.*
newserv comes with a set of patches for many of the above versions, in system/client-functions/.
### DOL loader
You can put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWordGC.ppc.s, WriteMemoryGC.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
I mainly built the DOL loading functionality for documentation purposes. By now, there are many better ways to load homebrew code on an unmodified GameCube, but to my knowledge there isn't another open-source implementation of this method in existence.
## Using newserv as a proxy
If you want to play online on remote servers rather than running your own server, newserv also includes a PSO proxy. Currently this works with PSO GC and may work with PC and DC; it also works with some BB clients in specific situations.
To use the proxy for PSO DC, PC, or GC, add an entry to the corresponding ProxyDestinations dictionary in config.json, then run newserv and connect to it as normal (see below). You'll see a "Proxy server" option in the main menu, and you can pick which remote server to connect to.
To use the proxy for PSO BB, set the ProxyDestination-BB entry in config.json. If this option is set, it essentially disables the game server for all BB clients - all BB clients will be proxied to the specified destination instead. Unfortunately, because PSO BB uses a different set of handlers for the data server phase and character selection, there's no in-game way to present the player with a list of options, like there is on PSO PC and PSO GC.
When you're on PSO DC, PC, GC, or Xbox and are connected to a remote server through newserv's proxy, choosing the Change Ship or Change Block action from the lobby counter will send you back to newserv's main menu instead of the remote server's ship or block select menu. You can go back to the server you were just on by choosing it from the proxy server menu again.
There are many options available when starting a proxy session. All options are off by default unless otherwise noted. The options are:
* **Chat commands**: enables chat commands in the proxy session (on by default).
* **Chat filter**: enables escape sequences in chat messages and info board (on by default).
* **Player notifications**: shows a message when any player joins or leaves the game or lobby you're in.
* **Block pings**: blocks automatic pings sent by the client, and responds to ping commands from the server automatically.
* **Infinite HP**: automatically heals you whenever you get hit. An attack that kills you in one hit will still kill you, however.
* **Infinite TP**: automatically restores your TP whenever you use any technique.
* **Switch assist**: unlocks doors that require two or four players in a one-player game, when you step on one of the switches.
* **Infinite Meseta** (Episode 3 only): gives you 1,000,000 Meseta, regardless of the value sent by the remote server.
* **Block events**: disables holiday events sent by the remote server.
* **Block patches**: prevents any B2 (client function / patch) commands from reaching the client.
* **Save files**: saves copies of several kinds of files when they're sent by the remote server. The files are written to the current directory (which is usually the directory containing the system/ directory). Saved files can then be used with newserv by just moving the file into the appropriate place in the system/ directory and renaming it appropriately. These kinds of files can be saved:
* Online quests and download quests (saved as .bin/.dat files)
* GBA games (saved as .gba files)
* Client functions / patches (saved as .bin files and disassembled as .txt 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)
* Episode 3 media updates (saved as .gvm, .bml, or .bin files)
The remote server will probably try to assign you a Guild Card number that doesn't match the one you have on newserv. The proxy rewrites the commands in transit to make it look like the remote server assigned you the same Guild Card number as you have on newserv, but if the remote server has some external integrations (e.g. forum or Discord bots), they will use the Guild Card number that the remote server believes it has assigned to you. The number assigned by the remote server is shown to you when you first connect to the remote server, and you can retrieve it in lobbies or during games with the `$li` command.
Some chat commands (see below) have the same basic function on the proxy but have different effects or conditions. In addition, there are some server shell commands that affect clients on the proxy (run `help` in the shell to see what they are). If there's only one proxy session open, the shell's proxy commands will affect that session. Otherwise, you'll have to specify which session to affect with the `on` prefix - to send a chat message in C-17's session, for example, you would run `on C-17 chat ...`.
## Chat commands
newserv supports a variety of commands players can use by chatting in-game. Any chat message that begins with `$` is treated as a chat command. (If you actually want to send a chat message starting with `$`, type `$$` instead.) On the DC 11/2000 prototype, `@` is used instead of `$` for all chat commands, since `$` does not appear on the English virtual keyboard.
Some commands only work for clients not in proxy sessions. The chat commands are:
* Information commands
* `$li`: Show basic information about the lobby or game you're in. If you're on the proxy, show information about your connection instead (remote Guild Card number, client ID, etc.).
* `$si`: Show basic information about the server.
* `$ping`: Show round-trip ping time from the server to you. On the proxy, show the ping time from you to the proxy and from the proxy to the server.
* `$matcount` (non-proxy only): Show how many of each type of material you've used.
* `$killcount` (non-proxy only): Show the kill count on your currently-equipped weapon. If you're in a game and not on BB, the value is only accurate at the time the item enters the game.
* `$itemnotifs <mode>`: Enable item drop notification messages. If the game has private drops enabled, you will only see a notification if the dropped item is visible to you; you won't be notified of other players' drops. The modes are:
* `off`: No notifications are shown.
* `rare`: You are notified when a rare item drops.
* `on`: You are notified when any item drops, except Meseta.
* `every`: You are notified when any item drops, including Meseta.
* `$announcerares`: Enable or disable announcements for your rare item finds. This determines whether rare items you find will be announced to the game and server, not whether you will see announcements for others finding rare items.
* `$what` (non-proxy only): Show the type, name, and stats of the nearest item on the ground.
* `$where`: Show your current floor number and coordinates. Mainly useful for debugging.
* `$qfread <field-name>` (non-proxy only): Show the value of a quest counter in your player data. The field names are defined in config.json.
* Basic debugging commands (special permissions not required)
* `$whatobj` and `$whatene` (non-proxy only): Tells you what the closest object or enemy spawn point is to your position, along with its coordinates and object or enemy ID. The full definition is also printed to the server's log.
* `$qcheck <flag-num>` (non-proxy only): Show the value of a quest flag. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only).
* `$qgread <flag-num>` (non-proxy only): Show the value of a quest counter ("global flag").
* `$sound <sound-id>`: Play the given sound (GC only).
* Restricted debugging commands (`$debug` permission required)
* `$debug`: Enable debug mode. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
* You'll be able to use the rest of the commands in this section.
* You'll see in-game messages from the server when you take some actions, like killing enemies, opening boxes, or flipping switches.
* You'll see the rare seed value and floor variations when you join a game.
* You'll be placed into the last available slot in lobbies and games instead of the first, unless you're joining a BB solo-mode game.
* You'll be able to run any client function with `$patch`, not only those that are marked visible.
* You'll be able to join games with any PSO version, not only those for which cross-version play is normally enabled. See the "Cross-version play" section above for details on this.
* `$readmem <address>`: Read 4 bytes from the given address and show you the values.
* `$writemem <address> <data>`: Write data to the given address. Data is not required to be any specific size.
* `$nativecall <address> [arg1 ...]` (GC only): Call a native function on your client. Only arguments passed in registers are supported; calling functions that take many arguments is not supported.
* `$quest <number>` (non-proxy only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. `$debug` is not required for this command if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
* `$qcall <function-id>`: Call a quest function on your client.
* `$qset <flag-num>` or `$qclear <flag-num>`: Set or clear a quest flag for everyone in the game. If you're in the lobby and on BB, set or clear the saved value of a quest flag in your character file.
* `$qgwrite <flag-num> <value>` (non-proxy only): Set the value of a quest counter ("global flag") for yourself.
* `$qsync <reg-num> <value>`: Set a quest register's value for yourself only. `<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.
* `$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).
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy, this will not work if the remote server controls item drops. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies and item drops. On the proxy, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
* `$swa`: Enable or disable switch assist. When enabled, the server will unlock two-player and four-player doors in non-quest games when you step on any of the required switches.
* `$exit`: If you're in a lobby, send you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, send you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
* `$patch <name>`: Run a client function. `<name>` must exactly match the name of a client function on the server.
* Character data commands (non-proxy only)
* `$switchchar <slot>` (BB only): Switch to a different character from your account without logging out.
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$loadchar <slot>`: Load character data from the specified slot on the server, and replace your current character with it. See the [server-side saves section](#server-side-saves) for more details.
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the [server-side saves section](#server-side-saves) for more details.
* `$checkchar [slot]`: Tells you basic information about a server-side character previously saved using `$savechar`. If `slot` is not given, tells you which slots are used and which are free.
* `$deletechar <slot>`: Deletes a server-side character previously saved using `$savechar`.
* `$edit <stat> <value>`: Modify your character data. See the [using $edit](#using-edit) section for details.
* Blue Burst player commands (non-proxy only)
* `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
* `$save`: Save your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
* Game state commands (non-proxy only)
* `$maxlevel <level>`: Set the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
* `$minlevel <level>`: Set the minimum level for players to join the current game.
* `$password <password>`: Set the game's join password. To unlock the game, run `$password` with nothing after it.
* `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the [item tables and drop modes section](#item-tables-and-drop-modes) for more information.
* `$persist`: Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The states of enemies, objects, and switches will be saved, and items left on the floor will not be deleted. (But if you're in the private or duplicate drop mode, items dropped by enemies are deleted - to make sure a certain item won't be deleted, you can pick it up and drop it again.) If the game is empty for too long (15 minutes by default), it is then deleted.
* Episode 3 commands (non-proxy only)
* `$spec`: Toggle the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they are sent back to the lobby.
* `$inftime`: Toggle infinite-time mode. Must be used before starting a battle. If infinite-time mode is on, the overall and per-phase time limits will be disabled regardless of the values chosen during battle rules setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Set override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them.
* `$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 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 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
* `$event <event>`: Set the current holiday event in the current lobby. Holiday events are documented in the "Using $event" item in the information menu. If you're on the proxy, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
* `$allevent <event>` (non-proxy only): Set the current holiday event in all lobbies.
* `$song <song-id>` (Episode 3 only): Play a specific song in the current lobby.
* Administration commands (non-proxy only)
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. On BB, the message appears in the scrolling top bar.
* `$ann!`, `$ann?`, `$ann?!`: Same as `$ann`, but with `?`, omits the sender's name, and with `!`, sends the message as a Simple Mail message instead of on-screen text.
* `$silence <identifier>`: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number.
* `$kick <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
* `$ban <duration> <identifier>`: Ban a player. The duration should be of the form `10m` (minutes), `10h` (hours), `10d` (days), `10w` (weeks), `10M` (months), or `10y` (years). (Numbers other than 10 may be used, of course.) As with `$kick`, the identifier may be the player's name or Guild Card number.
### Using $edit
The $edit command modifies your character data. This command doesn't work on V3 (GameCube/Xbox). If you are on V1 or V2 (DC or PC, not BB), your changes will be undone if you join a game - to save your changes, disconnect from the lobby.
Some subcommands are always available. They are:
* `$edit mat reset power`: Clear your usage of power materials (BB only)
* `$edit mat reset mind`: Clear your usage of mind materials (BB only)
* `$edit mat reset evade`: Clear your usage of evade materials (BB only)
* `$edit mat reset def`: Clear your usage of def materials (BB only)
* `$edit mat reset luck`: Clear your usage of luck materials (BB only)
* `$edit mat reset hp`: Clear your usage of HP materials (BB only)
* `$edit mat reset tp`: Clear your usage of TP materials (BB only)
* `$edit mat reset all`: Clear your usage of all materials except HP and TP (BB only)
* `$edit mat reset every`: Clear your usage of all materials including HP and TP (BB only)
* `$edit namecolor AARRGGBB`: Set your name color (AARRGGBB specified in hex)
* `$edit language L`: Set your language (Generally only useful on BB; values for L: J = Japanese, E = English, G = German, F = French, S = Spanish, B = Simplified Chinese, T = Traditional Chinese, K = Korean)
* `$edit name NAME`: Set your character name
* `$edit npc NPC-NAME`: Set or remove an NPC skin on your character (use `none` to remove a skin). The NPC names are:
* On all versions except DCv1 and early prototypes: `ninja`, `rico`, `sonic`, `knuckles`, `tails`
* On GC, Xbox, and BB: `flowen`, `elly`
* On BB only: `momoka`, `irene`, `guild`, `nurse`
* `$edit secid SECID-NAME`: Set your section ID (cheat mode is required unless your character is Level 1)
The remaining subcommands are only available if cheat mode is enabled on the server. They are:
* `$edit atp N`: Set your ATP to N until stats are updated (e.g. by leveling up)
* `$edit mst N`: Set your MST to N until stats are updated
* `$edit evp N`: Set your EVP to N until stats are updated
* `$edit dfp N`: Set your DFP to N until stats are updated
* `$edit ata N`: Set your ATA to N until stats are updated
* `$edit lck N`: Set your LCK to N until stats are updated
* `$edit hp N`: Set your HP to N until stats are updated
* `$edit meseta N`: Set the amount of Meseta in your inventory
* `$edit exp N`: Set your total amount of EXP (does not affect level)
* `$edit level N`: Set your current level (recomputes stats, but does not affect EXP)
* `$edit tech TECH-NAME LEVEL`: Set the level of one of your techniques
## REST API
newserv has an optional HTTP server that provides a way to programmatically get data from the server in realtime. This is intended for use with external integrations; for example, a web site could query this API to get the current player count to display on the home page.
The HTTP server is disabled by default, and you have to explicitly enable it in config.json if you want this functionality. **If you enable it, make sure that the HTTP port can't be accessed from the public Internet.** The API provides a lot of internal data about players and games, and it should only be accessed by programs that you've written or that you trust.
To enable the HTTP server, add a port number in the HTTPListen list in config.json. The HTTP server will listen on that port.
All returned data is JSON-encoded, and all request data (for POST requests) must also be JSON-encoded with the `Content-Type: application/json` header.
The HTTP server has the following endpoints:
* `GET /`: Returns the server's build date and revision.
* `GET /y/data/ep3-cards`: Returns the Episode 3 card definitions.
* `GET /y/data/ep3-cards-trial`: Returns the Episode 3 Trial Edition card definitions.
* `GET /y/data/common-tables`: Returns the parameters for generating common items (ItemPT files). This endpoint returns a lot of data and can be slow!
* `GET /y/data/rare-tables`: Returns a list of rare table names.
* `GET /y/data/rare-tables/<TABLE-NAME>` (for example, `/y/data/rare-tables/rare-table-v4`): Returns the contents of a rare item table.
* `GET /y/data/quests`: Returns metadata about all available quests and quest categories.
* `GET /y/data/config`: Returns the server's configuration file.
* `GET /y/accounts`: Returns information about all registered accounts.
* `GET /y/clients`: Returns information about all connected clients on the game server.
* `GET /y/proxy-clients`: Returns information about all connected clients on the proxy.
* `GET /y/lobbies`: Returns information about all lobbies and games.
* `GET /y/server`: Returns information about the server.
* `GET /y/summary`: Returns a summary of the server's state, connected clients, active games, and proxy sessions.
* `WS /y/rare-drops/stream`: WebSocket endpoint that sends messages whenever an announceable rare item is dropped in any game. See below.
* `POST /y/shell-exec`: Runs a server shell command. Input should be a JSON dict of e.g. `{"command": "announce hello"}`; response will be a JSON dict of `{"result": "<result text>"}` or an HTTP error.
### Rare drop stream endpoint
The `/y/rare-drops/stream` endpoint provides a way to implement a drop log in e.g. Discord. For every announceable rare item, a message is sent to all connected clients on this endpoint. (Announceable rare items are items for which an in-game or server-wide text message is sent announcing the find.)
Upon connecting, you'll get the message `{"ServerType": "newserv"}`. After that, when a rare item announcement is sent, you'll get a message like this:
```
{
"PlayerAccountID", 12345,
"PlayerName", "SONIC",
"PlayerVersion", "GC_V3",
"GameName", "ttf",
"GameDropMode", "SERVER_PRIVATE",
"ItemData", "03000000 00010000 00000000 (0021002C) 00000000",
"ItemDescription", "Monomate x1",
"NotifyGame", true,
"NotifyServer", false,
}
```
# Non-server features
newserv has many CLI options, which can be used to access functionality other than the game server and proxy. Run `newserv help` to see a full list of the options and how to use each one.
The data formats that newserv can convert to/from are:
| Format | Encode/compress action | Decode/extract action |
|-------------------------------------|-------------------------------|-------------------------------|
| PRS compression | `compress-prs` | `decompress-prs` |
| PR2/PRC compression | `compress-pr2` | `decompress-pr2` |
| BC0 compression | `compress-bc0` | `decompress-bc0` |
| Raw encrypted data | `encrypt-data` | `decrypt-data` |
| Episode 3 command mask | `encrypt-trivial-data` | `decrypt-trivial-data` |
| Challenge Mode rank text | `encrypt-challenge-data` | `decrypt-challenge-data` |
| PSO DC quest file (.vms) | None | `decode-vms` |
| PSO GC quest file (.gci) | None | `decode-gci` |
| Download quest file (.dlq) | None | `decode-dlq` |
| Server quest file (.qst) | `encode-qst` | `decode-qst` |
| PSO DC save file (.vms) | `encrypt-vms-save` | `decrypt-vms-save` |
| PSO PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO Xbox save file | None | `decrypt-xbox-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive (.afs) | None | `extract-afs` |
| BML archive (.bml) | None | `extract-bml` |
| PPK archive (.ppk) | None | `extract-ppk` |
| GSL archive (.gsl) | `generate-gsl` | `extract-gsl` |
| GVM texture (.gvm) | `encode-gvm` | None (use resource_dasm) |
| Bitmap font (.fon) | `encode-bitmap-font` | `decode-bitmap-font` |
| Text archive | `encode-text-archive` | `decode-text-archive` |
| Unicode text set | `encode-unicode-text-set` | `decode-unicode-text-set` |
| Word Select data set | None | `decode-word-select-set` |
| Set data table | None | `disassemble-set-data-table` |
| Rare item table (AFS/GSL/JSON/HTML) | `convert-rare-item-set` | `convert-rare-item-set` |
| Item definitions (ItemPMT) | `encode-item-parameter-table` | `decode-item-parameter-table` |
There are several actions that don't fit well into the table above, which let you do other things:
* Compute the decompressed size of compressed PRS data without decompressing it (`prs-size`)
* Find the likely round1 or round2 seed for a corrupt save file (`salvage-gci`)
* Run a brute-force search for a decryption seed (`find-decryption-seed`)
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`, `generate-ep3-cards-html`)
* Format Blue Burst battle parameter files in a human-readable manner (`show-battle-params`)
* Convert item data to a human-readable description, or vice versa (`describe-item`)
* Show the server's item and level tables (`show-item-tables`, `show-level-tables`)
* Connect to another PSO server and pretend to be a client (`cat-client`)
* Generate or describe DC serial numbers (`generate-dc-serial-number`, `inspect-dc-serial-number`)
# Docker
Docker is new and mostly unsupported at this time. However, here are some best-effort steps to build and run in a docker container on Ubuntu Linux.
Tested on Ubuntu 22.04.4 LTS.
Note: You cannot have anything except this docker container using port 53 (DNS) on your server.
Install prerequisites
```
sudo apt install -y git
sudo apt install -y cmake. ## minimum version is 3.10. Check installed version with "cmake --version"
```
Clone repository
```
cd ~
git clone https://github.com/fuzziqersoftware/newserv/
cd ~/newserv
```
Build newserv. This will take a while. Don't forget the period at the end!
```
sudo docker build -t newserv .
```
Create persistent directories. Assuming you want to store the persistent data in your home directory
```
mkdir ~/newservPersist
mkdir ~/newservPersist/players
mkdir ~/newservPersist/teams
mkdir ~/newservPersist/licenses
```
Copy config file to config dir
```
cp ~/newserv/system/config.example.json ~/newservPersist/config.json
```
Edit config.json
```
nano ~/newservPersist/config.json
```
Pro tip:
Set "LocalAddress" to the static, LAN IP address of your server. If your server LAN IP is "192.168.0.10":
"LocalAddress": "192.168.0.10",
Set "ExternalAddress" to the WAN IP address of your network. If your WAN IP is "8.8.8.8":
"ExternalAddress": "8.8.8.8",
For Dolphin > Settings. Set SP1 to "Broadband Adapter (HLE)" Click [...] next to this, and set the DNS to the IP address of your server. Then start the game. Changes will not take affect if the game is running.
Docker run. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
docker run --name newserv -p 53:53/udp -p 5100:5100 -p 5110:5110 -p 5111:5111 -p 5112:5112 -p 9064:9064 -p 9100:9100 -p 9103:9103 -p 9300:9300 -p 11000:11000 -p 12000:12000 -p 12004:12004 -p 12005:12005 -v /etc/localtime:/etc/localtime:ro -v /home/changeme/newservPersist/config.json:/newserv/system/config.json -v /home/changeme/newservPersist/players:/newserv/system/players -v /home/changeme/newservPersist/teams:/newserv/system/teams -v /home/changeme/newservPersist/licenses:/newserv/system/licenses --restart no newserv:latest
```
Docker run host network mode. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
docker run --net host --name newserv -v /etc/localtime:/etc/localtime:ro -v /home/changeme/newservPersist/config.json:/newserv/system/config.json -v /home/changeme/newservPersist/players:/newserv/system/players -v /home/changeme/newservPersist/teams:/newserv/system/teams -v /home/changeme/newservPersist/licenses:/newserv/system/licenses --restart no newserv:latest
```
Docker compose. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
name: psonewserv
services:
newserv:
container_name: newserv
ports:
- 53:53/udp
- 5100:5100
- 5110:5110
- 5111:5111
- 5112:5112
- 9064:9064
- 9100:9100
- 9103:9103
- 9300:9300
- 11000:11000
- 12000:12000
- 12004:12004
- 12005:12005
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/changeme/newservPersist/config.json:/newserv/system/config.json
- /home/changeme/newservPersist/players:/newserv/system/players
- /home/changeme/newservPersist/teams:/newserv/system/teams
- /home/changeme/newservPersist/licenses:/newserv/system/licenses
restart: no ## Set to whatever you want.
image: newserv:latest
```
Docker compose host network mode. Remember to change /home/changeme/newservPersist to your persistent directory. Do not use aliases such as '~'
```
name: psonewserv
services:
newserv:
container_name: newserv
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/changeme/newservPersist/config.json:/newserv/system/config.json
- /home/changeme/newservPersist/players:/newserv/system/players
- /home/changeme/newservPersist/teams:/newserv/system/teams
- /home/changeme/newservPersist/licenses:/newserv/system/licenses
restart: no ## Set to whatever you want.
network_mode: host
image: newserv:latest
```
+67
View File
@@ -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())
+366 -13
View File
@@ -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
@@ -39,6 +41,7 @@ Version codes (from README.md):
4OEU: PSO Xbox US TU
4OPD: PSO Xbox EU Disc
4OPU: PSO Xbox EU TU
50YJ: PSO BB US 1.24.3
59NJ: PSO BB JP 1.25.11
59NL: PSO BB JP 1.25.13 (including the Tethealla client)
@@ -79,8 +82,33 @@ Disable item equip restrictions ("God of equip")
3OJ5 => 041050D4 38000005
3OJT => 0415BF50 38000005
3OP0 => 041052D4 38000005
5OYJ => 005C8C8F E9A7000000
59NJ => 005C9F35 E9A7000000
59NL => 005C9F31 E9A7000000
All items visible in Pioneer 2
3OE1 => 04102D88 38600000
Mags visible in Pioneer 2
5OYJ => 005D7053 EB04
59NJ => 005D8F27 EB04
59NL => 005D8F4B EB04
Disable pause menu background + offset
3OE1 => 0424BD5C 48000370
0428735C 4800000C
3OE2 => 0424CED8 48000370
042887D8 4800000C
5OYJ => 00713758 9090
0072D417 9090
0072D27E 90E9
59NJ => 00719C58 9090
00733C57 9090
00733ABE 90E9
59NL => 00719B54 9090
00733BA7 9090
00733A0E 90E9
All rareable enemies are rare
3OE0 => 040AC944 60000000 // Hildeblue
040C1B70 60000000 // Rappies
@@ -196,6 +224,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 +266,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 +281,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 +306,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 +369,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 +589,72 @@ 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
5OYJ => 006D3F7B mov dword [edi + 0x14C], 1
006D3F98 jmp +0x0B
59NJ => 006DA14B mov dword [edi + 0x14C], 1
006DA168 jmp +0x0B
59NL => 006DA113 mov dword [edi + 0x14C], 1
006DA130 jmp +0x0B
Allow loading corrupted save files
3OJ2 => 041FC784 38600007
041FC788 4E800020
@@ -557,8 +682,20 @@ Allow loading corrupted save files
041156D4 4E800020
60 frames per second
This does not adjust any logic or animations; everything just runs faster
3OE1 => 045CDEF8 00000001
This doesn't adjust any logic or animations; everything just runs faster
3OJT => 043F5AC0 38800001
3OJ2 => 043D8550 38800001
3OJ3 => 043DAF58 38800001
3OJ4 => 043DCDF8 38800001
3OJ5 => 043DCBA8 38800001
3OE0 => 043D9820 38800001
3OE1 => 043D9878 38800001
3OE2 => 043DCF78 38800001
3OP0 => 043DBA68 38800001
3SJT => 043567AC 38800001
3SE0 => 0438A804 38800001
3SJ0 => 043897B4 38800001
3SP0 => 0438B6D4 38800001
Show extended item info when targeting a dropped item
(Compiled from the ExtendedItemInfo patch, also written by me)
@@ -793,3 +930,219 @@ 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)
5OYJ => 008075C3 XXXXXXXX (count * 4 as little-endian dword)
008075DC XXXXXXXX (count as little-endian dword)
59NJ => 0080FA3F XXXXXXXX (count * 4 as little-endian dword)
0080FA58 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)
Disable HP reduction warning sound in Challenge mode
3OE1 => 04076A28 4E800020
Mag invincibility effect sparkliness modifier
(Default 003C; smaller values are more sparkly)
3OE1 => 801131C4 3860XXXX
+2 -1
View File
@@ -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
+1 -2
View File
@@ -4,7 +4,6 @@ import subprocess
import sys
from dataclasses import dataclass
version_tokens = ("3OJ2", "3OJ3", "3OJ4", "3OJ5", "3OE0", "3OE1", "3OE2", "3OP0")
@@ -62,7 +61,7 @@ def write_patches_for_code(
f.write("reloc0:\n")
f.write(" .offsetof start\n")
f.write("start:\n")
f.write(" .include WriteCodeBlocksGC\n")
f.write(" .include WriteCodeBlocks\n")
for region in write_regions:
f.write(
f" # region @ {region.address:08X} ({len(region.data) * 4} bytes)\n"
+972 -975
View File
File diff suppressed because it is too large Load Diff
+586
View File
@@ -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 (CHAOS_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
+1 -1
View File
@@ -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
+73
View File
@@ -0,0 +1,73 @@
########################################################################
DOWNLOAD
########################################################################
The official installer for this client is seemingly lost to time.
However, we do still have access to a download link to a directory of
the game client. Located at the bottom of this post:
https://github.com/fuzziqersoftware/newserv/discussions/734
The correct client exe to use, would be PsoBB.pat inside the
"3. PSOBB Executable" directory. While the file extension is .pat, it
can be renamed and changed to .exe .
However, PsoBB.exe in its current state will not work on its own.
As it is packed with a version of ASProtect. Which will impede you from
removing GameGuard, as well as modifying the client to connect to a desired
IP address.
There are two ways around this.
1. Use a code injection dll
2. Unpack the exe
As far as I know, There is currently not any code injection dll projects
available for use with this client. So our main option is going to be
unpacking the client.
There are several ways to unpack a client. For the sake of simplicity, we
will use a automated program.
Something like:
https://github.com/Hendi48/ASpirin
Originally found in this issue:
https://github.com/fuzziqersoftware/newserv/issues/748
You will know the process was successful if the new resulting exe file
has a much larger file size than the original.
########################################################################
REMOVE GAMEGUARD
########################################################################
The first step in being able to use this client, is removing GameGuard.
In order to do this, we will prevent GameGuard from initializing by
forcing the responsible function to return.
00844A9C - ret (or C3 in hex)
This will effectively stop GameGuard from ever starting.
However, the client has checks on startup to see if GameGuard is running,
and will close the game if it detects otherwise.
008444BB - jmp 008444DD
Now there is nothing in the way from starting up the game.
Find and edit the client's IP addresses, and have fun.
########################################################################
NOTES
########################################################################
Despite being a US client primarily using english, the client seems to
still have a reliance on having Japanese-IME enabled.
You can get around any kind of issue with this by patching out the need
for IME.
008582CC - call dword ptr ds:[0x008E0228]
Alternatively, in a hex editor, you can search for:
"EB 1A 6A 00 FF 15 9C C3"
Once found, replace with:
"EB 1A 6A 00 FF 15 28 02"
+1 -1
View File
@@ -3,7 +3,7 @@ PSOBB SUPPORT FILES, NOTES & RESOURCES
--------------------------------------------------------------------------------
CLIENT LOCALIZATION
By default PSOBB loads everything in Japanese so it requires some extra files
By default PSOBB JP clients load everything in Japanese so it requires some extra files
to properly implement the English localization from SOA, these files are offered
here inside the usbb-resources folder for your convenience they are the same ones
from the old official USBB client
View File
View File
View File
+340 -187
View File
@@ -1,187 +1,340 @@
0007 = Set by rico capsule in caves
000B = P2 Tyrell Start
000C = P2 Irene Start
000D = P2 Scientist 1 Start
000E = P2 Scientist 2 Start
000F = P2 More Scientist stuff.
0010 = P2 Irene after talking to Tyrell
0011 = Read a rico capsule (any)
0012 = P2 Scientist after talking to Irene.
0013 = P2 Menu 6, quest counter / Tekker talked to
0014 = Entered Forest 1
0015 = Entered Forest 2
0016 = Entered Dragon Area
0017 = Dragon defeated
0018 = Caves unlocked
0018 = P2 Principle after defeating dragon
0019 = P2 Scientist after defeating dragon
001E = Entered Caves 1 (Gov 2-1)
001F = Entered De Rol Le in 2-4
0020 = De Rol Le defeated
0021 = Mines unlocked (P2 Tyrell after defeating De Rol Le)
0028 = Entered Mines 1
0029 = Entered Vol Opt Area
002A = Defeated Vol Opt
002B = Set by rico capsule about the 3 seals (after vol opt).
002C = Activated Forest monument
002D = Activated Caves monument (Gov 2-2)
002E = Activated Mines monument
002F = Activated all monuments
0030 = Entered Ruins 1
0032 = Entered Falz 1
0035 = Hard mode unlocked
0036 = Entered Falz 3 // Very Hard mode unlocked (?)
0037 = Ultimate unlocked
0046 = One CCA door lock unlocked
0047 = One CCA door lock unlocked
0048 = One CCA door lock unlocked
0049 = Entered Laboratory
004A = Lab Assistant Start
004B = Entered Temple Beta
004C = Defeated Barba Ray
004D = Lab Assistant after defeating barba ray
004E = Entered Spaceship Beta
004F = Defeated Gol Dragon
0051 = Entered CCA
0052 = Defeated Gal Gyrphon // Defeated Gol dragon in seat of heart (?)
0054 = Entered Seabed Upper
0057 = Defeated Olga Flow
005B = Lab Natasha Start
005C = Lab Natasha after VR temple
005D = Lab Natasha after VR Spaceship
005E = Lab Assistant after defeating Gal gryphon
005F = After reading the last capsule from flowen
0060 = Lab Natasha after CCA
0065 = Cleared Magnitude of Metal
0067 = Cleared Claiming a Stake
0069 = Cleared Value of Money
006B = Cleared Battle Training
006D = Cleared Journalistic Pursuit
006F = Cleared The Fake in Yellow
0071 = Cleared Native Research
0073 = Cleared Forest of Sorrow
0075 = Cleared Gran Squall
0077 = Cleared Addicting Food
0079 = Cleared The Lost Bride
007B = Cleared Waterfall Tears
007D = Cleared Black Paper
007F = Cleared Secret Delivery
0081 = Cleared Soul of a Blacksmith
0083 = Cleared Letter from Lionel
0085 = Cleared The Grave's Butler
0087 = Cleared Knowing One's Heart
0089 = Cleared The Retired Hunter
008B = Cleared Dr. Osto's Research
008D = Cleared Unsealed Door
008F = Cleared Soul of Steel
0091 = Cleared Doc's Secret Plan (able to make enemy part weapons)
0093 = Cleared Seek my Master
0095 = Cleared From the Depths
0096 = Unknown (set in the fake in yellow)
0097 = Seat of heart unknown
009B = Cleared Central Dome Fire Swirl
00A1 = Cleared Seat of the Heart
00C9 = Got an enemy weapon converted
00CA = unknown Fake In Yellow
00CE = unknown Fake In Yellow
00D3 = Dr.Osto's research black paper subplot. Told Sue your name
00D4 = Dr.Osto's research black paper subplot. Didn't tell Sue your name from before.
00D5 = Dr.Osto's research black paper subplot. Did tell Sue your name from before.
00D6 = Unsealed door. black paper subplot Talked to Sue. Refused to tell her your name
00D7 = Unsealed door. black paper subplot. bernie tells you Sue is part of black paper.
00D8 = Black paper subplot in waterfall of tears talking to Sue
00D9 = Black paper subplot in Black paper talking to Sue (used option 2)
00DB = Black paper subplot in Black paper talking to Sue (used any option)
00DE = Black paper subplot in Black paper talked to Sue at the end of quest?
00DF = Knowing ones heart talked to Bernie?
00E0 = Seek my master. Zoke ,Donoph subplot?
00E2 = Bernie Gran Squall
00E7 = Defeated Kireek in waterfall of tears
00E8 = Black paper subplot in black paper. defeated Kireek...
00EB = Black paper subplot in from the depths. Defeated Kireek and got soul eater!
00F1 = Secret delivery. Started the Weapons subplot //is cleared if quest is left
00F3 = Weapon badge approval for claiming the snake //is cleared if quest is left
00F4 = Weapon badge approval for the lost bride //is cleared if quest is left
00F5 = Weapon badge approval for gran squall //is cleared if quest is left
00F6 = Secret delivery. Got AKIKO's FRYING PAN!
00FB = Got Orochi-agito
00FD = Unknown addicting food
0105 = Central dome fire swirl. Got Glory of the past!
0106 = Central dome fire swirl. Got Mark3.
0107 = Central dome fire swirl. got Sonic knuckles
0108 = Central dome fire swirl. got mail from BOGARDE
0109 = Central dome fire swirl. got mail from ANNA
010A = Central dome fire swirl. got mail from NADJA
010B = Central dome fire swirl. got mail from Lionel
010C = Soul of the blacksmith. Got one of the 3 special weapons!
010D = Donoph Baz dies The Retired Hunter
010E = Seat of heart unknown
010F = Seat of heart unknown
0110 = Seat of heart unknown
0111 = Seat of heart unknown
0112 = Seat of heart unknown
0113 = Seat of heart unknown
0187 = Soul of steel. Got Marina's bag! //dreamcast
0188 = Soul of steel. Unknown.
0191 = Capsule Elly VR
0197 = Cleared VR Temple
01AD = Capsule elly CCA
01AE = Capsule elly CCA
01B3 = After reading a capsule from flowen
01D6 = Set after unlocking vr spaceship
01F5 = Episode1: Cleared government 1-1
01F7 = Episode1: Cleared government 1-2
01F9 = Episode1: Cleared government 1-3
01FB = Episode1: Cleared government 2-1
01FD = Episode1: Cleared government 2-2
01FF = Episode1: Cleared government 2-3
0201 = Episode1: Cleared government 2-4
0203 = Episode1: Cleared government 3-1
0205 = Episode1: Cleared government 3-2
0207 = Episode1: Cleared government 3-3
0209 = Episode1: Cleared government 4-1
020B = Episode1: Cleared government 4-2
020D = Episode1: Cleared government 4-3
020F = Episode1: Cleared government 4-4
0211 = Episode1: Cleared government 4-5
0213 = Episode2: Cleared government 5-1 // Talked to Tekker (?)
0214 = Entered Forest 1
0215 = Episode2: Cleared government 5-2
0217 = Episode2: Cleared government 5-3 // Defeated Dragon (?)
0219 = Episode2: Cleared government 5-4
021B = Episode2: Cleared government 5-5
021D = Episode2: Cleared government 6-1
021F = Episode2: Cleared government 6-2
0220 = Defeated De Rol Le
0221 = Episode2: Cleared government 6-3
0223 = Episode2: Cleared government 6-4
0225 = Episode2: Cleared government 6-5
0227 = Episode2: Cleared government 7-1
0229 = Episode2: Cleared government 7-2
022A = Defeated Vol Opt (002A and 022A together on hard mode)
022B = Episode2: Cleared government 7-3 // Rico capsule after Vol Opt, at Ruins door (?)
022D = Episode2: Cleared government 7-4 // Entered Caves 2 (?)
022F = Episode2: Cleared government 7-5
0230 = Entered Ruins 1
0231 = Episode2: Cleared government 8-1
0233 = Episode2: Cleared government 8-2
0234 = Entered Falz 2
0235 = Episode2: Cleared government 8-3
0246 = Activated Jungle East big door switch
0248 = Activated Seaside big door switch
024F = Defeated Gol Dragon
0252 = Defeated Gal Gryphon
02BD = Episode4: Cleared government 9-1
02BE = Episode4: Cleared government 9-2
02BF = Episode4: Cleared government 9-3
02C0 = Episode4: Cleared government 9-4
02C1 = Episode4: Cleared government 9-5
02C2 = Episode4: Cleared government 9-6
02C3 = Episode4: Cleared government 9-7
02C4 = Episode4: Cleared government 9-8
0314 = Entered Forest 1
0330 = Entered Ruins 1
03FA = P2 Menu 7, G-Counter // Talked to Momoka
03FB = Nol start
03FC = Cleared Ep2 government on ultimate
03FE = Cleared Ep2 government on normal-vh
* = verified from client or quest disassembly
0007 = Set by rico capsule in caves
000B * = Has seen first single-mode Tyrell conversation (Episode 1)
000C = P2 Irene Start
000D = P2 Scientist 1 Start
000E = P2 Scientist 2 Start
000F = P2 More Scientist stuff.
0010 = P2 Irene after talking to Tyrell
0011 = Read a rico capsule (any)
0012 = P2 Scientist after talking to Irene.
0013 = P2 Menu 6, quest counter / Tekker talked to
0014 * = Has been to Forest 1
0015 = Entered Forest 2
0016 * = TBoss1Dragon encountered
0017 * = Dragon defeated (Caves unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 1)
0018 * = Talked with Tyrell after defeating Dragon (Caves unlocked in offline single mode (pre-V4))
0019 = P2 Scientist after defeating dragon
001E * = Has been to Cave 1
001F = Entered De Rol Le in 2-4
0020 * = De Rol Le defeated (Mines unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 2)
0021 * = Talked with Tyrell after defeating De Rol Le (Mines unlocked in offline single mode (pre-V4))
0028 * = Has been to Mine 1
0029 * = TBoss3Volopt encountered
002A * = Vol Opt defeated (Ruins unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 3)
002B = Set by rico capsule about the 3 seals (after vol opt).
002C * = Activated Forest monument (checked by TODoorVoShip_update and TODoorVoShip_init)
002D * = Activated Caves monument (checked by TODoorVoShip_update and TODoorVoShip_init)
002E * = Activated Mines monument (checked by TODoorVoShip_update and TODoorVoShip_init)
002F * = Activated all monuments (checked by TODoorVoShip_update and TODoorVoShip_init; causes Vol Opt to construct different objects upon defeat; see 3OE1:8003CB50, 3OE1:80040E68)
0030 * = Has been to Ruins 1 (Ruins unlocked in offline single mode (pre-V4))
0032 * = TBoss4Type1 encountered
0033 * = TBoss4Type1 defeated; sets command 10 quest tier to 4
0034 * = TBoss4Type2 encountered
0035 * = TBoss4Type2 defeated; unlocks Hard if set in Normal
0036 * = TBoss4Type3 encountered
0037 * = TBoss4Type3 defeated; unlocks Very Hard or Ultimate if set in Hard or Very Hard respectively
0046 * = First CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
0047 * = Second CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
0048 * = Third CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
0049 = Entered Laboratory
004A = Lab Assistant Start
004B * = Has been to VR Temple Beta
004C * = Barba Ray defeated (VR Spaceship unlocked in online/multi mode (pre-V4))
004D * = Talked with Lab Assistant after defeating Barba Ray (VR Spaceship unlocked in offline single mode (pre-V4))
004E * = Has been to VR Spaceship Beta
004F * = TBoss8Dragon defeated (CCA unlocked in online/multi mode (pre-V4))
0050 * = CCA unlocked in offline single mode (pre-V4)
0051 * = Has been to CCA
0052 * = Gal Gryphon defeated (Seabed unlocked in online/multi mode (pre-V4))
0053 * = Seabed unlocked in offline single mode (pre-V4)
0054 * = Has been to Seabed Upper
0055 * = Has been to Seabed Lower
0056 * = TBoss6PlotFalz encountered
0057 * = TBoss6PlotFalz defeated (unlocks the next difficulty level)
005B * = Has seen first single-mode Natasha conversation (Episode 1)
005C = Lab Natasha after VR temple
005D = Lab Natasha after VR Spaceship
005E = Lab Assistant after defeating Gal gryphon
005F = After reading the last capsule from flowen
0060 = Lab Natasha after CCA
0064 * = Magnitude of Metal unlocked
0065 * = Magnitude of Metal completed
0066 * = Claiming A Stake unlocked
0067 * = Claiming A Stake completed
0068 * = The Value of Money unlocked
0069 * = The Value of Money completed
006A * = Battle Training unlocked
006B * = Battle Training completed
006C * = Journalistic Pursuit unlocked
006D * = Journalistic Pursuit completed
006E * = The Fake in yellow unlocked
006F * = The Fake in yellow completed
0070 * = Native Research unlocked
0071 * = Native Research completed
0072 * = Forest of Sorrow unlocked
0073 * = Forest of Sorrow completed
0074 * = Gran Squall unlocked
0075 * = Gran Squall completed
0076 * = Addicting Food unlocked
0077 * = Addicting Food completed
0078 * = The Lost Bride unlocked
0079 * = The Lost Bride completed
007A * = Waterfall tears unlocked
007B * = Waterfall tears completed
007C * = Black Paper unlocked
007D * = Black Paper completed
007E * = Secret Delivery unlocked
007F * = Secret Delivery completed
0080 * = Soul of a Blacksmith unlocked
0081 * = Soul of a Blacksmith completed
0082 * = Letter from Lionel unlocked
0083 * = Letter from Lionel completed
0084 * = The Grave's Butler unlocked
0085 * = The Grave's Butler completed
0086 * = Knowing One's Heart unlocked
0087 * = Knowing One's Heart completed
0088 * = Retired Hunter unlocked
0089 * = Retired Hunter completed
008A * = Dr. Osto's Research unlocked
008B * = Dr. Osto's Research completed
008C * = The Unsealed Door unlocked
008D * = The Unsealed Door completed
008E * = Soul of Steel unlocked
008F * = Soul of Steel completed
0090 * = Doc's Secret Plan unlocked
0091 * = Doc's Secret Plan completed
0092 * = Seek My Master unlocked
0093 * = Seek My Master completed
0094 * = From the Depths unlocked
0095 * = From the Depths completed
0096 = Unknown (set in the fake in yellow)
0097 * = TBoss4Type3 defeated while any player was using Dark Flow, Dark Meteor, or Dark Bridge
0098 * = TBoss6PlotFalz defeated while any player was using a Read weapon (e.g. Red Saber, Reg Handgun, etc.) or any of Rico's armors (Red Ring, Rico's Glasses, Rico's Earring)
0099 * = TBoss4Thanks destroyed
009A * = TBoss6Thanks destroyed
009B = Cleared Central Dome Fire Swirl
009F * = Central Dome Fire Swirl unlocked
00A0 * = Central Dome Fire Swirl completed
00A1 * = Seat of the Heart completed
00A2 * = The East Tower completed
00A3 * = The East Tower completed
00A4 * = The West Tower completed
00A5 * = The West Tower completed
00C9 = Got an enemy weapon converted
00CA = unknown Fake In Yellow
00CE = unknown Fake In Yellow
00D3 = Dr.Osto's research black paper subplot. Told Sue your name
00D4 = Dr.Osto's research black paper subplot. Didn't tell Sue your name from before.
00D5 = Dr.Osto's research black paper subplot. Did tell Sue your name from before.
00D6 = Unsealed door. black paper subplot Talked to Sue. Refused to tell her your name
00D7 = Unsealed door. black paper subplot. bernie tells you Sue is part of black paper.
00D8 = Black paper subplot in waterfall of tears talking to Sue
00D9 = Black paper subplot in Black paper talking to Sue (used option 2)
00DB = Black paper subplot in Black paper talking to Sue (used any option)
00DE = Black paper subplot in Black paper talked to Sue at the end of quest?
00DF = Knowing ones heart talked to Bernie?
00E0 = Seek my master. Zoke ,Donoph subplot?
00E2 = Bernie Gran Squall
00E7 = Defeated Kireek in waterfall of tears
00E8 = Black paper subplot in black paper. defeated Kireek...
00EB = Black paper subplot in from the depths. Defeated Kireek and got soul eater!
00F1 = Secret delivery. Started the Weapons subplot //is cleared if quest is left
00F3 = Weapon badge approval for claiming the snake //is cleared if quest is left
00F4 = Weapon badge approval for the lost bride //is cleared if quest is left
00F5 = Weapon badge approval for gran squall //is cleared if quest is left
00F6 = Secret delivery. Got AKIKO's FRYING PAN!
00FB = Got Orochi-agito
00FD = Unknown addicting food
0105 = Central dome fire swirl. Got Glory of the past!
0106 = Central dome fire swirl. Got Mark3.
0107 = Central dome fire swirl. got Sonic knuckles
0108 = Central dome fire swirl. got mail from BOGARDE
0109 = Central dome fire swirl. got mail from ANNA
010A = Central dome fire swirl. got mail from NADJA
010B = Central dome fire swirl. got mail from Lionel
010C = Soul of the blacksmith. Got one of the 3 special weapons!
010D = Donoph Baz dies The Retired Hunter
010E = Seat of heart unknown
010F = Seat of heart unknown
0110 = Seat of heart unknown
0111 = Seat of heart unknown
0112 = Seat of heart unknown
0113 = Seat of heart unknown
0187 = Soul of steel. Got Marina's bag! //dreamcast
0188 = Soul of steel. Unknown.
0191 = Capsule Elly VR
0197 = Cleared VR Temple
01AD = Capsule elly CCA
01AE = Capsule elly CCA
01B3 = After reading a capsule from flowen
01D6 = Set after unlocking vr spaceship
01F5 * = Episode1: Cleared government 1-1
01F7 * = Episode1: Cleared government 1-2
01F9 * = Episode1: Cleared government 1-3; Caves unlocked (V4)
01FB * = Episode1: Cleared government 2-1
01FD * = Episode1: Cleared government 2-2
01FF * = Episode1: Cleared government 2-3
0201 * = Episode1: Cleared government 2-4; Mines unlocked (V4)
0203 * = Episode1: Cleared government 3-1
0205 * = Episode1: Cleared government 3-2
0207 * = Episode1: Cleared government 3-3; Ruins unlocked (V4)
0209 * = Episode1: Cleared government 4-1
020B * = Episode1: Cleared government 4-2
020D * = Episode1: Cleared government 4-3
020F * = Episode1: Cleared government 4-4
0211 * = Episode1: Cleared government 4-5
0213 * = Episode2: Cleared government 5-1
0215 * = Episode2: Cleared government 5-2
0217 * = Episode2: Cleared government 5-3
0219 * = Episode2: Cleared government 5-4
021B * = Episode2: Cleared government 5-5; VR Spaceship unlocked (V4)
021D * = Episode2: Cleared government 6-1
021F * = Episode2: Cleared government 6-2
0221 * = Episode2: Cleared government 6-3
0223 * = Episode2: Cleared government 6-4
0225 * = Episode2: Cleared government 6-5; CCA unlocked (V4)
0227 * = Episode2: Cleared government 7-1
0229 * = Episode2: Cleared government 7-2
022B * = Episode2: Cleared government 7-3
022D * = Episode2: Cleared government 7-4
022F * = Episode2: Cleared government 7-5; Seabed unlocked (V4)
0231 * = Episode2: Cleared government 8-1
0233 * = Episode2: Cleared government 8-2
0235 * = Episode2: Cleared government 8-3
0246 = Activated Jungle East big door switch
0248 = Activated Seaside big door switch
024F = Defeated Gol Dragon
0252 = Defeated Gal Gryphon
02BD * = Episode4: Cleared government 9-1; Crater West unlocked
02BE * = Episode4: Cleared government 9-2; Crater South unlocked
02BF * = Episode4: Cleared government 9-3; Crater North unlocked
02C0 * = Episode4: Cleared government 9-4; Crater Interior unlocked
02C1 * = Episode4: Cleared government 9-5; Desert unlocked
02C2 * = Episode4: Cleared government 9-6
02C3 * = Episode4: Cleared government 9-7
02C4 * = Episode4: Cleared government 9-8
0314 = Entered Forest 1
0330 = Entered Ruins 1
03FA = P2 Menu 7, G-Counter // Talked to Momoka
03FB = Nol start
03FC = Cleared Ep2 government on ultimate
03FE * = TODO (3OE1:8019BA34, 3OE1:80218F74, 59NL:0066A287)
Quest unlock conditions:
QUESTNUM NAMEIDX SDESCIDX LDESCIDX ENFL CPFL FLAGS FILE
00000001 00000000 00000001 00000002 006A 006B 00000000 quest04
00000002 00000003 00000004 00000005 0066 0067 00000000 quest02
00000003 00000006 00000007 00000008 0064 0065 00000000 quest01
00000004 00000009 0000000A 0000000B 0068 0069 00000000 quest03
00000005 0000000C 0000000D 0000000E 006C 006D 00000000 quest05
00000006 0000000F 00000010 00000011 006E 006F 00000000 quest06
00000007 00000012 00000013 00000014 0070 0071 00000000 quest07
00000008 00000015 00000016 00000017 0072 0073 00000000 quest08
00000009 00000018 00000019 0000001A 0074 0075 00000000 quest09
0000000A 0000001B 0000001C 0000001D 0076 0077 00000000 quest10
0000000B 0000001E 0000001F 00000020 0078 0079 00000000 quest11
0000000C 00000021 00000022 00000023 007A 007B 00000000 quest12
0000000D 00000024 00000025 00000026 007C 007D 00000000 quest13
0000000E 00000027 00000028 00000029 007E 007F 00000000 quest14
0000000F 0000002A 0000002B 0000002C 0080 0081 00000000 quest15
00000010 0000002D 0000002E 0000002F 0082 0083 00000000 quest16
00000011 00000030 00000031 00000032 0084 0085 00000000 quest17
00000012 00000033 00000034 00000035 0086 0087 00000000 quest18
00000013 00000036 00000037 00000038 0088 0089 00000000 quest19
00000014 00000039 0000003A 0000003B 008A 008B 00000000 quest20
00000015 0000003C 0000003D 0000003E 008C 008D 00000000 quest21
00000016 0000003F 00000040 00000041 008E 008F 00000000 quest22
00000017 00000042 00000043 00000044 0090 0091 00000000 quest23
00000018 00000045 00000046 00000047 0092 0093 00000000 quest24
00000019 00000048 00000049 0000004A 0094 0095 00000000 quest25
0000001A 0000004B 0000004C 0000004D 009F 00A0 00000000 quest26 (plus only; CDFS)
0000001B 0000004E 0000004F 00000050 FFFF 00A1 00000000 quest27 (plus only; ep2; Seat of the Heart)
0000001C 00000051 00000052 00000053 00A2 00A3 00000000 quest28 (plus only; ep2; The East Tower)
0000001D 00000054 00000055 00000056 00A4 00A5 00000000 quest29 (plus only; ep2; THe West Tower)
// Pre-BB
/* quest01 */ F_0064 = true;
/* quest02 */ F_0066 = true;
/* quest03 */ F_0068 = F_0065 && F_0067 && F_006B && F_0018;
/* quest04 */ F_006A = true;
/* quest05 */ F_006C = F_0065 && F_0067 && F_006B;
/* quest06 */ F_006E = F_0065 && F_0067 && F_006B;
/* quest07 */ F_0070 = F_0065 && F_0067 && F_006B;
/* quest08 */ F_0072 = F_0071;
/* quest09 */ F_0074 = F_0065 && F_0067 && F_006B;
/* quest10 */ F_0076 = F_0065 && F_0067 && F_006B && F_0018;
/* quest11 */ F_0078 = F_0065 && F_0067 && F_006B && F_0018;
/* quest12 */ F_007A = F_0077 && F_0079 && F_007F && F_0085;
/* quest13 */ F_007C = F_007B;
/* quest14 */ F_007E = F_0065 && F_0067 && F_006B && F_0018;
/* quest15 */ F_0080 = F_0077 && F_0079 && F_007F && F_0085;
/* quest16 */ F_0082 = F_0065 && F_0067 && F_006B && F_0021;
/* quest17 */ F_0084 = F_0065 && F_0067 && F_006B && F_0018;
/* quest18 */ F_0086 = F_0065 && F_0067 && F_006B && F_0021;
/* quest19 */ F_0088 = F_0065 && F_0067 && F_006B && F_0030;
/* quest20 */ F_008A = F_0065 && F_0067 && F_006B && F_0021;
/* quest21 */ F_008C = F_008B && F_007F && F_0021;
/* quest22 */ F_008E = F_008D && F_0030 && F_0091;
/* quest23 */ F_0090 = F_007F && F_0030;
/* quest24 */ F_0092 = F_0065 && F_0067 && F_006B && F_0030;
/* quest25 */ F_0094 = F_008D && F_0030 && F_0091;
/* quest26 (Plus only) */ F_009F = F_0095;
/* quest28 (Plus only) */ F_00A2 = F_00A1;
/* quest29 (Plus only) */ F_00A4 = F_00A3;
// BB
/* quest01 */ F_0064 = true;
/* quest02 */ F_0066 = true;
/* quest03 */ F_0068 = F_0065 && F_0067 && F_006B && F_01F9;
/* quest04 */ F_006A = true;
/* quest05 */ F_006C = F_0065 && F_0067 && F_006B;
/* quest06 */ F_006E = F_0065 && F_0067 && F_006B;
/* quest07 */ F_0070 = F_0065 && F_0067 && F_006B;
/* quest08 */ F_0072 = F_0071;
/* quest09 */ F_0074 = F_0065 && F_0067 && F_006B;
/* quest10 */ F_0076 = F_0065 && F_0067 && F_006B && F_01F9;
/* quest11 */ F_0078 = F_0065 && F_0067 && F_006B && F_01F9;
/* quest12 */ F_007A = F_0077 && F_0079 && F_007F && F_0085;
/* quest13 */ F_007C = F_007B;
/* quest14 */ F_007E = F_0065 && F_0067 && F_006B && F_01F9;
/* quest15 */ F_0080 = F_0077 && F_0079 && F_007F && F_0085;
/* quest16 */ F_0082 = F_0065 && F_0067 && F_006B && F_0201;
/* quest17 */ F_0084 = F_0065 && F_0067 && F_006B && F_01F9;
/* quest18 */ F_0086 = F_0065 && F_0067 && F_006B && F_0201;
/* quest19 */ F_0088 = F_0065 && F_0067 && F_006B && F_0207;
/* quest20 */ F_008A = F_0065 && F_0067 && F_006B && F_0201;
/* quest21 */ F_008C = F_008B && F_007F && F_0201;
/* quest22 */ F_008E = F_008D && F_0091 && F_0207;
/* quest23 */ F_0090 = F_007F && F_0207;
/* quest24 */ F_0092 = F_0065 && F_0067 && F_006B && F_0207;
/* quest25 */ F_0094 = F_008D && F_0091 && F_0207;
### T FLAG NAME REQUIREMENTS AVAILABLE_IF ENABLED_IF
001 1 0065 Magnitude of Metal !F_0065 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
002 1 0067 Claiming A Stake !F_0067 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
003 3 0069 The Value of Money T1, Caves F_0065 && F_0067 && F_006B && F_01F9 !F_0069 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
004 1 006B Battle Training !F_006B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
005 2 006D Journalistic Pursuit T1 F_0065 && F_0067 && F_006B !F_006D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
006 2 006F The Fake in yellow T1 F_0065 && F_0067 && F_006B !F_006F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
007 2 0071 Native Research T1 F_0065 && F_0067 && F_006B !F_0071 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
008 2 0073 Forest of Sorrow 007 F_0071 !F_0073 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
009 2 0075 Gran Squall T1 F_0065 && F_0067 && F_006B !F_0075 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
010 3 0077 Addicting Food T1 F_0065 && F_0067 && F_006B && F_01F9 !F_0077 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
011 3 0079 The Lost Bride T1 F_0065 && F_0067 && F_006B && F_01F9 !F_0079 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
012 3 007B Waterfall tears 010, 011, 014, 017 F_0077 && F_0079 && F_007F && F_0085 !F_007B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
013 3 007D Black Paper 012 F_007B !F_007D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
014 3 007F Secret Delivery T1 F_0065 && F_0067 && F_006B && F_01F9 !F_007F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
015 3 0081 Soul of a Blacksmith 010, 011, 014, 017 F_0077 && F_0079 && F_007F && F_0085 !F_0081 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
016 3 0083 Letter from Lionel T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_0083 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
017 3 0085 The Grave's Butler T1 F_0065 && F_0067 && F_006B && F_01F9 !F_0085 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
018 4 0087 Knowing One's Heart T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_0087 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
019 5 0089 Retired Hunter T1, Ruins F_0065 && F_0067 && F_006B && F_0207 !F_0089 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
020 4 008B Dr. Osto's Research T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_008B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
021 4 008D The Unsealed Door 020, 014 F_008B && F_007F && F_0201 !F_008D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
022 5 008F Soul of Steel 023 F_008D && F_0091 && F_0207 !F_008F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
023 5 0091 Doc's Secret Plan 014, Ruins F_007F && F_0207 !F_0091 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
024 5 0093 Seek My Master T1, Ruins F_0065 && F_0067 && F_006B && F_0207 !F_0093 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
025 5 0095 From the Depths 023 F_008D && F_0091 && F_0207 !F_0095 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
026 2 009B Central Dome Fire Swirl 008 F_0073
-27
View File
@@ -1,27 +0,0 @@
### T FLAG NAME REQUIREMENTS AVAILABLE_IF ENABLED_IF
001 1 0065 Magnitude of Metal !F_0065 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
002 1 0067 Claiming A Stake !F_0067 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
003 3 0069 The Value of Money T1, Caves F_0065 && F_0067 && F_006B && F_01F9 !F_0069 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
004 1 006B Battle Training !F_006B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
005 2 006D Journalistic Pursuit T1 F_0065 && F_0067 && F_006B !F_006D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
006 2 006F The Fake in yellow T1 F_0065 && F_0067 && F_006B !F_006F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
007 2 0071 Native Research T1 F_0065 && F_0067 && F_006B !F_0071 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
008 2 0073 Forest of Sorrow 007 F_0071 !F_0073 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
009 2 0075 Gran Squall T1 F_0065 && F_0067 && F_006B !F_0075 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
010 3 0077 Addicting Food T1 F_0065 && F_0067 && F_006B !F_0077 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
011 3 0079 The Lost Bride T1 F_0065 && F_0067 && F_006B !F_0079 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
012 3 007B Waterfall tears 010, 011, 014, 017 F_0077 && F_0079 && F_007F && F_0085 !F_007B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
013 3 007D Black Paper 012 F_007B !F_007D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
014 3 007F Secret Delivery T1 F_0065 && F_0067 && F_006B !F_007F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
015 3 0081 Soul of a Blacksmith 010, 011, 014, 017 F_0077 && F_0079 && F_007F && F_0085 !F_0081 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
016 3 0083 Letter from Lionel T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_0083 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
017 3 0085 The Grave's Butler T1 F_0065 && F_0067 && F_006B !F_0085 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
018 4 0087 Knowing One's Heart T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_0087 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
019 5 0089 Retired Hunter T1, Ruins F_0065 && F_0067 && F_006B && F_0207 !F_0089 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
020 4 008B Dr. Osto's Research T1, Mines F_0065 && F_0067 && F_006B && F_0201 !F_008B || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
021 4 008D The Unsealed Door 020, 014 F_008B && F_007F !F_008D || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
022 5 008F Soul of Steel 023 F_0091 !F_008F || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
023 5 0091 Doc's Secret Plan 014, Ruins F_007F && F_0207 !F_0091 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
024 5 0093 Seek My Master T1, Ruins F_0065 && F_0067 && F_006B && F_0207 !F_0093 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
025 5 0095 From the Depths 023 F_0091 !F_0095 || (F_0065 && F_0067 && F_0069 && F_006B && F_006D && F_006F && F_0071 && F_0073 && F_0075 && F_0077 && F_0079 && F_007B && F_007D && F_007F && F_0081 && F_0083 && F_0085 && F_0087 && F_0089 && F_008B && F_008D && F_008F && F_0091 && F_0093 && F_0095)
026 2 009B Central Dome Fire Swirl 008 F_0073
+12 -15
View File
@@ -9,10 +9,7 @@
#include "Text.hh"
using namespace std;
AFSArchive::AFSArchive(shared_ptr<const string> data)
: data(data) {
AFSArchive::AFSArchive(std::shared_ptr<const std::string> data) : data(data) {
struct FileHeader {
be_uint32_t magic;
le_uint32_t num_files;
@@ -26,7 +23,7 @@ AFSArchive::AFSArchive(shared_ptr<const string> data)
phosg::StringReader r(*this->data);
const auto& header = r.get<FileHeader>();
if (header.magic != 0x41465300) { // 'AFS\0'
throw runtime_error("file is not an AFS archive");
throw std::runtime_error("file is not an AFS archive");
}
while (this->entries.size() < header.num_files) {
@@ -35,21 +32,21 @@ AFSArchive::AFSArchive(shared_ptr<const string> data)
}
}
pair<const void*, size_t> AFSArchive::get(size_t index) const {
std::pair<const void*, size_t> AFSArchive::get(size_t index) const {
const auto& entry = this->entries.at(index);
if (entry.offset > this->data->size()) {
throw out_of_range("entry begins beyond end of archive");
throw std::out_of_range("entry begins beyond end of archive");
}
if (entry.offset + entry.size > this->data->size()) {
throw out_of_range("entry extends beyond end of archive");
throw std::out_of_range("entry extends beyond end of archive");
}
return make_pair(this->data->data() + entry.offset, entry.size);
return std::make_pair(this->data->data() + entry.offset, entry.size);
}
string AFSArchive::get_copy(size_t index) const {
std::string AFSArchive::get_copy(size_t index) const {
auto ret = this->get(index);
return string(reinterpret_cast<const char*>(ret.first), ret.second);
return std::string(reinterpret_cast<const char*>(ret.first), ret.second);
}
phosg::StringReader AFSArchive::get_reader(size_t index) const {
@@ -57,18 +54,18 @@ phosg::StringReader AFSArchive::get_reader(size_t index) const {
return phosg::StringReader(ret.first, ret.second);
}
string AFSArchive::generate(const vector<string>& files, bool big_endian) {
std::string AFSArchive::generate(const std::vector<std::string>& files, bool big_endian) {
return big_endian ? AFSArchive::generate_t<true>(files) : AFSArchive::generate_t<false>(files);
}
template <bool BE>
string AFSArchive::generate_t(const vector<string>& files) {
std::string AFSArchive::generate_t(const std::vector<std::string>& files) {
phosg::StringWriter w;
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);
+202 -224
View File
@@ -9,68 +9,61 @@
#include <phosg/Time.hh>
#include "Account.hh"
#include "AccountSync.hh"
using namespace std;
shared_ptr<DCNTELicense> DCNTELicense::from_json(const phosg::JSON& json) {
auto ret = make_shared<DCNTELicense>();
std::shared_ptr<DCNTELicense> DCNTELicense::from_json(const phosg::JSON& json) {
auto ret = std::make_shared<DCNTELicense>();
ret->serial_number = json.get_string("SerialNumber");
ret->access_key = json.get_string("AccessKey");
if (ret->serial_number.size() > 16) {
throw runtime_error("serial number is too long");
throw std::runtime_error("serial number is too long");
}
if (ret->serial_number.empty()) {
throw runtime_error("serial number is too short");
throw std::runtime_error("serial number is too short");
}
if (ret->access_key.size() > 16) {
throw runtime_error("access key is too long");
throw std::runtime_error("access key is too long");
}
if (ret->access_key.empty()) {
throw runtime_error("access key is too short");
throw std::runtime_error("access key is too short");
}
return ret;
}
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) {
auto ret = make_shared<V1V2License>();
std::shared_ptr<V1V2License> V1V2License::from_json(const phosg::JSON& json) {
auto ret = std::make_shared<V1V2License>();
ret->serial_number = json.get_int("SerialNumber");
ret->access_key = json.get_string("AccessKey");
if (ret->serial_number == 0) {
throw runtime_error("serial number is zero");
throw std::runtime_error("serial number is zero");
}
if (ret->access_key.size() != 8) {
throw runtime_error("access key length is incorrect");
throw std::runtime_error("access key length is incorrect");
}
return ret;
}
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) {
auto ret = make_shared<GCLicense>();
std::shared_ptr<GCLicense> GCLicense::from_json(const phosg::JSON& json) {
auto ret = std::make_shared<GCLicense>();
ret->serial_number = json.get_int("SerialNumber");
ret->access_key = json.get_string("AccessKey");
ret->password = json.get_string("Password");
if (ret->serial_number == 0) {
throw runtime_error("serial number is zero");
throw std::runtime_error("serial number is zero");
}
if (ret->access_key.size() != 12) {
throw runtime_error("access key length is incorrect");
throw std::runtime_error("access key length is incorrect");
}
if (ret->password.empty()) {
throw runtime_error("password is too short");
throw std::runtime_error("password is too short");
}
return ret;
}
@@ -83,55 +76,48 @@ phosg::JSON GCLicense::json() const {
});
}
shared_ptr<XBLicense> XBLicense::from_json(const phosg::JSON& json) {
auto ret = make_shared<XBLicense>();
std::shared_ptr<XBLicense> XBLicense::from_json(const phosg::JSON& json) {
auto ret = std::make_shared<XBLicense>();
ret->gamertag = json.get_string("GamerTag");
ret->user_id = json.get_int("UserID");
ret->account_id = json.get_int("AccountID");
if (ret->gamertag.empty()) {
throw runtime_error("gamertag is too short");
throw std::runtime_error("gamertag is too short");
}
if (ret->user_id == 0) {
throw runtime_error("user ID is zero");
throw std::runtime_error("user ID is zero");
}
if (ret->account_id == 0) {
throw runtime_error("account ID is zero");
throw std::runtime_error("account ID is zero");
}
return ret;
}
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) {
auto ret = make_shared<BBLicense>();
std::shared_ptr<BBLicense> BBLicense::from_json(const phosg::JSON& json) {
auto ret = std::make_shared<BBLicense>();
ret->username = json.get_string("UserName");
ret->password = json.get_string("Password");
if (ret->username.size() > 16) {
throw runtime_error("username is too long");
throw std::runtime_error("username is too long");
}
if (ret->username.empty()) {
throw runtime_error("username is too short");
throw std::runtime_error("username is too short");
}
if (ret->password.size() > 16) {
throw runtime_error("password is too long");
throw std::runtime_error("password is too long");
}
if (ret->password.empty()) {
throw runtime_error("password is too short");
throw std::runtime_error("password is too short");
}
return ret;
}
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)
@@ -145,51 +131,51 @@ Account::Account(const phosg::JSON& json)
uint64_t format_version = 0;
try {
format_version = json.get_int("FormatVersion");
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (format_version == 0) {
// Original format - no account ID
this->account_id = json.get_int("SerialNumber");
string access_key = json.get_string("AccessKey", "");
string dc_nte_serial_number = json.get_string("DCNTESerialNumber", "");
string dc_nte_access_key = json.get_string("DCNTEAccessKey", "");
string gc_password = json.get_string("GCPassword", "");
string xb_gamertag = json.get_string("XBGamerTag", "");
std::string access_key = json.get_string("AccessKey", "");
std::string dc_nte_serial_number = json.get_string("DCNTESerialNumber", "");
std::string dc_nte_access_key = json.get_string("DCNTEAccessKey", "");
std::string gc_password = json.get_string("GCPassword", "");
std::string xb_gamertag = json.get_string("XBGamerTag", "");
uint64_t xb_user_id = json.get_int("XBUserID", 0);
uint64_t xb_account_id = json.get_int("XBAccountID", 0);
string bb_username = json.get_string("BBUsername", "");
string bb_password = json.get_string("BBPassword", "");
std::string bb_username = json.get_string("BBUsername", "");
std::string bb_password = json.get_string("BBPassword", "");
if (access_key.size() == 12) {
if (!gc_password.empty()) {
auto lic = make_shared<GCLicense>();
auto lic = std::make_shared<GCLicense>();
lic->serial_number = this->account_id;
lic->access_key = access_key;
lic->password = gc_password;
this->gc_licenses.emplace(lic->serial_number, lic);
}
} else if (access_key.size() >= 8) {
auto lic = make_shared<V1V2License>();
auto lic = std::make_shared<V1V2License>();
lic->serial_number = this->account_id;
lic->access_key = access_key.substr(0, 8);
this->dc_licenses.emplace(lic->serial_number, lic);
this->pc_licenses.emplace(lic->serial_number, lic);
}
if (!dc_nte_serial_number.empty() && !dc_nte_access_key.empty()) {
auto lic = make_shared<DCNTELicense>();
auto lic = std::make_shared<DCNTELicense>();
lic->serial_number = dc_nte_serial_number;
lic->access_key = dc_nte_access_key;
this->dc_nte_licenses.emplace(lic->serial_number, lic);
}
if (!xb_gamertag.empty() && xb_user_id && xb_account_id) {
auto lic = make_shared<XBLicense>();
auto lic = std::make_shared<XBLicense>();
lic->gamertag = xb_gamertag;
lic->user_id = xb_user_id;
lic->account_id = xb_account_id;
this->xb_licenses.emplace(lic->user_id, lic);
}
if (!bb_username.empty() && !bb_password.empty()) {
auto lic = make_shared<BBLicense>();
auto lic = std::make_shared<BBLicense>();
lic->username = bb_username;
lic->password = bb_password;
this->bb_licenses.emplace(lic->username, lic);
@@ -236,7 +222,7 @@ Account::Account(const phosg::JSON& json)
for (const auto& it : json.get_list("AutoPatchesEnabled")) {
this->auto_patches_enabled.emplace(it->as_string());
}
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
}
@@ -292,11 +278,11 @@ phosg::JSON Account::json() const {
});
}
string Account::str() const {
std::string Account::str() const {
std::string ret = std::format("Account: {:010}/{:08X}\n", this->account_id, this->account_id);
if (this->flags) {
string flags_str = "";
std::string flags_str = "";
if (this->flags == static_cast<uint32_t>(Flag::ROOT)) {
flags_str = "ROOT";
} else if (this->flags == static_cast<uint32_t>(Flag::ADMINISTRATOR)) {
@@ -329,6 +315,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)) {
@@ -344,7 +333,7 @@ string Account::str() const {
}
if (this->user_flags) {
string user_flags_str = "";
std::string user_flags_str = "";
if (this->check_user_flag(UserFlag::DISABLE_DROP_NOTIFICATION_BROADCAST)) {
user_flags_str += "DISABLE_DROP_NOTIFICATION_BROADCAST,";
}
@@ -357,8 +346,7 @@ string Account::str() const {
}
if (this->ban_end_time) {
string time_str = phosg::format_time(this->ban_end_time);
ret += std::format(" Banned until: {} ({})\n", this->ban_end_time, time_str);
ret += std::format(" Banned until: {} ({})\n", this->ban_end_time, phosg::format_time(this->ban_end_time));
}
if (this->ep3_current_meseta || this->ep3_total_meseta_earned) {
ret += std::format(" Episode 3 meseta: {} (total earned: {})\n",
@@ -409,39 +397,21 @@ 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 filename = std::format("system/licenses/{:010}.json", this->account_id);
std::string json_data = json.serialize(
phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS);
std::string filename = std::format("system/licenses/{:010}.json", this->account_id);
phosg::save_file(filename, json_data);
AccountSync::notify_account_saved(this->account_id, filename);
}
}
void Account::delete_file() const {
string filename = std::format("system/licenses/{:010}.json", this->account_id);
remove(filename.c_str());
std::filesystem::remove(std::format("system/licenses/{:010}.json", this->account_id));
}
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);
std::string Login::str() const {
std::string ret = std::format("Account:{:08X}", this->account->account_id);
if (this->account_was_created) {
ret += " (new)";
}
@@ -464,21 +434,21 @@ string Login::str() const {
}
size_t AccountIndex::count() const {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->by_account_id.size();
}
shared_ptr<Account> AccountIndex::from_account_id(uint32_t account_id) const {
std::shared_ptr<Account> AccountIndex::from_account_id(uint32_t account_id) const {
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->by_account_id.at(account_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
throw missing_account();
}
}
shared_ptr<Login> AccountIndex::from_dc_nte_credentials_locked(const string& serial_number, const string& access_key) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_dc_nte_credentials_locked(const std::string& serial_number, const std::string& access_key) {
auto login = std::make_shared<Login>();
login->account = this->by_dc_nte_serial_number.at(serial_number);
login->dc_nte_license = login->account->dc_nte_licenses.at(serial_number);
if (login->dc_nte_license->access_key != access_key) {
@@ -490,30 +460,30 @@ shared_ptr<Login> AccountIndex::from_dc_nte_credentials_locked(const string& ser
return login;
}
shared_ptr<Login> AccountIndex::from_dc_nte_credentials(
const string& serial_number, const string& access_key, bool allow_create) {
std::shared_ptr<Login> AccountIndex::from_dc_nte_credentials(
const std::string& serial_number, const std::string& access_key, bool allow_create) {
if (serial_number.empty()) {
throw no_username();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_dc_nte_credentials_locked(serial_number, access_key);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_dc_nte_credentials_locked(serial_number, access_key);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = phosg::fnv1a32(serial_number) & 0x7FFFFFFF;
auto lic = make_shared<DCNTELicense>();
auto lic = std::make_shared<DCNTELicense>();
lic->serial_number = serial_number;
lic->access_key = access_key;
login->account->dc_nte_licenses.emplace(lic->serial_number, lic);
@@ -525,9 +495,9 @@ shared_ptr<Login> AccountIndex::from_dc_nte_credentials(
}
}
shared_ptr<Login> AccountIndex::from_dc_credentials_locked(
uint32_t serial_number, const string& access_key, const string& character_name) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_dc_credentials_locked(
uint32_t serial_number, const std::string& access_key, const std::string& character_name) {
auto login = std::make_shared<Login>();
login->account = this->by_dc_serial_number.at(serial_number);
login->dc_license = login->account->dc_licenses.at(serial_number);
bool is_shared = login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT);
@@ -543,30 +513,30 @@ shared_ptr<Login> AccountIndex::from_dc_credentials_locked(
return login;
}
shared_ptr<Login> AccountIndex::from_dc_credentials(
uint32_t serial_number, const string& access_key, const string& character_name, bool allow_create) {
std::shared_ptr<Login> AccountIndex::from_dc_credentials(
uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create) {
if (serial_number == 0) {
throw no_username();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_dc_credentials_locked(serial_number, access_key, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_dc_credentials_locked(serial_number, access_key, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = serial_number;
auto lic = make_shared<V1V2License>();
auto lic = std::make_shared<V1V2License>();
lic->serial_number = serial_number;
lic->access_key = access_key;
login->account->dc_licenses.emplace(lic->serial_number, lic);
@@ -578,19 +548,19 @@ shared_ptr<Login> AccountIndex::from_dc_credentials(
}
}
shared_ptr<Login> AccountIndex::from_pc_nte_credentials(uint32_t guild_card_number, bool allow_create) {
std::shared_ptr<Login> AccountIndex::from_pc_nte_credentials(uint32_t guild_card_number, bool allow_create) {
if (!allow_create) {
throw missing_account();
}
if (guild_card_number == 0xFFFFFFFF) {
guild_card_number = phosg::random_object<uint32_t>() & 0x7FFFFFFF;
}
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = guild_card_number;
login->account->is_temporary = true;
auto lic = make_shared<V1V2License>();
auto lic = std::make_shared<V1V2License>();
lic->serial_number = guild_card_number;
login->account->pc_licenses.emplace(lic->serial_number, lic);
login->pc_license = lic;
@@ -598,9 +568,9 @@ shared_ptr<Login> AccountIndex::from_pc_nte_credentials(uint32_t guild_card_numb
return login;
}
shared_ptr<Login> AccountIndex::from_pc_credentials_locked(
uint32_t serial_number, const string& access_key, const string& character_name) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_pc_credentials_locked(
uint32_t serial_number, const std::string& access_key, const std::string& character_name) {
auto login = std::make_shared<Login>();
login->account = this->by_pc_serial_number.at(serial_number);
login->pc_license = login->account->pc_licenses.at(serial_number);
bool is_shared = login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT);
@@ -616,30 +586,30 @@ shared_ptr<Login> AccountIndex::from_pc_credentials_locked(
return login;
}
shared_ptr<Login> AccountIndex::from_pc_credentials(
uint32_t serial_number, const string& access_key, const string& character_name, bool allow_create) {
std::shared_ptr<Login> AccountIndex::from_pc_credentials(
uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create) {
if (serial_number == 0) {
throw no_username();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_pc_credentials_locked(serial_number, access_key, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_pc_credentials_locked(serial_number, access_key, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = serial_number;
auto lic = make_shared<V1V2License>();
auto lic = std::make_shared<V1V2License>();
lic->serial_number = serial_number;
lic->access_key = access_key;
login->account->pc_licenses.emplace(lic->serial_number, lic);
@@ -651,9 +621,12 @@ shared_ptr<Login> AccountIndex::from_pc_credentials(
}
}
shared_ptr<Login> AccountIndex::from_gc_credentials_locked(
uint32_t serial_number, const string& access_key, const string* password, const string& character_name) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_gc_credentials_locked(
uint32_t serial_number,
const std::string& access_key,
const std::string* password,
const std::string& character_name) {
auto login = std::make_shared<Login>();
login->account = this->by_gc_serial_number.at(serial_number);
login->gc_license = login->account->gc_licenses.at(serial_number);
bool is_shared = login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT);
@@ -672,30 +645,34 @@ shared_ptr<Login> AccountIndex::from_gc_credentials_locked(
return login;
}
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) {
std::shared_ptr<Login> AccountIndex::from_gc_credentials(
uint32_t serial_number,
const std::string& access_key,
const std::string* password,
const std::string& character_name,
bool allow_create) {
if (serial_number == 0) {
throw no_username();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_gc_credentials_locked(serial_number, access_key, password, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_gc_credentials_locked(serial_number, access_key, password, character_name);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create && password) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = serial_number;
auto lic = make_shared<GCLicense>();
auto lic = std::make_shared<GCLicense>();
lic->serial_number = serial_number;
lic->access_key = access_key;
lic->password = *password;
@@ -708,8 +685,8 @@ shared_ptr<Login> AccountIndex::from_gc_credentials(
}
}
shared_ptr<Login> AccountIndex::from_xb_credentials_locked(uint64_t user_id) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_xb_credentials_locked(uint64_t user_id) {
auto login = std::make_shared<Login>();
login->account = this->by_xb_user_id.at(user_id);
login->xb_license = login->account->xb_licenses.at(user_id);
if (login->account->ban_end_time && (login->account->ban_end_time >= phosg::now())) {
@@ -718,30 +695,30 @@ shared_ptr<Login> AccountIndex::from_xb_credentials_locked(uint64_t user_id) {
return login;
}
shared_ptr<Login> AccountIndex::from_xb_credentials(
const string& gamertag, uint64_t user_id, uint64_t account_id, bool allow_create) {
std::shared_ptr<Login> AccountIndex::from_xb_credentials(
const std::string& gamertag, uint64_t user_id, uint64_t account_id, bool allow_create) {
if (user_id == 0 || account_id == 0) {
throw incorrect_access_key();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_xb_credentials_locked(user_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_xb_credentials_locked(user_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = phosg::fnv1a32(gamertag) & 0x7FFFFFFF;
auto lic = make_shared<XBLicense>();
auto lic = std::make_shared<XBLicense>();
lic->gamertag = gamertag;
lic->user_id = user_id;
lic->account_id = account_id;
@@ -754,8 +731,9 @@ shared_ptr<Login> AccountIndex::from_xb_credentials(
}
}
shared_ptr<Login> AccountIndex::from_bb_credentials_locked(const string& username, const string* password) {
auto login = make_shared<Login>();
std::shared_ptr<Login> AccountIndex::from_bb_credentials_locked(
const std::string& username, const std::string* password) {
auto login = std::make_shared<Login>();
login->account = this->by_bb_username.at(username);
login->bb_license = login->account->bb_licenses.at(username);
if (password && (login->bb_license->password != *password)) {
@@ -767,29 +745,30 @@ 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) {
std::shared_ptr<Login> AccountIndex::from_bb_credentials(
const std::string& username, const std::string* password, bool allow_create) {
if (username.empty() || (password && password->empty())) {
throw no_username();
}
try {
shared_lock g(this->lock);
std::shared_lock g(this->lock);
return this->from_bb_credentials_locked(username, password);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
unique_lock g(this->lock);
std::unique_lock g(this->lock);
try {
return this->from_bb_credentials_locked(username, password);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (allow_create && password) {
auto login = make_shared<Login>();
auto login = std::make_shared<Login>();
login->account_was_created = true;
login->account = make_shared<Account>();
login->account = std::make_shared<Account>();
login->account->account_id = phosg::fnv1a32(username) & 0x7FFFFFFF;
auto lic = make_shared<BBLicense>();
auto lic = std::make_shared<BBLicense>();
lic->username = username;
lic->password = *password;
login->account->bb_licenses.emplace(lic->username, lic);
@@ -801,9 +780,9 @@ shared_ptr<Login> AccountIndex::from_bb_credentials(const string& username, cons
}
}
vector<shared_ptr<Account>> AccountIndex::all() const {
shared_lock g(this->lock);
vector<shared_ptr<Account>> ret;
std::vector<std::shared_ptr<Account>> AccountIndex::all() const {
std::shared_lock g(this->lock);
std::vector<std::shared_ptr<Account>> ret;
ret.reserve(this->by_account_id.size());
for (const auto& it : this->by_account_id) {
ret.emplace_back(it.second);
@@ -811,44 +790,44 @@ vector<shared_ptr<Account>> AccountIndex::all() const {
return ret;
}
void AccountIndex::add(shared_ptr<Account> a) {
unique_lock g(this->lock);
void AccountIndex::add(std::shared_ptr<Account> a) {
std::unique_lock g(this->lock);
this->add_locked(a);
}
void AccountIndex::add_locked(shared_ptr<Account> a) {
void AccountIndex::add_locked(std::shared_ptr<Account> a) {
if (this->force_all_temporary) {
a->is_temporary = true;
}
for (const auto& it : a->dc_nte_licenses) {
if (this->by_dc_nte_serial_number.count(it.second->serial_number)) {
throw runtime_error("account already exists with this DC NTE serial number");
throw std::runtime_error("account already exists with this DC NTE serial number");
}
}
for (const auto& it : a->dc_licenses) {
if (this->by_dc_serial_number.count(it.second->serial_number)) {
throw runtime_error("account already exists with this DC serial number");
throw std::runtime_error("account already exists with this DC serial number");
}
}
for (const auto& it : a->pc_licenses) {
if (this->by_pc_serial_number.count(it.second->serial_number)) {
throw runtime_error("account already exists with this PC NTE serial number");
throw std::runtime_error("account already exists with this PC NTE serial number");
}
}
for (const auto& it : a->gc_licenses) {
if (this->by_gc_serial_number.count(it.second->serial_number)) {
throw runtime_error("account already exists with this GC serial number");
throw std::runtime_error("account already exists with this GC serial number");
}
}
for (const auto& it : a->xb_licenses) {
if (this->by_xb_user_id.count(it.second->user_id)) {
throw runtime_error("account already exists with this XB user ID");
throw std::runtime_error("account already exists with this XB user ID");
}
}
for (const auto& it : a->bb_licenses) {
if (this->by_bb_username.count(it.second->username)) {
throw runtime_error("account already exists with this BB username");
throw std::runtime_error("account already exists with this BB username");
}
}
@@ -878,10 +857,10 @@ void AccountIndex::add_locked(shared_ptr<Account> a) {
}
void AccountIndex::remove(uint32_t account_id) {
unique_lock g(this->lock);
std::unique_lock g(this->lock);
auto acc_it = this->by_account_id.find(account_id);
if (acc_it == this->by_account_id.end()) {
throw out_of_range("account does not exist");
throw std::out_of_range("account does not exist");
}
auto a = std::move(acc_it->second);
this->by_account_id.erase(acc_it);
@@ -906,154 +885,153 @@ void AccountIndex::remove(uint32_t account_id) {
}
}
void AccountIndex::add_dc_nte_license(shared_ptr<Account> account, shared_ptr<DCNTELicense> license) {
void AccountIndex::add_dc_nte_license(std::shared_ptr<Account> account, std::shared_ptr<DCNTELicense> license) {
if (!this->by_dc_nte_serial_number.emplace(license->serial_number, account).second) {
throw runtime_error("serial number already registered");
throw std::runtime_error("serial number already registered");
}
if (!account->dc_nte_licenses.emplace(license->serial_number, license).second) {
this->by_dc_nte_serial_number.erase(license->serial_number);
throw logic_error("serial number registered in account but not in account index");
throw std::logic_error("serial number registered in account but not in account index");
}
}
void AccountIndex::add_dc_license(shared_ptr<Account> account, shared_ptr<V1V2License> license) {
void AccountIndex::add_dc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license) {
if (!this->by_dc_serial_number.emplace(license->serial_number, account).second) {
throw runtime_error("serial number already registered");
throw std::runtime_error("serial number already registered");
}
if (!account->dc_licenses.emplace(license->serial_number, license).second) {
this->by_dc_serial_number.erase(license->serial_number);
throw logic_error("serial number registered in account but not in account index");
throw std::logic_error("serial number registered in account but not in account index");
}
}
void AccountIndex::add_pc_license(shared_ptr<Account> account, shared_ptr<V1V2License> license) {
void AccountIndex::add_pc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license) {
if (!this->by_pc_serial_number.emplace(license->serial_number, account).second) {
throw runtime_error("serial number already registered");
throw std::runtime_error("serial number already registered");
}
if (!account->pc_licenses.emplace(license->serial_number, license).second) {
this->by_pc_serial_number.erase(license->serial_number);
throw logic_error("serial number registered in account but not in account index");
throw std::logic_error("serial number registered in account but not in account index");
}
}
void AccountIndex::add_gc_license(shared_ptr<Account> account, shared_ptr<GCLicense> license) {
void AccountIndex::add_gc_license(std::shared_ptr<Account> account, std::shared_ptr<GCLicense> license) {
if (!this->by_gc_serial_number.emplace(license->serial_number, account).second) {
throw runtime_error("serial number already registered");
throw std::runtime_error("serial number already registered");
}
if (!account->gc_licenses.emplace(license->serial_number, license).second) {
this->by_gc_serial_number.erase(license->serial_number);
throw logic_error("serial number registered in account but not in account index");
throw std::logic_error("serial number registered in account but not in account index");
}
}
void AccountIndex::add_xb_license(shared_ptr<Account> account, shared_ptr<XBLicense> license) {
void AccountIndex::add_xb_license(std::shared_ptr<Account> account, std::shared_ptr<XBLicense> license) {
if (!this->by_xb_user_id.emplace(license->user_id, account).second) {
throw runtime_error("user ID already registered");
throw std::runtime_error("user ID already registered");
}
if (!account->xb_licenses.emplace(license->user_id, license).second) {
this->by_xb_user_id.erase(license->user_id);
throw logic_error("user ID registered in account but not in account index");
throw std::logic_error("user ID registered in account but not in account index");
}
}
void AccountIndex::add_bb_license(shared_ptr<Account> account, shared_ptr<BBLicense> license) {
void AccountIndex::add_bb_license(std::shared_ptr<Account> account, std::shared_ptr<BBLicense> license) {
if (!this->by_bb_username.emplace(license->username, account).second) {
throw runtime_error("username already registered");
throw std::runtime_error("username already registered");
}
if (!account->bb_licenses.emplace(license->username, license).second) {
this->by_bb_username.erase(license->username);
throw logic_error("username registered in account but not in account index");
throw std::logic_error("username registered in account but not in account index");
}
}
void AccountIndex::remove_dc_nte_license(shared_ptr<Account> account, const string& serial_number) {
void AccountIndex::remove_dc_nte_license(std::shared_ptr<Account> account, const std::string& serial_number) {
auto it = account->dc_nte_licenses.find(serial_number);
if (it == account->dc_nte_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_dc_nte_serial_number.erase(it->second->serial_number)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->dc_nte_licenses.erase(it);
}
void AccountIndex::remove_dc_license(shared_ptr<Account> account, uint32_t serial_number) {
void AccountIndex::remove_dc_license(std::shared_ptr<Account> account, uint32_t serial_number) {
auto it = account->dc_licenses.find(serial_number);
if (it == account->dc_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_dc_serial_number.erase(it->second->serial_number)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->dc_licenses.erase(it);
}
void AccountIndex::remove_pc_license(shared_ptr<Account> account, uint32_t serial_number) {
void AccountIndex::remove_pc_license(std::shared_ptr<Account> account, uint32_t serial_number) {
auto it = account->pc_licenses.find(serial_number);
if (it == account->pc_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_pc_serial_number.erase(it->second->serial_number)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->pc_licenses.erase(it);
}
void AccountIndex::remove_gc_license(shared_ptr<Account> account, uint32_t serial_number) {
void AccountIndex::remove_gc_license(std::shared_ptr<Account> account, uint32_t serial_number) {
auto it = account->gc_licenses.find(serial_number);
if (it == account->gc_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_gc_serial_number.erase(it->second->serial_number)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->gc_licenses.erase(it);
}
void AccountIndex::remove_xb_license(shared_ptr<Account> account, uint64_t user_id) {
void AccountIndex::remove_xb_license(std::shared_ptr<Account> account, uint64_t user_id) {
auto it = account->xb_licenses.find(user_id);
if (it == account->xb_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_xb_user_id.erase(it->second->user_id)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->xb_licenses.erase(it);
}
void AccountIndex::remove_bb_license(shared_ptr<Account> account, const string& username) {
void AccountIndex::remove_bb_license(std::shared_ptr<Account> account, const std::string& username) {
auto it = account->bb_licenses.find(username);
if (it == account->bb_licenses.end()) {
throw runtime_error("license not registered to account");
throw std::runtime_error("license not registered to account");
}
if (!this->by_bb_username.erase(it->second->username)) {
throw runtime_error("license registered in account but not in account index");
throw std::runtime_error("license registered in account but not in account index");
}
account->bb_licenses.erase(it);
}
shared_ptr<Account> AccountIndex::create_temporary_account_for_shared_account(
shared_ptr<const Account> src_a, const string& variation_data) const {
auto ret = make_shared<Account>(*src_a);
std::shared_ptr<Account> AccountIndex::create_temporary_account_for_shared_account(
std::shared_ptr<const Account> src_a, const std::string& variation_data) const {
auto ret = std::make_shared<Account>(*src_a);
ret->is_temporary = true;
ret->account_id = phosg::fnv1a32(&src_a->account_id, sizeof(src_a->account_id));
ret->account_id = phosg::fnv1a32(variation_data, ret->account_id);
return ret;
}
AccountIndex::AccountIndex(bool force_all_temporary)
: force_all_temporary(force_all_temporary) {
AccountIndex::AccountIndex(bool force_all_temporary) : force_all_temporary(force_all_temporary) {
if (!this->force_all_temporary) {
if (!std::filesystem::is_directory("system/licenses")) {
std::filesystem::create_directories("system/licenses");
} else {
for (const auto& item : std::filesystem::directory_iterator("system/licenses")) {
string filename = item.path().filename().string();
std::string filename = item.path().filename().string();
if (filename.ends_with(".json")) {
try {
phosg::JSON json = phosg::JSON::parse(phosg::load_file("system/licenses/" + filename));
this->add(make_shared<Account>(json));
} catch (const exception& e) {
this->add(std::make_shared<Account>(json));
} catch (const std::exception& e) {
phosg::log_error_f("Failed to index account {}", filename);
throw;
}
+12 -60
View File
@@ -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);
};
+834
View File
@@ -0,0 +1,834 @@
#include "AccountSync.hh"
#include "AsyncUtils.hh"
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cstdio>
#include <inttypes.h>
#include <filesystem>
#include <memory>
#include <format>
#include <fstream>
#include <mutex>
#include <stdexcept>
#include <string>
namespace AccountSync {
static std::mutex config_mutex;
static std::mutex spool_mutex;
static Config current_config;
static std::atomic<bool> heartbeat_task_started(false);
static asio::io_context* login_lock_io_context = nullptr;
static uint64_t now_usecs() {
using namespace std::chrono;
return duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
}
static Config get_config() {
std::lock_guard<std::mutex> g(config_mutex);
return current_config;
}
struct ParsedHTTPURL {
std::string host;
uint16_t port = 80;
std::string path = "/";
};
static ParsedHTTPURL parse_http_url(const std::string& url) {
static const std::string prefix = "http://";
if (!url.starts_with(prefix)) {
throw std::runtime_error("only http:// coordinator URLs are supported");
}
size_t host_start = prefix.size();
size_t path_start = url.find('/', host_start);
std::string host_port = (path_start == std::string::npos)
? url.substr(host_start)
: url.substr(host_start, path_start - host_start);
ParsedHTTPURL ret;
ret.path = (path_start == std::string::npos) ? "/" : url.substr(path_start);
if (host_port.empty()) {
throw std::runtime_error("coordinator URL has empty host");
}
size_t colon_offset = host_port.rfind(':');
if (colon_offset == std::string::npos) {
ret.host = host_port;
} else {
ret.host = host_port.substr(0, colon_offset);
std::string port_s = host_port.substr(colon_offset + 1);
if (ret.host.empty() || port_s.empty()) {
throw std::runtime_error("coordinator URL has invalid host/port");
}
size_t end_offset = 0;
uint64_t port = std::stoull(port_s, &end_offset, 10);
if ((end_offset != port_s.size()) || (port == 0) || (port > 0xFFFF)) {
throw std::runtime_error("coordinator URL has invalid port");
}
ret.port = port;
}
return ret;
}
static std::string join_url_path(std::string base_path, const std::string& suffix) {
while ((base_path.size() > 1) && (base_path.back() == '/')) {
base_path.pop_back();
}
if (base_path.empty() || (base_path == "/")) {
return suffix;
}
return base_path + suffix;
}
static std::string lowercase(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char ch) -> char {
return static_cast<char>(std::tolower(ch));
});
return s;
}
static void trim_ascii_inplace(std::string& s) {
while (!s.empty() && ((s.back() == ' ') || (s.back() == '\t') || (s.back() == '\r') || (s.back() == '\n'))) {
s.pop_back();
}
size_t start = 0;
while ((start < s.size()) && ((s[start] == ' ') || (s[start] == '\t') || (s[start] == '\r') || (s[start] == '\n'))) {
start++;
}
if (start) {
s = s.substr(start);
}
}
static asio::awaitable<std::string> read_http_line(
asio::ip::tcp::socket& sock,
std::string& pending_data,
size_t max_length) {
static const char* delimiter = "\r\n";
static const size_t delimiter_size = 2;
size_t delimiter_pos = pending_data.find(delimiter);
while ((delimiter_pos == std::string::npos) && (pending_data.size() < max_length)) {
size_t pre_size = pending_data.size();
pending_data.resize(std::min(max_length, pending_data.size() + 0x400));
size_t bytes_read = co_await sock.async_read_some(
asio::buffer(pending_data.data() + pre_size, pending_data.size() - pre_size),
asio::use_awaitable);
pending_data.resize(pre_size + bytes_read);
delimiter_pos = pending_data.find(delimiter, (pre_size >= 1) ? (pre_size - 1) : 0);
}
if (delimiter_pos == std::string::npos) {
throw std::runtime_error("HTTP response line exceeds maximum length");
}
std::string ret = pending_data.substr(0, delimiter_pos);
pending_data = pending_data.substr(delimiter_pos + delimiter_size);
co_return ret;
}
static asio::awaitable<std::string> read_http_data(
asio::ip::tcp::socket& sock,
std::string& pending_data,
size_t size) {
std::string ret;
if (pending_data.size() == size) {
pending_data.swap(ret);
} else if (pending_data.size() > size) {
ret = pending_data.substr(0, size);
pending_data = pending_data.substr(size);
} else {
size_t bytes_to_read = size - pending_data.size();
pending_data.swap(ret);
ret.resize(size);
co_await asio::async_read(
sock,
asio::buffer(ret.data() + size - bytes_to_read, bytes_to_read),
asio::use_awaitable);
}
co_return ret;
}
static asio::awaitable<phosg::JSON> post_json_with_timeout(
const Config& cfg,
const std::string& path_suffix,
const std::string& body) {
ParsedHTTPURL url = parse_http_url(cfg.coordinator_url);
std::string path = join_url_path(url.path, path_suffix);
auto executor = co_await asio::this_coro::executor;
auto resolver = std::make_shared<asio::ip::tcp::resolver>(executor);
auto sock = std::make_shared<asio::ip::tcp::socket>(executor);
auto timer = std::make_shared<asio::steady_timer>(executor);
auto timed_out = std::make_shared<bool>(false);
timer->expires_after(std::chrono::microseconds(cfg.request_timeout_usecs));
timer->async_wait([resolver, sock, timed_out](std::error_code ec) -> void {
if (!ec) {
*timed_out = true;
resolver->cancel();
if (sock->is_open()) {
sock->close();
}
}
});
try {
auto endpoints = co_await resolver->async_resolve(url.host, std::format("{}", url.port), asio::use_awaitable);
co_await asio::async_connect(*sock, endpoints, asio::use_awaitable);
std::string host_header = url.host;
if (url.port != 80) {
host_header += std::format(":{}", url.port);
}
std::string request = std::format(
"POST {} HTTP/1.1\r\n"
"Host: {}\r\n"
"User-Agent: psopeeps-newserv\r\n"
"Content-Type: application/json\r\n"
"Accept: application/json\r\n"
"Connection: close\r\n"
"X-Psopeeps-Admin-Secret: {}\r\n"
"Content-Length: {}\r\n"
"\r\n"
"{}",
path,
host_header,
cfg.shared_secret,
body.size(),
body);
co_await asio::async_write(*sock, asio::buffer(request), asio::use_awaitable);
std::string pending_data;
std::string status_line = co_await read_http_line(*sock, pending_data, 0x1000);
if (!status_line.starts_with("HTTP/1.")) {
throw std::runtime_error("invalid HTTP response from coordinator");
}
size_t first_space = status_line.find(' ');
if (first_space == std::string::npos) {
throw std::runtime_error("invalid HTTP status line from coordinator");
}
size_t second_space = status_line.find(' ', first_space + 1);
std::string code_s = status_line.substr(
first_space + 1,
(second_space == std::string::npos) ? std::string::npos : (second_space - first_space - 1));
int response_code = std::stoi(code_s);
size_t content_length = 0;
for (;;) {
std::string line = co_await read_http_line(*sock, pending_data, 0x10000);
if (line.empty()) {
break;
}
size_t colon_offset = line.find(':');
if (colon_offset == std::string::npos) {
continue;
}
std::string name = lowercase(line.substr(0, colon_offset));
std::string value = line.substr(colon_offset + 1);
trim_ascii_inplace(value);
if (name == "content-length") {
size_t end_offset = 0;
content_length = std::stoull(value, &end_offset, 10);
if (end_offset != value.size()) {
throw std::runtime_error("invalid Content-Length from coordinator");
}
}
}
if (response_code != 200) {
throw std::runtime_error(std::format("coordinator returned HTTP {}", response_code));
}
if (content_length > 0x100000) {
throw std::runtime_error("coordinator response is too large");
}
std::string response_body = co_await read_http_data(*sock, pending_data, content_length);
timer->cancel();
co_return phosg::JSON::parse(response_body);
} catch (...) {
timer->cancel();
if (*timed_out) {
throw std::runtime_error("coordinator request timed out");
}
throw;
}
}
static std::string source_label(const Config& cfg) {
if (!cfg.source.empty()) {
return cfg.source;
}
if (!cfg.source_region.empty() && !cfg.source_ship.empty()) {
return cfg.source_region + "-" + cfg.source_ship;
}
if (!cfg.source_region.empty()) {
return cfg.source_region;
}
if (!cfg.source_ship.empty()) {
return cfg.source_ship;
}
return "unknown";
}
static std::string json_escape(const std::string& s) {
std::string ret;
ret.reserve(s.size() + 8);
for (unsigned char ch : s) {
switch (ch) {
case '\\':
ret += "\\\\";
break;
case '"':
ret += "\\\"";
break;
case '\b':
ret += "\\b";
break;
case '\f':
ret += "\\f";
break;
case '\n':
ret += "\\n";
break;
case '\r':
ret += "\\r";
break;
case '\t':
ret += "\\t";
break;
default:
if (ch < 0x20) {
char buf[8];
std::snprintf(buf, sizeof(buf), "\\u%04X", ch);
ret += buf;
} else {
ret += static_cast<char>(ch);
}
}
}
return ret;
}
static void append_spool_line(const Config& cfg, const std::string& line) {
if (cfg.spool_directory.empty()) {
return;
}
try {
std::lock_guard<std::mutex> g(spool_mutex);
std::filesystem::create_directories(cfg.spool_directory);
std::filesystem::path path = std::filesystem::path(cfg.spool_directory) / "events.jsonl";
std::ofstream f(path, std::ios::app);
if (!f) {
throw std::runtime_error("failed to open spool file");
}
f << line << '\n';
} catch (const std::exception& e) {
std::fprintf(stderr,
"[AccountSync] warning failed_to_write_spool directory=%s error=%s\n",
cfg.spool_directory.c_str(),
e.what());
}
}
static std::string base_event_json(const Config& cfg, const char* event, uint32_t account_id) {
return std::format(
"{{\"timestamp_usecs\":{},\"producer\":\"newserv\",\"source\":\"{}\",\"source_region\":\"{}\",\"source_ship\":\"{}\",\"account_store\":\"{}\",\"event\":\"{}\",\"account_id\":{},\"account_id_str\":\"{:010}\"",
now_usecs(),
json_escape(source_label(cfg)),
json_escape(cfg.source_region),
json_escape(cfg.source_ship),
json_escape(cfg.account_store),
json_escape(event),
static_cast<unsigned int>(account_id),
static_cast<unsigned int>(account_id));
}
void configure(const Config& cfg) {
{
std::lock_guard<std::mutex> g(config_mutex);
current_config = cfg;
}
if (cfg.enabled) {
std::fprintf(stderr,
"[AccountSync] config enabled source=%s source_region=%s source_ship=%s account_store=%s coordinator_url=%s notify_bb_sessions=%s spool_directory=%s login_locks=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
cfg.coordinator_url.c_str(),
cfg.notify_bb_sessions ? "true" : "false",
cfg.spool_directory.c_str(),
cfg.enable_login_locks ? "true" : "false");
}
}
void configure_from_json(const phosg::JSON& json) {
Config cfg;
cfg.enabled = json.get_bool("Enabled", false);
const std::string legacy_region = json.get_string("Region", "");
cfg.source = json.get_string("Source", legacy_region);
cfg.source_region = json.get_string("SourceRegion", "");
cfg.source_ship = json.get_string("SourceShip", "");
cfg.account_store = json.get_string("AccountStore", "shared");
if (cfg.source_region.empty() && cfg.source_ship.empty() && !legacy_region.empty()) {
size_t dash_offset = legacy_region.find('-');
if (dash_offset != std::string::npos) {
cfg.source_region = legacy_region.substr(0, dash_offset);
cfg.source_ship = legacy_region.substr(dash_offset + 1);
} else {
cfg.source_region = legacy_region;
}
}
cfg.coordinator_url = json.get_string("CoordinatorURL", "");
cfg.shared_secret = json.get_string("SharedSecret", "");
cfg.request_timeout_usecs = json.get_int("RequestTimeoutUsecs", 3000000);
cfg.fail_open = json.get_bool("FailOpen", false);
cfg.notify_account_saves = json.get_bool("NotifyAccountSaves", true);
cfg.notify_player_saves = json.get_bool("NotifyPlayerSaves", true);
cfg.notify_backup_saves = json.get_bool("NotifyBackupSaves", true);
cfg.enable_login_locks = json.get_bool("EnableLoginLocks", false);
cfg.login_lock_heartbeat_interval_usecs = json.get_int("LoginLockHeartbeatIntervalUsecs", 60000000);
cfg.notify_bb_sessions = json.get_bool("NotifyBBSessions", cfg.enable_login_locks);
cfg.spool_directory = json.get_string("SpoolDirectory", "system/account-sync-spool");
configure(cfg);
}
static asio::awaitable<void> send_login_lock_heartbeat() {
auto cfg = get_config();
if (!cfg.enabled || !cfg.enable_login_locks) {
co_return;
}
if (cfg.coordinator_url.empty()) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_heartbeat_skipped reason=coordinator_url_not_configured source=%s\n",
source_label(cfg).c_str());
co_return;
}
std::string body = std::format(
"{{\"source\":\"{}\",\"source_region\":\"{}\",\"source_ship\":\"{}\",\"account_store\":\"{}\"}}",
json_escape(source_label(cfg)),
json_escape(cfg.source_region),
json_escape(cfg.source_ship),
json_escape(cfg.account_store));
try {
phosg::JSON response = co_await post_json_with_timeout(cfg, "/account-locks/heartbeat", body);
bool ok = response.get_bool("ok", response.get_bool("OK", false));
if (!ok) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_heartbeat_rejected source=%s response=%s\n",
source_label(cfg).c_str(),
response.serialize().c_str());
co_return;
}
int64_t refreshed = response.get_int("refreshed", 0);
std::fprintf(stderr,
"[AccountSync] login_lock_heartbeat_ok source=%s refreshed=%" PRId64 "\n",
source_label(cfg).c_str(),
refreshed);
} catch (const std::exception& e) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_heartbeat_failed source=%s error=%s\n",
source_label(cfg).c_str(),
e.what());
}
}
static asio::awaitable<void> login_lock_heartbeat_task() {
for (;;) {
auto cfg = get_config();
uint64_t interval_usecs = cfg.login_lock_heartbeat_interval_usecs;
if (interval_usecs < 5000000) {
interval_usecs = 5000000;
}
co_await async_sleep(std::chrono::microseconds(interval_usecs));
co_await send_login_lock_heartbeat();
}
}
void start_login_lock_heartbeat_task(asio::io_context& io_context) {
login_lock_io_context = &io_context;
bool expected = false;
if (!heartbeat_task_started.compare_exchange_strong(expected, true)) {
return;
}
asio::co_spawn(io_context, login_lock_heartbeat_task(), asio::detached);
std::fprintf(stderr, "[AccountSync] login lock heartbeat task started\n");
}
asio::awaitable<LoginLockAcquireResult> acquire_login_lock(
uint32_t account_id,
const std::string& version_name,
const std::string& existing_session_nonce) {
auto cfg = get_config();
LoginLockAcquireResult ret;
if (!cfg.enabled || !cfg.enable_login_locks) {
co_return ret;
}
if (!existing_session_nonce.empty()) {
ret.session_nonce = existing_session_nonce;
co_return ret;
}
std::string proposed_session_nonce = std::format("{}-{}-{}", source_label(cfg), account_id, now_usecs());
if (cfg.coordinator_url.empty()) {
std::string message = "account lock coordinator URL is not configured";
if (cfg.fail_open) {
ret.allowed = true;
ret.fail_open_used = true;
ret.session_nonce = proposed_session_nonce;
ret.message = message;
std::fprintf(stderr,
"[AccountSync] warning login_lock_fail_open reason=%s account_id=%010u source=%s version=%s nonce=%s\n",
message.c_str(),
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str(),
ret.session_nonce.c_str());
co_return ret;
}
ret.allowed = false;
ret.message = "$C6Account lock server\nis unavailable.";
std::fprintf(stderr,
"[AccountSync] login_lock_denied reason=%s account_id=%010u source=%s version=%s\n",
message.c_str(),
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str());
co_return ret;
}
std::string body = std::format(
"{{\"account_id\":{},\"account_id_str\":\"{:010}\",\"source\":\"{}\",\"source_region\":\"{}\",\"source_ship\":\"{}\",\"account_store\":\"{}\",\"version\":\"{}\",\"session_nonce\":\"{}\"}}",
static_cast<unsigned int>(account_id),
static_cast<unsigned int>(account_id),
json_escape(source_label(cfg)),
json_escape(cfg.source_region),
json_escape(cfg.source_ship),
json_escape(cfg.account_store),
json_escape(version_name),
json_escape(proposed_session_nonce));
try {
phosg::JSON response = co_await post_json_with_timeout(cfg, "/account-locks/acquire", body);
ret.allowed = response.get_bool("ok", response.get_bool("OK", false));
ret.session_nonce = response.get_string("session_nonce", proposed_session_nonce);
ret.message = response.get_string("message", "");
ret.holder_source = response.get_string("holder_source", "");
if (ret.allowed) {
if (ret.session_nonce.empty()) {
ret.session_nonce = proposed_session_nonce;
}
std::fprintf(stderr,
"[AccountSync] login_lock_acquired account_id=%010u source=%s version=%s nonce=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str(),
ret.session_nonce.c_str());
} else {
if (ret.message.empty()) {
ret.message = "$C6Account is already active\non another ship.";
}
std::fprintf(stderr,
"[AccountSync] login_lock_denied account_id=%010u source=%s version=%s holder_source=%s message=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str(),
ret.holder_source.c_str(),
ret.message.c_str());
}
co_return ret;
} catch (const std::exception& e) {
if (cfg.fail_open) {
ret.allowed = true;
ret.fail_open_used = true;
ret.session_nonce = proposed_session_nonce;
ret.message = e.what();
std::fprintf(stderr,
"[AccountSync] warning login_lock_fail_open reason=%s account_id=%010u source=%s version=%s nonce=%s\n",
e.what(),
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str(),
ret.session_nonce.c_str());
co_return ret;
}
ret.allowed = false;
ret.message = "$C6Account lock server\nis unavailable.";
std::fprintf(stderr,
"[AccountSync] login_lock_denied reason=%s account_id=%010u source=%s version=%s\n",
e.what(),
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str());
co_return ret;
}
}
static asio::awaitable<void> send_login_lock_session_end(
uint32_t account_id,
std::string session_nonce,
std::string version_name) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.enable_login_locks) {
co_return;
}
if (cfg.coordinator_url.empty()) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_session_end_skipped reason=coordinator_url_not_configured account_id=%010u source=%s nonce=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
session_nonce.c_str());
co_return;
}
if (session_nonce.empty()) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_session_end_skipped reason=empty_session_nonce account_id=%010u source=%s version=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
version_name.c_str());
co_return;
}
std::string body = std::format(
"{{\"account_id\":{},\"account_id_str\":\"{:010}\",\"source\":\"{}\",\"source_region\":\"{}\",\"source_ship\":\"{}\",\"account_store\":\"{}\",\"version\":\"{}\",\"session_nonce\":\"{}\"}}",
static_cast<unsigned int>(account_id),
static_cast<unsigned int>(account_id),
json_escape(source_label(cfg)),
json_escape(cfg.source_region),
json_escape(cfg.source_ship),
json_escape(cfg.account_store),
json_escape(version_name),
json_escape(session_nonce));
try {
phosg::JSON response = co_await post_json_with_timeout(cfg, "/account-locks/session-end", body);
bool ok = response.get_bool("ok", response.get_bool("OK", false));
if (!ok) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_session_end_rejected account_id=%010u source=%s nonce=%s response=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
session_nonce.c_str(),
response.serialize().c_str());
co_return;
}
std::fprintf(stderr,
"[AccountSync] login_lock_session_end_ok account_id=%010u source=%s nonce=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
session_nonce.c_str());
} catch (const std::exception& e) {
std::fprintf(stderr,
"[AccountSync] warning login_lock_session_end_failed account_id=%010u source=%s nonce=%s error=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
session_nonce.c_str(),
e.what());
}
}
void notify_login_session_end(
uint32_t account_id,
const std::string& session_nonce,
const std::string& version_name) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.enable_login_locks) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=login_session_end source=%s source_region=%s source_ship=%s account_store=%s account_id=%010u session_nonce=%s version=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
static_cast<unsigned int>(account_id),
session_nonce.c_str(),
version_name.c_str());
if (login_lock_io_context) {
asio::co_spawn(
*login_lock_io_context,
send_login_lock_session_end(account_id, session_nonce, version_name),
asio::detached);
} else {
std::fprintf(stderr,
"[AccountSync] warning login_lock_session_end_not_spawned reason=io_context_not_available account_id=%010u source=%s nonce=%s\n",
static_cast<unsigned int>(account_id),
source_label(cfg).c_str(),
session_nonce.c_str());
}
auto line = base_event_json(cfg, "login_session_end", account_id) +
std::format(",\"session_nonce\":\"{}\",\"version\":\"{}\"}}",
json_escape(session_nonce),
json_escape(version_name));
append_spool_line(cfg, line);
}
void notify_account_saved(uint32_t account_id, const std::string& filename) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.notify_account_saves) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=account_saved source=%s source_region=%s source_ship=%s account_store=%s account_id=%010u filename=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
static_cast<unsigned int>(account_id),
filename.c_str());
auto line = base_event_json(cfg, "account_saved", account_id) +
std::format(",\"filename\":\"{}\"}}", json_escape(filename));
append_spool_line(cfg, line);
}
void notify_backup_saved(uint32_t account_id, size_t slot, const std::string& filename) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.notify_backup_saves) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=backup_saved source=%s source_region=%s source_ship=%s account_store=%s account_id=%010u slot=%zu filename=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
static_cast<unsigned int>(account_id),
slot,
filename.c_str());
auto line = base_event_json(cfg, "backup_saved", account_id) +
std::format(",\"slot\":{},\"filename\":\"{}\"}}", slot, json_escape(filename));
append_spool_line(cfg, line);
}
void notify_player_state_saved(
const char* reason,
uint32_t account_id,
const std::string& bb_username,
const std::string& filename) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.notify_player_saves) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=player_state_saved source=%s source_region=%s source_ship=%s account_store=%s reason=%s account_id=%010u bb_username=%s filename=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
reason,
static_cast<unsigned int>(account_id),
bb_username.c_str(),
filename.c_str());
auto line = base_event_json(cfg, "player_state_saved", account_id) +
std::format(",\"reason\":\"{}\",\"bb_username\":\"{}\",\"filename\":\"{}\"}}",
json_escape(reason),
json_escape(bb_username),
json_escape(filename));
append_spool_line(cfg, line);
}
void notify_bb_login_start(
uint32_t account_id,
const std::string& bb_username,
int64_t character_slot,
uint8_t connection_phase) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.notify_bb_sessions) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=bb_login_start source=%s source_region=%s source_ship=%s account_store=%s account_id=%010u bb_username=%s character_slot=%lld connection_phase=%u\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
static_cast<unsigned int>(account_id),
bb_username.c_str(),
static_cast<long long>(character_slot),
static_cast<unsigned int>(connection_phase));
auto line = base_event_json(cfg, "bb_login_start", account_id) +
std::format(",\"bb_username\":\"{}\",\"character_slot\":{},\"connection_phase\":{}}}",
json_escape(bb_username),
static_cast<long long>(character_slot),
static_cast<unsigned int>(connection_phase));
append_spool_line(cfg, line);
}
void notify_bb_login_end(
uint32_t account_id,
const std::string& bb_username,
int64_t character_slot) {
auto cfg = get_config();
if (!cfg.enabled || !cfg.notify_bb_sessions) {
return;
}
std::fprintf(stderr,
"[AccountSync] event=bb_login_end source=%s source_region=%s source_ship=%s account_store=%s account_id=%010u bb_username=%s character_slot=%lld\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.account_store.c_str(),
static_cast<unsigned int>(account_id),
bb_username.c_str(),
static_cast<long long>(character_slot));
auto line = base_event_json(cfg, "bb_login_end", account_id) +
std::format(",\"bb_username\":\"{}\",\"character_slot\":{}}}",
json_escape(bb_username),
static_cast<long long>(character_slot));
append_spool_line(cfg, line);
}
} // namespace AccountSync
+79
View File
@@ -0,0 +1,79 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <asio.hpp>
#include <string>
#include <phosg/JSON.hh>
namespace AccountSync {
struct Config {
bool enabled = false;
// Source identity. Region is no longer enough because account JSON is shared
// across live/test/hardcore in a region.
std::string source;
std::string source_region;
std::string source_ship;
std::string account_store = "shared";
std::string coordinator_url;
std::string shared_secret;
uint64_t request_timeout_usecs = 3000000;
bool fail_open = false;
bool notify_account_saves = true;
bool notify_player_saves = true;
bool notify_backup_saves = true;
bool notify_bb_sessions = false;
bool enable_login_locks = false; // Reserved for future blocking lock behavior
uint64_t login_lock_heartbeat_interval_usecs = 60000000;
std::string spool_directory = "system/account-sync-spool";
};
void configure(const Config& cfg);
void configure_from_json(const phosg::JSON& json);
struct LoginLockAcquireResult {
bool allowed = true;
bool fail_open_used = false;
std::string session_nonce;
std::string message;
std::string holder_source;
};
void start_login_lock_heartbeat_task(asio::io_context& io_context);
asio::awaitable<LoginLockAcquireResult> acquire_login_lock(
uint32_t account_id,
const std::string& version_name,
const std::string& existing_session_nonce);
void notify_login_session_end(
uint32_t account_id,
const std::string& session_nonce,
const std::string& version_name);
void notify_account_saved(uint32_t account_id, const std::string& filename);
void notify_backup_saved(uint32_t account_id, size_t slot, const std::string& filename);
void notify_player_state_saved(
const char* reason,
uint32_t account_id,
const std::string& bb_username,
const std::string& filename);
void notify_bb_login_start(
uint32_t account_id,
const std::string& bb_username,
int64_t character_slot,
uint8_t connection_phase);
void notify_bb_login_end(
uint32_t account_id,
const std::string& bb_username,
int64_t character_slot);
} // namespace AccountSync
+313 -122
View File
@@ -5,6 +5,7 @@
#include <future>
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#include <resource_file/ExecutableFormats/DOLFile.hh>
#include <resource_file/ExecutableFormats/PEFile.hh>
@@ -14,8 +15,6 @@
#include "Text.hh"
#include "Types.hh"
using namespace std;
class AddressTranslator {
public:
enum class ExpandMethod {
@@ -63,7 +62,7 @@ public:
case ExpandMethod::RAW_BOTH:
return "RAW_BOTH";
default:
throw logic_error("invalid expand method");
throw std::logic_error("invalid expand method");
}
}
@@ -85,7 +84,7 @@ public:
case ExpandMethod::RAW_BOTH:
return false;
default:
throw logic_error("invalid expand method");
throw std::logic_error("invalid expand method");
}
}
@@ -107,46 +106,46 @@ public:
case ExpandMethod::RAW_BOTH:
return false;
default:
throw logic_error("invalid expand method");
throw std::logic_error("invalid expand method");
}
}
AddressTranslator(const string& directory)
AddressTranslator(const std::string& directory)
: log("[addr-trans] "),
directory(directory) {
while (this->directory.ends_with("/")) {
this->directory.pop_back();
}
for (const auto& item : std::filesystem::directory_iterator(this->directory)) {
string filename = item.path().filename().string();
std::string filename = item.path().filename().string();
if (filename.size() < 4) {
continue;
}
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
std::string name = filename.substr(0, filename.size() - 4);
std::string path = directory + "/" + filename;
if (filename.ends_with(".dol")) {
ResourceDASM::DOLFile dol(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
auto mem = std::make_shared<ResourceDASM::MemoryContext>();
dol.load_into(mem);
this->mems.emplace(name, mem);
this->ppc_mems.emplace(mem);
this->log.info_f("Loaded {}", name);
} else if (filename.ends_with(".xbe")) {
ResourceDASM::XBEFile xbe(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
auto mem = std::make_shared<ResourceDASM::MemoryContext>();
xbe.load_into(mem);
this->mems.emplace(name, mem);
this->log.info_f("Loaded {}", name);
} else if (filename.ends_with(".exe")) {
ResourceDASM::PEFile pe(path.c_str());
auto mem = make_shared<ResourceDASM::MemoryContext>();
auto mem = std::make_shared<ResourceDASM::MemoryContext>();
pe.load_into(mem);
this->mems.emplace(name, mem);
this->log.info_f("Loaded {}", name);
} else if (filename.ends_with(".bin")) {
string data = phosg::load_file(path);
auto mem = make_shared<ResourceDASM::MemoryContext>();
std::string data = phosg::load_file(path);
auto mem = std::make_shared<ResourceDASM::MemoryContext>();
mem->allocate_at(0x8C010000, data.size());
mem->memcpy(0x8C010000, data.data(), data.size());
this->mems.emplace(name, mem);
@@ -156,10 +155,10 @@ public:
}
~AddressTranslator() = default;
const string& get_source_filename() const {
const std::string& get_source_filename() const {
return this->src_filename;
}
void set_source_file(const string& filename) {
void set_source_file(const std::string& filename) {
this->src_filename = filename;
this->src_mem = this->mems.at(this->src_filename);
}
@@ -178,25 +177,25 @@ public:
uint32_t opcode = r.get_u32b();
if ((opcode & 0xFFFF0000) == 0x3DA00000) {
if (r13_high_found) {
throw runtime_error("multiple values for r13_high");
throw std::runtime_error("multiple values for r13_high");
}
r13_high_found = true;
r13 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x3C400000) {
if (r2_high_found) {
throw runtime_error("multiple values for r2_high");
throw std::runtime_error("multiple values for r2_high");
}
r2_high_found = true;
r2 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x61AD0000) {
if (r13_low_found) {
throw runtime_error("multiple values for r13_low");
throw std::runtime_error("multiple values for r13_low");
}
r13_low_found = true;
r13 |= (opcode & 0xFFFF);
} else if ((opcode & 0xFFFF0000) == 0x60420000) {
if (r2_low_found) {
throw runtime_error("multiple values for r2_low");
throw std::runtime_error("multiple values for r2_low");
}
r2_low_found = true;
r2 |= (opcode & 0xFFFF);
@@ -217,11 +216,11 @@ public:
}
struct ParseDATConstructorTableSpec {
string src_name;
std::string src_name;
uint32_t index_addr;
size_t num_areas;
bool has_names;
vector<uint32_t> x86_constructor_calls;
std::vector<uint32_t> x86_constructor_calls;
ParseDATConstructorTableSpec(const phosg::JSON& json) {
this->src_name = json.at("SourceName").as_string();
@@ -233,8 +232,8 @@ public:
}
}
static vector<ParseDATConstructorTableSpec> from_json_list(const phosg::JSON& json) {
vector<ParseDATConstructorTableSpec> ret;
static std::vector<ParseDATConstructorTableSpec> from_json_list(const phosg::JSON& json) {
std::vector<ParseDATConstructorTableSpec> ret;
for (const auto& z : json.as_list()) {
ret.emplace_back(*z);
}
@@ -247,9 +246,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,37 +258,33 @@ 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) {
std::map<uint32_t, std::map<uint32_t, std::vector<std::pair<size_t, size_t>>>> parse_dat_constructor_table_t(
std::shared_ptr<const ResourceDASM::MemoryContext>& mem, const ParseDATConstructorTableSpec& spec) {
if (!mem) {
throw runtime_error("no file selected");
throw std::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.
shared_ptr<const ResourceDASM::MemoryContext> effective_mem = mem;
// 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.
std::shared_ptr<const ResourceDASM::MemoryContext> effective_mem = mem;
if (!spec.x86_constructor_calls.empty()) {
auto constructed_mem = make_shared<ResourceDASM::MemoryContext>(mem->duplicate());
auto constructed_mem = std::make_shared<ResourceDASM::MemoryContext>(mem->duplicate());
uint32_t esp = constructed_mem->allocate(0x1000) + 0x1000;
for (uint32_t constructor_addr : spec.x86_constructor_calls) {
ResourceDASM::X86Emulator emu(constructed_mem);
// Uncomment for debugging
// auto debugger = make_shared<ResourceDASM::EmulatorDebugger<ResourceDASM::X86Emulator>>();
// auto debugger = std::make_shared<ResourceDASM::EmulatorDebugger<ResourceDASM::X86Emulator>>();
// debugger->bind(emu);
// debugger->state.mode = ResourceDASM::DebuggerMode::TRACE;
@@ -299,7 +294,7 @@ public:
constructed_mem->write_u32l(esp - 4, 0xFFFFFFFF); // Return addr
try {
emu.execute();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
if (regs.eip != 0xFFFFFFFF) {
throw;
}
@@ -308,7 +303,7 @@ public:
effective_mem = constructed_mem;
}
map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>> table;
std::map<uint32_t, std::map<uint32_t, std::vector<std::pair<size_t, size_t>>>> table;
auto index_r = effective_mem->reader(spec.index_addr, spec.num_areas * sizeof(uint32_t));
for (size_t area = 0; area < spec.num_areas; area++) {
@@ -326,18 +321,18 @@ public:
if (!group.empty() && (group.back().second == (area - 1))) {
group.back().second = area;
} else {
group.emplace_back(make_pair(area, area));
group.emplace_back(std::make_pair(area, area));
}
}
if (entries_r.eof()) {
throw runtime_error("did not find end-of-entries marker");
throw std::runtime_error("did not find end-of-entries marker");
}
}
return table;
}
static uint64_t area_mask_for_ranges(const vector<pair<size_t, size_t>>& ranges) {
static uint64_t area_mask_for_ranges(const std::vector<std::pair<size_t, size_t>>& ranges) {
uint64_t ret = 0;
for (const auto& [start, end] : ranges) {
for (size_t z = start; z <= end; z++) {
@@ -348,7 +343,7 @@ public:
}
void parse_dat_constructor_table(const ParseDATConstructorTableSpec& spec) {
map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>> table;
std::map<uint32_t, std::map<uint32_t, std::vector<std::pair<size_t, size_t>>>> table;
auto spec_mem = this->mems.at(spec.src_name);
if (this->ppc_mems.count(spec_mem)) {
table = this->parse_dat_constructor_table_t<DATConstructorTableEntry<true>>(spec_mem, spec);
@@ -378,10 +373,10 @@ public:
}
void parse_dat_constructor_table_multi(
const vector<ParseDATConstructorTableSpec>& specs, bool is_enemies, bool print_area_masks) {
map<string, map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>>> all_tables;
const std::vector<ParseDATConstructorTableSpec>& specs, bool is_enemies, bool print_area_masks) {
std::map<std::string, std::map<uint32_t, std::map<uint32_t, std::vector<std::pair<size_t, size_t>>>>> all_tables;
for (const auto& spec : specs) {
map<uint32_t, map<uint32_t, vector<pair<size_t, size_t>>>> table;
std::map<uint32_t, std::map<uint32_t, std::vector<std::pair<size_t, size_t>>>> table;
auto spec_mem = this->mems.at(spec.src_name);
if (this->ppc_mems.count(spec_mem)) {
table = this->parse_dat_constructor_table_t<DATConstructorTableEntry<true>>(spec_mem, spec);
@@ -393,14 +388,14 @@ public:
all_tables.emplace(spec.src_name, std::move(table));
}
map<string, size_t> version_widths;
map<uint32_t, map<string, string>> formatted_cells_for_type;
std::map<std::string, size_t> version_widths;
std::map<uint32_t, std::map<std::string, std::string>> formatted_cells_for_type;
for (const auto& spec : specs) {
const auto& table = all_tables.at(spec.src_name);
size_t max_width = 0;
for (const auto& [type, constructor_to_area_ranges] : table) {
string cell_data;
std::string cell_data;
for (const auto& [constructor, area_ranges] : constructor_to_area_ranges) {
if (!cell_data.empty()) {
cell_data.push_back(' ');
@@ -421,14 +416,14 @@ public:
}
}
}
max_width = max<size_t>(max_width, cell_data.size());
max_width = std::max<size_t>(max_width, cell_data.size());
formatted_cells_for_type[type][spec.src_name] = std::move(cell_data);
}
version_widths[spec.src_name] = max_width;
}
vector<string> formatted_lines;
string header_line = "TYPE =>";
std::vector<std::string> formatted_lines;
std::string header_line = "TYPE =>";
for (const auto& spec : specs) {
size_t width = version_widths.at(spec.src_name);
header_line.push_back(' ');
@@ -440,7 +435,7 @@ public:
header_line += " NAME";
for (const auto& [type, formatted_cells] : formatted_cells_for_type) {
string line = std::format("{:04X} =>", type);
std::string line = std::format("{:04X} =>", type);
for (const auto& spec : specs) {
size_t width = version_widths.at(spec.src_name);
try {
@@ -450,14 +445,12 @@ public:
if (width > cell_data.size()) {
line.resize(line.size() + (width - cell_data.size()), ' ');
}
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
line.resize(line.size() + (width + 1), ' ');
}
}
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);
@@ -472,21 +465,21 @@ public:
}
uint32_t find_match(
shared_ptr<const ResourceDASM::MemoryContext> dest_mem,
std::shared_ptr<const ResourceDASM::MemoryContext> dest_mem,
uint32_t src_addr,
uint32_t src_size,
ExpandMethod expand_method) const {
bool is_ppc = this->is_ppc_expand_method(expand_method);
bool is_ppc_data = this->is_ppc_data_expand_method(expand_method);
if (!this->src_mem) {
throw runtime_error("no source file selected");
throw std::runtime_error("no source file selected");
}
if (src_size == 0) {
src_size = is_ppc ? 4 : 1;
}
pair<uint32_t, uint32_t> src_section = make_pair(0, 0);
std::pair<uint32_t, uint32_t> src_section = std::make_pair(0, 0);
for (const auto& sec : this->src_mem->allocated_blocks()) {
if (src_addr >= sec.first && src_addr + src_size <= sec.first + sec.second) {
src_section = sec;
@@ -494,7 +487,7 @@ public:
}
}
if (!src_section.second) {
throw runtime_error("source address not within any section");
throw std::runtime_error("source address not within any section");
}
const char* method_token = this->name_for_expand_method(expand_method);
@@ -576,7 +569,7 @@ public:
if (num_matches == 1) {
return last_match_address;
} else if (num_matches == 0) {
throw runtime_error("did not find exactly one match");
throw std::runtime_error("did not find exactly one match");
}
bool can_expand_backward = false;
bool can_expand_forward = false;
@@ -620,10 +613,10 @@ public:
can_expand_forward = (src_bytes_available_after > match_bytes_after);
break;
default:
throw logic_error("invalid expand method");
throw std::logic_error("invalid expand method");
}
if (!can_expand_backward && !can_expand_forward) {
throw runtime_error("no further expansion is allowed");
throw std::runtime_error("no further expansion is allowed");
}
if (can_expand_backward) {
match_bytes_before += (is_ppc ? 4 : 1);
@@ -632,7 +625,7 @@ public:
match_bytes_after += (is_ppc ? 4 : 1);
}
}
throw runtime_error("scan field too long; too many matches");
throw std::runtime_error("scan field too long; too many matches");
}
enum class MatchType {
@@ -643,18 +636,18 @@ public:
void find_all_matches(uint32_t src_addr, uint32_t src_size, MatchType type) const {
if (!this->src_mem) {
throw runtime_error("no source file selected");
throw std::runtime_error("no source file selected");
}
map<string, uint32_t> results;
std::map<std::string, uint32_t> results;
for (const auto& it : this->mems) {
if (it.second == this->src_mem) {
log.info_f("({}) {:08X} (from source)", it.first, src_addr);
results.emplace(it.first, src_addr);
} else {
vector<future<uint32_t>> futures;
static const vector<ExpandMethod> ppc_methods = {
std::vector<std::future<uint32_t>> futures;
static const std::vector<ExpandMethod> ppc_methods = {
ExpandMethod::PPC_TEXT_FORWARD,
ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BACKWARD,
@@ -666,7 +659,7 @@ public:
ExpandMethod::PPC_DATA_BACKWARD,
ExpandMethod::PPC_DATA_BOTH,
};
static const vector<ExpandMethod> ppc_text_methods = {
static const std::vector<ExpandMethod> ppc_text_methods = {
ExpandMethod::PPC_TEXT_FORWARD,
ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BACKWARD,
@@ -675,18 +668,18 @@ public:
ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN,
};
static const vector<ExpandMethod> ppc_data_methods = {
static const std::vector<ExpandMethod> ppc_data_methods = {
ExpandMethod::PPC_DATA_FORWARD,
ExpandMethod::PPC_DATA_BACKWARD,
ExpandMethod::PPC_DATA_BOTH,
};
static const vector<ExpandMethod> raw_methods = {
static const std::vector<ExpandMethod> raw_methods = {
ExpandMethod::RAW_FORWARD,
ExpandMethod::RAW_BACKWARD,
ExpandMethod::RAW_BOTH,
};
const vector<ExpandMethod>* methods;
const std::vector<ExpandMethod>* methods;
if (this->ppc_mems.count(it.second)) {
if (type == MatchType::ANY) {
methods = &ppc_methods;
@@ -695,7 +688,7 @@ public:
} else if (type == MatchType::DATA) {
methods = &ppc_data_methods;
} else {
throw logic_error("invalid match type");
throw std::logic_error("invalid match type");
}
} else {
methods = &raw_methods;
@@ -705,14 +698,14 @@ public:
futures.emplace_back(async(&AddressTranslator::find_match, this, it.second, src_addr, src_size, methods->at(z)));
}
unordered_set<uint32_t> match_addrs;
std::unordered_set<uint32_t> match_addrs;
for (size_t z = 0; z < futures.size(); z++) {
const char* method_name = this->name_for_expand_method(methods->at(z));
try {
uint32_t ret = futures[z].get();
log.info_f("({}) ({}) {:08X}", it.first, method_name, ret);
match_addrs.emplace(ret);
} catch (const exception& e) {
} catch (const std::exception& e) {
log.error_f("({}) ({}) failed: {}", it.first, method_name, e.what());
}
}
@@ -732,14 +725,12 @@ 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 {
std::shared_ptr<const ResourceDASM::MemoryContext> dest_mem, uint32_t src_addr, uint32_t src_size) const {
if (src_size == 0) {
src_size = 4;
}
pair<uint32_t, uint32_t> src_section = make_pair(0, 0);
std::pair<uint32_t, uint32_t> src_section = std::make_pair(0, 0);
for (const auto& sec : this->src_mem->allocated_blocks()) {
if (src_addr >= sec.first && src_addr + src_size <= sec.first + sec.second) {
src_section = sec;
@@ -747,7 +738,7 @@ public:
}
}
if (!src_section.second) {
throw runtime_error("source address not within any section");
throw std::runtime_error("source address not within any section");
}
size_t src_offset = src_addr - src_section.first;
@@ -790,12 +781,12 @@ public:
if (num_matches == 1) {
return last_match_address;
} else if (num_matches == 0) {
throw runtime_error("did not find exactly one match");
throw std::runtime_error("did not find exactly one match");
}
bool can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
bool can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
if (!can_expand_backward && !can_expand_forward) {
throw runtime_error("no further expansion is allowed");
throw std::runtime_error("no further expansion is allowed");
}
if (can_expand_backward) {
match_bytes_before += 4;
@@ -804,15 +795,15 @@ public:
match_bytes_after += 4;
}
}
throw runtime_error("scan field too long; too many matches");
throw std::runtime_error("scan field too long; too many matches");
}
void find_all_be_to_le_data_matches(uint32_t src_addr, uint32_t src_size) const {
if (!this->src_mem) {
throw runtime_error("no source file selected");
throw std::runtime_error("no source file selected");
}
map<string, uint32_t> results;
std::map<std::string, uint32_t> results;
for (const auto& it : this->mems) {
if (it.second == this->src_mem) {
log.info_f("({}) {:08X} (from source)", it.first, src_addr);
@@ -823,7 +814,7 @@ public:
try {
ret = this->find_be_to_le_data_match(it.second, src_addr, src_size);
log.info_f("({}) {:08X}", it.first, ret);
} catch (const exception& e) {
} catch (const std::exception& e) {
log.error_f("({}) failed: {}", it.first, e.what());
}
@@ -839,7 +830,7 @@ public:
}
}
void find_data(const string& data) const {
void find_data(const std::string& data) const {
for (const auto& [name, mem] : this->mems) {
for (const auto& [sec_addr, sec_size] : mem->allocated_blocks()) {
uint32_t last_addr = sec_addr + sec_size - data.size();
@@ -852,10 +843,10 @@ public:
}
}
void handle_command(const string& command) {
void handle_command(const std::string& command) {
auto tokens = phosg::split(command, ' ');
if (tokens.empty()) {
throw runtime_error("no command given");
throw std::runtime_error("no command given");
}
phosg::strip_trailing_whitespace(tokens[tokens.size() - 1]);
@@ -863,6 +854,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") {
std::unordered_set<std::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),
@@ -890,7 +890,7 @@ public:
auto specs = ParseDATConstructorTableSpec::from_json_list(phosg::JSON::parse(phosg::load_file(tokens.at(1))));
this->parse_dat_constructor_table_multi(specs, is_enemies, true);
} else if (!tokens[0].empty()) {
throw runtime_error("unknown command");
throw std::runtime_error("unknown command");
}
}
@@ -903,10 +903,10 @@ public:
}
fflush(stdout);
string command = phosg::fgets(stdin);
std::string command = phosg::fgets(stdin);
try {
this->handle_command(command);
} catch (const exception& e) {
} catch (const std::exception& e) {
this->log.error_f("Failed: {}", e.what());
}
}
@@ -915,14 +915,14 @@ public:
private:
phosg::PrefixedLogger log;
string directory;
unordered_map<string, shared_ptr<const ResourceDASM::MemoryContext>> mems;
unordered_set<shared_ptr<const ResourceDASM::MemoryContext>> ppc_mems;
string src_filename;
shared_ptr<const ResourceDASM::MemoryContext> src_mem;
std::string directory;
std::unordered_map<std::string, std::shared_ptr<const ResourceDASM::MemoryContext>> mems;
std::unordered_set<std::shared_ptr<const ResourceDASM::MemoryContext>> ppc_mems;
std::string src_filename;
std::shared_ptr<const ResourceDASM::MemoryContext> src_mem;
};
void run_address_translator(const string& directory, const string& use_filename, const string& command) {
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
AddressTranslator trans(directory);
if (!use_filename.empty()) {
trans.set_source_file(use_filename);
@@ -935,32 +935,32 @@ void run_address_translator(const string& directory, const string& use_filename,
}
}
vector<DiffEntry> diff_dol_files(const string& a_filename, const string& b_filename) {
std::vector<DiffEntry> diff_dol_files(const std::string& a_filename, const std::string& b_filename) {
ResourceDASM::DOLFile a(a_filename.c_str());
ResourceDASM::DOLFile b(b_filename.c_str());
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
auto b_mem = make_shared<ResourceDASM::MemoryContext>();
auto a_mem = std::make_shared<ResourceDASM::MemoryContext>();
auto b_mem = std::make_shared<ResourceDASM::MemoryContext>();
a.load_into(a_mem);
b.load_into(b_mem);
uint32_t min_addr = 0xFFFFFFFF;
uint32_t max_addr = 0x00000000;
for (const auto& sec : a.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
min_addr = std::min<uint32_t>(min_addr, sec.address);
max_addr = std::max<uint32_t>(max_addr, sec.address + sec.data.size());
}
for (const auto& sec : b.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
min_addr = std::min<uint32_t>(min_addr, sec.address);
max_addr = std::max<uint32_t>(max_addr, sec.address + sec.data.size());
}
vector<DiffEntry> ret;
std::vector<DiffEntry> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
bool a_exists = a_mem->exists(addr, 4);
bool b_exists = b_mem->exists(addr, 4);
if (a_exists && b_exists) {
string a_value = a_mem->read(addr, 4);
string b_value = b_mem->read(addr, 4);
std::string a_value = a_mem->read(addr, 4);
std::string b_value = b_mem->read(addr, 4);
if (a_value != b_value) {
if (!ret.empty() && (ret.back().address + ret.back().b_data.size() == addr)) {
ret.back().a_data += a_value;
@@ -974,26 +974,217 @@ vector<DiffEntry> diff_dol_files(const string& a_filename, const string& b_filen
return ret;
}
vector<DiffEntry> diff_xbe_files(const string& a_filename, const string& b_filename) {
void diff_dol_files_semantic(
FILE* stream,
const std::string& a_filename,
const std::string& b_filename,
const std::unordered_set<uint32_t>& a_ignore_functions,
const std::unordered_set<uint32_t>& b_ignore_functions) {
ResourceDASM::DOLFile a(a_filename.c_str());
ResourceDASM::DOLFile b(b_filename.c_str());
// There must be the same number of sections
if (a.sections.size() != b.sections.size()) {
throw std::runtime_error("DOL files do not have the same section count");
}
for (size_t section_index = 0; section_index < a.sections.size(); section_index++) {
const auto& a_sec = a.sections[section_index];
const auto& b_sec = b.sections[section_index];
if (!a_sec.is_text || !b_sec.is_text) {
phosg::fwrite_fmt(stderr, "SECTION {} DATA\n", section_index);
// TODO: Diff the contents as binary data
} else {
phosg::fwrite_fmt(stderr, "SECTION {} TEXT\n", section_index);
struct FileAnalysis {
struct Function {
const ResourceDASM::EmulatorBase::DisassembleResult::Label* label;
size_t size;
std::vector<std::pair<uint32_t, uint32_t>> code; // [(opcode, mask)]
};
std::vector<Function> functions;
ResourceDASM::EmulatorBase::DisassembleResult dasm;
};
auto disassemble_section = [&](const ResourceDASM::DOLFile& file, const ResourceDASM::DOLFile::Section& sec) -> FileAnalysis {
std::multimap<uint32_t, std::string> labels;
if ((file.entrypoint >= sec.address) && (file.entrypoint < (sec.address + sec.data.size()))) {
labels.emplace(file.entrypoint, "entry");
}
FileAnalysis ret;
ret.dasm = ResourceDASM::PPC32Emulator::disassemble_structured(
sec.data.data(), sec.data.size(), sec.address, &labels);
FileAnalysis::Function* prev_fn = nullptr;
for (const auto& [addr, label] : ret.dasm.labels) {
if (label.refs.call_addrs.empty() ||
(label.address < sec.address) ||
(label.address >= (sec.address + sec.data.size()))) {
continue;
}
if (prev_fn) {
prev_fn->size = addr - prev_fn->label->address;
}
auto& fn = ret.functions.emplace_back();
fn.label = &label;
prev_fn = &fn;
}
if (prev_fn) {
prev_fn->size = sec.data.size() - (prev_fn->label->address - sec.address);
}
for (auto& fn : ret.functions) {
const be_uint32_t* code = reinterpret_cast<const be_uint32_t*>(
sec.data.data() + (fn.label->address - sec.address));
for (size_t z = 0; z < fn.size >> 2; z++) {
uint32_t opcode = code[z];
if ((opcode & 0xFC000000) == 0x34000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // subic.
} else if ((opcode & 0xFC000000) == 0x38000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // addi
} else if ((opcode & 0xFC1F0000) == 0x3C000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lis
} else if ((opcode & 0xFC000000) == 0x48000000) {
fn.code.emplace_back(opcode, 0xFC000000); // b[la]
} else if ((opcode & 0xF8000000) == 0x60000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // ori
} else if ((opcode & 0xF8000000) == 0x80000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lwz, lwzu
} else if ((opcode & 0xFC000000) == 0x88000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lbz
} else if ((opcode & 0xF8000000) == 0x90000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // stw, stwu
} else if ((opcode & 0xF8000000) == 0x98000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // stb, stbu
} else if ((opcode & 0xF8000000) == 0xA0000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lhz, lhzu
} else if ((opcode & 0xFC000000) == 0xAC000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lhau
} else if ((opcode & 0xF8000000) == 0xB0000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // sth, sthu
} else if ((opcode & 0xF8000000) == 0xC0000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lfs, lfsu
} else if ((opcode & 0xFC000000) == 0xC8000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // lfd
} else if ((opcode & 0xF8000000) == 0xD0000000) {
fn.code.emplace_back(opcode, 0xFFFF0000); // stfs, stfsu
} else {
fn.code.emplace_back(opcode, 0xFFFFFFFF);
}
}
}
return ret;
};
auto a_ana = disassemble_section(a, a_sec);
auto b_ana = disassemble_section(b, b_sec);
bool use_color = isatty(fileno(stream));
auto a_fn_it = a_ana.functions.cbegin();
auto b_fn_it = b_ana.functions.cbegin();
while ((a_fn_it != a_ana.functions.end()) || (b_fn_it != b_ana.functions.end())) {
if ((a_fn_it != a_ana.functions.end()) && (b_fn_it != b_ana.functions.end())) {
phosg::fwrite_fmt(stream, "FUNCTION: A:{:08X} B:{:08X}\n", a_fn_it->label->address, b_fn_it->label->address);
bool functions_identical = true;
for (size_t z = 0; z < std::max<size_t>(a_fn_it->code.size(), b_fn_it->code.size()); z++) {
uint32_t a_op = (z < a_fn_it->code.size()) ? a_fn_it->code[z].first : 0xFFFFFFFF;
uint32_t b_op = (z < b_fn_it->code.size()) ? b_fn_it->code[z].first : 0xFFFFFFFF;
uint32_t a_mask = (z < a_fn_it->code.size()) ? a_fn_it->code[z].second : 0xFFFFFFFF;
uint32_t b_mask = (z < b_fn_it->code.size()) ? b_fn_it->code[z].second : 0xFFFFFFFF;
uint32_t mask = a_mask | b_mask;
if ((a_op & mask) != (b_op & mask)) {
functions_identical = false;
}
}
if (!functions_identical) {
for (size_t z = 0; z < std::max<size_t>(a_fn_it->code.size(), b_fn_it->code.size()); z++) {
uint32_t a_op = (z < a_fn_it->code.size()) ? a_fn_it->code[z].first : 0xFFFFFFFF;
uint32_t b_op = (z < b_fn_it->code.size()) ? b_fn_it->code[z].first : 0xFFFFFFFF;
uint32_t a_mask = (z < a_fn_it->code.size()) ? a_fn_it->code[z].second : 0xFFFFFFFF;
uint32_t b_mask = (z < b_fn_it->code.size()) ? b_fn_it->code[z].second : 0xFFFFFFFF;
uint32_t mask = a_mask | b_mask;
if ((a_op & mask) == (b_op & mask)) {
phosg::fwrite_fmt(stream, " {:08X}->{:08X} {:08X} {}\n",
a_fn_it->label->address + z * 4, b_fn_it->label->address + z * 4,
a_op, ResourceDASM::PPC32Emulator::disassemble_one(a_fn_it->label->address + z * 4, a_op));
} else {
if (use_color) {
phosg::print_color_escape(stream, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::FG_RED, phosg::TerminalFormat::END);
}
phosg::fwrite_fmt(stream, "- {:08X}->{:08X} {:08X} {}\n",
a_fn_it->label->address + z * 4, b_fn_it->label->address + z * 4,
a_op, ResourceDASM::PPC32Emulator::disassemble_one(a_fn_it->label->address + z * 4, a_op));
if (use_color) {
phosg::print_color_escape(stream, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::FG_GREEN, phosg::TerminalFormat::END);
}
phosg::fwrite_fmt(stream, "+ {:08X}->{:08X} {:08X} {}\n",
a_fn_it->label->address + z * 4, b_fn_it->label->address + z * 4,
b_op, ResourceDASM::PPC32Emulator::disassemble_one(b_fn_it->label->address + z * 4, b_op));
if (use_color) {
phosg::print_color_escape(stream, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END);
}
}
}
}
do {
a_fn_it++;
} while (a_fn_it != a_ana.functions.end() && a_ignore_functions.count(a_fn_it->label->address));
do {
b_fn_it++;
} while (b_fn_it != b_ana.functions.end() && b_ignore_functions.count(b_fn_it->label->address));
} else if (a_fn_it != a_ana.functions.end()) {
phosg::fwrite_fmt(stream, "FUNCTION: A:{:08X} B:(missing)\n", a_fn_it->label->address);
for (size_t z = 0; z < a_fn_it->code.size(); z++) {
phosg::fwrite_fmt(stream, " {:08X} {:08X} {}\n",
a_fn_it->label->address + z * 4, a_fn_it->code[z].first,
ResourceDASM::PPC32Emulator::disassemble_one(a_fn_it->label->address + z * 4, a_fn_it->code[z].first));
}
do {
a_fn_it++;
} while (a_fn_it != a_ana.functions.end() && a_ignore_functions.count(a_fn_it->label->address));
} else {
phosg::fwrite_fmt(stream, "FUNCTION: A:(missing) B:{:08X}\n", b_fn_it->label->address);
for (size_t z = 0; z < b_fn_it->code.size(); z++) {
phosg::fwrite_fmt(stream, " {:08X} {:08X} {}\n",
b_fn_it->label->address + z * 4, b_fn_it->code[z].first,
ResourceDASM::PPC32Emulator::disassemble_one(b_fn_it->label->address + z * 4, b_fn_it->code[z].first));
}
do {
b_fn_it++;
} while (b_fn_it != b_ana.functions.end() && b_ignore_functions.count(b_fn_it->label->address));
}
}
}
}
}
std::vector<DiffEntry> diff_xbe_files(const std::string& a_filename, const std::string& b_filename) {
ResourceDASM::XBEFile a(a_filename.c_str());
ResourceDASM::XBEFile b(b_filename.c_str());
auto a_mem = make_shared<ResourceDASM::MemoryContext>();
auto b_mem = make_shared<ResourceDASM::MemoryContext>();
auto a_mem = std::make_shared<ResourceDASM::MemoryContext>();
auto b_mem = std::make_shared<ResourceDASM::MemoryContext>();
a.load_into(a_mem);
b.load_into(b_mem);
uint32_t min_addr = 0xFFFFFFFF;
uint32_t max_addr = 0x00000000;
for (const auto& sec : a.sections) {
min_addr = min<uint32_t>(min_addr, sec.addr);
max_addr = max<uint32_t>(max_addr, sec.addr + sec.size);
min_addr = std::min<uint32_t>(min_addr, sec.addr);
max_addr = std::max<uint32_t>(max_addr, sec.addr + sec.size);
}
for (const auto& sec : b.sections) {
min_addr = min<uint32_t>(min_addr, sec.addr);
max_addr = max<uint32_t>(max_addr, sec.addr + sec.size);
min_addr = std::min<uint32_t>(min_addr, sec.addr);
max_addr = std::max<uint32_t>(max_addr, sec.addr + sec.size);
}
vector<DiffEntry> ret;
std::vector<DiffEntry> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr++) {
bool a_exists = a_mem->exists(addr, 1);
bool b_exists = b_mem->exists(addr, 1);
+9
View File
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
@@ -13,5 +14,13 @@ struct DiffEntry {
};
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
std::vector<DiffEntry> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
std::vector<DiffEntry> diff_xbe_files(const std::string& a_filename, const std::string& b_filename);
void diff_dol_files_semantic(
FILE* stream,
const std::string& a_filename,
const std::string& b_filename,
const std::unordered_set<uint32_t>& a_ignore_functions,
const std::unordered_set<uint32_t>& b_ignore_functions);
+35 -39
View File
@@ -14,9 +14,7 @@
#include "Revision.hh"
#include "Server.hh"
using namespace std;
static const unordered_map<int, const char*> explanation_for_response_code{
static const std::unordered_map<int, const char*> explanation_for_response_code{
{100, "Continue"},
{101, "Switching Protocols"},
{102, "Processing"},
@@ -92,7 +90,7 @@ const std::string* HTTPRequest::get_header(const std::string& name) const {
if (its.first == its.second) {
return nullptr;
}
const string* ret = &its.first->second;
const std::string* ret = &its.first->second;
its.first++;
if (its.first != its.second) {
throw std::out_of_range("Header appears multiple times: " + name);
@@ -105,7 +103,7 @@ const std::string* HTTPRequest::get_query_param(const std::string& name) const {
if (its.first == its.second) {
return nullptr;
}
const string* ret = &its.first->second;
const std::string* ret = &its.first->second;
its.first++;
if (its.first != its.second) {
throw std::out_of_range("Query parameter appears multiple times: " + name);
@@ -113,7 +111,7 @@ const std::string* HTTPRequest::get_query_param(const std::string& name) const {
return ret;
}
static void url_decode_inplace(string& s) {
static void url_decode_inplace(std::string& s) {
size_t write_offset = 0, read_offset = 0;
for (; read_offset < s.size(); write_offset++) {
if ((s[read_offset] == '%') && (read_offset < s.size() - 2)) {
@@ -139,7 +137,7 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
std::string request_line = co_await this->r.read_line("\r\n", max_line_size);
auto line_tokens = phosg::split(request_line, ' ');
if (line_tokens.size() != 3) {
throw runtime_error("invalid HTTP request line");
throw std::runtime_error("invalid HTTP request line");
}
const auto& method_token = line_tokens[0];
if (method_token == "GET") {
@@ -163,20 +161,20 @@ 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]);
size_t fragment_start_offset = line_tokens[1].find('#');
if (fragment_start_offset != string::npos) {
if (fragment_start_offset != std::string::npos) {
req.fragment = line_tokens[1].substr(fragment_start_offset + 1);
line_tokens[1].resize(fragment_start_offset);
}
size_t query_start_offset = line_tokens[1].find('?');
string query;
if (query_start_offset != string::npos) {
std::string query;
if (query_start_offset != std::string::npos) {
query = line_tokens[1].substr(query_start_offset + 1);
line_tokens[1].resize(query_start_offset);
}
@@ -189,12 +187,12 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
auto query_tokens = phosg::split(query, '&');
for (auto& token : query_tokens) {
size_t equals_pos = token.find('=');
if (equals_pos == string::npos) {
if (equals_pos == std::string::npos) {
url_decode_inplace(token);
req.query_params.emplace(std::move(token), "");
} else {
string key = token.substr(0, equals_pos);
string value = token.substr(equals_pos + 1);
std::string key = token.substr(0, equals_pos);
std::string value = token.substr(equals_pos + 1);
url_decode_inplace(key);
url_decode_inplace(value);
req.query_params.emplace(std::move(key), std::move(value));
@@ -217,11 +215,11 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
}
} else {
size_t colon_pos = line.find(':');
if (colon_pos == string::npos) {
throw runtime_error("malformed header line");
if (colon_pos == std::string::npos) {
throw std::runtime_error("malformed header line");
}
string key = line.substr(0, colon_pos);
string value = line.substr(colon_pos + 1);
std::string key = line.substr(0, colon_pos);
std::string value = line.substr(colon_pos + 1);
phosg::strip_whitespace(key);
phosg::strip_whitespace(value);
prev_header_it = req.headers.emplace(phosg::tolower(key), std::move(value));
@@ -230,33 +228,33 @@ asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size,
auto transfer_encoding_header = req.get_header("transfer-encoding");
if (transfer_encoding_header && phosg::tolower(*transfer_encoding_header) == "chunked") {
deque<string> chunks;
std::deque<std::string> chunks;
size_t total_data_bytes = 0;
for (;;) {
auto line = co_await this->r.read_line("\r\n", 0x20);
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 +287,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
@@ -307,7 +304,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
}
if (payload_size > max_data_size) {
throw runtime_error("Incoming WebSocket message exceeds size limit");
throw std::runtime_error("Incoming WebSocket message exceeds size limit");
}
// Read the masking key if present
@@ -325,8 +322,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 +332,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 +340,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,16 +370,15 @@ 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;
}
}
throw logic_error("failed to receive websocket message");
throw std::logic_error("failed to receive websocket message");
}
asio::awaitable<void> HTTPClient::send_websocket_message(const void* data, size_t size, uint8_t opcode) {
@@ -398,7 +394,7 @@ asio::awaitable<void> HTTPClient::send_websocket_message(const void* data, size_
w.put_u8(size);
}
array<asio::const_buffer, 2> bufs = {asio::const_buffer(w.data(), w.size()), asio::const_buffer(data, size)};
std::array<asio::const_buffer, 2> bufs = {asio::const_buffer(w.data(), w.size()), asio::const_buffer(data, size)};
co_await asio::async_write(this->r.get_socket(), bufs, asio::use_awaitable);
}
+133 -15
View File
@@ -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;
+26 -26
View File
@@ -7,25 +7,25 @@
#include <phosg/Strings.hh>
#include <string>
using namespace std;
AsyncEvent::AsyncEvent(asio::any_io_executor ex)
: executor(ex), is_set(false) {}
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;
{
std::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() {
lock_guard g(this->lock);
std::lock_guard g(this->lock);
this->is_set = false;
}
@@ -33,11 +33,12 @@ asio::awaitable<void> AsyncEvent::wait() {
auto token = asio::use_awaitable_t<>{};
co_await asio::async_initiate<asio::use_awaitable_t<>, void()>(
[this](auto&& handler) -> void {
lock_guard g(this->lock);
std::lock_guard g(this->lock);
if (this->is_set) {
handler();
} else {
this->waiters.emplace_back(make_unique<asio::detail::awaitable_handler<asio::any_io_executor>>(std::move(handler)));
this->waiters.emplace_back(
std::make_unique<asio::detail::awaitable_handler<asio::any_io_executor>>(std::move(handler)));
}
},
token);
@@ -46,17 +47,17 @@ asio::awaitable<void> AsyncEvent::wait() {
AsyncSocketReader::AsyncSocketReader(asio::ip::tcp::socket&& sock)
: sock(std::move(sock)) {}
asio::awaitable<string> AsyncSocketReader::read_line(const char* delimiter, size_t max_length) {
asio::awaitable<std::string> AsyncSocketReader::read_line(const char* delimiter, size_t max_length) {
size_t delimiter_size = strlen(delimiter);
if (delimiter_size == 0) {
throw logic_error("delimiter is empty");
throw std::logic_error("delimiter is empty");
}
size_t delimiter_backup_bytes = delimiter_size - 1;
size_t delimiter_pos = this->pending_data.find(delimiter);
while ((delimiter_pos == string::npos) && (!max_length || (this->pending_data.size() < max_length))) {
while ((delimiter_pos == std::string::npos) && (!max_length || (this->pending_data.size() < max_length))) {
size_t pre_size = this->pending_data.size();
this->pending_data.resize(min(max_length, this->pending_data.size() + 0x400));
this->pending_data.resize(std::min(max_length, this->pending_data.size() + 0x400));
auto buf = asio::buffer(this->pending_data.data() + pre_size, this->pending_data.size() - pre_size);
size_t bytes_read = co_await this->sock.async_read_some(buf, asio::use_awaitable);
@@ -66,19 +67,18 @@ asio::awaitable<string> AsyncSocketReader::read_line(const char* delimiter, size
(delimiter_backup_bytes > pre_size) ? 0 : (pre_size - delimiter_backup_bytes));
}
if (delimiter_pos == string::npos) {
throw runtime_error("line exceeds max length");
if (delimiter_pos == std::string::npos) {
throw std::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.
string ret = this->pending_data.substr(0, delimiter_pos);
// TODO: It's not great that we copy the data here. There's probably a more idiomatic and efficient way to do this.
std::string ret = this->pending_data.substr(0, delimiter_pos);
this->pending_data = this->pending_data.substr(delimiter_pos + delimiter_size);
co_return ret;
}
asio::awaitable<string> AsyncSocketReader::read_data(size_t size) {
string ret;
asio::awaitable<std::string> AsyncSocketReader::read_data(size_t size) {
std::string ret;
if (this->pending_data.size() == size) {
this->pending_data.swap(ret);
} else if (this->pending_data.size() > size) {
@@ -109,7 +109,7 @@ asio::awaitable<void> AsyncSocketReader::read_data_into(void* data, size_t size)
}
}
void AsyncWriteCollector::add(string&& data) {
void AsyncWriteCollector::add(std::string&& data) {
const auto& item = this->owned_data.emplace_back(std::move(data));
bufs.emplace_back(asio::buffer(item.data(), item.size()));
}
@@ -119,14 +119,14 @@ void AsyncWriteCollector::add_reference(const void* data, size_t size) {
}
asio::awaitable<void> AsyncWriteCollector::write(asio::ip::tcp::socket& sock) {
deque<string> local_owned_data;
std::deque<std::string> local_owned_data;
local_owned_data.swap(this->owned_data);
vector<asio::const_buffer> local_bufs;
std::vector<asio::const_buffer> local_bufs;
local_bufs.swap(this->bufs);
co_await asio::async_write(sock, local_bufs, asio::use_awaitable);
}
asio::awaitable<void> async_sleep(chrono::steady_clock::duration duration) {
asio::awaitable<void> async_sleep(std::chrono::steady_clock::duration duration) {
asio::steady_timer timer(co_await asio::this_coro::executor, duration);
co_await timer.async_wait(asio::use_awaitable);
}
+20 -12
View File
@@ -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 std::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();
}
+20 -29
View File
@@ -7,19 +7,14 @@
#include "Text.hh"
#include "Types.hh"
using namespace std;
template <bool BE>
struct BMLHeaderT {
parray<uint8_t, 0x04> unknown_a1;
U32T<BE> num_entries;
parray<uint8_t, 0x38> unknown_a2;
} __attribute__((packed));
} __packed_ws_be__(BMLHeaderT, 0x40);
using BMLHeader = BMLHeaderT<false>;
using BMLHeaderBE = BMLHeaderT<true>;
check_struct_size(BMLHeader, 0x40);
check_struct_size(BMLHeaderBE, 0x40);
template <bool BE>
struct BMLHeaderEntryT {
@@ -30,12 +25,9 @@ struct BMLHeaderEntryT {
U32T<BE> compressed_gvm_size;
U32T<BE> decompressed_gvm_size;
parray<uint8_t, 0x0C> unknown_a2;
} __attribute__((packed));
} __packed_ws_be__(BMLHeaderEntryT, 0x40);
using BMLHeaderEntry = BMLHeaderEntryT<false>;
using BMLHeaderEntryBE = BMLHeaderEntryT<true>;
check_struct_size(BMLHeaderEntry, 0x40);
check_struct_size(BMLHeaderEntryBE, 0x40);
template <bool BE>
void BMLArchive::load_t() {
@@ -48,13 +40,13 @@ void BMLArchive::load_t() {
const auto& entry = r.get<BMLHeaderEntryT<BE>>();
if (offset + entry.compressed_size > this->data->size()) {
throw runtime_error("BML data entry extends beyond end of data");
throw std::runtime_error("BML data entry extends beyond end of data");
}
size_t data_offset = offset;
offset = (offset + entry.compressed_size + 0x1F) & (~0x1F);
if (offset + entry.compressed_gvm_size > this->data->size()) {
throw runtime_error("BML GVM entry extends beyond end of data");
throw std::runtime_error("BML GVM entry extends beyond end of data");
}
size_t gvm_offset = offset;
offset = (offset + entry.compressed_gvm_size + 0x1F) & (~0x1F);
@@ -63,8 +55,7 @@ void BMLArchive::load_t() {
}
}
BMLArchive::BMLArchive(shared_ptr<const string> data, bool big_endian)
: data(data) {
BMLArchive::BMLArchive(std::shared_ptr<const std::string> data, bool big_endian) : data(data) {
if (big_endian) {
this->load_t<true>();
} else {
@@ -72,42 +63,42 @@ BMLArchive::BMLArchive(shared_ptr<const string> data, bool big_endian)
}
}
const unordered_map<string, BMLArchive::Entry> BMLArchive::all_entries() const {
const std::unordered_map<std::string, BMLArchive::Entry> BMLArchive::all_entries() const {
return this->entries;
}
pair<const void*, size_t> BMLArchive::get(const std::string& name) const {
std::pair<const void*, size_t> BMLArchive::get(const std::string& name) const {
try {
const auto& entry = this->entries.at(name);
return make_pair(this->data->data() + entry.offset, entry.size);
} catch (const out_of_range&) {
throw out_of_range("BML does not contain file: " + name);
return std::make_pair(this->data->data() + entry.offset, entry.size);
} catch (const std::out_of_range&) {
throw std::out_of_range("BML does not contain file: " + name);
}
}
pair<const void*, size_t> BMLArchive::get_gvm(const std::string& name) const {
std::pair<const void*, size_t> BMLArchive::get_gvm(const std::string& name) const {
try {
const auto& entry = this->entries.at(name);
return make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size);
} catch (const out_of_range&) {
throw out_of_range("BML does not contain file: " + name);
return std::make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size);
} catch (const std::out_of_range&) {
throw std::out_of_range("BML does not contain file: " + name);
}
}
string BMLArchive::get_copy(const string& name) const {
std::string BMLArchive::get_copy(const std::string& name) const {
try {
const auto& entry = this->entries.at(name);
return this->data->substr(entry.offset, entry.size);
} catch (const out_of_range&) {
throw out_of_range("BML does not contain file: " + name);
} catch (const std::out_of_range&) {
throw std::out_of_range("BML does not contain file: " + name);
}
}
phosg::StringReader BMLArchive::get_reader(const string& name) const {
phosg::StringReader BMLArchive::get_reader(const std::string& name) const {
try {
const auto& entry = this->entries.at(name);
return phosg::StringReader(this->data->data() + entry.offset, entry.size);
} catch (const out_of_range&) {
throw out_of_range("BML does not contain file: " + name);
} catch (const std::out_of_range&) {
throw std::out_of_range("BML does not contain file: " + name);
}
}
+288 -46
View File
@@ -7,50 +7,298 @@
#include "PSOEncryption.hh"
#include "StaticGameData.hh"
using namespace std;
BattleParamsIndex::AttackData BattleParamsIndex::AttackData::from_json(const phosg::JSON& json) {
return AttackData{
json.get_int("MinATP"),
json.get_int("MaxATP"),
json.get_int("MinATA"),
json.get_int("MaxATA"),
json.get_float("DistanceX"),
json.get_int("Angle"),
json.get_float("DistanceY"),
json.get_int("UnknownA8"),
json.get_int("UnknownA9"),
json.get_int("UnknownA10"),
json.get_int("UnknownA11"),
json.get_int("UnknownA12"),
json.get_int("UnknownA13"),
json.get_int("UnknownA14"),
json.get_int("UnknownA15"),
json.get_int("UnknownA16"),
};
}
phosg::JSON BattleParamsIndex::AttackData::json() const {
return phosg::JSON::dict({
{"MinATP", this->min_atp.load()},
{"MaxATP", this->max_atp.load()},
{"MinATA", this->min_ata.load()},
{"MaxATA", this->max_ata.load()},
{"DistanceX", this->distance_x.load()},
{"Angle", this->angle.load()},
{"DistanceY", this->distance_y.load()},
{"UnknownA8", this->unknown_a8.load()},
{"UnknownA9", this->unknown_a9.load()},
{"UnknownA10", this->unknown_a10.load()},
{"UnknownA11", this->unknown_a11.load()},
{"UnknownA12", this->unknown_a12.load()},
{"UnknownA13", this->unknown_a13.load()},
{"UnknownA14", this->unknown_a14.load()},
{"UnknownA15", this->unknown_a15.load()},
{"UnknownA16", this->unknown_a16.load()},
});
}
BattleParamsIndex::ResistData BattleParamsIndex::ResistData::from_json(const phosg::JSON& json) {
return BattleParamsIndex::ResistData{
json.get_int("EVPBonus"),
json.get_int("EFR"),
json.get_int("EIC"),
json.get_int("ETH"),
json.get_int("ELT"),
json.get_int("EDK"),
json.get_int("UnknownA6"),
json.get_int("UnknownA7"),
json.get_int("UnknownA8"),
json.get_int("UnknownA9"),
json.get_int("DFPBonus"),
};
}
phosg::JSON BattleParamsIndex::ResistData::json() const {
return phosg::JSON::dict({
{"EVPBonus", this->evp_bonus.load()},
{"EFR", this->efr.load()},
{"EIC", this->eic.load()},
{"ETH", this->eth.load()},
{"ELT", this->elt.load()},
{"EDK", this->edk.load()},
{"UnknownA6", this->unknown_a6.load()},
{"UnknownA7", this->unknown_a7.load()},
{"UnknownA8", this->unknown_a8.load()},
{"UnknownA9", this->unknown_a9.load()},
{"DFPBonus", this->dfp_bonus.load()},
});
}
BattleParamsIndex::MovementData BattleParamsIndex::MovementData::from_json(const phosg::JSON& json) {
const auto& fparams_json = json.at("FParams").as_list();
const auto& iparams_json = json.at("IParams").as_list();
return BattleParamsIndex::MovementData{
fparams_json.at(0)->as_float(),
fparams_json.at(1)->as_float(),
fparams_json.at(2)->as_float(),
fparams_json.at(3)->as_float(),
fparams_json.at(4)->as_float(),
fparams_json.at(5)->as_float(),
iparams_json.at(0)->as_float(),
iparams_json.at(1)->as_float(),
iparams_json.at(2)->as_float(),
iparams_json.at(3)->as_float(),
iparams_json.at(4)->as_float(),
iparams_json.at(5)->as_float(),
};
}
phosg::JSON BattleParamsIndex::MovementData::json() const {
auto fparams_list = phosg::JSON::list({
this->fparam1.load(),
this->fparam2.load(),
this->fparam3.load(),
this->fparam4.load(),
this->fparam5.load(),
this->fparam6.load(),
});
auto iparams_list = phosg::JSON::list({
this->iparam1.load(),
this->iparam2.load(),
this->iparam3.load(),
this->iparam4.load(),
this->iparam5.load(),
this->iparam6.load(),
});
return phosg::JSON::dict({{"FParams", std::move(fparams_list)}, {"IParams", std::move(iparams_list)}});
}
BattleParamsIndex::Table BattleParamsIndex::Table::from_json(const phosg::JSON& json) {
BattleParamsIndex::Table ret;
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
const auto& diff_json = json.at(name_for_difficulty(difficulty));
for (size_t z = 0; z < 0x60; z++) {
const auto& entry_json = diff_json.at(z);
ret.stats[static_cast<size_t>(difficulty)][z] = PlayerStats::from_json(entry_json.at("Stats"));
ret.attack_data[static_cast<size_t>(difficulty)][z] = AttackData::from_json(entry_json.at("AttackData"));
ret.resist_data[static_cast<size_t>(difficulty)][z] = ResistData::from_json(entry_json.at("ResistData"));
ret.movement_data[static_cast<size_t>(difficulty)][z] = MovementData::from_json(entry_json.at("MovementData"));
}
}
return ret;
}
phosg::JSON BattleParamsIndex::Table::json() const {
auto ret = phosg::JSON::dict();
for (Difficulty difficulty : ALL_DIFFICULTIES_V234) {
auto diff_ret = phosg::JSON::list();
for (size_t z = 0; z < 0x60; z++) {
auto stats_json = this->stats_for_index(difficulty, z).json();
auto attack_data_json = this->attack_data_for_index(difficulty, z).json();
auto resist_data_json = this->resist_data_for_index(difficulty, z).json();
auto movement_data_json = this->movement_data_for_index(difficulty, z).json();
std::set<EnemyType> stats_names;
std::set<EnemyType> attack_data_names;
std::set<EnemyType> resist_data_names;
std::set<EnemyType> movement_data_names;
for (Episode episode : ALL_EPISODES_V4) {
for (const auto& enemy_type : enemy_types_for_battle_param_stats_index(episode, z)) {
stats_names.emplace(enemy_type);
}
for (const auto& enemy_type : enemy_types_for_battle_param_attack_data_index(episode, z)) {
attack_data_names.emplace(enemy_type);
}
for (const auto& enemy_type : enemy_types_for_battle_param_resist_data_index(episode, z)) {
resist_data_names.emplace(enemy_type);
}
for (const auto& enemy_type : enemy_types_for_battle_param_movement_data_index(episode, z)) {
movement_data_names.emplace(enemy_type);
}
}
auto stats_names_json = phosg::JSON::list();
for (EnemyType enemy_type : stats_names) {
stats_names_json.emplace_back(phosg::name_for_enum(enemy_type));
}
auto attack_data_names_json = phosg::JSON::list();
for (EnemyType enemy_type : attack_data_names) {
attack_data_names_json.emplace_back(phosg::name_for_enum(enemy_type));
}
auto resist_data_names_json = phosg::JSON::list();
for (EnemyType enemy_type : resist_data_names) {
resist_data_names_json.emplace_back(phosg::name_for_enum(enemy_type));
}
auto movement_data_names_json = phosg::JSON::list();
for (EnemyType enemy_type : movement_data_names) {
movement_data_names_json.emplace_back(phosg::name_for_enum(enemy_type));
}
stats_json.emplace("Enemies", std::move(stats_names_json));
attack_data_json.emplace("Enemies", std::move(attack_data_names_json));
resist_data_json.emplace("Enemies", std::move(resist_data_names_json));
movement_data_json.emplace("Enemies", std::move(movement_data_names_json));
diff_ret.emplace_back(phosg::JSON::dict({
{"BPIndex", z},
{"Stats", std::move(stats_json)},
{"AttackData", std::move(attack_data_json)},
{"ResistData", std::move(resist_data_json)},
{"MovementData", std::move(movement_data_json)},
}));
}
ret.emplace(name_for_difficulty(difficulty), std::move(diff_ret));
}
return ret;
}
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);
std::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.exp, 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);
}
}
}
BattleParamsIndex::BattleParamsIndex(
shared_ptr<const string> data_on_ep1,
shared_ptr<const string> data_on_ep2,
shared_ptr<const string> data_on_ep4,
shared_ptr<const string> data_off_ep1,
shared_ptr<const string> data_off_ep2,
shared_ptr<const string> data_off_ep4) {
phosg::JSON BattleParamsIndex::json() const {
return phosg::JSON::dict({
{"Episode1-Online", this->get_table(false, Episode::EP1).json()},
{"Episode2-Online", this->get_table(false, Episode::EP2).json()},
{"Episode4-Online", this->get_table(false, Episode::EP4).json()},
{"Episode1-Solo", this->get_table(true, Episode::EP1).json()},
{"Episode2-Solo", this->get_table(true, Episode::EP2).json()},
{"Episode4-Solo", this->get_table(true, Episode::EP4).json()},
});
}
JSONBattleParamsIndex::JSONBattleParamsIndex(const phosg::JSON& json) {
this->tables[0][0] = Table::from_json(json.at("Episode1-Online"));
this->tables[0][1] = Table::from_json(json.at("Episode2-Online"));
this->tables[0][2] = Table::from_json(json.at("Episode4-Online"));
this->tables[1][0] = Table::from_json(json.at("Episode1-Solo"));
this->tables[1][1] = Table::from_json(json.at("Episode2-Solo"));
this->tables[1][2] = Table::from_json(json.at("Episode4-Solo"));
}
const BattleParamsIndex::Table& JSONBattleParamsIndex::get_table(bool solo, Episode episode) const {
switch (episode) {
case Episode::EP1:
return this->tables[!!solo][0];
case Episode::EP2:
return this->tables[!!solo][1];
case Episode::EP4:
return this->tables[!!solo][2];
default:
throw std::invalid_argument("invalid episode");
}
}
BinaryBattleParamsIndex::BinaryBattleParamsIndex(
std::shared_ptr<const std::string> data_on_ep1,
std::shared_ptr<const std::string> data_on_ep2,
std::shared_ptr<const std::string> data_on_ep4,
std::shared_ptr<const std::string> data_off_ep1,
std::shared_ptr<const std::string> data_off_ep2,
std::shared_ptr<const std::string> data_off_ep4) {
this->files[0][0].data = data_on_ep1;
this->files[0][1].data = data_on_ep2;
this->files[0][2].data = data_on_ep4;
@@ -62,7 +310,7 @@ BattleParamsIndex::BattleParamsIndex(
for (uint8_t episode = 0; episode < 3; episode++) {
auto& file = this->files[is_solo][episode];
if (file.data->size() < sizeof(Table)) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"battle params table size is incorrect (expected {:X} bytes, have {:X} bytes; is_solo={}, episode={})",
sizeof(Table), file.data->size(), is_solo, episode));
}
@@ -71,21 +319,15 @@ BattleParamsIndex::BattleParamsIndex(
}
}
const BattleParamsIndex::Table& BattleParamsIndex::get_table(bool solo, Episode episode) const {
uint8_t ep_index;
const BattleParamsIndex::Table& BinaryBattleParamsIndex::get_table(bool solo, Episode episode) const {
switch (episode) {
case Episode::EP1:
ep_index = 0;
break;
return *this->files[!!solo][0].table;
case Episode::EP2:
ep_index = 1;
break;
return *this->files[!!solo][1].table;
case Episode::EP4:
ep_index = 2;
break;
return *this->files[!!solo][2].table;
default:
throw invalid_argument("invalid episode");
throw std::invalid_argument("invalid episode");
}
return *this->files[!!solo][ep_index].table;
}
+68 -27
View File
@@ -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;
@@ -35,7 +35,8 @@ public:
/* 24 */ le_uint32_t unknown_a14;
/* 28 */ le_uint32_t unknown_a15;
/* 2C */ le_uint32_t unknown_a16;
/* 30 */
static AttackData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __packed_ws__(AttackData, 0x30);
struct ResistData {
@@ -50,36 +51,76 @@ public:
/* 14 */ le_uint32_t unknown_a8;
/* 18 */ le_uint32_t unknown_a9;
/* 1C */ le_int32_t dfp_bonus;
/* 20 */
static ResistData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __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;
/* 30 */
/* 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;
static MovementData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __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 */
inline const PlayerStats& stats_for_index(Difficulty difficulty, uint8_t index) const {
return this->stats.at(static_cast<size_t>(difficulty)).at(index);
}
inline const AttackData& attack_data_for_index(Difficulty difficulty, uint8_t index) const {
return this->attack_data.at(static_cast<size_t>(difficulty)).at(index);
}
inline const ResistData& resist_data_for_index(Difficulty difficulty, uint8_t index) const {
return this->resist_data.at(static_cast<size_t>(difficulty)).at(index);
}
inline const MovementData& movement_data_for_index(Difficulty difficulty, uint8_t index) const {
return this->movement_data.at(static_cast<size_t>(difficulty)).at(index);
}
static Table from_json(const phosg::JSON& json);
phosg::JSON json() const;
void print(FILE* stream, Episode episode) const;
} __packed_ws__(Table, 0xF600);
BattleParamsIndex(
virtual ~BattleParamsIndex() = default;
virtual const Table& get_table(bool solo, Episode episode) const = 0;
phosg::JSON json() const;
protected:
BattleParamsIndex() = default;
};
class JSONBattleParamsIndex : public BattleParamsIndex {
public:
explicit JSONBattleParamsIndex(const phosg::JSON& json);
virtual const Table& get_table(bool solo, Episode episode) const;
protected:
// Indexed as [online/offline][episode]
std::array<std::array<Table, 3>, 2> tables;
};
class BinaryBattleParamsIndex : public BattleParamsIndex {
public:
BinaryBattleParamsIndex(
std::shared_ptr<const std::string> data_on_ep1, // BattleParamEntry_on.dat
std::shared_ptr<const std::string> data_on_ep2, // BattleParamEntry_lab_on.dat
std::shared_ptr<const std::string> data_on_ep4, // BattleParamEntry_ep4_on.dat
@@ -87,9 +128,9 @@ public:
std::shared_ptr<const std::string> data_off_ep2, // BattleParamEntry_lab.dat
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.dat
const Table& get_table(bool solo, Episode episode) const;
virtual const Table& get_table(bool solo, Episode episode) const;
private:
protected:
struct File {
std::shared_ptr<const std::string> data;
const Table* table = nullptr;
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <array>
#include <cstdint>
struct BrutalPeepsTierDefinition {
int8_t tier;
uint32_t required_level;
float exp_multiplier;
float enemy_hp_multiplier;
double rare_drop_multiplier;
};
static constexpr std::array<BrutalPeepsTierDefinition, 11> BRUTAL_PEEPS_TIERS = {{
{1, 100, 1.10f, 1.10f, 1.001},
{2, 110, 1.15f, 1.15f, 1.002},
{3, 120, 1.20f, 1.20f, 1.005},
{4, 130, 1.30f, 1.30f, 1.006},
{5, 140, 1.40f, 1.40f, 1.008},
{6, 150, 1.50f, 1.50f, 1.009},
{7, 160, 1.75f, 1.75f, 1.010},
{8, 170, 2.00f, 2.00f, 1.020},
{9, 180, 2.50f, 2.50f, 1.030},
{10, 190, 3.00f, 3.00f, 1.040},
{11, 200, 1.00f, 4.00f, 1.050},
}};
static inline const BrutalPeepsTierDefinition* brutal_peeps_tier_definition(int64_t tier) {
for (const auto& def : BRUTAL_PEEPS_TIERS) {
if (def.tier == tier) {
return &def;
}
}
return nullptr;
}
static inline int8_t max_brutal_peeps_tier_for_level(uint32_t level) {
int8_t ret = -1;
for (const auto& def : BRUTAL_PEEPS_TIERS) {
if (level >= def.required_level) {
ret = def.tier;
}
}
return ret;
}
+97 -63
View File
@@ -7,31 +7,36 @@
#include <phosg/Network.hh>
#include <phosg/Time.hh>
#include "CommandCensorData.hh"
#include "Loggers.hh"
#include "StaticGameData.hh"
#include "Version.hh"
using namespace std;
extern bool use_terminal_colors;
Channel::Channel(
Version version,
uint8_t language,
const string& name,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color)
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials)
: version(version),
language(language),
name(name),
terminal_send_color(terminal_send_color),
terminal_recv_color(terminal_recv_color) {
terminal_recv_color(terminal_recv_color),
censor_received_credentials(censor_received_credentials),
censor_sent_credentials(censor_sent_credentials) {
}
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;
@@ -42,7 +47,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
size += b.second;
}
string send_data;
std::string send_data;
size_t logical_size;
size_t send_data_size = 0;
switch (this->version) {
@@ -56,10 +61,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 +91,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;
@@ -111,13 +111,12 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
}
default:
throw logic_error("unimplemented game version in send_command");
throw std::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");
throw std::runtime_error("outbound command too large");
}
send_data.reserve(send_data_size);
@@ -131,13 +130,25 @@ 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);
}
phosg::print_data(stderr, send_data.data(), logical_size, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
struct iovec iov{.iov_base = send_data.data(), .iov_len = send_data.size()};
if (this->censor_sent_credentials) {
auto [censor_data, censor_size] = censor_data_for_client_command(this->version, cmd);
struct iovec censor_iovs[2] = {
// const_casts are OK here because print_data does not modify the buffers
{.iov_base = const_cast<char*>("\0\0\0\0\0\0\0\0"), .iov_len = static_cast<size_t>(is_v4(this->version) ? 8 : 4)},
{.iov_base = const_cast<void*>(censor_data), .iov_len = censor_size}};
phosg::print_data(stderr, &iov, 1, 0, nullptr, 0, censor_iovs, 2, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
} else {
phosg::print_data(stderr, &iov, 1, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
}
if (use_terminal_colors && this->terminal_send_color != phosg::TerminalFormat::NORMAL) {
print_color_escape(stderr, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END);
}
@@ -151,10 +162,10 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
}
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent) {
this->send(cmd, flag, {make_pair(data, size)}, silent);
this->send(cmd, flag, {std::make_pair(data, size)}, silent);
}
void Channel::send(uint16_t cmd, uint32_t flag, const string& data, bool silent) {
void Channel::send(uint16_t cmd, uint32_t flag, const std::string& data, bool silent) {
this->send(cmd, flag, data.data(), data.size(), silent);
}
@@ -169,7 +180,7 @@ void Channel::send(const void* data, size_t size, bool silent) {
silent);
}
void Channel::send(const string& data, bool silent) {
void Channel::send(const std::string& data, bool silent) {
this->send(data.data(), data.size(), silent);
}
@@ -183,24 +194,22 @@ asio::awaitable<Channel::Message> Channel::recv() {
size_t command_logical_size = header.size(version);
if (command_logical_size < header_size) {
throw runtime_error("header size field is smaller than header");
throw std::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;
string command_data(command_physical_size - header_size, '\0');
std::string command_data(command_physical_size - header_size, '\0');
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());
@@ -208,6 +217,7 @@ asio::awaitable<Channel::Message> Channel::recv() {
}
command_data.resize(command_logical_size - header_size);
uint16_t command = header.command(this->version);
if (command_data_log.should_log(phosg::LogLevel::L_INFO) && (this->terminal_recv_color != phosg::TerminalFormat::END)) {
if (use_terminal_colors && this->terminal_recv_color != phosg::TerminalFormat::NORMAL) {
print_color_escape(stderr, this->terminal_recv_color, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::END);
@@ -228,10 +238,20 @@ asio::awaitable<Channel::Message> Channel::recv() {
header.flag(this->version));
}
vector<struct iovec> iovs;
iovs.emplace_back(iovec{.iov_base = &header, .iov_len = header_size});
iovs.emplace_back(iovec{.iov_base = command_data.data(), .iov_len = command_data.size()});
phosg::print_data(stderr, iovs, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
struct iovec iovs[2] = {
{.iov_base = &header, .iov_len = header_size},
{.iov_base = command_data.data(), .iov_len = command_data.size()}};
if (this->censor_received_credentials) {
auto [censor_data, censor_size] = censor_data_for_client_command(this->version, command);
struct iovec censor_iovs[2] = {
// const_casts are OK here because print_data does not modify the buffers
{.iov_base = const_cast<char*>("\0\0\0\0\0\0\0\0"), .iov_len = header_size},
{.iov_base = const_cast<void*>(censor_data), .iov_len = censor_size}};
phosg::print_data(stderr, iovs, 2, 0, nullptr, 0, censor_iovs, 2, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
} else {
phosg::print_data(stderr, iovs, 2, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
}
if (use_terminal_colors && this->terminal_recv_color != phosg::TerminalFormat::NORMAL) {
phosg::print_color_escape(stderr, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END);
@@ -239,22 +259,32 @@ asio::awaitable<Channel::Message> Channel::recv() {
}
co_return Message{
.command = header.command(this->version),
.command = command,
.flag = header.flag(this->version),
.data = std::move(command_data),
};
}
shared_ptr<SocketChannel> SocketChannel::create(
std::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,
const string& name,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color) {
shared_ptr<SocketChannel> ret(new SocketChannel(
io_context, std::move(sock), version, language, name, terminal_send_color, terminal_recv_color));
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials) {
std::shared_ptr<SocketChannel> ret(new SocketChannel(
io_context,
std::move(sock),
version,
language,
name,
terminal_send_color,
terminal_recv_color,
censor_received_credentials,
censor_sent_credentials));
asio::co_spawn(*io_context, ret->send_task(), asio::detached);
return ret;
}
@@ -263,11 +293,13 @@ SocketChannel::SocketChannel(
std::shared_ptr<asio::io_context> io_context,
std::unique_ptr<asio::ip::tcp::socket>&& sock,
Version version,
uint8_t language,
const string& name,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color)
: Channel(version, language, name, terminal_send_color, terminal_recv_color),
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials)
: Channel(version, language, name, terminal_send_color, terminal_recv_color, censor_received_credentials, censor_sent_credentials),
sock(std::move(sock)),
local_addr(this->sock->local_endpoint()),
remote_addr(this->sock->remote_endpoint()),
@@ -286,7 +318,7 @@ void SocketChannel::disconnect() {
this->send_buffer_nonempty_signal.set();
}
void SocketChannel::send_raw(string&& data) {
void SocketChannel::send_raw(std::string&& data) {
if (this->sock && !this->should_disconnect) {
this->outbound_data.emplace_back(std::move(data));
this->send_buffer_nonempty_signal.set();
@@ -295,7 +327,7 @@ void SocketChannel::send_raw(string&& data) {
asio::awaitable<void> SocketChannel::recv_raw(void* data, size_t size) {
if (!this->sock || this->should_disconnect) {
throw runtime_error("Cannot receive on closed channel");
throw std::runtime_error("Cannot receive on closed channel");
}
co_await asio::async_read(*this->sock, asio::buffer(data, size), asio::use_awaitable);
}
@@ -305,11 +337,11 @@ asio::awaitable<void> SocketChannel::send_task() {
auto this_sh = this->shared_from_this();
while (this->sock->is_open()) {
deque<string> to_send;
std::deque<std::string> to_send;
to_send.swap(this->outbound_data);
if (!to_send.empty()) {
vector<asio::const_buffer> bufs;
std::vector<asio::const_buffer> bufs;
bufs.reserve(to_send.size());
for (const auto& it : to_send) {
bufs.emplace_back(asio::buffer(it.data(), it.size()));
@@ -331,16 +363,18 @@ 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)
: Channel(version, language, name, terminal_send_color, terminal_recv_color),
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials)
: Channel(version, language, name, terminal_send_color, terminal_recv_color, censor_received_credentials, censor_sent_credentials),
send_buffer_nonempty_signal(io_context->get_executor()) {}
void PeerChannel::link_peers(std::shared_ptr<PeerChannel> peer1, std::shared_ptr<PeerChannel> peer2) {
if (peer1->connected() || peer2->connected()) {
throw logic_error("Cannot link already-connected peer channels");
throw std::logic_error("Cannot link already-connected peer channels");
}
peer1->peer = peer2;
peer2->peer = peer1;
@@ -364,7 +398,7 @@ void PeerChannel::disconnect() {
this->send_buffer_nonempty_signal.set();
}
void PeerChannel::send_raw(string&& data) {
void PeerChannel::send_raw(std::string&& data) {
auto peer = this->peer.lock();
if (peer) {
peer->inbound_data.emplace_back(std::move(data));
@@ -392,7 +426,7 @@ asio::awaitable<void> PeerChannel::recv_raw(void* data, size_t size) {
this->inbound_data.pop_front();
}
} else if (!this->peer.lock()) {
throw runtime_error("Channel peer has disconnected");
throw std::runtime_error("Channel peer has disconnected");
}
}
}
+33 -30
View File
@@ -12,13 +12,15 @@
class Channel {
public:
Version version;
uint8_t language;
Language language;
std::shared_ptr<PSOEncryption> crypt_in;
std::shared_ptr<PSOEncryption> crypt_out;
std::string name;
phosg::TerminalFormat terminal_send_color;
phosg::TerminalFormat terminal_recv_color;
bool censor_received_credentials;
bool censor_sent_credentials;
struct Message {
uint16_t command;
@@ -60,9 +62,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 +77,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,43 +87,42 @@ 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);
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials);
Channel(const Channel& other) = delete;
Channel(Channel&& other) = delete;
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,
const std::string& name = "",
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials);
virtual std::string default_name() const;
@@ -138,10 +137,12 @@ 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);
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials);
std::deque<std::string> outbound_data;
bool should_disconnect = false;
@@ -158,10 +159,12 @@ public:
PeerChannel(
std::shared_ptr<asio::io_context> io_context,
Version version,
uint8_t language,
const std::string& name = "",
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials);
static void link_peers(std::shared_ptr<PeerChannel> peer1, std::shared_ptr<PeerChannel> peer2);
+515 -352
View File
File diff suppressed because it is too large Load Diff
+10 -12
View File
@@ -5,9 +5,7 @@
#include "Client.hh"
using namespace std;
const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
const std::vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES{
ChoiceSearchCategory{
.id = 0x0001,
.name = "Level",
@@ -24,7 +22,7 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0009, "Level 121-160"},
{0x000A, "Level 161-200"},
},
.client_matches = +[](shared_ptr<Client> searcher_c, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
.client_matches = +[](std::shared_ptr<Client> searcher_c, std::shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
if (choice_id == 0x0000) {
return true;
}
@@ -75,18 +73,18 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0008, "FOnewm"},
{0x0009, "FOnewearl"},
},
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
.client_matches = +[](std::shared_ptr<Client>, std::shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
switch (choice_id) {
case 0x0000:
return true;
case 0x0010:
return target_c->character_file()->disp.visual.class_flags & 0x20;
return target_c->character_file()->disp.visual.sh.class_flags & 0x20;
case 0x0011:
return target_c->character_file()->disp.visual.class_flags & 0x40;
return target_c->character_file()->disp.visual.sh.class_flags & 0x40;
case 0x0012:
return target_c->character_file()->disp.visual.class_flags & 0x80;
return target_c->character_file()->disp.visual.sh.class_flags & 0x80;
default:
return ((choice_id - 1) == target_c->character_file()->disp.visual.char_class);
return ((choice_id - 1) == target_c->character_file()->disp.visual.sh.char_class);
}
},
},
@@ -102,7 +100,7 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0005, "GC Episode 3"},
{0x0006, "BB"},
},
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
.client_matches = +[](std::shared_ptr<Client>, std::shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
if (choice_id == 0x0000) {
return true;
}
@@ -142,9 +140,9 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0005, "Battle"},
{0x0006, "Challenge"},
},
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
.client_matches = +[](std::shared_ptr<Client>, std::shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
uint16_t target_choice_id = target_c->character_file()->choice_search_config.get_setting(0x0204);
return (choice_id == 0) || (target_choice_id == 0) || (choice_id == target_choice_id);
},
},
});
};
+1 -4
View File
@@ -40,12 +40,9 @@ struct ChoiceSearchConfigT {
}
return ret;
}
} __attribute__((packed));
} __packed_ws_be__(ChoiceSearchConfigT, 0x18);
using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
check_struct_size(ChoiceSearchConfig, 0x18);
check_struct_size(ChoiceSearchConfigBE, 0x18);
struct ChoiceSearchCategory {
struct Choice {
+409 -265
View File
File diff suppressed because it is too large Load Diff
+77 -74
View File
@@ -6,11 +6,10 @@
#include "Account.hh"
#include "AsyncUtils.hh"
#include "Channel.hh"
#include "ClientFunctionIndex.hh"
#include "CommandFormats.hh"
#include "Episode3/BattleRecord.hh"
#include "Episode3/Tournament.hh"
#include "FileContentsCache.hh"
#include "FunctionCompiler.hh"
#include "PSOEncryption.hh"
#include "PSOProtocol.hh"
#include "PatchFileIndex.hh"
@@ -19,6 +18,7 @@
#include "QuestScript.hh"
#include "TeamIndex.hh"
#include "Text.hh"
#include <string>
extern const uint64_t CLIENT_CONFIG_MAGIC;
@@ -27,7 +27,7 @@ struct Lobby;
class Parsed6x70Data;
struct GetPlayerInfoResult {
// Exactly one of the following two shared_ptrs is not null
// Exactly one of the following two std::shared_ptrs is not null
std::shared_ptr<PSOBBCharacterFile> character;
std::shared_ptr<PSOGCEp3CharacterFile::Character> ep3_character;
bool is_full_info; // True if the client sent 30; false if it was 61 or 98
@@ -39,57 +39,60 @@ 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
HAS_PSO_PEEPS_XP_PATCH = 0x0000200000000000, // Must be same as in PSO Peeps XP patches
// 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 {
@@ -129,6 +132,9 @@ public:
uint64_t xb_user_id = 0;
uint32_t xb_unknown_a1b = 0;
std::shared_ptr<Login> login;
bool account_sync_lock_acquired = false;
uint32_t account_sync_lock_account_id = 0;
std::string account_sync_session_nonce;
std::shared_ptr<ProxySession> proxy_session;
// Patch server state (only used for PC_PATCH and BB_PATCH versions)
@@ -138,6 +144,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,13 +155,15 @@ 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_brutal_peeps_tier = -1; // -1 = normal lobby/game; 1..11 = requested Brutal Peeps tier
int8_t brutal_peeps_pc_battleparam_patch_tier = -1; // -1 = vanilla; 1..11 = currently applied PC BattleParam BP 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;
uint8_t lobby_arrow_color = 0;
int64_t preferred_lobby_id = -1; // <0 = no preference
int64_t preferred_lobby_id = -1; // <0 = none chosen
asio::steady_timer save_game_data_timer;
asio::steady_timer send_ping_timer;
@@ -186,10 +195,10 @@ public:
};
bool should_update_play_time;
std::unordered_set<uint32_t> blocked_senders;
std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp;
std::unique_ptr<PlayerDispDataV123> 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)
std::unordered_set<uint16_t> expected_game_state_sync_commands; // (command_num << 8) | target_client_id
// 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 +207,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 +222,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 +233,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 +261,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 +270,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,8 +319,8 @@ public:
void save_character_file();
void create_character_file(
uint32_t guild_card_number,
uint8_t language,
const PlayerDispDataBBPreview& preview,
Language language,
const PlayerVisualConfigV4& visual,
std::shared_ptr<const LevelTable> level_table);
void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
@@ -343,7 +346,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 +354,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 +365,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);
};
+633
View File
@@ -0,0 +1,633 @@
#include "ClientFunctionIndex.hh"
#include <stdio.h>
#include <string.h>
#include <filesystem>
#include <phosg/Filesystem.hh>
#include <phosg/Hash.hh>
#include <phosg/Time.hh>
#include <stdexcept>
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/SH4Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#include "CommandFormats.hh"
#include "CommonFileFormats.hh"
#include "Compression.hh"
#include "Loggers.hh"
using Arch = ClientFunctionIndex::Function::Architecture;
const char* name_for_architecture(Arch arch) {
switch (arch) {
case Arch::SH4:
return "SH-4";
case Arch::POWERPC:
return "PowerPC";
case Arch::X86:
return "x86";
default:
throw std::logic_error("invalid architecture");
}
}
uint32_t specific_version_for_architecture(Arch arch) {
switch (arch) {
case Arch::SH4:
return SPECIFIC_VERSION_SH4_INDETERMINATE;
case Arch::POWERPC:
return SPECIFIC_VERSION_PPC_INDETERMINATE;
case Arch::X86:
return SPECIFIC_VERSION_X86_INDETERMINATE;
default:
throw std::logic_error("invalid architecture");
}
}
Arch architecture_for_specific_version(uint32_t specific_version) {
if (specific_version == SPECIFIC_VERSION_SH4_INDETERMINATE) {
return Arch::SH4;
} else if (specific_version == SPECIFIC_VERSION_PPC_INDETERMINATE) {
return Arch::POWERPC;
} else if (specific_version == SPECIFIC_VERSION_X86_INDETERMINATE) {
return Arch::X86;
} else if (specific_version_is_dc(specific_version)) {
return Arch::SH4;
} else if (specific_version_is_gc(specific_version)) {
return Arch::POWERPC;
} else {
return Arch::X86;
}
}
static inline std::string cache_key(const std::string& name, uint32_t specific_version) {
return std::format("{}-{:08X}", name, specific_version);
}
template <typename T>
const T& get_with_sv_fallback(
const std::unordered_map<std::string, T>& index, const std::string& name, uint32_t specific_version) {
try {
return index.at(cache_key(name, specific_version));
} catch (const std::out_of_range&) {
}
uint32_t arch_specific_version = specific_version_for_architecture(architecture_for_specific_version(
specific_version));
if (arch_specific_version != specific_version) {
try {
return index.at(cache_key(name, arch_specific_version));
} catch (const std::out_of_range&) {
}
}
return index.at(name);
}
template <bool BE>
std::string ClientFunctionIndex::Function::generate_client_command_t(
const std::unordered_map<std::string, uint32_t>& label_writes,
const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const {
using FooterT = RELFileFooterT<BE>;
FooterT footer;
footer.num_relocations = this->relocation_deltas.size();
footer.unused1.clear(0);
footer.root_offset = this->entrypoint_offset_offset;
footer.unused2.clear(0);
phosg::StringWriter w;
if (!label_writes.empty()) {
std::string modified_code = this->code;
for (const auto& it : label_writes) {
size_t offset = this->label_offsets.at(it.first);
if (offset > modified_code.size() - 4) {
throw std::runtime_error("label out of range");
}
*reinterpret_cast<U32T<FooterT::IsBE>*>(modified_code.data() + offset) = it.second;
}
w.write(modified_code);
} else {
w.write(this->code);
}
if (suffix_size) {
w.write(suffix_data, suffix_size);
}
while (w.size() & 3) {
w.put_u8(0);
}
footer.relocations_offset = w.size();
// Always write at least 4 bytes even if there are no relocations
if (this->relocation_deltas.empty()) {
w.put_u32(0);
}
if (override_relocations_offset) {
footer.relocations_offset = override_relocations_offset;
} else {
for (uint16_t delta : this->relocation_deltas) {
w.put<U16T<FooterT::IsBE>>(delta);
}
if (this->relocation_deltas.size() & 1) {
w.put_u16(0);
}
}
w.put(footer);
return std::move(w.str());
}
std::string ClientFunctionIndex::Function::generate_client_command(
const std::unordered_map<std::string, uint32_t>& label_writes,
const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const {
if (this->is_big_endian()) {
return this->generate_client_command_t<true>(label_writes, suffix_data, suffix_size, override_relocations_offset);
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
return this->generate_client_command_t<false>(label_writes, suffix_data, suffix_size, override_relocations_offset);
} else {
throw std::logic_error("invalid architecture");
}
}
static std::unordered_map<uint32_t, std::string> preprocess_function_code(const std::string& text) {
std::unordered_set<uint32_t> all_specific_versions;
struct Line {
std::string text;
std::unordered_map<uint32_t, size_t> new_specific_versions; // Nonempty iff line is a .versions directive
bool enable_all_versions = false;
};
std::vector<Line> lines;
for (auto& line_text : phosg::split(text, '\n')) {
auto& line = lines.emplace_back();
line.text = std::move(line_text);
std::string stripped_line = line.text;
phosg::strip_whitespace(stripped_line);
if (stripped_line == ".all_versions") {
line.enable_all_versions = true;
} else if (stripped_line.starts_with(".versions ")) {
for (auto& vers_token : phosg::split(stripped_line.substr(10), ' ')) {
phosg::strip_whitespace(vers_token);
if (!vers_token.empty()) {
uint32_t specific_version = specific_version_for_str(vers_token);
size_t version_index = line.new_specific_versions.size();
all_specific_versions.emplace(specific_version);
line.new_specific_versions.emplace(std::move(specific_version), version_index);
}
}
}
}
static const std::string empty_str = "";
std::unordered_map<uint32_t, std::string> ret;
for (uint32_t specific_version : all_specific_versions) {
std::deque<std::string> version_lines;
bool include_current_line = true;
size_t current_vers_index = all_specific_versions.size();
for (size_t line_znum = 0; line_znum < lines.size(); line_znum++) {
const auto& line = lines[line_znum];
if (line.enable_all_versions) {
include_current_line = true;
current_vers_index = all_specific_versions.size();
version_lines.emplace_back(empty_str);
} else if (!line.new_specific_versions.empty()) {
auto it = line.new_specific_versions.find(specific_version);
if (it == line.new_specific_versions.end()) {
include_current_line = false;
current_vers_index = all_specific_versions.size();
} else {
include_current_line = true;
current_vers_index = it->second;
}
version_lines.emplace_back(empty_str);
} else if (!include_current_line) {
version_lines.emplace_back(empty_str);
} else {
std::string line_text = line.text;
size_t vers_offset = line_text.find("<VERS ");
while (vers_offset != std::string::npos) {
size_t end_offset = line_text.find('>', vers_offset + 6);
if (end_offset == std::string::npos) {
throw std::runtime_error(std::format("(version {}) (line {}) unterminated <VERS> replacement",
str_for_specific_version(specific_version), line_znum + 1));
}
auto tokens = phosg::split(line_text.substr(vers_offset + 6, end_offset - vers_offset - 6), ' ');
if (current_vers_index >= tokens.size()) {
throw std::runtime_error(std::format("(version {}) (line {}) invalid <VERS> replacement",
str_for_specific_version(specific_version), line_znum + 1));
}
line_text = line_text.substr(0, vers_offset) + tokens[current_vers_index] + line_text.substr(end_offset + 1);
vers_offset = line_text.find("<VERS ");
}
version_lines.emplace_back(std::move(line_text));
}
}
ret.emplace(specific_version, phosg::join(version_lines, "\n"));
}
return ret;
}
ClientFunctionIndex::ClientFunctionIndex(const std::string& root_dir, bool raise_on_any_failure) {
std::map<std::string, std::string> source_files;
std::function<void(const std::string&)> add_directory = [&](const std::string& dir) -> void {
for (const auto& item : std::filesystem::directory_iterator(dir)) {
std::string item_name = item.path().filename().string();
std::string item_path = dir.ends_with("/") ? (dir + item_name) : (dir + "/" + item_name);
if (std::filesystem::is_directory(item_path)) {
add_directory(item_path);
} else if (item_path.ends_with(".s") && std::filesystem::is_regular_file(item_path)) {
client_functions_log.debug_f("Adding {} from {}", item_name, item_path);
if (item_name.find("Dragon") != std::string::npos) {
client_functions_log.warning_f("Dragon source load debug: adding {} from {}", item_name, item_path);
}
if (!source_files.emplace(item_name, phosg::load_file(item_path)).second) {
throw std::runtime_error(std::format("Duplicate source filename: {}", item_name));
}
} else if (item_path.ends_with(".bin") && std::filesystem::is_regular_file(item_path)) {
client_functions_log.debug_f("Adding {} from {}", item_name, item_path);
if (!source_files.emplace(item_name, phosg::load_file(item_path)).second) {
throw std::runtime_error(std::format("Duplicate binary filename: {}", item_name));
}
} else {
client_functions_log.debug_f("Ignoring {}", item_path);
}
}
};
add_directory(root_dir);
std::unordered_map<std::string, std::string> include_cache;
uint32_t last_menu_item_id = 0;
for (const auto& [source_filename, source] : source_files) {
if (!source_filename.ends_with(".s")) {
client_functions_log.debug_f("Skipping root compile for {} because it is not a .s file", source_filename);
continue;
}
if (source_filename.ends_with(".inc.s")) {
client_functions_log.debug_f("Skipping root compile for {} because it is an include", source_filename);
continue;
}
std::unordered_map<uint32_t, std::string> preprocessed;
try {
preprocessed = preprocess_function_code(source);
} catch (const std::exception& e) {
throw std::runtime_error(std::format("({} preprocessing) {}", source_filename, e.what()));
}
if (source_filename.find("Dragon") != std::string::npos) {
client_functions_log.warning_f(
"Dragon preprocess debug: source={} produced {} version chunk(s)",
source_filename,
preprocessed.size());
for (const auto& [debug_sv, debug_source] : preprocessed) {
client_functions_log.warning_f(
"Dragon preprocess debug: source={} sv={} chunk_size={}",
source_filename,
str_for_specific_version(debug_sv),
debug_source.size());
}
}
for (const auto& [specific_version, source] : preprocessed) {
std::shared_ptr<Function> fn = std::make_shared<Function>();
fn->short_name = source_filename.substr(0, source_filename.size() - 2);
fn->specific_version = specific_version;
fn->menu_item_id = ++last_menu_item_id;
fn->arch = architecture_for_specific_version(fn->specific_version);
try {
std::unordered_set<std::string> get_include_stack;
std::function<std::string(const std::string&, uint32_t)> get_include_for_sv = [&include_cache, &source_files, &get_include_stack, &get_include_for_sv](const std::string& name, uint32_t specific_version) -> std::string {
try {
return get_with_sv_fallback(include_cache, name, specific_version);
} catch (const std::out_of_range&) {
}
if (client_functions_log.should_log(phosg::LogLevel::L_DEBUG)) {
client_functions_log.debug_f("({}) Include {}-{} needs to be compiled",
get_include_stack.size(), name, str_for_specific_version(specific_version));
}
auto it = source_files.find(name + ".inc.s");
if (it != source_files.end()) {
if (!get_include_stack.emplace(name).second) {
throw std::runtime_error("Mutual recursion between includes: " + name);
}
for (const auto& [include_specific_version, include_source] : preprocess_function_code(it->second)) {
ResourceDASM::EmulatorBase::AssembleResult ret;
auto get_include = std::bind(get_include_for_sv, std::placeholders::_1, include_specific_version);
switch (architecture_for_specific_version(include_specific_version)) {
case Arch::POWERPC:
ret = ResourceDASM::PPC32Emulator::assemble(include_source, get_include);
break;
case Arch::X86:
ret = ResourceDASM::X86Emulator::assemble(include_source, get_include);
break;
case Arch::SH4:
ret = ResourceDASM::SH4Emulator::assemble(include_source, get_include);
break;
default:
throw std::runtime_error("unknown architecture");
}
if (client_functions_log.should_log(phosg::LogLevel::L_DEBUG)) {
client_functions_log.debug_f("({}) Compiled include {}-{}",
get_include_stack.size(), name, str_for_specific_version(include_specific_version));
}
include_cache.emplace(cache_key(name, include_specific_version), std::move(ret.code));
}
get_include_stack.erase(name);
} else {
it = source_files.find(name + ".inc.bin");
if (it != source_files.end()) {
include_cache.emplace(name, it->second).first->second;
client_functions_log.debug_f("({}) Cached binary include {}", get_include_stack.size(), name);
}
}
try {
return get_with_sv_fallback(include_cache, name, specific_version);
} catch (const std::out_of_range&) {
}
throw std::runtime_error(std::format(
"Data not found for include {} ({})", name, str_for_specific_version(specific_version)));
};
try {
ResourceDASM::EmulatorBase::AssembleResult assembled;
auto get_include = std::bind(get_include_for_sv, std::placeholders::_1, specific_version);
switch (fn->arch) {
case Arch::POWERPC:
assembled = ResourceDASM::PPC32Emulator::assemble(source, get_include);
break;
case Arch::X86:
assembled = ResourceDASM::X86Emulator::assemble(source, get_include);
break;
case Arch::SH4:
assembled = ResourceDASM::SH4Emulator::assemble(source, get_include);
break;
default:
throw std::runtime_error("invalid architecture");
}
fn->code = std::move(assembled.code);
fn->label_offsets = std::move(assembled.label_offsets);
for (const auto& [key, value] : assembled.metadata_keys) {
if (key == "visibility") {
if (value == "hidden") {
fn->visibility = Function::Visibility::DEBUG_ONLY;
} else if (value == "cheat") {
fn->visibility = Function::Visibility::CHAT_COMMAND_ONLY_WITH_CHEAT_MODE;
} else if (value == "chat") {
fn->visibility = Function::Visibility::CHAT_COMMAND_ONLY;
} else if (value == "menu") {
fn->visibility = Function::Visibility::PATCHES_MENU_ONLY;
} else if (value == "all") {
fn->visibility = Function::Visibility::PATCHES_MENU_AND_CHAT_COMMAND;
} else {
throw std::runtime_error("Invalid visibility value");
}
} else if (key == "key") {
fn->short_name = value;
} else if (key == "name") {
fn->long_name = value;
} else if (key == "description") {
fn->description = value;
} else if (key == "client_flag") {
fn->client_flag = stoull(value, nullptr, 0);
} else if (key == "show_return_value") {
fn->show_return_value = true;
} else {
throw std::runtime_error("unknown metadata key: " + key);
}
}
try {
fn->entrypoint_offset_offset = fn->label_offsets.at("entry_ptr");
} catch (const std::out_of_range&) {
throw std::runtime_error("code does not contain entry_ptr label");
}
std::set<uint32_t> reloc_indexes;
for (const auto& it : fn->label_offsets) {
if (it.first.starts_with("reloc")) {
reloc_indexes.emplace(it.second / 4);
}
}
uint32_t prev_index = 0;
for (const auto& it : reloc_indexes) {
uint32_t delta = it - prev_index;
if (delta > 0xFFFF) {
throw std::runtime_error("relocation delta too far away");
}
fn->relocation_deltas.emplace_back(delta);
prev_index = it;
}
} catch (const std::exception& e) {
if (raise_on_any_failure) {
throw;
}
client_functions_log.warning_f("Failed to compile function {} ({}): {}",
fn->short_name, str_for_specific_version(specific_version), e.what());
}
auto key = cache_key(fn->short_name, specific_version);
if (!this->all_functions.emplace(key, fn).second) {
throw std::runtime_error("Duplicate function key: " + key);
}
this->functions_by_specific_version[specific_version].emplace(key, fn);
this->functions_by_menu_item_id.emplace(fn->menu_item_id, fn);
client_functions_log.debug_f("Compiled function {} ({}; {}; {})",
fn->short_name, str_for_specific_version(fn->specific_version), name_for_architecture(fn->arch),
phosg::name_for_enum(fn->visibility));
} catch (const std::exception& e) {
throw std::runtime_error(std::format(
"({}-{}) {}", fn->short_name, str_for_specific_version(specific_version), e.what()));
}
}
}
for (const char* probe_name : {"DragonVisualFix", "PsoPeepsDragonVisualFixPC", "RaresInQuests"}) {
for (uint32_t probe_sv : {0x324F4A57u, SPECIFIC_VERSION_X86_INDETERMINATE}) {
std::string key = cache_key(probe_name, probe_sv);
auto all_it = this->all_functions.find(key);
auto map_it = this->functions_by_specific_version.find(probe_sv);
bool in_version_map = false;
if (map_it != this->functions_by_specific_version.end()) {
in_version_map = map_it->second.count(key);
}
client_functions_log.warning_f(
"Client function probe: name={} sv={} key={} all_functions={} version_map={} map_size={}",
probe_name,
str_for_specific_version(probe_sv),
key,
all_it != this->all_functions.end(),
in_version_map,
map_it == this->functions_by_specific_version.end() ? 0 : map_it->second.size());
if (all_it != this->all_functions.end()) {
const auto& fn = all_it->second;
client_functions_log.warning_f(
"Client function probe detail: short={} long={} visibility={} specific_version={} arch={} menu_item_id={:08X}",
fn->short_name,
fn->long_name,
phosg::name_for_enum(fn->visibility),
str_for_specific_version(fn->specific_version),
name_for_architecture(fn->arch),
static_cast<uint32_t>(fn->menu_item_id));
}
}
}
}
std::shared_ptr<const Menu> ClientFunctionIndex::patch_switches_menu(
uint32_t specific_version,
const std::unordered_set<std::string>& server_auto_patches_enabled,
const std::unordered_set<std::string>& client_auto_patches_enabled) const {
auto ret = std::make_shared<Menu>(MenuID::PATCH_SWITCHES, "Patches");
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
auto map_it = this->functions_by_specific_version.find(specific_version);
if (map_it != this->functions_by_specific_version.end()) {
client_functions_log.warning_f(
"Patch menu debug: building menu for specific_version={} with {} function entries",
str_for_specific_version(specific_version),
map_it->second.size());
for (auto [name, fn] : map_it->second) {
bool appears = fn->appears_in_patches_menu();
bool server_auto = server_auto_patches_enabled.count(fn->short_name);
bool client_enabled = client_auto_patches_enabled.count(fn->short_name);
bool dragon_debug =
(fn->short_name.find("Dragon") != std::string::npos) ||
(fn->long_name.find("Dragon") != std::string::npos);
if (dragon_debug || appears) {
client_functions_log.warning_f(
"Patch menu debug: key={} short={} long={} visibility={} appears={} server_auto={} client_enabled={} menu_item_id={:08X}",
name,
fn->short_name,
fn->long_name,
phosg::name_for_enum(fn->visibility),
appears,
server_auto,
client_enabled,
static_cast<uint32_t>(fn->menu_item_id));
}
if (appears && !server_auto) {
std::string item_text;
item_text.push_back(client_enabled ? '*' : '-');
item_text += fn->long_name.empty() ? fn->short_name : fn->long_name;
ret->items.emplace_back(
fn->menu_item_id, item_text, fn->description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
}
}
} else {
client_functions_log.warning_f(
"Patch menu debug: no functions for specific_version={}",
str_for_specific_version(specific_version));
}
return ret;
}
bool ClientFunctionIndex::patch_menu_empty(uint32_t specific_version) const {
uint32_t mask = specific_version_is_indeterminate(specific_version) ? 0xFF000000 : 0xFFFFFFFF;
auto it = this->functions_by_specific_version.lower_bound(specific_version & mask);
return ((it == this->functions_by_specific_version.end()) || ((it->first & mask) != (specific_version & mask)));
}
std::shared_ptr<const ClientFunctionIndex::Function> ClientFunctionIndex::get(
const std::string& name, uint32_t specific_version) const {
return get_with_sv_fallback(this->all_functions, name, specific_version);
}
std::shared_ptr<const ClientFunctionIndex::Function> ClientFunctionIndex::get(
const std::string& name, Arch arch) const {
return get_with_sv_fallback(this->all_functions, name, specific_version_for_architecture(arch));
}
std::shared_ptr<const ClientFunctionIndex::Function> ClientFunctionIndex::get(const std::string& name) const {
return this->all_functions.at(name);
}
std::shared_ptr<const ClientFunctionIndex::Function> ClientFunctionIndex::get_by_menu_item_id(
uint32_t menu_item_id) const {
return this->functions_by_menu_item_id.at(menu_item_id);
}
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum) {
static std::unordered_map<uint32_t, uint32_t> checksum_to_specific_version;
if (checksum_to_specific_version.empty()) {
struct {
char system_code = 'G';
char game_code1 = 'P';
char game_code2;
char region_code;
char developer_code1 = '8';
char developer_code2 = 'P';
uint8_t disc_number = 0;
uint8_t version_code;
} __attribute__((packed)) data;
for (const char* game_code2 = "OS"; *game_code2; game_code2++) {
data.game_code2 = *game_code2;
for (const char* region_code = "JEP"; *region_code; region_code++) {
data.region_code = *region_code;
for (uint8_t version_code = 0; version_code < 8; version_code++) {
data.version_code = version_code;
uint32_t checksum = phosg::crc32(&data, sizeof(data));
uint32_t specific_version = 0x33000030 | (*game_code2 << 16) | (*region_code << 8) | version_code;
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
throw std::logic_error("multiple specific_versions have same header checksum");
}
}
}
{
// Generate entries for Trial Editions
data.region_code = 'J';
data.system_code = 'D';
data.version_code = 0;
uint32_t checksum = phosg::crc32(&data, sizeof(data));
uint32_t specific_version = 0x33004A54 | (*game_code2 << 16);
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
throw std::logic_error("multiple specific_versions have same header checksum");
}
data.system_code = 'G';
}
}
}
return checksum_to_specific_version.at(header_checksum);
}
template <>
const char* phosg::name_for_enum<ClientFunctionIndex::Function::Visibility>(
ClientFunctionIndex::Function::Visibility vis) {
switch (vis) {
case ClientFunctionIndex::Function::Visibility::DEBUG_ONLY:
return "DEBUG_ONLY";
case ClientFunctionIndex::Function::Visibility::CHAT_COMMAND_ONLY_WITH_CHEAT_MODE:
return "CHAT_COMMAND_ONLY_WITH_CHEAT_MODE";
case ClientFunctionIndex::Function::Visibility::CHAT_COMMAND_ONLY:
return "CHAT_COMMAND_ONLY";
case ClientFunctionIndex::Function::Visibility::PATCHES_MENU_ONLY:
return "PATCHES_MENU_ONLY";
case ClientFunctionIndex::Function::Visibility::PATCHES_MENU_AND_CHAT_COMMAND:
return "PATCHES_MENU_AND_CHAT_COMMAND";
default:
throw std::logic_error("Invalid client function visibility");
}
}
+96
View File
@@ -0,0 +1,96 @@
#pragma once
#include <inttypes.h>
#include <map>
#include <memory>
#include <phosg/Strings.hh>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "Menu.hh"
class ClientFunctionIndex {
public:
struct Function {
enum class Architecture {
UNKNOWN = 0,
POWERPC, // GC
X86, // PC, XB, BB
SH4, // Dreamcast
};
Architecture arch = Architecture::UNKNOWN;
std::string code;
std::vector<uint16_t> relocation_deltas;
std::unordered_map<std::string, uint32_t> label_offsets;
uint32_t entrypoint_offset_offset = 0;
std::string short_name; // Based on filename
std::string long_name; // From .meta name directive
std::string description; // From .meta description directive
uint64_t client_flag = 0; // From .meta client_flag directive
uint32_t menu_item_id = 0;
enum class Visibility {
DEBUG_ONLY = 0,
CHAT_COMMAND_ONLY_WITH_CHEAT_MODE,
CHAT_COMMAND_ONLY,
PATCHES_MENU_ONLY,
PATCHES_MENU_AND_CHAT_COMMAND,
};
Visibility visibility;
bool show_return_value = false;
uint32_t specific_version;
inline bool appears_in_patches_menu() const {
return (this->visibility == Visibility::PATCHES_MENU_ONLY) ||
(this->visibility == Visibility::PATCHES_MENU_AND_CHAT_COMMAND);
}
inline bool allowed_via_chat_command(bool cheat_mode_enabled) const {
return (cheat_mode_enabled && (this->visibility == Visibility::CHAT_COMMAND_ONLY_WITH_CHEAT_MODE)) ||
(this->visibility == Visibility::CHAT_COMMAND_ONLY) ||
(this->visibility == Visibility::PATCHES_MENU_AND_CHAT_COMMAND);
}
inline bool is_big_endian() const {
return (this->arch == Architecture::POWERPC);
}
template <bool BE>
std::string generate_client_command_t(
const std::unordered_map<std::string, uint32_t>& label_writes,
const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const;
std::string generate_client_command(
const std::unordered_map<std::string, uint32_t>& label_writes = {},
const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const;
};
ClientFunctionIndex() = default;
ClientFunctionIndex(const std::string& directory, bool raise_on_any_failure);
std::unordered_map<std::string, std::shared_ptr<Function>> all_functions; // Key is "PatchName-SpecificVersion"
std::map<uint32_t, std::map<std::string, std::shared_ptr<Function>>> functions_by_specific_version;
std::map<uint32_t, std::shared_ptr<Function>> functions_by_menu_item_id;
std::shared_ptr<const Menu> patch_switches_menu(
uint32_t specific_version,
const std::unordered_set<std::string>& server_auto_patches_enabled,
const std::unordered_set<std::string>& client_auto_patches_enabled) const;
bool patch_menu_empty(uint32_t specific_version) const;
std::shared_ptr<const Function> get(const std::string& name, uint32_t specific_version) const;
std::shared_ptr<const Function> get(const std::string& name, Function::Architecture arch) const;
std::shared_ptr<const Function> get(const std::string& name) const;
std::shared_ptr<const Function> get_by_menu_item_id(uint32_t menu_item_id) const;
};
const char* name_for_architecture(ClientFunctionIndex::Function::Architecture arch);
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);
template <>
const char* phosg::name_for_enum<ClientFunctionIndex::Function::Visibility>(
ClientFunctionIndex::Function::Visibility vis);
+241
View File
@@ -0,0 +1,241 @@
#include "CommandCensorData.hh"
#include "CommandFormats.hh"
std::pair<const void*, size_t> censor_data_for_client_command(Version version, uint16_t command) {
switch (command) {
case 0x03: {
static const C_LegacyLogin_PC_V3_03 ret{
.hardware_id = 0,
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused = 0,
.serial_number2 = 1,
.access_key2 = 1,
};
return std::make_pair(&ret, sizeof(ret));
}
case 0x04:
if (is_patch(version)) {
static const C_Login_Patch_04 ret{.unused{0}, .username{1}, .password{1}, .email_address{1}};
return std::make_pair(&ret, sizeof(ret));
} else if (!is_v4(version)) {
static const C_LegacyLogin_PC_V3_04 ret{
.hardware_id = 0,
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused = 0,
.serial_number = 1,
.access_key = 1,
};
return std::make_pair(&ret, sizeof(ret));
} else {
static const C_LegacyLogin_BB_04 ret{
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused = 0,
.username = 1,
.password = 1};
return std::make_pair(&ret, sizeof(ret));
}
case 0x88:
if (version == Version::DC_NTE) {
static const C_Login_DCNTE_88 ret{.serial_number{1}, .access_key{1}};
return std::make_pair(&ret, sizeof(ret));
} else {
return std::make_pair(nullptr, 0);
}
case 0x8A:
if (version == Version::DC_NTE) {
static const C_ConnectionInfo_DCNTE_8A ret{
.hardware_id = 0, .sub_version = 0, .unused = 0, .username = 1, .password = 1, .email_address = 1};
return std::make_pair(&ret, sizeof(ret));
} else {
return std::make_pair(nullptr, 0);
}
case 0x8B:
if (version == Version::DC_NTE) {
static const C_Login_DCNTE_8B ret{
.player_tag = 0,
.guild_card_number = 0,
.hardware_id = 0,
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused1 = 0,
.serial_number = 1,
.access_key = 1,
.username = 1,
.password = 1,
.login_character_name = 0,
.unused = 0,
};
return std::make_pair(&ret, sizeof(ret));
} else {
return std::make_pair(nullptr, 0);
}
case 0x90: {
static const C_LoginV1_DC_PC_V3_90 ret{.serial_number = 1, .access_key = 1};
return std::make_pair(&ret, sizeof(ret));
}
case 0x92: {
static const C_RegisterV1_DC_92 ret{
.hardware_id = 0,
.sub_version = 0,
.unused1 = 0,
.language = Language::JAPANESE,
.unused2 = 0,
.serial_number2 = 1,
.access_key2 = 1,
.email_address = 1,
};
return std::make_pair(&ret, sizeof(ret));
}
case 0x93:
if (!is_v4(version)) {
static const C_LoginV1_DC_93 ret{
.player_tag = 0,
.guild_card_number = 0,
.hardware_id = 0,
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused1 = 0,
.serial_number = 1,
.access_key = 1,
.serial_number2 = 1,
.access_key2 = 1,
.login_character_name = 0,
.unused2 = 0,
};
return std::make_pair(&ret, sizeof(ret));
} else {
static const C_LoginBase_BB_93 ret{
.player_tag = 0,
.guild_card_number = 0,
.sub_version = 0,
.language = Language::JAPANESE,
.character_slot = 0,
.connection_phase = 0,
.client_code = 0,
.security_token = 0,
.username = 1,
.password = 1,
.menu_id = 0,
.preferred_lobby_id = 0,
};
return std::make_pair(&ret, sizeof(ret));
}
case 0x9A: {
static const C_Login_DC_PC_V3_9A ret{
.v1_serial_number = 1,
.v1_access_key = 1,
.serial_number = 1,
.access_key = 1,
.player_tag = 0,
.guild_card_number = 0,
.sub_version = 0,
.serial_number2 = 1,
.access_key2 = 1,
.email_address = 1,
};
return std::make_pair(&ret, sizeof(ret));
}
case 0x9C:
if (!is_v4(version)) {
static const C_Register_DC_PC_V3_9C ret{
.hardware_id = 0,
.sub_version = 0,
.unused1 = 0,
.language = Language::JAPANESE,
.unused2 = 0,
.serial_number = 1,
.access_key = 1,
.password = 1,
};
return std::make_pair(&ret, sizeof(ret));
} else {
static const C_Register_BB_9C ret{
.sub_version = 0,
.unused1 = 0,
.language = Language::JAPANESE,
.unused2 = 0,
.username = 1,
.password = 1,
.game_tag = 0,
};
return std::make_pair(&ret, sizeof(ret));
}
case 0x9D:
case 0x9E:
if (!is_v4(version)) {
static const C_Login_DC_PC_GC_9D ret{
.player_tag = 0,
.guild_card_number = 0,
.hardware_id = 0,
.sub_version = 0,
.is_extended = 0,
.language = Language::JAPANESE,
.unused3 = 0,
.v1_serial_number = 1,
.v1_access_key = 1,
.serial_number = 1,
.access_key = 1,
.serial_number2 = 1,
.access_key2 = 1,
.login_character_name = 0,
};
return std::make_pair(&ret, sizeof(ret));
} else {
static const C_LoginExtended_BB_9E ret{
.player_tag = 0,
.guild_card_number = 0,
.sub_version = 0,
.language32 = 0,
.unknown_a2 = 0,
.v1_serial_number = 1,
.v1_access_key = 1,
.serial_number = 1,
.access_key = 1,
.username = 1,
.password = 1,
.guild_card_number_str = 0,
.client_config = 0,
.extension{},
};
return std::make_pair(&ret, sizeof(ret));
}
case 0xDB:
if (!is_v4(version)) {
static const C_VerifyAccount_V3_DB ret{
.v1_serial_number = 1,
.v1_access_key = 1,
.serial_number = 1,
.access_key = 1,
.hardware_id = 0,
.sub_version = 0,
.serial_number2 = 1,
.access_key2 = 1,
.password = 1,
};
return std::make_pair(&ret, sizeof(ret));
} else {
static const C_VerifyAccount_BB_DB ret{
.v1_serial_number = 1,
.v1_access_key = 1,
.serial_number = 1,
.access_key = 1,
.sub_version = 0,
.username = 1,
.password = 1,
.game_tag = 0,
};
return std::make_pair(&ret, sizeof(ret));
}
default:
return std::make_pair(nullptr, 0);
}
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
#include <utility>
#include "Version.hh"
std::pair<const void*, size_t> censor_data_for_client_command(Version version, uint16_t command);
+1826 -2256
View File
File diff suppressed because it is too large Load Diff
+137 -32
View File
@@ -1,7 +1,9 @@
#pragma once
#include <phosg/Encoding.hh>
#include <phosg/Strings.hh>
#include <phosg/Vector.hh>
#include <set>
#include "Text.hh"
@@ -37,6 +39,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 +96,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 {
@@ -132,39 +133,143 @@ struct ArrayRefT {
/* 00 */ U32T<BE> count;
/* 04 */ U32T<BE> offset;
/* 08 */
} __attribute__((packed));
} __packed_ws_be__(ArrayRefT, 8);
using ArrayRef = ArrayRefT<false>;
using ArrayRefBE = ArrayRefT<true>;
check_struct_size(ArrayRef, 8);
check_struct_size(ArrayRefBE, 8);
template <bool BE>
struct RELFileFooterT {
static constexpr bool IsBE = BE;
// Relocations is a list of words (le_uint16_t on DC/PC/XB/BB, be_uint16_t on
// GC) containing the number of doublewords (uint32_t) to skip for each
// relocation. The relocation pointer starts 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;
U32T<BE> root_offset = 0;
parray<U32T<BE>, 3> unused2;
} __attribute__((packed));
} __packed_ws_be__(RELFileFooterT, 0x20);
using RELFileFooter = RELFileFooterT<false>;
using RELFileFooterBE = RELFileFooterT<true>;
check_struct_size(RELFileFooter, 0x20);
check_struct_size(RELFileFooterBE, 0x20);
template <bool BE>
std::set<uint32_t> all_relocation_offsets_for_rel_file(const void* data, size_t size) {
phosg::StringReader r(data, size);
std::set<uint32_t> ret;
ret.emplace(r.size() - 0x20); // REL footer
ret.emplace(r.pget<U32T<BE>>(r.size() - 0x10)); // root
ret.emplace(r.pget<U32T<BE>>(r.size() - 0x20)); // relocations
const auto& footer = r.pget<RELFileFooterT<BE>>(r.size() - sizeof(RELFileFooterT<BE>));
auto sub_r = r.sub(footer.relocations_offset, footer.num_relocations * sizeof(U16T<BE>));
uint32_t offset = 0;
while (!sub_r.eof()) {
offset += sub_r.template get<U16T<BE>>() * 4;
ret.emplace(r.pget<U32T<BE>>(offset));
}
return ret;
}
template <typename T>
size_t get_rel_array_count(const std::set<uint32_t>& offsets, size_t start_offset) {
auto it = offsets.lower_bound(start_offset);
if (it == offsets.end()) {
throw std::out_of_range("start offset out of range");
}
if (*it == start_offset) {
it++;
}
if (it == offsets.end()) {
throw std::out_of_range("no further offset beyond start offset");
}
return (*it - start_offset) / sizeof(T);
}
template <bool BE>
class RELFileWriter {
public:
RELFileWriter() = default;
~RELFileWriter() = default;
template <typename T>
uint32_t put(const T& obj) {
uint32_t ret = this->w.size();
this->w.put<T>(obj);
return ret;
}
uint32_t write(const void* data, size_t size) {
uint32_t ret = this->w.size();
this->w.write(data, size);
return ret;
}
uint32_t write(const std::string& data) {
uint32_t ret = this->w.size();
this->w.write(data);
return ret;
}
uint32_t write_offset(uint32_t value) {
uint32_t ret = this->w.size();
this->relocations.emplace(ret);
this->w.put<U32T<BE>>(value);
return ret;
}
uint32_t write_ref(const ArrayRefT<BE>& ref) {
uint32_t ret = this->w.size();
this->w.put<ArrayRefT<BE>>(ref);
this->relocations.emplace(ret + offsetof(ArrayRefT<BE>, offset));
return ret;
}
void align(size_t alignment) {
while (this->w.size() & (alignment - 1)) {
this->w.put_u8(0);
}
}
std::string finalize(uint32_t root_offset) {
RELFileFooterT<BE> footer;
footer.root_offset = root_offset;
this->align(0x20);
footer.relocations_offset = this->w.size();
footer.num_relocations = this->relocations.size();
footer.unused1[0] = 1;
uint32_t last_offset = 0;
for (uint32_t reloc_offset : this->relocations) {
if (reloc_offset & 3) {
throw std::logic_error("Relocation is not 4-byte aligned");
}
size_t reloc_value = (reloc_offset - last_offset) >> 2;
if (reloc_value > 0xFFFF) {
throw std::runtime_error("Relocation offset is too far away from previous");
}
this->w.put<U16T<BE>>(reloc_value);
last_offset = reloc_offset;
}
align(0x20);
this->w.put<RELFileFooterT<BE>>(footer);
return std::move(this->w.str());
}
phosg::StringWriter w;
std::set<uint32_t> relocations;
};
+389 -426
View File
File diff suppressed because it is too large Load Diff
+110 -425
View File
@@ -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;
@@ -63,55 +69,44 @@ public:
void parse_itempt_t(const phosg::StringReader& r, bool is_v3);
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.
struct RootT {
// 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
@@ -261,17 +244,19 @@ public:
/* 50 */ U32T<BE> box_item_class_prob_table_offset;
// There are several unused fields here.
} __attribute__((packed));
using Offsets = OffsetsT<false>;
using OffsetsBE = OffsetsT<true>;
check_struct_size(Offsets, 0x54);
check_struct_size(OffsetsBE, 0x54);
} __packed_ws_be__(RootT, 0x54);
using Root = RootT<false>;
using RootBE = RootT<true>;
};
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 +264,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;
};
@@ -298,304 +284,3 @@ class JSONCommonItemSet : public CommonItemSet {
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.
template <typename ItemT, size_t MaxCount>
struct ProbabilityTable {
ItemT items[MaxCount];
size_t count;
ProbabilityTable() : count(0) {}
void push(ItemT item) {
if (this->count == MaxCount) {
throw std::runtime_error("push to full probability table");
}
this->items[this->count++] = item;
}
ItemT pop() {
if (this->count == 0) {
throw std::runtime_error("pop from empty probability table");
}
return this->items[--this->count];
}
void shuffle(std::shared_ptr<RandomGenerator> rand_crypt) {
for (size_t z = 1; z < this->count; z++) {
size_t other_z = rand_crypt->next() % (z + 1);
ItemT t = this->items[z];
this->items[z] = this->items[other_z];
this->items[other_z] = t;
}
}
ItemT sample(std::shared_ptr<RandomGenerator> rand_crypt) const {
if (this->count == 0) {
throw std::runtime_error("sample from empty probability table");
} else if (this->count == 1) {
return this->items[0];
} else {
return this->items[rand_crypt->next() % this->count];
}
}
};
class RELFileSet {
public:
template <typename ValueT, typename WeightT = ValueT>
struct WeightTableEntry {
ValueT value;
WeightT weight;
} __attribute__((packed));
using WeightTableEntry8 = WeightTableEntry<uint8_t>;
using WeightTableEntry32 = WeightTableEntry<be_uint32_t>;
check_struct_size(WeightTableEntry8, 2);
check_struct_size(WeightTableEntry32, 8);
protected:
std::shared_ptr<const std::string> data;
phosg::StringReader r;
struct TableSpec {
be_uint32_t offset;
uint8_t entries_per_table;
parray<uint8_t, 3> unused;
} __packed_ws__(TableSpec, 8);
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 {
const T* entries = &r.pget<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);
}
};
class ArmorRandomSet : public RELFileSet {
public:
// This class parses and accesses data from ArmorRandom.rel
ArmorRandomSet(std::shared_ptr<const std::string> data);
std::pair<const WeightTableEntry8*, size_t> get_armor_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_shield_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_unit_table(size_t index) const;
private:
const parray<TableSpec, 3>* tables;
};
class ToolRandomSet : public RELFileSet {
public:
// This class parses and accesses data from ToolRandom.rel
ToolRandomSet(std::shared_ptr<const std::string> data);
struct TechDiskLevelEntry {
enum class Mode : uint8_t {
LEVEL_1 = 0,
PLAYER_LEVEL_DIVISOR = 1,
RANDOM_IN_RANGE = 2,
};
Mode mode;
uint8_t player_level_divisor_or_min_level;
uint8_t max_level;
} __packed_ws__(TechDiskLevelEntry, 3);
std::pair<const uint8_t*, size_t> get_common_recovery_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_rare_recovery_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_tech_disk_table(size_t index) const;
std::pair<const TechDiskLevelEntry*, size_t> get_tech_disk_level_table(size_t index) const;
private:
const TableSpec* common_recovery_table_spec;
const TableSpec* rare_recovery_table_spec;
const TableSpec* tech_disk_table_spec;
const TableSpec* tech_disk_level_table_spec;
};
class WeaponRandomSet : public RELFileSet {
public:
// This class parses and accesses data from WeaponRandom*.rel
WeaponRandomSet(std::shared_ptr<const std::string> data);
struct RangeTableEntry {
be_uint32_t min;
be_uint32_t max;
} __packed_ws__(RangeTableEntry, 8);
std::pair<const WeightTableEntry8*, size_t> get_weapon_type_table(size_t index) const;
const parray<WeightTableEntry32, 6>* get_bonus_type_table(size_t which, size_t index) const;
const RangeTableEntry* get_bonus_range(size_t which, size_t index) const;
const parray<WeightTableEntry32, 3>* get_special_mode_table(size_t index) const;
const RangeTableEntry* get_standard_grind_range(size_t index) const;
const RangeTableEntry* get_favored_grind_range(size_t index) const;
private:
struct Offsets {
be_uint32_t weapon_type_table; // [{c, o -> (table)}](10)
be_uint32_t bonus_type_table1; // [[{u32 value, u32 weight}](6)](9)
be_uint32_t bonus_type_table2; // [[{u32 value, u32 weight}](6)](9)
be_uint32_t bonus_range_table1; // [{u32 min_index, u32 max_index}](9)
be_uint32_t bonus_range_table2; // [{u32 min_index, u32 max_index}](9)
be_uint32_t special_mode_table; // [[{u32 value, u32 weight}](3)](8)
be_uint32_t standard_grind_range_table; // [{u32 min, u32 max}](6)
be_uint32_t favored_grind_range_table; // [{u32 min, u32 max}](6)
} __packed_ws__(Offsets, 0x20);
const Offsets* offsets;
};
class TekkerAdjustmentSet {
public:
// This class parses and accesses data from JudgeItem.rel
TekkerAdjustmentSet(std::shared_ptr<const std::string> data);
const ProbabilityTable<uint8_t, 100>& get_special_upgrade_prob_table(uint8_t section_id, bool favored) const;
const ProbabilityTable<uint8_t, 100>& get_grind_delta_prob_table(uint8_t section_id, bool favored) const;
const ProbabilityTable<uint8_t, 100>& get_bonus_delta_prob_table(uint8_t section_id, bool favored) const;
int8_t get_luck_for_special_upgrade(uint8_t delta_index) const;
int8_t get_luck_for_grind_delta(uint8_t delta_index) const;
int8_t get_luck_for_bonus_delta(uint8_t delta_index) const;
private:
const ProbabilityTable<uint8_t, 100>& get_table(
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_default,
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_favored,
uint32_t offset_and_count_offset,
bool favored,
uint8_t section_id) const;
int8_t get_luck(uint32_t start_offset, uint8_t delta_index) const;
std::shared_ptr<const std::string> data;
phosg::StringReader r;
struct DeltaProbabilityEntry {
uint8_t delta_index;
uint8_t count_default;
uint8_t count_favored;
} __packed_ws__(DeltaProbabilityEntry, 3);
struct LuckTableEntry {
uint8_t delta_index;
int8_t luck;
} __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.
// 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.
// In PSO V3, the special upgrade table is:
// Viridia => (D) +1=10%, 0=60%, -1=30%
// Viridia => (F) +1=25%, 0=50%, -1=25%
// Greennill => (D) +1=25%, 0=65%, -1=10%
// Greennill => (F) +1=40%, 0=55%, -1=5%
// Skyly => (D) +1=15%, 0=70%, -1=15%
// Skyly => (F) +1=30%, 0=60%, -1=10%
// Bluefull => (D) +1=10%, 0=60%, -1=30%
// Bluefull => (F) +1=25%, 0=50%, -1=25%
// Purplenum => (D) +1=25%, 0=65%, -1=10%
// Purplenum => (F) +1=40%, 0=55%, -1=5%
// Pinkal => (D) +1=15%, 0=70%, -1=15%
// Pinkal => (F) +1=30%, 0=60%, -1=10%
// Redria => (D) +1=20%, 0=60%, -1=20%
// Redria => (F) +1=0%, 0=0%, -1=0%
// Oran => (D) +1=15%, 0=70%, -1=15%
// Oran => (F) +1=30%, 0=60%, -1=10%
// Yellowboze => (D) +1=25%, 0=65%, -1=10%
// Yellowboze => (F) +1=40%, 0=55%, -1=5%
// Whitill => (D) +1=10%, 0=60%, -1=30%
// 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.
// 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%
// Greennill => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
// Greennill => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
// Skyly => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
// Skyly => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
// Bluefull => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
// Bluefull => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
// Purplenum => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
// Purplenum => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
// Pinkal => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
// Pinkal => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
// Redria => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
// Redria => (F) +3=0%, +2=0%, +1=0%, 0=0%, -1=0%, -2=0%, -3=0%
// Oran => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
// Oran => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
// Yellowboze => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
// Yellowboze => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
// Whitill => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
// 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).
// 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%
// Greennill => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
// Greennill => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
// Skyly => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
// Skyly => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
// Bluefull => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
// Bluefull => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
// Purplenum => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
// Purplenum => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
// Pinkal => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
// Pinkal => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
// Redria => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
// Redria => (F) +10=0%, +5=0%, 0=0%, -5=0%, -10=0%
// Oran => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
// Oran => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
// Yellowboze => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
// Yellowboze => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
// Whitill => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
// 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.
// In PSO V3, the special upgrade luck table is:
// +1 => +20, 0 => 0, -1 => -20
be_uint32_t special_upgrade_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
// In PSO V3, the grind delta luck table is:
// +3 => +10, +2 => +5, +1 => +3, 0 => 0, -1 => -3, -2 => -5, -3 => -10
be_uint32_t grind_delta_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
// In PSO V3, the bonus delta luck table is:
// +10 => +15, +5 => +8, 0 => 0, -5 => -8, -10 => -15
be_uint32_t bonus_delta_luck_offset; // LuckTableEntry[...]; ending with FF FF
} __packed_ws__(Offsets, 0x18);
const Offsets* offsets;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_default;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_favored;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_default;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_favored;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_default;
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_favored;
};
+256 -235
View File
@@ -11,8 +11,6 @@
#include "Text.hh"
using namespace std;
template <>
const char* phosg::name_for_enum<CompressPhase>(CompressPhase v) {
switch (v) {
@@ -30,29 +28,29 @@ const char* phosg::name_for_enum<CompressPhase>(CompressPhase v) {
}
template <size_t WindowLength, size_t MaxMatchLength>
struct WindowIndex {
struct MapWindowIndex {
const uint8_t* data;
size_t size;
size_t offset;
set<size_t, function<bool(size_t, size_t)>> index;
size_t current_offset;
std::set<size_t, std::function<bool(size_t, size_t)>> index;
WindowIndex(const void* data, size_t size)
MapWindowIndex(const void* data, size_t size)
: data(reinterpret_cast<const uint8_t*>(data)),
size(size),
offset(0),
index(bind(&WindowIndex::set_comparator, this, placeholders::_1, placeholders::_2)) {}
current_offset(0),
index(std::bind(&MapWindowIndex::set_comparator, this, std::placeholders::_1, std::placeholders::_2)) {}
void advance() {
if (this->offset >= WindowLength) {
this->index.erase(this->offset - WindowLength);
if (this->current_offset >= WindowLength) {
this->index.erase(this->current_offset - WindowLength);
}
this->index.emplace(this->offset);
this->offset++;
this->index.emplace(this->current_offset);
this->current_offset++;
}
size_t get_match_length(size_t match_offset) const {
size_t match_iter = match_offset;
size_t offset_iter = this->offset;
size_t offset_iter = this->current_offset;
while ((match_iter < match_offset + MaxMatchLength) &&
(match_iter < this->size) &&
(offset_iter < this->size) &&
@@ -63,16 +61,13 @@ 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 max_length = std::min<size_t>(MaxMatchLength, this->size - std::max<size_t>(a, b));
size_t end_a = a + max_length;
for (; a < end_a; a++, b++) {
uint8_t data_a = static_cast<uint8_t>(this->data[a]);
@@ -86,16 +81,14 @@ struct WindowIndex {
return a < b; // Maximum-length match; order them by offset
};
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
std::pair<size_t, size_t> 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
// default.
size_t match_offset = 0;
size_t match_size = 0;
auto it = this->index.upper_bound(this->offset);
auto it = this->index.upper_bound(this->current_offset);
if (it != this->index.end()) {
size_t new_match_offset = *it;
size_t new_match_size = this->get_match_length(new_match_offset);
@@ -113,19 +106,93 @@ struct WindowIndex {
match_size = new_match_size;
}
}
return make_pair(match_offset, match_size);
return std::make_pair(match_offset, match_size);
}
};
template <size_t WindowLength, size_t MaxMatchLength>
struct TreeWindowIndex {
// This class is the result of an experiment to see if a prefix tree is faster for optimal compression. It turns out
// it's not, even if the std::map in Node is replaced with a std::unordered_map or std::array. This structure is
// easier to understand than MapWindowIndex, but is about 6-7x slower on average.
const uint8_t* data;
size_t size;
size_t current_offset;
struct Node {
size_t start_offset = 0;
std::map<uint8_t, Node> children;
};
Node root;
TreeWindowIndex(const void* data, size_t size)
: data(reinterpret_cast<const uint8_t*>(data)), size(size), current_offset(0) {}
void advance() {
// Delete the oldest string, if the current offset has passed the initial window
if (this->current_offset >= WindowLength) {
size_t start_offset = this->current_offset - WindowLength;
size_t end_offset = std::min<size_t>(this->size, start_offset + MaxMatchLength);
Node* current = &this->root;
for (size_t offset = start_offset; offset < end_offset; offset++) {
auto child_it = current->children.find(this->data[offset]);
// The child should always be in the set - we should have added all of its nodes in a previous advance() call
if (child_it == current->children.end()) {
throw std::logic_error(std::format("Attempted to delete string at offset {:X} which was not in the set",
start_offset));
}
if (child_it->second.start_offset == start_offset) {
// If the child's start offset matches start_offset, then the rest of the nodes below it must also match
// start_offset (they were never again visited by the second part of this function after the first time they
// were added) so the entire subtree can be deleted. This means there are no other strings in the window that
// share the first (start_offset + 1) bytes with this string.
current->children.erase(child_it);
break;
} else {
// If the start offset does not match start_offset, then this node belongs to a later string; we need to
// check its subtree to see if anything should be deleted
current = &child_it->second;
}
}
}
// Create all nodes for the current string, or update their start_offsets if they already exist
size_t end_offset = std::min<size_t>(size, this->current_offset + MaxMatchLength);
Node* current = &this->root;
for (size_t offset = this->current_offset; offset < end_offset; offset++) {
current = &current->children[this->data[offset]];
current->start_offset = this->current_offset;
}
this->current_offset++;
}
std::pair<size_t, size_t> match() const {
size_t end_offset = std::min<size_t>(size, this->current_offset + MaxMatchLength);
const Node* current = &this->root;
size_t offset;
for (offset = this->current_offset; offset < end_offset; offset++) {
auto it = current->children.find(this->data[offset]);
if (it == current->children.end()) {
break;
} else {
current = &it->second;
}
}
return std::make_pair(current->start_offset, offset - this->current_offset);
}
};
template <size_t WindowSize, size_t MaxMatchLength>
using WindowIndex = MapWindowIndex<WindowSize, MaxMatchLength>;
struct LZSSInterleavedWriter {
phosg::StringWriter w;
size_t buf_offset;
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;
}
@@ -147,7 +214,7 @@ struct LZSSInterleavedWriter {
void write_control(bool v) {
if (this->next_control_bit == 0) {
throw logic_error("write_control called with no space to write");
throw std::logic_error("write_control called with no space to write");
}
if (v) {
this->buf[0] |= this->next_control_bit;
@@ -166,9 +233,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)) {
@@ -217,28 +282,28 @@ struct PRSPathNode {
size_t to_offset = 0;
};
string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
std::string prs_compress_optimal(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);
vector<PRSPathNode> nodes;
std::vector<PRSPathNode> nodes;
nodes.resize(in_size + 1);
nodes[0].bits_used = 18; // Stop command: 2 control bits and 2 data bytes
size_t copy_progress_max = 3 * in_size;
atomic<size_t> copy_progress = 0;
std::atomic<size_t> copy_progress = 0;
// Populate all possible short copies
std::thread short_window_thread([&]() -> void {
WindowIndex<0x100, 5> window(in_data_v, in_size);
while (window.offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) {
while (window.current_offset < in_size) {
if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
}
auto& node = nodes[window.offset];
auto match = window.get_best_match();
auto& node = nodes[window.current_offset];
auto match = window.match();
if (match.second >= 2) {
node.short_copy_offset = match.first - window.offset;
node.short_copy_offset = match.first - window.current_offset;
node.max_short_copy_size = match.second;
}
window.advance();
@@ -248,15 +313,15 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
// Populate all possible long copies
std::thread long_window_thread([&]() -> void {
WindowIndex<0x1FFF, 9> window(in_data_v, in_size);
while (window.offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) {
while (window.current_offset < in_size) {
if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
}
auto& node = nodes[window.offset];
auto match = window.get_best_match();
auto& node = nodes[window.current_offset];
auto match = window.match();
if (match.second >= 3) {
node.long_copy_offset = match.first - window.offset;
node.long_copy_offset = match.first - window.current_offset;
node.max_long_copy_size = match.second;
}
window.advance();
@@ -266,15 +331,15 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
// Populate all possible extended copies
std::thread extended_window_thread([&]() -> void {
WindowIndex<0x1FFF, 0x100> window(in_data_v, in_size);
while (window.offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) {
while (window.current_offset < in_size) {
if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
}
auto& node = nodes[window.offset];
auto match = window.get_best_match();
auto& node = nodes[window.current_offset];
auto match = window.match();
if (match.second >= 1) {
node.extended_copy_offset = match.first - window.offset;
node.extended_copy_offset = match.first - window.current_offset;
node.max_extended_copy_size = match.second;
}
window.advance();
@@ -285,8 +350,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);
@@ -371,14 +435,14 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
switch (next_node.from_command_type) {
case PRSPathNode::CommandType::LITERAL:
if (copy_size != 1) {
throw logic_error("incorrect size for LITERAL copy type");
throw std::logic_error("incorrect size for LITERAL copy type");
}
w.write_control(true);
w.write_data(in_data[offset]);
break;
case PRSPathNode::CommandType::SHORT_COPY: {
if (copy_size < 2 || copy_size > 5) {
throw logic_error("incorrect size for SHORT_COPY copy type");
throw std::logic_error("incorrect size for SHORT_COPY copy type");
}
uint8_t encoded_size = copy_size - 2;
w.write_control(false);
@@ -393,7 +457,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
}
case PRSPathNode::CommandType::LONG_COPY: {
if (copy_size < 2 || copy_size > 9) {
throw logic_error("incorrect size for LONG_COPY copy type");
throw std::logic_error("incorrect size for LONG_COPY copy type");
}
w.write_control(false);
w.flush_if_ready();
@@ -405,7 +469,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
}
case PRSPathNode::CommandType::EXTENDED_COPY: {
if (copy_size < 1 || copy_size > 0x100) {
throw logic_error("incorrect size for EXTENDED_COPY copy type");
throw std::logic_error("incorrect size for EXTENDED_COPY copy type");
}
w.write_control(false);
w.flush_if_ready();
@@ -417,7 +481,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
break;
}
default:
throw logic_error("invalid copy type in shortest path");
throw std::logic_error("invalid copy type in shortest path");
}
w.flush_if_ready();
@@ -434,23 +498,22 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
return std::move(w.close());
}
string prs_compress_optimal(const string& data, ProgressCallback progress_fn) {
std::string prs_compress_optimal(const std::string& data, ProgressCallback progress_fn) {
return prs_compress_optimal(data.data(), data.size(), progress_fn);
}
string prs_compress_pessimal(const void* vdata, size_t size) {
std::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++) {
auto match = window.get_best_match();
auto match = window.match();
if (match.second >= 1) {
// Write extended copy
int16_t offset = match.first - window.offset;
int16_t offset = match.first - window.current_offset;
w.write_control(false);
w.flush_if_ready();
w.write_control(true);
@@ -490,7 +553,7 @@ PRSCompressor::PRSCompressor(
void PRSCompressor::add(const void* data, size_t size) {
if (this->closed) {
throw logic_error("compressor is closed");
throw std::logic_error("compressor is closed");
}
phosg::StringReader r(data, size);
@@ -499,7 +562,7 @@ void PRSCompressor::add(const void* data, size_t size) {
}
}
void PRSCompressor::add(const string& data) {
void PRSCompressor::add(const std::string& data) {
this->add(data.data(), data.size());
}
@@ -539,9 +602,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 +620,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 +636,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)) {
@@ -587,7 +647,7 @@ void PRSCompressor::advance() {
this->advance_extended_copy(backreference_offset, best_match_size);
} else {
throw logic_error("invalid best match");
throw std::logic_error("invalid best match");
}
}
@@ -635,7 +695,7 @@ void PRSCompressor::advance_extended_copy(ssize_t offset, size_t size) {
this->move_forward_data_to_reverse_log(size);
}
string& PRSCompressor::close() {
std::string& PRSCompressor::close() {
if (!this->closed) {
// Advance until all input is consumed
while (this->reverse_log.end_offset() < this->input_bytes) {
@@ -655,14 +715,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,35 +729,26 @@ 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");
throw std::logic_error("data written without control bits");
}
this->output.str().resize(this->output.str().size() - 1);
}
}
string prs_compress(
const void* vdata,
size_t size,
ssize_t compression_level,
ProgressCallback progress_fn) {
std::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) {
std::string prs_compress(const std::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) {
std::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;
@@ -708,24 +757,21 @@ string prs_compress_indexed(
WindowIndex<0x1FFF, 0x100> w_extended(in_data_v, in_size);
size_t last_progress_fn_call_offset = 0;
while (w_short.offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (w_short.offset & ~0xFFF))) {
last_progress_fn_call_offset = w_short.offset;
progress_fn(CompressPhase::GENERATE_RESULT, w_short.offset, in_size, w.size());
while (w_short.current_offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (w_short.current_offset & ~0xFFF))) {
last_progress_fn_call_offset = w_short.current_offset;
progress_fn(CompressPhase::GENERATE_RESULT, w_short.current_offset, in_size, w.size());
}
auto m_short = w_short.get_best_match();
auto m_long = w_long.get_best_match();
auto m_extended = w_extended.get_best_match();
auto m_short = w_short.match();
auto m_long = w_long.match();
auto m_extended = w_extended.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;
@@ -765,11 +811,11 @@ string prs_compress_indexed(
switch (command_type) {
case PRSPathNode::CommandType::LITERAL:
w.write_control(true);
w.write_data(in_data[w_short.offset]);
w.write_data(in_data[w_short.current_offset]);
bytes_consumed = 1;
break;
case PRSPathNode::CommandType::SHORT_COPY: {
ssize_t backreference_offset = m_short.first - w_short.offset;
ssize_t backreference_offset = m_short.first - w_short.current_offset;
uint8_t encoded_size = m_short.second - 2;
w.write_control(false);
w.flush_if_ready();
@@ -783,7 +829,7 @@ string prs_compress_indexed(
break;
}
case PRSPathNode::CommandType::LONG_COPY: {
ssize_t backreference_offset = m_long.first - w_long.offset;
ssize_t backreference_offset = m_long.first - w_long.current_offset;
w.write_control(false);
w.flush_if_ready();
w.write_control(true);
@@ -794,7 +840,7 @@ string prs_compress_indexed(
break;
}
case PRSPathNode::CommandType::EXTENDED_COPY: {
ssize_t backreference_offset = m_extended.first - w_extended.offset;
ssize_t backreference_offset = m_extended.first - w_extended.current_offset;
w.write_control(false);
w.flush_if_ready();
w.write_control(true);
@@ -807,12 +853,12 @@ string prs_compress_indexed(
}
case PRSPathNode::CommandType::NONE:
default:
throw logic_error("invalid command type");
throw std::logic_error("invalid command type");
}
w.flush_if_ready();
if (bytes_consumed == 0) {
throw logic_error("no input data was consumed");
throw std::logic_error("no input data was consumed");
}
for (size_t z = 0; z < bytes_consumed; z++) {
@@ -832,47 +878,36 @@ string prs_compress_indexed(
return std::move(w.close());
}
string prs_compress_indexed(const string& data, ProgressCallback progress_fn) {
std::string prs_compress_indexed(const std::string& data, ProgressCallback progress_fn) {
return prs_compress_indexed(data.data(), data.size(), 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);
@@ -885,7 +920,7 @@ PRSDecompressResult prs_decompress_with_meta(
if (allow_unterminated) {
return {std::move(w.str()), r.where()};
} else {
throw runtime_error("maximum output size exceeded");
throw std::runtime_error("maximum output size exceeded");
}
}
w.put_u8(r.get_u8());
@@ -894,10 +929,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,34 +939,31 @@ 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");
throw std::runtime_error("backreference offset beyond beginning of output");
}
for (size_t z = 0; z < count; z++) {
if (max_output_size && w.size() == max_output_size) {
if (allow_unterminated) {
return {std::move(w.str()), r.where()};
} else {
throw out_of_range("maximum output size exceeded");
throw std::out_of_range("maximum output size exceeded");
}
}
w.put_u8(w.str()[read_offset + z]);
@@ -943,16 +974,16 @@ PRSDecompressResult prs_decompress_with_meta(
return {std::move(w.str()), r.where()};
}
PRSDecompressResult prs_decompress_with_meta(const string& data, size_t max_output_size, bool allow_unterminated) {
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size, bool allow_unterminated) {
return prs_decompress_with_meta(data.data(), data.size(), max_output_size, allow_unterminated);
}
string prs_decompress(const void* data, size_t size, size_t max_output_size, bool allow_unterminated) {
std::string prs_decompress(const void* data, size_t size, size_t max_output_size, bool allow_unterminated) {
auto ret = prs_decompress_with_meta(data, size, max_output_size, allow_unterminated);
return std::move(ret.data);
}
string prs_decompress(const string& data, size_t max_output_size, bool allow_unterminated) {
std::string prs_decompress(const std::string& data, size_t max_output_size, bool allow_unterminated) {
auto ret = prs_decompress_with_meta(data.data(), data.size(), max_output_size, allow_unterminated);
return std::move(ret.data);
}
@@ -988,7 +1019,7 @@ size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size
size_t read_offset = ret + offset;
if (read_offset >= ret) {
throw runtime_error("backreference offset beyond beginning of output");
throw std::runtime_error("backreference offset beyond beginning of output");
}
ret += count;
}
@@ -997,7 +1028,7 @@ size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size
if (allow_unterminated) {
return max_output_size;
} else {
throw out_of_range("maximum output size exceeded");
throw std::out_of_range("maximum output size exceeded");
}
}
}
@@ -1005,7 +1036,7 @@ size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size
return ret;
}
size_t prs_decompress_size(const string& data, size_t max_output_size, bool allow_unterminated) {
size_t prs_decompress_size(const std::string& data, size_t max_output_size, bool allow_unterminated) {
return prs_decompress_size(data.data(), data.size(), max_output_size, allow_unterminated);
}
@@ -1058,7 +1089,7 @@ void prs_disassemble(FILE* stream, const void* data, size_t size) {
}
if (read_offset >= output_bytes) {
throw runtime_error("backreference offset beyond beginning of output");
throw std::runtime_error("backreference offset beyond beginning of output");
}
output_bytes += count;
}
@@ -1069,11 +1100,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;
@@ -1087,23 +1117,22 @@ struct BC0PathNode {
size_t to_offset = 0;
};
string bc0_compress_optimal(
const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
std::string bc0_compress_optimal(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);
vector<BC0PathNode> nodes;
std::vector<BC0PathNode> nodes;
nodes.resize(in_size + 1);
nodes[0].bits_used = 0;
// Populate all possible backreferences
{
WindowIndex<0x1000, 0x12> window(in_data_v, in_size);
while (window.offset < in_size) {
if ((window.offset & 0xFFF) == 0 && progress_fn) {
progress_fn(CompressPhase::INDEX, window.offset, in_size, 0);
while (window.current_offset < in_size) {
if ((window.current_offset & 0xFFF) == 0 && progress_fn) {
progress_fn(CompressPhase::INDEX, window.current_offset, in_size, 0);
}
auto& node = nodes[window.offset];
auto match = window.get_best_match();
auto& node = nodes[window.current_offset];
auto match = window.match();
if (match.second >= 3) {
node.memo_offset = (match.first - 0x12) & 0xFFF;
node.max_copy_size = match.second;
@@ -1112,8 +1141,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);
@@ -1185,24 +1213,24 @@ string bc0_compress_optimal(
return std::move(w.close());
}
string bc0_compress(const string& data, ProgressCallback progress_fn) {
std::string bc0_compress(const std::string& data, ProgressCallback progress_fn) {
return bc0_compress(data.data(), data.size(), progress_fn);
}
string bc0_compress(const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
std::string bc0_compress(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;
WindowIndex<0x1000, 0x12> window(in_data_v, in_size);
size_t last_progress_fn_call_offset = 0;
while (window.offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (window.offset & ~0xFFF))) {
last_progress_fn_call_offset = window.offset;
progress_fn(CompressPhase::GENERATE_RESULT, window.offset, in_size, w.size());
while (window.current_offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (window.current_offset & ~0xFFF))) {
last_progress_fn_call_offset = window.current_offset;
progress_fn(CompressPhase::GENERATE_RESULT, window.current_offset, in_size, w.size());
}
auto match = window.get_best_match();
auto match = window.match();
// Write a backreference if a match was found; otherwise, write a literal
if (match.second >= 3) {
@@ -1212,7 +1240,7 @@ string bc0_compress(const void* in_data_v, size_t in_size, ProgressCallback prog
w.write_data(((memo_offset >> 4) & 0xF0) | (match.second - 3));
} else {
w.write_control(true);
w.write_data(in_data[window.offset]);
w.write_data(in_data[window.current_offset]);
match.second = 1;
}
w.flush_if_ready();
@@ -1225,7 +1253,7 @@ string bc0_compress(const void* in_data_v, size_t in_size, ProgressCallback prog
return std::move(w.close());
}
string bc0_encode(const void* in_data_v, size_t in_size) {
std::string bc0_encode(const void* in_data_v, size_t in_size) {
const uint8_t* in_data = reinterpret_cast<const uint8_t*>(in_data_v);
LZSSInterleavedWriter w;
@@ -1238,36 +1266,30 @@ 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) {
std::string bc0_decompress(const std::string& data) {
return bc0_decompress(data.data(), data.size());
}
string bc0_decompress(const void* data, size_t size) {
std::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 +1304,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 +1326,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;
@@ -1317,7 +1338,7 @@ string bc0_decompress(const void* data, size_t size) {
return std::move(w.str());
}
void bc0_disassemble(FILE* stream, const string& data) {
void bc0_disassemble(FILE* stream, const std::string& data) {
bc0_disassemble(stream, data.data(), data.size());
}
+35 -58
View File
@@ -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.
+749 -1132
View File
File diff suppressed because it is too large Load Diff
+8 -12
View File
@@ -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;
+11 -14
View File
@@ -14,10 +14,7 @@
#include "NetworkAddresses.hh"
#include "ServerState.hh"
using namespace std;
DNSServer::DNSServer(shared_ptr<ServerState> state)
: state(state) {}
DNSServer::DNSServer(std::shared_ptr<ServerState> state) : state(state) {}
void DNSServer::listen(const std::string& addr, int port) {
if (port == 0) {
@@ -25,15 +22,15 @@ void DNSServer::listen(const std::string& addr, int port) {
}
asio::ip::address asio_addr = addr.empty() ? asio::ip::address_v4::any() : asio::ip::make_address(addr);
asio::ip::udp::endpoint endpoint(asio_addr, port);
auto sock = make_shared<asio::ip::udp::socket>(*this->state->io_context, endpoint);
auto sock = std::make_shared<asio::ip::udp::socket>(*this->state->io_context, endpoint);
this->sockets.emplace(sock);
asio::co_spawn(*this->state->io_context, this->dns_server_task(sock), asio::detached);
}
string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
std::string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
if (size < 0x0C) {
throw invalid_argument("query too small");
throw std::invalid_argument("query too small");
}
const char* data = reinterpret_cast<const char*>(vdata);
@@ -41,7 +38,7 @@ string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t re
phosg::be_uint32_t be_resolved_address = resolved_address;
string response;
std::string response;
response.append(data, 2);
response.append("\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00", 10);
response.append(&data[12], name_len);
@@ -50,13 +47,13 @@ string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t re
return response;
}
string DNSServer::response_for_query(const string& query, uint32_t resolved_address) {
std::string DNSServer::response_for_query(const std::string& query, uint32_t resolved_address) {
return DNSServer::response_for_query(query.data(), query.size(), resolved_address);
}
asio::awaitable<void> DNSServer::dns_server_task(std::shared_ptr<asio::ip::udp::socket> sock) {
for (;;) {
string input(2048, 0);
std::string input(2048, 0);
asio::ip::udp::endpoint sender_ep;
size_t bytes = co_await sock->async_receive_from(asio::buffer(input), sender_ep, asio::use_awaitable);
uint32_t sender_addr = ipv4_addr_for_asio_addr(sender_ep.address());
@@ -64,12 +61,12 @@ asio::awaitable<void> DNSServer::dns_server_task(std::shared_ptr<asio::ip::udp::
if (bytes < 0x0C) {
dns_server_log.warning_f("input query too small");
phosg::print_data(stderr, input.data(), bytes);
} else if (!this->state->banned_ipv4_ranges->check(sender_addr)) {
} else if (!this->state->data->banned_ipv4_ranges->check(sender_addr)) {
input.resize(bytes);
uint32_t connect_address = is_local_address(sender_addr)
? this->state->local_address
: this->state->external_address;
string response = this->response_for_query(input, connect_address);
? this->state->data->local_address
: this->state->data->external_address;
std::string response = this->response_for_query(input, connect_address);
co_await sock->async_send_to(asio::buffer(response.data(), response.size()), sender_ep, asio::use_awaitable);
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
#include "IPV4RangeSet.hh"
struct ServerState;
class ServerState;
class DNSServer {
public:
+95
View File
@@ -0,0 +1,95 @@
#include "DOLFileIndex.hh"
#include <stdio.h>
#include <string.h>
#include <filesystem>
#include <phosg/Filesystem.hh>
#include <phosg/Hash.hh>
#include <phosg/Time.hh>
#include <stdexcept>
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/SH4Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#include "CommandFormats.hh"
#include "CommonFileFormats.hh"
#include "Compression.hh"
#include "Loggers.hh"
DOLFileIndex::DOLFileIndex(const std::string& directory) {
if (!std::filesystem::is_directory(directory)) {
client_functions_log.info_f("DOL file directory is missing");
return;
}
auto menu = std::make_shared<Menu>(MenuID::PROGRAMS, "Programs");
this->menu = menu;
menu->items.emplace_back(ProgramsMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
std::vector<std::string> filenames;
for (const auto& item : std::filesystem::directory_iterator(directory)) {
filenames.emplace_back(item.path().filename().string());
}
std::sort(filenames.begin(), filenames.end());
uint32_t next_menu_item_id = 0;
for (const auto& filename : filenames) {
bool is_dol = filename.ends_with(".dol");
bool is_compressed_dol = filename.ends_with(".dol.prs");
if (!is_dol && !is_compressed_dol) {
continue;
}
std::string name = filename.substr(0, filename.size() - (is_compressed_dol ? 8 : 4));
try {
auto dol = std::make_shared<File>();
dol->menu_item_id = next_menu_item_id++;
dol->name = name;
std::string path = directory + "/" + filename;
std::string file_data = phosg::load_file(path);
std::string description;
if (is_compressed_dol) {
size_t decompressed_size = prs_decompress_size(file_data);
phosg::StringWriter w;
w.put_u32b(file_data.size());
w.put_u32b(decompressed_size);
w.write(file_data);
while (w.size() & 3) {
w.put_u8(0);
}
dol->data = std::move(w.str());
std::string compressed_size_str = phosg::format_size(file_data.size());
std::string decompressed_size_str = phosg::format_size(decompressed_size);
client_functions_log.debug_f("Loaded compressed DOL file {} ({} -> {})",
dol->name, compressed_size_str, decompressed_size_str);
description = std::format("$C6{}$C7\n{}\n{} (orig)", dol->name, compressed_size_str, decompressed_size_str);
} else {
phosg::StringWriter w;
w.put_u32b(0);
w.put_u32b(file_data.size());
w.write(file_data);
while (w.size() & 3) {
w.put_u8(0);
}
dol->data = std::move(w.str());
std::string size_str = phosg::format_size(dol->data.size());
client_functions_log.debug_f("Loaded DOL file {} ({})", filename, size_str);
description = std::format("$C6{}$C7\n{}", dol->name, size_str);
}
this->item_id_to_file.emplace_back(dol);
menu->items.emplace_back(dol->menu_item_id, dol->name, description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
} catch (const std::exception& e) {
client_functions_log.warning_f("Failed to load DOL file {}: {}", filename, e.what());
}
}
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <inttypes.h>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "Menu.hh"
struct DOLFileIndex {
struct File {
uint32_t menu_item_id;
std::string name;
std::string data;
bool is_compressed;
};
std::vector<std::shared_ptr<File>> item_id_to_file;
std::shared_ptr<const Menu> menu;
DOLFileIndex() = default;
explicit DOLFileIndex(const std::string& directory);
inline bool empty() const {
return this->item_id_to_file.empty();
}
};
+2063
View File
File diff suppressed because it is too large Load Diff
+421
View File
@@ -0,0 +1,421 @@
#pragma once
#include <atomic>
#include <map>
#include <memory>
#include <phosg/JSON.hh>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "Account.hh"
#include "Client.hh"
#include "ClientFunctionIndex.hh"
#include "CommonItemSet.hh"
#include "DNSServer.hh"
#include "DOLFileIndex.hh"
#include "Episode3/DataIndexes.hh"
#include "Episode3/Tournament.hh"
#include "GSLArchive.hh"
#include "IPV4RangeSet.hh"
#include "ItemNameIndex.hh"
#include "ItemParameterTable.hh"
#include "ItemTranslationTable.hh"
#include "LevelTable.hh"
#include "Lobby.hh"
#include "MagMetadataTable.hh"
#include "Menu.hh"
#include "Quest.hh"
#include "ShopRandomSets.hh"
#include "TeamIndex.hh"
#include "TekkerAdjustmentSet.hh"
#include "WordSelectTable.hh"
struct DataIndex {
// This structure contains everything which is essentially immutable during the server's uptime - e.g. configuration,
// tables, item definitions, etc. which are only changed by reloading them from disk. Mutable structures, like
// AccountIndex and TeamIndex, are on ServerState instead.
struct PortConfiguration {
std::string name;
std::string addr; // Blank = listen on all interfaces (default)
uint16_t port;
Version version;
ServerBehavior behavior;
};
struct CheatFlags {
// This structure describes which behaviors are considered cheating (that is, require cheat mode to be enabled or the
// user to have the CHEAT_ANYWHERE account flag). A false value here means that that particular behavior is NOT
// cheating, so cheat mode is NOT required.
bool create_items = true;
bool edit_section_id = true;
bool edit_stats = true;
bool ep3_replace_assist = true;
bool ep3_unset_field_character = true;
bool infinite_hp_tp = true;
bool fast_kills = true;
bool insufficient_minimum_level = true;
bool override_random_seed = true;
bool override_section_id = true;
bool override_variations = true;
bool proxy_override_drops = true;
bool reset_materials = false;
bool warp = true;
CheatFlags() = default;
explicit CheatFlags(const phosg::JSON& json);
};
struct BBStreamFile {
struct Entry {
uint32_t offset;
uint32_t size;
uint32_t checksum; // crc32
std::string filename;
};
std::vector<Entry> entries;
std::string data;
};
enum class RunShellBehavior {
DEFAULT = 0,
ALWAYS,
NEVER,
};
enum class BehaviorSwitch {
OFF = 0,
OFF_BY_DEFAULT,
ON_BY_DEFAULT,
ON,
};
static inline bool behavior_enabled(BehaviorSwitch b) {
return (b == BehaviorSwitch::ON_BY_DEFAULT) || (b == BehaviorSwitch::ON);
}
static inline bool behavior_can_be_overridden(BehaviorSwitch b) {
return (b == BehaviorSwitch::OFF_BY_DEFAULT) || (b == BehaviorSwitch::ON_BY_DEFAULT);
}
uint64_t creation_time;
std::string config_filename;
std::shared_ptr<const phosg::JSON> config_json;
bool one_time_config_loaded = false;
size_t num_worker_threads = 0;
std::string name;
std::unordered_map<std::string, PortConfiguration> name_to_port_config;
std::unordered_map<uint16_t, PortConfiguration> number_to_port_config;
std::unordered_map<uint16_t, uint16_t> ip_stack_port_remap;
std::string username;
std::string dns_server_addr;
uint16_t dns_server_port = 0;
std::vector<std::string> ip_stack_addresses;
std::vector<std::string> ppp_stack_addresses;
std::vector<std::string> ppp_raw_addresses;
std::vector<std::string> http_addresses;
uint64_t client_ping_interval_usecs = 30000000;
uint64_t client_idle_timeout_usecs = 60000000;
uint64_t patch_client_idle_timeout_usecs = 300000000;
uint64_t psopeeps_dcv2_exp_multiplier = 5;
bool is_debug = false;
bool ip_stack_debug = false;
bool allow_unregistered_users = false;
bool allow_pc_nte = false;
bool use_temp_accounts_for_prototypes = true;
bool allow_same_account_concurrent_logins = true;
bool allow_same_account_concurrent_logins_across_client_sources = false;
std::array<uint16_t, NUM_VERSIONS> compatibility_groups = {};
bool enable_chat_commands = true;
char chat_command_sentinel = '\0'; // 0 = default (@ on 11/2000; $ on all other versions)
size_t num_backup_character_slots = 16;
std::unique_ptr<std::array<uint32_t, NUM_NON_PATCH_VERSIONS>> version_name_colors;
uint32_t client_customization_name_color = 0x00000000;
uint8_t allowed_drop_modes_v1_v2_normal = 0x1F;
uint8_t allowed_drop_modes_v1_v2_battle = 0x07;
uint8_t allowed_drop_modes_v1_v2_challenge = 0x07;
uint8_t allowed_drop_modes_v3_normal = 0x1F;
uint8_t allowed_drop_modes_v3_battle = 0x07;
uint8_t allowed_drop_modes_v3_challenge = 0x07;
uint8_t allowed_drop_modes_v4_normal = 0x1D; // CLIENT not allowed
uint8_t allowed_drop_modes_v4_battle = 0x05;
uint8_t allowed_drop_modes_v4_challenge = 0x05;
ServerDropMode default_drop_mode_v1_v2_normal = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v1_v2_battle = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v1_v2_challenge = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v3_normal = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v3_battle = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v3_challenge = ServerDropMode::CLIENT;
ServerDropMode default_drop_mode_v4_normal = ServerDropMode::SERVER_SHARED;
ServerDropMode default_drop_mode_v4_battle = ServerDropMode::SERVER_SHARED;
ServerDropMode default_drop_mode_v4_challenge = ServerDropMode::SERVER_SHARED;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v1_v2;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v3;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v4;
std::unordered_map<std::string, std::pair<uint8_t, uint32_t>> quest_counter_fields; // For $qfread command
uint64_t persistent_game_idle_timeout_usecs = 0;
std::unordered_map<uint32_t, int64_t> enable_send_function_call_quest_numbers;
bool enable_v3_v4_protected_subcommands = false;
bool ep3_infinite_meseta = false;
std::vector<uint32_t> ep3_defeat_player_meseta_rewards = {400, 500, 600, 700, 800};
std::vector<uint32_t> ep3_defeat_com_meseta_rewards = {100, 200, 300, 400, 500};
uint32_t ep3_final_round_meseta_bonus = 300;
bool ep3_jukebox_is_free = false;
uint32_t ep3_behavior_flags = 0;
bool hide_download_commands = true;
bool censor_credentials = true;
RunShellBehavior run_shell_behavior = RunShellBehavior::DEFAULT;
BehaviorSwitch cheat_mode_behavior = BehaviorSwitch::OFF_BY_DEFAULT;
bool default_switch_assist_enabled = false;
bool use_game_creator_section_id = false;
bool enable_bb_ship_selection_menu = false;
bool enable_brutal_peeps_mode = false;
bool enable_hardcore_mode = false;
bool enable_test_mode = false;
bool rare_notifs_enabled_for_client_drops = false;
bool default_rare_notifs_enabled_v1_v2 = false;
bool default_rare_notifs_enabled_v3_v4 = false;
std::unordered_set<uint32_t> notify_game_for_item_primary_identifiers_v1_v2;
std::unordered_set<uint32_t> notify_game_for_item_primary_identifiers_v3;
std::unordered_set<uint32_t> notify_game_for_item_primary_identifiers_v4;
std::unordered_set<uint32_t> notify_server_for_item_primary_identifiers_v1_v2;
std::unordered_set<uint32_t> notify_server_for_item_primary_identifiers_v3;
std::unordered_set<uint32_t> notify_server_for_item_primary_identifiers_v4;
bool notify_server_for_max_level_achieved = false;
std::vector<std::shared_ptr<const PSOBBEncryption::KeyFile>> bb_private_keys;
std::shared_ptr<const parray<uint8_t, 0x16C>> bb_default_keyboard_config;
std::shared_ptr<const parray<uint8_t, 0x38>> bb_default_joystick_config;
std::shared_ptr<const ClientFunctionIndex> client_functions;
std::shared_ptr<const PatchFileIndex> pc_patch_file_index;
std::shared_ptr<const PatchFileIndex> bb_patch_file_index;
std::unordered_map<uint64_t, std::shared_ptr<const MapFile>> map_file_for_source_hash;
std::map<uint32_t, std::array<std::shared_ptr<const MapFile>, NUM_VERSIONS>> map_files_for_free_play_key;
std::unordered_map<uint64_t, std::shared_ptr<const SuperMap>> supermap_for_source_hash_sum;
std::unordered_map<uint32_t, std::shared_ptr<const SuperMap>> supermap_for_free_play_key;
std::shared_ptr<const RoomLayoutIndex> room_layout_index;
std::shared_ptr<const BBStreamFile> bb_stream_file;
std::shared_ptr<const DOLFileIndex> dol_file_index;
std::shared_ptr<const Episode3::CardIndex> ep3_card_index;
std::shared_ptr<const Episode3::CardIndex> ep3_card_index_trial;
std::shared_ptr<const Episode3::MapIndex> ep3_map_index;
std::shared_ptr<const Episode3::COMDeckIndex> ep3_com_deck_index;
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_default_ex_values;
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_tournament_ex_values;
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_tournament_final_round_ex_values;
std::shared_ptr<const QuestCategoryIndex> quest_category_index;
std::shared_ptr<const QuestIndex> quest_index;
std::shared_ptr<const LevelTable> level_table_v1_v2;
std::shared_ptr<const LevelTable> level_table_v3;
std::shared_ptr<const LevelTable> level_table_v4;
std::shared_ptr<const BattleParamsIndex> battle_params;
std::shared_ptr<const GSLArchive> bb_data_gsl;
std::unordered_map<std::string, std::shared_ptr<const CommonItemSet>> common_item_sets;
std::unordered_map<std::string, std::shared_ptr<const RareItemSet>> rare_item_sets;
std::shared_ptr<const ArmorShopRandomSet> armor_random_set;
std::shared_ptr<const ToolShopRandomSet> tool_random_set;
std::array<std::shared_ptr<const WeaponShopRandomSet>, 4> weapon_random_sets; // Keyed on difficulty
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set;
std::array<std::shared_ptr<const ItemParameterTable>, NUM_VERSIONS> item_parameter_tables;
std::shared_ptr<const ItemTranslationTable> item_translation_table;
std::array<std::shared_ptr<const ItemData::StackLimits>, NUM_VERSIONS> item_stack_limits_tables;
size_t bb_max_bank_items = 200;
size_t bb_max_bank_meseta = 999999;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_dc_nte;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_dc_11_2000;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_v1;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_v2;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_v3;
std::shared_ptr<const MagMetadataTable> mag_metadata_table_v4;
std::shared_ptr<const TextIndex> text_index;
std::array<std::shared_ptr<const ItemNameIndex>, NUM_VERSIONS> item_name_indexes;
std::shared_ptr<const WordSelectTable> word_select_table;
std::array<std::shared_ptr<const SetDataTableBase>, NUM_VERSIONS> set_data_tables;
std::array<std::shared_ptr<const SetDataTableBase>, NUM_VERSIONS> set_data_tables_ep1_ult;
std::shared_ptr<const SetDataTableBase> bb_solo_set_data_table;
std::shared_ptr<const SetDataTableBase> bb_solo_set_data_table_ep1_ult;
std::array<std::shared_ptr<const MapState::RareEnemyRates>, 4> rare_enemy_rates_by_difficulty;
std::shared_ptr<const MapState::RareEnemyRates> rare_enemy_rates_challenge;
std::array<std::array<size_t, 4>, 3> min_levels_v1_v2; // Indexed as [episode][difficulty]
std::array<std::array<size_t, 4>, 3> min_levels_v3; // Indexed as [episode][difficulty]
std::array<std::array<size_t, 4>, 3> min_levels_v4; // Indexed as [episode][difficulty]
std::unordered_set<std::string> bb_required_patches;
std::unordered_set<std::string> auto_patches;
CheatFlags cheat_flags;
struct QuestF960Result {
uint32_t meseta_cost = 0;
uint32_t base_probability = 0;
uint32_t probability_upgrade = 0;
std::array<std::vector<ItemData>, 7> results;
QuestF960Result() = default;
QuestF960Result(
const phosg::JSON& json, std::shared_ptr<const ItemNameIndex> name_index, const ItemData::StackLimits& limits);
};
// Indexed as [type][difficulty][random_choice]
std::vector<std::vector<std::vector<ItemData>>> quest_F95E_results;
std::vector<std::pair<size_t, ItemData>> quest_F95F_results; // [(num_photon_tickets, item)]
std::vector<QuestF960Result> quest_F960_success_results;
QuestF960Result quest_F960_failure_results;
float bb_global_exp_multiplier = 1.0f;
int64_t dc_v2_exp_multiplier = 1;
int64_t gc_v3_exp_multiplier = 1;
float exp_share_multiplier = 0.5f;
float server_global_drop_rate_multiplier = 1.0f;
uint16_t ep3_card_auction_points = 0;
uint16_t ep3_card_auction_min_size = 0;
uint16_t ep3_card_auction_max_size = 0;
struct CardAuctionPoolEntry {
uint64_t probability;
uint16_t card_id;
uint16_t min_price;
};
std::vector<CardAuctionPoolEntry> ep3_card_auction_pool;
std::array<std::vector<uint16_t>, 5> ep3_trap_card_ids;
struct Ep3LobbyBannerEntry {
uint32_t type = 1;
uint32_t which; // See B9 documentation in CommandFormats.hh
std::string data;
};
std::vector<Ep3LobbyBannerEntry> ep3_lobby_banners;
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
phosg::JSON team_reward_defs_json;
std::shared_ptr<const Menu> information_menu_v2;
std::shared_ptr<const Menu> information_menu_v3;
std::shared_ptr<const std::vector<std::string>> information_contents_v2;
std::shared_ptr<const std::vector<std::string>> information_contents_v3;
std::shared_ptr<const Menu> proxy_destinations_menu_dc;
std::shared_ptr<const Menu> proxy_destinations_menu_pc;
std::shared_ptr<const Menu> proxy_destinations_menu_gc;
std::shared_ptr<const Menu> proxy_destinations_menu_xb;
std::vector<std::pair<std::string, uint16_t>> proxy_destinations_dc;
std::vector<std::pair<std::string, uint16_t>> proxy_destinations_pc;
std::vector<std::pair<std::string, uint16_t>> proxy_destinations_gc;
std::vector<std::pair<std::string, uint16_t>> proxy_destinations_xb;
std::optional<std::pair<std::string, uint16_t>> proxy_destination_patch;
std::optional<std::pair<std::string, uint16_t>> proxy_destination_bb;
std::string welcome_message;
std::string pc_patch_server_message;
std::string bb_patch_server_message;
std::array<std::vector<uint32_t>, NUM_VERSIONS> public_lobby_search_orders;
std::vector<uint32_t> client_customization_public_lobby_search_order;
uint8_t pre_lobby_event = 0;
std::vector<uint8_t> per_lobby_events;
int32_t ep3_menu_song = -1;
std::map<std::string, uint32_t> all_addresses;
uint32_t local_address = 0;
uint32_t external_address = 0;
bool proxy_allow_save_files = true;
explicit DataIndex(const std::string& config_filename = "");
uint32_t connect_address_for_client(std::shared_ptr<Client> c) const;
uint16_t game_server_port_for_version(Version v) const;
std::shared_ptr<const Menu> information_menu(Version version) const;
std::shared_ptr<const Menu> proxy_destinations_menu(Version version) const;
const std::vector<std::pair<std::string, uint16_t>>& proxy_destinations(Version version) const;
std::shared_ptr<const SetDataTableBase> set_data_table(
Version version, Episode episode, GameMode mode, Difficulty difficulty) const;
inline std::shared_ptr<const WeaponShopRandomSet> weapon_random_set(Difficulty difficulty) const {
return this->weapon_random_sets.at(static_cast<size_t>(difficulty));
}
inline std::shared_ptr<const MapState::RareEnemyRates> rare_enemy_rates(Difficulty difficulty) const {
return this->rare_enemy_rates_by_difficulty.at(static_cast<size_t>(difficulty));
}
std::shared_ptr<const LevelTable> level_table(Version version) const;
std::shared_ptr<const ItemParameterTable> item_parameter_table(Version version) const;
std::shared_ptr<const ItemParameterTable> item_parameter_table_for_encode(Version version) const;
std::shared_ptr<const MagMetadataTable> mag_metadata_table(Version version) const;
std::shared_ptr<const ItemData::StackLimits> item_stack_limits(Version version) const;
std::shared_ptr<const ItemNameIndex> item_name_index_opt(Version version) const; // Returns null if missing
std::shared_ptr<const ItemNameIndex> item_name_index(Version version) const; // Throws if missing
std::string describe_item(Version version, const ItemData& item, uint8_t flags = 0) const;
ItemData parse_item_description(Version version, const std::string& description) const;
std::shared_ptr<const CommonItemSet> common_item_set(Version logic_version, std::shared_ptr<const Quest> q) const;
std::shared_ptr<const RareItemSet> rare_item_set(Version logic_version, std::shared_ptr<const Quest> q) const;
const std::vector<uint32_t>& public_lobby_search_order(Version version, bool is_client_customization) const;
inline const std::vector<uint32_t>& public_lobby_search_order(std::shared_ptr<const Client> c) const {
return this->public_lobby_search_order(c->version(), c->check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION));
}
inline uint32_t name_color_for_client(Version v, bool is_client_customization) const {
if (is_client_customization && this->client_customization_name_color) {
return this->client_customization_name_color;
}
return this->version_name_colors ? this->version_name_colors->at(static_cast<size_t>(v) - NUM_PATCH_VERSIONS) : 0;
}
inline uint32_t name_color_for_client(std::shared_ptr<const Client> c) const {
return this->name_color_for_client(c->version(), c->check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION));
}
std::shared_ptr<const std::vector<std::string>> information_contents_for_client(std::shared_ptr<const Client> c) const;
size_t default_min_level_for_game(Version version, Episode episode, Difficulty difficulty) const;
void set_port_configuration(const std::vector<PortConfiguration>& port_configs);
std::shared_ptr<const std::string> load_bb_file(const std::string& patch_index_filename) const;
std::shared_ptr<const std::string> load_map_file(Version version, const std::string& filename) const;
std::pair<std::string, uint16_t> parse_port_spec(const phosg::JSON& json) const;
std::vector<PortConfiguration> parse_port_configuration(const phosg::JSON& json) const;
static constexpr uint32_t free_play_key(
Episode episode, GameMode mode, Difficulty difficulty, uint8_t floor, uint32_t layout, uint32_t entities) {
return (static_cast<uint32_t>(episode) << 28) |
(static_cast<uint32_t>(mode) << 26) |
(static_cast<uint32_t>(difficulty) << 24) |
(static_cast<uint32_t>(floor) << 16) |
(static_cast<uint32_t>(layout) << 8) |
(static_cast<uint32_t>(entities) << 0);
}
std::shared_ptr<const SuperMap> get_free_play_supermap(
Episode episode, GameMode mode, Difficulty difficulty, uint8_t floor, uint32_t layout, uint32_t entities);
std::vector<std::shared_ptr<const SuperMap>> supermaps_for_variations(
Episode episode, GameMode mode, Difficulty difficulty, const Variations& variations);
void collect_network_addresses();
void load_config_early();
void load_config_late();
void load_bb_private_keys();
void load_bb_system_defaults();
void load_patch_indexes();
void load_maps();
void load_battle_params();
void load_level_tables();
void load_text_index();
std::shared_ptr<ItemNameIndex> create_item_name_index_for_version(
std::shared_ptr<const ItemParameterTable> pmt,
std::shared_ptr<const ItemData::StackLimits> limits,
std::shared_ptr<const TextIndex> text_index) const;
void load_item_name_indexes();
void load_drop_tables();
void load_item_definitions();
void load_set_data_tables();
void load_word_select_table();
void load_ep3_cards();
void load_ep3_maps(bool raise_on_any_failure = false);
void load_quest_index(bool raise_on_any_failure = false);
void compile_functions(bool raise_on_any_failure = false);
void load_dol_files();
void generate_bb_stream_file();
void load_all();
};
+66 -66
View File
@@ -22,12 +22,10 @@
#include "ReceiveSubcommands.hh"
#include "SendCommands.hh"
using namespace std;
static string random_name() {
string ret;
static std::string random_name() {
std::string ret;
size_t length = (phosg::random_object<size_t>() % 12) + 4;
static const string alphabet = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-+<>:\"\',.";
static const std::string alphabet = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-+<>:\"\',.";
while (ret.size() < length) {
ret.push_back(alphabet[phosg::random_object<size_t>() % alphabet.size()]);
}
@@ -40,7 +38,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,
@@ -87,40 +85,40 @@ DownloadSession::DownloadSession(
case Version::DC_V1:
case Version::DC_V2:
if (this->serial_number2 == 0 || this->serial_number == 0 || this->access_key.empty()) {
throw runtime_error("missing credentials");
throw std::runtime_error("missing credentials");
}
break;
case Version::PC_V2:
if (this->serial_number == 0 || this->access_key.empty()) {
throw runtime_error("missing credentials");
throw std::runtime_error("missing credentials");
}
break;
case Version::GC_V3:
if (this->serial_number == 0 || this->access_key.empty() || this->password.empty()) {
throw runtime_error("missing credentials");
throw std::runtime_error("missing credentials");
}
break;
case Version::XB_V3:
if (this->xb_gamertag.empty() || this->xb_user_id == 0 || this->xb_account_id == 0) {
throw runtime_error("missing credentials");
throw std::runtime_error("missing credentials");
}
break;
case Version::BB_V4:
if (this->username.empty() || this->password.empty()) {
throw runtime_error("missing credentials");
throw std::runtime_error("missing credentials");
}
break;
default:
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
this->character->inventory.language = language;
}
asio::awaitable<void> DownloadSession::run() {
string netloc_str = std::format("{}:{}", this->remote_host, this->remote_port);
std::string netloc_str = std::format("{}:{}", this->remote_host, this->remote_port);
this->log.info_f("Connecting to {}", netloc_str);
auto sock = make_unique<asio::ip::tcp::socket>(co_await async_connect_tcp(this->remote_host, this->remote_port));
auto sock = std::make_unique<asio::ip::tcp::socket>(co_await async_connect_tcp(this->remote_host, this->remote_port));
this->channel = SocketChannel::create(
this->io_context,
std::move(sock),
@@ -128,7 +126,9 @@ asio::awaitable<void> DownloadSession::run() {
this->language,
netloc_str,
this->show_command_data ? phosg::TerminalFormat::FG_GREEN : phosg::TerminalFormat::END,
this->show_command_data ? phosg::TerminalFormat::FG_YELLOW : phosg::TerminalFormat::END);
this->show_command_data ? phosg::TerminalFormat::FG_YELLOW : phosg::TerminalFormat::END,
false,
false);
this->log.info_f("Server channel connected");
while (this->channel->connected()) {
@@ -149,7 +149,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
ret.serial_number.encode(std::format("{:08X}", this->serial_number));
ret.access_key.encode(this->access_key);
ret.serial_number2.encode(std::format("{:08X}", this->serial_number2));
ret.login_character_name.encode(this->character->disp.name.decode());
ret.login_character_name.encode(this->character->disp.visual.name.decode());
this->channel->send(0x93, 0x01, &ret, extended ? sizeof(ret) : sizeof(C_LoginV1_DC_93));
} else if (is_v2(this->version)) {
@@ -164,7 +164,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
ret.access_key.encode(this->access_key);
ret.serial_number2 = ret.serial_number;
ret.access_key2 = ret.access_key;
ret.login_character_name.encode(this->character->disp.name.decode());
ret.login_character_name.encode(this->character->disp.visual.name.decode());
size_t data_size = extended
? ((this->version == Version::PC_V2) ? sizeof(ret) : sizeof(C_LoginExtended_DC_GC_9D))
: sizeof(C_Login_DC_PC_GC_9D);
@@ -182,7 +182,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
ret.access_key.encode(this->access_key);
ret.serial_number2 = ret.serial_number;
ret.access_key2 = ret.access_key;
ret.login_character_name.encode(this->character->disp.name.decode());
ret.login_character_name.encode(this->character->disp.visual.name.decode());
ret.client_config = this->client_config;
this->channel->send(0x9E, 0x01, &ret, extended ? sizeof(ret) : sizeof(C_Login_PC_GC_9E));
@@ -198,7 +198,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
ret.access_key.encode(std::format("{:016X}", this->xb_user_id));
ret.serial_number2 = ret.serial_number;
ret.access_key2 = ret.access_key;
ret.login_character_name.encode(this->character->disp.name.decode());
ret.login_character_name.encode(this->character->disp.visual.name.decode());
ret.xb_netloc.internal_ipv4_address = phosg::random_object<uint32_t>();
ret.xb_netloc.external_ipv4_address = phosg::random_object<uint32_t>();
ret.xb_netloc.port = 9500;
@@ -212,7 +212,7 @@ void DownloadSession::send_93_9D_9E(bool extended) {
this->channel->send(0x9E, 0x01, &ret, extended ? sizeof(ret) : sizeof(C_Login_DC_PC_GC_9D));
} else {
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
}
@@ -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<PlayerDispDataV123, PlayerDispDataV4>(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<PlayerDispDataV123, PlayerDispDataV4>(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<PlayerDispDataV123, PlayerDispDataV4>(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<PlayerDispDataV123, PlayerDispDataV4>(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;
@@ -264,7 +264,7 @@ void DownloadSession::send_61_98(bool is_98) {
this->channel->send(command, 0x04, ret);
} else {
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
}
@@ -276,16 +276,16 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
switch (msg.command) {
case 0x03: {
if (this->version != Version::BB_V4) {
throw runtime_error("BB server sent non-BB encryption command");
throw std::runtime_error("BB server sent non-BB encryption command");
}
if (!this->bb_key_file) {
throw runtime_error("BB encryption requires a key file");
throw std::runtime_error("BB encryption requires a key file");
}
const auto& cmd = msg.check_size_t<S_ServerInitDefault_BB_03_9B>(0xFFFF);
this->channel->crypt_in = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key));
this->channel->crypt_out = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key));
this->channel->crypt_in = std::make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key));
this->channel->crypt_out = std::make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key));
this->log.info_f("Enabled BB encryption");
throw runtime_error("not yet implemented"); // Send 93
throw std::runtime_error("not yet implemented"); // Send 93
break;
}
@@ -295,17 +295,17 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
case 0x9B: {
const auto& cmd = msg.check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(0xFFFF);
if (uses_v3_encryption(this->version)) {
this->channel->crypt_in = make_shared<PSOV3Encryption>(cmd.server_key);
this->channel->crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
this->channel->crypt_in = std::make_shared<PSOV3Encryption>(cmd.server_key);
this->channel->crypt_out = std::make_shared<PSOV3Encryption>(cmd.client_key);
this->log.info_f("Enabled V3 encryption (server key {:08X}, client key {:08X})",
cmd.server_key, cmd.client_key);
} else if (!uses_v4_encryption(this->version)) {
this->channel->crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
this->channel->crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
this->channel->crypt_in = std::make_shared<PSOV2Encryption>(cmd.server_key);
this->channel->crypt_out = std::make_shared<PSOV2Encryption>(cmd.client_key);
this->log.info_f("Enabled V2 encryption (server key {:08X}, client key {:08X})",
cmd.server_key, cmd.client_key);
} else {
throw runtime_error("BB server sent non-BB encryption command");
throw std::runtime_error("BB server sent non-BB encryption command");
}
if (msg.command == 0x02) {
@@ -344,7 +344,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
this->send_93_9D_9E(true);
} else {
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
}
@@ -379,14 +379,14 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
this->channel->send(0x9C, 0x00, ret);
} else {
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
} else if (msg.flag == 0 || msg.flag == 2) {
this->send_93_9D_9E(true);
} else {
throw runtime_error("login failed");
throw std::runtime_error("login failed");
}
break;
}
@@ -394,14 +394,14 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
case 0x92:
case 0x9C:
if (msg.flag == 0) {
throw runtime_error("server rejected login credentials");
throw std::runtime_error("server rejected login credentials");
}
this->send_93_9D_9E(true);
break;
case 0x9F: {
if (is_v1_or_v2(this->version)) {
throw runtime_error("invalid command");
throw std::runtime_error("invalid command");
}
this->channel->send(0x9F, 0x00, this->client_config);
break;
@@ -475,11 +475,11 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
if (this->interactive) {
while (item_index == 0 || item_index > msg.flag) {
this->log.info_f("Choose response index:");
string input = phosg::fgets(stdin);
item_index = stoul(input, nullptr, 0);
std::string input = phosg::fgets(stdin);
item_index = std::stoul(input, nullptr, 0);
}
} else {
throw runtime_error("unhandled menu selection");
throw std::runtime_error("unhandled menu selection");
}
}
ret.menu_id = items[item_index].menu_id;
@@ -519,9 +519,9 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
const auto& cmd = msg.check_size_t<S_Reconnect_19>(sizeof(S_Reconnect_19), 0xFFFF);
auto new_ep = make_endpoint_ipv4(cmd.address, cmd.port);
string netloc_str = str_for_endpoint(new_ep);
std::string netloc_str = str_for_endpoint(new_ep);
this->log.info_f("Connecting to {}", netloc_str);
auto sock = make_unique<asio::ip::tcp::socket>(co_await async_connect_tcp(new_ep));
auto sock = std::make_unique<asio::ip::tcp::socket>(co_await async_connect_tcp(new_ep));
this->channel = SocketChannel::create(
this->io_context,
std::move(sock),
@@ -529,7 +529,9 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
this->language,
netloc_str,
this->show_command_data ? phosg::TerminalFormat::FG_GREEN : phosg::TerminalFormat::END,
this->show_command_data ? phosg::TerminalFormat::FG_YELLOW : phosg::TerminalFormat::END);
this->show_command_data ? phosg::TerminalFormat::FG_YELLOW : phosg::TerminalFormat::END,
false,
false);
this->log.info_f("Server channel connected");
break;
}
@@ -544,15 +546,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 +564,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 +584,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) {
@@ -645,18 +647,18 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
case 0xA6: {
auto handle_command = [&]<typename CmdT>() {
const auto& cmd = msg.check_size_t<CmdT>(0xFFFF);
string internal_name = cmd.filename.decode();
string filtered_name;
std::string internal_name = cmd.filename.decode();
std::string filtered_name;
for (char ch : internal_name) {
filtered_name.push_back((isalnum(ch) || (ch == '-') || (ch == '.') || (ch == '_')) ? ch : '_');
}
string local_filename = std::format(
"{}/{:016X}_{}_{}_{}_{}",
std::string local_filename = std::format(
"{}/{: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 = ""});
};
@@ -673,7 +675,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
case 0x13:
case 0xA7: {
const auto& cmd = msg.check_size_t<S_WriteFile_13_A7>();
string internal_filename = cmd.filename.decode();
std::string internal_filename = cmd.filename.decode();
if (!is_v1_or_v2(this->version)) {
C_WriteFileConfirmation_V3_BB_13_A7 ret;
@@ -688,10 +690,8 @@ 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 data_size = min<size_t>(cmd.data_size, allowed_block_size);
size_t allowed_block_size = (block_offset < f.total_size) ? std::min<size_t>(f.total_size - block_offset, 0x400) : 0;
size_t data_size = std::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()) {
f.data.resize(block_end_offset);
@@ -718,7 +718,7 @@ asio::awaitable<void> DownloadSession::on_message(Channel::Message& msg) {
}
case 0xAC: {
if (is_v1_or_v2(this->version)) {
throw runtime_error("unsupported version");
throw std::runtime_error("unsupported version");
}
this->on_request_complete();
break;
@@ -743,7 +743,7 @@ void DownloadSession::send_next_request() {
this->log.info_f("{:016X}: {}", it.first, it.second);
}
this->log.info_f("Choose item to expand by ID (q to quit; s to skip to next config):");
string input = phosg::fgets(stdin);
std::string input = phosg::fgets(stdin);
if (input.empty() || (input == "q\n")) {
this->channel->disconnect();
return;
@@ -751,7 +751,7 @@ void DownloadSession::send_next_request() {
this->pending_requests.clear();
this->on_request_complete();
} else {
this->current_request = stoull(input, nullptr, 16);
this->current_request = std::stoull(input, nullptr, 16);
this->done_requests.emplace(this->current_request);
this->pending_requests.erase(this->current_request);
}
@@ -811,7 +811,7 @@ void DownloadSession::on_request_complete() {
}
}
const std::vector<DownloadSession::GameConfig> DownloadSession::game_configs({
const std::vector<DownloadSession::GameConfig> DownloadSession::game_configs{
{.mode = GameMode::NORMAL, .episode = Episode::EP1, .v1 = true, .v2 = true, .v3 = true},
{.mode = GameMode::NORMAL, .episode = Episode::EP2, .v1 = false, .v2 = false, .v3 = true},
{.mode = GameMode::NORMAL, .episode = Episode::EP4, .v1 = false, .v2 = false, .v3 = false},
@@ -821,4 +821,4 @@ const std::vector<DownloadSession::GameConfig> DownloadSession::game_configs({
{.mode = GameMode::SOLO, .episode = Episode::EP1, .v1 = false, .v2 = false, .v3 = false},
{.mode = GameMode::SOLO, .episode = Episode::EP2, .v1 = false, .v2 = false, .v3 = false},
{.mode = GameMode::SOLO, .episode = Episode::EP4, .v1 = false, .v2 = false, .v3 = false},
});
};
+2 -2
View File
@@ -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;
+241 -184
View File
@@ -2,150 +2,155 @@
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <set>
#include "Loggers.hh"
#include "PSOEncryption.hh"
#include "StaticGameData.hh"
using namespace std;
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 const vector<EnemyTypeDefinition> type_defs{
static constexpr uint8_t NONE = 0xFF;
static const std::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 BP-MOVEMENT 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}, {0x19}, "AL_RAPPY", "Al Rappy", "Pal Rappy"},
{EnemyType::ASTARK, EP4, 0x58, 0x41, {0x09}, {0x0B, 0x0A, 0x0C}, {0x09}, {0x09}, "ASTARK", "Astark", nullptr},
{EnemyType::BA_BOOTA, EP4, 0x62, 0x4F, {0x03}, {0x03, 0x02, 0x04}, {0x03}, {0x03}, "BA_BOOTA", "Ba Boota", nullptr},
{EnemyType::BARBA_RAY_JOINT, EP2 | BOSS, 0x49, 0x49, {0x10}, {0x0F}, {0x10}, {}, "BARBA_RAY_JOINT", "Barba Ray (joint)", nullptr},
{EnemyType::BARBA_RAY, EP2 | BOSS, 0x49, 0x49, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "BARBA_RAY", "Barba Ray", nullptr},
{EnemyType::BARBAROUS_WOLF, EP1 | EP2, 0x08, 0x08, {0x03}, {0x03}, {0x03}, {0x03}, "BARBAROUS_WOLF", "Barbarous Wolf", "Gulgus-gue"},
{EnemyType::BEE_L, EP1 | EP2, NONE, NONE, {0x0C}, {0x0C}, {0x0C}, {0x0C}, "BEE_L", "Bee L", "Gee L"},
{EnemyType::BEE_R, EP1 | EP2, NONE, NONE, {0x0B}, {0x0B}, {0x0B}, {0x0B}, "BEE_R", "Bee R", "Gee R"},
{EnemyType::BOOMA, EP1, 0x09, 0x09, {0x4B}, {0x4E}, {0x4A}, {0x4A}, "BOOMA", "Booma", "Bartle"},
{EnemyType::BOOTA, EP4, 0x60, 0x4D, {0x00}, {0x00, 0x02, 0x04}, {0x00}, {0x00}, "BOOTA", "Boota", nullptr},
{EnemyType::BULCLAW, EP1, 0x28, 0x28, {0x1F}, {0x1F}, {0x1F}, {0x1F, 0x20}, "BULCLAW", "Bulclaw", nullptr},
{EnemyType::BULK, EP1, 0x27, 0x27, {0x1F}, {0x1F}, {0x1F}, {0x1F, 0x20}, "BULK", "Bulk", nullptr},
{EnemyType::CANADINE_GROUP, EP1, 0x1C, 0x1C, {0x08}, {0x08}, {0x08}, {0x08}, "CANADINE_GROUP", "Canadine (group)", "Canabin (group)"},
{EnemyType::CANADINE, EP1, 0x1C, 0x1C, {0x07}, {0x07}, {0x07}, {0x07}, "CANADINE", "Canadine", "Canabin"},
{EnemyType::CANANE, EP1, 0x1D, 0x1D, {0x09}, {0x09}, {0x09}, {0x09}, "CANANE", "Canane", "Canune"},
{EnemyType::CHAOS_BRINGER, EP1, 0x24, 0x24, {0x0D}, {0x0D}, {0x0D}, {0x0A, 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}, {0x0E}, "DARK_BELRA", "Dark Belra", "Indi Belra"},
{EnemyType::DARK_FALZ_1, EP1 | BOSS, NONE, NONE, {0x36}, {0x36}, {0x36}, {0x36, 0x39}, "DARK_FALZ_1", "Dark Falz (phase 1)", nullptr},
{EnemyType::DARK_FALZ_2, EP1 | BOSS, 0x2F, 0x2F, {0x37}, {0x37}, {0x37}, {0x37}, "DARK_FALZ_2", "Dark Falz (phase 2)", nullptr},
{EnemyType::DARK_FALZ_3, EP1 | BOSS, 0x2F, 0x2F, {0x38}, {0x38}, {0x38}, {0x38}, "DARK_FALZ_3", "Dark Falz (phase 3)", nullptr},
{EnemyType::DARK_GUNNER_CONTROL, EP1, NONE, NONE, {}, {}, {}, {}, "DARK_GUNNER_CONTROL", "Dark Gunner (control)", nullptr},
{EnemyType::DARK_GUNNER, EP1, 0x22, 0x22, {0x1E}, {0x1E}, {0x1E}, {0x1E}, "DARK_GUNNER", "Dark Gunner", nullptr},
{EnemyType::DARVANT, EP1, NONE, NONE, {0x35}, {0x35}, {0x35}, {0x35, 0x39}, "DARVANT", "Darvant", nullptr},
{EnemyType::DE_ROL_LE_BODY, EP1 | BOSS, NONE, NONE, {0x10}, {0x0F}, {0x10}, {0x0F}, "DE_ROL_LE_BODY", "De Rol Le (body)", "Dal Ra Lie (body)"},
{EnemyType::DE_ROL_LE_MINE, EP1 | BOSS, NONE, NONE, {0x11}, {0x0F}, {0x11}, {0x0F}, "DE_ROL_LE_MINE", "De Rol Le (mine)", "Dal Ra Lie (mine)"},
{EnemyType::DE_ROL_LE, EP1 | BOSS, 0x2D, 0x2D, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "DE_ROL_LE", "De Rol Le", "Dal Ra Lie"},
{EnemyType::DEATH_GUNNER, EP1, 0x23, 0x23, {0x1E}, {0x1E}, {0x1E}, {0x1E}, "DEATH_GUNNER", "Death Gunner", nullptr},
{EnemyType::DEL_LILY, EP2, 0x53, 0x53, {0x25}, {0x25}, {0x25}, {0x25}, "DEL_LILY", "Del Lily", nullptr},
{EnemyType::DEL_RAPPY_CRATER, EP4, 0x69, 0x57, {0x06}, {0x06}, {0x06}, {0x06}, "DEL_RAPPY_CRATER", "Del Rappy (crater)", nullptr},
{EnemyType::DEL_RAPPY_DESERT, EP4, 0x69, 0x58, {0x18}, {0x18}, {0x18}, {0x18}, "DEL_RAPPY_DESERT", "Del Rappy (desert)", nullptr},
{EnemyType::DELBITER, EP2, 0x48, 0x48, {0x0D}, {0x0D}, {0x0D}, {0x0D}, "DELBITER", "Delbiter", nullptr},
{EnemyType::DELDEPTH, EP2, 0x47, 0x47, {0x30}, {0x30}, {0x30}, {0x30}, "DELDEPTH", "Deldepth", nullptr},
{EnemyType::DELSABER, EP1 | EP2, 0x1E, 0x1E, {0x52}, {0x57, 0x58, 0x59}, {0x51}, {0x51}, "DELSABER", "Delsaber", nullptr},
{EnemyType::DIMENIAN, EP1 | EP2, 0x29, 0x29, {0x53}, {0x5A}, {0x52}, {0x52}, "DIMENIAN", "Dimenian", "Arlan"},
{EnemyType::DOLMDARL, EP2, 0x41, 0x41, {0x50}, {0x55}, {0x4F}, {0x4F}, "DOLMDARL", "Dolmdarl", nullptr},
{EnemyType::DOLMOLM, EP2, 0x40, 0x40, {0x4F}, {0x54}, {0x4E}, {0x4E}, "DOLMOLM", "Dolmolm", nullptr},
{EnemyType::DORPHON_ECLAIR, EP4 | RARE, 0x64, 0x51, {0x10}, {0x10}, {0x10}, {0x10}, "DORPHON_ECLAIR", "Dorphon Eclair", nullptr},
{EnemyType::DORPHON, EP4, 0x63, 0x50, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "DORPHON", "Dorphon", nullptr},
{EnemyType::DRAGON, EP1 | BOSS, 0x2C, 0x2C, {0x12}, {0x12, 0x14, 0x15, 0x16, 0x17}, {0x12}, {0x11}, "DRAGON", "Dragon", "Sil Dragon"},
{EnemyType::DUBCHIC, EP1 | EP2, 0x18, 0x18, {0x1B}, {0x1B}, {0x1B}, {0x1B}, "DUBCHIC", "Dubchic", "Dubchich"},
{EnemyType::DUBWITCH, EP1 | EP2, NONE, NONE, {}, {}, {}, {}, "DUBWITCH", "Dubwitch", "Duvuik"},
{EnemyType::EGG_RAPPY, EP2, 0x51, 0x51, {0x19}, {0x19}, {0x19}, {0x19}, "EGG_RAPPY", "Egg Rappy", nullptr},
{EnemyType::EPSIGARD, EP2, NONE, NONE, {0x24}, {0x24}, {0x24}, {0x24}, "EPSIGARD", "Episgard", nullptr},
{EnemyType::EPSILON, EP2, 0x54, 0x54, {0x23}, {0x23}, {0x23}, {0x23}, "EPSILON", "Epsilon", nullptr},
{EnemyType::EVIL_SHARK, EP1, 0x10, 0x10, {0x4F}, {0x54}, {0x4E}, {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}, {0x1E, 0x1F, 0x20}, "GAL_GRYPHON", "Gal Gryphon", nullptr},
{EnemyType::GARANZ, EP1 | EP2, 0x19, 0x19, {0x1D}, {0x1D}, {0x1D}, {0x1D}, "GARANZ", "Garanz", "Baranz"},
{EnemyType::GEE, EP2, 0x36, 0x36, {0x07}, {0x07}, {0x07}, {0x07}, "GEE", "Gee", nullptr},
{EnemyType::GI_GUE, EP2, 0x37, 0x37, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "GI_GUE", "Gi Gue", nullptr},
{EnemyType::GIBBLES, EP2, 0x3D, 0x3D, {0x3D}, {0x3D, 0x3E, 0x3F}, {0x3D}, {0x3D}, "GIBBLES", "Gibbles", nullptr},
{EnemyType::GIGOBOOMA, EP1, 0x0B, 0x0B, {0x4D}, {0x50}, {0x4C}, {0x4C}, "GIGOBOOMA", "Gigobooma", "Tollaw"},
{EnemyType::GILLCHIC, EP1 | EP2, 0x32, 0x32, {0x1C}, {0x1C}, {0x1C}, {0x1C}, "GILLCHIC", "Gillchic", "Gillchich"},
{EnemyType::GIRTABLULU, EP4, 0x5D, 0x48, {0x1F}, {0x1F}, {0x1F}, {0x1F}, "GIRTABLULU", "Girtablulu", nullptr},
{EnemyType::GOBOOMA, EP1, 0x0A, 0x0A, {0x4C}, {0x4F}, {0x4B}, {0x4B}, "GOBOOMA", "Gobooma", "Barble"},
{EnemyType::GOL_DRAGON, EP2 | BOSS, 0x4C, 0x4C, {0x12}, {0x12, 0x14, 0x15, 0x16, 0x17}, {0x12}, {0x11, 0x12, 0x13}, "GOL_DRAGON", "Gol Dragon", nullptr},
{EnemyType::GORAN_DETONATOR, EP4, 0x66, 0x53, {0x13}, {0x13, 0x16}, {0x13}, {0x13}, "GORAN_DETONATOR", "Goran Detonator", nullptr},
{EnemyType::GORAN, EP4, 0x65, 0x52, {0x11}, {0x11, 0x14}, {0x11}, {0x11}, "GORAN", "Goran", nullptr},
{EnemyType::GRASS_ASSASSIN, EP1 | EP2, 0x0C, 0x0C, {0x4E}, {0x51, 0x52, 0x53}, {0x4D}, {0x4D}, "GRASS_ASSASSIN", "Grass Assassin", "Crimson Assassin"},
{EnemyType::GUIL_SHARK, EP1, 0x12, 0x12, {0x51}, {0x56}, {0x50}, {0x50}, "GUIL_SHARK", "Guil Shark", "Melqueek"},
{EnemyType::HALLO_RAPPY, EP2, 0x50, 0x50, {0x19}, {0x19}, {0x19}, {0x19}, "HALLO_RAPPY", "Hallo Rappy", nullptr},
{EnemyType::HIDOOM, EP1 | EP2, 0x17, 0x17, {0x32}, {0x32}, {0x32}, {0x32}, "HIDOOM", "Hidoom", nullptr},
{EnemyType::HILDEBEAR, EP1 | EP2, 0x01, 0x01, {0x49}, {0x48, 0x49, 0x4A}, {0x48}, {0x48}, "HILDEBEAR", "Hildebear", "Hildelt"},
{EnemyType::HILDEBLUE, EP1 | EP2 | RARE, 0x02, 0x02, {0x4A}, {0x4B, 0x4C, 0x4D}, {0x49}, {0x49}, "HILDEBLUE", "Hildeblue", "Hildetorr"},
{EnemyType::ILL_GILL, EP2, 0x52, 0x52, {0x26}, {0x26, 0x27, 0x28, 0x29}, {0x26}, {0x26}, "ILL_GILL", "Ill Gill", nullptr},
{EnemyType::KONDRIEU_SPINNER, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x29, 0x2B}, {0x29, 0x2B}, {0x29, 0x2B}, {0x29, 0x2B}, "KONDRIEU_SPINNER", "Kondrieu (spinner)", nullptr},
{EnemyType::KONDRIEU, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x28, 0x2A}, {0x28, 0x2A}, {0x28, 0x2A}, {0x28, 0x2A}, "KONDRIEU", "Kondrieu", nullptr},
{EnemyType::LA_DIMENIAN, EP1 | EP2, 0x2A, 0x2A, {0x54}, {0x5B}, {0x53}, {0x53}, "LA_DIMENIAN", "La Dimenian", "Merlan"},
{EnemyType::LOVE_RAPPY, EP2, 0x33, 0x33, {0x19}, {0x19}, {0x19}, {0x19}, "LOVE_RAPPY", "Love Rappy", nullptr},
{EnemyType::MERICARAND, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, {0x3A}, "MERICARAND", "Mericarand", nullptr},
{EnemyType::MERICAROL, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, {0x3A}, "MERICAROL", "Mericarol", nullptr},
{EnemyType::MERICUS, EP2 | RARE, 0x3A, 0x3A, {0x46}, {0x46}, {0x46}, {0x46}, "MERICUS", "Mericus", nullptr},
{EnemyType::MERIKLE, EP2 | RARE, 0x39, 0x39, {0x45}, {0x45}, {0x45}, {0x45}, "MERIKLE", "Merikle", nullptr},
{EnemyType::MERILLIA, EP2, 0x34, 0x34, {0x4B}, {0x4E}, {0x4A}, {0x4A}, "MERILLIA", "Merillia", nullptr},
{EnemyType::MERILTAS, EP2, 0x35, 0x35, {0x4C}, {0x4F}, {0x4B}, {0x4B}, "MERILTAS", "Meriltas", nullptr},
{EnemyType::MERISSA_A, EP4, 0x5B, 0x46, {0x19}, {0x19}, {0x19}, {0x19}, "MERISSA_A", "Merissa A", nullptr},
{EnemyType::MERISSA_AA, EP4 | RARE, 0x5C, 0x47, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "MERISSA_AA", "Merissa AA", nullptr},
{EnemyType::MIGIUM, EP1 | EP2, 0x16, 0x16, {0x33}, {0x33}, {0x33}, {0x33}, "MIGIUM", "Migium", nullptr},
{EnemyType::MONEST, EP1 | EP2, 0x04, 0x04, {0x01}, {0x01}, {0x01}, {0x01}, "MONEST", "Monest", "Mothvist"},
{EnemyType::MORFOS, EP2, 0x42, 0x42, {0x40}, {0x40, 0x50}, {0x40}, {0x40}, "MORFOS", "Morfos", nullptr},
{EnemyType::MOTHMANT, EP1 | EP2, 0x03, 0x03, {0x00}, {0x00}, {0x00}, {0x00}, "MOTHMANT", "Mothmant", "Mothvert"},
{EnemyType::NANO_DRAGON, EP1, 0x0F, 0x0F, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "NANO_DRAGON", "Nano Dragon", nullptr},
{EnemyType::NAR_LILY, EP1 | EP2 | RARE, 0x0E, 0x0E, {0x05}, {0x05}, {0x05}, {0x05}, "NAR_LILY", "Nar Lily", "Mil Lily"},
{EnemyType::OLGA_FLOW_1, EP2 | BOSS, NONE, NONE, {0x2B}, {0x2B}, {0x2B}, {0x2B, 0x2D, 0x2F}, "OLGA_FLOW_1", "Olga Flow (phase 1)", nullptr},
{EnemyType::OLGA_FLOW_2, EP2 | BOSS, 0x4E, 0x4E, {0x2C}, {0x2C}, {0x2C}, {0x2C, 0x2D, 0x3E, 0x2F}, "OLGA_FLOW_2", "Olga Flow (phase 2)", nullptr},
{EnemyType::PAL_SHARK, EP1, 0x11, 0x11, {0x50}, {0x55}, {0x4F}, {0x4F}, "PAL_SHARK", "Pal Shark", "Govulmer"},
{EnemyType::PAN_ARMS, EP1 | EP2, 0x15, 0x15, {0x31}, {0x31}, {0x31}, {0x31}, "PAN_ARMS", "Pan Arms", nullptr},
{EnemyType::PAZUZU_CRATER, EP4 | RARE, 0x5F, 0x4B, {0x08}, {0x08}, {0x08}, {0x08}, "PAZUZU_CRATER", "Pazuzu (crater)", nullptr},
{EnemyType::PAZUZU_DESERT, EP4 | RARE, 0x5F, 0x4C, {0x1C}, {0x1C}, {0x1C}, {0x1C}, "PAZUZU_DESERT", "Pazuzu (desert)", nullptr},
{EnemyType::PIG_RAY, EP2, 0x4A, NONE, {0x08}, {0x08}, {0x08}, {0x08}, "PIG_RAY", "Pig Ray", nullptr},
{EnemyType::POFUILLY_SLIME, EP1, 0x13, 0x13, {0x30}, {0x30}, {0x30}, {0x30}, "POFUILLY_SLIME", "Pofuilly Slime", nullptr},
{EnemyType::POISON_LILY, EP1 | EP2, 0x0D, 0x0D, {0x04}, {0x04}, {0x04}, {0x04}, "POISON_LILY", "Poison Lily", "Ob Lily"},
{EnemyType::POUILLY_SLIME, EP1 | RARE, 0x14, 0x14, {0x34}, {0x34}, {0x34}, {0x34}, "POUILLY_SLIME", "Pouilly Slime", nullptr},
{EnemyType::PYRO_GORAN, EP4, 0x67, 0x54, {0x12}, {0x12, 0x15}, {0x12}, {0x12}, "PYRO_GORAN", "Pyro Goran", nullptr},
{EnemyType::RAG_RAPPY, EP1 | EP2, 0x05, 0x05, {0x18}, {0x18}, {0x18}, {0x18}, "RAG_RAPPY", "Rag Rappy", "El Rappy"},
{EnemyType::RECOBOX, EP2, 0x43, 0x43, {0x41}, {0x41}, {0x41}, {0x41}, "RECOBOX", "Recobox", nullptr},
{EnemyType::RECON, EP2, 0x44, 0x44, {0x42}, {0x42}, {0x42}, {0x42}, "RECON", "Recon", nullptr},
{EnemyType::SAINT_MILION_SPINNER, EP4 | BOSS, 0x6A, 0x59, {0x21, 0x23}, {0x21, 0x23}, {0x21, 0x23}, {0x21, 0x23}, "SAINT_MILION_SPINNER", "Saint-Milion (spinner)", nullptr},
{EnemyType::SAINT_MILION, EP4 | BOSS, 0x6A, 0x59, {0x20, 0x22}, {0x20, 0x22}, {0x20, 0x22}, {0x20, 0x22}, "SAINT_MILION", "Saint-Milion", nullptr},
{EnemyType::SAINT_RAPPY, EP2, 0x4F, 0x4F, {0x19}, {0x19}, {0x19}, {0x19}, "SAINT_RAPPY", "Saint Rappy", nullptr},
{EnemyType::SAND_RAPPY_CRATER, EP4, 0x68, 0x55, {0x05}, {0x05}, {0x05}, {0x05}, "SAND_RAPPY_CRATER", "Sand Rappy (crater)", nullptr},
{EnemyType::SAND_RAPPY_DESERT, EP4, 0x68, 0x56, {0x17}, {0x17}, {0x17}, {0x17}, "SAND_RAPPY_DESERT", "Sand Rappy (desert)", nullptr},
{EnemyType::SATELLITE_LIZARD_CRATER, EP4, 0x5A, 0x44, {0x0D}, {0x0D}, {0x0D}, {0x0D}, "SATELLITE_LIZARD_CRATER", "Satellite Lizard (crater)", nullptr},
{EnemyType::SATELLITE_LIZARD_DESERT, EP4, 0x5A, 0x45, {0x1D}, {0x1D}, {0x1D}, {0x1D}, "SATELLITE_LIZARD_DESERT", "Satellite Lizard (desert)", nullptr},
{EnemyType::SAVAGE_WOLF, EP1 | EP2, 0x07, 0x07, {0x02}, {0x02}, {0x02}, {0x02}, "SAVAGE_WOLF", "Savage Wolf", "Gulgus"},
{EnemyType::SHAMBERTIN_SPINNER, EP4 | BOSS, 0x6B, 0x5A, {0x25, 0x27}, {0x25, 0x27}, {0x25, 0x27}, {0x25, 0x27}, "SHAMBERTIN_SPINNER", "Shambertin (spinner)", nullptr},
{EnemyType::SHAMBERTIN, EP4 | BOSS, 0x6B, 0x5A, {0x24, 0x26}, {0x24, 0x26}, {0x24, 0x26}, {0x24, 0x26}, "SHAMBERTIN", "Shambertin", nullptr},
{EnemyType::SINOW_BEAT, EP1, 0x1A, 0x1A, {0x06}, {0x06}, {0x06}, {0x06}, "SINOW_BEAT", "Sinow Beat", "Sinow Blue"},
{EnemyType::SINOW_BERILL, EP2, 0x3E, 0x3E, {0x06}, {0x06}, {0x06}, {0x06}, "SINOW_BERILL", "Sinow Berill", nullptr},
{EnemyType::SINOW_GOLD, EP1, 0x1B, 0x1B, {0x13}, {0x47}, {0x13}, {0x10}, "SINOW_GOLD", "Sinow Gold", "Sinow Red"},
{EnemyType::SINOW_SPIGELL, EP2, 0x3F, 0x3F, {0x13}, {0x47}, {0x13}, {0x10}, "SINOW_SPIGELL", "Sinow Spigell", nullptr},
{EnemyType::SINOW_ZELE, EP2, 0x46, 0x46, {0x44}, {0x44}, {0x44}, {0x44}, "SINOW_ZELE", "Sinow Zele", nullptr},
{EnemyType::SINOW_ZOA, EP2, 0x45, 0x45, {0x43}, {0x43}, {0x43}, {0x43}, "SINOW_ZOA", "Sinow Zoa", nullptr},
{EnemyType::SO_DIMENIAN, EP1 | EP2, 0x2B, 0x2B, {0x55}, {0x5C}, {0x54}, {0x54}, "SO_DIMENIAN", "So Dimenian", "Del-D"},
{EnemyType::UL_GIBBON, EP2, 0x3B, 0x3B, {0x3B}, {0x3B}, {0x3B}, {0x3B}, "UL_GIBBON", "Ul Gibbon", nullptr},
{EnemyType::UL_RAY, EP2, 0x4B, NONE, {0x09}, {0x09}, {0x09}, {0x09}, "UL_RAY", "Ul Ray", nullptr},
{EnemyType::VOL_OPT_1, EP1 | BOSS, NONE, NONE, {0x21}, {0x21}, {0x21}, {0x21, 0x22, 0x23}, "VOL_OPT_1", "Vol Opt (phase 1)", "Vol Opt ver.2 (phase 1)"},
{EnemyType::VOL_OPT_2, EP1 | BOSS, 0x2E, 0x2E, {0x25}, {0x25}, {0x25}, {0x25, 0x26, 0x28, 0x29, 0x2A}, "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}, {0x0E}, "YOWIE_CRATER", "Yowie (crater)", nullptr},
{EnemyType::YOWIE_DESERT, EP4, 0x59, 0x43, {0x1E}, {0x1E}, {0x1E}, {0x1E}, "YOWIE_DESERT", "Yowie (desert)", nullptr},
{EnemyType::ZE_BOOTA, EP4, 0x61, 0x4E, {0x01}, {0x01, 0x02, 0x04}, {0x01}, {0x01}, "ZE_BOOTA", "Ze Boota", nullptr},
{EnemyType::ZOL_GIBBON, EP2, 0x3C, 0x3C, {0x3C}, {0x3C}, {0x3C}, {0x3C}, "ZOL_GIBBON", "Zol Gibbon", nullptr},
{EnemyType::ZU_CRATER, EP4, 0x5E, 0x49, {0x07}, {0x07}, {0x07}, {0x07}, "ZU_CRATER", "Zu (crater)", nullptr},
{EnemyType::ZU_DESERT, EP4, 0x5E, 0x4A, {0x1B}, {0x1B}, {0x1B}, {0x1B}, "ZU_DESERT", "Zu (desert)", nullptr},
// clang-format on
};
@@ -160,94 +165,146 @@ const char* phosg::name_for_enum<EnemyType>(EnemyType type) {
template <>
EnemyType phosg::enum_for_name<EnemyType>(const char* name) {
static unordered_map<string, EnemyType> index;
static std::unordered_map<std::string, EnemyType> index;
if (index.empty()) {
for (const auto& def : type_defs) {
if (!index.emplace(def.enum_name, def.type).second) {
throw logic_error(std::format("duplicate enemy enum name: {}", def.enum_name));
throw std::logic_error(std::format("duplicate enemy enum name: {}", def.enum_name));
}
}
}
return index.at(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;
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index) {
static std::array<std::vector<std::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);
} catch (const out_of_range&) {
static const vector<EnemyType> empty_vec;
} catch (const std::out_of_range&) {
static const std::vector<EnemyType> empty_vec;
return empty_vec;
}
}
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;
struct BPIndexCacheEntry {
std::set<EnemyType> stats;
std::set<EnemyType> attack_data;
std::set<EnemyType> resist_data;
std::set<EnemyType> movement_data;
};
static const BPIndexCacheEntry& get_bp_index_cache_entry(Episode episode, uint8_t bp_index) {
static bool cache_populated = false;
static std::array<std::vector<BPIndexCacheEntry>, 5> data;
if (!cache_populated) {
cache_populated = true;
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);
for (const auto& episode : ALL_EPISODES_V4) {
if (!def.valid_in_episode(episode)) {
continue;
}
auto& ep_index = data[static_cast<size_t>(episode)];
for (const auto& bp_index : def.bp_stats_indexes) {
if (bp_index >= ep_index.size()) {
ep_index.resize(bp_index + 1);
}
ep_index[bp_index].stats.emplace(def.type);
}
for (const auto& bp_index : def.bp_attack_data_indexes) {
if (bp_index >= ep_index.size()) {
ep_index.resize(bp_index + 1);
}
ep_index[bp_index].attack_data.emplace(def.type);
}
for (const auto& bp_index : def.bp_resist_data_indexes) {
if (bp_index >= ep_index.size()) {
ep_index.resize(bp_index + 1);
}
ep_index[bp_index].resist_data.emplace(def.type);
}
for (const auto& bp_index : def.bp_movement_data_indexes) {
if (bp_index >= ep_index.size()) {
ep_index.resize(bp_index + 1);
}
ep_index[bp_index].movement_data.emplace(def.type);
}
ret[def.bp_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);
}
auto& ep_index = data.at(static_cast<size_t>(episode));
return ep_index.at(bp_index);
}
static const std::set<EnemyType> empty_vec;
const std::set<EnemyType>& enemy_types_for_battle_param_stats_index(Episode episode, uint8_t bp_index) {
try {
return ret.at(bp_index);
} catch (const out_of_range&) {
static const vector<EnemyType> empty_vec;
return get_bp_index_cache_entry(episode, bp_index).stats;
} catch (const std::out_of_range&) {
return empty_vec;
}
}
EnemyType EnemyTypeDefinition::rare_type(Episode episode, uint8_t event, uint8_t floor) const {
const std::set<EnemyType>& enemy_types_for_battle_param_attack_data_index(Episode episode, uint8_t bp_index) {
try {
return get_bp_index_cache_entry(episode, bp_index).attack_data;
} catch (const std::out_of_range&) {
return empty_vec;
}
}
const std::set<EnemyType>& enemy_types_for_battle_param_resist_data_index(Episode episode, uint8_t bp_index) {
try {
return get_bp_index_cache_entry(episode, bp_index).resist_data;
} catch (const std::out_of_range&) {
return empty_vec;
}
}
const std::set<EnemyType>& enemy_types_for_battle_param_movement_data_index(Episode episode, uint8_t bp_index) {
try {
return get_bp_index_cache_entry(episode, bp_index).movement_data;
} catch (const std::out_of_range&) {
return empty_vec;
}
}
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;
+36 -12
View File
@@ -3,17 +3,25 @@
#include <inttypes.h>
#include <phosg/Tools.hh>
#include <set>
#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,
AL_RAPPY,
ASTARK,
BA_BOOTA,
BARBA_RAY_JOINT,
BARBA_RAY,
BARBAROUS_WOLF,
BEE_L,
@@ -22,8 +30,8 @@ enum class EnemyType : uint8_t {
BOOTA,
BULCLAW,
BULK,
CANADINE,
CANADINE_GROUP,
CANADINE,
CANANE,
CHAOS_BRINGER,
CHAOS_SORCERER,
@@ -32,13 +40,12 @@ enum class EnemyType : uint8_t {
DARK_FALZ_1,
DARK_FALZ_2,
DARK_FALZ_3,
DARK_GUNNER,
DARK_GUNNER_CONTROL,
DARK_GUNNER,
DARVANT,
DARVANT_ULTIMATE,
DE_ROL_LE,
DE_ROL_LE_BODY,
DE_ROL_LE_MINE,
DE_ROL_LE,
DEATH_GUNNER,
DEL_LILY,
DEL_RAPPY_CRATER,
@@ -49,8 +56,8 @@ enum class EnemyType : uint8_t {
DIMENIAN,
DOLMDARL,
DOLMOLM,
DORPHON,
DORPHON_ECLAIR,
DORPHON,
DRAGON,
DUBCHIC,
DUBWITCH, // Has no entry in battle params
@@ -69,8 +76,8 @@ enum class EnemyType : uint8_t {
GIRTABLULU,
GOBOOMA,
GOL_DRAGON,
GORAN,
GORAN_DETONATOR,
GORAN,
GRASS_ASSASSIN,
GUIL_SHARK,
HALLO_RAPPY,
@@ -78,6 +85,7 @@ enum class EnemyType : uint8_t {
HILDEBEAR,
HILDEBLUE,
ILL_GILL,
KONDRIEU_SPINNER,
KONDRIEU,
LA_DIMENIAN,
LOVE_RAPPY,
@@ -103,12 +111,13 @@ enum class EnemyType : uint8_t {
PAZUZU_DESERT,
PIG_RAY,
POFUILLY_SLIME,
POUILLY_SLIME,
POISON_LILY,
POUILLY_SLIME,
PYRO_GORAN,
RAG_RAPPY,
RECOBOX,
RECON,
SAINT_MILION_SPINNER,
SAINT_MILION,
SAINT_RAPPY,
SAND_RAPPY_CRATER,
@@ -116,6 +125,7 @@ enum class EnemyType : uint8_t {
SATELLITE_LIZARD_CRATER,
SATELLITE_LIZARD_DESERT,
SAVAGE_WOLF,
SHAMBERTIN_SPINNER,
SHAMBERTIN,
SINOW_BEAT,
SINOW_BERILL,
@@ -125,6 +135,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 +148,7 @@ enum class EnemyType : uint8_t {
ZOL_GIBBON,
ZU_CRATER,
ZU_DESERT,
MAX_ENEMY_TYPE,
MAX_VALUE,
};
struct EnemyTypeDefinition {
@@ -146,11 +157,18 @@ 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;
std::vector<uint8_t> bp_movement_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 +188,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 +202,7 @@ 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::set<EnemyType>& enemy_types_for_battle_param_stats_index(Episode episode, uint8_t bp_index);
const std::set<EnemyType>& enemy_types_for_battle_param_attack_data_index(Episode episode, uint8_t bp_index);
const std::set<EnemyType>& enemy_types_for_battle_param_resist_data_index(Episode episode, uint8_t bp_index);
const std::set<EnemyType>& enemy_types_for_battle_param_movement_data_index(Episode episode, uint8_t bp_index);
+31 -44
View File
@@ -2,43 +2,36 @@
#include "Server.hh"
using namespace std;
namespace Episode3 {
const vector<uint16_t>& all_assist_card_ids(bool is_nte) {
const std::vector<uint16_t>& all_assist_card_ids(bool is_nte) {
// Note: This order matches the order that the cards are defined in the original
// 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};
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};
static const std::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};
static const std::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};
return is_nte ? ALL_ASSIST_CARD_IDS_TRIAL : ALL_ASSIST_CARD_IDS_FINAL;
}
AssistEffect assist_effect_number_for_card_id(uint16_t card_id, bool is_nte) {
static const unordered_map<uint16_t, AssistEffect> card_id_to_effect_final_only({
static const std::unordered_map<uint16_t, AssistEffect> card_id_to_effect_final_only({
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
});
static const unordered_map<uint16_t, AssistEffect> card_id_to_effect({
static const std::unordered_map<uint16_t, AssistEffect> card_id_to_effect({
{0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
{0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER},
@@ -114,18 +107,18 @@ AssistEffect assist_effect_number_for_card_id(uint16_t card_id, bool is_nte) {
});
try {
return card_id_to_effect.at(card_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
if (!is_nte) {
try {
return card_id_to_effect_final_only.at(card_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
}
return AssistEffect::NONE;
}
AssistServer::AssistServer(shared_ptr<Server> server)
AssistServer::AssistServer(std::shared_ptr<Server> server)
: w_server(server),
assist_effects(AssistEffect::NONE),
num_assist_cards_set(0),
@@ -133,18 +126,18 @@ AssistServer::AssistServer(shared_ptr<Server> server)
active_assist_effects(AssistEffect::NONE),
num_active_assists(0) {}
shared_ptr<Server> AssistServer::server() {
std::shared_ptr<Server> AssistServer::server() {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<const Server> AssistServer::server() const {
std::shared_ptr<const Server> AssistServer::server() const {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
@@ -153,7 +146,7 @@ uint16_t AssistServer::card_id_for_card_ref(uint16_t card_ref) const {
return this->server()->card_id_for_card_ref(card_ref);
}
shared_ptr<const CardIndex::CardEntry> AssistServer::definition_for_card_id(
std::shared_ptr<const CardIndex::CardEntry> AssistServer::definition_for_card_id(
uint16_t card_id) const {
return this->server()->definition_for_card_id(card_id);
}
@@ -174,13 +167,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 +217,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 +227,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() {
+39 -73
View File
@@ -5,14 +5,11 @@
#include "../CommandFormats.hh"
#include "../SendCommands.hh"
using namespace std;
namespace Episode3 {
void BattleRecord::PlayerEntry::print(FILE* stream) const {
// TODO: Format this nicely somehow. Maybe factor out the functions in
// QuestScript that format some of these structures
phosg::print_data(stream, this, sizeof(*this), 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
// TODO: Format this nicely somehow. Maybe factor out the functions in QuestScript that format some of these structs
phosg::print_data(stream, this, sizeof(*this), 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
}
BattleRecord::Event::Event(phosg::StringReader& r) {
@@ -42,7 +39,7 @@ BattleRecord::Event::Event(phosg::StringReader& r) {
this->data = r.read(r.get_u16l());
break;
default:
throw logic_error("unknown event type");
throw std::logic_error("unknown event type");
}
}
@@ -52,7 +49,7 @@ void BattleRecord::Event::serialize(phosg::StringWriter& w) const {
switch (this->type) {
case Event::Type::PLAYER_JOIN:
if (this->players.size() != 1) {
throw logic_error("player join event does not contain 1 player entry");
throw std::logic_error("player join event does not contain 1 player entry");
}
w.put(this->players[0]);
break;
@@ -76,13 +73,12 @@ void BattleRecord::Event::serialize(phosg::StringWriter& w) const {
w.write(this->data);
break;
default:
throw logic_error("unknown event type");
throw std::logic_error("unknown event type");
}
}
void BattleRecord::Event::print(FILE* stream) const {
string time_str = phosg::format_time(this->timestamp);
phosg::fwrite_fmt(stream, "Event @{:016X} ({}) ", this->timestamp, time_str);
phosg::fwrite_fmt(stream, "Event @{:016X} ({}) ", this->timestamp, phosg::format_time(this->timestamp));
switch (this->type) {
case Type::PLAYER_JOIN:
phosg::fwrite_fmt(stream, "PLAYER_JOIN {:02X}\n", this->players[0].lobby_data.client_id);
@@ -103,26 +99,26 @@ void BattleRecord::Event::print(FILE* stream) const {
break;
case Type::BATTLE_COMMAND:
phosg::fwrite_fmt(stream, "BATTLE_COMMAND\n");
phosg::print_data(stream, this->data, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this->data, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
break;
case Type::GAME_COMMAND:
phosg::fwrite_fmt(stream, "GAME_COMMAND\n");
phosg::print_data(stream, this->data, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this->data, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
break;
case Type::EP3_GAME_COMMAND:
phosg::fwrite_fmt(stream, "EP3_GAME_COMMAND\n");
phosg::print_data(stream, this->data, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this->data, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
break;
case Type::CHAT_MESSAGE:
phosg::fwrite_fmt(stream, "CHAT_MESSAGE {:08X}\n", this->guild_card_number);
phosg::print_data(stream, this->data, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this->data, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
break;
case Type::SERVER_DATA_COMMAND:
phosg::fwrite_fmt(stream, "SERVER_DATA_COMMAND\n");
phosg::print_data(stream, this->data, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this->data, 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
break;
default:
throw runtime_error("unknown event type in battle record");
throw std::runtime_error("unknown event type in battle record");
}
}
@@ -132,11 +128,8 @@ BattleRecord::BattleRecord(uint32_t behavior_flags)
battle_start_timestamp(0),
battle_end_timestamp(0) {}
BattleRecord::BattleRecord(const string& data)
: is_writable(false),
behavior_flags(0),
battle_start_timestamp(0),
battle_end_timestamp(0) {
BattleRecord::BattleRecord(const std::string& data)
: is_writable(false), behavior_flags(0), battle_start_timestamp(0), battle_end_timestamp(0) {
phosg::StringReader r(data);
uint64_t signature = r.get_u64l();
@@ -146,7 +139,7 @@ BattleRecord::BattleRecord(const string& data)
} else if (signature == this->SIGNATURE_V2) {
has_random_stream = true;
} else {
throw runtime_error("incorrect battle record signature");
throw std::runtime_error("incorrect battle record signature");
}
this->battle_start_timestamp = r.get_u64l();
@@ -160,7 +153,7 @@ BattleRecord::BattleRecord(const string& data)
}
}
string BattleRecord::serialize() const {
std::string BattleRecord::serialize() const {
phosg::StringWriter w;
w.put_u64l(this->SIGNATURE_V2);
w.put_u64l(this->battle_start_timestamp);
@@ -174,31 +167,16 @@ 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,
const PlayerDispDataDCPCV3& disp,
const PlayerDispDataV123& disp,
uint32_t level) {
if (!this->is_writable) {
throw logic_error("cannot write to battle record");
throw std::logic_error("cannot write to battle record");
}
if (this->battle_start_timestamp != 0) {
throw runtime_error("cannot add player during battle");
throw std::runtime_error("cannot add player during battle");
}
Event& ev = this->events.emplace_back();
ev.type = Event::Type::PLAYER_JOIN;
@@ -212,7 +190,7 @@ void BattleRecord::add_player(
void BattleRecord::delete_player(uint8_t client_id) {
if (!this->is_writable) {
throw logic_error("cannot write to battle record");
throw std::logic_error("cannot write to battle record");
}
Event& ev = this->events.emplace_back();
ev.type = Event::Type::PLAYER_LEAVE;
@@ -222,7 +200,7 @@ void BattleRecord::delete_player(uint8_t client_id) {
void BattleRecord::add_command(Event::Type type, const void* data, size_t size) {
if (!this->is_writable) {
throw logic_error("cannot write to battle record");
throw std::logic_error("cannot write to battle record");
}
Event& ev = this->events.emplace_back();
ev.type = type;
@@ -230,9 +208,9 @@ void BattleRecord::add_command(Event::Type type, const void* data, size_t size)
ev.data.assign(reinterpret_cast<const char*>(data), size);
}
void BattleRecord::add_command(Event::Type type, string&& data) {
void BattleRecord::add_command(Event::Type type, std::string&& data) {
if (!this->is_writable) {
throw logic_error("cannot write to battle record");
throw std::logic_error("cannot write to battle record");
}
Event& ev = this->events.emplace_back();
ev.type = type;
@@ -240,10 +218,9 @@ void BattleRecord::add_command(Event::Type type, string&& data) {
ev.data = std::move(data);
}
void BattleRecord::add_chat_message(
uint32_t guild_card_number, string&& data) {
void BattleRecord::add_chat_message(uint32_t guild_card_number, std::string&& data) {
if (!this->is_writable) {
throw logic_error("cannot write to battle record");
throw std::logic_error("cannot write to battle record");
}
Event& ev = this->events.emplace_back();
ev.type = Event::Type::CHAT_MESSAGE;
@@ -256,17 +233,7 @@ 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 {
const std::string& BattleRecord::get_random_stream() const {
return this->random_stream;
}
@@ -285,7 +252,7 @@ bool BattleRecord::is_map_definition_event(const Event& ev) {
void BattleRecord::set_battle_start_timestamp() {
if (this->battle_start_timestamp != 0) {
throw logic_error("battle start timestamp is already set");
throw std::logic_error("battle start timestamp is already set");
}
this->battle_start_timestamp = phosg::now();
@@ -297,30 +264,30 @@ void BattleRecord::set_battle_start_timestamp() {
for (auto& ev : this->events) {
if (ev.type == Event::Type::PLAYER_JOIN) {
if (ev.players.size() != 1) {
throw logic_error("player join event does not contain 1 player entry");
throw std::logic_error("player join event does not contain 1 player entry");
}
auto& player = ev.players[0];
if (player.lobby_data.client_id >= 4) {
throw runtime_error("invalid client ID");
throw std::runtime_error("invalid client ID");
}
players[player.lobby_data.client_id] = player;
players_present[player.lobby_data.client_id] = true;
} else if (ev.type == Event::Type::PLAYER_LEAVE) {
if (ev.leaving_client_id >= 4) {
throw logic_error("invalid client ID");
throw std::logic_error("invalid client ID");
}
players_present[ev.leaving_client_id] = false;
} else if (ev.type == Event::Type::SET_INITIAL_PLAYERS) {
throw logic_error("BattleRecord::set_battle_start_timestamp called twice");
throw std::logic_error("BattleRecord::set_battle_start_timestamp called twice");
} else if (this->is_map_definition_event(ev)) {
num_map_events++;
}
}
deque<Event> new_events;
std::deque<Event> new_events;
// Generate the initial players event
Event initial_ev;
@@ -361,32 +328,31 @@ void BattleRecord::set_battle_end_timestamp() {
}
void BattleRecord::print(FILE* stream) const {
string start_str = phosg::format_time(this->battle_start_timestamp);
string end_str = phosg::format_time(this->battle_end_timestamp);
phosg::fwrite_fmt(stream, "BattleRecord {} behavior_flags={:08X} start={:016X} ({}) end={:016X} ({}); {} events\n",
this->is_writable ? "writable" : "read-only",
this->behavior_flags,
this->battle_start_timestamp,
start_str,
phosg::format_time(this->battle_start_timestamp),
this->battle_end_timestamp,
end_str, this->events.size());
phosg::format_time(this->battle_end_timestamp),
this->events.size());
for (const auto& event : this->events) {
event.print(stream);
}
}
BattleRecordPlayer::BattleRecordPlayer(std::shared_ptr<asio::io_context> io_context, shared_ptr<const BattleRecord> rec)
BattleRecordPlayer::BattleRecordPlayer(std::shared_ptr<asio::io_context> io_context, std::shared_ptr<const BattleRecord> rec)
: io_context(io_context),
record(rec),
event_it(this->record->events.begin()),
play_start_timestamp(0),
next_command_timer(*this->io_context) {}
shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
std::shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
return this->record;
}
void BattleRecordPlayer::set_lobby(shared_ptr<Lobby> l) {
void BattleRecordPlayer::set_lobby(std::shared_ptr<Lobby> l) {
this->lobby = l;
}
@@ -432,7 +398,7 @@ asio::awaitable<void> BattleRecordPlayer::play_task() {
switch (ev.type) {
case BattleRecord::Event::Type::PLAYER_JOIN:
// Technically we can support this, but it should never happen
throw runtime_error("player join event during battle replay");
throw std::runtime_error("player join event during battle replay");
case BattleRecord::Event::Type::PLAYER_LEAVE:
send_player_leave_notification(l, ev.leaving_client_id);
break;
+20 -6
View File
@@ -22,7 +22,7 @@ public:
struct PlayerEntry {
PlayerLobbyDataDCGC lobby_data;
PlayerInventory inventory;
PlayerDispDataDCPCV3 disp;
PlayerDispDataV123 disp;
le_uint32_t level;
void print(FILE* stream) const;
@@ -62,15 +62,30 @@ 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,
const PlayerInventory& inventory,
const PlayerDispDataDCPCV3& disp,
const PlayerDispDataV123& disp,
uint32_t level);
void delete_player(uint8_t client_id);
void add_command(Event::Type type, const void* data, size_t size);
@@ -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:
+81 -107
View File
@@ -3,15 +3,9 @@
#include "../CommandFormats.hh"
#include "Server.hh"
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, std::shared_ptr<Server> server)
: w_server(server),
w_player_state(server->get_player_state(client_id)),
client_id(client_id),
@@ -43,7 +37,7 @@ void Card::init() {
// Arkz-side. This could break things later on in the battle, and even if it
// doesn't, it certainly isn't behavior that the player would expect, so we
// prevent it instead.
throw runtime_error("card definition is missing");
throw std::runtime_error("card definition is missing");
}
this->sc_card_ref = ps->get_sc_card_ref();
this->sc_def_entry = s->definition_for_card_id(ps->get_sc_card_id());
@@ -60,7 +54,7 @@ void Card::init() {
} else {
int16_t rules_char_hp = s->map_and_rules->rules.char_hp;
int16_t base_char_hp = (rules_char_hp == 0) ? 15 : rules_char_hp;
int16_t hp = clamp<int16_t>(base_char_hp + this->def_entry->def.hp.stat, 1, 99);
int16_t hp = std::clamp<int16_t>(base_char_hp + this->def_entry->def.hp.stat, 1, 99);
this->max_hp = hp;
this->current_hp = hp;
}
@@ -82,34 +76,34 @@ void Card::init() {
}
}
shared_ptr<Server> Card::server() {
std::shared_ptr<Server> Card::server() {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<const Server> Card::server() const {
std::shared_ptr<const Server> Card::server() const {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<PlayerState> Card::player_state() {
std::shared_ptr<PlayerState> Card::player_state() {
auto s = this->w_player_state.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<const PlayerState> Card::player_state() const {
std::shared_ptr<const PlayerState> Card::player_state() const {
auto s = this->w_player_state.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
@@ -132,8 +126,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 {
@@ -163,7 +156,7 @@ ssize_t Card::apply_abnormal_condition(
int16_t existing_cond_value = 0;
auto& cond = this->action_chain.conditions[cond_index];
if ((eff.type == ConditionType::MV_BONUS) && (cond.type == ConditionType::MV_BONUS)) {
existing_cond_value = clamp<int16_t>(cond.value, -99, 99);
existing_cond_value = std::clamp<int16_t>(cond.value, -99, 99);
log.debug_f("MV_BONUS combines => existing_cond_value = {}", existing_cond_value);
}
@@ -173,11 +166,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;
@@ -185,7 +174,7 @@ ssize_t Card::apply_abnormal_condition(
switch (eff.arg1.at(0)) {
case 'a': {
string s = eff.arg1.decode();
std::string s = eff.arg1.decode();
cond.a_arg_value = atoi(s.c_str() + 1);
break;
}
@@ -199,13 +188,12 @@ ssize_t Card::apply_abnormal_condition(
cond.remaining_turns = 102;
break;
case 't': {
string s = eff.arg1.decode();
std::string s = eff.arg1.decode();
cond.remaining_turns = atoi(s.c_str() + 1);
}
}
string cond_str = cond.str(s);
log.debug_f("wrote condition {} => {}", cond_index, cond_str);
log.debug_f("wrote condition {} => {}", cond_index, cond.str(s));
if (!is_nte) {
s->card_special->update_condition_orders(this->shared_from_this());
@@ -213,8 +201,7 @@ ssize_t Card::apply_abnormal_condition(
if (this->action_chain.conditions[z].type == ConditionType::NONE) {
continue;
}
string cond_str = cond.str(s);
log.debug_f("sorted conditions: [{}] => {}", z, cond_str);
log.debug_f("sorted conditions: [{}] => {}", z, cond.str(s));
}
}
@@ -222,7 +209,7 @@ ssize_t Card::apply_abnormal_condition(
}
void Card::apply_ap_and_tp_adjust_assists_to_attack(
shared_ptr<const Card> attacker_card,
std::shared_ptr<const Card> attacker_card,
int16_t* inout_attacker_ap,
int16_t* in_defense_power,
int16_t* inout_attacker_tp) const {
@@ -235,12 +222,12 @@ void Card::apply_ap_and_tp_adjust_assists_to_attack(
switch (s->assist_server->get_active_assist_by_index(z)) {
case AssistEffect::POWERLESS_RAIN:
if (is_nte) {
*inout_attacker_ap = max<int16_t>(*inout_attacker_ap - 2, 0);
*inout_attacker_ap = std::max<int16_t>(*inout_attacker_ap - 2, 0);
}
break;
case AssistEffect::BRAVE_WIND:
if (is_nte) {
*inout_attacker_ap = max<int16_t>(*inout_attacker_ap + 2, 0);
*inout_attacker_ap = std::max<int16_t>(*inout_attacker_ap + 2, 0);
}
break;
case AssistEffect::SILENT_COLOSSEUM:
@@ -293,7 +280,7 @@ bool Card::check_card_flag(uint32_t flags) const {
void Card::commit_attack(
int16_t damage,
shared_ptr<Card> attacker_card,
std::shared_ptr<Card> attacker_card,
G_ApplyConditionEffect_Ep3_6xB4x06* cmd,
size_t strike_number,
int16_t* out_effective_damage) {
@@ -309,10 +296,9 @@ 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);
int16_t exp_amount = std::clamp<int16_t>(s->team_exp[team_id], 0, effective_damage);
s->team_exp[team_id] -= exp_amount;
effective_damage -= exp_amount;
if (!is_nte) {
@@ -336,11 +322,10 @@ void Card::commit_attack(
this->player_state()->stats.damage_taken += effective_damage;
log.debug_f("updated stats");
this->current_hp = clamp<int16_t>(this->current_hp - effective_damage, 0, this->max_hp);
this->current_hp = std::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);
}
@@ -377,7 +362,7 @@ void Card::commit_attack(
}
}
int16_t Card::compute_defense_power_for_attacker_card(shared_ptr<const Card> attacker_card) {
int16_t Card::compute_defense_power_for_attacker_card(std::shared_ptr<const Card> attacker_card) {
if (!attacker_card) {
return 0;
}
@@ -396,12 +381,14 @@ 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;
}
void Card::destroy_set_card(shared_ptr<Card> attacker_card) {
void Card::destroy_set_card(std::shared_ptr<Card> attacker_card) {
auto s = this->server();
auto ps = this->player_state();
@@ -439,8 +426,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 +450,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 +474,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
@@ -501,7 +486,7 @@ int32_t Card::error_code_for_move_to_location(const Location& loc) const {
return 0;
}
void Card::execute_attack(shared_ptr<Card> attacker_card) {
void Card::execute_attack(std::shared_ptr<Card> attacker_card) {
if (!attacker_card) {
return;
}
@@ -529,9 +514,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 = std::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;
@@ -558,7 +541,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
log.debug_f("assist adjusts ap={}, defense={}", attack_ap, defense_power);
int16_t raw_damage = attack_ap - defense_power;
int16_t preliminary_damage = max<int16_t>(raw_damage, 0) - attack_tp;
int16_t preliminary_damage = std::max<int16_t>(raw_damage, 0) - attack_tp;
this->last_attack_preliminary_damage = preliminary_damage;
log.debug_f("raw_damage={}, preliminary_damange={}", raw_damage, preliminary_damage);
@@ -584,8 +567,8 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
}
}
cmd.effect.current_hp = is_nte ? attack_ap : min<int16_t>(attack_ap, 99);
cmd.effect.ap = is_nte ? defense_power : min<int16_t>(defense_power, 99);
cmd.effect.current_hp = is_nte ? attack_ap : std::min<int16_t>(attack_ap, 99);
cmd.effect.ap = is_nte ? defense_power : std::min<int16_t>(defense_power, 99);
cmd.effect.tp = attack_tp;
auto ps = this->player_state();
@@ -596,7 +579,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
for (size_t strike_num = 0; strike_num < attacker_card->action_chain.chain.strike_count; strike_num++) {
int16_t final_effective_damage = 0;
target->commit_attack(preliminary_damage, attacker_card, &cmd, strike_num, &final_effective_damage);
ps->stats.action_card_negated_damage += max<int16_t>(0, this->current_defense_power - final_effective_damage);
ps->stats.action_card_negated_damage += std::max<int16_t>(0, this->current_defense_power - final_effective_damage);
}
} else {
log.debug_f("flag 2 set; committing zero-damage attack");
@@ -613,11 +596,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);
}
@@ -635,7 +614,7 @@ const Condition* Card::find_condition(ConditionType cond_type) const {
return const_cast<Card*>(this)->find_condition(cond_type);
}
shared_ptr<const CardIndex::CardEntry> Card::get_definition() const {
std::shared_ptr<const CardIndex::CardEntry> Card::get_definition() const {
return this->def_entry;
}
@@ -697,9 +676,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 +729,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);
}
}
@@ -859,10 +835,10 @@ void Card::set_current_and_max_hp(int16_t hp) {
void Card::set_current_hp(
uint32_t new_hp, bool propagate_shared_hp, bool enforce_max_hp) {
if (!enforce_max_hp) {
new_hp = max<int16_t>(new_hp, 0);
this->max_hp = max<int16_t>(this->max_hp, new_hp);
new_hp = std::max<int16_t>(new_hp, 0);
this->max_hp = std::max<int16_t>(this->max_hp, new_hp);
} else {
new_hp = clamp<int16_t>(new_hp, 0, this->max_hp);
new_hp = std::clamp<int16_t>(new_hp, 0, this->max_hp);
}
this->current_hp = new_hp;
@@ -906,7 +882,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 +907,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);
}
@@ -973,11 +951,11 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
}
if (!this->action_chain.check_flag(0x10)) {
this->action_chain.chain.effective_ap = is_nte ? effective_ap : min<int16_t>(effective_ap, 99);
this->action_chain.chain.effective_ap = is_nte ? effective_ap : std::min<int16_t>(effective_ap, 99);
log.debug_f("set chain effective_ap = {}", this->action_chain.chain.effective_ap);
}
if (!this->action_chain.check_flag(0x20)) {
this->action_chain.chain.effective_tp = is_nte ? effective_tp : min<int16_t>(effective_tp, 99);
this->action_chain.chain.effective_tp = is_nte ? effective_tp : std::min<int16_t>(effective_tp, 99);
log.debug_f("set chain effective_tp = {}", this->action_chain.chain.effective_tp);
}
@@ -1008,7 +986,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 +1060,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,25 +1083,28 @@ 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");
}
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);
: std::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);
if (apply_action_conditions) {
auto this_sh = this->shared_from_this();
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 2, nullptr);
log.debug_f("applied action conditions (2)");
if (!is_nte && this->action_chain.check_flag(0x100)) {
this->action_chain.chain.damage = min<int16_t>(this->action_chain.chain.damage + 5, 99);
this->action_chain.chain.damage = std::min<int16_t>(this->action_chain.chain.damage + 5, 99);
log.debug_f("(has flag 0x100) chain damage = {}", this->action_chain.chain.damage);
}
} else {
@@ -1157,8 +1137,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
}
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string chain_str = this->action_chain.str(s);
log.debug_f("result computed as {}", chain_str);
log.debug_f("result computed as {}", this->action_chain.str(s));
}
}
@@ -1224,20 +1203,19 @@ void Card::move_phase_before() {
this->server()->card_special->move_phase_before_for_card(this->shared_from_this());
}
void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as) {
void Card::unknown_80236374(std::shared_ptr<Card> other_card, const ActionState* as) {
auto s = this->server();
auto log = s->log_stack(std::format("unknown_80236374(@{:04X} #{:04X}, @{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->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");
}
}
auto check_card = [&](shared_ptr<Card> card) -> void {
auto check_card = [&](std::shared_ptr<Card> card) -> void {
if (card) {
if (!card->unknown_80236554(other_card, as)) {
log.debug_f("check_card @{:04X} #{:04X} => false", card->get_card_ref(), card->get_card_id());
@@ -1271,8 +1249,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) {
@@ -1280,7 +1257,7 @@ void Card::unknown_802379DC(const ActionState& pa) {
pa.defense_card_ref, this->shared_from_this(), pa.original_attacker_card_ref);
this->server()->card_special->unknown_8024A9D8(pa, 0xFFFF);
for (size_t z = 0; z < this->action_metadata.target_card_ref_count; z++) {
shared_ptr<Card> card = this->server()->card_for_set_card_ref(this->action_metadata.target_card_refs[z]);
std::shared_ptr<Card> card = this->server()->card_for_set_card_ref(this->action_metadata.target_card_refs[z]);
if (card) {
card->action_chain.set_action_subphase_from_card(this->shared_from_this());
card->send_6xB4x4E_4C_4D_if_needed();
@@ -1319,7 +1296,7 @@ void Card::unknown_80237A90(const ActionState& pa, uint16_t action_card_ref) {
if (this->action_chain.chain.target_card_ref_count == 0) {
for (size_t z = 0; (z < 4 * 9) && (pa.target_card_refs[z] != 0xFFFF); z++) {
this->action_chain.add_target_card_ref(pa.target_card_refs[z]);
shared_ptr<Card> sc_card = s->card_for_set_card_ref(pa.target_card_refs[z]);
std::shared_ptr<Card> sc_card = s->card_for_set_card_ref(pa.target_card_refs[z]);
if (sc_card) {
sc_card->action_metadata.add_target_card_ref(this->card_ref);
sc_card->card_flags |= 8;
@@ -1359,8 +1336,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());
}
}
}
@@ -1375,15 +1351,14 @@ bool Card::is_guard_item() const {
return (this->def_entry->def.card_class() == CardClass::GUARD_ITEM);
}
bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as) {
bool Card::unknown_80236554(std::shared_ptr<Card> other_card, const ActionState* as) {
auto s = this->server();
auto log = s->log_stack(other_card
? std::format("unknown_80236554(@{:04X} #{:04X}, @{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id())
: 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");
}
@@ -1414,7 +1389,7 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
}
}
this->action_metadata.attack_bonus = max<int16_t>(attack_bonus, 0);
this->action_metadata.attack_bonus = std::max<int16_t>(attack_bonus, 0);
log.debug_f("attack_bonus = {}", this->action_metadata.attack_bonus);
this->last_attack_preliminary_damage = 0;
this->last_attack_final_damage = 0;
@@ -1440,17 +1415,17 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
return ret;
}
void Card::execute_attack_on_all_valid_targets(shared_ptr<Card> attacker_card) {
void Card::execute_attack_on_all_valid_targets(std::shared_ptr<Card> attacker_card) {
auto s = this->server();
for (size_t client_id = 0; client_id < 4; client_id++) {
auto ps = s->player_states[client_id];
if (ps) {
shared_ptr<Card> card = ps->get_sc_card();
std::shared_ptr<Card> card = ps->get_sc_card();
if (card) {
card->execute_attack(attacker_card);
}
for (size_t set_index = 0; set_index < 8; set_index++) {
shared_ptr<Card> card = ps->get_set_card(set_index);
std::shared_ptr<Card> card = ps->get_set_card(set_index);
if (card) {
card->execute_attack(attacker_card);
}
@@ -1495,7 +1470,7 @@ void Card::apply_attack_result() {
temp_chain.chain.target_card_ref_count++;
} else if ((target_card->get_definition()->def.type == CardType::ITEM) && !this->action_chain.check_flag(0x02)) {
auto target_ps = target_card->player_state();
shared_ptr<Card> candidate_card;
std::shared_ptr<Card> candidate_card;
for (size_t set_index = 0; set_index < 8; set_index++) {
auto set_card = target_ps->get_set_card(set_index);
if (set_card && (set_card != target_card) && !(set_card->card_flags & 2) && set_card->is_guard_item()) {
@@ -1574,12 +1549,11 @@ void Card::apply_attack_result() {
}
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string as_str = as.str(s);
log.debug_f("as constructed as {}", as_str);
log.debug_f("as constructed as {}", as.str(s));
}
for (size_t z = 0; z < this->action_chain.chain.target_card_ref_count; z++) {
shared_ptr<Card> card = s->card_for_set_card_ref(this->action_chain.chain.target_card_refs[z]);
std::shared_ptr<Card> card = s->card_for_set_card_ref(this->action_chain.chain.target_card_refs[z]);
if (card) {
card->current_defense_power = card->action_metadata.attack_bonus;
if (!this->action_chain.check_flag(0x40)) {
File diff suppressed because it is too large Load Diff
+34 -94
View File
@@ -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;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+20 -29
View File
@@ -2,8 +2,6 @@
#include "Server.hh"
using namespace std;
namespace Episode3 {
NameEntry::NameEntry() {
@@ -92,8 +90,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 +99,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 +127,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 +158,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 +186,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];
@@ -207,7 +196,7 @@ void DeckState::redraw_initial_hand(bool is_nte) {
auto s = this->server.lock();
if (!s) {
throw runtime_error("server is missing");
throw std::runtime_error("server is missing");
}
// Shuffle the deck, except the first 5 cards (which are about to be drawn).
@@ -269,16 +258,14 @@ void DeckState::shuffle() {
if (this->shuffle_enabled) {
auto s = this->server.lock();
if (!s) {
throw runtime_error("server is missing");
throw std::runtime_error("server is missing");
}
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,20 +296,24 @@ 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;
std::shared_ptr<const CardIndex::CardEntry> ce;
if (card_index) {
try {
ce = card_index->definition_for_id(e.card_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
}
if (ce) {
string name = ce->def.en_name.decode(1);
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));
z, e.deck_index, this->card_refs[z], e.card_id, ce->def.en_name.decode(Language::ENGLISH),
name_for_card_state(e.state));
} else {
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_for_card_state(e.state));
+3 -7
View File
@@ -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),
-2
View File
@@ -1,7 +1,5 @@
#include "MapState.hh"
using namespace std;
namespace Episode3 {
MapState::MapState() {
+88 -141
View File
@@ -2,11 +2,9 @@
#include "Server.hh"
using namespace std;
namespace Episode3 {
PlayerState::PlayerState(uint8_t client_id, shared_ptr<Server> server)
PlayerState::PlayerState(uint8_t client_id, std::shared_ptr<Server> server)
: w_server(server),
client_id(client_id),
num_hand_redraws_allowed(1),
@@ -46,10 +44,10 @@ void PlayerState::init() {
if (s->player_states.at(this->client_id).get() != this) {
// Note: The original code handles this, but we don't. This appears not to
// ever happen, so we didn't bother implementing it.
throw logic_error("replacing a player state object is not permitted");
throw std::logic_error("replacing a player state object is not permitted");
}
this->deck_state = make_shared<DeckState>(this->client_id, s->deck_entries[client_id]->card_ids, s);
this->deck_state = std::make_shared<DeckState>(this->client_id, s->deck_entries[client_id]->card_ids, s);
if (s->map_and_rules->rules.disable_deck_shuffle) {
this->deck_state->disable_shuffle();
}
@@ -62,7 +60,7 @@ void PlayerState::init() {
this->team_id = s->deck_entries[this->client_id]->team_id;
auto sc_ce = s->definition_for_card_ref(this->sc_card_ref);
if (!sc_ce) {
throw runtime_error("SC card definition is missing");
throw std::runtime_error("SC card definition is missing");
}
if (sc_ce->def.type == CardType::HUNTERS_SC) {
this->sc_card_type = CardType::HUNTERS_SC;
@@ -72,13 +70,13 @@ void PlayerState::init() {
// In the original code, sc_card_type gets left as 0xFFFFFFFF (yes, it's a
// uint32_t). This probably breaks some things later on, so we instead
// prevent it upfront.
throw runtime_error("SC card is not a Hunters or Arkz SC");
throw std::runtime_error("SC card is not a Hunters or Arkz SC");
}
this->hand_and_equip = make_shared<HandAndEquipState>();
this->card_short_statuses = make_shared<parray<CardShortStatus, 0x10>>();
this->set_card_action_chains = make_shared<parray<ActionChainWithConds, 9>>();
this->set_card_action_metadatas = make_shared<parray<ActionMetadata, 9>>();
this->hand_and_equip = std::make_shared<HandAndEquipState>();
this->card_short_statuses = std::make_shared<parray<CardShortStatus, 0x10>>();
this->set_card_action_chains = std::make_shared<parray<ActionChainWithConds, 9>>();
this->set_card_action_metadatas = std::make_shared<parray<ActionMetadata, 9>>();
this->hand_and_equip->clear_FF();
for (size_t z = 0; z < 0x10; z++) {
@@ -89,7 +87,7 @@ void PlayerState::init() {
this->set_card_action_metadatas->at(z).clear_FF();
}
this->sc_card = make_shared<Card>(this->deck_state->sc_card_id(), this->sc_card_ref, this->client_id, s);
this->sc_card = std::make_shared<Card>(this->deck_state->sc_card_id(), this->sc_card_ref, this->client_id, s);
this->sc_card->init();
this->draw_initial_hand();
if (s->options.is_nte()) {
@@ -110,24 +108,22 @@ 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);
}
shared_ptr<Server> PlayerState::server() {
std::shared_ptr<Server> PlayerState::server() {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<const Server> PlayerState::server() const {
std::shared_ptr<const Server> PlayerState::server() const {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
@@ -153,8 +149,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(std::shared_ptr<PlayerState> setter_ps) {
auto s = this->server();
uint16_t assist_card_id = this->set_assist_card_id;
@@ -163,8 +158,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;
}
@@ -248,7 +242,7 @@ void PlayerState::apply_assist_card_effect_on_set(
case AssistEffect::LEGACY: {
uint16_t total_cost = 0;
for (ssize_t z = 7; z >= 0; z--) {
shared_ptr<const Card> card = this->set_cards[z];
std::shared_ptr<const Card> card = this->set_cards[z];
if (card) {
auto ce = card->get_definition();
uint8_t card_cost = ce->def.self_cost;
@@ -262,7 +256,7 @@ void PlayerState::apply_assist_card_effect_on_set(
if (!is_nte) {
this->on_cards_destroyed();
}
this->atk_points = min<uint8_t>(9, this->atk_points + (total_cost >> 1));
this->atk_points = std::min<uint8_t>(9, this->atk_points + (total_cost >> 1));
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
if (!is_nte) {
s->send_6xB4x05();
@@ -314,8 +308,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;
@@ -328,7 +321,7 @@ void PlayerState::apply_assist_card_effect_on_set(
if (!s->options.is_nte()) {
s->team_num_cards_destroyed[this->team_id] = 0;
for (size_t client_id = 0; client_id < 4; client_id++) {
const auto other_ps = s->get_player_state(client_id);
auto other_ps = s->get_player_state(client_id);
if (other_ps && (this->team_id == other_ps->get_team_id())) {
auto card = other_ps->get_sc_card();
if (card) {
@@ -358,13 +351,11 @@ void PlayerState::apply_assist_card_effect_on_set(
if (is_nte
? (other_ps->assist_remaining_turns != 90 && other_ps->assist_remaining_turns != 99)
: (other_ps->assist_remaining_turns < 10)) {
other_ps->assist_remaining_turns = min<uint8_t>(9, other_ps->assist_remaining_turns << 1);
other_ps->assist_remaining_turns = std::min<uint8_t>(9, other_ps->assist_remaining_turns << 1);
}
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];
@@ -376,7 +367,7 @@ void PlayerState::apply_assist_card_effect_on_set(
cond.remaining_turns <<= 1;
}
} else if (cond.remaining_turns < 10) {
cond.remaining_turns = min<uint8_t>(9, cond.remaining_turns << 1);
cond.remaining_turns = std::min<uint8_t>(9, cond.remaining_turns << 1);
}
}
}
@@ -404,9 +395,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];
@@ -489,7 +478,7 @@ void PlayerState::apply_dice_effects() {
}
for (size_t die_index = 0; die_index < 2; die_index++) {
this->dice_results[die_index] = min<uint8_t>(this->dice_results[die_index], 9);
this->dice_results[die_index] = std::min<uint8_t>(this->dice_results[die_index], 9);
}
}
@@ -537,9 +526,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 +566,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 +759,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 +769,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 +800,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;
@@ -833,21 +816,17 @@ 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 {
std::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 {
auto s = this->server();
auto log = s->log_stack("get_all_cards_within_range: ");
string loc_str = loc.str();
log.debug_f("loc={}, target_team_id={:02X}", loc_str, target_team_id);
log.debug_f("loc={}, target_team_id={:02X}", loc.str(), target_team_id);
vector<uint16_t> ret;
std::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());
}
@@ -863,7 +842,7 @@ void PlayerState::get_short_status_for_card_index_in_hand(size_t hand_index, Car
stat->card_ref = this->card_refs[hand_index - 1];
}
shared_ptr<DeckState> PlayerState::get_deck() {
std::shared_ptr<DeckState> PlayerState::get_deck() {
return this->deck_state;
}
@@ -889,11 +868,11 @@ uint16_t PlayerState::get_sc_card_id() const {
return this->sc_card_id;
}
shared_ptr<Card> PlayerState::get_sc_card() {
std::shared_ptr<Card> PlayerState::get_sc_card() {
return this->sc_card;
}
shared_ptr<const Card> PlayerState::get_sc_card() const {
std::shared_ptr<const Card> PlayerState::get_sc_card() const {
return this->sc_card;
}
@@ -905,11 +884,11 @@ CardType PlayerState::get_sc_card_type() const {
return this->sc_card_type;
}
shared_ptr<Card> PlayerState::get_set_card(size_t set_index) {
std::shared_ptr<Card> PlayerState::get_set_card(size_t set_index) {
return (set_index < 8) ? this->set_cards[set_index] : nullptr;
}
shared_ptr<const Card> PlayerState::get_set_card(size_t set_index) const {
std::shared_ptr<const Card> PlayerState::get_set_card(size_t set_index) const {
return (set_index < 8) ? this->set_cards[set_index] : nullptr;
}
@@ -945,9 +924,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 +939,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)) {
@@ -984,7 +961,7 @@ uint16_t PlayerState::pop_from_discard_log(uint16_t) {
bool PlayerState::move_card_to_location_by_card_index(size_t card_index, const Location& new_loc) {
auto s = this->server();
shared_ptr<Card> card;
std::shared_ptr<Card> card;
if (card_index == 0) {
card = this->sc_card;
} else {
@@ -1030,9 +1007,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;
std::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 +1081,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,9 +1329,8 @@ 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?
this->set_cards[card_index - 7] = make_shared<Card>(s->card_id_for_card_ref(card_ref), card_ref, this->client_id, s);
// 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] = std::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 +1338,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 +1408,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;
@@ -1459,7 +1430,7 @@ void PlayerState::set_initial_location() {
static const uint8_t start_tile_defs_offset_for_team_size[4] = {0, 0, 1, 3};
if (num_team_players >= 4) {
throw logic_error("too many players on team");
throw std::logic_error("too many players on team");
}
size_t start_tile_def_index = start_tile_defs_offset_for_team_size[num_team_players] + player_index_within_team;
uint8_t player_start_tile = mr->map.start_tile_definitions[this->team_id][start_tile_def_index];
@@ -1481,12 +1452,11 @@ void PlayerState::set_initial_location() {
}
}
if (!start_tile_found) {
throw runtime_error("player start location not set");
throw std::runtime_error("player start location not set");
}
}
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(std::shared_ptr<const Card> card) {
if (!card) {
return;
}
@@ -1498,8 +1468,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 +1478,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 +1486,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 +1497,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);
@@ -1555,7 +1521,7 @@ bool PlayerState::subtract_or_check_atk_or_def_points_for_action(
void PlayerState::subtract_atk_points(uint8_t cost) {
this->atk_points -= cost;
this->atk_points2 = min<uint8_t>(this->atk_points, this->atk_points2_max);
this->atk_points2 = std::min<uint8_t>(this->atk_points, this->atk_points2_max);
}
G_UpdateHand_Ep3_6xB4x02 PlayerState::prepare_6xB4x02() const {
@@ -1580,9 +1546,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 +1555,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;
@@ -1605,7 +1568,7 @@ void PlayerState::set_random_assist_card_from_hand_for_free() {
auto s = this->server();
bool is_nte = s->options.is_nte();
vector<uint16_t> candidate_card_refs;
std::vector<uint16_t> candidate_card_refs;
for (size_t hand_index = 0; hand_index < 6; hand_index++) {
uint16_t card_ref = this->card_refs[hand_index];
auto ce = s->definition_for_card_ref(card_ref);
@@ -1618,8 +1581,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 +1603,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;
}
@@ -1673,13 +1633,11 @@ 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 {
std::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 {
auto s = this->server();
vector<uint16_t> ret;
std::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 && ((other_ps->get_sc_card_type() == type) || (type == CardType::ITEM))) {
@@ -1726,8 +1684,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,9 +1693,8 @@ 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?
this->atk_points = min<int16_t>(this->atk_points + 2, 9);
// Note: This behavior doesn't match the card description. Is it supposed to add 2 or multiply by 2?
this->atk_points = std::min<int16_t>(this->atk_points + 2, 9);
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
break;
case AssistEffect::SKIP_TURN:
@@ -1797,8 +1753,7 @@ bool PlayerState::set_action_cards_for_action_state(const ActionState& pa) {
size_t z = 0;
do {
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string ref_str = s->debug_str_for_card_ref(pa.action_card_refs[z]);
log.debug_f("on action card ref {}", ref_str);
log.debug_f("on action card ref {}", s->debug_str_for_card_ref(pa.action_card_refs[z]));
}
card->unknown_80237A90(pa, pa.action_card_refs[z]);
card->unknown_802379BC(pa.action_card_refs[z]);
@@ -1834,8 +1789,7 @@ bool PlayerState::set_action_cards_for_action_state(const ActionState& pa) {
auto target_card = s->card_for_set_card_ref(pa.target_card_refs[z]);
if (target_card) {
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string ref_str = s->debug_str_for_card_ref(pa.target_card_refs[z]);
log.debug_f("on target card ref {}", ref_str);
log.debug_f("on target card ref {}", s->debug_str_for_card_ref(pa.target_card_refs[z]));
}
target_card->unknown_802379DC(pa);
if (!is_nte) {
@@ -1864,8 +1818,7 @@ bool PlayerState::set_action_cards_for_action_state(const ActionState& pa) {
}
for (size_t z = 0; (z < pa.action_card_refs.size()) && (pa.action_card_refs[z] != 0xFFFF); z++) {
if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string ref_str = s->debug_str_for_card_ref(pa.action_card_refs[z]);
log.debug_f("discarding {} from hand", ref_str);
log.debug_f("discarding {} from hand", s->debug_str_for_card_ref(pa.action_card_refs[z]));
}
this->discard_ref_from_hand(pa.action_card_refs[z]);
}
@@ -1885,9 +1838,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();
@@ -1909,7 +1860,7 @@ void PlayerState::dice_phase_before() {
this->send_set_card_updates();
}
void PlayerState::handle_homesick_assist_effect_from_bomb(shared_ptr<Card> card) {
void PlayerState::handle_homesick_assist_effect_from_bomb(std::shared_ptr<Card> card) {
if (!card) {
return;
}
@@ -1984,12 +1935,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]);
@@ -2043,13 +1992,13 @@ void PlayerState::roll_main_dice_or_apply_after_effects() {
}
this->atk_points += s->team_dice_bonus[this->team_id];
this->def_points += s->team_dice_bonus[this->team_id];
this->atk_points = clamp<uint8_t>(this->atk_points, 1, 9);
this->def_points = clamp<uint8_t>(this->def_points, 1, 9);
this->atk_points = std::clamp<uint8_t>(this->atk_points, 1, 9);
this->def_points = std::clamp<uint8_t>(this->def_points, 1, 9);
if (!s->options.is_nte()) {
this->atk_bonuses = this->atk_points - atk_before_bonuses;
this->def_bonuses = this->def_points - def_before_bonuses;
}
this->atk_points2 = min<uint8_t>(this->atk_points2_max, this->atk_points);
this->atk_points2 = std::min<uint8_t>(this->atk_points2_max, this->atk_points);
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
}
@@ -2079,11 +2028,9 @@ 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);
s->team_dice_bonus[current_team_turn] = clamp<int16_t>(dice_boost, 0, 8);
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] = std::clamp<int16_t>(dice_boost, 0, 8);
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
}
+16 -24
View File
@@ -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;
+72 -127
View File
@@ -2,8 +2,6 @@
#include "Server.hh"
using namespace std;
namespace Episode3 {
Condition::Condition() {
@@ -61,9 +59,7 @@ void Condition::clear_FF() {
this->unknown_a8 = 0xFF;
}
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);
std::string Condition::str(std::shared_ptr<const Server> s) const {
return std::format(
"Condition[type={}, turns={}, a_arg={}, dice={}, flags={:02X}, "
"def_eff_index={}, ref={}, value={}, giver_ref={} "
@@ -74,9 +70,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,
@@ -100,15 +96,11 @@ void EffectResult::clear() {
this->dice_roll_value = 0;
}
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);
std::string EffectResult::str(std::shared_ptr<const Server> s) const {
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,
@@ -136,16 +128,13 @@ bool CardShortStatus::operator!=(const CardShortStatus& other) const {
return !this->operator==(other);
}
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);
std::string CardShortStatus::str(std::shared_ptr<const Server> s) const {
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);
@@ -187,24 +176,17 @@ void ActionState::clear() {
this->unused2 = 0xFFFF;
}
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);
std::string ActionState::str(std::shared_ptr<const Server> s) const {
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() {
@@ -238,25 +220,18 @@ bool ActionChain::operator!=(const ActionChain& other) const {
return !this->operator==(other);
}
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);
std::string ActionChain::str(std::shared_ptr<const Server> s) const {
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 +245,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() {
@@ -332,8 +307,8 @@ bool ActionChainWithConds::operator!=(const ActionChainWithConds& other) const {
return !this->operator==(other);
}
std::string ActionChainWithConds::str(shared_ptr<const Server> s) const {
string ret = "ActionChainWithConds[chain=";
std::string ActionChainWithConds::str(std::shared_ptr<const Server> s) const {
std::string ret = "ActionChainWithConds[chain=";
ret += this->chain.str(s);
ret += ", conds=[";
for (size_t z = 0; z < this->conditions.size(); z++) {
@@ -406,8 +381,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, std::shared_ptr<Server> server) {
if (card_ref != 0xFFFF) {
this->chain.attack_action_card_refs[this->chain.attack_action_card_ref_count++] = card_ref;
}
@@ -416,13 +390,12 @@ 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;
}
}
void ActionChainWithConds::compute_attack_medium(shared_ptr<Server> server) {
void ActionChainWithConds::compute_attack_medium(std::shared_ptr<Server> server) {
this->chain.attack_medium = AttackMedium::PHYSICAL;
for (size_t z = 0; z < this->chain.attack_action_card_ref_count; z++) {
uint16_t card_ref = this->chain.attack_action_card_refs[z];
@@ -440,11 +413,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 +435,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(std::shared_ptr<const Card> card) {
this->chain.action_subphase = card->server()->get_current_action_subphase();
}
@@ -575,17 +543,11 @@ bool ActionMetadata::operator!=(const ActionMetadata& other) const {
return !this->operator==(other);
}
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);
std::string ActionMetadata::str(std::shared_ptr<const Server> s) const {
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 +555,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 +567,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 +613,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, std::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;
@@ -674,22 +632,11 @@ HandAndEquipState::HandAndEquipState() {
this->clear();
}
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);
std::string HandAndEquipState::str(std::shared_ptr<const Server> s) const {
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 +646,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 +742,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 +762,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;
@@ -832,7 +775,7 @@ uint8_t PlayerBattleStats::rank_for_score(float score) {
const char* PlayerBattleStats::name_for_rank(uint8_t rank) {
if (rank >= RANK_THRESHOLD_COUNT + 1) {
throw invalid_argument("invalid rank");
throw std::invalid_argument("invalid rank");
}
return RANK_NAMES[rank];
}
@@ -874,13 +817,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;
}
@@ -895,12 +840,12 @@ static bool is_card_within_range(
return ret;
}
vector<uint16_t> get_card_refs_within_range(
std::vector<uint16_t> get_card_refs_within_range(
const parray<uint8_t, 9 * 9>& range,
const Location& loc,
const parray<CardShortStatus, 0x10>& short_statuses,
phosg::PrefixedLogger* log) {
vector<uint16_t> ret;
std::vector<uint16_t> ret;
if (is_card_within_range(range, loc, short_statuses[0], log)) {
if (log) {
log->debug_f("get_card_refs_within_range: sc card @{:04X} within range", short_statuses[0].card_ref);
+3 -7
View File
@@ -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);
+137 -197
View File
@@ -5,34 +5,30 @@
#include "DataIndexes.hh"
#include "Server.hh"
using namespace std;
namespace Episode3 {
void compute_effective_range(
parray<uint8_t, 9 * 9>& ret,
shared_ptr<const CardIndex> card_index,
std::shared_ptr<const CardIndex> card_index,
uint16_t card_id,
const Location& loc,
shared_ptr<const MapAndRulesState> map_and_rules,
std::shared_ptr<const MapAndRulesState> map_and_rules,
phosg::PrefixedLogger* log) {
if (log && log->should_log(phosg::LogLevel::L_DEBUG)) {
string loc_str = loc.str();
log->debug_f("compute_effective_range: card_id=#{:04X}, loc={}", card_id, loc_str);
log->debug_f("compute_effective_range: card_id=#{:04X}, loc={}", card_id, loc.str());
log->debug_f("compute_effective_range: map_and_rules->map:");
map_and_rules->map.print(stderr);
}
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;
std::shared_ptr<const CardIndex::CardEntry> ce;
try {
ce = card_index->definition_for_id(card_id);
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
return;
}
for (size_t z = 0; z < 6; z++) {
@@ -40,11 +36,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 +61,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]);
}
}
@@ -94,11 +92,12 @@ void compute_effective_range(
up_y = 9 - y - 1;
break;
default:
throw logic_error("invalid direction");
throw std::logic_error("invalid direction");
}
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,15 +107,16 @@ 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]);
}
}
}
bool card_linkage_is_valid(
shared_ptr<const CardIndex::CardEntry> right_ce,
shared_ptr<const CardIndex::CardEntry> left_ce,
shared_ptr<const CardIndex::CardEntry> sc_ce,
std::shared_ptr<const CardIndex::CardEntry> right_ce,
std::shared_ptr<const CardIndex::CardEntry> left_ce,
std::shared_ptr<const CardIndex::CardEntry> sc_ce,
bool has_permission_effect) {
if (!right_ce) {
return false;
@@ -124,9 +124,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 +134,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 +143,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) &&
@@ -175,40 +170,33 @@ bool card_linkage_is_valid(
return false;
}
RulerServer::RulerServer(shared_ptr<Server> server)
: w_server(server),
team_id_for_client_id(0xFF),
error_code1(0),
error_code2(0),
error_code3(0) {}
RulerServer::RulerServer(std::shared_ptr<Server> server)
: w_server(server), team_id_for_client_id(0xFF), error_code1(0), error_code2(0), error_code3(0) {}
shared_ptr<Server> RulerServer::server() {
std::shared_ptr<Server> RulerServer::server() {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
shared_ptr<const Server> RulerServer::server() const {
std::shared_ptr<const Server> RulerServer::server() const {
auto s = this->w_server.lock();
if (!s) {
throw runtime_error("server is deleted");
throw std::runtime_error("server is deleted");
}
return s;
}
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));
ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(uint16_t card_ref) {
return const_cast<ActionChainWithConds*>(std::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 +207,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 +279,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 +340,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 +381,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;
}
@@ -405,7 +391,7 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(const ActionState& pa
last_action_card_index = z;
}
auto check_chain = [&]() -> optional<bool> {
auto check_chain = [&]() -> std::optional<bool> {
const auto* chain = this->action_chain_with_conds_for_card_ref(pa.attacker_card_ref);
if (chain) {
for (ssize_t cond_index = 8; cond_index >= 0; cond_index--) {
@@ -422,7 +408,7 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(const ActionState& pa
}
}
}
return nullopt;
return std::nullopt;
};
if (is_nte) {
@@ -433,8 +419,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 +545,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 +555,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 +627,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 +667,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 +675,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 +732,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 +751,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;
// }
@@ -782,7 +760,7 @@ bool RulerServer::check_move_path_and_get_cost(
if (max_dist < 1) {
return false;
}
max_dist = min<uint8_t>(max_dist, 9);
max_dist = std::min<uint8_t>(max_dist, 9);
const auto* short_status = this->short_status_for_card_ref(card_ref);
if (!short_status) {
@@ -833,8 +811,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 +948,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 +960,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:
@@ -1049,7 +1023,7 @@ bool RulerServer::check_usability_or_condition_apply(
}
break;
case CriterionCode::HUNTER_NON_ANDROID_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0002, // Kranz
0x0003, // Ino'lis
@@ -1078,7 +1052,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_HU_CLASS_MALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0113, // Teifu
0x02AA, // H-HUmar
@@ -1089,7 +1063,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_FEMALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0003, // Ino'lis
0x0004, // Sil'fer
0x0006, // Kylria
@@ -1113,7 +1087,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_NON_RA_CLASS_HUMAN_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0003, // Ino'lis
0x0004, // Sil'fer
@@ -1136,7 +1110,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_HU_CLASS_ANDROID_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0110, // Saligun
0x0113, // Teifu
0x02AC, // H-HUcast
@@ -1147,7 +1121,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_NON_RA_CLASS_NON_NEWMAN_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0003, // Ino'lis
0x0110, // Saligun
@@ -1167,7 +1141,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_NON_NEWMAN_NON_FORCE_MALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0002, // Kranz
0x0005, // Guykild
@@ -1185,7 +1159,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_HUNEWEARL_CLASS_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0004, // Sil'fer
0x02AB, // H-HUnewearl
0x02CF, // H-HUnewearl
@@ -1193,7 +1167,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_RA_CLASS_MALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0002, // Kranz
0x0005, // Guykild
0x02AE, // H-RAmar
@@ -1204,7 +1178,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_RA_CLASS_FEMALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0006, // Kylria
0x0114, // Stella
0x02AF, // H-RAmarl
@@ -1215,7 +1189,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_RA_OR_FO_CLASS_FEMALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0003, // Ino'lis
0x0006, // Kylria
0x0112, // Viviana
@@ -1232,7 +1206,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_HU_OR_RA_CLASS_HUMAN_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0001, // Orland
0x0002, // Kranz
0x0004, // Sil'fer
@@ -1249,7 +1223,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_RA_CLASS_ANDROID_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0005, // Guykild
0x0114, // Stella
0x02B0, // H-RAcast
@@ -1260,7 +1234,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_FO_CLASS_FEMALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0003, // Ino'lis
0x0112, // Viviana
0x02B3, // H-FOmarl
@@ -1271,7 +1245,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_HUMAN_FEMALE_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0003, // Ino'lis
0x0004, // Sil'fer
0x0006, // Kylria
@@ -1288,7 +1262,7 @@ bool RulerServer::check_usability_or_condition_apply(
return ret && card_ids.count(card_id2);
}
case CriterionCode::HUNTER_ANDROID_SC: {
static const unordered_set<uint16_t> card_ids = {
static const std::unordered_set<uint16_t> card_ids = {
0x0005, // Guykild
0x0110, // Saligun
0x0113, // Teifu
@@ -1359,9 +1333,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 +1355,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;
}
@@ -1455,14 +1426,14 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
final_cost = 0;
}
} else {
final_cost = max<int16_t>(final_cost, this->hand_and_equip_states[pa.client_id]->atk_points);
final_cost = std::max<int16_t>(final_cost, this->hand_and_equip_states[pa.client_id]->atk_points);
}
}
if (out_ally_cost) {
*out_ally_cost = total_ally_cost;
}
return max<int16_t>(final_cost, total_cost + assist_cost_bias);
return std::max<int16_t>(final_cost, total_cost + assist_cost_bias);
}
bool RulerServer::compute_effective_range_and_target_mode_for_attack(
@@ -1514,8 +1485,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 +1538,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);
@@ -1652,10 +1620,9 @@ bool RulerServer::defense_card_can_apply_to_attack(
bool RulerServer::defense_card_matches_any_attack_card_top_color(const ActionState& pa) const {
auto ce = this->definition_for_card_ref(pa.action_card_refs[0]);
if (!ce) {
throw runtime_error("defense card definition is missing");
throw std::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)) {
@@ -1672,7 +1639,7 @@ bool RulerServer::defense_card_matches_any_attack_card_top_color(const ActionSta
return false;
}
shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_ref(uint16_t card_ref) const {
std::shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_ref(uint16_t card_ref) const {
uint16_t card_id = this->card_id_for_card_ref(card_ref);
if (card_id == 0xFFFF) {
return nullptr;
@@ -1681,10 +1648,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 +1807,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 +1815,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;
}
@@ -1872,7 +1834,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
return -0x7E;
}
} else {
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
int16_t diff = std::max<int16_t>(summon_area_size - summon_cost, 0);
if (x_offset > 0) {
if (loc->x < summon_area_loc.x) {
return -0x7E;
@@ -1891,7 +1853,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
return -0x7E;
}
} else {
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
int16_t diff = std::max<int16_t>(summon_area_size - summon_cost, 0);
if (y_offset > 0) {
if (loc->y < summon_area_loc.y) {
return -0x7E;
@@ -1965,8 +1927,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 +1940,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,12 +1963,11 @@ 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) {
throw logic_error("invalid direction");
throw std::logic_error("invalid direction");
}
ret |= this->flood_fill_move_path(
chain,
@@ -2053,7 +2010,7 @@ uint16_t RulerServer::get_ally_sc_card_ref(uint16_t card_ref) const {
return 0xFFFF;
}
shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_id(uint32_t card_id) const {
std::shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_id(uint32_t card_id) const {
return this->server()->definition_for_card_id(card_id);
}
@@ -2061,9 +2018,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 +2034,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 +2079,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 +2110,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 +2123,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) {
std::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 {
std::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 +2153,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) {
@@ -2219,7 +2164,7 @@ ssize_t RulerServer::get_path_cost(
path_length *= cond.value;
}
}
return clamp<ssize_t>(path_length + cost_penalty, 0, 99);
return std::clamp<ssize_t>(path_length + cost_penalty, 0, 99);
}
ActionType RulerServer::get_pending_action_type(const ActionState& pa) const {
@@ -2253,13 +2198,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 +2215,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 +2254,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 +2269,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 +2308,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 +2394,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)) {
@@ -2490,9 +2433,9 @@ bool RulerServer::is_defense_valid(const ActionState& pa) {
}
void RulerServer::link_objects(
shared_ptr<MapAndRulesState> map_and_rules,
shared_ptr<StateFlags> state_flags,
shared_ptr<AssistServer> assist_server) {
std::shared_ptr<MapAndRulesState> map_and_rules,
std::shared_ptr<StateFlags> state_flags,
std::shared_ptr<AssistServer> assist_server) {
this->map_and_rules = map_and_rules;
this->state_flags = state_flags;
this->assist_server = assist_server;
@@ -2541,7 +2484,7 @@ size_t RulerServer::max_move_distance_for_card_ref(uint32_t card_ref) const {
if (this->find_condition_on_card_ref(card_ref, ConditionType::SET_MV, &cond, nullptr, true)) {
ret = cond.value;
}
ret = max<ssize_t>(0, ret);
ret = std::max<ssize_t>(0, ret);
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(client_id);
bool has_stamina_effect = false;
@@ -2555,7 +2498,7 @@ size_t RulerServer::max_move_distance_for_card_ref(uint32_t card_ref) const {
}
}
return has_stamina_effect ? 9 : min<ssize_t>(9, ret);
return has_stamina_effect ? 9 : std::min<ssize_t>(9, ret);
}
}
@@ -2590,9 +2533,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;
@@ -2617,11 +2559,11 @@ void RulerServer::offsets_for_direction(
void RulerServer::register_player(
uint8_t client_id,
shared_ptr<HandAndEquipState> hes,
shared_ptr<parray<CardShortStatus, 0x10>> short_statuses,
shared_ptr<DeckEntry> deck_entry,
shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains,
shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas) {
std::shared_ptr<HandAndEquipState> hes,
std::shared_ptr<parray<CardShortStatus, 0x10>> short_statuses,
std::shared_ptr<DeckEntry> deck_entry,
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains,
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas) {
this->hand_and_equip_states[client_id] = hes;
this->short_statuses[client_id] = short_statuses;
this->deck_entries[client_id] = deck_entry;
@@ -2629,8 +2571,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))) {
@@ -2708,7 +2649,7 @@ int32_t RulerServer::set_cost_for_card(uint8_t client_id, uint16_t card_ref) con
// In NTE, Land Price is apparently 2x rather than 1.5x
ret = is_nte ? (ret << 1) : (ret + (ret >> 1));
} else if (eff == AssistEffect::DEFLATION) {
ret = max<int32_t>(0, ret - 1);
ret = std::max<int32_t>(0, ret - 1);
} else if (eff == AssistEffect::INFLATION) {
ret++;
}
@@ -2737,8 +2678,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;
+2 -4
View File
@@ -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;
+223 -257
View File
File diff suppressed because it is too large Load Diff
+46 -52
View File
@@ -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 std::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;
+128 -179
View File
@@ -7,23 +7,18 @@
#include "../SendCommands.hh"
#include "../ServerState.hh"
using namespace std;
namespace Episode3 {
Tournament::PlayerEntry::PlayerEntry(uint32_t account_id, const string& player_name)
: account_id(account_id),
player_name(player_name) {}
Tournament::PlayerEntry::PlayerEntry(uint32_t account_id, const std::string& player_name)
: account_id(account_id), player_name(player_name) {}
Tournament::PlayerEntry::PlayerEntry(shared_ptr<Client> c)
Tournament::PlayerEntry::PlayerEntry(std::shared_ptr<Client> c)
: account_id(c->login->account->account_id),
client(c),
player_name(c->character_file()->disp.name.decode(c->language())) {}
player_name(c->character_file()->disp.visual.name.decode(c->language())) {}
Tournament::PlayerEntry::PlayerEntry(
shared_ptr<const COMDeckDefinition> com_deck)
: account_id(0),
com_deck(com_deck) {}
Tournament::PlayerEntry::PlayerEntry(std::shared_ptr<const COMDeckDefinition> com_deck)
: account_id(0), com_deck(com_deck) {}
bool Tournament::PlayerEntry::is_com() const {
return (this->com_deck != nullptr);
@@ -33,8 +28,7 @@ bool Tournament::PlayerEntry::is_human() const {
return (this->account_id != 0);
}
Tournament::Team::Team(
shared_ptr<Tournament> tournament, size_t index, size_t max_players)
Tournament::Team::Team(std::shared_ptr<Tournament> tournament, size_t index, size_t max_players)
: tournament(tournament),
index(index),
max_players(max_players),
@@ -43,7 +37,7 @@ Tournament::Team::Team(
num_rounds_cleared(0),
is_active(true) {}
string Tournament::Team::str() const {
std::string Tournament::Team::str() const {
size_t num_human_players = 0;
size_t num_com_players = 0;
for (const auto& player : this->players) {
@@ -51,7 +45,7 @@ string Tournament::Team::str() const {
num_com_players += player.is_com();
}
string ret = std::format("[Team/{} {} {}H/{}C/{}P name={} pass={} rounds={}",
std::string ret = std::format("[Team/{} {} {}H/{}C/{}P name={} pass={} rounds={}",
this->index, this->is_active ? "active" : "inactive",
num_human_players, num_com_players, this->max_players, this->name,
this->password, this->num_rounds_cleared);
@@ -68,28 +62,26 @@ string Tournament::Team::str() const {
}
void Tournament::Team::register_player(
shared_ptr<Client> c,
const string& team_name,
const string& password) {
std::shared_ptr<Client> c, const std::string& team_name, const std::string& password) {
if (this->players.size() >= this->max_players) {
throw runtime_error("team is full");
throw std::runtime_error("team is full");
}
if (!this->name.empty() && (password != this->password)) {
throw runtime_error("incorrect password");
throw std::runtime_error("incorrect password");
}
auto tournament = this->tournament.lock();
if (!tournament) {
throw runtime_error("tournament has been deleted");
throw std::runtime_error("tournament has been deleted");
}
if (!tournament->all_player_account_ids.emplace(c->login->account->account_id).second) {
throw runtime_error("player already registered in same tournament");
throw std::runtime_error("player already registered in same tournament");
}
for (const auto& player : this->players) {
if (player.is_human() && (player.account_id == c->login->account->account_id)) {
throw logic_error("player already registered in team but not in tournament");
throw std::logic_error("player already registered in team but not in tournament");
}
}
@@ -104,8 +96,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,15 +114,13 @@ 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");
throw std::logic_error("zero-round match is pending after tournament registration phase");
}
if (match->preceding_a->winner_team.get() == this) {
match->set_winner_team(match->preceding_b->winner_team);
@@ -142,11 +131,10 @@ 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");
throw std::logic_error("player removed from team but not from tournament");
}
}
@@ -183,31 +171,19 @@ 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)
: tournament(tournament),
preceding_a(preceding_a),
preceding_b(preceding_b),
winner_team(nullptr),
round_num(0) {
std::shared_ptr<Tournament> tournament, std::shared_ptr<Match> preceding_a, std::shared_ptr<Match> preceding_b)
: tournament(tournament), preceding_a(preceding_a), preceding_b(preceding_b), winner_team(nullptr), round_num(0) {
if (this->preceding_a->round_num != this->preceding_b->round_num) {
throw logic_error("preceding matches have different round numbers");
throw std::logic_error("preceding matches have different round numbers");
}
this->round_num = this->preceding_a->round_num + 1;
}
Tournament::Match::Match(
shared_ptr<Tournament> tournament,
shared_ptr<Team> winner_team)
: tournament(tournament),
preceding_a(nullptr),
preceding_b(nullptr),
winner_team(winner_team),
round_num(0) {}
Tournament::Match::Match(std::shared_ptr<Tournament> tournament, std::shared_ptr<Team> winner_team)
: tournament(tournament), preceding_a(nullptr), preceding_b(nullptr), winner_team(winner_team), round_num(0) {}
string Tournament::Match::str() const {
string winner_str = this->winner_team ? this->winner_team->str() : "(none)";
std::string Tournament::Match::str() const {
std::string winner_str = this->winner_team ? this->winner_team->str() : "(none)";
return std::format("[Match round={} winner={}]", this->round_num, winner_str);
}
@@ -228,9 +204,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 +222,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 +234,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
@@ -274,13 +249,12 @@ void Tournament::Match::on_winner_team_set() {
}
}
void Tournament::Match::set_winner_team_without_triggers(shared_ptr<Team> team) {
void Tournament::Match::set_winner_team_without_triggers(std::shared_ptr<Team> team) {
if (!this->preceding_a || !this->preceding_b) {
throw logic_error("set_winner_team called on zero-round match");
throw std::logic_error("set_winner_team called on zero-round match");
}
if ((team != this->preceding_a->winner_team) &&
(team != this->preceding_b->winner_team)) {
throw logic_error("winner team did not participate in match");
if ((team != this->preceding_a->winner_team) && (team != this->preceding_b->winner_team)) {
throw std::logic_error("winner team did not participate in match");
}
this->winner_team = team;
@@ -293,30 +267,29 @@ void Tournament::Match::set_winner_team_without_triggers(shared_ptr<Team> team)
}
}
void Tournament::Match::set_winner_team(shared_ptr<Team> team) {
void Tournament::Match::set_winner_team(std::shared_ptr<Team> team) {
this->set_winner_team_without_triggers(team);
this->on_winner_team_set();
}
shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(
shared_ptr<Team> team) const {
std::shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(std::shared_ptr<Team> team) const {
if (!this->preceding_a || !this->preceding_b) {
throw logic_error("zero-round matches do not have opponents");
throw std::logic_error("zero-round matches do not have opponents");
}
if (team == this->preceding_a->winner_team) {
return this->preceding_b->winner_team;
} else if (team == this->preceding_b->winner_team) {
return this->preceding_a->winner_team;
} else {
throw logic_error("team is not registered for this match");
throw std::logic_error("team is not registered for this match");
}
}
Tournament::Tournament(
shared_ptr<const MapIndex> map_index,
shared_ptr<const COMDeckIndex> com_deck_index,
const string& name,
shared_ptr<const MapIndex::Map> map,
std::shared_ptr<const MapIndex> map_index,
std::shared_ptr<const COMDeckIndex> com_deck_index,
const std::string& name,
std::shared_ptr<const MapIndex::Map> map,
const Rules& rules,
size_t num_teams,
uint8_t flags)
@@ -331,19 +304,19 @@ Tournament::Tournament(
current_state(State::REGISTRATION),
menu_item_id(0xFFFFFFFF) {
if (this->num_teams < 4) {
throw invalid_argument("team count must be 4 or more");
throw std::invalid_argument("team count must be 4 or more");
}
if (this->num_teams > 32) {
throw invalid_argument("team count must be 32 or fewer");
throw std::invalid_argument("team count must be 32 or fewer");
}
if (this->num_teams & (this->num_teams - 1)) {
throw invalid_argument("team count must be a power of 2");
throw std::invalid_argument("team count must be a power of 2");
}
}
Tournament::Tournament(
shared_ptr<const MapIndex> map_index,
shared_ptr<const COMDeckIndex> com_deck_index,
std::shared_ptr<const MapIndex> map_index,
std::shared_ptr<const COMDeckIndex> com_deck_index,
const phosg::JSON& json)
: log(std::format("[Tournament:{}] ", json.get_string("name"))),
map_index(map_index),
@@ -352,12 +325,12 @@ Tournament::Tournament(
current_state(State::REGISTRATION) {}
void Tournament::init() {
vector<size_t> team_index_to_rounds_cleared;
std::vector<size_t> team_index_to_rounds_cleared;
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)) {
@@ -366,7 +339,7 @@ void Tournament::init() {
is_registration_complete = this->source_json.get_bool("is_registration_complete");
for (const auto& team_json : this->source_json.get_list("teams")) {
auto& team = this->teams.emplace_back(make_shared<Team>(
auto& team = this->teams.emplace_back(std::make_shared<Team>(
this->shared_from_this(), this->teams.size(), team_json->get_int("max_players")));
team->name = team_json->get_string("name");
team->password = team_json->get_string("password");
@@ -383,7 +356,7 @@ void Tournament::init() {
} else if (player_json->is_string()) {
team->players.emplace_back(this->com_deck_index->deck_for_name(player_json->as_string()));
} else {
throw runtime_error("invalid player spec");
throw std::runtime_error("invalid player spec");
}
}
}
@@ -394,8 +367,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 = std::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;
@@ -407,12 +379,12 @@ void Tournament::init() {
this->create_bracket_matches();
// Start with all zero-round matches in the match queue
unordered_set<shared_ptr<Match>> match_queue;
std::unordered_set<std::shared_ptr<Match>> match_queue;
for (auto match : this->zero_round_matches) {
match_queue.emplace(match->following.lock());
}
if (match_queue.count(nullptr)) {
throw logic_error("null match in match queue");
throw std::logic_error("null match in match queue");
}
// For each match in the queue, either resolve it from the previous state or
@@ -423,12 +395,12 @@ void Tournament::init() {
match_queue.erase(match_it);
if (!match->preceding_a->winner_team || !match->preceding_b->winner_team) {
throw logic_error("preceding matches are not resolved");
throw std::logic_error("preceding matches are not resolved");
}
size_t& a_rounds_cleared = team_index_to_rounds_cleared[match->preceding_a->winner_team->index];
size_t& b_rounds_cleared = team_index_to_rounds_cleared[match->preceding_b->winner_team->index];
if (a_rounds_cleared && b_rounds_cleared) {
throw runtime_error("both teams won the same match");
throw std::runtime_error("both teams won the same match");
}
if (!a_rounds_cleared && !b_rounds_cleared) {
this->pending_matches.emplace(match); // Neither team has won yet
@@ -444,16 +416,14 @@ 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);
}
}
}
if (!this->final_match->winner_team == this->pending_matches.empty()) {
throw logic_error("there must be pending matches if and only if the final match is not resolved");
throw std::logic_error("there must be pending matches if and only if the final match is not resolved");
}
// If all matches are resolved, then the tournament is complete
@@ -468,20 +438,19 @@ void Tournament::init() {
void Tournament::create_bracket_matches() {
if (this->teams.size() < 4) {
throw logic_error("tournaments must have at least 4 teams");
throw std::logic_error("tournaments must have at least 4 teams");
}
if (this->teams.size() > 32) {
throw logic_error("tournaments must have at most 32 teams");
throw std::logic_error("tournaments must have at most 32 teams");
}
if (this->teams.size() & (this->teams.size() - 1)) {
throw logic_error("tournaments team count is not a power of 2");
throw std::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);
auto m = std::make_shared<Match>(this->shared_from_this(), team);
this->zero_round_matches.emplace_back(m);
if (this->current_state == State::REGISTRATION) {
this->pending_matches.emplace(m);
@@ -489,14 +458,11 @@ void Tournament::create_bracket_matches() {
}
// Create the bracket matches
vector<shared_ptr<Match>> current_round_matches = this->zero_round_matches;
std::vector<std::shared_ptr<Match>> current_round_matches = this->zero_round_matches;
while (current_round_matches.size() > 1) {
vector<shared_ptr<Match>> next_round_matches;
std::vector<std::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 = std::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));
@@ -539,42 +505,39 @@ phosg::JSON Tournament::json() const {
});
}
shared_ptr<Tournament::Team> Tournament::get_winner_team() const {
std::shared_ptr<Tournament::Team> Tournament::get_winner_team() const {
if (this->current_state != State::COMPLETE) {
return nullptr;
}
if (!this->final_match) {
throw logic_error("tournament is complete but final match is missing");
throw std::logic_error("tournament is complete but final match is missing");
}
if (!this->final_match->winner_team) {
throw logic_error("tournament is complete but winner is not set");
throw std::logic_error("tournament is complete but winner is not set");
}
return this->final_match->winner_team;
}
shared_ptr<Tournament::Match> Tournament::next_match_for_team(
shared_ptr<Team> team) const {
std::shared_ptr<Tournament::Match> Tournament::next_match_for_team(std::shared_ptr<Team> team) const {
if (this->current_state == Tournament::State::REGISTRATION) {
return nullptr;
}
for (auto match : this->pending_matches) {
if (!match->preceding_a || !match->preceding_b) {
throw logic_error("zero-round match is pending after tournament registration phase");
throw std::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;
}
}
return nullptr;
}
shared_ptr<Tournament::Match> Tournament::get_final_match() const {
std::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 {
std::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;
}
@@ -587,23 +550,22 @@ shared_ptr<Tournament::Team> Tournament::team_for_account_id(
}
}
throw logic_error("account ID registered in tournament but not in any team");
throw std::logic_error("account ID registered in tournament but not in any team");
}
const set<uint32_t>& Tournament::get_all_player_account_ids() const {
const std::set<uint32_t>& Tournament::get_all_player_account_ids() const {
return this->all_player_account_ids;
}
void Tournament::start() {
if (this->current_state != State::REGISTRATION) {
throw runtime_error("tournament has already started");
throw std::runtime_error("tournament has already started");
}
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()) {
@@ -611,13 +573,12 @@ void Tournament::start() {
}
}
if (num_human_teams < (has_com_teams ? 1 : 2)) {
throw runtime_error("not enough registrants to start tournament");
throw std::runtime_error("not enough registrants to start tournament");
}
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 +591,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 +622,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;
@@ -671,17 +631,15 @@ void Tournament::start() {
}
for (const auto& player : t->players) {
if (player.is_com()) {
throw logic_error("non-human player on team before tournament start");
throw std::logic_error("non-human player on team before 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");
throw std::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 +656,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());
}
@@ -719,10 +676,10 @@ void Tournament::send_all_state_updates_on_deletion() const {
}
}
string Tournament::bracket_str() const {
string ret = std::format("Tournament \"{}\"\n", this->name);
std::string Tournament::bracket_str() const {
std::string ret = std::format("Tournament \"{}\"\n", this->name);
function<void(shared_ptr<Match>, size_t)> add_match = [&](shared_ptr<Match> m, size_t indent_level) -> void {
std::function<void(std::shared_ptr<Match>, size_t)> add_match = [&](std::shared_ptr<Match> m, size_t indent_level) -> void {
ret.append(2 * indent_level, ' ');
ret += m->str();
if (this->pending_matches.count(m)) {
@@ -737,15 +694,14 @@ 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);
std::string map_name = en_vm->map->name.decode(en_vm->language);
ret += std::format(" Map: {:08X} ({})\n", this->map->map_number, map_name);
} else {
ret += std::format(" Map: {:08X}\n", this->map->map_number);
}
string rules_str = this->rules.str();
ret += std::format(" Rules: {}\n", rules_str);
ret += std::format(" Rules: {}\n", this->rules.str());
ret += std::format(" Structure: {}, {} entries\n", (this->flags & Flag::IS_2V2) ? "2v2" : "1v1", this->num_teams);
ret += std::format(" COM teams: {}\n", (this->flags & Flag::HAS_COM_TEAMS) ? "allowed" : "forbidden");
ret += std::format(" Shuffle entries: {}\n", (this->flags & Flag::SHUFFLE_ENTRIES) ? "yes" : "no");
@@ -771,14 +727,12 @@ string Tournament::bracket_str() const {
if (this->current_state == State::REGISTRATION) {
ret += " Teams:\n";
for (const auto& team : this->teams) {
string team_str = team->str();
ret += std::format(" {}\n", team_str);
ret += std::format(" {}\n", team->str());
}
} else {
ret += " Pending matches:\n";
for (const auto& match : this->pending_matches) {
string match_str = match->str();
ret += std::format(" {}\n", match_str);
ret += std::format(" {}\n", match->str());
}
}
@@ -787,13 +741,11 @@ string Tournament::bracket_str() const {
}
TournamentIndex::TournamentIndex(
shared_ptr<const MapIndex> map_index,
shared_ptr<const COMDeckIndex> com_deck_index,
const string& state_filename,
std::shared_ptr<const MapIndex> map_index,
std::shared_ptr<const COMDeckIndex> com_deck_index,
const std::string& state_filename,
bool skip_load_state)
: map_index(map_index),
com_deck_index(com_deck_index),
state_filename(state_filename) {
: map_index(map_index), com_deck_index(com_deck_index), state_filename(state_filename) {
if (this->state_filename.empty() || skip_load_state) {
return;
}
@@ -807,14 +759,14 @@ TournamentIndex::TournamentIndex(
if (json.is_list()) {
if (json.size() > 0x20) {
throw runtime_error("tournament phosg::JSON list length is incorrect");
throw std::runtime_error("tournament phosg::JSON list length is incorrect");
}
for (size_t z = 0; z < min<size_t>(json.size(), 0x20); z++) {
for (size_t z = 0; z < std::min<size_t>(json.size(), 0x20); z++) {
if (!json.at(z).is_null()) {
auto tourn = make_shared<Tournament>(this->map_index, this->com_deck_index, json.at(z));
auto tourn = std::make_shared<Tournament>(this->map_index, this->com_deck_index, json.at(z));
tourn->init();
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
throw runtime_error("multiple tournaments have the same name: " + tourn->get_name());
throw std::runtime_error("multiple tournaments have the same name: " + tourn->get_name());
}
tourn->set_menu_item_id(this->menu_item_id_to_tournament.size());
this->menu_item_id_to_tournament.emplace_back(tourn);
@@ -822,21 +774,20 @@ TournamentIndex::TournamentIndex(
}
} else if (json.is_dict()) {
if (json.size() > 0x20) {
throw runtime_error("tournament phosg::JSON dict length is incorrect");
throw std::runtime_error("tournament phosg::JSON dict length is incorrect");
}
for (const auto& it : json.as_dict()) {
auto tourn = make_shared<Tournament>(this->map_index, this->com_deck_index, *it.second);
auto tourn = std::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
throw logic_error("multiple tournaments have the same name: " + tourn->get_name());
// This is logic_error instead of runtime_error because phosg::JSON dicts already have unique keys
throw std::logic_error("multiple tournaments have the same name: " + tourn->get_name());
}
tourn->set_menu_item_id(this->menu_item_id_to_tournament.size());
this->menu_item_id_to_tournament.emplace_back(tourn);
}
} else {
throw runtime_error("tournament state root phosg::JSON is not a list or dict");
throw std::runtime_error("tournament state root phosg::JSON is not a list or dict");
}
}
@@ -852,21 +803,20 @@ void TournamentIndex::save() const {
phosg::save_file(this->state_filename, json.serialize(phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS | phosg::JSON::SerializeOption::ESCAPE_CONTROLS_ONLY));
}
shared_ptr<Tournament> TournamentIndex::create_tournament(
const string& name,
shared_ptr<const MapIndex::Map> map,
std::shared_ptr<Tournament> TournamentIndex::create_tournament(
const std::string& name,
std::shared_ptr<const MapIndex::Map> map,
const Rules& rules,
size_t num_teams,
uint8_t flags) {
if (this->name_to_tournament.size() >= 0x20) {
throw runtime_error("there can be at most 32 tournaments at a time");
throw std::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 = std::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");
throw std::runtime_error("a tournament with the same name already exists");
}
size_t z;
@@ -886,7 +836,7 @@ shared_ptr<Tournament> TournamentIndex::create_tournament(
return t;
}
bool TournamentIndex::delete_tournament(const string& name) {
bool TournamentIndex::delete_tournament(const std::string& name) {
auto it = this->name_to_tournament.find(name);
if (it == this->name_to_tournament.end()) {
return false;
@@ -903,7 +853,7 @@ bool TournamentIndex::delete_tournament(const string& name) {
return true;
}
shared_ptr<Tournament::Team> TournamentIndex::team_for_account_id(uint32_t account_id) const {
std::shared_ptr<Tournament::Team> TournamentIndex::team_for_account_id(uint32_t account_id) const {
for (const auto& it : this->name_to_tournament) {
const auto& tourn = it.second;
auto team = tourn->team_for_account_id(account_id);
@@ -914,7 +864,7 @@ shared_ptr<Tournament::Team> TournamentIndex::team_for_account_id(uint32_t accou
return nullptr;
}
void TournamentIndex::link_client(shared_ptr<Client> c) {
void TournamentIndex::link_client(std::shared_ptr<Client> c) {
if (!is_ep3(c->version())) {
return;
}
@@ -932,7 +882,7 @@ void TournamentIndex::link_client(shared_ptr<Client> c) {
return;
}
}
throw logic_error("tournament team found for player, but player not found on team");
throw std::logic_error("tournament team found for player, but player not found on team");
} else {
c->ep3_tournament_team.reset();
if (c->version() == Version::GC_EP3) {
@@ -942,8 +892,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);
+9 -19
View File
@@ -13,7 +13,7 @@
struct Lobby;
class Client;
struct ServerState;
class ServerState;
namespace Episode3 {
@@ -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;
-91
View File
@@ -1,91 +0,0 @@
#include "FileContentsCache.hh"
#include <unistd.h>
#include <phosg/Filesystem.hh>
#include <phosg/Time.hh>
using namespace std;
FileContentsCache::FileContentsCache(uint64_t ttl_usecs) : ttl_usecs(ttl_usecs) {}
FileContentsCache::File::File(
const string& name,
string&& data,
uint64_t load_time)
: name(name),
data(make_shared<string>(std::move(data))),
load_time(load_time) {}
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
const string& name, string&& data, uint64_t t) {
if (t == 0) {
t = phosg::now();
}
auto new_file = make_shared<File>(name, std::move(data), t);
auto emplace_ret = this->name_to_file.emplace(name, new_file);
if (!emplace_ret.second) {
emplace_ret.first->second = new_file;
}
return new_file;
}
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
const string& name, const void* data, size_t size, uint64_t t) {
string s(reinterpret_cast<const char*>(data), size);
return this->replace(name, std::move(s), t);
}
FileContentsCache::GetResult FileContentsCache::get_or_load(const std::string& name) {
return this->get(name, phosg::load_file);
}
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) {
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) {
return this->get_or_throw(string(name));
}
FileContentsCache::GetResult FileContentsCache::get(const std::string& name,
std::function<std::string(const std::string&)> generate) {
uint64_t t = phosg::now();
try {
auto& entry = this->name_to_file.at(name);
if (this->ttl_usecs && (t - entry->load_time < this->ttl_usecs)) {
return {entry, false};
}
} catch (const out_of_range& e) {
}
return {this->replace(name, generate(name)), true};
}
FileContentsCache::GetResult FileContentsCache::get(const char* name,
std::function<std::string(const std::string&)> generate) {
return this->get(string(name), generate);
}
shared_ptr<const string> ThreadSafeFileCache::get(
const string& name, std::function<shared_ptr<const string>(const std::string&)> generate) {
try {
shared_lock g(this->lock);
return this->name_to_file.at(name);
} catch (const out_of_range&) {
unique_lock g(this->lock);
auto it = this->name_to_file.find(name);
if (it == this->name_to_file.end()) {
it = this->name_to_file.emplace(name, generate(name)).first;
}
return it->second;
}
}
-124
View File
@@ -1,124 +0,0 @@
#pragma once
#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <unordered_map>
#include <phosg/Time.hh>
class FileContentsCache {
public:
struct File {
std::string name;
std::shared_ptr<const std::string> data;
uint64_t load_time;
File() = delete;
File(const std::string& name, std::string&& contents, uint64_t load_time);
File(const File&) = delete;
File(File&&) = delete;
File& operator=(const File&) = delete;
File& operator=(File&&) = delete;
~File() = default;
};
explicit FileContentsCache(uint64_t ttl_usecs);
FileContentsCache(const FileContentsCache&) = delete;
FileContentsCache(FileContentsCache&&) = delete;
FileContentsCache& operator=(const FileContentsCache&) = delete;
FileContentsCache& operator=(FileContentsCache&&) = delete;
~FileContentsCache() = default;
template <typename NameT>
bool delete_key(NameT key) {
return this->name_to_file.erase(key);
}
std::shared_ptr<const File> replace(const std::string& name, std::string&& data, uint64_t t = 0);
std::shared_ptr<const File> replace(const std::string& name, const void* data, size_t size, uint64_t t = 0);
struct GetResult {
std::shared_ptr<const File> file;
bool generate_called;
};
GetResult get_or_load(const std::string& name);
GetResult get_or_load(const char* name);
std::shared_ptr<const File> get_or_throw(const std::string& name);
std::shared_ptr<const File> get_or_throw(const char* name);
GetResult get(const std::string& name, std::function<std::string(const std::string&)> generate);
GetResult get(const char* name, std::function<std::string(const std::string&)> generate);
template <typename T>
struct GetObjResult {
const T& obj;
std::shared_ptr<const File> data;
bool generate_called;
};
template <typename T, typename NameT>
GetObjResult<T> get_obj_or_load(NameT name) {
auto res = this->get_or_load(name);
if (res.file->data->size() != sizeof(T)) {
throw std::runtime_error("cached string size is incorrect");
}
return {*reinterpret_cast<const T*>(res.file->data->data()), res.file, res.generate_called};
}
template <typename T, typename NameT>
GetObjResult<T> get_obj_or_throw(NameT name) {
auto res = this->get_or_throw(name);
if (res.file->data->size() != sizeof(T)) {
throw std::runtime_error("cached string size is incorrect");
}
return {*reinterpret_cast<const T*>(res.file->data->data()), res.file, res.generate_called};
}
template <typename T, typename NameT>
GetObjResult<T> get_obj(NameT name, std::function<T(const std::string&)> generate) {
uint64_t t = phosg::now();
try {
auto& f = this->name_to_file.at(name);
if (f->data->size() != sizeof(T)) {
throw std::runtime_error("cached string size is incorrect");
}
if (this->ttl_usecs && (t - f->load_time < this->ttl_usecs)) {
return {*reinterpret_cast<const T*>(f->data->data()), f, false};
}
} catch (const std::out_of_range& e) {
}
T value = generate(name);
auto ret = this->replace_obj(name, value);
ret.generate_called = true;
return ret;
}
template <typename T, typename NameT>
GetObjResult<T> replace_obj(NameT name, const T& value) {
auto cached_value = this->replace(name, &value, sizeof(value));
return {*reinterpret_cast<const T*>(cached_value->data->data()), cached_value, false};
}
private:
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
uint64_t ttl_usecs;
};
class ThreadSafeFileCache {
public:
explicit ThreadSafeFileCache() = default;
ThreadSafeFileCache(const ThreadSafeFileCache&) = delete;
ThreadSafeFileCache(ThreadSafeFileCache&&) = delete;
ThreadSafeFileCache& operator=(const ThreadSafeFileCache&) = delete;
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);
private:
std::shared_mutex lock;
std::unordered_map<std::string, std::shared_ptr<const std::string>> name_to_file;
};
-560
View File
@@ -1,560 +0,0 @@
#include "FunctionCompiler.hh"
#include <stdio.h>
#include <string.h>
#include <filesystem>
#include <phosg/Filesystem.hh>
#include <phosg/Hash.hh>
#include <phosg/Time.hh>
#include <stdexcept>
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/SH4Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#include "CommandFormats.hh"
#include "CommonFileFormats.hh"
#include "Compression.hh"
#include "Loggers.hh"
using namespace std;
const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
switch (arch) {
case CompiledFunctionCode::Architecture::POWERPC:
return "PowerPC";
case CompiledFunctionCode::Architecture::X86:
return "x86";
case CompiledFunctionCode::Architecture::SH4:
return "SH-4";
default:
throw logic_error("invalid architecture");
}
}
template <bool BE>
string CompiledFunctionCode::generate_client_command_t(
const unordered_map<string, uint32_t>& label_writes,
const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const {
using FooterT = RELFileFooterT<BE>;
FooterT footer;
footer.num_relocations = this->relocation_deltas.size();
footer.unused1.clear(0);
footer.root_offset = this->entrypoint_offset_offset;
footer.unused2.clear(0);
phosg::StringWriter w;
if (!label_writes.empty()) {
string modified_code = this->code;
for (const auto& it : label_writes) {
size_t offset = this->label_offsets.at(it.first);
if (offset > modified_code.size() - 4) {
throw runtime_error("label out of range");
}
*reinterpret_cast<U32T<FooterT::IsBE>*>(modified_code.data() + offset) = it.second;
}
w.write(modified_code);
} else {
w.write(this->code);
}
if (suffix_size) {
w.write(suffix_data, suffix_size);
}
while (w.size() & 3) {
w.put_u8(0);
}
footer.relocations_offset = w.size();
// Always write at least 4 bytes even if there are no relocations
if (this->relocation_deltas.empty()) {
w.put_u32(0);
}
if (override_relocations_offset) {
footer.relocations_offset = override_relocations_offset;
} else {
for (uint16_t delta : this->relocation_deltas) {
w.put<U16T<FooterT::IsBE>>(delta);
}
if (this->relocation_deltas.size() & 1) {
w.put_u16(0);
}
}
w.put(footer);
return std::move(w.str());
}
string CompiledFunctionCode::generate_client_command(
const unordered_map<string, uint32_t>& label_writes,
const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const {
if (this->arch == Architecture::POWERPC) {
return this->generate_client_command_t<true>(label_writes, suffix_data, suffix_size, override_relocations_offset);
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
return this->generate_client_command_t<false>(label_writes, suffix_data, suffix_size, override_relocations_offset);
} else {
throw logic_error("invalid architecture");
}
}
bool CompiledFunctionCode::is_big_endian() const {
return this->arch == Architecture::POWERPC;
}
static vector<shared_ptr<CompiledFunctionCode>> compile_function_code(
CompiledFunctionCode::Architecture arch,
const string& function_directory,
const string& system_directory,
const string& name,
const string& text) {
unordered_set<string> get_include_stack;
function<string(const string&)> get_include = [&](const string& name) -> string {
const char* arch_name_token;
switch (arch) {
case CompiledFunctionCode::Architecture::POWERPC:
arch_name_token = "ppc";
break;
case CompiledFunctionCode::Architecture::X86:
arch_name_token = "x86";
break;
case CompiledFunctionCode::Architecture::SH4:
arch_name_token = "sh4";
break;
default:
throw runtime_error("unknown architecture");
}
// Look in the function directory first, then the system directory
string asm_filename = std::format("{}/{}.{}.inc.s", function_directory, name, arch_name_token);
if (!std::filesystem::is_regular_file(asm_filename)) {
asm_filename = std::format("{}/{}.{}.inc.s", system_directory, name, arch_name_token);
}
if (std::filesystem::is_regular_file(asm_filename)) {
if (!get_include_stack.emplace(name).second) {
throw runtime_error("mutual recursion between includes: " + name);
}
ResourceDASM::EmulatorBase::AssembleResult ret;
switch (arch) {
case CompiledFunctionCode::Architecture::POWERPC:
ret = ResourceDASM::PPC32Emulator::assemble(phosg::load_file(asm_filename), get_include);
break;
case CompiledFunctionCode::Architecture::X86:
ret = ResourceDASM::X86Emulator::assemble(phosg::load_file(asm_filename), get_include);
break;
case CompiledFunctionCode::Architecture::SH4:
ret = ResourceDASM::SH4Emulator::assemble(phosg::load_file(asm_filename), get_include);
break;
default:
throw runtime_error("unknown architecture");
}
get_include_stack.erase(name);
return ret.code;
}
string bin_filename = function_directory + "/" + name + ".inc.bin";
if (std::filesystem::is_regular_file(bin_filename)) {
return phosg::load_file(bin_filename);
}
bin_filename = system_directory + "/" + name + ".inc.bin";
if (std::filesystem::is_regular_file(bin_filename)) {
return phosg::load_file(bin_filename);
}
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"));
}
}
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);
try {
ResourceDASM::EmulatorBase::AssembleResult assembled;
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
assembled = ResourceDASM::PPC32Emulator::assemble(version_text, get_include);
} else if (arch == CompiledFunctionCode::Architecture::X86) {
assembled = ResourceDASM::X86Emulator::assemble(version_text, get_include);
} else if (arch == CompiledFunctionCode::Architecture::SH4) {
assembled = ResourceDASM::SH4Emulator::assemble(version_text, get_include);
} else {
throw runtime_error("invalid architecture");
}
auto compiled = ret.emplace_back(make_shared<CompiledFunctionCode>());
compiled->arch = arch;
compiled->short_name = name;
compiled->specific_version = specific_version;
compiled->code = std::move(assembled.code);
compiled->label_offsets = std::move(assembled.label_offsets);
for (const auto& it : assembled.metadata_keys) {
if (it.first == "hide_from_patches_menu") {
compiled->hide_from_patches_menu = true;
} else if (it.first == "name") {
compiled->long_name = it.second;
} else if (it.first == "description") {
compiled->description = it.second;
} else if (it.first == "client_flag") {
compiled->client_flag = stoull(it.second, nullptr, 0);
} else {
throw runtime_error("unknown metadata key: " + it.first);
}
}
set<uint32_t> reloc_indexes;
for (const auto& it : compiled->label_offsets) {
if (it.first.starts_with("reloc")) {
reloc_indexes.emplace(it.second / 4);
}
}
try {
compiled->entrypoint_offset_offset = compiled->label_offsets.at("entry_ptr");
} catch (const out_of_range&) {
throw runtime_error("code does not contain entry_ptr label");
}
uint32_t prev_index = 0;
for (const auto& it : reloc_indexes) {
uint32_t delta = it - prev_index;
if (delta > 0xFFFF) {
throw runtime_error("relocation delta too far away");
}
compiled->relocation_deltas.emplace_back(delta);
prev_index = it;
}
} catch (const exception& e) {
string version_str = specific_version ? (" (" + str_for_specific_version(specific_version) + ")") : "";
function_compiler_log.warning_f("Failed to compile function {}{}: {}", name, version_str, e.what());
}
}
return ret;
}
FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
string system_dir_path = directory.ends_with("/") ? (directory + "System") : (directory + "/System");
uint32_t next_menu_item_id = 1;
for (const auto& item : std::filesystem::directory_iterator(directory)) {
string subdir_name = item.path().filename().string();
string subdir_path = directory.ends_with("/") ? (directory + subdir_name) : (directory + "/" + subdir_name);
auto add_file = [&](string filename) -> void {
try {
if (!filename.ends_with(".s")) {
return;
}
string name = filename.substr(0, filename.size() - 2);
if (name.ends_with(".inc")) {
return;
}
bool is_patch = name.ends_with(".patch");
if (is_patch) {
name.resize(name.size() - 6);
}
// Figure out the version or specific_version
CompiledFunctionCode::Architecture arch = CompiledFunctionCode::Architecture::UNKNOWN;
uint32_t specific_version = 0;
string short_name = name;
if (name.ends_with(".ppc")) {
arch = CompiledFunctionCode::Architecture::POWERPC;
name.resize(name.size() - 4);
short_name = name;
} else if (name.ends_with(".x86")) {
arch = CompiledFunctionCode::Architecture::X86;
name.resize(name.size() - 4);
short_name = name;
} else if (name.ends_with(".sh4")) {
arch = CompiledFunctionCode::Architecture::SH4;
name.resize(name.size() - 4);
short_name = name;
} else if (is_patch && (name.size() >= 5) && (name[name.size() - 5] == '.')) {
specific_version = (name[name.size() - 4] << 24) | (name[name.size() - 3] << 16) | (name[name.size() - 2] << 8) | name[name.size() - 1];
if (specific_version_is_dc(specific_version)) {
arch = CompiledFunctionCode::Architecture::SH4;
} else if (specific_version_is_gc(specific_version)) {
arch = CompiledFunctionCode::Architecture::POWERPC;
} else if (specific_version_is_pc_v2(specific_version) ||
specific_version_is_xb(specific_version) ||
specific_version_is_bb(specific_version)) {
arch = CompiledFunctionCode::Architecture::X86;
} else {
throw runtime_error("unable to determine architecture from specific_version");
}
short_name = name.substr(0, name.size() - 5);
}
if (arch == CompiledFunctionCode::Architecture::UNKNOWN) {
throw runtime_error("unable to determine architecture");
}
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)) {
if (code->specific_version == 0) {
code->specific_version = specific_version;
}
code->source_path = path;
code->short_name = short_name;
this->name_to_function.emplace(name, code);
if (is_patch) {
code->menu_item_id = next_menu_item_id++;
this->menu_item_id_and_specific_version_to_patch_function.emplace(
static_cast<uint64_t>(code->menu_item_id) << 32 | code->specific_version, code);
this->name_and_specific_version_to_patch_function.emplace(
std::format("{}-{:08X}", code->short_name, code->specific_version), code);
}
string patch_prefix = is_patch ? std::format("[{:08X}] ", code->menu_item_id) : "";
function_compiler_log.debug_f("Compiled function {}{} ({}; {})",
patch_prefix, name, str_for_specific_version(code->specific_version), name_for_architecture(code->arch));
}
} catch (const exception& e) {
function_compiler_log.warning_f("Failed to compile function {}: {}", filename, e.what());
}
};
if (std::filesystem::is_regular_file(subdir_path)) {
add_file(subdir_path);
} else if (std::filesystem::is_directory(subdir_path)) {
for (const auto& item : std::filesystem::directory_iterator(subdir_path)) {
string filename = item.path().filename().string();
add_file(filename);
}
} else {
function_compiler_log.warning_f("Skipping {} (unknown file type)", subdir_name);
continue;
}
}
}
shared_ptr<const Menu> FunctionCodeIndex::patch_switches_menu(
uint32_t specific_version,
const std::unordered_set<std::string>& server_auto_patches_enabled,
const std::unordered_set<std::string>& client_auto_patches_enabled) const {
auto suffix = std::format("-{:08X}", specific_version);
auto ret = make_shared<Menu>(MenuID::PATCH_SWITCHES, "Patches");
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
for (const auto& it : this->name_and_specific_version_to_patch_function) {
const auto& fn = it.second;
if (fn->hide_from_patches_menu || !it.first.ends_with(suffix) || server_auto_patches_enabled.count(fn->short_name)) {
continue;
}
string name;
name.push_back(client_auto_patches_enabled.count(fn->short_name) ? '*' : '-');
name += fn->long_name.empty() ? fn->short_name : fn->long_name;
ret->items.emplace_back(fn->menu_item_id, name, fn->description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
}
return ret;
}
bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
uint32_t mask = specific_version_is_indeterminate(specific_version) ? 0xFF000000 : 0xFFFFFFFF;
for (const auto& it : this->menu_item_id_and_specific_version_to_patch_function) {
if ((it.first & mask) == (specific_version & mask)) {
return false;
}
}
return true;
}
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));
}
DOLFileIndex::DOLFileIndex(const string& directory) {
if (!std::filesystem::is_directory(directory)) {
function_compiler_log.info_f("DOL file directory is missing");
return;
}
auto menu = make_shared<Menu>(MenuID::PROGRAMS, "Programs");
this->menu = menu;
menu->items.emplace_back(ProgramsMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
uint32_t next_menu_item_id = 0;
for (const auto& item : std::filesystem::directory_iterator(directory)) {
string filename = item.path().filename().string();
bool is_dol = filename.ends_with(".dol");
bool is_compressed_dol = filename.ends_with(".dol.prs");
if (!is_dol && !is_compressed_dol) {
continue;
}
string name = filename.substr(0, filename.size() - (is_compressed_dol ? 8 : 4));
try {
auto dol = make_shared<File>();
dol->menu_item_id = next_menu_item_id++;
dol->name = name;
string path = directory + "/" + filename;
string file_data = phosg::load_file(path);
string description;
if (is_compressed_dol) {
size_t decompressed_size = prs_decompress_size(file_data);
phosg::StringWriter w;
w.put_u32b(file_data.size());
w.put_u32b(decompressed_size);
w.write(file_data);
while (w.size() & 3) {
w.put_u8(0);
}
dol->data = std::move(w.str());
string compressed_size_str = phosg::format_size(file_data.size());
string decompressed_size_str = phosg::format_size(decompressed_size);
function_compiler_log.debug_f("Loaded compressed DOL file {} ({} -> {})",
dol->name, compressed_size_str, decompressed_size_str);
description = std::format("$C6{}$C7\n{}\n{} (orig)", dol->name, compressed_size_str, decompressed_size_str);
} else {
phosg::StringWriter w;
w.put_u32b(0);
w.put_u32b(file_data.size());
w.write(file_data);
while (w.size() & 3) {
w.put_u8(0);
}
dol->data = std::move(w.str());
string size_str = phosg::format_size(dol->data.size());
function_compiler_log.debug_f("Loaded DOL file {} ({})", filename, size_str);
description = std::format("$C6{}$C7\n{}", dol->name, size_str);
}
this->name_to_file.emplace(dol->name, dol);
this->item_id_to_file.emplace_back(dol);
menu->items.emplace_back(dol->menu_item_id, dol->name, description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL_RUNS_CODE);
} catch (const exception& e) {
function_compiler_log.warning_f("Failed to load DOL file {}: {}", filename, e.what());
}
}
}
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum) {
static unordered_map<uint32_t, uint32_t> checksum_to_specific_version;
if (checksum_to_specific_version.empty()) {
struct {
char system_code = 'G';
char game_code1 = 'P';
char game_code2;
char region_code;
char developer_code1 = '8';
char developer_code2 = 'P';
uint8_t disc_number = 0;
uint8_t version_code;
} __attribute__((packed)) data;
for (const char* game_code2 = "OS"; *game_code2; game_code2++) {
data.game_code2 = *game_code2;
for (const char* region_code = "JEP"; *region_code; region_code++) {
data.region_code = *region_code;
for (uint8_t version_code = 0; version_code < 8; version_code++) {
data.version_code = version_code;
uint32_t checksum = phosg::crc32(&data, sizeof(data));
uint32_t specific_version = 0x33000030 | (*game_code2 << 16) | (*region_code << 8) | version_code;
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
throw logic_error("multiple specific_versions have same header checksum");
}
}
}
{
// Generate entries for Trial Editions
data.region_code = 'J';
data.system_code = 'D';
data.version_code = 0;
uint32_t checksum = phosg::crc32(&data, sizeof(data));
uint32_t specific_version = 0x33004A54 | (*game_code2 << 16);
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
throw logic_error("multiple specific_versions have same header checksum");
}
data.system_code = 'G';
}
}
}
return checksum_to_specific_version.at(header_checksum);
}
-94
View File
@@ -1,94 +0,0 @@
#pragma once
#include <inttypes.h>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "Menu.hh"
// TODO: Support x86 and SH4 function calls in the future. Currently we only
// support PPC32 because I haven't written an appropriate x86 assembler yet.
struct CompiledFunctionCode {
enum class Architecture {
UNKNOWN = 0,
POWERPC, // GC
X86, // PC, XB, BB
SH4, // Dreamcast
};
Architecture arch;
std::string code;
std::vector<uint16_t> relocation_deltas;
std::unordered_map<std::string, uint32_t> label_offsets;
uint32_t entrypoint_offset_offset = 0;
std::string source_path; // Path to source file from newserv root
std::string short_name; // Based on filename
std::string long_name; // From .meta name directive
std::string description; // From .meta description directive
uint64_t client_flag = 0; // From .meta client_flag directive
uint32_t menu_item_id = 0;
bool hide_from_patches_menu = false;
uint32_t specific_version = 0; // 0 = not a client-selectable patch
bool is_big_endian() const;
template <bool BE>
std::string generate_client_command_t(
const std::unordered_map<std::string, uint32_t>& label_writes,
const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const;
std::string generate_client_command(
const std::unordered_map<std::string, uint32_t>& label_writes = {},
const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const;
};
const char* name_for_architecture(CompiledFunctionCode::Architecture arch);
struct FunctionCodeIndex {
FunctionCodeIndex() = default;
explicit FunctionCodeIndex(const std::string& directory);
std::unordered_map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_function;
std::unordered_map<uint8_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
std::unordered_map<uint64_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_and_specific_version_to_patch_function;
// Key here is e.g. "PATCHNAME-SPECIFICVERSION", with the latter in hex
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
std::shared_ptr<const Menu> patch_switches_menu(
uint32_t specific_version,
const std::unordered_set<std::string>& server_auto_patches_enabled,
const std::unordered_set<std::string>& client_auto_patches_enabled) const;
bool patch_menu_empty(uint32_t specific_version) const;
std::shared_ptr<const CompiledFunctionCode> get_patch(const std::string& name, uint32_t specific_version) const;
};
struct DOLFileIndex {
struct File {
uint32_t menu_item_id;
std::string name;
std::string data;
bool is_compressed;
};
std::vector<std::shared_ptr<File>> item_id_to_file;
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
std::shared_ptr<const Menu> menu;
DOLFileIndex() = default;
explicit DOLFileIndex(const std::string& directory);
inline bool empty() const {
return this->name_to_file.empty() && this->item_id_to_file.empty();
}
};
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);

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