Compare commits

...

744 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
Martin Michelsen 2bab3f2f8f fix episode 4 boss drops
Docker / Build (push) Has been cancelled
2025-09-30 23:19:44 -07:00
Martin Michelsen fdd0bfea08 rewrite quest metadata indexing
- split ep3 download quests from quest index
- fix Ep3 NTE download quests
- automatically detect battle/challenge params and area remaps
2025-09-28 23:26:14 -07:00
Martin Michelsen 48c225366f rewrite trade sequence 2025-09-26 21:45:24 -07:00
Martin Michelsen 0d88253334 add deadzone hint to font bitmap decoder 2025-09-26 21:45:04 -07:00
Martin Michelsen d7b17aa383 update some notes 2025-09-26 21:44:44 -07:00
Martin Michelsen ba131ab94a handle 6xE2 full inventory case 2025-09-25 21:20:48 -07:00
Martin Michelsen 648d9c5164 remove leader check on 6x17 2025-09-25 09:06:53 -07:00
Martin Michelsen 60487daf6f fix 6x17 checks for Vol Opt arena 2025-09-24 21:02:05 -07:00
Martin Michelsen e0c43836b3 add English AR code for Ep1&2 Trial 2025-09-22 18:05:42 -07:00
Martin Michelsen 719a403b1d show dmc patch in patches menu 2025-09-22 18:05:42 -07:00
Martin Michelsen 6f88c3d31a fix size field in 6xDD 2025-09-22 09:20:45 -07:00
Martin Michelsen 7114798e69 fix size check on 6xDD extension 2025-09-21 17:18:42 -07:00
Martin Michelsen 65384435a3 add extension for fractional EXP multipliers on BB 2025-09-21 13:16:28 -07:00
Martin Michelsen 4236ff62b1 add ep1 boss rush test 2025-09-19 09:16:28 -07:00
Martin Michelsen 277be9bcd6 obscure security updates 2025-09-18 23:48:14 -07:00
Martin Michelsen 9493e2d3e7 add some ar codes 2025-09-18 21:51:55 -07:00
Martin Michelsen 16b15162d5 add decrypt_pr1_data 2025-09-16 08:39:19 -07:00
Martin Michelsen 9854b93d02 support AFS tables in convert-common-item-set 2025-09-16 08:39:12 -07:00
Martin Michelsen d02ab1e7a5 add node about D5 non-repeatability on BB 2025-09-16 08:38:49 -07:00
Martin Michelsen e0c8ca677f add Windows build outline 2025-09-14 21:03:42 -07:00
Martin Michelsen 2cea44f790 add Ep3 JP subcommands in handler-tables 2025-09-14 13:37:39 -07:00
Martin Michelsen fb783034bc handle incorrect flags in 10 command 2025-09-14 13:04:42 -07:00
Martin Michelsen 40a6f49b29 fix crossplay challenge restart logic 2025-09-13 22:38:32 -07:00
Martin Michelsen dea0ac99c3 update some command notes 2025-09-13 22:38:27 -07:00
Martin Michelsen 24cf8e73c6 fix incorrect symlink on q080-gcn 2025-09-12 23:50:47 -07:00
Martin Michelsen c301a921e6 assume all GC NTE quests are Episode 1 2025-09-12 23:50:47 -07:00
Martin Michelsen 22d7825ba3 handle devil's/demon's in EnemyDamageSync 2025-09-12 23:45:51 -07:00
Martin Michelsen 526bfb64e5 fix memcpy call that gcc is unhappy with 2025-09-11 16:17:38 -07:00
Martin Michelsen 55cbf6e20b fix out-of-bounds access in 6x46, etc. 2025-09-11 10:14:39 -07:00
Martin Michelsen 0b86ffb227 fix use-after-free in AsyncPromise 2025-09-11 10:14:39 -07:00
Matt Swift e28596c825 Add Aberrant Grove custom quest 2025-09-11 09:31:14 -07:00
Matt Swift 716676b87d Add GC NTE quest symlinks 2025-09-11 09:31:14 -07:00
Martin Michelsen 5ca0265c37 remove unused argument 2025-09-10 22:10:47 -07:00
Martin Michelsen c7a0873ca8 fix cross-floor commands in EnemyDamageSync 2025-09-10 21:15:22 -07:00
Martin Michelsen b1d51cdbbe fix visibility for some patches 2025-09-09 23:18:09 -07:00
Martin Michelsen 5a7151bc63 minor proxy bugfixes 2025-09-09 23:18:01 -07:00
Martin Michelsen 49d861919f update some notes 2025-09-06 22:53:59 -07:00
Martin Michelsen 3f20c4239f remove cmake from explicit-install list in GH Actions script 2025-09-02 21:37:58 -07:00
Martin Michelsen 038f306661 update notes on some 6xB5 subcommands 2025-09-02 21:34:39 -07:00
Martin Michelsen 0575f3c9cf fix windows build 2025-09-02 21:34:19 -07:00
Martin Michelsen e37307acb3 fix bank load function when index not set 2025-08-29 18:49:32 -07:00
Martin Michelsen 4b32b41183 add note in readme about xbox connectivity 2025-08-29 10:33:51 -07:00
Martin Michelsen c8f8a6f65b clean up legacy format notes 2025-08-26 23:54:56 -07:00
Martin Michelsen 0c93275e88 describe some esoteric NTE and 11/2000 commands 2025-08-24 22:47:33 -07:00
Martin Michelsen c44ab27c7e update some command notes 2025-08-24 18:17:39 -07:00
Martin Michelsen 3f09a7b57b add version checks around bank access 2025-08-24 17:28:26 -07:00
Martin Michelsen 0b4d5b2f89 add BB BankSize patch 2025-08-22 22:39:32 -07:00
Martin Michelsen 45824b46fe support per-quest common and rare tables 2025-08-22 14:09:41 -07:00
Martin Michelsen e78f3142e3 update comment on send_lobby_list 2025-08-21 10:37:35 -07:00
Martin Michelsen 4166149841 add player check in HungryMagSound 2025-08-19 23:18:03 -07:00
Martin Michelsen 45131dabc0 fix dice range parsing in create-tournament 2025-08-19 20:22:41 -07:00
Martin Michelsen b235644575 expand leaf containers in text set serialization 2025-08-15 12:54:13 -07:00
Martin Michelsen 377d8beac3 implement $switchchar command 2025-08-14 23:44:16 -07:00
Martin Michelsen 16bff52575 update comments in expand_rate 2025-08-13 11:51:35 -07:00
Martin Michelsen 49fb7eba60 fix $bank when used with MoreSaveSlots 2025-08-13 11:42:20 -07:00
Martin Michelsen 00b46d7161 update game_flags notes 2025-08-13 11:42:07 -07:00
Martin Michelsen 5bea9d3a2b add warning about crossplay + stack limits 2025-08-07 00:00:25 -07:00
Martin Michelsen a9dcd4b87e enforce stack limits when loading BB character data
Docker / Build (push) Has been cancelled
2025-08-06 21:23:30 -07:00
Martin Michelsen 5c84581978 add names in show-battle-params 2025-08-06 21:03:20 -07:00
Martin Michelsen ab38a58e39 mention address config in readme 2025-08-06 21:02:30 -07:00
Martin Michelsen d430112a94 support chat shell command for non-proxy clients 2025-07-27 14:18:48 -07:00
Martin Michelsen 0cf59f874d use remote_addr for SocketChannel in send_reconnect 2025-07-26 16:54:13 -07:00
Martin Michelsen bf028ed0f6 fix data2 handling in 30 command from GetExtendedPlayerInfo 2025-07-24 21:37:36 -07:00
Martin Michelsen 1ecc41dea9 format show-item-tables output more cleanly 2025-07-24 18:38:14 -07:00
Justin Schwartz 648e15a016 document the original unit stars random state 2025-07-22 23:18:53 -07:00
Martin Michelsen 1729edc1d2 add dynamic switching in EnemyDamageSync 2025-07-22 00:27:21 -07:00
Martin Michelsen bbcc03f832 improve CommonItemSet JSON parser/serializer 2025-07-20 22:30:04 -07:00
Martin Michelsen 6827229c83 refine 6x79 a bit 2025-07-20 22:30:01 -07:00
Martin Michelsen 60291993b6 add configurable min levels for non-BB; closes #666 2025-07-11 17:57:39 -07:00
Martin Michelsen 118512ebb2 fix websocket timeout 2025-07-10 09:38:31 -07:00
Martin Michelsen ae9eaccd29 fix disconnect for websocket clients 2025-07-08 20:09:20 -07:00
Martin Michelsen 3025420aea fix headers in show-item-tables 2025-07-08 20:09:04 -07:00
Martin Michelsen 3c4ad43e71 add belra arm bug fix 2025-07-06 23:25:03 -07:00
Martin Michelsen 9e02b6c666 add $sound command 2025-07-06 21:41:31 -07:00
Martin Michelsen fe435c13d3 fix local address detection 2025-07-06 20:48:44 -07:00
Martin Michelsen 3b5145880c fix $loadchar description in readme 2025-07-06 15:35:56 -07:00
Martin Michelsen d965ff5031 add stat boosts to ItemPMT formatting 2025-07-06 13:57:31 -07:00
Martin Michelsen 22a89deb8b fix save game data timer 2025-07-05 20:27:24 -07:00
Martin Michelsen c9ba61a4b0 fix NAME_ONLY for units with kill counts 2025-07-05 19:54:30 -07:00
Martin Michelsen 0cdf2784cc fix text alignment in MoreSaveSlots 2025-07-05 19:49:20 -07:00
Martin Michelsen 76a948a45d fix unused variable 2025-07-03 00:27:38 -07:00
Martin Michelsen fd39a89957 fix BB proxy bugs 2025-07-02 21:14:32 -07:00
Martin Michelsen 0a5065707c use new phosg::Image class 2025-07-01 09:56:42 -07:00
Martin Michelsen 072e647c7b update readme 2025-06-29 11:22:40 -07:00
Martin Michelsen 148db03a9a fix copy-paste error in MoreSaveSlots patch 2025-06-24 20:53:33 -07:00
Martin Michelsen cff5ad23fc fix scroll bar setup in MoreSaveSlots 2025-06-24 20:12:49 -07:00
Martin Michelsen 3e174b7397 add notes on TObjSinBoard 2025-06-24 20:12:33 -07:00
Martin Michelsen e9bf51f3f7 save all fields when applying npc skins 2025-06-24 20:12:24 -07:00
Martin Michelsen 28ab1bea9c add IPv6 support in proxy 2025-06-17 01:19:26 -07:00
Martin Michelsen 923cc4ebb0 add missing xbox includes 2025-06-16 19:22:38 -07:00
Martin Michelsen e24a0e3c40 decrypt Ep3 player config at load time 2025-06-16 00:30:53 -07:00
Martin Michelsen a857cc9d03 update some notes 2025-06-16 00:10:50 -07:00
Martin Michelsen 8746b544b6 describe the PCv2-exclusive quest opcodes 2025-06-14 20:40:53 -07:00
Martin Michelsen ccd5baedf1 add notes from BB trial edition 2025-06-14 12:00:36 -07:00
Martin Michelsen 9621e89cd7 add notes and support for final PCv2 version 2025-06-14 00:35:56 -07:00
Martin Michelsen 3844c9881c add AccurateKillCount patch 2025-06-12 18:49:38 -07:00
Martin Michelsen 6999694f89 rewrite 6xE4 logic 2025-06-12 01:27:54 -07:00
Martin Michelsen 54acd931da use .label/.address in xbox client functions 2025-06-09 10:00:38 -07:00
Martin Michelsen 9bc9e219b5 add patch for disabling Xbox save signature validation 2025-06-07 19:32:21 -07:00
Martin Michelsen e8b2765a71 add xbox disk file formats 2025-06-07 19:26:34 -07:00
Martin Michelsen d4bc880018 make $killcount work for units too 2025-06-07 09:53:56 -07:00
Martin Michelsen c1a2742617 update readme 2025-06-07 09:53:35 -07:00
Martin Michelsen ebaeb2f70a update docs for find_inventory_item quest opcode 2025-06-05 21:33:51 -07:00
Martin Michelsen 0366e36edb add Xbox-US1 quest handlers 2025-06-05 20:59:41 -07:00
Martin Michelsen a0f52f01bb use 6x2F for infinite HP 2025-06-04 00:18:57 -07:00
Martin Michelsen bee4c55446 make client functions parameterizable by version 2025-06-04 00:16:43 -07:00
Martin Michelsen 1a6b26e56b add text-only matching in AddressTranslator 2025-06-03 09:59:19 -07:00
Martin Michelsen 1047d089d5 fix 6x0B error message 2025-05-31 23:15:23 -07:00
Martin Michelsen 2d6096cfda fix $savechar on BB 2025-05-31 23:15:00 -07:00
Martin Michelsen 7cbd9402d0 fix CallNativeFunctionGC
Docker / Build (push) Has been cancelled
2025-05-31 15:15:03 -07:00
Martin Michelsen 0396337994 fix inventory/bank debug messages 2025-05-31 15:14:04 -07:00
Martin Michelsen 6fbc0829ae add patch to replace Pinz shop cards 2025-05-31 10:56:01 -07:00
Martin Michelsen 4f41cbc9ce fix description generated in $item command 2025-05-31 10:07:11 -07:00
Martin Michelsen d1e6d75d70 fix TethVer detection hack 2025-05-31 10:04:09 -07:00
Martin Michelsen 067f2439ca make redirect wait apply to SocketChannels as well 2025-05-31 09:34:09 -07:00
Martin Michelsen 2d2edbd7be fix ping exception handler 2025-05-31 09:29:01 -07:00
Vargur f5f457aa6f Fix HTTP endpoint logic: remove incorrect negation in rare-tables path check
The !req.path.starts_with( was causing every subsequent command to be processed as a rare-tables substring command.
2025-05-30 19:29:52 -07:00
Martin Michelsen aabbafb749 fix game flag translation across v2/v3 boundary 2025-05-28 22:01:54 -07:00
Martin Michelsen e72e37f713 implement extended $infhp features on proxy server; closes #501 2025-05-27 19:34:47 -07:00
Martin Michelsen f884893b18 reprioritize to-do list 2025-05-27 19:34:25 -07:00
Martin Michelsen c74c0e2250 fix conditions 2025-05-26 23:52:43 -07:00
Martin Michelsen 5f4d2ec891 complete implementation of $checkchar and make slot count configurable; closes #645 2025-05-26 21:55:19 -07:00
Martin Michelsen 33b0ab3ed3 improve BB proxy functionality 2025-05-26 18:56:23 -07:00
Martin Michelsen 2e158a1df8 fix Programs menu item in tests
Docker / Build (push) Has been cancelled
2025-05-26 15:08:26 -07:00
Martin Michelsen 6a89f18580 make logging less verbose 2025-05-26 14:51:43 -07:00
Martin Michelsen b3e757dcdc add Windows platform wrapper 2025-05-26 14:20:20 -07:00
Martin Michelsen 9c675a14ab fix CI build steps 2025-05-26 14:17:47 -07:00
Martin Michelsen cc99050964 switch to coroutine execution model 2025-05-26 14:11:38 -07:00
Martin Michelsen f65b1f1c14 make login faster with MoreSaveSlots 2025-04-25 08:56:19 -07:00
Martin Michelsen 1ad2c47444 make $exit work without a quest loaded on most versions 2025-04-24 18:58:20 -07:00
Martin Michelsen ebef2f2bd1 add aliases for $arrow command 2025-04-21 19:51:00 -07:00
Martin Michelsen afa23f03c7 describe how TObjNpcEnemy works 2025-04-19 11:01:31 -07:00
Martin Michelsen 9d7b6c6341 update some notes 2025-04-19 11:00:33 -07:00
Martin Michelsen 4199f7bb23 update comments on MoreSaveSlots patch 2025-04-13 19:11:12 -07:00
Martin Michelsen 140d488239 support more BB save slots; add client patch 2025-04-12 23:35:00 -07:00
Martin Michelsen 22e9314e18 fix some notes 2025-04-07 23:49:08 -07:00
anzz1 c8a3b3ba31 add 59NL version of Palette client patch
Enables the alternate action palette for number keys
Credits to Soly from Blue Burst Patch Project
2025-04-05 21:42:09 -07:00
Martin Michelsen 8b7e4014ae fix quest max players check; closes #636 2025-04-05 14:11:21 -07:00
Martin Michelsen 13b94e7ba1 minor cleanup in map entity notes 2025-04-05 11:38:04 -07:00
Martin Michelsen ab2a8d5fa9 document item/level table format commands 2025-04-05 11:38:04 -07:00
Martin Michelsen a01d8206e1 add outline of ep4 enemy args 2025-04-04 14:23:43 -07:00
Martin Michelsen 61570a2563 add version/area flags to object/enemy defs 2025-04-04 00:39:57 -07:00
Martin Michelsen 822c0e0670 more ep2 enemy notes 2025-04-03 10:39:40 -07:00
Martin Michelsen c5b5ab3815 fixes after compiler upgrade 2025-04-03 10:38:55 -07:00
anzz1 b28e9a5d54 [BB] unitxt_shop_e typo fix
"This item will be delete. OK?" -> "This item will be deleted. OK?"
2025-03-31 20:19:30 -07:00
anzz1 e5e61d189c [BB] Correct unitxt_shop_e.prs, add WS files for reference
Corrected unitxt_shop_e.prs: Fixed typo 'Mestea' -> 'Meseta', added missing Present Counter text lines.
Added WS files to notes for reference (from gsl)
2025-03-31 20:19:30 -07:00
anzz1 8b35d07fc9 59NL DrawDistance client function (beta)
Currently beta quality, map objects that fade like boxes, and Pioneer's
background billboards and elevators still have regular draw distance.
TODO: 90% of stuff is included, bring home the last 10%.
2025-03-31 20:18:39 -07:00
anzz1 2f462d391e Update HungryMagSound.59NL.patch.s
Change the hungry mag sound effect from "message received" to "mag feed"
2025-03-31 20:15:38 -07:00
Martin Michelsen 09d3b90169 describe some Ep2 enemies 2025-03-30 16:21:02 -07:00
Martin Michelsen a329db3036 use new phosg hash interface 2025-03-30 12:57:55 -07:00
Martin Michelsen 711fa742be describe ep1/ep2 bosses 2025-03-29 21:51:05 -07:00
Martin Michelsen d9c549bef5 add $whatene command 2025-03-29 21:50:11 -07:00
Martin Michelsen e0d1db0363 handle DARK_GUNNER_CONTROL properly 2025-03-29 16:32:53 -07:00
Martin Michelsen 1723a4152c describe Ruins enemies 2025-03-29 16:19:35 -07:00
Martin Michelsen c212b2987c describe Mines enemies 2025-03-28 22:36:19 -07:00
Martin Michelsen 488a5b201e more enemy type docs 2025-03-27 23:38:46 -07:00
Martin Michelsen 4770297cd0 document some things in ItemPMT 2025-03-27 23:38:37 -07:00
Martin Michelsen 3297df580a port the menu code to all versions 2025-03-26 23:22:03 -07:00
Martin Michelsen 936b914cbc start describing enemy types 2025-03-26 23:07:39 -07:00
Martin Michelsen ad51dcf16f describe remaining object types 2025-03-25 17:37:03 -07:00
Martin Michelsen c8f330e2c8 describe some ep4 objects 2025-03-25 11:30:11 -07:00
Martin Michelsen 6467693df9 describe a few Ep4 objects 2025-03-24 23:45:22 -07:00
Martin Michelsen 07716fd301 describe Ep3 map objects 2025-03-24 18:33:59 -07:00
Martin Michelsen b30cd3bb8e load Ep3 Morgue map 2025-03-24 18:29:09 -07:00
Martin Michelsen a4a8389add describe remaining Ep2 objects 2025-03-24 15:24:19 -07:00
Martin Michelsen 7f2fca3a79 add notes for lobby, temple, and spaceship objects 2025-03-23 21:58:37 -07:00
Martin Michelsen cfea8a2712 more object notes 2025-03-22 12:52:31 -07:00
Martin Michelsen 3e59f9a91e brace-init in vector math 2025-03-22 00:05:50 -07:00
Martin Michelsen 69edba036e add $whatobj command 2025-03-21 23:58:49 -07:00
Martin Michelsen ca1dc6ad7d more object notes 2025-03-21 23:58:49 -07:00
Martin Michelsen dcd8d3b650 more object notes 2025-03-18 23:45:38 -07:00
Martin Michelsen 1bc668f72f disable non-resource-file CI build 2025-03-18 20:58:44 -07:00
Martin Michelsen 52d019a321 make BB proxy's Save Files option generate .psochar files 2025-03-18 20:55:04 -07:00
Martin Michelsen 02c3d35d78 more object comments 2025-03-18 20:55:04 -07:00
Martin Michelsen 6328453d38 make resource_file required 2025-03-18 18:59:16 -07:00
Martin Michelsen 595675df20 refine object comments 2025-03-18 00:49:55 -07:00
Martin Michelsen 4489bca037 document more map object types 2025-03-17 22:57:24 -07:00
Martin Michelsen 333b62b884 rewrite dat constructor tables 2025-03-16 23:09:49 -07:00
Martin Michelsen f06b07a7c4 add note on F829 2025-03-16 12:20:13 -07:00
Martin Michelsen b52a2e4a5b refine some ItemPMT structures 2025-03-16 12:20:13 -07:00
Martin Michelsen 26c3a87a73 distinguish hidden-name ES weapons 2025-03-16 12:20:13 -07:00
Martin Michelsen 73eef4815b update 6x9A description 2025-03-16 12:20:13 -07:00
Martin Michelsen d85737b1a7 update release instructions; closes #621 2025-03-14 23:36:03 -07:00
Martin Michelsen ed05bbe2e3 write gc/xbox versions of NoRareSelling 2025-03-14 23:23:39 -07:00
Martin Michelsen f0c492abea remove patches menu in favor of patch switches; closes #623 2025-03-14 23:20:09 -07:00
Martin Michelsen 2cff04943f add player_count in 83 command struct 2025-03-14 23:20:09 -07:00
anzz1 1df7b821e8 cleanup 59NL NoSellRare client patch 2025-03-14 21:17:54 -07:00
anzz1 5fb842761d add 59NL version of NoSellRare client patch
Prevents you from accidentally selling rares and untekked weapons to vendor
Credits to Soly from Blue Burst Patch Project
2025-03-14 21:17:54 -07:00
Martin Michelsen 3cddb99c20 use IP stack sim address in HTTP responses if client is on tapserver 2025-03-09 23:27:07 -07:00
2129 changed files with 613362 additions and 280449 deletions
+2 -4
View File
@@ -16,19 +16,18 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest]
with_resource_file: ["true", "false"]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install libraries (Linux) - name: Install libraries (Linux)
if: ${{ matrix.os == 'ubuntu-latest' }} if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install -y libevent-dev run: sudo apt-get install -y cmake libasio-dev
- name: Install libraries (macOS) - name: Install libraries (macOS)
if: ${{ matrix.os == 'macos-latest' }} if: ${{ matrix.os == 'macos-latest' }}
run: | run: |
brew install libevent brew install asio libiconv
cat << EOF > nproc cat << EOF > nproc
#!/bin/sh #!/bin/sh
@@ -47,7 +46,6 @@ jobs:
sudo make install sudo make install
- name: Install resource_file - name: Install resource_file
if: ${{ matrix.with_resource_file == 'true' }}
run: | run: |
git clone https://github.com/fuzziqersoftware/resource_dasm.git git clone https://github.com/fuzziqersoftware/resource_dasm.git
cd resource_dasm cd resource_dasm
+26 -11
View File
@@ -2,43 +2,58 @@
.DS_Store .DS_Store
# Build products # Build products
src/Revision.cc
newserv newserv
newserv.exe
src/Revision.cc
# CMake files # CMake files
build
cmake_install.cmake cmake_install.cmake
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
CTestTestFile.cmake
CTestTestfile.cmake CTestTestfile.cmake
CTestTestFile.cmake
install_manifest.txt install_manifest.txt
Makefile Makefile
Testing Testing
# Files modified by the user and/or server that don't have defaults # Files modified by the user and/or server that don't have defaults
system/config.json system/config.json
system/ep3/battle-records/*.mzr
system/ep3/battle-records/*.mzrd system/ep3/battle-records/*.mzrd
system/ep3/tournament-state.json system/ep3/tournament-state.json
system/licenses.nsi system/licenses.nsi
system/licenses/*.json 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/*.psochar
system/players/*.psosys system/players/*.psosys
system/players/*.psocard
system/players/*.nsc
system/players/*.nsa
system/teams/*.json
system/teams/*.bmp system/teams/*.bmp
system/patch-pc/.metadata-cache.json system/teams/*.json
system/patch-bb/.metadata-cache.json
# Files fuzziqersoftware uses that don't make sense to be committed to the main # Files fuzziqersoftware uses that don't make sense to be committed to the main
# repository # repository
*.dec
*.WIP-s
files files
make_release.py notes-private
old-khyller old-khyller
old-newserv old-newserv
release release
release.zip release.zip
system/patch-bb/data all-quests
system/patch-bb/psobb.pat
system/dol 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
+44 -58
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.22)
set(CMAKE_POLICY_DEFAULT_CMP0110 NEW) set(CMAKE_POLICY_DEFAULT_CMP0110 NEW)
@@ -19,19 +19,15 @@ endif()
# Library search # Library search
find_path (LIBEVENT_INCLUDE_DIR NAMES event.h) find_path(ASIO_INCLUDE_DIR NAMES asio.hpp HINTS "${WINDOWS_ENV}/include" REQUIRED)
find_library (LIBEVENT_LIBRARY NAMES event) if(WIN32)
find_library (LIBEVENT_CORE NAMES event_core) find_path(Iconv_INCLUDE_DIRS NAMES iconv.h HINTS "${WINDOWS_ENV}/include" REQUIRED)
find_library (LIBEVENT_PTHREADS NAMES event_pthreads) find_library(Iconv_LIBRARIES NAMES iconv HINTS "${WINDOWS_ENV}/lib" REQUIRED)
set (LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) else()
set (LIBEVENT_LIBRARIES find_package(Iconv REQUIRED)
${LIBEVENT_LIBRARY} endif()
${LIBEVENT_CORE}
${LIBEVENT_PTHREADS})
find_package(phosg REQUIRED) find_package(phosg REQUIRED)
find_package(Iconv REQUIRED) find_package(resource_file REQUIRED)
find_package(resource_file QUIET)
@@ -54,18 +50,26 @@ add_custom_target(
set(SOURCES set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc
src/Account.cc src/Account.cc
src/AccountSync.cc
src/TeamSync.cc
src/AddressTranslator.cc
src/AFSArchive.cc src/AFSArchive.cc
src/AsyncHTTPServer.cc
src/AsyncUtils.cc
src/BattleParamsIndex.cc src/BattleParamsIndex.cc
src/BMLArchive.cc src/BMLArchive.cc
src/CatSession.cc
src/Channel.cc src/Channel.cc
src/ChatCommands.cc src/ChatCommands.cc
src/ChoiceSearch.cc src/ChoiceSearch.cc
src/Client.cc src/Client.cc
src/ClientFunctionIndex.cc
src/CommandCensorData.cc
src/CommonItemSet.cc src/CommonItemSet.cc
src/Compression.cc src/Compression.cc
src/DCSerialNumbers.cc src/DCSerialNumbers.cc
src/DNSServer.cc src/DNSServer.cc
src/DOLFileIndex.cc
src/DataIndex.cc
src/DownloadSession.cc src/DownloadSession.cc
src/EnemyType.cc src/EnemyType.cc
src/Episode3/AssistServer.cc src/Episode3/AssistServer.cc
@@ -80,9 +84,7 @@ set(SOURCES
src/Episode3/RulerServer.cc src/Episode3/RulerServer.cc
src/Episode3/Server.cc src/Episode3/Server.cc
src/Episode3/Tournament.cc src/Episode3/Tournament.cc
src/EventUtils.cc src/GameServer.cc
src/FileContentsCache.cc
src/FunctionCompiler.cc
src/GSLArchive.cc src/GSLArchive.cc
src/HTTPServer.cc src/HTTPServer.cc
src/ImageEncoder.cc src/ImageEncoder.cc
@@ -94,60 +96,57 @@ set(SOURCES
src/ItemData.cc src/ItemData.cc
src/ItemNameIndex.cc src/ItemNameIndex.cc
src/ItemParameterTable.cc src/ItemParameterTable.cc
src/ItemTranslationTable.cc
src/Items.cc src/Items.cc
src/ItemTranslationTable.cc
src/LevelTable.cc src/LevelTable.cc
src/Lobby.cc src/Lobby.cc
src/Loggers.cc src/Loggers.cc
src/MagMetadataTable.cc
src/Main.cc src/Main.cc
src/Map.cc src/Map.cc
src/Menu.cc src/Menu.cc
src/NetworkAddresses.cc src/NetworkAddresses.cc
src/PatchDownloadSession.cc
src/PatchFileIndex.cc src/PatchFileIndex.cc
src/PatchServer.cc src/PlayerInventory.cc
src/PlayerFilesManager.cc
src/PlayerSubordinates.cc src/PlayerSubordinates.cc
src/PPKArchive.cc src/PPKArchive.cc
src/ProxyCommands.cc src/ProxyCommands.cc
src/ProxyServer.cc src/ProxySession.cc
src/PSOEncryption.cc src/PSOEncryption.cc
src/PSOGCObjectGraph.cc src/PSOGCObjectGraph.cc
src/PSOProtocol.cc src/PSOProtocol.cc
src/Quest.cc src/Quest.cc
src/QuestMetadata.cc
src/QuestScript.cc src/QuestScript.cc
src/RareItemSet.cc src/RareItemSet.cc
src/ReceiveCommands.cc src/ReceiveCommands.cc
src/ReceiveSubcommands.cc src/ReceiveSubcommands.cc
src/ReplaySession.cc src/ReplaySession.cc
src/Revision.cc
src/SaveFileFormats.cc src/SaveFileFormats.cc
src/SendCommands.cc src/SendCommands.cc
src/Server.cc
src/ServerShell.cc src/ServerShell.cc
src/ServerState.cc src/ServerState.cc
src/ShellCommands.cc src/ShellCommands.cc
src/ShopRandomSets.cc
src/SignalWatcher.cc src/SignalWatcher.cc
src/StaticGameData.cc src/StaticGameData.cc
src/TeamIndex.cc src/TeamIndex.cc
src/TekkerAdjustmentSet.cc
src/Text.cc src/Text.cc
src/TextIndex.cc src/TextIndex.cc
src/Version.cc src/Version.cc
src/WordSelectTable.cc src/WordSelectTable.cc
) )
if(resource_file_FOUND)
set(SOURCES ${SOURCES} src/AddressTranslator.cc)
endif()
add_executable(newserv ${SOURCES}) add_executable(newserv ${SOURCES})
target_include_directories(newserv PUBLIC ${LIBEVENT_INCLUDE_DIR} ${Iconv_INCLUDE_DIRS}) target_include_directories(newserv PUBLIC ${ASIO_INCLUDE_DIR} ${Iconv_INCLUDE_DIRS})
target_link_libraries(newserv phosg::phosg ${LIBEVENT_LIBRARIES} ${Iconv_LIBRARIES} pthread) target_link_libraries(newserv phosg::phosg ${Iconv_LIBRARIES} resource_file::resource_file)
if(resource_file_FOUND) if (WIN32)
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE) target_compile_definitions(newserv PUBLIC WINVER=0x0A00 _WIN32_WINNT=0x0A00)
target_link_libraries(newserv resource_file::resource_file) target_compile_options(newserv PRIVATE -Wa,-mbig-obj -Wno-mismatched-new-delete)
message(STATUS "resource_file found; enabling patch support") target_link_options(newserv PRIVATE -static -static-libgcc -static-libstdc++)
else() target_link_libraries(newserv ws2_32 mswsock bcrypt iphlpapi)
message(WARNING "resource_file not found; disabling patch support")
endif() endif()
add_dependencies(newserv newserv-Revision-cc) add_dependencies(newserv newserv-Revision-cc)
@@ -160,32 +159,19 @@ add_dependencies(newserv newserv-Revision-cc)
enable_testing() enable_testing()
file(GLOB LogTestCases ${CMAKE_SOURCE_DIR}/tests/*.test.txt) file(GLOB LOG_TEST_CASES ${CMAKE_SOURCE_DIR}/tests/*.test.txt)
file(GLOB LogRDTestCases ${CMAKE_SOURCE_DIR}/tests/*.rdtest.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( add_test(
NAME ${LogTestCase} NAME ${SCRIPT_TEST_CASE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_BINARY_DIR}/newserv --replay-log=${LogTestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json) COMMAND ${SCRIPT_TEST_CASE} ${CMAKE_BINARY_DIR}/newserv)
endforeach()
if(resource_file_FOUND)
foreach(LogRDTestCase IN ITEMS ${LogRDTestCases})
add_test(
NAME ${LogRDTestCase}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_BINARY_DIR}/newserv --replay-log=${LogRDTestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json)
endforeach()
endif()
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)
endforeach() endforeach()
+8 -8
View File
@@ -11,7 +11,7 @@ RUN apt update && apt install -y --no-install-recommends \
make \ make \
cmake \ cmake \
g++ \ g++ \
libevent-dev \ libasio-dev \
zlib1g-dev zlib1g-dev
# --- # ---
@@ -29,13 +29,13 @@ RUN git clone --depth 1 -b ${PHOSG_TARGET} https://github.com/fuzziqersoftware/p
sudo make install sudo make install
RUN \ RUN \
if [ "$BUILD_RESOURCE_DASM" = "true" ] ; then \ if [ "$BUILD_RESOURCE_DASM" = "true" ] ; then \
git clone --depth 1 -b ${RESOURCE_DASM_TARGET} https://github.com/fuzziqersoftware/resource_dasm.git && \ git clone --depth 1 -b ${RESOURCE_DASM_TARGET} https://github.com/fuzziqersoftware/resource_dasm.git && \
cd resource_dasm && \ cd resource_dasm && \
cmake . && \ cmake . && \
make -j$(nproc) && \ make -j$(nproc) && \
sudo make install \ sudo make install \
; fi ; fi
# --- # ---
@@ -53,10 +53,10 @@ RUN cmake -B $PWD/build -DCMAKE_BUILD_TYPE=${BUILD_TYPE} && \
sudo make -C build install sudo make -C build install
RUN \ RUN \
if [ "$BUILD_STRIP" = "true" ] ; then \ if [ "$BUILD_STRIP" = "true" ] ; then \
strip /usr/local/lib/*.a && \ strip /usr/local/lib/*.a && \
strip /usr/local/bin/* \ strip /usr/local/bin/* \
; fi ; fi
# --- # ---
@@ -72,7 +72,7 @@ RUN cp -f system/config.example.json system/config.json && \
FROM ${BASE_IMAGE} AS final FROM ${BASE_IMAGE} AS final
RUN apt update && apt install -y --no-install-recommends \ RUN apt update && apt install -y --no-install-recommends \
libevent-dev \ libasio-dev \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* && rm -rf /var/lib/apt/lists/* /var/cache/apt/*
WORKDIR /newserv WORKDIR /newserv
+16 -855
View File
@@ -1,869 +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.
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 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.
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. 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.
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. For the original upstream project, see:
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. https://github.com/fuzziqersoftware/newserv
**Table of contents** ## About this repository
* Background
* [History](#history)
* [Other server projects](#other-server-projects)
* [Developer information](#developer-information)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [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-client-functions-and-dol-files)
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
* [Chat commands](#chat-commands)
* [REST API](#rest-api)
* [Non-server features](#non-server-features)
# History 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.
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. Some changes may not be appropriate for upstream newserv or for general newserv deployments.
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. ## Original README
<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. A copy of the upstream README is preserved here:
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. [docs/upstream-README.md](docs/upstream-README.md)
<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. 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-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. ## License and attribution
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 a bit tedious to compile on Windows but does work.) This project remains based on newserv by fuzziqersoftware.
<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). See `LICENSE` for license details. Any copied or modified upstream code retains the original license attribution.
## 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. Still active and popular as of early 2025. Schtserv is also the only other unofficial server to support all versions of PSO, including Episode 3. (Their implementation of Episode 3 is based on newserv's, which is itself based on Sega's.)
* (2005) **Khyller**: An early attempt of mine to support PSO PC, GC, and BB. See above for more details.
* (2006) **Aeon**: My second attempt. Better than Khyller, but still unreliable.
* (2008) **Tethealla**: A fairly extensive implementation of PSOBB, written in C by Sodaboy. The public version of Tethealla has been [officially disowned](https://www.pioneer2.net/community/threads/tethealla-server-forums-removal.26365/) (as it is now more than 15 years old), but closed-source development continues. [Ephinea](https://ephinea.pioneer2.net/), currently the most popular PSOBB server, is the continuation of this project. Several other modern PSOBB servers are forks of the initial public version of Tethealla as well.
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server; written in C by BlueCrab. Still active and popular as of early 2025.
* (2015) **[Archon](https://github.com/dcrodman/archon)**: A PSOBB server written in Go by Drew Rodman.
* (2015) **[Idola](https://github.com/HybridEidolon/idolapsoserv)**: A PSOBB server written in Rust by HybridEidolon. Functionality status unknown; the project has been archived.
* (2017) **[Aselia](https://github.com/Solybum/Aselia)**: A PSOBB server written written in C# by Soly. It seems this was planned to be open-source at some point, but that has not (yet) happened.
* (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.
* (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.
## Developer information
There is a lot of code in this project that could be useful as a reference. Some of the more notable files are:
* **src/CommandFormats.hh**: Complete listing of all network commands used in all known versions of the game, and their formats
* **src/CommonItemSet.hh/cc**: Format of ItemPT files, shop definition files, and tekker adjustment tables
* **src/DCSerialNumbers.hh/cc**: PSO DC serial number validation algorithm and serial number generator
* **src/ItemData.hh**: Item format reference
* **src/ItemCreator.hh/cc**: Reverse-engineered item generator from Episodes 1&2 (used for all versions)
* **src/ItemParameterTable.hh**: Format of many structures in ItemPMT.prs
* **src/Map.hh/cc**: Map file (.dat) structure and reverse-engineered Challenge Mode random enemy generation algorithm
* **src/QuestScript.cc**: Complete listing of all quest opcodes on all versions, along with their arguments and behavior
* **src/RareItemSet.hh/cc**: Format of ItemRT files (rare item drop tables)
* **src/SaveFileFormats.hh**: Definitions of save file structures for all versions
* **src/Episode3/DataIndexes.hh**: Episode 3 file structures, including card definition format and map/quest format
* **system/item-tables/names-v4.json**: Names of all items, indexed by the first 3 bytes of data1
## Using newserv in other projects
There is a fair amount of code in this project that could potentially be useful to 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.
# 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 | No |
| DC 11/2000 | Yes | Yes | No |
| 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 | No |
| PC | Yes | Yes | Yes |
| GC Ep1&2 NTE | Yes | Yes | Yes |
| GC Ep1&2 | Yes | Yes | Yes |
| GC Ep1&2 Plus | Yes | Yes | Yes |
| GC Ep3 NTE | Yes | Yes (2) | Yes |
| GC Ep3 | Yes | Yes | Yes |
| Xbox Ep1&2 Beta | Yes | Yes | Yes |
| Xbox Ep1&2 | Yes | Yes | Yes |
| 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.*
# 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-windows-amd64.zip or release-macos-arm64.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. (Optional) If you want to change any config options, 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.
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 "Building from source" section below.
### Building from source
1. Install the packages newserv depends on.
* If you're on Windows, install [Cygwin](https://www.cygwin.com/). While doing so, install the `cmake`, `gcc-core`, `gcc-g++`, `git`, `libevent2.1_7`, `libevent-devel`, `make`, `libiconv-devel`, and `zlib` packages. Do the rest of these steps inside a Cygwin shell (not a Windows cmd shell or PowerShell).
* If you're on macOS, run `brew install cmake libevent libiconv`.
* If you're on Linux, run `sudo apt-get install cmake libevent-dev` (or use your Linux distribution's package manager).
3. Build and install [phosg](https://github.com/fuzziqersoftware/phosg).
4. Optionally, install [resource_dasm](https://github.com/fuzziqersoftware/resource_dasm). This will enable newserv to send memory patches and load DOL files on PSO GC clients. PSO GC clients can play PSO normally on newserv without this.
5. 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.
## 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 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 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 (mostly battle and challenge mode quests) have additional JSON metadata files that describe how the server should handle them. These files include flags that can be used to hide the quest unless a preceding quest has been cleared, or to hide the quest unless purchased as a BB team reward. These metadata files are generally named similarly to their .bin and .dat counterparts, except the `VERSION` token may also be omitted if the metadata applies to all languages of the quest on all PSO versions. See system/quests/battle/b88001.json for documentation on the exact format of the JSON file.
Some quests may also include a .pvr file, which contains an image used in the quest. These files are named similarly to their .bin and .dat counterparts.
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 together, and allows GC and Xbox players to play together. You can change these rules to allow all versions to play together, or to prevent versions from playing together, with the CompatibilityGroups setting in config.json.
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.
There is a third 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, client functions, and DOL files
*Everything in this section requires resource_dasm to be installed, so newserv can use the assemblers and disassemblers from its libresource_file library. If resource_dasm is not installed, newserv will still build and run, but these features will not be available.*
You can put assembly files in the system/client-functions directory with filenames like PatchName.VERS.patch.s and they will appear in the Patches menu for clients that support client functions. Client functions are written in SH-4, PowerPC, or x86 assembly and are compiled when newserv is started. The assembly system's features are documented in the comments in system/client-functions/System/WriteMemoryGC.ppc.s.
The VERS token in client function filenames refers to the specific version of the game that the client function applies to. Some versions do not support receiving client functions at all. *Note: newserv uses the shorter GameCube versioning convention, where discs labeled DOL-XXXX-0-0Y are version 1.Y. The PSO community seems to use the convention 1.0Y in some places instead, but these are the same version. For example, the version that newserv calls v1.4 is the same as v1.04, and is labeled DOL-GPOJ-0-04 on the underside of the disc.*
The specific versions are:
| Game | VERS | Architecture |
|------------------------------|------|---------------|
| PSO DC Network Trial Edition | 1OJ1 | Not supported |
| PSO DC 11/2000 prototype | 1OJ2 | Not supported |
| PSO DC 12/2000 prototype | 1OJ3 | Not supported |
| PSO DC 01/2001 prototype | 1OJ4 | Not supported |
| PSO DC v1 JP | 1OJF | Not supported |
| PSO DC v1 US | 1OEF | Not supported |
| PSO DC v1 EU | 1OPF | Not supported |
| PSO DC 08/2001 prototype | 2OJ5 | SH-4 |
| PSO DC v2 JP | 2OJF | SH-4 |
| PSO DC v2 US | 2OEF | SH-4 |
| PSO DC v2 EU | 2OPF | SH-4 |
| PSO PC (v2) | 2OJW | Not supported |
| PSO GC Trial Edition | 3OJT | PowerPC |
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 (Plus) JP | 3OJ4 | PowerPC |
| PSO GC v1.5 (Plus) JP | 3OJ5 | PowerPC (1) |
| PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 (Plus) US | 3OE2 | PowerPC (1) |
| PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 Trial Edition | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | PowerPC (1) |
| PSO GC Ep3 EU | 3SP0 | PowerPC (1) |
| PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.11 | 59NJ | x86 |
| PSO BB JP 1.25.13 | 59NL | x86 |
| PSO BB Tethealla | 59NL | x86 |
*Notes:*
1. *Client functions are only supported on these versions if EnableSendFunctionCallQuestNumbers is set in config.json. See the comments there for more information.*
newserv comes with a set of patches for many of the above versions, based on AR codes originally made by Ralf at GC-Forever and Aleron Ives. Many of them were originally posted in [this thread](https://www.gc-forever.com/forums/viewtopic.php?f=38&t=2050).
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, 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 PSO BB clients - all 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, or GC 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). 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 to text files if newserv is built with patch support)
* Player data from BB sessions (saved as .bin files, which are not the same format as .nsc files)
* Episode 3 online quests and maps (saved as .mnmd files)
* Episode 3 download quests (saved as .mnm files)
* 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. On PSO DC, PC and GC, the proxy server 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 server 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 LinkedSession:17205AE4, for example, you would run `on 17205AE4 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 on the game server and not on the proxy server. The chat commands are:
* Information commands
* `$li`: Show basic information about the lobby or game you're in. If you're on the proxy server, show information about your connection instead (remote Guild Card number, client ID, etc.).
* `$si` (game server only): Show basic information about the server.
* `$ping`: Show round-trip ping time from the server to you. On the proxy server, show the ping time from you to the proxy and from the proxy to the server.
* `$matcount` (game server only): Show how many of each type of material you've used.
* `$killcount` (game server 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` (game server only): Show the type, name, and stats of the nearest item on the ground.
* `$where` (game server only): Show your current floor number and coordinates. Mainly useful for debugging.
* `$qfread <field-name>` (game server only): Show the value of a quest counter in your player data. The field names are defined in config.json.
* Debugging commands
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
* You'll see in-game messages from the server when you take 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.
* The rest of the commands in this section are enabled on the game server. (They are always enabled on the proxy server.)
* `$readmem <address>` (game server only): Read 4 bytes from the given address and show you the values.
* `$writemem <address> <data>` (game server only): Write data to the given address. Data is not required to be any specific size.
* `$nativecall <address> [arg1 ...]` (game server only, GC only): Call a native function on your client. Only arguments passed in registers are supported; calling functions that take many arguments is not supported.
* `$quest <number>` (game server only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. Debug is not required to be enabled if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
* `$qcall <function-id>`: Call a quest function on your client.
* `$qcheck <flag-num>` (game server only): Show the value of a quest flag. This command can be used without debug mode enabled. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only).
* `$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.
* `$qgread <flag-num>` (game server only): Show the value of a quest counter ("global flag"). This command can be used without debug mode enabled.
* `$qgwrite <flag-num> <value>` (game server 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` (game server 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, regardless of how many players are in the game or if you have a VIP card.
* Personal state commands
* `$arrow <color-id>`: Change your lobby arrow color.
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy server, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
* `$swa`: Enable or disable switch assist. When enabled, the server will unlock two-player and four-player doors in non-quest games when you step on any of the required switches.
* `$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 (game server only)
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$loadchar <slot>`: Save your current character data on the server in the specified slot. See the [server-side saves section](#server-side-saves) for more details.
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the [server-side saves section](#server-side-saves) for more details.
* `$edit <stat> <value>`: Modify your character data. See the [using $edit](#using-edit) section for details.
* Blue Burst player commands (game server only)
* `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
* `$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 (game server 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 (game server 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` (game server 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 server, 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 (not DCv1, GC US 1.2, or GC JP 1.5), the server will automatically revive you if you die. On all versions except GC US 1.2 and GC JP 1.5, infinite HP also automatically cures status ailments.
* `$inftp`: Enable or disable infinite TP mode. Applies to only you; does not affect other players.
* `$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 server.
* `$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 server, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions.
* `$unset <index>` (game server 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 server): 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 server 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 server, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
* `$allevent <event>` (game server 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 (game server only)
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies. On BB, the message appears in the scrolling top bar.
* `$ann!`, `$ann?`, `$ann?!`: Same as `$ann`, but with `?`, omits the sender's name, and with `!`, sends the message as a Simple Mail message instead of on-screen text.
* `$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 server.
* `GET /y/lobbies`: Returns information about all lobbies and games.
* `GET /y/server`: Returns information about the server.
* `GET /y/summary`: Returns a summary of the server's state, connected clients, active games, and proxy sessions.
* `WS /y/rare-drops/stream`: WebSocket endpoint that sends messages whenever an announceable rare item is dropped in any game. See below.
* `POST /y/shell-exec`: Runs a server shell command. Input should be a JSON dict of e.g. `{"command": "announce hello"}`; response will be a JSON dict of `{"result": "<result text>"}` or an HTTP error.
### Rare drop stream endpoint
The `/y/rare-drops/stream` endpoint provides a way to implement a drop log in e.g. Discord. For every announceable rare item, a message is sent to all connected clients on this endpoint. (Announceable rare items are items for which an in-game or server-wide text message is sent announcing the find.)
Upon connecting, you'll get the message `{"ServerType": "newserv"}`. After that, when a rare item announcement is sent, you'll get a message like this:
```
{
"PlayerAccountID", 12345,
"PlayerName", "SONIC",
"PlayerVersion", "GC_V3",
"GameName", "ttf",
"GameDropMode", "SERVER_PRIVATE",
"ItemData", "03000000 00010000 00000000 (0021002C) 00000000",
"ItemDescription", "Monomate x1",
"NotifyGame", true,
"NotifyServer", false,
}
```
# Non-server features
newserv has many CLI options, which can be used to access functionality other than the game and proxy server. Run `newserv help` to see a full list of the options and how to use each one.
The data formats that newserv can convert to/from are:
| Format | Encode/compress action | Decode/extract action |
|-------------------------------------|---------------------------|------------------------------|
| PRS compression | `compress-prs` | `decompress-prs` |
| PR2/PRC compression | `compress-pr2` | `decompress-pr2` |
| BC0 compression | `compress-bc0` | `decompress-bc0` |
| Raw encrypted data | `encrypt-data` | `decrypt-data` |
| Episode 3 command mask | `encrypt-trivial-data` | `decrypt-trivial-data` |
| Challenge Mode rank text | `encrypt-challenge-data` | `decrypt-challenge-data` |
| PSO DC quest file (.vms) | None | `decode-vms` |
| PSO GC quest file (.gci) | None | `decode-gci` |
| Download quest file (.dlq) | None | `decode-dlq` |
| Server quest file (.qst) | `encode-qst` | `decode-qst` |
| PSO DC save file (.vms) | `encrypt-vms-save` | `decrypt-vms-save` |
| PSO PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive (.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`)
* 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
```
+8 -5
View File
@@ -1,13 +1,17 @@
## General ## General
- Make a server patch version of story flag fixer quest
- 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)
- Make UI strings localizable (e.g. entries in menus, welcome message, etc.) - Make UI strings localizable (e.g. entries in menus, welcome message, etc.)
- Add an idle connection timeout for proxy sessions
- Clean up ItemParameterTable implementation (see comment at the top of the class definition)
- Handle MeetUserExtensions properly in 41 and C4 commands on the proxy (rewrite the embedded 19 command and store a map of received destinations)
## PSO DC ## PSO DC
- Investigate if https://crates.io/crates/blaze-ssl-async can be used to implement the HL check server - Investigate if https://crates.io/crates/blaze-ssl-async can be used to implement the HL check server
- v2 challenge data in $savechar/$loadchar doesn't work properly
## Episode 3 ## Episode 3
@@ -24,6 +28,5 @@
## PSOBB ## PSOBB
- Figure out why Pouilly Slime EXP doesn't work
- Make server-specified rare enemies work with maps loaded by the proxy - Make server-specified rare enemies work with maps loaded by the proxy
- Implement serialization for various table types (ItemPMT, ItemPT, etc.) - 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())
+449 -6
View File
@@ -13,11 +13,14 @@ Version codes (from README.md):
1OJF: PSO DC v1 JP 1OJF: PSO DC v1 JP
1OEF: PSO DC v1 US 1OEF: PSO DC v1 US
1OPF: PSO DC v1 EU 1OPF: PSO DC v1 EU
2OJ4: PSO DC 08/2001 prototype
2OJ5: PSO DC 08/2001 prototype 2OJ5: PSO DC 08/2001 prototype
2OJF: PSO DC v2 JP 2OJF: PSO DC v2 JP
2OEF: PSO DC v2 US 2OEF: PSO DC v2 US
2OPF: PSO DC v2 EU 2OPF: PSO DC v2 EU
2OJW: PSO PC (v2) 2OJT: PSO PC Trial Edition
2OJW: PSO PC (v2) 04/2002
2OJZ: PSO PC (v2) 02/2003
3OJT: PSO GC Trial Edition 3OJT: PSO GC Trial Edition
3OJ2: PSO GC v1.2 JP 3OJ2: PSO GC v1.2 JP
3OJ3: PSO GC v1.3 JP 3OJ3: PSO GC v1.3 JP
@@ -38,29 +41,107 @@ Version codes (from README.md):
4OEU: PSO Xbox US TU 4OEU: PSO Xbox US TU
4OPD: PSO Xbox EU Disc 4OPD: PSO Xbox EU Disc
4OPU: PSO Xbox EU TU 4OPU: PSO Xbox EU TU
50YJ: PSO BB US 1.24.3
59NJ: PSO BB JP 1.25.11 59NJ: PSO BB JP 1.25.11
59NL: PSO BB JP 1.25.13 59NL: PSO BB JP 1.25.13 (including the Tethealla client)
59NL: PSO BB Tethealla
The menu code The menu code
This code makes all disabled items in menus selectable, which allows you to e.g. use items you can't normally use This code makes all disabled items in menus selectable, which allows you to e.g. use items you can't normally use
3OJ2 => 04263B80 48000028
042AC548 48000020
3OJ3 => 04264758 48000028
042AD3F0 48000020
3OJ4 => 042657B4 48000028
042AE51C 48000020
3OJ5 => 04265554 48000028
042AE2D0 48000020
3OE0 => 04264458 48000028
042ACF04 48000020
3OE1 => 04264458 48000028 3OE1 => 04264458 48000028
042ACF48 48000020 042ACF48 48000020
3OE2 => 04265818 48000028
042AE484 48000020
3OP0 => 04265060 48000028
042ADC18 48000020
3SJT => 0417ADD0 48000028
3SJ0 => 0416B5A4 48000028
3SE0 => 0416B458 48000028 3SE0 => 0416B458 48000028
3SP0 => 0416B904 48000028
Disable serial number validation (untested) Disable serial number validation (untested)
2OEF => 8C1E743E 01E0 2OEF => 8C1E743E 01E0
8C2670B6 01E0 8C2670B6 01E0
Disable item equip restrictions ("God of equip") Disable item equip restrictions ("God of equip")
3OE0 => 0410521C 38000005
3OE1 => 0410521C 38000005 3OE1 => 0410521C 38000005
3OE2 => 041050E4 38000005
3OJ2 => 04104F78 38000005
3OJ3 => 04105154 38000005
3OJ4 => 04105240 38000005
3OJ5 => 041050D4 38000005
3OJT => 0415BF50 38000005
3OP0 => 041052D4 38000005
5OYJ => 005C8C8F E9A7000000
59NJ => 005C9F35 E9A7000000
59NL => 005C9F31 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 All rareable enemies are rare
3OE0 => 040AC944 60000000 // Hildeblue
040C1B70 60000000 // Rappies
040C3FC8 60000000 // Nar Lily
040EB050 48000010 // Pouilly Slime
3OE1 => 040AC944 60000000 // Hildeblue 3OE1 => 040AC944 60000000 // Hildeblue
040C1B70 60000000 // Rappies 040C1B70 60000000 // Rappies
040C3FC8 60000000 // Nar Lily 040C3FC8 60000000 // Nar Lily
040EB050 48000010 // Pouilly Slime 040EB050 48000010 // Pouilly Slime
3OE2 => 040ACAFC 60000000 // Hildeblue
040C1D08 60000000 // Rappies
040C4160 60000000 // Nar Lily
040EB1E8 48000010 // Pouilly Slime
3OJ2 => 040AC6B8 60000000 // Hildeblue
040C18CC 60000000 // Rappies
040C3D24 60000000 // Nar Lily
040EADAC 48000010 // Pouilly Slime
3OJ3 => 040AC9C4 60000000 // Hildeblue
040C1BD0 60000000 // Rappies
040C4028 60000000 // Nar Lily
040EB0B0 48000010 // Pouilly Slime
3OJ4 => 040ACB3C 60000000 // Hildeblue
040C1E04 60000000 // Rappies
040C41A0 60000000 // Nar Lily
040EB374 48000010 // Pouilly Slime
3OJ5 => 040ACAEC 60000000 // Hildeblue
040C1CF8 60000000 // Rappies
040C4150 60000000 // Nar Lily
040EB1D8 48000010 // Pouilly Slime
3OP0 => 040ACAC4 60000000 // Hildeblue
040C1CD0 60000000 // Rappies
040C4128 60000000 // Nar Lily
040EB1B0 48000010 // Pouilly Slime
Unlock all songs in BGM test Unlock all songs in BGM test
Note: sadly, there are no secret/unused ones Note: sadly, there are no secret/unused ones
@@ -143,6 +224,9 @@ Auto-press A as fast as possible during loading screens
3SJT => 040C2C48 60000000 3SJT => 040C2C48 60000000
3SJ0 => 042F8B74 60000000 3SJ0 => 042F8B74 60000000
CARD lobby battle tables react immediately
3SE0 => 042C04D4 60000000
Change type of all loading screens 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 Values for X: 0 = lobby/game join, 1 = quest load, 3 = pipe up, 4 = pipe down, anything else = silent black screen
3OE1 => 0401CA04 3BE0000X 3OE1 => 0401CA04 3BE0000X
@@ -197,12 +281,47 @@ Enable Change Marker option in all lobbies
3OE2 => 041385C8 4800004C 3OE2 => 041385C8 4800004C
3OP0 => 04138848 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 Change HUD color mask
3SE0 => 0438CA8C 3C00RRGG 3SE0 => 0438CA8C 3C00RRGG
0438CA90 6000BBAA 0438CA90 6000BBAA
Disable lobby event music (but keep the visuals) Disable lobby event music (but keep the visuals)
3OJT => 040B2394 38000000
3SE0 => 040B705C 38000000 3SE0 => 040B705C 38000000
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 Enable Pinz's Shop Super Card Capsule Machine as a fourth option
3SE0 => 043101C0 38800004 3SE0 => 043101C0 38800004
@@ -250,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 This unlocks ALL maps, including a bunch of maps with garbage names that crash if you try to play them
3SJT => 042BE538 38600001 3SJT => 042BE538 38600001
3SJ0 => 042C9C2C 38600001 3SJ0 => 042C9C2C 38600001
3SP0 => 042CB50C 38600001
3SE0 => 042CAA00 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 Talk to auction counter offline to get all cards
3SE0 => 042F5D18 4BD160E8 3SE0 => 042F5D18 4BD160E8
@@ -417,6 +542,11 @@ Note: Without a TextEnglish.pr2/pr3 patch, the menu items for these sounds will
0442B6E0 802C0000 0442B6E0 802C0000
Use English language files Use English language files
3OJT => 04189FE8 38000001
0418A010 38000001
0418A0A0 38000001
0418A0C8 38000001
04189EC4 3BC00001
3SJT => 0408E414 38600001 3SJT => 0408E414 38600001
0408E448 38000001 0408E448 38000001
0408E44C 900DA62C 0408E44C 900DA62C
@@ -459,6 +589,72 @@ Heaven Punisher's special always works
3OE2 => 0412AD84 38800001 3OE2 => 0412AD84 38800001
3OP0 => 0412AF5C 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 Allow loading corrupted save files
3OJ2 => 041FC784 38600007 3OJ2 => 041FC784 38600007
041FC788 4E800020 041FC788 4E800020
@@ -486,8 +682,20 @@ Allow loading corrupted save files
041156D4 4E800020 041156D4 4E800020
60 frames per second 60 frames per second
This does not adjust any logic or animations; everything just runs faster This doesn't adjust any logic or animations; everything just runs faster
3OE1 => 045CDEF8 00000001 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 Show extended item info when targeting a dropped item
(Compiled from the ExtendedItemInfo patch, also written by me) (Compiled from the ExtendedItemInfo patch, also written by me)
@@ -703,3 +911,238 @@ Show extended item info when targeting a dropped item
04005188 38210020 04005188 38210020
0400518C 7C0803A6 0400518C 7C0803A6
04005190 4E800020 04005190 4E800020
All weapons can do 3-hit combos
3OE0 => 041D3248 38000001
3OE1 => 041D3248 38000001
3OE2 => 041D3448 38000001
3OJ2 => 041D2DEC 38000001
3OJ3 => 041D3318 38000001
3OJ4 => 041D3144 38000001
3OJ5 => 041D33E4 38000001
3OP0 => 041D3904 38000001
Disable save file signature validation (for moving Xbox saves across consoles)
4OJB => 002F01CB 9090
4OJD => 002F0CDB 9090
4OJU => 002F22DB 9090
4OED => 002F212B 9090
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
File diff suppressed because one or more lines are too long
+6 -5
View File
@@ -1,5 +1,6 @@
DC NTE: pso02.dricas.ne.jp 1OJ1 (DC NTE): pso02.dricas.ne.jp
Nov 2000 proto: test1.st-pso.games.sega.net 1OJ2 (11/2000): test1.st-pso.games.sega.net
Dec 2000 proto: sg107634.csrd.sega.co.jp OR master.pso.dream-key.com 1OJ3 (12/2000): sg107634.csrd.sega.co.jp OR master.pso.dream-key.com
Jan 2001 proto: master.pso.dream-key.com 1OJ4 (01/2001): master.pso.dream-key.com
Aug 2001 proto (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
+2
View File
@@ -1,4 +1,6 @@
List of differences in Ep3 NTE compared to Final: List of differences in Ep3 NTE compared to Final:
- COMs can play more than one defense card per turn
- The battle setup menu allows 1v2 battles
- Assist cards - Assist cards
- - Dice Fever sets dice to 6, not 5, and there is no Dice Fever + - - Dice Fever sets dice to 6, not 5, and there is no Dice Fever +
- - Rich + and Charity + also don't exist - - Rich + and Charity + also don't exist
+1 -2
View File
@@ -4,7 +4,6 @@ import subprocess
import sys import sys
from dataclasses import dataclass from dataclasses import dataclass
version_tokens = ("3OJ2", "3OJ3", "3OJ4", "3OJ5", "3OE0", "3OE1", "3OE2", "3OP0") 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("reloc0:\n")
f.write(" .offsetof start\n") f.write(" .offsetof start\n")
f.write("start:\n") f.write("start:\n")
f.write(" .include WriteCodeBlocksGC\n") f.write(" .include WriteCodeBlocks\n")
for region in write_regions: for region in write_regions:
f.write( f.write(
f" # region @ {region.address:08X} ({len(region.data) * 4} bytes)\n" f" # region @ {region.address:08X} ({len(region.data) * 4} bytes)\n"
+979 -979
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -1,7 +1,7 @@
patch required in TethVer12513 to get this to work: 0048210D EB patch required in 59NL to get this to work: 0048210D EB
is_hangame callsites: is_hangame callsites in 59NL:
0040457C - ??? (something in TDataProtocol?) 0040457C - don't save password on disconnect
004820F4 - client version check (use patch above to bypass) 004820F4 - client version check (use patch above to bypass)
00708318 - patch server domain name 00708318 - patch server domain name
00708348 - patch server port 00708348 - patch server port
+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] 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 */ 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 */ 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 Dropped Mag Colour Bug Fix
BugFixes BugFixes
Binary file not shown.
Binary file not shown.
+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 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 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 here inside the usbb-resources folder for your convenience they are the same ones
from the old official USBB client from the old official USBB client
View File
View File
View File
Binary file not shown.
Binary file not shown.
+340 -188
View File
@@ -1,188 +1,340 @@
0007 = Set by rico capsule in caves * = verified from client or quest disassembly
000B = P2 Tyrell Start
000C = P2 Irene Start 0007 = Set by rico capsule in caves
000D = P2 Scientist 1 Start 000B * = Has seen first single-mode Tyrell conversation (Episode 1)
000E = P2 Scientist 2 Start 000C = P2 Irene Start
000F = P2 More Scientist stuff. 000D = P2 Scientist 1 Start
0010 = P2 Irene after talking to Tyrell 000E = P2 Scientist 2 Start
0011 = Read a rico capsule (any) 000F = P2 More Scientist stuff.
0012 = P2 Scientist after talking to Irene. 0010 = P2 Irene after talking to Tyrell
0013 = P2 Menu 6, quest counter / Tekker talked to 0011 = Read a rico capsule (any)
0014 = Entered Forest 1 0012 = P2 Scientist after talking to Irene.
0015 = Entered Forest 2 0013 = P2 Menu 6, quest counter / Tekker talked to
0016 = Entered Dragon Area 0014 * = Has been to Forest 1
0017 = Dragon defeated 0015 = Entered Forest 2
0018 = Caves unlocked 0016 * = TBoss1Dragon encountered
0018 = P2 Principle after defeating dragon 0017 * = Dragon defeated (Caves unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 1)
0019 = P2 Scientist after defeating dragon 0018 * = Talked with Tyrell after defeating Dragon (Caves unlocked in offline single mode (pre-V4))
001E = Entered Caves 1 (Gov 2-1) 0019 = P2 Scientist after defeating dragon
001F = Entered De Rol Le in 2-4 001E * = Has been to Cave 1
0020 = De Ro lee defeated 001F = Entered De Rol Le in 2-4
0021 = Mines unlocked (P2 Tyrell after defeating De Rol Le) 0020 * = De Rol Le defeated (Mines unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 2)
0028 = Entered Mines 1 0021 * = Talked with Tyrell after defeating De Rol Le (Mines unlocked in offline single mode (pre-V4))
0029 = Entered Vol Opt Area 0028 * = Has been to Mine 1
002A = Defeated Vol Opt 0029 * = TBoss3Volopt encountered
002B = Set by rico capsule about the 3 seals (after vol opt). 002A * = Vol Opt defeated (Ruins unlocked in online/multi mode (pre-V4); sets command 10 quest tier to 3)
002C = Activated Forest monument 002B = Set by rico capsule about the 3 seals (after vol opt).
002D = Activated Caves monument (Gov 2-2) 002C * = Activated Forest monument (checked by TODoorVoShip_update and TODoorVoShip_init)
002E = Activated Mines monument 002D * = Activated Caves monument (checked by TODoorVoShip_update and TODoorVoShip_init)
002F = Activated all monuments 002E * = Activated Mines monument (checked by TODoorVoShip_update and TODoorVoShip_init)
0030 = Entered Ruins 1 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)
0032 = Entered Falz 1 0030 * = Has been to Ruins 1 (Ruins unlocked in offline single mode (pre-V4))
0035 = Hard mode unlocked 0032 * = TBoss4Type1 encountered
0036 = Entered Falz 3 // Very Hard mode unlocked (?) 0033 * = TBoss4Type1 defeated; sets command 10 quest tier to 4
0037 = Ultimate unlocked 0034 * = TBoss4Type2 encountered
0046 = One CCA door lock unlocked 0035 * = TBoss4Type2 defeated; unlocks Hard if set in Normal
0047 = One CCA door lock unlocked 0036 * = TBoss4Type3 encountered
0048 = One CCA door lock unlocked 0037 * = TBoss4Type3 defeated; unlocks Very Hard or Ultimate if set in Hard or Very Hard respectively
0049 = Entered Laboratory 0046 * = First CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
004A = Lab Assistant Start 0047 * = Second CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
004B = Entered Temple Beta 0048 * = Third CCA door lock unlocked (TODO: Cleared by 59NL:006585E4; is this triggered anywhere?)
004C = Defeated Barba Ray 0049 = Entered Laboratory
004D = Lab Assistant after defeating barba ray 004A = Lab Assistant Start
004E = Entered Spaceship Beta 004B * = Has been to VR Temple Beta
004F = Defeated Gol Dragon 004C * = Barba Ray defeated (VR Spaceship unlocked in online/multi mode (pre-V4))
0051 = Entered CCA 004D * = Talked with Lab Assistant after defeating Barba Ray (VR Spaceship unlocked in offline single mode (pre-V4))
0052 = Defeated Gal Gyrphon // Defeated Gol dragon in seat of heart (?) 004E * = Has been to VR Spaceship Beta
0054 = Entered Seabed Upper 004F * = TBoss8Dragon defeated (CCA unlocked in online/multi mode (pre-V4))
0057 = Defeated Olga Flow 0050 * = CCA unlocked in offline single mode (pre-V4)
005B = Lab Natasha Start 0051 * = Has been to CCA
005C = Lab Natasha after VR temple 0052 * = Gal Gryphon defeated (Seabed unlocked in online/multi mode (pre-V4))
005D = Lab Natasha after VR Spaceship 0053 * = Seabed unlocked in offline single mode (pre-V4)
005E = Lab Assistant after defeating Gal gryphon 0054 * = Has been to Seabed Upper
005F = After reading the last capsule from flowen 0055 * = Has been to Seabed Lower
0060 = Lab Natasha after CCA 0056 * = TBoss6PlotFalz encountered
0065 = Cleared Magnitude of Metal 0057 * = TBoss6PlotFalz defeated (unlocks the next difficulty level)
0067 = Cleared Claiming a Stake 005B * = Has seen first single-mode Natasha conversation (Episode 1)
0069 = Cleared Value of Money 005C = Lab Natasha after VR temple
006B = Cleared Battle Training 005D = Lab Natasha after VR Spaceship
006D = Cleared Journalistic Pursuit 005E = Lab Assistant after defeating Gal gryphon
006F = Cleared The Fake in Yellow 005F = After reading the last capsule from flowen
0071 = Cleared Native Research 0060 = Lab Natasha after CCA
0073 = Cleared Forest of Sorrow 0064 * = Magnitude of Metal unlocked
0075 = Cleared Gran Squall 0065 * = Magnitude of Metal completed
0077 = Cleared Addicting Food 0066 * = Claiming A Stake unlocked
0079 = Cleared The Lost Bride 0067 * = Claiming A Stake completed
007B = Cleared Waterfall Tears 0068 * = The Value of Money unlocked
007D = Cleared Black Paper 0069 * = The Value of Money completed
007F = Cleared Secret Delivery 006A * = Battle Training unlocked
0081 = Cleared Soul of a Blacksmith 006B * = Battle Training completed
0083 = Cleared Letter from Lionel 006C * = Journalistic Pursuit unlocked
0085 = Cleared The Grave's Butler 006D * = Journalistic Pursuit completed
0087 = Cleared Knowing One's Heart 006E * = The Fake in yellow unlocked
0089 = Cleared The Retired Hunter 006F * = The Fake in yellow completed
008B = Cleared Dr. Osto's Research 0070 * = Native Research unlocked
008D = Cleared Unsealed Door 0071 * = Native Research completed
008F = Cleared Soul of Steel 0072 * = Forest of Sorrow unlocked
0091 = Cleared Doc's Secret Plan (able to make enemy part weapons) 0073 * = Forest of Sorrow completed
0093 = Cleared Seek my Master 0074 * = Gran Squall unlocked
0095 = Cleared From the Depths 0075 * = Gran Squall completed
0096 = Unknown (set in the fake in yellow) 0076 * = Addicting Food unlocked
0097 = Seat of heart unknown 0077 * = Addicting Food completed
009B = Cleared Central Dome Fire Swirl 0078 * = The Lost Bride unlocked
00A1 = Cleared Seat of the Heart 0079 * = The Lost Bride completed
00C9 = Got an enemy weapon converted 007A * = Waterfall tears unlocked
00CA = unknown Fake In Yellow 007B * = Waterfall tears completed
00CE = unknown Fake In Yellow 007C * = Black Paper unlocked
00D3 = Dr.Osto's research black paper subplot. Told Sue your name 007D * = Black Paper completed
00D4 = Dr.Osto's research black paper subplot. Didn't tell Sue your name from before. 007E * = Secret Delivery unlocked
00D5 = Dr.Osto's research black paper subplot. Did tell Sue your name from before. 007F * = Secret Delivery completed
00D6 = Unsealed door. black paper subplot Talked to Sue. Refused to tell her your name 0080 * = Soul of a Blacksmith unlocked
00D7 = Unsealed door. black paper subplot. bernie tells you Sue is part of black paper. 0081 * = Soul of a Blacksmith completed
00D8 = Black paper subplot in waterfall of tears talking to Sue 0082 * = Letter from Lionel unlocked
00D9 = Black paper subplot in Black paper talking to Sue (used option 2) 0083 * = Letter from Lionel completed
00DB = Black paper subplot in Black paper talking to Sue (used any option) 0084 * = The Grave's Butler unlocked
00DE = Black paper subplot in Black paper talked to Sue at the end of quest? 0085 * = The Grave's Butler completed
00DF = Knowing ones heart talked to Bernie? 0086 * = Knowing One's Heart unlocked
00E0 = Seek my master. Zoke ,Donoph subplot? 0087 * = Knowing One's Heart completed
00E2 = Bernie Gran Squall 0088 * = Retired Hunter unlocked
00E7 = Defeated Kireek in waterfall of tears 0089 * = Retired Hunter completed
00E8 = Black paper subplot in black paper. defeated Kireek... 008A * = Dr. Osto's Research unlocked
00EB = Black paper subplot in from the depths. Defeated Kireek and got soul eater! 008B * = Dr. Osto's Research completed
00F1 = Secret delivery. Started the Weapons subplot //is cleared if quest is left 008C * = The Unsealed Door unlocked
00F3 = Weapon badge approval for claiming the snake //is cleared if quest is left 008D * = The Unsealed Door completed
00F4 = Weapon badge approval for the lost bride //is cleared if quest is left 008E * = Soul of Steel unlocked
00F5 = Weapon badge approval for gran squall //is cleared if quest is left 008F * = Soul of Steel completed
00F6 = Secret delivery. Got AKIKO's FRYING PAN! 0090 * = Doc's Secret Plan unlocked
00FB = Got Orochi-agito 0091 * = Doc's Secret Plan completed
00FB = Received OROCHI-AGITO! 0092 * = Seek My Master unlocked
00FD = Unknown addicting food 0093 * = Seek My Master completed
0105 = Central dome fire swirl. Got Glory of the past! 0094 * = From the Depths unlocked
0106 = Central dome fire swirl. Got Mark3. 0095 * = From the Depths completed
0107 = Central dome fire swirl. got Sonic knuckles 0096 = Unknown (set in the fake in yellow)
0108 = Central dome fire swirl. got mail from BOGARDE 0097 * = TBoss4Type3 defeated while any player was using Dark Flow, Dark Meteor, or Dark Bridge
0109 = Central dome fire swirl. got mail from ANNA 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)
010A = Central dome fire swirl. got mail from NADJA 0099 * = TBoss4Thanks destroyed
010B = Central dome fire swirl. got mail from Lionel 009A * = TBoss6Thanks destroyed
010C = Soul of the blacksmith. Got one of the 3 special weapons! 009B = Cleared Central Dome Fire Swirl
010D = Donoph Baz dies The Retired Hunter 009F * = Central Dome Fire Swirl unlocked
010E = Seat of heart unknown 00A0 * = Central Dome Fire Swirl completed
010F = Seat of heart unknown 00A1 * = Seat of the Heart completed
0110 = Seat of heart unknown 00A2 * = The East Tower completed
0111 = Seat of heart unknown 00A3 * = The East Tower completed
0112 = Seat of heart unknown 00A4 * = The West Tower completed
0113 = Seat of heart unknown 00A5 * = The West Tower completed
0187 = Soul of steel. Got Marina's bag! //dreamcast 00C9 = Got an enemy weapon converted
0188 = Soul of steel. Unknown. 00CA = unknown Fake In Yellow
0191 = Capsule Elly VR 00CE = unknown Fake In Yellow
0197 = Cleared VR Temple 00D3 = Dr.Osto's research black paper subplot. Told Sue your name
01AD = Capsule elly CCA 00D4 = Dr.Osto's research black paper subplot. Didn't tell Sue your name from before.
01AE = Capsule elly CCA 00D5 = Dr.Osto's research black paper subplot. Did tell Sue your name from before.
01B3 = After reading a capsule from flowen 00D6 = Unsealed door. black paper subplot Talked to Sue. Refused to tell her your name
01D6 = Set after unlocking vr spaceship 00D7 = Unsealed door. black paper subplot. bernie tells you Sue is part of black paper.
01F5 = Episode1: Cleared government 1-1 00D8 = Black paper subplot in waterfall of tears talking to Sue
01F7 = Episode1: Cleared government 1-2 00D9 = Black paper subplot in Black paper talking to Sue (used option 2)
01F9 = Episode1: Cleared government 1-3 00DB = Black paper subplot in Black paper talking to Sue (used any option)
01FB = Episode1: Cleared government 2-1 00DE = Black paper subplot in Black paper talked to Sue at the end of quest?
01FD = Episode1: Cleared government 2-2 00DF = Knowing ones heart talked to Bernie?
01FF = Episode1: Cleared government 2-3 00E0 = Seek my master. Zoke ,Donoph subplot?
0201 = Episode1: Cleared government 2-4 00E2 = Bernie Gran Squall
0203 = Episode1: Cleared government 3-1 00E7 = Defeated Kireek in waterfall of tears
0205 = Episode1: Cleared government 3-2 00E8 = Black paper subplot in black paper. defeated Kireek...
0207 = Episode1: Cleared government 3-3 00EB = Black paper subplot in from the depths. Defeated Kireek and got soul eater!
0209 = Episode1: Cleared government 4-1 00F1 = Secret delivery. Started the Weapons subplot //is cleared if quest is left
020B = Episode1: Cleared government 4-2 00F3 = Weapon badge approval for claiming the snake //is cleared if quest is left
020D = Episode1: Cleared government 4-3 00F4 = Weapon badge approval for the lost bride //is cleared if quest is left
020F = Episode1: Cleared government 4-4 00F5 = Weapon badge approval for gran squall //is cleared if quest is left
0211 = Episode1: Cleared government 4-5 00F6 = Secret delivery. Got AKIKO's FRYING PAN!
0213 = Episode2: Cleared government 5-1 // Talked to Tekker (?) 00FB = Got Orochi-agito
0214 = Entered Forest 1 00FD = Unknown addicting food
0215 = Episode2: Cleared government 5-2 0105 = Central dome fire swirl. Got Glory of the past!
0217 = Episode2: Cleared government 5-3 // Defeated Dragon (?) 0106 = Central dome fire swirl. Got Mark3.
0219 = Episode2: Cleared government 5-4 0107 = Central dome fire swirl. got Sonic knuckles
021B = Episode2: Cleared government 5-5 0108 = Central dome fire swirl. got mail from BOGARDE
021D = Episode2: Cleared government 6-1 0109 = Central dome fire swirl. got mail from ANNA
021F = Episode2: Cleared government 6-2 010A = Central dome fire swirl. got mail from NADJA
0220 = Defeated De Rol Le 010B = Central dome fire swirl. got mail from Lionel
0221 = Episode2: Cleared government 6-3 010C = Soul of the blacksmith. Got one of the 3 special weapons!
0223 = Episode2: Cleared government 6-4 010D = Donoph Baz dies The Retired Hunter
0225 = Episode2: Cleared government 6-5 010E = Seat of heart unknown
0227 = Episode2: Cleared government 7-1 010F = Seat of heart unknown
0229 = Episode2: Cleared government 7-2 0110 = Seat of heart unknown
022A = Defeated Vol Opt (002A and 022A together on hard mode) 0111 = Seat of heart unknown
022B = Episode2: Cleared government 7-3 // Rico capsule after Vol Opt, at Ruins door (?) 0112 = Seat of heart unknown
022D = Episode2: Cleared government 7-4 // Entered Caves 2 (?) 0113 = Seat of heart unknown
022F = Episode2: Cleared government 7-5 0187 = Soul of steel. Got Marina's bag! //dreamcast
0230 = Entered Ruins 1 0188 = Soul of steel. Unknown.
0231 = Episode2: Cleared government 8-1 0191 = Capsule Elly VR
0233 = Episode2: Cleared government 8-2 0197 = Cleared VR Temple
0234 = Entered Falz 2 01AD = Capsule elly CCA
0235 = Episode2: Cleared government 8-3 01AE = Capsule elly CCA
0246 = Activated Jungle East big door switch 01B3 = After reading a capsule from flowen
0248 = Activated Seaside big door switch 01D6 = Set after unlocking vr spaceship
024F = Defeated Gol Dragon 01F5 * = Episode1: Cleared government 1-1
0252 = Defeated Gal Gryphon 01F7 * = Episode1: Cleared government 1-2
02BD = Episode4: Cleared government 9-1 01F9 * = Episode1: Cleared government 1-3; Caves unlocked (V4)
02BE = Episode4: Cleared government 9-2 01FB * = Episode1: Cleared government 2-1
02BF = Episode4: Cleared government 9-3 01FD * = Episode1: Cleared government 2-2
02C0 = Episode4: Cleared government 9-4 01FF * = Episode1: Cleared government 2-3
02C1 = Episode4: Cleared government 9-5 0201 * = Episode1: Cleared government 2-4; Mines unlocked (V4)
02C2 = Episode4: Cleared government 9-6 0203 * = Episode1: Cleared government 3-1
02C3 = Episode4: Cleared government 9-7 0205 * = Episode1: Cleared government 3-2
02C4 = Episode4: Cleared government 9-8 0207 * = Episode1: Cleared government 3-3; Ruins unlocked (V4)
0314 = Entered Forest 1 0209 * = Episode1: Cleared government 4-1
0330 = Entered Ruins 1 020B * = Episode1: Cleared government 4-2
03FA = P2 Menu 7, G-Counter // Talked to Momoka 020D * = Episode1: Cleared government 4-3
03FB = Nol start 020F * = Episode1: Cleared government 4-4
03FC = Cleared Ep2 government on ultimate 0211 * = Episode1: Cleared government 4-5
03FE = Cleared Ep2 government on normal-vh 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" #include "Text.hh"
using namespace std; AFSArchive::AFSArchive(std::shared_ptr<const std::string> data) : data(data) {
AFSArchive::AFSArchive(shared_ptr<const string> data)
: data(data) {
struct FileHeader { struct FileHeader {
be_uint32_t magic; be_uint32_t magic;
le_uint32_t num_files; le_uint32_t num_files;
@@ -26,7 +23,7 @@ AFSArchive::AFSArchive(shared_ptr<const string> data)
phosg::StringReader r(*this->data); phosg::StringReader r(*this->data);
const auto& header = r.get<FileHeader>(); const auto& header = r.get<FileHeader>();
if (header.magic != 0x41465300) { // 'AFS\0' 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) { 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); const auto& entry = this->entries.at(index);
if (entry.offset > this->data->size()) { 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()) { 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); 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 { 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); 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); return big_endian ? AFSArchive::generate_t<true>(files) : AFSArchive::generate_t<false>(files);
} }
template <bool BE> 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; phosg::StringWriter w;
w.put_u32b(0x41465300); // 'AFS\0' w.put_u32b(0x41465300); // 'AFS\0'
w.put<U32T<BE>>(files.size()); w.put<U32T<BE>>(files.size());
// It seems entries are aligned to 0x800-byte boundaries, and the file's // It seems entries are aligned to 0x800-byte boundaries, and the file's header is always 0x80000 (!) bytes, most of
// header is always 0x80000 (!) bytes, most of which is unused // which is unused
uint32_t data_offset = 0x80000; uint32_t data_offset = 0x80000;
for (const auto& file : files) { for (const auto& file : files) {
w.put<U32T<BE>>(data_offset); w.put<U32T<BE>>(data_offset);
+4
View File
@@ -23,6 +23,10 @@ public:
return this->entries; return this->entries;
} }
inline size_t num_entries() const {
return this->entries.size();
}
std::pair<const void*, size_t> get(size_t index) const; std::pair<const void*, size_t> get(size_t index) const;
std::string get_copy(size_t index) const; std::string get_copy(size_t index) const;
phosg::StringReader get_reader(size_t index) const; phosg::StringReader get_reader(size_t index) const;
+238 -258
View File
File diff suppressed because it is too large Load Diff
+12 -60
View File
@@ -17,10 +17,6 @@ struct DCNTELicense {
std::string serial_number; std::string serial_number;
std::string access_key; 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); static std::shared_ptr<DCNTELicense> from_json(const phosg::JSON& json);
phosg::JSON json() const; phosg::JSON json() const;
}; };
@@ -29,10 +25,6 @@ struct V1V2License {
uint32_t serial_number = 0; uint32_t serial_number = 0;
std::string access_key; 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); static std::shared_ptr<V1V2License> from_json(const phosg::JSON& json);
phosg::JSON json() const; phosg::JSON json() const;
}; };
@@ -42,10 +34,6 @@ struct GCLicense {
std::string access_key; std::string access_key;
std::string password; 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); static std::shared_ptr<GCLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const; phosg::JSON json() const;
}; };
@@ -55,10 +43,6 @@ struct XBLicense {
uint64_t user_id = 0; uint64_t user_id = 0;
uint64_t account_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); static std::shared_ptr<XBLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const; phosg::JSON json() const;
}; };
@@ -67,10 +51,6 @@ struct BBLicense {
std::string username; std::string username;
std::string password; 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); static std::shared_ptr<BBLicense> from_json(const phosg::JSON& json);
phosg::JSON json() const; phosg::JSON json() const;
}; };
@@ -92,8 +72,7 @@ struct Account {
ADMINISTRATOR = 0x000000FF, ADMINISTRATOR = 0x000000FF,
ROOT = 0x7FFFFFFF, ROOT = 0x7FFFFFFF,
IS_SHARED_ACCOUNT = 0x80000000, IS_SHARED_ACCOUNT = 0x80000000,
// NOTE: When adding or changing license flags, don't forget to change the // NOTE: When adding or changing license flags, don't forget to change the documentation in the shell's help text.
// documentation in the shell's help text.
UNUSED_BITS = 0x70FFFF00, UNUSED_BITS = 0x70FFFF00,
// clang-format on // clang-format on
}; };
@@ -169,8 +148,7 @@ struct Login {
bool account_was_created = false; bool account_was_created = false;
// This field will never be null // This field will never be null
std::shared_ptr<Account> account; std::shared_ptr<Account> account;
// Exactly one of the following will be non-null, representing the license // Exactly one of the following will be non-null, representing the license that the client logged in with
// that the client logged in with
std::shared_ptr<DCNTELicense> dc_nte_license; std::shared_ptr<DCNTELicense> dc_nte_license;
std::shared_ptr<V1V2License> dc_license; std::shared_ptr<V1V2License> dc_license;
std::shared_ptr<V1V2License> pc_license; std::shared_ptr<V1V2License> pc_license;
@@ -178,8 +156,6 @@ struct Login {
std::shared_ptr<XBLicense> xb_license; std::shared_ptr<XBLicense> xb_license;
std::shared_ptr<BBLicense> bb_license; std::shared_ptr<BBLicense> bb_license;
uint64_t proxy_session_id() const;
std::string str() 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<Account> from_account_id(uint32_t account_id) const;
std::shared_ptr<Login> from_dc_nte_credentials( std::shared_ptr<Login> from_dc_nte_credentials(
const std::string& serial_number, const std::string& serial_number, const std::string& access_key, bool allow_create);
const std::string& access_key,
bool allow_create);
std::shared_ptr<Login> from_dc_credentials( std::shared_ptr<Login> from_dc_credentials(
uint32_t serial_number, uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create);
const std::string& access_key, std::shared_ptr<Login> from_pc_nte_credentials(uint32_t guild_card_number, bool allow_create);
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( std::shared_ptr<Login> from_pc_credentials(
uint32_t serial_number, uint32_t serial_number, const std::string& access_key, const std::string& character_name, bool allow_create);
const std::string& access_key,
const std::string& character_name,
bool allow_create);
std::shared_ptr<Login> from_gc_credentials( std::shared_ptr<Login> from_gc_credentials(
uint32_t serial_number, uint32_t serial_number,
const std::string& access_key, const std::string& access_key,
@@ -255,14 +221,9 @@ public:
const std::string& character_name, const std::string& character_name,
bool allow_create); bool allow_create);
std::shared_ptr<Login> from_xb_credentials( std::shared_ptr<Login> from_xb_credentials(
const std::string& gamertag, const std::string& gamertag, uint64_t user_id, uint64_t account_id, bool allow_create);
uint64_t user_id,
uint64_t account_id,
bool allow_create);
std::shared_ptr<Login> from_bb_credentials( std::shared_ptr<Login> from_bb_credentials(
const std::string& username, const std::string& username, const std::string* password, bool allow_create);
const std::string* password,
bool allow_create);
std::shared_ptr<Account> create_temporary_account_for_shared_account( std::shared_ptr<Account> create_temporary_account_for_shared_account(
std::shared_ptr<const Account> src_a, const std::string& variation_data) const; std::shared_ptr<const Account> src_a, const std::string& variation_data) const;
@@ -270,8 +231,6 @@ public:
protected: protected:
bool force_all_temporary; 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; mutable std::shared_mutex lock;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_account_id; 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; 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); void add_locked(std::shared_ptr<Account> a);
std::shared_ptr<Login> from_dc_nte_credentials_locked( std::shared_ptr<Login> from_dc_nte_credentials_locked(
const std::string& serial_number, const std::string& serial_number, const std::string& access_key);
const std::string& access_key);
std::shared_ptr<Login> from_dc_credentials_locked( std::shared_ptr<Login> from_dc_credentials_locked(
uint32_t serial_number, uint32_t serial_number, const std::string& access_key, const std::string& character_name);
const std::string& access_key,
const std::string& character_name);
std::shared_ptr<Login> from_pc_credentials_locked( std::shared_ptr<Login> from_pc_credentials_locked(
uint32_t serial_number, uint32_t serial_number, const std::string& access_key, const std::string& character_name);
const std::string& access_key,
const std::string& character_name);
std::shared_ptr<Login> from_gc_credentials_locked( std::shared_ptr<Login> from_gc_credentials_locked(
uint32_t serial_number, uint32_t serial_number,
const std::string& access_key, const std::string& access_key,
const std::string* password, const std::string* password,
const std::string& character_name); const std::string& character_name);
std::shared_ptr<Login> from_xb_credentials_locked(uint64_t user_id); std::shared_ptr<Login> from_xb_credentials_locked(uint64_t user_id);
std::shared_ptr<Login> from_bb_credentials_locked( std::shared_ptr<Login> from_bb_credentials_locked(const std::string& username, const std::string* password);
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
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
struct DiffEntry {
uint32_t address;
std::string a_data;
std::string b_data;
};
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<DiffEntry> diff_dol_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<DiffEntry> diff_xbe_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
+616 -113
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #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); 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_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); 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);
+405
View File
@@ -0,0 +1,405 @@
#include "AsyncHTTPServer.hh"
#include <inttypes.h>
#include <stdlib.h>
#include <phosg/Encoding.hh>
#include <phosg/Network.hh>
#include <phosg/Time.hh>
#include <string>
#include <vector>
#include "AsyncUtils.hh"
#include "Loggers.hh"
#include "Revision.hh"
#include "Server.hh"
static const std::unordered_map<int, const char*> explanation_for_response_code{
{100, "Continue"},
{101, "Switching Protocols"},
{102, "Processing"},
{200, "OK"},
{201, "Created"},
{202, "Accepted"},
{203, "Non-Authoritative Information"},
{204, "No Content"},
{205, "Reset Content"},
{206, "Partial Content"},
{207, "Multi-Status"},
{208, "Already Reported"},
{226, "IM Used"},
{300, "Multiple Choices"},
{301, "Moved Permanently"},
{302, "Found"},
{303, "See Other"},
{304, "Not Modified"},
{305, "Use Proxy"},
{307, "Temporary Redirect"},
{308, "Permanent Redirect"},
{400, "Bad Request"},
{401, "Unathorized"},
{402, "Payment Required"},
{403, "Forbidden"},
{404, "Not Found"},
{405, "Method Not Allowed"},
{406, "Not Acceptable"},
{407, "Proxy Authentication Required"},
{408, "Request Timeout"},
{409, "Conflict"},
{410, "Gone"},
{411, "Length Required"},
{412, "Precondition Failed"},
{413, "Request Entity Too Large"},
{414, "Request-URI Too Long"},
{415, "Unsupported Media Type"},
{416, "Requested Range Not Satisfiable"},
{417, "Expectation Failed"},
{418, "I\'m a Teapot"},
{420, "Enhance Your Calm"},
{422, "Unprocessable Entity"},
{423, "Locked"},
{424, "Failed Dependency"},
{426, "Upgrade Required"},
{428, "Precondition Required"},
{429, "Too Many Requests"},
{431, "Request Header Fields Too Large"},
{444, "No Response"},
{449, "Retry With"},
{451, "Unavailable For Legal Reasons"},
{500, "Internal Server Error"},
{501, "Not Implemented"},
{502, "Bad Gateway"},
{503, "Service Unavailable"},
{504, "Gateway Timeout"},
{505, "HTTP Version Not Supported"},
{506, "Variant Also Negotiates"},
{507, "Insufficient Storage"},
{508, "Loop Detected"},
{509, "Bandwidth Limit Exceeded"},
{510, "Not Extended"},
{511, "Network Authentication Required"},
{598, "Network Read Timeout Error"},
{599, "Network Connect Timeout Error"},
};
HTTPError::HTTPError(int code, const std::string& what)
: std::runtime_error(what), code(code) {}
const std::string* HTTPRequest::get_header(const std::string& name) const {
auto its = this->headers.equal_range(name);
if (its.first == its.second) {
return nullptr;
}
const std::string* ret = &its.first->second;
its.first++;
if (its.first != its.second) {
throw std::out_of_range("Header appears multiple times: " + name);
}
return ret;
}
const std::string* HTTPRequest::get_query_param(const std::string& name) const {
auto its = this->query_params.equal_range(name);
if (its.first == its.second) {
return nullptr;
}
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);
}
return ret;
}
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)) {
s[write_offset] =
static_cast<char>(phosg::value_for_hex_char(s[read_offset + 1]) << 4) |
static_cast<char>(phosg::value_for_hex_char(s[read_offset + 2]));
read_offset += 3;
} else if (s[write_offset] == '+') {
s[write_offset] = ' ';
read_offset++;
} else {
s[write_offset] = s[read_offset];
read_offset++;
}
}
s.resize(write_offset);
}
HTTPClient::HTTPClient(asio::ip::tcp::socket&& sock) : r(std::move(sock)) {}
asio::awaitable<HTTPRequest> HTTPClient::recv_http_request(size_t max_line_size, size_t max_body_size) {
HTTPRequest req;
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 std::runtime_error("invalid HTTP request line");
}
const auto& method_token = line_tokens[0];
if (method_token == "GET") {
req.method = HTTPRequest::Method::GET;
} else if (method_token == "POST") {
req.method = HTTPRequest::Method::POST;
} else if (method_token == "DELETE") {
req.method = HTTPRequest::Method::DELETE;
} else if (method_token == "HEAD") {
req.method = HTTPRequest::Method::HEAD;
} else if (method_token == "PATCH") {
req.method = HTTPRequest::Method::PATCH;
} else if (method_token == "PUT") {
req.method = HTTPRequest::Method::PUT;
} else if (method_token == "UPDATE") {
req.method = HTTPRequest::Method::UPDATE;
} else if (method_token == "OPTIONS") {
req.method = HTTPRequest::Method::OPTIONS;
} else if (method_token == "CONNECT") {
req.method = HTTPRequest::Method::CONNECT;
} else if (method_token == "TRACE") {
req.method = HTTPRequest::Method::TRACE;
} else {
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 != 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('?');
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);
}
req.path = std::move(line_tokens[1]);
if (req.path.empty()) {
throw std::runtime_error("request path is missing");
}
auto query_tokens = phosg::split(query, '&');
for (auto& token : query_tokens) {
size_t equals_pos = token.find('=');
if (equals_pos == std::string::npos) {
url_decode_inplace(token);
req.query_params.emplace(std::move(token), "");
} else {
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));
}
}
auto prev_header_it = req.headers.end();
for (;;) {
std::string line = co_await this->r.read_line("\r\n", max_line_size);
if (line.empty()) {
break;
}
if (line[0] == ' ' || line[0] == '\t') {
if (prev_header_it == req.headers.end()) {
throw std::runtime_error("received header continuation line before any header");
} else {
phosg::strip_whitespace(line);
prev_header_it->second.append(1, ' ');
prev_header_it->second += line;
}
} else {
size_t colon_pos = line.find(':');
if (colon_pos == std::string::npos) {
throw std::runtime_error("malformed header line");
}
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));
}
}
auto transfer_encoding_header = req.get_header("transfer-encoding");
if (transfer_encoding_header && phosg::tolower(*transfer_encoding_header) == "chunked") {
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");
}
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");
}
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");
}
}
} 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");
} else if (content_length > 0) {
req.data = co_await this->r.read_data(content_length);
}
}
co_return req;
}
asio::awaitable<void> HTTPClient::send_http_response(const HTTPResponse& resp) {
AsyncWriteCollector w;
w.add(std::format("{} {} {}\r\n",
resp.http_version, resp.response_code, explanation_for_response_code.at(resp.response_code)));
for (const auto& it : resp.headers) {
w.add(it.first + ": " + it.second + "\r\n");
}
if (!resp.data.empty()) {
w.add(std::format("Content-Length: {}\r\n", resp.data.size()));
}
w.add("\r\n");
if (!resp.data.empty()) {
w.add_reference(resp.data.data(), resp.data.size());
}
co_await w.write(this->r.get_socket());
}
asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_data_size) {
WebSocketMessage prev_msg;
bool prev_msg_present = false;
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
co_await this->r.read_data_into(msg.header, 2);
// Get the payload size
bool has_mask = msg.header[1] & 0x80;
size_t payload_size = msg.header[1] & 0x7F;
if (payload_size == 0x7F) {
phosg::be_uint64_t wire_size;
co_await this->r.read_data_into(&wire_size, sizeof(wire_size));
payload_size = wire_size;
} else if (payload_size == 0x7E) {
phosg::be_uint16_t wire_size;
co_await this->r.read_data_into(&wire_size, sizeof(wire_size));
payload_size = wire_size;
}
if (payload_size > max_data_size) {
throw std::runtime_error("Incoming WebSocket message exceeds size limit");
}
// Read the masking key if present
if (has_mask) {
co_await this->r.read_data_into(msg.mask_key, sizeof(msg.mask_key));
}
// Read and unmask message data
msg.data = co_await this->r.read_data(payload_size);
if (has_mask) {
for (size_t x = 0; x < msg.data.size(); x++) {
msg.data[x] ^= msg.mask_key[x & 3];
}
}
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)
uint8_t opcode = msg.header[0] & 0x0F;
if (opcode & 0x08) {
if (opcode == 0x0A) {
// Ping response; ignore it
} else if (opcode == 0x08) {
// Close message
co_await this->send_websocket_message(msg.data, msg.opcode);
this->r.close();
} else if (opcode == 0x09) {
// Ping message
co_await this->send_websocket_message(msg.data, 0x0A);
} else {
// Unknown control message type
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 (prev_msg_present == (opcode != 0)) {
this->r.close();
continue;
}
// Save the message opcode, if present, and append the frame data
if (!prev_msg_present) {
prev_msg = std::move(msg);
} else {
prev_msg.header[0] = msg.header[0];
prev_msg.header[1] = msg.header[1];
if (opcode) {
prev_msg.opcode = msg.opcode;
}
if (has_mask) {
prev_msg.mask_key[0] = msg.mask_key[0];
prev_msg.mask_key[1] = msg.mask_key[1];
prev_msg.mask_key[2] = msg.mask_key[2];
prev_msg.mask_key[3] = msg.mask_key[3];
}
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 (prev_msg.header[0] & 0x80) {
co_return prev_msg;
}
}
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) {
phosg::StringWriter w;
w.put_u8(0x80 | (opcode & 0x0F));
if (size > 0xFFFF) {
w.put_u8(0x7F);
w.put_u64b(size);
} else if (size > 0x7D) {
w.put_u8(0x7E);
w.put_u16b(size);
} else {
w.put_u8(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);
}
asio::awaitable<void> HTTPClient::send_websocket_message(const std::string& data, uint8_t opcode) {
return this->send_websocket_message(data.data(), data.size(), opcode);
}
const HTTPServerLimits DEFAULT_HTTP_LIMITS;
+348
View File
@@ -0,0 +1,348 @@
#pragma once
#include "WindowsPlatform.hh"
#include <stdlib.h>
#include <asio.hpp>
#include <exception>
#include <functional>
#include <memory>
#include <optional>
#include <phosg/Encoding.hh>
#include <phosg/Hash.hh>
#include <phosg/Time.hh>
#include <string>
#include "AsyncUtils.hh"
#include "Server.hh"
struct HTTPRequest {
enum class Method {
GET = 0,
POST,
DELETE,
HEAD,
PATCH,
PUT,
UPDATE,
OPTIONS,
CONNECT,
TRACE,
};
std::string http_version;
Method method;
std::string path;
std::string fragment;
std::unordered_multimap<std::string, std::string> headers; // Header names converted to all lowercase
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.
const std::string* get_header(const std::string& name) const;
const std::string* get_query_param(const std::string& name) const;
};
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 isn't blank.
std::unordered_multimap<std::string, std::string> headers;
std::string data;
};
struct WebSocketMessage {
uint8_t header[2] = {0, 0};
uint8_t opcode = 0x01;
uint8_t mask_key[4] = {0, 0, 0, 0};
std::string data;
};
class HTTPError : public std::runtime_error {
public:
HTTPError(int code, const std::string& what);
int code;
};
struct HTTPClient {
AsyncSocketReader r;
uint64_t last_communication_time = 0;
bool is_websocket = false;
HTTPClient(asio::ip::tcp::socket&& sock);
asio::awaitable<HTTPRequest> recv_http_request(size_t max_line_size, size_t max_body_size);
asio::awaitable<void> send_http_response(const HTTPResponse& resp);
asio::awaitable<WebSocketMessage> recv_websocket_message(size_t max_data_size);
asio::awaitable<void> send_websocket_message(const void* data, size_t size, uint8_t opcode = 0x01);
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
size_t max_http_keepalive_idle_usecs = 300 * 1000 * 1000; // 5 minutes (0 = no limit)
size_t max_websocket_message_size = 0x200000; // 2MB
size_t max_websocket_idle_usecs = 0; // No limit by default
};
extern const HTTPServerLimits DEFAULT_HTTP_LIMITS;
template <typename ClientT = HTTPClient>
class AsyncHTTPServer : public Server<ClientT, ServerSocket> {
public:
explicit AsyncHTTPServer(
std::shared_ptr<asio::io_context> io_context,
const std::string& log_prefix = "[AsyncHTTPServer] ",
const HTTPServerLimits& limits = DEFAULT_HTTP_LIMITS)
: Server<ClientT, ServerSocket>(io_context, log_prefix), limits(limits) {}
AsyncHTTPServer(const AsyncHTTPServer&) = delete;
AsyncHTTPServer(AsyncHTTPServer&&) = delete;
AsyncHTTPServer& operator=(const AsyncHTTPServer&) = delete;
AsyncHTTPServer& operator=(AsyncHTTPServer&&) = delete;
virtual ~AsyncHTTPServer() = default;
void listen(const std::string& addr, int port) {
if (port == 0) {
throw std::runtime_error("Listening port cannot be zero");
}
asio::ip::address asio_addr = addr.empty() ? asio::ip::address_v4::any() : asio::ip::make_address(addr);
auto sock = std::make_shared<ServerSocket>();
sock->name = std::format("http:{}:{}", addr, port);
sock->endpoint = asio::ip::tcp::endpoint(asio_addr, port);
this->add_socket(std::move(sock));
}
protected:
HTTPServerLimits limits;
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;
}
auto connection_header = req.get_header("connection");
if (!connection_header || phosg::tolower(*connection_header) != "upgrade") {
co_return false;
}
auto upgrade_header = req.get_header("upgrade");
if (!upgrade_header || phosg::tolower(*upgrade_header) != "websocket") {
co_return false;
}
auto sec_websocket_key_header = req.get_header("sec-websocket-key");
if (!sec_websocket_key_header) {
co_return false;
}
std::string sec_websocket_accept_data = *sec_websocket_key_header + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::string sec_websocket_accept = phosg::base64_encode(phosg::SHA1(sec_websocket_accept_data).bin());
HTTPResponse resp;
resp.http_version = req.http_version;
resp.response_code = 101;
resp.headers.emplace("Upgrade", "websocket");
resp.headers.emplace("Connection", "upgrade");
resp.headers.emplace("Sec-WebSocket-Accept", std::move(sec_websocket_accept));
co_await c->send_http_response(resp);
c->is_websocket = true;
co_return true;
}
[[nodiscard]] virtual std::shared_ptr<ClientT> create_client(
std::shared_ptr<ServerSocket>, asio::ip::tcp::socket&& client_sock) {
return std::make_shared<HTTPClient>(std::move(client_sock));
}
// 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.
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;
}
virtual asio::awaitable<void> handle_client(std::shared_ptr<ClientT> c) {
asio::steady_timer idle_timer(*this->io_context);
while (c->r.get_socket().is_open()) {
if (c->is_websocket) {
WebSocketMessage msg = co_await c->recv_websocket_message(this->limits.max_websocket_message_size);
idle_timer.cancel();
try {
co_await this->handle_websocket_message(c, std::move(msg));
} catch (const std::exception& e) {
c->r.close();
}
} else {
HTTPRequest req = co_await c->recv_http_request(
this->limits.max_http_request_line_size, this->limits.max_http_data_size);
idle_timer.cancel();
std::unique_ptr<HTTPResponse> resp;
try {
resp = co_await this->handle_request(c, std::move(req));
} catch (const std::exception& e) {
resp = std::make_unique<HTTPResponse>();
resp->http_version = req.http_version;
resp->response_code = 500;
resp->headers.emplace("Content-Type", "text/plain");
resp->data = "Internal server error:\n";
resp->data += e.what();
}
if (resp) {
co_await c->send_http_response(*resp);
}
if (!c->is_websocket) {
auto* conn_header = req.get_header("connection");
if (!conn_header || (*conn_header != "keep-alive")) {
c->r.close();
}
}
}
size_t idle_usecs_limit = c->is_websocket
? this->limits.max_websocket_idle_usecs
: this->limits.max_http_keepalive_idle_usecs;
if (idle_usecs_limit && c->r.get_socket().is_open()) {
idle_timer.expires_after(std::chrono::microseconds(idle_usecs_limit));
idle_timer.async_wait([c](std::error_code ec) {
if (!ec) {
c->r.close();
}
});
}
}
idle_timer.cancel();
}
};
+160
View File
@@ -0,0 +1,160 @@
#include "AsyncUtils.hh"
#include <asio.hpp>
#include <exception>
#include <functional>
#include <optional>
#include <phosg/Strings.hh>
#include <string>
AsyncEvent::AsyncEvent(asio::any_io_executor ex) : executor(ex), is_set(false) {}
void AsyncEvent::set() {
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)();
});
}
}
void AsyncEvent::clear() {
std::lock_guard g(this->lock);
this->is_set = false;
}
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 {
std::lock_guard g(this->lock);
if (this->is_set) {
handler();
} else {
this->waiters.emplace_back(
std::make_unique<asio::detail::awaitable_handler<asio::any_io_executor>>(std::move(handler)));
}
},
token);
}
AsyncSocketReader::AsyncSocketReader(asio::ip::tcp::socket&& sock)
: sock(std::move(sock)) {}
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 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 == std::string::npos) && (!max_length || (this->pending_data.size() < max_length))) {
size_t pre_size = this->pending_data.size();
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);
this->pending_data.resize(pre_size + bytes_read);
delimiter_pos = this->pending_data.find(
delimiter,
(delimiter_backup_bytes > pre_size) ? 0 : (pre_size - delimiter_backup_bytes));
}
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.
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<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) {
ret = this->pending_data.substr(0, size);
this->pending_data = this->pending_data.substr(size);
} else {
size_t bytes_to_read = size - this->pending_data.size();
this->pending_data.swap(ret);
ret.resize(size);
co_await asio::async_read(this->sock, asio::buffer(ret.data() + size - bytes_to_read, bytes_to_read), asio::use_awaitable);
}
co_return ret;
}
asio::awaitable<void> AsyncSocketReader::read_data_into(void* data, size_t size) {
if (this->pending_data.size() == size) {
memcpy(data, this->pending_data.data(), size);
this->pending_data.clear();
} else if (this->pending_data.size() > size) {
memcpy(data, this->pending_data.data(), size);
this->pending_data = this->pending_data.substr(size);
} else {
memcpy(data, this->pending_data.data(), this->pending_data.size());
size_t bytes_to_read = size - this->pending_data.size();
this->pending_data.clear();
void* read_buf = reinterpret_cast<uint8_t*>(data) + size - bytes_to_read;
co_await asio::async_read(this->sock, asio::buffer(read_buf, bytes_to_read), asio::use_awaitable);
}
}
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()));
}
void AsyncWriteCollector::add_reference(const void* data, size_t size) {
bufs.emplace_back(asio::buffer(data, size));
}
asio::awaitable<void> AsyncWriteCollector::write(asio::ip::tcp::socket& sock) {
std::deque<std::string> local_owned_data;
local_owned_data.swap(this->owned_data);
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(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);
}
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(uint32_t ipv4_addr, uint16_t port) {
uint8_t octets[4] = {
static_cast<uint8_t>(ipv4_addr >> 24),
static_cast<uint8_t>(ipv4_addr >> 16),
static_cast<uint8_t>(ipv4_addr >> 8),
static_cast<uint8_t>(ipv4_addr)};
return async_connect_tcp(std::format("{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]), port);
}
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(const std::string& host, uint16_t port) {
auto executor = co_await asio::this_coro::executor;
asio::ip::tcp::resolver resolver(executor);
auto endpoints = co_await resolver.async_resolve(host, std::format("{}", port), asio::use_awaitable);
asio::ip::tcp::socket sock(executor);
co_await asio::async_connect(sock, endpoints, asio::use_awaitable);
co_return sock;
}
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(const asio::ip::tcp::endpoint& ep) {
auto executor = co_await asio::this_coro::executor;
asio::ip::tcp::socket sock(executor);
co_await sock.async_connect(ep, asio::use_awaitable);
co_return sock;
}
+273
View File
@@ -0,0 +1,273 @@
#pragma once
#include <asio.hpp>
#include <asio/experimental/parallel_group.hpp>
#include <asio/experimental/promise.hpp>
#include <deque>
#include <exception>
#include <functional>
#include <optional>
#include <phosg/Strings.hh>
template <typename T>
class AsyncPromise {
public:
AsyncPromise() = default;
asio::awaitable<T> get() {
if (!this->exc && !this->val.has_value()) {
auto executor = co_await asio::this_coro::executor;
co_await asio::async_initiate<decltype(asio::use_awaitable), void(std::error_code)>(
[this, &executor](auto&& new_handler) {
this->resolver_ref.emplace(ResolverRef{.resolve = std::move(new_handler), .executor = &executor});
},
asio::use_awaitable);
}
if (this->exc) {
std::rethrow_exception(this->exc);
} else if (this->val.has_value()) {
co_return *this->val;
} else {
throw std::logic_error("AsyncPromise await resolved but did not have a value or exception");
}
}
void set_value(T&& result) {
if (this->done()) {
throw std::logic_error("attempted to set value on completed promise");
}
this->val = result;
this->resolve();
}
void set_exception(std::exception_ptr ex) {
if (this->done()) {
throw std::logic_error("attempted to set value on completed promise");
}
this->exc = ex;
this->resolve();
}
void cancel() {
this->set_exception(std::make_exception_ptr(std::runtime_error("AsyncPromise cancelled")));
}
bool done() const {
return this->exc || this->val.has_value();
}
private:
struct ResolverRef {
asio::detail::awaitable_handler<asio::any_io_executor, std::error_code> resolve;
asio::any_io_executor* executor;
};
std::optional<T> val;
std::exception_ptr exc;
std::optional<ResolverRef> resolver_ref;
void resolve() {
if (this->resolver_ref) {
auto* executor = this->resolver_ref->executor;
ResolverRef ref = std::move(*this->resolver_ref);
this->resolver_ref.reset();
asio::post(*executor, [ref = std::move(ref)]() mutable -> void {
ref.resolve(std::error_code{});
});
}
}
};
template <>
class AsyncPromise<void> {
public:
AsyncPromise() = default;
asio::awaitable<void> get() {
if (!this->exc && !this->returned) {
auto executor = co_await asio::this_coro::executor;
co_await asio::async_initiate<decltype(asio::use_awaitable), void(std::error_code)>(
[this, &executor](auto&& new_handler) {
this->resolver_ref.emplace(ResolverRef{.resolve = std::move(new_handler), .executor = &executor});
},
asio::use_awaitable);
}
if (this->exc) {
std::rethrow_exception(this->exc);
} else if (this->returned) {
co_return;
} else {
throw std::logic_error("AsyncPromise await resolved but did not have a value or exception");
}
}
void set_value() {
if (this->done()) {
throw std::logic_error("attempted to set value on completed promise");
}
this->returned = true;
this->resolve();
}
void set_exception(std::exception_ptr ex) {
if (this->done()) {
throw std::logic_error("attempted to set value on completed promise");
}
this->exc = ex;
this->resolve();
}
void cancel() {
this->set_exception(std::make_exception_ptr(std::runtime_error("AsyncPromise cancelled")));
}
bool done() const {
return this->exc || this->returned;
}
private:
struct ResolverRef {
asio::detail::awaitable_handler<asio::any_io_executor, std::error_code> resolve;
asio::any_io_executor* executor;
};
bool returned = false;
std::exception_ptr exc;
std::optional<ResolverRef> resolver_ref;
void resolve() {
if (this->resolver_ref) {
auto* executor = this->resolver_ref->executor;
ResolverRef ref = std::move(*this->resolver_ref);
this->resolver_ref.reset();
asio::post(*executor, [ref = std::move(ref)]() mutable -> void {
ref.resolve(std::error_code{});
});
}
}
};
class AsyncEvent {
public:
AsyncEvent(asio::any_io_executor ex);
AsyncEvent(const AsyncEvent&) = delete;
AsyncEvent(AsyncEvent&&) = delete;
AsyncEvent& operator=(const AsyncEvent&) = delete;
AsyncEvent& operator=(AsyncEvent&&) = delete;
void set();
void clear();
asio::awaitable<void> wait();
private:
asio::any_io_executor executor;
bool is_set;
std::mutex lock;
std::vector<std::unique_ptr<asio::detail::awaitable_handler<asio::any_io_executor>>> waiters;
};
class AsyncSocketReader {
public:
explicit AsyncSocketReader(asio::ip::tcp::socket&& sock);
AsyncSocketReader(const AsyncSocketReader&) = delete;
AsyncSocketReader(AsyncSocketReader&&) = delete;
AsyncSocketReader& operator=(const AsyncSocketReader&) = delete;
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.
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
inline asio::ip::tcp::socket& get_socket() {
return this->sock;
}
inline bool is_open() const {
return this->sock.is_open();
}
inline void close() {
if (this->sock.is_open()) {
this->sock.close();
}
}
private:
std::string pending_data; // Data read but not yet returned to the caller
asio::ip::tcp::socket sock;
};
class AsyncWriteCollector {
public:
AsyncWriteCollector() = default;
AsyncWriteCollector(const AsyncWriteCollector&) = delete;
AsyncWriteCollector(AsyncWriteCollector&&) = delete;
AsyncWriteCollector& operator=(const AsyncWriteCollector&) = delete;
AsyncWriteCollector& operator=(AsyncWriteCollector&&) = delete;
~AsyncWriteCollector() = default;
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.
void add_reference(const void* data, size_t size);
asio::awaitable<void> write(asio::ip::tcp::socket& sock);
private:
std::deque<std::string> owned_data;
std::vector<asio::const_buffer> bufs;
};
asio::awaitable<void> async_sleep(std::chrono::steady_clock::duration duration);
inline asio::ip::tcp::endpoint make_endpoint_ipv4(uint32_t addr, uint16_t port) {
return asio::ip::tcp::endpoint(asio::ip::address_v4(addr), port);
}
inline asio::ip::tcp::endpoint make_endpoint_ipv6(const void* addr, uint16_t port) {
std::array<uint8_t, 0x10> bytes;
for (size_t z = 0; z < 0x10; z++) {
bytes[z] = reinterpret_cast<const uint8_t*>(addr)[z];
}
return asio::ip::tcp::endpoint(asio::ip::address_v6(bytes), port);
}
inline std::string str_for_endpoint(const asio::ip::tcp::endpoint& ep) {
return ep.address().to_string() + std::format(":{}", ep.port());
}
inline uint32_t ipv4_addr_for_asio_addr(const asio::ip::address& addr) {
if (!addr.is_v4()) {
throw std::runtime_error("Address is not IPv4");
}
return addr.to_v4().to_uint();
}
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(uint32_t ipv4_addr, uint16_t port);
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(const std::string& host, uint16_t port);
asio::awaitable<asio::ip::tcp::socket> async_connect_tcp(const asio::ip::tcp::endpoint& ep);
template <typename FnT, typename... ArgTs>
asio::awaitable<std::invoke_result_t<FnT, ArgTs...>> call_on_thread_pool(asio::thread_pool& pool, FnT&& f, ArgTs&&... args) {
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 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 {
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 "Text.hh"
#include "Types.hh" #include "Types.hh"
using namespace std;
template <bool BE> template <bool BE>
struct BMLHeaderT { struct BMLHeaderT {
parray<uint8_t, 0x04> unknown_a1; parray<uint8_t, 0x04> unknown_a1;
U32T<BE> num_entries; U32T<BE> num_entries;
parray<uint8_t, 0x38> unknown_a2; parray<uint8_t, 0x38> unknown_a2;
} __packed__; } __packed_ws_be__(BMLHeaderT, 0x40);
using BMLHeader = BMLHeaderT<false>; using BMLHeader = BMLHeaderT<false>;
using BMLHeaderBE = BMLHeaderT<true>; using BMLHeaderBE = BMLHeaderT<true>;
check_struct_size(BMLHeader, 0x40);
check_struct_size(BMLHeaderBE, 0x40);
template <bool BE> template <bool BE>
struct BMLHeaderEntryT { struct BMLHeaderEntryT {
@@ -30,12 +25,9 @@ struct BMLHeaderEntryT {
U32T<BE> compressed_gvm_size; U32T<BE> compressed_gvm_size;
U32T<BE> decompressed_gvm_size; U32T<BE> decompressed_gvm_size;
parray<uint8_t, 0x0C> unknown_a2; parray<uint8_t, 0x0C> unknown_a2;
} __packed__; } __packed_ws_be__(BMLHeaderEntryT, 0x40);
using BMLHeaderEntry = BMLHeaderEntryT<false>; using BMLHeaderEntry = BMLHeaderEntryT<false>;
using BMLHeaderEntryBE = BMLHeaderEntryT<true>; using BMLHeaderEntryBE = BMLHeaderEntryT<true>;
check_struct_size(BMLHeaderEntry, 0x40);
check_struct_size(BMLHeaderEntryBE, 0x40);
template <bool BE> template <bool BE>
void BMLArchive::load_t() { void BMLArchive::load_t() {
@@ -48,13 +40,13 @@ void BMLArchive::load_t() {
const auto& entry = r.get<BMLHeaderEntryT<BE>>(); const auto& entry = r.get<BMLHeaderEntryT<BE>>();
if (offset + entry.compressed_size > this->data->size()) { 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; size_t data_offset = offset;
offset = (offset + entry.compressed_size + 0x1F) & (~0x1F); offset = (offset + entry.compressed_size + 0x1F) & (~0x1F);
if (offset + entry.compressed_gvm_size > this->data->size()) { 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; size_t gvm_offset = offset;
offset = (offset + entry.compressed_gvm_size + 0x1F) & (~0x1F); 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) BMLArchive::BMLArchive(std::shared_ptr<const std::string> data, bool big_endian) : data(data) {
: data(data) {
if (big_endian) { if (big_endian) {
this->load_t<true>(); this->load_t<true>();
} else { } 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; 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 { try {
const auto& entry = this->entries.at(name); const auto& entry = this->entries.at(name);
return make_pair(this->data->data() + entry.offset, entry.size); return std::make_pair(this->data->data() + entry.offset, entry.size);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
throw out_of_range("BML does not contain file: " + name); 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 { try {
const auto& entry = this->entries.at(name); const auto& entry = this->entries.at(name);
return make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size); return std::make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
throw out_of_range("BML does not contain file: " + name); 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 { try {
const auto& entry = this->entries.at(name); const auto& entry = this->entries.at(name);
return this->data->substr(entry.offset, entry.size); return this->data->substr(entry.offset, entry.size);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
throw out_of_range("BML does not contain file: " + name); 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 { try {
const auto& entry = this->entries.at(name); const auto& entry = this->entries.at(name);
return phosg::StringReader(this->data->data() + entry.offset, entry.size); return phosg::StringReader(this->data->data() + entry.offset, entry.size);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
throw out_of_range("BML does not contain file: " + name); throw std::out_of_range("BML does not contain file: " + name);
} }
} }
+291 -41
View File
@@ -7,42 +7,298 @@
#include "PSOEncryption.hh" #include "PSOEncryption.hh"
#include "StaticGameData.hh" #include "StaticGameData.hh"
using namespace std; BattleParamsIndex::AttackData BattleParamsIndex::AttackData::from_json(const phosg::JSON& json) {
return AttackData{
void BattleParamsIndex::Table::print(FILE* stream) const { json.get_int("MinATP"),
auto print_entry = +[](FILE* stream, const PlayerStats& e) { json.get_int("MaxATP"),
fprintf(stream, json.get_int("MinATA"),
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %5" PRIu32 " %5" PRIu32, json.get_int("MaxATA"),
e.char_stats.atp.load(), json.get_float("DistanceX"),
e.char_stats.mst.load(), json.get_int("Angle"),
e.char_stats.evp.load(), json.get_float("DistanceY"),
e.char_stats.hp.load(), json.get_int("UnknownA8"),
e.char_stats.dfp.load(), json.get_int("UnknownA9"),
e.char_stats.ata.load(), json.get_int("UnknownA10"),
e.char_stats.lck.load(), json.get_int("UnknownA11"),
e.esp.load(), json.get_int("UnknownA12"),
e.experience.load(), json.get_int("UnknownA13"),
e.meseta.load()); 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()},
});
}
for (size_t diff = 0; diff < 4; diff++) { BattleParamsIndex::ResistData BattleParamsIndex::ResistData::from_json(const phosg::JSON& json) {
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP EXP DIFF\n", return BattleParamsIndex::ResistData{
abbreviation_for_difficulty(diff)); 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++) { for (size_t z = 0; z < 0x60; z++) {
fprintf(stream, " %02zX ", z); const auto& entry_json = diff_json.at(z);
print_entry(stream, this->stats[diff][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 {
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(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);
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); fputc('\n', stream);
} }
} }
} }
BattleParamsIndex::BattleParamsIndex( phosg::JSON BattleParamsIndex::json() const {
shared_ptr<const string> data_on_ep1, return phosg::JSON::dict({
shared_ptr<const string> data_on_ep2, {"Episode1-Online", this->get_table(false, Episode::EP1).json()},
shared_ptr<const string> data_on_ep4, {"Episode2-Online", this->get_table(false, Episode::EP2).json()},
shared_ptr<const string> data_off_ep1, {"Episode4-Online", this->get_table(false, Episode::EP4).json()},
shared_ptr<const string> data_off_ep2, {"Episode1-Solo", this->get_table(true, Episode::EP1).json()},
shared_ptr<const string> data_off_ep4) { {"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][0].data = data_on_ep1;
this->files[0][1].data = data_on_ep2; this->files[0][1].data = data_on_ep2;
this->files[0][2].data = data_on_ep4; this->files[0][2].data = data_on_ep4;
@@ -54,8 +310,8 @@ BattleParamsIndex::BattleParamsIndex(
for (uint8_t episode = 0; episode < 3; episode++) { for (uint8_t episode = 0; episode < 3; episode++) {
auto& file = this->files[is_solo][episode]; auto& file = this->files[is_solo][episode];
if (file.data->size() < sizeof(Table)) { if (file.data->size() < sizeof(Table)) {
throw runtime_error(phosg::string_printf( throw std::runtime_error(std::format(
"battle params table size is incorrect (expected %zX bytes, have %zX bytes; is_solo=%hhu, episode=%hhu)", "battle params table size is incorrect (expected {:X} bytes, have {:X} bytes; is_solo={}, episode={})",
sizeof(Table), file.data->size(), is_solo, episode)); sizeof(Table), file.data->size(), is_solo, episode));
} }
file.table = reinterpret_cast<const Table*>(file.data->data()); file.table = reinterpret_cast<const Table*>(file.data->data());
@@ -63,21 +319,15 @@ BattleParamsIndex::BattleParamsIndex(
} }
} }
const BattleParamsIndex::Table& BattleParamsIndex::get_table(bool solo, Episode episode) const { const BattleParamsIndex::Table& BinaryBattleParamsIndex::get_table(bool solo, Episode episode) const {
uint8_t ep_index;
switch (episode) { switch (episode) {
case Episode::EP1: case Episode::EP1:
ep_index = 0; return *this->files[!!solo][0].table;
break;
case Episode::EP2: case Episode::EP2:
ep_index = 1; return *this->files[!!solo][1].table;
break;
case Episode::EP4: case Episode::EP4:
ep_index = 2; return *this->files[!!solo][2].table;
break;
default: default:
throw invalid_argument("invalid episode"); throw std::invalid_argument("invalid episode");
} }
return *this->files[!!solo][ep_index].table;
} }
+69 -28
View File
@@ -19,12 +19,12 @@ public:
// These files are little-endian, even on PSO GC. // These files are little-endian, even on PSO GC.
struct AttackData { struct AttackData {
/* 00 */ le_int16_t unknown_a1; /* 00 */ le_int16_t min_atp;
/* 02 */ le_int16_t atp; /* 02 */ le_int16_t max_atp;
/* 04 */ le_int16_t ata_bonus; /* 04 */ le_int16_t min_ata;
/* 06 */ le_uint16_t unknown_a4; /* 06 */ le_int16_t max_ata;
/* 08 */ le_float distance_x; /* 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; /* 10 */ le_float distance_y;
/* 14 */ le_uint16_t unknown_a8; /* 14 */ le_uint16_t unknown_a8;
/* 16 */ le_uint16_t unknown_a9; /* 16 */ le_uint16_t unknown_a9;
@@ -35,7 +35,8 @@ public:
/* 24 */ le_uint32_t unknown_a14; /* 24 */ le_uint32_t unknown_a14;
/* 28 */ le_uint32_t unknown_a15; /* 28 */ le_uint32_t unknown_a15;
/* 2C */ le_uint32_t unknown_a16; /* 2C */ le_uint32_t unknown_a16;
/* 30 */ static AttackData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __packed_ws__(AttackData, 0x30); } __packed_ws__(AttackData, 0x30);
struct ResistData { struct ResistData {
@@ -50,36 +51,76 @@ public:
/* 14 */ le_uint32_t unknown_a8; /* 14 */ le_uint32_t unknown_a8;
/* 18 */ le_uint32_t unknown_a9; /* 18 */ le_uint32_t unknown_a9;
/* 1C */ le_int32_t dfp_bonus; /* 1C */ le_int32_t dfp_bonus;
/* 20 */ static ResistData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __packed_ws__(ResistData, 0x20); } __packed_ws__(ResistData, 0x20);
struct MovementData { struct MovementData {
/* 00 */ le_float idle_move_speed; /* 00 */ le_float fparam1;
/* 04 */ le_float idle_animation_speed; /* 04 */ le_float fparam2;
/* 08 */ le_float move_speed; /* 03 */ le_float fparam3;
/* 0C */ le_float animation_speed; /* 0C */ le_float fparam4;
/* 10 */ le_float unknown_a1; /* 10 */ le_float fparam5;
/* 14 */ le_float unknown_a2; /* 14 */ le_float fparam6;
/* 18 */ le_uint32_t unknown_a3; /* 18 */ le_uint32_t iparam1;
/* 1C */ le_uint32_t unknown_a4; /* 1C */ le_uint32_t iparam2;
/* 20 */ le_uint32_t unknown_a5; /* 20 */ le_uint32_t iparam3;
/* 24 */ le_uint32_t unknown_a6; /* 24 */ le_uint32_t iparam4;
/* 28 */ le_uint32_t unknown_a7; /* 28 */ le_uint32_t iparam5;
/* 2C */ le_uint32_t unknown_a8; /* 2C */ le_uint32_t iparam6;
/* 30 */ static MovementData from_json(const phosg::JSON& json);
phosg::JSON json() const;
} __packed_ws__(MovementData, 0x30); } __packed_ws__(MovementData, 0x30);
struct Table { struct Table {
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats; /* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats; // [difficulty][bp_index]
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data; /* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data; // [difficulty][bp_index]
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data; /* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data; // [difficulty][bp_index]
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data; /* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data; // [difficulty][bp_index]
/* F600 */ /* F600 */
void print(FILE* stream) const; 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); } __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_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_ep2, // BattleParamEntry_lab_on.dat
std::shared_ptr<const std::string> data_on_ep4, // BattleParamEntry_ep4_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_ep2, // BattleParamEntry_lab.dat
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.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 { struct File {
std::shared_ptr<const std::string> data; std::shared_ptr<const std::string> data;
const Table* table = nullptr; 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;
}
-187
View File
@@ -1,187 +0,0 @@
#include "CatSession.hh"
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <event2/listener.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <algorithm>
#include <iostream>
#include <phosg/Encoding.hh>
#include <phosg/Filesystem.hh>
#include <phosg/Network.hh>
#include <phosg/Random.hh>
#include <phosg/Strings.hh>
#include <phosg/Time.hh>
#include "Loggers.hh"
#include "PSOProtocol.hh"
#include "ProxyCommands.hh"
#include "ReceiveCommands.hh"
#include "ReceiveSubcommands.hh"
#include "SendCommands.hh"
using namespace std;
CatSession::exit_shell::exit_shell() : runtime_error("shell exited") {}
CatSession::CatSession(
shared_ptr<struct event_base> base,
const struct sockaddr_storage& remote,
Version version,
shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file)
: log(phosg::string_printf("[CatSession:%s] ", phosg::name_for_enum(version)), proxy_server_log.min_level),
base(base),
read_event(event_new(this->base.get(), 0, EV_READ | EV_PERSIST, CatSession::dispatch_read_stdin, this), event_free),
channel(version, 1, CatSession::dispatch_on_channel_input, CatSession::dispatch_on_channel_error, this, "CatSession"),
bb_key_file(bb_key_file) {
if (remote.ss_family != AF_INET) {
throw runtime_error("remote is not AF_INET");
}
string netloc_str = phosg::render_sockaddr_storage(remote);
this->log.info("Connecting to %s", netloc_str.c_str());
struct bufferevent* bev = bufferevent_socket_new(
this->base.get(), -1, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
if (!bev) {
throw runtime_error(phosg::string_printf("failed to open socket (%d)", EVUTIL_SOCKET_ERROR()));
}
this->channel.set_bufferevent(bev, 0);
if (bufferevent_socket_connect(this->channel.bev.get(),
reinterpret_cast<const sockaddr*>(&remote), sizeof(struct sockaddr_in)) != 0) {
throw runtime_error(phosg::string_printf("failed to connect (%d)", EVUTIL_SOCKET_ERROR()));
}
event_add(this->read_event.get(), nullptr);
this->poll.add(0, POLLIN);
}
void CatSession::execute_command(const std::string& command) {
string full_cmd = phosg::parse_data_string(command, nullptr, phosg::ParseDataFlags::ALLOW_FILES);
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
}
void CatSession::dispatch_on_channel_input(
Channel& ch, uint16_t command, uint32_t flag, std::string& data) {
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
session->on_channel_input(command, flag, data);
}
void CatSession::on_channel_input(
uint16_t command, uint32_t flag, std::string& data) {
if (!uses_v4_encryption(this->channel.version)) {
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
if (uses_v3_encryption(this->channel.version)) {
this->channel.crypt_in = make_shared<PSOV3Encryption>(cmd.server_key);
this->channel.crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
this->log.info("Enabled V3 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
cmd.server_key.load(), cmd.client_key.load());
} else { // PC, DC, or patch server
this->channel.crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
this->channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
this->log.info("Enabled V2 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
cmd.server_key.load(), cmd.client_key.load());
}
}
} else { // BB
if (command == 0x03 || command == 0x9B) {
if (!this->bb_key_file) {
throw runtime_error("BB encryption requires a key file");
}
const auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data, 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->log.info("Enabled BB encryption");
}
}
// TODO: Use the iovec form of print_data here instead of
// prepend_command_header (which copies the string)
string full_cmd = prepend_command_header(this->channel.version, this->channel.crypt_in.get(), command, flag, data);
phosg::print_data(stdout, full_cmd, 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::OFFSET_16_BITS);
}
void CatSession::dispatch_on_channel_error(Channel& ch, short events) {
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
session->on_channel_error(events);
}
void CatSession::on_channel_error(short events) {
if (events & BEV_EVENT_CONNECTED) {
this->log.info("Channel connected");
}
if (events & BEV_EVENT_ERROR) {
int err = EVUTIL_SOCKET_ERROR();
this->log.warning("Error %d (%s) in unlinked client stream", err,
evutil_socket_error_to_string(err));
}
if (events & (BEV_EVENT_ERROR | BEV_EVENT_EOF)) {
this->log.info("Session endpoint has disconnected");
this->channel.disconnect();
event_base_loopexit(this->base.get(), nullptr);
}
}
void CatSession::dispatch_read_stdin(evutil_socket_t, short, void* ctx) {
reinterpret_cast<CatSession*>(ctx)->read_stdin();
}
void CatSession::read_stdin() {
bool any_command_read = false;
for (;;) {
auto poll_result = this->poll.poll();
short fd_events = 0;
try {
fd_events = poll_result.at(0);
} catch (const out_of_range&) {
}
if (!(fd_events & POLLIN)) {
break;
}
string command(2048, '\0');
if (!fgets(command.data(), command.size(), stdin)) {
if (!any_command_read) {
// ctrl+d probably; we should exit
fputc('\n', stderr);
event_base_loopexit(this->base.get(), nullptr);
return;
} else {
break; // probably not EOF; just no more commands for now
}
}
// trim the extra data off the string
size_t len = strlen(command.c_str());
if (len == 0) {
break;
}
if (command[len - 1] == '\n') {
len--;
}
command.resize(len);
any_command_read = true;
try {
execute_command(command);
} catch (const exit_shell&) {
event_base_loopexit(this->base.get(), nullptr);
return;
} catch (const exception& e) {
fprintf(stderr, "FAILED: %s\n", e.what());
}
}
}
-54
View File
@@ -1,54 +0,0 @@
#pragma once
#include <event2/event.h>
#include <functional>
#include <map>
#include <memory>
#include <phosg/Filesystem.hh>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "PSOEncryption.hh"
#include "PSOProtocol.hh"
#include "ServerState.hh"
class CatSession {
public:
CatSession(
std::shared_ptr<struct event_base> base,
const struct sockaddr_storage& remote,
Version version,
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file);
CatSession(const CatSession&) = delete;
CatSession(CatSession&&) = delete;
CatSession& operator=(const CatSession&) = delete;
CatSession& operator=(CatSession&&) = delete;
virtual ~CatSession() = default;
protected:
phosg::PrefixedLogger log;
std::shared_ptr<struct event_base> base;
std::unique_ptr<struct event, void (*)(struct event*)> read_event;
phosg::Poll poll;
Channel channel;
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
class exit_shell : public std::runtime_error {
public:
exit_shell();
~exit_shell() = default;
};
virtual void execute_command(const std::string& command);
static void dispatch_read_stdin(evutil_socket_t fd, short events, void* ctx);
static void dispatch_on_channel_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
static void dispatch_on_channel_error(Channel& ch, short events);
void on_channel_input(uint16_t command, uint32_t flag, std::string& msg);
void on_channel_error(short events);
void read_stdin();
};
+285 -274
View File
@@ -1,255 +1,44 @@
#include "Channel.hh" #include "Channel.hh"
#include <errno.h> #include <errno.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <phosg/Network.hh> #include <phosg/Network.hh>
#include <phosg/Time.hh> #include <phosg/Time.hh>
#include "CommandCensorData.hh"
#include "Loggers.hh" #include "Loggers.hh"
#include "StaticGameData.hh"
#include "Version.hh" #include "Version.hh"
using namespace std;
extern bool use_terminal_colors; extern bool use_terminal_colors;
static void flush_and_free_bufferevent(struct bufferevent* bev) {
bufferevent_flush(bev, EV_READ | EV_WRITE, BEV_FINISHED);
bufferevent_free(bev);
}
Channel::Channel( Channel::Channel(
Version version, Version version,
uint8_t language, Language language,
on_command_received_t on_command_received, const std::string& name,
on_error_t on_error,
void* context_obj,
const string& name,
phosg::TerminalFormat terminal_send_color, phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color) phosg::TerminalFormat terminal_recv_color,
: bev(nullptr, flush_and_free_bufferevent), bool censor_received_credentials,
virtual_network_id(0), bool censor_sent_credentials)
version(version), : version(version),
language(language), language(language),
name(name), name(name),
terminal_send_color(terminal_send_color), terminal_send_color(terminal_send_color),
terminal_recv_color(terminal_recv_color), terminal_recv_color(terminal_recv_color),
on_command_received(on_command_received), censor_received_credentials(censor_received_credentials),
on_error(on_error), censor_sent_credentials(censor_sent_credentials) {
context_obj(context_obj) {
}
Channel::Channel(
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
uint8_t language,
on_command_received_t on_command_received,
on_error_t on_error,
void* context_obj,
const string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color)
: bev(nullptr, flush_and_free_bufferevent),
version(version),
language(language),
name(name),
terminal_send_color(terminal_send_color),
terminal_recv_color(terminal_recv_color),
on_command_received(on_command_received),
on_error(on_error),
context_obj(context_obj) {
this->set_bufferevent(bev, virtual_network_id);
}
void Channel::replace_with(
Channel&& other,
on_command_received_t on_command_received,
on_error_t on_error,
void* context_obj,
const std::string& name) {
this->set_bufferevent(other.bev.release(), other.virtual_network_id);
this->local_addr = other.local_addr;
this->remote_addr = other.remote_addr;
this->version = other.version;
this->language = other.language;
this->crypt_in = other.crypt_in;
this->crypt_out = other.crypt_out;
this->name = name;
this->terminal_send_color = other.terminal_send_color;
this->terminal_recv_color = other.terminal_recv_color;
this->on_command_received = on_command_received;
this->on_error = on_error;
this->context_obj = context_obj;
other.disconnect(); // Clears crypts, addrs, etc.
}
void Channel::set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id) {
this->bev.reset(bev);
this->virtual_network_id = virtual_network_id;
if (this->bev.get()) {
int fd = bufferevent_getfd(this->bev.get());
if (fd < 0) {
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
} else {
phosg::get_socket_addresses(fd, &this->local_addr, &this->remote_addr);
}
bufferevent_setcb(this->bev.get(), &Channel::dispatch_on_input, nullptr, &Channel::dispatch_on_error, this);
bufferevent_enable(this->bev.get(), EV_READ | EV_WRITE);
} else {
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
}
}
void Channel::disconnect() {
if (this->bev.get()) {
// If the output buffer is not empty, move the bufferevent into the draining
// pool instead of disconnecting it, to make sure all the data gets sent.
struct evbuffer* out_buffer = bufferevent_get_output(this->bev.get());
if (evbuffer_get_length(out_buffer) == 0) {
this->bev.reset(); // Destructor flushes and frees the bufferevent
} else {
// The callbacks will free it when all the data is sent or the client
// disconnects
auto on_output = +[](struct bufferevent* bev, void*) -> void {
flush_and_free_bufferevent(bev);
};
auto on_error = +[](struct bufferevent* bev, short events, void*) -> void {
if (events & BEV_EVENT_ERROR) {
int err = EVUTIL_SOCKET_ERROR();
channel_exceptions_log.warning(
"Disconnecting channel caused error %d (%s)", err,
evutil_socket_error_to_string(err));
}
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
bufferevent_flush(bev, EV_WRITE, BEV_FINISHED);
bufferevent_free(bev);
}
};
struct bufferevent* bev = this->bev.release();
bufferevent_setcb(bev, nullptr, on_output, on_error, bev);
bufferevent_disable(bev, EV_READ);
}
}
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
this->virtual_network_id = false;
this->crypt_in.reset();
this->crypt_out.reset();
}
Channel::Message Channel::recv() {
struct evbuffer* buf = bufferevent_get_input(this->bev.get());
size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
PSOCommandHeader header;
if (evbuffer_copyout(buf, &header, header_size) < static_cast<ssize_t>(header_size)) {
throw out_of_range("no command available");
}
if (this->crypt_in.get()) {
this->crypt_in->decrypt(&header, header_size, false);
}
size_t command_logical_size = header.size(version);
// 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;
if (evbuffer_get_length(buf) < command_physical_size) {
throw out_of_range("no command available");
}
// If we get here, then there is a full command in the buffer. Some encryption
// algorithms' advancement depends on the decrypted data, so we have to
// actually decrypt the header again (with advance=true) to keep them in a
// consistent state.
string header_data(header_size, '\0');
if (evbuffer_remove(buf, header_data.data(), header_data.size()) < static_cast<ssize_t>(header_data.size())) {
throw logic_error("enough bytes available, but could not remove them");
}
if (this->crypt_in.get()) {
this->crypt_in->decrypt(header_data.data(), header_data.size());
}
string command_data(command_physical_size - header_size, '\0');
if (evbuffer_remove(buf, command_data.data(), command_data.size()) < static_cast<ssize_t>(command_data.size())) {
throw logic_error("enough bytes available, but could not remove them");
}
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.
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());
command_data.resize(orig_size);
}
command_data.resize(command_logical_size - header_size);
if (command_data_log.should_log(phosg::LogLevel::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);
}
if (version == Version::BB_V4) {
command_data_log.info(
"Received from %s (version=BB command=%04hX flag=%08" PRIX32 ")",
this->name.c_str(),
header.command(this->version),
header.flag(this->version));
} else {
command_data_log.info(
"Received from %s (version=%s command=%02hX flag=%02" PRIX32 ")",
this->name.c_str(),
phosg::name_for_enum(this->version),
header.command(this->version),
header.flag(this->version));
}
vector<struct iovec> iovs;
iovs.emplace_back(iovec{.iov_base = header_data.data(), .iov_len = header_data.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);
if (use_terminal_colors && this->terminal_recv_color != phosg::TerminalFormat::NORMAL) {
phosg::print_color_escape(stderr, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END);
}
}
return {
.command = header.command(this->version),
.flag = header.flag(this->version),
.data = std::move(command_data),
};
} }
void Channel::send(uint16_t cmd, uint32_t flag, bool silent) { void Channel::send(uint16_t cmd, uint32_t flag, bool silent) {
this->send(cmd, flag, nullptr, 0, 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()) { if (!this->connected()) {
channel_exceptions_log.warning("Attempted to send command on closed channel; dropping data"); channel_exceptions_log.warning_f("Attempted to send command on closed channel; dropping data");
return; return;
} }
@@ -258,7 +47,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
size += b.second; size += b.second;
} }
string send_data; std::string send_data;
size_t logical_size; size_t logical_size;
size_t send_data_size = 0; size_t send_data_size = 0;
switch (this->version) { switch (this->version) {
@@ -272,10 +61,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
case Version::GC_EP3: case Version::GC_EP3:
case Version::XB_V3: { case Version::XB_V3: {
PSOCommandHeaderDCV3 header; PSOCommandHeaderDCV3 header;
if (this->crypt_out.get() && if (this->crypt_out.get() && !is_v1(this->version)) {
(this->version != Version::DC_NTE) &&
(this->version != Version::DC_11_2000) &&
(this->version != Version::DC_V1)) {
send_data_size = (sizeof(header) + size + 3) & ~3; send_data_size = (sizeof(header) + size + 3) & ~3;
} else { } else {
send_data_size = (sizeof(header) + size); send_data_size = (sizeof(header) + size);
@@ -305,13 +91,11 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
break; break;
} }
case Version::BB_V4: { case Version::BB_V4: {
// BB has an annoying behavior here: command lengths must be multiples of // BB has an annoying behavior here: command lengths must be multiples of 4, but the actual data length must be a
// 4, but the actual data length must be a multiple of 8. If the size // multiple of 8. If the size field is not divisible by 8, 4 extra bytes are sent anyway. This behavior only
// field is not divisible by 8, 4 extra bytes are sent anyway. This // applies when encryption is enabled - any commands sent before encryption is enabled have no size restrictions
// behavior only applies when encryption is enabled - any commands sent // (except they must include a full header and must fit in the client's receive buffer), and no implicit extra
// before encryption is enabled have no size restrictions (except they // bytes are sent.
// must include a full header and must fit in the client's receive
// buffer), and no implicit extra bytes are sent.
PSOCommandHeaderBB header; PSOCommandHeaderBB header;
if (this->crypt_out.get()) { if (this->crypt_out.get()) {
send_data_size = (sizeof(header) + size + 7) & ~7; send_data_size = (sizeof(header) + size + 7) & ~7;
@@ -327,13 +111,12 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
} }
default: 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 // All versions of PSO I've seen (so far) have a receive buffer 0x7C00 bytes in size
// bytes in size
if (send_data_size > 0x7C00) { 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); send_data.reserve(send_data_size);
@@ -342,18 +125,30 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
} }
send_data.resize(send_data_size, '\0'); send_data.resize(send_data_size, '\0');
if (!silent && (command_data_log.should_log(phosg::LogLevel::INFO)) && (this->terminal_send_color != phosg::TerminalFormat::END)) { if (!silent && (command_data_log.should_log(phosg::LogLevel::L_INFO)) && (this->terminal_send_color != phosg::TerminalFormat::END)) {
if (use_terminal_colors && this->terminal_send_color != phosg::TerminalFormat::NORMAL) { if (use_terminal_colors && this->terminal_send_color != phosg::TerminalFormat::NORMAL) {
print_color_escape(stderr, phosg::TerminalFormat::FG_YELLOW, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::END); print_color_escape(stderr, phosg::TerminalFormat::FG_YELLOW, phosg::TerminalFormat::BOLD, phosg::TerminalFormat::END);
} }
if (version == Version::BB_V4) { if (version == Version::BB_V4) {
command_data_log.info("Sending to %s (version=BB command=%04hX flag=%08" PRIX32 ")", command_data_log.info_f("Sending to {} (version=BB command={:04X} flag={:08X})", this->name, cmd, flag);
this->name.c_str(), cmd, flag);
} else { } else {
command_data_log.info("Sending to %s (version=%s command=%02hX flag=%02" PRIX32 ")", command_data_log.info_f("Sending to {} (version={} command={:02X} flag={:02X})",
this->name.c_str(), phosg::name_for_enum(version), cmd, flag); 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) { if (use_terminal_colors && this->terminal_send_color != phosg::TerminalFormat::NORMAL) {
print_color_escape(stderr, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END); print_color_escape(stderr, phosg::TerminalFormat::NORMAL, phosg::TerminalFormat::END);
} }
@@ -363,15 +158,14 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
this->crypt_out->encrypt(send_data.data(), send_data.size()); this->crypt_out->encrypt(send_data.data(), send_data.size());
} }
struct evbuffer* buf = bufferevent_get_output(this->bev.get()); this->send_raw(std::move(send_data));
evbuffer_add(buf, send_data.data(), send_data.size());
} }
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent) { 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); this->send(cmd, flag, data.data(), data.size(), silent);
} }
@@ -386,36 +180,253 @@ void Channel::send(const void* data, size_t size, bool silent) {
silent); silent);
} }
void Channel::send(const string& data, bool silent) { void Channel::send(const std::string& data, bool silent) {
return this->send(data.data(), data.size(), silent); this->send(data.data(), data.size(), silent);
} }
void Channel::dispatch_on_input(struct bufferevent*, void* ctx) { asio::awaitable<Channel::Message> Channel::recv() {
Channel* ch = reinterpret_cast<Channel*>(ctx); size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
// The client can be disconnected during on_command_received, so we have to PSOCommandHeader header;
// make sure ch->bev is valid every time before calling recv() co_await this->recv_raw(&header, header_size);
while (ch->bev.get()) { if (this->crypt_in.get()) {
Message msg; this->crypt_in->decrypt(&header, header_size);
try { }
msg = ch->recv();
} catch (const out_of_range&) { size_t command_logical_size = header.size(version);
break; if (command_logical_size < header_size) {
} catch (const exception& e) { throw std::runtime_error("header size field is smaller than header");
channel_exceptions_log.warning("Error receiving on channel: %s", e.what()); }
ch->on_error(*ch, BEV_EVENT_ERROR);
break; // 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;
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.
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());
command_data.resize(orig_size);
}
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);
} }
if (ch->on_command_received) {
ch->on_command_received(*ch, msg.command, msg.flag, msg.data); if (version == Version::BB_V4) {
command_data_log.info_f(
"Received from {} (version=BB command={:04X} flag={:08X})",
this->name,
header.command(this->version),
header.flag(this->version));
} else {
command_data_log.info_f(
"Received from {} (version={} command={:02X} flag={:02X})",
this->name,
phosg::name_for_enum(this->version),
header.command(this->version),
header.flag(this->version));
}
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);
}
}
co_return Message{
.command = command,
.flag = header.flag(this->version),
.data = std::move(command_data),
};
}
std::shared_ptr<SocketChannel> SocketChannel::create(
std::shared_ptr<asio::io_context> io_context,
std::unique_ptr<asio::ip::tcp::socket>&& sock,
Version version,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_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;
}
SocketChannel::SocketChannel(
std::shared_ptr<asio::io_context> io_context,
std::unique_ptr<asio::ip::tcp::socket>&& sock,
Version version,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_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()),
send_buffer_nonempty_signal(io_context->get_executor()) {}
std::string SocketChannel::default_name() const {
return "ip:" + str_for_endpoint(this->remote_addr);
}
bool SocketChannel::connected() const {
return !this->should_disconnect && this->sock && this->sock->is_open();
}
void SocketChannel::disconnect() {
this->should_disconnect = true;
this->send_buffer_nonempty_signal.set();
}
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();
}
}
asio::awaitable<void> SocketChannel::recv_raw(void* data, size_t size) {
if (!this->sock || this->should_disconnect) {
throw std::runtime_error("Cannot receive on closed channel");
}
co_await asio::async_read(*this->sock, asio::buffer(data, size), asio::use_awaitable);
}
asio::awaitable<void> SocketChannel::send_task() {
// Ensure *this doesn't get deleted while the socket is open
auto this_sh = this->shared_from_this();
while (this->sock->is_open()) {
std::deque<std::string> to_send;
to_send.swap(this->outbound_data);
if (!to_send.empty()) {
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()));
}
co_await asio::async_write(*this->sock, bufs, asio::use_awaitable);
}
if (this->outbound_data.empty()) {
if (this->should_disconnect) {
this->sock->close();
} else {
this->send_buffer_nonempty_signal.clear();
co_await this->send_buffer_nonempty_signal.wait();
}
} }
} }
} }
void Channel::dispatch_on_error(struct bufferevent*, short events, void* ctx) { PeerChannel::PeerChannel(
Channel* ch = reinterpret_cast<Channel*>(ctx); std::shared_ptr<asio::io_context> io_context,
if (ch->on_error) { Version version,
ch->on_error(*ch, events); Language language,
} else { const std::string& name,
ch->disconnect(); phosg::TerminalFormat terminal_send_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 std::logic_error("Cannot link already-connected peer channels");
}
peer1->peer = peer2;
peer2->peer = peer1;
}
std::string PeerChannel::default_name() const {
return std::format("peer:{}->{}", reinterpret_cast<const void*>(this), reinterpret_cast<const void*>(this->peer.lock().get()));
}
bool PeerChannel::connected() const {
return (!this->inbound_data.empty()) || (this->peer.lock() != nullptr);
}
void PeerChannel::disconnect() {
auto peer = this->peer.lock();
if (peer) {
peer->peer.reset();
peer->send_buffer_nonempty_signal.set();
}
this->peer.reset();
this->send_buffer_nonempty_signal.set();
}
void PeerChannel::send_raw(std::string&& data) {
auto peer = this->peer.lock();
if (peer) {
peer->inbound_data.emplace_back(std::move(data));
peer->send_buffer_nonempty_signal.set();
}
}
asio::awaitable<void> PeerChannel::recv_raw(void* data, size_t size) {
while (size > 0) {
while (this->inbound_data.empty() && this->peer.lock()) {
this->send_buffer_nonempty_signal.clear();
co_await this->send_buffer_nonempty_signal.wait();
}
if (!this->inbound_data.empty()) {
auto& front_block = this->inbound_data.front();
if (size < front_block.size()) {
memcpy(data, front_block.data(), size);
front_block = front_block.substr(size);
size = 0;
} else {
memcpy(data, front_block.data(), front_block.size());
size -= front_block.size();
data = reinterpret_cast<uint8_t*>(data) + front_block.size();
this->inbound_data.pop_front();
}
} else if (!this->peer.lock()) {
throw std::runtime_error("Channel peer has disconnected");
}
} }
} }
+140 -61
View File
@@ -1,85 +1,70 @@
#pragma once #pragma once
#include <netinet/in.h> #include <asio.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include "AsyncUtils.hh"
#include "PSOEncryption.hh" #include "PSOEncryption.hh"
#include "PSOProtocol.hh" #include "PSOProtocol.hh"
#include "Version.hh" #include "Version.hh"
struct Channel { class Channel {
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev; public:
struct sockaddr_storage local_addr;
struct sockaddr_storage remote_addr;
uint64_t virtual_network_id; // 0 = normal TCP connection
Version version; Version version;
uint8_t language; Language language;
std::shared_ptr<PSOEncryption> crypt_in; std::shared_ptr<PSOEncryption> crypt_in;
std::shared_ptr<PSOEncryption> crypt_out; std::shared_ptr<PSOEncryption> crypt_out;
std::string name; std::string name;
phosg::TerminalFormat terminal_send_color; phosg::TerminalFormat terminal_send_color;
phosg::TerminalFormat terminal_recv_color; phosg::TerminalFormat terminal_recv_color;
bool censor_received_credentials;
bool censor_sent_credentials;
struct Message { struct Message {
uint16_t command; uint16_t command;
uint32_t flag; uint32_t flag;
std::string data; std::string data;
template <typename T>
const T& check_size_t(size_t min_size, size_t max_size) const {
return ::check_size_t<const T>(this->data.data(), this->data.size(), min_size, max_size);
}
template <typename T>
T& check_size_t(size_t min_size, size_t max_size) {
return ::check_size_t<T>(this->data.data(), this->data.size(), min_size, max_size);
}
template <typename T>
const T& check_size_t(size_t max_size) const {
return ::check_size_t<const T>(this->data.data(), this->data.size(), sizeof(T), max_size);
}
template <typename T>
T& check_size_t(size_t max_size) {
return ::check_size_t<T>(this->data.data(), this->data.size(), sizeof(T), max_size);
}
template <typename T>
const T& check_size_t() const {
return ::check_size_t<const T>(this->data.data(), this->data.size(), sizeof(T), sizeof(T));
}
template <typename T>
T& check_size_t() {
return ::check_size_t<T>(this->data.data(), this->data.size(), sizeof(T), sizeof(T));
}
}; };
typedef void (*on_command_received_t)(Channel&, uint16_t, uint32_t, std::string&); virtual ~Channel() = default;
typedef void (*on_error_t)(Channel&, short);
on_command_received_t on_command_received; virtual std::string default_name() const = 0;
on_error_t on_error;
void* context_obj;
// Creates an unconnected channel // Returns whether the channel is connected or not.
Channel( virtual bool connected() const = 0;
Version version,
uint8_t language,
on_command_received_t on_command_received,
on_error_t on_error,
void* context_obj,
const std::string& name,
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
// Creates a connected channel
Channel(
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
uint8_t language,
on_command_received_t on_command_received,
on_error_t on_error,
void* context_obj,
const std::string& name = "",
phosg::TerminalFormat terminal_send_color = phosg::TerminalFormat::END,
phosg::TerminalFormat terminal_recv_color = phosg::TerminalFormat::END);
Channel(const Channel& other) = delete;
Channel(Channel&& other) = delete;
Channel& operator=(const Channel& other) = delete;
Channel& operator=(Channel&& other) = delete;
void replace_with( // Disconnects the channel. Any pending data will still be sent before the underlying transport (e.g. socket) is
Channel&& other, // closed, but further send calls will do nothing.
on_command_received_t on_command_received, virtual void disconnect() = 0;
on_error_t on_error,
void* context_obj,
const std::string& name = "");
void set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id);
inline bool connected() const {
return this->bev.get() != nullptr;
}
void disconnect();
// Receives a message. Throws std::out_of_range if no messages are available.
Message recv();
// Sends a message with an automatically-constructed header. // Sends a message with an automatically-constructed header.
void send(uint16_t cmd, uint32_t flag = 0, bool silent = false); void send(uint16_t cmd, uint32_t flag = 0, bool silent = false);
@@ -92,12 +77,106 @@ struct Channel {
this->send(cmd, flag, &data, sizeof(data), silent); this->send(cmd, flag, &data, sizeof(data), silent);
} }
// Sends a message with a pre-existing header (as the first few bytes in the // Sends a message with a pre-existing header (as the first few bytes in the data)
// data)
void send(const void* data, size_t size, bool silent = false); void send(const void* data, size_t size, bool silent = false);
void send(const std::string& data, bool silent = false); void send(const std::string& data, bool silent = false);
private: // Receives a message. Throws std::out_of_range if no messages are available.
static void dispatch_on_input(struct bufferevent*, void* ctx); asio::awaitable<Message> recv();
static void dispatch_on_error(struct bufferevent*, short events, void* ctx);
protected:
Channel(
Version version,
Language language,
const std::string& name,
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.
virtual void send_raw(std::string&& data) = 0;
// 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.
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.
static std::shared_ptr<SocketChannel> create(std::shared_ptr<asio::io_context> io_context,
std::unique_ptr<asio::ip::tcp::socket>&& sock,
Version version,
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;
virtual bool connected() const;
virtual void disconnect();
virtual void send_raw(std::string&& data);
virtual asio::awaitable<void> recv_raw(void* data, size_t size);
private:
SocketChannel(
std::shared_ptr<asio::io_context> io_context,
std::unique_ptr<asio::ip::tcp::socket>&& sock,
Version version,
Language language,
const std::string& name,
phosg::TerminalFormat terminal_send_color,
phosg::TerminalFormat terminal_recv_color,
bool censor_received_credentials,
bool censor_sent_credentials);
std::deque<std::string> outbound_data;
bool should_disconnect = false;
AsyncEvent send_buffer_nonempty_signal;
asio::awaitable<void> send_task();
};
// In-process peer channel, used for replay testing.
class PeerChannel : public Channel {
public:
std::weak_ptr<PeerChannel> peer;
PeerChannel(
std::shared_ptr<asio::io_context> io_context,
Version version,
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);
virtual std::string default_name() const;
virtual bool connected() const;
virtual void disconnect();
virtual void send_raw(std::string&& data);
virtual asio::awaitable<void> recv_raw(void* data, size_t size);
private:
AsyncEvent send_buffer_nonempty_signal;
std::deque<std::string> inbound_data;
}; };
+1866 -1571
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -2,13 +2,13 @@
#include <stdint.h> #include <stdint.h>
#include <asio.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include "Client.hh" #include "Client.hh"
#include "Lobby.hh" #include "Lobby.hh"
#include "ProxyServer.hh" #include "ProxySession.hh"
#include "ServerState.hh" #include "ServerState.hh"
void on_chat_command(std::shared_ptr<Client> c, const std::string& text, bool check_permissions); asio::awaitable<void> on_chat_command(std::shared_ptr<Client> c, const std::string& text, bool check_permissions);
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::string& text, bool check_permissions);
+13 -15
View File
@@ -5,9 +5,7 @@
#include "Client.hh" #include "Client.hh"
using namespace std; const std::vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES{
const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
ChoiceSearchCategory{ ChoiceSearchCategory{
.id = 0x0001, .id = 0x0001,
.name = "Level", .name = "Level",
@@ -24,14 +22,14 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0009, "Level 121-160"}, {0x0009, "Level 121-160"},
{0x000A, "Level 161-200"}, {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) { if (choice_id == 0x0000) {
return true; return true;
} }
uint32_t target_level = target_c->character()->disp.stats.level + 1; uint32_t target_level = target_c->character_file()->disp.stats.level + 1;
switch (choice_id) { switch (choice_id) {
case 0x0001: case 0x0001:
return (labs(static_cast<int32_t>(target_level - searcher_c->character()->disp.stats.level)) <= 5); return (labs(static_cast<int32_t>(target_level - searcher_c->character_file()->disp.stats.level)) <= 5);
case 0x0002: case 0x0002:
return (target_level <= 10); return (target_level <= 10);
case 0x0003: case 0x0003:
@@ -75,18 +73,18 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0008, "FOnewm"}, {0x0008, "FOnewm"},
{0x0009, "FOnewearl"}, {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) { switch (choice_id) {
case 0x0000: case 0x0000:
return true; return true;
case 0x0010: case 0x0010:
return target_c->character()->disp.visual.class_flags & 0x20; return target_c->character_file()->disp.visual.sh.class_flags & 0x20;
case 0x0011: case 0x0011:
return target_c->character()->disp.visual.class_flags & 0x40; return target_c->character_file()->disp.visual.sh.class_flags & 0x40;
case 0x0012: case 0x0012:
return target_c->character()->disp.visual.class_flags & 0x80; return target_c->character_file()->disp.visual.sh.class_flags & 0x80;
default: default:
return ((choice_id - 1) == target_c->character()->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"}, {0x0005, "GC Episode 3"},
{0x0006, "BB"}, {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) { if (choice_id == 0x0000) {
return true; return true;
} }
@@ -142,9 +140,9 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
{0x0005, "Battle"}, {0x0005, "Battle"},
{0x0006, "Challenge"}, {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()->choice_search_config.get_setting(0x0204); 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); return (choice_id == 0) || (target_choice_id == 0) || (choice_id == target_choice_id);
}, },
}, },
}); };
+4 -7
View File
@@ -31,21 +31,18 @@ struct ChoiceSearchConfigT {
operator ChoiceSearchConfigT<!BE>() const { operator ChoiceSearchConfigT<!BE>() const {
ChoiceSearchConfigT<!BE> ret; ChoiceSearchConfigT<!BE> ret;
ret.disabled = this->disabled.load(); ret.disabled = this->disabled;
for (size_t z = 0; z < this->entries.size(); z++) { for (size_t z = 0; z < this->entries.size(); z++) {
auto& ret_e = ret.entries[z]; auto& ret_e = ret.entries[z];
const auto& this_e = this->entries[z]; const auto& this_e = this->entries[z];
ret_e.parent_choice_id = this_e.parent_choice_id.load(); ret_e.parent_choice_id = this_e.parent_choice_id;
ret_e.choice_id = this_e.choice_id.load(); ret_e.choice_id = this_e.choice_id;
} }
return ret; return ret;
} }
} __packed__; } __packed_ws_be__(ChoiceSearchConfigT, 0x18);
using ChoiceSearchConfig = ChoiceSearchConfigT<false>; using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>; using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
check_struct_size(ChoiceSearchConfig, 0x18);
check_struct_size(ChoiceSearchConfigBE, 0x18);
struct ChoiceSearchCategory { struct ChoiceSearchCategory {
struct Choice { struct Choice {
+763 -633
View File
File diff suppressed because it is too large Load Diff
+205 -253
View File
@@ -1,101 +1,98 @@
#pragma once #pragma once
#include <netinet/in.h>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include "Account.hh" #include "Account.hh"
#include "AsyncUtils.hh"
#include "Channel.hh" #include "Channel.hh"
#include "ClientFunctionIndex.hh"
#include "CommandFormats.hh" #include "CommandFormats.hh"
#include "Episode3/BattleRecord.hh" #include "Episode3/BattleRecord.hh"
#include "Episode3/Tournament.hh" #include "Episode3/Tournament.hh"
#include "FileContentsCache.hh"
#include "FunctionCompiler.hh"
#include "PSOEncryption.hh" #include "PSOEncryption.hh"
#include "PSOProtocol.hh" #include "PSOProtocol.hh"
#include "PatchFileIndex.hh" #include "PatchFileIndex.hh"
#include "ProxySession.hh"
#include "Quest.hh" #include "Quest.hh"
#include "QuestScript.hh" #include "QuestScript.hh"
#include "TeamIndex.hh" #include "TeamIndex.hh"
#include "Text.hh" #include "Text.hh"
#include <string>
extern const uint64_t CLIENT_CONFIG_MAGIC; extern const uint64_t CLIENT_CONFIG_MAGIC;
class Server; class GameServer;
struct Lobby; struct Lobby;
class Parsed6x70Data; class Parsed6x70Data;
struct GetPlayerInfoResult {
// 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
};
class Client : public std::enable_shared_from_this<Client> { class Client : public std::enable_shared_from_this<Client> {
public: public:
enum class Flag : uint64_t { enum class Flag : uint64_t {
// clang-format off // clang-format off
// This mask specifies which flags are sent to the client
// TODO: It'd be nice to use a pattern here (e.g. all server-side flags are
// in the high bits) but that would require re-recording or manually
// rewriting all the tests
CLIENT_SIDE_MASK = 0xEF3CFFFF7C0BFFFB,
// Version-related flags // Version-related flags
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002, CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000001,
NO_D6_AFTER_LOBBY = 0x0000000000000100, NO_D6_AFTER_LOBBY = 0x0000000000000002,
NO_D6 = 0x0000000000000200, NO_D6 = 0x0000000000000004,
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400, FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000008,
// Flags describing the behavior for send_function_call // Flags describing the behavior for send_function_call
HAS_SEND_FUNCTION_CALL = 0x0000000000001000, HAS_SEND_FUNCTION_CALL = 0x0000000000000010,
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000, ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000000020,
SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE = 0x0000000000004000, SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE = 0x0000000000000040,
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000, SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000000080,
CAN_RECEIVE_ENABLE_B2_QUEST = 0x0000000000020000, CAN_RECEIVE_ENABLE_B2_QUEST = 0x0000000000000100,
AWAITING_ENABLE_B2_QUEST = 0x0000000000040000, // Server-side only AWAITING_ENABLE_B2_QUEST = 0x0000000000000200,
// State flags // State flags
LOADING = 0x0000000000100000, // Server-side only LOADING = 0x0000000000000400,
LOADING_QUEST = 0x0000000000200000, // Server-side only LOADING_QUEST = 0x0000000000000800,
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000, // Server-side only LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000001000,
LOADING_TOURNAMENT = 0x0000000000800000, // Server-side only LOADING_TOURNAMENT = 0x0000000000002000,
IN_INFORMATION_MENU = 0x0000000001000000, // Server-side only IN_INFORMATION_MENU = 0x0000000000004000,
AT_WELCOME_MESSAGE = 0x0000000002000000, // Server-side only AT_WELCOME_MESSAGE = 0x0000000000008000,
SAVE_ENABLED = 0x0000000004000000, SAVE_ENABLED = 0x0000000000010000,
HAS_EP3_CARD_DEFS = 0x0000000008000000, HAS_EP3_CARD_DEFS = 0x0000000000020000,
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000, HAS_EP3_MEDIA_UPDATES = 0x0000000000040000,
USE_OVERRIDE_RANDOM_SEED = 0x0000000020000000, HAS_AUTO_PATCHES = 0x0000000000080000,
HAS_GUILD_CARD_NUMBER = 0x0000000040000000, AT_BANK_COUNTER = 0x0000000000100000,
HAS_AUTO_PATCHES = 0x0000004000000000, SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0000000000200000,
AT_BANK_COUNTER = 0x0000000080000000, // Server-side only SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0000000000400000,
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000, // Server-side only SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0000000000800000,
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000, // Server-side only SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0000000001000000,
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0080000000000000, // Server-side only SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0000000002000000,
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only SHOULD_SEND_ENABLE_SAVE = 0x0000000004000000,
SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0200000000000000, // Server-side only SWITCH_ASSIST_ENABLED = 0x0000000008000000,
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000, IS_CLIENT_CUSTOMIZATION = 0x0000000010000000,
SWITCH_ASSIST_ENABLED = 0x0000000100000000, EP3_ALLOW_6xBC = 0x0000000020000000,
IS_CLIENT_CUSTOMIZATION = 0x0100000000000000,
EP3_ALLOW_6xBC = 0x1000000000000000, // Server-side only
// Cheat mode and option flags // Cheat mode and option flags
INFINITE_HP_ENABLED = 0x0000000200000000, INFINITE_HP_ENABLED = 0x0000000040000000,
INFINITE_TP_ENABLED = 0x0000000400000000, INFINITE_TP_ENABLED = 0x0000000080000000,
DEBUG_ENABLED = 0x0000000800000000, FAST_KILLS_ENABLED = 0x0000000100000000,
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000, ALL_RARES_ENABLED = 0x0000100000000000,
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000, 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 option flags
PROXY_SAVE_FILES = 0x0000001000000000, PROXY_SAVE_FILES = 0x0000002000000000,
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000, PROXY_CHAT_COMMANDS_ENABLED = 0x0000004000000000,
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000, PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
PROXY_SUPPRESS_CLIENT_PINGS = 0x0000010000000000, PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000010000000000,
PROXY_SUPPRESS_REMOTE_LOGIN = 0x0000020000000000, PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000020000000000,
PROXY_ZERO_REMOTE_GUILD_CARD = 0x0000040000000000, PROXY_BLOCK_FUNCTION_CALLS = 0x0000040000000000,
PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000080000000000, PROXY_EP3_UNMASK_WHISPERS = 0x0000080000000000,
PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000100000000000,
PROXY_RED_NAME_ENABLED = 0x0000200000000000,
PROXY_BLANK_NAME_ENABLED = 0x0000400000000000,
PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000,
PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000,
PROXY_VIRTUAL_CLIENT = 0x0400000000000000,
// clang-format on // clang-format on
}; };
enum class ItemDropNotificationMode { enum class ItemDropNotificationMode {
@@ -107,123 +104,77 @@ public:
static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED); static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED);
struct Config { std::weak_ptr<GameServer> server;
uint64_t enabled_flags = DEFAULT_FLAGS; // Client::Flag enum
uint32_t specific_version = 0;
int32_t override_random_seed = 0;
uint8_t override_section_id = 0xFF; // FF = no override
uint8_t override_lobby_event = 0xFF; // FF = no override
uint8_t override_lobby_number = 0x80; // 80 = no override
uint32_t proxy_destination_address = 0;
uint16_t proxy_destination_port = 0;
Config() = default;
bool operator==(const Config& other) const = default;
bool operator!=(const Config& other) const = default;
bool should_update_vs(const Config& other) const;
[[nodiscard]] static inline bool check_flag(uint64_t enabled_flags, Flag flag) {
return !!(enabled_flags & static_cast<uint64_t>(flag));
}
[[nodiscard]] inline bool check_flag(Flag flag) const {
return this->check_flag(this->enabled_flags, flag);
}
inline void set_flag(Flag flag) {
this->enabled_flags |= static_cast<uint64_t>(flag);
}
inline void clear_flag(Flag flag) {
this->enabled_flags &= (~static_cast<uint64_t>(flag));
}
inline void toggle_flag(Flag flag) {
this->enabled_flags ^= static_cast<uint64_t>(flag);
}
void set_flags_for_version(Version version, int64_t sub_version);
ItemDropNotificationMode get_drop_notification_mode() const;
void set_drop_notification_mode(ItemDropNotificationMode new_mode);
template <size_t Bytes>
void parse_from(const parray<uint8_t, Bytes>& data) {
phosg::StringReader r(data.data(), data.size());
if (r.get_u32l() != CLIENT_CONFIG_MAGIC) {
throw std::invalid_argument("config signature is incorrect");
}
this->specific_version = r.get_u32l();
this->enabled_flags = r.get_u64l();
this->override_random_seed = r.get_u32l();
this->proxy_destination_address = r.get_u32b();
this->proxy_destination_port = r.get_u16l();
this->override_section_id = r.get_u8();
this->override_lobby_event = r.get_u8();
this->override_lobby_number = r.get_u8();
}
template <size_t Bytes>
void serialize_into(parray<uint8_t, Bytes>& data) const {
phosg::StringWriter w;
w.put_u32l(CLIENT_CONFIG_MAGIC);
w.put_u32l(this->specific_version);
w.put_u64l(this->enabled_flags & static_cast<uint64_t>(Flag::CLIENT_SIDE_MASK));
w.put_u32l(this->override_random_seed);
w.put_u32b(this->proxy_destination_address);
w.put_u16l(this->proxy_destination_port);
w.put_u8(this->override_section_id);
w.put_u8(this->override_lobby_event);
w.put_u8(this->override_lobby_number);
const auto& s = w.str();
for (size_t z = 0; z < s.size(); z++) {
data[z] = s[z];
}
data.clear_after(s.size(), 0xFF);
}
};
std::weak_ptr<Server> server;
uint64_t id; uint64_t id;
phosg::PrefixedLogger log; phosg::PrefixedLogger log;
// Account information (not all of these are used; depends on game version)
std::string username;
std::string password;
std::string email_address;
uint64_t hardware_id = 0;
int32_t sub_version = 0;
uint8_t bb_client_code = 0;
uint8_t bb_connection_phase = 0xFF;
ssize_t bb_character_index = -1; // -1 = not set
ssize_t bb_bank_character_index = -1; // -1 = shared bank
uint32_t bb_security_token = 0;
parray<uint8_t, 0x28> bb_client_config;
std::string login_character_name;
std::string serial_number;
std::string access_key;
std::string serial_number2;
std::string access_key2;
std::string v1_serial_number;
std::string v1_access_key;
XBNetworkLocation xb_netloc;
parray<le_uint32_t, 3> xb_unknown_a1a;
uint64_t xb_user_id = 0;
uint32_t xb_unknown_a1b = 0;
std::shared_ptr<Login> login; 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)
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
// Network // Network
Channel channel; std::shared_ptr<Channel> channel;
struct sockaddr_storage next_connection_addr; std::shared_ptr<PSOBBMultiKeyDetectorEncryption> bb_detector_crypt;
ServerBehavior server_behavior; ServerBehavior server_behavior;
bool should_disconnect; uint16_t listener_port = 0;
bool should_send_to_lobby_server;
bool should_send_to_proxy_server;
std::unordered_map<std::string, std::function<void()>> disconnect_hooks; std::unordered_map<std::string, std::function<void()>> disconnect_hooks;
std::shared_ptr<XBNetworkLocation> xb_netloc; uint64_t ping_start_time = 0;
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
uint8_t bb_connection_phase;
uint64_t ping_start_time;
// Lobby/positioning // Basic state
Config config; uint64_t enabled_flags = DEFAULT_FLAGS; // Client::Flag enum
Config synced_config; uint32_t specific_version = 0;
uint8_t override_section_id = 0xFF; // FF = no override
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; std::unique_ptr<Variations> override_variations;
int32_t sub_version; VectorXYZF pos;
VectorXZF pos; uint32_t floor = 0x0F;
uint32_t floor;
std::weak_ptr<Lobby> lobby; std::weak_ptr<Lobby> lobby;
uint8_t lobby_client_id; uint8_t lobby_client_id = 0;
uint8_t lobby_arrow_color; uint8_t lobby_arrow_color = 0;
int64_t preferred_lobby_id; // <0 = no preference int64_t preferred_lobby_id = -1; // <0 = none chosen
std::unique_ptr<struct event, void (*)(struct event*)> save_game_data_event; asio::steady_timer save_game_data_timer;
std::unique_ptr<struct event, void (*)(struct event*)> send_ping_event; asio::steady_timer send_ping_timer;
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_event; asio::steady_timer idle_timeout_timer;
int16_t card_battle_table_number; int16_t card_battle_table_number = -1;
uint16_t card_battle_table_seat_number; uint16_t card_battle_table_seat_number = 0;
uint16_t card_battle_table_seat_state; uint16_t card_battle_table_seat_state = 0;
std::weak_ptr<Episode3::Tournament::Team> ep3_tournament_team; std::weak_ptr<Episode3::Tournament::Team> ep3_tournament_team;
std::shared_ptr<const Episode3::BattleRecord> ep3_prev_battle_record; std::shared_ptr<const Episode3::BattleRecord> ep3_prev_battle_record;
std::shared_ptr<const Menu> last_menu_sent; std::shared_ptr<const Menu> last_menu_sent;
uint32_t last_game_info_requested; uint32_t last_game_info_requested = 0;
struct JoinCommand { struct JoinCommand {
uint16_t command; uint16_t command;
uint32_t flag; uint32_t flag;
@@ -244,58 +195,72 @@ public:
}; };
bool should_update_play_time; bool should_update_play_time;
std::unordered_set<uint32_t> blocked_senders; 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; std::shared_ptr<Parsed6x70Data> last_reported_6x70;
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) // 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<PendingItemTrade> pending_item_trade;
std::unique_ptr<PendingCardTrade> pending_card_trade; std::unique_ptr<PendingCardTrade> pending_card_trade;
uint32_t telepipe_lobby_id; uint32_t telepipe_lobby_id = 0;
TelepipeState telepipe_state; TelepipeState telepipe_state;
std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3 std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3
int8_t bb_character_index;
ItemData bb_identify_result; ItemData bb_identify_result;
std::array<std::vector<ItemData>, 3> bb_shop_contents; std::array<std::vector<ItemData>, 3> bb_shop_contents;
// Miscellaneous (used by chat commands) // Miscellaneous (used by chat commands / quest opcodes)
uint32_t next_exp_value; // next EXP value to give uint8_t schtserv_response_register = 0;
bool can_chat; uint32_t next_exp_value = 0;
struct PendingCharacterExport { bool can_chat = true;
std::shared_ptr<const Account> dest_account; // NOTE: If you add any new optional promises here, make sure to also add them to cancel_pending_promises.
ssize_t character_index = -1; // NOTE: Entries in this queue can be nullptr; that represents a B2 command sent by the remote server during a proxy
std::shared_ptr<const BBLicense> dest_bb_license; // Only used for $bbchar; null for $savechar // 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::unique_ptr<PendingCharacterExport> pending_character_export; std::deque<std::shared_ptr<AsyncPromise<C_ExecuteCodeResult_B3>>> function_call_response_queue;
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue; std::shared_ptr<AsyncPromise<GetPlayerInfoResult>> character_data_ready_promise;
std::shared_ptr<AsyncPromise<void>> enable_save_promise;
// File loading state // File loading state
uint32_t dol_base_addr;
std::shared_ptr<DOLFileIndex::File> loading_dol_file;
std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files; std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files;
Client( Client(std::shared_ptr<GameServer> server, std::shared_ptr<Channel> channel, ServerBehavior server_behavior);
std::shared_ptr<Server> server,
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
ServerBehavior server_behavior);
~Client(); ~Client();
void update_channel_name(); void update_channel_name();
void reschedule_save_game_data_event(); void reschedule_save_game_data_timer();
void reschedule_ping_and_timeout_events(); void reschedule_ping_and_timeout_timers();
inline Version version() const { inline Version version() const {
return this->channel.version; return this->channel->version;
} }
inline uint8_t language() const { inline Language language() const {
return this->channel.language; return this->channel->language;
} }
[[nodiscard]] static inline bool check_flag(uint64_t enabled_flags, Flag flag) {
return !!(enabled_flags & static_cast<uint64_t>(flag));
}
[[nodiscard]] inline bool check_flag(Flag flag) const {
return this->check_flag(this->enabled_flags, flag);
}
inline void set_flag(Flag flag) {
this->enabled_flags |= static_cast<uint64_t>(flag);
}
inline void clear_flag(Flag flag) {
this->enabled_flags &= (~static_cast<uint64_t>(flag));
}
inline void toggle_flag(Flag flag) {
this->enabled_flags ^= static_cast<uint64_t>(flag);
}
void set_flags_for_version(Version version, int64_t sub_version);
ItemDropNotificationMode get_drop_notification_mode() const;
void set_drop_notification_mode(ItemDropNotificationMode new_mode);
void convert_account_to_temporary_if_nte(); void convert_account_to_temporary_if_nte();
void sync_config();
std::shared_ptr<ServerState> require_server_state() const; std::shared_ptr<ServerState> require_server_state() const;
std::shared_ptr<Lobby> require_lobby() const; std::shared_ptr<Lobby> require_lobby() const;
@@ -305,37 +270,58 @@ public:
std::shared_ptr<const IntegralExpression> expr, std::shared_ptr<const IntegralExpression> expr,
std::shared_ptr<const Lobby> game, std::shared_ptr<const Lobby> game,
uint8_t event, uint8_t event,
uint8_t difficulty, Difficulty difficulty,
size_t num_players, size_t num_players,
bool v1_present) const; bool v1_present) const;
bool can_see_quest( bool can_see_quest(
std::shared_ptr<const Quest> q, std::shared_ptr<const Quest> q,
std::shared_ptr<const Lobby> game, std::shared_ptr<const Lobby> game,
uint8_t event, uint8_t event,
uint8_t difficulty, Difficulty difficulty,
size_t num_players, size_t num_players,
bool v1_present) const; bool v1_present) const;
bool can_play_quest( bool can_play_quest(
std::shared_ptr<const Quest> q, std::shared_ptr<const Quest> q,
std::shared_ptr<const Lobby> game, std::shared_ptr<const Lobby> game,
uint8_t event, uint8_t event,
uint8_t difficulty, Difficulty difficulty,
size_t num_players, size_t num_players,
bool v1_present) const; bool v1_present) const;
bool can_use_chat_commands() const; bool can_use_chat_commands() const;
static void dispatch_save_game_data(evutil_socket_t, short, void* ctx);
void save_game_data();
static void dispatch_send_ping(evutil_socket_t, short, void* ctx);
void send_ping();
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
void idle_timeout();
void suspend_timeouts();
void set_login(std::shared_ptr<Login> login); void set_login(std::shared_ptr<Login> login);
void import_blocked_senders(const parray<le_uint32_t, 30>& blocked_senders);
static std::string system_filename(const std::string& bb_username);
std::string system_filename() const;
std::shared_ptr<PSOBBBaseSystemFile> system_file(bool allow_load = true);
std::shared_ptr<const PSOBBBaseSystemFile> system_file(bool throw_if_missing = true) const;
void save_system_file() const;
static std::string guild_card_filename(const std::string& bb_username);
std::string guild_card_filename() const;
std::shared_ptr<PSOBBGuildCardFile> guild_card_file(bool allow_load = true);
std::shared_ptr<const PSOBBGuildCardFile> guild_card_file(bool allow_load = true) const;
void save_guild_card_file() const;
static std::string character_filename(const std::string& bb_username, ssize_t index);
static std::string backup_character_filename(uint32_t account_id, size_t index, bool is_ep3);
std::string character_filename() const;
std::shared_ptr<PSOBBCharacterFile> character_file(bool allow_load = true, bool allow_overlay = true);
std::shared_ptr<const PSOBBCharacterFile> character_file(bool throw_if_missing = true, bool allow_overlay = true) const;
static void save_character_file(
const std::string& filename,
std::shared_ptr<const PSOBBBaseSystemFile> sys,
std::shared_ptr<const PSOBBCharacterFile> character);
static void save_ep3_character_file(const std::string& filename, const PSOGCEp3CharacterFile::Character& character);
void save_character_file();
void create_character_file(
uint32_t guild_card_number,
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_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); void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
inline void delete_overlay() { inline void delete_overlay() {
@@ -345,73 +331,39 @@ public:
return this->overlay_character_data.get() != nullptr; return this->overlay_character_data.get() != nullptr;
} }
void import_blocked_senders(const parray<le_uint32_t, 30>& blocked_senders); static std::string bank_filename(const std::string& bb_username, ssize_t index);
std::string bank_filename() const;
std::shared_ptr<PlayerBank> bank_file(bool allow_load = true);
std::shared_ptr<const PlayerBank> bank_file(bool throw_if_missing = true) const;
static void save_bank_file(const std::string& filename, const PlayerBank& bank);
void save_bank_file() const;
void change_bank(ssize_t bb_character_index); // -1 = use shared bank
std::shared_ptr<PSOBBBaseSystemFile> system_file(bool allow_load = true);
std::shared_ptr<PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true);
std::shared_ptr<PSOBBGuildCardFile> guild_card_file(bool allow_load = true);
std::shared_ptr<const PSOBBBaseSystemFile> system_file(bool allow_load = true) const;
std::shared_ptr<const PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true) const;
std::shared_ptr<const PSOBBGuildCardFile> guild_card_file(bool allow_load = true) const;
void create_character_file(
uint32_t guild_card_number,
uint8_t language,
const PlayerDispDataBBPreview& preview,
std::shared_ptr<const LevelTable> level_table);
std::string system_filename() const;
static std::string character_filename(const std::string& bb_username, int8_t index);
static std::string backup_character_filename(uint32_t account_id, size_t index, bool is_ep3);
std::string character_filename(int8_t index = -1) const;
std::string guild_card_filename() const;
std::string shared_bank_filename() const;
std::string legacy_player_filename() const;
std::string legacy_account_filename() const; std::string legacy_account_filename() const;
std::string legacy_player_filename() const;
void save_all(); void save_all();
void save_system_file() const;
static void save_character_file(
const std::string& filename,
std::shared_ptr<const PSOBBBaseSystemFile> sys,
std::shared_ptr<const PSOBBCharacterFile> character);
static void save_ep3_character_file(
const std::string& filename,
const PSOGCEp3CharacterFile::Character& character);
// Note: This function is not const because it updates the player's play time.
void save_character_file();
void save_guild_card_file() const;
void load_backup_character(uint32_t account_id, size_t index); 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); 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);
PlayerBank200& current_bank(); void print_inventory() const;
const PlayerBank200& current_bank() const; void print_bank() const;
std::shared_ptr<PSOBBCharacterFile> current_bank_character();
bool use_shared_bank(); // Returns true if the bank exists; false if it was created
void use_character_bank(int8_t bb_character_index);
void use_default_bank();
void print_inventory(FILE* stream) const; void cancel_pending_promises();
void print_bank(FILE* stream) const;
private: private:
// The overlay character data is used in battle and challenge modes, when // The overlay character data is used in battle and challenge modes, when character data is temporarily replaced
// character data is temporarily replaced in-game. In other play modes and in // in-game. In other play modes and in lobbies, overlay_character_data is null.
// lobbies, overlay_character_data is null.
std::shared_ptr<PSOBBBaseSystemFile> system_data; std::shared_ptr<PSOBBBaseSystemFile> system_data;
std::shared_ptr<PSOBBCharacterFile> overlay_character_data; std::shared_ptr<PSOBBCharacterFile> overlay_character_data;
std::shared_ptr<PSOBBCharacterFile> character_data; std::shared_ptr<PSOBBCharacterFile> character_data;
std::shared_ptr<PSOBBGuildCardFile> guild_card_data; std::shared_ptr<PSOBBGuildCardFile> guild_card_data;
std::shared_ptr<PlayerBank200> external_bank; std::shared_ptr<PlayerBank> bank_data;
std::shared_ptr<PSOBBCharacterFile> external_bank_character; uint64_t last_play_time_update = 0;
int8_t external_bank_character_index;
uint64_t last_play_time_update;
void save_and_clear_external_bank();
void load_all_files(); void load_all_files();
void update_character_data_after_load(std::shared_ptr<PSOBBCharacterFile> character_data); 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);
+2050 -2308
View File
File diff suppressed because it is too large Load Diff
+162 -23
View File
@@ -1,10 +1,16 @@
#pragma once #pragma once
#include <phosg/Encoding.hh> #include <phosg/Encoding.hh>
#include <phosg/Strings.hh>
#include <phosg/Vector.hh> #include <phosg/Vector.hh>
#include <set>
#include "Text.hh" #include "Text.hh"
constexpr double radians_for_fixed_point_angle(uint16_t angle) {
return static_cast<double>(angle * 2 * M_PI) / 0x10000;
}
struct VectorXZF { struct VectorXZF {
le_float x = 0.0; le_float x = 0.0;
le_float z = 0.0; le_float z = 0.0;
@@ -33,9 +39,23 @@ struct VectorXZF {
inline double norm2() const { inline double norm2() const {
return ((this->x * this->x) + (this->z * this->z)); 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);
double c = cos(angle);
return VectorXZF{this->x * c - this->z * s, this->x * s + this->z * c};
}
inline std::string str() const { inline std::string str() const {
return phosg::string_printf("[VectorXZF x=%g z=%g]", this->x.load(), this->z.load()); return std::format("[VectorXZF x={:g} z={:g}]", this->x, this->z);
} }
} __packed_ws__(VectorXZF, 0x08); } __packed_ws__(VectorXZF, 0x08);
@@ -73,8 +93,24 @@ struct VectorXYZF {
return ((this->x * this->x) + (this->y * this->y) + (this->z * this->z)); return ((this->x * this->x) + (this->y * this->y) + (this->z * this->z));
} }
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};
}
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};
}
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};
}
inline std::string str() const { inline std::string str() const {
return phosg::string_printf("[VectorXYZF x=%g y=%g z=%g]", this->x.load(), this->y.load(), this->z.load()); return std::format("[VectorXYZF x={:g} y={:g} z={:g}]", this->x, this->y, this->z);
} }
} __packed_ws__(VectorXYZF, 0x0C); } __packed_ws__(VectorXYZF, 0x0C);
@@ -97,40 +133,143 @@ struct ArrayRefT {
/* 00 */ U32T<BE> count; /* 00 */ U32T<BE> count;
/* 04 */ U32T<BE> offset; /* 04 */ U32T<BE> offset;
/* 08 */ /* 08 */
} __packed__; } __packed_ws_be__(ArrayRefT, 8);
using ArrayRef = ArrayRefT<false>; using ArrayRef = ArrayRefT<false>;
using ArrayRefBE = ArrayRefT<true>; using ArrayRefBE = ArrayRefT<true>;
check_struct_size(ArrayRef, 8);
check_struct_size(ArrayRefBE, 8);
template <bool BE> template <bool BE>
struct RELFileFooterT { struct RELFileFooterT {
static constexpr bool IsBE = BE; static constexpr bool IsBE = BE;
// Relocations is a list of words (le_uint16_t on DC/PC/XB/BB, be_uint16_t on // Relocations is a list of words (le_uint16_t on DC/PC/XB/BB, be_uint16_t on GC) containing the number of
// GC) containing the number of doublewords (uint32_t) to skip for each // doublewords (uint32_t) to skip for each relocation. The relocation pointer starts at the beginning of the file
// relocation. The relocation pointer starts immediately after the // data, and advances by the value of one relocation word (times 4) before each relocation. At each relocated
// checksum_size field in the header, and advances by the value of one // doubleword, the address of the first byte of the file is added to the existing value.
// relocation word (times 4) before each relocation. At each relocated //
// doubleword, the address of the first byte of the code (after checksum_size) // For example, if the file data contains the following data (where R specifies doublewords to relocate):
// is added to the existing value.
// For example, if the code segment contains the following data (where R
// specifies doublewords to relocate):
// RR RR RR RR ?? ?? ?? ?? ?? ?? ?? ?? RR RR RR RR // RR RR RR RR ?? ?? ?? ?? ?? ?? ?? ?? RR RR RR RR
// 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. // 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. // If there is a small number of relocations, they may be placed in the unused fields of this structure to save space
// The game never accesses the last 12 bytes of this structure unless // 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 // relocations_offset points there, so those 12 bytes may also be omitted entirely in some situations (e.g. in the B2
// entirely in situations (e.g. in the B2 command, without changing code_size, // command, without changing code_size, so code_size would technically extend beyond the end of the B2 command).
// so code_size would technically extend beyond the end of the B2 command).
U32T<BE> relocations_offset = 0; U32T<BE> relocations_offset = 0;
U32T<BE> num_relocations = 0; U32T<BE> num_relocations = 0;
parray<U32T<BE>, 2> unused1; parray<U32T<BE>, 2> unused1;
U32T<BE> root_offset = 0; U32T<BE> root_offset = 0;
parray<U32T<BE>, 3> unused2; parray<U32T<BE>, 3> unused2;
} __attribute__((packed)); } __packed_ws_be__(RELFileFooterT, 0x20);
using RELFileFooter = RELFileFooterT<false>; using RELFileFooter = RELFileFooterT<false>;
using RELFileFooterBE = RELFileFooterT<true>; 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;
};
+569 -431
View File
File diff suppressed because it is too large Load Diff
+122 -426
View File
@@ -4,6 +4,7 @@
#include <phosg/Encoding.hh> #include <phosg/Encoding.hh>
#include <phosg/JSON.hh> #include <phosg/JSON.hh>
#include "EnemyType.hh"
#include "GSLArchive.hh" #include "GSLArchive.hh"
#include "PSOEncryption.hh" #include "PSOEncryption.hh"
#include "StaticGameData.hh" #include "StaticGameData.hh"
@@ -15,14 +16,24 @@ public:
class Table { class Table {
public: public:
Table() = delete; 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); Table(const phosg::StringReader& r, bool big_endian, bool is_v3, Episode episode);
bool operator==(const Table& other) const = default;
bool operator!=(const Table& other) const = default;
template <typename IntT> template <typename IntT>
struct Range { struct Range {
IntT min; IntT min = 0;
IntT max; IntT max = 0;
} __packed__;
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; Episode episode;
parray<uint8_t, 0x0C> base_weapon_type_prob_table; parray<uint8_t, 0x0C> base_weapon_type_prob_table;
@@ -31,9 +42,10 @@ public:
parray<parray<uint8_t, 4>, 9> grind_prob_table; parray<parray<uint8_t, 4>, 9> grind_prob_table;
parray<uint8_t, 0x05> armor_shield_type_index_prob_table; parray<uint8_t, 0x05> armor_shield_type_index_prob_table;
parray<uint8_t, 0x05> armor_slot_count_prob_table; parray<uint8_t, 0x05> armor_slot_count_prob_table;
parray<Range<uint16_t>, 0x64> enemy_meseta_ranges; // Note: PSO originally uses arrays indexed by rt_index here, but we index enemies by the EnemyType enum instead
parray<uint8_t, 0x64> enemy_type_drop_probs; std::unordered_map<EnemyType, Range<uint16_t>> enemy_type_meseta_ranges;
parray<uint8_t, 0x64> enemy_item_classes; 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; parray<Range<uint16_t>, 0x0A> box_meseta_ranges;
bool has_rare_bonus_value_prob_table; bool has_rare_bonus_value_prob_table;
parray<parray<uint16_t, 6>, 0x17> bonus_value_prob_table; parray<parray<uint16_t, 6>, 0x17> bonus_value_prob_table;
@@ -48,63 +60,53 @@ public:
parray<uint8_t, 0x0A> unit_max_stars_table; parray<uint8_t, 0x0A> unit_max_stars_table;
parray<parray<uint8_t, 10>, 7> box_item_class_prob_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(FILE* stream) const;
void print_diff(FILE* stream, const Table& other) const;
private: private:
template <bool BE> template <bool BE>
void parse_itempt_t(const phosg::StringReader& r, bool is_v3); void parse_itempt_t(const phosg::StringReader& r, bool is_v3);
template <bool BE> template <bool BE>
struct OffsetsT { struct RootT {
// This data structure uses index probability tables in multiple places. An // This data structure uses index probability tables in multiple places. An index probability table is a table
// index probability table is a table where each entry holds the probability // where each entry holds the probability that that entry's index is used. For example, if the armor slot count
// 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
// probability table contains [77, 17, 5, 1, 0], this means there is a 77% // slot, 5% chance of 2 slots, 1% chance of 3 slots, and no chance of 4 slots. The values in index probability
// chance of no slots, 17% chance of 1 slot, 5% chance of 2 slots, 1% chance // tables do not have to add up to 100; the game sums all of them and chooses a random number less than that
// of 3 slots, and no chance of 4 slots. The values in index probability // maximum.
// 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 // The area (floor) number is used in many places as well. Unlike the normal area numbers, which start with
// area numbers, which start with Pioneer 2, the area numbers in this // Pioneer 2, the area numbers in this structure start with Forest 1, and boss areas are treated as the first
// 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
// area of the next section (so De Rol Le has Mines 1 drops, for example). // last non-boss area (so Dark Falz boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
// Final boss areas are treated as the last non-boss area (so Dark Falz // (area - 1), or area_norm.
// boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
// (area - 1).
// This index probability table determines the types of non-rare weapons. // This index probability table determines the types of non-rare weapons. The indexes in this table correspond to
// The indexes in this table correspond to the non-rare weapon types 01 // the non-rare weapon types 01 through 0C (Saber through Wand).
// through 0C (Saber through Wand).
// V2/V3: -> parray<uint8_t, 0x0C> // V2/V3: -> parray<uint8_t, 0x0C>
/* 00 */ U32T<BE> base_weapon_type_prob_table_offset; /* 00 */ U32T<BE> base_weapon_type_prob_table_offset;
// This table specifies the base subtype for each weapon type. Negative // This table specifies the base subtype for each weapon type. Negative values here mean that the weapon cannot
// values here mean that the weapon cannot be found in the first N areas (so // be found in the first N areas (so -2, for example, means that the weapon never appears in Forest 1 or 2 at
// -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
// all). Nonnegative values here mean the subtype can be found in all areas, // (usually in the range [0, 4]). The subtype of weapon that actually appears depends on this value and a value
// and specify the base subtype (usually in the range [0, 4]). The subtype // from the following table.
// of weapon that actually appears depends on this value and a value from
// the following table.
// V2/V3: -> parray<int8_t, 0x0C> // V2/V3: -> parray<int8_t, 0x0C>
/* 04 */ U32T<BE> subtype_base_table_offset; /* 04 */ U32T<BE> subtype_base_table_offset;
// This table specifies how many areas each weapon subtype appears in. For // This table specifies how many areas each weapon subtype appears in. For example, if Sword (subtype 02, which
// example, if Sword (subtype 02, which is index 1 in this table and the // is index 1 in this table and the table above) has a subtype base of -2 and a subtype area length of 4, then
// table above) has a subtype base of -2 and a subtype area length of 4, // Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1 through Mine 1), and Gigush (the next sword
// then Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1 // subtype) can be found in Mine 1 through Ruins 3.
// through Mine 1), and Gigush (the next sword subtype) can be found in Mine
// 1 through Ruins 3.
// V2/V3: -> parray<uint8_t, 0x0C> // V2/V3: -> parray<uint8_t, 0x0C>
/* 08 */ U32T<BE> subtype_area_length_table_offset; /* 08 */ U32T<BE> subtype_area_length_table_offset;
// This index probability table specifies how likely each possible grind // This index probability table specifies how likely each possible grind value is. The table is indexed as
// value is. The table is indexed as [grind][subtype_area_index], where the // [grind][subtype_area_index], where the subtype area index is how many areas the player is beyond the first
// subtype area index is how many areas the player is beyond the first area // area in which the subtype can first be found (clamped to [0, 3]). To continue the example above, in Cave 3,
// in which the subtype can first be found (clamped to [0, 3]). To continue // subtype_area_index would be 2, since Swords can first be found two areas earlier in Cave 1.
// 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: // For example, this table could look like this:
// [64 1E 19 14] // Chance of getting a grind +0 // [64 1E 19 14] // Chance of getting a grind +0
// [00 1E 17 0F] // Chance of getting a grind +1 // [00 1E 17 0F] // Chance of getting a grind +1
@@ -114,74 +116,66 @@ public:
// V2/V3: -> parray<parray<uint8_t, 4>, 9> // V2/V3: -> parray<parray<uint8_t, 4>, 9>
/* 0C */ U32T<BE> grind_prob_table_offset; /* 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> // V2/V3: -> parray<uint8_t, 0x05>
/* 10 */ U32T<BE> armor_shield_type_index_prob_table_offset; /* 10 */ U32T<BE> armor_shield_type_index_prob_table_offset;
// This index probability table specifies how common each possible slot // This index probability table specifies how common each possible slot count is for armor drops.
// count is for armor drops.
// V2/V3: -> parray<uint8_t, 0x05> // V2/V3: -> parray<uint8_t, 0x05>
/* 14 */ U32T<BE> armor_slot_count_prob_table_offset; /* 14 */ U32T<BE> armor_slot_count_prob_table_offset;
// This array (indexed by enemy_type) specifies the range of meseta values // This array (indexed by rt_index) specifies the range of meseta values that each enemy can drop.
// that each enemy can drop. // V2/V3: -> parray<Range<U16T>, NUM_RT_INDEXES_V3>
// V2/V3: -> parray<Range<U16T>, 0x64> /* 18 */ U32T<BE> enemy_rt_index_meseta_ranges_offset;
/* 18 */ U32T<BE> enemy_meseta_ranges_offset;
// Each byte in this table (indexed by enemy_type) represents the percent // Each byte in this table (indexed by rt_index) represents the percent chance that the enemy drops anything at
// chance that the enemy drops anything at all. (This check is done before // all. (This check is done before the rare drop check, so the chance of getting a rare item from an enemy is
// the rare drop check, so the chance of getting a rare item from an enemy // essentially this probability multiplied by the rare drop rate.)
// is essentially this probability multiplied by the rare drop rate.) // V2/V3: -> parray<uint8_t, NUM_RT_INDEXES_V3>
// V2/V3: -> parray<uint8_t, 0x64> /* 1C */ U32T<BE> enemy_rt_index_drop_probs_offset;
/* 1C */ U32T<BE> enemy_type_drop_probs_offset;
// Each byte in this table (indexed by enemy_type) represents the class of // Each byte in this table (indexed by rt_index) represents the class of item that can drop. The values are:
// item that the enemy can drop. The values are: // 00 = weapon
// 00 = weapon // 01 = armor
// 01 = armor // 02 = shield
// 02 = shield // 03 = unit
// 03 = unit // 04 = tool
// 04 = tool // 05 = meseta
// 05 = meseta // Anything else = no item
// Anything else = no item // V2/V3: -> parray<uint8_t, NUM_RT_INDEXES_V3>
// V2/V3: -> parray<uint8_t, 0x64> /* 20 */ U32T<BE> enemy_rt_index_item_classes_offset;
/* 20 */ U32T<BE> enemy_item_classes_offset;
// This table (indexed by area - 1) specifies the ranges of meseta values // This table (indexed by area - 1) specifies the ranges of meseta values that can drop from boxes.
// that can drop from boxes.
// V2/V3: -> parray<Range<U16T>, 0x0A> // V2/V3: -> parray<Range<U16T>, 0x0A>
/* 24 */ U32T<BE> box_meseta_ranges_offset; /* 24 */ U32T<BE> box_meseta_ranges_offset;
// This array specifies the chance that a rare weapon will have each // This array specifies the chance that a rare weapon will have each possible bonus value. This is indexed as
// possible bonus value. This is indexed as [(bonus_value - 10 / 5)][spec], // [(bonus_value - 10 / 5)][spec], so the first row refers the probability of getting a -10% bonus, the next row
// so the first row refers the probability of getting a -10% bonus, the next // is the chance of getting -5%, etc., all the way up to +100%. For non-rare items (or all items on v1/v2), spec
// row is the chance of getting -5%, etc., all the way up to +100%. For // is determined randomly based on the following field; for rare items on v3+, spec is always 5.
// non-rare items, spec is determined randomly based on the following field;
// for rare items, spec is always 5.
// V2: -> parray<parray<uint8_t, 5>, 0x17> // V2: -> parray<parray<uint8_t, 5>, 0x17>
// V3: -> parray<parray<U16T, 6>, 0x17> // V3: -> parray<parray<U16T, 6>, 0x17>
/* 28 */ U32T<BE> bonus_value_prob_table_offset; /* 28 */ U32T<BE> bonus_value_prob_table_offset;
// This array specifies the value of spec to be used in the above lookup for // This array specifies the value of spec to be used in the above lookup for non-rare items. This is NOT an index
// non-rare items. This is NOT an index probability table; this is a direct // probability table; this is a direct lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte
// 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:
// of this array prevents any weapon from having a bonus in that slot.
// For example, the array might look like this:
// [00 00 00 01 01 01 01 02 02 02] // [00 00 00 01 01 01 01 02 02 02]
// [FF FF FF 00 00 00 01 01 01 01] // [FF FF FF 00 00 00 01 01 01 01]
// [FF FF FF FF FF FF FF FF FF 00] // [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) // 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 // 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
// a bonus. In Forest 1 and 2 and Cave 1, weapons may have at most one // 1, weapons may have at most one bonus; in all other areas except Ruins 3, they can have at most two bonuses,
// bonus; in all other areas except Ruins 3, they can have at most two // and in Ruins 3, they can have up to three bonuses.
// bonuses, and in Ruins 3, they can have up to three bonuses.
// V2/V3: // -> parray<parray<uint8_t, 10>, 3> // V2/V3: // -> parray<parray<uint8_t, 10>, 3>
/* 2C */ U32T<BE> nonrare_bonus_prob_spec_offset; /* 2C */ U32T<BE> nonrare_bonus_prob_spec_offset;
// This array specifies the chance that a weapon will have each bonus type. // This array specifies the chance that a weapon will have each bonus type. The table is indexed as
// The table is indexed as [bonus_type][area - 1] for non-rare items; for // [bonus_type][area - 1] for non-rare items; for rare items, a random value in the range [0, 9] is used instead
// rare items, a random value in the range [0, 9] is used instead of // of (area - 1).
// (area - 1).
// For example, the table might look like this: // For example, the table might look like this:
// [46 46 3F 3E 3E 3D 3C 3C 3A 3A] // Chance of getting no bonus // [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 // [14 14 0A 0A 09 02 02 04 05 05] // Chance of getting Native bonus
@@ -193,54 +187,50 @@ public:
// V2/V3: -> parray<parray<uint8_t, 10>, 6> // V2/V3: -> parray<parray<uint8_t, 10>, 6>
/* 30 */ U32T<BE> bonus_type_prob_table_offset; /* 30 */ U32T<BE> bonus_type_prob_table_offset;
// This array (indexed by area - 1) specifies a multiplier of used in // This array (indexed by area - 1) specifies a parameter used in weapon special generation. If the sampled value
// special ability determination. It seems this uses the star values from // from this table is 0, no special is generated. Otherwise, a random floating-point value W in the range [0,
// ItemPMT, but not yet clear exactly in what way. // special_mult] is generated and truncated to an integer. If this value is greater than 3, no special is
// TODO: Figure out exactly what this does. Anchor: 80106FEC // 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> // V2/V3: -> parray<uint8_t, 0x0A>
/* 34 */ U32T<BE> special_mult_offset; /* 34 */ U32T<BE> special_mult_offset;
// This array (indexed by area - 1) specifies the probability that any // This array (indexed by area - 1) specifies the probability that a non-rare weapon will have a special ability.
// non-rare weapon will have a special ability.
// V2/V3: -> parray<uint8_t, 0x0A> // V2/V3: -> parray<uint8_t, 0x0A>
/* 38 */ U32T<BE> special_percent_offset; /* 38 */ U32T<BE> special_percent_offset;
// This index probability table is indexed by [tool_class][area - 1]. The // This index probability table is indexed by [tool_class][area - 1]. The tool class refers to an entry in
// tool class refers to an entry in ItemPMT, which links it to the actual // ItemPMT, which links it to the actual item code.
// item code.
// V2/V3: -> parray<parray<U16T, 0x0A>, 0x1C> // V2/V3: -> parray<parray<U16T, 0x0A>, 0x1C>
/* 3C */ U32T<BE> tool_class_prob_table_offset; /* 3C */ U32T<BE> tool_class_prob_table_offset;
// This index probability table determines how likely each technique is to // This index probability table determines how likely each technique is to appear. The table is indexed as
// appear. The table is indexed as [technique_num][area - 1]. // [technique_num][area - 1].
// V2/V3: -> parray<parray<uint8_t, 0x0A>, 0x13> // V2/V3: -> parray<parray<uint8_t, 0x0A>, 0x13>
/* 40 */ U32T<BE> technique_index_prob_table_offset; /* 40 */ U32T<BE> technique_index_prob_table_offset;
// This table specifies the ranges for technique disk levels. The table is // This table specifies the ranges for technique disk levels. The table is indexed as [technique_num][area - 1].
// indexed as [technique_num][area - 1]. If either min or max in the range // If either min or max in the range is 0xFF, or if max < min, technique disks are not dropped for that technique
// is 0xFF, or if max < min, technique disks are not dropped for that // and area pair.
// technique and area pair.
// V2/V3: -> parray<parray<Range<uint8_t>, 0x0A>, 0x13> // V2/V3: -> parray<parray<Range<uint8_t>, 0x0A>, 0x13>
/* 44 */ U32T<BE> technique_level_ranges_offset; /* 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; /* 48 */ uint8_t armor_or_shield_type_bias;
/* 49 */ parray<uint8_t, 3> unused1; /* 49 */ parray<uint8_t, 3> unused1;
// These values specify the maximum number of stars any generated unit can // These values specify the maximum number of stars any generated unit can have in each area. The values here are
// have in each area. The values here are not inclusive; that is, a value // not inclusive; that is, a value of 7 means that only units with 1-6 stars can drop in that area. The game
// of 7 means that only units with 1-6 stars can drop in that area. The // uniformly chooses a random number of stars in the acceptable range, then uniformly chooses a random unit with
// game uniformly chooses a random number of stars in the acceptable // that many stars.
// range, then uniformly chooses a random unit with that many stars.
// V2/V3: -> parray<uint8_t, 0x0A> // V2/V3: -> parray<uint8_t, 0x0A>
/* 4C */ U32T<BE> unit_max_stars_offset; /* 4C */ U32T<BE> unit_max_stars_offset;
// This index probability table determines which type of items drop from // This index probability table determines which type of items drop from boxes. The table is indexed as
// boxes. The table is indexed as [item_class][area - 1], with item_class // [item_class][area - 1], with item_class as the result value (that is, in the example below, the game looks at
// as the result value (that is, in the example below, the game looks at a // a single column and sums the values going down, then the chosen item class is one of the row indexes based on
// single column and sums the values going down, then the chosen item // the weight values in the column.) The resulting value has the same meaning as in enemy_rt_index_item_classes.
// 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.
// For example, this array might look like the following: // 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 // [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 // [02 02 02 02 03 02 02 02 03 03] // Chances per area of an armor drop
@@ -254,21 +244,28 @@ public:
/* 50 */ U32T<BE> box_item_class_prob_table_offset; /* 50 */ U32T<BE> box_item_class_prob_table_offset;
// There are several unused fields here. // There are several unused fields here.
} __packed__; } __packed_ws_be__(RootT, 0x54);
using Offsets = OffsetsT<false>; using Root = RootT<false>;
using OffsetsBE = OffsetsT<true>; using RootBE = RootT<true>;
check_struct_size(Offsets, 0x54);
check_struct_size(OffsetsBE, 0x54);
}; };
std::shared_ptr<const Table> get_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const; 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, 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; phosg::JSON json() const;
void print(FILE* stream) const; void print(FILE* stream) const;
void print_diff(FILE* stream, const CommonItemSet& other) const;
protected: protected:
CommonItemSet() = default; 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; std::unordered_map<uint16_t, std::shared_ptr<Table>> tables;
}; };
@@ -287,304 +284,3 @@ class JSONCommonItemSet : public CommonItemSet {
public: public:
explicit JSONCommonItemSet(const phosg::JSON& json); 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<PSOLFGEncryption> opt_rand_crypt) {
for (size_t z = 1; z < this->count; z++) {
size_t other_z = random_from_optional_crypt(opt_rand_crypt) % (z + 1);
ItemT t = this->items[z];
this->items[z] = this->items[other_z];
this->items[other_z] = t;
}
}
ItemT sample(std::shared_ptr<PSOLFGEncryption> opt_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[random_from_optional_crypt(opt_rand_crypt) % this->count];
}
}
};
class RELFileSet {
public:
template <typename ValueT, typename WeightT = ValueT>
struct WeightTableEntry {
ValueT value;
WeightT weight;
} __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;
};
+263 -242
View File
@@ -11,8 +11,6 @@
#include "Text.hh" #include "Text.hh"
using namespace std;
template <> template <>
const char* phosg::name_for_enum<CompressPhase>(CompressPhase v) { const char* phosg::name_for_enum<CompressPhase>(CompressPhase v) {
switch (v) { switch (v) {
@@ -30,29 +28,29 @@ const char* phosg::name_for_enum<CompressPhase>(CompressPhase v) {
} }
template <size_t WindowLength, size_t MaxMatchLength> template <size_t WindowLength, size_t MaxMatchLength>
struct WindowIndex { struct MapWindowIndex {
const uint8_t* data; const uint8_t* data;
size_t size; size_t size;
size_t offset; size_t current_offset;
set<size_t, function<bool(size_t, size_t)>> index; 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)), : data(reinterpret_cast<const uint8_t*>(data)),
size(size), size(size),
offset(0), current_offset(0),
index(bind(&WindowIndex::set_comparator, this, placeholders::_1, placeholders::_2)) {} index(std::bind(&MapWindowIndex::set_comparator, this, std::placeholders::_1, std::placeholders::_2)) {}
void advance() { void advance() {
if (this->offset >= WindowLength) { if (this->current_offset >= WindowLength) {
this->index.erase(this->offset - WindowLength); this->index.erase(this->current_offset - WindowLength);
} }
this->index.emplace(this->offset); this->index.emplace(this->current_offset);
this->offset++; this->current_offset++;
} }
size_t get_match_length(size_t match_offset) const { size_t get_match_length(size_t match_offset) const {
size_t match_iter = match_offset; 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) && while ((match_iter < match_offset + MaxMatchLength) &&
(match_iter < this->size) && (match_iter < this->size) &&
(offset_iter < this->size) && (offset_iter < this->size) &&
@@ -63,16 +61,13 @@ struct WindowIndex {
return match_iter - match_offset; return match_iter - match_offset;
}; };
// The data structure we want is a binary-searchable set of all strings // The data structure we want is a binary-searchable set of all strings starting at all possible offsets within the
// starting at all possible offsets within the sliding window, and we need // sliding window, and we need to be able to search lexicographically but insert and delete by offset. A
// to be able to search lexicographically but insert and delete by offset. // std::map<std::string, size_t> would accomplish this, but would be horrendously inefficient: we'd have to copy
// A std::map<std::string, size_t> would accomplish this, but would be // strings far too much. We can solve this by instead storing the offset of each string as keys in a set and using a
// horrendously inefficient: we'd have to copy strings far too much. We can // custom comparator to treat them as references to binary strings within the data.
// 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 { 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; size_t end_a = a + max_length;
for (; a < end_a; a++, b++) { for (; a < end_a; a++, b++) {
uint8_t data_a = static_cast<uint8_t>(this->data[a]); 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 return a < b; // Maximum-length match; order them by offset
}; };
pair<size_t, size_t> get_best_match() const { std::pair<size_t, size_t> match() const {
// Find the best match from the index. It's unlikely that we'll get an // Find the best match from the index. It's unlikely that we'll get an exact match, so check the entry before the
// exact match, so check the entry before the upper_bound result too. // upper_bound result too. Note: We use upper_bound rather than lower_bound because in PRS, a backreference can be
// Note: We use upper_bound rather than lower_bound because in PRS, a // encoded with fewer bits if it's close to the decompression offset, and this makes us pick the latest match by
// 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. // default.
size_t match_offset = 0; size_t match_offset = 0;
size_t match_size = 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()) { if (it != this->index.end()) {
size_t new_match_offset = *it; size_t new_match_offset = *it;
size_t new_match_size = this->get_match_length(new_match_offset); size_t new_match_size = this->get_match_length(new_match_offset);
@@ -113,19 +106,93 @@ struct WindowIndex {
match_size = new_match_size; 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 { struct LZSSInterleavedWriter {
phosg::StringWriter w; phosg::StringWriter w;
size_t buf_offset; size_t buf_offset;
uint8_t next_control_bit; uint8_t next_control_bit;
uint8_t buf[0x19]; uint8_t buf[0x19];
LZSSInterleavedWriter() LZSSInterleavedWriter() : buf_offset(1), next_control_bit(1) {
: buf_offset(1),
next_control_bit(1) {
this->buf[0] = 0; this->buf[0] = 0;
} }
@@ -147,7 +214,7 @@ struct LZSSInterleavedWriter {
void write_control(bool v) { void write_control(bool v) {
if (this->next_control_bit == 0) { 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) { if (v) {
this->buf[0] |= this->next_control_bit; this->buf[0] |= this->next_control_bit;
@@ -166,9 +233,7 @@ struct LZSSInterleavedWriter {
class ControlStreamReader { class ControlStreamReader {
public: public:
ControlStreamReader(phosg::StringReader& r) ControlStreamReader(phosg::StringReader& r) : r(r), bits(0x0000) {}
: r(r),
bits(0x0000) {}
bool read() { bool read() {
if (!(this->bits & 0x0100)) { if (!(this->bits & 0x0100)) {
@@ -217,28 +282,28 @@ struct PRSPathNode {
size_t to_offset = 0; 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); 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.resize(in_size + 1);
nodes[0].bits_used = 18; // Stop command: 2 control bits and 2 data bytes nodes[0].bits_used = 18; // Stop command: 2 control bits and 2 data bytes
size_t copy_progress_max = 3 * in_size; 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 // Populate all possible short copies
std::thread short_window_thread([&]() -> void { std::thread short_window_thread([&]() -> void {
WindowIndex<0x100, 5> window(in_data_v, in_size); WindowIndex<0x100, 5> window(in_data_v, in_size);
while (window.offset < in_size) { while (window.current_offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) { if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000; size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0); progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
} }
auto& node = nodes[window.offset]; auto& node = nodes[window.current_offset];
auto match = window.get_best_match(); auto match = window.match();
if (match.second >= 2) { 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; node.max_short_copy_size = match.second;
} }
window.advance(); 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 // Populate all possible long copies
std::thread long_window_thread([&]() -> void { std::thread long_window_thread([&]() -> void {
WindowIndex<0x1FFF, 9> window(in_data_v, in_size); WindowIndex<0x1FFF, 9> window(in_data_v, in_size);
while (window.offset < in_size) { while (window.current_offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) { if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000; size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0); progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
} }
auto& node = nodes[window.offset]; auto& node = nodes[window.current_offset];
auto match = window.get_best_match(); auto match = window.match();
if (match.second >= 3) { 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; node.max_long_copy_size = match.second;
} }
window.advance(); 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 // Populate all possible extended copies
std::thread extended_window_thread([&]() -> void { std::thread extended_window_thread([&]() -> void {
WindowIndex<0x1FFF, 0x100> window(in_data_v, in_size); WindowIndex<0x1FFF, 0x100> window(in_data_v, in_size);
while (window.offset < in_size) { while (window.current_offset < in_size) {
if (window.offset && (window.offset & 0xFFF) == 0 && progress_fn) { if (window.current_offset && (window.current_offset & 0xFFF) == 0 && progress_fn) {
size_t progress = copy_progress.fetch_add(0x1000) + 0x1000; size_t progress = copy_progress.fetch_add(0x1000) + 0x1000;
progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0); progress_fn(CompressPhase::INDEX, progress, copy_progress_max, 0);
} }
auto& node = nodes[window.offset]; auto& node = nodes[window.current_offset];
auto match = window.get_best_match(); auto match = window.match();
if (match.second >= 1) { 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; node.max_extended_copy_size = match.second;
} }
window.advance(); window.advance();
@@ -285,8 +350,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
long_window_thread.join(); long_window_thread.join();
extended_window_thread.join(); extended_window_thread.join();
// For each node, populate the literal value, and the best ways to get to the // For each node, populate the literal value, and the best ways to get to the following nodes
// following nodes
for (size_t z = 0; z < in_size; z++) { for (size_t z = 0; z < in_size; z++) {
if ((z & 0xFFF) == 0 && progress_fn) { if ((z & 0xFFF) == 0 && progress_fn) {
progress_fn(CompressPhase::CONSTRUCT_PATHS, z, in_size, 0); 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) { switch (next_node.from_command_type) {
case PRSPathNode::CommandType::LITERAL: case PRSPathNode::CommandType::LITERAL:
if (copy_size != 1) { 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_control(true);
w.write_data(in_data[offset]); w.write_data(in_data[offset]);
break; break;
case PRSPathNode::CommandType::SHORT_COPY: { case PRSPathNode::CommandType::SHORT_COPY: {
if (copy_size < 2 || copy_size > 5) { 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; uint8_t encoded_size = copy_size - 2;
w.write_control(false); 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: { case PRSPathNode::CommandType::LONG_COPY: {
if (copy_size < 2 || copy_size > 9) { 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.write_control(false);
w.flush_if_ready(); 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: { case PRSPathNode::CommandType::EXTENDED_COPY: {
if (copy_size < 1 || copy_size > 0x100) { 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.write_control(false);
w.flush_if_ready(); w.flush_if_ready();
@@ -417,7 +481,7 @@ string prs_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallb
break; break;
} }
default: default:
throw logic_error("invalid copy type in shortest path"); throw std::logic_error("invalid copy type in shortest path");
} }
w.flush_if_ready(); 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()); 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); 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); 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 worst possible encoding we can do is a literal byte when no byte with the same value is within the window, or
// the same value is within the window, or an extended copy if there is a byte // an extended copy if there is a byte with the same value in the window.
// with the same value in the window.
WindowIndex<0x1FFF, 1> window(in_data, size); WindowIndex<0x1FFF, 1> window(in_data, size);
LZSSInterleavedWriter w; LZSSInterleavedWriter w;
for (size_t z = 0; z < size; z++) { for (size_t z = 0; z < size; z++) {
auto match = window.get_best_match(); auto match = window.match();
if (match.second >= 1) { if (match.second >= 1) {
// Write extended copy // Write extended copy
int16_t offset = match.first - window.offset; int16_t offset = match.first - window.current_offset;
w.write_control(false); w.write_control(false);
w.flush_if_ready(); w.flush_if_ready();
w.write_control(true); w.write_control(true);
@@ -490,7 +553,7 @@ PRSCompressor::PRSCompressor(
void PRSCompressor::add(const void* data, size_t size) { void PRSCompressor::add(const void* data, size_t size) {
if (this->closed) { if (this->closed) {
throw logic_error("compressor is closed"); throw std::logic_error("compressor is closed");
} }
phosg::StringReader r(data, size); 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()); this->add(data.data(), data.size());
} }
@@ -539,9 +602,8 @@ void PRSCompressor::advance() {
match_size++; match_size++;
} }
// If there are multiple matches of the longest length, use the latest one, // If there are multiple matches of the longest length, use the latest one, since it's more likely that it can be
// since it's more likely that it can be expressed as a short copy instead // expressed as a short copy instead of a long copy.
// of a long copy.
if (match_size >= (best_match_size + best_match_literals)) { if (match_size >= (best_match_size + best_match_literals)) {
best_match_offset = match_offset; best_match_offset = match_offset;
best_match_size = match_size; best_match_size = match_size;
@@ -558,15 +620,13 @@ void PRSCompressor::advance() {
this->advance_literal(); this->advance_literal();
} }
// If there is a suitable match, write a backreference; otherwise, write a // If there is a match, write a backreference; otherwise, write a literal. The backreference should be encoded:
// literal. The backreference should be encoded:
// - As a short copy if offset in [-0x100, -1] and size in [2, 5] // - 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 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] // - 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 // Technically an extended copy can be used for sizes 1-9 as well, but if size is 1 or 2, writing literals is better
// size is 1 or 2, writing literals is better (since it uses fewer data // (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), and a long copy can cover sizes 3-9 (and also // bytes and control bits).
// uses fewer data bytes and control bits).
ssize_t backreference_offset = best_match_offset - this->reverse_log.end_offset(); ssize_t backreference_offset = best_match_offset - this->reverse_log.end_offset();
if (best_match_size < 2) { if (best_match_size < 2) {
// The match is too small; a literal would use fewer bits // 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); this->advance_short_copy(backreference_offset, best_match_size);
} else if (best_match_size < 3) { } 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 // 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
// extended copy for this either (as noted above), so write a literal // above), so write a literal
this->advance_literal(); this->advance_literal();
} else if ((backreference_offset >= -0x1FFF) && (best_match_size <= 9)) { } 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); this->advance_extended_copy(backreference_offset, best_match_size);
} else { } 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); this->move_forward_data_to_reverse_log(size);
} }
string& PRSCompressor::close() { std::string& PRSCompressor::close() {
if (!this->closed) { if (!this->closed) {
// Advance until all input is consumed // Advance until all input is consumed
while (this->reverse_log.end_offset() < this->input_bytes) { while (this->reverse_log.end_offset() < this->input_bytes) {
@@ -655,14 +715,12 @@ string& PRSCompressor::close() {
void PRSCompressor::write_control(bool z) { void PRSCompressor::write_control(bool z) {
if (this->pending_control_bits & 0x0100) { if (this->pending_control_bits & 0x0100) {
this->output.pput_u8( this->output.pput_u8(this->control_byte_offset, this->pending_control_bits & 0xFF);
this->control_byte_offset, this->pending_control_bits & 0xFF);
this->control_byte_offset = this->output.size(); this->control_byte_offset = this->output.size();
this->output.put_u8(0); this->output.put_u8(0);
this->pending_control_bits = z ? 0x8080 : 0x8000; this->pending_control_bits = z ? 0x8080 : 0x8000;
} else { } else {
this->pending_control_bits = this->pending_control_bits = (this->pending_control_bits >> 1) | (z ? 0x8080 : 0x8000);
(this->pending_control_bits >> 1) | (z ? 0x8080 : 0x8000);
} }
} }
@@ -671,35 +729,26 @@ void PRSCompressor::flush_control() {
while (!(this->pending_control_bits & 0x0100)) { while (!(this->pending_control_bits & 0x0100)) {
this->pending_control_bits >>= 1; this->pending_control_bits >>= 1;
} }
this->output.pput_u8( this->output.pput_u8(this->control_byte_offset, this->pending_control_bits & 0xFF);
this->control_byte_offset, this->pending_control_bits & 0xFF);
} else { } else {
if (this->control_byte_offset != this->output.size() - 1) { 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); this->output.str().resize(this->output.str().size() - 1);
} }
} }
string prs_compress( std::string prs_compress(const void* vdata, size_t size, ssize_t compression_level, ProgressCallback progress_fn) {
const void* vdata,
size_t size,
ssize_t compression_level,
ProgressCallback progress_fn) {
PRSCompressor prs(compression_level, progress_fn); PRSCompressor prs(compression_level, progress_fn);
prs.add(vdata, size); prs.add(vdata, size);
return std::move(prs.close()); return std::move(prs.close());
} }
string prs_compress( std::string prs_compress(const std::string& data, ssize_t compression_level, ProgressCallback progress_fn) {
const string& data,
ssize_t compression_level,
ProgressCallback progress_fn) {
return prs_compress(data.data(), data.size(), compression_level, progress_fn); return prs_compress(data.data(), data.size(), compression_level, progress_fn);
} }
string prs_compress_indexed( std::string prs_compress_indexed(const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
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); const uint8_t* in_data = reinterpret_cast<const uint8_t*>(in_data_v);
LZSSInterleavedWriter w; LZSSInterleavedWriter w;
@@ -708,24 +757,21 @@ string prs_compress_indexed(
WindowIndex<0x1FFF, 0x100> w_extended(in_data_v, in_size); WindowIndex<0x1FFF, 0x100> w_extended(in_data_v, in_size);
size_t last_progress_fn_call_offset = 0; size_t last_progress_fn_call_offset = 0;
while (w_short.offset < in_size) { while (w_short.current_offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (w_short.offset & ~0xFFF))) { if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (w_short.current_offset & ~0xFFF))) {
last_progress_fn_call_offset = w_short.offset; last_progress_fn_call_offset = w_short.current_offset;
progress_fn(CompressPhase::GENERATE_RESULT, w_short.offset, in_size, w.size()); progress_fn(CompressPhase::GENERATE_RESULT, w_short.current_offset, in_size, w.size());
} }
auto m_short = w_short.get_best_match(); auto m_short = w_short.match();
auto m_long = w_long.get_best_match(); auto m_long = w_long.match();
auto m_extended = w_extended.get_best_match(); auto m_extended = w_extended.match();
// Write the match that achieves the best ratio of output bytes to // Write the match that achieves the best ratio of output bytes to compressed bits used. To do this without
// compressed bits used. To do this without floating-point math, we multiply // floating-point math, we multiply the output byte count for each type of command by 468 / (command_bits), since
// the output byte count for each type of command by 468 / (command_bits), // 468 is the least common multiple of the number of bits for each command type. The command type with the highest
// since 468 is the least common multiple of the number of bits for each // score is the one we'll use, breaking ties by choosing the shorter command type. Note that the size of any copy
// command type. The command type with the highest score is the one we'll // type can be zero if no match was found; if no matches were found at all, then we can always write a literal.
// 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_literal = 52;
size_t score_short = m_short.second * 39; size_t score_short = m_short.second * 39;
size_t score_long = m_long.second * 26; size_t score_long = m_long.second * 26;
@@ -765,11 +811,11 @@ string prs_compress_indexed(
switch (command_type) { switch (command_type) {
case PRSPathNode::CommandType::LITERAL: case PRSPathNode::CommandType::LITERAL:
w.write_control(true); w.write_control(true);
w.write_data(in_data[w_short.offset]); w.write_data(in_data[w_short.current_offset]);
bytes_consumed = 1; bytes_consumed = 1;
break; break;
case PRSPathNode::CommandType::SHORT_COPY: { 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; uint8_t encoded_size = m_short.second - 2;
w.write_control(false); w.write_control(false);
w.flush_if_ready(); w.flush_if_ready();
@@ -783,7 +829,7 @@ string prs_compress_indexed(
break; break;
} }
case PRSPathNode::CommandType::LONG_COPY: { 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.write_control(false);
w.flush_if_ready(); w.flush_if_ready();
w.write_control(true); w.write_control(true);
@@ -794,7 +840,7 @@ string prs_compress_indexed(
break; break;
} }
case PRSPathNode::CommandType::EXTENDED_COPY: { 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.write_control(false);
w.flush_if_ready(); w.flush_if_ready();
w.write_control(true); w.write_control(true);
@@ -807,12 +853,12 @@ string prs_compress_indexed(
} }
case PRSPathNode::CommandType::NONE: case PRSPathNode::CommandType::NONE:
default: default:
throw logic_error("invalid command type"); throw std::logic_error("invalid command type");
} }
w.flush_if_ready(); w.flush_if_ready();
if (bytes_consumed == 0) { 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++) { for (size_t z = 0; z < bytes_consumed; z++) {
@@ -832,47 +878,36 @@ string prs_compress_indexed(
return std::move(w.close()); 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); return prs_compress_indexed(data.data(), data.size(), progress_fn);
} }
PRSDecompressResult prs_decompress_with_meta( PRSDecompressResult prs_decompress_with_meta(
const void* data, size_t size, size_t max_output_size, bool allow_unterminated) { 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 // PRS is an LZ77-based compression algorithm. Compressed data is split into two streams: a control stream and a data
// two streams: a control stream and a data stream. The control stream is read // stream. The control stream is read one bit at a time, and the data stream is read one byte at a time. The streams
// one bit at a time, and the data stream is read one byte at a time. The // are interleaved such that the decompressor never has to move backward in the input stream - when the decompressor
// streams are interleaved such that the decompressor never has to move // needs a control bit and there are no unused bits from the previous byte of the control stream, it reads a byte
// backward in the input stream - when the decompressor needs a control bit // from the input and treats it as the next 8 control bits.
// 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: // 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 // 1 - Literal byte. The decompressor copies one byte from the input data stream to the output.
// stream to the output. // 00 - Short backreference. The decompressor reads two control bits and adds 2 to this value to determine the number
// 00 - Short backreference. The decompressor reads two control bits and adds // of bytes to copy, then reads one byte from the data stream to determine how far back in the output to copy
// 2 to this value to determine the number of bytes to copy, then reads // from. This byte is treated as an 8-bit negative number - so 0xF7, for example, means to start copying data
// one byte from the data stream to determine how far back in the output // from 9 bytes before the end of the output. The range must start before the end of the output, but the end of
// to copy from. This byte is treated as an 8-bit negative number - so // the range may be beyond the end of the output. In this case, the bytes between the beginning of the range and
// 0xF7, for example, means to start copying data from 9 bytes before the // original end of the output are simply repeated.
// end of the output. The range must start before the end of the output, // 01 - Long backreference. The decompressor reads two bytes from the data and byteswaps the resulting 16-bit value
// but the end of the range may be beyond the end of the output. In this // (that is, the low byte is read first). The start offset (again, as a negative number) is the top 13 bits of
// case, the bytes between the beginning of the range and original end of // this value; the size is the low 3 bits of this value, plus 2. If the size bits are all zero, an additional
// the output are simply repeated. // byte is read from the data stream and 1 is added to it to determine the backreference size (we call this an
// 01 - Long backreference. The decompressor reads two bytes from the data and // extended backreference). Therefore, the maximum backreference size is 256 bytes.
// byteswaps the resulting 16-bit value (that is, the low byte is read // Decompression ends when either there are no more input bytes to read, or when a long backreference is read with
// first). The start offset (again, as a negative number) is the top 13 // all zeroes in its offset field. The original implementation stops decompression successfully when any attempt to
// bits of this value; the size is the low 3 bits of this value, plus 2. // read from the input encounters the end of the stream, but newserv's implementation only allows this at the end of
// If the size bits are all zero, an additional byte is read from the // an opcode - if end-of-stream is encountered partway through an opcode, we throw instead, because it's likely the
// data stream and 1 is added to it to determine the backreference size // input has been truncated or is malformed in some way.
// (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::StringWriter w;
phosg::StringReader r(data, size); phosg::StringReader r(data, size);
@@ -885,7 +920,7 @@ PRSDecompressResult prs_decompress_with_meta(
if (allow_unterminated) { if (allow_unterminated) {
return {std::move(w.str()), r.where()}; return {std::move(w.str()), r.where()};
} else { } else {
throw runtime_error("maximum output size exceeded"); throw std::runtime_error("maximum output size exceeded");
} }
} }
w.put_u8(r.get_u8()); w.put_u8(r.get_u8());
@@ -894,10 +929,9 @@ PRSDecompressResult prs_decompress_with_meta(
ssize_t offset; ssize_t offset;
size_t count; size_t count;
// Control 01 = long backreference
if (cr.read()) { if (cr.read()) {
// The bits stored in the data stream are AAAAABBBCCCCCCCC, which we // Control 01 = long backreference
// rearrange into offset = CCCCCCCCAAAAA and size = BBB. // The bits from the data stream are AAAAABBBCCCCCCCC, which we rearrange as offset=CCCCCCCCAAAAA and size=BBB.
uint16_t a = r.get_u8(); uint16_t a = r.get_u8();
a |= (r.get_u8() << 8); a |= (r.get_u8() << 8);
offset = (a >> 3) | (~0x1FFF); offset = (a >> 3) | (~0x1FFF);
@@ -905,34 +939,31 @@ PRSDecompressResult prs_decompress_with_meta(
if (offset == ~0x1FFF) { if (offset == ~0x1FFF) {
break; break;
} }
// If the size field is zero, it's an extended backreference (size comes // If the size field is zero, it's an extended backreference (size comes from another byte in the data stream)
// from another byte in the data stream)
count = (a & 7) ? ((a & 7) + 2) : (r.get_u8() + 1); count = (a & 7) ? ((a & 7) + 2) : (r.get_u8() + 1);
// Control 00 = short backreference
} else { } else {
// Count comes from 2 bits in the control stream instead of from the // Control 00 = short backreference
// data stream (and 2 is added). Importantly, the control stream bits // Count comes from 2 bits in the control stream instead of from the data stream (and 2 is added). Importantly,
// are read first - this may involve reading another control stream // the control stream bits are read first - this may involve reading another control stream byte, which happens
// byte, which happens before the offset is read from the data stream. // before the offset is read from the data stream.
count = cr.read() << 1; count = cr.read() << 1;
count = (count | cr.read()) + 2; count = (count | cr.read()) + 2;
offset = r.get_u8() | (~0xFF); offset = r.get_u8() | (~0xFF);
} }
// Copy bytes from the referenced location in the output. Importantly, // Copy bytes from the referenced location in the output. Importantly, copy only one byte at a time, in order to
// copy only one byte at a time, in order to support ranges that cover the // support ranges that cover the current end of the output.
// current end of the output.
size_t read_offset = w.size() + offset; size_t read_offset = w.size() + offset;
if (read_offset >= w.size()) { 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++) { for (size_t z = 0; z < count; z++) {
if (max_output_size && w.size() == max_output_size) { if (max_output_size && w.size() == max_output_size) {
if (allow_unterminated) { if (allow_unterminated) {
return {std::move(w.str()), r.where()}; return {std::move(w.str()), r.where()};
} else { } 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]); w.put_u8(w.str()[read_offset + z]);
@@ -943,16 +974,16 @@ PRSDecompressResult prs_decompress_with_meta(
return {std::move(w.str()), r.where()}; 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); 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); auto ret = prs_decompress_with_meta(data, size, max_output_size, allow_unterminated);
return std::move(ret.data); 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); auto ret = prs_decompress_with_meta(data.data(), data.size(), max_output_size, allow_unterminated);
return std::move(ret.data); 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; size_t read_offset = ret + offset;
if (read_offset >= ret) { 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; 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) { if (allow_unterminated) {
return max_output_size; return max_output_size;
} else { } 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; 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); return prs_decompress_size(data.data(), data.size(), max_output_size, allow_unterminated);
} }
@@ -1018,7 +1049,7 @@ void prs_disassemble(FILE* stream, const void* data, size_t size) {
uint8_t buffered_bits = cr.buffered_bits(); uint8_t buffered_bits = cr.buffered_bits();
if (cr.read()) { if (cr.read()) {
uint8_t literal_value = r.get_u8(); uint8_t literal_value = r.get_u8();
fprintf(stream, "[%zX] %hhu> 1 %02hhX literal %02hhX\n", phosg::fwrite_fmt(stream, "[{:X}] {}> 1 {:02X} literal {:02X}\n",
output_bytes, buffered_bits, literal_value, literal_value); output_bytes, buffered_bits, literal_value, literal_value);
output_bytes++; output_bytes++;
@@ -1030,19 +1061,19 @@ void prs_disassemble(FILE* stream, const void* data, size_t size) {
uint16_t a = (a_high << 8) | a_low; uint16_t a = (a_high << 8) | a_low;
ssize_t offset = (a >> 3) | (~0x1FFF); ssize_t offset = (a >> 3) | (~0x1FFF);
if (offset == ~0x1FFF) { if (offset == ~0x1FFF) {
fprintf(stream, "[%zX] end\n", output_bytes); phosg::fwrite_fmt(stream, "[{:X}] end\n", output_bytes);
break; break;
} }
if (a & 7) { if (a & 7) {
count = (a & 7) + 2; count = (a & 7) + 2;
read_offset = output_bytes + offset; read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 01 %02hhX %02hhX long copy from %zd (offset=%zX) size=%zX\n", phosg::fwrite_fmt(stream, "[{:X}] {}> 01 {:02X} {:02X} long copy from {} (offset={:X}) size={:X}\n",
output_bytes, buffered_bits, a_low, a_high, offset, read_offset, count); output_bytes, buffered_bits, a_low, a_high, offset, read_offset, count);
} else { } else {
uint8_t count_u8 = r.get_u8(); uint8_t count_u8 = r.get_u8();
count = count_u8 + 1; count = count_u8 + 1;
read_offset = output_bytes + offset; read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 01 %02hhX %02hhX %02hhX extended copy from %zd (offset=%zX) size=%zX\n", phosg::fwrite_fmt(stream, "[{:X}] {}> 01 {:02X} {:02X} {:02X} extended copy from {} (offset={:X}) size={:X}\n",
output_bytes, buffered_bits, a_low, a_high, count_u8, offset, read_offset, count); output_bytes, buffered_bits, a_low, a_high, count_u8, offset, read_offset, count);
} }
@@ -1053,12 +1084,12 @@ void prs_disassemble(FILE* stream, const void* data, size_t size) {
count = ((first_bit ? 2 : 0) | (second_bit ? 1 : 0)) + 2; count = ((first_bit ? 2 : 0) | (second_bit ? 1 : 0)) + 2;
ssize_t offset = offset_u8 | (~0xFF); ssize_t offset = offset_u8 | (~0xFF);
read_offset = output_bytes + offset; read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 00%c%c %02hhX short copy from %zd (offset=%zX) size=%zX\n", phosg::fwrite_fmt(stream, "[{:X}] {}> 00{}{} {:02X} short copy from {} (offset={:X}) size={:X}\n",
output_bytes, buffered_bits, first_bit ? '1' : '0', second_bit ? '1' : '0', offset_u8, offset, read_offset, count); output_bytes, buffered_bits, first_bit ? '1' : '0', second_bit ? '1' : '0', offset_u8, offset, read_offset, count);
} }
if (read_offset >= output_bytes) { 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; output_bytes += count;
} }
@@ -1069,11 +1100,10 @@ void prs_disassemble(FILE* stream, const std::string& data) {
return prs_disassemble(stream, data.data(), data.size()); return prs_disassemble(stream, data.data(), data.size());
} }
// BC0 is a compression algorithm fairly similar to PRS, but with a simpler set // BC0 is a compression algorithm fairly similar to PRS, but with a simpler set of commands. Like PRS, there is a
// of commands. Like PRS, there is a control stream, indicating when to copy a // control stream, indicating when to copy a literal byte from the input and when to copy from a backreference; unlike
// 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
// PRS, there is only one type of backreference. Also, there is no stop opcode; // there are no more input bytes to read.
// the decompressor simply stops when there are no more input bytes to read.
struct BC0PathNode { struct BC0PathNode {
uint16_t memo_offset = 0; uint16_t memo_offset = 0;
@@ -1087,23 +1117,22 @@ struct BC0PathNode {
size_t to_offset = 0; size_t to_offset = 0;
}; };
string bc0_compress_optimal( std::string bc0_compress_optimal(const void* in_data_v, size_t in_size, ProgressCallback progress_fn) {
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); 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.resize(in_size + 1);
nodes[0].bits_used = 0; nodes[0].bits_used = 0;
// Populate all possible backreferences // Populate all possible backreferences
{ {
WindowIndex<0x1000, 0x12> window(in_data_v, in_size); WindowIndex<0x1000, 0x12> window(in_data_v, in_size);
while (window.offset < in_size) { while (window.current_offset < in_size) {
if ((window.offset & 0xFFF) == 0 && progress_fn) { if ((window.current_offset & 0xFFF) == 0 && progress_fn) {
progress_fn(CompressPhase::INDEX, window.offset, in_size, 0); progress_fn(CompressPhase::INDEX, window.current_offset, in_size, 0);
} }
auto& node = nodes[window.offset]; auto& node = nodes[window.current_offset];
auto match = window.get_best_match(); auto match = window.match();
if (match.second >= 3) { if (match.second >= 3) {
node.memo_offset = (match.first - 0x12) & 0xFFF; node.memo_offset = (match.first - 0x12) & 0xFFF;
node.max_copy_size = match.second; 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 // For each node, populate the literal value, and the best ways to get to the following nodes
// following nodes
for (size_t z = 0; z < in_size; z++) { for (size_t z = 0; z < in_size; z++) {
if ((z & 0xFFF) == 0 && progress_fn) { if ((z & 0xFFF) == 0 && progress_fn) {
progress_fn(CompressPhase::CONSTRUCT_PATHS, z, in_size, 0); progress_fn(CompressPhase::CONSTRUCT_PATHS, z, in_size, 0);
@@ -1185,24 +1213,24 @@ string bc0_compress_optimal(
return std::move(w.close()); 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); 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); const uint8_t* in_data = reinterpret_cast<const uint8_t*>(in_data_v);
LZSSInterleavedWriter w; LZSSInterleavedWriter w;
WindowIndex<0x1000, 0x12> window(in_data_v, in_size); WindowIndex<0x1000, 0x12> window(in_data_v, in_size);
size_t last_progress_fn_call_offset = 0; size_t last_progress_fn_call_offset = 0;
while (window.offset < in_size) { while (window.current_offset < in_size) {
if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (window.offset & ~0xFFF))) { if (progress_fn && ((last_progress_fn_call_offset & ~0xFFF) != (window.current_offset & ~0xFFF))) {
last_progress_fn_call_offset = window.offset; last_progress_fn_call_offset = window.current_offset;
progress_fn(CompressPhase::GENERATE_RESULT, window.offset, in_size, w.size()); 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 // Write a backreference if a match was found; otherwise, write a literal
if (match.second >= 3) { 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)); w.write_data(((memo_offset >> 4) & 0xF0) | (match.second - 3));
} else { } else {
w.write_control(true); w.write_control(true);
w.write_data(in_data[window.offset]); w.write_data(in_data[window.current_offset]);
match.second = 1; match.second = 1;
} }
w.flush_if_ready(); 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()); 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); const uint8_t* in_data = reinterpret_cast<const uint8_t*>(in_data_v);
LZSSInterleavedWriter w; LZSSInterleavedWriter w;
@@ -1238,36 +1266,30 @@ string bc0_encode(const void* in_data_v, size_t in_size) {
return std::move(w.close()); return std::move(w.close());
} }
// The BC0 decompression implementation in PSO GC is vulnerable to overflow // The BC0 decompression implementation in PSO GC is vulnerable to overflow attacks - there is no bounds checking on
// attacks - there is no bounds checking on the output buffer. It is unlikely // the output buffer. It is unlikely that this can be usefully exploited (e.g. for RCE) because the output pointer is
// that this can be usefully exploited (e.g. for RCE) because the output pointer // loaded from memory before every byte is written, so we cannot change the output pointer to any arbitrary address.
// 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()); 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::StringReader r(data, size);
phosg::StringWriter w; phosg::StringWriter w;
// Unlike PRS, BC0 uses a memo which "rolls over" every 0x1000 bytes. The // Unlike PRS, BC0 uses a memo which "rolls over" every 0x1000 bytes. The boundaries of these "memo pages" are offset
// boundaries of these "memo pages" are offset by -0x12 bytes for some reason, // by -0x12 bytes for some reason, so the first output byte corresponds to position 0xFEE on the first memo page.
// so the first output byte corresponds to position 0xFEE on the first memo // Backreferences refer to offsets based on the start of memo pages; for example, if the current output offset is
// page. Backreferences refer to offsets based on the start of memo pages; for // 0x1234, a backreference with offset 0x123 refers to the byte that was written at offset 0x1111 (because that byte
// example, if the current output offset is 0x1234, a backreference with // is at offset 0x111 in the memo, because the memo rolls over every 0x1000 bytes and the first memo byte was 0x12
// offset 0x123 refers to the byte that was written at offset 0x1111 (because // bytes before the beginning of the next page). The memo is initially zeroed from 0 to 0xFEE; it seems PSO GC
// that byte is at offset 0x111 in the memo, because the memo rolls over every // doesn't initialize the last 0x12 bytes of the first memo page.
// 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; parray<uint8_t, 0x1000> memo;
uint16_t memo_offset = 0x0FEE; uint16_t memo_offset = 0x0FEE;
// The low byte of this value contains the control stream data; the high bits // The low byte of this value contains the control stream data; the high bits specify which low bits are valid. When
// specify which low bits are valid. When the last 1 is shifted out of the // 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
// high byte, we need to read a new control stream byte to get the next set of
// control bits. // control bits.
uint16_t control_stream_bits = 0x0000; 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) { if ((control_stream_bits & 1) == 0) {
// Control bit 0 means to perform a backreference copy. The offset and // Control bit 0 means to perform a backreference copy. The offset and size are stored in two bytes in the input
// size are stored in two bytes in the input stream, laid out as follows: // stream, laid out as follows:
// a1 = 0bBBBBBBBB // a1 = 0bBBBBBBBB
// a2 = 0bAAAACCCC // a2 = 0bAAAACCCC
// The offset is the concatenation of bits AAAABBBBBBBB, which refers to // The offset is the concatenation of bits AAAABBBBBBBB, which refers to a position in the memo; the number of
// a position in the memo; the number of bytes to copy is (CCCC + 3). The // bytes to copy is (CCCC + 3). The decompressor copies that many bytes from that offset in the memo, and writes
// decompressor copies that many bytes from that offset in the memo, and // them to the output and to the current position in the memo.
// writes them to the output and to the current position in the memo.
uint8_t a1 = r.get_u8(); uint8_t a1 = r.get_u8();
if (r.eof()) { if (r.eof()) {
break; break;
@@ -1305,8 +1326,8 @@ string bc0_decompress(const void* data, size_t size) {
} }
} else { } else {
// Control bit 1 means to write a byte directly from the input to the // Control bit 1 means to write a byte directly from the input to the output. As above, the byte is also written
// output. As above, the byte is also written to the memo. // to the memo.
uint8_t v = r.get_u8(); uint8_t v = r.get_u8();
w.put_u8(v); w.put_u8(v);
memo[memo_offset] = v; memo[memo_offset] = v;
@@ -1317,7 +1338,7 @@ string bc0_decompress(const void* data, size_t size) {
return std::move(w.str()); 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()); bc0_disassemble(stream, data.data(), data.size());
} }
@@ -1346,11 +1367,11 @@ void bc0_disassemble(FILE* stream, const void* data, size_t size) {
uint8_t a2 = r.get_u8(); uint8_t a2 = r.get_u8();
size_t count = (a2 & 0x0F) + 3; size_t count = (a2 & 0x0F) + 3;
// size_t backreference_offset = a1 | ((a2 << 4) & 0xF00); // size_t backreference_offset = a1 | ((a2 << 4) & 0xF00);
fprintf(stream, "[%zX] backreference %02zX\n", output_bytes, count); phosg::fwrite_fmt(stream, "[{:X}] backreference {:02X}\n", output_bytes, count);
output_bytes += count; output_bytes += count;
} else { } else {
fprintf(stream, "[%zX] literal %02hhX\n", output_bytes, r.get_u8()); phosg::fwrite_fmt(stream, "[{:X}] literal {:02X}\n", output_bytes, r.get_u8());
output_bytes++; output_bytes++;
} }
} }
+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; typedef std::function<void(CompressPhase phase, size_t input_progress, size_t input_size, size_t output_size)> ProgressCallback;
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PRS compression // PRS compression
////////////////////////////////////////////////////////////////////////////////
// Use this class if you need to compress from multiple input buffers, or need // Use this class if you need to compress from multiple input buffers, or need to compress multiple chunks and don't
// to compress multiple chunks and don't want to copy their contents // want to copy their contents unnecessarily. (For most common use cases, use prs_compress, below, instead.) To use
// unnecessarily. (For most common use cases, use prs_compress, below, instead.) // this class, instantiate it, then call .add() one or more times, then call .close() and use the returned string as
// To use this class, instantiate it, then call .add() one or more times, then // the compressed result.
// call .close() and use the returned string as the compressed result.
class PRSCompressor { class PRSCompressor {
public: public:
// compression_level specifies how aggressively to search for alternate paths: // compression_level specifies how aggressively to search for alternate paths:
// -1: Don't perform any compression at all, but produce output that can be // -1: Don't perform any compression at all, but produce output that can be understood by prs_decompress. The
// understood by prs_decompress. The output will be about 9/8 the size // output will be about 9/8 the size of the input.
// of the input. // 0: Greedily search for the longest backreference at every point. Don't consider any alternate paths. Generally
// 0: Greedily search for the longest backreference at every point. Don't // offers a good balance between speed and output size.
// consider any alternate paths. Generally offers a good balance between // 1: Consider two paths at each point when a backreference is found: using the backreference or ignoring it.
// speed and output size. // 2+: Consider further chains of paths at each point. Using values 2 or greater for compression_level generally
// 1: Consider two paths at each point when a backreference is found: using // yields diminishing returns.
// 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); explicit PRSCompressor(ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
~PRSCompressor() = default; ~PRSCompressor() = default;
// Adds more input data to be compressed, which logically comes after all // Adds more input data to be compressed, which logically comes after all previous data provided via add() calls.
// previous data provided via add() calls. Cannot be called after close() is // Cannot be called after close() is called.
// called.
void add(const void* data, size_t size); void add(const void* data, size_t size);
void add(const std::string& data); void add(const std::string& data);
// Ends compression and returns the complete compressed result. It's OK to // Ends compression and returns the complete compressed result. It's OK to std::move() from the returned reference.
// std::move() from the returned string reference.
std::string& close(); std::string& close();
// Returns the total number of bytes passed to add() calls so far. // Returns the total number of bytes passed to add() calls so far.
@@ -149,36 +142,24 @@ private:
phosg::StringWriter output; phosg::StringWriter output;
}; };
// These functions use PRSCompressor to compress a buffer of data. This is // These functions use PRSCompressor to compress a buffer of data. This is essentially a shortcut for constructing a
// essentially a shortcut for constructing a PRSCompressor, calling .add() on // PRSCompressor, calling .add() on it once, then calling .close().
// it once, then calling .close().
std::string prs_compress( std::string prs_compress(
const void* vdata, const void* vdata, size_t size, ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
size_t size,
ssize_t compression_level = 0,
ProgressCallback progress_fn = nullptr);
std::string prs_compress( std::string prs_compress(
const std::string& data, const std::string& data, ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
ssize_t compression_level = 0,
ProgressCallback progress_fn = nullptr);
// A faster form of prs_compress that doesn't have a tunable compression level. // A faster form of prs_compress that doesn't have a tunable compression level.
std::string prs_compress_indexed( std::string prs_compress_indexed(const void* vdata, size_t size, ProgressCallback progress_fn = nullptr);
const void* vdata, std::string prs_compress_indexed(const std::string& data, ProgressCallback progress_fn = nullptr);
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 // Compresses data using PRS to the smallest possible output size. This function is slow, but produces results
// is slow, but produces results significantly smaller than even Sega's original // significantly smaller than even Sega's original compressor.
// compressor.
std::string prs_compress_optimal(const void* vdata, size_t size, ProgressCallback progress_fn = nullptr); 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); 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 // Compresses data using PRS to the LARGEST possible output size. There is no practical use for this function except
// practical use for this function except for amusement. // for amusement.
std::string prs_compress_pessimal(const void* vdata, size_t size); std::string prs_compress_pessimal(const void* vdata, size_t size);
// Decompresses PRS-compressed data. // Decompresses PRS-compressed data.
@@ -186,13 +167,14 @@ struct PRSDecompressResult {
std::string data; std::string data;
size_t input_bytes_used; 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(
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false); 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 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); 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 // Returns the decompressed size of PRS-compressed data, without actually decompressing it.
// 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 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); 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 void* data, size_t size);
void prs_disassemble(FILE* stream, const std::string& data); void prs_disassemble(FILE* stream, const std::string& data);
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BC0 compression // BC0 compression
////////////////////////////////////////////////////////////////////////////////
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant // Compresses data using the BC0 algorithm. Like with PRS, the optimal variant is slow, but produces the smallest
// is slow, but produces the smallest possible output. // possible output.
std::string bc0_compress_optimal(
const void* in_data_v,
size_t in_size,
ProgressCallback progress_fn = nullptr);
std::string bc0_compress(const std::string& data, ProgressCallback progress_fn = nullptr); 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(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 // Encodes data in a BC0-compatible format without compression (similar to compression_level=-1 in prs_compress).
// compression_level=-1 with prs_compress).
std::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);
// Decompresses BC0-compressed data. // Decompresses BC0-compressed data.
+756 -1139
View File
File diff suppressed because it is too large Load Diff
+8 -12
View File
@@ -5,20 +5,16 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
// dc_serial_number_is_valid_slow is Sega's implementation; // dc_serial_number_is_valid_slow is Sega's implementation; dc_serial_number_is_valid_fast produces identical results
// dc_serial_number_is_valid_fast produces identical results but is between 3000 // but is between 3000 and 7500 times faster, depending on the compiler's optimization level.
// 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_slow( bool dc_serial_number_is_valid_fast(const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
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 dc_serial_number_is_valid_fast( bool decoded_dc_serial_number_is_valid_fast(uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
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::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 { struct DCSerialNumberIterator {
bool started = false; bool started = false;
+28 -76
View File
@@ -1,7 +1,5 @@
#include "DNSServer.hh" #include "DNSServer.hh"
#include <netinet/in.h>
#include <poll.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -14,53 +12,25 @@
#include "Loggers.hh" #include "Loggers.hh"
#include "NetworkAddresses.hh" #include "NetworkAddresses.hh"
#include "ServerState.hh"
using namespace std; DNSServer::DNSServer(std::shared_ptr<ServerState> state) : state(state) {}
DNSServer::DNSServer(
shared_ptr<struct event_base> base,
uint32_t local_connect_address,
uint32_t external_connect_address,
shared_ptr<const IPV4RangeSet> banned_ipv4_ranges)
: base(base),
local_connect_address(local_connect_address),
external_connect_address(external_connect_address),
banned_ipv4_ranges(banned_ipv4_ranges) {}
DNSServer::~DNSServer() {
for (const auto& it : this->fd_to_receive_event) {
close(it.first);
}
}
void DNSServer::listen(const std::string& socket_path) {
this->add_socket(phosg::listen(socket_path, 0, 0));
}
void DNSServer::listen(const std::string& addr, int port) { void DNSServer::listen(const std::string& addr, int port) {
this->add_socket(phosg::listen(addr, port, 0)); if (port == 0) {
throw std::runtime_error("Listening port cannot be zero");
}
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 = 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);
} }
void DNSServer::listen(int port) { std::string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
this->add_socket(phosg::listen("", port, 0));
}
void DNSServer::add_socket(int fd) {
unique_ptr<struct event, void (*)(struct event*)> e(
event_new(this->base.get(), fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message, this),
event_free);
event_add(e.get(), nullptr);
this->fd_to_receive_event.emplace(fd, std::move(e));
}
void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
short events, void* ctx) {
reinterpret_cast<DNSServer*>(ctx)->on_receive_message(fd, events);
}
string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
if (size < 0x0C) { if (size < 0x0C) {
throw invalid_argument("query too small"); throw std::invalid_argument("query too small");
} }
const char* data = reinterpret_cast<const char*>(vdata); const char* data = reinterpret_cast<const char*>(vdata);
@@ -68,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; phosg::be_uint32_t be_resolved_address = resolved_address;
string response; std::string response;
response.append(data, 2); response.append(data, 2);
response.append("\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00", 10); response.append("\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00", 10);
response.append(&data[12], name_len); response.append(&data[12], name_len);
@@ -77,45 +47,27 @@ string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t re
return response; return response;
} }
string DNSServer::response_for_query( std::string DNSServer::response_for_query(const std::string& query, uint32_t resolved_address) {
const string& query, uint32_t resolved_address) {
return DNSServer::response_for_query(query.data(), query.size(), resolved_address); return DNSServer::response_for_query(query.data(), query.size(), resolved_address);
} }
void DNSServer::on_receive_message(int fd, short) { asio::awaitable<void> DNSServer::dns_server_task(std::shared_ptr<asio::ip::udp::socket> sock) {
for (;;) { for (;;) {
struct sockaddr_storage remote; std::string input(2048, 0);
socklen_t remote_size = sizeof(sockaddr_in); asio::ip::udp::endpoint sender_ep;
memset(&remote, 0, remote_size); 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());
string input(2048, 0); if (bytes < 0x0C) {
ssize_t bytes = recvfrom(fd, const_cast<char*>(input.data()), input.size(), dns_server_log.warning_f("input query too small");
0, reinterpret_cast<sockaddr*>(&remote), &remote_size);
if (bytes < 0) {
if (errno != EAGAIN) {
dns_server_log.error("input error %d", errno);
throw runtime_error("cannot read from udp socket");
}
break;
} else if (bytes == 0) {
break;
} else if (bytes < 0x0C) {
dns_server_log.warning("input query too small");
phosg::print_data(stderr, input.data(), bytes); phosg::print_data(stderr, input.data(), bytes);
} else if (!this->state->data->banned_ipv4_ranges->check(sender_addr)) {
} else if (!this->banned_ipv4_ranges->check(remote)) {
input.resize(bytes); input.resize(bytes);
const sockaddr_in* remote_sin = reinterpret_cast<const sockaddr_in*>(&remote); uint32_t connect_address = is_local_address(sender_addr)
uint32_t remote_address = ntohl(remote_sin->sin_addr.s_addr); ? this->state->data->local_address
uint32_t connect_address = is_local_address(remote_address) : this->state->data->external_address;
? this->local_connect_address std::string response = this->response_for_query(input, connect_address);
: this->external_connect_address; co_await sock->async_send_to(asio::buffer(response.data(), response.size()), sender_ep, asio::use_awaitable);
string response = this->response_for_query(input, connect_address);
sendto(fd, response.data(), response.size(), 0,
reinterpret_cast<const sockaddr*>(&remote), remote_size);
} }
} }
} }
+10 -22
View File
@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <event2/event.h> #include <asio.hpp>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
@@ -9,36 +8,25 @@
#include "IPV4RangeSet.hh" #include "IPV4RangeSet.hh"
class ServerState;
class DNSServer { class DNSServer {
public: public:
DNSServer( explicit DNSServer(std::shared_ptr<ServerState> state);
std::shared_ptr<struct event_base> base,
uint32_t local_connect_address,
uint32_t external_connect_address,
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges);
DNSServer(const DNSServer&) = delete; DNSServer(const DNSServer&) = delete;
DNSServer(DNSServer&&) = delete; DNSServer(DNSServer&&) = delete;
virtual ~DNSServer(); DNSServer& operator=(const DNSServer&) = delete;
DNSServer& operator=(DNSServer&&) = delete;
virtual ~DNSServer() = default;
inline void set_banned_ipv4_ranges(std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges) {
this->banned_ipv4_ranges = banned_ipv4_ranges;
}
void listen(const std::string& socket_path);
void listen(const std::string& addr, int port); void listen(const std::string& addr, int port);
void listen(int port);
void add_socket(int fd);
static std::string response_for_query(const void* vdata, size_t size, uint32_t resolved_address); static std::string response_for_query(const void* vdata, size_t size, uint32_t resolved_address);
static std::string response_for_query(const std::string& query, uint32_t resolved_address); static std::string response_for_query(const std::string& query, uint32_t resolved_address);
private: private:
std::shared_ptr<struct event_base> base; std::shared_ptr<ServerState> state;
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event; std::unordered_set<std::shared_ptr<asio::ip::udp::socket>> sockets;
uint32_t local_connect_address;
uint32_t external_connect_address;
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
static void dispatch_on_receive_message(evutil_socket_t fd, short events, void* ctx); asio::awaitable<void> dns_server_task(std::shared_ptr<asio::ip::udp::socket> sock);
void on_receive_message(int fd, short event);
}; };
+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();
};
+268 -321
View File
File diff suppressed because it is too large Load Diff
+25 -25
View File
@@ -1,7 +1,5 @@
#pragma once #pragma once
#include <event2/event.h>
#include <functional> #include <functional>
#include <map> #include <map>
#include <memory> #include <memory>
@@ -18,11 +16,12 @@
class DownloadSession { class DownloadSession {
public: public:
DownloadSession( DownloadSession(
std::shared_ptr<struct event_base> base, std::shared_ptr<asio::io_context> io_context,
const struct sockaddr_storage& remote, const std::string& remote_host,
uint16_t remote_port,
const std::string& output_dir, const std::string& output_dir,
Version version, Version version,
uint8_t language, Language language,
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file, std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file,
uint32_t serial_number2, uint32_t serial_number2,
uint32_t serial_number, uint32_t serial_number,
@@ -43,12 +42,19 @@ public:
DownloadSession& operator=(DownloadSession&&) = delete; DownloadSession& operator=(DownloadSession&&) = delete;
virtual ~DownloadSession() = default; virtual ~DownloadSession() = default;
asio::awaitable<void> run();
protected: protected:
// Config (must be set by caller) // Config (must be set by caller)
std::string remote_host;
uint16_t remote_port;
std::string output_dir; std::string output_dir;
Version version;
Language language;
bool show_command_data;
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file; std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
uint32_t serial_number2;
uint32_t serial_number; uint32_t serial_number;
uint32_t serial_number2;
std::string access_key; std::string access_key;
std::string username; std::string username;
std::string password; std::string password;
@@ -62,17 +68,17 @@ protected:
// State (set during session) // State (set during session)
phosg::PrefixedLogger log; phosg::PrefixedLogger log;
std::shared_ptr<struct event_base> base; std::shared_ptr<asio::io_context> io_context;
Channel channel; std::shared_ptr<Channel> channel;
uint64_t hardware_id; uint64_t hardware_id;
uint32_t guild_card_number; uint32_t guild_card_number = 0;
parray<uint8_t, 0x28> prev_cmd_data; parray<uint8_t, 0x28> prev_cmd_data;
parray<uint8_t, 0x20> client_config; parray<uint8_t, 0x20> client_config;
bool sent_96; bool sent_96 = false;
std::vector<S_LobbyListEntry_83> lobby_menu_items; std::vector<S_LobbyListEntry_83> lobby_menu_items;
bool should_request_category_list; bool should_request_category_list = true;
uint64_t current_request; uint64_t current_request = 0;
std::map<uint64_t, std::string> pending_requests; std::map<uint64_t, std::string> pending_requests;
std::unordered_set<uint64_t> done_requests; std::unordered_set<uint64_t> done_requests;
@@ -92,20 +98,14 @@ protected:
bool v3; bool v3;
}; };
static const std::vector<GameConfig> game_configs; static const std::vector<GameConfig> game_configs;
size_t current_game_config_index; size_t current_game_config_index = 0;
bool in_game; bool in_game = false;
bool bin_complete; bool bin_complete = false;
bool dat_complete; bool dat_complete = false;
static void dispatch_on_channel_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
static void dispatch_on_channel_error(Channel& ch, short events);
void on_channel_input(uint16_t command, uint32_t flag, std::string& msg);
void on_channel_error(short events);
void send_next_request();
void on_request_complete();
void assign_item_ids(uint32_t base_item_id);
void send_93_9D_9E(bool extended); void send_93_9D_9E(bool extended);
void send_61_98(bool is_98); void send_61_98(bool is_98);
asio::awaitable<void> on_message(Channel::Message& msg);
void send_next_request();
void on_request_complete();
}; };
+251 -166
View File
@@ -2,149 +2,155 @@
#include <phosg/Filesystem.hh> #include <phosg/Filesystem.hh>
#include <phosg/Strings.hh> #include <phosg/Strings.hh>
#include <set>
#include "Loggers.hh" #include "Loggers.hh"
#include "PSOEncryption.hh" #include "PSOEncryption.hh"
#include "StaticGameData.hh" #include "StaticGameData.hh"
using namespace std;
static constexpr uint8_t EP1 = EnemyTypeDefinition::Flag::VALID_EP1; static constexpr uint8_t EP1 = EnemyTypeDefinition::Flag::VALID_EP1;
static constexpr uint8_t EP2 = EnemyTypeDefinition::Flag::VALID_EP2; static constexpr uint8_t EP2 = EnemyTypeDefinition::Flag::VALID_EP2;
static constexpr uint8_t EP4 = EnemyTypeDefinition::Flag::VALID_EP4; static constexpr uint8_t EP4 = EnemyTypeDefinition::Flag::VALID_EP4;
static constexpr uint8_t RARE = EnemyTypeDefinition::Flag::IS_RARE; 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 // clang-format off
// TYPE FLAGS RT BP ENUM NAME IN-GAME NAME ULTIMATE NAME // TYPE FLAGS RT OLDRT BP-STATS BP-ATTACK BP-RESIST BP-MOVEMENT ENUM NAME IN-GAME NAME ULTIMATE NAME
{EnemyType::UNKNOWN, 0, 0xFF, 0xFF, "UNKNOWN", "__UNKNOWN__", nullptr}, {EnemyType::UNKNOWN, 0, NONE, NONE, {}, {}, {}, {}, "UNKNOWN", "__UNKNOWN__", nullptr},
{EnemyType::NONE, 0, 0xFF, 0xFF, "NONE", "__NONE__", nullptr}, {EnemyType::NONE, 0, NONE, NONE, {}, {}, {}, {}, "NONE", "__NONE__", nullptr},
{EnemyType::NON_ENEMY_NPC, EP1 | EP2 | EP4, 0xFF, 0xFF, "NON_ENEMY_NPC", "__NPC__", nullptr}, {EnemyType::NON_ENEMY_NPC, EP1 | EP2 | EP4, NONE, NONE, {}, {}, {}, {}, "NON_ENEMY_NPC", "__NPC__", nullptr},
{EnemyType::AL_RAPPY, EP1 | RARE, 0x06, 0x19, "AL_RAPPY", "Al Rappy", "Pal Rappy"}, {EnemyType::AL_RAPPY, EP1 | RARE, 0x06, 0x06, {0x19}, {0x19}, {0x19}, {0x19}, "AL_RAPPY", "Al Rappy", "Pal Rappy"},
{EnemyType::ASTARK, EP4, 0x41, 0x09, "ASTARK", "Astark", nullptr}, {EnemyType::ASTARK, EP4, 0x58, 0x41, {0x09}, {0x0B, 0x0A, 0x0C}, {0x09}, {0x09}, "ASTARK", "Astark", nullptr},
{EnemyType::BA_BOOTA, EP4, 0x4F, 0x03, "BA_BOOTA", "Ba Boota", nullptr}, {EnemyType::BA_BOOTA, EP4, 0x62, 0x4F, {0x03}, {0x03, 0x02, 0x04}, {0x03}, {0x03}, "BA_BOOTA", "Ba Boota", nullptr},
{EnemyType::BARBA_RAY, EP2, 0x49, 0x0F, "BARBA_RAY", "Barba Ray", nullptr}, {EnemyType::BARBA_RAY_JOINT, EP2 | BOSS, 0x49, 0x49, {0x10}, {0x0F}, {0x10}, {}, "BARBA_RAY_JOINT", "Barba Ray (joint)", nullptr},
{EnemyType::BARBAROUS_WOLF, EP1 | EP2, 0x08, 0x03, "BARBAROUS_WOLF", "Barbarous Wolf", "Gulgus-gue"}, {EnemyType::BARBA_RAY, EP2 | BOSS, 0x49, 0x49, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "BARBA_RAY", "Barba Ray", nullptr},
{EnemyType::BEE_L, EP1 | EP2, 0xFF, 0xFF, "BEE_L", "Bee L", "Gee L"}, {EnemyType::BARBAROUS_WOLF, EP1 | EP2, 0x08, 0x08, {0x03}, {0x03}, {0x03}, {0x03}, "BARBAROUS_WOLF", "Barbarous Wolf", "Gulgus-gue"},
{EnemyType::BEE_R, EP1 | EP2, 0xFF, 0xFF, "BEE_R", "Bee R", "Gee R"}, {EnemyType::BEE_L, EP1 | EP2, NONE, NONE, {0x0C}, {0x0C}, {0x0C}, {0x0C}, "BEE_L", "Bee L", "Gee L"},
{EnemyType::BOOMA, EP1, 0x09, 0x4B, "BOOMA", "Booma", "Bartle"}, {EnemyType::BEE_R, EP1 | EP2, NONE, NONE, {0x0B}, {0x0B}, {0x0B}, {0x0B}, "BEE_R", "Bee R", "Gee R"},
{EnemyType::BOOTA, EP4, 0x4D, 0x00, "BOOTA", "Boota", nullptr}, {EnemyType::BOOMA, EP1, 0x09, 0x09, {0x4B}, {0x4E}, {0x4A}, {0x4A}, "BOOMA", "Booma", "Bartle"},
{EnemyType::BULCLAW, EP1, 0x28, 0x1F, "BULCLAW", "Bulclaw", nullptr}, {EnemyType::BOOTA, EP4, 0x60, 0x4D, {0x00}, {0x00, 0x02, 0x04}, {0x00}, {0x00}, "BOOTA", "Boota", nullptr},
{EnemyType::BULK, EP1, 0x27, 0x1F, "BULK", "Bulk", nullptr}, {EnemyType::BULCLAW, EP1, 0x28, 0x28, {0x1F}, {0x1F}, {0x1F}, {0x1F, 0x20}, "BULCLAW", "Bulclaw", nullptr},
{EnemyType::CANADINE, EP1, 0x1C, 0x07, "CANADINE", "Canadine", "Canabin"}, {EnemyType::BULK, EP1, 0x27, 0x27, {0x1F}, {0x1F}, {0x1F}, {0x1F, 0x20}, "BULK", "Bulk", nullptr},
{EnemyType::CANADINE_GROUP, EP1, 0x1C, 0x08, "CANADINE_GROUP", "Canadine (group)", "Canabin (group)"}, {EnemyType::CANADINE_GROUP, EP1, 0x1C, 0x1C, {0x08}, {0x08}, {0x08}, {0x08}, "CANADINE_GROUP", "Canadine (group)", "Canabin (group)"},
{EnemyType::CANANE, EP1, 0x1D, 0x09, "CANANE", "Canane", "Canune"}, {EnemyType::CANADINE, EP1, 0x1C, 0x1C, {0x07}, {0x07}, {0x07}, {0x07}, "CANADINE", "Canadine", "Canabin"},
{EnemyType::CHAOS_BRINGER, EP1, 0x24, 0x0D, "CHAOS_BRINGER", "Chaos Bringer", "Dark Bringer"}, {EnemyType::CANANE, EP1, 0x1D, 0x1D, {0x09}, {0x09}, {0x09}, {0x09}, "CANANE", "Canane", "Canune"},
{EnemyType::CHAOS_SORCERER, EP1 | EP2, 0x1F, 0x0A, "CHAOS_SORCERER", "Chaos Sorceror", "Gran Sorceror"}, {EnemyType::CHAOS_BRINGER, EP1, 0x24, 0x24, {0x0D}, {0x0D}, {0x0D}, {0x0A, 0x0D}, "CHAOS_BRINGER", "Chaos Bringer", "Dark Bringer"},
{EnemyType::CLAW, EP1, 0x26, 0x20, "CLAW", "Claw", nullptr}, {EnemyType::CHAOS_SORCERER, EP1 | EP2, 0x1F, 0x1F, {0x0A}, {0x0A}, {0x0A}, {}, "CHAOS_SORCERER", "Chaos Sorceror", "Gran Sorceror"},
{EnemyType::DARK_BELRA, EP1 | EP2, 0x25, 0x0E, "DARK_BELRA", "Dark Belra", "Indi Belra"}, {EnemyType::CLAW, EP1, 0x26, 0x26, {0x20}, {0x20}, {0x20}, {}, "CLAW", "Claw", nullptr},
{EnemyType::DARK_FALZ_1, EP1, 0xFF, 0x36, "DARK_FALZ_1", "Dark Falz (phase 1)", nullptr}, {EnemyType::DARK_BELRA, EP1 | EP2, 0x25, 0x25, {0x0E}, {0x0E, 0x13}, {0x0E}, {0x0E}, "DARK_BELRA", "Dark Belra", "Indi Belra"},
{EnemyType::DARK_FALZ_2, EP1, 0x2F, 0x37, "DARK_FALZ_2", "Dark Falz (phase 2)", nullptr}, {EnemyType::DARK_FALZ_1, EP1 | BOSS, NONE, NONE, {0x36}, {0x36}, {0x36}, {0x36, 0x39}, "DARK_FALZ_1", "Dark Falz (phase 1)", nullptr},
{EnemyType::DARK_FALZ_3, EP1, 0x2F, 0x38, "DARK_FALZ_3", "Dark Falz (phase 3)", nullptr}, {EnemyType::DARK_FALZ_2, EP1 | BOSS, 0x2F, 0x2F, {0x37}, {0x37}, {0x37}, {0x37}, "DARK_FALZ_2", "Dark Falz (phase 2)", nullptr},
{EnemyType::DARK_GUNNER, EP1, 0x22, 0x1E, "DARK_GUNNER", "Dark Gunner", nullptr}, {EnemyType::DARK_FALZ_3, EP1 | BOSS, 0x2F, 0x2F, {0x38}, {0x38}, {0x38}, {0x38}, "DARK_FALZ_3", "Dark Falz (phase 3)", nullptr},
{EnemyType::DARVANT, EP1, 0xFF, 0x35, "DARVANT", "Darvant", nullptr}, {EnemyType::DARK_GUNNER_CONTROL, EP1, NONE, NONE, {}, {}, {}, {}, "DARK_GUNNER_CONTROL", "Dark Gunner (control)", nullptr},
{EnemyType::DARVANT_ULTIMATE, EP1, 0xFF, 0x39, "DARVANT_ULTIMATE", "Darvant (ultimate)", nullptr}, {EnemyType::DARK_GUNNER, EP1, 0x22, 0x22, {0x1E}, {0x1E}, {0x1E}, {0x1E}, "DARK_GUNNER", "Dark Gunner", nullptr},
{EnemyType::DE_ROL_LE, EP1, 0x2D, 0x0F, "DE_ROL_LE", "De Rol Le", "Dal Ral Lie"}, {EnemyType::DARVANT, EP1, NONE, NONE, {0x35}, {0x35}, {0x35}, {0x35, 0x39}, "DARVANT", "Darvant", nullptr},
{EnemyType::DE_ROL_LE_BODY, EP1, 0xFF, 0xFF, "DE_ROL_LE_BODY", "De Rol Le (body)", "Dal Ral Lie (body)"}, {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, 0xFF, 0xFF, "DE_ROL_LE_MINE", "De Rol Le (mine)", "Dal Ral Lie (mine)"}, {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::DEATH_GUNNER, EP1, 0x23, 0x1E, "DEATH_GUNNER", "Death Gunner", nullptr}, {EnemyType::DE_ROL_LE, EP1 | BOSS, 0x2D, 0x2D, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "DE_ROL_LE", "De Rol Le", "Dal Ra Lie"},
{EnemyType::DEL_LILY, EP2, 0x53, 0x25, "DEL_LILY", "Del Lily", nullptr}, {EnemyType::DEATH_GUNNER, EP1, 0x23, 0x23, {0x1E}, {0x1E}, {0x1E}, {0x1E}, "DEATH_GUNNER", "Death Gunner", nullptr},
{EnemyType::DEL_RAPPY_CRATER, EP4, 0x57, 0x06, "DEL_RAPPY_CRATER", "Del Rappy (crater)", nullptr}, {EnemyType::DEL_LILY, EP2, 0x53, 0x53, {0x25}, {0x25}, {0x25}, {0x25}, "DEL_LILY", "Del Lily", nullptr},
{EnemyType::DEL_RAPPY_DESERT, EP4, 0x58, 0x18, "DEL_RAPPY_DESERT", "Del Rappy (desert)", nullptr}, {EnemyType::DEL_RAPPY_CRATER, EP4, 0x69, 0x57, {0x06}, {0x06}, {0x06}, {0x06}, "DEL_RAPPY_CRATER", "Del Rappy (crater)", nullptr},
{EnemyType::DELBITER, EP2, 0x48, 0x0D, "DELBITER", "Delbiter", nullptr}, {EnemyType::DEL_RAPPY_DESERT, EP4, 0x69, 0x58, {0x18}, {0x18}, {0x18}, {0x18}, "DEL_RAPPY_DESERT", "Del Rappy (desert)", nullptr},
{EnemyType::DELDEPTH, EP2, 0x47, 0x30, "DELDEPTH", "Deldepth", nullptr}, {EnemyType::DELBITER, EP2, 0x48, 0x48, {0x0D}, {0x0D}, {0x0D}, {0x0D}, "DELBITER", "Delbiter", nullptr},
{EnemyType::DELSABER, EP1 | EP2, 0x1E, 0x52, "DELSABER", "Delsaber", nullptr}, {EnemyType::DELDEPTH, EP2, 0x47, 0x47, {0x30}, {0x30}, {0x30}, {0x30}, "DELDEPTH", "Deldepth", nullptr},
{EnemyType::DIMENIAN, EP1 | EP2, 0x29, 0x53, "DIMENIAN", "Dimenian", "Arlan"}, {EnemyType::DELSABER, EP1 | EP2, 0x1E, 0x1E, {0x52}, {0x57, 0x58, 0x59}, {0x51}, {0x51}, "DELSABER", "Delsaber", nullptr},
{EnemyType::DOLMDARL, EP2, 0x41, 0x50, "DOLMDARL", "Dolmdarl", nullptr}, {EnemyType::DIMENIAN, EP1 | EP2, 0x29, 0x29, {0x53}, {0x5A}, {0x52}, {0x52}, "DIMENIAN", "Dimenian", "Arlan"},
{EnemyType::DOLMOLM, EP2, 0x40, 0x4F, "DOLMOLM", "Dolmolm", nullptr}, {EnemyType::DOLMDARL, EP2, 0x41, 0x41, {0x50}, {0x55}, {0x4F}, {0x4F}, "DOLMDARL", "Dolmdarl", nullptr},
{EnemyType::DORPHON, EP4, 0x50, 0x0F, "DORPHON", "Dorphon", nullptr}, {EnemyType::DOLMOLM, EP2, 0x40, 0x40, {0x4F}, {0x54}, {0x4E}, {0x4E}, "DOLMOLM", "Dolmolm", nullptr},
{EnemyType::DORPHON_ECLAIR, EP4 | RARE, 0x51, 0x10, "DORPHON_ECLAIR", "Dorphon Eclair", nullptr}, {EnemyType::DORPHON_ECLAIR, EP4 | RARE, 0x64, 0x51, {0x10}, {0x10}, {0x10}, {0x10}, "DORPHON_ECLAIR", "Dorphon Eclair", nullptr},
{EnemyType::DRAGON, EP1, 0x2C, 0x12, "DRAGON", "Dragon", "Sil Dragon"}, {EnemyType::DORPHON, EP4, 0x63, 0x50, {0x0F}, {0x0F}, {0x0F}, {0x0F}, "DORPHON", "Dorphon", nullptr},
{EnemyType::DUBCHIC, EP1 | EP2, 0x18, 0x1B, "DUBCHIC", "Dubchic", "Dubchich"}, {EnemyType::DRAGON, EP1 | BOSS, 0x2C, 0x2C, {0x12}, {0x12, 0x14, 0x15, 0x16, 0x17}, {0x12}, {0x11}, "DRAGON", "Dragon", "Sil Dragon"},
{EnemyType::DUBWITCH, EP1 | EP2, 0xFF, 0xFF, "DUBWITCH", "Dubwitch", "Duvuik"}, {EnemyType::DUBCHIC, EP1 | EP2, 0x18, 0x18, {0x1B}, {0x1B}, {0x1B}, {0x1B}, "DUBCHIC", "Dubchic", "Dubchich"},
{EnemyType::EGG_RAPPY, EP2, 0x51, 0x19, "EGG_RAPPY", "Egg Rappy", nullptr}, {EnemyType::DUBWITCH, EP1 | EP2, NONE, NONE, {}, {}, {}, {}, "DUBWITCH", "Dubwitch", "Duvuik"},
{EnemyType::EPSIGARD, EP2, 0xFF, 0xFF, "EPSIGARD", "Episgard", nullptr}, {EnemyType::EGG_RAPPY, EP2, 0x51, 0x51, {0x19}, {0x19}, {0x19}, {0x19}, "EGG_RAPPY", "Egg Rappy", nullptr},
{EnemyType::EPSILON, EP2, 0x54, 0x23, "EPSILON", "Epsilon", nullptr}, {EnemyType::EPSIGARD, EP2, NONE, NONE, {0x24}, {0x24}, {0x24}, {0x24}, "EPSIGARD", "Episgard", nullptr},
{EnemyType::EVIL_SHARK, EP1, 0x10, 0x4F, "EVIL_SHARK", "Evil Shark", "Vulmer"}, {EnemyType::EPSILON, EP2, 0x54, 0x54, {0x23}, {0x23}, {0x23}, {0x23}, "EPSILON", "Epsilon", nullptr},
{EnemyType::GAEL_OR_GIEL, EP2, 0xFF, 0x2E, "GAEL", "Gael/Giel", nullptr}, {EnemyType::EVIL_SHARK, EP1, 0x10, 0x10, {0x4F}, {0x54}, {0x4E}, {0x4E}, "EVIL_SHARK", "Evil Shark", "Vulmer"},
{EnemyType::GAL_GRYPHON, EP2, 0x4D, 0x1E, "GAL_GRYPHON", "Gal Gryphon", nullptr}, {EnemyType::GAEL_OR_GIEL, EP2, NONE, NONE, {0x2E}, {0x2E}, {0x2E}, {}, "GAEL_OR_GIEL", "Gael/Giel", nullptr},
{EnemyType::GARANZ, EP1 | EP2, 0x19, 0x1D, "GARANZ", "Garanz", "Baranz"}, {EnemyType::GAL_GRYPHON, EP2 | BOSS, 0x4D, 0x4D, {0x1E}, {0x1E, 0x1F, 0x20, 0x21, 0x22}, {0x1E}, {0x1E, 0x1F, 0x20}, "GAL_GRYPHON", "Gal Gryphon", nullptr},
{EnemyType::GEE, EP2, 0x36, 0x07, "GEE", "Gee", nullptr}, {EnemyType::GARANZ, EP1 | EP2, 0x19, 0x19, {0x1D}, {0x1D}, {0x1D}, {0x1D}, "GARANZ", "Garanz", "Baranz"},
{EnemyType::GI_GUE, EP2, 0x37, 0x1A, "GI_GUE", "Gi Gue", nullptr}, {EnemyType::GEE, EP2, 0x36, 0x36, {0x07}, {0x07}, {0x07}, {0x07}, "GEE", "Gee", nullptr},
{EnemyType::GIBBLES, EP2, 0x3D, 0x3D, "GIBBLES", "Gibbles", nullptr}, {EnemyType::GI_GUE, EP2, 0x37, 0x37, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "GI_GUE", "Gi Gue", nullptr},
{EnemyType::GIGOBOOMA, EP1, 0x0B, 0x4D, "GIGOBOOMA", "Gigobooma", "Tollaw"}, {EnemyType::GIBBLES, EP2, 0x3D, 0x3D, {0x3D}, {0x3D, 0x3E, 0x3F}, {0x3D}, {0x3D}, "GIBBLES", "Gibbles", nullptr},
{EnemyType::GILLCHIC, EP1 | EP2, 0x32, 0x1C, "GILLCHIC", "Gillchic", "Gillchich"}, {EnemyType::GIGOBOOMA, EP1, 0x0B, 0x0B, {0x4D}, {0x50}, {0x4C}, {0x4C}, "GIGOBOOMA", "Gigobooma", "Tollaw"},
{EnemyType::GIRTABLULU, EP4, 0x48, 0x1F, "GIRTABLULU", "Girtablulu", nullptr}, {EnemyType::GILLCHIC, EP1 | EP2, 0x32, 0x32, {0x1C}, {0x1C}, {0x1C}, {0x1C}, "GILLCHIC", "Gillchic", "Gillchich"},
{EnemyType::GOBOOMA, EP1, 0x0A, 0x4C, "GOBOOMA", "Gobooma", "Barble"}, {EnemyType::GIRTABLULU, EP4, 0x5D, 0x48, {0x1F}, {0x1F}, {0x1F}, {0x1F}, "GIRTABLULU", "Girtablulu", nullptr},
{EnemyType::GOL_DRAGON, EP2, 0x4C, 0x12, "GOL_DRAGON", "Gol Dragon", nullptr}, {EnemyType::GOBOOMA, EP1, 0x0A, 0x0A, {0x4C}, {0x4F}, {0x4B}, {0x4B}, "GOBOOMA", "Gobooma", "Barble"},
{EnemyType::GORAN, EP4, 0x52, 0x11, "GORAN", "Goran", nullptr}, {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, 0x53, 0x13, "GORAN_DETONATOR", "Goran Detonator", nullptr}, {EnemyType::GORAN_DETONATOR, EP4, 0x66, 0x53, {0x13}, {0x13, 0x16}, {0x13}, {0x13}, "GORAN_DETONATOR", "Goran Detonator", nullptr},
{EnemyType::GRASS_ASSASSIN, EP1 | EP2, 0x0C, 0x4E, "GRASS_ASSASSIN", "Grass Assassin", "Crimson Assassin"}, {EnemyType::GORAN, EP4, 0x65, 0x52, {0x11}, {0x11, 0x14}, {0x11}, {0x11}, "GORAN", "Goran", nullptr},
{EnemyType::GUIL_SHARK, EP1, 0x12, 0x51, "GUIL_SHARK", "Guil Shark", "Melqueek"}, {EnemyType::GRASS_ASSASSIN, EP1 | EP2, 0x0C, 0x0C, {0x4E}, {0x51, 0x52, 0x53}, {0x4D}, {0x4D}, "GRASS_ASSASSIN", "Grass Assassin", "Crimson Assassin"},
{EnemyType::HALLO_RAPPY, EP2, 0x50, 0x19, "HALLO_RAPPY", "Hallo Rappy", nullptr}, {EnemyType::GUIL_SHARK, EP1, 0x12, 0x12, {0x51}, {0x56}, {0x50}, {0x50}, "GUIL_SHARK", "Guil Shark", "Melqueek"},
{EnemyType::HIDOOM, EP1 | EP2, 0x17, 0x32, "HIDOOM", "Hidoom", nullptr}, {EnemyType::HALLO_RAPPY, EP2, 0x50, 0x50, {0x19}, {0x19}, {0x19}, {0x19}, "HALLO_RAPPY", "Hallo Rappy", nullptr},
{EnemyType::HILDEBEAR, EP1 | EP2, 0x01, 0x49, "HILDEBEAR", "Hildebear", "Hildelt"}, {EnemyType::HIDOOM, EP1 | EP2, 0x17, 0x17, {0x32}, {0x32}, {0x32}, {0x32}, "HIDOOM", "Hidoom", nullptr},
{EnemyType::HILDEBLUE, EP1 | EP2 | RARE, 0x02, 0x4A, "HILDEBLUE", "Hildeblue", "Hildetorr"}, {EnemyType::HILDEBEAR, EP1 | EP2, 0x01, 0x01, {0x49}, {0x48, 0x49, 0x4A}, {0x48}, {0x48}, "HILDEBEAR", "Hildebear", "Hildelt"},
{EnemyType::ILL_GILL, EP2, 0x52, 0x26, "ILL_GILL", "Ill Gill", nullptr}, {EnemyType::HILDEBLUE, EP1 | EP2 | RARE, 0x02, 0x02, {0x4A}, {0x4B, 0x4C, 0x4D}, {0x49}, {0x49}, "HILDEBLUE", "Hildeblue", "Hildetorr"},
{EnemyType::KONDRIEU, EP4 | RARE, 0x5B, 0x2A, "KONDRIEU", "Kondrieu", nullptr}, {EnemyType::ILL_GILL, EP2, 0x52, 0x52, {0x26}, {0x26, 0x27, 0x28, 0x29}, {0x26}, {0x26}, "ILL_GILL", "Ill Gill", nullptr},
{EnemyType::LA_DIMENIAN, EP1 | EP2, 0x2A, 0x54, "LA_DIMENIAN", "La Dimenian", "Merlan"}, {EnemyType::KONDRIEU_SPINNER, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x29, 0x2B}, {0x29, 0x2B}, {0x29, 0x2B}, {0x29, 0x2B}, "KONDRIEU_SPINNER", "Kondrieu (spinner)", nullptr},
{EnemyType::LOVE_RAPPY, EP2, 0x33, 0x19, "LOVE_RAPPY", "Love Rappy", nullptr}, {EnemyType::KONDRIEU, EP4 | RARE | BOSS, 0x6C, 0x5B, {0x28, 0x2A}, {0x28, 0x2A}, {0x28, 0x2A}, {0x28, 0x2A}, "KONDRIEU", "Kondrieu", nullptr},
{EnemyType::MERICARAND, EP2, 0x38, 0x3A, "MERICARAND", "Mericarand", nullptr}, {EnemyType::LA_DIMENIAN, EP1 | EP2, 0x2A, 0x2A, {0x54}, {0x5B}, {0x53}, {0x53}, "LA_DIMENIAN", "La Dimenian", "Merlan"},
{EnemyType::MERICAROL, EP2, 0x38, 0x3A, "MERICAROL", "Mericarol", nullptr}, {EnemyType::LOVE_RAPPY, EP2, 0x33, 0x33, {0x19}, {0x19}, {0x19}, {0x19}, "LOVE_RAPPY", "Love Rappy", nullptr},
{EnemyType::MERICUS, EP2 | RARE, 0x3A, 0x46, "MERICUS", "Mericus", nullptr}, {EnemyType::MERICARAND, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, {0x3A}, "MERICARAND", "Mericarand", nullptr},
{EnemyType::MERIKLE, EP2 | RARE, 0x39, 0x45, "MERIKLE", "Merikle", nullptr}, {EnemyType::MERICAROL, EP2, 0x38, 0x38, {0x3A}, {0x3A}, {0x3A}, {0x3A}, "MERICAROL", "Mericarol", nullptr},
{EnemyType::MERILLIA, EP2, 0x34, 0x4B, "MERILLIA", "Merillia", nullptr}, {EnemyType::MERICUS, EP2 | RARE, 0x3A, 0x3A, {0x46}, {0x46}, {0x46}, {0x46}, "MERICUS", "Mericus", nullptr},
{EnemyType::MERILTAS, EP2, 0x35, 0x4C, "MERILTAS", "Meriltas", nullptr}, {EnemyType::MERIKLE, EP2 | RARE, 0x39, 0x39, {0x45}, {0x45}, {0x45}, {0x45}, "MERIKLE", "Merikle", nullptr},
{EnemyType::MERISSA_A, EP4, 0x46, 0x19, "MERISSA_A", "Merissa A", nullptr}, {EnemyType::MERILLIA, EP2, 0x34, 0x34, {0x4B}, {0x4E}, {0x4A}, {0x4A}, "MERILLIA", "Merillia", nullptr},
{EnemyType::MERISSA_AA, EP4 | RARE, 0x47, 0x1A, "MERISSA_AA", "Merissa AA", nullptr}, {EnemyType::MERILTAS, EP2, 0x35, 0x35, {0x4C}, {0x4F}, {0x4B}, {0x4B}, "MERILTAS", "Meriltas", nullptr},
{EnemyType::MIGIUM, EP1 | EP2, 0x16, 0x33, "MIGIUM", "Migium", nullptr}, {EnemyType::MERISSA_A, EP4, 0x5B, 0x46, {0x19}, {0x19}, {0x19}, {0x19}, "MERISSA_A", "Merissa A", nullptr},
{EnemyType::MONEST, EP1 | EP2, 0x04, 0x01, "MONEST", "Monest", "Mothvist"}, {EnemyType::MERISSA_AA, EP4 | RARE, 0x5C, 0x47, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "MERISSA_AA", "Merissa AA", nullptr},
{EnemyType::MORFOS, EP2, 0x42, 0x40, "MORFOS", "Morfos", nullptr}, {EnemyType::MIGIUM, EP1 | EP2, 0x16, 0x16, {0x33}, {0x33}, {0x33}, {0x33}, "MIGIUM", "Migium", nullptr},
{EnemyType::MOTHMANT, EP1 | EP2, 0x03, 0x00, "MOTHMANT", "Mothmant", "Mothvert"}, {EnemyType::MONEST, EP1 | EP2, 0x04, 0x04, {0x01}, {0x01}, {0x01}, {0x01}, "MONEST", "Monest", "Mothvist"},
{EnemyType::NANO_DRAGON, EP1, 0x0F, 0x1A, "NANO_DRAGON", "Nano Dragon", nullptr}, {EnemyType::MORFOS, EP2, 0x42, 0x42, {0x40}, {0x40, 0x50}, {0x40}, {0x40}, "MORFOS", "Morfos", nullptr},
{EnemyType::NAR_LILY, EP1 | EP2 | RARE, 0x0E, 0x05, "NAR_LILY", "Nar Lily", "Mil Lily"}, {EnemyType::MOTHMANT, EP1 | EP2, 0x03, 0x03, {0x00}, {0x00}, {0x00}, {0x00}, "MOTHMANT", "Mothmant", "Mothvert"},
{EnemyType::OLGA_FLOW_1, EP2, 0xFF, 0x2B, "OLGA_FLOW_1", "Olga Flow (phase 1)", nullptr}, {EnemyType::NANO_DRAGON, EP1, 0x0F, 0x0F, {0x1A}, {0x1A}, {0x1A}, {0x1A}, "NANO_DRAGON", "Nano Dragon", nullptr},
{EnemyType::OLGA_FLOW_2, EP2, 0x4E, 0x2C, "OLGA_FLOW_2", "Olga Flow (phase 2)", nullptr}, {EnemyType::NAR_LILY, EP1 | EP2 | RARE, 0x0E, 0x0E, {0x05}, {0x05}, {0x05}, {0x05}, "NAR_LILY", "Nar Lily", "Mil Lily"},
{EnemyType::PAL_SHARK, EP1, 0x11, 0x50, "PAL_SHARK", "Pal Shark", "Govulmer"}, {EnemyType::OLGA_FLOW_1, EP2 | BOSS, NONE, NONE, {0x2B}, {0x2B}, {0x2B}, {0x2B, 0x2D, 0x2F}, "OLGA_FLOW_1", "Olga Flow (phase 1)", nullptr},
{EnemyType::PAN_ARMS, EP1 | EP2, 0x15, 0x31, "PAN_ARMS", "Pan Arms", 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::PAZUZU_CRATER, EP4 | RARE, 0x4B, 0x08, "PAZUZU_CRATER", "Pazuzu (crater)", nullptr}, {EnemyType::PAL_SHARK, EP1, 0x11, 0x11, {0x50}, {0x55}, {0x4F}, {0x4F}, "PAL_SHARK", "Pal Shark", "Govulmer"},
{EnemyType::PAZUZU_DESERT, EP4 | RARE, 0x4C, 0x1C, "PAZUZU_DESERT", "Pazuzu (desert)", nullptr}, {EnemyType::PAN_ARMS, EP1 | EP2, 0x15, 0x15, {0x31}, {0x31}, {0x31}, {0x31}, "PAN_ARMS", "Pan Arms", nullptr},
{EnemyType::PIG_RAY, EP2, 0xFF, 0xFF, "PIG_RAY", "Pig Ray", nullptr}, {EnemyType::PAZUZU_CRATER, EP4 | RARE, 0x5F, 0x4B, {0x08}, {0x08}, {0x08}, {0x08}, "PAZUZU_CRATER", "Pazuzu (crater)", nullptr},
{EnemyType::POFUILLY_SLIME, EP1, 0x13, 0x30, "POFUILLY_SLIME", "Pofuilly Slime", nullptr}, {EnemyType::PAZUZU_DESERT, EP4 | RARE, 0x5F, 0x4C, {0x1C}, {0x1C}, {0x1C}, {0x1C}, "PAZUZU_DESERT", "Pazuzu (desert)", nullptr},
{EnemyType::POUILLY_SLIME, EP1 | RARE, 0x14, 0x2F, "POUILLY_SLIME", "Pouilly Slime", nullptr}, {EnemyType::PIG_RAY, EP2, 0x4A, NONE, {0x08}, {0x08}, {0x08}, {0x08}, "PIG_RAY", "Pig Ray", nullptr},
{EnemyType::POISON_LILY, EP1 | EP2, 0x0D, 0x04, "POISON_LILY", "Poison Lily", "Ob Lily"}, {EnemyType::POFUILLY_SLIME, EP1, 0x13, 0x13, {0x30}, {0x30}, {0x30}, {0x30}, "POFUILLY_SLIME", "Pofuilly Slime", nullptr},
{EnemyType::PYRO_GORAN, EP4, 0x54, 0x12, "PYRO_GORAN", "Pyro Goran", nullptr}, {EnemyType::POISON_LILY, EP1 | EP2, 0x0D, 0x0D, {0x04}, {0x04}, {0x04}, {0x04}, "POISON_LILY", "Poison Lily", "Ob Lily"},
{EnemyType::RAG_RAPPY, EP1 | EP2, 0x05, 0x18, "RAG_RAPPY", "Rag Rappy", "El Rappy"}, {EnemyType::POUILLY_SLIME, EP1 | RARE, 0x14, 0x14, {0x34}, {0x34}, {0x34}, {0x34}, "POUILLY_SLIME", "Pouilly Slime", nullptr},
{EnemyType::RECOBOX, EP2, 0x43, 0x41, "RECOBOX", "Recobox", nullptr}, {EnemyType::PYRO_GORAN, EP4, 0x67, 0x54, {0x12}, {0x12, 0x15}, {0x12}, {0x12}, "PYRO_GORAN", "Pyro Goran", nullptr},
{EnemyType::RECON, EP2, 0x44, 0x42, "RECON", "Recon", nullptr}, {EnemyType::RAG_RAPPY, EP1 | EP2, 0x05, 0x05, {0x18}, {0x18}, {0x18}, {0x18}, "RAG_RAPPY", "Rag Rappy", "El Rappy"},
{EnemyType::SAINT_MILION, EP4, 0x59, 0x22, "SAINT_MILION", "Saint-Milion", nullptr}, {EnemyType::RECOBOX, EP2, 0x43, 0x43, {0x41}, {0x41}, {0x41}, {0x41}, "RECOBOX", "Recobox", nullptr},
{EnemyType::SAINT_RAPPY, EP2, 0x4F, 0x19, "SAINT_RAPPY", "Saint Rappy", nullptr}, {EnemyType::RECON, EP2, 0x44, 0x44, {0x42}, {0x42}, {0x42}, {0x42}, "RECON", "Recon", nullptr},
{EnemyType::SAND_RAPPY_CRATER, EP4, 0x55, 0x05, "SAND_RAPPY_CRATER", "Sand Rappy (crater)", 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::SAND_RAPPY_DESERT, EP4, 0x56, 0x17, "SAND_RAPPY_DESERT", "Sand Rappy (desert)", nullptr}, {EnemyType::SAINT_MILION, EP4 | BOSS, 0x6A, 0x59, {0x20, 0x22}, {0x20, 0x22}, {0x20, 0x22}, {0x20, 0x22}, "SAINT_MILION", "Saint-Milion", nullptr},
{EnemyType::SATELLITE_LIZARD_CRATER, EP4, 0x44, 0x0D, "SATELLITE_LIZARD_CRATER", "Satellite Lizard (crater)", nullptr}, {EnemyType::SAINT_RAPPY, EP2, 0x4F, 0x4F, {0x19}, {0x19}, {0x19}, {0x19}, "SAINT_RAPPY", "Saint Rappy", nullptr},
{EnemyType::SATELLITE_LIZARD_DESERT, EP4, 0x45, 0x1D, "SATELLITE_LIZARD_DESERT", "Satellite Lizard (desert)", nullptr}, {EnemyType::SAND_RAPPY_CRATER, EP4, 0x68, 0x55, {0x05}, {0x05}, {0x05}, {0x05}, "SAND_RAPPY_CRATER", "Sand Rappy (crater)", nullptr},
{EnemyType::SAVAGE_WOLF, EP1 | EP2, 0x07, 0x02, "SAVAGE_WOLF", "Savage Wolf", "Gulgus"}, {EnemyType::SAND_RAPPY_DESERT, EP4, 0x68, 0x56, {0x17}, {0x17}, {0x17}, {0x17}, "SAND_RAPPY_DESERT", "Sand Rappy (desert)", nullptr},
{EnemyType::SHAMBERTIN, EP4, 0x5A, 0x26, "SHAMBERTIN", "Shambertin", nullptr}, {EnemyType::SATELLITE_LIZARD_CRATER, EP4, 0x5A, 0x44, {0x0D}, {0x0D}, {0x0D}, {0x0D}, "SATELLITE_LIZARD_CRATER", "Satellite Lizard (crater)", nullptr},
{EnemyType::SINOW_BEAT, EP1, 0x1A, 0x06, "SINOW_BEAT", "Sinow Beat", "Sinow Blue"}, {EnemyType::SATELLITE_LIZARD_DESERT, EP4, 0x5A, 0x45, {0x1D}, {0x1D}, {0x1D}, {0x1D}, "SATELLITE_LIZARD_DESERT", "Satellite Lizard (desert)", nullptr},
{EnemyType::SINOW_BERILL, EP2, 0x3E, 0x06, "SINOW_BERILL", "Sinow Berill", nullptr}, {EnemyType::SAVAGE_WOLF, EP1 | EP2, 0x07, 0x07, {0x02}, {0x02}, {0x02}, {0x02}, "SAVAGE_WOLF", "Savage Wolf", "Gulgus"},
{EnemyType::SINOW_GOLD, EP1, 0x1B, 0x13, "SINOW_GOLD", "Sinow Gold", "Sinow Red"}, {EnemyType::SHAMBERTIN_SPINNER, EP4 | BOSS, 0x6B, 0x5A, {0x25, 0x27}, {0x25, 0x27}, {0x25, 0x27}, {0x25, 0x27}, "SHAMBERTIN_SPINNER", "Shambertin (spinner)", nullptr},
{EnemyType::SINOW_SPIGELL, EP2, 0x3F, 0x13, "SINOW_SPIGELL", "Sinow Spigell", nullptr}, {EnemyType::SHAMBERTIN, EP4 | BOSS, 0x6B, 0x5A, {0x24, 0x26}, {0x24, 0x26}, {0x24, 0x26}, {0x24, 0x26}, "SHAMBERTIN", "Shambertin", nullptr},
{EnemyType::SINOW_ZELE, EP2, 0x46, 0x44, "SINOW_ZELE", "Sinow Zele", nullptr}, {EnemyType::SINOW_BEAT, EP1, 0x1A, 0x1A, {0x06}, {0x06}, {0x06}, {0x06}, "SINOW_BEAT", "Sinow Beat", "Sinow Blue"},
{EnemyType::SINOW_ZOA, EP2, 0x45, 0x43, "SINOW_ZOA", "Sinow Zoa", nullptr}, {EnemyType::SINOW_BERILL, EP2, 0x3E, 0x3E, {0x06}, {0x06}, {0x06}, {0x06}, "SINOW_BERILL", "Sinow Berill", nullptr},
{EnemyType::SO_DIMENIAN, EP1 | EP2, 0x2B, 0x55, "SO_DIMENIAN", "So Dimenian", "Del-D"}, {EnemyType::SINOW_GOLD, EP1, 0x1B, 0x1B, {0x13}, {0x47}, {0x13}, {0x10}, "SINOW_GOLD", "Sinow Gold", "Sinow Red"},
{EnemyType::UL_GIBBON, EP2, 0x3B, 0x3B, "UL_GIBBON", "Ul Gibbon", nullptr}, {EnemyType::SINOW_SPIGELL, EP2, 0x3F, 0x3F, {0x13}, {0x47}, {0x13}, {0x10}, "SINOW_SPIGELL", "Sinow Spigell", nullptr},
{EnemyType::VOL_OPT_1, EP1, 0xFF, 0xFF, "VOL_OPT_1", "Vol Opt (phase 1)", "Vol Opt ver.2 (phase 1)"}, {EnemyType::SINOW_ZELE, EP2, 0x46, 0x46, {0x44}, {0x44}, {0x44}, {0x44}, "SINOW_ZELE", "Sinow Zele", nullptr},
{EnemyType::VOL_OPT_2, EP1, 0x2E, 0x25, "VOL_OPT_2", "Vol Opt (phase 2)", "Vol Opt ver.2 (phase 2)"}, {EnemyType::SINOW_ZOA, EP2, 0x45, 0x45, {0x43}, {0x43}, {0x43}, {0x43}, "SINOW_ZOA", "Sinow Zoa", nullptr},
{EnemyType::VOL_OPT_AMP, EP1, 0xFF, 0xFF, "VOL_OPT_AMP", "Vol Opt (amp)", "Vol Opt ver.2 (amp)"}, {EnemyType::SO_DIMENIAN, EP1 | EP2, 0x2B, 0x2B, {0x55}, {0x5C}, {0x54}, {0x54}, "SO_DIMENIAN", "So Dimenian", "Del-D"},
{EnemyType::VOL_OPT_CORE, EP1, 0xFF, 0xFF, "VOL_OPT_CORE", "Vol Opt (core)", "Vol Opt ver.2 (core)"}, {EnemyType::UL_GIBBON, EP2, 0x3B, 0x3B, {0x3B}, {0x3B}, {0x3B}, {0x3B}, "UL_GIBBON", "Ul Gibbon", nullptr},
{EnemyType::VOL_OPT_MONITOR, EP1, 0xFF, 0xFF, "VOL_OPT_MONITOR", "Vol Opt (monitor)", "Vol Opt ver.2 (monitor)"}, {EnemyType::UL_RAY, EP2, 0x4B, NONE, {0x09}, {0x09}, {0x09}, {0x09}, "UL_RAY", "Ul Ray", nullptr},
{EnemyType::VOL_OPT_PILLAR, EP1, 0xFF, 0xFF, "VOL_OPT_PILLAR", "Vol Opt (pillar)", "Vol Opt ver.2 (pillar)"}, {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::YOWIE_CRATER, EP4, 0x42, 0x0E, "YOWIE_CRATER", "Yowie (crater)", nullptr}, {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::YOWIE_DESERT, EP4, 0x43, 0x1E, "YOWIE_DESERT", "Yowie (desert)", nullptr}, {EnemyType::VOL_OPT_AMP, EP1 | BOSS, NONE, NONE, {0x24}, {0x24}, {0x24}, {}, "VOL_OPT_AMP", "Vol Opt (amp)", "Vol Opt ver.2 (amp)"},
{EnemyType::ZE_BOOTA, EP4, 0x4E, 0x01, "ZE_BOOTA", "Ze Boota", nullptr}, {EnemyType::VOL_OPT_CORE, EP1 | BOSS, NONE, NONE, {0x26}, {0x26}, {0x26}, {}, "VOL_OPT_CORE", "Vol Opt (core)", "Vol Opt ver.2 (core)"},
{EnemyType::ZOL_GIBBON, EP2, 0x3C, 0x3C, "ZOL_GIBBON", "Zol Gibbon", nullptr}, {EnemyType::VOL_OPT_MONITOR, EP1 | BOSS, NONE, NONE, {0x23}, {0x23}, {0x23}, {}, "VOL_OPT_MONITOR", "Vol Opt (monitor)", "Vol Opt ver.2 (monitor)"},
{EnemyType::ZU_CRATER, EP4, 0x49, 0x07, "ZU_CRATER", "Zu (crater)", nullptr}, {EnemyType::VOL_OPT_PILLAR, EP1 | BOSS, NONE, NONE, {0x22}, {0x22}, {0x22}, {}, "VOL_OPT_PILLAR", "Vol Opt (pillar)", "Vol Opt ver.2 (pillar)"},
{EnemyType::ZU_DESERT, EP4, 0x4A, 0x1B, "ZU_DESERT", "Zu (desert)", nullptr}, {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 // clang-format on
}; };
@@ -159,67 +165,146 @@ const char* phosg::name_for_enum<EnemyType>(EnemyType type) {
template <> template <>
EnemyType phosg::enum_for_name<EnemyType>(const char* name) { 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()) { if (index.empty()) {
for (const auto& def : type_defs) { for (const auto& def : type_defs) {
if (!index.emplace(def.enum_name, def.type).second) { if (!index.emplace(def.enum_name, def.type).second) {
throw logic_error(phosg::string_printf("duplicate enemy enum name: %s", def.enum_name)); throw std::logic_error(std::format("duplicate enemy enum name: {}", def.enum_name));
} }
} }
} }
return index.at(name); return index.at(name);
} }
const vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index) { const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index) {
const auto& generate_table = +[](Episode episode) -> vector<vector<EnemyType>> { static std::array<std::vector<std::vector<EnemyType>>, 5> data;
vector<vector<EnemyType>> ret; auto& ret = data.at(static_cast<size_t>(episode));
if (ret.empty()) {
for (const auto& def : type_defs) { 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()) { if (def.rt_index >= ret.size()) {
ret.resize(def.rt_index + 1); ret.resize(def.rt_index + 1);
} }
ret[def.rt_index].emplace_back(def.type); 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 { try {
return ret.at(rt_index); return ret.at(rt_index);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
static const vector<EnemyType> empty_vec; static const std::vector<EnemyType> empty_vec;
return empty_vec; return empty_vec;
} }
} }
EnemyType EnemyTypeDefinition::rare_type(Episode episode, uint8_t event, uint8_t floor) const { 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) {
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);
}
}
}
}
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 get_bp_index_cache_entry(episode, bp_index).stats;
} catch (const std::out_of_range&) {
return empty_vec;
}
}
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) { switch (this->type) {
case EnemyType::HILDEBEAR: case EnemyType::HILDEBEAR:
return EnemyType::HILDEBLUE; return EnemyType::HILDEBLUE;
case EnemyType::RAG_RAPPY: case EnemyType::RAG_RAPPY:
switch (episode) { if (area < 0x12) {
case Episode::EP1: return EnemyType::AL_RAPPY;
return EnemyType::AL_RAPPY; } else if (area < 0x24) {
case Episode::EP2: switch (event) {
switch (event) { case 0x01: // rappy_type 1
case 0x01: // rappy_type 1 return EnemyType::SAINT_RAPPY;
return EnemyType::SAINT_RAPPY; case 0x04: // rappy_type 2
case 0x04: // rappy_type 2 return EnemyType::EGG_RAPPY;
return EnemyType::EGG_RAPPY; case 0x05: // rappy_type 3
case 0x05: // rappy_type 3 return EnemyType::HALLO_RAPPY;
return EnemyType::HALLO_RAPPY; default:
default: return EnemyType::LOVE_RAPPY;
return EnemyType::LOVE_RAPPY; }
} } else if (area <= 0x28) {
case Episode::EP4: return EnemyType::DEL_RAPPY_CRATER;
return (floor > 0x05) ? EnemyType::DEL_RAPPY_DESERT : EnemyType::DEL_RAPPY_CRATER; } else {
default: return EnemyType::DEL_RAPPY_DESERT;
throw logic_error("invalid episode");
} }
case EnemyType::POISON_LILY: case EnemyType::POISON_LILY:
return EnemyType::NAR_LILY; return EnemyType::NAR_LILY;
+36 -10
View File
@@ -3,17 +3,25 @@
#include <inttypes.h> #include <inttypes.h>
#include <phosg/Tools.hh> #include <phosg/Tools.hh>
#include <set>
#include "StaticGameData.hh" #include "StaticGameData.hh"
#include "Types.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 { enum class EnemyType : uint8_t {
MIN_VALUE = 0,
UNKNOWN = 0, UNKNOWN = 0,
NONE, NONE,
NON_ENEMY_NPC, NON_ENEMY_NPC,
AL_RAPPY, AL_RAPPY,
ASTARK, ASTARK,
BA_BOOTA, BA_BOOTA,
BARBA_RAY_JOINT,
BARBA_RAY, BARBA_RAY,
BARBAROUS_WOLF, BARBAROUS_WOLF,
BEE_L, BEE_L,
@@ -22,8 +30,8 @@ enum class EnemyType : uint8_t {
BOOTA, BOOTA,
BULCLAW, BULCLAW,
BULK, BULK,
CANADINE,
CANADINE_GROUP, CANADINE_GROUP,
CANADINE,
CANANE, CANANE,
CHAOS_BRINGER, CHAOS_BRINGER,
CHAOS_SORCERER, CHAOS_SORCERER,
@@ -32,12 +40,12 @@ enum class EnemyType : uint8_t {
DARK_FALZ_1, DARK_FALZ_1,
DARK_FALZ_2, DARK_FALZ_2,
DARK_FALZ_3, DARK_FALZ_3,
DARK_GUNNER_CONTROL,
DARK_GUNNER, DARK_GUNNER,
DARVANT, DARVANT,
DARVANT_ULTIMATE,
DE_ROL_LE,
DE_ROL_LE_BODY, DE_ROL_LE_BODY,
DE_ROL_LE_MINE, DE_ROL_LE_MINE,
DE_ROL_LE,
DEATH_GUNNER, DEATH_GUNNER,
DEL_LILY, DEL_LILY,
DEL_RAPPY_CRATER, DEL_RAPPY_CRATER,
@@ -48,8 +56,8 @@ enum class EnemyType : uint8_t {
DIMENIAN, DIMENIAN,
DOLMDARL, DOLMDARL,
DOLMOLM, DOLMOLM,
DORPHON,
DORPHON_ECLAIR, DORPHON_ECLAIR,
DORPHON,
DRAGON, DRAGON,
DUBCHIC, DUBCHIC,
DUBWITCH, // Has no entry in battle params DUBWITCH, // Has no entry in battle params
@@ -68,8 +76,8 @@ enum class EnemyType : uint8_t {
GIRTABLULU, GIRTABLULU,
GOBOOMA, GOBOOMA,
GOL_DRAGON, GOL_DRAGON,
GORAN,
GORAN_DETONATOR, GORAN_DETONATOR,
GORAN,
GRASS_ASSASSIN, GRASS_ASSASSIN,
GUIL_SHARK, GUIL_SHARK,
HALLO_RAPPY, HALLO_RAPPY,
@@ -77,6 +85,7 @@ enum class EnemyType : uint8_t {
HILDEBEAR, HILDEBEAR,
HILDEBLUE, HILDEBLUE,
ILL_GILL, ILL_GILL,
KONDRIEU_SPINNER,
KONDRIEU, KONDRIEU,
LA_DIMENIAN, LA_DIMENIAN,
LOVE_RAPPY, LOVE_RAPPY,
@@ -102,12 +111,13 @@ enum class EnemyType : uint8_t {
PAZUZU_DESERT, PAZUZU_DESERT,
PIG_RAY, PIG_RAY,
POFUILLY_SLIME, POFUILLY_SLIME,
POUILLY_SLIME,
POISON_LILY, POISON_LILY,
POUILLY_SLIME,
PYRO_GORAN, PYRO_GORAN,
RAG_RAPPY, RAG_RAPPY,
RECOBOX, RECOBOX,
RECON, RECON,
SAINT_MILION_SPINNER,
SAINT_MILION, SAINT_MILION,
SAINT_RAPPY, SAINT_RAPPY,
SAND_RAPPY_CRATER, SAND_RAPPY_CRATER,
@@ -115,6 +125,7 @@ enum class EnemyType : uint8_t {
SATELLITE_LIZARD_CRATER, SATELLITE_LIZARD_CRATER,
SATELLITE_LIZARD_DESERT, SATELLITE_LIZARD_DESERT,
SAVAGE_WOLF, SAVAGE_WOLF,
SHAMBERTIN_SPINNER,
SHAMBERTIN, SHAMBERTIN,
SINOW_BEAT, SINOW_BEAT,
SINOW_BERILL, SINOW_BERILL,
@@ -124,6 +135,7 @@ enum class EnemyType : uint8_t {
SINOW_ZOA, SINOW_ZOA,
SO_DIMENIAN, SO_DIMENIAN,
UL_GIBBON, UL_GIBBON,
UL_RAY,
VOL_OPT_1, VOL_OPT_1,
VOL_OPT_2, VOL_OPT_2,
VOL_OPT_AMP, VOL_OPT_AMP,
@@ -136,7 +148,7 @@ enum class EnemyType : uint8_t {
ZOL_GIBBON, ZOL_GIBBON,
ZU_CRATER, ZU_CRATER,
ZU_DESERT, ZU_DESERT,
MAX_ENEMY_TYPE, MAX_VALUE,
}; };
struct EnemyTypeDefinition { struct EnemyTypeDefinition {
@@ -145,11 +157,18 @@ struct EnemyTypeDefinition {
VALID_EP2 = 0x02, VALID_EP2 = 0x02,
VALID_EP4 = 0x04, VALID_EP4 = 0x04,
IS_RARE = 0x08, IS_RARE = 0x08,
IS_BOSS = 0x10,
}; };
EnemyType type; EnemyType type;
uint8_t flags; uint8_t flags;
uint8_t rt_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 bp_index; // 0xFF if not valid (e.g. not an enemy) 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* enum_name;
const char* in_game_name; const char* in_game_name;
const char* ultimate_name; // May be null if same as in_game_name const char* ultimate_name; // May be null if same as in_game_name
@@ -169,7 +188,10 @@ struct EnemyTypeDefinition {
inline bool is_rare() const { inline bool is_rare() const {
return (this->flags & Flag::IS_RARE); 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); const EnemyTypeDefinition& type_definition_for_enemy(EnemyType type);
@@ -180,3 +202,7 @@ template <>
EnemyType phosg::enum_for_name<EnemyType>(const char* name); 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_rare_table_index(Episode episode, uint8_t rt_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" #include "Server.hh"
using namespace std;
namespace Episode3 { 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 // 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 // code. This is relevant for consistency of results when choosing a random card
// (for God Whim). // (for God Whim).
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_TRIAL = { static const std::vector<uint16_t> ALL_ASSIST_CARD_IDS_TRIAL = {
0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102,
0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, 0x010F, 0x0121,
0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, 0x010F, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D, 0x013E, 0x013F, 0x0140,
0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F, 0x0240,
0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D, 0x013E, 0x0241, 0x0242};
0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148, static const std::vector<uint16_t> ALL_ASSIST_CARD_IDS_FINAL = {
0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F, 0x0240, 0x0241, 0x0242}; 0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF,
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_FINAL = { 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D,
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F,
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103, 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D,
0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D,
0x010D, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x014E, 0x023F, 0x0240, 0x0241, 0x0242};
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; 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) { 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}, {0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS}, {0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
{0x001A, /* 0x004B */ AssistEffect::CHARITY_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}, {0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1}, {0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
{0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER}, {0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER},
@@ -114,18 +107,18 @@ AssistEffect assist_effect_number_for_card_id(uint16_t card_id, bool is_nte) {
}); });
try { try {
return card_id_to_effect.at(card_id); return card_id_to_effect.at(card_id);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
} }
if (!is_nte) { if (!is_nte) {
try { try {
return card_id_to_effect_final_only.at(card_id); return card_id_to_effect_final_only.at(card_id);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
} }
} }
return AssistEffect::NONE; return AssistEffect::NONE;
} }
AssistServer::AssistServer(shared_ptr<Server> server) AssistServer::AssistServer(std::shared_ptr<Server> server)
: w_server(server), : w_server(server),
assist_effects(AssistEffect::NONE), assist_effects(AssistEffect::NONE),
num_assist_cards_set(0), num_assist_cards_set(0),
@@ -133,18 +126,18 @@ AssistServer::AssistServer(shared_ptr<Server> server)
active_assist_effects(AssistEffect::NONE), active_assist_effects(AssistEffect::NONE),
num_active_assists(0) {} num_active_assists(0) {}
shared_ptr<Server> AssistServer::server() { std::shared_ptr<Server> AssistServer::server() {
auto s = this->w_server.lock(); auto s = this->w_server.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; return s;
} }
shared_ptr<const Server> AssistServer::server() const { std::shared_ptr<const Server> AssistServer::server() const {
auto s = this->w_server.lock(); auto s = this->w_server.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; 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); 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 { uint16_t card_id) const {
return this->server()->definition_for_card_id(card_id); 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) { if (ce->def.target_mode == TargetMode::TEAM) {
auto this_deck_entry = this->deck_entries[client_id]; auto this_deck_entry = this->deck_entries[client_id];
auto other_deck_entry = this->deck_entries[z]; auto other_deck_entry = this->deck_entries[z];
if (this_deck_entry && other_deck_entry && if (this_deck_entry && other_deck_entry && (this_deck_entry->team_id == other_deck_entry->team_id)) {
(this_deck_entry->team_id == other_deck_entry->team_id)) {
affected = true; affected = true;
} }
} else if ((ce->def.target_mode == TargetMode::SELF) && (z == client_id)) { } else if (((ce->def.target_mode == TargetMode::SELF) && (z == client_id)) ||
affected = true; (ce->def.target_mode == TargetMode::EVERYONE)) {
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
affected = true; affected = true;
} }
if (affected) { 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)) { (this->deck_entries[client_id]->team_id == this->deck_entries[z]->team_id)) {
return true; return true;
} }
} else if ((ce->def.target_mode == TargetMode::SELF) && (client_id == z)) { } else if (((ce->def.target_mode == TargetMode::SELF) && (client_id == z)) ||
return true; (ce->def.target_mode == TargetMode::EVERYONE)) {
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
return true; 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 { AssistEffect AssistServer::get_active_assist_by_index(size_t index) const {
if (index < this->num_active_assists) { return (index < this->num_active_assists) ? this->active_assist_effects[index] : AssistEffect::NONE;
return this->active_assist_effects[index];
}
return AssistEffect::NONE;
} }
void AssistServer::populate_effects() { void AssistServer::populate_effects() {
+71 -111
View File
@@ -5,14 +5,11 @@
#include "../CommandFormats.hh" #include "../CommandFormats.hh"
#include "../SendCommands.hh" #include "../SendCommands.hh"
using namespace std;
namespace Episode3 { namespace Episode3 {
void BattleRecord::PlayerEntry::print(FILE* stream) const { void BattleRecord::PlayerEntry::print(FILE* stream) const {
// TODO: Format this nicely somehow. Maybe factor out the functions in // TODO: Format this nicely somehow. Maybe factor out the functions in QuestScript that format some of these structs
// QuestScript that format some of these structures phosg::print_data(stream, this, sizeof(*this), 0, phosg::FormatDataFlags::PRINT_ASCII | phosg::FormatDataFlags::OFFSET_16_BITS);
phosg::print_data(stream, this, sizeof(*this), 0, nullptr, phosg::PrintDataFlags::PRINT_ASCII | phosg::PrintDataFlags::DISABLE_COLOR | phosg::PrintDataFlags::OFFSET_16_BITS);
} }
BattleRecord::Event::Event(phosg::StringReader& r) { BattleRecord::Event::Event(phosg::StringReader& r) {
@@ -42,7 +39,7 @@ BattleRecord::Event::Event(phosg::StringReader& r) {
this->data = r.read(r.get_u16l()); this->data = r.read(r.get_u16l());
break; break;
default: 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) { switch (this->type) {
case Event::Type::PLAYER_JOIN: case Event::Type::PLAYER_JOIN:
if (this->players.size() != 1) { 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]); w.put(this->players[0]);
break; break;
@@ -76,25 +73,24 @@ void BattleRecord::Event::serialize(phosg::StringWriter& w) const {
w.write(this->data); w.write(this->data);
break; break;
default: default:
throw logic_error("unknown event type"); throw std::logic_error("unknown event type");
} }
} }
void BattleRecord::Event::print(FILE* stream) const { void BattleRecord::Event::print(FILE* stream) const {
string time_str = phosg::format_time(this->timestamp); phosg::fwrite_fmt(stream, "Event @{:016X} ({}) ", this->timestamp, phosg::format_time(this->timestamp));
fprintf(stream, "Event @%016" PRIX64 " (%s) ", this->timestamp, time_str.c_str());
switch (this->type) { switch (this->type) {
case Type::PLAYER_JOIN: case Type::PLAYER_JOIN:
fprintf(stream, "PLAYER_JOIN %02" PRIX32 "\n", this->players[0].lobby_data.client_id.load()); phosg::fwrite_fmt(stream, "PLAYER_JOIN {:02X}\n", this->players[0].lobby_data.client_id);
this->players[0].print(stream); this->players[0].print(stream);
break; break;
case Type::PLAYER_LEAVE: case Type::PLAYER_LEAVE:
fprintf(stream, "PLAYER_LEAVE %02hhu\n", this->leaving_client_id); phosg::fwrite_fmt(stream, "PLAYER_LEAVE {:02}\n", this->leaving_client_id);
break; break;
case Type::SET_INITIAL_PLAYERS: case Type::SET_INITIAL_PLAYERS:
fprintf(stream, "SET_INITIAL_PLAYERS"); phosg::fwrite_fmt(stream, "SET_INITIAL_PLAYERS");
for (const auto& player : this->players) { for (const auto& player : this->players) {
fprintf(stream, " %02" PRIX32, player.lobby_data.client_id.load()); phosg::fwrite_fmt(stream, " {:02X}", player.lobby_data.client_id);
} }
fputc('\n', stream); fputc('\n', stream);
for (const auto& player : this->players) { for (const auto& player : this->players) {
@@ -102,27 +98,27 @@ void BattleRecord::Event::print(FILE* stream) const {
} }
break; break;
case Type::BATTLE_COMMAND: case Type::BATTLE_COMMAND:
fprintf(stream, "BATTLE_COMMAND\n"); 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; break;
case Type::GAME_COMMAND: case Type::GAME_COMMAND:
fprintf(stream, "GAME_COMMAND\n"); 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; break;
case Type::EP3_GAME_COMMAND: case Type::EP3_GAME_COMMAND:
fprintf(stream, "EP3_GAME_COMMAND\n"); 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; break;
case Type::CHAT_MESSAGE: case Type::CHAT_MESSAGE:
fprintf(stream, "CHAT_MESSAGE %08" PRIX32 "\n", this->guild_card_number); 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; break;
case Type::SERVER_DATA_COMMAND: case Type::SERVER_DATA_COMMAND:
fprintf(stream, "SERVER_DATA_COMMAND\n"); 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; break;
default: 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_start_timestamp(0),
battle_end_timestamp(0) {} battle_end_timestamp(0) {}
BattleRecord::BattleRecord(const string& data) BattleRecord::BattleRecord(const std::string& data)
: is_writable(false), : is_writable(false), behavior_flags(0), battle_start_timestamp(0), battle_end_timestamp(0) {
behavior_flags(0),
battle_start_timestamp(0),
battle_end_timestamp(0) {
phosg::StringReader r(data); phosg::StringReader r(data);
uint64_t signature = r.get_u64l(); uint64_t signature = r.get_u64l();
@@ -146,7 +139,7 @@ BattleRecord::BattleRecord(const string& data)
} else if (signature == this->SIGNATURE_V2) { } else if (signature == this->SIGNATURE_V2) {
has_random_stream = true; has_random_stream = true;
} else { } else {
throw runtime_error("incorrect battle record signature"); throw std::runtime_error("incorrect battle record signature");
} }
this->battle_start_timestamp = r.get_u64l(); 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; phosg::StringWriter w;
w.put_u64l(this->SIGNATURE_V2); w.put_u64l(this->SIGNATURE_V2);
w.put_u64l(this->battle_start_timestamp); w.put_u64l(this->battle_start_timestamp);
@@ -174,31 +167,16 @@ string BattleRecord::serialize() const {
return std::move(w.str()); 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( void BattleRecord::add_player(
const PlayerLobbyDataDCGC& lobby_data, const PlayerLobbyDataDCGC& lobby_data,
const PlayerInventory& inventory, const PlayerInventory& inventory,
const PlayerDispDataDCPCV3& disp, const PlayerDispDataV123& disp,
uint32_t level) { uint32_t level) {
if (!this->is_writable) { 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) { 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(); Event& ev = this->events.emplace_back();
ev.type = Event::Type::PLAYER_JOIN; ev.type = Event::Type::PLAYER_JOIN;
@@ -212,7 +190,7 @@ void BattleRecord::add_player(
void BattleRecord::delete_player(uint8_t client_id) { void BattleRecord::delete_player(uint8_t client_id) {
if (!this->is_writable) { 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(); Event& ev = this->events.emplace_back();
ev.type = Event::Type::PLAYER_LEAVE; 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) { void BattleRecord::add_command(Event::Type type, const void* data, size_t size) {
if (!this->is_writable) { 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(); Event& ev = this->events.emplace_back();
ev.type = type; 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); 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) { 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(); Event& ev = this->events.emplace_back();
ev.type = type; ev.type = type;
@@ -240,10 +218,9 @@ void BattleRecord::add_command(Event::Type type, string&& data) {
ev.data = std::move(data); ev.data = std::move(data);
} }
void BattleRecord::add_chat_message( void BattleRecord::add_chat_message(uint32_t guild_card_number, std::string&& data) {
uint32_t guild_card_number, string&& data) {
if (!this->is_writable) { 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(); Event& ev = this->events.emplace_back();
ev.type = Event::Type::CHAT_MESSAGE; 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); this->random_stream.append(reinterpret_cast<const char*>(data), size);
} }
vector<string> BattleRecord::get_all_server_data_commands() const { const std::string& BattleRecord::get_random_stream() const {
vector<string> ret;
for (const auto& event : this->events) {
if (event.type == Event::Type::SERVER_DATA_COMMAND) {
ret.emplace_back(event.data);
}
}
return ret;
}
const string& BattleRecord::get_random_stream() const {
return this->random_stream; return this->random_stream;
} }
@@ -285,7 +252,7 @@ bool BattleRecord::is_map_definition_event(const Event& ev) {
void BattleRecord::set_battle_start_timestamp() { void BattleRecord::set_battle_start_timestamp() {
if (this->battle_start_timestamp != 0) { 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(); this->battle_start_timestamp = phosg::now();
@@ -297,30 +264,30 @@ void BattleRecord::set_battle_start_timestamp() {
for (auto& ev : this->events) { for (auto& ev : this->events) {
if (ev.type == Event::Type::PLAYER_JOIN) { if (ev.type == Event::Type::PLAYER_JOIN) {
if (ev.players.size() != 1) { 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]; auto& player = ev.players[0];
if (player.lobby_data.client_id >= 4) { 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[player.lobby_data.client_id] = player;
players_present[player.lobby_data.client_id] = true; players_present[player.lobby_data.client_id] = true;
} else if (ev.type == Event::Type::PLAYER_LEAVE) { } else if (ev.type == Event::Type::PLAYER_LEAVE) {
if (ev.leaving_client_id >= 4) { 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; players_present[ev.leaving_client_id] = false;
} else if (ev.type == Event::Type::SET_INITIAL_PLAYERS) { } 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)) { } else if (this->is_map_definition_event(ev)) {
num_map_events++; num_map_events++;
} }
} }
deque<Event> new_events; std::deque<Event> new_events;
// Generate the initial players event // Generate the initial players event
Event initial_ev; Event initial_ev;
@@ -361,74 +328,68 @@ void BattleRecord::set_battle_end_timestamp() {
} }
void BattleRecord::print(FILE* stream) const { void BattleRecord::print(FILE* stream) const {
string start_str = phosg::format_time(this->battle_start_timestamp); phosg::fwrite_fmt(stream, "BattleRecord {} behavior_flags={:08X} start={:016X} ({}) end={:016X} ({}); {} events\n",
string end_str = phosg::format_time(this->battle_end_timestamp);
fprintf(stream, "BattleRecord %s behavior_flags=%08" PRIX32 " start=%016" PRIX64 " (%s) end=%016" PRIX64 " (%s); %zu events\n",
this->is_writable ? "writable" : "read-only", this->is_writable ? "writable" : "read-only",
this->behavior_flags, this->behavior_flags,
this->battle_start_timestamp, this->battle_start_timestamp,
start_str.c_str(), phosg::format_time(this->battle_start_timestamp),
this->battle_end_timestamp, this->battle_end_timestamp,
end_str.c_str(), this->events.size()); phosg::format_time(this->battle_end_timestamp),
this->events.size());
for (const auto& event : this->events) { for (const auto& event : this->events) {
event.print(stream); event.print(stream);
} }
} }
BattleRecordPlayer::BattleRecordPlayer( BattleRecordPlayer::BattleRecordPlayer(std::shared_ptr<asio::io_context> io_context, std::shared_ptr<const BattleRecord> rec)
shared_ptr<const BattleRecord> rec, : io_context(io_context),
shared_ptr<struct event_base> base) record(rec),
: record(rec),
event_it(this->record->events.begin()), event_it(this->record->events.begin()),
play_start_timestamp(0), play_start_timestamp(0),
base(base), next_command_timer(*this->io_context) {}
next_command_ev(event_new(this->base.get(), -1, EV_TIMEOUT, &BattleRecordPlayer::dispatch_schedule_events, this), event_free) {}
shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const { std::shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
return this->record; return this->record;
} }
void BattleRecordPlayer::set_lobby(shared_ptr<Lobby> l) { void BattleRecordPlayer::set_lobby(std::shared_ptr<Lobby> l) {
this->lobby = l; this->lobby = l;
} }
void BattleRecordPlayer::start() { void BattleRecordPlayer::start() {
if (this->play_start_timestamp == 0) { if (this->play_start_timestamp == 0) {
this->play_start_timestamp = phosg::now(); this->play_start_timestamp = phosg::now();
this->schedule_events(); asio::co_spawn(*this->io_context, this->play_task(), asio::detached);
} }
} }
void BattleRecordPlayer::dispatch_schedule_events(evutil_socket_t, short, void* ctx) { asio::awaitable<void> BattleRecordPlayer::play_task() {
reinterpret_cast<BattleRecordPlayer*>(ctx)->schedule_events();
}
void BattleRecordPlayer::schedule_events() {
// If the lobby is destroyed, we can't replay anything - just return without
// rescheduling
auto l = this->lobby.lock(); auto l = this->lobby.lock();
if (!l) {
return;
}
for (;;) { for (;;) {
uint64_t relative_ts = phosg::now() - this->play_start_timestamp + this->record->battle_start_timestamp; uint64_t relative_ts = phosg::now() - this->play_start_timestamp + this->record->battle_start_timestamp;
// If the lobby is destroyed, we can't replay anything
if (!l) {
co_return;
}
if (this->event_it == this->record->events.end()) { if (this->event_it == this->record->events.end()) {
if (relative_ts >= this->record->battle_end_timestamp) { if (relative_ts >= this->record->battle_end_timestamp) {
// If the record is complete and the end timestamp has been reached, // If the record is complete and the end timestamp has been reached,
// send exit commands to all players in the lobby, and don't reschedule // send exit commands to all players in the lobby, and don't reschedule
// the event (it will be deleted along with the Player when the lobby is // the event (it will be deleted along with the Player when the lobby
// destroyed, when the last client leaves) // is destroyed, when the last client leaves)
send_command(l, 0xED, 0x00); send_command(l, 0xED, 0x00);
break;
} else { } else {
// There are no more events to play, but the battle has not officially // There are no more events to play, but the battle has not actually
// ended yet - reschedule the event for the end time // ended yet; wait until the end time
auto tv = phosg::usecs_to_timeval(this->record->battle_end_timestamp - relative_ts); this->next_command_timer.expires_after(std::chrono::microseconds(this->record->battle_end_timestamp - relative_ts));
event_add(this->next_command_ev.get(), &tv); co_await this->next_command_timer.async_wait(asio::use_awaitable);
l = this->lobby.lock();
} }
break;
} else { } else {
if (this->event_it->timestamp <= relative_ts) { if (this->event_it->timestamp <= relative_ts) {
@@ -437,7 +398,7 @@ void BattleRecordPlayer::schedule_events() {
switch (ev.type) { switch (ev.type) {
case BattleRecord::Event::Type::PLAYER_JOIN: case BattleRecord::Event::Type::PLAYER_JOIN:
// Technically we can support this, but it should never happen // 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: case BattleRecord::Event::Type::PLAYER_LEAVE:
send_player_leave_notification(l, ev.leaving_client_id); send_player_leave_notification(l, ev.leaving_client_id);
break; break;
@@ -464,11 +425,10 @@ void BattleRecordPlayer::schedule_events() {
this->event_it++; this->event_it++;
} else { } else {
// The next event should not occur yet, so reschedule for the time when // The next event should not occur yet, so wait until its time
// it should occur this->next_command_timer.expires_after(std::chrono::microseconds(this->event_it->timestamp - relative_ts));
auto tv = phosg::usecs_to_timeval(this->event_it->timestamp - relative_ts); co_await this->next_command_timer.async_wait(asio::use_awaitable);
event_add(this->next_command_ev.get(), &tv); l = this->lobby.lock();
break;
} }
} }
} }
+26 -14
View File
@@ -1,8 +1,8 @@
#pragma once #pragma once
#include <event2/event.h>
#include <stdint.h> #include <stdint.h>
#include <asio.hpp>
#include <deque> #include <deque>
#include <memory> #include <memory>
#include <phosg/Strings.hh> #include <phosg/Strings.hh>
@@ -22,7 +22,7 @@ public:
struct PlayerEntry { struct PlayerEntry {
PlayerLobbyDataDCGC lobby_data; PlayerLobbyDataDCGC lobby_data;
PlayerInventory inventory; PlayerInventory inventory;
PlayerDispDataDCPCV3 disp; PlayerDispDataV123 disp;
le_uint32_t level; le_uint32_t level;
void print(FILE* stream) const; void print(FILE* stream) const;
@@ -62,15 +62,30 @@ public:
explicit BattleRecord(const std::string& data); explicit BattleRecord(const std::string& data);
std::string serialize() const; std::string serialize() const;
bool writable() const; inline bool writable() const {
bool battle_in_progress() 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( void add_player(
const PlayerLobbyDataDCGC& lobby_data, const PlayerLobbyDataDCGC& lobby_data,
const PlayerInventory& inventory, const PlayerInventory& inventory,
const PlayerDispDataDCPCV3& disp, const PlayerDispDataV123& disp,
uint32_t level); uint32_t level);
void delete_player(uint8_t client_id); void delete_player(uint8_t client_id);
void add_command(Event::Type type, const void* data, size_t size); void add_command(Event::Type type, const void* data, size_t size);
@@ -86,7 +101,6 @@ public:
void print(FILE* stream) const; void print(FILE* stream) const;
std::vector<std::string> get_all_server_data_commands() const;
const std::string& get_random_stream() const; const std::string& get_random_stream() const;
private: private:
@@ -108,7 +122,7 @@ private:
class BattleRecordPlayer { class BattleRecordPlayer {
public: public:
BattleRecordPlayer(std::shared_ptr<const BattleRecord> rec, std::shared_ptr<struct event_base> base); BattleRecordPlayer(std::shared_ptr<asio::io_context> io_context, std::shared_ptr<const BattleRecord> rec);
~BattleRecordPlayer() = default; ~BattleRecordPlayer() = default;
std::shared_ptr<const BattleRecord> get_record() const; std::shared_ptr<const BattleRecord> get_record() const;
@@ -117,16 +131,14 @@ public:
void start(); void start();
private: private:
static void dispatch_schedule_events(evutil_socket_t, short, void* ctx); std::shared_ptr<asio::io_context> io_context;
void schedule_events();
std::shared_ptr<const BattleRecord> record; std::shared_ptr<const BattleRecord> record;
std::deque<BattleRecord::Event>::const_iterator event_it; std::deque<BattleRecord::Event>::const_iterator event_it;
uint64_t play_start_timestamp; uint64_t play_start_timestamp;
std::shared_ptr<struct event_base> base;
std::weak_ptr<Lobby> lobby; std::weak_ptr<Lobby> lobby;
std::shared_ptr<struct event> next_command_ev; asio::steady_timer next_command_timer;
phosg::StringReader random_r;
asio::awaitable<void> play_task();
}; };
} // namespace Episode3 } // namespace Episode3
+155 -181
View File
@@ -3,15 +3,9 @@
#include "../CommandFormats.hh" #include "../CommandFormats.hh"
#include "Server.hh" #include "Server.hh"
using namespace std;
namespace Episode3 { namespace Episode3 {
Card::Card( Card::Card(uint16_t card_id, uint16_t card_ref, uint16_t client_id, std::shared_ptr<Server> server)
uint16_t card_id,
uint16_t card_ref,
uint16_t client_id,
shared_ptr<Server> server)
: w_server(server), : w_server(server),
w_player_state(server->get_player_state(client_id)), w_player_state(server->get_player_state(client_id)),
client_id(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 // 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 // doesn't, it certainly isn't behavior that the player would expect, so we
// prevent it instead. // 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_card_ref = ps->get_sc_card_ref();
this->sc_def_entry = s->definition_for_card_id(ps->get_sc_card_id()); this->sc_def_entry = s->definition_for_card_id(ps->get_sc_card_id());
@@ -60,7 +54,7 @@ void Card::init() {
} else { } else {
int16_t rules_char_hp = s->map_and_rules->rules.char_hp; 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 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->max_hp = hp;
this->current_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(); auto s = this->w_server.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; return s;
} }
shared_ptr<const Server> Card::server() const { std::shared_ptr<const Server> Card::server() const {
auto s = this->w_server.lock(); auto s = this->w_server.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; return s;
} }
shared_ptr<PlayerState> Card::player_state() { std::shared_ptr<PlayerState> Card::player_state() {
auto s = this->w_player_state.lock(); auto s = this->w_player_state.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; 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(); auto s = this->w_player_state.lock();
if (!s) { if (!s) {
throw runtime_error("server is deleted"); throw std::runtime_error("server is deleted");
} }
return s; return s;
} }
@@ -123,7 +117,7 @@ ssize_t Card::apply_abnormal_condition(
int8_t dice_roll_value, int8_t dice_roll_value,
int8_t random_percent) { int8_t random_percent) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(phosg::string_printf("apply_abnormal_condition(%02hhX, @%04X, @%04X, %hd, %hhd, %hhd): ", def_effect_index, target_card_ref, sc_card_ref, value, dice_roll_value, random_percent)); auto log = s->log_stack(std::format("apply_abnormal_condition({:02X}, @{:04X}, @{:04X}, {}, {}, {}): ", def_effect_index, target_card_ref, sc_card_ref, value, dice_roll_value, random_percent));
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
ssize_t existing_cond_index; ssize_t existing_cond_index;
@@ -132,8 +126,7 @@ ssize_t Card::apply_abnormal_condition(
if (cond.type == eff.type) { if (cond.type == eff.type) {
existing_cond_index = z; existing_cond_index = z;
if ((!is_nte && eff.type == ConditionType::MV_BONUS) || if ((!is_nte && eff.type == ConditionType::MV_BONUS) ||
((cond.card_definition_effect_index == def_effect_index) && ((cond.card_definition_effect_index == def_effect_index) && (cond.card_ref == target_card_ref))) {
(cond.card_ref == target_card_ref))) {
break; break;
} }
} else { } else {
@@ -150,21 +143,21 @@ ssize_t Card::apply_abnormal_condition(
break; break;
} }
} }
log.debug("existing_cond_index < 0 (new condition) => cond_index = %zd", cond_index); log.debug_f("existing_cond_index < 0 (new condition) => cond_index = {}", cond_index);
} else { } else {
log.debug("existing_cond_index = %zd (existing condition)", existing_cond_index); log.debug_f("existing_cond_index = {} (existing condition)", existing_cond_index);
} }
if (cond_index < 0) { if (cond_index < 0) {
log.debug("no space for condition"); log.debug_f("no space for condition");
return -1; return -1;
} }
int16_t existing_cond_value = 0; int16_t existing_cond_value = 0;
auto& cond = this->action_chain.conditions[cond_index]; auto& cond = this->action_chain.conditions[cond_index];
if ((eff.type == ConditionType::MV_BONUS) && (cond.type == ConditionType::MV_BONUS)) { 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("MV_BONUS combines => existing_cond_value = %hd", existing_cond_value); log.debug_f("MV_BONUS combines => existing_cond_value = {}", existing_cond_value);
} }
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());
@@ -173,11 +166,7 @@ ssize_t Card::apply_abnormal_condition(
cond.condition_giver_card_ref = sc_card_ref; cond.condition_giver_card_ref = sc_card_ref;
cond.card_definition_effect_index = def_effect_index; cond.card_definition_effect_index = def_effect_index;
cond.order = 10; cond.order = 10;
if (dice_roll_value < 0) { cond.dice_roll_value = (dice_roll_value < 0) ? this->player_state()->roll_dice_with_effects(1) : dice_roll_value;
cond.dice_roll_value = this->player_state()->roll_dice_with_effects(1);
} else {
cond.dice_roll_value = dice_roll_value;
}
cond.flags = 0; cond.flags = 0;
cond.value = value + existing_cond_value; cond.value = value + existing_cond_value;
cond.value8 = 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)) { switch (eff.arg1.at(0)) {
case 'a': { case 'a': {
string s = eff.arg1.decode(); std::string s = eff.arg1.decode();
cond.a_arg_value = atoi(s.c_str() + 1); cond.a_arg_value = atoi(s.c_str() + 1);
break; break;
} }
@@ -199,13 +188,12 @@ ssize_t Card::apply_abnormal_condition(
cond.remaining_turns = 102; cond.remaining_turns = 102;
break; break;
case 't': { case 't': {
string s = eff.arg1.decode(); std::string s = eff.arg1.decode();
cond.remaining_turns = atoi(s.c_str() + 1); cond.remaining_turns = atoi(s.c_str() + 1);
} }
} }
string cond_str = cond.str(s); log.debug_f("wrote condition {} => {}", cond_index, cond.str(s));
log.debug("wrote condition %zd => %s", cond_index, cond_str.c_str());
if (!is_nte) { if (!is_nte) {
s->card_special->update_condition_orders(this->shared_from_this()); 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) { if (this->action_chain.conditions[z].type == ConditionType::NONE) {
continue; continue;
} }
string cond_str = cond.str(s); log.debug_f("sorted conditions: [{}] => {}", z, cond.str(s));
log.debug("sorted conditions: [%zu] => %s", z, cond_str.c_str());
} }
} }
@@ -222,7 +209,7 @@ ssize_t Card::apply_abnormal_condition(
} }
void Card::apply_ap_and_tp_adjust_assists_to_attack( 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* inout_attacker_ap,
int16_t* in_defense_power, int16_t* in_defense_power,
int16_t* inout_attacker_tp) const { 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)) { switch (s->assist_server->get_active_assist_by_index(z)) {
case AssistEffect::POWERLESS_RAIN: case AssistEffect::POWERLESS_RAIN:
if (is_nte) { 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; break;
case AssistEffect::BRAVE_WIND: case AssistEffect::BRAVE_WIND:
if (is_nte) { 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; break;
case AssistEffect::SILENT_COLOSSEUM: case AssistEffect::SILENT_COLOSSEUM:
@@ -293,26 +280,25 @@ bool Card::check_card_flag(uint32_t flags) const {
void Card::commit_attack( void Card::commit_attack(
int16_t damage, int16_t damage,
shared_ptr<Card> attacker_card, std::shared_ptr<Card> attacker_card,
G_ApplyConditionEffect_Ep3_6xB4x06* cmd, G_ApplyConditionEffect_Ep3_6xB4x06* cmd,
size_t strike_number, size_t strike_number,
int16_t* out_effective_damage) { int16_t* out_effective_damage) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(phosg::string_printf("commit_attack(@%04hX #%04hX, @%04hX #%04hX => %hd (str%zu)): ", this->get_card_ref(), this->get_card_id(), attacker_card->get_card_ref(), attacker_card->get_card_id(), damage, strike_number)); auto log = s->log_stack(std::format("commit_attack(@{:04X} #{:04X}, @{:04X} #{:04X} => {} (str{})): ", this->get_card_ref(), this->get_card_id(), attacker_card->get_card_ref(), attacker_card->get_card_id(), damage, strike_number));
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
int16_t effective_damage = damage; int16_t effective_damage = damage;
s->card_special->adjust_attack_damage_due_to_conditions( s->card_special->adjust_attack_damage_due_to_conditions(
this->shared_from_this(), &effective_damage, attacker_card->get_card_ref()); this->shared_from_this(), &effective_damage, attacker_card->get_card_ref());
log.debug("adjusted damage = %hd", effective_damage); log.debug_f("adjusted damage = {}", effective_damage);
size_t num_assists = s->assist_server->compute_num_assist_effects_for_client(this->client_id); 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++) { for (size_t z = 0; z < num_assists; z++) {
auto eff = s->assist_server->get_active_assist_by_index(z); auto eff = s->assist_server->get_active_assist_by_index(z);
if ((eff == AssistEffect::RANSOM) && if ((eff == AssistEffect::RANSOM) && (attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL)) {
(attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL)) {
uint8_t team_id = this->player_state()->get_team_id(); 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; s->team_exp[team_id] -= exp_amount;
effective_damage -= exp_amount; effective_damage -= exp_amount;
if (!is_nte) { if (!is_nte) {
@@ -324,36 +310,35 @@ void Card::commit_attack(
} }
} }
} }
log.debug("after assists = %hd", effective_damage); log.debug_f("after assists = {}", effective_damage);
if (this->action_metadata.check_flag(0x10)) { if (this->action_metadata.check_flag(0x10)) {
effective_damage = 0; effective_damage = 0;
log.debug("flag 0x10 => effective damage = %hd", effective_damage); log.debug_f("flag 0x10 => effective damage = {}", effective_damage);
} }
auto attacker_ps = attacker_card->player_state(); auto attacker_ps = attacker_card->player_state();
attacker_ps->stats.damage_given += effective_damage; attacker_ps->stats.damage_given += effective_damage;
this->player_state()->stats.damage_taken += effective_damage; this->player_state()->stats.damage_taken += effective_damage;
log.debug("updated stats"); 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("hp set to %hd", this->current_hp); log.debug_f("hp set to {}", this->current_hp);
if ((effective_damage > 0) && if ((effective_damage > 0) && (attacker_ps->stats.max_attack_damage < effective_damage)) {
(attacker_ps->stats.max_attack_damage < effective_damage)) {
attacker_ps->stats.max_attack_damage = effective_damage; attacker_ps->stats.max_attack_damage = effective_damage;
log.debug("attacker new max damage %hd", effective_damage); log.debug_f("attacker new max damage {}", effective_damage);
} }
this->last_attack_final_damage = effective_damage; this->last_attack_final_damage = effective_damage;
log.debug("last attack final damage = %hd", effective_damage); log.debug_f("last attack final damage = {}", effective_damage);
if (effective_damage > 0) { if (effective_damage > 0) {
this->card_flags = this->card_flags | 4; this->card_flags = this->card_flags | 4;
log.debug("set flag 4"); log.debug_f("set flag 4");
} }
if (this->current_hp < 1) { if (this->current_hp < 1) {
this->destroy_set_card(attacker_card); this->destroy_set_card(attacker_card);
log.debug("card destroyed"); log.debug_f("card destroyed");
} }
G_ApplyConditionEffect_Ep3_6xB4x06 cmd_to_send; G_ApplyConditionEffect_Ep3_6xB4x06 cmd_to_send;
@@ -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) { if (!attacker_card) {
return 0; 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(
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x10, nullptr); 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; 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 s = this->server();
auto ps = this->player_state(); 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) && if ((s->map_and_rules->rules.hp_type == HPType::DEFEAT_TEAM) && (ps->get_sc_card().get() == this)) {
(ps->get_sc_card().get() == this)) {
for (size_t set_index = 0; set_index < 8; set_index++) { for (size_t set_index = 0; set_index < 8; set_index++) {
auto card = ps->get_set_card(set_index); auto card = ps->get_set_card(set_index);
if (card) { 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 other_team_id = s->player_states[client_id]->get_team_id();
uint8_t this_team_id = ps->get_team_id(); uint8_t this_team_id = ps->get_team_id();
if (this_team_id == other_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) { if (this->card_flags & 2) {
return -0x60; return -0x60;
} }
if (!this->server()->ruler_server->card_ref_can_move( if (!this->server()->ruler_server->card_ref_can_move(this->client_id, this->card_ref, 1)) {
this->client_id, this->card_ref, 1)) {
return -0x7B; return -0x7B;
} }
// Note: The original code passes non-null pointers here but ignores the // Note: The original code passes non-null pointers here but ignores the
@@ -501,25 +486,25 @@ int32_t Card::error_code_for_move_to_location(const Location& loc) const {
return 0; return 0;
} }
void Card::execute_attack(shared_ptr<Card> attacker_card) { void Card::execute_attack(std::shared_ptr<Card> attacker_card) {
if (!attacker_card) { if (!attacker_card) {
return; return;
} }
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(phosg::string_printf("execute_attack(@%04X #%04X, @%04X #%04X): ", this->get_card_ref(), this->get_card_id(), attacker_card->get_card_ref(), attacker_card->get_card_id())); auto log = s->log_stack(std::format("execute_attack(@{:04X} #{:04X}, @{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id(), attacker_card->get_card_ref(), attacker_card->get_card_id()));
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
this->card_flags &= 0xFFFFFFF3; this->card_flags &= 0xFFFFFFF3;
int16_t attack_ap = this->action_metadata.attack_bonus; int16_t attack_ap = this->action_metadata.attack_bonus;
int16_t attack_tp = 0; int16_t attack_tp = 0;
int16_t defense_power = is_nte ? 0 : this->compute_defense_power_for_attacker_card(attacker_card); int16_t defense_power = is_nte ? 0 : this->compute_defense_power_for_attacker_card(attacker_card);
log.debug("ap=%hd, tp=%hd", attack_ap, attack_tp); log.debug_f("ap={}, tp={}", attack_ap, attack_tp);
if (!is_nte && (attack_ap == 0) && !this->action_metadata.check_flag(0x20)) { if (!is_nte && (attack_ap == 0) && !this->action_metadata.check_flag(0x20)) {
log.debug("ap == 0 and flag 0x20 not set"); log.debug_f("ap == 0 and flag 0x20 not set");
return; return;
} else { } else {
log.debug("ap != 0 or flag 0x20 set; continuing..."); log.debug_f("ap != 0 or flag 0x20 set; continuing...");
} }
G_ApplyConditionEffect_Ep3_6xB4x06 cmd; G_ApplyConditionEffect_Ep3_6xB4x06 cmd;
@@ -529,9 +514,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
if (attacker_card->action_chain.chain.attack_medium == AttackMedium::UNKNOWN_03) { if (attacker_card->action_chain.chain.attack_medium == AttackMedium::UNKNOWN_03) {
// Probably Resta // Probably Resta
for (size_t strike_num = 0; strike_num < attacker_card->action_chain.chain.strike_count; strike_num++) { 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 = std::min<int16_t>(this->current_hp + attacker_card->action_chain.chain.effective_tp, this->max_hp);
this->current_hp + attacker_card->action_chain.chain.effective_tp,
this->max_hp);
} }
this->propagate_shared_hp_if_needed(); this->propagate_shared_hp_if_needed();
cmd.effect.tp = attacker_card->action_chain.chain.effective_tp; cmd.effect.tp = attacker_card->action_chain.chain.effective_tp;
@@ -542,7 +525,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
if (is_nte) { if (is_nte) {
defense_power = this->compute_defense_power_for_attacker_card(attacker_card); defense_power = this->compute_defense_power_for_attacker_card(attacker_card);
log.debug("ap=%hd, tp=%hd, defense=%hd", attack_ap, attack_tp, defense_power); log.debug_f("ap={}, tp={}, defense={}", attack_ap, attack_tp, defense_power);
attacker_card->compute_action_chain_results(true, false); attacker_card->compute_action_chain_results(true, false);
attack_ap = attacker_card->action_chain.chain.damage; attack_ap = attacker_card->action_chain.chain.damage;
if (this->action_chain.chain.attack_medium == AttackMedium::TECH) { if (this->action_chain.chain.attack_medium == AttackMedium::TECH) {
@@ -553,14 +536,14 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
} }
s->card_special->compute_attack_ap(this->shared_from_this(), &attack_ap, attacker_card->get_card_ref()); s->card_special->compute_attack_ap(this->shared_from_this(), &attack_ap, attacker_card->get_card_ref());
log.debug("computed ap %hd", attack_ap); log.debug_f("computed ap {}", attack_ap);
this->apply_ap_and_tp_adjust_assists_to_attack(attacker_card, &attack_ap, &defense_power, &attack_tp); this->apply_ap_and_tp_adjust_assists_to_attack(attacker_card, &attack_ap, &defense_power, &attack_tp);
log.debug("assist adjusts ap=%hd, defense=%hd", attack_ap, defense_power); log.debug_f("assist adjusts ap={}, defense={}", attack_ap, defense_power);
int16_t raw_damage = 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; this->last_attack_preliminary_damage = preliminary_damage;
log.debug("raw_damage=%hd, preliminary_damange=%hd", raw_damage, preliminary_damage); log.debug_f("raw_damage={}, preliminary_damange={}", raw_damage, preliminary_damage);
uint32_t unknown_a9 = 0; uint32_t unknown_a9 = 0;
auto target = s->card_special->compute_replaced_target_based_on_conditions( auto target = s->card_special->compute_replaced_target_based_on_conditions(
@@ -568,43 +551,43 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
if (!target) { if (!target) {
target = this->shared_from_this(); target = this->shared_from_this();
log.debug("target is not replaced"); log.debug_f("target is not replaced");
} else { } else {
log.debug("target replaced with @%04hX #%04hX", target->get_card_ref(), target->get_card_id()); log.debug_f("target replaced with @{:04X} #{:04X}", target->get_card_ref(), target->get_card_id());
} }
if (!is_nte) { if (!is_nte) {
if (unknown_a9 != 0) { if (unknown_a9 != 0) {
preliminary_damage = 0; preliminary_damage = 0;
log.debug("a9 nonzero; preliminary_damage = 0"); log.debug_f("a9 nonzero; preliminary_damage = 0");
} }
if (!(this->card_flags & 2) && (!attacker_card || !(attacker_card->card_flags & 2))) { if (!(this->card_flags & 2) && (!attacker_card || !(attacker_card->card_flags & 2))) {
s->card_special->check_for_defense_interference(attacker_card, this->shared_from_this(), &preliminary_damage); s->card_special->check_for_defense_interference(attacker_card, this->shared_from_this(), &preliminary_damage);
log.debug("checked for defense interference"); log.debug_f("checked for defense interference");
} }
} }
cmd.effect.current_hp = is_nte ? attack_ap : min<int16_t>(attack_ap, 99); cmd.effect.current_hp = is_nte ? attack_ap : std::min<int16_t>(attack_ap, 99);
cmd.effect.ap = is_nte ? defense_power : min<int16_t>(defense_power, 99); cmd.effect.ap = is_nte ? defense_power : std::min<int16_t>(defense_power, 99);
cmd.effect.tp = attack_tp; cmd.effect.tp = attack_tp;
auto ps = this->player_state(); auto ps = this->player_state();
ps->stats.num_attacks_taken++; ps->stats.num_attacks_taken++;
if (!(target->card_flags & 2)) { if (!(target->card_flags & 2)) {
log.debug("flag 2 not set"); log.debug_f("flag 2 not set");
for (size_t strike_num = 0; strike_num < attacker_card->action_chain.chain.strike_count; strike_num++) { for (size_t strike_num = 0; strike_num < attacker_card->action_chain.chain.strike_count; strike_num++) {
int16_t final_effective_damage = 0; int16_t final_effective_damage = 0;
target->commit_attack(preliminary_damage, attacker_card, &cmd, strike_num, &final_effective_damage); 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 { } else {
log.debug("flag 2 set; committing zero-damage attack"); log.debug_f("flag 2 set; committing zero-damage attack");
target->commit_attack(0, attacker_card, &cmd, 0, nullptr); target->commit_attack(0, attacker_card, &cmd, 0, nullptr);
} }
if (!is_nte && (this != target.get())) { if (!is_nte && (this != target.get())) {
log.debug("target was replaced; committing zero-damage attack on original card"); log.debug_f("target was replaced; committing zero-damage attack on original card");
this->commit_attack(0, attacker_card, &cmd, 0, nullptr); this->commit_attack(0, attacker_card, &cmd, 0, nullptr);
} }
@@ -613,11 +596,7 @@ void Card::execute_attack(shared_ptr<Card> attacker_card) {
} }
bool Card::get_condition_value( bool Card::get_condition_value(
ConditionType cond_type, ConditionType cond_type, uint16_t card_ref, uint8_t def_effect_index, uint16_t value, uint16_t* out_value) const {
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); 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); 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; return this->def_entry;
} }
@@ -697,9 +676,7 @@ int32_t Card::move_to_location(const Location& loc) {
this->card_flags = this->card_flags | 0x80; this->card_flags = this->card_flags | 0x80;
// On NTE, traps happen now, not after the Move phase // On NTE, traps happen now, not after the Move phase
if (s->options.is_nte() && if (s->options.is_nte() && this->def_entry->def.is_sc() && ((s->overlay_state.tiles[loc.y][loc.x] & 0xF0) == 0x40)) {
this->def_entry->def.is_sc() &&
((s->overlay_state.tiles[loc.y][loc.x] & 0xF0) == 0x40)) {
for (size_t z = 0; z < 4; z++) { for (size_t z = 0; z < 4; z++) {
auto other_ps = s->player_states[z]; auto other_ps = s->player_states[z];
if (!other_ps) { 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))) { ((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++) { for (size_t other_client_id = 0; other_client_id < 4; other_client_id++) {
auto other_ps = this->server()->player_states[other_client_id]; auto other_ps = this->server()->player_states[other_client_id];
if ((other_client_id != this->client_id) && other_ps && if ((other_client_id != this->client_id) && other_ps && (other_ps->get_team_id() == this->team_id)) {
(other_ps->get_team_id() == this->team_id)) {
other_ps->get_sc_card()->set_current_hp(this->current_hp, false); 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( void Card::set_current_hp(
uint32_t new_hp, bool propagate_shared_hp, bool enforce_max_hp) { uint32_t new_hp, bool propagate_shared_hp, bool enforce_max_hp) {
if (!enforce_max_hp) { if (!enforce_max_hp) {
new_hp = max<int16_t>(new_hp, 0); new_hp = std::max<int16_t>(new_hp, 0);
this->max_hp = max<int16_t>(this->max_hp, new_hp); this->max_hp = std::max<int16_t>(this->max_hp, new_hp);
} else { } 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; 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) { void Card::compute_action_chain_results(bool apply_action_conditions, bool ignore_this_card_ap_tp) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(phosg::string_printf("compute_action_chain_results(@%04hX #%04hX): ", 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(); bool is_nte = s->options.is_nte();
this->action_chain.compute_attack_medium(s); this->action_chain.compute_attack_medium(s);
@@ -914,7 +891,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
this->action_chain.chain.ap_effect_bonus = 0; this->action_chain.chain.ap_effect_bonus = 0;
this->action_chain.chain.tp_effect_bonus = 0; this->action_chain.chain.tp_effect_bonus = 0;
log.debug("(initial) medium=%s, strike_count=%hhu, ap_effect_bonus=%hhd, tp_effect_bonus=%hhd", log.debug_f("(initial) medium={}, strike_count={}, ap_effect_bonus={}, tp_effect_bonus={}",
phosg::name_for_enum(this->action_chain.chain.attack_medium), phosg::name_for_enum(this->action_chain.chain.attack_medium),
this->action_chain.chain.strike_count, this->action_chain.chain.strike_count,
this->action_chain.chain.ap_effect_bonus, this->action_chain.chain.ap_effect_bonus,
@@ -929,9 +906,10 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
stat_swap_type = StatSwapType::NONE; stat_swap_type = StatSwapType::NONE;
} else { } else {
stat_swap_type = s->card_special->compute_stat_swap_type(this->shared_from_this()); stat_swap_type = s->card_special->compute_stat_swap_type(this->shared_from_this());
log.debug("stat_swap_type = %zu (0=none, 1=a/t, 2=a/h)", static_cast<size_t>(stat_swap_type)); 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(
log.debug("effective_ap = %hd, effective_tp = %hd", effective_ap, effective_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);
} }
// This option doesn't exist in NTE // This option doesn't exist in NTE
@@ -942,7 +920,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
if (ce) { if (ce) {
effective_ap += ce->def.ap.stat; effective_ap += ce->def.ap.stat;
effective_tp += ce->def.tp.stat; effective_tp += ce->def.tp.stat;
log.debug("(action card @%04hX) updated effective_ap = %hd, effective_tp = %hd", this->action_chain.chain.attack_action_card_refs[z].load(), effective_ap, effective_tp); log.debug_f("(action card @{:04X}) updated effective_ap = {}, effective_tp = {}", this->action_chain.chain.attack_action_card_refs[z], effective_ap, effective_tp);
} }
} }
@@ -957,7 +935,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
stat_swap_type, &card_ap, &card_tp, card->get_current_hp(), card->ap, card->tp); stat_swap_type, &card_ap, &card_tp, card->get_current_hp(), card->ap, card->tp);
effective_ap += card_ap; effective_ap += card_ap;
effective_tp += card_tp; effective_tp += card_tp;
log.debug("(mag card set_index %zu @%04hX) updated effective_ap = %hd, effective_tp = %hd", log.debug_f("(mag card set_index {} @{:04X}) updated effective_ap = {}, effective_tp = {}",
set_index, card->get_card_ref(), effective_ap, effective_tp); set_index, card->get_card_ref(), effective_ap, effective_tp);
} }
} }
@@ -968,25 +946,25 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
sc_card->compute_action_chain_results(apply_action_conditions, true); sc_card->compute_action_chain_results(apply_action_conditions, true);
effective_ap += sc_card->action_chain.chain.effective_ap + sc_card->action_chain.chain.ap_effect_bonus; effective_ap += sc_card->action_chain.chain.effective_ap + sc_card->action_chain.chain.ap_effect_bonus;
effective_tp += sc_card->action_chain.chain.effective_tp + sc_card->action_chain.chain.tp_effect_bonus; effective_tp += sc_card->action_chain.chain.effective_tp + sc_card->action_chain.chain.tp_effect_bonus;
log.debug("(item is attacking; adding SC stats) updated effective_ap = %hd, effective_tp = %hd", log.debug_f("(item is attacking; adding SC stats) updated effective_ap = {}, effective_tp = {}",
effective_ap, effective_tp); effective_ap, effective_tp);
} }
if (!this->action_chain.check_flag(0x10)) { 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("set chain effective_ap = %hd", this->action_chain.chain.effective_ap); log.debug_f("set chain effective_ap = {}", this->action_chain.chain.effective_ap);
} }
if (!this->action_chain.check_flag(0x20)) { 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("set chain effective_tp = %hd", this->action_chain.chain.effective_tp); log.debug_f("set chain effective_tp = {}", this->action_chain.chain.effective_tp);
} }
if (apply_action_conditions) { if (apply_action_conditions) {
auto this_sh = this->shared_from_this(); auto this_sh = this->shared_from_this();
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 1, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 1, nullptr);
log.debug("applied action conditions (1)"); log.debug_f("applied action conditions (1)");
} else { } else {
log.debug("skipped applying action conditions (1)"); log.debug_f("skipped applying action conditions (1)");
} }
size_t num_assists = s->assist_server->compute_num_assist_effects_for_client(this->client_id); size_t num_assists = s->assist_server->compute_num_assist_effects_for_client(this->client_id);
@@ -1008,7 +986,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
break; break;
case AssistEffect::INFLUENCE: case AssistEffect::INFLUENCE:
if (!is_nte && this->card_type_is_sc_or_creature()) { 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); this->action_chain.chain.ap_effect_bonus += (count >> 1);
} }
break; 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(); auto other_sc_card = other_ps->get_sc_card();
if (other_sc_card && if (other_sc_card &&
(abs(this->loc.x - other_sc_card->loc.x) < 2) && (abs(this->loc.x - other_sc_card->loc.x) < 2) && (abs(this->loc.y - other_sc_card->loc.y) < 2)) {
(abs(this->loc.y - other_sc_card->loc.y) < 2)) {
num_scs_in_range++; num_scs_in_range++;
} }
} }
@@ -1106,29 +1083,32 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
int16_t damage = 0; int16_t damage = 0;
if (this->action_chain.chain.attack_medium == AttackMedium::TECH) { if (this->action_chain.chain.attack_medium == AttackMedium::TECH) {
damage = this->action_chain.chain.effective_tp + this->action_chain.chain.tp_effect_bonus; damage = this->action_chain.chain.effective_tp + this->action_chain.chain.tp_effect_bonus;
log.debug("(tech) damage = %hhd (eff) + %hhd (bonus) = %hd", 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) { } else if (this->action_chain.chain.attack_medium == AttackMedium::PHYSICAL) {
damage = this->action_chain.chain.effective_ap + this->action_chain.chain.ap_effect_bonus; damage = this->action_chain.chain.effective_ap + this->action_chain.chain.ap_effect_bonus;
log.debug("(physical) damage = %hhd (eff) + %hhd (bonus) = %hd", 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 { } else {
log.debug("(unknown attack medium) damage = 0"); log.debug_f("(unknown attack medium) damage = 0");
} }
this->action_chain.chain.damage = is_nte this->action_chain.chain.damage = is_nte
? (damage * this->action_chain.chain.damage_multiplier) ? (damage * this->action_chain.chain.damage_multiplier)
: min<int16_t>(damage * this->action_chain.chain.damage_multiplier, 99); : std::min<int16_t>(damage * this->action_chain.chain.damage_multiplier, 99);
log.debug("overall chain damage = %hd (base) * %hhd (mult) = %hhd", damage, this->action_chain.chain.damage_multiplier, this->action_chain.chain.damage); log.debug_f("overall chain damage = {} (base) * {} (mult) = {}",
damage, this->action_chain.chain.damage_multiplier, this->action_chain.chain.damage);
if (apply_action_conditions) { if (apply_action_conditions) {
auto this_sh = this->shared_from_this(); auto this_sh = this->shared_from_this();
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 2, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 2, nullptr);
log.debug("applied action conditions (2)"); log.debug_f("applied action conditions (2)");
if (!is_nte && this->action_chain.check_flag(0x100)) { 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("(has flag 0x100) chain damage = %hhd", this->action_chain.chain.damage); log.debug_f("(has flag 0x100) chain damage = {}", this->action_chain.chain.damage);
} }
} else { } else {
log.debug("skipped applying action conditions (2)"); log.debug_f("skipped applying action conditions (2)");
} }
if (!is_nte) { if (!is_nte) {
@@ -1156,9 +1136,8 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
} }
} }
if (log.should_log(phosg::LogLevel::DEBUG)) { if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string chain_str = this->action_chain.str(s); log.debug_f("result computed as {}", this->action_chain.str(s));
log.debug("result computed as %s", chain_str.c_str());
} }
} }
@@ -1224,26 +1203,25 @@ void Card::move_phase_before() {
this->server()->card_special->move_phase_before_for_card(this->shared_from_this()); 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 s = this->server();
auto log = s->log_stack(phosg::string_printf("unknown_80236374(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id())); 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::DEBUG)) { if (log.should_log(phosg::LogLevel::L_DEBUG)) {
if (as) { if (as) {
string as_str = as->str(s); log.debug_f("as = {}", as->str(s));
log.debug("as = %s", as_str.c_str());
} else { } else {
log.debug("as = null"); 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) {
if (!card->unknown_80236554(other_card, as)) { if (!card->unknown_80236554(other_card, as)) {
log.debug("check_card @%04hX #%04hX => false", card->get_card_ref(), card->get_card_id()); log.debug_f("check_card @{:04X} #{:04X} => false", card->get_card_ref(), card->get_card_id());
card->action_metadata.clear_flags(0x20); card->action_metadata.clear_flags(0x20);
} else { } else {
log.debug("check_card @%04hX #%04hX => true", card->get_card_ref(), card->get_card_id()); log.debug_f("check_card @{:04X} #{:04X} => true", card->get_card_ref(), card->get_card_id());
card->action_metadata.set_flags(0x20); card->action_metadata.set_flags(0x20);
} }
} }
@@ -1271,8 +1249,7 @@ void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as)
} }
void Card::unknown_802379BC(uint16_t card_ref) { void Card::unknown_802379BC(uint16_t card_ref) {
this->action_chain.chain.unknown_card_ref_a3 = this->action_chain.chain.unknown_card_ref_a3 = (card_ref == 0xFFFF) ? this->card_ref : card_ref;
(card_ref == 0xFFFF) ? this->card_ref : card_ref;
} }
void Card::unknown_802379DC(const ActionState& pa) { 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); pa.defense_card_ref, this->shared_from_this(), pa.original_attacker_card_ref);
this->server()->card_special->unknown_8024A9D8(pa, 0xFFFF); this->server()->card_special->unknown_8024A9D8(pa, 0xFFFF);
for (size_t z = 0; z < this->action_metadata.target_card_ref_count; z++) { 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) { if (card) {
card->action_chain.set_action_subphase_from_card(this->shared_from_this()); card->action_chain.set_action_subphase_from_card(this->shared_from_this());
card->send_6xB4x4E_4C_4D_if_needed(); 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) { 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++) { 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]); 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) { if (sc_card) {
sc_card->action_metadata.add_target_card_ref(this->card_ref); sc_card->action_metadata.add_target_card_ref(this->card_ref);
sc_card->card_flags |= 8; sc_card->card_flags |= 8;
@@ -1359,8 +1336,7 @@ void Card::dice_phase_before() {
cond.remaining_turns--; cond.remaining_turns--;
} }
if (cond.remaining_turns < 1) { if (cond.remaining_turns < 1) {
s->card_special->apply_stat_deltas_to_card_from_condition_and_clear_cond( s->card_special->apply_stat_deltas_to_card_from_condition_and_clear_cond(cond, this->shared_from_this());
cond, this->shared_from_this());
} }
} }
} }
@@ -1375,17 +1351,16 @@ bool Card::is_guard_item() const {
return (this->def_entry->def.card_class() == CardClass::GUARD_ITEM); 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 s = this->server();
auto log = s->log_stack(other_card auto log = s->log_stack(other_card
? phosg::string_printf("unknown_80236554(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id()) ? 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())
: phosg::string_printf("unknown_80236554(@%04hX #%04hX, null): ", this->get_card_ref(), this->get_card_id())); : std::format("unknown_80236554(@{:04X} #{:04X}, null): ", this->get_card_ref(), this->get_card_id()));
if (log.should_log(phosg::LogLevel::DEBUG)) { if (log.should_log(phosg::LogLevel::L_DEBUG)) {
if (as) { if (as) {
string as_str = as->str(s); log.debug_f("as = {}", as->str(s));
log.debug("as = %s", as_str.c_str());
} else { } else {
log.debug("as = null"); log.debug_f("as = null");
} }
} }
@@ -1398,7 +1373,7 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
if (other_card->action_chain.chain.target_card_refs[z] == this->get_card_ref()) { if (other_card->action_chain.chain.target_card_refs[z] == this->get_card_ref()) {
attack_bonus = other_card->action_chain.chain.damage; attack_bonus = other_card->action_chain.chain.damage;
ret = true; ret = true;
log.debug("attack_bonus = %hd (matched other_card->action_chain.chain.target_card_refs)", attack_bonus); log.debug_f("attack_bonus = {} (matched other_card->action_chain.chain.target_card_refs)", attack_bonus);
break; break;
} }
} }
@@ -1406,7 +1381,7 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
for (size_t z = 0; (z < 4 * 9) && (as->target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as->target_card_refs[z] != 0xFFFF); z++) {
if (as->target_card_refs[z] == this->get_card_ref()) { if (as->target_card_refs[z] == this->get_card_ref()) {
attack_bonus = other_card->action_chain.chain.damage; attack_bonus = other_card->action_chain.chain.damage;
log.debug("attack_bonus = %hd (matched as->target_card_refs)", attack_bonus); log.debug_f("attack_bonus = {} (matched as->target_card_refs)", attack_bonus);
ret = true; ret = true;
break; break;
} }
@@ -1414,43 +1389,43 @@ 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("attack_bonus = %hhd", this->action_metadata.attack_bonus); log.debug_f("attack_bonus = {}", this->action_metadata.attack_bonus);
this->last_attack_preliminary_damage = 0; this->last_attack_preliminary_damage = 0;
this->last_attack_final_damage = 0; this->last_attack_final_damage = 0;
log.debug("last attack damage stats cleared"); log.debug_f("last attack damage stats cleared");
if (other_card) { if (other_card) {
log.debug("applying BEFORE_ANY_CARD_ATTACK conditions"); log.debug_f("applying BEFORE_ANY_CARD_ATTACK conditions");
s->card_special->apply_action_conditions( s->card_special->apply_action_conditions(
EffectWhen::BEFORE_ANY_CARD_ATTACK, other_card, this->shared_from_this(), 0x20, as); EffectWhen::BEFORE_ANY_CARD_ATTACK, other_card, this->shared_from_this(), 0x20, as);
log.debug("applying BEFORE_THIS_CARD_ATTACKED conditions"); log.debug_f("applying BEFORE_THIS_CARD_ATTACKED conditions");
s->card_special->apply_action_conditions( s->card_special->apply_action_conditions(
EffectWhen::BEFORE_THIS_CARD_ATTACKED, other_card, this->shared_from_this(), 0x40, as); EffectWhen::BEFORE_THIS_CARD_ATTACKED, other_card, this->shared_from_this(), 0x40, as);
if (other_card->action_chain.check_flag(0x20000)) { if (other_card->action_chain.check_flag(0x20000)) {
log.debug("attack_bonus cleared due to cancellation"); log.debug_f("attack_bonus cleared due to cancellation");
this->action_metadata.attack_bonus = 0; this->action_metadata.attack_bonus = 0;
return ret; return ret;
} }
} }
if (this->card_flags & 2) { if (this->card_flags & 2) {
log.debug("attack_bonus cleared due to destruction"); log.debug_f("attack_bonus cleared due to destruction");
this->action_metadata.attack_bonus = 0; this->action_metadata.attack_bonus = 0;
} }
return ret; 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(); auto s = this->server();
for (size_t client_id = 0; client_id < 4; client_id++) { for (size_t client_id = 0; client_id < 4; client_id++) {
auto ps = s->player_states[client_id]; auto ps = s->player_states[client_id];
if (ps) { if (ps) {
shared_ptr<Card> card = ps->get_sc_card(); std::shared_ptr<Card> card = ps->get_sc_card();
if (card) { if (card) {
card->execute_attack(attacker_card); card->execute_attack(attacker_card);
} }
for (size_t set_index = 0; set_index < 8; set_index++) { 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) { if (card) {
card->execute_attack(attacker_card); card->execute_attack(attacker_card);
} }
@@ -1464,7 +1439,7 @@ void Card::apply_attack_result() {
auto ps = this->player_state(); auto ps = this->player_state();
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
auto log = s->log_stack(phosg::string_printf("apply_attack_result(@%04hX #%04hX): ", this->get_card_ref(), this->get_card_id())); auto log = s->log_stack(std::format("apply_attack_result(@{:04X} #{:04X}): ", this->get_card_ref(), this->get_card_id()));
if (!this->action_chain.can_apply_attack()) { if (!this->action_chain.can_apply_attack()) {
return; return;
} }
@@ -1495,7 +1470,7 @@ void Card::apply_attack_result() {
temp_chain.chain.target_card_ref_count++; temp_chain.chain.target_card_ref_count++;
} else if ((target_card->get_definition()->def.type == CardType::ITEM) && !this->action_chain.check_flag(0x02)) { } else if ((target_card->get_definition()->def.type == CardType::ITEM) && !this->action_chain.check_flag(0x02)) {
auto target_ps = target_card->player_state(); 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++) { for (size_t set_index = 0; set_index < 8; set_index++) {
auto set_card = target_ps->get_set_card(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()) { if (set_card && (set_card != target_card) && !(set_card->card_flags & 2) && set_card->is_guard_item()) {
@@ -1573,46 +1548,45 @@ void Card::apply_attack_result() {
} }
} }
if (log.should_log(phosg::LogLevel::DEBUG)) { if (log.should_log(phosg::LogLevel::L_DEBUG)) {
string as_str = as.str(s); log.debug_f("as constructed as {}", as.str(s));
log.debug("as constructed as %s", as_str.c_str());
} }
for (size_t z = 0; z < this->action_chain.chain.target_card_ref_count; z++) { 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) { if (card) {
card->current_defense_power = card->action_metadata.attack_bonus; card->current_defense_power = card->action_metadata.attack_bonus;
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
log.debug("unknown_8024A6DC(@%04hX #%04hX) ...", card->get_card_ref(), card->get_card_id()); log.debug_f("unknown_8024A6DC(@{:04X} #{:04X}) ...", card->get_card_ref(), card->get_card_id());
s->card_special->unknown_8024A6DC(this->shared_from_this(), card); s->card_special->unknown_8024A6DC(this->shared_from_this(), card);
} }
} }
} }
log.debug("compute_action_chain_results 1 ..."); log.debug_f("compute_action_chain_results 1 ...");
this->compute_action_chain_results(true, false); this->compute_action_chain_results(true, false);
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
log.debug("apply_effects_before_attack ..."); log.debug_f("apply_effects_before_attack ...");
s->card_special->apply_effects_before_attack(this->shared_from_this()); s->card_special->apply_effects_before_attack(this->shared_from_this());
} }
if (!(this->card_flags & 2)) { if (!(this->card_flags & 2)) {
log.debug("compute_action_chain_results 2 ..."); log.debug_f("compute_action_chain_results 2 ...");
this->compute_action_chain_results(true, false); this->compute_action_chain_results(true, false);
log.debug("check_for_attack_interference ..."); log.debug_f("check_for_attack_interference ...");
s->card_special->check_for_attack_interference(this->shared_from_this()); s->card_special->check_for_attack_interference(this->shared_from_this());
} }
log.debug("compute_action_chain_results 3 ..."); log.debug_f("compute_action_chain_results 3 ...");
this->compute_action_chain_results(true, false); this->compute_action_chain_results(true, false);
log.debug("unknown_80236374 ..."); log.debug_f("unknown_80236374 ...");
this->unknown_80236374(this->shared_from_this(), nullptr); this->unknown_80236374(this->shared_from_this(), nullptr);
log.debug("execute_attack_on_all_valid_targets ..."); log.debug_f("execute_attack_on_all_valid_targets ...");
this->execute_attack_on_all_valid_targets(this->shared_from_this()); this->execute_attack_on_all_valid_targets(this->shared_from_this());
} }
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
log.debug("apply_effects_after_attack ..."); log.debug_f("apply_effects_after_attack ...");
s->card_special->apply_effects_after_attack(this->shared_from_this()); s->card_special->apply_effects_after_attack(this->shared_from_this());
} }
ps->stats.num_attacks_given++; ps->stats.num_attacks_given++;
@@ -1625,7 +1599,7 @@ void Card::apply_attack_result() {
for (size_t client_id = 0; client_id < 4; client_id++) { for (size_t client_id = 0; client_id < 4; client_id++) {
auto ps = s->player_states[client_id]; auto ps = s->player_states[client_id];
if (ps) { if (ps) {
log.debug("unknown_8023C110(%zu) ...", client_id); log.debug_f("unknown_8023C110({}) ...", client_id);
ps->unknown_8023C110(); ps->unknown_8023C110();
} }
} }
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( const InterferenceProbabilityEntry* get_interference_probability_entry(
uint16_t row_card_id, uint16_t row_card_id, uint16_t column_card_id, bool is_attack);
uint16_t column_card_id,
bool is_attack);
class CardSpecial { class CardSpecial {
public: 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 { struct DiceRoll {
uint8_t client_id; uint8_t client_id;
uint8_t unknown_a2; uint8_t unknown_a2;
@@ -77,9 +64,8 @@ public:
/* 70 */ uint32_t effective_ap_if_not_tech2; // "tt" in expr /* 70 */ uint32_t effective_ap_if_not_tech2; // "tt" in expr
/* 74 */ uint32_t team_dice_bonus; // "lv" in expr /* 74 */ uint32_t team_dice_bonus; // "lv" in expr
/* 78 */ uint32_t sc_effective_ap; // "adm" in expr /* 78 */ uint32_t sc_effective_ap; // "adm" in expr
// The following fields do not exist in Trial Edition. Because this struct // The following fields do not exist in Trial Edition. Because this struct is never sent to the client, we use the
// is never sent to the client, we use the full struct even when playing // full struct even when playing Trial Edition, just for simplicity.
// Trial Edition, just for simplicity.
/* 7C */ uint32_t attack_bonus; // "ddm" in expr /* 7C */ uint32_t attack_bonus; // "ddm" in expr
/* 80 */ uint32_t num_sword_type_items_on_team; // "sat" in expr /* 80 */ uint32_t num_sword_type_items_on_team; // "sat" in expr
/* 84 */ uint32_t target_attack_bonus; // "edm" in expr /* 84 */ uint32_t target_attack_bonus; // "edm" in expr
@@ -126,26 +112,14 @@ public:
uint32_t flags, uint32_t flags,
bool unknown_p8); bool unknown_p8);
bool apply_defense_conditions( bool apply_defense_conditions(
const ActionState& as, const ActionState& as, EffectWhen when, std::shared_ptr<Card> defender_card, uint32_t flags);
EffectWhen when, bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(uint16_t card_ref);
std::shared_ptr<Card> defender_card, bool apply_stat_deltas_to_card_from_condition_and_clear_cond(Condition& cond, std::shared_ptr<Card> card);
uint32_t flags); bool apply_stats_deltas_to_card_from_all_conditions_with_card_ref(uint16_t card_ref, std::shared_ptr<Card> card);
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( bool card_has_condition_with_ref(
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref, uint16_t match_card_ref) const;
ConditionType cond_type,
uint16_t card_ref,
uint16_t match_card_ref) const;
bool card_is_destroyed(std::shared_ptr<const Card> card) const; bool card_is_destroyed(std::shared_ptr<const Card> card) const;
void compute_attack_ap( void compute_attack_ap(std::shared_ptr<const Card> target_card, int16_t* out_value, uint16_t attacker_card_ref);
std::shared_ptr<const Card> target_card,
int16_t* out_value,
uint16_t attacker_card_ref);
AttackEnvStats compute_attack_env_stats( AttackEnvStats compute_attack_env_stats(
const ActionState& pa, const ActionState& pa,
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card,
@@ -166,21 +140,16 @@ public:
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const; StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
void compute_team_dice_bonus(uint8_t team_id); void compute_team_dice_bonus(uint8_t team_id);
bool condition_applies_on_sc_or_item_attack(const Condition& cond) const; bool condition_applies_on_sc_or_item_attack(const Condition& cond) const;
size_t count_action_cards_with_condition_for_all_current_attacks( size_t count_action_cards_with_condition_for_all_current_attacks(ConditionType cond_type, uint16_t card_ref) const;
ConditionType cond_type, uint16_t card_ref) const;
size_t count_action_cards_with_condition_for_current_attack( size_t count_action_cards_with_condition_for_current_attack(
std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref) const; std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref) const;
size_t count_cards_with_card_id_except_card_ref( size_t count_cards_with_card_id_except_card_ref(uint16_t card_id, uint16_t card_ref) const;
uint16_t card_id, uint16_t card_ref) const;
std::vector<std::shared_ptr<const Card>> get_all_set_cards_by_team_and_class( 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; CardClass card_class, uint8_t team_id, bool exclude_destroyed_cards) const;
ActionState create_attack_state_from_card_action_chain( ActionState create_attack_state_from_card_action_chain(std::shared_ptr<const Card> attacker_card) const;
std::shared_ptr<const Card> attacker_card) const;
ActionState create_defense_state_for_card_pair_action_chains( ActionState create_defense_state_for_card_pair_action_chains(
std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> defender_card) const;
std::shared_ptr<const Card> defender_card) const; void destroy_card_if_hp_zero(std::shared_ptr<Card> card, uint16_t attacker_card_ref);
void destroy_card_if_hp_zero(
std::shared_ptr<Card> card, uint16_t attacker_card_ref);
bool evaluate_effect_arg2_condition( bool evaluate_effect_arg2_condition(
const ActionState& as, const ActionState& as,
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card,
@@ -190,10 +159,7 @@ public:
uint16_t sc_card_ref, uint16_t sc_card_ref,
uint8_t random_percent, uint8_t random_percent,
EffectWhen when) const; EffectWhen when) const;
int32_t evaluate_effect_expr( int32_t evaluate_effect_expr(const AttackEnvStats& ast, const char* expr, DiceRoll& dice_roll) const;
const AttackEnvStats& ast,
const char* expr,
DiceRoll& dice_roll) const;
bool execute_effect( bool execute_effect(
Condition& cond, Condition& cond,
std::shared_ptr<Card> card, std::shared_ptr<Card> card,
@@ -208,25 +174,13 @@ public:
uint16_t set_card_ref, uint16_t set_card_ref,
uint8_t def_effect_index) const; uint8_t def_effect_index) const;
Condition* find_condition_with_parameters( Condition* find_condition_with_parameters(
std::shared_ptr<Card> card, std::shared_ptr<Card> card, ConditionType cond_type, uint16_t set_card_ref, uint8_t def_effect_index) const;
ConditionType cond_type,
uint16_t set_card_ref,
uint8_t def_effect_index) const;
static void get_card1_loc_with_card2_opposite_direction( static void get_card1_loc_with_card2_opposite_direction(
Location* out_loc, Location* out_loc, std::shared_ptr<const Card> card1, std::shared_ptr<const Card> card2);
std::shared_ptr<const Card> card1,
std::shared_ptr<const Card> card2);
uint16_t get_card_id_with_effective_range( 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; std::shared_ptr<const Card> card1, uint16_t default_card_id, std::shared_ptr<const Card> card2) const;
static void get_effective_ap_tp( static void get_effective_ap_tp(
StatSwapType type, StatSwapType type, int16_t* effective_ap, int16_t* effective_tp, int16_t hp, int16_t ap, int16_t tp);
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;
std::vector<std::shared_ptr<const Card>> get_targeted_cards_for_condition( std::vector<std::shared_ptr<const Card>> get_targeted_cards_for_condition(
uint16_t card_ref, uint16_t card_ref,
uint8_t def_effect_index, uint8_t def_effect_index,
@@ -244,18 +198,12 @@ public:
bool is_card_targeted_by_condition( bool is_card_targeted_by_condition(
const Condition& cond, const ActionState& as, std::shared_ptr<const Card> card) const; 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); void on_card_set(std::shared_ptr<PlayerState> ps, uint16_t card_ref);
const CardDefinition::Effect* original_definition_for_condition( const CardDefinition::Effect* original_definition_for_condition(const Condition& cond) const;
const Condition& cond) const;
bool card_ref_has_ability_trap(const Condition& eff) const; bool card_ref_has_ability_trap(const Condition& eff) const;
void send_6xB4x06_for_exp_change( void send_6xB4x06_for_exp_change(
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card, uint16_t attacker_card_ref, uint8_t dice_roll_value, bool unknown_p5) const;
uint16_t attacker_card_ref, void send_6xB4x06_for_card_destroyed(std::shared_ptr<const Card> destroyed_card, uint16_t attacker_card_ref) const;
uint8_t dice_roll_value, uint16_t send_6xB4x06_if_card_ref_invalid(uint16_t card_ref, int16_t value) const;
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( void send_6xB4x06_for_stat_delta(
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card,
uint16_t attacker_card_ref, uint16_t attacker_card_ref,
@@ -268,19 +216,14 @@ public:
std::shared_ptr<const Card> card, std::shared_ptr<const Card> card,
uint16_t target_card_ref, uint16_t target_card_ref,
uint16_t sc_card_ref) const; uint16_t sc_card_ref) const;
bool should_return_card_ref_to_hand_on_destruction( bool should_return_card_ref_to_hand_on_destruction(uint16_t card_ref) const;
uint16_t card_ref) const;
size_t sum_last_attack_damage( size_t sum_last_attack_damage(
std::vector<std::shared_ptr<const Card>>* out_cards, std::vector<std::shared_ptr<const Card>>* out_cards, int32_t* out_damage_sum, size_t* out_damage_count) const;
int32_t* out_damage_sum,
size_t* out_damage_count) const;
void update_condition_orders(std::shared_ptr<Card> card); void update_condition_orders(std::shared_ptr<Card> card);
int16_t max_all_attack_bonuses(size_t* out_count) const; int16_t max_all_attack_bonuses(size_t* out_count) const;
void apply_effects_after_card_move(std::shared_ptr<Card> card); void apply_effects_after_card_move(std::shared_ptr<Card> card);
void check_for_defense_interference( void check_for_defense_interference(
std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> attacker_card, std::shared_ptr<Card> target_card, int16_t* inout_unknown_p4);
std::shared_ptr<Card> target_card,
int16_t* inout_unknown_p4);
void evaluate_and_apply_effects( void evaluate_and_apply_effects(
EffectWhen when, EffectWhen when,
uint16_t set_card_ref, uint16_t set_card_ref,
@@ -294,20 +237,19 @@ public:
ConditionType exclude_cond = ConditionType::NONE, ConditionType exclude_cond = ConditionType::NONE,
AssistEffect include_eff = AssistEffect::NONE, AssistEffect include_eff = AssistEffect::NONE,
AssistEffect exclude_eff = AssistEffect::NONE) const; AssistEffect exclude_eff = AssistEffect::NONE) const;
void clear_invalid_conditions_on_card( void clear_invalid_conditions_on_card(std::shared_ptr<Card> card, const ActionState& as);
std::shared_ptr<Card> card, const ActionState& as); void on_card_destroyed(std::shared_ptr<Card> attacker_card, std::shared_ptr<Card> destroyed_card);
void on_card_destroyed( std::vector<std::shared_ptr<const Card>> find_cards_in_hp_range(int16_t min, int16_t max) const;
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_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_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_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> sc_card_for_client_id(uint8_t client_id) const;
std::shared_ptr<const Card> get_attacker_card(const ActionState& as) 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>> 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( std::vector<std::shared_ptr<const Card>> filter_cards_by_range(
const std::vector<std::shared_ptr<const Card>>& cards, const std::vector<std::shared_ptr<const Card>>& cards,
std::shared_ptr<const Card> card1, std::shared_ptr<const Card> card1,
@@ -334,10 +276,8 @@ public:
void apply_effects_before_attack(std::shared_ptr<Card> card); void apply_effects_before_attack(std::shared_ptr<Card> card);
void apply_effects_after_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); bool client_has_atk_dice_boost_condition(uint8_t client_id);
void unknown_8024A6DC( void unknown_8024A6DC(std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3);
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;
std::vector<std::shared_ptr<const Card>> find_all_sc_cards_of_class(
CardClass card_class) const;
private: private:
std::weak_ptr<Server> w_server; 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
+24 -33
View File
@@ -2,8 +2,6 @@
#include "Server.hh" #include "Server.hh"
using namespace std;
namespace Episode3 { namespace Episode3 {
NameEntry::NameEntry() { NameEntry::NameEntry() {
@@ -92,8 +90,7 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
auto& entry = this->entries[index]; auto& entry = this->entries[index];
if (entry.state == CardState::DISCARDED) { if (entry.state == CardState::DISCARDED) {
// If the card is discarded, then it should be before the draw index, and we // If the card is discarded, then it should be before the draw index, and we can just change its state.
// can just change its state.
entry.state = CardState::IN_HAND; entry.state = CardState::IN_HAND;
return true; return true;
} }
@@ -102,9 +99,8 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
return false; return false;
} }
// If the card is still drawable, we need to move it so it's just in front of // If the card is still drawable, we need to move it so it's just in front of the draw index, then immediately draw
// the draw index, then immediately draw it. Ep3 NTE does not handle this // it. Ep3 NTE does not handle this case, but we do even when playing NTE.
// case, but we do even when playing NTE.
size_t ref_index; size_t ref_index;
for (ref_index = 0; ref_index < this->card_refs.size(); ref_index++) { for (ref_index = 0; ref_index < this->card_refs.size(); ref_index++) {
if (this->card_refs[ref_index] == card_ref) { 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) { if (card_ref == 0xFFFF) {
return 0xFFFF; return 0xFFFF;
} }
uint8_t index = index_for_card_ref(card_ref); uint8_t index = index_for_card_ref(card_ref);
if (index < this->entries.size()) { return (index < this->entries.size()) ? this->entries[index].card_id : 0xFFFF;
return this->entries[index].card_id;
} else {
return 0xFFFF;
}
} }
uint16_t DeckState::sc_card_id() const { 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 // For any cards that are still in hand or still in play, move their refs to the already-drawn part of the deck
// the already-drawn part of the deck
this->draw_index = 0; this->draw_index = 0;
for (size_t z = 0; z < this->entries.size(); z++) { for (size_t z = 0; z < this->entries.size(); z++) {
if (this->entries[z].state != CardState::DRAWABLE) { if (this->entries[z].state != CardState::DRAWABLE) {
@@ -187,7 +177,7 @@ void DeckState::restart() {
this->shuffle(); this->shuffle();
} }
void DeckState::do_mulligan(bool is_nte) { void DeckState::redraw_initial_hand(bool is_nte) {
for (size_t z = 0; z < this->entries.size(); z++) { for (size_t z = 0; z < this->entries.size(); z++) {
if (this->entries[z].state == CardState::DISCARDED) { if (this->entries[z].state == CardState::DISCARDED) {
this->entries[z].state = CardState::DRAWABLE; this->entries[z].state = CardState::DRAWABLE;
@@ -196,8 +186,7 @@ void DeckState::do_mulligan(bool is_nte) {
this->draw_index = 1; this->draw_index = 1;
if (is_nte || this->shuffle_enabled) { if (is_nte || this->shuffle_enabled) {
// Get the next 5 cards from the deck, and put the previous 5 cards after // Get the next 5 cards from the deck, and put the previous 5 cards after them (so they will be shuffled back in).
// them (so they will be shuffled back in).
for (uint8_t z = 0; z < 5; z++) { for (uint8_t z = 0; z < 5; z++) {
uint8_t index = z + this->draw_index; uint8_t index = z + this->draw_index;
uint16_t temp_ref = this->card_refs[index]; uint16_t temp_ref = this->card_refs[index];
@@ -207,7 +196,7 @@ void DeckState::do_mulligan(bool is_nte) {
auto s = this->server.lock(); auto s = this->server.lock();
if (!s) { 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). // 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) { if (this->shuffle_enabled) {
auto s = this->server.lock(); auto s = this->server.lock();
if (!s) { if (!s) {
throw runtime_error("server is missing"); throw std::runtime_error("server is missing");
} }
size_t max = this->num_drawable_cards(); size_t max = this->num_drawable_cards();
for (size_t z = 0; z < this->card_refs.size(); z++) { for (size_t z = 0; z < this->card_refs.size(); z++) {
// Note: This is the way Sega originally implemented shuffling - they just // Note: This is the way Sega originally implemented shuffling - they just do N swaps on the entire array. A more
// do N swaps on the entire array. A more uniform way to do it would be to // uniform way to do it would be to instead swap each item with another random item (possibly itself) that
// 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.
// 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 index1 = this->draw_index + s->get_random(max);
uint8_t index2 = 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]; uint16_t temp_ref = this->card_refs[index1];
@@ -308,23 +295,27 @@ static const char* name_for_card_state(DeckState::CardState st) {
} }
void DeckState::print(FILE* stream, std::shared_ptr<const CardIndex> card_index) const { void DeckState::print(FILE* stream, std::shared_ptr<const CardIndex> card_index) const {
fprintf(stream, "DeckState: client_id=%hhu draw_index=%hhu card_ref_base=@%04hX shuffle=%s loop=%s\n", 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++) { for (size_t z = 0; z < 31; z++) {
const auto& e = this->entries[z]; const auto& e = this->entries[z];
shared_ptr<const CardIndex::CardEntry> ce; std::shared_ptr<const CardIndex::CardEntry> ce;
if (card_index) { if (card_index) {
try { try {
ce = card_index->definition_for_id(e.card_id); ce = card_index->definition_for_id(e.card_id);
} catch (const out_of_range&) { } catch (const std::out_of_range&) {
} }
} }
if (ce) { if (ce) {
string name = ce->def.en_name.decode(1); phosg::fwrite_fmt(stream, " ({:02}) index={:02X} ref=@{:04X} card_id=#{:04X} \"{}\" {}\n",
fprintf(stream, " (%02zu) index=%02hhX ref=@%04hX card_id=#%04hX \"%s\" %s\n", z, e.deck_index, this->card_refs[z], e.card_id, ce->def.en_name.decode(Language::ENGLISH),
z, e.deck_index, this->card_refs[z], e.card_id, name.c_str(), name_for_card_state(e.state)); name_for_card_state(e.state));
} else { } else {
fprintf(stream, " (%02zu) index=%02hhX ref=@%04hX card_id=#%04hX %s\n", 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)); z, e.deck_index, this->card_refs[z], e.card_id, name_for_card_state(e.state));
} }
} }
+4 -8
View File
@@ -28,9 +28,8 @@ struct DeckEntry {
/* 00 */ pstring<TextEncoding::MARKED, 0x10> name; /* 00 */ pstring<TextEncoding::MARKED, 0x10> name;
/* 10 */ le_uint32_t team_id; /* 10 */ le_uint32_t team_id;
/* 14 */ parray<le_uint16_t, 31> card_ids; /* 14 */ parray<le_uint16_t, 31> card_ids;
// If the following flag is not set to 3, then the God Whim assist effect can // If the following flag is not set to 3, then the God Whim assist effect can use cards that are hidden from the
// use cards that are hidden from the player during deck building. The client // player during deck building. The client always sets this to 3, and it's not clear why this even exists.
// always sets this to 3, and it's not clear why this even exists.
/* 52 */ uint8_t god_whim_flag; /* 52 */ uint8_t god_whim_flag;
/* 53 */ uint8_t unused1; /* 53 */ uint8_t unused1;
/* 54 */ le_uint16_t player_level; /* 54 */ le_uint16_t player_level;
@@ -56,10 +55,7 @@ public:
}; };
template <typename CardIDT> template <typename CardIDT>
DeckState( DeckState(uint8_t client_id, const parray<CardIDT, 0x1F>& card_ids, std::shared_ptr<Server> server)
uint8_t client_id,
const parray<CardIDT, 0x1F>& card_ids,
std::shared_ptr<Server> server)
: server(server), : server(server),
client_id(client_id), client_id(client_id),
draw_index(1), draw_index(1),
@@ -96,7 +92,7 @@ public:
void restart(); void restart();
void shuffle(); void shuffle();
void do_mulligan(bool is_nte); void redraw_initial_hand(bool is_nte);
void print(FILE* stream, std::shared_ptr<const CardIndex> card_index = nullptr) const; void print(FILE* stream, std::shared_ptr<const CardIndex> card_index = nullptr) const;
+2 -4
View File
@@ -1,7 +1,5 @@
#include "MapState.hh" #include "MapState.hh"
using namespace std;
namespace Episode3 { namespace Episode3 {
MapState::MapState() { MapState::MapState() {
@@ -20,11 +18,11 @@ void MapState::clear() {
} }
void MapState::print(FILE* stream) const { void MapState::print(FILE* stream) const {
fprintf(stream, "[Map: w=%hu h=%hu]\n", this->width.load(), this->height.load()); phosg::fwrite_fmt(stream, "[Map: w={} h={}]\n", this->width, this->height);
for (size_t y = 0; y < this->height; y++) { for (size_t y = 0; y < this->height; y++) {
fputc(' ', stream); fputc(' ', stream);
for (size_t x = 0; x < this->width; x++) { for (size_t x = 0; x < this->width; x++) {
fprintf(stream, " %02hhX", this->tiles[y][x]); phosg::fwrite_fmt(stream, " {:02X}", this->tiles[y][x]);
} }
fputc('\n', stream); fputc('\n', stream);
} }

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