Compare commits

..

481 Commits

Author SHA1 Message Date
Martin Michelsen d08aaef0f8 add remote address to command log messages 2024-04-21 15:19:16 -07:00
Martin Michelsen 245df782b9 fix v2 battle record init sequence 2024-04-21 01:27:29 -07:00
Martin Michelsen 9ffe429a1f implement ban/unban accounts via the shell 2024-04-21 01:14:10 -07:00
Martin Michelsen 673c767a42 add random stream into Ep3 battle records 2024-04-21 01:14:10 -07:00
Martin Michelsen de42135532 implement IPv4 range bans 2024-04-21 01:14:10 -07:00
Martin Michelsen 79bf6b3fa9 fix rendering issue in readme 2024-04-20 14:31:41 -07:00
Martin Michelsen 741456d1da organize system/client-functions 2024-04-20 10:51:48 -07:00
Martin Michelsen c95b158e4e add decrypt/encrypt for simple DCv2 executable encryption 2024-04-20 10:51:48 -07:00
Martin Michelsen d40c260d18 fix infinite loop in determine_first_team_turn 2024-04-17 11:36:32 -07:00
Martin Michelsen 454e0e558b clean up notes directory 2024-04-17 08:30:00 -07:00
Martin Michelsen 5ea49425c7 don't fail on proxy server if maps don't load properly 2024-04-17 00:39:26 -07:00
Martin Michelsen 08ea9403e9 add encrypt/decrypt actions for DCv2 executables 2024-04-17 00:37:57 -07:00
Martin Michelsen f01882db39 improve PRS disassembly output 2024-04-17 00:37:30 -07:00
Martin Michelsen 1870273f89 add further learnings about Ep3 B9 command 2024-04-15 22:53:14 -07:00
Martin Michelsen d6edf1b24d set up framework for DC patching 2024-04-14 22:20:28 -07:00
Martin Michelsen 8ecbe6798d fix --config option to less-common commands 2024-04-14 20:58:55 -07:00
Martin Michelsen 587ad1933d add DC 50Hz sub_versions 2024-04-14 20:57:45 -07:00
Martin Michelsen 70548aef04 move Ep3 recording finalization to CA command handler 2024-04-14 13:56:24 -07:00
Martin Michelsen 43663cbe79 add missing include on linux 2024-04-12 22:24:04 -07:00
Martin Michelsen 5f2e7e543b fix some patch metadata 2024-04-12 22:17:16 -07:00
Martin Michelsen c98d1081a3 add support for auto-patching 2024-04-12 22:17:16 -07:00
Martin Michelsen 0b2272bfa7 don't show non-unique team rewards in purchased list 2024-04-12 22:09:52 -07:00
Martin Michelsen 04982d919c fix 11/2000 set data table 2024-04-12 22:09:52 -07:00
Martin Michelsen 34751f99e9 allow multiple licenses per account 2024-04-12 22:09:52 -07:00
Martin Michelsen 40d5c6ee64 fix --config option to non-server actions 2024-04-07 14:40:18 -07:00
Martin Michelsen be0b70f903 use existing test config for load-maps-test 2024-04-07 13:35:29 -07:00
Martin Michelsen 76aeacfdfd fix permission on custom-sji test input 2024-04-07 13:34:06 -07:00
Martin Michelsen dec979fb52 fix custom-sjis test 2024-04-07 13:13:58 -07:00
Martin Michelsen 1c85d46436 add load-maps test 2024-04-07 13:04:08 -07:00
Martin Michelsen f05dc6d9f9 handle PSO font characters properly 2024-04-07 13:03:11 -07:00
Martin Michelsen e141642dd6 fix episode field in game list command 2024-04-06 22:58:53 -07:00
Martin Michelsen af4d3a3325 implement full character backups on GC 2024-04-06 19:52:22 -07:00
Martin Michelsen 91131f8b36 update notes on xb bugfix patch 2024-04-02 22:22:09 -07:00
Martin Michelsen b2ea059fd8 add xb reticle color patches 2024-04-02 22:21:21 -07:00
Martin Michelsen 150acda1ea add union field team reward 2024-04-02 00:01:15 -07:00
Martin Michelsen 3e1449bb80 add team size field for union field 2024-04-02 00:01:05 -07:00
Martin Michelsen 4c104443bc fix non-unique team rewards 2024-04-01 23:31:55 -07:00
Martin Michelsen de8a210d0f add debug messages for wave events and switch flags 2024-04-01 23:28:41 -07:00
Martin Michelsen 9d2b36b787 add idle disconnect patch 2024-04-01 21:50:39 -07:00
Martin Michelsen 03b78c3825 add WIP XB bugfixes patch 2024-04-01 21:50:39 -07:00
Matt 3c8674dcc7 Provide updated Teth client links (#1)
This adds archive links to updated Teth clients to make set up work with newserv more seamlessly. The Teth clients linked:

- Have map files for Coren
- Have fixed unitxt_e.prs and unitxt_j.prs files so no "Revival Curiass" error
- Connect to 127.0.0.1 by default for the common use case of local server on same machine
- Japanese client has had the version string changed to "JTethVer12513" so it doesn't get overriden to English

I will probably update these archives in the future to use the English files properly with the English client but for now this will make things just work in the mean time hopefully.
2024-04-01 19:22:03 -07:00
Martin Michelsen 95919b8b01 add xbox hungry mag sound patch 2024-03-31 17:59:18 -07:00
Martin Michelsen 1712b13106 add link to original installer in readme 2024-03-31 16:49:35 -07:00
Martin Michelsen 50a32429be split rare announcement item sets by game version 2024-03-31 12:31:25 -07:00
Martin Michelsen 6f0124f7ec add $edit language 2024-03-31 11:59:21 -07:00
Martin Michelsen acbebaeb70 use scrolling message for rare and max level announcements on BB 2024-03-31 10:06:47 -07:00
Martin Michelsen d44b0b3d62 add max level notifications 2024-03-30 23:37:50 -07:00
Martin Michelsen 4a3b0118a8 replace UnlockAllAreas and PreventPersistQuestFlags with generalized rewrite map 2024-03-30 22:36:09 -07:00
Martin Michelsen 7c7df39e6d clarify BB behavior with UnlockAllAreas 2024-03-30 20:47:26 -07:00
Martin Michelsen dba49be1e3 add name for 6xB4x4A 2024-03-30 20:47:08 -07:00
Martin Michelsen 33483bbfbf handle duplicate set event IDs properly 2024-03-30 13:38:17 -07:00
Martin Michelsen 9630b06284 refine 6x68 structure 2024-03-30 13:37:50 -07:00
Martin Michelsen e6acea8247 add $swset, $swclear, and $swsetall 2024-03-29 21:08:42 -07:00
Martin Michelsen 2cd4c733ef switch item pickup notifs to explicit lists 2024-03-29 21:08:42 -07:00
Matt 05e5705537 Update ReceiveCommands.cc 2024-03-29 20:02:08 -07:00
Martin Michelsen 24e48b1abd write short readme section about accounts 2024-03-28 22:51:25 -07:00
Martin Michelsen 6d73cae91b fix desyncs if protected commands aren't supported by client 2024-03-28 22:50:57 -07:00
Martin Michelsen dd9bc51457 implement rare item pickup notifications 2024-03-28 21:44:05 -07:00
Martin Michelsen dce0f91678 highlight hit% if dropped weapon has positive bonus 2024-03-27 20:15:16 -07:00
Martin Michelsen eb5701ece9 update BB patch directory setup instructions 2024-03-26 14:00:48 -07:00
Martin Michelsen 6f99b3b1c8 run patch server on main thread on windows 2024-03-25 22:28:15 -07:00
Martin Michelsen da9765f1aa fix cleanup in compression test 2024-03-25 22:28:02 -07:00
Martin Michelsen b7897cddf2 show uncaught exception messages on windows 2024-03-24 22:00:22 -07:00
Martin Michelsen ce2300b116 add pessimal compression 2024-03-24 21:59:28 -07:00
Martin Michelsen cb05dce764 handle quest loading client bug 2024-03-24 15:43:35 -07:00
Martin Michelsen a762c0f8f8 make prev battle record const 2024-03-24 10:24:36 -07:00
Martin Michelsen cd008ab0ba rewrite DeckState::draw_card_by_ref 2024-03-23 21:02:00 -07:00
Martin Michelsen 53b36d7074 put an extra \n in choice search result text 2024-03-23 21:02:00 -07:00
Martin Michelsen 5a1880bd65 allow sender_c to be null in Ep3 server command handlers 2024-03-23 21:02:00 -07:00
Martin Michelsen 8e280a1464 fix wrong type in default ep3 behavior flags 2024-03-22 22:25:14 -07:00
Martin Michelsen 0bcdd9997e define choice_search_config in gc char file format 2024-03-22 22:25:04 -07:00
Martin Michelsen d5351c4580 set BB player mag color at char creation time 2024-03-22 22:24:45 -07:00
Martin Michelsen 76bc2385ca add PSOBB Hangame functions 2024-03-22 22:24:04 -07:00
Martin Michelsen 325f7c6efc add UnlockAllAreas config option 2024-03-18 10:03:37 -07:00
Martin Michelsen 93d97d3e5b factor out debug mode check 2024-03-17 21:16:31 -07:00
Martin Michelsen 66b64603a0 add $sb command 2024-03-17 19:03:24 -07:00
Martin Michelsen 7405eaea0b add format-ep3-battle-record command 2024-03-17 14:12:57 -07:00
Martin Michelsen 477e433361 update some command notes 2024-03-17 14:12:57 -07:00
Martin Michelsen 7ca2012bc4 add CA commands into Ep3 battle record format 2024-03-16 18:48:27 -07:00
Martin Michelsen dace165ef2 fix enemy data json in /y/data/common-tables 2024-03-16 18:45:35 -07:00
Martin Michelsen f6df2b5b45 add note about C4 crash 2024-03-16 18:45:11 -07:00
Martin Michelsen 1a310df17e fix choice search crash 2024-03-16 09:57:35 -07:00
Martin Michelsen 31edec701b refine game info messages 2024-03-15 22:59:50 -07:00
Martin Michelsen dc36d2ae8d fix quest expr checks from lobby 2024-03-15 10:20:19 -07:00
Martin Michelsen 4e733b0dc6 add object type name in map disassembly 2024-03-15 00:32:00 -07:00
Martin Michelsen 6eadaaca66 use pthreads for libevent on windows 2024-03-15 00:31:50 -07:00
Martin Michelsen d778340999 add BB format of 6x6F command 2024-03-15 00:31:33 -07:00
Martin Michelsen e2d76f77be extend switch assist to 4-player doors 2024-03-14 00:14:40 -07:00
Martin Michelsen 0b80af3f41 fix format code in event action stream disassembly 2024-03-13 22:04:39 -07:00
Martin Michelsen f65acda803 reorder initializers in Map::Object construction 2024-03-13 10:06:07 -07:00
Martin Michelsen 53f485b8f2 fix variable overshadow in 6x6F queued case 2024-03-13 09:53:47 -07:00
Martin Michelsen 69f40f9157 extend persistence to enemy, set, and switch flags 2024-03-12 23:43:08 -07:00
Martin Michelsen 84bb946e05 fix error message for bad entry in trap card list 2024-03-12 20:15:53 -07:00
Martin Michelsen eb132f38d2 fix Ep3 map formatting bug 2024-03-12 20:15:53 -07:00
Martin Michelsen 0f1fbb1069 fix infinite loop edge case in text transcoding 2024-03-12 12:09:12 -07:00
Martin Michelsen c9f7ca2259 add BULK and DEATH_GUNNER to rare tables 2024-03-10 15:21:29 -07:00
Martin Michelsen 8594e5af3c add condition clearing and auto-revive to infinite hp mode 2024-03-10 12:07:30 -07:00
Martin Michelsen 6b5e657630 make name colors appear correctly in v2/v3 crossplay 2024-03-10 12:07:30 -07:00
Martin Michelsen a7845e4b0e add logging for p36 target mode in Ep3 2024-03-10 12:07:30 -07:00
Martin Michelsen c0624334c4 fix format width in log messages 2024-03-09 11:59:48 -08:00
Martin Michelsen 34bac4c5b5 add enemy, object, and event tracking for persistence 2024-03-09 11:28:49 -08:00
Martin Michelsen b81385efdb add TODO for item table serialization 2024-03-09 09:56:49 -08:00
Martin Michelsen 2aae90e65a add option to use game creator section ID 2024-03-09 09:45:20 -08:00
Martin Michelsen 64f2cb8f9e add ServerGlobalDropRateMultiplier 2024-03-09 09:21:36 -08:00
Martin Michelsen 2820b8866c update readme for $secid change 2024-03-08 21:24:30 -08:00
Martin Michelsen a39881fa89 change game section ID on leader change 2024-03-08 21:19:56 -08:00
Martin Michelsen 9d4116f035 fix size field when forwarding 6x7C 2024-03-08 14:31:14 -08:00
Martin Michelsen 287296cf48 fix PCv2 6x7C command 2024-03-08 13:42:54 -08:00
Martin Michelsen b491a57f57 don't load maps for ep3 games on proxy server 2024-03-08 09:17:23 -08:00
Martin Michelsen 19e7f1c677 add confirmation for clear license action 2024-03-08 00:02:50 -08:00
Martin Michelsen 8a7e19757a add --multiply option to convert-rare-item-set 2024-03-07 22:51:32 -08:00
Martin Michelsen 70c57e7727 add V_V1Present token in quest conditions 2024-03-07 21:18:51 -08:00
Martin Michelsen 4a8415308e support extended attributes in json rare tables 2024-03-07 20:52:40 -08:00
Martin Michelsen 0e3df10fc0 print Devolution phone numbers during startup 2024-03-06 13:03:10 -08:00
Martin Michelsen 33b95015a2 add option to override name colors by game version 2024-03-06 13:03:10 -08:00
Martin Michelsen 2ecef68a72 update option_flags description 2024-03-06 12:49:03 -08:00
Martin Michelsen 0db0a55e6b update Ep3 lobby banner instructions 2024-03-06 09:53:48 -08:00
Martin Michelsen 0aedfcc17f don't let exceptions fall out of reload config 2024-03-05 10:11:15 -08:00
Martin Michelsen 581f95051d filter solo-extra quests by episode for consistency 2024-03-05 08:52:32 -08:00
Martin Michelsen 31005ec39d add option to disable chat commands 2024-03-04 22:48:05 -08:00
Martin Michelsen b0b3bb6140 fix NPC last-hit EXP 2024-03-04 21:50:48 -08:00
Martin Michelsen 7e4bc52d99 enable episode filter flag on solo-story category 2024-03-04 21:50:48 -08:00
Martin Michelsen b9f1a1d964 add commands for announcements via Simple Mail 2024-03-04 19:59:21 -08:00
Martin Michelsen a48f79eafa auto-port several codes 2024-03-04 19:47:17 -08:00
Martin Michelsen 907c4fda3c add poison room test 2024-03-04 09:21:30 -08:00
Martin Michelsen 3189b71d46 fix 6x2F client ID check 2024-03-03 23:34:24 -08:00
Martin Michelsen 6ae08e9b05 update event metadata for quests 2024-03-03 23:22:40 -08:00
Martin Michelsen 7cd5aa1c2d fix event lookups in quest availability expressions 2024-03-03 23:15:57 -08:00
Martin Michelsen 6d6a8621bb fix per-lobby events in config.json 2024-03-03 23:15:35 -08:00
Martin Michelsen db254a977b fix long credentials on 11/2000 2024-03-03 22:36:12 -08:00
Martin Michelsen 454bcf107b add DC NTE format for 6x06 command 2024-03-03 22:33:55 -08:00
Martin Michelsen 52688982ea use MARKED encoding for info board 2024-03-03 21:32:56 -08:00
Martin Michelsen 2432d8b32b handle JP heart symbol correctly 2024-03-03 21:24:13 -08:00
Martin Michelsen 7f71b87b9b add $variations command 2024-03-03 21:01:41 -08:00
Martin Michelsen 4faad54872 split team points update 2024-03-02 18:38:31 -08:00
Martin Michelsen e2da4322e2 fix name field in BB 6x70 2024-03-02 16:52:23 -08:00
Martin Michelsen f44706570a alias ep3 item indexes to v3 index 2024-03-02 11:00:54 -08:00
Martin Michelsen b452b11854 handle GC_NTE 6x7C properly 2024-03-02 10:55:53 -08:00
Martin Michelsen f2b5f0950f fix describe-item action 2024-03-02 10:55:40 -08:00
Martin Michelsen f43563edb3 add full versions in get_cli_version 2024-03-02 10:54:59 -08:00
Martin Michelsen bec6d741d4 fix gc nte mag encoding 2024-03-02 10:54:47 -08:00
Martin Michelsen d93e6405c3 fix v1-encoded item descriptions 2024-03-01 23:19:18 -08:00
Martin Michelsen a2e3f4882d make quest episode filter configurable 2024-03-01 21:22:14 -08:00
Martin Michelsen ef101894d1 update solo story quest flag expressions 2024-03-01 20:52:09 -08:00
Martin Michelsen 6eb896f83d clean up some is_nte flags in ep3 server 2024-03-01 19:51:47 -08:00
Martin Michelsen c7812bf764 make bcarray not packed 2024-02-29 23:33:31 -08:00
Martin Michelsen 11f49af6f9 fix using incorrect card object in 59:SLAYERS_ASSASSINS 2024-02-29 22:49:06 -08:00
Martin Michelsen af1c51b2b5 fix v1 unidentified item logic 2024-02-29 21:28:15 -08:00
Martin Michelsen f7c63d82f9 fix material usage on GC NTE 2024-02-29 19:25:14 -08:00
Martin Michelsen a00c25ee17 port vip card patch to all ep3 versions 2024-02-29 09:54:38 -08:00
Martin Michelsen 913f7d04f7 fix non-Japanese encoding in Episode 3 maps 2024-02-28 21:57:25 -08:00
Martin Michelsen b37224a453 add asan definition in comments 2024-02-28 21:53:54 -08:00
Martin Michelsen 8375c61236 add some tools for ep3 replay 2024-02-28 21:08:04 -08:00
Martin Michelsen 424f191bc6 ignore client's equip slot if item can't be equipped in it 2024-02-28 19:52:15 -08:00
Martin Michelsen 90152b4138 add TODO for proxy meet user extension 2024-02-28 19:49:02 -08:00
Martin Michelsen c8041558f5 fix Poison Lily rare check 2024-02-28 19:49:02 -08:00
Martin Michelsen 1f10d03923 describe 6x6B and 6x6C more completely 2024-02-28 19:49:02 -08:00
Martin Michelsen bb560c1153 add XBOX-US1 handlers 2024-02-28 19:38:36 -08:00
Martin Michelsen 72794ad50e write xb decoction patch 2024-02-27 23:07:35 -08:00
Martin Michelsen af1c0a548d add map event files 2024-02-27 00:14:15 -08:00
Martin Michelsen 2f5d547c19 delay all new TCP PSH frames until timeout or ACK is received 2024-02-26 20:28:38 -08:00
Martin Michelsen 32f056c6eb add HTTP /y/data/common-tables 2024-02-26 20:07:28 -08:00
Martin Michelsen ac62cc455c add more xbox patches 2024-02-25 21:55:25 -08:00
Martin Michelsen 79f85f46dc add xbe patch translator shell 2024-02-25 21:40:58 -08:00
Martin Michelsen e2e5875c8d fix xb item loss patches 2024-02-25 10:55:18 -08:00
Martin Michelsen 3868a9fc50 fix eu xb movement patches 2024-02-25 10:23:55 -08:00
Martin Michelsen 28cb1c52b5 support full DC NTE credentials 2024-02-24 22:49:37 -08:00
Martin Michelsen 70325793d9 add missing include on linux 2024-02-24 22:00:58 -08:00
Martin Michelsen a2d1eb4532 add non-US versions of XB item loss patch 2024-02-24 21:54:19 -08:00
Martin Michelsen b17ccd264a move HTTP server to separate thread 2024-02-24 21:53:17 -08:00
Martin Michelsen eaa02b2b78 add ep3 cards and rare tables to HTTP server 2024-02-24 19:13:18 -08:00
Martin Michelsen c3b3cf5140 add other projects to readme 2024-02-24 18:14:17 -08:00
Martin Michelsen 3be7b5f56b add PPPRawListen to example config 2024-02-24 18:03:14 -08:00
Martin Michelsen 14bf23c496 only send next TCP PSH if client's acked seq has changed 2024-02-24 10:24:03 -08:00
Martin Michelsen 5b79785c96 remove unused alias 2024-02-24 09:46:13 -08:00
Martin Michelsen f92fe61aa7 fix ep3 dice range override 2024-02-24 09:42:31 -08:00
Martin Michelsen b7c9fb3864 fix Japanese symbol chat name 2024-02-24 09:40:42 -08:00
Martin Michelsen 294d180e68 use system randomness by default unless overridden 2024-02-23 23:58:10 -08:00
Martin Michelsen 7dc5a02a83 bring back history section in readme 2024-02-23 23:58:10 -08:00
Martin Michelsen 82004b05dc add PPP_RAW protocol 2024-02-23 23:52:17 -08:00
Martin Michelsen a4f69f6ca3 add xbox movement patch 2024-02-23 23:52:17 -08:00
Martin Michelsen 66571d751f color unidentified weapon names in $what 2024-02-23 09:25:29 -08:00
Martin Michelsen 680a1a797c define some flags in 6x0A 2024-02-23 09:25:04 -08:00
Martin Michelsen 543bbb45dc add Xbox beta to handler-tables 2024-02-22 19:11:02 -08:00
Martin Michelsen 38504b3133 clear x bit on all files in system/ 2024-02-22 18:28:21 -08:00
Martin Michelsen f0d15be552 decompress PC NTE map files 2024-02-22 18:20:13 -08:00
Martin Michelsen 0383dc90b8 allow overriding stack sizes 2024-02-22 00:10:42 -08:00
Martin Michelsen 4e4ba5650d add B/T/K language markers 2024-02-20 22:59:53 -08:00
Martin Michelsen 29baaf2d95 fix loading long names on BB 2024-02-20 21:34:30 -08:00
Martin Michelsen 67e64d6836 update readme 2024-02-20 21:34:30 -08:00
Martin Michelsen af8c27dcef mark XB beta as tested 2024-02-20 21:31:02 -08:00
Martin Michelsen 163ec73c04 fix JP v1.3 D6 behavior 2024-02-20 20:47:07 -08:00
Martin Michelsen b74ad9d639 add Quest field in game summary JSON 2024-02-20 09:27:11 -08:00
Martin Michelsen 42c72b92ac fix some edge cases in GC NTE item creation 2024-02-19 23:22:22 -08:00
Martin Michelsen b46be572a6 enforce name length limit at edge only 2024-02-19 21:25:50 -08:00
Martin Michelsen 5d2d4cf2ad fix 6x70 transcoding between BB/non-BB 2024-02-19 21:21:01 -08:00
Martin Michelsen 2ba4224a83 add server info to api 2024-02-19 21:13:12 -08:00
Martin Michelsen 9687a0e522 split game flags in api according to game episode 2024-02-19 20:59:20 -08:00
Martin Michelsen cd77fae4e3 fix play time field and marked utf16 fields 2024-02-19 20:59:20 -08:00
Martin Michelsen f2f1007cee clarify $sropmode text a bit 2024-02-19 20:59:20 -08:00
Martin Michelsen db2c2a4774 implement $dropmode on proxy server 2024-02-18 22:41:42 -08:00
Martin Michelsen f16b8ef983 add HTTP server 2024-02-18 22:41:42 -08:00
Martin Michelsen bd13950ba6 fix system file updates when overlay is present 2024-02-18 10:05:25 -08:00
Martin Michelsen cda86e586d fix Dragon and De Rol Le drops on v1 2024-02-18 09:33:38 -08:00
Martin Michelsen 255878bf60 add $itemnotifs every mode 2024-02-18 09:33:21 -08:00
Martin Michelsen 1d42faac3e move patch servers to separate threads 2024-02-17 22:28:03 -08:00
Martin Michelsen 350a89f3da describe 6x7C command 2024-02-17 17:49:04 -08:00
Martin Michelsen 5bfda213c7 move shell to separate thread 2024-02-16 22:52:46 -08:00
Martin Michelsen d3d63dd36c fix battle table disconnect hook 2024-02-16 18:19:53 -08:00
Martin Michelsen 4dd7b75232 don't show item notifs option on ep3 2024-02-15 20:11:47 -08:00
Martin Michelsen 26abf2f306 update readme 2024-02-15 20:11:34 -08:00
Martin Michelsen 9ff7d6fff3 fix Ep3 NTE DEF die rules not working 2024-02-14 18:53:15 -08:00
Michael Stenberg 8c514a0688 fix/add GC NTE ClassMaxes 2024-02-14 08:33:38 -08:00
Martin Michelsen 08ba5d821b fix case where map selection is changed during setup 2024-02-13 21:37:15 -08:00
Martin Michelsen 35e2a9d6f4 use quest extended rules if present 2024-02-13 21:23:33 -08:00
Martin Michelsen 46e509aa69 fix segfault when attacks default back to SC 2024-02-11 21:39:17 -08:00
Martin Michelsen 198db59816 make invalid label index errors clearer 2024-02-11 15:50:53 -08:00
Martin Michelsen 46667bce46 fix 6xB4x3D NTE format 2024-02-11 15:50:38 -08:00
Martin Michelsen 639c1c3e95 add 06 phase to 93 notes 2024-02-11 15:50:28 -08:00
Martin Michelsen 07ebafa8c6 fix Ep3 NTE tournament menu bugs 2024-02-11 12:17:48 -08:00
Martin Michelsen f548fc04e2 make some text messages shorter 2024-02-11 10:54:16 -08:00
Martin Michelsen c55b19dbc0 fix $dicerange 2024-02-11 10:50:34 -08:00
Martin Michelsen c78c91d408 add Ep3 NTE AR codes 2024-02-11 10:49:55 -08:00
Martin Michelsen e07f65eec5 fix Ep3 NTE target replacement function 2024-02-10 21:53:21 -08:00
Martin Michelsen cfbbdc7216 add nop command in shell 2024-02-10 21:53:21 -08:00
Martin Michelsen cb34b350b0 fix Ep4 boss battle param indexes 2024-02-10 21:53:21 -08:00
Martin Michelsen 23f3bfabaa fix angle_x type in AttackData 2024-02-10 21:53:21 -08:00
Martin Michelsen b66069c10b name PlayerStats::esp 2024-02-10 21:53:21 -08:00
Martin Michelsen 093ba1fd38 replace $defrange with $dicerange 2024-02-10 14:29:37 -08:00
Martin Michelsen a312191ced add AllCards patch for Ep3 NTE 2024-02-10 12:29:54 -08:00
Martin Michelsen 841c722178 fix assembly of F_ARGS opcodes on pre-v3 2024-02-10 12:17:04 -08:00
Martin Michelsen 1ed2112bff update to-do list 2024-02-10 10:23:32 -08:00
Martin Michelsen d015406fa6 fix DEF die behavior not being editable in NTE 2024-02-10 10:06:22 -08:00
Martin Michelsen eea9eaf672 update tests for recording semantic change 2024-02-10 09:47:07 -08:00
Martin Michelsen c79e5017ad clear ep3 server state on 6F 2024-02-10 09:37:47 -08:00
Martin Michelsen c3d56f630e add Ep3 NTE COM decks 2024-02-10 00:44:51 -08:00
Martin Michelsen b1f419e337 use a more concise format for xb patches 2024-02-10 00:44:40 -08:00
Martin Michelsen 068ef68dd6 add sjis case for text set encode/decode 2024-02-10 00:44:28 -08:00
Martin Michelsen 51d74b092a add cases for Ep3 NTE cards HTML 2024-02-09 20:46:43 -08:00
Martin Michelsen 884a5ce75a replace is_trial with is_nte 2024-02-09 19:12:02 -08:00
Martin Michelsen d0c3e1b7d8 fix Ep3 NTE 6xB5 masking 2024-02-09 18:17:03 -08:00
Martin Michelsen 0fe28c021a add English code for Ep3 NTE 2024-02-09 18:17:03 -08:00
Martin Michelsen e6e599d760 don't send media updates to Ep3 NTE clients 2024-02-09 11:20:32 -08:00
Martin Michelsen 753c8da4bb update readme 2024-02-09 00:41:43 -08:00
Martin Michelsen 8165f240dc don't expect mask_key from Ep3 NTE 2024-02-09 00:40:12 -08:00
Martin Michelsen f98fae470b add Ep3 NTE differences notes 2024-02-09 00:09:34 -08:00
Martin Michelsen fcc274ce3e fix some bugs introduced by Ep3 NTE work 2024-02-09 00:06:05 -08:00
Martin Michelsen 47533e1a5f fix incorrect player state presence checks 2024-02-08 09:30:29 -08:00
Martin Michelsen 20f5a92d81 implement E1/E3 commands on NTE 2024-02-08 09:13:34 -08:00
Martin Michelsen dcea0e4520 use Ep3 NTE command formats 2024-02-08 01:02:23 -08:00
Martin Michelsen 729d9af4b0 Ep3 NTE checkpoint 5 2024-02-08 01:02:14 -08:00
Martin Michelsen 01afe12487 fix unusual unit modifiers 2024-02-07 23:21:25 -08:00
Martin Michelsen c57dc64950 add missing header 2024-02-07 10:28:29 -08:00
Martin Michelsen 07996444a1 fix download quests with PVR files 2024-02-07 10:23:37 -08:00
Martin Michelsen ba53f67097 Ep3 NTE checkpoint 4 2024-02-07 00:59:15 -08:00
Martin Michelsen 7fad72ef9c fix 4OEU item loss patch 2024-02-05 21:04:47 -08:00
Martin Michelsen 964f646654 fix enum/non-enum ternary 2024-02-05 08:38:01 -08:00
Martin Michelsen 7a23b37c0c Ep3 NTE battles checkpoint 3 2024-02-05 00:18:50 -08:00
Martin Michelsen bfd5c246de don't use 6x97 for challenge retries on BB 2024-02-04 17:13:43 -08:00
Martin Michelsen b89f18ce4e add fallthrough tag 2024-02-04 17:13:31 -08:00
Martin Michelsen 97cf9c5093 fix challenge overlays after retry on non-BB versions 2024-02-04 17:08:03 -08:00
Martin Michelsen c6e930b994 Ep3 NTE battles checkpoint 2 2024-02-04 17:08:03 -08:00
Martin Michelsen 611193610b add $itemnotifs on proxy server 2024-02-03 18:30:46 -08:00
Martin Michelsen 4c735d055e Ep3 NTE battles checkpoint 1 2024-02-03 18:30:45 -08:00
Martin Michelsen adb79e8a41 add description of why the F0 command exists 2024-02-03 18:30:45 -08:00
Martin Michelsen 0f4e4fa48e don't mask Ep3 NTE game commands 2024-02-03 18:30:45 -08:00
Martin Michelsen 5bf868e2aa fix warp command argument name 2024-02-03 18:30:45 -08:00
Matt Swift f6f5c358eb Add shared serials list in notes 2024-02-02 08:36:40 -08:00
Martin Michelsen 50f3ebca5e add support for shared serial mechanics 2024-02-01 21:28:35 -08:00
Martin Michelsen ef89699d59 accept misspelling of Greennill in chat commands 2024-01-31 20:35:00 -08:00
Martin Michelsen b6817e278a add $qgread and $qgwrite commands 2024-01-31 20:23:58 -08:00
Martin Michelsen 4830f5a41e fix battle area number normalization and add more structs/enums 2024-01-30 21:46:03 -08:00
Martin Michelsen 340fbb8ca5 add event conditions in quest visibility 2024-01-30 20:57:09 -08:00
Martin Michelsen 7aa05f39e2 rewrite non-server features section in readme 2024-01-30 19:12:48 -08:00
Martin Michelsen 5e2cc6f07f switch back to original GC versioning convention 2024-01-30 13:58:29 -08:00
Martin Michelsen 34f05e5162 remove debug print 2024-01-29 20:45:16 -08:00
Martin Michelsen d75891e78b add a few ways to customize lobbies 2024-01-28 23:33:55 -08:00
Martin Michelsen 9bf1114535 fix spectator team whisper logic 2024-01-28 16:09:59 -08:00
Martin Michelsen 9084910235 handle missing width/height values in decode-gci-snapshot 2024-01-26 20:44:09 -08:00
Martin Michelsen 33407f88d7 make client idle timeout configurable 2024-01-26 20:43:54 -08:00
Martin Michelsen 82854604b8 remove unnecessary check 2024-01-24 21:51:37 -08:00
Martin Michelsen 6ac2ceca45 remove 6x69 command 01 check 2024-01-24 21:09:01 -08:00
Martin Michelsen 082f88d242 use ESCAPE_CONTROLS_ONLY when writing JSON 2024-01-24 21:03:48 -08:00
Martin Michelsen 0fff4ebd4e enable JP BB ports by default 2024-01-24 14:29:41 -08:00
nolrinale 36a370078c Added original BB client ports to example config 2024-01-24 14:28:09 -08:00
nolrinale 1788aebd00 Added the correct unitxt_j for BB 2024-01-23 23:58:40 -08:00
Martin Michelsen 0de3d2737f update rarely-used and unused subcommand handlers 2024-01-23 23:53:52 -08:00
Martin Michelsen fc6b0992e9 add flags to subcommand handler table 2024-01-23 21:57:06 -08:00
Martin Michelsen 111d45220e add GC GameJam debug 6x handlers 2024-01-23 00:08:20 -08:00
Martin Michelsen fed1044813 add DC HL check note to TODO 2024-01-23 00:08:20 -08:00
Martin Michelsen 3b9c887dbe update credits on patches 2024-01-23 00:08:20 -08:00
Martin Michelsen 80a57f9d3e add xbox patch support 2024-01-21 22:36:52 -08:00
Martin Michelsen db3cecdd2b fix signed/unsigned comparison 2024-01-20 16:33:12 -08:00
Martin Michelsen e13b5950ca use SetDataTable files as map indexes 2024-01-20 16:19:29 -08:00
Martin Michelsen fe1d5a874a also disassemble x86 patches 2024-01-20 16:01:20 -08:00
Martin Michelsen ea76a537fd document 24-bit time_flags field 2024-01-18 22:54:11 -08:00
ShiftaDeband be0569d2cb Adjust loading maps for GC NTE 2024-01-17 18:08:52 -08:00
Martin Michelsen c5e8d2c77c document more Ep3 NTE differences 2024-01-16 22:27:36 -08:00
Martin Michelsen 408bc1befc fix team_dice_bonus variable names 2024-01-16 21:38:44 -08:00
Martin Michelsen 86e98fbfe5 add Ep3 NTE subsubcommand handlers 2024-01-16 21:38:44 -08:00
Martin Michelsen c85b3c144e fix falz/flow drop generation on v1/v2 2024-01-16 21:38:44 -08:00
Martin Michelsen 9311483932 fix 6x0A definition 2024-01-16 21:38:44 -08:00
Martin Michelsen c15e154846 implement challenge stage unlocks 2024-01-16 21:38:44 -08:00
Martin Michelsen 02e8f8ea8b disassemble quests during Save Files 2024-01-15 10:03:48 -08:00
Elixir70 31ddde6e80 Replace Blue Burst BP files with those from pub Teth to fix the small HP differences. 2024-01-15 09:52:27 -08:00
Martin Michelsen 4a23d86f56 fix output interleaving during rare enemy search 2024-01-13 09:48:00 -08:00
Martin Michelsen 1453cd4c9c cache decompressed dat files for quests 2024-01-13 09:47:43 -08:00
Martin Michelsen be8130b621 handle v1/v2 rare rates properly in map loader 2024-01-13 09:33:13 -08:00
Martin Michelsen 9e8f7a6c6b add mutex header 2024-01-13 00:01:25 -08:00
Martin Michelsen d052163a9e add brute-force search command for game seeds that result in rare enemies 2024-01-12 23:54:23 -08:00
Martin Michelsen f188ea1554 add Ep3 NTE battles to to-do list 2024-01-12 23:52:57 -08:00
Martin Michelsen a9894e2d05 fix GC JP 1.02 handler table entries 2024-01-12 23:52:42 -08:00
Martin Michelsen 0a60a24783 update handler-tables with XBOX-US0 2024-01-11 21:23:08 -08:00
Martin Michelsen d8f8dfc53f fix Ep3 NTE disconnect on leaving game 2024-01-11 20:56:17 -08:00
Martin Michelsen cc8dd77d51 fix double start label in quest disassembly 2024-01-11 20:51:14 -08:00
Martin Michelsen d5d85bf5d9 fix ItemCreator unit table on DC NTE and GC NTE 2024-01-11 12:38:12 -08:00
Martin Michelsen 2dff814e8f fix BB stream file symlinks 2024-01-10 22:18:08 -08:00
Martin Michelsen ad86acd8ef fix DCv1 ItemCreator constructor 2024-01-10 07:48:47 -08:00
Martin Michelsen 68be13dd62 write assemble-all-patches action 2024-01-09 21:50:08 -08:00
Martin Michelsen 9e0dfc7749 fix draw distance patch name 2024-01-09 21:50:08 -08:00
nolrinale 3747025a11 Recovered original Coren map files from SEGA 2024-01-09 20:56:39 -08:00
Martin Michelsen e5d4ae1f80 Revert "delete now-unused item name tables"
This reverts commit cbf4540602.
2024-01-09 18:45:40 -08:00
Martin Michelsen 07ea97a6ea update comment in 6x6D struct 2024-01-09 18:44:25 -08:00
Martin Michelsen 9a5d8f9d1a support already-encoded GVM files for Ep3 lobby banners 2024-01-08 20:58:30 -08:00
Martin Michelsen ad2312efee delete broken symlinks 2024-01-08 20:58:30 -08:00
Martin Michelsen dfe1944d2b don't use ItemRT.rel as a fallback 2024-01-08 20:43:32 -08:00
Martin Michelsen 695404165b add support for all versions in ItemParameterTable 2024-01-07 21:33:10 -08:00
Martin Michelsen d3bc2dad4f fix ep3 lobby banner descriptions 2024-01-07 21:22:36 -08:00
Martin Michelsen 194e408863 make $rarenotifs also notify on rare tools regardless of source 2024-01-07 10:36:32 -08:00
Martin Michelsen b2350a537d update build instructions in readme 2024-01-06 18:16:26 -08:00
Martin Michelsen ba4681e35d fix Ep3 NTE proxy sessions 2024-01-06 18:16:26 -08:00
Martin Michelsen 3b9684d8ac remove conditions only works on v1/v2 2024-01-06 18:16:25 -08:00
Martin Michelsen d32c5f1d61 fix show-ep3-maps action 2024-01-06 18:16:25 -08:00
Matt cf2c8f0699 Add English translation of Episode 3 Trial quest 2024-01-06 18:16:08 -08:00
Matt c8681bcf05 Update README.md 2024-01-06 11:52:10 -08:00
Matt fe256cff2a Update README.md 2024-01-06 11:52:10 -08:00
Matt 1df03c45f7 Update README.md 2024-01-06 11:52:10 -08:00
Matt 458e2ef0cd Update README.md 2024-01-06 11:52:10 -08:00
Martin Michelsen dd4284ab63 Update issue templates 2024-01-06 11:44:53 -08:00
Martin Michelsen 251cc80233 update issue templates 2024-01-05 16:35:50 -08:00
Martin Michelsen c6baed2d23 add revision and build date to logs 2024-01-05 16:30:22 -08:00
Martin Michelsen 90e2889204 fix various 6xC6 cases 2024-01-05 12:15:14 -08:00
Martin Michelsen ea4f6da48e update word select alias table 2024-01-05 11:59:33 -08:00
Martin Michelsen b69cf96aa9 fix flags on sync commands during game join 2024-01-05 11:59:20 -08:00
Martin Michelsen cbf4540602 delete now-unused item name tables 2024-01-05 10:34:19 -08:00
nolrinale 058d1ede54 Adjusted Coren init functions for EP2 2024-01-05 09:50:44 -08:00
Martin Michelsen d3c2a0bad0 minor cleanup 2024-01-05 00:15:46 -08:00
Martin Michelsen 83f5487e7b fix GC rare enemy logic 2024-01-04 23:09:09 -08:00
Martin Michelsen d3d89f0168 catch text encode/decode errors in more places 2024-01-04 21:46:27 -08:00
Martin Michelsen b7257a793f enforce min level limits when cheat mode is disabled 2024-01-04 17:31:41 -08:00
Martin Michelsen e50d7a4e65 fix mag feed result primary identifiers 2024-01-04 12:13:00 -08:00
Martin Michelsen 4be431471c rewrite game list filtering logic for BB 2024-01-04 11:49:56 -08:00
Martin Michelsen 649a7c9871 fix incorrect primary_identifier mask 2024-01-04 11:02:46 -08:00
Martin Michelsen 7fc3cca11b fix incorrect exception type during item identification 2024-01-04 10:58:34 -08:00
Martin Michelsen c9d7fe1c2a more minor encryption code cleanup 2024-01-04 10:42:25 -08:00
Martin Michelsen 612b5d28ba fix tech disk stacking on 11/2000 2024-01-04 10:39:18 -08:00
Martin Michelsen 70207896e3 clean up v2 encryption code 2024-01-03 23:28:29 -08:00
Martin Michelsen 08437844e4 add results of rare enemy RE 2024-01-03 23:28:29 -08:00
Martin Michelsen e13b220be9 support non-BB rare enemy generation logic 2024-01-03 23:28:29 -08:00
Martin Michelsen fccc0f7346 fix 0AE8 command 2024-01-03 21:01:39 -08:00
Martin Michelsen 1449bf090b fix item ID sync bug with Challenge grave recovery items 2024-01-03 21:01:39 -08:00
Martin Michelsen c9902e386f don't allow $defrange to override tournament rules 2024-01-03 10:28:31 -08:00
Martin Michelsen fb7d70c943 Merge pull request #311 from nolrinale/master
Techs & Options strings fixes for BB unitxt_e
2024-01-03 10:13:33 -08:00
Martin Michelsen e066c383a0 clean up rt_index logic on drop handler 2024-01-03 10:08:55 -08:00
Martin Michelsen 0e9f66f72e throw if Ep3 player start location not set 2024-01-03 09:40:43 -08:00
Martin Michelsen ec99dad874 fix typo in DC NTE variation definitions 2024-01-03 01:00:25 -08:00
Martin Michelsen b85fd4fced update DC NTE and 11/2000 variations list 2024-01-03 00:40:46 -08:00
Martin Michelsen 2050173666 fix incorrect ItemPT meseta ranges giving 65535 meseta 2024-01-03 00:29:35 -08:00
Martin Michelsen df29a60a6e load maps on all versions 2024-01-03 00:22:28 -08:00
Martin Michelsen 78e407a70f document sound subcommands 2024-01-02 22:32:13 -08:00
Martin Michelsen 04e2f94e2b add maps for all versions 2024-01-02 21:33:01 -08:00
nolrinale 4124f2714a added IME patch instructions for Tethealla client 2024-01-03 02:02:25 +01:00
nolrinale e21365db78 BB unitxt_e option setting string fixes 2024-01-02 00:16:50 +01:00
nolrinale dae7946526 Removed extra space from Tech Names for BB unitxt 2024-01-01 23:51:39 +01:00
Maria J. Belmonte 6a37a2de3d Merge branch 'fuzziqersoftware:master' into master 2024-01-01 23:18:19 +01:00
Martin Michelsen 4f650bebf0 fix disk name in BB unitxt_e 2024-01-01 13:57:46 -08:00
Maria J. Belmonte eb5827e059 Merge branch 'fuzziqersoftware:master' into master 2024-01-01 21:52:20 +01:00
Martin Michelsen 6917f40d3e 11/2000 also doesn't expect mag colors 2024-01-01 12:28:15 -08:00
Martin Michelsen efe2515a44 make generated mag colors random 2024-01-01 12:08:32 -08:00
Martin Michelsen c6ce39623e add config option to enable rare notifs by default 2024-01-01 11:30:30 -08:00
Martin Michelsen 962ee6874e fix tool item stackability on 11/2000 2024-01-01 11:22:03 -08:00
Martin Michelsen 2fda85c750 restrict rare notifs to items generated from ItemRT 2024-01-01 10:24:18 -08:00
Martin Michelsen f1e00ccf0e fix crashes in some non-server actions 2024-01-01 00:05:19 -08:00
Martin Michelsen 09b7885013 fix common cross-version lobby counter animation mismatch 2023-12-31 23:55:00 -08:00
Martin Michelsen e126015b5f don't use specific initializer in StepGraph 2023-12-31 22:37:35 -08:00
Martin Michelsen 4ff4c86047 add ability to specify listening interfaces 2023-12-31 22:21:00 -08:00
Martin Michelsen cd4a8050d7 fix word select data filenames 2023-12-31 21:58:32 -08:00
Martin Michelsen c09bd56e19 add $rarenotifs command 2023-12-31 21:56:41 -08:00
Martin Michelsen 6945a55584 re-record DC NTE game smoke test 2023-12-31 21:28:26 -08:00
Martin Michelsen 32c79a7b6a fix 6x70 handling during replay sessions 2023-12-31 21:28:26 -08:00
Martin Michelsen 57f47f147a silently skip .DS_Store files when indexing quests 2023-12-31 21:28:26 -08:00
Martin Michelsen 6a65940720 remove magic numbers in version arrays 2023-12-31 21:28:26 -08:00
Martin Michelsen 40dcbb77ad fix incorrect next item IDs in synthesized 6x6D commands 2023-12-31 21:28:26 -08:00
Martin Michelsen f479f586cb rewrite ServerState dependency management 2023-12-31 21:28:26 -08:00
Martin Michelsen a24d0ad703 rewrite ItemNameIndex and index all game text 2023-12-31 21:28:26 -08:00
Martin Michelsen ac39db2f36 fix 6x6D synthesis for persistent games 2023-12-31 00:31:04 -08:00
Martin Michelsen 9b4da7e3b3 add stat_boost field in ItemParameterTable::WeaponV2 2023-12-30 20:45:37 -08:00
Martin Michelsen 1f1f4bd815 set up test harness for ep3 server log replays 2023-12-30 18:48:37 -08:00
Maria J. Belmonte 00258d4607 Merge branch 'fuzziqersoftware:master' into master 2023-12-31 00:48:57 +01:00
Martin Michelsen 3aaaf0353e use player-visible client IDs in $setassist command 2023-12-30 15:20:53 -08:00
Martin Michelsen f54d7b0476 add $setassist command 2023-12-30 15:18:42 -08:00
Martin Michelsen 111260cdf3 clean up challenge mode template syntax 2023-12-30 12:15:50 -08:00
Martin Michelsen 91c8cba0d2 make it easier to debug mag evolution bugs 2023-12-30 12:15:50 -08:00
Martin Michelsen 0f8dcd3713 fix incorrect left photon blast assignment bug 2023-12-30 12:14:05 -08:00
Martin Michelsen e89802f288 add option to use temporary licenses for NTE versions 2023-12-30 11:30:43 -08:00
Martin Michelsen c1ac34c1f7 update word select alias table 2023-12-30 09:28:35 -08:00
Martin Michelsen c74a931986 fix platform-dependent test case 2023-12-30 00:57:08 -08:00
Martin Michelsen 686bae25f3 remove unused word select table 2023-12-30 00:52:13 -08:00
Martin Michelsen ff5d0af7ad clang-format Main.cc 2023-12-30 00:51:58 -08:00
Martin Michelsen 8518349cce fix BB name encoding bug 2023-12-30 00:48:34 -08:00
Martin Michelsen 818204a93f rewrite word select table to support all versions 2023-12-30 00:48:20 -08:00
Martin Michelsen eea12d8d75 make cross-joins more compatible 2023-12-29 16:27:22 -08:00
Martin Michelsen 43ee4a9c5a fix name_color_checksum computation bug 2023-12-29 16:25:53 -08:00
Martin Michelsen 7ee7af0b0f allow $edit to change a few things even if cheat mode is disabled 2023-12-29 16:25:03 -08:00
Maria J. Belmonte d15f1cc1a3 Merge branch 'fuzziqersoftware:master' into master 2023-12-30 00:27:59 +01:00
Martin Michelsen 4f2432cbac refine 6x70 format to enable all cross-version joins 2023-12-29 10:44:25 -08:00
Martin Michelsen 60f6b609da make $debug allow all cross-version games 2023-12-28 19:42:01 -08:00
Martin Michelsen 1058998550 fix $password command 2023-12-28 19:39:44 -08:00
Martin Michelsen c00b554b56 fix go-go ball command 2023-12-28 13:06:14 -08:00
Martin Michelsen 0bd3bb7b77 fix item ID conflicts in lobbies 2023-12-28 11:29:09 -08:00
Martin Michelsen b6cfb5b2a2 fix 6x69 command 02 checks 2023-12-28 11:07:06 -08:00
Martin Michelsen c1bcd45ea1 fix incorrect item parsing in config.json 2023-12-28 10:41:59 -08:00
Maria J. Belmonte 5ba652aa38 Merge branch 'fuzziqersoftware:master' into master 2023-12-28 19:34:47 +01:00
Martin Michelsen 1ba50e96ca update lobby datas on team master transfer 2023-12-28 10:23:13 -08:00
Martin Michelsen 7b7c9d371f assign inventory item IDs in lobbies too 2023-12-28 10:22:48 -08:00
Martin Michelsen 09ac8921fe don't require full login information on patch server 2023-12-28 09:57:47 -08:00
Martin Michelsen 29a4347f2b allow overwriting equips on DC NTE and 11/2000 2023-12-28 09:45:11 -08:00
Martin Michelsen 68cf06c6d0 add 1.23.4 US BB handlers to table 2023-12-28 09:29:17 -08:00
Martin Michelsen 5307051e04 make it obvious how to compress/decompress prc files 2023-12-28 09:14:00 -08:00
Maria J. Belmonte 045ff9b169 Merge branch 'fuzziqersoftware:master' into master 2023-12-28 08:58:53 +01:00
Martin Michelsen c1122e1f90 add comment about client_config scrambling 2023-12-27 23:21:36 -08:00
Martin Michelsen d478e9b0be implement BB client's config scramble logic 2023-12-27 23:08:17 -08:00
Martin Michelsen 2aa699b5b0 always generate the same length for box arrays in ItemRT conversion 2023-12-27 21:11:13 -08:00
Martin Michelsen c96cfad4d2 fix sub_version sharing between some Ep3 and BB versions 2023-12-27 21:10:54 -08:00
Martin Michelsen bf26e437ff add missing include on linux 2023-12-27 19:54:32 -08:00
Martin Michelsen 9efdf88101 fix invalid 6x69 command checks 2023-12-27 19:35:42 -08:00
Martin Michelsen 4273ae84f4 document Change Name option 2023-12-27 18:26:01 -08:00
Martin Michelsen b49408a88b implement level table parsers for v2 and v3 2023-12-27 18:03:52 -08:00
Martin Michelsen 764fbf8841 update chat command documentation in readme 2023-12-27 18:03:39 -08:00
Martin Michelsen f74b416c19 use client's stats struct during $savechar on v1/v2 2023-12-27 11:06:22 -08:00
Martin Michelsen 8104fd0853 fix ghost items in persistent games 2023-12-27 10:42:30 -08:00
Martin Michelsen 910555f299 fix incorrect next item ID during game join 2023-12-27 10:42:30 -08:00
Martin Michelsen 2dd7601dbd fix DC prototypes level up command 2023-12-27 10:42:30 -08:00
Martin Michelsen d7e390e494 show original filenames in quest load logs 2023-12-27 10:42:30 -08:00
Maria J. Belmonte c8b001411e Merge branch 'fuzziqersoftware:master' into master 2023-12-27 16:50:29 +01:00
ShiftaDeband a5265874a2 Remove comment addition in tests config.json 2023-12-26 16:07:18 -08:00
ShiftaDeband 81eaa893b9 Update tests config.json with item spacing adjustments, ’ -> ' 2023-12-26 16:07:18 -08:00
ShiftaDeband a0e84b5d5c Update example config with item spacing adjustments, ’ -> ' 2023-12-26 16:07:18 -08:00
ShiftaDeband e8891adf8e Fix typo for "REVIVAL CUIRASS" 2023-12-26 16:07:18 -08:00
Martin Michelsen 1a2d5c1772 rename GC_EP3_TRIAL_EDITION to GC_EP3_NTE 2023-12-26 09:56:38 -08:00
Martin Michelsen 65b9048ab6 update tests for add_color bugfix 2023-12-26 07:52:29 -08:00
Martin Michelsen ccd1b56cae escape player-provided text in various places 2023-12-26 07:37:07 -08:00
Martin Michelsen 5382e12b8d support generating v1 rare item sets 2023-12-26 07:04:30 -08:00
Martin Michelsen 2cdebd5f20 don't skip blank entries when serializing REL rare item tables 2023-12-26 06:58:21 -08:00
Maria J. Belmonte 61e5460bc1 Merge branch 'fuzziqersoftware:master' into master 2023-12-26 09:07:02 +01:00
Martin Michelsen c100d76a5b add notes about protected subcommands 2023-12-25 22:41:36 -08:00
Martin Michelsen d59b59cd51 make switch assist a non-cheat command 2023-12-25 19:32:44 -08:00
Martin Michelsen c7059874d3 make infinite HP also heal conditions 2023-12-25 19:32:44 -08:00
Martin Michelsen dfc451e86a improve proxy compatibility on GC NTE 2023-12-25 19:05:56 -08:00
Martin Michelsen d1022e9b53 rename sys_guild_card_number to team_master_guild_card_number 2023-12-25 17:39:39 -08:00
Martin Michelsen 7c9309f6c5 fix next item ID set incorrectly when joining a persistent game 2023-12-25 17:11:38 -08:00
Martin Michelsen 441457a873 fix Commander Blade effect in games 2023-12-25 16:30:01 -08:00
Martin Michelsen 9255037f50 fix tests for removed client flag 2023-12-25 15:20:29 -08:00
Martin Michelsen 4c95adcdb3 update to-do list 2023-12-25 15:20:05 -08:00
Martin Michelsen 2ef6acaa0e fix incorrect team flag alpha channel when loaded from disk 2023-12-25 15:06:38 -08:00
Martin Michelsen a8061efc0d implement rename team command 2023-12-25 11:11:03 -08:00
Martin Michelsen 206552ed63 remove proxy chat filter option 2023-12-25 09:59:30 -08:00
Martin Michelsen 9e48259414 update to-do list 2023-12-24 22:55:25 -08:00
Martin Michelsen ad32c0a986 make hide_download_commands configurable 2023-12-24 22:51:59 -08:00
Martin Michelsen 84ed80365c make BB games deterministic for replays 2023-12-23 23:26:44 -08:00
Martin Michelsen 87440437fb move Revision.cc to source dir 2023-12-23 21:34:57 -08:00
Martin Michelsen 2aca408a9e create output dir if needed 2023-12-23 21:25:11 -08:00
Martin Michelsen 3991d7b534 fix Revision.cc generation 2023-12-23 21:22:02 -08:00
Martin Michelsen 3823fc94f1 add $si command 2023-12-23 20:41:21 -08:00
Maria J. Belmonte 190e89181e Merge branch 'fuzziqersoftware:master' into master 2023-12-23 12:42:42 +01:00
Maria J. Belmonte 20ca2529ac Merge branch 'fuzziqersoftware:master' into master 2023-12-23 02:34:06 +01:00
nolrinale 143da7e5a5 Added Map files to spawn Coren 2023-12-23 02:15:20 +01:00
nolrinale 37b95f35c2 Coren labo area client function adjustments 2023-12-23 02:08:06 +01:00
Maria J. Belmonte aed2c61706 Merge branch 'fuzziqersoftware:master' into master 2023-12-23 01:47:30 +01:00
Maria J. Belmonte 0955d1e5fd Merge branch 'fuzziqersoftware:master' into master 2023-12-22 23:10:31 +01:00
nolrinale e51924bf49 Adding Coren localized files 2023-12-22 14:30:16 +01:00
3652 changed files with 105007 additions and 24421 deletions
+27
View File
@@ -0,0 +1,27 @@
---
name: Bug report
about: Report incorrect behavior or unexpected errors
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
Write a clear and concise description of what the bug is, and what you expected to happen instead.
**To reproduce**
Fill in steps to reproduce the behavior, such as:
1. Connect to server
2. Create a game
3. Start quest X
4. Talk to NPC Y
**Game version(s) (choose one or more of the following):**
DC NTE, DC prototype, DC v1, DC v2, PC, GC Ep1&2, GC Ep3, Xbox, BB
**Server log output**
On macOS/Linux, or in a Cygwin shell on Windows, you can run the server as `./newserv 2>&1 | tee server-log.txt` to generate a log file. Do that, then do whatever you need to do to get the bug to happen, then upload the log file here.
**Additional context**
Add any other context about the problem here.
+20
View File
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
Write a clear and concise description of what the problem is. For example, "I'm always frustrated when [...]"
**Describe the solution you'd like**
Write a clear and concise description of what you want to happen.
**Game version(s) (choose one or more of the following):**
DC NTE, DC prototype, DC v1, DC v2, PC, GC Ep1&2, GC Ep3, Xbox, BB
**Additional context**
Add any other context or screenshots about the feature request here.
+2
View File
@@ -2,6 +2,7 @@
.DS_Store
# Build products
src/Revision.cc
newserv
# CMake files
@@ -26,6 +27,7 @@ system/players/*.psocard
system/players/*.nsc
system/players/*.nsa
system/teams/*.json
system/teams/*.bmp
system/patch-pc/.metadata-cache.json
system/patch-bb/.metadata-cache.json
+30 -6
View File
@@ -27,10 +27,12 @@ link_directories(${LOCAL_LIB_DIR})
find_path (LIBEVENT_INCLUDE_DIR NAMES event.h)
find_library (LIBEVENT_LIBRARY NAMES event)
find_library (LIBEVENT_CORE NAMES event_core)
find_library (LIBEVENT_PTHREADS NAMES event_pthreads)
set (LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR})
set (LIBEVENT_LIBRARIES
${LIBEVENT_LIBRARY}
${LIBEVENT_CORE})
${LIBEVENT_CORE}
${LIBEVENT_PTHREADS})
find_package(phosg REQUIRED)
find_package(Iconv REQUIRED)
@@ -38,9 +40,25 @@ find_package(resource_file QUIET)
# Git metadata
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/__Revision__.cc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/Revision-generate.sh ${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
)
add_custom_target(
newserv-Revision-cc
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/__Revision__.cc
)
# Executable definition
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc
src/Account.cc
src/AFSArchive.cc
src/BattleParamsIndex.cc
src/BMLArchive.cc
@@ -66,25 +84,28 @@ set(SOURCES
src/Episode3/RulerServer.cc
src/Episode3/Server.cc
src/Episode3/Tournament.cc
src/EventUtils.cc
src/FileContentsCache.cc
src/FunctionCompiler.cc
src/GSLArchive.cc
src/GVMEncoder.cc
src/HTTPServer.cc
src/IPFrameInfo.cc
src/IPStackSimulator.cc
src/IPV4RangeSet.cc
src/ItemCreator.cc
src/ItemData.cc
src/ItemNameIndex.cc
src/ItemParameterTable.cc
src/Items.cc
src/LevelTable.cc
src/License.cc
src/Lobby.cc
src/Loggers.cc
src/Main.cc
src/Map.cc
src/Menu.cc
src/NetworkAddresses.cc
src/PatchServer.cc
src/PatchFileIndex.cc
src/PlayerFilesManager.cc
src/PlayerSubordinates.cc
@@ -94,23 +115,22 @@ set(SOURCES
src/PSOGCObjectGraph.cc
src/PSOProtocol.cc
src/Quest.cc
src/QuestAvailabilityExpression.cc
src/IntegralExpression.cc
src/QuestScript.cc
src/RareItemSet.cc
src/ReceiveCommands.cc
src/ReceiveSubcommands.cc
src/ReplaySession.cc
src/Revision.cc
src/SaveFileFormats.cc
src/SendCommands.cc
src/Server.cc
src/ServerShell.cc
src/ServerState.cc
src/Shell.cc
src/StaticGameData.cc
src/TeamIndex.cc
src/Text.cc
src/TextArchive.cc
src/UnicodeTextSet.cc
src/TextIndex.cc
src/Version.cc
src/WordSelectTable.cc
)
@@ -122,6 +142,10 @@ endif()
add_executable(newserv ${SOURCES})
target_include_directories(newserv PUBLIC ${LIBEVENT_INCLUDE_DIR} ${Iconv_INCLUDE_DIRS})
target_link_libraries(newserv phosg ${LIBEVENT_LIBRARIES} ${Iconv_LIBRARIES} pthread)
add_dependencies(newserv newserv-Revision-cc)
# target_compile_options(newserv PRIVATE -fsanitize=address)
# target_link_options(newserv PRIVATE -fsanitize=address)
if(resource_file_FOUND)
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE)
+338 -179
View File
@@ -1,4 +1,4 @@
# newserv <img align="right" src="s-newserv.png" />
# newserv <img align="right" src="static/s-newserv.png" />
newserv is a game server, proxy, and reverse-engineering tool for Phantasy Star Online (PSO).
@@ -9,83 +9,241 @@ Feel free to submit GitHub issues if you find bugs or have feature requests. I'd
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)
* [Compatibility](#compatibility)
* Setup
* [Configuration](#configuration)
* [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)
* [Episode 3 features](#episode-3-features)
* [Client patch directories for PC and BB](#client-patch-directories)
* [Memory patches and DOL files for GC](#memory-patches-and-dol-files)
* [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)
* How to connect
* Connecting local clients
* [PSO DC](#pso-dc)
* [PSO DC on Flycast](#pso-dc-on-flycast)
* [PSO PC](#pso-pc)
* [PSO GC on a real GameCube](#pso-gc-on-a-real-gamecube)
* [PSO GC on Dolphin](#pso-gc-on-dolphin)
* [PSO BB](#pso-bb)
* [Connecting external clients](#connecting-external-clients)
* [Non-server features](#non-server-features)
## Compatibility
# History
newserv supports several versions of PSO, including various development prototypes. Specifically:
| 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 (3) | 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 | Partial (1) | Yes |
| GC Ep3 | Yes | Yes | Yes |
| Xbox Ep1&2 | Yes | Yes | Yes |
| BB (vanilla) | Yes | Yes (2) | Yes |
| BB (Tethealla) | Yes | Yes (2) | Yes |
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 a bit tedious 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. Still active and popular as of this writing (early 2024). Schtserv is also the only other unofficial server to support all versions of PSO, including Episode 3.
* (2005) **Khyller**: An early attempt of mine to support PSO PC, GC, and BB. See above for more details.
* (2006) **Aeon**: My second attempt. Better than Khyller, but still unreliable.
* (2008) **Tethealla**: A fairly extensive implementation of PSOBB, written in C by Sodaboy. The public version of Tethealla has been [officially disowned](https://www.pioneer2.net/community/threads/tethealla-server-forums-removal.26365/) (as it is now more than 15 years old), but closed-source development continues. [Ephinea](https://ephinea.pioneer2.net/), currently the most popular PSOBB server, is the continuation of this project. Several other modern PSOBB servers are forks of the initial public version of Tethealla as well.
* (2008) **[Sylverant](https://sylverant.net/)** [(source)](https://sourceforge.net/projects/sylverant/): The second public-access PSO server; written in C by BlueCrab. Still active and popular as of this writing (early 2024).
* (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.
* (2022) **[PSOSERVER](https://github.com/Sancaros/PSOSERVER)**: A server for all versions, written in C by Sancaros and based on Sylverant and newserv.
# Compatibility
newserv supports all known versions of PSO, including development prototypes. Specifically:
| 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 (3) | Yes | No |
| PC | Yes | Yes | Yes |
| GC Ep1&2 NTE | Yes | Yes | Yes |
| GC Ep1&2 | Yes | Yes | Yes |
| GC Ep1&2 Plus | Yes | Yes | Yes |
| GC Ep3 NTE | Yes | Yes (1) | Yes |
| GC Ep3 | Yes | Yes | Yes |
| Xbox Ep1&2 Beta | Yes | Yes | Yes |
| Xbox Ep1&2 | Yes | Yes | Yes |
| BB (vanilla) | Yes | Yes (2) | Yes |
| BB (Tethealla) | Yes | Yes (2) | Yes |
*Notes:*
1. *Players can create games, edit decks, trade cards, and participate in auctions, but CARD battles don't work on Episode 3 Trial Edition on newserv.*
1. *Ep3 NTE battles are not well-tested; some things may not work. See notes/ep3-nte-differences.txt for a list of known differences between NTE and the final version. NTE and non-NTE players cannot battle each other.*
2. *Some BB-specific features are not well-tested (for example, some quests that use rare commands may not work properly). Please submit a GitHub issue if you find something that doesn't work.*
3. *This is the only version of PSO that doesn't have any way to identify the player's account - there is no serial number or username. For this reason, AllowUnregisteredUsers must be enabled in config.json to support PC NTE, and PC NTE players receive a random Guild Card number every time they connect. To prevent abuse, PC NTE support can be disabled in config.json.*
## Setup
# Setup
### Configuration
## Server setup
Currently newserv works on macOS, Windows, and Ubuntu Linux. It will likely work on other Linux flavors too.
There is a fairly recent macOS ARM64 release on the newserv GitHub repository. You may need to install libevent manually even if you use this release (run `brew install libevent`).
### Windows/macOS
There is a fairly recent Windows release on the newserv GitHub repository also. It's built with Cygwin, and all the necessary DLL files should be included. That said, I've only tested it on my own machine and there is no CI for Windows builds like there is for macOS and Linux, so if it doesn't work for you, please open a GitHub issue to let me know.
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 release folder to a location on your computer.
3. Edit the config.example.json file in the system folder as needed, then rename it to config.json.
4. If you plan to play Blue Burst on newserv, set up the patch directory. See [client patch directories](#client-patch-directories) for more information.
5. Run the newserv executable.
If you're not using a release from the GitHub repository, do this to build newserv:
1. If you're on Windows, install Cygwin. While doing so, install the `cmake`, `gcc-core`, `gcc-g++`, `git`, `libevent2.1_7`, `make`, `libiconv-devel`, and `zlib` packages. Do the rest of these steps inside a Cygwin shell (not a Windows cmd shell or PowerShell).
2. Make sure you have CMake, libevent, and libiconv installed. (On macOS, `brew install cmake libevent libiconv`; on most Linuxes, `sudo apt-get install cmake libevent-dev`; on Windows, you already did this in step 1.)
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.
### Linux
There are currently no precompiled releases for Linux. To run newserv on Linux, 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`, `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 or downloading a release, do this to set it up and use it:
1. In the system/ directory, make a copy of config.example.json named config.json, and edit it appropriately.
2. If you plan to play PSO Blue Burst on newserv, set up the patch directory. See the "Client patch directories" section below.
3. Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. You may need `sudo` if newserv's built-in DNS server is enabled.
4. If you set AllowUnregisteredUsers to false in config.json, use the interactive shell to add your license. Run `help` in the shell to see how to do this.
5. Set your client's network settings appropriately and start an online game. See the "Connecting local clients" or "Connecting remote clients" section to see how to get your game client to connect.
After building newserv, edit system/config.example.json as needed and rename it to system/config.json, set up [client patch directories](#client-patch-directories) if you're planning to play Blue Burst, then run `./newserv` in newserv's directory.
To use newserv in other ways (e.g. for translating data), see the end of this document.
### Installing quests
## 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 do not have a BB client, or 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 its default gateway and DNS server addresses in 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 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. In the old days, one way to get around this was to create a fake network adapter on the server (or use an existing real one) that has an IP address on a different subnet, tell the GameCube that the server is the default gateway (as above), and have the server reply to the DNS request with its non-local IP address. To do this with newserv, just set LocalAddress in the config file to a different interface. For example, if the GameCube is on the 192.168.0.x network and your other adapter has address 10.0.1.6, set newserv's LocalAddress to 10.0.1.6 and set PSO's DNS server and default gateway addresses to the server's 192.168.0.x address. This may not work on modern systems or on non-Windows machines - I haven't tested 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 cnnect 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 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 a version of Dolphin with tapserver support, you can make it connect to a newserv instance running on the same machine via the tapserver interface. You do not need to install or run tapserver. To do this:
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv.
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
4. Start an online game.
### PSO BB
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the "Client patch directories" section for instructions on setting this up.)
The original Japanese and US versions of PSO BB should work (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)), but you'll have to modify your hosts file or edit psobb.exe to point to your newserv instance. The original versions 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) / [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)); you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect. 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.
### Connecting external clients
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.
@@ -137,9 +295,9 @@ Episode 3 download quests consist only of a .bin file - there is no correspondin
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 quests` 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.
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
## 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.
@@ -152,11 +310,11 @@ There are five different available behaviors for item drops:
In the `SERVER_PRIVATE` and `SERVER_DUPLICATE` modes, there is no incentive to pick up items before another player, since other players cannot pick up the items you see dropped from boxes and enemies. However, if you pick up an item and drop it later, it can then be seen and picked up by any player.
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, they 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.
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
## Cross-version play
All versions of PSO can see and interact with each other in the lobby. newserv also allows some versions to play in-game with each other:
* DC V1 players can join DC V2 games if the difficulty level isn't set to Ultimate and the creator chose to allow V1 players.
@@ -166,7 +324,7 @@ All versions of PSO can see and interact with each other in the lobby. newserv a
In V1/V2 cross-version play, when any of the server drop modes are used, the server uses the drop table corresponding to the version the game was created with. (For example, if a DC V1 player created the game, rare-table-v1.json will be used, even after V2 players join.)
### Episode 3 features
## 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).
@@ -177,11 +335,11 @@ newserv supports many features unique to Episode 3:
* 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
### 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
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.
@@ -189,7 +347,7 @@ These tournament semantics mean that there can be multiple matches in the same t
The Meseta rewards for winning tournament matches can be configured in config.json.
#### Episode 3 files
### 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.
@@ -203,44 +361,64 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i
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 .bin or .mnm files before editing them, but you don't need to compress the files again to use them - 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` in the interactive shell to make the changes take effect without restarting the server.
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-data` in the interactive shell to make the changes take effect without restarting the server.
### Client patch directories
## Memory patches, client functions, and DOL files
If you're not playing PSO Blue Burst on newserv, you can skip these steps.
*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.*
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.
You can put assembly files in the system/client-functions directory with filenames like PatchName.VERS.patch.s and they will appear in the Patches menu for clients that support client functions. Client functions are written in SH-4, PowerPC, or x86 assembly and are compiled when newserv is started. The assembly system's features are documented in the comments in system/client-functions/System/WriteMemory.ppc.s.
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.
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. The specific versions are:
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/blueburst/map directory, but if these don't match the client's copies of the files, odd behavior will occur in games.
| Game | VERS | Supported |
|-------------------|------|-----------|
| PSO DC NTE | 1OJ1 | No |
| PSO DC 11/2000 | 1OJ2 | No |
| PSO DC 12/2000 | 1OJ3 | No |
| PSO DC 01/2001 | 1OJ4 | No |
| PSO DC v1 JP | 1OJF | No |
| PSO DC v1 US | 1OEF | No |
| PSO DC v1 EU | 1OPF | No |
| PSO DC 08/2001 | 2OJ5 | Yes |
| PSO DC v2 JP | 2OJF | Yes |
| PSO DC v2 US | 2OEF | Yes |
| PSO DC v2 EU | 2OPF | Yes |
| PSO PC (v2) | 2OJW | No |
| PSO GC NTE | 3OJT | Yes |
| PSO GC v1.2 JP | 3OJ2 | Yes |
| PSO GC v1.3 JP | 3OJ3 | Yes |
| PSO GC v1.4 JP | 3OJ4 | Yes |
| PSO GC v1.5 JP | 3OJ5 | No |
| PSO GC v1.0 US | 3OE0 | Yes |
| PSO GC v1.1 US | 3OE1 | Yes |
| PSO GC v1.2 US | 3OE2 | No |
| PSO GC v1.0 EU | 3OP0 | Yes |
| PSO GC Ep3 NTE | 3SJT | Yes |
| PSO GC Ep3 JP | 3SJ0 | Yes |
| PSO GC Ep3 US | 3SE0 | No |
| PSO GC Ep3 EU | 3SP0 | No |
| PSO Xbox Beta | 4OJB | Yes |
| PSO Xbox JP Disc | 4OJD | Yes |
| PSO Xbox JP TU | 4OJU | Yes |
| PSO Xbox US Disc | 4OED | Yes |
| PSO Xbox US TU | 4OEU | Yes |
| PSO Xbox EU Disc | 4OPD | Yes |
| PSO Xbox EU TU | 4OPU | Yes |
| PSO BB JP 1.25.13 | 51OC | Yes |
| PSO BB Tethealla | 51OC | Yes |
Specifically, the patch-bb directory should contain at least the data.gsl file and all map_*.dat files from the version of PSOBB that you want to play on newserv. You can copy these files out of the client's data directory from a clean installation, and put them in system/patch-bb/data.
*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.*
Patch directory contents are cached in memory. If you've changed any of these files, you can run `reload patches` in the interactive shell to make the changes take effect without restarting the server.
newserv comes with a set of patches for some 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).
### Memory patches and DOL files
Everything in this section requires resource_dasm to be installed, so newserv can use the PowerPC assembler and disassembler from its libresource_file library. If resource_dasm is not installed, newserv will still build and run, but these features will not be available.
In addition, these features are only supported for the following game versions:
* PSO GameCube Episodes 1&2 JP, USA, and EU (not Plus)
* PSO GameCube Episodes 1&2 Plus JP v1.04 (not v1.05)
* PSO GameCube Episode 3 Trial Edition
* PSO GameCube Episode 3 JP
* PSO GameCube Episode 3 USA (experimental; must be manually enabled in config.json)
You can put memory patches in the system/ppc directory with filenames like PatchName.patch.s and they will appear in the Patches menu for PSO GC clients that support patching. Memory patches are written in PowerPC assembly and are compiled when newserv is started. The PowerPC assembly system's features are documented in the comments in system/ppc/WriteMemory.s - this file is not a memory patch itself, but it describes how memory patches may be written and the restrictions that apply to them.
newserv comes with a set of patches for Episodes 1&2 based on AR codes originally made by Ralf at GC-Forever. 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. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.s, WriteMemory.s, and RunDOL.s must be present in the system/ppc directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.ppc.s, WriteMemory.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions 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
## 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.
@@ -257,7 +435,7 @@ There are many options available when starting a proxy session. All options are
* **Block pings**: blocks automatic pings sent by the client, and responds to ping commands from the server automatically. This works around a bug in Sylverant's login server.
* **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**: attempts to unlock doors that require two players in a one-player game.
* **Switch assist**: attempts to unlock doors that require two or four players in a one-player game.
* **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.
@@ -275,7 +453,7 @@ The remote server will probably try to assign you a Guild Card number that doesn
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
## 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.
@@ -283,36 +461,56 @@ Some commands only work on the game server and not on the proxy server. The chat
* Information commands
* `$li`: Shows basic information about the lobby or game you're in. If you're on the proxy server, shows information about your connection instead (remote Guild Card number, client ID, etc.).
* `$si` (game server only): Shows basic information about the server.
* `$ping`: Shows round-trip ping time from the server to you. On the proxy server, shows the ping time from you to the proxy and from the proxy to the server.
* `$matcount` (game server only): Shows how many of each type of material you've used.
* `$itemnotifs <mode>`: Enables 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.
* `$what` (game server only): Shows the type, name, and stats of the nearest item on the ground.
* `$where` (game server only): Shows your current floor number and coordinates. Mainly useful for debugging.
* Debugging commands
* `$debug` (game server only): Enable or disable debug. You need the DEBUG permission in your user license to use this command. When debug is enabled, you'll see in-game messages from the server when you take certain actions. You'll also be placed into the highest available slot in lobbies and games instead of the lowest, which is useful for finding commands for which newserv doesn't handle client IDs properly. This setting also disables certain safeguards and allows you to do some things that might crash your client.
* `$quest <number>`: Load a quest by quest number. Can be used to load battle or challenge quests with only one player present.
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does a few things:
* You'll see in-game messages from the server when you take certain actions, like killing an enemy in BB.
* You'll see the rare seed value and floor variations when you join a game.
* You'll be placed into the highest available slot in lobbies and games instead of the lowest, unless you're joining a BB solo-mode game.
* You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Please do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above).
* The rest of the commands in this section are enabled on the game server. (They are always enabled on the proxy server.)
* `$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.
* `$qcall <function-id>`: Call a quest function on your client.
* `$qcheck <flag-num>`: Show the value of a quest flag.
* `$qset <flag-num>` or `$qclear <flag-num>`: Set or clear a global quest flag for everyone in the game.
* `$qsync <reg-num> <value>`: Set a quest register's value on your client. `<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.
* `$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): Get 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`: Sets 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.
* `$persist` (game server only): Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The state of enemies and objects on the map will be reset when the last player leaves.
* `$sc <data>`: Send a command to yourself.
* `$ss <data>` (proxy server only): Send a command to the remote server.
* `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server.
* `$sb <data>`: Send a command to yourself, and to the remote server or game server.
* `$meseta <amount>` (game server only; Episode 3 only): Add the given amount to your Meseta total.
* `$auction` (Episode 3 only): Bring up the CARD Auction menu, regardless of how many players are in the game or if you have a VIP card.
* `$ep3battledebug` (game server only; Episode 3 only): Enable or disable TCard00_Select. If enabled, the game will enter the debug menu when you start a battle.
* Personal state commands
* `$arrow <color-id>`: Changes your lobby arrow color.
* `$secid <section-id>`: Sets 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. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$secid <section-id>`: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$rand <seed>`: Sets 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]`: Sets 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`: Enables or disables switch assist. When enabled, the server will attempt to automatically unlock two-player and four-player doors in non-quest games if you step on all the required switches sequentially.
* `$exit`: If you're in a lobby, sends you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, sends 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
* Character data commands (game server only)
* `$savechar <slot>`: Saves your current character data on the server in the specified slot (each serial number has 4 slots, numbered 1-4). These slots are separate from BB character slots; using this command does not affect BB characters.
* `$loadchar <slot>` (v1 and v2 only): Loads your character data from the specified slot. The changes will be undone if you join a game - to save your changes, disconnect from the lobby.
* `$bbchar <username> <password> <slot>`: Use this command when playing on a non-BB version of PSO. If the username and password are correct, this command converts your current character to BB format and saves it on the server in the given slot (1-4). Any character already in that slot is overwritten. (This command is similar to `$savechar`, except it overwrites a BB character slot, and can transfer characters across accounts.) Note that the character's chat data, quick menu config, and bank contents are not copied, since there is no way for the server to request those types of data.
* `$edit <stat> <value>`: Modifies your character data. If you are on V3 (GameCube/Xbox), or if the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing. 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.
* `$edit <stat> <value>`: Modifies your character data. If you are on V3 (GameCube/Xbox), this command does nothing. 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. If cheats are allowed on the server, `<stat>` can be any of `atp`, `mst`, `evp`, `hp`, `dfp`, `ata`, `lck`, `meseta`, `exp`, `level`, `namecolor`, `secid`, `name`, `language`, `npc`, or `tech`. If cheats are not allowed, only `namecolor`, `name`, `language`, and `npc` can be used. Changing your character's language is only useful on BB; to do so, use a single-character language code (e.g. to switch your character to English, use `$edit language E`; for Japanese, use `$edit language J`).
* Blue Burst player commands (game server only)
* `$bank [number]`: Switches 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, switches back to your current character's bank.
@@ -323,25 +521,26 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$minlevel <level>`: Sets the minimum level for players to join the current game.
* `$password <password>`: Sets the game's join password. To unlock the game, run `$password` with nothing after it.
* `$dropmode [mode]`: Changes the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the "Item tables and drop modes" section for more information.
* `$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 (except items only visible to the leaving player). If the game is empty for too long (15 minutes by default), it is then deleted. There is an edge case with persistence: if the player defeats a boss, leaves the room, joins again, and returns to the boss arena, neither the boss nor the exit warp will spawn, so they will be stuck there and have to use $warp or Quit Game to get out. For this reason, `$warp 0` is allowed in boss arenas once the boss is defeated, even if cheat mode is disabled.
* Episode 3 commands (game server only)
* `$spec`: Toggles the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they will be sent back to the lobby.
* `$inftime`: Toggles infinite-time mode. Must be used before starting a battle. If infinite-time mode is enabled, the overall and per-phase time limits will be disabled regardless of the values chosen during battle 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).
* `$defrange <min>-<max>`: Sets the DEF dice range for the next battle. If this is used, the dice range set during battle rules setup will apply only to ATK dice; DEF dice will use this range instead. Assist cards and other dice effects will still apply. Dice exchange also still applies if it is enabled.
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Sets 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>`: Shows 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`: Causes your team to immediately lose the current battle.
* `$saverec <name>`: Saves the recording of the last battle.
* `$playrec <name>`: Plays a battle recording. This command creates a spectator team and replays the specified battle log within it. There is a bug in Dolphin that makes use of this command unstable in emulation (see the "Battle records" section above).
* Cheat mode commands
* `$cheat`: Enables or disables 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.
* `$infhp` / `$inftp`: Enables or disables infinite HP or TP mode. Applies to only you. In infinite HP mode, one-hit KO attacks will still kill you.
* `$warpme <floor-id>`: Warps yourself to the given floor.
* `$cheat` (game server only): Enables or disables 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` / `$inftp`: Enables or disables infinite HP or TP mode. Applies to only you. In infinite HP mode, one-hit KO attacks will still kill you. On V1 and V2, infinite HP also automatically cures status ailments.
* `$warpme <floor-id>` (or `$warp <floor-id>`): Warps yourself to the given floor.
* `$warpall <floor-id>`: Warps 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`: Warps yourself to the next floor.
* `$swa`: Enables or disables switch assist. When enabled, the server will attempt to automatically unlock two-player doors in solo games if you step on both switches sequentially.
* `$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>`: 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.
* `$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): Changes 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.
* Configuration commands
* `$event <event>`: Sets 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.
@@ -349,94 +548,54 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$song <song-id>` (Episode 3 only): Plays a specific song in the current lobby.
* Administration commands (game server only)
* `$ann <message>`: Sends an announcement message. The message text is sent to all players in all games and lobbies.
* `$ann <message>`: Sends an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies.
* `$ann! <message>`: Sends an announcement message. The message is sent as a Simple Mail message to all players in all games and lobbies.
* `$ax <message>`: Sends a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
* `$silence <identifier>`: Silences a player (remove their ability to chat) or unsilences a player. The identifier may be the player's name or Guild Card number.
* `$kick <identifier>`: Disconnects a player. The identifier may be the player's name or Guild Card number.
* `$ban <identifier>`: Bans a player. The identifier may be the player's name or Guild Card number.
### Connecting local clients
# Non-server features
#### PSO DC
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.
Some versions of PSO DC will connect to a private server if you just set their DNS server address (in the network configuration) to newserv's address, and enable newserv's DNS server. This will not work for other versions; for those, you'll need a cheat code. Creating such a code is beyond the scope of this document.
The data formats that newserv can convert to/from are:
If you're emulating PSO DC or have a disc image, you can patch the appropriate files within the disc image to make it connect to any address you want. Creating such a patch is also beyond the scope of this document.
| 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 PC save file | `encrypt-pc-save` | `decrypt-pc-save` |
| PSO GC save file (.gci) | `encrypt-gci-save` | `decrypt-gci-save` |
| PSO GC snapshot file | None | `decode-gci-snapshot` |
| Quest script (.bin) | `assemble-quest-script` | `disassemble-quest-script` |
| Quest map (.dat) | None | `disassemble-quest-map` |
| AFS archive | None | `extract-afs` |
| BML archive | None | `extract-bml` |
| GSL archive | None | `extract-gsl` |
| GVM texture | `encode-gvm` | None |
| Text archive | `encode-text-archive` | `decode-text-archive` |
| Unicode text set | `encode-unicode-text-set` | `decode-unicode-text-set` |
| Word Select data set | None | `decode-word-select-set` |
| Set data table | None | `disassemble-set-data-table` |
| Rare item table (AFS/GSL/JSON) | `convert-rare-item-set` | `convert-rare-item-set` |
#### PSO DC on Flycast
There are several actions that don't fit well into the table above, which let you do other things:
If you're emulating PSO DC, all 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.
Once set up, the EU and US versions will work without any extra set up (other than the HL Check Disable code for USv2), while the JP versions require HL Check Disable codes to be running.
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.
#### PSO PC
The version of PSO PC I have has the server addresses starting at offset 0x29CB34 in pso.exe. Using a hex editor, change those 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 its default gateway and DNS server addresses to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube.
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. In the old days, one way to get around this was to create a fake network adapter on the server (or use an existing real one) that has an IP address on a different subnet, tell the GameCube that the server is the default gateway (as above), and have the server reply to the DNS request with its non-local IP address. To do this with newserv, just set LocalAddress in the config file to a different interface. For example, if the GameCube is on the 192.168.0.x network and your other adapter has address 10.0.1.6, set newserv's LocalAddress to 10.0.1.6 and set PSO's DNS server and default gateway addresses to the server's 192.168.0.x address. This may not work on modern systems or on non-Windows machines - I haven't tested it in many years.
#### 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, try your local IP address or 127.0.0.1.) In PSO, use the example values below in PSO's network configuration.
If you're using the TAP BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
If you're using a version of Dolphin with tapserver support, you can make it connect to a newserv instance running on the same machine via the tapserver interface. You do not need to install or run tapserver. To do this:
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv.
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
4. Start an online game.
#### PSO BB
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the "Client patch directories" section for instructions on setting this up.)
The original Japanese and US versions of PSO BB should work, but you'll have to modify your hosts file or edit psobb.exe to point to your newserv instance. The original versions are packed, 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 (https://archive.org/details/psobb-tethealla-client); you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
### Connecting external clients
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.
### 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 these options and how to use them. The non-server things newserv can do are:
* Compress or decompress data in PRS, PR2, or BC0 format (`compress-prs`, `compress-pr2`, `compress-bc0`, `decompress-prs`, `decompress-pr2`, `decompress-bc0`)
* Compute the decompressed size of compressed PRS data without decompressing it (`prs-size`)
* Encrypt or decrypt data using any PSO version's network encryption scheme (`encrypt-data`, `decrypt-data`)
* Encrypt or decrypt data using Episode 3's trivial scheme (`encrypt-trivial-data`, `decrypt-trivial-data`)
* Encrypt or decrypt data using the Challenge Mode text algorithm (`encrypt-challenge-data`, `decrypt-challenge-data`)
* Encrypt or decrypt PSO GC save data (.gci files) (`encrypt-gci-save`, `decrypt-gci-save`)
* Convert a PSO GC or Episode 3 snapshot file to a BMP image (`decode-gci-snapshot`)
* 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`)
* Convert quests in .gci, .vms, .dlq, or .qst format to .bin/.dat format (`decode-gci`, `decode-vms`, `decode-dlq`, `decode-qst`)
* Convert quests in .bin/.dat to .qst format (`encode-qst`)
* Convert text archives (e.g. TextEnglish.pr2) to JSON and vice versa (`decode-text-archive`, `encode-text-archive`)
* Compile or disassemble quest scripts (`assemble-quest-script`, `disassemble-quest-script`)
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`)
* Convert item data to a human-readable description, or vice versa (`describe-item`, `encode-item`)
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`, `generate-ep3-cards-html`)
* Format Blue Burst battle parameter files in a human-readable manner (`show-battle-params`)
* Search for rare enemy seeds that result in rare enemies on console versions (`find-rare-enemy-seeds`)
* Convert item data to a human-readable description, or vice versa (`describe-item`)
* Connect to another PSO server and pretend to be a client (`cat-client`)
* Replay a session log for testing (`replay-log`)
* Extract the contents of a .gsl or .bml archive (`extract-gsl`, `extract-bml`)
* Generate or describe DC serial numbers (`generate-dc-serial-number`, `inspect-dc-serial-number`)
+11 -8
View File
@@ -1,29 +1,32 @@
## General
- Encapsulate BB server-side random state and make replays deterministic
- Write a simple status API
- Implement per-game logging
- Make reloading happen on separate threads so compression doesn't block active clients
- Implement decrypt/encrypt actions for VMS files
- Make UI strings localizable (e.g. entries in menus, welcome message, etc.)
- Figure out what causes the corruption message on PC proxy sessions and fix it
- Add an idle connection timeout for proxy sessions
- Look into JP heart symbol bug on Linux
- 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 )
## PSO DC
- Investigate if https://crates.io/crates/blaze-ssl-async can be used to implement the HL check server
## Episode 3
- Enforce tournament deck restrictions (e.g. rank checks, No Assist option) when populating COMs at tournament start time
- Add support for recording battles on the proxy server (both in primary and spectator teams)
- Make `reload licenses` not vulnerable to online players' licenses overwriting licenses on disk somehow
- Make `reload accounts` not vulnerable to online players' accounts overwriting accounts on disk somehow
- Implement ranks (based on total Meseta earned)
- Make an AR code that gets rid of the SAMPLE overlays on NTE
## PSO XBOX
- Fix receiving Guild Cards from non-Xbox players
- Research the F94D quest opcode
- Finish porting the remaining GC patches
## PSOBB
- Test all quest item subcommands
- Check if Commander Blade effect works and implement it if not
- Figure out why Pouilly Slime EXP doesn't work
- Make server-specified rare enemies work with maps loaded by the proxy
- Implement serialization for various table types (ItemPMT, ItemPT, etc.)
-16
View File
@@ -1,16 +0,0 @@
struct AITalkBin {
be_uint32_t num_scs;
be_uint32_t sc_offsets[num_scs];
struct SCDialogueEntry {
be_uint32_t num_entries;
be_uint32_t unknown_a1;
be_uint32_t size; // in bytes
struct WhenEntry {
be_uint32_t when;
be_uint32_t percent_chance; // 0-100
be_uint32_t count;
be_uint32_t string_ids[count];
} __attribute__((packed));
} __attribute__((packed));
} __attribute__((packed));
+121 -35
View File
@@ -1,29 +1,83 @@
(Ep1&2 USA) Unlock all songs in BGM test
Unlock all songs in BGM test
(Note: sadly, there are no secret/unused ones)
04368960 38600001
04368964 4E800020
Ep12-JP12 => 04367A68 38600001
04367A6C 4E800020
Ep12-JP13 => 04368ED8 38600001
04368EDC 4E800020
Ep12-JP14 => 0436A434 38600001
0436A438 4E800020
Ep12-JP15 => 0436A1E8 38600001
0436A1EC 4E800020
Ep12-US10 => 0436891C 38600001
04368920 4E800020
Ep12-US11 => 04368960 38600001
04368964 4E800020
Ep12-US12 => 0436A5B4 38600001
0436A5B8 4E800020
Ep12-EU => 043699A8 38600001
043699AC 4E800020
Ep3-NTE => 041EA948 38600001
041EA94C 4E800020
Ep3-JP => 041D8CF0 38600001
041D8CF4 4E800020
Ep3-US => 041D8D7C 38600001
041D8D80 4E800020
Ep3-EU => 041D93F0 38600001
041D93F4 4E800020
(Ep1&2 USA v1.01) Play lobby (and event) music on Pioneer 2 also
0417E0F0 60000000
Play lobby (and event) music in Morgue also
Ep12-JP12 => 0417DD34 60000000
Ep12-JP13 => 0417E0E8 60000000
Ep12-JP14 => 0417E24C 60000000
Ep12-JP15 => 0417E1AC 60000000
Ep12-US10 => 0417E0F0 60000000
Ep12-US11 => 0417E0F0 60000000
Ep12-US12 => 0417E210 60000000
Ep12-EU => 0417E6D4 60000000
Ep3-NTE => 040B8C7C 60000000
Ep3-US => 040B7028 60000000
Ep3-JP => 040B7044 60000000
Ep3-EU => 040B746C 60000000
(Ep3 USA) Play lobby (and event) music in Morgue also
040B7028 60000000
Skip white logo screens during startup
Ep12-JP12 => 0413EE54 38000007
Ep12-JP13 => 0413F1DC 38000007
Ep12-JP14 => 0413F338 38000007
Ep12-JP15 => 0413F298 38000007
Ep12-US10 => 0413F190 38000007
Ep12-US11 => 0413F190 38000007
Ep12-US12 => 0413F2A8 38000007
Ep12-EU => 0413F524 38000007
Ep3-NTE => 0409E10C 38000007
Ep3-JP => 0409D810 38000007
Ep3-US => 0409D774 38000007
Ep3-EU => 0409D9A4 38000007
(Ep3 USA) Skip white logo screens during startup
0409D774 38000007
(Episodes 1&2 USA v1.01) Skip white logo screens during startup
0413F190 38000007
Skip agreement prompts before online game
Ep12-JP12 => 0432737C 38000003
Ep12-JP13 => 043283CC 38000003
Ep12-JP14 => 043298E8 38000003
Ep12-JP15 => 04329690 38000003
Ep12-US10 => 04327D3C 38000003
Ep12-US11 => 04327D80 38000003
Ep12-US12 => 0432984C 38000003
Ep12-EU => 04328C58 38000003
Ep3-NTE => 041C67D0 38000003
Ep3-JP => 041B5234 38000003
Ep3-US => 041B50C8 38000003
Ep3-EU => 041B574C 38000003
(Ep3 USA) Skip agreement prompts before online game
041B50C8 38000003
(Episodes 1&2 USA v1.01) Skip agreement prompt before online game
04327D80 38000003
Disable rate limit for pressing A during loading screens
Ep3-NTE => 042E1030 38000000
Ep3-JP => 042F8BE4 38000000
Ep3-US => 042F9B30 38000000
Ep3-EU => 042FA734 38000000
(Ep3 USA) Disable rate limit for pressing A during loading screens
042F9B30 38000000
(Ep3 USA) Auto-press A as fast as possible during loading screens
042F9AC0 60000000
Auto-press A as fast as possible during loading screens
Ep3-EU => 042FA6C4 60000000
Ep3-US => 042F9AC0 60000000
Ep3-NTE => 040C2C48 60000000
Ep3-JP => 042F8B74 60000000
(Ep3 USA) Replace loading screen A button sounds with random sounds
042F9B18 4804BB19
@@ -32,6 +86,13 @@
042F9B24 64630005
042F9B28 38800000
(Ep3 NTE) Replace loading screen A button sounds with random sounds
042E1018 480309A9
042E101C 5463063E
042E1020 60631400
042E1024 64630005
042E1028 38800000
(Ep3 USA) Change color of loading screens
(Replace AA, RR, GG, BB appropriately)
042FA704 3CC0AARR
@@ -43,11 +104,16 @@
0400BD64 EC5D00B2
0400BD68 4E800020
(Ep3 USA) Disable darkening effect during battle details mode
042F951C 4E800020
Disable darkening effect during battle details mode
Ep3-NTE => 042E09D8 4E800020
Ep3-JP => 042F85D0 4E800020
Ep3-US => 042F951C 4E800020
Ep3-EU => 042FA120 4E800020
(Ep3 USA) Unlock all COM decks
042CA908 38600001
Unlock all COM decks
Ep3-JP => 042C9B34 38600001
Ep3-EU => 042CB414 38600001
Ep3-US => 042CA908 38600001
(Ep3 USA) Enable all lobby counter options in non-CARD lobbies
04096A8C 480000C0
@@ -103,8 +169,11 @@
040002BC 7C633050
040002C0 4E800020
(Ep3 USA) Unlock all offline free battle maps
042CAA00 38600001
Unlock all offline free battle maps
Ep3-NTE => 042BE538 38600001
Ep3-JP => 042C9C2C 38600001
Ep3-EU => 042CB50C 38600001
Ep3-US => 042CAA00 38600001
(This unlocks ALL maps, including a bunch of maps with garbage names that crash if you try to play them)
(Ep3 USA) Talk to auction counter offline to get all cards
@@ -155,7 +224,7 @@
0400BEAC 7C0803A6
0400BEB0 482E9FC0
(Episodes 1&2 USA v1.01) Press L for enemy debug; enable various other debug messages
(Episodes 1&2 USA v1.1) Press L for enemy debug; enable various other debug messages
040FD9D8 38600001 # Various enemy debug messages
00153E53 00000001 # Poison fog debug 1
00153E4B 00000001 # Poison fog debug 2
@@ -165,8 +234,10 @@
025CB6AA 00000001
TODO: Figure out more debug message conditionals (vars/functions) and add them here
(Episode 3 USA) Able to find VIP cards offline (but they're still rare)
042C0B20 4800000C
Able to find VIP cards offline (but they're still rare)
Ep3-EU => 042C15DC 4800000C
Ep3-JP => 042BFE24 4800000C
Ep3-US => 042C0B20 4800000C
(Ep3 USA) Hold L when starting battle to enter debug menu
042C5460 4BD3AF78
@@ -181,8 +252,11 @@ TODO: Figure out more debug message conditionals (vars/functions) and add them h
040003F8 3800001A
040003FC 482C5068
(Ep3 USA) Dressing room always accessible
041A16FC 38600001
Dressing room always accessible
Ep3-NTE => 041B2A2C 38600001
Ep3-JP => 041A1920 38600001
Ep3-EU => 041A1C84 38600001
Ep3-US => 041A16FC 38600001
(Ep3 USA) Full dressing room v1
Can't change your class, but you start with your existing appearance
@@ -201,8 +275,11 @@ Go online with this code on after using the dressing room to fully save changes
(Ep3 USA) Replace Options menu with debug menu
04149E70 38600019
(Ep3 USA) Jukebox is free
0430D1DC 48000024
Jukebox is free
Ep3-NTE => 042248C4 48000024 (useless because the jukebox isn't loaded in NTE, but apparently the code for it exists)
Ep3-JP => 0430C178 48000024
Ep3-US => 0430D1DC 48000024
Ep3-EU => 0430DE3C 48000024
(Ep3 USA) Use own character in battle (online only)
041FFAB0 4800001C
@@ -233,8 +310,11 @@ Go online with this code on after using the dressing room to fully save changes
0412F8D4 7D0803A6
0412F8D8 4BEDEBF4
(Ep3 USA) Metal tiles don't appear in Simulator map
04296904 4E800020
Metal tiles don't appear in Simulator map
Ep3-NTE => 0428FED8 4E800020
Ep3-JP => 04296054 4E800020
Ep3-US => 04296904 4E800020
Ep3-EU => 04297278 4E800020
(Ep3 USA) Enable Boooo and Laughter soundchat sounds
Note: Without a TextEnglish.pr2/pr3 patch, the menu items for these sounds will be blank (but they will still work)
@@ -264,3 +344,9 @@ Note: Without a TextEnglish.pr2/pr3 patch, the menu items for these sounds will
0442B6D8 804D804E
0442B6DC 804F802A
0442B6E0 802C0000
(Ep3 NTE) Use English language files
0408E414 38600001
0408E448 38000001
0408E44C 900DA62C
0408E450 4E800020
+28
View File
@@ -0,0 +1,28 @@
This is a list of common shared serials for the Dreamcast version of the game.
These serials are listed in decimal format for use with newserv and are not valid
for use in the game itself.
If you are looking for a serial number to use for your Dreamcast copy of the game,
please use newserv's DC serial number generator, or PSO Tool GUI at
https://segaxtreme.net/resources/pso-tool-gui-by-razorx.224/
To allow the below shared serials to be used on your server by multiple users, use
the below command (this works if the serial is already registered too):
add-license serial=<serial-number> flags=80000000
---
144243108
297233506
400533035
446310728
532044219
1315107383
1567634924
1748940599
2004318071
2309795986
3811232030
3828776100
4098754580
+56
View File
@@ -0,0 +1,56 @@
List of differences in Ep3 NTE compared to Final:
- Assist cards
- - Dice Fever sets dice to 6, not 5, and there is no Dice Fever +
- - Rich + and Charity + also don't exist
- - Powerless Rain, Brave Wind, Influence, Fix apply at a different phase of the attack procedure
- - Tech Field applies to SCs only; on Final, it applies to SCs and creatures
- - The denominator for Vengeance is 2; on Final it's 3
- - AP Absorption logic is different (TODO: see apply_ap_and_tp_adjust_assists_to_attack)
- - God Whim can use ANY assist card, not only the normally-obtainable ones, and it assigns all 4 players an assist, not only those who already had assists
- - Inflation and Deflation only cause +1 or -1 cost per action, not per card
- - Exchange can be set on other players
- - The SET_MV condition overrides Snail Pace and Stamina completely
- - Stamina sets your effective MV to 99 instead of 9
- - Land Price is 2x instead of 1.5x
- - Shuffle All and Shuffle Group don't respect deck shuffle/loop disabled settings
- - Assist Vanish clears immediately, which means it can override other assists that happen at the same time (Trash 1, Empty Hand, etc.); in Final it happens after those
- Abilities
- - Rampage and Pierce are not player-specific; that is, if an attack has Rampage against one target, it has Rampage against all targets (this distinction is important for conditional abilities like Major Rampage and Heavy Pierce)
- - Several abilities don't exist (TODO: Which ones? 0x64 and above?)
- - Abnormal conditions do not have priorities like they do on Final
- - Ability Trap seems incompletely implemented (or not implemented at all?)
- - It appears that Major Pierce doesn't work against Arkz SCs, and this was fixed in Final
- Conditions
- - Anti-Abnormality doesn't prevent Freeze, Drop, Guom, or Curse
- - SCs can get Freeze (they can't in Final)
- - Bosses do not have automatic Anti-Abnormality
- - Ability Trap prevents all abnormal conditions
- Traps
- - Traps trigger as soon as you move into their tile; on Final, they trigger at the end of the Move phase
- - Traps may use any assist card, and this can be configured in the map definition (TODO: verify this last part)
- Rules
- - Dice Boost does not exist
- - ATK and DEF dice ranges can be set independently, but there are only 7 options for each: 1-6, 1-1, 2-2, 3-3, 4-4, 5-5, 6-6
- - There may be a bug when either die is set to 1-1 so you'll always get 2 instead (TODO: verify this)
- COM interference is not implemented
- The target's defense power is computed after checking if the attack is Resta instead of before
- Card definitions
- - The n21 and n22 arg2 conditions don't exist
- - The p25 condition finds cards with Paralyze or Fly in NTE, vs. Aerial or Fly in Final; looks like a copy-paste error by Sega
- - The p36 condition includes SCs and items on NTE, but only SCs on Final
- - The p41 condition includes only your team on NTE, but both teams on Final
- - Several tokens can't be used in expr fields: ddm, sat, edm, ldm, rdm, fdm, ndm, ehp
- Missing rule checks
- - Boss SCs can use items
- - Move logic is different, which I didn't reverse-engineer because I was too lazy and couldn't imagine how it could be meaningfully different from Final
- - Many values are not clamped (in Final, many are clamped to 0-9 or -99-99)
- - You can set cards that aren't actually in your hand
- - The game assumes team A always is at the top facing down and team B is always at the bottom facing up; if the map defines them to start on different edges or facing different directions than expected, the creature summoning areas will be wrong
- - Character HP rule completely overrides the HP stat on SC cards; in Final, the SC's HP stat is added to Character HP
- - Boss SCs are not exempt from this either; they have the same HP as normal SCs
- - Cards marked as dead but not yet deleted can still attack
- - The HOLD (6) and CANNOT_DEFEND (7) conditions don't actually stop you from defending
- - There is no hard limit of 1000 turns for any battle
- - In case of a draw, the first two tiebreaker rules (number of dead SCs and remaining SC HP) are skipped
- The server cannot override EXP result values (thus post-battle EXP loss cannot be disabled)
- Surprisingly, the code for PBs is identical between NTE and Final; it seems like they didn't spend any time on PBs after NTE at all
+1 -1
View File
@@ -81,7 +81,7 @@ blr
Ep1&2 v1.01 version of the above code
Ep1&2 v1.1 version of the above code
send_D9
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DA398
+1 -1
View File
@@ -72,7 +72,7 @@ def write_patches_for_code(
f.write("reloc0:\n")
f.write(" .offsetof start\n")
f.write("start:\n")
f.write(" .include WriteCodeBlocks\n")
f.write(" .include WriteCodeBlocksGC\n")
for region in write_regions:
f.write(
f" # region @ {region.address:08X} ({len(region.data) * 4} bytes)\n"
+1026 -984
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -718,8 +718,8 @@ JP12------------- JP13------------- JP14------------- JP15------------- US10----
80267EC8 4BDA57D8 80268B74 4BDA4B2C 80269BD0 4BDA3AD0 80269984 4BDA3D1C 80268874 4BDA4E2C 80268874 4BDA4E2C 80269C48 4BDA3A58 80269490 4BDA4210 b -0x0025B1D4 /* 8000D6A0 */
Improved Draw Distance of most objects
DrawDistance
*** name=DrawDistance
Draw Distance
*** name=Draw Distance
*** desc=Extend the draw\ndistance of many\nobjects
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C1F8 8000DFA0 C3C2C200 8000DFA0 C3C2C200 8000DFA0 C3C2C200 8000DFA0 C3C2C200 lfs f30, [r2 - 0x3E00]
-2785
View File
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
########################################################################
Restore JP PSOBB original IME Behavior
########################################################################
The default Tethealla client included a custom patch to disable the IME
system in-game which allows you to type in Japanese (presumably to allow
English versions of Windows to type properly)
However, if you plan to play PSOBB in it's original Japanese language it
is recommended you remove this patch to restore the original functions
Open a unpacked PSOBB.exe in a hex editor and:
FIND 9CC38E
REPLACE WITH A8838F
Make sure to install Japanese Language Support in Windows 10/11 to enable
the Japanese keyboard and IME.
If there's a problem, you can also use the Legacy IME by heading into the
options of the Japanese Language settings and scroll down to the bottom of
the page to enable Legacy IME Support to restore the original Pre-Windows 7
IME system.
Last but not least, remember the default Tethealla client is the original
Japanese client, so you don't need to apply any other special patch but this
one and make sure you have the original Japanese files set in your data folder
the game should start entirely in Japanese.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
-11
View File
@@ -1,11 +0,0 @@
star value tables
psobb [B1-437]
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 0A0A0C0A 090A0C09 0A0B0A0A 0A0A0C0A 0A0A0A09 0A0C0A09 0A0A0A0A 0A090C0B 09090909 09090909 09090909 09090909 0909090B 0A0C0A0B 0B0C0A0A 0A090A0A 0A0A0B0A 0A0A0A0A 0909090A 0A090C0A 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0102 03040102 03040203 04020304 01020304 01020304 01020304 01020304 01020304 01020304 03040000 00010102 02030304 04050506 06070707 07080808 08080809 09090A0A 0A0A0A0A 0B0C0A0A 0A0A0A0A 0B0B0B0A 0B0B0C0B 0B0B0B0B 0A0A0A0A 0A0A0C09 0909090A 0A0B0C09 0B0A0A0A 0A0A0A0A 0A0A0A0B 0A0A0A0A 0A0A0A00 00010203 03040405 05050606 07070808 08080808 0A0A0A0A 0A0A0909 090A0A0A 0A0A0A0A 0A0A0B0A 0A0B0A09 0909090A 0B0B0000 0B000000 00080808 08080808 09080808 09080808 09070707 07070909 090C0909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 0A0A0B0A 0B0A0909 0B0B0B0C 0A0A0A09 0A0A0A0A 090A0A0A 0A0A0A0A 0A0A0A0A 0203050B 0203050B 0203050B 0203050B 0204060B 0204060B 0203050B 080B080A 0B020305 02030502 03050304 06030405 07080B04 06090406 09040609 06090B06 090B0909 09090909 0A0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0A0B0B0B 0B0B0B0B
psogc [94-2F7]
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 01020304 01020304 02030402 03040102 03040102 03040102 03040102 03040102 03040102 03040304 00000001 01020203 03040405 05060607 07070708 08080808 08090909 0A0A0A0A 0A0A0B0C 0A0A0A0A 0A0A0B0B 0B0A0B0B 0C0B0B0B 0B0B0000 01020303 04040505 05060607 07080808 0808080A 0A0A0A0A 0A090909 0A0A0A0A 0A0A0A0A 0A0B0A0A 0B0A0909 09090A0B 0B000000 00000000 08080808 08080809 08080809 08080809 07070707 07090909 0C090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090902 03050B02 03050B02 03050B02 03050B02 04060B02 04060B02 03050B08 0B080A0B 02030502 03050203 05030406 03040507 080B0406 09040609 04060906 090B0609 0B090909 090909
0203050B0203050B0203050B0203050B
+4 -2
View File
@@ -7,6 +7,8 @@
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include "Text.hh"
using namespace std;
AFSArchive::AFSArchive(shared_ptr<const string> data)
@@ -14,12 +16,12 @@ AFSArchive::AFSArchive(shared_ptr<const string> data)
struct FileHeader {
be_uint32_t magic;
le_uint32_t num_files;
} __attribute__((packed));
} __packed_ws__(FileHeader, 8);
struct FileEntry {
le_uint32_t offset;
le_uint32_t size;
} __attribute__((packed));
} __packed_ws__(FileEntry, 8);
StringReader r(*this->data);
const auto& header = r.get<FileHeader>();
+4
View File
@@ -9,6 +9,10 @@ inline void run_ar_code_translator(const std::string&, const std::string&, const
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline void run_xbe_patch_translator(const std::string&, const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
+242 -3
View File
@@ -5,6 +5,7 @@
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <resource_file/ExecutableFormats/DOLFile.hh>
#include <resource_file/ExecutableFormats/XBEFile.hh>
using namespace std;
@@ -63,11 +64,11 @@ public:
}
void set_source_file(const string& filename) {
this->src_filename = filename;
this->src_file = files.at(this->src_filename);
this->src_file = this->files.at(this->src_filename);
}
void find_rtoc_global_regs() const {
for (const auto& it : files) {
for (const auto& it : this->files) {
bool r2_high_found = false;
bool r2_low_found = false;
bool r13_high_found = false;
@@ -258,7 +259,7 @@ public:
}
unordered_map<string, uint32_t> results;
for (const auto& it : files) {
for (const auto& it : this->files) {
if (it.second == this->src_file) {
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
results.emplace(it.first, src_addr);
@@ -349,6 +350,231 @@ private:
shared_ptr<const DOLFile> src_file;
};
class XBEPatchTranslator {
public:
enum class ExpandMethod {
FORWARD = 0,
BACKWARD,
BOTH,
};
static const char* name_for_expand_method(ExpandMethod method) {
switch (method) {
case ExpandMethod::FORWARD:
return "FORWARD";
case ExpandMethod::BACKWARD:
return "BACKWARD";
case ExpandMethod::BOTH:
return "BOTH";
default:
throw logic_error("invalid expand method");
}
}
XBEPatchTranslator(const string& directory)
: log("[xbe-trans] "),
directory(directory) {
while (ends_with(this->directory, "/")) {
this->directory.pop_back();
}
for (const auto& filename : list_directory(this->directory)) {
if (ends_with(filename, ".xbe")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
this->files.emplace(name, make_shared<XBEFile>(path.c_str()));
this->log.info("Loaded %s", name.c_str());
}
}
}
~XBEPatchTranslator() = default;
const string& get_source_filename() const {
return this->src_filename;
}
void set_source_file(const string& filename) {
this->src_filename = filename;
this->src_file = this->files.at(this->src_filename);
}
uint32_t find_match(
shared_ptr<const XBEFile> dest_file,
uint32_t src_address,
uint32_t src_size,
ExpandMethod expand_method) const {
if (!this->src_file) {
throw runtime_error("no source file selected");
}
const XBEFile::Section* src_section = nullptr;
for (const auto& sec : this->src_file->sections) {
if (src_address >= sec.addr && src_address < sec.addr + sec.file_size) {
src_section = &sec;
break;
}
}
if (!src_section) {
throw runtime_error("source address not within any section");
}
const char* method_token = this->name_for_expand_method(expand_method);
size_t src_offset = src_address - src_section->addr;
size_t src_bytes_available_before = src_offset;
size_t src_bytes_available_after = src_section->file_size - src_offset - src_size;
this->log.info("(find_match/%s) Source offset = %08zX with %zX/%zX bytes available before/after",
method_token, src_offset, src_bytes_available_before, src_bytes_available_after);
size_t match_bytes_before = 0;
size_t match_bytes_after = 0;
while (match_bytes_before + match_bytes_after + src_size < 0x100) {
size_t num_matches = 0;
size_t last_match_address = 0;
size_t match_length = match_bytes_before + match_bytes_after + src_size;
auto src_r = this->src_file->read_from_addr(src_section->addr + src_offset - match_bytes_before, match_length);
for (const auto& dest_section : dest_file->sections) {
for (size_t dest_match_offset = 0; dest_match_offset + match_length <= dest_section.file_size; dest_match_offset++) {
src_r.go(0);
StringReader dest_r = dest_file->read_from_addr(dest_section.addr + dest_match_offset, match_length);
size_t z;
for (z = 0; z < match_length; z++) {
uint8_t src_data = src_r.get_u8();
uint8_t dest_data = dest_r.get_u8();
if (src_data != dest_data) {
break;
}
}
if (z == match_length) {
num_matches++;
last_match_address = dest_section.addr + dest_match_offset + match_bytes_before;
}
}
}
this->log.info("(find_match/%s) For match length %zX, %zu matches found", method_token, match_length, num_matches);
if (num_matches == 1) {
return last_match_address;
} else if (num_matches == 0) {
throw runtime_error("did not find exactly one match");
}
bool can_expand_backward = false;
bool can_expand_forward = false;
switch (expand_method) {
case ExpandMethod::BACKWARD:
can_expand_backward = (src_bytes_available_before > match_bytes_before);
break;
case ExpandMethod::FORWARD:
can_expand_forward = (src_bytes_available_after > match_bytes_after);
break;
case ExpandMethod::BOTH:
can_expand_backward = (src_bytes_available_before > match_bytes_before);
can_expand_forward = (src_bytes_available_after > match_bytes_after);
break;
default:
throw logic_error("invalid expand method");
}
if (!can_expand_backward && !can_expand_forward) {
throw runtime_error("no further expansion is allowed");
}
if (can_expand_backward) {
match_bytes_before++;
}
if (can_expand_forward) {
match_bytes_after++;
}
}
throw runtime_error("scan field too long; too many matches");
}
void find_all_matches(uint32_t src_addr, uint32_t src_size) const {
if (!this->src_file) {
throw runtime_error("no source file selected");
}
unordered_map<string, uint32_t> results;
for (const auto& it : files) {
if (it.second == this->src_file) {
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
results.emplace(it.first, src_addr);
} else {
array<future<uint32_t>, 3> futures;
static const array<ExpandMethod, 3> methods = {
ExpandMethod::FORWARD,
ExpandMethod::BACKWARD,
ExpandMethod::BOTH,
};
for (size_t z = 0; z < methods.size(); z++) {
futures[z] = async(&XBEPatchTranslator::find_match, this, it.second, src_addr, src_size, methods[z]);
}
unordered_set<uint32_t> match_addrs;
for (size_t z = 0; z < futures.size(); z++) {
const char* method_name = this->name_for_expand_method(methods[z]);
try {
uint32_t ret = futures[z].get();
log.info("(%s) (%s) %08" PRIX32, it.first.c_str(), method_name, ret);
match_addrs.emplace(ret);
} catch (const exception& e) {
log.error("(%s) (%s) failed: %s", it.first.c_str(), method_name, e.what());
}
}
if (match_addrs.empty()) {
log.error("(%s) no match found", it.first.c_str());
} else if (match_addrs.size() > 1) {
log.error("(%s) different matches found by different methods", it.first.c_str());
} else {
results.emplace(it.first, *match_addrs.begin());
}
}
}
for (const auto& it : results) {
fprintf(stdout, "%s => %08" PRIX32 "\n", it.first.c_str(), it.second);
}
}
void handle_command(const string& command) {
auto tokens = split(command, ' ');
if (tokens.empty()) {
throw runtime_error("no command given");
}
strip_trailing_whitespace(tokens[tokens.size() - 1]);
if (tokens[0] == "use") {
this->set_source_file(tokens.at(1));
} else if (tokens[0] == "match") {
this->find_all_matches(stoul(tokens.at(1), nullptr, 16), stoul(tokens.at(2), nullptr, 16));
} else if (!tokens[0].empty()) {
throw runtime_error("unknown command");
}
}
void run_shell() {
while (!feof(stdin)) {
if (!this->src_filename.empty()) {
fprintf(stdout, "ar-trans:%s/%s> ", this->directory.c_str(), this->src_filename.c_str());
} else {
fprintf(stdout, "ar-trans:%s> ", this->directory.c_str());
}
fflush(stdout);
string command = fgets(stdin);
try {
this->handle_command(command);
} catch (const exception& e) {
this->log.error("Failed: %s", e.what());
}
}
fputc('\n', stdout);
}
private:
PrefixedLogger log;
string directory;
unordered_map<string, shared_ptr<const XBEFile>> files;
string src_filename;
shared_ptr<const XBEFile> src_file;
};
void run_ar_code_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
ARCodeTranslator trans(directory);
if (!use_filename.empty()) {
@@ -362,6 +588,19 @@ void run_ar_code_translator(const std::string& directory, const std::string& use
}
}
void run_xbe_patch_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
XBEPatchTranslator trans(directory);
if (!use_filename.empty()) {
trans.set_source_file(use_filename);
}
if (!command.empty()) {
trans.handle_command(command);
} else {
trans.run_shell();
}
}
vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const string& b_filename) {
DOLFile a(a_filename.c_str());
DOLFile b(b_filename.c_str());
+2 -1
View File
@@ -6,5 +6,6 @@
#include <utility>
#include <vector>
void run_ar_code_translator(const std::string& initial_directory, const std::string& use_file, const std::string& command);
void run_ar_code_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
void run_xbe_patch_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
+1003
View File
File diff suppressed because it is too large Load Diff
+263
View File
@@ -0,0 +1,263 @@
#pragma once
#include <memory>
#include <mutex>
#include <phosg/JSON.hh>
#include <shared_mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "Text.hh"
class LicenseIndex;
struct DCNTELicense {
std::string serial_number;
std::string access_key;
static std::shared_ptr<DCNTELicense> from_json(const JSON& json);
JSON json() const;
};
struct V1V2License {
uint32_t serial_number = 0;
std::string access_key;
static std::shared_ptr<V1V2License> from_json(const JSON& json);
JSON json() const;
};
struct GCLicense {
uint32_t serial_number = 0;
std::string access_key;
std::string password;
static std::shared_ptr<GCLicense> from_json(const JSON& json);
JSON json() const;
};
struct XBLicense {
std::string gamertag;
uint64_t user_id = 0;
uint64_t account_id = 0;
static std::shared_ptr<XBLicense> from_json(const JSON& json);
JSON json() const;
};
struct BBLicense {
std::string username;
std::string password;
static std::shared_ptr<BBLicense> from_json(const JSON& json);
JSON json() const;
};
struct Account {
enum class Flag : uint32_t {
// clang-format off
KICK_USER = 0x00000001,
BAN_USER = 0x00000002,
SILENCE_USER = 0x00000004,
CHANGE_EVENT = 0x00000010,
ANNOUNCE = 0x00000020,
FREE_JOIN_GAMES = 0x00000040,
DEBUG = 0x01000000,
CHEAT_ANYWHERE = 0x02000000,
DISABLE_QUEST_REQUIREMENTS = 0x04000000,
ALWAYS_ENABLE_CHAT_COMMANDS = 0x08000000,
MODERATOR = 0x00000007,
ADMINISTRATOR = 0x000000FF,
ROOT = 0x7FFFFFFF,
IS_SHARED_ACCOUNT = 0x80000000,
// NOTE: When adding or changing license flags, don't forget to change the
// documentation in the shell's help text.
UNUSED_BITS = 0x70FFFF00,
// clang-format on
};
// account_id is also the account's guild card number
uint32_t account_id = 0;
uint32_t flags = 0;
uint64_t ban_end_time = 0; // 0 = not banned
std::string last_player_name;
std::string auto_reply_message;
uint32_t ep3_current_meseta = 0;
uint32_t ep3_total_meseta_earned = 0;
uint32_t bb_team_id = 0;
bool is_temporary = false; // If true, isn't saved to disk
std::unordered_set<std::string> auto_patches_enabled;
std::unordered_map<std::string, std::shared_ptr<DCNTELicense>> dc_nte_licenses;
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> dc_licenses;
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> pc_licenses;
std::unordered_map<uint32_t, std::shared_ptr<GCLicense>> gc_licenses;
std::unordered_map<std::string, std::shared_ptr<XBLicense>> xb_licenses;
std::unordered_map<std::string, std::shared_ptr<BBLicense>> bb_licenses;
Account() = default;
explicit Account(const JSON& json);
virtual ~Account() = default;
JSON json() const;
virtual void save() const;
virtual void delete_file() const;
[[nodiscard]] inline bool check_flag(Flag flag) const {
return !!(this->flags & static_cast<uint32_t>(flag));
}
inline void set_flag(Flag flag) {
this->flags |= static_cast<uint32_t>(flag);
}
inline void clear_flag(Flag flag) {
this->flags &= (~static_cast<uint32_t>(flag));
}
inline void toggle_flag(Flag flag) {
this->flags ^= static_cast<uint32_t>(flag);
}
inline void replace_all_flags(Flag mask) {
this->flags = static_cast<uint32_t>(mask);
}
void print(FILE* stream) const;
};
struct Login {
bool account_was_created = false;
// This field will never be null
std::shared_ptr<Account> account;
// Exactly one of the following will be non-null, representing the license
// that the client logged in with
std::shared_ptr<DCNTELicense> dc_nte_license;
std::shared_ptr<V1V2License> dc_license;
std::shared_ptr<V1V2License> pc_license;
std::shared_ptr<GCLicense> gc_license;
std::shared_ptr<XBLicense> xb_license;
std::shared_ptr<BBLicense> bb_license;
};
class AccountIndex {
public:
class no_username : public std::invalid_argument {
public:
no_username() : invalid_argument("serial number is zero or username is missing") {}
};
class incorrect_password : public std::invalid_argument {
public:
incorrect_password() : invalid_argument("incorrect password") {}
};
class incorrect_access_key : public std::invalid_argument {
public:
incorrect_access_key() : invalid_argument("incorrect access key") {}
};
class missing_account : public std::invalid_argument {
public:
missing_account() : invalid_argument("missing account") {}
};
explicit AccountIndex(bool force_all_temporary);
virtual ~AccountIndex() = default;
std::shared_ptr<Account> create_account(bool is_temporary) const;
size_t count() const;
std::vector<std::shared_ptr<Account>> all() const;
void add(std::shared_ptr<Account> a);
void remove(uint32_t serial_number);
void add_dc_nte_license(std::shared_ptr<Account> account, std::shared_ptr<DCNTELicense> license);
void add_dc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
void add_pc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
void add_gc_license(std::shared_ptr<Account> account, std::shared_ptr<GCLicense> license);
void add_xb_license(std::shared_ptr<Account> account, std::shared_ptr<XBLicense> license);
void add_bb_license(std::shared_ptr<Account> account, std::shared_ptr<BBLicense> license);
void remove_dc_nte_license(std::shared_ptr<Account> account, const std::string& serial_number);
void remove_dc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_pc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_gc_license(std::shared_ptr<Account> account, uint32_t serial_number);
void remove_xb_license(std::shared_ptr<Account> account, const std::string& gamertag);
void remove_bb_license(std::shared_ptr<Account> account, const std::string& username);
std::shared_ptr<Account> from_account_id(uint32_t account_id) const;
std::shared_ptr<Login> from_dc_nte_credentials(
const std::string& serial_number,
const std::string& access_key,
bool allow_create);
std::shared_ptr<Login> from_dc_credentials(
uint32_t serial_number,
const std::string& access_key,
const std::string& character_name,
bool allow_create);
std::shared_ptr<Login> from_pc_nte_credentials(
uint32_t guild_card_number,
bool allow_create);
std::shared_ptr<Login> from_pc_credentials(
uint32_t serial_number,
const std::string& access_key,
const std::string& character_name,
bool allow_create);
std::shared_ptr<Login> from_gc_credentials(
uint32_t serial_number,
const std::string& access_key,
const std::string* password,
const std::string& character_name,
bool allow_create);
std::shared_ptr<Login> from_xb_credentials(
const std::string& gamertag,
uint64_t user_id,
uint64_t account_id,
bool allow_create);
std::shared_ptr<Login> from_bb_credentials(
const std::string& username,
const std::string* password,
bool allow_create);
std::shared_ptr<Account> create_temporary_account_for_shared_account(
std::shared_ptr<const Account> src_a, const std::string& variation_data) const;
protected:
bool force_all_temporary;
// This class must be thread-safe because it's used by both the patch server
// and game server threads
mutable std::shared_mutex lock;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_account_id;
std::unordered_map<std::string, std::shared_ptr<Account>> by_dc_nte_serial_number;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_dc_serial_number;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_pc_serial_number;
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_gc_serial_number;
std::unordered_map<std::string, std::shared_ptr<Account>> by_xb_gamertag;
std::unordered_map<std::string, std::shared_ptr<Account>> by_bb_username;
void add_locked(std::shared_ptr<Account> a);
std::shared_ptr<Login> from_dc_nte_credentials_locked(
const std::string& serial_number,
const std::string& access_key);
std::shared_ptr<Login> from_dc_credentials_locked(
uint32_t serial_number,
const std::string& access_key,
const std::string& character_name);
std::shared_ptr<Login> from_pc_credentials_locked(
uint32_t serial_number,
const std::string& access_key,
const std::string& character_name);
std::shared_ptr<Login> from_gc_credentials_locked(
uint32_t serial_number,
const std::string& access_key,
const std::string* password,
const std::string& character_name);
std::shared_ptr<Login> from_xb_credentials_locked(
const std::string& gamertag,
uint64_t user_id,
uint64_t account_id);
std::shared_ptr<Login> from_bb_credentials_locked(
const std::string& username,
const std::string* password);
};
+16 -6
View File
@@ -9,16 +9,21 @@
using namespace std;
template <bool IsBigEndian>
struct BMLHeader {
struct BMLHeaderT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
parray<uint8_t, 0x04> unknown_a1;
U32T num_entries;
parray<uint8_t, 0x38> unknown_a2;
} __attribute__((packed));
} __packed__;
using BMLHeader = BMLHeaderT<false>;
using BMLHeaderBE = BMLHeaderT<true>;
check_struct_size(BMLHeader, 0x40);
check_struct_size(BMLHeaderBE, 0x40);
template <bool IsBigEndian>
struct BMLHeaderEntry {
struct BMLHeaderEntryT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
pstring<TextEncoding::ASCII, 0x20> filename;
@@ -28,17 +33,22 @@ struct BMLHeaderEntry {
U32T compressed_gvm_size;
U32T decompressed_gvm_size;
parray<uint8_t, 0x0C> unknown_a2;
} __attribute__((packed));
} __packed__;
using BMLHeaderEntry = BMLHeaderEntryT<false>;
using BMLHeaderEntryBE = BMLHeaderEntryT<true>;
check_struct_size(BMLHeaderEntry, 0x40);
check_struct_size(BMLHeaderEntryBE, 0x40);
template <bool IsBigEndian>
void BMLArchive::load_t() {
StringReader r(*this->data);
const auto& header = r.get<BMLHeader<IsBigEndian>>();
const auto& header = r.get<BMLHeaderT<IsBigEndian>>();
size_t offset = 0x800;
while (this->entries.size() < header.num_entries) {
const auto& entry = r.get<BMLHeaderEntry<IsBigEndian>>();
const auto& entry = r.get<BMLHeaderEntryT<IsBigEndian>>();
if (offset + entry.compressed_size > this->data->size()) {
throw runtime_error("BML data entry extends beyond end of data");
+1 -1
View File
@@ -20,7 +20,7 @@ void BattleParamsIndex::Table::print(FILE* stream) const {
e.char_stats.dfp.load(),
e.char_stats.ata.load(),
e.char_stats.lck.load(),
e.unknown_a1.load(),
e.esp.load(),
e.experience.load(),
e.meseta.load());
};
+5 -5
View File
@@ -24,7 +24,7 @@ public:
/* 04 */ le_int16_t ata_bonus;
/* 06 */ le_uint16_t unknown_a4;
/* 08 */ le_float distance_x;
/* 0C */ le_float angle_x;
/* 0C */ le_uint32_t angle_x; // Out of 0x10000 (high 16 bits are unused)
/* 10 */ le_float distance_y;
/* 14 */ le_uint16_t unknown_a8;
/* 16 */ le_uint16_t unknown_a9;
@@ -36,7 +36,7 @@ public:
/* 28 */ le_uint32_t unknown_a15;
/* 2C */ le_uint32_t unknown_a16;
/* 30 */
} __attribute__((packed));
} __packed_ws__(AttackData, 0x30);
struct ResistData {
/* 00 */ le_int16_t evp_bonus;
@@ -51,7 +51,7 @@ public:
/* 18 */ le_uint32_t unknown_a9;
/* 1C */ le_int32_t dfp_bonus;
/* 20 */
} __attribute__((packed));
} __packed_ws__(ResistData, 0x20);
struct MovementData {
/* 00 */ le_float idle_move_speed;
@@ -67,7 +67,7 @@ public:
/* 28 */ le_uint32_t unknown_a7;
/* 2C */ le_uint32_t unknown_a8;
/* 30 */
} __attribute__((packed));
} __packed_ws__(MovementData, 0x30);
struct Table {
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats;
@@ -77,7 +77,7 @@ public:
/* F600 */
void print(FILE* stream) const;
} __attribute__((packed));
} __packed_ws__(Table, 0xF600);
BattleParamsIndex(
std::shared_ptr<const std::string> data_on_ep1, // BattleParamEntry_on.dat
+66 -15
View File
@@ -31,21 +31,19 @@
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)
: Shell(base),
log(string_printf("[CatSession:%s] ", name_for_enum(version)), proxy_server_log.min_level),
channel(
version,
1,
CatSession::dispatch_on_channel_input,
CatSession::dispatch_on_channel_error,
this,
"CatSession"),
: log(string_printf("[CatSession:%s] ", 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");
}
@@ -58,12 +56,20 @@ CatSession::CatSession(
if (!bev) {
throw runtime_error(string_printf("failed to open socket (%d)", EVUTIL_SOCKET_ERROR()));
}
this->channel.set_bufferevent(bev);
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(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 = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
}
void CatSession::dispatch_on_channel_input(
@@ -129,9 +135,54 @@ void CatSession::on_channel_error(short events) {
}
}
void CatSession::print_prompt() {}
void CatSession::execute_command(const std::string& command) {
string full_cmd = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
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());
}
}
}
+18 -5
View File
@@ -14,28 +14,41 @@
#include "PSOEncryption.hh"
#include "PSOProtocol.hh"
#include "ServerState.hh"
#include "Shell.hh"
class CatSession : public Shell {
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:
PrefixedLogger log;
std::shared_ptr<struct event_base> base;
std::unique_ptr<struct event, void (*)(struct event*)> read_event;
Poll poll;
Channel channel;
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
virtual void print_prompt();
class exit_shell : public std::runtime_error {
public:
exit_shell();
~exit_shell() = default;
};
virtual void execute_command(const std::string& command);
static void dispatch_on_channel_input(
Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
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();
};
+9 -12
View File
@@ -32,6 +32,7 @@ Channel::Channel(
TerminalFormat terminal_send_color,
TerminalFormat terminal_recv_color)
: bev(nullptr, flush_and_free_bufferevent),
virtual_network_id(0),
version(version),
language(language),
name(name),
@@ -44,6 +45,7 @@ Channel::Channel(
Channel::Channel(
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
uint8_t language,
on_command_received_t on_command_received,
@@ -61,7 +63,7 @@ Channel::Channel(
on_command_received(on_command_received),
on_error(on_error),
context_obj(context_obj) {
this->set_bufferevent(bev);
this->set_bufferevent(bev, virtual_network_id);
}
void Channel::replace_with(
@@ -70,10 +72,9 @@ void Channel::replace_with(
on_error_t on_error,
void* context_obj,
const std::string& name) {
this->set_bufferevent(other.bev.release());
this->set_bufferevent(other.bev.release(), other.virtual_network_id);
this->local_addr = other.local_addr;
this->remote_addr = other.remote_addr;
this->is_virtual_connection = other.is_virtual_connection;
this->version = other.version;
this->language = other.language;
this->crypt_in = other.crypt_in;
@@ -87,27 +88,23 @@ void Channel::replace_with(
other.disconnect(); // Clears crypts, addrs, etc.
}
void Channel::set_bufferevent(struct bufferevent* bev) {
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) {
this->is_virtual_connection = true;
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
} else {
this->is_virtual_connection = false;
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_setcb(this->bev.get(), &Channel::dispatch_on_input, nullptr, &Channel::dispatch_on_error, this);
bufferevent_enable(this->bev.get(), EV_READ | EV_WRITE);
} else {
this->is_virtual_connection = false;
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
}
@@ -149,7 +146,7 @@ void Channel::disconnect() {
memset(&this->local_addr, 0, sizeof(this->local_addr));
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
this->is_virtual_connection = false;
this->virtual_network_id = false;
this->crypt_in.reset();
this->crypt_out.reset();
}
@@ -271,7 +268,7 @@ void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<cons
case Version::DC_V2:
case Version::GC_NTE:
case Version::GC_V3:
case Version::GC_EP3_TRIAL_EDITION:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
case Version::XB_V3: {
PSOCommandHeaderDCV3 header;
+3 -2
View File
@@ -13,7 +13,7 @@ struct Channel {
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev;
struct sockaddr_storage local_addr;
struct sockaddr_storage remote_addr;
bool is_virtual_connection;
uint64_t virtual_network_id; // 0 = normal TCP connection
Version version;
uint8_t language;
@@ -50,6 +50,7 @@ struct Channel {
// 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,
@@ -70,7 +71,7 @@ struct Channel {
void* context_obj,
const std::string& name = "");
void set_bufferevent(struct bufferevent* bev);
void set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id);
inline bool connected() const {
return this->bev.get() != nullptr;
+657 -176
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -120,7 +120,7 @@ const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
case Version::GC_V3:
case Version::XB_V3:
return (choice_id == 0x0004);
case Version::GC_EP3_TRIAL_EDITION:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
return (choice_id == 0x0005);
case Version::BB_V4:
+27 -6
View File
@@ -10,12 +10,16 @@
class Client;
struct ChoiceSearchConfig {
le_uint32_t disabled = 1; // 0 = enabled, 1 = disabled. Unused in command C3
template <bool IsBigEndian>
struct ChoiceSearchConfigT {
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
U32T disabled = 1; // 0 = enabled, 1 = disabled. Unused in command C3
struct Entry {
le_uint16_t parent_choice_id = 0;
le_uint16_t choice_id = 0;
} __attribute__((packed));
U16T parent_choice_id = 0;
U16T choice_id = 0;
} __packed_ws__(Entry, 4);
parray<Entry, 5> entries;
int32_t get_setting(uint16_t parent_choice_id) const {
@@ -26,7 +30,24 @@ struct ChoiceSearchConfig {
}
return -1;
}
} __attribute__((packed));
operator ChoiceSearchConfigT<!IsBigEndian>() const {
ChoiceSearchConfigT<!IsBigEndian> ret;
ret.disabled = this->disabled.load();
for (size_t z = 0; z < this->entries.size(); z++) {
auto& ret_e = ret.entries[z];
const auto& this_e = this->entries[z];
ret_e.parent_choice_id = this_e.parent_choice_id.load();
ret_e.choice_id = this_e.choice_id.load();
}
return ret;
}
} __packed__;
using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
check_struct_size(ChoiceSearchConfig, 0x18);
check_struct_size(ChoiceSearchConfigBE, 0x18);
struct ChoiceSearchCategory {
struct Choice {
+219 -109
View File
@@ -11,6 +11,7 @@
#include <phosg/Network.hh>
#include <phosg/Time.hh>
#include "IPStackSimulator.hh"
#include "Loggers.hh"
#include "Server.hh"
#include "Version.hh"
@@ -23,7 +24,15 @@ static atomic<uint64_t> next_id(1);
void Client::Config::set_flags_for_version(Version version, int64_t sub_version) {
this->set_flag(Flag::PROXY_CHAT_COMMANDS_ENABLED);
this->set_flag(Flag::PROXY_CHAT_FILTER_ENABLED);
// BB shares some sub_version values with GC Episode 3, so we handle it
// separately first.
if (version == Version::BB_V4) {
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::SAVE_ENABLED);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
return;
}
switch (sub_version) {
case -1: // Initial check (before sub_version recognition)
@@ -36,6 +45,9 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1:
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break;
case Version::DC_V2:
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
@@ -48,7 +60,7 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
break;
case Version::GC_NTE:
case Version::GC_V3:
case Version::GC_EP3_TRIAL_EDITION:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
break;
case Version::XB_V3:
@@ -56,11 +68,6 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case Version::BB_V4:
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::SAVE_ENABLED);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
default:
throw logic_error("invalid game version");
}
@@ -70,16 +77,16 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
case 0x21: // DCv1 US
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
// In the case of DCNTE, the IS_DC_TRIAL_EDITION flag is already set when
// we get here
break;
case 0x23: // DCv1 EU
case 0x22: // DCv1 EU 50Hz (presumably)
case 0x23: // DCv1 EU 60Hz (presumably)
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break;
case 0x25: // DCv2 JP
case 0x26: // DCv2 US
case 0x28: // DCv2 EU
case 0x27: // DCv2 EU 50Hz (presumably)
case 0x28: // DCv2 EU 60Hz (presumably)
this->set_flag(Flag::NO_D6);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
@@ -88,36 +95,32 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case 0x30: // GC Ep1&2 GameJam demo, GC Ep1&2 Trial Edition, GC Ep1&2 JP v1.02, at least one version of XB
case 0x31: // GC Ep1&2 US v1.00, GC US v1.01, XB US
case 0x34: // GC Ep1&2 JP v1.03
// In the case of GC Trial Edition, the IS_GC_TRIAL_EDITION flag is
// already set when we get here (because the client has used V2 encryption
// instead of V3)
case 0x30: // GC Ep1&2 GameJam demo, GC Ep1&2 Trial Edition, GC Ep1&2 JP v1.2, at least one version of XB
case 0x31: // GC Ep1&2 US v1.0, GC US v1.1, XB US
break;
case 0x32: // GC Ep1&2 EU 50Hz
case 0x33: // GC Ep1&2 EU 60Hz
case 0x34: // GC Ep1&2 JP v1.3
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
break;
case 0x35: // GC Ep1&2 JP v1.04 (Plus)
case 0x35: // GC Ep1&2 JP v1.4 (Plus)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break;
case 0x36: // GC Ep1&2 US v1.02 (Plus)
case 0x39: // GC Ep1&2 JP v1.05 (Plus)
case 0x36: // GC Ep1&2 US v1.2 (Plus)
case 0x39: // GC Ep1&2 JP v1.5 (Plus)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break;
case 0x40: // GC Ep3 JP and Trial Edition
case 0x40: // GC Ep3 JP and Trial Edition (and BB)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
// sub_version can't be used to tell JP final and Trial Edition apart; we
// instead look at header.flag in the 61 command and set the
// IS_EP3_TRIAL_EDITION flag there.
// instead look at header.flag in the 61 command and set the version then.
break;
case 0x41: // GC Ep3 US
case 0x41: // GC Ep3 US (and BB)
this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
@@ -132,15 +135,48 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
}
}
Client::ItemDropNotificationMode Client::Config::get_drop_notification_mode() const {
uint8_t mode_s = (this->check_flag(Flag::ITEM_DROP_NOTIFICATIONS_1) ? 1 : 0) |
(this->check_flag(Flag::ITEM_DROP_NOTIFICATIONS_2) ? 2 : 0);
return static_cast<Client::ItemDropNotificationMode>(mode_s);
}
void Client::Config::set_drop_notification_mode(ItemDropNotificationMode new_mode) {
uint8_t mode_s = static_cast<uint8_t>(new_mode);
if (mode_s & 1) {
this->set_flag(Client::Flag::ITEM_DROP_NOTIFICATIONS_1);
} else {
this->clear_flag(Client::Flag::ITEM_DROP_NOTIFICATIONS_1);
}
if (mode_s & 2) {
this->set_flag(Client::Flag::ITEM_DROP_NOTIFICATIONS_2);
} else {
this->clear_flag(Client::Flag::ITEM_DROP_NOTIFICATIONS_2);
}
}
bool Client::Config::should_update_vs(const Config& other) const {
constexpr uint64_t mask = static_cast<uint64_t>(Flag::CLIENT_SIDE_MASK);
return ((this->enabled_flags ^ other.enabled_flags) & mask) ||
(this->specific_version != other.specific_version) ||
(this->override_random_seed != other.override_random_seed) ||
(this->override_section_id != other.override_section_id) ||
(this->override_lobby_event != other.override_lobby_event) ||
(this->override_lobby_number != other.override_lobby_number) ||
(this->proxy_destination_address != other.proxy_destination_address) ||
(this->proxy_destination_port != other.proxy_destination_port);
}
Client::Client(
shared_ptr<Server> server,
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
ServerBehavior server_behavior)
: server(server),
id(next_id++),
log(string_printf("[C-%" PRIX64 "] ", this->id), client_log.min_level),
channel(bev, version, 1, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
channel(bev, virtual_network_id, version, 1, nullptr, nullptr, this, "", TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
server_behavior(server_behavior),
should_disconnect(false),
should_send_to_lobby_server(false),
@@ -172,6 +208,7 @@ Client::Client(
card_battle_table_number(-1),
card_battle_table_seat_number(0),
card_battle_table_seat_state(0),
last_game_info_requested(0),
should_update_play_time(false),
bb_character_index(-1),
next_exp_value(0),
@@ -179,10 +216,15 @@ Client::Client(
dol_base_addr(0),
external_bank_character_index(-1),
last_play_time_update(0) {
this->update_channel_name();
this->config.set_flags_for_version(version, -1);
auto s = server->get_state();
if (is_v1_or_v2(this->version()) ? s->default_rare_notifs_enabled_v1_v2 : s->default_rare_notifs_enabled_v3_v4) {
this->config.set_drop_notification_mode(ItemDropNotificationMode::RARES_ONLY);
}
this->config.specific_version = default_specific_version_for_version(version, -1);
this->last_switch_enabled_command.header.subcommand = 0;
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
this->reschedule_save_game_data_event();
@@ -191,7 +233,8 @@ Client::Client(
// Don't print data sent to patch clients to the logs. The patch server
// protocol is fully understood and data logs for patch clients are generally
// more annoying than helpful at this point.
if ((this->channel.version == Version::PC_PATCH) || (this->channel.version == Version::BB_PATCH)) {
if ((s->hide_download_commands) &&
((this->channel.version == Version::PC_PATCH) || (this->channel.version == Version::BB_PATCH))) {
this->channel.terminal_recv_color = TerminalFormat::END;
this->channel.terminal_send_color = TerminalFormat::END;
}
@@ -213,6 +256,19 @@ Client::~Client() {
this->log.info("Deleted");
}
void Client::update_channel_name() {
string ip_str = this->require_server_state()->format_address_for_channel_name(
this->channel.remote_addr, this->channel.virtual_network_id);
auto player = this->character(false, false);
if (player) {
string name_str = player->disp.name.decode(this->language());
this->channel.name = string_printf("C-%" PRIX64 " (%s) @ %s", this->id, name_str.c_str(), ip_str.c_str());
} else {
this->channel.name = string_printf("C-%" PRIX64 " @ %s", this->id, ip_str.c_str());
}
}
void Client::reschedule_save_game_data_event() {
if (this->version() == Version::BB_V4) {
struct timeval tv = usecs_to_timeval(60000000); // 1 minute
@@ -221,22 +277,24 @@ void Client::reschedule_save_game_data_event() {
}
void Client::reschedule_ping_and_timeout_events() {
struct timeval ping_tv = usecs_to_timeval(30000000); // 30 seconds
auto s = this->require_server_state();
struct timeval ping_tv = usecs_to_timeval(s->client_ping_interval_usecs);
event_add(this->send_ping_event.get(), &ping_tv);
struct timeval idle_tv = usecs_to_timeval(60000000); // 1 minute
struct timeval idle_tv = usecs_to_timeval(s->client_idle_timeout_usecs);
event_add(this->idle_timeout_event.get(), &idle_tv);
}
void Client::set_license(shared_ptr<License> l) {
if (this->version() == Version::BB_V4) {
// Make sure bb_username is filename-safe
for (char ch : l->bb_username) {
if (!isalnum(ch) && (ch != '-') && (ch != '_')) {
throw runtime_error("invalid characters in username");
}
}
void Client::convert_account_to_temporary_if_nte() {
// If the session is a prototype version and the account was created and we
// should use a temporary account instead, delete the permanent account and
// replace it with a temporary account.
auto s = this->require_server_state();
if (s->use_temp_accounts_for_prototypes && this->login->account_was_created && is_any_nte(this->version())) {
this->log.info("Client is a prototype version and the account was created during this session; converting permanent account to temporary account");
this->login->account->is_temporary = true;
this->login->account->delete_file();
this->login->account_was_created = false;
}
this->license = l;
}
shared_ptr<ServerState> Client::require_server_state() const {
@@ -256,29 +314,29 @@ shared_ptr<Lobby> Client::require_lobby() const {
}
shared_ptr<const TeamIndex::Team> Client::team() const {
if (!this->license) {
throw logic_error("Client::team called on client with no license");
if (!this->login) {
throw logic_error("Client::team called on client with no account");
}
if (this->license->bb_team_id == 0) {
if (this->login->account->bb_team_id == 0) {
return nullptr;
}
auto p = this->character(false);
auto s = this->require_server_state();
auto team = s->team_index->get_by_id(this->license->bb_team_id);
auto team = s->team_index->get_by_id(this->login->account->bb_team_id);
if (!team) {
this->log.info("License contains a team ID, but the team does not exist; clearing team ID from license");
this->license->bb_team_id = 0;
this->license->save();
this->log.info("Account contains a team ID, but the team does not exist; clearing team ID from account");
this->login->account->bb_team_id = 0;
this->login->account->save();
return nullptr;
}
auto member_it = team->members.find(this->license->serial_number);
auto member_it = team->members.find(this->login->account->account_id);
if (member_it == team->members.end()) {
this->log.info("License contains a team ID, but the team does not contain this member; clearing team ID from license");
this->license->bb_team_id = 0;
this->license->save();
this->log.info("Account contains a team ID, but the team does not contain this member; clearing team ID from account");
this->login->account->bb_team_id = 0;
this->login->account->save();
return nullptr;
}
@@ -289,47 +347,74 @@ shared_ptr<const TeamIndex::Team> Client::team() const {
string name = p->disp.name.decode(this->language());
if (m.name != name) {
this->log.info("Updating player name in team config");
s->team_index->update_member_name(this->license->serial_number, name);
s->team_index->update_member_name(this->login->account->account_id, name);
}
}
return team;
}
bool Client::can_see_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const {
if (this->license && (this->license->flags & License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
bool Client::evaluate_quest_availability_expression(
shared_ptr<const IntegralExpression> expr,
shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const {
if (this->login && this->login->account->check_flag(Account::Flag::DISABLE_QUEST_REQUIREMENTS)) {
return true;
}
if (!q->available_expression) {
if (!expr) {
return true;
}
string expr = q->available_expression->str();
QuestAvailabilityExpression::Env env = {
.flags = &this->character()->quest_flags.data.at(difficulty),
if (game && !game->quest_flag_values) {
throw logic_error("quest flags are missing from game");
}
auto p = this->character();
IntegralExpression::Env env = {
.flags = &p->quest_flags.data.at(difficulty),
.challenge_records = &p->challenge_records,
.team = this->team(),
.num_players = num_players,
.event = event,
.v1_present = v1_present,
};
int64_t ret = q->available_expression->evaluate(env);
this->log.info("Evaluated quest availability expression %s => %s", expr.c_str(), ret ? "TRUE" : "FALSE");
int64_t ret = expr->evaluate(env);
if (this->log.should_log(LogLevel::INFO)) {
string expr_str = expr->str();
this->log.info("Evaluated quest availability expression %s => %s", expr_str.c_str(), ret ? "TRUE" : "FALSE");
}
return ret;
}
bool Client::can_play_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const {
if (this->license && (this->license->flags & License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
bool Client::can_see_quest(
shared_ptr<const Quest> q,
shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const {
return this->evaluate_quest_availability_expression(q->available_expression, game, event, difficulty, num_players, v1_present);
}
bool Client::can_play_quest(
shared_ptr<const Quest> q,
shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const {
return this->evaluate_quest_availability_expression(q->enabled_expression, game, event, difficulty, num_players, v1_present);
}
bool Client::can_use_chat_commands() const {
if (!this->login) {
return false;
}
if (this->login->account->check_flag(Account::Flag::ALWAYS_ENABLE_CHAT_COMMANDS)) {
return true;
}
if (!q->enabled_expression) {
return true;
}
string expr = q->enabled_expression->str();
QuestAvailabilityExpression::Env env = {
.flags = &this->character()->quest_flags.data.at(difficulty),
.team = this->team(),
.num_players = num_players,
};
bool ret = q->enabled_expression->evaluate(env);
this->log.info("Evaluating quest enabled expression %s => %s", expr.c_str(), ret ? "TRUE" : "FALSE");
return ret;
return this->require_server_state()->enable_chat_commands;
}
void Client::dispatch_save_game_data(evutil_socket_t, short, void* ctx) {
@@ -406,10 +491,10 @@ void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_p
uint8_t char_class = this->overlay_character_data->disp.visual.char_class;
auto& stats = this->overlay_character_data->disp.stats;
stats.reset_to_base(char_class, level_table);
stats.advance_to_level(char_class, target_level, level_table);
level_table->reset_to_base(stats, char_class);
level_table->advance_to_level(stats, target_level, char_class);
stats.unknown_a1 = 40;
stats.esp = 40;
stats.meseta = 300;
}
if (rules->tech_disk_mode == BattleRules::TechDiskMode::LIMIT_LEVEL) {
@@ -452,10 +537,10 @@ void Client::create_challenge_overlay(Version version, size_t template_index, sh
overlay->inventory.items[13].extension_data2 = 1;
overlay->disp.stats.reset_to_base(overlay->disp.visual.char_class, level_table);
overlay->disp.stats.advance_to_level(overlay->disp.visual.char_class, tpl.level, level_table);
level_table->reset_to_base(overlay->disp.stats, overlay->disp.visual.char_class);
level_table->advance_to_level(overlay->disp.stats, tpl.level, overlay->disp.visual.char_class);
overlay->disp.stats.unknown_a1 = 40;
overlay->disp.stats.esp = 40;
overlay->disp.stats.unknown_a3 = 10.0;
overlay->disp.stats.experience = level_table->stats_delta_for_level(overlay->disp.visual.char_class, overlay->disp.stats.level).experience;
overlay->disp.stats.meseta = 0;
@@ -542,10 +627,10 @@ string Client::system_filename() const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have system data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
return string_printf("system/players/system_%s.psosys", this->license->bb_username.c_str());
return string_printf("system/players/system_%s.psosys", this->login->bb_license->username.c_str());
}
string Client::character_filename(const std::string& bb_username, int8_t index) {
@@ -558,55 +643,55 @@ string Client::character_filename(const std::string& bb_username, int8_t index)
return string_printf("system/players/player_%s_%hhd.psochar", bb_username.c_str(), index);
}
string Client::backup_character_filename(uint32_t serial_number, size_t index) {
return string_printf("system/players/backup_player_%" PRIu32 "_%zu.psochar", serial_number, index);
string Client::backup_character_filename(uint32_t account_id, size_t index) {
return string_printf("system/players/backup_player_%" PRIu32 "_%zu.psochar", account_id, index);
}
string Client::character_filename(int8_t index) const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have character data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
return this->character_filename(this->license->bb_username, (index < 0) ? this->bb_character_index : index);
return this->character_filename(this->login->bb_license->username, (index < 0) ? this->bb_character_index : index);
}
string Client::guild_card_filename() const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have character data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
return string_printf("system/players/guild_cards_%s.psocard", this->license->bb_username.c_str());
return string_printf("system/players/guild_cards_%s.psocard", this->login->bb_license->username.c_str());
}
string Client::shared_bank_filename() const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have character data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
return string_printf("system/players/shared_bank_%s.psobank", this->license->bb_username.c_str());
return string_printf("system/players/shared_bank_%s.psobank", this->login->bb_license->username.c_str());
}
string Client::legacy_account_filename() const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have character data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
return string_printf("system/players/account_%s.nsa", this->license->bb_username.c_str());
return string_printf("system/players/account_%s.nsa", this->login->bb_license->username.c_str());
}
string Client::legacy_player_filename() const {
if (this->version() != Version::BB_V4) {
throw logic_error("non-BB players do not have character data");
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("client is not logged in");
}
if (this->bb_character_index < 0) {
@@ -614,7 +699,7 @@ string Client::legacy_player_filename() const {
}
return string_printf(
"system/players/player_%s_%hhd.nsc",
this->license->bb_username.c_str(),
this->login->bb_license->username.c_str(),
static_cast<int8_t>(this->bb_character_index + 1));
}
@@ -634,7 +719,7 @@ void Client::load_all_files() {
this->guild_card_data = make_shared<PSOBBGuildCardFile>();
return;
}
if (!this->license) {
if (!this->login || !this->login->bb_license) {
throw logic_error("cannot load BB player data until client is logged in");
}
@@ -673,6 +758,7 @@ void Client::load_all_files() {
if (header.flag != 0x00000000) {
throw runtime_error("incorrect flag in character file header");
}
static_assert(sizeof(PSOBBCharacterFile) + sizeof(PSOBBFullSystemFile) == 0x3994, ".psochar size is incorrect");
this->character_data = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(f.get()));
files_manager->set_character(char_filename, this->character_data);
player_data_log.info("Loaded character data from %s", char_filename.c_str());
@@ -750,12 +836,11 @@ void Client::load_all_files() {
files_manager->set_character(this->character_filename(), this->character_data);
this->character_data->inventory = nsc_data.inventory;
this->character_data->disp = nsc_data.disp;
this->character_data->play_time_seconds = nsc_data.disp.play_time;
this->character_data->unknown_a2 = nsc_data.unknown_a2;
this->character_data->play_time_seconds = 0;
this->character_data->quest_flags = nsc_data.quest_flags;
this->character_data->death_count = nsc_data.death_count;
this->character_data->bank = nsc_data.bank;
this->character_data->guild_card.guild_card_number = this->license->serial_number;
this->character_data->guild_card.guild_card_number = this->login->account->account_id;
this->character_data->guild_card.name = nsc_data.disp.name;
this->character_data->guild_card.description = nsc_data.guild_card_description;
this->character_data->guild_card.present = 1;
@@ -766,8 +851,8 @@ void Client::load_all_files() {
this->character_data->info_board = nsc_data.info_board;
this->character_data->battle_records = nsc_data.battle_records;
this->character_data->challenge_records = nsc_data.challenge_records;
this->character_data->tech_menu_config = nsc_data.tech_menu_config;
this->character_data->quest_global_flags = nsc_data.quest_global_flags;
this->character_data->tech_menu_shortcut_entries = nsc_data.tech_menu_shortcut_entries;
this->character_data->quest_counters = nsc_data.quest_counters;
if (nsa_data) {
this->character_data->option_flags = nsa_data->option_flags;
this->character_data->symbol_chats = nsa_data->symbol_chats;
@@ -779,11 +864,6 @@ void Client::load_all_files() {
}
}
if (this->character_data) {
this->license->auto_reply_message = this->character_data->auto_reply.decode();
this->license->save();
}
this->blocked_senders.clear();
for (size_t z = 0; z < this->guild_card_data->blocked.size(); z++) {
if (this->guild_card_data->blocked[z].present) {
@@ -792,6 +872,10 @@ void Client::load_all_files() {
}
if (this->character_data) {
// Clear legacy play_time field
this->character_data->disp.name.clear_after_bytes(0x18);
this->login->account->auto_reply_message = this->character_data->auto_reply.decode();
this->login->account->save();
this->last_play_time_update = now();
}
}
@@ -838,10 +922,10 @@ void Client::save_character_file(
fwritex(f.get(), *character);
fwritex(f.get(), *system);
// TODO: Technically, we should write the actual team membership struct to the
// file here, but that would cause Client to depend on License, which
// file here, but that would cause Client to depend on Account, which
// it currently does not. This data doesn't matter at all for correctness
// within newserv, since it ignores this data entirely and instead generates
// the membership struct from the team ID in the License and the team's state.
// the membership struct from the team ID in the Account and the team's state.
// So, writing correct data here would mostly be for compatibility with other
// PSO servers. But if the other server is newserv, then this data would be
// used anyway, and if it's not, then it would presumably have a different set
@@ -864,8 +948,7 @@ void Client::save_character_file() {
// off each time we save. I'm lazy, so insert shrug emoji here.
uint64_t t = now();
uint64_t seconds = (t - this->last_play_time_update) / 1000000;
this->character_data->disp.play_time += seconds;
this->character_data->play_time_seconds = this->character_data->disp.play_time;
this->character_data->play_time_seconds += seconds;
player_data_log.info("Added %" PRIu64 " seconds to play time", seconds);
this->last_play_time_update = t;
}
@@ -882,8 +965,8 @@ void Client::save_guild_card_file() const {
player_data_log.info("Saved Guild Card file %s", filename.c_str());
}
void Client::load_backup_character(uint32_t serial_number, size_t index) {
string filename = this->backup_character_filename(serial_number, index);
void Client::load_backup_character(uint32_t account_id, size_t index) {
string filename = this->backup_character_filename(account_id, index);
auto f = fopen_unique(filename, "rb");
auto header = freadx<PSOCommandHeaderBB>(f.get());
if (header.size != 0x399C) {
@@ -988,3 +1071,30 @@ void Client::use_character_bank(int8_t index) {
}
}
}
void Client::print_inventory(FILE* stream) const {
auto s = this->require_server_state();
auto p = this->character();
fprintf(stream, "[PlayerInventory] Meseta: %" PRIu32 "\n", p->disp.stats.meseta.load());
fprintf(stream, "[PlayerInventory] %hhu items\n", p->inventory.num_items);
for (size_t x = 0; x < p->inventory.num_items; x++) {
const auto& item = p->inventory.items[x];
auto hex = item.data.hex();
auto name = s->describe_item(this->version(), item.data, false);
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s (%s)\n", x, item.flags.load(), hex.c_str(), name.c_str());
}
}
void Client::print_bank(FILE* stream) const {
auto s = this->require_server_state();
auto p = this->character();
fprintf(stream, "[PlayerBank] Meseta: %" PRIu32 "\n", p->bank.meseta.load());
fprintf(stream, "[PlayerBank] %" PRIu32 " items\n", p->bank.num_items.load());
for (size_t x = 0; x < p->bank.num_items; x++) {
const auto& item = p->bank.items[x];
const char* present_token = item.present ? "" : " (missing present flag)";
auto hex = item.data.hex();
auto name = s->describe_item(this->version(), item.data, false);
fprintf(stream, "[PlayerBank] %3zu: %s (%s) (x%hu)%s\n", x, hex.c_str(), name.c_str(), item.amount.load(), present_token);
}
}
+105 -60
View File
@@ -5,13 +5,13 @@
#include <memory>
#include <stdexcept>
#include "Account.hh"
#include "Channel.hh"
#include "CommandFormats.hh"
#include "Episode3/BattleRecord.hh"
#include "Episode3/Tournament.hh"
#include "FileContentsCache.hh"
#include "FunctionCompiler.hh"
#include "License.hh"
#include "PSOEncryption.hh"
#include "PSOProtocol.hh"
#include "PatchFileIndex.hh"
@@ -30,61 +30,76 @@ public:
enum class Flag : uint64_t {
// 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 = 0xFF3CFFFF7C0FFFFB,
// Version-related flags
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
NO_D6_AFTER_LOBBY = 0x0000000000000100,
NO_D6 = 0x0000000000000200,
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
NO_D6_AFTER_LOBBY = 0x0000000000000100,
NO_D6 = 0x0000000000000200,
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
// Flags describing the behavior for send_function_call
NO_SEND_FUNCTION_CALL = 0x0000000000001000,
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x0000000000010000,
NO_SEND_FUNCTION_CALL = 0x0000000000001000,
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x0000000000010000,
// State flags
LOADING = 0x0000000000100000,
LOADING_QUEST = 0x0000000000200000,
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000,
LOADING_TOURNAMENT = 0x0000000000800000,
IN_INFORMATION_MENU = 0x0000000001000000,
AT_WELCOME_MESSAGE = 0x0000000002000000,
SAVE_ENABLED = 0x0000000004000000,
HAS_EP3_CARD_DEFS = 0x0000000008000000,
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000,
USE_OVERRIDE_RANDOM_SEED = 0x0000000020000000,
HAS_GUILD_CARD_NUMBER = 0x0000000040000000,
AT_BANK_COUNTER = 0x0000000080000000,
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000,
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000,
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
LOADING = 0x0000000000100000, // Server-side only
LOADING_QUEST = 0x0000000000200000, // Server-side only
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000, // Server-side only
LOADING_TOURNAMENT = 0x0000000000800000, // Server-side only
IN_INFORMATION_MENU = 0x0000000001000000, // Server-side only
AT_WELCOME_MESSAGE = 0x0000000002000000, // Server-side only
SAVE_ENABLED = 0x0000000004000000,
HAS_EP3_CARD_DEFS = 0x0000000008000000,
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000,
USE_OVERRIDE_RANDOM_SEED = 0x0000000020000000,
HAS_GUILD_CARD_NUMBER = 0x0000000040000000,
HAS_AUTO_PATCHES = 0x0000004000000000,
AT_BANK_COUNTER = 0x0000000080000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0080000000000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
SWITCH_ASSIST_ENABLED = 0x0000000100000000,
// Cheat mode flags
SWITCH_ASSIST_ENABLED = 0x0000000100000000,
INFINITE_HP_ENABLED = 0x0000000200000000,
INFINITE_TP_ENABLED = 0x0000000400000000,
DEBUG_ENABLED = 0x0000000800000000,
// Cheat mode and option flags
INFINITE_HP_ENABLED = 0x0000000200000000,
INFINITE_TP_ENABLED = 0x0000000400000000,
DEBUG_ENABLED = 0x0000000800000000,
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000,
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000,
// Proxy option flags
PROXY_SAVE_FILES = 0x0000001000000000,
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000,
PROXY_CHAT_FILTER_ENABLED = 0x0000004000000000,
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
PROXY_SUPPRESS_CLIENT_PINGS = 0x0000010000000000,
PROXY_SUPPRESS_REMOTE_LOGIN = 0x0000020000000000,
PROXY_ZERO_REMOTE_GUILD_CARD = 0x0000040000000000,
PROXY_EP3_INFINITE_MESETA_ENABLED = 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_SAVE_FILES = 0x0000001000000000,
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000,
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
PROXY_SUPPRESS_CLIENT_PINGS = 0x0000010000000000,
PROXY_SUPPRESS_REMOTE_LOGIN = 0x0000020000000000,
PROXY_ZERO_REMOTE_GUILD_CARD = 0x0000040000000000,
PROXY_EP3_INFINITE_MESETA_ENABLED = 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,
// clang-format on
};
enum class ItemDropNotificationMode {
NOTHING = 0,
RARES_ONLY = 1,
ALL_ITEMS = 2,
ALL_ITEMS_INCLUDING_MESETA = 3,
};
static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED) |
static_cast<uint64_t>(Flag::PROXY_CHAT_FILTER_ENABLED);
static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED);
struct Config {
uint64_t enabled_flags = DEFAULT_FLAGS; // Client::Flag enum
@@ -101,6 +116,8 @@ public:
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));
}
@@ -120,6 +137,9 @@ public:
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) {
StringReader r(data.data(), data.size());
@@ -141,7 +161,7 @@ public:
StringWriter w;
w.put_u32l(CLIENT_CONFIG_MAGIC);
w.put_u32l(this->specific_version);
w.put_u64l(this->enabled_flags);
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);
@@ -161,8 +181,7 @@ public:
uint64_t id;
PrefixedLogger log;
// License & account
std::shared_ptr<License> license;
std::shared_ptr<Login> login;
// Network
Channel channel;
@@ -177,12 +196,10 @@ public:
uint8_t bb_connection_phase;
uint64_t ping_start_time;
// Patch server
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
// Lobby/positioning
Config config;
Config synced_config;
std::unique_ptr<parray<le_uint32_t, 0x20>> override_variations;
int32_t sub_version;
float x;
float z;
@@ -199,8 +216,9 @@ public:
uint16_t card_battle_table_seat_number;
uint16_t card_battle_table_seat_state;
std::weak_ptr<Episode3::Tournament::Team> ep3_tournament_team;
std::shared_ptr<Episode3::BattleRecord> ep3_prev_battle_record;
std::shared_ptr<const Episode3::BattleRecord> ep3_prev_battle_record;
std::shared_ptr<const Menu> last_menu_sent;
uint32_t last_game_info_requested;
struct JoinCommand {
uint16_t command;
uint32_t flag;
@@ -232,12 +250,12 @@ public:
// Miscellaneous (used by chat commands)
uint32_t next_exp_value; // next EXP value to give
G_SwitchStateChanged_6x05 last_switch_enabled_command;
RecentSwitchFlags recent_switch_flags; // used for switch assist
bool can_chat;
struct PendingCharacterExport {
std::shared_ptr<const License> license;
std::shared_ptr<const Account> dest_account;
ssize_t character_index = -1;
bool is_bb_conversion = false;
std::shared_ptr<const BBLicense> dest_bb_license; // Only used for $bbchar; null for $savechar
};
std::unique_ptr<PendingCharacterExport> pending_character_export;
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue;
@@ -250,10 +268,13 @@ public:
Client(
std::shared_ptr<Server> server,
struct bufferevent* bev,
uint64_t virtual_network_id,
Version version,
ServerBehavior server_behavior);
~Client();
void update_channel_name();
void reschedule_save_game_data_event();
void reschedule_ping_and_timeout_events();
@@ -264,7 +285,7 @@ public:
return this->channel.language;
}
void set_license(std::shared_ptr<License> l);
void convert_account_to_temporary_if_nte();
void sync_config();
@@ -273,8 +294,29 @@ public:
std::shared_ptr<const TeamIndex::Team> team() const;
bool can_see_quest(std::shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const;
bool can_play_quest(std::shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const;
bool evaluate_quest_availability_expression(
std::shared_ptr<const IntegralExpression> expr,
std::shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const;
bool can_see_quest(
std::shared_ptr<const Quest> q,
std::shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const;
bool can_play_quest(
std::shared_ptr<const Quest> q,
std::shared_ptr<const Lobby> game,
uint8_t event,
uint8_t difficulty,
size_t num_players,
bool v1_present) const;
bool can_use_chat_commands() const;
static void dispatch_save_game_data(evutil_socket_t, short, void* ctx);
void save_game_data();
@@ -314,7 +356,7 @@ public:
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 serial_number, size_t index);
static std::string backup_character_filename(uint32_t account_id, size_t index);
std::string character_filename(int8_t index = -1) const;
std::string guild_card_filename() const;
std::string shared_bank_filename() const;
@@ -332,7 +374,7 @@ public:
void save_character_file();
void save_guild_card_file() const;
void load_backup_character(uint32_t serial_number, size_t index);
void load_backup_character(uint32_t account_id, size_t index);
void save_and_unload_character();
PlayerBank& current_bank();
@@ -341,6 +383,9 @@ public:
void use_character_bank(int8_t bb_character_index);
void use_default_bank();
void print_inventory(FILE* stream) const;
void print_bank(FILE* stream) const;
private:
// The overlay character data is used in battle and challenge modes, when
// character data is temporarily replaced in-game. In other play modes and in
+1669 -1395
View File
File diff suppressed because it is too large Load Diff
+106 -1
View File
@@ -1,11 +1,116 @@
#include "CommonItemSet.hh"
#include "AFSArchive.hh"
#include "EnemyType.hh"
#include "GSLArchive.hh"
#include "StaticGameData.hh"
using namespace std;
template <typename IntT, size_t Count>
JSON to_json(const parray<IntT, Count>& v) {
auto ret = JSON::list();
for (size_t z = 0; z < Count; z++) {
ret.emplace_back(v[z]);
}
return ret;
}
template <typename IntT, size_t Count>
JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) {
auto ret = JSON::list();
for (size_t z = 0; z < Count; z++) {
ret.emplace_back(to_json(v[z]));
}
return ret;
}
template <typename IntT>
JSON to_json(const CommonItemSet::Table::Range<IntT>& v) {
if (v.min == v.max) {
return JSON(v.min);
} else {
return JSON::list({v.min, v.max});
}
}
template <typename IntT, size_t Count1, size_t Count2>
JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) {
auto ret = JSON::list();
for (size_t z = 0; z < Count1; z++) {
ret.emplace_back(to_json(v[z]));
}
return ret;
}
JSON CommonItemSet::Table::json() const {
JSON enemy_meseta_ranges_json = JSON::dict();
JSON enemy_type_drop_probs_json = JSON::dict();
JSON enemy_item_classes_json = JSON::dict();
for (size_t z = 0; z < 0x64; z++) {
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
for (Episode episode : episodes) {
for (auto type : enemy_types_for_rare_table_index(episode, z)) {
string name = string_printf("%s:%s", abbreviation_for_episode(episode), name_for_enum(type));
enemy_meseta_ranges_json.emplace(name, to_json(this->enemy_meseta_ranges[z]));
enemy_type_drop_probs_json.emplace(name, this->enemy_type_drop_probs[z]);
enemy_item_classes_json.emplace(name, this->enemy_item_classes[z]);
}
}
}
return JSON::dict({
{"BaseWeaponTypeProbTable", to_json(this->base_weapon_type_prob_table)},
{"SubtypeBaseTable", to_json(this->subtype_base_table)},
{"SubtypeAreaLengthTable", to_json(this->subtype_area_length_table)},
{"GrindProbTable", to_json(this->grind_prob_table)},
{"ArmorShieldTypeIndexProbTable", to_json(this->armor_shield_type_index_prob_table)},
{"ArmorSlotCountProbTable", to_json(this->armor_slot_count_prob_table)},
{"EnemyMesetaRanges", std::move(enemy_meseta_ranges_json)},
{"EnemyTypeDropProbs", std::move(enemy_type_drop_probs_json)},
{"EnemyItemClasses", std::move(enemy_item_classes_json)},
{"BoxMesetaRanges", to_json(this->box_meseta_ranges)},
{"HasRareBonusValueProbTable", this->has_rare_bonus_value_prob_table},
{"BonusValueProbTable", to_json(this->bonus_value_prob_table)},
{"NonRareBonusProbSpec", to_json(this->nonrare_bonus_prob_spec)},
{"BonusTypeProbTable", to_json(this->bonus_type_prob_table)},
{"SpecialMult", to_json(this->special_mult)},
{"SpecialPercent", to_json(this->special_percent)},
{"ToolClassProbTable", to_json(this->tool_class_prob_table)},
{"TechniqueIndexProbTable", to_json(this->technique_index_prob_table)},
{"TechniqueLevelRanges", to_json(this->technique_level_ranges)},
{"ArmorOrShieldTypeBias", this->armor_or_shield_type_bias},
{"UnitMaxStarsTable", to_json(this->unit_max_stars_table)},
{"BoxItemClassProbTable", to_json(this->box_item_class_prob_table)},
});
}
JSON CommonItemSet::json() const {
auto modes_dict = JSON::dict();
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
for (const auto& mode : modes) {
auto episodes_dict = JSON::dict();
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
for (const auto& episode : episodes) {
auto difficulty_dict = JSON::dict();
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
auto section_id_dict = JSON::dict();
for (uint8_t section_id = 0; section_id < 10; section_id++) {
try {
auto table = this->get_table(episode, mode, difficulty, section_id);
section_id_dict.emplace(name_for_section_id(section_id), table->json());
} catch (const runtime_error&) {
}
}
difficulty_dict.emplace(token_name_for_difficulty(difficulty), std::move(section_id_dict));
}
episodes_dict.emplace(token_name_for_episode(episode), std::move(difficulty_dict));
}
modes_dict.emplace(name_for_mode(mode), std::move(episodes_dict));
}
return modes_dict;
}
CommonItemSet::Table::Table(const StringReader& r, bool is_big_endian, bool is_v3) {
if (is_big_endian) {
this->parse_itempt_t<true>(r, is_v3);
@@ -19,7 +124,7 @@ void CommonItemSet::Table::parse_itempt_t(const StringReader& r, bool is_v3) {
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
const auto& offsets = r.pget<Offsets<IsBigEndian>>(r.pget<U32T>(r.size() - 0x10));
const auto& offsets = r.pget<OffsetsT<IsBigEndian>>(r.pget<U32T>(r.size() - 0x10));
this->base_weapon_type_prob_table = r.pget<parray<uint8_t, 0x0C>>(offsets.base_weapon_type_prob_table_offset);
this->subtype_base_table = r.pget<parray<int8_t, 0x0C>>(offsets.subtype_base_table_offset);
+24 -15
View File
@@ -2,6 +2,7 @@
#include <array>
#include <phosg/Encoding.hh>
#include <phosg/JSON.hh>
#include "GSLArchive.hh"
#include "PSOEncryption.hh"
@@ -19,7 +20,7 @@ public:
struct Range {
IntT min;
IntT max;
} __attribute__((packed));
} __packed__;
parray<uint8_t, 0x0C> base_weapon_type_prob_table;
parray<int8_t, 0x0C> subtype_base_table;
@@ -45,13 +46,14 @@ public:
parray<parray<uint8_t, 10>, 7> box_item_class_prob_table;
void print_enemy_table(FILE* stream) const;
JSON json() const;
private:
template <bool IsBigEndian>
void parse_itempt_t(const StringReader& r, bool is_v3);
template <bool IsBigEndian>
struct Offsets {
struct OffsetsT {
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
@@ -252,10 +254,15 @@ public:
/* 50 */ U32T box_item_class_prob_table_offset;
// There are several unused fields here.
} __attribute__((packed));
} __packed__;
using Offsets = OffsetsT<false>;
using OffsetsBE = OffsetsT<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;
JSON json() const;
protected:
CommonItemSet() = default;
@@ -298,22 +305,22 @@ struct ProbabilityTable {
return this->items[--this->count];
}
void shuffle(PSOLFGEncryption& random_crypt) {
void shuffle(std::shared_ptr<PSOLFGEncryption> opt_rand_crypt) {
for (size_t z = 1; z < this->count; z++) {
size_t other_z = random_crypt.next() % (z + 1);
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(PSOLFGEncryption& random_crypt) const {
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_crypt.next() % this->count];
return this->items[random_from_optional_crypt(opt_rand_crypt) % this->count];
}
}
};
@@ -324,10 +331,12 @@ public:
struct WeightTableEntry {
ValueT value;
WeightT weight;
} __attribute__((packed));
} __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;
@@ -337,7 +346,7 @@ protected:
be_uint32_t offset;
uint8_t entries_per_table;
parray<uint8_t, 3> unused;
} __attribute__((packed));
} __packed_ws__(TableSpec, 8);
RELFileSet(std::shared_ptr<const std::string> data);
@@ -378,7 +387,7 @@ public:
Mode mode;
uint8_t player_level_divisor_or_min_level;
uint8_t max_level;
} __attribute__((packed));
} __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;
@@ -400,7 +409,7 @@ public:
struct RangeTableEntry {
be_uint32_t min;
be_uint32_t max;
} __attribute__((packed));
} __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;
@@ -419,7 +428,7 @@ private:
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)
} __attribute__((packed));
} __packed_ws__(Offsets, 0x20);
const Offsets* offsets;
};
@@ -452,11 +461,11 @@ private:
uint8_t delta_index;
uint8_t count_default;
uint8_t count_favored;
} __attribute__((packed));
} __packed_ws__(DeltaProbabilityEntry, 3);
struct LuckTableEntry {
uint8_t delta_index;
int8_t luck;
} __attribute__((packed));
} __packed_ws__(LuckTableEntry, 2);
struct Offsets {
// Each section ID's favored weapon class has different probabilities than
@@ -562,7 +571,7 @@ private:
// 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
} __attribute__((packed));
} __packed_ws__(Offsets, 0x18);
const Offsets* offsets;
+64 -18
View File
@@ -438,6 +438,45 @@ string prs_compress_optimal(const string& data, ProgressCallback progress_fn) {
return prs_compress_optimal(data.data(), data.size(), progress_fn);
}
string prs_compress_pessimal(const void* vdata, size_t size) {
const uint8_t* in_data = reinterpret_cast<const uint8_t*>(vdata);
// The worst possible encoding we can do is a literal byte when no byte with
// the same value is within the window, or an extended copy if there is a byte
// with the same value in the window.
WindowIndex<0x1FFF, 1> window(in_data, size);
LZSSInterleavedWriter w;
for (size_t z = 0; z < size; z++) {
auto match = window.get_best_match();
if (match.second >= 1) {
// Write extended copy
int16_t offset = match.first - window.offset;
w.write_control(false);
w.flush_if_ready();
w.write_control(true);
uint16_t a = (offset << 3);
w.write_data(a & 0xFF);
w.write_data(a >> 8);
w.write_data(0);
} else {
// Write literal
w.write_control(true);
w.write_data(in_data[z]);
}
w.flush_if_ready();
window.advance();
}
// Write stop command
w.write_control(false);
w.flush_if_ready();
w.write_control(true);
w.write_data(0);
w.write_data(0);
return std::move(w.close());
}
PRSCompressor::PRSCompressor(
ssize_t compression_level, ProgressCallback progress_fn)
: compression_level(compression_level),
@@ -976,41 +1015,48 @@ void prs_disassemble(FILE* stream, const void* data, size_t size) {
ControlStreamReader cr(r);
while (!r.eof()) {
uint8_t buffered_bits = cr.buffered_bits();
if (cr.read()) {
fprintf(stream, "[%zX] literal %02hhX\n", output_bytes, r.get_u8());
uint8_t literal_value = r.get_u8();
fprintf(stream, "[%zX] %hhu> 1 %02hhX literal %02hhX\n",
output_bytes, buffered_bits, literal_value, literal_value);
output_bytes++;
} else {
ssize_t offset;
size_t count;
const char* copy_type;
size_t count, read_offset;
if (cr.read()) {
uint16_t a = r.get_u8();
a |= (r.get_u8() << 8);
offset = (a >> 3) | (~0x1FFF);
uint8_t a_low = r.get_u8();
uint8_t a_high = r.get_u8();
uint16_t a = (a_high << 8) | a_low;
ssize_t offset = (a >> 3) | (~0x1FFF);
if (offset == ~0x1FFF) {
fprintf(stream, "[%zX] end\n", output_bytes);
break;
}
if (a & 7) {
copy_type = "long";
count = (a & 7) + 2;
read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 01 %02hhX %02hhX long copy from %zd (offset=%zX) size=%zX\n",
output_bytes, buffered_bits, a_low, a_high, offset, read_offset, count);
} else {
copy_type = "extended";
count = r.get_u8() + 1;
uint8_t count_u8 = r.get_u8();
count = count_u8 + 1;
read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 01 %02hhX %02hhX %02hhX extended copy from %zd (offset=%zX) size=%zX\n",
output_bytes, buffered_bits, a_low, a_high, count_u8, offset, read_offset, count);
}
} else {
copy_type = "short";
count = cr.read() << 1;
count = (count | cr.read()) + 2;
offset = r.get_u8() | (~0xFF);
bool first_bit = cr.read();
bool second_bit = cr.read();
uint8_t offset_u8 = r.get_u8();
count = ((first_bit ? 2 : 0) | (second_bit ? 1 : 0)) + 2;
ssize_t offset = offset_u8 | (~0xFF);
read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %hhu> 00%c%c %02hhX short copy from %zd (offset=%zX) size=%zX\n",
output_bytes, buffered_bits, first_bit ? '1' : '0', second_bit ? '1' : '0', offset_u8, offset, read_offset, count);
}
size_t read_offset = output_bytes + offset;
fprintf(stream, "[%zX] %s copy %zX\n", output_bytes, copy_type, count);
if (read_offset >= output_bytes) {
throw runtime_error("backreference offset beyond beginning of output");
}
+4
View File
@@ -177,6 +177,10 @@ std::string prs_compress_indexed(
std::string prs_compress_optimal(const void* vdata, size_t size, ProgressCallback progress_fn = nullptr);
std::string prs_compress_optimal(const std::string& data, ProgressCallback progress_fn = nullptr);
// Compresses data using PRS to the LARGEST possible output size. There is no
// practical use for this function except for amusement.
std::string prs_compress_pessimal(const void* vdata, size_t size);
// Decompresses PRS-compressed data.
struct PRSDecompressResult {
std::string data;
+71
View File
@@ -1386,3 +1386,74 @@ void dc_serial_number_speed_test(uint64_t seed) {
fprintf(stderr, "Fast vs. slow speedup: %zux\n", static_cast<size_t>(time_slow / time_fast));
fprintf(stderr, "Disagreements: %zu\n", num_disagreements);
}
string decrypt_dp_address_jpn(
const string& executable,
const string& values,
const string& indexes) {
StringReader values_r(values);
StringReader indexes_r(indexes);
size_t fixup_values_offset = values_r.pget_u32l(0x3FFC) - 0x8C004000;
size_t fixup_steps_offset = indexes_r.pget_u32l(0x3BFC) - 0x8C008400;
StringReader fixup_values_r = values_r.sub(fixup_values_offset);
StringReader fixup_steps_r = indexes_r.sub(fixup_steps_offset);
auto decrypted = decrypt_pr2_data<false>(executable);
size_t fixup_offset = 0;
while (fixup_steps_r.get_u8(false)) {
fixup_offset += (fixup_steps_r.get_u8() << 2);
fixup_steps_r.skip(1);
if (fixup_offset + 4 > decrypted.compressed_data.size()) {
throw runtime_error("fixup beyond end of compressed data");
}
*reinterpret_cast<le_uint32_t*>(decrypted.compressed_data.data() + fixup_offset) = fixup_values_r.get_u32l();
}
return prs_decompress(decrypted.compressed_data);
}
EncryptedDCv2Executables encrypt_dp_address_jpn(const string& executable, const string& indexes) {
EncryptedDCv2Executables ret;
string compressed = prs_compress(executable);
ret.executable = encrypt_pr2_data<false>(compressed, executable.size(), random_object<uint32_t>() & 0x7FFFFF7F);
StringReader indexes_r(indexes);
size_t fixup_steps_offset = indexes_r.pget_u32l(0x3BFC) - 0x8C008400;
ret.indexes = indexes;
ret.indexes.at(fixup_steps_offset) = 0;
return ret;
}
std::string crypt_dp_address_jpn_simple(const std::string& data, int64_t mask_key) {
if (data.size() & 3) {
throw runtime_error("size is not a multiple of 4");
}
StringReader r(data);
if (mask_key < 0) {
unordered_map<uint32_t, size_t> key_freq;
while (!r.eof()) {
key_freq[r.get_u32l()] += 1;
}
size_t max_v = 0;
for (const auto& it : key_freq) {
if (it.second > max_v) {
max_v = it.second;
mask_key = it.first;
}
}
if (mask_key < 0) {
throw runtime_error("cannot determine mask key");
}
log_info("Determined %08" PRIX64 " to be the most likely mask key", mask_key);
r.go(0);
}
StringWriter w;
while (!r.eof()) {
w.put_u32l(r.get_u32l() ^ mask_key);
}
return std::move(w.str());
}
+13
View File
@@ -21,3 +21,16 @@ 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);
void dc_serial_number_speed_test(uint64_t seed = 0xFFFFFFFFFFFFFFFF);
struct EncryptedDCv2Executables {
std::string executable;
std::string indexes;
};
std::string decrypt_dp_address_jpn(
const std::string& dp_address_jpn_data,
const std::string& iwashi_sea_data,
const std::string& katsuo_sea_data);
EncryptedDCv2Executables encrypt_dp_address_jpn(const std::string& executable, const std::string& indexes);
std::string crypt_dp_address_jpn_simple(const std::string& data, int64_t seed = -1);
+10 -7
View File
@@ -19,10 +19,13 @@ using namespace std;
DNSServer::DNSServer(
shared_ptr<struct event_base> base,
uint32_t local_connect_address, uint32_t external_connect_address)
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) {}
external_connect_address(external_connect_address),
banned_ipv4_ranges(banned_ipv4_ranges) {}
DNSServer::~DNSServer() {
for (const auto& it : this->fd_to_receive_event) {
@@ -55,8 +58,7 @@ void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
reinterpret_cast<DNSServer*>(ctx)->on_receive_message(fd, events);
}
string DNSServer::response_for_query(
const void* vdata, size_t size, uint32_t resolved_address) {
string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
if (size < 0x0C) {
throw invalid_argument("query too small");
}
@@ -82,7 +84,7 @@ string DNSServer::response_for_query(
void DNSServer::on_receive_message(int fd, short) {
for (;;) {
sockaddr_in remote;
struct sockaddr_storage remote;
socklen_t remote_size = sizeof(sockaddr_in);
memset(&remote, 0, remote_size);
@@ -104,9 +106,10 @@ void DNSServer::on_receive_message(int fd, short) {
dns_server_log.warning("input query too small");
print_data(stderr, input.data(), bytes);
} else {
} else if (!this->banned_ipv4_ranges->check(remote)) {
input.resize(bytes);
uint32_t remote_address = ntohl(remote.sin_addr.s_addr);
const sockaddr_in* remote_sin = reinterpret_cast<const sockaddr_in*>(&remote);
uint32_t remote_address = ntohl(remote_sin->sin_addr.s_addr);
uint32_t connect_address = is_local_address(remote_address)
? this->local_connect_address
: this->external_connect_address;
+14 -6
View File
@@ -7,29 +7,37 @@
#include <string>
#include <unordered_map>
#include "IPV4RangeSet.hh"
class DNSServer {
public:
DNSServer(std::shared_ptr<struct event_base> base,
uint32_t local_connect_address, uint32_t external_connect_address);
DNSServer(
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(DNSServer&&) = delete;
virtual ~DNSServer();
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(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 std::string& query, 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);
private:
std::shared_ptr<struct event_base> base;
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event;
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);
void on_receive_message(int fd, short event);
+134 -110
View File
@@ -38,6 +38,8 @@ const char* name_for_enum<EnemyType>(EnemyType type) {
return "BOOTA";
case EnemyType::BULCLAW:
return "BULCLAW";
case EnemyType::BULK:
return "BULK";
case EnemyType::CANADINE:
return "CANADINE";
case EnemyType::CANADINE_GROUP:
@@ -287,6 +289,7 @@ EnemyType enum_for_name<EnemyType>(const char* name) {
{"BOOMA", EnemyType::BOOMA},
{"BOOTA", EnemyType::BOOTA},
{"BULCLAW", EnemyType::BULCLAW},
{"BULK", EnemyType::BULK},
{"CANADINE", EnemyType::CANADINE},
{"CANADINE_GROUP", EnemyType::CANADINE_GROUP},
{"CANANE", EnemyType::CANANE},
@@ -409,150 +412,152 @@ bool enemy_type_valid_for_episode(Episode episode, EnemyType enemy_type) {
switch (episode) {
case Episode::EP1:
switch (enemy_type) {
case EnemyType::MOTHMANT:
case EnemyType::MONEST:
case EnemyType::SAVAGE_WOLF:
case EnemyType::BARBAROUS_WOLF:
case EnemyType::POISON_LILY:
case EnemyType::NAR_LILY:
case EnemyType::SINOW_BEAT:
case EnemyType::CANADINE:
case EnemyType::CANADINE_GROUP:
case EnemyType::CANANE:
case EnemyType::CHAOS_SORCERER:
case EnemyType::CHAOS_BRINGER:
case EnemyType::DARK_BELRA:
case EnemyType::DE_ROL_LE:
case EnemyType::DRAGON:
case EnemyType::SINOW_GOLD:
case EnemyType::RAG_RAPPY:
case EnemyType::AL_RAPPY:
case EnemyType::NANO_DRAGON:
case EnemyType::DUBCHIC:
case EnemyType::GILLCHIC:
case EnemyType::GARANZ:
case EnemyType::DARK_GUNNER:
case EnemyType::BARBAROUS_WOLF:
case EnemyType::BOOMA:
case EnemyType::BULCLAW:
case EnemyType::BULK:
case EnemyType::CANADINE_GROUP:
case EnemyType::CANADINE:
case EnemyType::CANANE:
case EnemyType::CHAOS_BRINGER:
case EnemyType::CHAOS_SORCERER:
case EnemyType::CLAW:
case EnemyType::VOL_OPT_2:
case EnemyType::POUILLY_SLIME:
case EnemyType::POFUILLY_SLIME:
case EnemyType::PAN_ARMS:
case EnemyType::HIDOOM:
case EnemyType::MIGIUM:
case EnemyType::DARVANT:
case EnemyType::DARVANT_ULTIMATE:
case EnemyType::DARK_BELRA:
case EnemyType::DARK_FALZ_1:
case EnemyType::DARK_FALZ_2:
case EnemyType::DARK_FALZ_3:
case EnemyType::HILDEBEAR:
case EnemyType::HILDEBLUE:
case EnemyType::BOOMA:
case EnemyType::GOBOOMA:
case EnemyType::GIGOBOOMA:
case EnemyType::GRASS_ASSASSIN:
case EnemyType::EVIL_SHARK:
case EnemyType::PAL_SHARK:
case EnemyType::GUIL_SHARK:
case EnemyType::DARK_GUNNER:
case EnemyType::DARVANT_ULTIMATE:
case EnemyType::DARVANT:
case EnemyType::DE_ROL_LE:
case EnemyType::DEATH_GUNNER:
case EnemyType::DELSABER:
case EnemyType::DIMENIAN:
case EnemyType::DRAGON:
case EnemyType::DUBCHIC:
case EnemyType::EVIL_SHARK:
case EnemyType::GARANZ:
case EnemyType::GIGOBOOMA:
case EnemyType::GILLCHIC:
case EnemyType::GOBOOMA:
case EnemyType::GRASS_ASSASSIN:
case EnemyType::GUIL_SHARK:
case EnemyType::HIDOOM:
case EnemyType::HILDEBEAR:
case EnemyType::HILDEBLUE:
case EnemyType::LA_DIMENIAN:
case EnemyType::MIGIUM:
case EnemyType::MONEST:
case EnemyType::MOTHMANT:
case EnemyType::NANO_DRAGON:
case EnemyType::NAR_LILY:
case EnemyType::PAL_SHARK:
case EnemyType::PAN_ARMS:
case EnemyType::POFUILLY_SLIME:
case EnemyType::POISON_LILY:
case EnemyType::POUILLY_SLIME:
case EnemyType::RAG_RAPPY:
case EnemyType::SAVAGE_WOLF:
case EnemyType::SINOW_BEAT:
case EnemyType::SINOW_GOLD:
case EnemyType::SO_DIMENIAN:
case EnemyType::VOL_OPT_2:
return true;
default:
return false;
}
case Episode::EP2:
switch (enemy_type) {
case EnemyType::MOTHMANT:
case EnemyType::MONEST:
case EnemyType::SAVAGE_WOLF:
case EnemyType::BARBAROUS_WOLF:
case EnemyType::POISON_LILY:
case EnemyType::NAR_LILY:
case EnemyType::SINOW_BERILL:
case EnemyType::GEE:
case EnemyType::CHAOS_SORCERER:
case EnemyType::DELBITER:
case EnemyType::DARK_BELRA:
case EnemyType::BARBA_RAY:
case EnemyType::GOL_DRAGON:
case EnemyType::SINOW_SPIGELL:
case EnemyType::RAG_RAPPY:
case EnemyType::LOVE_RAPPY:
case EnemyType::SAINT_RAPPY:
case EnemyType::EGG_RAPPY:
case EnemyType::HALLO_RAPPY:
case EnemyType::GI_GUE:
case EnemyType::DUBCHIC:
case EnemyType::GILLCHIC:
case EnemyType::GARANZ:
case EnemyType::GAL_GRYPHON:
case EnemyType::EPSILON:
case EnemyType::BARBAROUS_WOLF:
case EnemyType::CHAOS_SORCERER:
case EnemyType::DARK_BELRA:
case EnemyType::DEL_LILY:
case EnemyType::ILL_GILL:
case EnemyType::OLGA_FLOW_1:
case EnemyType::OLGA_FLOW_2:
case EnemyType::GAEL:
case EnemyType::DELBITER:
case EnemyType::DELDEPTH:
case EnemyType::PAN_ARMS:
case EnemyType::HIDOOM:
case EnemyType::MIGIUM:
case EnemyType::MERICAROL:
case EnemyType::UL_GIBBON:
case EnemyType::ZOL_GIBBON:
case EnemyType::GIBBLES:
case EnemyType::MORFOS:
case EnemyType::RECOBOX:
case EnemyType::RECON:
case EnemyType::SINOW_ZOA:
case EnemyType::SINOW_ZELE:
case EnemyType::MERIKLE:
case EnemyType::MERICUS:
case EnemyType::HILDEBEAR:
case EnemyType::HILDEBLUE:
case EnemyType::MERILLIA:
case EnemyType::MERILTAS:
case EnemyType::GRASS_ASSASSIN:
case EnemyType::DOLMOLM:
case EnemyType::DOLMDARL:
case EnemyType::DELSABER:
case EnemyType::DIMENIAN:
case EnemyType::DOLMDARL:
case EnemyType::DOLMOLM:
case EnemyType::DUBCHIC:
case EnemyType::EGG_RAPPY:
case EnemyType::EPSILON:
case EnemyType::GAEL:
case EnemyType::GAL_GRYPHON:
case EnemyType::GARANZ:
case EnemyType::GEE:
case EnemyType::GI_GUE:
case EnemyType::GIBBLES:
case EnemyType::GILLCHIC:
case EnemyType::GOL_DRAGON:
case EnemyType::GRASS_ASSASSIN:
case EnemyType::HALLO_RAPPY:
case EnemyType::HIDOOM:
case EnemyType::HILDEBEAR:
case EnemyType::HILDEBLUE:
case EnemyType::ILL_GILL:
case EnemyType::LA_DIMENIAN:
case EnemyType::LOVE_RAPPY:
case EnemyType::MERICAROL:
case EnemyType::MERICUS:
case EnemyType::MERIKLE:
case EnemyType::MERILLIA:
case EnemyType::MERILTAS:
case EnemyType::MIGIUM:
case EnemyType::MONEST:
case EnemyType::MORFOS:
case EnemyType::MOTHMANT:
case EnemyType::NAR_LILY:
case EnemyType::OLGA_FLOW_1:
case EnemyType::OLGA_FLOW_2:
case EnemyType::PAN_ARMS:
case EnemyType::POISON_LILY:
case EnemyType::RAG_RAPPY:
case EnemyType::RECOBOX:
case EnemyType::RECON:
case EnemyType::SAINT_RAPPY:
case EnemyType::SAVAGE_WOLF:
case EnemyType::SINOW_BERILL:
case EnemyType::SINOW_SPIGELL:
case EnemyType::SINOW_ZELE:
case EnemyType::SINOW_ZOA:
case EnemyType::SO_DIMENIAN:
case EnemyType::UL_GIBBON:
case EnemyType::ZOL_GIBBON:
return true;
default:
return false;
}
case Episode::EP4:
switch (enemy_type) {
case EnemyType::BOOTA:
case EnemyType::ZE_BOOTA:
case EnemyType::BA_BOOTA:
case EnemyType::SAND_RAPPY:
case EnemyType::DEL_RAPPY:
case EnemyType::ZU:
case EnemyType::PAZUZU:
case EnemyType::ASTARK:
case EnemyType::SATELLITE_LIZARD:
case EnemyType::YOWIE:
case EnemyType::DORPHON:
case EnemyType::DORPHON_ECLAIR:
case EnemyType::GORAN:
case EnemyType::PYRO_GORAN:
case EnemyType::GORAN_DETONATOR:
case EnemyType::SAND_RAPPY_ALT:
case EnemyType::BA_BOOTA:
case EnemyType::BOOTA:
case EnemyType::DEL_RAPPY_ALT:
case EnemyType::DEL_RAPPY:
case EnemyType::DORPHON_ECLAIR:
case EnemyType::DORPHON:
case EnemyType::GIRTABLULU:
case EnemyType::GORAN_DETONATOR:
case EnemyType::GORAN:
case EnemyType::KONDRIEU:
case EnemyType::MERISSA_A:
case EnemyType::MERISSA_AA:
case EnemyType::ZU_ALT:
case EnemyType::PAZUZU_ALT:
case EnemyType::SATELLITE_LIZARD_ALT:
case EnemyType::YOWIE_ALT:
case EnemyType::GIRTABLULU:
case EnemyType::PAZUZU:
case EnemyType::PYRO_GORAN:
case EnemyType::SAINT_MILLION:
case EnemyType::SAND_RAPPY_ALT:
case EnemyType::SAND_RAPPY:
case EnemyType::SATELLITE_LIZARD_ALT:
case EnemyType::SATELLITE_LIZARD:
case EnemyType::SHAMBERTIN:
case EnemyType::KONDRIEU:
case EnemyType::YOWIE_ALT:
case EnemyType::YOWIE:
case EnemyType::ZE_BOOTA:
case EnemyType::ZU_ALT:
case EnemyType::ZU:
return true;
default:
return false;
@@ -611,8 +616,10 @@ uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type)
case EnemyType::GARANZ:
return 0x1D;
case EnemyType::DARK_GUNNER:
case EnemyType::DEATH_GUNNER:
return 0x1E;
case EnemyType::BULCLAW:
case EnemyType::BULK:
return 0x1F;
case EnemyType::CLAW:
return 0x20;
@@ -834,9 +841,11 @@ uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type)
case EnemyType::GIRTABLULU:
return 0x1F;
case EnemyType::SAINT_MILLION:
case EnemyType::SHAMBERTIN:
case EnemyType::KONDRIEU:
return 0x22;
case EnemyType::SHAMBERTIN:
return 0x26;
case EnemyType::KONDRIEU:
return 0x2A;
default:
throw runtime_error(string_printf("%s does not have battle parameters in Episode 4", name_for_enum(enemy_type)));
}
@@ -863,6 +872,8 @@ uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type) {
return 0x09;
case EnemyType::BOOTA:
return 0x4D;
case EnemyType::BULK:
return 0x27;
case EnemyType::BULCLAW:
return 0x28;
case EnemyType::CANADINE:
@@ -884,6 +895,8 @@ uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type) {
return 0x2F;
case EnemyType::DARK_GUNNER:
return 0x22;
case EnemyType::DEATH_GUNNER:
return 0x23;
case EnemyType::DE_ROL_LE:
return 0x2D;
case EnemyType::DEL_LILY:
@@ -1094,3 +1107,14 @@ const vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8
return empty_vec;
}
}
bool enemy_type_is_rare(EnemyType type) {
return ((type == EnemyType::HILDEBLUE) ||
(type == EnemyType::AL_RAPPY) ||
(type == EnemyType::NAR_LILY) ||
(type == EnemyType::POUILLY_SLIME) ||
(type == EnemyType::MERISSA_AA) ||
(type == EnemyType::PAZUZU_ALT) ||
(type == EnemyType::DORPHON_ECLAIR) ||
(type == EnemyType::KONDRIEU));
}
+2
View File
@@ -20,6 +20,7 @@ enum class EnemyType {
BOOMA,
BOOTA,
BULCLAW,
BULK,
CANADINE,
CANADINE_GROUP,
CANANE,
@@ -145,3 +146,4 @@ bool enemy_type_valid_for_episode(Episode episode, EnemyType enemy_type);
uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type);
uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type);
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index);
bool enemy_type_is_rare(EnemyType type);
+40 -19
View File
@@ -6,21 +6,38 @@ using namespace std;
namespace Episode3 {
// Note: This order matches the order that the cards are defined in the original
// code. This is relevant for consistency of results when choosing a random card
// (for God Whim).
const vector<uint16_t> ALL_ASSIST_CARD_IDS = {
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA,
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103,
0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C,
0x010D, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129,
0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B,
0x013C, 0x013D, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144,
0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F,
0x0240, 0x0241, 0x0242};
const vector<uint16_t>& all_assist_card_ids(bool is_nte) {
// Note: This order matches the order that the cards are defined in the original
// code. This is relevant for consistency of results when choosing a random card
// (for God Whim).
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_TRIAL = {
0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD,
0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106,
0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, 0x010F,
0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, 0x012C,
0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135,
0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, 0x013C, 0x013D, 0x013E,
0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0148,
0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F, 0x0240, 0x0241, 0x0242};
static const vector<uint16_t> ALL_ASSIST_CARD_IDS_FINAL = {
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA,
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103,
0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C,
0x010D, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129,
0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B,
0x013C, 0x013D, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144,
0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F,
0x0240, 0x0241, 0x0242};
return is_nte ? ALL_ASSIST_CARD_IDS_TRIAL : ALL_ASSIST_CARD_IDS_FINAL;
}
AssistEffect assist_effect_number_for_card_id(uint16_t card_id) {
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({
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
});
static const unordered_map<uint16_t, AssistEffect> card_id_to_effect({
{0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
@@ -94,15 +111,18 @@ AssistEffect assist_effect_number_for_card_id(uint16_t card_id) {
{0x0240, /* 0x0046 */ AssistEffect::BOMB},
{0x0241, /* 0x0047 */ AssistEffect::SKIP_TURN},
{0x0242, /* 0x0048 */ AssistEffect::BATTLE_ROYALE},
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
});
try {
return card_id_to_effect.at(card_id);
} catch (const out_of_range&) {
return AssistEffect::NONE;
}
if (!is_nte) {
try {
return card_id_to_effect_final_only.at(card_id);
} catch (const out_of_range&) {
}
}
return AssistEffect::NONE;
}
AssistServer::AssistServer(shared_ptr<Server> server)
@@ -224,6 +244,7 @@ AssistEffect AssistServer::get_active_assist_by_index(size_t index) const {
}
void AssistServer::populate_effects() {
bool is_nte = this->server()->options.is_nte();
for (size_t z = 0; z < 4; z++) {
this->assist_card_defs[z] = nullptr;
this->assist_effects[z] = AssistEffect::NONE;
@@ -232,7 +253,7 @@ void AssistServer::populate_effects() {
uint16_t card_id = hes->assist_card_id == 0xFFFF
? this->card_id_for_card_ref(hes->assist_card_ref)
: hes->assist_card_id.load();
this->assist_effects[z] = assist_effect_number_for_card_id(card_id);
this->assist_effects[z] = assist_effect_number_for_card_id(card_id, is_nte);
if (this->assist_effects[z] != AssistEffect::NONE) {
this->assist_card_defs[z] = this->definition_for_card_id(card_id);
}
+9 -10
View File
@@ -13,9 +13,8 @@ namespace Episode3 {
class Server;
extern const std::vector<uint16_t> ALL_ASSIST_CARD_IDS;
AssistEffect assist_effect_number_for_card_id(uint16_t card_id);
const std::vector<uint16_t>& all_assist_card_ids(bool is_nte);
AssistEffect assist_effect_number_for_card_id(uint16_t card_id, bool is_nte);
class AssistServer {
public:
@@ -40,17 +39,17 @@ private:
public:
parray<AssistEffect, 4> assist_effects;
std::shared_ptr<const CardIndex::CardEntry> assist_card_defs[4];
bcarray<std::shared_ptr<const CardIndex::CardEntry>, 4> assist_card_defs;
uint32_t num_assist_cards_set;
parray<uint8_t, 4> client_ids_with_assists;
parray<AssistEffect, 4> active_assist_effects;
std::shared_ptr<const CardIndex::CardEntry> active_assist_card_defs[4];
bcarray<std::shared_ptr<const CardIndex::CardEntry>, 4> active_assist_card_defs;
uint32_t num_active_assists;
std::shared_ptr<HandAndEquipState> hand_and_equip_states[4];
std::shared_ptr<parray<CardShortStatus, 0x10>> card_short_statuses[4];
std::shared_ptr<DeckEntry> deck_entries[4];
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains[4];
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas[4];
bcarray<std::shared_ptr<HandAndEquipState>, 4> hand_and_equip_states;
bcarray<std::shared_ptr<parray<CardShortStatus, 0x10>>, 4> card_short_statuses;
bcarray<std::shared_ptr<DeckEntry>, 4> deck_entries;
bcarray<std::shared_ptr<parray<ActionChainWithConds, 9>>, 4> set_card_action_chains;
bcarray<std::shared_ptr<parray<ActionMetadata, 9>>, 4> set_card_action_metadatas;
};
} // namespace Episode3
+93 -3
View File
@@ -9,6 +9,12 @@ using namespace std;
namespace Episode3 {
void BattleRecord::PlayerEntry::print(FILE* stream) const {
// TODO: Format this nicely somehow. Maybe factor out the functions in
// QuestScript that format some of these structures
print_data(stream, this, sizeof(this));
}
BattleRecord::Event::Event(StringReader& r) {
this->type = r.get<Event::Type>();
this->timestamp = r.get_u64l();
@@ -32,6 +38,7 @@ BattleRecord::Event::Event(StringReader& r) {
case Event::Type::GAME_COMMAND:
case Event::Type::BATTLE_COMMAND:
case Event::Type::EP3_GAME_COMMAND:
case Event::Type::SERVER_DATA_COMMAND:
this->data = r.read(r.get_u16l());
break;
default:
@@ -64,6 +71,7 @@ void BattleRecord::Event::serialize(StringWriter& w) const {
case Event::Type::GAME_COMMAND:
case Event::Type::BATTLE_COMMAND:
case Event::Type::EP3_GAME_COMMAND:
case Event::Type::SERVER_DATA_COMMAND:
w.put_u16l(this->data.size());
w.write(this->data);
break;
@@ -72,6 +80,51 @@ void BattleRecord::Event::serialize(StringWriter& w) const {
}
}
void BattleRecord::Event::print(FILE* stream) const {
string time_str = format_time(this->timestamp);
fprintf(stream, "Event @%016" PRIX64 " (%s) ", this->timestamp, time_str.c_str());
switch (this->type) {
case Type::PLAYER_JOIN:
fprintf(stream, "PLAYER_JOIN %02" PRIX32 "\n", this->players[0].lobby_data.client_id.load());
this->players[0].print(stream);
break;
case Type::PLAYER_LEAVE:
fprintf(stream, "PLAYER_LEAVE %02hhu\n", this->leaving_client_id);
break;
case Type::SET_INITIAL_PLAYERS:
fprintf(stream, "SET_INITIAL_PLAYERS");
for (const auto& player : this->players) {
fprintf(stream, " %02" PRIX32, player.lobby_data.client_id.load());
}
for (const auto& player : this->players) {
player.print(stream);
}
break;
case Type::BATTLE_COMMAND:
fprintf(stream, "BATTLE_COMMAND\n");
print_data(stream, this->data);
break;
case Type::GAME_COMMAND:
fprintf(stream, "GAME_COMMAND\n");
print_data(stream, this->data);
break;
case Type::EP3_GAME_COMMAND:
fprintf(stream, "EP3_GAME_COMMAND\n");
print_data(stream, this->data);
break;
case Type::CHAT_MESSAGE:
fprintf(stream, "CHAT_MESSAGE %08" PRIX32 "\n", this->guild_card_number);
print_data(stream, this->data);
break;
case Type::SERVER_DATA_COMMAND:
fprintf(stream, "SERVER_DATA_COMMAND\n");
print_data(stream, this->data);
break;
default:
throw runtime_error("unknown event type in battle record");
}
}
BattleRecord::BattleRecord(uint32_t behavior_flags)
: is_writable(true),
behavior_flags(behavior_flags),
@@ -84,14 +137,23 @@ BattleRecord::BattleRecord(const string& data)
battle_start_timestamp(0),
battle_end_timestamp(0) {
StringReader r(data);
uint64_t signature = r.get_u64l();
if (signature != this->SIGNATURE) {
bool has_random_stream;
if (signature == this->SIGNATURE_V1) {
has_random_stream = false;
} else if (signature == this->SIGNATURE_V2) {
has_random_stream = true;
} else {
throw runtime_error("incorrect battle record signature");
}
this->battle_start_timestamp = r.get_u64l();
this->battle_end_timestamp = r.get_u64l();
this->behavior_flags = r.get_u32l();
if (has_random_stream) {
this->random_stream = r.read(r.get_u32l());
}
while (!r.eof()) {
this->events.emplace_back(r);
}
@@ -99,10 +161,12 @@ BattleRecord::BattleRecord(const string& data)
string BattleRecord::serialize() const {
StringWriter w;
w.put_u64l(this->SIGNATURE);
w.put_u64l(this->SIGNATURE_V2);
w.put_u64l(this->battle_start_timestamp);
w.put_u64l(this->battle_end_timestamp);
w.put_u32l(this->behavior_flags);
w.put_u32l(this->random_stream.size());
w.write(this->random_stream);
for (const auto& ev : this->events) {
ev.serialize(w);
}
@@ -187,11 +251,15 @@ void BattleRecord::add_chat_message(
ev.data = std::move(data);
}
void BattleRecord::add_random_data(const void* data, size_t size) {
this->random_stream.append(reinterpret_cast<const char*>(data), size);
}
bool BattleRecord::is_map_definition_event(const Event& ev) {
if (ev.type == Event::Type::BATTLE_COMMAND) {
auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF);
if (header.subcommand == 0xB6) {
auto& header = check_size_t<G_MapSubsubcommand_GC_Ep3_6xB6>(ev.data, 0xFFFF);
auto& header = check_size_t<G_MapSubsubcommand_Ep3_6xB6>(ev.data, 0xFFFF);
if (header.subsubcommand == 0x41) {
return true;
}
@@ -268,12 +336,30 @@ void BattleRecord::set_battle_start_timestamp() {
}
}
this->events = std::move(new_events);
// Clear any existing random data (there shouldn't be any)
this->random_stream.clear();
}
void BattleRecord::set_battle_end_timestamp() {
this->battle_end_timestamp = now();
}
void BattleRecord::print(FILE* stream) const {
string start_str = format_time(this->battle_start_timestamp);
string end_str = 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->behavior_flags,
this->battle_start_timestamp,
start_str.c_str(),
this->battle_end_timestamp,
end_str.c_str(), this->events.size());
for (const auto& event : this->events) {
event.print(stream);
}
}
BattleRecordPlayer::BattleRecordPlayer(
shared_ptr<const BattleRecord> rec,
shared_ptr<struct event_base> base)
@@ -356,6 +442,10 @@ void BattleRecordPlayer::schedule_events() {
case BattleRecord::Event::Type::CHAT_MESSAGE:
send_prepared_chat_message(l, ev.guild_card_number, ev.data);
break;
case BattleRecord::Event::Type::SERVER_DATA_COMMAND:
// These are not replayed, since the battle record also contains
// the results of these commands.
break;
}
this->event_it++;
+13 -5
View File
@@ -24,7 +24,9 @@ public:
PlayerInventory inventory;
PlayerDispDataDCPCV3 disp;
le_uint32_t level;
} __attribute__((packed));
void print(FILE* stream) const;
} __packed_ws__(PlayerEntry, 0x440);
struct Event {
enum class Type : uint8_t {
@@ -35,6 +37,7 @@ public:
GAME_COMMAND = 4,
EP3_GAME_COMMAND = 5,
CHAT_MESSAGE = 6,
SERVER_DATA_COMMAND = 7,
};
// Fields used for all events
@@ -52,6 +55,7 @@ public:
Event() = default;
explicit Event(StringReader& r);
void serialize(StringWriter& w) const;
void print(FILE* stream) const;
};
explicit BattleRecord(uint32_t behavior_flags);
@@ -72,6 +76,7 @@ public:
void add_command(Event::Type type, const void* data, size_t size);
void add_command(Event::Type type, std::string&& data);
void add_chat_message(uint32_t guild_card_number, std::string&& data);
void add_random_data(const void* data, size_t size);
// This function collapses all the existing player join/leave events into a
// single SET_INITIAL_PLAYERS event, and deletes all events before the latest
// BATTLE_COMMAND command that specifies the battle map. This should provide a
@@ -79,8 +84,11 @@ public:
void set_battle_start_timestamp();
void set_battle_end_timestamp();
void print(FILE* stream) const;
private:
static constexpr uint64_t SIGNATURE = 0x14C946D56D1DAC50;
static constexpr uint64_t SIGNATURE_V1 = 0x14C946D56D1DAC50;
static constexpr uint64_t SIGNATURE_V2 = 0xD01E5EC12853C377;
static bool is_map_definition_event(const Event& ev);
@@ -90,15 +98,14 @@ private:
uint64_t battle_start_timestamp;
uint64_t battle_end_timestamp;
std::deque<Event> events;
std::string random_stream;
friend class BattleRecordPlayer;
};
class BattleRecordPlayer {
public:
BattleRecordPlayer(
std::shared_ptr<const BattleRecord> rec,
std::shared_ptr<struct event_base> base);
BattleRecordPlayer(std::shared_ptr<const BattleRecord> rec, std::shared_ptr<struct event_base> base);
~BattleRecordPlayer() = default;
std::shared_ptr<const BattleRecord> get_record() const;
@@ -116,6 +123,7 @@ private:
std::shared_ptr<struct event_base> base;
std::weak_ptr<Lobby> lobby;
std::shared_ptr<struct event> next_command_ev;
StringReader random_r;
};
} // namespace Episode3
+563 -297
View File
File diff suppressed because it is too large Load Diff
+19 -23
View File
@@ -15,11 +15,7 @@ class PlayerState;
class Card : public std::enable_shared_from_this<Card> {
public:
Card(
uint16_t card_id,
uint16_t card_ref,
uint16_t client_id,
std::shared_ptr<Server> server);
Card(uint16_t card_id, uint16_t card_ref, uint16_t client_id, std::shared_ptr<Server> server);
void init();
std::shared_ptr<Server> server();
std::shared_ptr<const Server> server() const;
@@ -34,29 +30,31 @@ public:
int16_t value,
int8_t dice_roll_value,
int8_t random_percent);
void apply_ap_adjust_assists_to_attack(
void apply_ap_and_tp_adjust_assists_to_attack(
std::shared_ptr<const Card> attacker_card,
int16_t* inout_attacker_ap,
int16_t* in_defense_power) const;
int16_t* in_defense_power,
int16_t* inout_attacker_tp) const;
bool card_type_is_sc_or_creature() const;
bool check_card_flag(uint32_t flags) const;
void commit_attack(
int16_t damage,
std::shared_ptr<Card> attacker_card,
G_ApplyConditionEffect_GC_Ep3_6xB4x06* cmd,
G_ApplyConditionEffect_Ep3_6xB4x06* cmd,
size_t strike_number,
int16_t* out_effective_damage);
int16_t compute_defense_power_for_attacker_card(
std::shared_ptr<const Card> attacker_card);
int16_t compute_defense_power_for_attacker_card(std::shared_ptr<const Card> attacker_card);
void destroy_set_card(std::shared_ptr<Card> attacker_card);
int32_t error_code_for_move_to_location(const Location& loc) const;
void execute_attack(std::shared_ptr<Card> attacker_card);
bool get_attack_condition_value(
bool get_condition_value(
ConditionType cond_type,
uint16_t card_ref,
uint8_t def_effect_index,
uint16_t value,
uint16_t* out_value) const;
uint16_t card_ref = 0xFFFF,
uint8_t def_effect_index = 0xFF,
uint16_t value = 0xFFFF,
uint16_t* out_value = nullptr) const;
Condition* find_condition(ConditionType cond_type);
const Condition* find_condition(ConditionType cond_type) const;
std::shared_ptr<const CardIndex::CardEntry> get_definition() const;
uint16_t get_card_ref() const;
uint16_t get_card_id() const;
@@ -70,23 +68,21 @@ public:
void send_6xB4x4E_4C_4D_if_needed(bool always_send = false);
void send_6xB4x4E_if_needed(bool always_send = false);
void set_current_and_max_hp(int16_t hp);
void set_current_hp(
uint32_t new_hp, bool propagate_shared_hp = true, bool enforce_max_hp = true);
void set_current_hp(uint32_t new_hp, bool propagate_shared_hp = true, bool enforce_max_hp = true);
void update_stats_on_destruction();
void clear_action_chain_and_metadata_and_most_flags();
void compute_action_chain_results(
bool apply_action_conditions, bool ignore_this_card_ap_tp);
void compute_action_chain_results(bool apply_action_conditions, bool ignore_this_card_ap_tp);
void unknown_802380C0();
void unknown_80237F98(bool require_condition_20_or_21);
void unknown_80237F88();
void unknown_80235AA0();
void unknown_80235AD4();
void unknown_80235B10();
void draw_phase_before();
void action_phase_before();
void move_phase_before();
void unknown_80236374(std::shared_ptr<Card> other_card, const ActionState* as);
void unknown_802379BC(uint16_t card_ref);
void unknown_802379DC(const ActionState& pa);
void unknown_80237A90(const ActionState& pa, uint16_t action_card_ref);
void unknown_8023813C();
void dice_phase_before();
bool is_guard_item() const;
bool unknown_80236554(std::shared_ptr<Card> other_card, const ActionState* as);
void unknown_802362D8(std::shared_ptr<Card> other_card);
File diff suppressed because it is too large Load Diff
+52 -51
View File
@@ -6,6 +6,7 @@
#include "../Text.hh"
#include "DataIndexes.hh"
#include "Server.hh"
namespace Episode3 {
@@ -45,52 +46,56 @@ public:
};
struct AttackEnvStats {
uint32_t num_set_cards; // "f" in expr
uint32_t dice_roll_value1; // "d" in expr
uint32_t effective_ap; // "ap" in expr
uint32_t effective_tp; // "tp" in expr
uint32_t current_hp; // "hp" in expr
uint32_t max_hp; // "mhp" in expr
uint32_t effective_ap_if_not_tech; // "dm" in expr
uint32_t effective_ap_if_not_physical; // "tdm" in expr
uint32_t player_num_destroyed_fcs; // "tf" in expr
uint32_t player_num_atk_points; // "ac" in expr
uint32_t defined_max_hp; // "php" in expr
uint32_t dice_roll_value2; // "dc" in expr
uint32_t card_cost; // "cs" in expr
uint32_t total_num_set_cards; // "a" in expr
uint32_t action_cards_ap; // "kap" in expr
uint32_t action_cards_tp; // "ktp" in expr
uint32_t unknown_a1; // "dn" in expr
uint32_t num_item_or_creature_cards_in_hand; // "hf" in expr
uint32_t num_destroyed_ally_fcs; // "df" in expr
uint32_t target_team_num_set_cards; // "ff" in expr
uint32_t condition_giver_team_num_set_cards; // "ef" in expr
uint32_t num_native_creatures; // "bi" in expr
uint32_t num_a_beast_creatures; // "ab" in expr
uint32_t num_machine_creatures; // "mc" in expr
uint32_t num_dark_creatures; // "dk" in expr
uint32_t num_sword_type_items; // "sa" in expr
uint32_t num_gun_type_items; // "gn" in expr
uint32_t num_cane_type_items; // "wd" in expr
uint32_t effective_ap_if_not_tech2; // "tt" in expr
uint32_t team_dice_boost; // "lv" in expr
uint32_t sc_effective_ap; // "adm" in expr
uint32_t attack_bonus; // "ddm" in expr
uint32_t num_sword_type_items_on_team; // "sat" in expr
uint32_t target_attack_bonus; // "edm" in expr
uint32_t last_attack_preliminary_damage; // "ldm" in expr
uint32_t last_attack_damage; // "rdm" in expr
uint32_t total_last_attack_damage; // "fdm" in expr
uint32_t last_attack_damage_count; // "ndm" in expr
uint32_t target_current_hp; // "ehp" in expr
/* 00 */ uint32_t num_set_cards; // "f" in expr
/* 04 */ uint32_t dice_roll_value1; // "d" in expr
/* 08 */ uint32_t effective_ap; // "ap" in expr
/* 0C */ uint32_t effective_tp; // "tp" in expr
/* 10 */ uint32_t current_hp; // "hp" in expr
/* 14 */ uint32_t max_hp; // "mhp" in expr
/* 18 */ uint32_t effective_ap_if_not_tech; // "dm" in expr
/* 1C */ uint32_t effective_ap_if_not_physical; // "tdm" in expr
/* 20 */ uint32_t player_num_destroyed_fcs; // "tf" in expr
/* 24 */ uint32_t player_num_atk_points; // "ac" in expr
/* 28 */ uint32_t defined_max_hp; // "php" in expr
/* 2C */ uint32_t dice_roll_value2; // "dc" in expr
/* 30 */ uint32_t card_cost; // "cs" in expr
/* 34 */ uint32_t total_num_set_cards; // "a" in expr
/* 38 */ uint32_t action_cards_ap; // "kap" in expr
/* 3C */ uint32_t action_cards_tp; // "ktp" in expr
/* 40 */ uint32_t unknown_a1; // "dn" in expr
/* 44 */ uint32_t num_item_or_creature_cards_in_hand; // "hf" in expr
/* 48 */ uint32_t num_destroyed_ally_fcs; // "df" in expr
/* 4C */ uint32_t target_team_num_set_cards; // "ff" in expr
/* 50 */ uint32_t non_target_team_num_set_cards; // "ef" in expr
/* 54 */ uint32_t num_native_creatures; // "bi" in expr
/* 58 */ uint32_t num_a_beast_creatures; // "ab" in expr
/* 5C */ uint32_t num_machine_creatures; // "mc" in expr
/* 60 */ uint32_t num_dark_creatures; // "dk" in expr
/* 64 */ uint32_t num_sword_type_items; // "sa" in expr
/* 68 */ uint32_t num_gun_type_items; // "gn" in expr
/* 6C */ uint32_t num_cane_type_items; // "wd" in expr
/* 70 */ uint32_t effective_ap_if_not_tech2; // "tt" in expr
/* 74 */ uint32_t team_dice_bonus; // "lv" in expr
/* 78 */ uint32_t sc_effective_ap; // "adm" in expr
// The following fields do not exist in Trial Edition. Because this struct
// is never sent to the client, we use the full struct even when playing
// Trial Edition, just for simplicity.
/* 7C */ uint32_t attack_bonus; // "ddm" in expr
/* 80 */ uint32_t num_sword_type_items_on_team; // "sat" in expr
/* 84 */ uint32_t target_attack_bonus; // "edm" in expr
/* 88 */ uint32_t last_attack_preliminary_damage; // "ldm" in expr
/* 8C */ uint32_t last_attack_damage; // "rdm" in expr
/* 90 */ uint32_t total_last_attack_damage; // "fdm" in expr
/* 94 */ uint32_t last_attack_damage_count; // "ndm" in expr
/* 98 */ uint32_t target_current_hp; // "ehp" in expr
/* 9C */
AttackEnvStats();
void clear();
void print(FILE* stream) const;
uint32_t at(size_t index) const;
} __attribute__((packed));
} __packed_ws__(AttackEnvStats, 0x9C);
CardSpecial(std::shared_ptr<Server> server);
std::shared_ptr<Server> server();
@@ -159,7 +164,7 @@ public:
uint32_t* unknown_p11,
uint16_t sc_card_ref);
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
void compute_team_dice_boost(uint8_t team_id);
void compute_team_dice_bonus(uint8_t team_id);
bool condition_has_when_20_or_21(const Condition& cond) const;
size_t count_action_cards_with_condition_for_all_current_attacks(
ConditionType cond_type, uint16_t card_ref) const;
@@ -309,14 +314,13 @@ public:
const Location& card1_loc,
std::shared_ptr<const Card> card2) const;
void unknown_8024AAB8(const ActionState& as);
void unknown_80244BE4(std::shared_ptr<Card> unknown_p2);
void unknown_80244CA8(std::shared_ptr<Card> card);
void move_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
void dice_phase_before_for_card(std::shared_ptr<Card> card);
template <uint8_t When1, uint8_t When2>
void unknown1_t(
std::shared_ptr<Card> unknown_p2, const ActionState* existing_as = nullptr);
void unknown_80249060(std::shared_ptr<Card> unknown_p2);
void unknown_80249254(std::shared_ptr<Card> unknown_p2);
void unknown_8024945C(std::shared_ptr<Card> unknown_p2, const ActionState& existing_as);
void apply_effects_on_phase_change_t(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as = nullptr);
void draw_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
void action_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
void unknown_8024945C(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as);
void unknown_8024966C(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as);
static std::shared_ptr<Card> sc_card_for_card(std::shared_ptr<Card> unknown_p2);
void unknown_8024A9D8(const ActionState& pa, uint16_t action_card_ref);
@@ -333,9 +337,6 @@ public:
private:
std::weak_ptr<Server> w_server;
ActionState unknown_action_state_a1;
ActionState action_state;
uint16_t unknown_a2;
};
} // namespace Episode3
File diff suppressed because it is too large Load Diff
+105 -78
View File
@@ -15,7 +15,7 @@
#include "../PlayerSubordinates.hh"
#include "../Text.hh"
#include "../TextArchive.hh"
#include "../TextIndex.hh"
namespace Episode3 {
@@ -36,6 +36,8 @@ enum BehaviorFlag : uint32_t {
DISABLE_MASKING = 0x00000080,
DISABLE_INTERFERENCE = 0x00000100,
ALLOW_NON_COM_INTERFERENCE = 0x00000200,
IS_TRIAL_EDITION = 0x00000400,
LOG_COMMANDS_IF_LOBBY_MISSING = 0x00000800,
};
enum class StatSwapType : uint8_t {
@@ -58,8 +60,6 @@ enum class AttackMedium : uint8_t {
INVALID_FF = 0xFF,
};
const char* name_for_attack_medium(AttackMedium medium);
enum class CriterionCode : uint8_t {
NONE = 0x00,
HU_CLASS_SC = 0x01,
@@ -98,8 +98,6 @@ enum class CriterionCode : uint8_t {
NON_PHYSICAL_NON_TECH_NON_UNKNOWN_ATTACK_MEDIUM_NON_SC = 0x22,
};
const char* name_for_criterion_code(CriterionCode code);
enum class CardRank : uint8_t {
N1 = 0x01,
R1 = 0x02,
@@ -137,8 +135,6 @@ enum class CardType : uint8_t {
END_CARD_LIST = 0xFF,
};
const char* name_for_card_type(CardType type);
enum class CardClass : uint16_t {
HU_SC = 0x0000,
RA_SC = 0x0001,
@@ -162,8 +158,7 @@ enum class CardClass : uint16_t {
ASSIST = 0x0028,
};
const char* name_for_card_class(CardClass cc);
bool card_class_is_tech_like(CardClass cc);
bool card_class_is_tech_like(CardClass cc, bool is_nte);
enum class TargetMode : uint8_t {
NONE = 0x00, // Used for defense cards, mags, shields, etc.
@@ -299,7 +294,7 @@ enum class ConditionType : uint8_t {
UNKNOWN_75 = 0x75,
REFLECT = 0x76, // Generate reverse attack
UNKNOWN_77 = 0x77,
ANY = 0x78, // Not a real condition; used as a wildcard in search functions
ANY = 0x78, // Not a real condition; used as a wildcard in search functions. Has value 0x64 on NTE
UNKNOWN_79 = 0x79,
UNKNOWN_7A = 0x7A,
UNKNOWN_7B = 0x7B,
@@ -309,8 +304,6 @@ enum class ConditionType : uint8_t {
ANY_FF = 0xFF, // Used as a wildcard in some search functions
};
const char* name_for_condition_type(ConditionType cond_type);
enum class AssistEffect : uint16_t {
NONE = 0x0000,
DICE_HALF = 0x0001,
@@ -407,8 +400,6 @@ enum class ActionSubphase : uint8_t {
INVALID_FF = 0xFF,
};
const char* name_for_action_subphase(ActionSubphase subphase);
enum class SetupPhase : uint8_t {
REGISTRATION = 0,
STARTER_ROLLS = 1,
@@ -438,7 +429,6 @@ enum class Direction : uint8_t {
Direction turn_left(Direction d);
Direction turn_right(Direction d);
Direction turn_around(Direction d);
const char* name_for_direction(Direction d);
struct Location {
/* 00 */ uint8_t x;
@@ -457,7 +447,7 @@ struct Location {
void clear();
void clear_FF();
} __attribute__((packed));
} __packed_ws__(Location, 4);
struct CardDefinition {
struct Stat {
@@ -479,7 +469,8 @@ struct CardDefinition {
void decode_code();
std::string str() const;
} __attribute__((packed));
JSON json() const;
} __packed_ws__(Stat, 4);
struct Effect {
// effect_num is the 1-based index of this effect within the card definition
@@ -514,11 +505,12 @@ struct CardDefinition {
bool is_empty() const;
static std::string str_for_arg(const std::string& arg);
std::string str(const char* separator = ", ", const TextArchive* text_archive = nullptr) const;
} __attribute__((packed));
std::string str(const char* separator = ", ", const TextSet* text_archive = nullptr) const;
JSON json() const;
} __packed_ws__(Effect, 0x20);
/* 0000 */ be_uint32_t card_id;
/* 0004 */ parray<uint8_t, 0x40> jp_name;
/* 0004 */ pstring<TextEncoding::SJIS, 0x40> jp_name;
// The list of card definitions ends with a "sentinel" definition that isn't a
// real card, but instead has a negative number in the type field here.
@@ -764,9 +756,9 @@ struct CardDefinition {
// enormous comment? That's what this array stores.
/* 009C */ parray<be_uint16_t, 2> drop_rates;
/* 00A0 */ pstring<TextEncoding::SJIS, 0x14> en_name;
/* 00A0 */ pstring<TextEncoding::ISO8859, 0x14> en_name;
/* 00B4 */ pstring<TextEncoding::SJIS, 0x0B> jp_short_name;
/* 00BF */ pstring<TextEncoding::SJIS, 0x08> en_short_name;
/* 00BF */ pstring<TextEncoding::ISO8859, 0x08> en_short_name;
// These effects modify the card's behavior in various situations. Only
// effects for which effect_num is not zero are used.
/* 00C7 */ parray<Effect, 3> effects;
@@ -780,8 +772,9 @@ struct CardDefinition {
CardClass card_class() const;
void decode_range();
std::string str(bool single_line = true, const TextArchive* text_archive = nullptr) const;
} __attribute__((packed)); // 0x128 bytes in total
std::string str(bool single_line = true, const TextSet* text_archive = nullptr) const;
JSON json() const;
} __packed_ws__(CardDefinition, 0x128);
struct CardDefinitionsFooter {
// Technically the card definitions file is a REL file, so the last 0x20 bytes
@@ -797,10 +790,10 @@ struct CardDefinitionsFooter {
/* 48 */ be_uint32_t footer_offset;
/* 4C */ parray<be_uint32_t, 3> unused2;
/* 58 */
} __attribute__((packed));
} __packed_ws__(CardDefinitionsFooter, 0x58);
struct DeckDefinition {
/* 00 */ pstring<TextEncoding::SJIS, 0x10> name;
/* 00 */ pstring<TextEncoding::MARKED, 0x10> name;
/* 10 */ be_uint32_t client_id; // 0-3
// List of card IDs. The card count is the number of nonzero entries here
// before a zero entry (or 50 if no entries are nonzero). The first card ID is
@@ -817,17 +810,17 @@ struct DeckDefinition {
/* 82 */ uint8_t second;
/* 83 */ uint8_t unknown_a2;
/* 84 */
} __attribute__((packed));
} __packed_ws__(DeckDefinition, 0x84);
struct PlayerConfig {
// The game splits this internally into two structures. The first column of
// offsets is relative to the start of the first structure; the second column
// is relative to the start of the second structure.
/* 0000:---- */ pstring<TextEncoding::SJIS, 12> rank_text; // From B7 command
/* 0000:---- */ pstring<TextEncoding::MARKED, 12> rank_text; // From B7 command
/* 000C:---- */ parray<uint8_t, 0x1C> unknown_a1;
/* 0028:---- */ parray<be_uint16_t, 20> tech_menu_shortcut_entries;
/* 0050:---- */ parray<be_uint32_t, 10> choice_search_config;
// This field maps to quest_global_flags on Episodes 1 & 2
// This field maps to quest_counters on Episodes 1 & 2
/* 0078:---- */ parray<be_uint32_t, 0x30> scenario_progress;
// place_counts[0] and [1] from this field are added to the player's win and
// loss count respectively when they're shown in the status menu. However,
@@ -835,7 +828,7 @@ struct PlayerConfig {
// earlier version, this was the offline records structure, but they later
// decided to just count online and offline records together in the main
// records structure and didn't remove the codepath that reads from this.
/* 0138:---- */ PlayerRecords_Battle<true> unused_offline_records;
/* 0138:---- */ PlayerRecordsBattleBE unused_offline_records;
/* 0150:---- */ parray<uint8_t, 4> unknown_a4;
// The PlayerDataSegment structure begins here. In newserv, we combine this
// structure into PlayerConfig since the two are always used together.
@@ -885,8 +878,8 @@ struct PlayerConfig {
/* 2124:1FD0 */ be_uint32_t online_clv_exp; // CLvOn = this / 100
struct PlayerReference {
/* 00 */ be_uint32_t guild_card_number;
/* 04 */ pstring<TextEncoding::SJIS, 0x18> player_name;
} __attribute__((packed));
/* 04 */ pstring<TextEncoding::MARKED, 0x18> name;
} __packed_ws__(PlayerReference, 0x1C);
// This array is updated when a battle is started (via a 6xB4x05 command). The
// client adds the opposing players' info to ths first two entries here if the
// opponents are human. (The existing entries are always moved back by two
@@ -909,7 +902,7 @@ struct PlayerConfig {
void decrypt();
void encrypt(uint8_t basis);
} __attribute__((packed));
} __packed_ws__(PlayerConfig, 0x2350);
enum class HPType : uint8_t {
DEFEAT_PLAYER = 0,
@@ -939,8 +932,8 @@ struct Rules {
/* 00 */ uint8_t overall_time_limit = 0;
/* 01 */ uint8_t phase_time_limit = 0; // In seconds; 0 = unlimited
/* 02 */ AllowedCards allowed_cards = AllowedCards::ALL;
/* 03 */ uint8_t min_dice = 1; // 0 = default (1)
/* 04 */ uint8_t max_dice = 6; // 0 = default (6)
/* 03 */ uint8_t min_dice_value = 1; // 0 = default (1)
/* 04 */ uint8_t max_dice_value = 6; // 0 = default (6)
/* 05 */ uint8_t disable_deck_shuffle = 0; // 0 = shuffle on, 1 = off
/* 06 */ uint8_t disable_deck_loop = 0; // 0 = loop on, 1 = off
/* 07 */ uint8_t char_hp = 15;
@@ -951,8 +944,11 @@ struct Rules {
/* 0C */ uint8_t disable_dice_boost = 0; // 0 = dice boost on, 1 = off
// NOTE: The following fields are unused in PSO's implementation, but newserv
// uses them to implement extended rules.
/* 0D */ uint8_t def_dice_range = 0; // High 4 bits = min, low 4 = max
/* 0E */ parray<uint8_t, 6> unused;
/* 0D */ uint8_t def_dice_value_range = 0; // High 4 bits = min, low 4 = max
// These fields specify override dice ranges for the 1-player team in 2v1
/* 0E */ uint8_t atk_dice_value_range_2v1 = 0; // High 4 bits = min, low 4 = max
/* 0F */ uint8_t def_dice_value_range_2v1 = 0; // High 4 bits = min, low 4 = max
/* 10 */ parray<uint8_t, 4> unused;
/* 14 */
// Annoyingly, this structure is a different size in Episode 3 Trial Edition.
@@ -972,20 +968,22 @@ struct Rules {
bool check_invalid_fields() const;
bool check_and_reset_invalid_fields();
uint8_t min_def_dice() const;
uint8_t max_def_dice() const;
std::pair<uint8_t, uint8_t> atk_dice_range(bool is_1p_2v1) const;
std::pair<uint8_t, uint8_t> def_dice_range(bool is_1p_2v1) const;
std::string str() const;
} __attribute__((packed));
} __packed_ws__(Rules, 0x14);
struct RulesTrial {
// The fields here have the same meaning as in the final version. The only
// difference is that Dice Boost does not exist in the trial version.
// Most fields here have the same meanings as in the final version.
/* 00 */ uint8_t overall_time_limit = 0;
/* 01 */ uint8_t phase_time_limit = 0;
/* 02 */ AllowedCards allowed_cards = AllowedCards::ALL;
/* 03 */ uint8_t atk_dice_max = 1;
/* 04 */ uint8_t def_dice_max = 6;
// In NTE, the dice behave differently than in non-NTE. A zero in either of
// these fields means the corresponding die is random in the range [1, 6];
// any nonzero value means that die will always take that value.
/* 03 */ uint8_t atk_die_behavior = 0;
/* 04 */ uint8_t def_die_behavior = 0;
/* 05 */ uint8_t disable_deck_shuffle = 0;
/* 06 */ uint8_t disable_deck_loop = 0;
/* 07 */ uint8_t char_hp = 15;
@@ -996,9 +994,9 @@ struct RulesTrial {
/* 0C */
RulesTrial() = default;
explicit RulesTrial(const Rules&);
RulesTrial(const Rules&);
operator Rules() const;
} __attribute__((packed));
} __packed_ws__(RulesTrial, 0x0C);
struct StateFlags {
/* 00 */ le_uint16_t turn_num;
@@ -1009,7 +1007,7 @@ struct StateFlags {
/* 06 */ SetupPhase setup_phase;
/* 07 */ RegistrationPhase registration_phase;
/* 08 */ parray<le_uint32_t, 2> team_exp;
/* 10 */ parray<uint8_t, 2> team_dice_boost;
/* 10 */ parray<uint8_t, 2> team_dice_bonus;
/* 12 */ uint8_t first_team_turn;
/* 13 */ uint8_t tournament_flag;
/* 14 */ parray<CardType, 4> client_sc_card_types;
@@ -1020,7 +1018,7 @@ struct StateFlags {
bool operator!=(const StateFlags& other) const;
void clear();
void clear_FF();
} __attribute__((packed));
} __packed_ws__(StateFlags, 0x18);
struct MapList {
be_uint32_t num_maps;
@@ -1048,18 +1046,18 @@ struct MapList {
/* 021C */ uint8_t map_category;
/* 021D */ parray<uint8_t, 3> unused;
/* 0220 */
} __attribute__((packed));
} __packed_ws__(Entry, 0x220);
// Variable-length fields:
// Entry entries[num_maps];
// char strings[...EOF]; // Null-terminated strings, pointed to by offsets in Entry structs
} __attribute__((packed));
} __packed_ws__(MapList, 0x10);
struct CompressedMapHeader { // .mnm file format
le_uint32_t map_number;
le_uint32_t compressed_data_size;
// Compressed data immediately follows (which decompresses to a MapDefinition)
} __attribute__((packed));
} __packed_ws__(CompressedMapHeader, 8);
struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
// If tag is not 0x00000100, the game considers the map to be corrupt in
@@ -1156,7 +1154,8 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
/* 48 */
std::string str() const;
} __attribute__((packed));
JSON json() const;
} __packed_ws__(CameraSpec, 0x48);
// This array specifies the camera zone maps. A camera zone map is a subset of
// the main map (specified in map_tiles). Tiles that are part of each camera
@@ -1183,8 +1182,9 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
// 10 = blocked by rock (as if the corresponding map_tiles value was 00)
// 20 = blocked by fence (as if the corresponding map_tiles value was 00)
// 30-34 = teleporters (2 of each value may be present)
// 40-44 = traps (one of each type is chosen at random to be a real trap at
// battle start time)
// 40-4F = traps on NTE
// 40-44 = traps on non-NTE (one of each type is chosen at random to be a real
// trap at battle start time)
// 50 = blocked by metal box (appears as improperly-z-buffered teal cube in
// preview; behaves like 10 and 20 in game)
// The assist cards that each trap type can contain are:
@@ -1198,10 +1198,10 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
/* 1D68 */ parray<uint8_t, 0x74> unknown_a5;
/* 1DDC */ Rules default_rules;
/* 1DF0 */ pstring<TextEncoding::SJIS, 0x14> name;
/* 1E04 */ pstring<TextEncoding::SJIS, 0x14> location_name;
/* 1E18 */ pstring<TextEncoding::SJIS, 0x3C> quest_name; // == location_name if not a quest
/* 1E54 */ pstring<TextEncoding::SJIS, 0x190> description;
/* 1DF0 */ pstring<TextEncoding::MARKED, 0x14> name;
/* 1E04 */ pstring<TextEncoding::MARKED, 0x14> location_name;
/* 1E18 */ pstring<TextEncoding::MARKED, 0x3C> quest_name; // == location_name if not a quest
/* 1E54 */ pstring<TextEncoding::MARKED, 0x190> description;
// These fields describe where the map cursor on the preview screen should
// scroll to
@@ -1209,10 +1209,11 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
/* 1FE6 */ be_uint16_t map_y;
struct NPCDeck {
/* 00 */ pstring<TextEncoding::SJIS, 0x18> name;
/* 00 */ pstring<TextEncoding::MARKED, 0x18> deck_name;
/* 18 */ parray<be_uint16_t, 0x20> card_ids; // Last one appears to always be FFFF
/* 58 */
} __attribute__((packed));
JSON json(uint8_t language) const;
} __packed_ws__(NPCDeck, 0x58);
/* 1FE8 */ parray<NPCDeck, 3> npc_decks; // Unused if name[0] == 0
// These are almost (but not quite) the same format as the entries in
@@ -1223,11 +1224,12 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
/* 0000 */ parray<be_uint16_t, 2> unknown_a1;
/* 0004 */ uint8_t is_arkz;
/* 0005 */ parray<uint8_t, 3> unknown_a2;
/* 0008 */ pstring<TextEncoding::SJIS, 0x10> name;
/* 0008 */ pstring<TextEncoding::MARKED, 0x10> ai_name;
// TODO: Figure out exactly how these are used and document here.
/* 0018 */ parray<be_uint16_t, 0x7E> params;
/* 0114 */
} __attribute__((packed));
JSON json(uint8_t language) const;
} __packed_ws__(AIParams, 0x114);
/* 20F0 */ parray<AIParams, 3> npc_ai_params; // Unused if name[0] == 0
/* 242C */ parray<uint8_t, 8> unknown_a7;
@@ -1257,9 +1259,9 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
// appears after the battle if it's not blank. dispatch_message appears right
// before the player chooses a deck if it's not blank; usually it says
// something like "You can only dispatch <character>".
/* 2440 */ pstring<TextEncoding::SJIS, 0x190> before_message;
/* 25D0 */ pstring<TextEncoding::SJIS, 0x190> after_message;
/* 2760 */ pstring<TextEncoding::SJIS, 0x190> dispatch_message;
/* 2440 */ pstring<TextEncoding::MARKED, 0x190> before_message;
/* 25D0 */ pstring<TextEncoding::MARKED, 0x190> after_message;
/* 2760 */ pstring<TextEncoding::MARKED, 0x190> dispatch_message;
struct DialogueSet {
// Dialogue sets specify lines that COMs can say at certain points during
@@ -1277,9 +1279,10 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
/* 0002 */ be_uint16_t percent_chance; // 0-100, or FFFF if unused
// If the dialogue set activates, the game randomly chooses one of these
// strings, excluding any that are empty or begin with the character '^'.
/* 0004 */ parray<pstring<TextEncoding::SJIS, 0x40>, 4> strings;
/* 0004 */ parray<pstring<TextEncoding::MARKED, 0x40>, 4> strings;
/* 0104 */
} __attribute__((packed));
JSON json(uint8_t language) const;
} __packed_ws__(DialogueSet, 0x104);
// There are up to 0x10 of these per valid NPC, but only the first 13 of them
// are used, since each one must have a unique value for .when and the values
@@ -1361,7 +1364,8 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
bool operator==(const EntryState& other) const = default;
bool operator!=(const EntryState& other) const = default;
} __attribute__((packed));
JSON json() const;
} __packed_ws__(EntryState, 2);
/* 5A10 */ parray<EntryState, 4> entry_states;
/* 5A18 */
@@ -1376,7 +1380,8 @@ struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
void assert_semantically_equivalent(const MapDefinition& other) const;
std::string str(const CardIndex* card_index, uint8_t language) const;
} __attribute__((packed));
JSON json(uint8_t language) const;
} __packed_ws__(MapDefinition, 0x5A18);
struct MapDefinitionTrial {
// This is the format of Episode 3 Trial Edition maps. See the comments in
@@ -1396,19 +1401,19 @@ struct MapDefinitionTrial {
/* 1C68 */ parray<parray<uint8_t, 0x10>, 0x10> modification_tiles;
/* 1D68 */ parray<uint8_t, 0x74> unknown_a5;
/* 1DD4 */ RulesTrial default_rules;
/* 1DE8 */ pstring<TextEncoding::SJIS, 0x14> name;
/* 1DFC */ pstring<TextEncoding::SJIS, 0x14> location_name;
/* 1E10 */ pstring<TextEncoding::SJIS, 0x3C> quest_name;
/* 1E4C */ pstring<TextEncoding::SJIS, 0x190> description;
/* 1DE8 */ pstring<TextEncoding::MARKED, 0x14> name;
/* 1DFC */ pstring<TextEncoding::MARKED, 0x14> location_name;
/* 1E10 */ pstring<TextEncoding::MARKED, 0x3C> quest_name;
/* 1E4C */ pstring<TextEncoding::MARKED, 0x190> description;
/* 1FDC */ be_uint16_t map_x;
/* 1FDE */ be_uint16_t map_y;
/* 1FE0 */ parray<MapDefinition::NPCDeck, 3> npc_decks;
/* 20E8 */ parray<MapDefinition::AIParams, 3> npc_ai_params;
/* 2424 */ parray<uint8_t, 8> unknown_a7;
/* 242C */ parray<be_int32_t, 3> npc_ai_params_entry_index;
/* 2438 */ pstring<TextEncoding::SJIS, 0x190> before_message;
/* 25C8 */ pstring<TextEncoding::SJIS, 0x190> after_message;
/* 2758 */ pstring<TextEncoding::SJIS, 0x190> dispatch_message;
/* 2438 */ pstring<TextEncoding::MARKED, 0x190> before_message;
/* 25C8 */ pstring<TextEncoding::MARKED, 0x190> after_message;
/* 2758 */ pstring<TextEncoding::MARKED, 0x190> dispatch_message;
/* 28E8 */ parray<parray<MapDefinition::DialogueSet, 8>, 3> dialogue_sets;
/* 4148 */ parray<be_uint16_t, 0x10> reward_card_ids;
/* 4168 */ be_int32_t win_level_override;
@@ -1425,7 +1430,7 @@ struct MapDefinitionTrial {
MapDefinitionTrial(const MapDefinition& map);
operator MapDefinition() const;
} __attribute__((packed));
} __packed_ws__(MapDefinitionTrial, 0x41A0);
struct COMDeckDefinition {
size_t index;
@@ -1458,6 +1463,7 @@ public:
std::shared_ptr<const CardEntry> definition_for_name_normalized(const std::string& name) const;
std::set<uint32_t> all_ids() const;
uint64_t definitions_mtime() const;
JSON definitions_json() const;
private:
static std::string normalize_card_name(const std::string& name);
@@ -1482,7 +1488,7 @@ public:
VersionedMap(std::string&& compressed_data, uint8_t language);
std::shared_ptr<const MapDefinitionTrial> trial() const;
const std::string& compressed(bool is_trial) const;
const std::string& compressed(bool is_nte) const;
private:
mutable std::shared_ptr<const MapDefinitionTrial> trial_map;
@@ -1549,3 +1555,24 @@ template <>
Episode3::AllowedCards enum_for_name<Episode3::AllowedCards>(const char* name);
template <>
const char* name_for_enum<Episode3::AllowedCards>(Episode3::AllowedCards allowed_cards);
template <>
const char* name_for_enum<Episode3::BattlePhase>(Episode3::BattlePhase phase);
template <>
const char* name_for_enum<Episode3::SetupPhase>(Episode3::SetupPhase phase);
template <>
const char* name_for_enum<Episode3::RegistrationPhase>(Episode3::RegistrationPhase phase);
template <>
const char* name_for_enum<Episode3::ActionSubphase>(Episode3::ActionSubphase phase);
template <>
const char* name_for_enum<Episode3::AttackMedium>(Episode3::AttackMedium medium);
template <>
const char* name_for_enum<Episode3::CriterionCode>(Episode3::CriterionCode code);
template <>
const char* name_for_enum<Episode3::CardType>(Episode3::CardType type);
template <>
const char* name_for_enum<Episode3::CardClass>(Episode3::CardClass cc);
template <>
const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_type);
template <>
const char* name_for_enum<Episode3::Direction>(Episode3::Direction d);
+50 -35
View File
@@ -1,5 +1,7 @@
#include "DeckState.hh"
#include "Server.hh"
using namespace std;
namespace Episode3 {
@@ -84,42 +86,45 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
}
uint8_t index = index_for_card_ref(card_ref);
if (index > this->entries.size()) {
if (index >= this->entries.size()) {
return false;
}
// If the card is discarded, then it should be before the draw index, and we
// can just change its state.
if (this->entries[index].state == CardState::DISCARDED) {
this->entries[index].state = CardState::IN_HAND;
auto& entry = this->entries[index];
if (entry.state == CardState::DISCARDED) {
// If the card is discarded, then it should be before the draw index, and we
// can just change its state.
entry.state = CardState::IN_HAND;
return true;
}
// If the card is still drawable, we need to move it so it's just in front of
// the draw index, then immediately draw it
} else if (this->entries[index].state == CardState::DRAWABLE) {
ssize_t ref_index;
for (ref_index = this->card_refs.size(); ref_index >= 0; ref_index--) {
if (this->card_refs[ref_index] == card_ref) {
break;
}
}
if (ref_index < 0) {
return false;
}
size_t ref_uindex = ref_index;
for (; ref_uindex > this->draw_index; ref_uindex--) {
// Note: draw_index is also unsigned, so ref_uindex cannot be zero here
this->card_refs[ref_uindex] = this->card_refs[ref_uindex - 1];
}
this->card_refs[this->draw_index] = card_ref;
this->entries[index].state = CardState::IN_HAND;
this->draw_index++;
return true;
} else {
if (entry.state != CardState::DRAWABLE) {
return false;
}
// If the card is still drawable, we need to move it so it's just in front of
// the draw index, then immediately draw it. Ep3 NTE does not handle this
// case, but we do even when playing NTE.
size_t ref_index;
for (ref_index = 0; ref_index < this->card_refs.size(); ref_index++) {
if (this->card_refs[ref_index] == card_ref) {
break;
}
}
if (ref_index >= this->card_refs.size()) {
return false;
}
for (; ref_index > this->draw_index; ref_index--) {
// this->draw_index is also unsigned, so ref_index cannot be zero here
this->card_refs[ref_index] = this->card_refs[ref_index - 1];
}
this->card_refs[this->draw_index] = card_ref;
// Draw the card
entry.state = CardState::IN_HAND;
this->draw_index++;
return true;
}
uint16_t DeckState::card_id_for_card_ref(uint16_t card_ref) const {
@@ -182,7 +187,7 @@ void DeckState::restart() {
this->shuffle();
}
void DeckState::do_mulligan() {
void DeckState::do_mulligan(bool is_nte) {
for (size_t z = 0; z < this->entries.size(); z++) {
if (this->entries[z].state == CardState::DISCARDED) {
this->entries[z].state = CardState::DRAWABLE;
@@ -190,7 +195,7 @@ void DeckState::do_mulligan() {
}
this->draw_index = 1;
if (this->shuffle_enabled) {
if (is_nte || this->shuffle_enabled) {
// Get the next 5 cards from the deck, and put the previous 5 cards after
// them (so they will be shuffled back in).
for (uint8_t z = 0; z < 5; z++) {
@@ -200,12 +205,17 @@ void DeckState::do_mulligan() {
this->card_refs[index + 5] = temp_ref;
}
auto s = this->server.lock();
if (!s) {
throw runtime_error("server is missing");
}
// Shuffle the deck, except the first 5 cards (which are about to be drawn).
size_t max = this->num_drawable_cards() - 5;
uint8_t base_index = this->draw_index + 5;
for (size_t z = 0; z < this->card_refs.size(); z++) {
uint8_t index1 = this->random_crypt->next() % max;
uint8_t index2 = this->random_crypt->next() % max;
uint8_t index1 = s->get_random(max);
uint8_t index2 = s->get_random(max);
uint16_t temp_ref = this->card_refs[base_index + index1];
this->card_refs[base_index + index1] = this->card_refs[base_index + index2];
this->card_refs[base_index + index2] = temp_ref;
@@ -257,6 +267,11 @@ void DeckState::set_card_discarded(uint16_t card_ref) {
void DeckState::shuffle() {
if (this->shuffle_enabled) {
auto s = this->server.lock();
if (!s) {
throw runtime_error("server is missing");
}
size_t max = this->num_drawable_cards();
for (size_t z = 0; z < this->card_refs.size(); z++) {
// Note: This is the way Sega originally implemented shuffling - they just
@@ -264,8 +279,8 @@ void DeckState::shuffle() {
// instead swap each item with another random item (possibly itself) that
// doesn't appear earlier than it in the array, but this is not what Sega
// did.
uint8_t index1 = this->draw_index + this->random_crypt->next() % max;
uint8_t index2 = this->draw_index + this->random_crypt->next() % max;
uint8_t index1 = this->draw_index + s->get_random(max);
uint8_t index2 = this->draw_index + s->get_random(max);
uint16_t temp_ref = this->card_refs[index1];
this->card_refs[index1] = this->card_refs[index2];
this->card_refs[index2] = temp_ref;
+25 -21
View File
@@ -10,32 +10,36 @@
namespace Episode3 {
class Server;
struct NameEntry {
parray<char, 0x10> name;
uint8_t client_id;
uint8_t present;
uint8_t is_cpu_player;
uint8_t unused;
/* 00 */ pstring<TextEncoding::MARKED, 0x10> name;
/* 10 */ uint8_t client_id;
/* 11 */ uint8_t present;
/* 12 */ uint8_t is_cpu_player;
/* 13 */ uint8_t unused;
/* 14 */
NameEntry();
void clear();
} __attribute__((packed));
} __packed_ws__(NameEntry, 0x14);
struct DeckEntry {
pstring<TextEncoding::SJIS, 0x10> name;
le_uint32_t team_id;
parray<le_uint16_t, 31> card_ids;
/* 00 */ pstring<TextEncoding::MARKED, 0x10> name;
/* 10 */ le_uint32_t team_id;
/* 14 */ parray<le_uint16_t, 31> card_ids;
// If the following flag is not set to 3, then the God Whim assist effect can
// use cards that are hidden from the player during deck building. The client
// always sets this to 3, and it's not clear why this even exists.
uint8_t god_whim_flag;
uint8_t unused1;
le_uint16_t player_level;
parray<uint8_t, 2> unused2;
/* 52 */ uint8_t god_whim_flag;
/* 53 */ uint8_t unused1;
/* 54 */ le_uint16_t player_level;
/* 56 */ parray<uint8_t, 2> unused2;
/* 58 */
DeckEntry();
void clear();
} __attribute__((packed));
} __packed_ws__(DeckEntry, 0x58);
uint8_t index_for_card_ref(uint16_t card_ref);
uint8_t client_id_for_card_ref(uint16_t card_ref);
@@ -55,13 +59,13 @@ public:
DeckState(
uint8_t client_id,
const parray<CardIDT, 0x1F>& card_ids,
std::shared_ptr<PSOLFGEncryption> random_crypt)
: client_id(client_id),
std::shared_ptr<Server> server)
: server(server),
client_id(client_id),
draw_index(1),
card_ref_base(this->client_id << 8),
shuffle_enabled(true),
loop_enabled(true),
random_crypt(random_crypt) {
loop_enabled(true) {
for (size_t z = 0; z < card_ids.size(); z++) {
auto& e = this->entries[z];
e.card_id = card_ids[z];
@@ -92,11 +96,13 @@ public:
void restart();
void shuffle();
void do_mulligan();
void do_mulligan(bool is_nte);
void print(FILE* stream, std::shared_ptr<const CardIndex> card_index = nullptr) const;
private:
std::weak_ptr<Server> server;
struct CardEntry {
uint16_t card_id;
uint8_t deck_index;
@@ -109,8 +115,6 @@ private:
bool loop_enabled;
parray<CardEntry, 31> entries;
parray<uint16_t, 31> card_refs;
std::shared_ptr<PSOLFGEncryption> random_crypt;
};
} // namespace Episode3
+33 -2
View File
@@ -43,7 +43,7 @@ void MapAndRulesState::clear() {
this->num_team0_players = 0;
this->unused2 = 0;
this->start_facing_directions = 0;
this->unused3 = 0;
this->unknown_a3 = 0;
this->map_number = 0;
this->unused4 = 0;
this->rules.clear();
@@ -68,6 +68,37 @@ void MapAndRulesState::clear_occupied_bit_for_tile(uint8_t x, uint8_t y) {
this->map.tiles[y][x] &= 0xEF;
}
MapAndRulesStateTrial::MapAndRulesStateTrial(const MapAndRulesState& state)
: map(state.map),
num_players(state.num_players),
unused1(state.unused1),
environment_number(state.environment_number),
num_players_per_team(state.num_players_per_team),
num_team0_players(state.num_team0_players),
unused2(state.unused2),
unused5(state.start_facing_directions),
unknown_a3(state.unknown_a3),
map_number(state.map_number),
unused4(state.unused4),
rules(state.rules) {}
MapAndRulesStateTrial::operator MapAndRulesState() const {
MapAndRulesState ret;
ret.map = this->map;
ret.num_players = this->num_players;
ret.unused1 = this->unused1;
ret.environment_number = this->environment_number;
ret.num_players_per_team = this->num_players_per_team;
ret.num_team0_players = this->num_team0_players;
ret.unused2 = this->unused2;
ret.start_facing_directions = this->unused5;
ret.unknown_a3 = this->unknown_a3;
ret.map_number = this->map_number;
ret.unused4 = this->unused4;
ret.rules = this->rules;
return ret;
}
OverlayState::OverlayState() {
this->clear();
}
@@ -78,7 +109,7 @@ void OverlayState::clear() {
}
this->unused1.clear(0);
this->unused2.clear(0);
this->unused3.clear(0);
this->trap_card_ids_nte.clear(0);
}
} // namespace Episode3
+42 -20
View File
@@ -10,30 +10,32 @@
namespace Episode3 {
struct MapState {
le_uint16_t width;
le_uint16_t height;
parray<parray<uint8_t, 0x10>, 0x10> tiles;
parray<parray<uint8_t, 6>, 2> start_tile_definitions;
/* 0000 */ le_uint16_t width = 0;
/* 0002 */ le_uint16_t height = 0;
/* 0004 */ parray<parray<uint8_t, 0x10>, 0x10> tiles;
/* 0104 */ parray<parray<uint8_t, 6>, 2> start_tile_definitions;
/* 0110 */
MapState();
void clear();
void print(FILE* stream) const;
} __attribute__((packed));
} __packed_ws__(MapState, 0x110);
struct MapAndRulesState {
MapState map;
uint8_t num_players;
uint8_t unused1;
uint8_t environment_number;
uint8_t num_players_per_team;
uint8_t num_team0_players;
uint8_t unused2;
le_uint16_t start_facing_directions;
uint32_t unused3;
le_uint32_t map_number;
uint32_t unused4;
Rules rules;
/* 0000 */ MapState map;
/* 0110 */ uint8_t num_players = 0;
/* 0111 */ uint8_t unused1 = 0;
/* 0112 */ uint8_t environment_number = 0;
/* 0113 */ uint8_t num_players_per_team = 0;
/* 0114 */ uint8_t num_team0_players = 0;
/* 0115 */ uint8_t unused2 = 0;
/* 0116 */ le_uint16_t start_facing_directions = 0;
/* 0118 */ be_uint32_t unknown_a3 = 0;
/* 011C */ le_uint32_t map_number = 0;
/* 0120 */ be_uint32_t unused4 = 0;
/* 0124 */ Rules rules;
/* 0138 */
MapAndRulesState();
void clear();
@@ -43,16 +45,36 @@ struct MapAndRulesState {
void set_occupied_bit_for_tile(uint8_t x, uint8_t y);
void clear_occupied_bit_for_tile(uint8_t x, uint8_t y);
} __attribute__((packed));
} __packed_ws__(MapAndRulesState, 0x138);
struct MapAndRulesStateTrial {
/* 0000 */ MapState map;
/* 0110 */ uint8_t num_players = 0;
/* 0111 */ uint8_t unused1 = 0;
/* 0112 */ uint8_t environment_number = 0;
/* 0113 */ uint8_t num_players_per_team = 0;
/* 0114 */ uint8_t num_team0_players = 0;
/* 0115 */ uint8_t unused2 = 0;
/* 0116 */ le_uint16_t unused5 = 0;
/* 0118 */ be_uint32_t unknown_a3 = 0;
/* 011C */ le_uint32_t map_number = 0;
/* 0120 */ be_uint32_t unused4 = 0;
/* 0124 */ RulesTrial rules;
/* 0130 */
MapAndRulesStateTrial() = default;
MapAndRulesStateTrial(const MapAndRulesState& state);
operator MapAndRulesState() const;
} __packed_ws__(MapAndRulesStateTrial, 0x130);
struct OverlayState {
parray<parray<uint8_t, 0x10>, 0x10> tiles;
parray<le_uint32_t, 5> unused1;
parray<le_uint32_t, 0x10> unused2;
parray<le_uint16_t, 0x10> unused3;
parray<le_uint16_t, 0x10> trap_card_ids_nte; // Unused on non-NTE
OverlayState();
void clear();
} __attribute__((packed));
} __packed_ws__(OverlayState, 0x174);
} // namespace Episode3
File diff suppressed because it is too large Load Diff
+20 -22
View File
@@ -20,6 +20,7 @@ enum AssistFlag : uint32_t {
// be bits used only by the client which are not documented here.
// clang-format off
NONE = 0x0000,
READY_TO_END_PHASE = 0x0001,
DICE_WERE_EXCHANGED = 0x0002,
HAS_WON_BATTLE = 0x0004,
@@ -52,14 +53,14 @@ public:
uint16_t card_ref_for_hand_index(size_t hand_index) const;
int16_t compute_attack_or_defense_atk_costs(const ActionState& pa) const;
void compute_total_set_cards_cost();
size_t count_set_cards_for_env_stats_nte() const;
size_t count_set_cards() const;
size_t count_set_refs() const;
void discard_all_assist_cards_from_hand();
void discard_all_attack_action_cards_from_hand();
void discard_all_item_and_creature_cards_from_hand();
void discard_and_redraw_hand();
bool discard_card_or_add_to_draw_pile(
uint16_t card_ref, bool add_to_draw_pile);
bool discard_card_or_add_to_draw_pile(uint16_t card_ref, bool add_to_draw_pile);
void discard_random_hand_card();
bool discard_ref_from_hand(uint16_t card_ref);
void discard_set_assist_card();
@@ -76,8 +77,7 @@ public:
const Location& loc,
uint8_t target_team_id) const;
uint8_t get_atk_points() const;
void get_short_status_for_card_index_in_hand(
size_t hand_index, CardShortStatus* stat) const;
void get_short_status_for_card_index_in_hand(size_t hand_index, CardShortStatus* stat) const;
std::shared_ptr<DeckState> get_deck();
uint8_t get_def_points() const;
uint8_t get_dice_result(size_t which) const;
@@ -96,8 +96,8 @@ public:
bool is_mulligan_allowed() const;
bool is_team_turn() const;
void log_discard(uint16_t card_ref, uint16_t reason);
bool move_card_to_location_by_card_index(
size_t card_index, const Location& new_loc);
uint16_t pop_from_discard_log(uint16_t reason);
bool move_card_to_location_by_card_index(size_t card_index, const Location& new_loc);
void move_null_hand_refs_to_end();
void on_cards_destroyed();
void replace_all_set_assists_with_random_assists();
@@ -115,42 +115,40 @@ public:
uint8_t assist_target_client_id,
bool skip_error_checks_and_atk_sub);
void set_initial_location();
void set_map_occupied_bit_for_card_on_warp_tile(
std::shared_ptr<const Card> card);
void set_map_occupied_bit_for_card_on_warp_tile(std::shared_ptr<const Card> card);
void set_map_occupied_bits_for_sc_and_creatures();
void subtract_def_points(uint8_t cost);
bool subtract_or_check_atk_or_def_points_for_action(
const ActionState& pa, bool deduct_points);
bool subtract_or_check_atk_or_def_points_for_action(const ActionState& pa, bool deduct_points);
void subtract_atk_points(uint8_t cost);
G_UpdateHand_GC_Ep3_6xB4x02 prepare_6xB4x02() const;
void update_hand_and_equip_state_and_send_6xB4x02_if_needed(
bool always_send = false);
G_UpdateHand_Ep3_6xB4x02 prepare_6xB4x02() const;
void update_hand_and_equip_state_and_send_6xB4x02_if_needed(bool always_send = false);
void set_random_assist_card_from_hand_for_free();
G_UpdateShortStatuses_GC_Ep3_6xB4x04 prepare_6xB4x04() const;
G_UpdateShortStatuses_Ep3_6xB4x04 prepare_6xB4x04() const;
void send_6xB4x04_if_needed(bool always_send = false);
std::vector<uint16_t> get_card_refs_within_range_from_all_players(
const parray<uint8_t, 9 * 9>& range,
const Location& loc,
CardType type) const;
void unknown_80239460();
void unknown_802394C4();
void unknown_80239528();
void draw_phase_before();
void action_phase_before();
void move_phase_before();
void handle_before_turn_assist_effects();
int16_t get_assist_turns_remaining();
bool set_action_cards_for_action_state(const ActionState& pa);
void unknown_8023C174();
void handle_homesick_assist_effect(std::shared_ptr<Card> card);
void dice_phase_before();
void handle_homesick_assist_effect_from_bomb(std::shared_ptr<Card> card);
void apply_main_die_assist_effects(uint8_t* die_value) const;
void roll_main_dice();
void roll_main_dice_or_apply_after_effects();
void unknown_8023C110();
void compute_team_dice_boost_after_draw_phase();
void compute_team_dice_bonus_after_draw_phase();
void send_6xB4x0A_for_set_card(size_t set_index);
private:
std::weak_ptr<Server> w_server;
public:
std::shared_ptr<Card> sc_card;
std::shared_ptr<Card> set_cards[8];
bcarray<std::shared_ptr<Card>, 8> set_cards;
uint8_t client_id;
uint16_t num_mulligans_allowed;
CardType sc_card_type;
+183 -88
View File
@@ -6,22 +6,6 @@ using namespace std;
namespace Episode3 {
template <size_t Count>
std::string string_for_refs(const parray<le_uint16_t, Count>& card_refs) {
string ret = "[";
for (size_t z = 0; z < Count; z++) {
if (card_refs[z] != 0xFFFF) {
ret += string_printf("%zu:@$%04X ", z, card_refs[z].load());
}
}
if (!ret.empty()) {
ret.back() = ']'; // Replace the ' ' from the last added item
} else {
ret.push_back(']');
}
return ret;
}
Condition::Condition() {
this->clear();
}
@@ -77,20 +61,22 @@ void Condition::clear_FF() {
this->unknown_a8 = 0xFF;
}
std::string Condition::str() const {
std::string Condition::str(shared_ptr<const Server> s) const {
auto card_ref_str = s->debug_str_for_card_ref(this->card_ref);
auto giver_ref_str = s->debug_str_for_card_ref(this->condition_giver_card_ref);
return string_printf(
"Condition[type=%s, turns=%hhu, a_arg=%hhd, dice=%hhu, flags=%02hhX, "
"def_eff_index=%hhu, ref=@%04hX, value=%hd, giver_ref=@%04hX "
"def_eff_index=%hhu, ref=%s, value=%hd, giver_ref=%s "
"percent=%hhu value8=%hd order=%hu a8=%hu]",
name_for_condition_type(this->type),
name_for_enum(this->type),
this->remaining_turns,
this->a_arg_value,
this->dice_roll_value,
this->flags,
this->card_definition_effect_index,
this->card_ref.load(),
card_ref_str.c_str(),
this->value.load(),
this->condition_giver_card_ref.load(),
giver_ref_str.c_str(),
this->random_percent,
this->value8,
this->order,
@@ -114,13 +100,15 @@ void EffectResult::clear() {
this->dice_roll_value = 0;
}
std::string EffectResult::str() const {
std::string EffectResult::str(shared_ptr<const Server> s) const {
string attacker_ref_str = s->debug_str_for_card_ref(this->attacker_card_ref);
string target_ref_str = s->debug_str_for_card_ref(this->target_card_ref);
return string_printf(
"EffectResult[att_ref=@%04hX, target_ref=@%04hX, value=%hhd, "
"EffectResult[att_ref=%s, target_ref=%s, value=%hhd, "
"cur_hp=%hhd, ap=%hhd, tp=%hhd, flags=%02hhX, op=%hhd, "
"cond_index=%hhu, dice=%hhu]",
this->attacker_card_ref.load(),
this->target_card_ref.load(),
attacker_ref_str.c_str(),
target_ref_str.c_str(),
this->value,
this->current_hp,
this->ap,
@@ -148,12 +136,13 @@ bool CardShortStatus::operator!=(const CardShortStatus& other) const {
return !this->operator==(other);
}
std::string CardShortStatus::str() const {
std::string CardShortStatus::str(shared_ptr<const Server> s) const {
string loc_s = this->loc.str();
string ref_str = s->debug_str_for_card_ref(this->card_ref);
return string_printf(
"CardShortStatus[ref=@%04hX, cur_hp=%hd, flags=%08" PRIX32 ", loc=%s, "
"CardShortStatus[ref=%s, cur_hp=%hd, flags=%08" PRIX32 ", loc=%s, "
"u1=%04hX, max_hp=%hhd, u2=%hhu]",
this->card_ref.load(),
ref_str.c_str(),
this->current_hp.load(),
this->card_flags.load(),
loc_s.c_str(),
@@ -195,23 +184,27 @@ void ActionState::clear() {
this->original_attacker_card_ref = 0xFFFF;
this->target_card_refs.clear(0xFFFF);
this->action_card_refs.clear(0xFFFF);
this->unused2 = 0xFFFF;
}
std::string ActionState::str() const {
string target_refs_s = string_for_refs(this->target_card_refs);
string action_refs_s = string_for_refs(this->action_card_refs);
std::string ActionState::str(shared_ptr<const Server> s) const {
string attacker_ref_s = s->debug_str_for_card_ref(this->attacker_card_ref);
string defense_ref_s = s->debug_str_for_card_ref(this->defense_card_ref);
string original_attacker_ref_s = s->debug_str_for_card_ref(this->original_attacker_card_ref);
string target_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
string action_refs_s = s->debug_str_for_card_refs(this->action_card_refs);
return string_printf(
"ActionState[client=%hu, u=%hhu, facing=%s, attacker_ref=@%04hX, "
"def_ref=@%04hX, target_refs=%s, action_refs=%s, "
"orig_attacker_ref=@%04hX]",
"ActionState[client=%hu, u=%hhu, facing=%s, attacker_ref=%s, "
"def_ref=%s, target_refs=%s, action_refs=%s, "
"orig_attacker_ref=%s]",
this->client_id.load(),
this->unused,
name_for_direction(this->facing_direction),
this->attacker_card_ref.load(),
this->defense_card_ref.load(),
name_for_enum(this->facing_direction),
attacker_ref_s.c_str(),
defense_ref_s.c_str(),
target_refs_s.c_str(),
action_refs_s.c_str(),
this->original_attacker_card_ref.load());
original_attacker_ref_s.c_str());
}
ActionChain::ActionChain() {
@@ -234,8 +227,8 @@ bool ActionChain::operator==(const ActionChain& other) const {
(this->damage_multiplier == other.damage_multiplier) &&
(this->attack_number == other.attack_number) &&
(this->tp_effect_bonus == other.tp_effect_bonus) &&
(this->unused1 == other.unused1) &&
(this->unused2 == other.unused2) &&
(this->physical_attack_bonus_nte == other.physical_attack_bonus_nte) &&
(this->tech_attack_bonus_nte == other.tech_attack_bonus_nte) &&
(this->card_ap == other.card_ap) &&
(this->card_tp == other.card_tp) &&
(this->flags == other.flags) &&
@@ -245,34 +238,35 @@ bool ActionChain::operator!=(const ActionChain& other) const {
return !this->operator==(other);
}
std::string ActionChain::str() const {
string attack_action_card_refs_s = string_for_refs(this->attack_action_card_refs);
string target_card_refs_s = string_for_refs(this->target_card_refs);
std::string ActionChain::str(shared_ptr<const Server> s) const {
string acting_card_ref_s = s->debug_str_for_card_ref(this->acting_card_ref);
string unknown_card_ref_a3_s = s->debug_str_for_card_ref(this->unknown_card_ref_a3);
string attack_action_card_refs_s = s->debug_str_for_card_refs(this->attack_action_card_refs);
string target_card_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
return string_printf(
"ActionChain[eff_ap=%hhd, eff_tp=%hhd, ap_bonus=%hhd, damage=%hhd, "
"acting_ref=@%04hX, unknown_ref_a3=@%04hX, "
"attack_action_refs=%s, attack_action_ref_count=%hhu, "
"medium=%s, target_ref_count=%hhu, subphase=%s, "
"strikes=%hhu, damage_mult=%hhd, attack_num=%hhu, "
"tp_bonus=%hhd, u1=%hhu, u2=%hhu, card_ap=%hhd, "
"acting_ref=%s, unknown_ref_a3=%s, attack_action_refs=%s, "
"attack_action_ref_count=%hhu, medium=%s, target_ref_count=%hhu, "
"subphase=%s, strikes=%hhu, damage_mult=%hhd, attack_num=%hhu, "
"tp_bonus=%hhd, phys_bonus_nte=%hhu, tech_bonus_nte=%hhu, card_ap=%hhd, "
"card_tp=%hhd, flags=%08" PRIX32 ", target_refs=%s]",
this->effective_ap,
this->effective_tp,
this->ap_effect_bonus,
this->damage,
this->acting_card_ref.load(),
this->unknown_card_ref_a3.load(),
acting_card_ref_s.c_str(),
unknown_card_ref_a3_s.c_str(),
attack_action_card_refs_s.c_str(),
this->attack_action_card_ref_count,
name_for_attack_medium(this->attack_medium),
name_for_enum(this->attack_medium),
this->target_card_ref_count,
name_for_action_subphase(this->action_subphase),
name_for_enum(this->action_subphase),
this->strike_count,
this->damage_multiplier,
this->attack_number,
this->tp_effect_bonus,
this->unused1,
this->unused2,
this->physical_attack_bonus_nte,
this->tech_attack_bonus_nte,
this->card_ap,
this->card_tp,
this->flags.load(),
@@ -294,8 +288,8 @@ void ActionChain::clear() {
this->damage_multiplier = 1;
this->attack_number = 0xFF;
this->tp_effect_bonus = 0;
this->unused1 = 0;
this->unused2 = 0;
this->physical_attack_bonus_nte = 0;
this->tech_attack_bonus_nte = 0;
this->card_ap = 0;
this->card_tp = 0;
this->flags = 0;
@@ -319,8 +313,8 @@ void ActionChain::clear_FF() {
this->damage_multiplier = -1;
this->attack_number = 0xFF;
this->tp_effect_bonus = -1;
this->unused1 = 0xFF;
this->unused2 = 0xFF;
this->physical_attack_bonus_nte = 0xFF;
this->tech_attack_bonus_nte = 0xFF;
this->card_ap = -1;
this->card_tp = -1;
this->flags = 0xFFFFFFFF;
@@ -338,17 +332,17 @@ bool ActionChainWithConds::operator!=(const ActionChainWithConds& other) const {
return !this->operator==(other);
}
std::string ActionChainWithConds::str() const {
std::string ActionChainWithConds::str(shared_ptr<const Server> s) const {
string ret = "ActionChainWithConds[chain=";
ret += this->chain.str();
ret += this->chain.str(s);
ret += ", conds=[";
for (size_t z = 0; z < this->conditions.size(); z++) {
if (this->conditions[z].type != ConditionType::NONE) {
if (ret.back() != '=') {
if (ret.back() != '[') {
ret += ", ";
}
ret += string_printf("%zu:", z);
ret += this->conditions[z].str();
ret += this->conditions[z].str(s);
}
}
ret += "]]";
@@ -393,8 +387,8 @@ void ActionChainWithConds::reset() {
this->chain.effective_tp = 0;
this->chain.ap_effect_bonus = 0;
this->chain.tp_effect_bonus = 0;
this->chain.unused1 = 0;
this->chain.unused2 = 0;
this->chain.physical_attack_bonus_nte = 0;
this->chain.tech_attack_bonus_nte = 0;
this->chain.damage = 0;
this->chain.strike_count = 1;
this->chain.damage_multiplier = 1;
@@ -439,7 +433,7 @@ void ActionChainWithConds::compute_attack_medium(shared_ptr<Server> server) {
if (!ce) {
continue;
}
if (card_class_is_tech_like(ce->def.card_class())) {
if (card_class_is_tech_like(ce->def.card_class(), server->options.is_nte())) {
this->chain.attack_medium = AttackMedium::TECH;
}
}
@@ -481,6 +475,85 @@ bool ActionChainWithConds::can_apply_attack() const {
return this->check_flag(4) ? false : (this->chain.target_card_ref_count != 0);
}
uint8_t ActionChainWithConds::get_adjusted_move_ability_nte(uint8_t ability) const {
for (size_t z = 0; z < this->conditions.size(); z++) {
const auto& cond = this->conditions[z];
switch (cond.type) {
case ConditionType::IMMOBILE:
case ConditionType::FREEZE:
ability = 0;
break;
case ConditionType::SET_MV_COST_TO_0:
ability = 99;
break;
case ConditionType::ADD_1_TO_MV_COST:
ability--;
break;
case ConditionType::SCALE_MV_COST:
if (cond.value == 0) {
ability = 99;
} else {
ability /= cond.value;
}
break;
default:
break;
}
}
return ability;
}
ActionChainWithCondsTrial::ActionChainWithCondsTrial(const ActionChainWithConds& src)
: effective_ap(src.chain.effective_ap),
effective_tp(src.chain.effective_tp),
ap_effect_bonus(src.chain.ap_effect_bonus),
damage(src.chain.damage),
acting_card_ref(src.chain.acting_card_ref),
unknown_card_ref_a3(src.chain.unknown_card_ref_a3),
attack_action_card_refs(src.chain.attack_action_card_refs),
attack_action_card_ref_count(src.chain.attack_action_card_ref_count),
attack_medium(src.chain.attack_medium),
target_card_ref_count(src.chain.target_card_ref_count),
action_subphase(src.chain.action_subphase),
strike_count(src.chain.strike_count),
damage_multiplier(src.chain.damage_multiplier),
attack_number(src.chain.attack_number),
tp_effect_bonus(src.chain.tp_effect_bonus),
physical_attack_bonus_nte(src.chain.physical_attack_bonus_nte),
tech_attack_bonus_nte(src.chain.tech_attack_bonus_nte),
card_ap(src.chain.card_ap),
card_tp(src.chain.card_tp),
flags(src.chain.flags),
conditions(src.conditions),
target_card_refs(src.chain.target_card_refs) {}
ActionChainWithCondsTrial::operator ActionChainWithConds() const {
ActionChainWithConds ret;
ret.chain.effective_ap = this->effective_ap;
ret.chain.effective_tp = this->effective_tp;
ret.chain.ap_effect_bonus = this->ap_effect_bonus;
ret.chain.damage = this->damage;
ret.chain.acting_card_ref = this->acting_card_ref;
ret.chain.unknown_card_ref_a3 = this->unknown_card_ref_a3;
ret.chain.attack_action_card_refs = this->attack_action_card_refs;
ret.chain.attack_action_card_ref_count = this->attack_action_card_ref_count;
ret.chain.attack_medium = this->attack_medium;
ret.chain.target_card_ref_count = this->target_card_ref_count;
ret.chain.action_subphase = this->action_subphase;
ret.chain.strike_count = this->strike_count;
ret.chain.damage_multiplier = this->damage_multiplier;
ret.chain.attack_number = this->attack_number;
ret.chain.tp_effect_bonus = this->tp_effect_bonus;
ret.chain.physical_attack_bonus_nte = this->physical_attack_bonus_nte;
ret.chain.tech_attack_bonus_nte = this->tech_attack_bonus_nte;
ret.chain.card_ap = this->card_ap;
ret.chain.card_tp = this->card_tp;
ret.chain.flags = this->flags;
ret.chain.target_card_refs = this->target_card_refs;
ret.conditions = this->conditions;
return ret;
}
ActionMetadata::ActionMetadata() {
this->clear();
}
@@ -502,19 +575,20 @@ bool ActionMetadata::operator!=(const ActionMetadata& other) const {
return !this->operator==(other);
}
std::string ActionMetadata::str() const {
string target_card_refs_s = string_for_refs(this->target_card_refs);
string defense_card_refs_s = string_for_refs(this->defense_card_refs);
string original_attacker_card_refs_s = string_for_refs(this->original_attacker_card_refs);
std::string ActionMetadata::str(shared_ptr<const Server> s) const {
string card_ref_s = s->debug_str_for_card_ref(this->card_ref);
string target_card_refs_s = s->debug_str_for_card_refs(this->target_card_refs);
string defense_card_refs_s = s->debug_str_for_card_refs(this->defense_card_refs);
string original_attacker_card_refs_s = s->debug_str_for_card_refs(this->original_attacker_card_refs);
return string_printf(
"ActionMetadata[ref=@%04hX, target_ref_count=%hhu, def_ref_count=%hhu, "
"ActionMetadata[ref=%s, target_ref_count=%hhu, def_ref_count=%hhu, "
"subphase=%s, def_power=%hhd, def_bonus=%hhd, "
"att_bonus=%hhd, flags=%08" PRIX32 ", target_refs=%s, "
"defense_refs=%s, original_attacker_refs=%s]",
this->card_ref.load(),
card_ref_s.c_str(),
this->target_card_ref_count,
this->defense_card_ref_count,
name_for_action_subphase(this->action_subphase),
name_for_enum(this->action_subphase),
this->defense_power,
this->defense_bonus,
this->attack_bonus,
@@ -531,6 +605,8 @@ void ActionMetadata::clear() {
this->action_subphase = ActionSubphase::INVALID_FF;
this->defense_power = 0;
this->defense_bonus = 0;
// TODO: Ep3 NTE doesn't set attack_bonus to zero here. Is the field just
// unused in NTE?
this->attack_bonus = 0;
this->flags = 0;
this->target_card_refs.clear(0xFFFF);
@@ -598,20 +674,22 @@ HandAndEquipState::HandAndEquipState() {
this->clear();
}
std::string HandAndEquipState::str() const {
string hand_card_refs_s = string_for_refs(this->hand_card_refs);
string set_card_refs_s = string_for_refs(this->set_card_refs);
string hand_card_refs2_s = string_for_refs(this->hand_card_refs2);
string set_card_refs2_s = string_for_refs(this->set_card_refs2);
std::string HandAndEquipState::str(shared_ptr<const Server> s) const {
string assist_card_ref_s = s->debug_str_for_card_ref(this->assist_card_ref);
string assist_card_ref2_s = s->debug_str_for_card_ref(this->assist_card_ref2);
string assist_card_id_s = s->debug_str_for_card_id(this->assist_card_id);
string sc_card_ref_s = s->debug_str_for_card_ref(this->sc_card_ref);
string hand_card_refs_s = s->debug_str_for_card_refs(this->hand_card_refs);
string set_card_refs_s = s->debug_str_for_card_refs(this->set_card_refs);
string hand_card_refs2_s = s->debug_str_for_card_refs(this->hand_card_refs2);
string set_card_refs2_s = s->debug_str_for_card_refs(this->set_card_refs2);
return string_printf(
"HandAndEquipState[dice=[%hhu, %hhu], atk=%hhu, def=%hhu, atk2=%hhu, "
"a1=%hhu, total_set_cost=%hhu, is_cpu=%hhu, "
"assist_flags=%08" PRIX32 ", hand_refs=%s, "
"assist_ref=@%04hX, set_refs=%s, sc_ref=@%04hX, "
"hand_refs2=%s, set_refs2=%s, assist_ref2=@%04hX, "
"assist_set_num=%hu, assist_card_id=#%04hX, "
"assist_turns=%hhu, assit_dely=%hhu, atk_bonus=%hhu, "
"def_bonus=%hhu, u2=[%hhu, %hhu]]",
"a1=%hhu, total_set_cost=%hhu, is_cpu=%hhu, assist_flags=%08" PRIX32 ", "
"hand_refs=%s, assist_ref=%s, set_refs=%s, sc_ref=%s, hand_refs2=%s, "
"set_refs2=%s, assist_ref2=%s, assist_set_num=%hu, assist_card_id=%s, "
"assist_turns=%hhu, assist_delay=%hhu, atk_bonus=%hhu, def_bonus=%hhu, "
"u2=[%hhu, %hhu]]",
this->dice_results[0],
this->dice_results[1],
this->atk_points,
@@ -622,14 +700,14 @@ std::string HandAndEquipState::str() const {
this->is_cpu_player,
this->assist_flags.load(),
hand_card_refs_s.c_str(),
this->assist_card_ref.load(),
assist_card_ref_s.c_str(),
set_card_refs_s.c_str(),
this->sc_card_ref.load(),
sc_card_ref_s.c_str(),
hand_card_refs2_s.c_str(),
set_card_refs2_s.c_str(),
this->assist_card_ref2.load(),
assist_card_ref2_s.c_str(),
this->assist_card_set_number.load(),
this->assist_card_id.load(),
assist_card_id_s.c_str(),
this->assist_remaining_turns,
this->assist_delay_turns,
this->atk_bonuses,
@@ -759,6 +837,23 @@ const char* PlayerBattleStats::name_for_rank(uint8_t rank) {
return RANK_NAMES[rank];
}
PlayerBattleStatsTrial::PlayerBattleStatsTrial(const PlayerBattleStats& data)
: damage_given(data.damage_given.load()),
damage_taken(data.damage_taken.load()),
num_opponent_cards_destroyed(data.num_opponent_cards_destroyed.load()),
num_owned_cards_destroyed(data.num_owned_cards_destroyed.load()),
total_move_distance(data.total_move_distance.load()) {}
PlayerBattleStatsTrial::operator PlayerBattleStats() const {
PlayerBattleStats ret;
ret.damage_given = this->damage_given.load();
ret.damage_taken = this->damage_taken.load();
ret.num_opponent_cards_destroyed = this->num_opponent_cards_destroyed.load();
ret.num_owned_cards_destroyed = this->num_owned_cards_destroyed.load();
ret.total_move_distance = this->total_move_distance.load();
return ret;
}
static bool is_card_within_range(
const parray<uint8_t, 9 * 9>& range,
const Location& anchor_loc,
+192 -133
View File
@@ -13,19 +13,20 @@ class Server;
class Card;
struct Condition {
ConditionType type;
uint8_t remaining_turns;
int8_t a_arg_value;
uint8_t dice_roll_value;
uint8_t flags;
uint8_t card_definition_effect_index;
le_uint16_t card_ref;
le_int16_t value;
le_uint16_t condition_giver_card_ref;
uint8_t random_percent;
int8_t value8;
uint8_t order;
uint8_t unknown_a8;
/* 00 */ ConditionType type;
/* 01 */ uint8_t remaining_turns;
/* 02 */ int8_t a_arg_value;
/* 03 */ uint8_t dice_roll_value;
/* 04 */ uint8_t flags;
/* 05 */ uint8_t card_definition_effect_index;
/* 06 */ le_uint16_t card_ref;
/* 08 */ le_int16_t value;
/* 0A */ le_uint16_t condition_giver_card_ref;
/* 0C */ uint8_t random_percent;
/* 0D */ int8_t value8;
/* 0E */ uint8_t order;
/* 0F */ uint8_t unknown_a8;
/* 10 */
Condition();
bool operator==(const Condition& other) const;
@@ -34,38 +35,40 @@ struct Condition {
void clear();
void clear_FF();
std::string str() const;
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(Condition, 0x10);
struct EffectResult {
le_uint16_t attacker_card_ref;
le_uint16_t target_card_ref;
int8_t value;
int8_t current_hp;
int8_t ap;
int8_t tp;
uint8_t flags;
int8_t operation; // May be a negative condition number
uint8_t condition_index;
uint8_t dice_roll_value;
/* 00 */ le_uint16_t attacker_card_ref;
/* 02 */ le_uint16_t target_card_ref;
/* 04 */ int8_t value;
/* 05 */ int8_t current_hp;
/* 06 */ int8_t ap;
/* 07 */ int8_t tp;
/* 08 */ uint8_t flags;
/* 09 */ int8_t operation; // May be a negative condition number
/* 0A */ uint8_t condition_index;
/* 0B */ uint8_t dice_roll_value;
/* 0C */
EffectResult();
bool operator==(const EffectResult& other) const;
bool operator!=(const EffectResult& other) const;
std::string str() const;
void clear();
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(EffectResult, 0x0C);
struct CardShortStatus {
le_uint16_t card_ref;
le_uint16_t current_hp;
le_uint32_t card_flags;
Location loc;
le_uint16_t unused1;
int8_t max_hp;
uint8_t unused2;
/* 00 */ le_uint16_t card_ref;
/* 02 */ le_uint16_t current_hp;
/* 04 */ le_uint32_t card_flags;
/* 08 */ Location loc;
/* 0C */ le_uint16_t unused1;
/* 0E */ int8_t max_hp;
/* 0F */ uint8_t unused2;
/* 10 */
CardShortStatus();
bool operator==(const CardShortStatus& other) const;
@@ -74,18 +77,20 @@ struct CardShortStatus {
void clear();
void clear_FF();
std::string str() const;
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(CardShortStatus, 0x10);
struct ActionState {
le_uint16_t client_id;
uint8_t unused;
Direction facing_direction;
le_uint16_t attacker_card_ref;
le_uint16_t defense_card_ref;
parray<le_uint16_t, 4 * 9> target_card_refs;
parray<le_uint16_t, 9> action_card_refs;
le_uint16_t original_attacker_card_ref;
/* 00 */ le_uint16_t client_id;
/* 02 */ uint8_t unused;
/* 03 */ Direction facing_direction;
/* 04 */ le_uint16_t attacker_card_ref;
/* 06 */ le_uint16_t defense_card_ref;
/* 08 */ parray<le_uint16_t, 4 * 9> target_card_refs;
/* 50 */ parray<le_uint16_t, 8> action_card_refs;
/* 60 */ le_uint16_t unused2;
/* 62 */ le_uint16_t original_attacker_card_ref;
/* 64 */
ActionState();
bool operator==(const ActionState& other) const;
@@ -93,31 +98,34 @@ struct ActionState {
void clear();
std::string str() const;
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(ActionState, 0x64);
struct ActionChain {
int8_t effective_ap;
int8_t effective_tp;
int8_t ap_effect_bonus;
int8_t damage;
le_uint16_t acting_card_ref;
le_uint16_t unknown_card_ref_a3;
parray<le_uint16_t, 8> attack_action_card_refs;
uint8_t attack_action_card_ref_count;
AttackMedium attack_medium;
uint8_t target_card_ref_count;
ActionSubphase action_subphase;
uint8_t strike_count;
int8_t damage_multiplier;
uint8_t attack_number;
int8_t tp_effect_bonus;
uint8_t unused1;
uint8_t unused2;
int8_t card_ap;
int8_t card_tp;
le_uint32_t flags;
parray<le_uint16_t, 4 * 9> target_card_refs;
// Note: Episode 3 Trial Edition has a different format for this structure.
// See ActionChainWithCondsTrial for details.
/* 00 */ int8_t effective_ap;
/* 01 */ int8_t effective_tp;
/* 02 */ int8_t ap_effect_bonus;
/* 03 */ int8_t damage;
/* 04 */ le_uint16_t acting_card_ref;
/* 06 */ le_uint16_t unknown_card_ref_a3;
/* 08 */ parray<le_uint16_t, 8> attack_action_card_refs;
/* 18 */ uint8_t attack_action_card_ref_count;
/* 19 */ AttackMedium attack_medium;
/* 1A */ uint8_t target_card_ref_count;
/* 1B */ ActionSubphase action_subphase;
/* 1C */ uint8_t strike_count;
/* 1D */ int8_t damage_multiplier;
/* 1E */ uint8_t attack_number;
/* 1F */ int8_t tp_effect_bonus;
/* 20 */ int8_t physical_attack_bonus_nte;
/* 21 */ int8_t tech_attack_bonus_nte;
/* 22 */ int8_t card_ap;
/* 23 */ int8_t card_tp;
/* 24 */ le_uint32_t flags;
/* 28 */ parray<le_uint16_t, 4 * 9> target_card_refs;
/* 70 */
ActionChain();
bool operator==(const ActionChain& other) const;
@@ -126,12 +134,13 @@ struct ActionChain {
void clear();
void clear_FF();
std::string str() const;
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(ActionChain, 0x70);
struct ActionChainWithConds {
ActionChain chain;
parray<Condition, 9> conditions;
/* 0000 */ ActionChain chain;
/* 0070 */ parray<Condition, 9> conditions;
/* 0100 */
ActionChainWithConds();
bool operator==(const ActionChainWithConds& other) const;
@@ -161,28 +170,61 @@ struct ActionChainWithConds {
void set_action_subphase_from_card(std::shared_ptr<const Card> card);
bool can_apply_attack() const;
std::string str() const;
} __attribute__((packed));
uint8_t get_adjusted_move_ability_nte(uint8_t ability) const;
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(ActionChainWithConds, 0x100);
struct ActionChainWithCondsTrial {
/* 0000 */ int8_t effective_ap;
/* 0001 */ int8_t effective_tp;
/* 0002 */ int8_t ap_effect_bonus;
/* 0003 */ int8_t damage;
/* 0004 */ le_uint16_t acting_card_ref;
/* 0006 */ le_uint16_t unknown_card_ref_a3;
/* 0008 */ parray<le_uint16_t, 8> attack_action_card_refs;
/* 0018 */ uint8_t attack_action_card_ref_count;
/* 0019 */ AttackMedium attack_medium;
/* 001A */ uint8_t target_card_ref_count;
/* 001B */ ActionSubphase action_subphase;
/* 001C */ uint8_t strike_count;
/* 001D */ int8_t damage_multiplier;
/* 001E */ uint8_t attack_number;
/* 001F */ int8_t tp_effect_bonus;
/* 0020 */ int8_t physical_attack_bonus_nte;
/* 0021 */ int8_t tech_attack_bonus_nte;
/* 0022 */ int8_t card_ap;
/* 0023 */ int8_t card_tp;
/* 0024 */ le_uint32_t flags;
// The only difference between this structure and ActionChainWithConds is that
// these two fields are in the opposite order.
/* 0028 */ parray<Condition, 9> conditions;
/* 00B8 */ parray<le_uint16_t, 4 * 9> target_card_refs;
/* 0100 */
ActionChainWithCondsTrial() = default;
ActionChainWithCondsTrial(const ActionChainWithConds& src);
operator ActionChainWithConds() const;
} __packed_ws__(ActionChainWithCondsTrial, 0x100);
struct ActionMetadata {
le_uint16_t card_ref;
uint8_t target_card_ref_count;
uint8_t defense_card_ref_count;
ActionSubphase action_subphase;
int8_t defense_power;
int8_t defense_bonus;
int8_t attack_bonus;
le_uint32_t flags;
parray<le_uint16_t, 4 * 9> target_card_refs;
parray<le_uint16_t, 8> defense_card_refs;
parray<le_uint16_t, 8> original_attacker_card_refs;
/* 00 */ le_uint16_t card_ref;
/* 02 */ uint8_t target_card_ref_count;
/* 03 */ uint8_t defense_card_ref_count;
/* 04 */ ActionSubphase action_subphase;
/* 05 */ int8_t defense_power;
/* 06 */ int8_t defense_bonus;
/* 07 */ int8_t attack_bonus;
/* 08 */ le_uint32_t flags;
/* 0C */ parray<le_uint16_t, 4 * 9> target_card_refs;
/* 54 */ parray<le_uint16_t, 8> defense_card_refs;
/* 64 */ parray<le_uint16_t, 8> original_attacker_card_refs;
/* 74 */
ActionMetadata();
bool operator==(const ActionMetadata& other) const;
bool operator!=(const ActionMetadata& other) const;
std::string str() const;
void clear();
void clear_FF();
@@ -197,31 +239,34 @@ struct ActionMetadata {
uint16_t defense_card_ref,
std::shared_ptr<Card> card,
uint16_t original_attacker_card_ref);
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(ActionMetadata, 0x74);
struct HandAndEquipState {
parray<uint8_t, 2> dice_results;
uint8_t atk_points;
uint8_t def_points;
uint8_t atk_points2; // TODO: rename this to something more appropriate
uint8_t unknown_a1;
uint8_t total_set_cards_cost;
uint8_t is_cpu_player;
le_uint32_t assist_flags;
parray<le_uint16_t, 6> hand_card_refs;
le_uint16_t assist_card_ref;
parray<le_uint16_t, 8> set_card_refs;
le_uint16_t sc_card_ref;
parray<le_uint16_t, 6> hand_card_refs2;
parray<le_uint16_t, 8> set_card_refs2;
le_uint16_t assist_card_ref2;
le_uint16_t assist_card_set_number;
le_uint16_t assist_card_id;
uint8_t assist_remaining_turns;
uint8_t assist_delay_turns;
uint8_t atk_bonuses;
uint8_t def_bonuses;
parray<uint8_t, 2> unused2;
/* 00 */ parray<uint8_t, 2> dice_results;
/* 02 */ uint8_t atk_points;
/* 03 */ uint8_t def_points;
/* 04 */ uint8_t atk_points2; // TODO: rename this to something more appropriate
/* 05 */ uint8_t unknown_a1;
/* 06 */ uint8_t total_set_cards_cost;
/* 07 */ uint8_t is_cpu_player;
/* 08 */ le_uint32_t assist_flags;
/* 0C */ parray<le_uint16_t, 6> hand_card_refs;
/* 18 */ le_uint16_t assist_card_ref;
/* 1A */ parray<le_uint16_t, 8> set_card_refs;
/* 2A */ le_uint16_t sc_card_ref;
/* 2C */ parray<le_uint16_t, 6> hand_card_refs2;
/* 38 */ parray<le_uint16_t, 8> set_card_refs2;
/* 48 */ le_uint16_t assist_card_ref2;
/* 4A */ le_uint16_t assist_card_set_number;
/* 4C */ le_uint16_t assist_card_id;
/* 4E */ uint8_t assist_remaining_turns;
/* 4F */ uint8_t assist_delay_turns;
/* 50 */ uint8_t atk_bonuses;
/* 51 */ uint8_t def_bonuses;
/* 52 */ parray<uint8_t, 2> unused2;
/* 54 */
HandAndEquipState();
bool operator==(const HandAndEquipState& other) const;
@@ -230,30 +275,31 @@ struct HandAndEquipState {
void clear();
void clear_FF();
std::string str() const;
} __attribute__((packed));
std::string str(std::shared_ptr<const Server> s) const;
} __packed_ws__(HandAndEquipState, 0x54);
struct PlayerBattleStats {
le_uint16_t damage_given;
le_uint16_t damage_taken;
le_uint16_t num_opponent_cards_destroyed;
le_uint16_t num_owned_cards_destroyed;
le_uint16_t total_move_distance;
le_uint16_t num_cards_set;
le_uint16_t num_item_or_creature_cards_set;
le_uint16_t num_attack_actions_set;
le_uint16_t num_tech_cards_set;
le_uint16_t num_assist_cards_set;
le_uint16_t defense_actions_set_on_self;
le_uint16_t defense_actions_set_on_ally;
le_uint16_t num_cards_drawn;
le_uint16_t max_attack_damage;
le_uint16_t max_attack_combo_size;
le_uint16_t num_attacks_given;
le_uint16_t num_attacks_taken;
le_uint16_t sc_damage_taken;
le_uint16_t action_card_negated_damage;
le_uint16_t unused;
/* 00 */ le_uint16_t damage_given;
/* 02 */ le_uint16_t damage_taken;
/* 04 */ le_uint16_t num_opponent_cards_destroyed;
/* 06 */ le_uint16_t num_owned_cards_destroyed;
/* 08 */ le_uint16_t total_move_distance;
/* 0A */ le_uint16_t num_cards_set;
/* 0C */ le_uint16_t num_item_or_creature_cards_set;
/* 0E */ le_uint16_t num_attack_actions_set;
/* 10 */ le_uint16_t num_tech_cards_set;
/* 12 */ le_uint16_t num_assist_cards_set;
/* 14 */ le_uint16_t defense_actions_set_on_self;
/* 16 */ le_uint16_t defense_actions_set_on_ally;
/* 18 */ le_uint16_t num_cards_drawn;
/* 1A */ le_uint16_t max_attack_damage;
/* 1C */ le_uint16_t max_attack_combo_size;
/* 1E */ le_uint16_t num_attacks_given;
/* 20 */ le_uint16_t num_attacks_taken;
/* 22 */ le_uint16_t sc_damage_taken;
/* 24 */ le_uint16_t action_card_negated_damage;
/* 26 */ le_uint16_t unused;
/* 28 */
PlayerBattleStats();
void clear();
@@ -264,7 +310,20 @@ struct PlayerBattleStats {
static uint8_t rank_for_score(float score);
static const char* name_for_rank(uint8_t rank);
} __attribute__((packed));
} __packed_ws__(PlayerBattleStats, 0x28);
struct PlayerBattleStatsTrial {
/* 00 */ le_uint32_t damage_given = 0;
/* 04 */ le_uint32_t damage_taken = 0;
/* 08 */ le_uint32_t num_opponent_cards_destroyed = 0;
/* 0C */ le_uint32_t num_owned_cards_destroyed = 0;
/* 10 */ le_uint32_t total_move_distance = 0;
/* 14 */
PlayerBattleStatsTrial() = default;
PlayerBattleStatsTrial(const PlayerBattleStats& data);
operator PlayerBattleStats() const;
} __packed_ws__(PlayerBattleStatsTrial, 0x14);
std::vector<uint16_t> get_card_refs_within_range(
const parray<uint8_t, 9 * 9>& range,
+270 -155
View File
@@ -1,5 +1,7 @@
#include "RulerServer.hh"
#include <optional>
#include "Server.hh"
using namespace std;
@@ -204,6 +206,8 @@ const ActionChainWithConds* RulerServer::action_chain_with_conds_for_card_ref(
uint16_t card_ref) const {
uint8_t client_id = client_id_for_card_ref(card_ref);
if (client_id != 0xFF) {
// There appears to be a bug in Trial Edition: the bound on this loop is
// 0x10, not 9.
for (size_t z = 0; z < 9; z++) {
const auto* chain = &this->set_card_action_chains[client_id]->at(z);
if (card_ref == chain->chain.acting_card_ref) {
@@ -235,19 +239,25 @@ bool RulerServer::card_has_pierce_or_rampage(
uint16_t action_card_ref,
uint8_t def_effect_index,
AttackMedium attack_medium) const {
auto short_statuses = (client_id != 0xFF) ? this->short_statuses[client_id] : nullptr;
auto short_statuses = (client_id < 4) ? this->short_statuses[client_id] : nullptr;
*out_has_rampage = false;
if (cond_type == ConditionType::NONE) {
return false;
bool ret;
bool is_nte = this->server()->options.is_nte();
if (is_nte) {
ret = true;
} else {
if (cond_type == ConditionType::NONE) {
return false;
}
ret = this->check_usability_or_apply_condition_for_card_refs(
action_card_ref,
attacker_card_ref,
// Original code omitted this null check and presumably could crash here
short_statuses ? short_statuses->at(0).card_ref.load() : 0xFFFF,
def_effect_index,
attack_medium);
}
bool ret = this->check_usability_or_apply_condition_for_card_refs(
action_card_ref,
attacker_card_ref,
// Original code omitted this null check and presumably could crash here
short_statuses ? short_statuses->at(0).card_ref.load() : 0xFFFF,
def_effect_index,
attack_medium);
switch (cond_type) {
case ConditionType::RAMPAGE:
@@ -280,7 +290,10 @@ bool RulerServer::card_has_pierce_or_rampage(
if (short_statuses) {
const auto& sc_status = short_statuses->at(0);
auto ce = this->definition_for_card_ref(sc_status.card_ref);
if (ce && (this->get_card_ref_max_hp(sc_status.card_ref) <= sc_status.current_hp * 2)) {
// This appears to be an NTE bug: Major Pierce doesn't work on Arkz SCs.
if (ce &&
(!is_nte || (ce->def.type == CardType::HUNTERS_SC)) &&
(this->get_card_ref_max_hp(sc_status.card_ref) <= sc_status.current_hp * 2)) {
return ret;
}
}
@@ -290,8 +303,7 @@ bool RulerServer::card_has_pierce_or_rampage(
}
}
bool RulerServer::attack_action_has_rampage_and_not_pierce(
const ActionState& pa, uint16_t card_ref) const {
bool RulerServer::attack_action_has_rampage_and_not_pierce(const ActionState& pa, uint16_t card_ref) const {
uint16_t orig_card_ref;
uint16_t effective_range_card_id;
TargetMode effective_target_mode;
@@ -365,15 +377,15 @@ bool RulerServer::attack_action_has_rampage_and_not_pierce(
return false;
}
bool RulerServer::attack_action_has_pierce_and_not_rampage(
const ActionState& pa, uint8_t client_id) {
if ((client_id_for_card_ref(pa.attacker_card_ref) == 0xFF) || (client_id == 0xFF)) {
bool RulerServer::attack_action_has_pierce_and_not_rampage(const ActionState& pa, uint8_t client_id) const {
if ((client_id_for_card_ref(pa.attacker_card_ref) == 0xFF) || (client_id >= 4)) {
return false;
}
bool is_nte = this->server()->options.is_nte();
auto attack_medium = this->get_attack_medium(pa);
auto stat = this->short_statuses[client_id];
if (!stat || !this->card_exists_by_status(stat->at(0)) || (stat->at(0).card_ref == 0xFFFF)) {
if (!stat || (!is_nte && !this->card_exists_by_status(stat->at(0))) || (stat->at(0).card_ref == 0xFFFF)) {
return false;
}
@@ -392,6 +404,33 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(
last_action_card_index = z;
}
auto check_chain = [&]() -> optional<bool> {
const auto* chain = this->action_chain_with_conds_for_card_ref(pa.attacker_card_ref);
if (chain) {
for (ssize_t cond_index = 8; cond_index >= 0; cond_index--) {
bool has_rampage = false;
if (this->card_has_pierce_or_rampage(
client_id, chain->conditions[cond_index].type, &has_rampage,
pa.attacker_card_ref, chain->conditions[cond_index].card_ref,
chain->conditions[cond_index].card_definition_effect_index,
attack_medium)) {
return true;
}
if (has_rampage) {
return false;
}
}
}
return nullopt;
};
if (is_nte) {
auto res = check_chain();
if (res.has_value()) {
return res.value();
}
}
for (; last_action_card_index >= 0; last_action_card_index--) {
auto ce = this->definition_for_card_ref(
pa.action_card_refs[last_action_card_index]);
@@ -418,20 +457,10 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(
}
}
const auto* chain = this->action_chain_with_conds_for_card_ref(pa.attacker_card_ref);
if (chain) {
for (ssize_t cond_index = 8; cond_index >= 0; cond_index--) {
bool has_rampage = false;
if (this->card_has_pierce_or_rampage(
client_id, chain->conditions[cond_index].type, &has_rampage,
pa.attacker_card_ref, chain->conditions[cond_index].card_ref,
chain->conditions[cond_index].card_definition_effect_index,
attack_medium)) {
return true;
}
if (has_rampage) {
return false;
}
if (!is_nte) {
auto res = check_chain();
if (res.has_value()) {
return res.value();
}
}
@@ -634,9 +663,11 @@ bool RulerServer::card_ref_has_free_maneuver(uint16_t card_ref) const {
}
bool RulerServer::card_ref_is_aerial(uint16_t card_ref) const {
const auto* stat = this->short_status_for_card_ref(card_ref);
if (!stat || !this->card_exists_by_status(*stat)) {
return false;
if (!this->server()->options.is_nte()) {
const auto* stat = this->short_status_for_card_ref(card_ref);
if (!stat || !this->card_exists_by_status(*stat)) {
return false;
}
}
uint8_t client_id = client_id_for_card_ref(card_ref);
@@ -791,10 +822,13 @@ bool RulerServer::check_pierce_and_rampage(
uint16_t action_card_ref,
uint8_t def_effect_index,
AttackMedium attack_medium) const {
bool is_nte = this->server()->options.is_nte();
// Note: NTE doesn't set this to zero; it apparently expects the caller to.
*out_has_pierce = false;
const auto* card_short_status = this->short_status_for_card_ref(card_ref);
if (cond_type == ConditionType::NONE) {
if (!is_nte && (cond_type == ConditionType::NONE)) {
return false;
}
@@ -816,8 +850,9 @@ bool RulerServer::check_pierce_and_rampage(
client_short_statuses = nullptr;
}
bool apply_check_result = this->check_usability_or_apply_condition_for_card_refs(
action_card_ref, attacker_card_ref, card_ref, def_effect_index, attack_medium);
bool apply_check_result = (is_nte ||
this->check_usability_or_apply_condition_for_card_refs(
action_card_ref, attacker_card_ref, card_ref, def_effect_index, attack_medium));
switch (cond_type) {
case ConditionType::PIERCE:
@@ -903,7 +938,9 @@ bool RulerServer::check_usability_or_condition_apply(
uint8_t def_effect_index,
bool is_item_usability_check,
AttackMedium attack_medium) const {
auto log = this->server()->log_stack(string_printf("check_usability_or_condition_apply(%02hhX, #%04hX, %02hhX, #%04hX, #%04hX, %02hhX, %s, %s): ", client_id1, card_id1, client_id2, card_id2, card_id3, def_effect_index, is_item_usability_check ? "true" : "false", name_for_attack_medium(attack_medium)));
auto s = this->server();
bool is_nte = s->options.is_nte();
auto log = s->log_stack(string_printf("check_usability_or_condition_apply(%02hhX, #%04hX, %02hhX, #%04hX, #%04hX, %02hhX, %s, %s): ", client_id1, card_id1, client_id2, card_id2, card_id3, def_effect_index, is_item_usability_check ? "true" : "false", name_for_enum(attack_medium)));
if (static_cast<uint8_t>(attack_medium) & 0x80) {
attack_medium = AttackMedium::UNKNOWN;
@@ -916,7 +953,7 @@ bool RulerServer::check_usability_or_condition_apply(
log.debug("ce1 missing");
return false;
}
if ((ce1->def.type == CardType::ITEM) && this->card_id_is_boss_sc(card_id2)) {
if (!is_nte && (ce1->def.type == CardType::ITEM) && this->card_id_is_boss_sc(card_id2)) {
log.debug("ce1 is item and card_id2 is boss sc");
return false;
}
@@ -931,7 +968,7 @@ bool RulerServer::check_usability_or_condition_apply(
}
criterion_code = ce1->def.effects[def_effect_index].apply_criterion;
}
log.debug("criterion_code=%s", name_for_criterion_code(criterion_code));
log.debug("criterion_code=%s", name_for_enum(criterion_code));
// For item usability checks, prevent criteria that depend on player
// positioning/team setup
@@ -952,8 +989,8 @@ bool RulerServer::check_usability_or_condition_apply(
// creature card is usable, the two client IDs should be the same or the
// second should not be given, so we'd return true if the criterion passes. If
// neither of these cases apply, we should return false as a failsafe even if
// the criterion passes.
bool ret = (!(def_effect_index & 0x80) || (client_id1 == client_id2)) || (client_id2 == 0xFF);
// the criterion passes. NTE did not have such a check.
bool ret = is_nte || (!(def_effect_index & 0x80) || (client_id1 == client_id2)) || (client_id2 == 0xFF);
switch (criterion_code) {
case CriterionCode::NONE:
return ret;
@@ -1361,6 +1398,7 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
cost_bias++;
}
bool is_nte = this->server()->options.is_nte();
if (pa.action_card_refs[0] == 0xFFFF) {
total_cost = cost_bias + 1;
} else {
@@ -1369,26 +1407,29 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
tech_cost_bias = -1;
}
auto s = this->server();
for (size_t z = 0; pa.action_card_refs[z] != 0xFFFF; z++) {
auto ce = this->definition_for_card_ref(pa.action_card_refs[z]);
if (has_mighty_knuckle || !ce || (ce->def.type != CardType::ACTION)) {
return 99;
}
total_cost += (ce->def.self_cost + cost_bias);
if (card_class_is_tech_like(ce->def.card_class())) {
if (card_class_is_tech_like(ce->def.card_class(), is_nte)) {
total_cost += tech_cost_bias;
}
total_ally_cost += ce->def.ally_cost;
if (this->card_has_mighty_knuckle(pa.action_card_refs[z])) {
has_mighty_knuckle = true;
}
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(pa.client_id);
for (size_t w = 0; w < num_assists; w++) {
auto assist_effect = this->assist_server->get_active_assist_by_index(w);
if (assist_effect == AssistEffect::INFLATION) {
assist_cost_bias++;
} else if (assist_effect == AssistEffect::DEFLATION) {
assist_cost_bias--;
if (!is_nte) {
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(pa.client_id);
for (size_t w = 0; w < num_assists; w++) {
auto assist_effect = this->assist_server->get_active_assist_by_index(w);
if (assist_effect == AssistEffect::INFLATION) {
assist_cost_bias++;
} else if (assist_effect == AssistEffect::DEFLATION) {
assist_cost_bias--;
}
}
}
}
@@ -1397,8 +1438,11 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(pa.client_id);
for (size_t w = 0; w < num_assists; w++) {
auto assist_effect = this->assist_server->get_active_assist_by_index(w);
if ((assist_effect == AssistEffect::BATTLE_ROYALE) &&
(pa.action_card_refs[0] == 0xFFFF)) {
if (is_nte && (assist_effect == AssistEffect::INFLATION)) {
assist_cost_bias++;
} else if (is_nte && (assist_effect == AssistEffect::DEFLATION)) {
assist_cost_bias--;
} else if ((assist_effect == AssistEffect::BATTLE_ROYALE) && (pa.action_card_refs[0] == 0xFFFF)) {
total_cost = 0;
final_cost = 0;
}
@@ -1406,7 +1450,9 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
if (has_mighty_knuckle) {
if (!allow_mighty_knuckle) {
final_cost = 0;
if (!is_nte) {
final_cost = 0;
}
} else {
final_cost = max<int16_t>(final_cost, this->hand_and_equip_states[pa.client_id]->atk_points);
}
@@ -1424,9 +1470,9 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
TargetMode* out_effective_target_mode,
uint16_t* out_orig_card_ref) const {
size_t z;
for (z = 0; (z < 9) && (pa.action_card_refs[z] != 0xFFFF); z++) {
for (z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
}
if (z >= 9) {
if (z >= 8) {
return false;
}
uint16_t card_ref = (z == 0) ? pa.attacker_card_ref : pa.action_card_refs[z - 1];
@@ -1449,9 +1495,11 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
auto target_mode = ce->def.target_mode;
if (this->card_ref_or_sc_has_fixed_range(pa.attacker_card_ref)) {
card_id = this->card_id_for_card_ref(pa.attacker_card_ref);
auto sc_ce = this->definition_for_card_id(card_id);
if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) {
target_mode = sc_ce->def.target_mode;
if (!this->server()->options.is_nte()) {
auto sc_ce = this->definition_for_card_id(card_id);
if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) {
target_mode = sc_ce->def.target_mode;
}
}
}
@@ -1474,8 +1522,7 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
return true;
}
size_t RulerServer::count_rampage_targets_for_attack(
const ActionState& pa, uint8_t client_id) const {
size_t RulerServer::count_rampage_targets_for_attack(const ActionState& pa, uint8_t client_id) const {
if (client_id == 0xFF) {
return 0;
}
@@ -1583,8 +1630,7 @@ bool RulerServer::defense_card_can_apply_to_attack(
return true;
}
bool RulerServer::defense_card_matches_any_attack_card_top_color(
const ActionState& pa) const {
bool RulerServer::defense_card_matches_any_attack_card_top_color(const ActionState& pa) const {
auto ce = this->definition_for_card_ref(pa.action_card_refs[0]);
if (!ce) {
throw runtime_error("defense card definition is missing");
@@ -1632,7 +1678,8 @@ int32_t RulerServer::error_code_for_client_setting_card(
return -0x76;
}
if (!this->is_card_ref_in_hand(card_ref)) {
bool is_nte = this->server()->options.is_nte();
if (!is_nte && !this->is_card_ref_in_hand(card_ref)) {
return -0x5E;
}
@@ -1672,8 +1719,8 @@ int32_t RulerServer::error_code_for_client_setting_card(
}
// Check for assists that can only be set on yourself
auto eff = assist_effect_number_for_card_id(ce->def.card_id);
if (((eff == AssistEffect::LEGACY) || (eff == AssistEffect::EXCHANGE)) &&
auto eff = assist_effect_number_for_card_id(ce->def.card_id, is_nte);
if (((eff == AssistEffect::LEGACY) || (!is_nte && (eff == AssistEffect::EXCHANGE))) &&
(assist_target_client_id != 0xFF) &&
(assist_target_client_id != client_id_for_card_ref(card_ref))) {
return -0x75;
@@ -1712,8 +1759,8 @@ int32_t RulerServer::error_code_for_client_setting_card(
if ((ce->def.type == CardType::ITEM) || (ce->def.type == CardType::CREATURE)) {
int16_t existing_fcs_cost = 0;
bool limit_summoning_by_count = this->find_condition_on_card_ref(
short_statuses->at(0).card_ref, ConditionType::FC_LIMIT_BY_COUNT);
bool limit_summoning_by_count = !is_nte &&
this->find_condition_on_card_ref(short_statuses->at(0).card_ref, ConditionType::FC_LIMIT_BY_COUNT);
for (size_t z = 7; z < 15; z++) {
const auto& this_status = short_statuses->at(z);
if ((this_status.card_ref != 0xFFFF) && this->card_exists_by_status(this_status)) {
@@ -1752,71 +1799,91 @@ int32_t RulerServer::error_code_for_client_setting_card(
return 0;
}
Location summon_area_loc;
uint8_t summon_area_size;
if (!this->get_creature_summon_area(
client_id, &summon_area_loc, &summon_area_size)) {
if (team_id != 1) {
if ((loc->x > 0) && (loc->x < this->map_and_rules->map.width - 1)) {
if ((loc->y < this->map_and_rules->map.height - summon_cost - 1) &&
(loc->y > 0)) {
return 0;
if (is_nte) {
// It seems NTE assumes that teams always start on the same ends of the
// map; non-NTE removes this restriction.
if (team_id == 1) {
if (((loc->x < 1) ||
(loc->x >= this->map_and_rules->map.width - 1) ||
(loc->y < summon_cost + 1) ||
(loc->y >= this->map_and_rules->map.height - 1)) &&
(loc->y != this->map_and_rules->map.height - 2)) {
return -0x7E;
}
} else if (((loc->x < 1) ||
(loc->x >= this->map_and_rules->map.width - 1) ||
(loc->y < 1) ||
(loc->y >= this->map_and_rules->map.height - summon_cost - 1)) &&
(loc->y != 1)) {
return -0x7E;
}
} else {
Location summon_area_loc;
uint8_t summon_area_size;
if (!this->get_creature_summon_area(client_id, &summon_area_loc, &summon_area_size)) {
if (team_id != 1) {
if ((loc->x > 0) && (loc->x < this->map_and_rules->map.width - 1)) {
if ((loc->y < this->map_and_rules->map.height - summon_cost - 1) &&
(loc->y > 0)) {
return 0;
}
if (loc->y == 1) {
return 0;
}
}
if (loc->y == 1) {
return 0;
} else {
if ((loc->x > 0) &&
(loc->x < this->map_and_rules->map.width - 1)) {
if ((summon_cost + 1 <= loc->y) && (loc->y < this->map_and_rules->map.height - 1)) {
return 0;
}
if (loc->y == this->map_and_rules->map.height - 2) {
return 0;
}
}
}
return -0x7E;
}
int32_t x_offset, y_offset;
this->offsets_for_direction(summon_area_loc, &x_offset, &y_offset);
if (x_offset == 0) {
if ((loc->x < 1) && (loc->x >= this->map_and_rules->map.width - 1)) {
return -0x7E;
}
} else {
if ((loc->x > 0) &&
(loc->x < this->map_and_rules->map.width - 1)) {
if ((summon_cost + 1 <= loc->y) && (loc->y < this->map_and_rules->map.height - 1)) {
return 0;
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
if (x_offset > 0) {
if (loc->x < summon_area_loc.x) {
return -0x7E;
}
if (loc->y == this->map_and_rules->map.height - 2) {
return 0;
if (loc->x > summon_area_loc.x + diff) {
return -0x7E;
}
} else if (x_offset < 0) {
if ((loc->x > summon_area_loc.x) || (loc->x < summon_area_loc.x - diff)) {
return -0x7E;
}
}
}
return -0x7E;
}
int32_t x_offset, y_offset;
this->offsets_for_direction(summon_area_loc, &x_offset, &y_offset);
if (x_offset == 0) {
if ((loc->x < 1) && (loc->x >= this->map_and_rules->map.width - 1)) {
return -0x7E;
}
} else {
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
if (x_offset > 0) {
if (loc->x < summon_area_loc.x) {
if (y_offset == 0) {
if ((loc->y < 1) && (loc->y >= this->map_and_rules->map.height - 1)) {
return -0x7E;
}
if (loc->x > summon_area_loc.x + diff) {
return -0x7E;
}
} else if (x_offset < 0) {
if ((loc->x > summon_area_loc.x) || (loc->x < summon_area_loc.x - diff)) {
return -0x7E;
}
}
}
if (y_offset == 0) {
if ((loc->y < 1) && (loc->y >= this->map_and_rules->map.height - 1)) {
return -0x7E;
}
} else {
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
if (y_offset > 0) {
if (loc->y < summon_area_loc.y) {
return -0x7E;
}
if (loc->y > summon_area_loc.y + diff) {
return -0x7E;
}
} else if (y_offset < 0) {
if ((loc->y > summon_area_loc.y) || (loc->y < summon_area_loc.y - diff)) {
return -0x7E;
} else {
int16_t diff = max<int16_t>(summon_area_size - summon_cost, 0);
if (y_offset > 0) {
if (loc->y < summon_area_loc.y) {
return -0x7E;
}
if (loc->y > summon_area_loc.y + diff) {
return -0x7E;
}
} else if (y_offset < 0) {
if ((loc->y > summon_area_loc.y) || (loc->y < summon_area_loc.y - diff)) {
return -0x7E;
}
}
}
}
@@ -2020,7 +2087,7 @@ uint8_t RulerServer::get_card_ref_max_hp(uint16_t card_ref) const {
return 0;
} else if (((ce->def.type == CardType::HUNTERS_SC) || (ce->def.type == CardType::ARKZ_SC)) &&
(this->map_and_rules->rules.char_hp > 0) &&
!this->card_ref_is_boss_sc(card_ref)) {
(this->server()->options.is_nte() || !this->card_ref_is_boss_sc(card_ref))) {
return this->map_and_rules->rules.char_hp;
} else {
return ce->def.hp.stat;
@@ -2169,7 +2236,7 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
return false;
}
if (attacker_card_status->card_flags & 2) {
if (!this->server()->options.is_nte() && (attacker_card_status->card_flags & 2)) {
this->error_code3 = -0x60;
return false;
}
@@ -2206,7 +2273,7 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
size_t conditional_card_count = 0;
size_t z;
for (z = 0; z < 9; z++) {
for (z = 0; z < 8; z++) {
uint16_t right_card_ref = pa.action_card_refs[z];
if (right_card_ref == 0xFFFF) {
break;
@@ -2285,7 +2352,9 @@ bool RulerServer::is_attack_or_defense_valid(const ActionState& pa) {
return false;
}
int16_t cost = this->compute_attack_or_defense_costs(pa, false, nullptr);
// NTE apparently does not check the action's cost here
bool is_nte = this->server()->options.is_nte();
int16_t cost = is_nte ? 0 : this->compute_attack_or_defense_costs(pa, false, nullptr);
switch (this->get_pending_action_type(pa)) {
case ActionType::ATTACK:
@@ -2381,8 +2450,9 @@ bool RulerServer::is_defense_valid(const ActionState& pa) {
}
}
if (this->find_condition_on_card_ref(pa.target_card_refs[0], ConditionType::HOLD) ||
this->find_condition_on_card_ref(pa.target_card_refs[0], ConditionType::CANNOT_DEFEND)) {
if (!this->server()->options.is_nte() &&
(this->find_condition_on_card_ref(pa.target_card_refs[0], ConditionType::HOLD) ||
this->find_condition_on_card_ref(pa.target_card_refs[0], ConditionType::CANNOT_DEFEND))) {
this->error_code3 = -0x63;
return false;
}
@@ -2411,30 +2481,53 @@ size_t RulerServer::max_move_distance_for_card_ref(uint32_t card_ref) const {
return 0;
}
ssize_t ret = ce->def.mv.stat;
Condition cond;
if (this->find_condition_on_card_ref(card_ref, ConditionType::MV_BONUS, &cond, nullptr, true)) {
ret += cond.value;
}
if (this->find_condition_on_card_ref(card_ref, ConditionType::SET_MV, &cond, nullptr, true)) {
ret = cond.value;
}
ret = max<ssize_t>(0, ret);
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(client_id);
bool has_stamina_effect = false;
for (size_t z = 0; z < num_assists; z++) {
auto eff = this->assist_server->get_active_assist_by_index(z);
if (eff == AssistEffect::SNAIL_PACE) {
return 1;
if (this->server()->options.is_nte()) {
if (ce->def.type == CardType::ITEM) {
return ce->def.mv.stat;
}
if (eff == AssistEffect::STAMINA) {
has_stamina_effect = true;
}
}
return (has_stamina_effect) ? 9 : min<ssize_t>(9, ret);
Condition cond;
if (this->find_condition_on_card_ref(card_ref, ConditionType::SET_MV, &cond)) {
return cond.value;
}
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(client_id);
bool has_stamina_effect = false;
for (size_t z = 0; z < num_assists; z = z + 1) {
auto assist = this->assist_server->get_active_assist_by_index(z);
if (assist == AssistEffect::SNAIL_PACE) {
return 1;
} else if (assist == AssistEffect::STAMINA) {
has_stamina_effect = true;
}
}
return has_stamina_effect ? 99 : ce->def.mv.stat;
} else {
ssize_t ret = ce->def.mv.stat;
Condition cond;
if (this->find_condition_on_card_ref(card_ref, ConditionType::MV_BONUS, &cond, nullptr, true)) {
ret += cond.value;
}
if (this->find_condition_on_card_ref(card_ref, ConditionType::SET_MV, &cond, nullptr, true)) {
ret = cond.value;
}
ret = max<ssize_t>(0, ret);
size_t num_assists = this->assist_server->compute_num_assist_effects_for_client(client_id);
bool has_stamina_effect = false;
for (size_t z = 0; z < num_assists; z++) {
auto eff = this->assist_server->get_active_assist_by_index(z);
if (eff == AssistEffect::SNAIL_PACE) {
return 1;
}
if (eff == AssistEffect::STAMINA) {
has_stamina_effect = true;
}
}
return has_stamina_effect ? 9 : min<ssize_t>(9, ret);
}
}
RulerServer::MovePath::MovePath()
@@ -2518,13 +2611,14 @@ void RulerServer::replace_D1_D2_rank_cards_with_Attack(
}
AttackMedium RulerServer::get_attack_medium(const ActionState& pa) const {
bool is_nte = this->server()->options.is_nte();
for (size_t z = 0; z < 8; z++) {
uint16_t card_ref = pa.action_card_refs[z];
if (card_ref == 0xFFFF) {
return AttackMedium::PHYSICAL;
}
auto ce = this->definition_for_card_ref(card_ref);
if (ce && card_class_is_tech_like(ce->def.card_class())) {
if (ce && card_class_is_tech_like(ce->def.card_class(), is_nte)) {
return AttackMedium::TECH;
}
}
@@ -2545,9 +2639,11 @@ int32_t RulerServer::set_cost_for_card(uint8_t client_id, uint16_t card_ref) con
return -0x7D;
}
bool is_nte = this->server()->options.is_nte();
auto short_statuses = this->short_statuses[client_id];
int32_t ret = ce->def.self_cost;
if (short_statuses &&
if (!is_nte &&
short_statuses &&
this->card_exists_by_status(short_statuses->at(0)) &&
this->find_condition_on_card_ref(short_statuses->at(0).card_ref, ConditionType::UNKNOWN_69)) {
ret = 0;
@@ -2580,9 +2676,8 @@ int32_t RulerServer::set_cost_for_card(uint8_t client_id, uint16_t card_ref) con
for (size_t z = 0; z < num_assists; z++) {
auto eff = this->assist_server->get_active_assist_by_index(z);
if (eff == AssistEffect::LAND_PRICE) {
// Note: Original code had an extra addend (ret < 0 && (ret & 1) != 0),
// but ret cannot be negatve here, so we omit it.
ret += ret >> 1;
// In NTE, Land Price is apparently 2x rather than 1.5x
ret = is_nte ? (ret << 1) : (ret + (ret >> 1));
} else if (eff == AssistEffect::DEFLATION) {
ret = max<int32_t>(0, ret - 1);
} else if (eff == AssistEffect::INFLATION) {
@@ -2667,4 +2762,24 @@ int32_t RulerServer::verify_deck(
return 0;
}
size_t RulerServer::count_targets_with_rampage_and_not_pierce_nte(const ActionState& as) const {
size_t ret = 0;
for (size_t z = 0; (z < as.target_card_refs.size()) && (as.target_card_refs[z] != 0xFFFF); z++) {
if (this->attack_action_has_rampage_and_not_pierce(as, as.target_card_refs[z])) {
ret++;
}
}
return ret;
}
size_t RulerServer::count_targets_with_pierce_and_not_rampage_nte(const ActionState& as) const {
size_t ret = 0;
for (size_t z = 0; (z < as.target_card_refs.size()) && (as.target_card_refs[z] != 0xFFFF); z++) {
if (this->attack_action_has_pierce_and_not_rampage(as, client_id_for_card_ref(as.target_card_refs[z]))) {
ret++;
}
}
return ret;
}
} // namespace Episode3
+22 -35
View File
@@ -49,12 +49,9 @@ public:
std::shared_ptr<Server> server();
std::shared_ptr<const Server> server() const;
ActionChainWithConds* action_chain_with_conds_for_card_ref(
uint16_t card_ref);
const ActionChainWithConds* action_chain_with_conds_for_card_ref(
uint16_t card_ref) const;
bool any_attack_action_card_is_support_tech_or_support_pb(
const ActionState& pa) const;
ActionChainWithConds* action_chain_with_conds_for_card_ref(uint16_t card_ref);
const ActionChainWithConds* action_chain_with_conds_for_card_ref(uint16_t card_ref) const;
bool any_attack_action_card_is_support_tech_or_support_pb(const ActionState& pa) const;
bool card_has_pierce_or_rampage(
uint8_t client_id,
ConditionType cond_type,
@@ -63,27 +60,23 @@ public:
uint16_t action_card_ref,
uint8_t def_effect_index,
AttackMedium attack_medium) const;
bool attack_action_has_rampage_and_not_pierce(
const ActionState& pa, uint16_t card_ref) const;
bool attack_action_has_pierce_and_not_rampage(
const ActionState& pa, uint8_t client_id);
bool attack_action_has_rampage_and_not_pierce(const ActionState& pa, uint16_t card_ref) const;
bool attack_action_has_pierce_and_not_rampage(const ActionState& pa, uint8_t client_id) const;
size_t count_targets_with_rampage_and_not_pierce_nte(const ActionState& as) const;
size_t count_targets_with_pierce_and_not_rampage_nte(const ActionState& as) const;
bool card_exists_by_status(const CardShortStatus& stat) const;
bool card_has_mighty_knuckle(uint32_t card_ref) const;
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
static bool card_id_is_boss_sc(uint16_t card_id);
static bool card_id_is_support_tech_or_support_pb(uint16_t card_id);
bool card_ref_can_attack(uint16_t card_ref);
bool card_ref_can_move(
uint8_t client_id, uint16_t card_ref, bool ignore_atk_points) const;
bool card_ref_has_class_usability_condition(
uint16_t card_ref) const;
bool card_ref_can_move(uint8_t client_id, uint16_t card_ref, bool ignore_atk_points) const;
bool card_ref_has_class_usability_condition(uint16_t card_ref) const;
bool card_ref_has_free_maneuver(uint16_t card_ref) const;
bool card_ref_is_aerial(uint16_t card_ref) const;
bool card_ref_is_aerial_or_has_free_maneuver(
uint16_t card_ref) const;
bool card_ref_is_aerial_or_has_free_maneuver(uint16_t card_ref) const;
bool card_ref_is_boss_sc(uint32_t card_ref) const;
bool card_ref_or_any_set_card_has_condition_46(
uint16_t card_ref) const;
bool card_ref_or_any_set_card_has_condition_46(uint16_t card_ref) const;
bool card_ref_or_sc_has_fixed_range(uint16_t card_ref) const;
bool check_move_path_and_get_cost(
uint8_t client_id,
@@ -123,14 +116,12 @@ public:
uint16_t* out_effective_card_id,
TargetMode* out_effective_target_mode,
uint16_t* out_orig_card_ref) const;
size_t count_rampage_targets_for_attack(
const ActionState& pa, uint8_t client_id) const;
size_t count_rampage_targets_for_attack(const ActionState& pa, uint8_t client_id) const;
bool defense_card_can_apply_to_attack(
uint16_t defense_card_ref,
uint16_t attacker_card_ref,
uint16_t attacker_sc_card_ref) const;
bool defense_card_matches_any_attack_card_top_color(
const ActionState& pa) const;
bool defense_card_matches_any_attack_card_top_color(const ActionState& pa) const;
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
int32_t error_code_for_client_setting_card(
uint8_t client_id,
@@ -157,17 +148,14 @@ public:
size_t num_occupied_tiles,
size_t num_vacant_tiles) const;
uint16_t get_ally_sc_card_ref(uint16_t card_ref) const;
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(
uint32_t card_id) const;
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint32_t card_id) const;
uint32_t get_card_id_with_effective_range(
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const;
uint8_t get_card_ref_max_hp(uint16_t card_ref) const;
bool get_creature_summon_area(
uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const;
std::shared_ptr<HandAndEquipState> get_hand_and_equip_state_for_client_id(
uint8_t client_id);
std::shared_ptr<const HandAndEquipState> get_hand_and_equip_state_for_client_id(
uint8_t client_id) const;
std::shared_ptr<HandAndEquipState> get_hand_and_equip_state_for_client_id(uint8_t client_id);
std::shared_ptr<const HandAndEquipState> get_hand_and_equip_state_for_client_id(uint8_t client_id) const;
bool get_move_path_length_and_cost(
uint32_t client_id,
uint32_t card_ref,
@@ -188,8 +176,7 @@ public:
std::shared_ptr<StateFlags> state_flags,
std::shared_ptr<AssistServer> assist_server);
size_t max_move_distance_for_card_ref(uint32_t card_ref) const;
static void offsets_for_direction(
const Location& loc, int32_t* out_x_offset, int32_t* out_y_offset);
static void offsets_for_direction(const Location& loc, int32_t* out_x_offset, int32_t* out_y_offset);
void register_player(
uint8_t client_id,
std::shared_ptr<HandAndEquipState> hes,
@@ -211,11 +198,11 @@ private:
std::weak_ptr<Server> w_server;
public:
std::shared_ptr<HandAndEquipState> hand_and_equip_states[4];
std::shared_ptr<parray<CardShortStatus, 0x10>> short_statuses[4];
std::shared_ptr<DeckEntry> deck_entries[4];
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains[4];
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas[4];
bcarray<std::shared_ptr<HandAndEquipState>, 4> hand_and_equip_states;
bcarray<std::shared_ptr<parray<CardShortStatus, 0x10>>, 4> short_statuses;
bcarray<std::shared_ptr<DeckEntry>, 4> deck_entries;
bcarray<std::shared_ptr<parray<ActionChainWithConds, 9>>, 4> set_card_action_chains;
bcarray<std::shared_ptr<parray<ActionMetadata, 9>>, 4> set_card_action_metadatas;
std::shared_ptr<MapAndRulesState> map_and_rules;
std::shared_ptr<StateFlags> state_flags;
std::shared_ptr<AssistServer> assist_server;
+889 -532
View File
File diff suppressed because it is too large Load Diff
+69 -27
View File
@@ -9,6 +9,7 @@
#include "../CommandFormats.hh"
#include "../Text.hh"
#include "AssistServer.hh"
#include "BattleRecord.hh"
#include "CardSpecial.hh"
#include "MapState.hh"
#include "PlayerState.hh"
@@ -71,9 +72,13 @@ public:
std::shared_ptr<const CardIndex> card_index;
std::shared_ptr<const MapIndex> map_index;
uint32_t behavior_flags;
std::shared_ptr<PSOLFGEncryption> random_crypt;
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
std::shared_ptr<const Tournament> tournament;
std::array<std::vector<uint16_t>, 5> trap_card_ids;
inline bool is_nte() const {
return (this->behavior_flags & BehaviorFlag::IS_TRIAL_EDITION);
}
};
Server(std::shared_ptr<Lobby> lobby, Options&& options);
~Server() noexcept(false);
@@ -95,26 +100,54 @@ public:
StackLogger log_stack(const std::string& prefix) const;
const StackLogger& log() const;
std::string debug_str_for_card_ref(uint16_t card_ref) const;
std::string debug_str_for_card_id(uint16_t card_id) const;
template <typename U16T>
std::string debug_str_for_card_refs(const U16T* refs, size_t count) const {
std::string ret = "[";
for (size_t z = 0; z < count; z++) {
if (refs[z] != 0xFFFF) {
std::string ref_str = this->debug_str_for_card_ref(refs[z]);
ret += string_printf("%zu:%s ", z, ref_str.c_str());
}
}
if (ret.size() > 1) {
ret.back() = ']'; // Replace the ' ' from the last added item
} else {
ret.push_back(']');
}
return ret;
}
template <typename U16T>
std::string debug_str_for_card_refs(const std::vector<U16T>& refs) const {
return this->debug_str_for_card_refs(refs.data(), refs.size());
}
template <typename U16T, size_t Count>
std::string debug_str_for_card_refs(const parray<U16T, Count>& refs) const {
return this->debug_str_for_card_refs(refs.data(), refs.size());
}
int8_t get_winner_team_id() const;
template <typename T>
void send(const T& cmd) const {
void send(const T& cmd, uint8_t command = 0xC9, bool enable_masking = true) const {
if (cmd.header.size != sizeof(cmd) / 4) {
throw std::logic_error("outbound command size field is incorrect");
}
if (cmd.header.subsubcommand == 0x06) {
if (!this->options.is_nte() && (cmd.header.subsubcommand == 0x06)) {
this->num_6xB4x06_commands_sent++;
this->prev_num_6xB4x06_commands_sent = this->num_6xB4x06_commands_sent;
if (this->num_6xB4x06_commands_sent > 0x100) {
return;
}
}
this->send(&cmd, cmd.header.size * 4);
this->send(&cmd, cmd.header.size * 4, command, enable_masking);
}
void send(const void* data, size_t size) const;
void send(const void* data, size_t size, uint8_t command = 0xC9, bool enable_masking = true) const;
void send_commands_for_joining_spectator(Channel& ch) const;
void force_battle_result(uint8_t surrendered_client_id, bool set_winner);
void force_replace_assist_card(uint8_t client_id, uint16_t card_id);
void force_destroy_field_character(uint8_t client_id, size_t set_index);
__attribute__((format(printf, 2, 3))) void send_debug_message_printf(const char* fmt, ...) const;
@@ -142,7 +175,7 @@ public:
bool check_presence_entry(uint8_t client_id) const;
void clear_player_flags_after_dice_phase();
void compute_all_map_occupied_bits();
void compute_team_dice_boost(uint8_t team_id);
void compute_team_dice_bonus(uint8_t team_id);
void copy_player_states_to_prev_states();
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
void destroy_cards_with_zero_hp();
@@ -159,6 +192,7 @@ public:
uint8_t get_current_team_turn() const;
std::shared_ptr<PlayerState> get_player_state(uint8_t client_id);
std::shared_ptr<const PlayerState> get_player_state(uint8_t client_id) const;
uint32_t get_random_raw();
uint32_t get_random(uint32_t max);
float get_random_float_0_1();
uint32_t get_round_num() const;
@@ -173,14 +207,14 @@ public:
void send_set_card_updates_and_6xB4x04_if_needed();
void set_battle_ended();
void set_battle_started();
void set_client_id_ready_to_advance_phase(uint8_t client_id);
bool player_can_receive_dice_boost(uint8_t client_id) const;
void set_client_id_ready_to_advance_phase(uint8_t client_id, BattlePhase battle_phase);
void set_phase_after();
void move_phase_before();
void set_player_deck_valid(uint8_t client_id);
void setup_and_start_battle();
G_SetStateFlags_GC_Ep3_6xB4x03 prepare_6xB4x03() const;
void update_battle_state_flags_and_send_6xB4x03_if_needed(
bool always_send = false);
G_SetStateFlags_Ep3_6xB4x03 prepare_6xB4x03() const;
void update_battle_state_flags_and_send_6xB4x03_if_needed(bool always_send = false);
bool update_registration_phase();
void on_server_data_input(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx0B_mulligan_hand(std::shared_ptr<Client> sender_c, const std::string& data);
@@ -191,6 +225,8 @@ public:
void handle_CAx10_move_fc_to_location(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx11_enqueue_attack_or_defense(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx12_end_attack_list(std::shared_ptr<Client> sender_c, const std::string& data);
template <typename CmdT>
void handle_CAx13_update_map_during_setup_t(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx13_update_map_during_setup(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx14_update_deck_during_setup(std::shared_ptr<Client> sender_c, const std::string& data);
void handle_CAx15_unused_hard_reset_server_state(std::shared_ptr<Client> sender_c, const std::string& data);
@@ -208,12 +244,11 @@ public:
void handle_CAx49_card_counts(std::shared_ptr<Client> sender_c, const std::string& data);
void compute_losing_team_id_and_add_winner_flags(uint32_t flags);
uint32_t get_team_exp(uint8_t team_id) const;
uint32_t send_6xB4x06_if_card_ref_invalid(
uint16_t card_ref, int16_t negative_value);
uint32_t send_6xB4x06_if_card_ref_invalid(uint16_t card_ref, int16_t negative_value);
void unknown_8023EEF4();
void execute_bomb_assist_effect();
void replace_targets_due_to_destruction_or_conditions(
ActionState* as);
void replace_targets_due_to_destruction_nte(ActionState* as);
void replace_targets_due_to_destruction_or_conditions(ActionState* as);
bool any_target_exists_for_attack(const ActionState& as);
uint8_t get_current_team_turn2() const;
void unknown_8023EE48();
@@ -224,12 +259,11 @@ public:
void send_6xB4x02_for_all_players_if_needed(bool always_send = false);
void send_6xB4x50_trap_tile_locations() const;
G_UpdateDecks_GC_Ep3_6xB4x07 prepare_6xB4x07_decks_update() const;
G_SetPlayerNames_GC_Ep3_6xB4x1C prepare_6xB4x1C_names_update() const;
static std::string prepare_6xB6x41_map_definition(
std::shared_ptr<const MapIndex::Map> map, uint8_t language, bool is_trial);
G_UpdateDecks_Ep3_6xB4x07 prepare_6xB4x07_decks_update() const;
G_SetPlayerNames_Ep3_6xB4x1C prepare_6xB4x1C_names_update() const;
static std::string prepare_6xB6x41_map_definition(std::shared_ptr<const MapIndex::Map> map, uint8_t language, bool is_nte);
void send_6xB6x41_to_all_clients() const;
G_SetTrapTileLocations_GC_Ep3_6xB4x50 prepare_6xB4x50_trap_tile_locations() const;
G_SetTrapTileLocations_Ep3_6xB4x50 prepare_6xB4x50_trap_tile_locations() const;
std::vector<std::shared_ptr<Card>> const_cast_set_cards_v(
const std::vector<std::shared_ptr<const Card>>& cards);
@@ -241,10 +275,15 @@ private:
public:
// These fields are not part of the original implementation
std::weak_ptr<Lobby> lobby;
std::shared_ptr<BattleRecord> battle_record;
bool has_lobby;
Options options;
std::shared_ptr<const MapIndex::Map> last_chosen_map;
bool tournament_match_result_sent;
uint8_t override_environment_number;
uint8_t def_dice_value_range_override;
uint8_t atk_dice_value_range_2v1_override;
uint8_t def_dice_value_range_2v1_override;
mutable std::deque<StackLogger*> logger_stack;
// These fields were originally contained in the TCardServerBase object
@@ -254,9 +293,10 @@ public:
uint8_t is_cpu_player;
PresenceEntry();
void clear();
} __attribute__((packed));
} __packed_ws__(PresenceEntry, 3);
std::shared_ptr<MapAndRulesState> map_and_rules;
std::shared_ptr<DeckEntry> deck_entries[4];
bcarray<std::shared_ptr<DeckEntry>, 4> deck_entries;
parray<PresenceEntry, 4> presence_entries;
uint8_t num_clients_present;
parray<NameEntry, 4> name_entries;
@@ -275,7 +315,7 @@ public:
RegistrationPhase registration_phase;
ActionSubphase action_subphase;
uint8_t current_team_turn2;
ActionState pending_attacks[0x20];
bcarray<ActionState, 0x20> pending_attacks;
uint32_t num_pending_attacks;
parray<uint8_t, 4> client_done_enqueuing_attacks;
parray<uint8_t, 4> player_ready_to_end_phase;
@@ -288,11 +328,11 @@ public:
uint32_t should_copy_prev_states_to_current_states;
std::shared_ptr<CardSpecial> card_special;
std::shared_ptr<StateFlags> state_flags;
std::shared_ptr<PlayerState> player_states[4];
std::array<std::shared_ptr<PlayerState>, 4> player_states;
parray<uint32_t, 4> clients_done_in_mulligan_phase;
uint32_t num_pending_attacks_with_cards;
std::shared_ptr<Card> attack_cards[0x20];
ActionState pending_attacks_with_cards[0x20];
bcarray<std::shared_ptr<Card>, 0x20> attack_cards;
bcarray<ActionState, 0x20> pending_attacks_with_cards;
uint32_t unknown_a14;
uint32_t unknown_a15;
parray<uint32_t, 4> defense_list_ended_for_client;
@@ -301,14 +341,16 @@ public:
std::shared_ptr<RulerServer> ruler_server;
parray<parray<parray<uint8_t, 2>, 2>, 5> warp_positions; // Array indexes are (type, end, x/y)
parray<int16_t, 2> team_exp;
parray<int16_t, 2> team_dice_boost;
parray<int16_t, 2> team_dice_bonus;
parray<uint32_t, 2> team_client_count;
parray<uint32_t, 2> team_num_ally_fcs_destroyed;
parray<uint32_t, 2> team_num_cards_destroyed;
parray<uint8_t, 5> num_trap_tiles_of_type;
parray<uint8_t, 5> chosen_trap_tile_index_of_type;
parray<parray<parray<uint8_t, 2>, 8>, 5> trap_tile_locs;
ActionState pb_action_states[4];
parray<parray<uint8_t, 2>, 0x10> trap_tile_locs_nte;
size_t num_trap_tiles_nte;
bcarray<ActionState, 4> pb_action_states;
parray<uint8_t, 4> has_done_pb;
parray<parray<uint8_t, 4>, 4> has_done_pb_with_client;
mutable uint32_t num_6xB4x06_commands_sent;
+32 -32
View File
@@ -9,18 +9,18 @@ using namespace std;
namespace Episode3 {
Tournament::PlayerEntry::PlayerEntry(uint32_t serial_number, const string& player_name)
: serial_number(serial_number),
Tournament::PlayerEntry::PlayerEntry(uint32_t account_id, const string& player_name)
: account_id(account_id),
player_name(player_name) {}
Tournament::PlayerEntry::PlayerEntry(shared_ptr<Client> c)
: serial_number(c->license->serial_number),
: account_id(c->login->account->account_id),
client(c),
player_name(c->character()->disp.name.decode(c->language())) {}
Tournament::PlayerEntry::PlayerEntry(
shared_ptr<const COMDeckDefinition> com_deck)
: serial_number(0),
: account_id(0),
com_deck(com_deck) {}
bool Tournament::PlayerEntry::is_com() const {
@@ -28,7 +28,7 @@ bool Tournament::PlayerEntry::is_com() const {
}
bool Tournament::PlayerEntry::is_human() const {
return (this->serial_number != 0);
return (this->account_id != 0);
}
Tournament::Team::Team(
@@ -56,9 +56,9 @@ string Tournament::Team::str() const {
for (const auto& player : this->players) {
if (player.is_human()) {
if (player.player_name.empty()) {
ret += string_printf(" %08" PRIX32, player.serial_number);
ret += string_printf(" %08" PRIX32, player.account_id);
} else {
ret += string_printf(" %08" PRIX32 " (%s)", player.serial_number, player.player_name.c_str());
ret += string_printf(" %08" PRIX32 " (%s)", player.account_id, player.player_name.c_str());
}
}
}
@@ -81,12 +81,12 @@ void Tournament::Team::register_player(
if (!tournament) {
throw runtime_error("tournament has been deleted");
}
if (!tournament->all_player_serial_numbers.emplace(c->license->serial_number).second) {
if (!tournament->all_player_account_ids.emplace(c->login->account->account_id).second) {
throw runtime_error("player already registered in same tournament");
}
for (const auto& player : this->players) {
if (player.is_human() && (player.serial_number == c->license->serial_number)) {
if (player.is_human() && (player.account_id == c->login->account->account_id)) {
throw logic_error("player already registered in team but not in tournament");
}
}
@@ -99,11 +99,11 @@ void Tournament::Team::register_player(
}
}
bool Tournament::Team::unregister_player(uint32_t serial_number) {
bool Tournament::Team::unregister_player(uint32_t account_id) {
size_t index;
for (index = 0; index < this->players.size(); index++) {
if (this->players[index].is_human() &&
(this->players[index].serial_number == serial_number)) {
(this->players[index].account_id == account_id)) {
break;
}
}
@@ -143,7 +143,7 @@ bool Tournament::Team::unregister_player(uint32_t serial_number) {
// If the tournament has not started yet, just remove the player from the
// team
} else {
if (!tournament->all_player_serial_numbers.erase(serial_number)) {
if (!tournament->all_player_account_ids.erase(account_id)) {
throw logic_error("player removed from team but not from tournament");
}
}
@@ -371,13 +371,13 @@ void Tournament::init() {
team_index_to_rounds_cleared.emplace_back(team_json->get_int("num_rounds_cleared"));
for (const auto& player_json : team_json->get_list("player_specs")) {
if (player_json->is_list()) {
uint32_t serial_number = player_json->at(0).as_int();
team->players.emplace_back(serial_number, player_json->at(1).as_string());
this->all_player_serial_numbers.emplace(serial_number);
uint32_t account_id = player_json->at(0).as_int();
team->players.emplace_back(account_id, player_json->at(1).as_string());
this->all_player_account_ids.emplace(account_id);
} else if (player_json->is_int()) {
uint32_t serial_number = player_json->as_int();
team->players.emplace_back(serial_number);
this->all_player_serial_numbers.emplace(serial_number);
uint32_t account_id = player_json->as_int();
team->players.emplace_back(account_id);
this->all_player_account_ids.emplace(account_id);
} else if (player_json->is_string()) {
team->players.emplace_back(this->com_deck_index->deck_for_name(player_json->as_string()));
} else {
@@ -511,9 +511,9 @@ JSON Tournament::json() const {
for (const auto& player : team->players) {
if (player.is_human()) {
if (!player.player_name.empty()) {
players_list.emplace_back(JSON::list({player.serial_number, player.player_name}));
players_list.emplace_back(JSON::list({player.account_id, player.player_name}));
} else {
players_list.emplace_back(player.serial_number);
players_list.emplace_back(player.account_id);
}
} else {
players_list.emplace_back(player.com_deck->deck_name);
@@ -571,25 +571,25 @@ shared_ptr<Tournament::Match> Tournament::get_final_match() const {
return this->final_match;
}
shared_ptr<Tournament::Team> Tournament::team_for_serial_number(
uint32_t serial_number) const {
if (!this->all_player_serial_numbers.count(serial_number)) {
shared_ptr<Tournament::Team> Tournament::team_for_account_id(
uint32_t account_id) const {
if (!this->all_player_account_ids.count(account_id)) {
return nullptr;
}
for (auto team : this->teams) {
for (const auto& player : team->players) {
if (player.serial_number == serial_number) {
if (player.account_id == account_id) {
return team->is_active ? team : nullptr;
}
}
}
throw logic_error("serial number registered in tournament but not in any team");
throw logic_error("account ID registered in tournament but not in any team");
}
const set<uint32_t>& Tournament::get_all_player_serial_numbers() const {
return this->all_player_serial_numbers;
const set<uint32_t>& Tournament::get_all_player_account_ids() const {
return this->all_player_account_ids;
}
void Tournament::start() {
@@ -842,7 +842,7 @@ void TournamentIndex::save() const {
for (const auto& it : this->name_to_tournament) {
json.emplace(it.second->get_name(), it.second->json());
}
save_file(this->state_filename, json.serialize(JSON::SerializeOption::FORMAT | JSON::SerializeOption::HEX_INTEGERS));
save_file(this->state_filename, json.serialize(JSON::SerializeOption::FORMAT | JSON::SerializeOption::HEX_INTEGERS | JSON::SerializeOption::ESCAPE_CONTROLS_ONLY));
}
shared_ptr<Tournament> TournamentIndex::create_tournament(
@@ -896,10 +896,10 @@ bool TournamentIndex::delete_tournament(const string& name) {
return true;
}
shared_ptr<Tournament::Team> TournamentIndex::team_for_serial_number(uint32_t serial_number) const {
shared_ptr<Tournament::Team> TournamentIndex::team_for_account_id(uint32_t account_id) const {
for (const auto& it : this->name_to_tournament) {
const auto& tourn = it.second;
auto team = tourn->team_for_serial_number(serial_number);
auto team = tourn->team_for_account_id(account_id);
if (team) {
return team;
}
@@ -912,11 +912,11 @@ void TournamentIndex::link_client(shared_ptr<Client> c) {
return;
}
auto team = this->team_for_serial_number(c->license->serial_number);
auto team = this->team_for_account_id(c->login->account->account_id);
auto tourn = team ? team->tournament.lock() : nullptr;
if (team && team->is_active && tourn) {
for (auto& player : team->players) {
if (player.serial_number == c->license->serial_number) {
if (player.account_id == c->login->account->account_id) {
c->ep3_tournament_team = team;
player.client = c;
if (c->version() == Version::GC_EP3) {
+9 -9
View File
@@ -33,16 +33,16 @@ public:
};
struct PlayerEntry {
// Invariant: (serial_number == 0) != (com_deck == nullptr)
// Invariant: (account_id == 0) != (com_deck == nullptr)
// (that is, exactly one of the following must be valid)
uint32_t serial_number;
uint32_t account_id;
std::shared_ptr<const COMDeckDefinition> com_deck;
// client is valid if serial_number is nonzero and the client is connected
// client is valid if account_id is nonzero and the client is connected
std::weak_ptr<Client> client;
std::string player_name; // Not used for COM decks
explicit PlayerEntry(uint32_t serial_number, const std::string& player_name = "");
explicit PlayerEntry(uint32_t account_id, const std::string& player_name = "");
explicit PlayerEntry(std::shared_ptr<Client> c);
explicit PlayerEntry(std::shared_ptr<const COMDeckDefinition> com_deck);
@@ -73,7 +73,7 @@ public:
std::shared_ptr<Client> c,
const std::string& team_name,
const std::string& password);
bool unregister_player(uint32_t serial_number);
bool unregister_player(uint32_t account_id);
bool has_any_human_players() const;
size_t num_human_players() const;
@@ -152,8 +152,8 @@ public:
std::shared_ptr<Team> get_winner_team() const;
std::shared_ptr<Match> next_match_for_team(std::shared_ptr<Team> team) const;
std::shared_ptr<Match> get_final_match() const;
std::shared_ptr<Team> team_for_serial_number(uint32_t serial_number) const;
const std::set<uint32_t>& get_all_player_serial_numbers() const;
std::shared_ptr<Team> team_for_account_id(uint32_t account_id) const;
const std::set<uint32_t>& get_all_player_account_ids() const;
void start();
@@ -178,7 +178,7 @@ private:
State current_state;
uint32_t menu_item_id;
std::set<uint32_t> all_player_serial_numbers;
std::set<uint32_t> all_player_account_ids;
std::unordered_set<std::shared_ptr<Match>> pending_matches;
// This vector contains all teams in the original starting order of the
@@ -231,7 +231,7 @@ public:
uint8_t flags);
bool delete_tournament(const std::string& name);
std::shared_ptr<Tournament::Team> team_for_serial_number(uint32_t serial_number) const;
std::shared_ptr<Tournament::Team> team_for_account_id(uint32_t account_id) const;
void link_client(std::shared_ptr<Client> c);
void link_all_clients(std::shared_ptr<ServerState> s);
+43
View File
@@ -0,0 +1,43 @@
#include "EventUtils.hh"
#include <event2/event.h>
#include <deque>
#include <functional>
#include <memory>
#include <stdexcept>
static void dispatch_forward_to_event_thread(evutil_socket_t, short, void* ctx) {
auto* fn = reinterpret_cast<std::function<void()>*>(ctx);
(*fn)();
delete fn;
}
void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn) {
struct timeval tv = {0, 0};
std::function<void()>* new_fn = new std::function<void()>(std::move(fn));
event_base_once(base.get(), -1, EV_TIMEOUT, dispatch_forward_to_event_thread, new_fn, &tv);
}
template <>
void call_on_event_thread<void>(std::shared_ptr<struct event_base> base, std::function<void()>&& compute) {
bool succeeded = false;
std::string exc_what;
std::mutex ret_lock;
std::condition_variable ret_cv;
std::unique_lock<std::mutex> g(ret_lock);
forward_to_event_thread(base, [&]() -> void {
std::lock_guard<std::mutex> g(ret_lock);
try {
compute();
succeeded = true;
} catch (const std::exception& e) {
exc_what = e.what();
}
ret_cv.notify_one();
});
ret_cv.wait(g);
if (!succeeded) {
throw std::runtime_error(exc_what);
}
}
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include <event2/event.h>
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <stdexcept>
void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn);
template <typename T>
T call_on_event_thread(std::shared_ptr<struct event_base> base, std::function<T()>&& compute) {
std::optional<T> ret;
std::string exc_what;
std::mutex ret_lock;
std::condition_variable ret_cv;
std::unique_lock<std::mutex> g(ret_lock);
forward_to_event_thread(base, [&]() -> void {
std::lock_guard<std::mutex> g(ret_lock);
try {
ret = compute();
} catch (const std::exception& e) {
exc_what = e.what();
}
ret_cv.notify_one();
});
ret_cv.wait(g);
if (!ret.has_value()) {
throw std::runtime_error(exc_what);
}
return ret.value();
}
template <>
void call_on_event_thread<void>(std::shared_ptr<struct event_base> base, std::function<void()>&& compute);
+15
View File
@@ -74,3 +74,18 @@ FileContentsCache::GetResult FileContentsCache::get(const char* name,
std::function<std::string(const std::string&)> generate) {
return this->get(string(name), generate);
}
shared_ptr<const string> ThreadSafeFileCache::get(
const string& name, std::function<shared_ptr<const string>(const std::string&)> generate) {
try {
shared_lock g(this->lock);
return this->name_to_file.at(name);
} catch (const out_of_range&) {
unique_lock g(this->lock);
auto it = this->name_to_file.find(name);
if (it == this->name_to_file.end()) {
it = this->name_to_file.emplace(name, generate(name)).first;
}
return it->second;
}
}
+20
View File
@@ -2,6 +2,8 @@
#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <unordered_map>
@@ -102,3 +104,21 @@ private:
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
uint64_t ttl_usecs;
};
class ThreadSafeFileCache {
public:
explicit ThreadSafeFileCache() = default;
ThreadSafeFileCache(const ThreadSafeFileCache&) = delete;
ThreadSafeFileCache(ThreadSafeFileCache&&) = delete;
ThreadSafeFileCache& operator=(const ThreadSafeFileCache&) = delete;
ThreadSafeFileCache& operator=(ThreadSafeFileCache&&) = delete;
~ThreadSafeFileCache() = default;
// Warning: generate() is called while the lock is held for writing, so it
// will block other threads.
std::shared_ptr<const std::string> get(const std::string& name, std::function<std::shared_ptr<const std::string>(const std::string&)> generate);
private:
std::shared_mutex lock;
std::unordered_map<std::string, std::shared_ptr<const std::string>> name_to_file;
};
+204 -73
View File
@@ -10,6 +10,8 @@
#ifdef HAVE_RESOURCE_FILE
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/SH4Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#endif
#include "CommandFormats.hh"
@@ -38,6 +40,8 @@ const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
return "PowerPC";
case CompiledFunctionCode::Architecture::X86:
return "x86";
case CompiledFunctionCode::Architecture::SH4:
return "SH-4";
default:
throw logic_error("invalid architecture");
}
@@ -116,12 +120,14 @@ bool CompiledFunctionCode::is_big_endian() const {
shared_ptr<CompiledFunctionCode> compile_function_code(
CompiledFunctionCode::Architecture arch,
const string& directory,
const string& function_directory,
const string& system_directory,
const string& name,
const string& text) {
#ifndef HAVE_RESOURCE_FILE
(void)arch;
(void)directory;
(void)function_directory;
(void)system_directory;
(void)name;
(void)text;
throw runtime_error("function compiler is not available");
@@ -133,28 +139,88 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
ret->index = 0;
ret->hide_from_patches_menu = false;
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
auto assembled = PPC32Emulator::assemble(text, {directory});
ret->code = std::move(assembled.code);
ret->label_offsets = std::move(assembled.label_offsets);
for (const auto& it : assembled.metadata_keys) {
if (it.first == "hide_from_patches_menu") {
ret->hide_from_patches_menu = true;
} else if (it.first == "index") {
if (it.second.size() != 1) {
throw runtime_error("invalid index value in .meta directive");
}
ret->index = it.second[0];
} else if (it.first == "name") {
ret->long_name = it.second;
} else if (it.first == "description") {
ret->description = it.second;
} else {
throw runtime_error("unknown metadata key: " + it.first);
}
unordered_set<string> get_include_stack;
function<string(const string&)> get_include = [&](const string& name) -> string {
const char* arch_name_token;
switch (arch) {
case CompiledFunctionCode::Architecture::POWERPC:
arch_name_token = "ppc";
break;
case CompiledFunctionCode::Architecture::X86:
arch_name_token = "x86";
break;
case CompiledFunctionCode::Architecture::SH4:
arch_name_token = "sh4";
break;
default:
throw runtime_error("unknown architecture");
}
// Look in the function directory first, then the system directory
string asm_filename = string_printf("%s/%s.%s.inc.s", function_directory.c_str(), name.c_str(), arch_name_token);
if (!isfile(asm_filename)) {
asm_filename = string_printf("%s/%s.%s.inc.s", system_directory.c_str(), name.c_str(), arch_name_token);
}
if (isfile(asm_filename)) {
if (!get_include_stack.emplace(name).second) {
throw runtime_error("mutual recursion between includes: " + name);
}
EmulatorBase::AssembleResult ret;
switch (arch) {
case CompiledFunctionCode::Architecture::POWERPC:
ret = PPC32Emulator::assemble(load_file(asm_filename), get_include);
break;
case CompiledFunctionCode::Architecture::X86:
ret = X86Emulator::assemble(load_file(asm_filename), get_include);
break;
case CompiledFunctionCode::Architecture::SH4:
ret = SH4Emulator::assemble(load_file(asm_filename), get_include);
break;
default:
throw runtime_error("unknown architecture");
}
get_include_stack.erase(name);
return ret.code;
}
string bin_filename = function_directory + "/" + name + ".inc.bin";
if (isfile(bin_filename)) {
return load_file(bin_filename);
}
bin_filename = system_directory + "/" + name + ".inc.bin";
if (isfile(bin_filename)) {
return load_file(bin_filename);
}
throw runtime_error("data not found for include: " + name + " (from " + asm_filename + " or " + bin_filename + ")");
};
EmulatorBase::AssembleResult assembled;
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
assembled = PPC32Emulator::assemble(text, get_include);
} else if (arch == CompiledFunctionCode::Architecture::X86) {
throw runtime_error("x86 assembler is not implemented");
assembled = X86Emulator::assemble(text, get_include);
} else if (arch == CompiledFunctionCode::Architecture::SH4) {
assembled = SH4Emulator::assemble(text, get_include);
} else {
throw runtime_error("invalid architecture");
}
ret->code = std::move(assembled.code);
ret->label_offsets = std::move(assembled.label_offsets);
for (const auto& it : assembled.metadata_keys) {
if (it.first == "hide_from_patches_menu") {
ret->hide_from_patches_menu = true;
} else if (it.first == "index") {
if (it.second.size() != 1) {
throw runtime_error("invalid index value in .meta directive");
}
ret->index = it.second[0];
} else if (it.first == "name") {
ret->long_name = it.second;
} else if (it.first == "description") {
ret->description = it.second;
} else {
throw runtime_error("unknown metadata key: " + it.first);
}
}
set<uint32_t> reloc_indexes;
@@ -190,56 +256,95 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
return;
}
uint32_t next_menu_item_id = 0;
for (const auto& filename : list_directory(directory)) {
if (!ends_with(filename, ".s") || ends_with(filename, ".inc.s")) {
string system_dir_path = ends_with(directory, "/") ? (directory + "System") : (directory + "/System");
uint32_t next_menu_item_id = 1;
for (const auto& subdir_name : list_directory_sorted(directory)) {
string subdir_path = ends_with(directory, "/") ? (directory + subdir_name) : (directory + "/" + subdir_name);
if (!isdir(subdir_path)) {
function_compiler_log.warning("Skipping %s (not a directory)", subdir_name.c_str());
continue;
}
bool is_patch = ends_with(filename, ".patch.s");
string name = filename.substr(0, filename.size() - (is_patch ? 8 : 2));
// Check for specific_version token
uint32_t specific_version = 0;
string short_name = name;
if (is_patch &&
(filename.size() >= 13) &&
(filename[filename.size() - 13] == '.') &&
isdigit(filename[filename.size() - 12]) &&
(filename[filename.size() - 11] == 'O' || filename[filename.size() - 11] == 'S') &&
(filename[filename.size() - 10] == 'E' || filename[filename.size() - 10] == 'J' || filename[filename.size() - 10] == 'P') &&
(isdigit(filename[filename.size() - 9]) || filename[filename.size() - 9] == 'T')) {
specific_version = 0x33000000 | (filename[filename.size() - 11] << 16) | (filename[filename.size() - 10] << 8) | filename[filename.size() - 9];
short_name = filename.substr(0, filename.size() - 13);
}
try {
string path = directory + "/" + filename;
string text = load_file(path);
auto code = compile_function_code(CompiledFunctionCode::Architecture::POWERPC, directory, name, text);
if (code->index != 0) {
if (!this->index_to_function.emplace(code->index, code).second) {
throw runtime_error(string_printf(
"duplicate function index: %08" PRIX32, code->index));
for (const auto& filename : list_directory_sorted(subdir_path)) {
try {
if (!ends_with(filename, ".s")) {
continue;
}
}
code->specific_version = specific_version;
code->short_name = short_name;
this->name_to_function.emplace(name, code);
if (is_patch) {
code->menu_item_id = next_menu_item_id++;
this->menu_item_id_and_specific_version_to_patch_function.emplace(
static_cast<uint64_t>(code->menu_item_id) << 32 | specific_version, code);
this->name_and_specific_version_to_patch_function.emplace(
string_printf("%s-%08" PRIX32, short_name.c_str(), specific_version), code);
}
string index_prefix = code->index ? string_printf("%02X => ", code->index) : "";
string patch_prefix = is_patch ? string_printf("[%08" PRIX32 "/%08" PRIX32 "] ", code->menu_item_id, code->specific_version) : "";
function_compiler_log.info("Compiled function %s%s%s (%s)",
index_prefix.c_str(), patch_prefix.c_str(), name.c_str(), name_for_architecture(code->arch));
string name = filename.substr(0, filename.size() - 2);
if (ends_with(name, ".inc")) {
continue;
}
} catch (const exception& e) {
function_compiler_log.warning("Failed to compile function %s: %s", name.c_str(), e.what());
bool is_patch = ends_with(name, ".patch");
if (is_patch) {
name.resize(name.size() - 6);
}
// Figure out the version or specific_version
CompiledFunctionCode::Architecture arch = CompiledFunctionCode::Architecture::UNKNOWN;
uint32_t specific_version = 0;
string short_name = name;
if (ends_with(name, ".ppc")) {
arch = CompiledFunctionCode::Architecture::POWERPC;
name.resize(name.size() - 4);
short_name = name;
} else if (ends_with(name, ".x86")) {
arch = CompiledFunctionCode::Architecture::X86;
name.resize(name.size() - 4);
short_name = name;
} else if (ends_with(name, ".sh4")) {
arch = CompiledFunctionCode::Architecture::SH4;
name.resize(name.size() - 4);
short_name = name;
} else if (is_patch && (name.size() >= 5) && (name[name.size() - 5] == '.')) {
specific_version = (name[name.size() - 4] << 24) | (name[name.size() - 3] << 16) | (name[name.size() - 2] << 8) | name[name.size() - 1];
if (specific_version_is_dc(specific_version)) {
arch = CompiledFunctionCode::Architecture::SH4;
} else if (specific_version_is_gc(specific_version)) {
arch = CompiledFunctionCode::Architecture::POWERPC;
} else if (specific_version_is_xb(specific_version) || specific_version_is_bb(specific_version)) {
arch = CompiledFunctionCode::Architecture::X86;
} else {
throw runtime_error("unable to determine architecture from specific_version");
}
short_name = name.substr(0, name.size() - 5);
}
if (arch == CompiledFunctionCode::Architecture::UNKNOWN) {
throw runtime_error("unable to determine architecture");
}
string path = subdir_path + "/" + filename;
string text = load_file(path);
auto code = compile_function_code(arch, subdir_path, system_dir_path, name, text);
if (code->index != 0) {
if (!this->index_to_function.emplace(code->index, code).second) {
throw runtime_error(string_printf(
"duplicate function index: %08" PRIX32, code->index));
}
}
code->specific_version = specific_version;
code->source_path = path;
code->short_name = short_name;
this->name_to_function.emplace(name, code);
if (is_patch) {
code->menu_item_id = next_menu_item_id++;
this->menu_item_id_and_specific_version_to_patch_function.emplace(
static_cast<uint64_t>(code->menu_item_id) << 32 | specific_version, code);
this->name_and_specific_version_to_patch_function.emplace(
string_printf("%s-%08" PRIX32, short_name.c_str(), specific_version), code);
}
string index_prefix = code->index ? string_printf("%02X => ", code->index) : "";
string patch_prefix = is_patch ? string_printf("[%08" PRIX32 "/%08" PRIX32 "] ", code->menu_item_id, code->specific_version) : "";
function_compiler_log.info("Compiled function %s%s%s (%s)",
index_prefix.c_str(), patch_prefix.c_str(), name.c_str(), name_for_architecture(code->arch));
} catch (const exception& e) {
function_compiler_log.warning("Failed to compile function %s: %s", filename.c_str(), e.what());
}
}
}
}
@@ -251,13 +356,33 @@ shared_ptr<const Menu> FunctionCodeIndex::patch_menu(uint32_t specific_version)
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
for (const auto& it : this->name_and_specific_version_to_patch_function) {
const auto& fn = it.second;
if (!fn->hide_from_patches_menu && ends_with(it.first, suffix)) {
ret->items.emplace_back(
fn->menu_item_id,
fn->long_name.empty() ? fn->short_name : fn->long_name,
fn->description,
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
if (fn->hide_from_patches_menu || !ends_with(it.first, suffix)) {
continue;
}
ret->items.emplace_back(
fn->menu_item_id,
fn->long_name.empty() ? fn->short_name : fn->long_name,
fn->description,
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
}
return ret;
}
shared_ptr<const Menu> FunctionCodeIndex::patch_switches_menu(
uint32_t specific_version, const std::unordered_set<std::string>& auto_patches_enabled) const {
auto suffix = string_printf("-%08" PRIX32, specific_version);
auto ret = make_shared<Menu>(MenuID::PATCH_SWITCHES, "Patch switches");
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0);
for (const auto& it : this->name_and_specific_version_to_patch_function) {
const auto& fn = it.second;
if (fn->hide_from_patches_menu || !ends_with(it.first, suffix)) {
continue;
}
string name;
name.push_back(auto_patches_enabled.count(fn->short_name) ? '*' : '-');
name += fn->long_name.empty() ? fn->short_name : fn->long_name;
ret->items.emplace_back(fn->menu_item_id, name, fn->description, MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
}
return ret;
}
@@ -271,6 +396,12 @@ bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
return true;
}
std::shared_ptr<const CompiledFunctionCode> FunctionCodeIndex::get_patch(
const std::string& name, uint32_t specific_version) const {
return this->name_and_specific_version_to_patch_function.at(
string_printf("%s-%08" PRIX32, name.c_str(), specific_version));
}
DOLFileIndex::DOLFileIndex(const string& directory) {
if (!function_compiler_available()) {
function_compiler_log.info("Function compiler is not available");
@@ -360,7 +491,7 @@ uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum) {
char developer_code2 = 'P';
uint8_t disc_number = 0;
uint8_t version_code;
} __attribute__((packed)) data;
} __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++) {
+7 -1
View File
@@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "Menu.hh"
@@ -18,7 +19,8 @@ void set_function_compiler_available(bool is_available);
struct CompiledFunctionCode {
enum class Architecture {
POWERPC = 0, // GC
UNKNOWN = 0,
POWERPC, // GC
X86, // PC, XB, BB
SH4, // Dreamcast
};
@@ -27,6 +29,7 @@ struct CompiledFunctionCode {
std::vector<uint16_t> relocation_deltas;
std::unordered_map<std::string, uint32_t> label_offsets;
uint32_t entrypoint_offset_offset;
std::string source_path; // Path to source file from newserv root
std::string short_name; // Based on filename
std::string long_name; // From .meta name directive
std::string description; // From .meta description directive
@@ -67,7 +70,10 @@ struct FunctionCodeIndex {
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
std::shared_ptr<const Menu> patch_menu(uint32_t specific_version) const;
std::shared_ptr<const Menu> patch_switches_menu(uint32_t specific_version, const std::unordered_set<std::string>& auto_patches_enabled) const;
bool patch_menu_empty(uint32_t specific_version) const;
std::shared_ptr<const CompiledFunctionCode> get_patch(const std::string& name, uint32_t specific_version) const;
};
struct DOLFileIndex {
+10 -5
View File
@@ -9,21 +9,26 @@
using namespace std;
template <bool IsBigEndian>
struct GSLHeaderEntry {
struct GSLHeaderEntryT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
pstring<TextEncoding::ASCII, 0x20> filename;
U32T offset; // In pages, so actual offset is this * 0x800
U32T size;
uint64_t unused;
} __attribute__((packed));
} __packed__;
using GSLHeaderEntry = GSLHeaderEntryT<false>;
using GSLHeaderEntryBE = GSLHeaderEntryT<true>;
check_struct_size(GSLHeaderEntry, 0x30);
check_struct_size(GSLHeaderEntryBE, 0x30);
template <bool IsBigEndian>
void GSLArchive::load_t() {
StringReader r(*this->data);
uint64_t min_data_offset = 0xFFFFFFFFFFFFFFFF;
while (r.where() < min_data_offset) {
const auto& entry = r.get<GSLHeaderEntry<IsBigEndian>>();
const auto& entry = r.get<GSLHeaderEntryT<IsBigEndian>>();
if (entry.filename.empty()) {
break;
}
@@ -85,10 +90,10 @@ string GSLArchive::generate_t(const unordered_map<string, string>& files) {
// Make sure there's enough space for a blank header entry before any file's
// data pages begin
uint32_t data_start_offset = ((sizeof(GSLHeaderEntry<IsBigEndian>) * (files.size() + 1)) + 0x7FF) & (~0x7FF);
uint32_t data_start_offset = ((sizeof(GSLHeaderEntryT<IsBigEndian>) * (files.size() + 1)) + 0x7FF) & (~0x7FF);
uint32_t data_offset = data_start_offset;
for (const auto& file : files) {
GSLHeaderEntry<IsBigEndian> entry;
GSLHeaderEntryT<IsBigEndian> entry;
entry.filename.encode(file.first);
entry.offset = data_offset >> 11;
entry.size = file.second.size();
+32 -21
View File
@@ -11,15 +11,18 @@ using namespace std;
struct GVMFileEntry {
be_uint16_t file_num;
pstring<TextEncoding::ASCII, 0x1C> name;
parray<be_uint32_t, 2> unknown_a1;
} __attribute__((packed));
uint8_t format_flags; // Same as in GVRHeader
GVRDataFormat data_format; // Same as in GVRHeader
be_uint16_t dimensions; // As powers of two in low nybbles (so e.g. 128x128 = 0x0055)
be_uint32_t global_index;
} __packed_ws__(GVMFileEntry, 0x26);
struct GVMFileHeader {
be_uint32_t magic; // 'GVMH'
be_uint32_t signature; // 'GVMH'
le_uint32_t header_size;
be_uint16_t flags;
be_uint16_t flags; // Specifies which fields are present in GVMFileEntries; we always use 0xF (all fields present)
be_uint16_t num_files;
} __attribute__((packed));
} __packed_ws__(GVMFileHeader, 0x0C);
struct GVRHeader {
be_uint32_t magic; // 'GVRT'
@@ -29,21 +32,26 @@ struct GVRHeader {
GVRDataFormat data_format;
be_uint16_t width;
be_uint16_t height;
} __attribute__((packed));
} __packed_ws__(GVRHeader, 0x10);
string encode_gvm(const Image& img, GVRDataFormat data_format) {
if (img.get_width() > 0xFFFF) {
throw runtime_error("image is too wide to be encoded as a GVR texture");
}
if (img.get_height() > 0xFFFF) {
throw runtime_error("image is too tall to be encoded as a GVR texture");
}
if (img.get_width() & 3) {
throw runtime_error("image width is not a multiple of 4");
}
if (img.get_height() & 3) {
throw runtime_error("image height is not a multiple of 4");
string encode_gvm(const Image& img, GVRDataFormat data_format, const std::string& internal_name, uint32_t global_index) {
int8_t dimensions_field = -2;
{
size_t h = img.get_height();
size_t w = img.get_width();
if ((h != w) || (w & (w - 1)) || (h & (h - 1))) {
throw runtime_error("image must be square and dimensions must be powers of 2");
}
for (w >>= 1; w; w >>= 1, dimensions_field++) {
}
if (dimensions_field < 1) {
throw runtime_error("image is too small");
}
if (dimensions_field > 0xF) {
throw runtime_error("image is too large");
}
}
size_t pixel_count = img.get_width() * img.get_height();
size_t pixel_bytes = 0;
switch (data_format) {
@@ -59,11 +67,14 @@ string encode_gvm(const Image& img, GVRDataFormat data_format) {
}
StringWriter w;
w.put<GVMFileHeader>({.magic = 0x47564D48, .header_size = 0x48, .flags = 0x010F, .num_files = 1});
w.put<GVMFileHeader>({.signature = 0x47564D48, .header_size = 0x48, .flags = 0x000F, .num_files = 1});
GVMFileEntry file_entry;
file_entry.file_num = 0;
file_entry.name.encode("img", 1);
file_entry.unknown_a1.clear(0);
file_entry.name.encode(internal_name, 1);
file_entry.data_format = data_format;
file_entry.format_flags = 0;
file_entry.dimensions = (dimensions_field << 4) | dimensions_field;
file_entry.global_index = global_index;
w.put(file_entry);
w.extend_to(0x50, 0x00);
w.put<GVRHeader>({.magic = 0x47565254,
+17 -17
View File
@@ -19,7 +19,7 @@ enum class GVRDataFormat : uint8_t {
DXT1 = 0x0E,
};
std::string encode_gvm(const Image& img, GVRDataFormat data_format);
std::string encode_gvm(const Image& img, GVRDataFormat data_format, const std::string& internal_name, uint32_t global_index);
constexpr uint16_t encode_rgb565(uint8_t r, uint8_t g, uint8_t b) {
return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F);
@@ -37,23 +37,23 @@ constexpr uint32_t encode_argb8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
return (a << 24) | (r << 16) | (g << 8) | b;
}
constexpr uint16_t encode_xrgb8888_to_xrgb1555(uint32_t xrgb8888) {
constexpr uint16_t encode_argb8888_to_argb1555(uint32_t argb8888) {
// In: aaaaaaaarrrrrrrrggggggggbbbbbbbb
// Out: arrrrrgggggbbbbb
return ((argb8888 >> 9) & 0x7C00) | ((argb8888 >> 6) & 0x03E0) | ((argb8888 >> 3) & 0x001F) | ((argb8888 >> 16) & 0x8000);
}
constexpr uint16_t encode_rgba8888_to_argb1555(uint32_t rgba8888) {
// In: rrrrrrrrggggggggbbbbbbbbaaaaaaaa
// Out: -rrrrrgggggbbbbb
return ((xrgb8888 >> 9) & 0x7C00) | ((xrgb8888 >> 6) & 0x03E0) | ((xrgb8888 >> 3) & 0x001F);
// Out: arrrrrgggggbbbbb
return ((rgba8888 >> 17) & 0x7C00) | ((rgba8888 >> 14) & 0x03E0) | ((rgba8888 >> 11) & 0x001F) | ((rgba8888 << 8) & 0x8000);
}
constexpr uint16_t encode_rgbx8888_to_xrgb1555(uint32_t rgbx8888) {
// In: rrrrrrrrggggggggbbbbbbbbxxxxxxxx
// Out: -rrrrrgggggbbbbb
return ((rgbx8888 >> 17) & 0x7C00) | ((rgbx8888 >> 14) & 0x03E0) | ((rgbx8888 >> 11) & 0x001F);
}
constexpr uint32_t decode_xrgb1555_to_rgba8888(uint16_t xrgb1555) {
// In: -rrrrrgggggbbbbb
// Out: rrrrrrrrggggggggbbbbbbbbaaaaaaaa (a is always FF)
return ((xrgb1555 << 17) & 0xF8000000) | ((xrgb1555 << 12) & 0x07000000) |
((xrgb1555 << 14) & 0x00F80000) | ((xrgb1555 << 9) & 0x00070000) |
((xrgb1555 << 11) & 0x0000F800) | ((xrgb1555 << 6) & 0x00000700) |
0x000000FF;
constexpr uint32_t decode_argb1555_to_rgba8888(uint16_t argb1555) {
// In: arrrrrgggggbbbbb
// Out: rrrrrrrrggggggggbbbbbbbbaaaaaaaa
return ((argb1555 << 17) & 0xF8000000) | ((argb1555 << 12) & 0x07000000) |
((argb1555 << 14) & 0x00F80000) | ((argb1555 << 9) & 0x00070000) |
((argb1555 << 11) & 0x0000F800) | ((argb1555 << 6) & 0x00000700) |
((argb1555 & 0x8000) ? 0x000000FF : 0x00000000);
}
+1023
View File
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
#pragma once
#include <event2/buffer.h>
#include <event2/event.h>
#include <event2/http.h>
#include <stdlib.h>
#include <memory>
#include <string>
#include "ProxyServer.hh"
#include "ServerState.hh"
class HTTPServer {
public:
HTTPServer(std::shared_ptr<ServerState> state);
HTTPServer(const HTTPServer&) = delete;
HTTPServer(HTTPServer&&) = delete;
HTTPServer& operator=(const HTTPServer&) = delete;
HTTPServer& operator=(HTTPServer&&) = delete;
virtual ~HTTPServer() = default;
void listen(const std::string& socket_path);
void listen(const std::string& addr, int port);
void listen(int port);
void add_socket(int fd);
void schedule_stop();
void wait_for_stop();
protected:
class http_error : public std::runtime_error {
public:
http_error(int code, const std::string& what);
int code;
};
std::shared_ptr<ServerState> state;
std::shared_ptr<struct event_base> base;
std::shared_ptr<struct evhttp> http;
std::thread th;
void thread_fn();
static void dispatch_handle_request(struct evhttp_request* req, void* ctx);
void handle_request(struct evhttp_request* req);
static const std::unordered_map<int, const char*> explanation_for_response_code;
static void send_response(struct evhttp_request* req, int code, const char* content_type, struct evbuffer* b);
static void send_response(struct evhttp_request* req, int code, const char* content_type, const char* fmt, ...);
static std::unordered_multimap<std::string, std::string> parse_url_params(const std::string& query);
static std::unordered_map<std::string, std::string> parse_url_params_unique(const std::string& query);
static const std::string& get_url_param(
const std::unordered_multimap<std::string, std::string>& params,
const std::string& key,
const std::string* _default = nullptr);
static JSON generate_quest_json_st(std::shared_ptr<const Quest> q);
static JSON generate_client_config_json_st(const Client::Config& config);
static JSON generate_account_json_st(std::shared_ptr<const Account> a);
static JSON generate_game_client_json_st(std::shared_ptr<const Client> c, std::shared_ptr<const ItemNameIndex> item_name_index);
static JSON generate_proxy_client_json_st(std::shared_ptr<const ProxyServer::LinkedSession> ses);
static JSON generate_lobby_json_st(std::shared_ptr<const Lobby> l, std::shared_ptr<const ItemNameIndex> item_name_index);
JSON generate_game_server_clients_json() const;
JSON generate_proxy_server_clients_json() const;
JSON generate_server_info_json() const;
JSON generate_lobbies_json() const;
JSON generate_summary_json() const;
JSON generate_all_json() const;
JSON generate_ep3_cards_json(bool trial) const;
JSON generate_common_tables_json() const;
JSON generate_rare_tables_json() const;
JSON generate_rare_table_json(const std::string& table_name) const;
};
+10 -10
View File
@@ -12,31 +12,31 @@ struct HDLCHeader {
uint8_t address; // 0xFF usually
uint8_t control; // 0x03 for PPP
be_uint16_t protocol;
} __attribute__((packed));
} __packed_ws__(HDLCHeader, 5);
struct LCPHeader {
uint8_t command;
uint8_t request_id;
be_uint16_t size;
} __attribute__((packed));
} __packed_ws__(LCPHeader, 4);
struct PAPHeader {
uint8_t command;
uint8_t request_id;
be_uint16_t size;
} __attribute__((packed));
} __packed_ws__(PAPHeader, 4);
struct IPCPHeader {
uint8_t command;
uint8_t request_id;
be_uint16_t size;
} __attribute__((packed));
} __packed_ws__(IPCPHeader, 4);
struct EthernetHeader {
parray<uint8_t, 6> dest_mac;
parray<uint8_t, 6> src_mac;
be_uint16_t protocol;
} __attribute__((packed));
} __packed_ws__(EthernetHeader, 0x0E);
struct ARPHeader {
be_uint16_t hardware_type;
@@ -44,7 +44,7 @@ struct ARPHeader {
uint8_t hwaddr_len;
uint8_t paddr_len;
be_uint16_t operation;
} __attribute__((packed));
} __packed_ws__(ARPHeader, 8);
struct IPv4Header {
uint8_t version_ihl;
@@ -57,14 +57,14 @@ struct IPv4Header {
be_uint16_t checksum;
be_uint32_t src_addr;
be_uint32_t dest_addr;
} __attribute__((packed));
} __packed_ws__(IPv4Header, 0x14);
struct UDPHeader {
be_uint16_t src_port;
be_uint16_t dest_port;
be_uint16_t size;
be_uint16_t checksum;
} __attribute__((packed));
} __packed_ws__(UDPHeader, 8);
struct TCPHeader {
enum Flag {
@@ -87,7 +87,7 @@ struct TCPHeader {
be_uint16_t window;
be_uint16_t checksum;
be_uint16_t urgent_ptr;
} __attribute__((packed));
} __packed_ws__(TCPHeader, 0x14);
struct DHCPHeader {
uint8_t opcode = 0;
@@ -105,7 +105,7 @@ struct DHCPHeader {
parray<uint8_t, 0xC0> unused_bootp_legacy;
be_uint32_t magic = 0x63825363;
// Options follow here, terminated with FF
} __attribute__((packed));
} __packed_ws__(DHCPHeader, 0xF0);
struct FrameInfo {
enum class LinkType {
+157 -95
View File
@@ -124,6 +124,7 @@ IPStackSimulator::IPStackSimulator(
shared_ptr<ServerState> state)
: base(base),
state(state),
next_network_id(1),
pcap_text_log_file(state->ip_stack_debug ? fopen("IPStackSimulator-Log.txt", "wt") : nullptr) {
this->host_mac_address_bytes.clear(0x90);
this->broadcast_mac_address_bytes.clear(0xFF);
@@ -135,28 +136,28 @@ IPStackSimulator::~IPStackSimulator() {
}
}
void IPStackSimulator::listen(const string& name, const string& socket_path, FrameInfo::LinkType link_type) {
void IPStackSimulator::listen(const string& name, const string& socket_path, Protocol proto) {
int fd = ::listen(socket_path, 0, SOMAXCONN);
ip_stack_simulator_log.info("Listening on Unix socket %s on fd %d as %s", socket_path.c_str(), fd, name.c_str());
this->add_socket(name, fd, link_type);
this->add_socket(name, fd, proto);
}
void IPStackSimulator::listen(const string& name, const string& addr, int port, FrameInfo::LinkType link_type) {
void IPStackSimulator::listen(const string& name, const string& addr, int port, Protocol proto) {
if (port == 0) {
this->listen(name, addr, link_type);
this->listen(name, addr, proto);
} else {
int fd = ::listen(addr, port, SOMAXCONN);
string netloc_str = render_netloc(addr, port);
ip_stack_simulator_log.info("Listening on TCP interface %s on fd %d as %s", netloc_str.c_str(), fd, name.c_str());
this->add_socket(name, fd, link_type);
this->add_socket(name, fd, proto);
}
}
void IPStackSimulator::listen(const string& name, int port, FrameInfo::LinkType link_type) {
this->listen(name, "", port, link_type);
void IPStackSimulator::listen(const string& name, int port, Protocol proto) {
this->listen(name, "", port, proto);
}
void IPStackSimulator::add_socket(const string& name, int fd, FrameInfo::LinkType link_type) {
void IPStackSimulator::add_socket(const string& name, int fd, Protocol proto) {
unique_listener l(
evconnlistener_new(
this->base.get(),
@@ -166,7 +167,11 @@ void IPStackSimulator::add_socket(const string& name, int fd, FrameInfo::LinkTyp
0,
fd),
evconnlistener_free);
this->listening_sockets.emplace(piecewise_construct, forward_as_tuple(fd), forward_as_tuple(name, link_type, std::move(l)));
this->listening_sockets.emplace(piecewise_construct, forward_as_tuple(fd), forward_as_tuple(name, proto, std::move(l)));
}
shared_ptr<IPStackSimulator::IPClient> IPStackSimulator::get_network(uint64_t network_id) const {
return this->network_id_to_client.at(network_id);
}
uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_addr) {
@@ -180,14 +185,17 @@ uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_ad
}
}
IPStackSimulator::IPClient::IPClient(shared_ptr<IPStackSimulator> sim, FrameInfo::LinkType link_type, struct bufferevent* bev)
IPStackSimulator::IPClient::IPClient(
shared_ptr<IPStackSimulator> sim, uint64_t network_id, Protocol protocol, struct bufferevent* bev)
: sim(sim),
network_id(network_id),
bev(bev, bufferevent_free),
link_type(link_type),
protocol(protocol),
mac_addr(0),
ipv4_addr(0),
idle_timeout_event(event_new(sim->base.get(), -1, EV_TIMEOUT, &IPStackSimulator::IPClient::dispatch_on_idle_timeout, this), event_free) {
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
uint64_t idle_timeout_usecs = sim->state->client_idle_timeout_usecs;
struct timeval tv = usecs_to_timeval(idle_timeout_usecs);
event_add(this->idle_timeout_event.get(), &tv);
}
@@ -199,7 +207,7 @@ void IPStackSimulator::IPClient::on_idle_timeout() {
auto sim = this->sim.lock();
if (sim) {
ip_stack_simulator_log.info("Idle timeout expired on virtual network %d", bufferevent_getfd(this->bev.get()));
sim->disconnect_client(this->bev.get());
sim->disconnect_client(this->network_id);
} else {
ip_stack_simulator_log.info("Idle timeout expired on virtual network %d, but simulator is missing", bufferevent_getfd(this->bev.get()));
}
@@ -226,40 +234,45 @@ IPStackSimulator::IPClient::TCPConnection::TCPConnection()
bytes_received(0),
bytes_sent(0) {}
void IPStackSimulator::disconnect_client(struct bufferevent* bev) {
ip_stack_simulator_log.info("Virtual network %d disconnected", bufferevent_getfd(bev));
this->bev_to_client.erase(bev);
void IPStackSimulator::disconnect_client(uint64_t network_id) {
ip_stack_simulator_log.info("Virtual network N-%" PRIu64 " disconnected", network_id);
this->network_id_to_client.erase(network_id);
}
void IPStackSimulator::dispatch_on_listen_accept(
struct evconnlistener* listener, evutil_socket_t fd,
struct sockaddr* address, int socklen, void* ctx) {
reinterpret_cast<IPStackSimulator*>(ctx)->on_listen_accept(
listener, fd, address, socklen);
reinterpret_cast<IPStackSimulator*>(ctx)->on_listen_accept(listener, fd, address, socklen);
}
void IPStackSimulator::on_listen_accept(struct evconnlistener* listener,
evutil_socket_t fd, struct sockaddr*, int) {
void IPStackSimulator::on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr*, int) {
struct sockaddr_storage remote_addr;
get_socket_addresses(fd, nullptr, &remote_addr);
if (this->state->banned_ipv4_ranges->check(remote_addr)) {
close(fd);
return;
}
int listen_fd = evconnlistener_get_fd(listener);
const ListeningSocket* listening_socket;
try {
listening_socket = &this->listening_sockets.at(listen_fd);
} catch (const out_of_range&) {
ip_stack_simulator_log.info("Virtual network %d connected via unknown listener %d; disconnecting", fd, listen_fd);
ip_stack_simulator_log.info("Virtual network fd %d connected via unknown listener %d; disconnecting", fd, listen_fd);
close(fd);
return;
}
ip_stack_simulator_log.info("Virtual network %d connected via %s", fd, listening_socket->name.c_str());
uint64_t network_id = this->next_network_id++;
ip_stack_simulator_log.info("Virtual network N-%" PRIu64 " connected via %s", network_id, listening_socket->name.c_str());
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd,
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
auto c = make_shared<IPClient>(this->shared_from_this(), listening_socket->link_type, bev);
this->bev_to_client.emplace(make_pair(bev, c));
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
auto c = make_shared<IPClient>(this->shared_from_this(), network_id, listening_socket->protocol, bev);
this->network_id_to_client.emplace(c->network_id, c);
bufferevent_setcb(bev, &IPStackSimulator::dispatch_on_client_input, nullptr,
&IPStackSimulator::dispatch_on_client_error, this);
bufferevent_setcb(bev, &IPStackSimulator::IPClient::dispatch_on_client_input, nullptr,
&IPStackSimulator::IPClient::dispatch_on_client_error, c.get());
bufferevent_enable(bev, EV_READ | EV_WRITE);
}
@@ -275,61 +288,99 @@ void IPStackSimulator::on_listen_error(struct evconnlistener* listener) {
event_base_loopexit(this->base.get(), nullptr);
}
void IPStackSimulator::dispatch_on_client_input(
struct bufferevent* bev, void* ctx) {
reinterpret_cast<IPStackSimulator*>(ctx)->on_client_input(bev);
void IPStackSimulator::IPClient::dispatch_on_client_input(struct bufferevent* bev, void* ctx) {
reinterpret_cast<IPClient*>(ctx)->on_client_input(bev);
}
void IPStackSimulator::on_client_input(struct bufferevent* bev) {
void IPStackSimulator::IPClient::on_client_input(struct bufferevent* bev) {
struct evbuffer* buf = bufferevent_get_input(bev);
shared_ptr<IPClient> c;
try {
c = this->bev_to_client.at(bev);
} catch (const out_of_range&) {
auto sim = this->sim.lock();
if (!sim) {
size_t bytes = evbuffer_get_length(buf);
ip_stack_simulator_log.warning("Ignoring data received from unregistered virtual network (0x%zX bytes)",
bytes);
ip_stack_simulator_log.warning("Ignoring data from unregistered virtual network (0x%zX bytes)", bytes);
evbuffer_drain(buf, bytes);
return;
}
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
event_add(c->idle_timeout_event.get(), &tv);
uint64_t idle_timeout_usecs = sim ? sim->state->client_idle_timeout_usecs : 60000000;
struct timeval tv = usecs_to_timeval(idle_timeout_usecs);
event_add(this->idle_timeout_event.get(), &tv);
while (evbuffer_get_length(buf) >= 2) {
uint16_t frame_size;
evbuffer_copyout(buf, &frame_size, 2);
if (evbuffer_get_length(buf) < static_cast<size_t>(frame_size + 2)) {
break; // No complete frame available; done for now
}
switch (this->protocol) {
case Protocol::ETHERNET_TAPSERVER:
case Protocol::HDLC_TAPSERVER:
while (evbuffer_get_length(buf) >= 2) {
uint16_t frame_size;
evbuffer_copyout(buf, &frame_size, 2);
if (evbuffer_get_length(buf) < static_cast<size_t>(frame_size + 2)) {
break; // No complete frame available; done for now
}
evbuffer_drain(buf, 2);
string frame(frame_size, '\0');
evbuffer_remove(buf, frame.data(), frame.size());
evbuffer_drain(buf, 2);
string frame(frame_size, '\0');
evbuffer_remove(buf, frame.data(), frame.size());
try {
this->on_client_frame(c, frame);
} catch (const exception& e) {
if (ip_stack_simulator_log.warning("Failed to process frame: %s", e.what())) {
print_data(stderr, frame);
try {
sim->on_client_frame(this->shared_from_this(), frame);
} catch (const exception& e) {
if (ip_stack_simulator_log.warning("Failed to process frame: %s", e.what())) {
print_data(stderr, frame);
}
}
}
}
break;
case Protocol::HDLC_RAW:
while (evbuffer_get_length(buf) >= 2) {
struct evbuffer_ptr res = evbuffer_search(buf, "\x7E", 1, nullptr);
if (res.pos < 0) {
break;
}
size_t start_offset = res.pos;
if (evbuffer_ptr_set(buf, &res, 1, EVBUFFER_PTR_ADD)) {
ip_stack_simulator_log.warning("Cannot advance search for end of frame");
break;
}
struct evbuffer_ptr end_res = evbuffer_search(buf, "\x7E", 1, &res);
if (end_res.pos < 0) {
break;
}
size_t frame_size = end_res.pos + 1 - start_offset;
if (start_offset) {
evbuffer_drain(buf, start_offset);
}
string frame(frame_size, '\0');
evbuffer_remove(buf, frame.data(), frame.size());
try {
sim->on_client_frame(this->shared_from_this(), frame);
} catch (const exception& e) {
if (ip_stack_simulator_log.warning("Failed to process frame: %s", e.what())) {
print_data(stderr, frame);
}
}
}
break;
}
}
void IPStackSimulator::dispatch_on_client_error(
struct bufferevent* bev, short events, void* ctx) {
reinterpret_cast<IPStackSimulator*>(ctx)->on_client_error(bev, events);
void IPStackSimulator::IPClient::dispatch_on_client_error(struct bufferevent* bev, short events, void* ctx) {
reinterpret_cast<IPClient*>(ctx)->on_client_error(bev, events);
}
void IPStackSimulator::on_client_error(struct bufferevent* bev, short events) {
void IPStackSimulator::IPClient::on_client_error(struct bufferevent*, short events) {
if (events & BEV_EVENT_ERROR) {
int err = EVUTIL_SOCKET_ERROR();
ip_stack_simulator_log.warning("Virtual network caused error %d (%s)", err,
evutil_socket_error_to_string(err));
ip_stack_simulator_log.warning("Virtual network caused error %d (%s)", err, evutil_socket_error_to_string(err));
}
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
this->disconnect_client(bev);
auto sim = this->sim.lock();
if (sim) {
sim->disconnect_client(this->network_id);
}
}
}
@@ -340,8 +391,8 @@ void IPStackSimulator::send_layer3_frame(shared_ptr<IPClient> c, FrameInfo::Prot
void IPStackSimulator::send_layer3_frame(shared_ptr<IPClient> c, FrameInfo::Protocol proto, const void* data, size_t size) const {
struct evbuffer* out_buf = bufferevent_get_output(c->bev.get());
switch (c->link_type) {
case FrameInfo::LinkType::ETHERNET: {
switch (c->protocol) {
case Protocol::ETHERNET_TAPSERVER: {
EthernetHeader ether;
ether.dest_mac = c->mac_addr;
ether.src_mac = this->host_mac_address_bytes;
@@ -373,7 +424,8 @@ void IPStackSimulator::send_layer3_frame(shared_ptr<IPClient> c, FrameInfo::Prot
break;
}
case FrameInfo::LinkType::HDLC: {
case Protocol::HDLC_TAPSERVER:
case Protocol::HDLC_RAW: {
HDLCHeader hdlc;
hdlc.start_sentinel1 = 0x7E;
hdlc.address = 0xFF;
@@ -410,8 +462,10 @@ void IPStackSimulator::send_layer3_frame(shared_ptr<IPClient> c, FrameInfo::Prot
print_data(stderr, w.str());
}
le_uint16_t frame_size = escaped.size();
evbuffer_add(out_buf, &frame_size, 2);
if (c->protocol == Protocol::HDLC_TAPSERVER) {
le_uint16_t frame_size = escaped.size();
evbuffer_add(out_buf, &frame_size, 2);
}
evbuffer_add(out_buf, escaped.data(), escaped.size());
if (this->pcap_text_log_file) {
this->log_frame(escaped);
@@ -425,9 +479,13 @@ void IPStackSimulator::send_layer3_frame(shared_ptr<IPClient> c, FrameInfo::Prot
}
void IPStackSimulator::on_client_frame(shared_ptr<IPClient> c, const string& frame) {
FrameInfo::LinkType link_type = (c->protocol == Protocol::ETHERNET_TAPSERVER)
? FrameInfo::LinkType::ETHERNET
: FrameInfo::LinkType::HDLC;
const string* effective_data = &frame;
string hdlc_unescaped_data;
if (c->link_type == FrameInfo::LinkType::HDLC) {
if (link_type == FrameInfo::LinkType::HDLC) {
hdlc_unescaped_data = unescape_hdlc_frame(frame);
effective_data = &hdlc_unescaped_data;
}
@@ -436,7 +494,7 @@ void IPStackSimulator::on_client_frame(shared_ptr<IPClient> c, const string& fra
}
this->log_frame(*effective_data);
FrameInfo fi(c->link_type, *effective_data);
FrameInfo fi(link_type, *effective_data);
if (ip_stack_simulator_log.should_log(LogLevel::DEBUG)) {
string fi_header = fi.header_str();
ip_stack_simulator_log.debug("Frame header: %s", fi_header.c_str());
@@ -1116,6 +1174,7 @@ void IPStackSimulator::on_client_tcp_frame(
throw runtime_error("non-SYN frame does not correspond to any open TCP connection");
}
bool conn_valid = true;
bool acked_seq_changed = false;
if (fi.tcp->flags & TCPHeader::Flag::ACK) {
ip_stack_simulator_log.debug("Client sent ACK %08" PRIX32, fi.tcp->ack_num.load());
@@ -1139,6 +1198,7 @@ void IPStackSimulator::on_client_tcp_frame(
conn->acked_server_seq += ack_delta;
conn->resend_push_usecs = DEFAULT_RESEND_PUSH_USECS;
conn->next_push_max_frame_size = conn->max_frame_size;
acked_seq_changed = true;
ip_stack_simulator_log.debug("Removed %08" PRIX32 " bytes from pending buffer and advanced acked_server_seq to %08" PRIX32,
ack_delta, conn->acked_server_seq);
@@ -1248,9 +1308,9 @@ void IPStackSimulator::on_client_tcp_frame(
conn_str.c_str(), conn->acked_server_seq, conn->next_client_seq, conn->bytes_received);
}
if (conn_valid) {
if (conn_valid && acked_seq_changed) {
// Try to send some more data if the client is waiting on it
this->send_pending_push_frame(c, *conn);
this->send_pending_push_frame(c, *conn, true);
}
}
}
@@ -1283,40 +1343,45 @@ void IPStackSimulator::open_server_connection(shared_ptr<IPClient> c, IPClient::
string conn_str = this->str_for_tcp_connection(c, conn);
if (port_config->behavior == ServerBehavior::PROXY_SERVER) {
if (!this->state->proxy_server.get()) {
ip_stack_simulator_log.error("TCP connection %s is to non-running proxy server",
conn_str.c_str());
ip_stack_simulator_log.error("TCP connection %s is to non-running proxy server", conn_str.c_str());
flush_and_free_bufferevent(bevs[1]);
} else {
this->state->proxy_server->connect_client(bevs[1], conn.server_port);
ip_stack_simulator_log.info("Connected TCP connection %s to proxy server",
conn_str.c_str());
this->state->proxy_server->connect_virtual_client(bevs[1], c->network_id, conn.server_port);
ip_stack_simulator_log.info("Connected TCP connection %s to proxy server", conn_str.c_str());
}
} else if (this->state->game_server.get()) {
this->state->game_server->connect_client(bevs[1], c->ipv4_addr,
conn.client_port, conn.server_port, port_config->version,
port_config->behavior);
ip_stack_simulator_log.info("Connected TCP connection %s to game server",
conn_str.c_str());
this->state->game_server->connect_virtual_client(
bevs[1], c->network_id, c->ipv4_addr, conn.client_port,
conn.server_port, port_config->version, port_config->behavior);
ip_stack_simulator_log.info("Connected TCP connection %s to game server", conn_str.c_str());
} else {
ip_stack_simulator_log.error("No server available for TCP connection %s",
conn_str.c_str());
ip_stack_simulator_log.error("No server available for TCP connection %s", conn_str.c_str());
flush_and_free_bufferevent(bevs[1]);
}
}
void IPStackSimulator::send_pending_push_frame(shared_ptr<IPClient> c, IPClient::TCPConnection& conn) {
void IPStackSimulator::send_pending_push_frame(
shared_ptr<IPClient> c, IPClient::TCPConnection& conn, bool always_send) {
size_t pending_bytes = evbuffer_get_length(conn.pending_data.get());
if (!pending_bytes) {
event_del(conn.resend_push_event.get());
return;
}
// If we're waiting to receive an ACK from the client, don't send another PSH
// until we get the ACK (unless this is a resend of a previous PSH due to a
// timeout)
if (!always_send && event_pending(conn.resend_push_event.get(), EV_TIMEOUT, nullptr)) {
return;
}
size_t bytes_to_send = min<size_t>(pending_bytes, conn.next_push_max_frame_size);
if ((c->link_type == FrameInfo::LinkType::HDLC) && (bytes_to_send > 200)) {
if (c->protocol == Protocol::HDLC_TAPSERVER) {
// There is a bug in Dolphin's modem implementation (which I wrote, so it's
// my fault) that causes commands to be dropped when too much data is sent
// at once. To work around this, we only send up to 200 bytes in each push
// frame.
bytes_to_send = 200;
bytes_to_send = min<size_t>(bytes_to_send, 200);
}
ip_stack_simulator_log.debug("Sending PSH frame with seq_num %08" PRIX32 ", 0x%zX/0x%zX data bytes",
@@ -1335,8 +1400,7 @@ void IPStackSimulator::send_pending_push_frame(shared_ptr<IPClient> c, IPClient:
if (conn.resend_push_usecs > 5000000) {
conn.resend_push_usecs = 5000000;
}
conn.next_push_max_frame_size = max<size_t>(
0x100, conn.next_push_max_frame_size - 0x100);
conn.next_push_max_frame_size = max<size_t>(0x100, conn.next_push_max_frame_size - 0x100);
}
void IPStackSimulator::send_tcp_frame(
@@ -1397,15 +1461,11 @@ void IPStackSimulator::dispatch_on_resend_push(evutil_socket_t, short, void* ctx
if (!sim) {
ip_stack_simulator_log.warning("Resend push event triggered for client on deleted simulator; ignoring");
} else {
sim->on_resend_push(c, *conn);
sim->send_pending_push_frame(c, *conn, true);
}
}
}
void IPStackSimulator::on_resend_push(shared_ptr<IPClient> c, IPClient::TCPConnection& conn) {
this->send_pending_push_frame(c, conn);
}
void IPStackSimulator::dispatch_on_server_input(struct bufferevent*, void* ctx) {
auto* conn = reinterpret_cast<IPClient::TCPConnection*>(ctx);
auto c = conn->client.lock();
@@ -1426,11 +1486,13 @@ void IPStackSimulator::on_server_input(shared_ptr<IPClient> c, IPClient::TCPConn
ip_stack_simulator_log.debug("Server input event: 0x%zX bytes to read",
evbuffer_get_length(buf));
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
auto sim = c->sim.lock();
uint64_t idle_timeout_usecs = sim ? sim->state->client_idle_timeout_usecs : 60000000;
struct timeval tv = usecs_to_timeval(idle_timeout_usecs);
event_add(c->idle_timeout_event.get(), &tv);
evbuffer_add_buffer(conn.pending_data.get(), buf);
this->send_pending_push_frame(c, conn);
this->send_pending_push_frame(c, conn, false);
}
void IPStackSimulator::dispatch_on_server_error(
+47 -39
View File
@@ -16,32 +16,23 @@
class IPStackSimulator : public std::enable_shared_from_this<IPStackSimulator> {
public:
IPStackSimulator(
std::shared_ptr<struct event_base> base,
std::shared_ptr<ServerState> state);
~IPStackSimulator();
void listen(const std::string& name, const std::string& socket_path, FrameInfo::LinkType link_type);
void listen(const std::string& name, const std::string& addr, int port, FrameInfo::LinkType link_type);
void listen(const std::string& name, int port, FrameInfo::LinkType link_type);
void add_socket(const std::string& name, int fd, FrameInfo::LinkType link_type);
static uint32_t connect_address_for_remote_address(uint32_t remote_addr);
private:
std::shared_ptr<struct event_base> base;
std::shared_ptr<ServerState> state;
enum class Protocol {
ETHERNET_TAPSERVER = 0,
HDLC_TAPSERVER,
HDLC_RAW,
};
using unique_listener = std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)>;
using unique_bufferevent = std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)>;
using unique_evbuffer = std::unique_ptr<struct evbuffer, void (*)(struct evbuffer*)>;
using unique_event = std::unique_ptr<struct event, void (*)(struct event*)>;
struct IPClient {
struct IPClient : std::enable_shared_from_this<IPClient> {
std::weak_ptr<IPStackSimulator> sim;
uint64_t network_id;
unique_bufferevent bev;
FrameInfo::LinkType link_type;
Protocol protocol;
uint32_t hdlc_escape_control_character_flags = 0xFFFFFFFF;
uint32_t hdlc_remote_magic_number = 0;
parray<uint8_t, 6> mac_addr; // Only used for LinkType::ETHERNET
@@ -80,53 +71,73 @@ private:
unique_event idle_timeout_event;
IPClient(std::shared_ptr<IPStackSimulator> sim, FrameInfo::LinkType link_type, struct bufferevent* bev);
IPClient(std::shared_ptr<IPStackSimulator> sim, uint64_t network_id, Protocol protocol, struct bufferevent* bev);
static void dispatch_on_client_input(struct bufferevent* bev, void* ctx);
void on_client_input(struct bufferevent* bev);
static void dispatch_on_client_error(struct bufferevent* bev, short events, void* ctx);
void on_client_error(struct bufferevent* bev, short events);
static void dispatch_on_idle_timeout(evutil_socket_t fd, short events, void* ctx);
void on_idle_timeout();
};
IPStackSimulator(
std::shared_ptr<struct event_base> base,
std::shared_ptr<ServerState> state);
~IPStackSimulator();
void listen(const std::string& name, const std::string& socket_path, Protocol protocol);
void listen(const std::string& name, const std::string& addr, int port, Protocol protocol);
void listen(const std::string& name, int port, Protocol protocol);
void add_socket(const std::string& name, int fd, Protocol protocol);
static uint32_t connect_address_for_remote_address(uint32_t remote_addr);
std::shared_ptr<IPClient> get_network(uint64_t network_id) const;
inline const std::unordered_map<uint64_t, std::shared_ptr<IPClient>>& all_networks() const {
return this->network_id_to_client;
}
void disconnect_client(uint64_t network_id);
private:
std::shared_ptr<struct event_base> base;
std::shared_ptr<ServerState> state;
uint64_t next_network_id;
struct ListeningSocket {
std::string name;
FrameInfo::LinkType link_type;
Protocol protocol;
unique_listener listener;
ListeningSocket(const std::string& name, FrameInfo::LinkType link_type, unique_listener&& l)
ListeningSocket(const std::string& name, Protocol protocol, unique_listener&& l)
: name(name),
link_type(link_type),
protocol(protocol),
listener(std::move(l)) {}
};
std::unordered_map<int, ListeningSocket> listening_sockets;
std::unordered_map<struct bufferevent*, std::shared_ptr<IPClient>> bev_to_client;
std::unordered_map<uint64_t, std::shared_ptr<IPClient>> network_id_to_client;
parray<uint8_t, 6> host_mac_address_bytes;
parray<uint8_t, 6> broadcast_mac_address_bytes;
FILE* pcap_text_log_file;
void disconnect_client(struct bufferevent* bev);
static uint64_t tcp_conn_key_for_connection(const IPClient::TCPConnection& conn);
static uint64_t tcp_conn_key_for_client_frame(const IPv4Header& ipv4, const TCPHeader& tcp);
static uint64_t tcp_conn_key_for_client_frame(const FrameInfo& fi);
static std::string str_for_ipv4_netloc(uint32_t addr, uint16_t port);
static std::string str_for_tcp_connection(std::shared_ptr<const IPClient> c,
const IPClient::TCPConnection& conn);
static std::string str_for_tcp_connection(std::shared_ptr<const IPClient> c, const IPClient::TCPConnection& conn);
static void dispatch_on_listen_accept(struct evconnlistener* listener,
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd,
struct sockaddr* address, int socklen);
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* address, int socklen);
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
void on_listen_error(struct evconnlistener* listener);
static void dispatch_on_client_input(struct bufferevent* bev, void* ctx);
void on_client_input(struct bufferevent* bev);
static void dispatch_on_client_error(struct bufferevent* bev, short events, void* ctx);
void on_client_error(struct bufferevent* bev, short events);
void send_layer3_frame(std::shared_ptr<IPClient> c, FrameInfo::Protocol proto, const std::string& data) const;
void send_layer3_frame(std::shared_ptr<IPClient> c, FrameInfo::Protocol proto, const void* data, size_t size) const;
@@ -138,15 +149,13 @@ private:
void on_client_udp_frame(std::shared_ptr<IPClient> c, const FrameInfo& fi);
void on_client_tcp_frame(std::shared_ptr<IPClient> c, const FrameInfo& fi);
static void dispatch_on_resend_push(evutil_socket_t fd, short events, void* ctx);
void on_resend_push(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
static void dispatch_on_server_input(struct bufferevent* bev, void* ctx);
void on_server_input(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
static void dispatch_on_server_error(struct bufferevent* bev, short events, void* ctx);
void on_server_error(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn, short events);
void send_pending_push_frame(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
static void dispatch_on_resend_push(evutil_socket_t, short, void* ctx);
void send_pending_push_frame(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn, bool always_send);
void send_tcp_frame(
std::shared_ptr<IPClient> c,
IPClient::TCPConnection& conn,
@@ -154,8 +163,7 @@ private:
struct evbuffer* src_buf = nullptr,
size_t src_bytes = 0);
void open_server_connection(
std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
void open_server_connection(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
void log_frame(const std::string& data) const;
};
+73
View File
@@ -0,0 +1,73 @@
#include "IPV4RangeSet.hh"
#include <arpa/inet.h>
using namespace std;
IPV4RangeSet::IPV4RangeSet(const JSON& json) {
for (const auto& it : json.as_list()) {
// String should be of the form a.b.c.d or a.b.c.d/e
auto tokens = split(it->as_string(), '/');
size_t mask_bits;
if (tokens.size() == 1) {
mask_bits = 32;
} else if (tokens.size() == 2) {
mask_bits = stoul(tokens[1], nullptr, 10);
if (mask_bits > 32) {
throw runtime_error("invalid IPv4 address range");
}
} else {
throw runtime_error("invalid IPv4 address range");
}
auto addr_tokens = split(tokens[0], '.');
if (addr_tokens.size() != 4) {
throw runtime_error("invalid IPv4 address");
}
uint32_t addr = 0;
for (size_t z = 0; z < 4; z++) {
size_t end_pos = 0;
size_t new_byte = stoul(addr_tokens[z], &end_pos, 10);
if (end_pos != addr_tokens[z].size() || new_byte > 0xFF) {
throw runtime_error("invalid IPv4 address");
}
addr = (addr << 8) | new_byte;
}
addr &= (0xFFFFFFFF << (32 - mask_bits));
this->ranges.emplace(addr, mask_bits);
}
}
JSON IPV4RangeSet::json() const {
auto ret = JSON::list();
for (const auto& it : this->ranges) {
uint32_t addr = it.first;
uint8_t mask_bits = it.second;
ret.emplace_back(string_printf("%hhu.%hhu.%hhu.%hhu/%hhu",
static_cast<uint8_t>((addr >> 24) & 0xFF),
static_cast<uint8_t>((addr >> 16) & 0xFF),
static_cast<uint8_t>((addr >> 8) & 0xFF),
static_cast<uint8_t>(addr & 0xFF),
mask_bits));
}
return ret;
}
bool IPV4RangeSet::check(uint32_t addr) const {
auto it = this->ranges.upper_bound(addr);
if (it == this->ranges.begin()) {
return false; // addr is before any range
}
const auto& range = *(--it);
return (((range.first ^ addr) & (0xFFFFFFFF << (32 - range.second))) == 0);
}
bool IPV4RangeSet::check(const struct sockaddr_storage& ss) const {
if (ss.ss_family != AF_INET) {
return false;
}
const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(&ss);
return this->check(ntohl(sin->sin_addr.s_addr));
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <phosg/JSON.hh>
#include <set>
class IPV4RangeSet {
public:
IPV4RangeSet() = default;
explicit IPV4RangeSet(const JSON& json);
JSON json() const;
bool check(uint32_t addr) const;
bool check(const struct sockaddr_storage& ss) const;
protected:
std::map<uint32_t, uint8_t> ranges; // {addr: mask_bits}
};
@@ -1,4 +1,4 @@
#include "QuestAvailabilityExpression.hh"
#include "IntegralExpression.hh"
#include <algorithm>
#include <mutex>
@@ -21,16 +21,16 @@
using namespace std;
QuestAvailabilityExpression::QuestAvailabilityExpression(const string& text)
IntegralExpression::IntegralExpression(const string& text)
: root(this->parse_expr(text)) {}
QuestAvailabilityExpression::BinaryOperatorNode::BinaryOperatorNode(
IntegralExpression::BinaryOperatorNode::BinaryOperatorNode(
Type type, unique_ptr<const Node>&& left, unique_ptr<const Node>&& right)
: type(type),
left(std::move(left)),
right(std::move(right)) {}
bool QuestAvailabilityExpression::BinaryOperatorNode::operator==(const Node& other) const {
bool IntegralExpression::BinaryOperatorNode::operator==(const Node& other) const {
try {
const BinaryOperatorNode& other_bin = dynamic_cast<const BinaryOperatorNode&>(other);
return other_bin.type == this->type && *other_bin.left == *this->left && *other_bin.right == *this->right;
@@ -39,7 +39,7 @@ bool QuestAvailabilityExpression::BinaryOperatorNode::operator==(const Node& oth
}
}
int64_t QuestAvailabilityExpression::BinaryOperatorNode::evaluate(const Env& env) const {
int64_t IntegralExpression::BinaryOperatorNode::evaluate(const Env& env) const {
switch (this->type) {
case Type::LOGICAL_OR:
return this->left->evaluate(env) || this->right->evaluate(env);
@@ -82,7 +82,7 @@ int64_t QuestAvailabilityExpression::BinaryOperatorNode::evaluate(const Env& env
}
}
string QuestAvailabilityExpression::BinaryOperatorNode::str() const {
string IntegralExpression::BinaryOperatorNode::str() const {
switch (this->type) {
case Type::LOGICAL_OR:
return "(" + this->left->str() + ") || (" + this->right->str() + ")";
@@ -125,11 +125,11 @@ string QuestAvailabilityExpression::BinaryOperatorNode::str() const {
}
}
QuestAvailabilityExpression::UnaryOperatorNode::UnaryOperatorNode(Type type, unique_ptr<const Node>&& sub)
IntegralExpression::UnaryOperatorNode::UnaryOperatorNode(Type type, unique_ptr<const Node>&& sub)
: type(type),
sub(std::move(sub)) {}
bool QuestAvailabilityExpression::UnaryOperatorNode::operator==(const Node& other) const {
bool IntegralExpression::UnaryOperatorNode::operator==(const Node& other) const {
try {
const UnaryOperatorNode& other_un = dynamic_cast<const UnaryOperatorNode&>(other);
return other_un.type == this->type && *other_un.sub == *this->sub;
@@ -138,7 +138,7 @@ bool QuestAvailabilityExpression::UnaryOperatorNode::operator==(const Node& othe
}
}
int64_t QuestAvailabilityExpression::UnaryOperatorNode::evaluate(const Env& env) const {
int64_t IntegralExpression::UnaryOperatorNode::evaluate(const Env& env) const {
switch (this->type) {
case Type::LOGICAL_NOT:
return !this->sub->evaluate(env);
@@ -151,7 +151,7 @@ int64_t QuestAvailabilityExpression::UnaryOperatorNode::evaluate(const Env& env)
}
}
string QuestAvailabilityExpression::UnaryOperatorNode::str() const {
string IntegralExpression::UnaryOperatorNode::str() const {
switch (this->type) {
case Type::LOGICAL_NOT:
return "!(" + this->sub->str() + ")";
@@ -164,10 +164,10 @@ string QuestAvailabilityExpression::UnaryOperatorNode::str() const {
}
}
QuestAvailabilityExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index)
IntegralExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index)
: flag_index(flag_index) {}
bool QuestAvailabilityExpression::FlagLookupNode::operator==(const Node& other) const {
bool IntegralExpression::FlagLookupNode::operator==(const Node& other) const {
try {
const FlagLookupNode& other_flag = dynamic_cast<const FlagLookupNode&>(other);
return other_flag.flag_index == this->flag_index;
@@ -176,18 +176,51 @@ bool QuestAvailabilityExpression::FlagLookupNode::operator==(const Node& other)
}
}
int64_t QuestAvailabilityExpression::FlagLookupNode::evaluate(const Env& env) const {
int64_t IntegralExpression::FlagLookupNode::evaluate(const Env& env) const {
if (!env.flags) {
throw runtime_error("quest flags not available");
}
return env.flags->get(this->flag_index) ? 1 : 0;
}
string QuestAvailabilityExpression::FlagLookupNode::str() const {
string IntegralExpression::FlagLookupNode::str() const {
return string_printf("F_%04hX", this->flag_index);
}
QuestAvailabilityExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name)
IntegralExpression::ChallengeCompletionLookupNode::ChallengeCompletionLookupNode(
Episode episode, uint8_t stage_index)
: episode(episode),
stage_index(stage_index) {}
bool IntegralExpression::ChallengeCompletionLookupNode::operator==(const Node& other) const {
try {
const ChallengeCompletionLookupNode& other_cc = dynamic_cast<const ChallengeCompletionLookupNode&>(other);
return other_cc.episode == this->episode && other_cc.stage_index == this->stage_index;
} catch (const bad_cast&) {
return false;
}
}
int64_t IntegralExpression::ChallengeCompletionLookupNode::evaluate(const Env& env) const {
if (!env.challenge_records) {
throw runtime_error("challenge records not available");
}
if (this->episode == Episode::EP1) {
return env.challenge_records->times_ep1_online.at(this->stage_index).has_value();
} else if (this->episode == Episode::EP2) {
return env.challenge_records->times_ep2_online.at(this->stage_index).has_value();
}
return false;
}
string IntegralExpression::ChallengeCompletionLookupNode::str() const {
return string_printf("CC_%s_%hhu", abbreviation_for_episode(this->episode), static_cast<uint8_t>(this->stage_index + 1));
}
IntegralExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name)
: reward_name(reward_name) {}
bool QuestAvailabilityExpression::TeamRewardLookupNode::operator==(const Node& other) const {
bool IntegralExpression::TeamRewardLookupNode::operator==(const Node& other) const {
try {
const TeamRewardLookupNode& other_team_reward = dynamic_cast<const TeamRewardLookupNode&>(other);
return other_team_reward.reward_name == this->reward_name;
@@ -196,32 +229,60 @@ bool QuestAvailabilityExpression::TeamRewardLookupNode::operator==(const Node& o
}
}
int64_t QuestAvailabilityExpression::TeamRewardLookupNode::evaluate(const Env& env) const {
int64_t IntegralExpression::TeamRewardLookupNode::evaluate(const Env& env) const {
return (env.team && env.team->has_reward(this->reward_name)) ? 1 : 0;
}
string QuestAvailabilityExpression::TeamRewardLookupNode::str() const {
string IntegralExpression::TeamRewardLookupNode::str() const {
return "T_" + this->reward_name;
}
QuestAvailabilityExpression::NumPlayersLookupNode::NumPlayersLookupNode() {}
IntegralExpression::NumPlayersLookupNode::NumPlayersLookupNode() {}
bool QuestAvailabilityExpression::NumPlayersLookupNode::operator==(const Node& other) const {
bool IntegralExpression::NumPlayersLookupNode::operator==(const Node& other) const {
return dynamic_cast<const NumPlayersLookupNode*>(&other) != nullptr;
}
int64_t QuestAvailabilityExpression::NumPlayersLookupNode::evaluate(const Env& env) const {
int64_t IntegralExpression::NumPlayersLookupNode::evaluate(const Env& env) const {
return env.num_players;
}
string QuestAvailabilityExpression::NumPlayersLookupNode::str() const {
string IntegralExpression::NumPlayersLookupNode::str() const {
return "V_NumPlayers";
}
QuestAvailabilityExpression::ConstantNode::ConstantNode(bool value)
IntegralExpression::EventLookupNode::EventLookupNode() {}
bool IntegralExpression::EventLookupNode::operator==(const Node& other) const {
return dynamic_cast<const EventLookupNode*>(&other) != nullptr;
}
int64_t IntegralExpression::EventLookupNode::evaluate(const Env& env) const {
return env.event;
}
string IntegralExpression::EventLookupNode::str() const {
return "V_Event";
}
IntegralExpression::V1PresenceLookupNode::V1PresenceLookupNode() {}
bool IntegralExpression::V1PresenceLookupNode::operator==(const Node& other) const {
return dynamic_cast<const V1PresenceLookupNode*>(&other) != nullptr;
}
int64_t IntegralExpression::V1PresenceLookupNode::evaluate(const Env& env) const {
return env.v1_present ? 1 : 0;
}
string IntegralExpression::V1PresenceLookupNode::str() const {
return "V_V1Present";
}
IntegralExpression::ConstantNode::ConstantNode(int64_t value)
: value(value) {}
bool QuestAvailabilityExpression::ConstantNode::operator==(const Node& other) const {
bool IntegralExpression::ConstantNode::operator==(const Node& other) const {
try {
const ConstantNode& other_const = dynamic_cast<const ConstantNode&>(other);
return other_const.value == this->value;
@@ -230,15 +291,15 @@ bool QuestAvailabilityExpression::ConstantNode::operator==(const Node& other) co
}
}
int64_t QuestAvailabilityExpression::ConstantNode::evaluate(const Env&) const {
int64_t IntegralExpression::ConstantNode::evaluate(const Env&) const {
return this->value;
}
string QuestAvailabilityExpression::ConstantNode::str() const {
string IntegralExpression::ConstantNode::str() const {
return string_printf("%" PRId64, this->value);
}
unique_ptr<const QuestAvailabilityExpression::Node> QuestAvailabilityExpression::parse_expr(string_view text) {
unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string_view text) {
// Strip off spaces and fully-enclosing parentheses
for (;;) {
size_t starting_size = text.size();
@@ -279,13 +340,13 @@ unique_ptr<const QuestAvailabilityExpression::Node> QuestAvailabilityExpression:
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
QuestAvailabilityExpression::parse_expr(text.substr(1)));
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
QuestAvailabilityExpression::parse_expr(text.substr(1)));
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
QuestAvailabilityExpression::parse_expr(text.substr(1)));
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for binary operators at the root level
@@ -322,8 +383,8 @@ unique_ptr<const QuestAvailabilityExpression::Node> QuestAvailabilityExpression:
((z < oper.first.size()) || (text.compare(z - oper.first.size(), oper.first.size(), oper.first) != 0)) &&
(text.compare(z, oper.first.size(), oper.first) == 0) &&
(text.compare(z + oper.first.size(), oper.first.size(), oper.first) != 0)) {
auto left = QuestAvailabilityExpression::parse_expr(text.substr(0, z));
auto right = QuestAvailabilityExpression::parse_expr(text.substr(z + oper.first.size()));
auto left = IntegralExpression::parse_expr(text.substr(0, z));
auto right = IntegralExpression::parse_expr(text.substr(z + oper.first.size()));
return make_unique<BinaryOperatorNode>(oper.second, std::move(left), std::move(right));
}
}
@@ -343,12 +404,37 @@ unique_ptr<const QuestAvailabilityExpression::Node> QuestAvailabilityExpression:
}
return make_unique<FlagLookupNode>(flag);
}
if (text.starts_with("CC_")) {
Episode episode;
if (text.starts_with("CC_Ep1_")) {
episode = Episode::EP1;
} else if (text.starts_with("CC_Ep2_")) {
episode = Episode::EP2;
} else {
throw runtime_error("invalid challenge episode");
}
char* endptr = nullptr;
uint64_t stage_index = strtoul(text.data() + 7, &endptr, 0) - 1;
if (endptr != text.data() + text.size()) {
throw runtime_error("invalid challenge completion lookup token");
}
if ((episode == Episode::EP1 && stage_index > 8) || (episode == Episode::EP2 && stage_index > 4)) {
throw runtime_error("invalid challenge stage index");
}
return make_unique<ChallengeCompletionLookupNode>(episode, stage_index);
}
if (text.starts_with("T_")) {
return make_unique<TeamRewardLookupNode>(string(text.substr(2)));
}
if (text == "V_NumPlayers") {
return make_unique<NumPlayersLookupNode>();
}
if (text == "V_Event") {
return make_unique<EventLookupNode>();
}
if (text == "V_V1Present") {
return make_unique<V1PresenceLookupNode>();
}
// Check for constants
if (text == "true") {
@@ -13,20 +13,23 @@
#include "StaticGameData.hh"
#include "TeamIndex.hh"
class QuestAvailabilityExpression {
class IntegralExpression {
public:
struct Env {
const QuestFlagsForDifficulty* flags;
const PlayerRecordsChallengeBB* challenge_records;
std::shared_ptr<const TeamIndex::Team> team;
size_t num_players;
uint8_t event;
bool v1_present;
};
QuestAvailabilityExpression(const std::string& text);
~QuestAvailabilityExpression() = default;
inline bool operator==(const QuestAvailabilityExpression& other) const {
IntegralExpression(const std::string& text);
~IntegralExpression() = default;
inline bool operator==(const IntegralExpression& other) const {
return this->root->operator==(*other.root);
}
inline bool operator!=(const QuestAvailabilityExpression& other) const {
inline bool operator!=(const IntegralExpression& other) const {
return !this->operator==(other);
}
inline int64_t evaluate(const Env& env) const {
@@ -115,6 +118,19 @@ protected:
uint16_t flag_index;
};
class ChallengeCompletionLookupNode : public Node {
public:
ChallengeCompletionLookupNode(Episode episode, uint8_t stage_index);
virtual ~ChallengeCompletionLookupNode() = default;
virtual bool operator==(const Node& other) const;
virtual int64_t evaluate(const Env& env) const;
virtual std::string str() const;
protected:
Episode episode;
uint8_t stage_index;
};
class TeamRewardLookupNode : public Node {
public:
TeamRewardLookupNode(const std::string& reward_name);
@@ -136,9 +152,27 @@ protected:
virtual std::string str() const;
};
class EventLookupNode : public Node {
public:
EventLookupNode();
virtual ~EventLookupNode() = default;
virtual bool operator==(const Node& other) const;
virtual int64_t evaluate(const Env& env) const;
virtual std::string str() const;
};
class V1PresenceLookupNode : public Node {
public:
V1PresenceLookupNode();
virtual ~V1PresenceLookupNode() = default;
virtual bool operator==(const Node& other) const;
virtual int64_t evaluate(const Env& env) const;
virtual std::string str() const;
};
class ConstantNode : public Node {
public:
ConstantNode(bool value);
ConstantNode(int64_t value);
virtual ~ConstantNode() = default;
virtual bool operator==(const Node& other) const;
virtual int64_t evaluate(const Env& env) const;
+209 -170
View File
@@ -18,15 +18,16 @@ ItemCreator::ItemCreator(
shared_ptr<const WeaponRandomSet> weapon_random_set,
shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set,
shared_ptr<const ItemParameterTable> item_parameter_table,
Version version,
std::shared_ptr<const ItemData::StackLimits> stack_limits,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t section_id,
uint32_t random_seed,
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
shared_ptr<const BattleRules> restrictions)
: log(string_printf("[ItemCreator:%s/%s/%s/%c/%hhu] ", name_for_enum(version), abbreviation_for_episode(episode), abbreviation_for_mode(mode), abbreviation_for_difficulty(difficulty), section_id), lobby_log.min_level),
version(version),
: log(string_printf("[ItemCreator:%s/%s/%s/%c/%hhu] ", name_for_enum(stack_limits->version), abbreviation_for_episode(episode), abbreviation_for_mode(mode), abbreviation_for_difficulty(difficulty), section_id), lobby_log.min_level),
logic_version(stack_limits->version),
stack_limits(stack_limits),
episode(episode),
mode(mode),
difficulty(difficulty),
@@ -37,40 +38,37 @@ ItemCreator::ItemCreator(
weapon_random_set(weapon_random_set),
tekker_adjustment_set(tekker_adjustment_set),
item_parameter_table(item_parameter_table),
common_item_set(common_item_set),
pt(common_item_set->get_table(this->episode, this->mode, this->difficulty, this->section_id)),
restrictions(restrictions),
random_crypt(random_seed) {
opt_rand_crypt(opt_rand_crypt ? make_shared<PSOV2Encryption>(opt_rand_crypt->seed()) : nullptr) {
this->generate_unit_stars_tables();
}
void ItemCreator::set_random_state(uint32_t seed, uint32_t absolute_offset) {
if ((this->random_crypt.seed() != seed) || (this->random_crypt.absolute_offset() > absolute_offset)) {
this->random_crypt = PSOV2Encryption(seed);
void ItemCreator::set_random_crypt(shared_ptr<PSOLFGEncryption> new_random_crypt) {
this->opt_rand_crypt = new_random_crypt;
}
void ItemCreator::set_section_id(uint8_t new_section_id) {
if (this->section_id != new_section_id) {
this->section_id = new_section_id;
this->log.prefix = string_printf("[ItemCreator:%s/%s/%s/%c/%hhu] ",
name_for_enum(stack_limits->version),
abbreviation_for_episode(episode),
abbreviation_for_mode(mode),
abbreviation_for_difficulty(difficulty),
this->section_id);
this->pt = common_item_set->get_table(this->episode, this->mode, this->difficulty, this->section_id);
}
while (this->random_crypt.absolute_offset() < absolute_offset) {
this->random_crypt.next();
}
}
void ItemCreator::set_box_destroyed(uint16_t entity_id) {
this->destroyed_boxes.emplace(entity_id);
}
void ItemCreator::set_monster_destroyed(uint16_t entity_id) {
this->destroyed_monsters.emplace(entity_id);
}
void ItemCreator::clear_destroyed_entities() {
this->destroyed_monsters.clear();
this->destroyed_boxes.clear();
}
bool ItemCreator::are_rare_drops_allowed() const {
// Note: The client has an additional check here, which appears to be a subtle
// anti-cheating measure. There is a flag on the client, initially zero, which
// is set to 1 when certain unexpected item-related things happen (for
// example, a player possessing a mag with a level above 200). When the flag
// is set, this function returns false, which prevents all rare item drops.
// example, a player possessing a mag with a level above 200, or a stack of
// consumables with an amount above the stack size limit). When the flag is
// set, this function returns false, which prevents all rare item drops.
// newserv intentionally does not implement this flag.
return (this->mode != GameMode::CHALLENGE);
}
@@ -130,50 +128,62 @@ uint8_t ItemCreator::normalize_area_number(uint8_t area) const {
}
} else {
return this->restrictions->box_drop_area;
return this->restrictions->box_drop_area - 1;
}
}
ItemData ItemCreator::on_box_item_drop(uint16_t entity_id, uint8_t area) {
return this->destroyed_boxes.count(entity_id)
? ItemData()
: this->on_box_item_drop_with_area_norm(this->normalize_area_number(area));
ItemCreator::DropResult ItemCreator::on_box_item_drop(uint8_t area) {
try {
return this->on_box_item_drop_with_area_norm(this->normalize_area_number(area));
} catch (const exception& e) {
this->log.error("Exception in item creation: %s", e.what());
return DropResult();
}
}
ItemData ItemCreator::on_monster_item_drop(uint16_t entity_id, uint32_t enemy_type, uint8_t area) {
return this->destroyed_monsters.count(entity_id)
? ItemData()
: this->on_monster_item_drop_with_area_norm(enemy_type, this->normalize_area_number(area));
ItemCreator::DropResult ItemCreator::on_monster_item_drop(uint32_t enemy_type, uint8_t area) {
try {
return this->on_monster_item_drop_with_area_norm(enemy_type, this->normalize_area_number(area));
} catch (const exception& e) {
this->log.error("Exception in item creation: %s", e.what());
return DropResult();
}
}
ItemData ItemCreator::on_box_item_drop_with_area_norm(uint8_t area_norm) {
this->log.info("Box drop checks for area_norm %02hhX; random state: %08" PRIX32 " %08" PRIX32,
area_norm, this->random_crypt.seed(), this->random_crypt.absolute_offset());
ItemData item = this->check_rare_specs_and_create_rare_box_item(area_norm);
if (item.empty()) {
ItemCreator::DropResult ItemCreator::on_box_item_drop_with_area_norm(uint8_t area_norm) {
this->log.info("Box drop checks for area_norm %02hhX", area_norm);
if (this->opt_rand_crypt) {
this->log.info("Random state: %08" PRIX32 " %08" PRIX32,
this->opt_rand_crypt->seed(), this->opt_rand_crypt->absolute_offset());
}
DropResult res;
res.item = this->check_rare_specs_and_create_rare_box_item(area_norm);
if (!res.item.empty()) {
res.is_from_rare_table = true;
} else {
uint8_t item_class = this->get_rand_from_weighted_tables_2d_vertical(this->pt->box_item_class_prob_table, area_norm);
this->log.info("Item class is %02hhX", item_class);
switch (item_class) {
case 0: // Weapon
item.data1[0] = 0;
res.item.data1[0] = 0;
break;
case 1: // Armor
item.data1[0] = 1;
item.data1[1] = 1;
res.item.data1[0] = 1;
res.item.data1[1] = 1;
break;
case 2: // Shield
item.data1[0] = 1;
item.data1[1] = 2;
res.item.data1[0] = 1;
res.item.data1[1] = 2;
break;
case 3: // Unit
item.data1[0] = 1;
item.data1[1] = 3;
res.item.data1[0] = 1;
res.item.data1[1] = 3;
break;
case 4: // Tool
item.data1[0] = 3;
res.item.data1[0] = 3;
break;
case 5: // Meseta
item.data1[0] = 4;
res.item.data1[0] = 4;
break;
case 6: // Nothing
break;
@@ -181,30 +191,37 @@ ItemData ItemCreator::on_box_item_drop_with_area_norm(uint8_t area_norm) {
throw logic_error("this should be impossible");
}
if (item_class < 6) {
this->generate_common_item_variances(area_norm, item);
this->generate_common_item_variances(area_norm, res.item);
}
}
return item;
return res;
}
ItemData ItemCreator::on_monster_item_drop_with_area_norm(uint32_t enemy_type, uint8_t area_norm) {
ItemCreator::DropResult ItemCreator::on_monster_item_drop_with_area_norm(uint32_t enemy_type, uint8_t area_norm) {
if (enemy_type > 0x58) {
this->log.warning("Invalid enemy type: %" PRIX32, enemy_type);
return ItemData();
return DropResult();
}
this->log.info("Enemy type: %" PRIX32 "", enemy_type);
if (this->opt_rand_crypt) {
this->log.info("Random state: %08" PRIX32 " %08" PRIX32,
this->opt_rand_crypt->seed(), this->opt_rand_crypt->absolute_offset());
}
this->log.info("Enemy type: %" PRIX32 "; random state: %08" PRIX32 " %08" PRIX32, enemy_type, this->random_crypt.seed(), this->random_crypt.absolute_offset());
uint8_t type_drop_prob = this->pt->enemy_type_drop_probs.at(enemy_type);
uint8_t drop_sample = this->rand_int(100);
if (drop_sample >= type_drop_prob) {
this->log.info("Drop not chosen (%hhu >= %hhu)", drop_sample, type_drop_prob);
return ItemData();
return DropResult();
} else {
this->log.info("Drop chosen (%hhu < %hhu)", drop_sample, type_drop_prob);
}
ItemData item = this->check_rare_spec_and_create_rare_enemy_item(enemy_type, area_norm);
if (item.empty()) {
DropResult res;
res.item = this->check_rare_spec_and_create_rare_enemy_item(enemy_type, area_norm);
if (!res.item.empty()) {
res.is_from_rare_table = true;
} else {
uint32_t item_class_determinant =
this->should_allow_meseta_drops()
? this->rand_int(3)
@@ -229,34 +246,34 @@ ItemData ItemCreator::on_monster_item_drop_with_area_norm(uint32_t enemy_type, u
switch (item_class) {
case 0: // Weapon
item.data1[0] = 0x00;
res.item.data1[0] = 0x00;
break;
case 1: // Armor
item.data1w[0] = 0x0101;
res.item.data1w[0] = 0x0101;
break;
case 2: // Shield
item.data1w[0] = 0x0201;
res.item.data1w[0] = 0x0201;
break;
case 3: // Unit
item.data1w[0] = 0x0301;
res.item.data1w[0] = 0x0301;
break;
case 4: // Tool
item.data1[0] = 0x03;
res.item.data1[0] = 0x03;
break;
case 5: // Meseta
item.data1[0] = 0x04;
item.data2d = this->choose_meseta_amount(this->pt->enemy_meseta_ranges, enemy_type) & 0xFFFF;
res.item.data1[0] = 0x04;
res.item.data2d = this->choose_meseta_amount(this->pt->enemy_meseta_ranges, enemy_type) & 0xFFFF;
break;
default:
return item;
return res;
}
if (item.data1[0] != 0x04) {
this->generate_common_item_variances(area_norm, item);
if (res.item.data1[0] != 0x04) {
this->generate_common_item_variances(area_norm, res.item);
}
}
return item;
return res;
}
ItemData ItemCreator::check_rare_specs_and_create_rare_box_item(uint8_t area_norm) {
@@ -270,23 +287,27 @@ ItemData ItemCreator::check_rare_specs_and_create_rare_box_item(uint8_t area_nor
for (const auto& spec : rare_specs) {
item = this->check_rate_and_create_rare_item(spec, area_norm);
if (!item.empty()) {
this->log.info("Box spec %08" PRIX32 " produced item %02hhX%02hhX%02hhX",
spec.probability, spec.item_code[0], spec.item_code[1], spec.item_code[2]);
if (this->log.should_log(LogLevel::INFO)) {
auto hex = spec.data.hex();
this->log.info("Box spec %08" PRIX32 " produced item %s", spec.probability, hex.c_str());
}
break;
}
this->log.info("Box spec %08" PRIX32 " did not produce item %02hhX%02hhX%02hhX",
spec.probability, spec.item_code[0], spec.item_code[1], spec.item_code[2]);
if (this->log.should_log(LogLevel::INFO)) {
auto hex = spec.data.hex();
this->log.info("Box spec %08" PRIX32 " did not produce item %s", spec.probability, hex.c_str());
}
}
return item;
}
uint32_t ItemCreator::rand_int(uint64_t max) {
return this->random_crypt.next() % max;
return random_from_optional_crypt(this->opt_rand_crypt) % max;
}
float ItemCreator::rand_float_0_1_from_crypt() {
// This lacks some precision, but matches the original implementation.
return (static_cast<double>(this->random_crypt.next() >> 16) / 65536.0);
return (static_cast<double>(random_from_optional_crypt(this->opt_rand_crypt) >> 16) / 65536.0);
}
template <size_t NumRanges>
@@ -296,16 +317,17 @@ uint32_t ItemCreator::choose_meseta_amount(
uint16_t min = ranges[table_index].min;
uint16_t max = ranges[table_index].max;
// Note: The original code seems like it has a bug here: it compares to 0xFF
// instead of 0xFFFF (and returns 0xFF if either limit matches 0xFF).
uint32_t ret = 0;
if (((min == 0xFFFF) || (max == 0xFFFF)) || (max < min)) {
ret = 0xFFFF;
} else if (min != max) {
ret = this->rand_int((max - min) + 1) + min;
} else {
// Note: The original code returns 0xFF here if either limit is equal to 0xFF
// (despite them being 16-bit integers!)
uint16_t ret;
if (min == max) {
ret = min;
} else if (max < min) {
ret = this->rand_int((min - max) + 1) + max;
} else {
ret = this->rand_int((max - min) + 1) + min;
}
this->log.info("Chose %" PRIu32 " Meseta from range [%hu, %hu]", ret, min, max);
return ret;
}
@@ -326,12 +348,16 @@ ItemData ItemCreator::check_rare_spec_and_create_rare_enemy_item(uint32_t enemy_
for (const auto& spec : rare_specs) {
item = this->check_rate_and_create_rare_item(spec, area_norm);
if (!item.empty()) {
this->log.info("Enemy spec %08" PRIX32 " produced item %02hhX%02hhX%02hhX",
spec.probability, spec.item_code[0], spec.item_code[1], spec.item_code[2]);
if (this->log.should_log(LogLevel::INFO)) {
auto hex = spec.data.hex();
this->log.info("Enemy spec %08" PRIX32 " produced item %s", spec.probability, hex.c_str());
}
break;
}
this->log.info("Enemy spec %08" PRIX32 " did not produce item %02hhX%02hhX%02hhX",
spec.probability, spec.item_code[0], spec.item_code[1], spec.item_code[2]);
if (this->log.should_log(LogLevel::INFO)) {
auto hex = spec.data.hex();
this->log.info("Enemy spec %08" PRIX32 " did not produce item %s", spec.probability, hex.c_str());
}
}
}
return item;
@@ -348,37 +374,36 @@ ItemData ItemCreator::check_rate_and_create_rare_item(const RareItemSet::Expande
return ItemData();
}
ItemData item;
item.data1[0] = drop.item_code[0];
item.data1[1] = drop.item_code[1];
item.data1[2] = drop.item_code[2];
switch (item.data1[0]) {
case 0:
if (this->pt->has_rare_bonus_value_prob_table) {
this->generate_rare_weapon_bonuses(item, this->rand_int(10));
} else {
this->generate_common_weapon_bonuses(item, area_norm);
}
this->set_item_unidentified_flag_if_not_challenge(item);
break;
case 1:
this->generate_common_armor_slots_and_bonuses(item);
break;
case 2:
this->generate_common_mag_variances(item);
break;
case 3:
this->clear_tool_item_if_invalid(item);
this->set_tool_item_amount_to_1(item);
break;
case 4:
break;
default:
throw logic_error("invalid item class");
ItemData item = drop.data;
if (item.can_be_encoded_in_rel_rare_table()) {
switch (item.data1[0]) {
case 0:
if (this->pt->has_rare_bonus_value_prob_table) {
this->generate_rare_weapon_bonuses(item, this->rand_int(10));
} else {
this->generate_common_weapon_bonuses(item, area_norm);
}
this->set_item_unidentified_flag_if_not_challenge(item);
break;
case 1:
this->generate_common_armor_slots_and_bonuses(item);
break;
case 2:
this->generate_common_mag_variances(item);
break;
case 3:
this->clear_tool_item_if_invalid(item);
this->set_tool_item_amount_to_1(item);
break;
case 4:
break;
default:
throw logic_error("invalid item class");
}
this->set_item_kill_count_if_unsealable(item);
}
this->clear_item_if_restricted(item);
this->set_item_kill_count_if_unsealable(item);
return item;
}
@@ -458,23 +483,21 @@ void ItemCreator::set_item_unidentified_flag_if_not_challenge(ItemData& item) co
if (item.data1[0] != 0x00) {
return;
}
// On V3, all rare weapons and weapons with specials are untekked when
// created; on V2, only rares that are not in the standard item classes are
// untekked when created.
if (this->is_v3()) {
if (this->item_parameter_table->is_item_rare(item) || (item.data1[4] != 0)) {
item.data1[4] |= 0x80;
}
} else {
if (this->item_parameter_table->is_item_rare(item) ? (item.data1[1] > 0x0C) : (item.data1[4] != 0)) {
item.data1[4] |= 0x80;
}
// On V1, V3, and V4, all rare weapons and weapons with specials are untekked
// when created; on V2, only rares that are not in the standard item classes
// are untekked when created.
bool is_rare = this->item_parameter_table->is_item_rare(item);
bool use_v2_logic = is_v2(this->logic_version) && (this->logic_version != Version::GC_NTE);
if (use_v2_logic
? (is_rare ? (item.data1[1] > 0x0C) : (item.data1[4] != 0))
: (is_rare || (item.data1[4] != 0))) {
item.data1[4] |= 0x80;
}
}
void ItemCreator::set_tool_item_amount_to_1(ItemData& item) const {
if (item.data1[0] == 0x03) {
item.set_tool_item_amount(1);
item.set_tool_item_amount(*this->stack_limits, 1);
}
}
@@ -654,7 +677,7 @@ void ItemCreator::generate_common_tool_variances(uint32_t area_norm, ItemData& i
item.clear();
uint8_t tool_class = this->get_rand_from_weighted_tables_2d_vertical(this->pt->tool_class_prob_table, area_norm);
if (this->is_v3() && (tool_class == 0x1A)) {
if ((!is_v1_or_v2(this->logic_version) || (this->logic_version == Version::GC_NTE)) && (tool_class == 0x1A)) {
tool_class = 0x73;
}
this->log.info("Generating tool with class %02hhX", tool_class);
@@ -695,10 +718,20 @@ uint8_t ItemCreator::generate_tech_disk_level(uint32_t tech_num, uint32_t area_n
return range.min;
}
void ItemCreator::generate_common_mag_variances(ItemData& item) const {
void ItemCreator::generate_common_mag_variances(ItemData& item) {
if (item.data1[0] == 0x02) {
item.data1[1] = 0x00;
item.assign_mag_stats(ItemMagStats());
// The original code (on PSO GC) assigns the mag color as 0x0E. We assign
// a random color instead.
if (is_pre_v1(this->logic_version)) {
item.data2[3] = 0x00;
} else if (is_v1_or_v2(this->logic_version)) {
item.data2[3] = random_from_optional_crypt(this->opt_rand_crypt) % 0x0E;
} else {
item.data2[3] = random_from_optional_crypt(this->opt_rand_crypt) % 0x12;
}
}
}
@@ -810,23 +843,31 @@ void ItemCreator::generate_unit_stars_tables() {
size_t star_base_index;
uint8_t num_units;
switch (this->version) {
switch (this->logic_version) {
case Version::PC_PATCH:
case Version::BB_PATCH:
case Version::GC_NTE:
throw logic_error("unknown parameters for version");
case Version::GC_EP3_TRIAL_EDITION:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
throw logic_error("ItemCreator cannot be created for Episode 3 games");
case Version::DC_NTE:
star_base_index = 0x124;
num_units = 0x43;
break;
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1:
star_base_index = 0x128;
num_units = 0x44;
break;
case Version::DC_V2:
case Version::PC_NTE:
case Version::PC_V2:
star_base_index = 0x1D1;
num_units = 0x44;
break;
case Version::GC_NTE:
star_base_index = 0x251;
num_units = 0x47;
break;
case Version::GC_V3:
case Version::XB_V3:
star_base_index = 0x2AF;
@@ -987,7 +1028,7 @@ bool ItemCreator::shop_does_not_contain_duplicate_or_too_many_similar_weapons(
return true;
}
bool ItemCreator::shop_does_not_contain_duplicate_item_by_primary_identifier(
bool ItemCreator::shop_does_not_contain_duplicate_item_by_data1_0_1_2(
const vector<ItemData>& shop, const ItemData& item) {
for (const auto& shop_item : shop) {
if ((shop_item.data1[0] == item.data1[0]) &&
@@ -999,8 +1040,7 @@ bool ItemCreator::shop_does_not_contain_duplicate_item_by_primary_identifier(
return true;
}
void ItemCreator::generate_armor_shop_armors(
vector<ItemData>& shop, size_t player_level) {
void ItemCreator::generate_armor_shop_armors(vector<ItemData>& shop, size_t player_level) {
size_t num_items;
if (player_level < 11) {
num_items = 4;
@@ -1020,7 +1060,7 @@ void ItemCreator::generate_armor_shop_armors(
pt.push(src_table.first[z].value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
for (size_t items_generated = 0; items_generated < num_items;) {
ItemData item;
@@ -1064,7 +1104,7 @@ void ItemCreator::generate_armor_shop_shields(vector<ItemData>& shop, size_t pla
pt.push(src_table.first[z].value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
for (size_t items_generated = 0; items_generated < num_items;) {
ItemData item;
@@ -1080,7 +1120,7 @@ void ItemCreator::generate_armor_shop_shields(vector<ItemData>& shop, size_t pla
}
}
if (this->shop_does_not_contain_duplicate_item_by_primary_identifier(shop, item)) {
if (this->shop_does_not_contain_duplicate_item_by_data1_0_1_2(shop, item)) {
shop.emplace_back(std::move(item));
items_generated++;
}
@@ -1107,14 +1147,14 @@ void ItemCreator::generate_armor_shop_units(vector<ItemData>& shop, size_t playe
pt.push(src_table.first[z].value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
for (size_t items_generated = 0; items_generated < num_items;) {
ItemData item;
item.data1[0] = 1;
item.data1[1] = 3;
item.data1[2] = pt.pop();
if (this->shop_does_not_contain_duplicate_item_by_primary_identifier(shop, item)) {
if (this->shop_does_not_contain_duplicate_item_by_data1_0_1_2(shop, item)) {
shop.emplace_back(std::move(item));
items_generated++;
}
@@ -1210,7 +1250,7 @@ void ItemCreator::generate_rare_tool_shop_recovery_items(
pt.push(e.value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
size_t effective_num_items = num_items;
size_t items_generated = 0;
@@ -1225,7 +1265,7 @@ void ItemCreator::generate_rare_tool_shop_recovery_items(
item.data1[0] = 3;
item.data1[1] = tool_item_defs[type].first;
item.data1[2] = tool_item_defs[type].second;
if (this->shop_does_not_contain_duplicate_item_by_primary_identifier(shop, item)) {
if (this->shop_does_not_contain_duplicate_item_by_data1_0_1_2(shop, item)) {
shop.emplace_back(std::move(item));
items_generated++;
}
@@ -1253,7 +1293,7 @@ void ItemCreator::generate_tool_shop_tech_disks(vector<ItemData>& shop, size_t p
pt.push(e.value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
static const array<uint8_t, 0x13> tech_num_map = {
0x00, 0x03, 0x06, 0x0F, 0x10, 0x0D, 0x0A, 0x0B, 0x0C, 0x01, 0x04, 0x07,
@@ -1354,7 +1394,7 @@ vector<ItemData> ItemCreator::generate_weapon_shop_contents(size_t player_level)
pt.push(e.value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
vector<ItemData> shop;
while (shop.size() < num_items) {
@@ -1554,7 +1594,7 @@ void ItemCreator::generate_weapon_shop_item_special(ItemData& item, size_t playe
// Note: The original code shuffles pt and then pops a single value from it.
// For simplicity, we just sample a single value (and don't pop it) instead.
switch (pt.sample(this->random_crypt)) {
switch (pt.sample(this->opt_rand_crypt)) {
case 0:
item.data1[4] = 0;
break;
@@ -1606,7 +1646,7 @@ void ItemCreator::generate_weapon_shop_item_bonus1(
// Note: The original code shuffles pt and then pops a single value from it.
// For simplicity, we just sample a single value (and don't pop it) instead.
item.data1[6] = pt.sample(this->random_crypt);
item.data1[6] = pt.sample(this->opt_rand_crypt);
if (item.data1[6] == 0) {
item.data1[7] = 0;
@@ -1647,7 +1687,7 @@ void ItemCreator::generate_weapon_shop_item_bonus2(ItemData& item, size_t player
pt.push(e.value);
}
}
pt.shuffle(this->random_crypt);
pt.shuffle(this->opt_rand_crypt);
do {
item.data1[8] = pt.pop();
@@ -1663,23 +1703,20 @@ void ItemCreator::generate_weapon_shop_item_bonus2(ItemData& item, size_t player
}
}
ItemData ItemCreator::on_specialized_box_item_drop(
uint16_t entity_id, uint8_t area, float def_z, uint32_t def0, uint32_t def1, uint32_t def2) {
if (this->destroyed_boxes.count(entity_id)) {
return ItemData();
}
ItemData item = this->base_item_for_specialized_box(def0, def1, def2);
ItemCreator::DropResult ItemCreator::on_specialized_box_item_drop(
uint8_t area, float def_z, uint32_t def0, uint32_t def1, uint32_t def2) {
DropResult res;
res.item = this->base_item_for_specialized_box(def0, def1, def2);
if (def_z == 0.0f) {
uint16_t type = item.data1w[0];
item.clear();
item.data1w[0] = type;
this->generate_common_item_variances(this->normalize_area_number(area), item);
uint16_t type = res.item.data1w[0];
res.item.clear();
res.item.data1w[0] = type;
this->generate_common_item_variances(this->normalize_area_number(area), res.item);
}
return item;
return res;
}
ItemData ItemCreator::base_item_for_specialized_box(uint32_t def0, uint32_t def1, uint32_t def2) {
ItemData ItemCreator::base_item_for_specialized_box(uint32_t def0, uint32_t def1, uint32_t def2) const {
ItemData item;
item.data1[0] = (def0 >> 0x18) & 0x0F;
item.data1[1] = (def0 >> 0x10) + ((item.data1[0] == 0x00) || (item.data1[0] == 0x01));
@@ -1708,7 +1745,7 @@ ItemData ItemCreator::base_item_for_specialized_box(uint32_t def0, uint32_t def1
if (item.data1[1] == 0x02) {
item.data1[4] = def0 & 0xFF;
}
item.set_tool_item_amount(1);
item.set_tool_item_amount(*this->stack_limits, 1);
break;
case 0x04:
item.data2d = ((def1 >> 0x10) & 0xFFFF) * 10;
@@ -1736,7 +1773,7 @@ ssize_t ItemCreator::apply_tekker_deltas(ItemData& item, uint8_t section_id) {
// Adjust the weapon's special
{
const auto& prob_table = this->tekker_adjustment_set->get_special_upgrade_prob_table(section_id, favored);
uint8_t delta_index = prob_table.sample(this->random_crypt);
uint8_t delta_index = prob_table.sample(this->opt_rand_crypt);
int8_t delta = delta_table.at(delta_index);
this->log.info("(Special) Delta index %hhu, delta %hhd", delta_index, delta);
// Note: The original code checks specifically for -1 and +1 here, but the
@@ -1753,13 +1790,15 @@ ssize_t ItemCreator::apply_tekker_deltas(ItemData& item, uint8_t section_id) {
} else {
new_special = item.data1[4];
}
if ((new_special != item.data1[4]) &&
(this->item_parameter_table->get_special(item.data1[4]).type ==
this->item_parameter_table->get_special(new_special).type)) {
this->log.info("(Special) Delta canceled because it would change special category");
item.data1[4] = new_special;
if (new_special != item.data1[4]) {
if (this->item_parameter_table->get_special(item.data1[4]).type ==
this->item_parameter_table->get_special(new_special).type) {
item.data1[4] = new_special;
} else {
this->log.info("(Special) Delta canceled because it would change special category");
}
}
} catch (const runtime_error&) {
} catch (const out_of_range&) {
// Invalid special number passed to get_special; just ignore it
}
luck += this->tekker_adjustment_set->get_luck_for_special_upgrade(delta_index);
@@ -1770,7 +1809,7 @@ ssize_t ItemCreator::apply_tekker_deltas(ItemData& item, uint8_t section_id) {
if (!this->item_parameter_table->is_item_rare(item)) {
const auto& weapon_def = this->item_parameter_table->get_weapon(item.data1[1], item.data1[2]);
const auto& prob_table = this->tekker_adjustment_set->get_grind_delta_prob_table(section_id, favored);
uint8_t delta_index = prob_table.sample(this->random_crypt);
uint8_t delta_index = prob_table.sample(this->opt_rand_crypt);
int8_t delta = delta_table.at(delta_index);
this->log.info("(Grind) Delta index %hhu, delta %hhd", delta_index, delta);
int16_t new_grind = static_cast<int16_t>(item.data1[3]) + static_cast<int16_t>(delta);
@@ -1786,7 +1825,7 @@ ssize_t ItemCreator::apply_tekker_deltas(ItemData& item, uint8_t section_id) {
const auto& prob_table = this->tekker_adjustment_set->get_bonus_delta_prob_table(section_id, favored);
// Note: The original code really does use the same delta for all three
// bonuses.
uint8_t delta_index = prob_table.sample(this->random_crypt);
uint8_t delta_index = prob_table.sample(this->opt_rand_crypt);
int8_t delta = delta_table.at(delta_index);
this->log.info("(Bonuses) Delta index %hhu, delta %hhd", delta_index, delta);
// Note: The original code doesn't check if there's actually a bonus in each
+24 -23
View File
@@ -19,26 +19,27 @@ public:
std::shared_ptr<const WeaponRandomSet> weapon_random_set,
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set,
std::shared_ptr<const ItemParameterTable> item_parameter_table,
Version version,
std::shared_ptr<const ItemData::StackLimits> stack_limits,
Episode episode,
GameMode mode,
uint8_t difficulty,
uint8_t section_id,
uint32_t random_seed,
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
std::shared_ptr<const BattleRules> restrictions = nullptr);
~ItemCreator() = default;
void set_random_state(uint32_t seed, uint32_t absolute_offset);
void clear_destroyed_entities();
void set_random_crypt(std::shared_ptr<PSOLFGEncryption> new_random_crypt);
ItemData on_monster_item_drop(uint16_t entity_id, uint32_t enemy_type, uint8_t area);
ItemData on_box_item_drop(uint16_t entity_id, uint8_t area);
ItemData on_specialized_box_item_drop(uint16_t entity_id, uint8_t area, float def_z, uint32_t def0, uint32_t def1, uint32_t def2);
struct DropResult {
ItemData item;
bool is_from_rare_table = false;
};
void set_monster_destroyed(uint16_t entity_id);
void set_box_destroyed(uint16_t entity_id);
DropResult on_monster_item_drop(uint32_t enemy_type, uint8_t area);
DropResult on_box_item_drop(uint8_t area);
DropResult on_specialized_box_item_drop(uint8_t area, float def_z, uint32_t def0, uint32_t def1, uint32_t def2);
static ItemData base_item_for_specialized_box(uint32_t def0, uint32_t def1, uint32_t def2);
ItemData base_item_for_specialized_box(uint32_t def0, uint32_t def1, uint32_t def2) const;
std::vector<ItemData> generate_armor_shop_contents(size_t player_level);
std::vector<ItemData> generate_tool_shop_contents(size_t player_level);
@@ -51,10 +52,15 @@ public:
inline void set_restrictions(std::shared_ptr<const BattleRules> restrictions) {
this->restrictions = restrictions;
}
inline uint8_t get_section_id() const {
return this->section_id;
}
void set_section_id(uint8_t new_section_id);
private:
PrefixedLogger log;
Version version;
Version logic_version;
std::shared_ptr<const ItemData::StackLimits> stack_limits;
Episode episode;
GameMode mode;
uint8_t difficulty;
@@ -65,30 +71,25 @@ private:
std::shared_ptr<const WeaponRandomSet> weapon_random_set;
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set;
std::shared_ptr<const ItemParameterTable> item_parameter_table;
std::shared_ptr<const CommonItemSet> common_item_set;
std::shared_ptr<const CommonItemSet::Table> pt;
std::shared_ptr<const BattleRules> restrictions;
struct UnitResult {
uint8_t unit;
int8_t modifier;
} __attribute__((packed));
} __packed_ws__(UnitResult, 2);
std::array<std::vector<UnitResult>, 13> unit_results_by_star_count;
// Note: The original implementation uses 17 different random states for some
// reason. We forego that and use only one for simplicity.
PSOV2Encryption random_crypt;
std::unordered_set<uint16_t> destroyed_monsters;
std::unordered_set<uint16_t> destroyed_boxes;
inline bool is_v3() const {
return !is_v1_or_v2(this->version);
}
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
bool are_rare_drops_allowed() const;
uint8_t normalize_area_number(uint8_t area) const;
ItemData on_monster_item_drop_with_area_norm(uint32_t enemy_type, uint8_t area_norm);
ItemData on_box_item_drop_with_area_norm(uint8_t area_norm);
DropResult on_monster_item_drop_with_area_norm(uint32_t enemy_type, uint8_t area_norm);
DropResult on_box_item_drop_with_area_norm(uint8_t area_norm);
uint32_t rand_int(uint64_t max);
float rand_float_0_1_from_crypt();
@@ -116,7 +117,7 @@ private:
void generate_common_armor_or_shield_type_and_variances(char area_norm, ItemData& item);
void generate_common_tool_variances(uint32_t area_norm, ItemData& item);
uint8_t generate_tech_disk_level(uint32_t tech_num, uint32_t area_norm);
void generate_common_mag_variances(ItemData& item) const;
void generate_common_mag_variances(ItemData& item);
void generate_common_weapon_variances(uint8_t area_norm, ItemData& item);
void generate_common_weapon_grind(ItemData& item, uint8_t offset_within_subtype_range);
void generate_common_weapon_bonuses(ItemData& item, uint8_t area_norm);
@@ -135,7 +136,7 @@ private:
const std::vector<ItemData>& shop, const ItemData& item);
static bool shop_does_not_contain_duplicate_or_too_many_similar_weapons(
const std::vector<ItemData>& shop, const ItemData& item);
static bool shop_does_not_contain_duplicate_item_by_primary_identifier(
static bool shop_does_not_contain_duplicate_item_by_data1_0_1_2(
const std::vector<ItemData>& shop, const ItemData& item);
void generate_armor_shop_armors(
std::vector<ItemData>& shop, size_t player_level);
+127 -46
View File
@@ -8,6 +8,39 @@
using namespace std;
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_11_2000(
{10});
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V1_V2(
{10, 10, 1, 10, 10, 10, 10, 10, 10, 1});
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4(
{10, 10, 1, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 99, 1});
ItemData::StackLimits::StackLimits(
Version version, const vector<uint8_t>& max_tool_stack_sizes_by_data1_1, uint32_t max_meseta_stack_size)
: version(version),
max_tool_stack_sizes_by_data1_1(max_tool_stack_sizes_by_data1_1),
max_meseta_stack_size(max_meseta_stack_size) {}
ItemData::StackLimits::StackLimits(Version version, const JSON& json)
: version(version) {
this->max_tool_stack_sizes_by_data1_1.clear();
for (const auto& limit_json : json.at("ToolLimits").as_list()) {
this->max_tool_stack_sizes_by_data1_1.emplace_back(limit_json->as_int());
}
this->max_meseta_stack_size = json.at("MesetaLimit").as_int();
}
uint8_t ItemData::StackLimits::get(uint8_t data1_0, uint8_t data1_1) const {
if (data1_0 == 4) {
return this->max_meseta_stack_size;
}
if (data1_0 == 3) {
const auto& vec = this->max_tool_stack_sizes_by_data1_1;
return vec.at(min<size_t>(data1_1, vec.size() - 1));
}
return 1;
}
ItemData::ItemData() {
this->clear();
}
@@ -68,23 +101,32 @@ bool ItemData::empty() const {
}
uint32_t ItemData::primary_identifier() const {
// Primary identifiers are like:
// - 00TTSS00 = weapon (T = type, S = subtype; subtype is 0 for ES weapons)
// - 01TTSS00 = armor/shield/unit
// - 02TT0000 = mag
// - 0302ZZLL = tech disk (Z = tech number, L = level)
// - 03TTSS00 = tool
// - 04000000 = meseta
// The game treats any item starting with 04 as Meseta, and ignores the rest
// of data1 (the value is in data2)
if (this->data1[0] == 0x04) {
return 0x040000;
return 0x04000000;
}
if (this->data1[0] == 0x03 && this->data1[1] == 0x02) {
return 0x030200; // Tech disk (data1[2] is level, so omit it)
// Tech disk (tech ID is data1[4], not [2])
return 0x03020000 | (this->data1[4] << 8) | this->data1[2];
} else if (this->data1[0] == 0x02) {
return 0x020000 | (this->data1[1] << 8); // Mag
return 0x02000000 | (this->data1[1] << 16); // Mag
} else if (this->is_s_rank_weapon()) {
return (this->data1[0] << 16) | (this->data1[1] << 8);
return (this->data1[0] << 24) | (this->data1[1] << 16);
} else {
return (this->data1[0] << 16) | (this->data1[1] << 8) | this->data1[2];
return (this->data1[0] << 24) | (this->data1[1] << 16) | (this->data1[2] << 8);
}
}
bool ItemData::is_wrapped() const {
bool ItemData::is_wrapped(const StackLimits& limits) const {
switch (this->data1[0]) {
case 0:
case 1:
@@ -92,7 +134,7 @@ bool ItemData::is_wrapped() const {
case 2:
return this->data2[2] & 0x40;
case 3:
return !this->is_stackable() && (this->data1[3] & 0x40);
return !this->is_stackable(limits) && (this->data1[3] & 0x40);
case 4:
return false;
default:
@@ -100,7 +142,7 @@ bool ItemData::is_wrapped() const {
}
}
void ItemData::wrap() {
void ItemData::wrap(const StackLimits& limits) {
switch (this->data1[0]) {
case 0:
case 1:
@@ -110,7 +152,7 @@ void ItemData::wrap() {
this->data2[2] |= 0x40;
break;
case 3:
if (!this->is_stackable()) {
if (!this->is_stackable(limits)) {
this->data1[3] |= 0x40;
}
break;
@@ -121,7 +163,7 @@ void ItemData::wrap() {
}
}
void ItemData::unwrap() {
void ItemData::unwrap(const StackLimits& limits) {
switch (this->data1[0]) {
case 0:
case 1:
@@ -131,7 +173,7 @@ void ItemData::unwrap() {
this->data2[2] &= 0xBF;
break;
case 3:
if (!this->is_stackable()) {
if (!this->is_stackable(limits)) {
this->data1[3] &= 0xBF;
}
break;
@@ -142,32 +184,31 @@ void ItemData::unwrap() {
}
}
bool ItemData::is_stackable() const {
return this->max_stack_size() > 1;
bool ItemData::is_stackable(const StackLimits& limits) const {
return this->max_stack_size(limits) > 1;
}
size_t ItemData::stack_size() const {
if (max_stack_size_for_item(this->data1[0], this->data1[1]) > 1) {
size_t ItemData::stack_size(const StackLimits& limits) const {
if (this->max_stack_size(limits) > 1) {
return this->data1[5];
}
return 1;
}
size_t ItemData::max_stack_size() const {
return max_stack_size_for_item(this->data1[0], this->data1[1]);
size_t ItemData::max_stack_size(const StackLimits& limits) const {
return limits.get(this->data1[0], this->data1[1]);
}
void ItemData::enforce_min_stack_size() {
if (this->stack_size() == 0) {
void ItemData::enforce_min_stack_size(const StackLimits& limits) {
if (this->stack_size(limits) == 0) {
this->data1[5] = 1;
}
}
bool ItemData::is_common_consumable(uint32_t primary_identifier) {
if (primary_identifier == 0x030200) {
return false;
}
return (primary_identifier >= 0x030000) && (primary_identifier < 0x030A00);
return (primary_identifier >= 0x03000000) &&
(primary_identifier < 0x030A0000) &&
((primary_identifier & 0xFFFF0000) != 0x03020000);
}
bool ItemData::is_common_consumable() const {
@@ -298,15 +339,15 @@ void ItemData::add_mag_photon_blast(uint8_t pb_num) {
}
if (pb_num >= 4) {
throw runtime_error("left photon blast number is too high");
pb_nums |= (pb_num << 6);
}
pb_nums |= (pb_num << 6);
flags |= 4;
}
}
void ItemData::decode_for_version(Version from_version) {
uint8_t encoded_v2_data = this->get_encoded_v2_data();
bool should_decode_v2_data = (is_v1(from_version) || is_v2(from_version)) &&
bool should_decode_v2_data = (is_v1(from_version) || is_v2(from_version)) && (from_version != Version::GC_NTE) &&
(encoded_v2_data != 0x00) && this->has_encoded_v2_data();
switch (this->data1[0]) {
@@ -330,13 +371,9 @@ void ItemData::decode_for_version(Version from_version) {
this->data1[1] = encoded_v2_data + 0x2B;
}
if (is_big_endian(from_version)) {
// PSO GC erroneously byteswaps the data2d field, even though it's actually
// just four individual bytes, so we correct for that here.
this->data2d = bswap32(this->data2d);
} else if (is_v1(from_version) || is_v2(from_version)) {
// PSO PC encodes mags in a tediously annoying manner. The first four bytes are the same, but then...
if (is_v1(from_version) || is_v2(from_version)) {
// PSO PC and GC NTE encode mags in a tediously annoying manner. The
// first four bytes are the same, but then...
// V2: pHHHHHHHHHHHHHHc pIIIIIIIIIIIIIIc JJJJJJJJJJJJJJJc KKKKKKKKKKKKKKKc QQQQQQQQ QQQQQQQQ YYYYYYYY pYYYYYYY
// V3: HHHHHHHHHHHHHHHH IIIIIIIIIIIIIIII JJJJJJJJJJJJJJJJ KKKKKKKKKKKKKKKK YYYYYYYY QQQQQQQQ PPPPPPPP CCCCCCCC
// c = color in V2 (4 bits; low bit first)
@@ -352,10 +389,18 @@ void ItemData::decode_for_version(Version from_version) {
this->data2[0] = this->data2w[1] & 0x7FFF; // Synchro
this->data2[2] = ((this->data2[3] >> 7) & 1) | ((this->data1w[2] >> 14) & 2) | ((this->data1w[3] >> 13) & 4); // PB flags
this->data2[3] = (this->data1w[2] & 1) | ((this->data1w[3] & 1) << 1) | ((this->data1w[4] & 1) << 2) | ((this->data1w[5] & 1) << 3); // Color
// 01000080
this->data1w[2] &= 0x7FFE;
this->data1w[3] &= 0x7FFE;
this->data1w[4] &= 0xFFFE;
this->data1w[5] &= 0xFFFE;
} else if (is_big_endian(from_version)) {
// PSO GC (but not GC NTE, which uses the above logic) byteswaps the
// data2d field, since internally it's actually a uint32_t. We treat it
// as individual bytes instead, so we correct for the client's
// byteswapping here.
this->data2d = bswap32(this->data2d);
}
break;
@@ -386,7 +431,7 @@ void ItemData::decode_for_version(Version from_version) {
}
void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParameterTable> item_parameter_table) {
bool should_encode_v2_data = (is_v1(to_version) || is_v2(to_version)) && !this->has_encoded_v2_data();
bool should_encode_v2_data = (is_v1(to_version) || is_v2(to_version)) && (to_version != Version::GC_NTE) && !this->has_encoded_v2_data();
switch (this->data1[0]) {
case 0x00:
@@ -425,9 +470,7 @@ void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParam
// This logic is the inverse of the corresponding logic in
// decode_for_version; see that function for a description of what's
// going on here.
if (is_big_endian(to_version)) {
this->data2d = bswap32(this->data2d);
} else if (is_v1(to_version) || is_v2(to_version)) {
if (is_v1(to_version) || is_v2(to_version)) {
this->data1w[2] = (this->data1w[2] & 0x7FFE) | ((this->data2[2] << 14) & 0x8000) | (this->data2[3] & 1);
this->data1w[3] = (this->data1w[3] & 0x7FFE) | ((this->data2[2] << 13) & 0x8000) | ((this->data2[3] >> 1) & 1);
this->data1w[4] = (this->data1w[4] & 0xFFFE) | ((this->data2[3] >> 2) & 1);
@@ -435,6 +478,8 @@ void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParam
// Order is important; data2w[0] must not be written before data2[0] is read
this->data2w[1] = this->data2[0] | ((this->data2[2] << 15) & 0x8000);
this->data2w[0] = this->data2[1];
} else if (is_big_endian(to_version)) {
this->data2d = bswap32(this->data2d);
}
break;
@@ -502,12 +547,12 @@ void ItemData::set_sealed_item_kill_count(uint16_t v) {
}
}
uint8_t ItemData::get_tool_item_amount() const {
return this->is_stackable() ? this->data1[5] : 1;
uint8_t ItemData::get_tool_item_amount(const StackLimits& limits) const {
return this->is_stackable(limits) ? this->data1[5] : 1;
}
void ItemData::set_tool_item_amount(uint8_t amount) {
if (this->is_stackable()) {
void ItemData::set_tool_item_amount(const StackLimits& limits, uint8_t amount) {
if (this->is_stackable(limits)) {
this->data1[5] = amount;
} else if (this->data1[0] == 0x03) {
this->data1[5] = 0x00;
@@ -628,6 +673,10 @@ bool ItemData::can_be_equipped_in_slot(EquipSlot slot) const {
}
}
bool ItemData::can_be_encoded_in_rel_rare_table() const {
return !(this->data1[3] || this->data1d[1] || this->data1d[2] || this->data2d);
}
bool ItemData::compare_for_sort(const ItemData& a, const ItemData& b) {
for (size_t z = 0; z < 12; z++) {
if (a.data1[z] < b.data1[z]) {
@@ -647,6 +696,9 @@ bool ItemData::compare_for_sort(const ItemData& a, const ItemData& b) {
}
ItemData ItemData::from_data(const string& data) {
if (data.size() < 2) {
throw runtime_error("data is too short");
}
if (data.size() > 0x10) {
throw runtime_error("data is too long");
}
@@ -658,14 +710,43 @@ ItemData ItemData::from_data(const string& data) {
for (size_t z = 12; z < min<size_t>(data.size(), 16); z++) {
ret.data2[z - 12] = data[z];
}
if (ret.data1[0] > 4) {
throw runtime_error("invalid item class");
}
return ret;
}
ItemData ItemData::from_primary_identifier(const StackLimits& limits, uint32_t primary_identifier) {
ItemData ret;
if (primary_identifier > 0x04000000) {
throw runtime_error("invalid item class");
}
ret.data1[0] = (primary_identifier >> 24) & 0xFF;
ret.data1[1] = (primary_identifier >> 16) & 0xFF;
if ((primary_identifier & 0xFFFF0000) == 0x03020000) {
ret.data1[4] = (primary_identifier >> 8) & 0xFF;
ret.data1[2] = primary_identifier & 0xFF;
} else {
ret.data1[2] = (primary_identifier >> 8) & 0xFF;
}
ret.set_tool_item_amount(limits, 1);
return ret;
}
string ItemData::hex() const {
return string_printf("%02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX (%08" PRIX32 ") %02hhX%02hhX%02hhX%02hhX",
this->data1[0], this->data1[1], this->data1[2], this->data1[3],
this->data1[4], this->data1[5], this->data1[6], this->data1[7],
this->data1[8], this->data1[9], this->data1[10], this->data1[11],
this->id.load(),
this->data2[0], this->data2[1], this->data2[2], this->data2[3]);
return string_printf("%08" PRIX32 " %08" PRIX32 " %08" PRIX32 " (%08" PRIX32 ") %08" PRIX32,
this->data1db[0].load(), this->data1db[1].load(), this->data1db[2].load(), this->id.load(), this->data2db.load());
}
string ItemData::short_hex() const {
auto ret = string_printf("%08" PRIX32 "%08" PRIX32 "%08" PRIX32 "%08" PRIX32,
this->data1db[0].load(), this->data1db[1].load(), this->data1db[2].load(), this->data2db.load());
size_t offset = ret.find_last_not_of('0');
if (offset != string::npos) {
offset += (offset & 1) ? 1 : 2;
if (offset < ret.size()) {
ret.resize(offset);
}
}
return ret;
}

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