Compare commits

...

187 Commits

Author SHA1 Message Date
Martin Michelsen 5ea3d0ad4b add missing quest files 2024-07-10 20:41:18 -07:00
Martin Michelsen 90efde7aa9 handle rare shell i/o error 2024-07-10 19:48:51 -07:00
Martin Michelsen 55f1869125 add replace sound effects code 2024-07-08 01:08:43 -07:00
Martin Michelsen b4efd90fdc replace q050 and q052 with direct backports 2024-07-07 16:39:52 -07:00
Martin Michelsen 87dd554592 remove offset comments in reassembly mode 2024-07-07 15:19:18 -07:00
Martin Michelsen 58974ae1be use JP version as default sub_version 2024-07-06 12:57:30 -07:00
Martin Michelsen 21c8bab91c handle one 6x63 data race 2024-07-06 09:54:07 -07:00
Martin Michelsen c58b37be23 add GC-GJAM quest opcodes in handler-tables 2024-07-05 21:55:16 -07:00
Martin Michelsen d3d98c44b8 clear ep3 media when switching to proxy server 2024-07-04 16:25:21 -07:00
Martin Michelsen dc2e73d198 fix item notifications for mags on GC 2024-07-04 16:24:36 -07:00
Martin Michelsen 774f9649da fix binary operator bind order 2024-07-04 16:24:18 -07:00
Martin Michelsen 093287af75 fix condition icons in enemy HP bars patch 2024-06-29 22:25:32 -07:00
Martin Michelsen 0126189cbd fix 3OJ2 and 3OJ3 item loss patches 2024-06-29 12:22:27 -07:00
Martin Michelsen c250a2dbc4 update enemy HP bars patch 2024-06-28 20:57:16 -07:00
Martin Michelsen 2ff9df19c8 don't allow language fallback for q88500 2024-06-28 14:10:06 -07:00
Martin Michelsen 528593651b update TODO.md 2024-06-28 10:13:24 -07:00
Martin Michelsen 9f073d07cd don't use member initialization 2024-06-28 10:10:39 -07:00
Martin Michelsen 4bd6ef12a9 implement $savechar on Episode 3 2024-06-28 09:48:09 -07:00
Martin Michelsen 52644695a3 fix grind limit overdraft 2024-06-26 20:00:22 -07:00
Martin Michelsen 45e619718c fix patch menu on BB 2024-06-26 19:37:21 -07:00
nolrinale 43fd979763 Fixed Coren rewards item names causing parsing issues 2024-06-26 09:36:21 -07:00
Martin Michelsen 082bc49a4d add customization segregation test 2024-06-24 00:01:09 -07:00
Martin Michelsen 4adcaa7bee skip max grind check on v3 2024-06-24 00:00:48 -07:00
Martin Michelsen 630ae0beb4 fix stack limits on DC NTE 2024-06-23 22:38:46 -07:00
Martin Michelsen 246dfd9fe0 update notes on DC NTE quest commands 2024-06-23 22:38:46 -07:00
Martin Michelsen 6f056cb1bd update proxy options 2024-06-23 22:38:46 -07:00
Martin Michelsen 9322c023da fix missing sub_version check 2024-06-23 22:38:46 -07:00
Martin Michelsen fd4719f8ec clean up comments in q88500 2024-06-23 08:38:51 -07:00
Martin Michelsen 3a22a5c489 add Ep3 codepaths to B2 enabler 2024-06-23 00:24:01 -07:00
Martin Michelsen 862b3d27da add B2 patch support on PSO Plus 2024-06-22 21:42:30 -07:00
Martin Michelsen 998664d2fb add loading screen AR code 2024-06-22 17:22:02 -07:00
Martin Michelsen 0bf2d950ac fix offsets on DCv1 item loss patches 2024-06-22 15:23:38 -07:00
Martin Michelsen 3ae5e875a1 fix comments on some quest opcodes 2024-06-22 15:23:23 -07:00
Martin Michelsen a88795d8b9 fix edge case in quest episode detection 2024-06-22 15:22:52 -07:00
Martin Michelsen 9ca1b79409 add .include directives in quest assembler 2024-06-22 15:22:32 -07:00
Martin Michelsen ce8277b96a describe 6x51 command 2024-06-22 15:20:48 -07:00
Martin Michelsen 25731eb71f add comments about UDP subcommands 2024-06-22 15:20:39 -07:00
Martin Michelsen e55963b82b specify types on some quest handlers 2024-06-22 14:22:29 -07:00
Martin Michelsen b9d9b38351 add US v1.2 quest opcodes to handler-tables 2024-06-22 09:29:40 -07:00
Martin Michelsen 782babf3ae add quest opcode names in handler-tables 2024-06-22 09:07:37 -07:00
Martin Michelsen 9869fa03c2 only send notifs for client-generated items if the game drop mode is CLIENT 2024-06-21 11:02:59 -07:00
Martin Michelsen 0ae02b0191 add websocket endpoint for rare drop stream 2024-06-21 10:59:01 -07:00
Martin Michelsen c0ea976fdc fix typo in VersionDetectGC 2024-06-21 10:59:01 -07:00
nolrinale c4bf9e7d5b Adjusted Coren rewards to match Retail server ones 2024-06-20 20:24:05 -07:00
Martin Michelsen 2e5d95d612 fix data race in 6xCA command 2024-06-19 23:31:51 -07:00
nolrinale 75b2827da9 Corrected BB english client files 2024-06-18 19:37:37 -07:00
Martin Michelsen 5b72e59ebe fix mag flag reset during combo item apply 2024-06-18 09:56:29 -07:00
Matt Swift d2c16b5363 Add Ultimate Map Fix for DCv2 2024-06-18 09:53:08 -07:00
Martin Michelsen 977ed05526 don't let item parsing from config.json prevent server startup 2024-06-18 08:55:55 -07:00
Martin Michelsen e2c34dfb70 add option to enable switch assist by default 2024-06-17 22:02:31 -07:00
Martin Michelsen 4416579210 add 11/2000 item loss patch 2024-06-17 00:42:31 -07:00
Martin Michelsen 5f591ac189 add DCv1 item loss patches 2024-06-16 23:50:37 -07:00
Martin Michelsen aa9d2beffe convert all CRLF line endings to LF only 2024-06-16 21:03:00 -07:00
Martin Michelsen 24656d587b make $where show other players' floors 2024-06-16 11:03:44 -07:00
Martin Michelsen fbaf7d722d delete overlay before parsing character data in 98 command 2024-06-16 10:44:16 -07:00
Martin Michelsen bda5c40cc2 fix disassembly of invalid episode numbers in quest headers 2024-06-16 10:44:00 -07:00
Martin Michelsen eeac5ccf4d refine battle mode commands structures 2024-06-16 10:43:46 -07:00
Martin Michelsen bbff30071e fix battle mode level up on players close to level 200 2024-06-16 10:11:35 -07:00
Martin Michelsen a7a512682c fix unsealable item kill count check 2024-06-16 00:10:12 -07:00
Martin Michelsen f3f933aaca add lobby order option for client customization 2024-06-15 17:25:58 -07:00
Martin Michelsen 5433663866 fix Guild Card comment update on BB 2024-06-15 17:11:31 -07:00
Martin Michelsen 598120c661 implement BB EXP share 2024-06-15 16:45:09 -07:00
Martin Michelsen d4f885fad1 fix 6xE3 client ID field 2024-06-15 15:20:08 -07:00
Martin Michelsen 8ab1eabda7 remove TODO 2024-06-15 15:09:43 -07:00
Martin Michelsen d23775f069 use overlay for 07ED command 2024-06-15 10:18:19 -07:00
Martin Michelsen de45f49b78 add name color for IS_CLIENT_CUSTOMIZATION flag 2024-06-15 09:56:04 -07:00
Martin Michelsen 2608d5d601 fix episode 4 bonus value tables 2024-06-14 23:43:36 -07:00
Martin Michelsen 92df4ff1e2 add CommonItemSet introspection 2024-06-14 23:41:29 -07:00
Martin Michelsen 27ecab2993 fix register reassignment if name doesn't appear first in file 2024-06-13 23:38:20 -07:00
Martin Michelsen 3dc106b42e add comments in EventUtils 2024-06-10 20:20:51 -07:00
Martin Michelsen 768e8bbfe2 make label/register assignment order deterministic 2024-06-04 22:08:18 -07:00
Martin Michelsen 324f681c46 use concise existence checks in test scripts 2024-06-04 21:28:20 -07:00
Martin Michelsen d178d062a8 add named registers in quest assembler 2024-06-04 21:17:22 -07:00
Martin Michelsen 3ac421cf55 add note about GC target crashes 2024-06-03 21:00:42 -07:00
Martin Michelsen 0e9bd019af add comment about TItemDrop random states 2024-06-02 08:43:38 -07:00
Martin Michelsen 5ce4eb8cfc fix unary operator bind order in integral tree parser 2024-05-31 23:05:19 -07:00
Martin Michelsen 64082fa872 fix attribution on some patch ports 2024-05-28 22:52:10 -07:00
Martin Michelsen 063f67d3f6 add section on license 2024-05-28 22:12:40 -07:00
Martin Michelsen 5df98fb691 speed up quest loading 2024-05-28 22:12:17 -07:00
Martin Michelsen a686d81d4c fix gcc-specific compiler warnings 2024-05-28 22:12:17 -07:00
Martin Michelsen bc9fc25799 add number as well as name for when 2024-05-28 22:12:17 -07:00
Martin Michelsen 07d8e1df7b add enum for when 2024-05-28 22:12:17 -07:00
Martin Michelsen 7427fbd252 add room unlock sound in swsetall 2024-05-28 22:12:17 -07:00
Martin Michelsen 679f58937f move ep3 offline maps to not be available by default 2024-05-28 22:12:17 -07:00
Martin Michelsen af5770058b sync config files after major quest update 2024-05-28 22:12:17 -07:00
Matt Swift d2cb7a4cb8 Actually make Caelum C1 2v2 compatible 2024-05-28 22:12:17 -07:00
Matt Swift 62c778d877 Update Caelum C1 to be 2v2 compatible 2024-05-28 22:12:17 -07:00
Matt Swift 9dd6339fe8 Add custom content for Episode 3 2024-05-28 22:12:17 -07:00
Matt Swift 7b6b8151a7 Add custom content and backports for V1 to V3 2024-05-28 22:12:17 -07:00
Martin Michelsen e77ee397cd improve bank handling across version boundaries 2024-05-28 22:12:17 -07:00
Matt Swift 8775367043 Fix typo in GC targets for XB 2024-05-24 10:16:59 -07:00
Martin Michelsen ba752eb7dc update GC connection instructions in readme 2024-05-23 21:52:17 -07:00
Martin Michelsen 8421ab16d5 fix xbox rare alert patch 2024-05-22 22:13:47 -07:00
Martin Michelsen 340a36878b add $qfread command 2024-05-22 21:19:53 -07:00
Martin Michelsen 836704e987 track telepipe state in games 2024-05-21 20:29:32 -07:00
Martin Michelsen d0ff9bd048 update specific_version comments 2024-05-21 20:29:32 -07:00
Martin Michelsen 001c2c905f fix BB item subcommands in joinable quests 2024-05-19 09:06:38 -07:00
Martin Michelsen 443a0a3037 prevent players from joining game when quest menu is open 2024-05-19 09:06:38 -07:00
Martin Michelsen d294dbcc55 actually add v2/v3 level tables 2024-05-18 23:21:16 -07:00
Martin Michelsen 0c63d6a07f add v2/v3 level table files 2024-05-18 23:16:28 -07:00
Martin Michelsen 3f6157c03f add 3OJT versions of PlayerInfo patches 2024-05-18 23:16:05 -07:00
Martin Michelsen c8eab046c0 add GC NTE save file format 2024-05-18 21:25:11 -07:00
Martin Michelsen d8230eb37a load non-v4 level tables 2024-05-17 20:32:52 -07:00
Martin Michelsen f71980382a add favored weapon type table in comments 2024-05-16 21:35:21 -07:00
Martin Michelsen 0a8678fda7 fix tekker section id 2024-05-16 19:57:46 -07:00
Martin Michelsen adb5d51510 update save file structs and encode/decode pathways 2024-05-15 22:06:11 -07:00
Martin Michelsen 45679a7f98 add index comments in shop generator 2024-05-15 22:05:34 -07:00
Martin Michelsen f6f5ca47e9 fix flag check during mag evolution 2024-05-15 10:01:38 -07:00
Martin Michelsen a4ade28755 fix BB team flag transparency 2024-05-13 22:43:12 -07:00
Martin Michelsen c957ea6c10 reorganize some quests 2024-05-13 22:34:37 -07:00
Martin Michelsen 6bfb84d999 fix joinability flags on Japanese BB government quests 2024-05-13 22:16:44 -07:00
Martin Michelsen 49fbacf0fa make ep4 quests use orange icon 2024-05-13 21:55:42 -07:00
Martin Michelsen 79efce5252 fix Tethealla client detection 2024-05-13 21:55:32 -07:00
Martin Michelsen cb9a0ed1c4 move illegal delay slot instructions out of delay slots 2024-05-13 21:13:52 -07:00
Martin Michelsen fc5788364b don't encode/decode inventories in GC extended player data 2024-05-13 20:47:21 -07:00
Martin Michelsen df2b64a601 fix big-endian ints in xbox save file format 2024-05-13 20:40:36 -07:00
Martin Michelsen 2ff75fe132 implement savechar/loadchar on DCv2 and Xbox 2024-05-12 22:40:43 -07:00
Martin Michelsen 625e8e0624 recompress all quest files 2024-05-12 16:16:45 -07:00
Martin Michelsen de8ed72233 fix disassembly of max_players header field 2024-05-12 16:11:03 -07:00
Martin Michelsen ce2607253c add missing JP quests from PR #486 2024-05-12 16:08:57 -07:00
Martin Michelsen b6fb9051b6 refine PC save file format 2024-05-12 15:09:31 -07:00
Martin Michelsen f069622b94 add DCv1 save file structure 2024-05-12 00:17:52 -07:00
Martin Michelsen 0b7e532b32 clarify $infhp behaviors 2024-05-11 22:34:12 -07:00
Martin Michelsen f4e6a40097 clean up SaveFileFormats.hh 2024-05-11 22:31:16 -07:00
Martin Michelsen 2ed97974e0 add CallProtectedHandler on BB 2024-05-11 22:31:09 -07:00
Martin Michelsen 251a9ecd0a add DC version of GetExtendedPlayerInfo 2024-05-11 21:33:31 -07:00
Martin Michelsen 777ffc1108 update GC connection instructions 2024-05-11 19:36:39 -07:00
Martin Michelsen 3951a46386 fix typo in readme 2024-05-11 19:33:23 -07:00
Martin Michelsen bfbf1ba87e update BB connection instructions 2024-05-11 19:30:17 -07:00
Martin Michelsen dc7c3eb58c add DC v2 save file format 2024-05-11 18:18:17 -07:00
Martin Michelsen a0126bd6b5 fix bug in GetExtendedPlayerInfoGC 2024-05-11 18:18:17 -07:00
Martin Michelsen c86ecbe9ef explicitly clear unsaved flag in DC item loss patch 2024-05-11 14:28:31 -07:00
Martin Michelsen 99a606be18 add flag 0x40 in part2 2024-05-11 14:28:08 -07:00
Martin Michelsen 7ebae9ed9d update check_for_hacking quest opcode flags 2024-05-11 14:27:54 -07:00
Martin Michelsen e803ca54c6 update DC item loss patches 2024-05-10 00:37:09 -07:00
Martin Michelsen d619bff349 update xbox network location struct 2024-05-10 00:36:53 -07:00
Martin Michelsen c7cb81e0fc add DCv2 item loss prevention patch 2024-05-09 00:24:50 -07:00
Martin Michelsen f7c847bcf0 fix comment 2024-05-08 21:04:10 -07:00
Martin Michelsen b81d119906 update 6x49 command name 2024-05-07 21:34:13 -07:00
Martin Michelsen 5535d749b9 update headers in handler tables 2024-05-07 21:30:34 -07:00
Martin Michelsen 992d204a83 recompress all quest files 2024-05-07 20:29:21 -07:00
Martin Michelsen b478c035bb deduplicate E/J government quest dat files 2024-05-07 20:12:30 -07:00
nolrinale 0f81d98c6e Adjusted quest filtering defaults for BB's Gov. Quests 2024-05-07 19:10:41 -07:00
nolrinale edc659a241 Adds all the Government quests in Japanese for BB 2024-05-07 19:10:41 -07:00
Martin Michelsen ef08805f93 add BB idle disconnect patch 2024-05-06 09:11:39 -07:00
Martin Michelsen 70413668d8 support B2 patches on BB 2024-05-05 10:52:09 -07:00
Martin Michelsen 27bbb2c7e4 add --language option to disassemble_quest_script 2024-05-05 09:03:08 -07:00
Martin Michelsen 43ad1597a4 change quest category menu icons 2024-05-05 08:47:08 -07:00
Martin Michelsen ce0badde87 fix mag stats reset on item combination 2024-05-05 08:42:59 -07:00
Martin Michelsen 9d46d1042b more ep3 debugging 2024-05-05 08:42:44 -07:00
Martin Michelsen 2e7c792b97 fix equip state after item combinations applied 2024-05-04 20:39:52 -07:00
Martin Michelsen c411cec06c remove debug stub 2024-05-04 12:28:49 -07:00
Martin Michelsen 451c8d5e09 add DC idle disconnect patch 2024-05-04 11:52:06 -07:00
Martin Michelsen a35753fdf1 add GetExtendedPlayerInfo for xbox 2024-05-04 11:20:44 -07:00
Martin Michelsen ca6605877a set up DC patch framework 2024-05-04 10:51:42 -07:00
Martin Michelsen 59db3c82f9 generalize ARCodeTranslator 2024-05-04 10:49:51 -07:00
Martin Michelsen e42cfb649f fix NPC inventory item creation 2024-05-03 10:10:56 -07:00
Martin Michelsen cf88455975 override BB player language code at load time 2024-05-02 22:51:24 -07:00
Martin Michelsen b272f2326e check old drop tables against new tables 2024-05-02 21:43:24 -07:00
Martin Michelsen a29494b120 describe 6x8A in more detail 2024-05-02 09:47:18 -07:00
Martin Michelsen 4d172fff64 fix challenge mode times window 2024-05-01 23:26:46 -07:00
Martin Michelsen 57ea246dd7 prep for $loadchar on xbox 2024-05-01 23:26:46 -07:00
Martin Michelsen 636309952e don't allow loading quests in incorrect game mode 2024-05-01 08:31:00 -07:00
Martin Michelsen dfeeed2b1a clarify comments in b88001.json 2024-04-30 22:32:49 -07:00
Martin Michelsen f83822bba0 add option to allow $quest without $debug for certain quests 2024-04-30 22:27:45 -07:00
Martin Michelsen 60f67fa791 add debugging for compute_effective_range_and_target_mode_for_attack 2024-04-30 21:30:45 -07:00
Martin Michelsen 9b6a6e4412 fix HTTP server segfault if proxy server is disabled 2024-04-30 09:11:02 -07:00
Martin Michelsen 83b8c199b9 support GetExtendedPlayerInfo on xbox 2024-04-30 09:10:10 -07:00
Martin Michelsen 3f1939e674 increase number of savechar slots to 16 2024-04-29 22:21:08 -07:00
Martin Michelsen 31616954cc implement extended $loadchar on GC 2024-04-28 23:48:02 -07:00
Martin Michelsen ee21885f13 add more missing initializers 2024-04-28 15:38:57 -07:00
Martin Michelsen 2cc6a85d4b add missing initializer 2024-04-28 15:33:40 -07:00
Martin Michelsen 29320f0858 don't skip server data commands before battle start 2024-04-28 15:19:31 -07:00
Martin Michelsen 29f200b83e add a way for joinable quests to lock themselves 2024-04-28 00:23:21 -07:00
Martin Michelsen 09bf81f77f fix duplicate 6xDD commands 2024-04-27 18:31:10 -07:00
Martin Michelsen ddbb922b95 support joinable quests on all versions 2024-04-27 18:31:10 -07:00
Martin Michelsen c7dd98ccc0 use flag to separate customized GC clients from non-customized 2024-04-27 14:25:46 -07:00
Martin Michelsen f5c2c930d8 don't use $CG in any server announcements 2024-04-27 12:08:31 -07:00
Martin Michelsen 79fee4cec4 explain overwritten field in DecoctionXB 2024-04-27 10:26:02 -07:00
Martin Michelsen 0bec4d0f49 update sub_version conditions 2024-04-27 10:25:45 -07:00
Martin Michelsen a4fc133d75 block 6xB2 in most cases 2024-04-26 21:09:21 -07:00
Martin Michelsen 45c9dc9a23 rename PSOXReticleColors to match convention 2024-04-26 20:43:47 -07:00
Martin Michelsen 594ffbe7e6 add xbox rare drop notifs patch 2024-04-25 20:00:19 -07:00
Martin Michelsen 7decab75c2 update 6xB2 structure 2024-04-24 23:35:15 -07:00
Martin Michelsen 9815126ced save battle records when CA handler raises 2024-04-23 22:36:29 -07:00
Martin Michelsen 4b5eba3727 upgrade to c++23 2024-04-23 22:23:25 -07:00
Martin Michelsen 49010b02f1 sort CMakeLists 2024-04-22 22:07:04 -07:00
2976 changed files with 82950 additions and 180930 deletions
+4 -4
View File
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.10)
project(newserv) project(newserv)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
if (MSVC) if (MSVC)
add_compile_options(/W4 /WX) add_compile_options(/W4 /WX)
@@ -90,6 +90,7 @@ set(SOURCES
src/GSLArchive.cc src/GSLArchive.cc
src/GVMEncoder.cc src/GVMEncoder.cc
src/HTTPServer.cc src/HTTPServer.cc
src/IntegralExpression.cc
src/IPFrameInfo.cc src/IPFrameInfo.cc
src/IPStackSimulator.cc src/IPStackSimulator.cc
src/IPV4RangeSet.cc src/IPV4RangeSet.cc
@@ -105,8 +106,8 @@ set(SOURCES
src/Map.cc src/Map.cc
src/Menu.cc src/Menu.cc
src/NetworkAddresses.cc src/NetworkAddresses.cc
src/PatchServer.cc
src/PatchFileIndex.cc src/PatchFileIndex.cc
src/PatchServer.cc
src/PlayerFilesManager.cc src/PlayerFilesManager.cc
src/PlayerSubordinates.cc src/PlayerSubordinates.cc
src/ProxyCommands.cc src/ProxyCommands.cc
@@ -115,7 +116,6 @@ set(SOURCES
src/PSOGCObjectGraph.cc src/PSOGCObjectGraph.cc
src/PSOProtocol.cc src/PSOProtocol.cc
src/Quest.cc src/Quest.cc
src/IntegralExpression.cc
src/QuestScript.cc src/QuestScript.cc
src/RareItemSet.cc src/RareItemSet.cc
src/ReceiveCommands.cc src/ReceiveCommands.cc
@@ -136,7 +136,7 @@ set(SOURCES
) )
if(resource_file_FOUND) if(resource_file_FOUND)
set(SOURCES ${SOURCES} src/ARCodeTranslator.cc) set(SOURCES ${SOURCES} src/AddressTranslator.cc)
endif() endif()
add_executable(newserv ${SOURCES}) add_executable(newserv ${SOURCES})
+1 -2
View File
@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2023 Martin Michelsen Copyright (c) 2024 Martin Michelsen
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@@ -18,4 +18,3 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+146 -102
View File
@@ -12,6 +12,7 @@ See TODO.md for a list of known issues and future work I've curated, or go to th
* Background * Background
* [History](#history) * [History](#history)
* [Other server projects](#other-server-projects) * [Other server projects](#other-server-projects)
* [Using newserv in other projects](#using-newserv-in-other-projects)
* [Compatibility](#compatibility) * [Compatibility](#compatibility)
* Setup * Setup
* [Server setup](#server-setup) * [Server setup](#server-setup)
@@ -62,7 +63,14 @@ Independently of this project, there are many other PSO servers out there. Those
* (2019) **[Mechonis](https://gitlab.com/sora3087/mechonis)**: A PSOBB server with a microservice architecture written in TypeScript by TrueVision. * (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) **[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. * (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.
## Using newserv in other projects
There is a fair amount of code in this project that could potentially be useful to other projects. You are free to use code from newserv in your own open-source projects; the only condition is that the contents of the LICENSE file must be included in your project if you use code from newserv. Your project does not also have to use the MIT license; you can use any license you want.
If you want to use parts of newserv in your project, there are two easy ways to do so with proper licensing:
* If you're using a lot of code from newserv, you can put a copy of newserv's LICENSE file in your repository alongside your own license file, or include the contents of newserv's license in your own license file.
* If you're only using a few files from newserv, you can copy and paste the contents of the LICENSE file into a comment at the beginning of each copied file.
# Compatibility # Compatibility
@@ -183,9 +191,13 @@ The version of PSO PC I have has the server addresses starting at offset 0x29CB3
### PSO GC on a real GameCube ### 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. You can make PSO connect to newserv by setting the default gateway and DNS server addresses in the game's network settings to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube. If you're not playing PSO Plus or Episode III, this should be all you need to do, assuming you already set LocalAddress in config.json to your PC's private IP address.
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. 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. If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. There are a couple of ways to get around this.
Sodaboy described a fairly easy method, which is to forward the PSO and DNS ports in your router's configuration to your PC's private IP address (the PSO ports are in config.json, and are all TCP; the DNS port is 53 and is UDP). Then, set LocalAddress and ExternalAddress in config.json to your external IP address (from e.g. whatismyip.com). Most routers will let you connect to your public IP address even from within the local network, but the GameCube will think it's connecting to a different network, so it won't reject the connection. If you're concerned about security and don't want your server to be publicly accessible, you can use Windows Firewall or UFW on Linux block incoming connections on the ports you opened, except for connections from the IP addresses you specify.
Another method is to use two network interfaces on the same PC, and tell the GameCube to connect to the one that appears to be on a different network. For example, if your GameCube is on the 10.0.0.x subnet and your PC's address is 10.0.0.5, you can create a fake network adapter on your PC (or use an existing real one) that has an IP address on a different subnet than the GameCube, such as 192.168.0.8. Then, in PSO's network config, set the default gateway and DNS server addresses to 192.168.0.8, and set LocalAddress in config.json to 192.168.0.8, and PSO should connect. This is what I did back in the old days when I primarily developed software on Windows, but I haven't tried it in many years.
### PSO GC on a Wii or Wii U ### PSO GC on a Wii or Wii U
@@ -193,7 +205,7 @@ Using a Wii or Wii U to connect to newserv requires the Wii or vWii to be softmo
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). 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: Devolution includes modem emulation and is compatible with all PSO GameCube versions including Episodes I&II Trial Edition. newserv can act as a PPP server, which Devolution can directly connect to. To do this:
1. Enable the PPPRawListen option according to the comments in config.json. 1. Enable the PPPRawListen option according to the comments in config.json.
2. Start newserv. 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. 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.
@@ -204,9 +216,9 @@ If you're using the HLE BBA type, set the BBA's DNS server address to newserv's
If you're using the TAP BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address. If you're using the TAP 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: If you're using the tapserver BBA or modem type, you can make it connect to a newserv instance running on the same machine via the tapserver interface. To do this:
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1). 1. In the GameCube pane of the Config window, set the SP1 device to Broadband Adapter (tapserver) or Modem Adapter (tapserver).
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv. 2. Set IPStackListen (for BBA) or PPPStackListen (for modem) 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. 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. 4. Start an online game.
@@ -214,9 +226,12 @@ If you're using a version of Dolphin with tapserver support, you can make it con
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the "Client patch directories" section for instructions on setting this up.) The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's 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. The original Japanese and US versions of PSO BB work with newserv (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)). To get them to connect to your server, do one of the following:
* Use a drop-in patcher like [AzureFlare](https://github.com/Repflez/AzureFlare).
* Modify your hosts file to redirect the client's destination address to localhost or your server's address.
* Edit psobb.exe to point to your newserv instance. The original clients are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) / [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. Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
### Connecting external clients ### Connecting external clients
@@ -324,6 +339,32 @@ 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.) 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.)
## Server-side saves
newserv has the ability to save character data on the server side. For PSO BB, this is required of course, but this feature can also be used on other PSO versions.
Each account has 4 BB character slots and 16 non-BB character file slots. The non-BB slots are independent of the BB slots, and can be accessed with the `$savechar <slot>` and `$loadchar <slot>` commands (slots are numbered 1 through 16). `$savechar` copies the character you're currently playing as and saves the data on the server, and `$loadchar` does the reverse, overwriting your current character with the data saved on the server. Note that you can load a character that was saved from a different version of PSO, which allows you to easily transfer characters between games. On v1 and v2, changes done by `$loadchar` will be undone if you join a game; to permanently save your changes, disconnect from the lobby after using the command.
There is a third command, `$bbchar <username> <password> <slot>`, which behaves similarly to `$savechar` but writes the character data to a BB character slot in a different account instead (slots are numbered 1 through 4). This can be used to "upgrade" a character to BB from an earlier version.
Exactly which data is saved and loaded depends on the game version:
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/challenge |
|----------------------|-----------|-----------|---------------|-------------|------|------------------|
| PSO DC v1 prototypes | Yes | Yes | No | No | No | N/A |
| PSO DC v1 | Yes | Yes | No | No | No | N/A |
| PSO DC v2 | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO PC (v2) | Yes | Yes | No | No | No | Save only |
| PSO GC NTE | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC (not Plus) | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO GC Plus (1) | Save only | Save only | No | No | No | Save only |
| PSO GC Ep3 (1) | No | Save only | No | No | No | Save only |
| PSO Xbox | Yes | Yes | Yes | Yes | Yes | Yes |
| PSO BB | Yes | Yes | Yes | Yes | Yes | Yes |
*Notes*:
1. *If EnableSendFunctionCallQuestNumber is enabled in config.json, then $savechar and $loadchar can save and restore all character data on these versions, just like on GC non-Plus. Episode 3 characters exist in a separate namespace; that is, you can't use $savechar and $loadchar to convert an Ep3 character to non-Ep3, or vice versa.*
## Episode 3 features ## Episode 3 features
newserv supports many features unique to Episode 3: newserv supports many features unique to Episode 3:
@@ -355,13 +396,14 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i
* card-text.mnr: Compressed card text archive. Generally only used for debugging. * card-text.mnr: Compressed card text archive. Generally only used for debugging.
* card-text.mnrd: Decompressed card text archive; same format as TextCardE.bin. Generally only used for debugging. * card-text.mnrd: Decompressed card text archive; same format as TextCardE.bin. Generally only used for debugging.
* com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time. * com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time.
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with all the original online and offline maps, including Story Mode quests. If you don't want the offline maps and quests to be playable online, delete the .bind files system/ep3/maps. * maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with the default online maps, as well as some fan-made variations and quests to help new players get up to speed.
* maps-download/: Download maps and quests (.mnm/.bin/.mnmd/.bind files). There are two subcategories by default (download maps and Trial Edition download maps), but you can add more by editing QuestCategories in config.json. Categories that have flag 0x40 (Ep3 download) set are indexed from this directory; all others are indexed from system/quests/. Files in maps-download/ subdirectories have the same format as those in the maps/ directory, but should be named like `e###-gc3-LANGUAGE.EXT` (similar to how non-Episode 3 quests are named in the system/quests/ directory). If you want a map to be available for online play and for downloading, the file must exist in both maps/ and in a maps-download/ subdirectory (a symbolic link is acceptable). * maps-download/: Download maps and quests (.mnm/.bin/.mnmd/.bind files). There are two subcategories by default (download maps and Trial Edition download maps), but you can add more by editing QuestCategories in config.json. Categories that have flag 0x40 (Ep3 download) set are indexed from this directory; all others are indexed from system/quests/. Files in maps-download/ subdirectories have the same format as those in the maps/ directory, but should be named like `e###-gc3-LANGUAGE.EXT` (similar to how non-Episode 3 quests are named in the system/quests/ directory). If you want a map to be available for online play and for downloading, the file must exist in both maps/ and in a maps-download/ subdirectory (a symbolic link is acceptable).
* maps-offline/: Offline map files. These are all the offline quests and free battle maps from the client, including some debugging/test maps that were inaccessible during normal play. To make them playable online, put the files in the maps/ directory.
* tournament-state.json: State of all active tournaments. This file is automatically written when any tournament changes state for any reason (e.g. a tournament is created/started/deleted or a match is resolved). * tournament-state.json: State of all active tournaments. This file is automatically written when any tournament changes state for any reason (e.g. a tournament is created/started/deleted or a match is resolved).
There is no public editor for Episode 3 maps and quests, but the format is described fairly thoroughly in src/Episode3/DataIndexes.hh (see the MapDefinition structure). You'll need to use `newserv decompress-prs ...` to decompress .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. There is no public editor for Episode 3 maps and quests, but the format is described fairly thoroughly in src/Episode3/DataIndexes.hh (see the MapDefinition structure). You'll need to use `newserv decompress-prs ...` to decompress a .bin or .mnm file before editing it, but you don't need to compress it again to use it - just put the .bind or .mnmd file in the maps directory and newserv will make it available.
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3-data` 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-cards` or `reload ep3-maps` in the interactive shell to make the changes take effect without restarting the server.
## Memory patches, client functions, and DOL files ## Memory patches, client functions, and DOL files
@@ -371,48 +413,48 @@ You can put assembly files in the system/client-functions directory with filenam
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: 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:
| Game | VERS | Supported | | Game | VERS | Architecture |
|-------------------|------|-----------| |-------------------|------|---------------|
| PSO DC NTE | 1OJ1 | No | | PSO DC NTE | 1OJ1 | Not supported |
| PSO DC 11/2000 | 1OJ2 | No | | PSO DC 11/2000 | 1OJ2 | Not supported |
| PSO DC 12/2000 | 1OJ3 | No | | PSO DC 12/2000 | 1OJ3 | Not supported |
| PSO DC 01/2001 | 1OJ4 | No | | PSO DC 01/2001 | 1OJ4 | Not supported |
| PSO DC v1 JP | 1OJF | No | | PSO DC v1 JP | 1OJF | Not supported |
| PSO DC v1 US | 1OEF | No | | PSO DC v1 US | 1OEF | Not supported |
| PSO DC v1 EU | 1OPF | No | | PSO DC v1 EU | 1OPF | Not supported |
| PSO DC 08/2001 | 2OJ5 | Yes | | PSO DC 08/2001 | 2OJ5 | SH-4 |
| PSO DC v2 JP | 2OJF | Yes | | PSO DC v2 JP | 2OJF | SH-4 |
| PSO DC v2 US | 2OEF | Yes | | PSO DC v2 US | 2OEF | SH-4 |
| PSO DC v2 EU | 2OPF | Yes | | PSO DC v2 EU | 2OPF | SH-4 |
| PSO PC (v2) | 2OJW | No | | PSO PC (v2) | 2OJW | Not supported |
| PSO GC NTE | 3OJT | Yes | | PSO GC NTE | 3OJT | PowerPC |
| PSO GC v1.2 JP | 3OJ2 | Yes | | PSO GC v1.2 JP | 3OJ2 | PowerPC |
| PSO GC v1.3 JP | 3OJ3 | Yes | | PSO GC v1.3 JP | 3OJ3 | PowerPC |
| PSO GC v1.4 JP | 3OJ4 | Yes | | PSO GC v1.4 JP | 3OJ4 | PowerPC |
| PSO GC v1.5 JP | 3OJ5 | No | | PSO GC v1.5 JP | 3OJ5 | Not supported |
| PSO GC v1.0 US | 3OE0 | Yes | | PSO GC v1.0 US | 3OE0 | PowerPC |
| PSO GC v1.1 US | 3OE1 | Yes | | PSO GC v1.1 US | 3OE1 | PowerPC |
| PSO GC v1.2 US | 3OE2 | No | | PSO GC v1.2 US | 3OE2 | Not supported |
| PSO GC v1.0 EU | 3OP0 | Yes | | PSO GC v1.0 EU | 3OP0 | PowerPC |
| PSO GC Ep3 NTE | 3SJT | Yes | | PSO GC Ep3 NTE | 3SJT | PowerPC |
| PSO GC Ep3 JP | 3SJ0 | Yes | | PSO GC Ep3 JP | 3SJ0 | PowerPC |
| PSO GC Ep3 US | 3SE0 | No | | PSO GC Ep3 US | 3SE0 | Not supported |
| PSO GC Ep3 EU | 3SP0 | No | | PSO GC Ep3 EU | 3SP0 | Not supported |
| PSO Xbox Beta | 4OJB | Yes | | PSO Xbox Beta | 4OJB | x86 |
| PSO Xbox JP Disc | 4OJD | Yes | | PSO Xbox JP Disc | 4OJD | x86 |
| PSO Xbox JP TU | 4OJU | Yes | | PSO Xbox JP TU | 4OJU | x86 |
| PSO Xbox US Disc | 4OED | Yes | | PSO Xbox US Disc | 4OED | x86 |
| PSO Xbox US TU | 4OEU | Yes | | PSO Xbox US TU | 4OEU | x86 |
| PSO Xbox EU Disc | 4OPD | Yes | | PSO Xbox EU Disc | 4OPD | x86 |
| PSO Xbox EU TU | 4OPU | Yes | | PSO Xbox EU TU | 4OPU | x86 |
| PSO BB JP 1.25.13 | 51OC | Yes | | PSO BB JP 1.25.13 | 51OC | x86 |
| PSO BB Tethealla | 51OC | Yes | | PSO BB Tethealla | 51OC | x86 |
*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.* *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.*
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). 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).
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. You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.ppc.s, WriteMemory.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
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. 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.
@@ -460,35 +502,36 @@ newserv supports a variety of commands players can use by chatting in-game. Any
Some commands only work on the game server and not on the proxy server. The chat commands are: Some commands only work on the game server and not on the proxy server. The chat commands are:
* Information commands * 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.). * `$li`: Show basic information about the lobby or game you're in. If you're on the proxy server, show information about your connection instead (remote Guild Card number, client ID, etc.).
* `$si` (game server only): Shows basic information about the server. * `$si` (game server only): Show 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. * `$ping`: Show round-trip ping time from the server to you. On the proxy server, show the ping time from you to the proxy and from the proxy to the server.
* `$matcount` (game server only): Shows how many of each type of material you've used. * `$matcount` (game server only): Show 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: * `$itemnotifs <mode>`: Enable item drop notification messages. If the game has private drops enabled, you will only see a notification if the dropped item is visible to you; you won't be notified of other players' drops. The modes are:
* `off`: No notifications are shown. * `off`: No notifications are shown.
* `rare`: You are notified when a rare item drops. * `rare`: You are notified when a rare item drops.
* `on`: You are notified when any item drops, except Meseta. * `on`: You are notified when any item drops, except Meseta.
* `every`: You are notified when any item drops, including 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. * `$what` (game server only): Show 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. * `$where` (game server only): Show your current floor number and coordinates. Mainly useful for debugging.
* `$qfread <field-name>` (game server only): Show the value of a quest counter in your player data. The field names are defined in config.json.
* Debugging commands * Debugging commands
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does a few things: * `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
* You'll see in-game messages from the server when you take certain actions, like killing an enemy in BB. * You'll see in-game messages from the server when you take 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 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 placed into the last available slot in lobbies and games instead of the first, unless you're joining a BB solo-mode game.
* You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Please do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above). * You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above).
* The rest of the commands in this section are enabled on the game server. (They are always enabled on the proxy server.) * 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. * `$quest <number>` (game server only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. Debug is not required to be enabled if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
* `$qcall <function-id>`: Call a quest function on your client. * `$qcall <function-id>`: Call a quest function on your client.
* `$qcheck <flag-num>` (game server only): Show the value of a quest flag. This command can be used without debug mode enabled. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only). * `$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. * `$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. * `$qgread <flag-num>` (game server only): Show the value of a quest counter ("global flag"). This command can be used without debug mode enabled.
* `$qgwrite <flag-num> <value>` (game server only): Set the value of a quest counter ("global flag") for yourself. * `$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. * `$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. * `$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. * `$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. * `$swsetall`: Set all switch flags on your current floor. This unlocks all doors, disables all laser fences, triggers all light/poison switches, etc.
* `$gc` (game server only): Send your own Guild Card to yourself. * `$gc` (game server only): Send your own Guild Card to yourself.
* `$sc <data>`: Send a command to yourself. * `$sc <data>`: Send a command to yourself.
* `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server. * `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server.
@@ -498,62 +541,63 @@ Some commands only work on the game server and not on the proxy server. The chat
* `$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. * `$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 * Personal state commands
* `$arrow <color-id>`: Changes your lobby arrow color. * `$arrow <color-id>`: Change 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. 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. * `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$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. * `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$ln [name-or-type]`: 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. * `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy server, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
* `$swa`: 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. * `$swa`: Enable or disable 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. * `$exit`: If you're in a lobby, send you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, send you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server. * `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
* Character data commands (game server only) * 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. * `$savechar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
* `$loadchar <slot>` (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. * `$loadchar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
* `$bbchar <username> <password> <slot>`: 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. * `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the "Server-side saves" section for more details.
* `$edit <stat> <value>`: 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`). * `$edit <stat> <value>`: Modify 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) * 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. * `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
* `$save`: Saves your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.) * `$save`: Save your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
* Game state commands (game server only) * Game state commands (game server only)
* `$maxlevel <level>`: Sets the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.) * `$maxlevel <level>`: Set the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
* `$minlevel <level>`: Sets the minimum level for players to join the current game. * `$minlevel <level>`: Set 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. * `$password <password>`: Set 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. * `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the "Item tables and drop modes" section for more information.
* `$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. * `$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 that were only visible to the leaving player, which are deleted). 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 appear, 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) * 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. * `$spec`: Toggle the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they are sent back to the lobby.
* `$inftime`: 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). * `$inftime`: Toggle infinite-time mode. Must be used before starting a battle. If infinite-time mode is on, the overall and per-phase time limits will be disabled regardless of the values chosen during battle rules setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: 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. * `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Set override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them.
* `$stat <what>`: 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`. * `$stat <what>`: Show a statistic about your player or team in the current battle. `<what>` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`.
* `$surrender`: Causes your team to immediately lose the current battle. * `$surrender`: Cause your team to immediately lose the current battle.
* `$saverec <name>`: Saves the recording of the last battle. * `$saverec <name>`: Save 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). * `$playrec <name>`: Play a battle recording. This command creates a spectator team immediately but the replay does not start automatically, to give other players a chance to join. To start the battle replay within the spectator team, run `$playrec` again (with no name). There is a bug in Dolphin that makes this command unstable in emulation (see the "Battle records" section above).
* Cheat mode commands * Cheat mode commands
* `$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. * `$cheat` (game server only): Enable or disable cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games. Cheat mode is always enabled on the proxy server, unless cheat mode is disabled on the entire server.
* `$infhp` / `$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. * `$infhp`: Enable or disable infinite HP mode. Applies to only you; does not affect other players. When enabled, one-hit KO attacks will still kill you, but on most versions of the game (not DCv1, GC US 1.2, or GC JP 1.5), the server will automatically revive you if you die. On all versions except GC US 1.2 and GC JP 1.5, infinite HP also automatically cures status ailments.
* `$warpme <floor-id>` (or `$warp <floor-id>`): Warps yourself to the given floor. * `$inftp`: Enable or disable infinite TP mode. Applies to only you; does not affect other players.
* `$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. * `$warpme <floor-id>` (or `$warp <floor-id>`): Warp yourself to the given floor.
* `$next`: Warps yourself to the next floor. * `$warpall <floor-id>`: Warp everyone in the game to the given floor. You must be the leader to use this command, unless you're on the proxy server.
* `$next`: Warp yourself to the next floor.
* `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item (e.g. "Hell Saber +5 0/10/25/0/10") or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy server, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions. * `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item (e.g. "Hell Saber +5 0/10/25/0/10") or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy server, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions.
* `$unset <index>` (game server only): In an Episode 3 battle, removes one of your set cards from the field. `<index>` is the index of the set card as it appears on your screen - 1 is the card next to your SC's icon, 2 is the card to the right of 1, etc. This does not cause a Hunters-side SC to lose HP, as they normally do when their items are destroyed. * `$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. * `$dropmode [mode]` (proxy server): Change the way item drops behave in the current game, if you are not on BB. Unlike the game server version of this command, using this on the proxy server requires cheats to be enabled. This works by intercepting the drop requests sent to and from the leader. (So, if you are the leader and not using server drop mode on the remote server, it affects the entire game; otherwise, it affects only items generated by your actions.) `mode` can be `none` (no drops), `default` (normal drops), or `proxy` (use newserv's drop tables instead of the remote server's). If `mode` is not given, tells you the current drop mode without changing it.
* Configuration commands * Aesthetic 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. * `$event <event>`: Set the current holiday event in the current lobby. Holiday events are documented in the "Using $event" item in the information menu. If you're on the proxy server, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
* `$allevent <event>` (game server only): Sets the current holiday event in all lobbies. * `$allevent <event>` (game server only): Set the current holiday event in all lobbies.
* `$song <song-id>` (Episode 3 only): Plays a specific song in the current lobby. * `$song <song-id>` (Episode 3 only): Play a specific song in the current lobby.
* Administration commands (game server only) * Administration commands (game server only)
* `$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>`: Send 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. * `$ann! <message>`: Send 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. * `$ax <message>`: Send a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
* `$silence <identifier>`: Silences a player (remove their ability to chat) or unsilences a player. The identifier may be the player's name or Guild Card number. * `$silence <identifier>`: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number.
* `$kick <identifier>`: Disconnects a player. The identifier may be the player's name or Guild Card number. * `$kick <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
* `$ban <identifier>`: Bans a player. The identifier may be the player's name or Guild Card number. * `$ban <duration> <identifier>`: Ban a player. The duration should be of the form `10m` (minutes), `10h` (hours), `10d` (days), `10w` (weeks), `10M` (months), or `10y` (years). (Numbers other than 10 may be used, of course.) As with `$kick`, the identifier may be the player's name or Guild Card number.
# Non-server features # Non-server features
+1 -3
View File
@@ -1,11 +1,10 @@
## General ## General
- Make reloading happen on separate threads so compression doesn't block active clients
- Implement decrypt/encrypt actions for VMS files - Implement decrypt/encrypt actions for VMS files
- Make UI strings localizable (e.g. entries in menus, welcome message, etc.) - Make UI strings localizable (e.g. entries in menus, welcome message, etc.)
- Add an idle connection timeout for proxy sessions - Add an idle connection timeout for proxy sessions
- Clean up ItemParameterTable implementation (see comment at the top of the class definition) - 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 ) - Handle MeetUserExtensions properly in 41 and C4 commands on the proxy (rewrite the embedded 19 command and store a map of received destinations)
## PSO DC ## PSO DC
@@ -26,7 +25,6 @@
## PSOBB ## PSOBB
- Test all quest item subcommands
- Figure out why Pouilly Slime EXP doesn't work - Figure out why Pouilly Slime EXP doesn't work
- Make server-specified rare enemies work with maps loaded by the proxy - Make server-specified rare enemies work with maps loaded by the proxy
- Implement serialization for various table types (ItemPMT, ItemPT, etc.) - Implement serialization for various table types (ItemPMT, ItemPT, etc.)
+10
View File
@@ -79,6 +79,11 @@ Ep3-US => 042F9AC0 60000000
Ep3-NTE => 040C2C48 60000000 Ep3-NTE => 040C2C48 60000000
Ep3-JP => 042F8B74 60000000 Ep3-JP => 042F8B74 60000000
(Ep1&2 USA v1.1) Change type of all loading screens
0401CA04 3BE0000X
0401CA08 48000038
Values for X: 0 = lobby/game join, 1 = quest load, 3 = pipe up, 4 = pipe down, anything else = silent black screen
(Ep3 USA) Replace loading screen A button sounds with random sounds (Ep3 USA) Replace loading screen A button sounds with random sounds
042F9B18 4804BB19 042F9B18 4804BB19
042F9B1C 5463063E 042F9B1C 5463063E
@@ -350,3 +355,8 @@ Note: Without a TextEnglish.pr2/pr3 patch, the menu items for these sounds will
0408E448 38000001 0408E448 38000001
0408E44C 900DA62C 0408E44C 900DA62C
0408E450 4E800020 0408E450 4E800020
(v1.1 USA) Replace all sound effects with specified sound effect
042256E4 3F40XXXX
042256E8 635AYYYY
042256EC 4800000C
+602 -602
View File
File diff suppressed because it is too large Load Diff
+41 -11
View File
@@ -73,9 +73,9 @@ ItemLossPrevention
*** desc=Don't lose items if\nyou don't log off\nnormally *** desc=Don't lose items if\nyou don't log off\nnormally
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10) JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10)
801D33E4 4800004C 801D38EC 4800004C 801D3CC4 4800004C 801D39B8 4800004C 801D381C 4800004C 801D381C 4800004C 801D3A1C 4800004C 801D3ED8 4800004C b +0x0000004C /* 801D3868 */ 801D33E4 4800004C 801D38EC 4800004C 801D3CC4 4800004C 801D39B8 4800004C 801D381C 4800004C 801D381C 4800004C 801D3A1C 4800004C 801D3ED8 4800004C b +0x0000004C /* 801D3868 */
8020010C 60000000 801FF710 60000000 801FF0FC 60000000 801FF0FC 60000000 801FFA44 60000000 801FF9E0 60000000 nop 801FE900 60000000 801FF174 60000000 8020010C 60000000 801FF710 60000000 801FF0FC 60000000 801FF0FC 60000000 801FFA44 60000000 801FF9E0 60000000 nop
802016CC 60000000 80200C9C 60000000 80200658 60000000 80200658 60000000 80200FD0 60000000 80200F3C 60000000 nop 801FFE5C 60000000 802006D0 60000000 802016CC 60000000 80200C9C 60000000 80200658 60000000 80200658 60000000 80200FD0 60000000 80200F3C 60000000 nop
801FD944 38000000 80202860 38000000 802021C4 38000000 802021C4 38000000 80202B94 38000000 80202AA8 38000000 li r0, 0x0000 802019C8 38000000 8020223C 38000000 801FD944 38000000 80202860 38000000 802021C4 38000000 802021C4 38000000 80202B94 38000000 80202AA8 38000000 li r0, 0x0000
802C2060 4800004C 802C2F98 4800004C 802C42E4 4800004C 802C3E78 4800004C 802C2A40 4800004C 802C2A84 4800004C 802C402C 4800004C 802C37C0 4800004C b +0x0000004C /* 802C2A8C */ 802C2060 4800004C 802C2F98 4800004C 802C42E4 4800004C 802C3E78 4800004C 802C2A40 4800004C 802C2A84 4800004C 802C402C 4800004C 802C37C0 4800004C b +0x0000004C /* 802C2A8C */
802D0AA0 48000020 802D1A58 48000020 802D2C10 48000020 802D2938 48000020 802D1480 48000020 802D14C4 48000020 802D2AEC 48000020 802D2280 48000020 b +0x00000020 /* 802D14A0 */ 802D0AA0 48000020 802D1A58 48000020 802D2C10 48000020 802D2938 48000020 802D1480 48000020 802D14C4 48000020 802D2AEC 48000020 802D2280 48000020 b +0x00000020 /* 802D14A0 */
@@ -754,15 +754,45 @@ Show Enemy HP Bars
EnemyHPBars EnemyHPBars
*** name=Enemy HP bars *** name=Enemy HP bars
*** desc=Show HP bars in\nenemy info windows *** desc=Show HP bars in\nenemy info windows
JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US10) JP12------------- JP13------------- JP14------------- JP15------------- US10------------- US11------------- US12------------- EU--------------- DISASSEMBLY (US12)
802612C4 4BFE1541 80261E9C 4BFE1349 80262EE4 4BFE0665 80262C98 4BFE1241 80261B9C 4BFE1545 80261B9C 4BFE1545 80262F5C 4BFE12B1 802627A4 4BFE12B1 bl -0x0001EABC /* 802430E0 */ 802612C4 4BFE1541 80261E9C 4BFE1349 80262EE4 4BFE0665 80262C98 4BFE1241 80261B9C 4BFE1545 80261B9C 4BFE1545 80262F5C 4BFE12B1 802627A4 4BFE12B1 bl -0x0001EABC /* 802430E0 */
804CAF00 42300000 804CE650 42300000 804D0BA0 42300000 804D0940 42300000 804CB6D0 42300000 804CBBB0 42300000 804D0218 42300000 804D0608 42300000 bdnz cr4, +0x00000000 /* 804CB6D0 */ 804CAF00 42780000 804CE650 42780000 804D0BA0 42780000 804D0940 42780000 804CB6D0 42780000 804CBBB0 42780000 804D0218 42780000 804D0608 42780000
804CAF1C FF00FF15 804CE66C FF00FF15 804D0BBC FF00FF15 804D095C FF00FF15 804CB6EC FF00FF15 804CBBCC FF00FF15 804D0234 FF00FF15 804D0624 FF00FF15 .invalid FC, 0 804CAF1C FF00FF15 804CE66C FF00FF15 804D0BBC FF00FF15 804D095C FF00FF15 804CB6EC FF00FF15 804CBBCC FF00FF15 804D0234 FF00FF15 804D0624 FF00FF15
805CBFBC 42A00000 805D65BC 42A00000 805DDA5C 42A00000 805DD7FC 42A00000 805CC8C4 42A00000 805D38E4 42A00000 805DD104 42A00000 805D9344 42A00000 b +0x00000000 /* 805CC8C4 */ 805CBFBC 42C00000 805D65BC 42C00000 805DDA5C 42C00000 805DD7FC 42C00000 805CC8C4 42C00000 805D38E4 42C00000 805DD104 42C00000 805D9344 42C00000
804CAE40 42640000 804CE590 42640000 804D0AE0 42640000 804D0880 42640000 804CB610 42640000 804CBAF0 42640000 804D0158 42640000 804D0548 42640000 bc 19, 4, +0x00000000 /* 804CB610 */ 804CAE40 42960000 804CE590 42960000 804D0AE0 42960000 804D0880 42960000 804CB610 42960000 804CBAF0 42960000 804D0158 42960000 804D0548 42960000
804CAE4C 42640000 804CE59C 42640000 804D0AEC 42640000 804D088C 42640000 804CB61C 42640000 804CBAFC 42640000 804D0164 42640000 804D0554 42640000 bc 19, 4, +0x00000000 /* 804CB61C */ 804CAE4C 42960000 804CE59C 42960000 804D0AEC 42960000 804D088C 42960000 804CB61C 42960000 804CBAFC 42960000 804D0164 42960000 804D0554 42960000
804CAE58 42640000 804CE5A8 42640000 804D0AF8 42640000 804D0898 42640000 804CB628 42640000 804CBB08 42640000 804D0170 42640000 804D0560 42640000 bc 19, 4, +0x00000000 /* 804CB628 */ 804CAE58 42960000 804CE5A8 42960000 804D0AF8 42960000 804D0898 42960000 804CB628 42960000 804CBB08 42960000 804D0170 42960000 804D0560 42960000
804CAE64 42640000 804CE5B4 42640000 804D0B04 42640000 804D08A4 42640000 804CB634 42640000 804CBB14 42640000 804D017C 42640000 804D056C 42640000 bc 19, 4, +0x00000000 /* 804CB634 */ 804CAE64 42960000 804CE5B4 42960000 804D0B04 42960000 804D08A4 42960000 804CB634 42960000 804CBB14 42960000 804D017C 42960000 804D056C 42960000
804CAE70 42960000 804CE5C0 42960000 804D0B10 42960000 804D08B0 42960000 804CB640 42960000 804CBB20 42960000 804D0188 42960000 804D0578 42960000
80261260 4BDAA3F1 80261E38 4BDA9819 80262E80 4BDA87D1 80262C34 4BDA8A1D 80261B38 4BDA9B19 80261B38 4BDA9B19 80262EF8 4BDA8759 80262740 4BDA8F11 bl -0x002578A8 /* 8000B650 */
80261420 4BDAA245 80261FF8 4BDA966D 80263040 4BDA8625 80262DF4 4BDA8871 80261CF8 4BDA996D 80261CF8 4BDA996D 802630B8 4BDA85AD 80262900 4BDA8D65 bl -0x00257A54 /* 8000B664 */
8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 8000B650 3CA08001 lis r5, 0x8001
8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC 8000B654 8065B6BC lwz r3, [r5 - 0x4944]
8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 8000B658 7FFEFB78 mr r30, r31
8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C 8000B65C A8DE032C lha r6, [r30 + 0x032C]
8000B660 48000010 8000B660 48000010 8000B660 48000010 8000B660 48000010 8000B660 48000010 8000B660 48000010 8000B660 48000010 8000B660 48000010 b +0x00000010 /* 8000B670 */
8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 8000B664 A8DE02B8 lha r6, [r30 + 0x02B8]
8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 8000B668 3CA08001 lis r5, 0x8001
8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC 8000B66C 9065B6BC stw [r5 - 0x4944], r3
8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 8000B670 7C0802A6 mflr r0
8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 8000B674 9005B6C0 stw [r5 - 0x4940], r0
8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 8000B678 7C651B78 mr r5, r3
8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 8000B67C A8FE02B8 lha r7, [r30 + 0x02B8]
8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 8000B680 3C808000 lis r4, 0x8000
8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC 8000B684 6084B6AC ori r4, r4, 0xB6AC
8000B688 38640018 8000B688 38640018 8000B688 38640018 8000B688 38640018 8000B688 38640018 8000B688 38640018 8000B688 38640018 8000B688 38640018 addi r3, r4, 0x0018
8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 8000B68C 4CC63182 crxor crb6, crb6, crb6
8000B690 4838A86D 8000B690 4838D275 8000B690 4838F115 8000B690 4838EEC5 8000B690 4838BB3D 8000B690 4838BB95 8000B690 4838F295 8000B690 4838DD85 bl sprintf /* 8039A924 */
8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 8000B694 3C808000 lis r4, 0x8000
8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 8000B698 6084B6C4 ori r4, r4, 0xB6C4
8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 8000B69C 7F83E378 mr r3, r28
8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC 8000B6A0 8004FFFC lwz r0, [r4 - 0x0004]
8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 8000B6A4 7C0803A6 mtlr r0
8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 8000B6A8 4E800020 blr
8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A 8000B6AC 25730A0A .invalid
8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 8000B6B0 48503A25 bl +0x00503A24 /* 8050F0D4 */
8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 8000B6B4 642F2564 oris r15, r1, 0x2564
8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 8000B6B8 00000000 .invalid
PSO DC Reticle Colours PSO DC Reticle Colours
DCReticleColors DCReticleColors
@@ -92,5 +92,3 @@ You'll win someday!
In case you want to try again, In case you want to try again,
come back to me once more. come back to me once more.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
Binary file not shown.
View File
File diff suppressed because it is too large Load Diff
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
inline void run_ar_code_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 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");
}
-640
View File
@@ -1,640 +0,0 @@
#include "ARCodeTranslator.hh"
#include <array>
#include <future>
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <resource_file/ExecutableFormats/DOLFile.hh>
#include <resource_file/ExecutableFormats/XBEFile.hh>
using namespace std;
class ARCodeTranslator {
public:
enum class ExpandMethod {
FORWARD = 0,
FORWARD_WITH_BARRIER,
BACKWARD,
BACKWARD_WITH_BARRIER,
BOTH,
BOTH_WITH_BARRIER,
BOTH_IGNORE_ORIGIN,
};
static const char* name_for_expand_method(ExpandMethod method) {
switch (method) {
case ExpandMethod::FORWARD:
return "FORWARD";
case ExpandMethod::FORWARD_WITH_BARRIER:
return "FORWARD_WITH_BARRIER";
case ExpandMethod::BACKWARD:
return "BACKWARD";
case ExpandMethod::BACKWARD_WITH_BARRIER:
return "BACKWARD_WITH_BARRIER";
case ExpandMethod::BOTH:
return "BOTH";
case ExpandMethod::BOTH_WITH_BARRIER:
return "BOTH_WITH_BARRIER";
case ExpandMethod::BOTH_IGNORE_ORIGIN:
return "BOTH_IGNORE_ORIGIN";
default:
throw logic_error("invalid expand method");
}
}
ARCodeTranslator(const string& directory)
: log("[ar-trans] "),
directory(directory) {
while (ends_with(this->directory, "/")) {
this->directory.pop_back();
}
for (const auto& filename : list_directory(this->directory)) {
if (ends_with(filename, ".dol")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
this->files.emplace(name, make_shared<DOLFile>(path.c_str()));
this->log.info("Loaded %s", name.c_str());
}
}
}
~ARCodeTranslator() = 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);
}
void find_rtoc_global_regs() const {
for (const auto& it : this->files) {
bool r2_high_found = false;
bool r2_low_found = false;
bool r13_high_found = false;
bool r13_low_found = false;
uint32_t r2 = 0;
uint32_t r13 = 0;
for (const auto& section : it.second->sections) {
if (!section.is_text) {
continue;
}
StringReader r(section.data);
while (!r.eof() && r.where()) {
uint32_t opcode = r.get_u32b();
if ((opcode & 0xFFFF0000) == 0x3DA00000) {
if (r13_high_found) {
throw runtime_error("multiple values for r13_high");
}
r13_high_found = true;
r13 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x3C400000) {
if (r2_high_found) {
throw runtime_error("multiple values for r2_high");
}
r2_high_found = true;
r2 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x61AD0000) {
if (r13_low_found) {
throw runtime_error("multiple values for r13_low");
}
r13_low_found = true;
r13 |= (opcode & 0xFFFF);
} else if ((opcode & 0xFFFF0000) == 0x60420000) {
if (r2_low_found) {
throw runtime_error("multiple values for r2_low");
}
r2_low_found = true;
r2 |= (opcode & 0xFFFF);
}
}
}
if (r2_low_found && r2_high_found) {
fprintf(stderr, "(%s) r2 = %08" PRIX32 "\n", it.first.c_str(), r2);
} else {
fprintf(stderr, "(%s) r2 = __MISSING__\n", it.first.c_str());
}
if (r13_low_found && r13_high_found) {
fprintf(stderr, "(%s) r13 = %08" PRIX32 "\n", it.first.c_str(), r13);
} else {
fprintf(stderr, "(%s) r13 = __MISSING__\n", it.first.c_str());
}
}
}
uint32_t find_match(shared_ptr<const DOLFile> dest_file, uint32_t src_address, ExpandMethod expand_method) const {
if (!this->src_file) {
throw runtime_error("no source file selected");
}
const DOLFile::Section* src_section = nullptr;
for (const auto& sec : this->src_file->sections) {
if (src_address >= sec.address && src_address < sec.address + sec.data.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->address;
size_t src_bytes_available_before = src_offset;
size_t src_bytes_available_after = src_section->data.size() - src_offset - 4;
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 + 4 < 0x100) {
size_t num_matches = 0;
size_t last_match_address = 0;
size_t match_length = match_bytes_before + match_bytes_after + 4;
StringReader src_r(src_section->data.data() + 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 < dest_section.data.size();
dest_match_offset += 4) {
src_r.go(0);
StringReader dest_r(dest_section.data.data() + dest_match_offset, match_length);
size_t z;
for (z = 0; z < match_length; z += 4) {
if (expand_method == ExpandMethod::BOTH_IGNORE_ORIGIN && z == match_bytes_before) {
src_r.skip(4);
dest_r.skip(4);
} else if (src_section->is_text) {
uint32_t src_opcode = src_r.get_u32b();
uint32_t dest_opcode = dest_r.get_u32b();
uint32_t src_class = src_opcode & 0xFC000000;
if (src_class != (dest_opcode & 0xFC000000)) {
break;
}
if (src_class == 0x48000000) {
// b +-offset
src_opcode &= 0xFC000003;
dest_opcode &= 0xFC000003;
} else if (((src_opcode & 0xAC1F0000) == 0x800D0000) || ((src_opcode & 0xAC1F0000) == 0x80020000)) {
// lwz/lfs rXX/fXX, [r2/r13 +- offset] OR stw/stfs [r2/r13 +- offset], rXX/fXX
src_opcode &= 0xFFFF0000;
dest_opcode &= 0xFFFF0000;
}
if (src_opcode != dest_opcode) {
break;
}
} else {
uint32_t src_data = src_r.get_u32b();
uint32_t dest_data = dest_r.get_u32b();
if ((src_data & 0xFE000000) == 0x80000000) {
src_data &= 0xFE000003;
}
if ((dest_data & 0xFE000000) == 0x80000000) {
dest_data &= 0xFE000003;
}
if (src_data != dest_data) {
break;
}
}
}
if (z == match_length) {
num_matches++;
last_match_address = dest_section.address + 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_WITH_BARRIER:
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
(src_bytes_available_before >= match_bytes_before + 4);
break;
case ExpandMethod::BACKWARD:
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
break;
case ExpandMethod::FORWARD_WITH_BARRIER:
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
(src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::FORWARD:
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::BOTH_WITH_BARRIER:
case ExpandMethod::BOTH_IGNORE_ORIGIN:
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
(src_bytes_available_before >= match_bytes_before + 4);
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
(src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::BOTH:
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
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 += 4;
}
if (can_expand_forward) {
match_bytes_after += 4;
}
}
throw runtime_error("scan field too long; too many matches");
}
void find_all_matches(uint32_t src_addr) const {
if (!this->src_file) {
throw runtime_error("no source file selected");
}
unordered_map<string, uint32_t> results;
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);
} else {
array<future<uint32_t>, 7> futures;
static const array<ExpandMethod, 7> methods = {
ExpandMethod::FORWARD,
ExpandMethod::FORWARD_WITH_BARRIER,
ExpandMethod::BACKWARD,
ExpandMethod::BACKWARD_WITH_BARRIER,
ExpandMethod::BOTH,
ExpandMethod::BOTH_WITH_BARRIER,
ExpandMethod::BOTH_IGNORE_ORIGIN,
};
for (size_t z = 0; z < methods.size(); z++) {
futures[z] = async(&ARCodeTranslator::find_match, this, it.second, src_addr, 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));
} else if (tokens[0] == "find-globals") {
this->find_rtoc_global_regs();
} 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 DOLFile>> files;
string src_filename;
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()) {
trans.set_source_file(use_filename);
}
if (!command.empty()) {
trans.handle_command(command);
} else {
trans.run_shell();
}
}
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());
auto a_mem = make_shared<MemoryContext>();
auto b_mem = make_shared<MemoryContext>();
a.load_into(a_mem);
b.load_into(b_mem);
uint32_t min_addr = 0xFFFFFFFF;
uint32_t max_addr = 0x00000000;
for (const auto& sec : a.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
}
for (const auto& sec : b.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
}
vector<pair<uint32_t, string>> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
bool a_exists = a_mem->exists(addr, 4);
bool b_exists = b_mem->exists(addr, 4);
if (a_exists && b_exists) {
string a_value = a_mem->read(addr, 4);
string b_value = b_mem->read(addr, 4);
if (a_value != b_value) {
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
ret.back().second += b_value;
} else {
ret.emplace_back(make_pair(addr, b_value));
}
}
}
}
return ret;
}
-11
View File
@@ -1,11 +0,0 @@
#pragma once
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
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);
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
}
+528
View File
@@ -0,0 +1,528 @@
#include "AddressTranslator.hh"
#include <array>
#include <future>
#include <phosg/Filesystem.hh>
#include <phosg/Strings.hh>
#include <resource_file/ExecutableFormats/DOLFile.hh>
#include <resource_file/ExecutableFormats/XBEFile.hh>
using namespace std;
class AddressTranslator {
public:
enum class ExpandMethod {
PPC_TEXT_FORWARD = 0,
PPC_TEXT_FORWARD_WITH_BARRIER,
PPC_TEXT_BACKWARD,
PPC_TEXT_BACKWARD_WITH_BARRIER,
PPC_TEXT_BOTH,
PPC_TEXT_BOTH_WITH_BARRIER,
PPC_TEXT_BOTH_IGNORE_ORIGIN,
PPC_DATA_FORWARD,
PPC_DATA_BACKWARD,
PPC_DATA_BOTH,
RAW_FORWARD,
RAW_BACKWARD,
RAW_BOTH,
};
static const char* name_for_expand_method(ExpandMethod method) {
switch (method) {
case ExpandMethod::PPC_TEXT_FORWARD:
return "PPC_TEXT_FORWARD";
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
return "PPC_TEXT_FORWARD_WITH_BARRIER";
case ExpandMethod::PPC_TEXT_BACKWARD:
return "PPC_TEXT_BACKWARD";
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
return "PPC_TEXT_BACKWARD_WITH_BARRIER";
case ExpandMethod::PPC_TEXT_BOTH:
return "PPC_TEXT_BOTH";
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
return "PPC_TEXT_BOTH_WITH_BARRIER";
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
return "PPC_TEXT_BOTH_IGNORE_ORIGIN";
case ExpandMethod::PPC_DATA_FORWARD:
return "PPC_DATA_FORWARD";
case ExpandMethod::PPC_DATA_BACKWARD:
return "PPC_DATA_BACKWARD";
case ExpandMethod::PPC_DATA_BOTH:
return "PPC_DATA_BOTH";
case ExpandMethod::RAW_FORWARD:
return "RAW_FORWARD";
case ExpandMethod::RAW_BACKWARD:
return "RAW_BACKWARD";
case ExpandMethod::RAW_BOTH:
return "RAW_BOTH";
default:
throw logic_error("invalid expand method");
}
}
static bool is_ppc_expand_method(ExpandMethod method) {
switch (method) {
case ExpandMethod::PPC_TEXT_FORWARD:
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BACKWARD:
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BOTH:
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
case ExpandMethod::PPC_DATA_FORWARD:
case ExpandMethod::PPC_DATA_BACKWARD:
case ExpandMethod::PPC_DATA_BOTH:
return true;
case ExpandMethod::RAW_FORWARD:
case ExpandMethod::RAW_BACKWARD:
case ExpandMethod::RAW_BOTH:
return false;
default:
throw logic_error("invalid expand method");
}
}
static bool is_ppc_data_expand_method(ExpandMethod method) {
switch (method) {
case ExpandMethod::PPC_DATA_FORWARD:
case ExpandMethod::PPC_DATA_BACKWARD:
case ExpandMethod::PPC_DATA_BOTH:
return true;
case ExpandMethod::PPC_TEXT_FORWARD:
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BACKWARD:
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BOTH:
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
case ExpandMethod::RAW_FORWARD:
case ExpandMethod::RAW_BACKWARD:
case ExpandMethod::RAW_BOTH:
return false;
default:
throw logic_error("invalid expand method");
}
}
AddressTranslator(const string& directory)
: log("[addr-trans] "),
directory(directory),
enable_ppc(false) {
while (ends_with(this->directory, "/")) {
this->directory.pop_back();
}
for (const auto& filename : list_directory(this->directory)) {
if (ends_with(filename, ".dol")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
DOLFile dol(path.c_str());
auto mem = make_shared<MemoryContext>();
dol.load_into(mem);
this->mems.emplace(name, mem);
this->enable_ppc = true;
this->log.info("Loaded %s", name.c_str());
} else if (ends_with(filename, ".xbe")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
XBEFile xbe(path.c_str());
auto mem = make_shared<MemoryContext>();
xbe.load_into(mem);
this->mems.emplace(name, mem);
this->log.info("Loaded %s", name.c_str());
} else if (ends_with(filename, ".bin")) {
string name = filename.substr(0, filename.size() - 4);
string path = directory + "/" + filename;
string data = load_file(path);
auto mem = make_shared<MemoryContext>();
mem->allocate_at(0x8C010000, data.size());
mem->memcpy(0x8C010000, data.data(), data.size());
this->mems.emplace(name, mem);
this->log.info("Loaded %s", name.c_str());
}
}
}
~AddressTranslator() = default;
const string& get_source_filename() const {
return this->src_filename;
}
void set_source_file(const string& filename) {
this->src_filename = filename;
this->src_mem = this->mems.at(this->src_filename);
}
void find_ppc_rtoc_global_regs() const {
for (const auto& it : this->mems) {
bool r2_high_found = false;
bool r2_low_found = false;
bool r13_high_found = false;
bool r13_low_found = false;
uint32_t r2 = 0;
uint32_t r13 = 0;
for (const auto& block : it.second->allocated_blocks()) {
StringReader r = it.second->reader(block.first, block.second);
while (!r.eof() && r.where()) {
uint32_t opcode = r.get_u32b();
if ((opcode & 0xFFFF0000) == 0x3DA00000) {
if (r13_high_found) {
throw runtime_error("multiple values for r13_high");
}
r13_high_found = true;
r13 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x3C400000) {
if (r2_high_found) {
throw runtime_error("multiple values for r2_high");
}
r2_high_found = true;
r2 |= (opcode << 16);
} else if ((opcode & 0xFFFF0000) == 0x61AD0000) {
if (r13_low_found) {
throw runtime_error("multiple values for r13_low");
}
r13_low_found = true;
r13 |= (opcode & 0xFFFF);
} else if ((opcode & 0xFFFF0000) == 0x60420000) {
if (r2_low_found) {
throw runtime_error("multiple values for r2_low");
}
r2_low_found = true;
r2 |= (opcode & 0xFFFF);
}
}
}
if (r2_low_found && r2_high_found) {
fprintf(stderr, "(%s) r2 = %08" PRIX32 "\n", it.first.c_str(), r2);
} else {
fprintf(stderr, "(%s) r2 = __MISSING__\n", it.first.c_str());
}
if (r13_low_found && r13_high_found) {
fprintf(stderr, "(%s) r13 = %08" PRIX32 "\n", it.first.c_str(), r13);
} else {
fprintf(stderr, "(%s) r13 = __MISSING__\n", it.first.c_str());
}
}
}
uint32_t find_match(
shared_ptr<const MemoryContext> dest_mem,
uint32_t src_addr,
uint32_t src_size,
ExpandMethod expand_method) const {
bool is_ppc = this->is_ppc_expand_method(expand_method);
bool is_ppc_data = this->is_ppc_data_expand_method(expand_method);
if (!this->src_mem) {
throw runtime_error("no source file selected");
}
if (src_size == 0) {
src_size = is_ppc ? 4 : 1;
}
pair<uint32_t, uint32_t> src_section = make_pair(0, 0);
for (const auto& sec : this->src_mem->allocated_blocks()) {
if (src_addr >= sec.first && src_addr + src_size <= sec.first + sec.second) {
src_section = sec;
break;
}
}
if (!src_section.second) {
throw runtime_error("source address not within any section");
}
const char* method_token = this->name_for_expand_method(expand_method);
size_t src_offset = src_addr - src_section.first;
size_t src_bytes_available_before = src_offset;
size_t src_bytes_available_after = src_section.second - src_offset - 4;
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 + 4 < 0x100) {
size_t num_matches = 0;
size_t last_match_address = 0;
size_t match_length = match_bytes_before + match_bytes_after + 4;
StringReader src_r = this->src_mem->reader(src_section.first + src_offset - match_bytes_before, match_length);
for (const auto& dest_section : dest_mem->allocated_blocks()) {
for (size_t dest_match_offset = 0;
dest_match_offset + match_length < dest_section.second;
dest_match_offset += (is_ppc ? 4 : 1)) {
src_r.go(0);
StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
size_t z;
if (is_ppc) {
for (z = 0; z < match_length; z += 4) {
if ((expand_method == ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN) && (z == match_bytes_before)) {
src_r.skip(4);
dest_r.skip(4);
} else if (!is_ppc_data) {
uint32_t src_opcode = src_r.get_u32b();
uint32_t dest_opcode = dest_r.get_u32b();
uint32_t src_class = src_opcode & 0xFC000000;
if (src_class != (dest_opcode & 0xFC000000)) {
break;
}
if (src_class == 0x48000000) {
// b +-offset
src_opcode &= 0xFC000003;
dest_opcode &= 0xFC000003;
} else if (((src_opcode & 0xAC1F0000) == 0x800D0000) || ((src_opcode & 0xAC1F0000) == 0x80020000)) {
// lwz/lfs rXX/fXX, [r2/r13 +- offset] OR stw/stfs [r2/r13 +- offset], rXX/fXX
src_opcode &= 0xFFFF0000;
dest_opcode &= 0xFFFF0000;
}
if (src_opcode != dest_opcode) {
break;
}
} else {
uint32_t src_data = src_r.get_u32b();
uint32_t dest_data = dest_r.get_u32b();
if ((src_data & 0xFE000000) == 0x80000000) {
src_data &= 0xFE000003;
}
if ((dest_data & 0xFE000000) == 0x80000000) {
dest_data &= 0xFE000003;
}
if (src_data != dest_data) {
break;
}
}
}
} else {
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.first + 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::PPC_TEXT_BACKWARD_WITH_BARRIER:
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
(src_bytes_available_before >= match_bytes_before + 4);
break;
case ExpandMethod::PPC_TEXT_BACKWARD:
case ExpandMethod::PPC_DATA_BACKWARD:
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
break;
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
(src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::PPC_TEXT_FORWARD:
case ExpandMethod::PPC_DATA_FORWARD:
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
(src_bytes_available_before >= match_bytes_before + 4);
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
(src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::PPC_TEXT_BOTH:
case ExpandMethod::PPC_DATA_BOTH:
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
break;
case ExpandMethod::RAW_BACKWARD:
can_expand_backward = (src_bytes_available_before > match_bytes_before);
break;
case ExpandMethod::RAW_FORWARD:
can_expand_forward = (src_bytes_available_after > match_bytes_after);
break;
case ExpandMethod::RAW_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 += (is_ppc ? 4 : 1);
}
if (can_expand_forward) {
match_bytes_after += (is_ppc ? 4 : 1);
}
}
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_mem) {
throw runtime_error("no source file selected");
}
map<string, uint32_t> results;
for (const auto& it : this->mems) {
if (it.second == this->src_mem) {
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
results.emplace(it.first, src_addr);
} else {
vector<future<uint32_t>> futures;
static const vector<ExpandMethod> ppc_methods = {
ExpandMethod::PPC_TEXT_FORWARD,
ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BACKWARD,
ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BOTH,
ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER,
ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN,
ExpandMethod::PPC_DATA_FORWARD,
ExpandMethod::PPC_DATA_BACKWARD,
ExpandMethod::PPC_DATA_BOTH,
};
static const vector<ExpandMethod> raw_methods = {
ExpandMethod::RAW_FORWARD,
ExpandMethod::RAW_BACKWARD,
ExpandMethod::RAW_BOTH,
};
const auto& methods = this->enable_ppc ? ppc_methods : raw_methods;
for (size_t z = 0; z < methods.size(); z++) {
futures.emplace_back(async(&AddressTranslator::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),
tokens.size() >= 3 ? stoul(tokens[2], nullptr, 16) : 0);
} else if (tokens[0] == "find-ppc-globals") {
this->find_ppc_rtoc_global_regs();
} else if (!tokens[0].empty()) {
throw runtime_error("unknown command");
}
}
void run_shell() {
while (!feof(stdin)) {
if (!this->src_filename.empty()) {
fprintf(stdout, "addr-trans:%s/%s> ", this->directory.c_str(), this->src_filename.c_str());
} else {
fprintf(stdout, "addr-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 MemoryContext>> mems;
string src_filename;
shared_ptr<const MemoryContext> src_mem;
bool enable_ppc;
};
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
AddressTranslator trans(directory);
if (!use_filename.empty()) {
trans.set_source_file(use_filename);
}
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());
auto a_mem = make_shared<MemoryContext>();
auto b_mem = make_shared<MemoryContext>();
a.load_into(a_mem);
b.load_into(b_mem);
uint32_t min_addr = 0xFFFFFFFF;
uint32_t max_addr = 0x00000000;
for (const auto& sec : a.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
}
for (const auto& sec : b.sections) {
min_addr = min<uint32_t>(min_addr, sec.address);
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
}
vector<pair<uint32_t, string>> ret;
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
bool a_exists = a_mem->exists(addr, 4);
bool b_exists = b_mem->exists(addr, 4);
if (a_exists && b_exists) {
string a_value = a_mem->read(addr, 4);
string b_value = b_mem->read(addr, 4);
if (a_value != b_value) {
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
ret.back().second += b_value;
} else {
ret.emplace_back(make_pair(addr, b_value));
}
}
}
}
return ret;
}
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
+169 -28
View File
@@ -298,18 +298,29 @@ static void server_command_debug(shared_ptr<Client> c, const std::string&) {
} }
static void server_command_quest(shared_ptr<Client> c, const std::string& args) { static void server_command_quest(shared_ptr<Client> c, const std::string& args) {
check_debug_enabled(c);
Version effective_version = is_ep3(c->version()) ? Version::GC_V3 : c->version();
auto s = c->require_server_state(); auto s = c->require_server_state();
auto l = c->require_lobby(); auto l = c->require_lobby();
if (!l->is_game()) {
throw precondition_failed("$C6Quests cannot be\nstarted from the\nlobby");
}
Version effective_version = is_ep3(c->version()) ? Version::GC_V3 : c->version();
auto q = s->quest_index(effective_version)->get(stoul(args)); auto q = s->quest_index(effective_version)->get(stoul(args));
if (!q) { if (!q) {
send_text_message(c, "$C6Quest not found"); send_text_message(c, "$C6Quest not found");
} else { return;
set_lobby_quest(c->require_lobby(), q, true);
} }
if (!c->config.check_flag(Client::Flag::DEBUG_ENABLED)) {
if (l->count_clients() > 1) {
throw precondition_failed("$C6This command can only\nbe used with no\nother players present");
}
if (!q->allow_start_from_chat_command) {
throw precondition_failed("$C6This quest cannot\nbe started with the\n%squest command");
}
}
set_lobby_quest(c->require_lobby(), q, true);
} }
static void server_command_qcheck(shared_ptr<Client> c, const std::string& args) { static void server_command_qcheck(shared_ptr<Client> c, const std::string& args) {
@@ -427,6 +438,7 @@ static void server_command_swsetall(shared_ptr<Client> c, const std::string&) {
cmd.switch_flag_num = z; cmd.switch_flag_num = z;
cmd.flags = 0x01; cmd.flags = 0x01;
} }
cmds[0].flags = 0x03; // Play room unlock sound
send_command_t(l, 0x6C, 0x00, cmds); send_command_t(l, 0x6C, 0x00, cmds);
} }
@@ -446,6 +458,7 @@ static void proxy_command_swsetall(shared_ptr<ProxyServer::LinkedSession> ses, c
cmd.switch_flag_num = z; cmd.switch_flag_num = z;
cmd.flags = 0x01; cmd.flags = 0x01;
} }
cmds[0].flags = 0x03; // Play room unlock sound
ses->client_channel.send(0x6C, 0x00, &cmds, sizeof(cmds)); ses->client_channel.send(0x6C, 0x00, &cmds, sizeof(cmds));
ses->server_channel.send(0x6C, 0x00, &cmds, sizeof(cmds)); ses->server_channel.send(0x6C, 0x00, &cmds, sizeof(cmds));
} }
@@ -469,8 +482,10 @@ static void server_command_qset_qclear(shared_ptr<Client> c, const std::string&
} else { } else {
l->quest_flag_values->clear(l->difficulty, flag_num); l->quest_flag_values->clear(l->difficulty, flag_num);
} }
} else if (c->version() == Version::BB_V4) { }
auto p = c->character();
auto p = c->character(false);
if (p) {
if (should_set) { if (should_set) {
p->quest_flags.set(l->difficulty, flag_num); p->quest_flags.set(l->difficulty, flag_num);
} else { } else {
@@ -527,8 +542,38 @@ static void server_command_qgread(shared_ptr<Client> c, const std::string& args)
if (flag_num >= flags.size()) { if (flag_num >= flags.size()) {
send_text_message_printf(c, "$C7Flag number must be\nless than %zu", flags.size()); send_text_message_printf(c, "$C7Flag number must be\nless than %zu", flags.size());
} else { } else {
send_text_message_printf(c, "$C7Quest counter %hhu\nhas value %" PRIu32, send_text_message_printf(c, "$C7Quest counter %hhu\nhas value %" PRIu32, flag_num, flags[flag_num].load());
flag_num, flags[flag_num].load()); }
}
static void server_command_qfread(shared_ptr<Client> c, const std::string& args) {
auto s = c->require_server_state();
uint8_t counter_index;
uint32_t mask;
try {
const auto& def = s->quest_counter_fields.at(args);
counter_index = def.first;
mask = def.second;
} catch (const out_of_range&) {
send_text_message(c, "$C4Invalid field name");
return;
}
if (mask == 0) {
throw runtime_error("invalid quest counter definition");
}
uint32_t counter_value = c->character()->quest_counters.at(counter_index) & mask;
while (!(mask & 1)) {
mask >>= 1;
counter_value >>= 1;
}
if (mask == 1) {
send_text_message_printf(c, "$C7Field %s\nhas value %s", args.c_str(), counter_value ? "TRUE" : "FALSE");
} else {
send_text_message_printf(c, "$C7Field %s\nhas value %" PRIu32, args.c_str(), counter_value);
} }
} }
@@ -577,7 +622,7 @@ static void server_command_qsync_qsyncall(shared_ptr<Client> c, const std::strin
return; return;
} }
G_SyncQuestData_6x77 cmd; G_SyncQuestRegister_6x77 cmd;
cmd.header = {0x77, 0x03, 0x0000}; cmd.header = {0x77, 0x03, 0x0000};
cmd.register_number = stoul(tokens[0].substr(1), nullptr, 0); cmd.register_number = stoul(tokens[0].substr(1), nullptr, 0);
cmd.unused = 0; cmd.unused = 0;
@@ -616,7 +661,7 @@ static void proxy_command_qsync_qsyncall(shared_ptr<ProxyServer::LinkedSession>
return; return;
} }
G_SyncQuestData_6x77 cmd; G_SyncQuestRegister_6x77 cmd;
cmd.header = {0x77, 0x03, 0x0000}; cmd.header = {0x77, 0x03, 0x0000};
cmd.register_number = stoul(tokens[0].substr(1), nullptr, 0); cmd.register_number = stoul(tokens[0].substr(1), nullptr, 0);
cmd.unused = 0; cmd.unused = 0;
@@ -737,8 +782,7 @@ static void proxy_command_patch(shared_ptr<ProxyServer::LinkedSession> ses, cons
auto send_version_detect_or_send_call = [args, ses, send_call]() { auto send_version_detect_or_send_call = [args, ses, send_call]() {
bool is_gc = ::is_gc(ses->version()); bool is_gc = ::is_gc(ses->version());
bool is_xb = (ses->version() == Version::XB_V3); bool is_xb = (ses->version() == Version::XB_V3);
if ((is_gc || is_xb) && if ((is_gc || is_xb) && specific_version_is_indeterminate(ses->config.specific_version)) {
ses->config.specific_version == default_specific_version_for_version(ses->version(), -1)) {
auto s = ses->require_server_state(); auto s = ses->require_server_state();
send_function_call( send_function_call(
ses->client_channel, ses->client_channel,
@@ -1051,6 +1095,7 @@ static void server_command_playrec(shared_ptr<Client> c, const std::string& args
} }
s->change_client_lobby(c, game); s->change_client_lobby(c, game);
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
} }
} else { } else {
send_text_message(c, "$C4This command cannot\nbe used in a game"); send_text_message(c, "$C4This command cannot\nbe used in a game");
@@ -1287,8 +1332,9 @@ static void server_command_edit(shared_ptr<Client> c, const std::string& args) {
p->disp.stats.experience = stoul(tokens.at(1)); p->disp.stats.experience = stoul(tokens.at(1));
} else if (tokens.at(0) == "level" && cheats_allowed) { } else if (tokens.at(0) == "level" && cheats_allowed) {
uint32_t level = stoul(tokens.at(1)) - 1; uint32_t level = stoul(tokens.at(1)) - 1;
s->level_table->reset_to_base(p->disp.stats, p->disp.visual.char_class); auto level_table = s->level_table(c->version());
s->level_table->advance_to_level(p->disp.stats, level, p->disp.visual.char_class); level_table->reset_to_base(p->disp.stats, p->disp.visual.char_class);
level_table->advance_to_level(p->disp.stats, level, p->disp.visual.char_class);
} else if (tokens.at(0) == "namecolor") { } else if (tokens.at(0) == "namecolor") {
uint32_t new_color; uint32_t new_color;
sscanf(tokens.at(1).c_str(), "%8X", &new_color); sscanf(tokens.at(1).c_str(), "%8X", &new_color);
@@ -1403,6 +1449,11 @@ static void server_command_bbchar_savechar(shared_ptr<Client> c, const std::stri
auto l = c->require_lobby(); auto l = c->require_lobby();
check_is_game(l, false); check_is_game(l, false);
if (is_bb_conversion && is_ep3(c->version())) {
send_text_message(c, "$C6Episode 3 players\ncannot be converted\nto BB format");
return;
}
auto pending_export = make_unique<Client::PendingCharacterExport>(); auto pending_export = make_unique<Client::PendingCharacterExport>();
if (is_bb_conversion) { if (is_bb_conversion) {
@@ -1430,8 +1481,8 @@ static void server_command_bbchar_savechar(shared_ptr<Client> c, const std::stri
} else { } else {
pending_export->character_index = stoll(args) - 1; pending_export->character_index = stoll(args) - 1;
if ((pending_export->character_index > 3) || (pending_export->character_index < 0)) { if ((pending_export->character_index > 15) || (pending_export->character_index < 0)) {
send_text_message(c, "$C6Player index must\nbe in range 1-4"); send_text_message(c, "$C6Player index must\nbe in range 1-16");
return; return;
} }
pending_export->dest_account = c->login->account; pending_export->dest_account = c->login->account;
@@ -1457,10 +1508,6 @@ static void server_command_savechar(shared_ptr<Client> c, const std::string& arg
} }
static void server_command_loadchar(shared_ptr<Client> c, const std::string& args) { static void server_command_loadchar(shared_ptr<Client> c, const std::string& args) {
if (!is_v1_or_v2(c->version())) {
send_text_message(c, "$C7This command can only\nbe used on v1 or v2");
return;
}
if (c->login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT)) { if (c->login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT)) {
send_text_message(c, "$C7This command cannot\nbe used on a shared\naccount"); send_text_message(c, "$C7This command cannot\nbe used on a shared\naccount");
return; return;
@@ -1469,16 +1516,100 @@ static void server_command_loadchar(shared_ptr<Client> c, const std::string& arg
check_is_game(l, false); check_is_game(l, false);
size_t index = stoull(args, nullptr, 0) - 1; size_t index = stoull(args, nullptr, 0) - 1;
if (index > 3) { if (index > 15) {
send_text_message(c, "$C6Player index must\nbe in range 1-4"); send_text_message(c, "$C6Player index must\nbe in range 1-16");
return; return;
} }
c->load_backup_character(c->login->account->account_id, index);
shared_ptr<PSOGCEp3CharacterFile::Character> ep3_char;
if (is_ep3(c->version())) {
ep3_char = c->load_ep3_backup_character(c->login->account->account_id, index);
} else {
c->load_backup_character(c->login->account->account_id, index);
}
if (c->version() == Version::BB_V4) {
// On BB, it suffices to simply send the character file again
auto s = c->require_server_state();
send_complete_player_bb(c);
send_player_leave_notification(l, c->lobby_client_id);
s->send_lobby_join_notifications(l, c);
} else if ((c->version() == Version::DC_V2) ||
(c->version() == Version::GC_NTE) ||
(c->version() == Version::GC_V3) ||
(c->version() == Version::GC_EP3_NTE) ||
(c->version() == Version::GC_EP3) ||
(c->version() == Version::XB_V3)) {
// TODO: Support extended player info on other versions
auto s = c->require_server_state();
if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL) ||
c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) {
send_text_message_printf(c, "Can\'t load character\ndata on this game\nversion");
return;
}
auto send_set_extended_player_info = []<typename CharT>(shared_ptr<Client> c, shared_ptr<const CharT> char_file) -> void {
prepare_client_for_patches(c, [wc = weak_ptr<Client>(c), char_file]() {
auto c = wc.lock();
if (!c) {
return;
}
try {
auto s = c->require_server_state();
auto fn = s->function_code_index->get_patch("SetExtendedPlayerInfo", c->config.specific_version);
send_function_call(c, fn, {}, char_file.get(), sizeof(CharT));
c->function_call_response_queue.emplace_back([wc = weak_ptr<Client>(c)](uint32_t, uint32_t) -> void {
auto c = wc.lock();
if (!c) {
return;
}
auto l = c->lobby.lock();
if (l) {
auto s = c->require_server_state(); auto s = c->require_server_state();
send_player_leave_notification(l, c->lobby_client_id); send_player_leave_notification(l, c->lobby_client_id);
s->send_lobby_join_notifications(l, c); s->send_lobby_join_notifications(l, c);
} }
});
} catch (const exception& e) {
c->log.warning("Failed to set extended player info: %s", e.what());
send_text_message_printf(c, "Failed to set\nplayer info:\n%s", e.what());
}
});
};
if (c->version() == Version::DC_V2) {
auto dc_char = make_shared<PSODCV2CharacterFile>(c->character()->to_dc_v2());
send_set_extended_player_info.operator()<PSODCV2CharacterFile>(c, dc_char);
} else if (c->version() == Version::GC_NTE) {
auto gc_char = make_shared<PSOGCNTECharacterFileCharacter>(c->character()->to_gc_nte());
send_set_extended_player_info.operator()<PSOGCNTECharacterFileCharacter>(c, gc_char);
} else if (c->version() == Version::GC_V3) {
auto gc_char = make_shared<PSOGCCharacterFile::Character>(c->character()->to_gc());
send_set_extended_player_info.operator()<PSOGCCharacterFile::Character>(c, gc_char);
} else if (c->version() == Version::GC_EP3_NTE) {
auto nte_char = make_shared<PSOGCEp3NTECharacter>(*ep3_char);
send_set_extended_player_info.operator()<PSOGCEp3NTECharacter>(c, nte_char);
} else if (c->version() == Version::GC_EP3) {
send_set_extended_player_info.operator()<PSOGCEp3CharacterFile::Character>(c, ep3_char);
} else if (c->version() == Version::XB_V3) {
if (!c->login || !c->login->xb_license) {
throw runtime_error("XB client is not logged in");
}
auto xb_char = make_shared<PSOXBCharacterFileCharacter>(c->character()->to_xb(c->login->xb_license->user_id));
send_set_extended_player_info.operator()<PSOXBCharacterFileCharacter>(c, xb_char);
} else {
throw logic_error("unimplemented extended player info version");
}
} else {
// On v1 and v2, the client will assign its character data from the lobby
// join command, so it suffices to just resend the join notification.
auto s = c->require_server_state();
send_player_leave_notification(l, c->lobby_client_id);
s->send_lobby_join_notifications(l, c);
}
}
static void server_command_save(shared_ptr<Client> c, const std::string&) { static void server_command_save(shared_ptr<Client> c, const std::string&) {
check_version(c, Version::BB_V4); check_version(c, Version::BB_V4);
@@ -1547,7 +1678,7 @@ static void server_command_kick(shared_ptr<Client> c, const std::string& args) {
return; return;
} }
send_message_box(target, "$C6You were kicked off by a moderator."); send_message_box(target, "$C6You have been kicked off the server.");
target->should_disconnect = true; target->should_disconnect = true;
string target_name = name_for_client(target); string target_name = name_for_client(target);
send_text_message_printf(l, "$C6%s kicked off", target_name.c_str()); send_text_message_printf(l, "$C6%s kicked off", target_name.c_str());
@@ -1598,7 +1729,7 @@ static void server_command_ban(shared_ptr<Client> c, const std::string& args) {
target->login->account->ban_end_time = now() + usecs; target->login->account->ban_end_time = now() + usecs;
target->login->account->save(); target->login->account->save();
send_message_box(target, "$C6You were banned by a moderator."); send_message_box(target, "$C6You have been banned.");
target->should_disconnect = true; target->should_disconnect = true;
string target_name = name_for_client(target); string target_name = name_for_client(target);
send_text_message_printf(l, "$C6%s banned", target_name.c_str()); send_text_message_printf(l, "$C6%s banned", target_name.c_str());
@@ -1706,7 +1837,16 @@ static void proxy_command_next(shared_ptr<ProxyServer::LinkedSession> ses, const
} }
static void server_command_where(shared_ptr<Client> c, const std::string&) { static void server_command_where(shared_ptr<Client> c, const std::string&) {
send_text_message_printf(c, "$C7Floor: %02" PRIX32 "\nX: %g\nZ: %g", c->floor, c->x, c->z); auto l = c->require_lobby();
send_text_message_printf(c, "$C7%01" PRIX32 ":%s X:%" PRId32 " Z:%" PRId32,
c->floor, short_name_for_floor(l->episode, c->floor), static_cast<int32_t>(c->x), static_cast<int32_t>(c->z));
for (auto lc : l->clients) {
if (lc && (lc != c)) {
string name = lc->character()->disp.name.decode(lc->language());
send_text_message_printf(c, "$C6%s$C7 %01" PRIX32 ":%s",
name.c_str(), lc->floor, short_name_for_floor(l->episode, lc->floor));
}
}
} }
static void server_command_what(shared_ptr<Client> c, const std::string&) { static void server_command_what(shared_ptr<Client> c, const std::string&) {
@@ -2368,6 +2508,7 @@ static const unordered_map<string, ChatCommandDefinition> chat_commands({
{"$qcall", {server_command_qcall, proxy_command_qcall}}, {"$qcall", {server_command_qcall, proxy_command_qcall}},
{"$qcheck", {server_command_qcheck, nullptr}}, {"$qcheck", {server_command_qcheck, nullptr}},
{"$qclear", {server_command_qclear, proxy_command_qclear}}, {"$qclear", {server_command_qclear, proxy_command_qclear}},
{"$qfread", {server_command_qfread, nullptr}},
{"$qgread", {server_command_qgread, nullptr}}, {"$qgread", {server_command_qgread, nullptr}},
{"$qgwrite", {server_command_qgwrite, nullptr}}, {"$qgwrite", {server_command_qgwrite, nullptr}},
{"$qset", {server_command_qset, proxy_command_qset}}, {"$qset", {server_command_qset, proxy_command_qset}},
+67 -20
View File
@@ -13,6 +13,7 @@
#include "IPStackSimulator.hh" #include "IPStackSimulator.hh"
#include "Loggers.hh" #include "Loggers.hh"
#include "SendCommands.hh"
#include "Server.hh" #include "Server.hh"
#include "Version.hh" #include "Version.hh"
@@ -30,6 +31,7 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
if (version == Version::BB_V4) { if (version == Version::BB_V4) {
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::SAVE_ENABLED); this->set_flag(Flag::SAVE_ENABLED);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
return; return;
} }
@@ -40,32 +42,40 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
case Version::PC_PATCH: case Version::PC_PATCH:
case Version::BB_PATCH: case Version::BB_PATCH:
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break; break;
case Version::DC_NTE: case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE: case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1: case Version::DC_V1:
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break; break;
case Version::DC_V2: case Version::DC_V2:
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
case Version::PC_NTE: case Version::PC_NTE:
case Version::PC_V2: case Version::PC_V2:
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY); this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
case Version::GC_NTE: case Version::GC_NTE:
case Version::GC_V3: this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
break;
case Version::GC_EP3_NTE: case Version::GC_EP3_NTE:
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
break;
case Version::GC_V3:
case Version::GC_EP3: case Version::GC_EP3:
// Some of these versions have send_function_call and some don't; we
// have to set these flags later when we get sub_version
break; break;
case Version::XB_V3: case Version::XB_V3:
// TODO: Do all versions of XB need this flag? US does, at least. // TODO: Do all versions of XB need this flag? US does, at least.
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
default: default:
@@ -76,59 +86,62 @@ void Client::Config::set_flags_for_version(Version version, int64_t sub_version)
case 0x20: // DCNTE, possibly also DCv1 JP case 0x20: // DCNTE, possibly also DCv1 JP
case 0x21: // DCv1 US case 0x21: // DCv1 US
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break; break;
case 0x22: // DCv1 EU 50Hz (presumably) case 0x22: // DCv1 EU 50Hz (presumably)
case 0x23: // DCv1 EU 60Hz (presumably) case 0x23: // DCv1 EU 60Hz (presumably)
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL);
break; break;
case 0x25: // DCv2 JP case 0x25: // DCv2 JP
case 0x26: // DCv2 US case 0x26: // DCv2 US
case 0x27: // DCv2 EU 50Hz (presumably) case 0x27: // DCv2 EU 50Hz (presumably)
case 0x28: // DCv2 EU 60Hz (presumably) case 0x28: // DCv2 EU 60Hz (presumably)
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
case 0x29: // PC case 0x29: // PC
this->set_flag(Flag::NO_D6); this->set_flag(Flag::NO_D6);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY); this->set_flag(Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
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 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 case 0x31: // GC Ep1&2 US v1.0, GC US v1.1, XB US
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
break; break;
case 0x32: // GC Ep1&2 EU 50Hz case 0x32: // GC Ep1&2 EU 50Hz
case 0x33: // GC Ep1&2 EU 60Hz case 0x33: // GC Ep1&2 EU 60Hz
case 0x34: // GC Ep1&2 JP v1.3 case 0x34: // GC Ep1&2 JP v1.3
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
break; break;
case 0x35: // GC Ep1&2 JP v1.4 (Plus) case 0x35: // GC Ep1&2 JP v1.4 (Plus)
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL); this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
break; break;
case 0x3A: // GC Ep1&2 US v1.2 (Plus) GMK edition
this->set_flag(Flag::IS_CLIENT_CUSTOMIZATION);
[[fallthrough]];
case 0x36: // GC Ep1&2 US v1.2 (Plus) case 0x36: // GC Ep1&2 US v1.2 (Plus)
case 0x39: // GC Ep1&2 JP v1.5 (Plus) case 0x39: // GC Ep1&2 JP v1.5 (Plus)
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL); this->set_flag(Flag::CAN_RECEIVE_ENABLE_B2_QUEST);
break; break;
case 0x40: // GC Ep3 JP and Trial Edition (and BB) case 0x40: // GC Ep3 JP and Trial Edition (and BB)
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::HAS_SEND_FUNCTION_CALL);
this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL); this->set_flag(Flag::ENCRYPTED_SEND_FUNCTION_CALL);
this->set_flag(Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH); 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 // sub_version can't be used to tell JP final and Trial Edition apart; we
// instead look at header.flag in the 61 command and set the version then. // instead look at header.flag in the 61 command and set the version then.
break; break;
case 0x41: // GC Ep3 US (and BB) 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);
break;
case 0x42: // GC Ep3 EU 50Hz case 0x42: // GC Ep3 EU 50Hz
case 0x43: // GC Ep3 EU 60Hz case 0x43: // GC Ep3 EU 60Hz
this->set_flag(Flag::NO_D6_AFTER_LOBBY); this->set_flag(Flag::NO_D6_AFTER_LOBBY);
this->set_flag(Flag::NO_SEND_FUNCTION_CALL); this->set_flag(Flag::CAN_RECEIVE_ENABLE_B2_QUEST);
break; break;
default: default:
throw runtime_error(string_printf("unknown sub_version %" PRIX64, sub_version)); throw runtime_error(string_printf("unknown sub_version %" PRIX64, sub_version));
@@ -382,7 +395,7 @@ bool Client::evaluate_quest_availability_expression(
int64_t ret = expr->evaluate(env); int64_t ret = expr->evaluate(env);
if (this->log.should_log(LogLevel::INFO)) { if (this->log.should_log(LogLevel::INFO)) {
string expr_str = expr->str(); string expr_str = expr->str();
this->log.info("Evaluated quest availability expression %s => %s", expr_str.c_str(), ret ? "TRUE" : "FALSE"); this->log.info("Evaluated integral expression %s => %s", expr_str.c_str(), ret ? "TRUE" : "FALSE");
} }
return ret; return ret;
} }
@@ -643,8 +656,9 @@ 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); return string_printf("system/players/player_%s_%hhd.psochar", bb_username.c_str(), index);
} }
string Client::backup_character_filename(uint32_t account_id, size_t index) { string Client::backup_character_filename(uint32_t account_id, size_t index, bool is_ep3) {
return string_printf("system/players/backup_player_%" PRIu32 "_%zu.psochar", account_id, index); return string_printf("system/players/backup_player_%" PRIu32 "_%zu.%s",
account_id, index, is_ep3 ? "pso3char" : "psochar");
} }
string Client::character_filename(int8_t index) const { string Client::character_filename(int8_t index) const {
@@ -770,6 +784,10 @@ void Client::load_all_files() {
files_manager->set_system(sys_filename, this->system_data); files_manager->set_system(sys_filename, this->system_data);
player_data_log.info("Loaded system data from %s", char_filename.c_str()); player_data_log.info("Loaded system data from %s", char_filename.c_str());
} }
this->update_character_data_after_load(this->character_data);
this->system_data->base.language = this->language();
} else { } else {
player_data_log.info("Character file is missing: %s", char_filename.c_str()); player_data_log.info("Character file is missing: %s", char_filename.c_str());
} }
@@ -861,6 +879,7 @@ void Client::load_all_files() {
} else { } else {
player_data_log.info("Loaded legacy player data from %s", nsc_filename.c_str()); player_data_log.info("Loaded legacy player data from %s", nsc_filename.c_str());
} }
this->update_character_data_after_load(this->character_data);
} }
} }
@@ -880,6 +899,15 @@ void Client::load_all_files() {
} }
} }
void Client::update_character_data_after_load(shared_ptr<PSOBBCharacterFile> charfile) {
charfile->import_tethealla_material_usage(this->require_server_state()->level_table(this->version()));
uint8_t lang = this->language();
player_data_log.info("Overriding language fields in save files with %02hhX (%c)", lang, char_for_language_code(lang));
charfile->inventory.language = lang;
charfile->guild_card.language = lang;
}
void Client::save_all() { void Client::save_all() {
if (this->system_data) { if (this->system_data) {
this->save_system_file(); this->save_system_file();
@@ -892,7 +920,7 @@ void Client::save_all() {
} }
if (this->external_bank) { if (this->external_bank) {
string filename = this->shared_bank_filename(); string filename = this->shared_bank_filename();
save_object_file<PlayerBank>(filename, *this->external_bank); save_object_file<PlayerBank200>(filename, *this->external_bank);
player_data_log.info("Saved shared bank file %s", filename.c_str()); player_data_log.info("Saved shared bank file %s", filename.c_str());
} }
if (this->external_bank_character) { if (this->external_bank_character) {
@@ -936,6 +964,13 @@ void Client::save_character_file(
player_data_log.info("Saved character file %s", filename.c_str()); player_data_log.info("Saved character file %s", filename.c_str());
} }
void Client::save_ep3_character_file(
const string& filename,
const PSOGCEp3CharacterFile::Character& character) {
save_file(filename, &character, sizeof(character));
player_data_log.info("Saved Episode 3 character file %s", filename.c_str());
}
void Client::save_character_file() { void Client::save_character_file() {
if (!this->system_data.get()) { if (!this->system_data.get()) {
throw logic_error("no system file loaded"); throw logic_error("no system file loaded");
@@ -966,7 +1001,7 @@ void Client::save_guild_card_file() const {
} }
void Client::load_backup_character(uint32_t account_id, size_t index) { void Client::load_backup_character(uint32_t account_id, size_t index) {
string filename = this->backup_character_filename(account_id, index); string filename = this->backup_character_filename(account_id, index, false);
auto f = fopen_unique(filename, "rb"); auto f = fopen_unique(filename, "rb");
auto header = freadx<PSOCommandHeaderBB>(f.get()); auto header = freadx<PSOCommandHeaderBB>(f.get());
if (header.size != 0x399C) { if (header.size != 0x399C) {
@@ -979,9 +1014,20 @@ void Client::load_backup_character(uint32_t account_id, size_t index) {
throw runtime_error("incorrect flag in character file header"); throw runtime_error("incorrect flag in character file header");
} }
this->character_data = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(f.get())); this->character_data = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(f.get()));
this->update_character_data_after_load(this->character_data);
this->v1_v2_last_reported_disp.reset(); this->v1_v2_last_reported_disp.reset();
} }
shared_ptr<PSOGCEp3CharacterFile::Character> Client::load_ep3_backup_character(uint32_t account_id, size_t index) {
string filename = this->backup_character_filename(account_id, index, true);
auto ch = make_shared<PSOGCEp3CharacterFile::Character>(load_object_file<PSOGCEp3CharacterFile::Character>(filename));
this->character_data = PSOBBCharacterFile::create_from_ep3(*ch);
this->ep3_config = make_shared<Episode3::PlayerConfig>(ch->ep3_config);
this->update_character_data_after_load(this->character_data);
this->v1_v2_last_reported_disp.reset();
return ch;
}
void Client::save_and_unload_character() { void Client::save_and_unload_character() {
if (this->character_data) { if (this->character_data) {
this->save_character_file(); this->save_character_file();
@@ -990,7 +1036,7 @@ void Client::save_and_unload_character() {
} }
} }
PlayerBank& Client::current_bank() { PlayerBank200& Client::current_bank() {
if (this->external_bank) { if (this->external_bank) {
return *this->external_bank; return *this->external_bank;
} else if (this->external_bank_character) { } else if (this->external_bank_character) {
@@ -1006,7 +1052,7 @@ std::shared_ptr<PSOBBCharacterFile> Client::current_bank_character() {
void Client::use_default_bank() { void Client::use_default_bank() {
if (this->external_bank) { if (this->external_bank) {
string filename = this->shared_bank_filename(); string filename = this->shared_bank_filename();
save_object_file<PlayerBank>(filename, *this->external_bank); save_object_file<PlayerBank200>(filename, *this->external_bank);
this->external_bank.reset(); this->external_bank.reset();
player_data_log.info("Detached shared bank %s", filename.c_str()); player_data_log.info("Detached shared bank %s", filename.c_str());
} }
@@ -1028,12 +1074,12 @@ bool Client::use_shared_bank() {
player_data_log.info("Using loaded shared bank %s", filename.c_str()); player_data_log.info("Using loaded shared bank %s", filename.c_str());
return true; return true;
} else if (isfile(filename)) { } else if (isfile(filename)) {
this->external_bank = make_shared<PlayerBank>(load_object_file<PlayerBank>(filename)); this->external_bank = make_shared<PlayerBank200>(load_object_file<PlayerBank200>(filename));
files_manager->set_bank(filename, this->external_bank); files_manager->set_bank(filename, this->external_bank);
player_data_log.info("Loaded shared bank %s", filename.c_str()); player_data_log.info("Loaded shared bank %s", filename.c_str());
return true; return true;
} else { } else {
this->external_bank = make_shared<PlayerBank>(); this->external_bank = make_shared<PlayerBank200>();
files_manager->set_bank(filename, this->external_bank); files_manager->set_bank(filename, this->external_bank);
player_data_log.info("Created shared bank for %s", filename.c_str()); player_data_log.info("Created shared bank for %s", filename.c_str());
return false; return false;
@@ -1063,6 +1109,7 @@ void Client::use_character_bank(int8_t index) {
throw runtime_error("incorrect flag in character file header"); throw runtime_error("incorrect flag in character file header");
} }
this->external_bank_character = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(f.get())); this->external_bank_character = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(f.get()));
this->update_character_data_after_load(this->external_bank_character);
this->external_bank_character_index = index; this->external_bank_character_index = index;
files_manager->set_character(filename, this->external_bank_character); files_manager->set_character(filename, this->external_bank_character);
player_data_log.info("Loaded character data from %s for external bank", filename.c_str()); player_data_log.info("Loaded character data from %s for external bank", filename.c_str());
+19 -6
View File
@@ -24,6 +24,7 @@ extern const uint64_t CLIENT_CONFIG_MAGIC;
class Server; class Server;
struct Lobby; struct Lobby;
class Parsed6x70Data;
class Client : public std::enable_shared_from_this<Client> { class Client : public std::enable_shared_from_this<Client> {
public: public:
@@ -34,7 +35,7 @@ public:
// TODO: It'd be nice to use a pattern here (e.g. all server-side flags are // 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 // in the high bits) but that would require re-recording or manually
// rewriting all the tests // rewriting all the tests
CLIENT_SIDE_MASK = 0xFF3CFFFF7C0FFFFB, CLIENT_SIDE_MASK = 0xFF3CFFFF7C0BFFFB,
// Version-related flags // Version-related flags
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002, CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
@@ -43,11 +44,12 @@ public:
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400, FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
// Flags describing the behavior for send_function_call // Flags describing the behavior for send_function_call
NO_SEND_FUNCTION_CALL = 0x0000000000001000, HAS_SEND_FUNCTION_CALL = 0x0000000000001000,
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000, ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000, SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000, SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x0000000000010000, CAN_RECEIVE_ENABLE_B2_QUEST = 0x0000000000020000,
AWAITING_ENABLE_B2_QUEST = 0x0000000000040000, // Server-side only
// State flags // State flags
LOADING = 0x0000000000100000, // Server-side only LOADING = 0x0000000000100000, // Server-side only
@@ -67,8 +69,10 @@ public:
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000, // 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_OBJECT_STATE = 0x0080000000000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only
SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0200000000000000, // Server-side only
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000, SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
SWITCH_ASSIST_ENABLED = 0x0000000100000000, SWITCH_ASSIST_ENABLED = 0x0000000100000000,
IS_CLIENT_CUSTOMIZATION = 0x0100000000000000,
// Cheat mode and option flags // Cheat mode and option flags
INFINITE_HP_ENABLED = 0x0000000200000000, INFINITE_HP_ENABLED = 0x0000000200000000,
@@ -90,6 +94,7 @@ public:
PROXY_BLANK_NAME_ENABLED = 0x0000400000000000, PROXY_BLANK_NAME_ENABLED = 0x0000400000000000,
PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000, PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000,
PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000, PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000,
PROXY_VIRTUAL_CLIENT = 0x0400000000000000,
// clang-format on // clang-format on
}; };
enum class ItemDropNotificationMode { enum class ItemDropNotificationMode {
@@ -240,9 +245,12 @@ public:
bool should_update_play_time; bool should_update_play_time;
std::unordered_set<uint32_t> blocked_senders; std::unordered_set<uint32_t> blocked_senders;
std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp; std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp;
std::shared_ptr<Parsed6x70Data> last_reported_6x70;
// These are null unless the client is within the trade sequence (D0-D4 or EE commands) // These are null unless the client is within the trade sequence (D0-D4 or EE commands)
std::unique_ptr<PendingItemTrade> pending_item_trade; std::unique_ptr<PendingItemTrade> pending_item_trade;
std::unique_ptr<PendingCardTrade> pending_card_trade; std::unique_ptr<PendingCardTrade> pending_card_trade;
uint32_t telepipe_lobby_id;
G_SetTelepipeState_6x68 telepipe_state;
std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3 std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3
int8_t bb_character_index; int8_t bb_character_index;
ItemData bb_identify_result; ItemData bb_identify_result;
@@ -356,7 +364,7 @@ public:
std::string system_filename() const; std::string system_filename() const;
static std::string character_filename(const std::string& bb_username, int8_t index); static std::string character_filename(const std::string& bb_username, int8_t index);
static std::string backup_character_filename(uint32_t account_id, size_t index); static std::string backup_character_filename(uint32_t account_id, size_t index, bool is_ep3);
std::string character_filename(int8_t index = -1) const; std::string character_filename(int8_t index = -1) const;
std::string guild_card_filename() const; std::string guild_card_filename() const;
std::string shared_bank_filename() const; std::string shared_bank_filename() const;
@@ -370,14 +378,18 @@ public:
const std::string& filename, const std::string& filename,
std::shared_ptr<const PSOBBBaseSystemFile> sys, std::shared_ptr<const PSOBBBaseSystemFile> sys,
std::shared_ptr<const PSOBBCharacterFile> character); std::shared_ptr<const PSOBBCharacterFile> character);
static void save_ep3_character_file(
const std::string& filename,
const PSOGCEp3CharacterFile::Character& character);
// Note: This function is not const because it updates the player's play time. // Note: This function is not const because it updates the player's play time.
void save_character_file(); void save_character_file();
void save_guild_card_file() const; void save_guild_card_file() const;
void load_backup_character(uint32_t account_id, size_t index); void load_backup_character(uint32_t account_id, size_t index);
std::shared_ptr<PSOGCEp3CharacterFile::Character> load_ep3_backup_character(uint32_t account_id, size_t index);
void save_and_unload_character(); void save_and_unload_character();
PlayerBank& current_bank(); PlayerBank200& current_bank();
std::shared_ptr<PSOBBCharacterFile> current_bank_character(); std::shared_ptr<PSOBBCharacterFile> current_bank_character();
bool use_shared_bank(); // Returns true if the bank exists; false if it was created bool use_shared_bank(); // Returns true if the bank exists; false if it was created
void use_character_bank(int8_t bb_character_index); void use_character_bank(int8_t bb_character_index);
@@ -394,7 +406,7 @@ private:
std::shared_ptr<PSOBBCharacterFile> overlay_character_data; std::shared_ptr<PSOBBCharacterFile> overlay_character_data;
std::shared_ptr<PSOBBCharacterFile> character_data; std::shared_ptr<PSOBBCharacterFile> character_data;
std::shared_ptr<PSOBBGuildCardFile> guild_card_data; std::shared_ptr<PSOBBGuildCardFile> guild_card_data;
std::shared_ptr<PlayerBank> external_bank; std::shared_ptr<PlayerBank200> external_bank;
std::shared_ptr<PSOBBCharacterFile> external_bank_character; std::shared_ptr<PSOBBCharacterFile> external_bank_character;
int8_t external_bank_character_index; int8_t external_bank_character_index;
uint64_t last_play_time_update; uint64_t last_play_time_update;
@@ -402,4 +414,5 @@ private:
void save_and_clear_external_bank(); void save_and_clear_external_bank();
void load_all_files(); void load_all_files();
void update_character_data_after_load(std::shared_ptr<PSOBBCharacterFile> character_data);
}; };
+124 -64
View File
@@ -72,7 +72,7 @@
// - - $C7: White (FFFFFF) // - - $C7: White (FFFFFF)
// - - $C8: Pink (FF8080) // - - $C8: Pink (FF8080)
// - - $C9: Violet (8080FF) // - - $C9: Violet (8080FF)
// - - $CG: Orange pulse (FFE000 + darkenings thereof) // - - $CG: Orange pulse (FFE000 + darkenings thereof; v2 and later only)
// - - $Ca: Orange (F5A052; Episode 3 only) // - - $Ca: Orange (F5A052; Episode 3 only)
// - Special character codes (Ep3 only) // - Special character codes (Ep3 only)
// - - $B: Dash + small bullet // - - $B: Dash + small bullet
@@ -430,8 +430,7 @@ struct C_LegacyLogin_BB_04 {
// Any other nonzero value = Generic failure (101) // Any other nonzero value = Generic failure (101)
// The client config field in this command is ignored by pre-V3 clients as well // The client config field in this command is ignored by pre-V3 clients as well
// as Episodes 1&2 Trial Edition. All other V3 clients save it as opaque data to // as Episodes 1&2 Trial Edition. All other V3 clients save it as opaque data to
// be returned in a 9E or 9F command later. newserv sends the client config // be returned in a 9E or 9F command later.
// anyway to clients that ignore it.
// The client will respond with a 96 command, but only the first time it // The client will respond with a 96 command, but only the first time it
// receives this command - for later 04 commands, the client will still update // receives this command - for later 04 commands, the client will still update
// its client config but will not respond. Changing the security data at any // its client config but will not respond. Changing the security data at any
@@ -718,16 +717,19 @@ check_struct_size(C_MenuSelection_PC_BB_10_Flag03, 0x48);
// Internal name: RcvDownLoad // Internal name: RcvDownLoad
// Used for downloading online quests. For download quests (to be saved to the // Used for downloading online quests. For download quests (to be saved to the
// memory card), use A7 instead. // memory card), use A7 instead.
// This command exists on DC NTE, but it does nothing. DC NTE does not have the
// 44 command, which would also be required for loading quests, so online
// quests canot be loaded on DC NTE.
// All chunks except the last must have 0x400 data bytes. When downloading an // All chunks except the last must have 0x400 data bytes. When downloading an
// online quest, the .bin and .dat chunks may be interleaved (although newserv // online quest, the .bin and .dat chunks may be interleaved. There is a client
// currently sends them sequentially). There is a client bug in BB (and // bug in BB (and probably all other versions) where if the quest file's size
// probably all other versions) where if the quest file's size is a multiple // is a multiple of 0x400, the last chunk will have size 0x400, and the client
// of 0x400, the last chunk will have size 0x400, and the client will never // will never consider the download complete since it only checks if the last
// consider the download complete since it only checks if the last chunk has // chunk has size < 0x400; it does not check if all expected bytes have been
// size < 0x400; it does not check if all expected bytes have been received. // received. To work around this, newserv appends an extra zero byte if the
// To work around this, newserv appends an extra zero byte if the quest file's // quest file's size is a multiple of 0x400; this byte will be ignored since
// size is a multiple of 0x400; this byte will be ignored since the PRS // the PRS decompression algorithm contains a stop command, so it will never
// decompression algorithm contains a stop command, so it will never read it. // read it.
// header.flag = file chunk index (start offset / 0x400) // header.flag = file chunk index (start offset / 0x400)
struct S_WriteFile_13_A7 { struct S_WriteFile_13_A7 {
@@ -975,6 +977,8 @@ check_struct_size(S_GuildCardSearchResult_BB_41, 0x128);
// Internal name: RcvDownLoadHead // Internal name: RcvDownLoadHead
// Used for downloading online quests. The client will react to a 44 command if // Used for downloading online quests. The client will react to a 44 command if
// the filename ends in .bin or .dat. // the filename ends in .bin or .dat.
// This command is not implemented on DC NTE, so DC NTE cannot receive online
// quest files.
// For download quests (to be saved to the memory card) and GBA games, the A6 // For download quests (to be saved to the memory card) and GBA games, the A6
// command is used instead. The client will react to A6 if the filename ends in // command is used instead. The client will react to A6 if the filename ends in
// .bin/.dat (quests), .pvr (textures), or .gba (GameBoy Advance games). // .bin/.dat (quests), .pvr (textures), or .gba (GameBoy Advance games).
@@ -2022,8 +2026,19 @@ template <TextEncoding Encoding, size_t ShortDescLength>
struct S_QuestMenuEntryT { struct S_QuestMenuEntryT {
// Note: The game treats menu_id as two 8-bit fields followed by a 16-bit // Note: The game treats menu_id as two 8-bit fields followed by a 16-bit
// field. In most situations, this is opaque to the server, so we treat it as // field. In most situations, this is opaque to the server, so we treat it as
// a single 32-bit field, but in the case of the quest menu, the second byte // a single 32-bit field; however, in the case of the quest menu, the first
// is used to determine the icon that appears to the left of the quest name. // and second bytes have meaning on the client.
//
// The first byte is used as the quest episode number, which is only relevant
// for showing the Challenge Mode times window when a quest is selected.
// This byte must be set correctly on the quest category entry, not the quest
// itself, so the Episode 1 Challenge quests category should have a value of
// 1 in this byte, and the Episode 2 Challenge quests category should have a
// value of 2. (This is not the only condition required for the Challenge
// Mode times window to work; see the description of command A3 also.)
//
// The second byte of the menu ID is used to determine which icon appears to
// the left of the quest name.
// Specifically: // Specifically:
// 0 = online quest icon (green diamond) // 0 = online quest icon (green diamond)
// 1 = download quest icon (green square with outlined diamond) // 1 = download quest icon (green square with outlined diamond)
@@ -2054,7 +2069,13 @@ struct S_QuestMenuEntry_BB_A2_A4 {
} __packed_ws__(S_QuestMenuEntry_BB_A2_A4, 0x13C); } __packed_ws__(S_QuestMenuEntry_BB_A2_A4, 0x13C);
// A3 (S->C): Quest information // A3 (S->C): Quest information
// Same format as 1A/D5 command (plain text) // Same format as 1A/D5 command (plain text). The header.flag field is used to
// inform the client of the Challenge stage number, so it can show the correct
// timing window when the stage is selected. The Episode 1 stage numbers should
// be specified as 51-59 (decimal) in header.flag, and the Episode 2 stage
// numbers should be specified as 61-65 (decimal). If the header.flag value is
// outside this range, it is ignored, and the Challenge Mode times window does
// not update.
// A4 (S->C): Download quest menu // A4 (S->C): Download quest menu
// Internal name: RcvQuestList // Internal name: RcvQuestList
@@ -2088,14 +2109,11 @@ struct S_QuestMenuEntry_BB_A2_A4 {
// A9 (C->S): Quest menu closed (canceled) // A9 (C->S): Quest menu closed (canceled)
// Internal name: SndQuestEnd // Internal name: SndQuestEnd
// No arguments // No arguments
// This command is sent when the in-game quest menu (A2) is closed. When the // This command is sent when the in-game quest menu (A2) is closed. This is used
// by the server to unlock the game if the players don't select a quest, since
// players are forbidden from joining while the quest menu is open. When the
// download quest menu is closed, either by downloading a quest or canceling, // download quest menu is closed, either by downloading a quest or canceling,
// the client sends A0 instead. The existence of the A0 response on the download // the client sends A0 instead.
// case makes sense, because the client may not be in a lobby and the server may
// need to send another menu or redirect the client. But for the online quest
// menu, the client is already in a game and can move normally after canceling
// the quest menu, so it's not obvious why A9 is needed at all. newserv (and
// probably all other private servers) ignores it.
// Curiously, PSO GC sends uninitialized data in header.flag. // Curiously, PSO GC sends uninitialized data in header.flag.
// AA (C->S): Send quest statistic (V3/BB) // AA (C->S): Send quest statistic (V3/BB)
@@ -3864,7 +3882,7 @@ struct G_SwitchStateChanged_6x05 {
// Note: header.object_id is 0xFFFF for room clear when all enemies defeated // Note: header.object_id is 0xFFFF for room clear when all enemies defeated
G_ObjectIDHeader header; G_ObjectIDHeader header;
// TODO: Some of these might be big-endian on GC; it only byteswaps // TODO: Some of these might be big-endian on GC; it only byteswaps
// unknown_a3. Are the others actually uint16, or are they uint8[2]? // switch_flag_num. Are the others actually uint16, or are they uint8[2]?
le_uint16_t unknown_a1 = 0; le_uint16_t unknown_a1 = 0;
le_uint16_t unknown_a2 = 0; le_uint16_t unknown_a2 = 0;
le_uint16_t switch_flag_num = 0; le_uint16_t switch_flag_num = 0;
@@ -3894,6 +3912,11 @@ struct G_SendGuildCard_PC_6x06 {
GuildCardPC guild_card; GuildCardPC guild_card;
} __packed_ws__(G_SendGuildCard_PC_6x06, 0xF4); } __packed_ws__(G_SendGuildCard_PC_6x06, 0xF4);
struct G_SendGuildCard_GCNTE_6x06 {
G_UnusedHeader header;
GuildCardGCNTE guild_card;
} __packed_ws__(G_SendGuildCard_GCNTE_6x06, 0xA8);
struct G_SendGuildCard_GC_6x06 { struct G_SendGuildCard_GC_6x06 {
G_UnusedHeader header; G_UnusedHeader header;
GuildCardGC guild_card; GuildCardGC guild_card;
@@ -3910,6 +3933,7 @@ struct G_SendGuildCard_BB_6x06 {
} __packed_ws__(G_SendGuildCard_BB_6x06, 0x10C); } __packed_ws__(G_SendGuildCard_BB_6x06, 0x10C);
// 6x07: Symbol chat // 6x07: Symbol chat
// If UDP mode is enabled, this command is sent via UDP.
struct G_SymbolChat_6x07 { struct G_SymbolChat_6x07 {
G_UnusedHeader header; G_UnusedHeader header;
@@ -4332,6 +4356,7 @@ struct G_SetPosition_6x3F {
} __packed_ws__(G_SetPosition_6x3F, 0x18); } __packed_ws__(G_SetPosition_6x3F, 0x18);
// 6x40: Walk (protected on V3/V4) // 6x40: Walk (protected on V3/V4)
// If UDP mode is enabled, this command is sent via UDP.
struct G_WalkToPosition_6x40 { struct G_WalkToPosition_6x40 {
G_ClientIDHeader header; G_ClientIDHeader header;
@@ -4350,6 +4375,7 @@ struct G_Unknown_6x41 {
} __packed_ws__(G_Unknown_6x41, 0x0C); } __packed_ws__(G_Unknown_6x41, 0x0C);
// 6x42: Run (protected on V3/V4) // 6x42: Run (protected on V3/V4)
// If UDP mode is enabled, this command is sent via UDP.
struct G_RunToPosition_6x42 { struct G_RunToPosition_6x42 {
G_ClientIDHeader header; G_ClientIDHeader header;
@@ -4360,6 +4386,7 @@ struct G_RunToPosition_6x42 {
// 6x43: First attack (protected on V3/V4) // 6x43: First attack (protected on V3/V4)
// 6x44: Second attack (protected on V3/V4) // 6x44: Second attack (protected on V3/V4)
// 6x45: Third attack (protected on V3/V4) // 6x45: Third attack (protected on V3/V4)
// If UDP mode is enabled, these commands are sent via UDP.
struct G_Attack_6x43_6x44_6x45 { struct G_Attack_6x43_6x44_6x45 {
G_ClientIDHeader header; G_ClientIDHeader header;
@@ -4368,6 +4395,10 @@ struct G_Attack_6x43_6x44_6x45 {
} __packed_ws__(G_Attack_6x43_6x44_6x45, 8); } __packed_ws__(G_Attack_6x43_6x44_6x45, 8);
// 6x46: Attack finished (sent after each of 43, 44, and 45) (protected on V3/V4) // 6x46: Attack finished (sent after each of 43, 44, and 45) (protected on V3/V4)
// The number of targets is not bounds-checked during byteswapping on GC
// clients. The client only expects up to 10 entries here, so if the number of
// targets is too large, the client will byteswap the function's return address
// on the stack, and it will crash.
struct TargetEntry { struct TargetEntry {
le_uint16_t entity_id = 0; le_uint16_t entity_id = 0;
@@ -4382,6 +4413,7 @@ struct G_AttackFinished_6x46 {
} __packed_ws__(G_AttackFinished_6x46, 0x30); } __packed_ws__(G_AttackFinished_6x46, 0x30);
// 6x47: Cast technique (protected on V3/V4) // 6x47: Cast technique (protected on V3/V4)
// On GC, this command has the same bounds-check bug as 6x46.
struct G_CastTechnique_6x47 { struct G_CastTechnique_6x47 {
G_ClientIDHeader header; G_ClientIDHeader header;
@@ -4408,22 +4440,19 @@ struct G_CastTechniqueComplete_6x48 {
le_uint16_t level = 0; le_uint16_t level = 0;
} __packed_ws__(G_CastTechniqueComplete_6x48, 8); } __packed_ws__(G_CastTechniqueComplete_6x48, 8);
// 6x49: Subtract photon blast energy (protected on V3/V4) // 6x49: Execute Photon Blast (protected on V3/V4)
// On GC, this command has the same bounds-check bug as 6x46.
struct G_SubtractPBEnergy_6x49 { struct G_ExecutePhotonBlast_6x49 {
G_ClientIDHeader header; G_ClientIDHeader header;
uint8_t unknown_a1 = 0; uint8_t unknown_a1 = 0;
uint8_t unknown_a2 = 0; uint8_t unknown_a2 = 0;
le_uint16_t entry_count = 0; le_uint16_t target_count = 0;
le_uint16_t unknown_a3 = 0; le_uint16_t unknown_a3 = 0;
le_uint16_t unknown_a4 = 0; le_uint16_t unknown_a4 = 0;
struct Entry {
le_uint16_t unknown_a1 = 0;
le_uint16_t unknown_a2 = 0;
} __packed_ws__(Entry, 4);
// The client may send a shorter command if not all of these are used. // The client may send a shorter command if not all of these are used.
parray<Entry, 10> entries; parray<TargetEntry, 10> targets;
} __packed_ws__(G_SubtractPBEnergy_6x49, 0x34); } __packed_ws__(G_ExecutePhotonBlast_6x49, 0x34);
// 6x4A: Fully shield attack (protected on V3/V4) // 6x4A: Fully shield attack (protected on V3/V4)
@@ -4462,13 +4491,24 @@ struct G_PlayerRevived_6x4F {
} __packed_ws__(G_PlayerRevived_6x4F, 4); } __packed_ws__(G_PlayerRevived_6x4F, 4);
// 6x50: Switch interaction (protected on V3/V4) // 6x50: Switch interaction (protected on V3/V4)
// If UDP mode is enabled, this command is sent via UDP.
struct G_SwitchInteraction_6x50 { struct G_SwitchInteraction_6x50 {
G_ClientIDHeader header; G_ClientIDHeader header;
le_uint32_t unknown_a1 = 0; le_uint32_t unknown_a1 = 0;
} __packed_ws__(G_SwitchInteraction_6x50, 8); } __packed_ws__(G_SwitchInteraction_6x50, 8);
// 6x51: Invalid subcommand // 6x51: Set player angle
// If UDP mode is enabled, this command is sent via UDP.
// This command appears to be vestigial - no version of the game has a handler
// for it (it is always ignored), but PSO GC has a function that sends it. It's
// not known if this function is ever called, or how to trigger it.
struct G_SetPlayerAngle_6x51 {
G_ClientIDHeader header;
le_uint16_t angle = 0;
parray<uint8_t, 2> unused;
} __packed_ws__(G_SetPlayerAngle_6x51, 8);
// 6x52: Set animation state (protected on V3/V4) // 6x52: Set animation state (protected on V3/V4)
@@ -4522,6 +4562,7 @@ struct G_Unknown_6x57 {
} __packed_ws__(G_Unknown_6x57, 4); } __packed_ws__(G_Unknown_6x57, 4);
// 6x58: Lobby animation (protected on V3/V4) // 6x58: Lobby animation (protected on V3/V4)
// If UDP mode is enabled, this command is sent via UDP.
struct G_LobbyAnimation_6x58 { struct G_LobbyAnimation_6x58 {
G_ClientIDHeader header; G_ClientIDHeader header;
@@ -4635,7 +4676,9 @@ struct G_ActivateMagEffect_6x61 {
// 6x62: Unknown // 6x62: Unknown
// This command has a handler, but it does nothing even on DC NTE. // This command has a handler, but it does nothing even on DC NTE.
// 6x63: Destroy floor item (used when too many items have been dropped) // 6x63: Destroy floor item
// This is sent by the leader to destroy a floor item when there are 50 or more
// items already on the ground on the current floor.
struct G_DestroyFloorItem_6x5C_6x63 { struct G_DestroyFloorItem_6x5C_6x63 {
G_UnusedHeader header; G_UnusedHeader header;
@@ -4665,18 +4708,20 @@ struct G_TriggerSetEvent_6x67 {
le_uint32_t client_id = 0; le_uint32_t client_id = 0;
} __packed_ws__(G_TriggerSetEvent_6x67, 0x10); } __packed_ws__(G_TriggerSetEvent_6x67, 0x10);
// 6x68: Create telepipe / cast Ryuker // 6x68: Set telepipe state
struct G_CreateTelepipe_6x68 { struct G_SetTelepipeState_6x68 {
G_UnusedHeader header; G_UnusedHeader header;
le_uint16_t client_id2 = 0; le_uint16_t client_id2 = 0;
le_uint16_t floor = 0; le_uint16_t floor = 0;
le_uint32_t unknown_a2 = 0; le_uint16_t unknown_b1 = 0;
uint8_t unknown_b2 = 0;
uint8_t unknown_b3 = 0;
le_float x = 0.0f; le_float x = 0.0f;
le_float y = 0.0f; le_float y = 0.0f;
le_float z = 0.0f; le_float z = 0.0f;
le_uint32_t unused3 = 0; le_uint32_t unknown_a3 = 0;
} __packed_ws__(G_CreateTelepipe_6x68, 0x1C); } __packed_ws__(G_SetTelepipeState_6x68, 0x1C);
// 6x69: NPC control // 6x69: NPC control
// Note: NPCs cannot be destroyed with 6x69; 6x1C is used instead for that. // Note: NPCs cannot be destroyed with 6x69; 6x1C is used instead for that.
@@ -4823,16 +4868,16 @@ struct G_SetQuestFlags_BB_6x6F {
// and instead rearranged a bunch of things. This is presumably because this // and instead rearranged a bunch of things. This is presumably because this
// structure also includes transient state (e.g. current HP). // structure also includes transient state (e.g. current HP).
struct Telepipe { struct Telepipe6x70 {
/* 00 */ le_uint16_t owner_client_id = 0xFFFF; /* 00 */ le_uint16_t owner_client_id = 0xFFFF;
/* 02 */ le_uint16_t floor = 0; /* 02 */ le_uint16_t floor = 0;
/* 04 */ le_uint32_t unknown_a2 = 0; /* 04 */ le_uint32_t unknown_a1 = 0;
/* 08 */ le_float x = 0.0f; /* 08 */ le_float x = 0.0f;
/* 0C */ le_float y = 0.0f; /* 0C */ le_float y = 0.0f;
/* 10 */ le_float z = 0.0f; /* 10 */ le_float z = 0.0f;
/* 14 */ le_uint32_t unknown_a3 = 0; /* 14 */ le_uint32_t unknown_a3 = 0;
/* 18 */ le_uint32_t unknown_a4 = 0x0000FFFF; /* 18 */ le_uint32_t unknown_a4 = 0x0000FFFF;
} __packed_ws__(Telepipe, 0x1C); } __packed_ws__(Telepipe6x70, 0x1C);
struct G_Unknown_6x70_SubA1 { struct G_Unknown_6x70_SubA1 {
// This is used in all versions of this command except DCNTE and 11/2000. // This is used in all versions of this command except DCNTE and 11/2000.
@@ -4872,7 +4917,7 @@ struct G_SyncPlayerDispAndInventory_DCNTE_6x70 {
// The following two fields appear to contain uninitialized data // The following two fields appear to contain uninitialized data
/* 0030 */ le_uint32_t unknown_a5 = 0; /* 0030 */ le_uint32_t unknown_a5 = 0;
/* 0034 */ le_uint32_t unknown_a6 = 0; /* 0034 */ le_uint32_t unknown_a6 = 0;
/* 0038 */ Telepipe telepipe; /* 0038 */ Telepipe6x70 telepipe;
/* 0054 */ le_uint32_t unknown_a8 = 0; /* 0054 */ le_uint32_t unknown_a8 = 0;
/* 0058 */ parray<uint8_t, 0x10> unknown_a9; /* 0058 */ parray<uint8_t, 0x10> unknown_a9;
/* 0068 */ le_uint32_t area = 0; /* 0068 */ le_uint32_t area = 0;
@@ -4891,7 +4936,7 @@ struct G_SyncPlayerDispAndInventory_DC112000_6x70 {
/* 0030 */ le_uint16_t bonus_hp_from_materials = 0; /* 0030 */ le_uint16_t bonus_hp_from_materials = 0;
/* 0032 */ le_uint16_t bonus_tp_from_materials = 0; /* 0032 */ le_uint16_t bonus_tp_from_materials = 0;
/* 0034 */ parray<uint8_t, 0x10> unknown_a5; /* 0034 */ parray<uint8_t, 0x10> unknown_a5;
/* 0044 */ Telepipe telepipe; /* 0044 */ Telepipe6x70 telepipe;
/* 0060 */ le_uint32_t unknown_a8 = 0; /* 0060 */ le_uint32_t unknown_a8 = 0;
/* 0064 */ parray<uint8_t, 0x10> unknown_a9; /* 0064 */ parray<uint8_t, 0x10> unknown_a9;
/* 0074 */ le_uint32_t area = 0; /* 0074 */ le_uint32_t area = 0;
@@ -4913,7 +4958,7 @@ struct G_SyncPlayerDispAndInventory_BaseV1 {
/* 006C */ le_uint32_t guild_card_number = 0; /* 006C */ le_uint32_t guild_card_number = 0;
/* 0070 */ le_uint32_t unknown_a6 = 0; /* 0070 */ le_uint32_t unknown_a6 = 0;
/* 0074 */ le_uint32_t battle_team_number = 0; /* 0074 */ le_uint32_t battle_team_number = 0;
/* 0078 */ Telepipe telepipe; /* 0078 */ Telepipe6x70 telepipe;
/* 0094 */ le_uint32_t unknown_a8 = 0; /* 0094 */ le_uint32_t unknown_a8 = 0;
/* 0098 */ G_Unknown_6x70_SubA1 unknown_a9; /* 0098 */ G_Unknown_6x70_SubA1 unknown_a9;
/* 00AC */ le_uint32_t area = 0; /* 00AC */ le_uint32_t area = 0;
@@ -4974,11 +5019,11 @@ struct G_SyncPlayerDispAndInventory_BB_6x70 {
/* 04C8 */ /* 04C8 */
} __packed_ws__(G_SyncPlayerDispAndInventory_BB_6x70, 0x4C0); } __packed_ws__(G_SyncPlayerDispAndInventory_BB_6x70, 0x4C0);
// 6x71: Unknown (used while loading into game) // 6x71: Unblock game join (used while loading into game)
struct G_Unknown_6x71 { struct G_UnblockGameJoin_6x71 {
G_UnusedHeader header; G_UnusedHeader header;
} __packed_ws__(G_Unknown_6x71, 4); } __packed_ws__(G_UnblockGameJoin_6x71, 4);
// 6x72: Player done loading into game // 6x72: Player done loading into game
@@ -5034,10 +5079,10 @@ struct G_SetEntitySetFlags_6x76 {
le_uint16_t flags = 0; le_uint16_t flags = 0;
} __packed_ws__(G_SetEntitySetFlags_6x76, 8); } __packed_ws__(G_SetEntitySetFlags_6x76, 8);
// 6x77: Sync quest data // 6x77: Sync quest register
// This is sent by the client when an opcode D9 is executed within a quest. // This is sent by the client when an opcode D9 is executed within a quest.
struct G_SyncQuestData_6x77 { struct G_SyncQuestRegister_6x77 {
G_UnusedHeader header; G_UnusedHeader header;
le_uint16_t register_number = 0; // Must be < 0x100 le_uint16_t register_number = 0; // Must be < 0x100
le_uint16_t unused = 0; le_uint16_t unused = 0;
@@ -5045,7 +5090,7 @@ struct G_SyncQuestData_6x77 {
le_uint32_t as_int; le_uint32_t as_int;
le_float as_float; le_float as_float;
} __packed__ value; } __packed__ value;
} __packed_ws__(G_SyncQuestData_6x77, 0x0C); } __packed_ws__(G_SyncQuestRegister_6x77, 0x0C);
// 6x78: Unknown // 6x78: Unknown
@@ -5109,7 +5154,7 @@ struct G_SetBattleModeData_6x7D {
// 0 = Unknown (params[0] and [1] are used) // 0 = Unknown (params[0] and [1] are used)
// 1 = Does nothing // 1 = Does nothing
// 2 = Unknown (no params are used) // 2 = Unknown (no params are used)
// 3 = Set player meseta score (params[0] = client ID, [1] = score) // 3 = Set player score (params[0] = client ID, [1] = score)
// 4 = Unknown (params[0] = client ID) // 4 = Unknown (params[0] = client ID)
// 5 = Unknown (no params are used) // 5 = Unknown (no params are used)
// 6 = Unknown (all params are used) // 6 = Unknown (all params are used)
@@ -5220,12 +5265,22 @@ struct G_PlayerKilledByMonster_6x89 {
le_uint16_t unused = 0; le_uint16_t unused = 0;
} __packed_ws__(G_PlayerKilledByMonster_6x89, 8); } __packed_ws__(G_PlayerKilledByMonster_6x89, 8);
// 6x8A: Unknown (not valid on Episode 3) // 6x8A: Show Challenge time records window (not valid on Episode 3)
// The leader sends this command to tell other clients to show, hide, or update
// the window that shows Challenge Mode stage competion and time records during
// Challenge quest selection.
struct G_Unknown_6x8A { struct G_ShowChallengeTimeRecordsWindow_6x8A {
G_ClientIDHeader header; G_ClientIDHeader header;
le_uint32_t unknown_a1 = 0; // Must be < 0x11 // Values for which (decimal):
} __packed_ws__(G_Unknown_6x8A, 8); // 0 = hide window
// 1 = show Episode 1 completion state per player
// 2 = show Episode 2 completion state per player
// 3-11 = show times for Episode 1 stage (which - 2)
// 12-16 = show times for Episode 2 stage (which - 11)
// Anything else = command is ignored
le_uint32_t which = 0;
} __packed_ws__(G_ShowChallengeTimeRecordsWindow_6x8A, 8);
// 6x8B: Unknown (not valid on Episode 3) // 6x8B: Unknown (not valid on Episode 3)
// This command has a handler, but it does nothing. // This command has a handler, but it does nothing.
@@ -5345,13 +5400,15 @@ struct G_UpdatePlayerStat_6x9A {
uint8_t amount = 0; uint8_t amount = 0;
} __packed_ws__(G_UpdatePlayerStat_6x9A, 8); } __packed_ws__(G_UpdatePlayerStat_6x9A, 8);
// 6x9B: Unknown (protected on V3/V4) // 6x9B: Level up all techniques (protected on V3/V4)
// Used in battle mode if the rules specify that techniques should level up
// upon character death.
struct G_Unknown_6x9B { struct G_LevelUpAllTechniques_6x9B {
G_UnusedHeader header; G_UnusedHeader header;
uint8_t unknown_a1 = 0; uint8_t num_levels = 0;
parray<uint8_t, 3> unused; parray<uint8_t, 3> unused;
} __packed_ws__(G_Unknown_6x9B, 8); } __packed_ws__(G_LevelUpAllTechniques_6x9B, 8);
// 6x9C: Unknown (supported; game only; not valid on Episode 3) // 6x9C: Unknown (supported; game only; not valid on Episode 3)
@@ -5563,13 +5620,14 @@ struct G_MoveLobbyChair_6xB0 {
// 6xB2: Play sound from player (not valid on pre-V3 or GC Trial Edition) // 6xB2: Play sound from player (not valid on pre-V3 or GC Trial Edition)
// This command is sent when a snapshot is taken on PSO GC, but it can be used // This command is sent when a snapshot is taken on PSO GC, but it can be used
// to play any sound, centered on the player identified by client_id. // to play any sound, centered on the local player. If localize is FFFF, then
// the sound is not centered on the local player and is just played globally.
struct G_PlaySoundFromPlayer_6xB2 { struct G_PlaySoundFromPlayer_6xB2 {
G_UnusedHeader header; G_UnusedHeader header;
uint8_t floor = 0; uint8_t floor = 0;
uint8_t unused = 0; uint8_t unused = 0;
le_uint16_t client_id = 0; le_uint16_t localize = 0;
le_uint32_t sound_id = 0; // 0x00051720 = camera shutter sound le_uint32_t sound_id = 0; // 0x00051720 = camera shutter sound
} __packed_ws__(G_PlaySoundFromPlayer_6xB2, 0x0C); } __packed_ws__(G_PlaySoundFromPlayer_6xB2, 0x0C);
@@ -7191,5 +7249,7 @@ struct G_RejectBattleStartRequest_Ep3_6xB4x53 {
// implement extended functionality. // implement extended functionality.
// 30 (C->S): Extended player info // 30 (C->S): Extended player info
// Requested with the GetExtendedPlayerInfo patch. // Requested with the GetExtendedPlayerInfo patch. Format depends on version:
// Format is PSOGCCharacterFile::Character. // DC v2: PSODCV2CharacterFile
// GC v3: PSOGCCharacterFile::Character
// XB v3: PSOXBCharacterFileCharacter
+345 -40
View File
@@ -16,6 +16,16 @@ JSON to_json(const parray<IntT, Count>& v) {
return ret; return ret;
} }
template <typename IntT, size_t Count>
void from_json_into(const JSON& json, parray<IntT, Count>& ret) {
if (json.size() != Count) {
throw runtime_error("incorrect array length");
}
for (size_t z = 0; z < Count; z++) {
ret[z] = json.at(z).as_int();
}
}
template <typename IntT, size_t Count> template <typename IntT, size_t Count>
JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) { JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) {
auto ret = JSON::list(); auto ret = JSON::list();
@@ -25,6 +35,16 @@ JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) {
return ret; return ret;
} }
template <typename IntT, size_t Count>
void from_json_into(const JSON& json, parray<CommonItemSet::Table::Range<IntT>, Count>& ret) {
if (json.size() != Count) {
throw runtime_error("incorrect array length");
}
for (size_t z = 0; z < Count; z++) {
from_json_into(json.at(z), ret[z]);
}
}
template <typename IntT> template <typename IntT>
JSON to_json(const CommonItemSet::Table::Range<IntT>& v) { JSON to_json(const CommonItemSet::Table::Range<IntT>& v) {
if (v.min == v.max) { if (v.min == v.max) {
@@ -34,6 +54,22 @@ JSON to_json(const CommonItemSet::Table::Range<IntT>& v) {
} }
} }
template <typename IntT>
void from_json_into(const JSON& json, CommonItemSet::Table::Range<IntT>& ret) {
if (json.is_int()) {
IntT v = json.as_int();
ret.min = v;
ret.max = v;
} else {
const auto& l = json.as_list();
if (l.size() != 2) {
throw runtime_error("incorrect range list length");
}
ret.min = l.at(0)->as_int();
ret.max = l.at(1)->as_int();
}
}
template <typename IntT, size_t Count1, size_t Count2> template <typename IntT, size_t Count1, size_t Count2>
JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) { JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) {
auto ret = JSON::list(); auto ret = JSON::list();
@@ -43,6 +79,262 @@ JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) {
return ret; return ret;
} }
template <typename IntT, size_t Count1, size_t Count2>
void from_json_into(const JSON& json, parray<parray<IntT, Count2>, Count1>& ret) {
if (json.size() != Count1) {
throw runtime_error("incorrect array length");
}
for (size_t z = 0; z < Count1; z++) {
from_json_into(json.at(z), ret[z]);
}
}
template <typename IntT, size_t Count1, size_t Count2>
void from_json_into(const JSON& json, parray<parray<CommonItemSet::Table::Range<IntT>, Count2>, Count1>& ret) {
if (json.size() != Count1) {
throw runtime_error("incorrect array length");
}
for (size_t z = 0; z < Count1; z++) {
from_json_into(json.at(z), ret[z]);
}
}
CommonItemSet::Table::Table(const JSON& json, Episode episode)
: episode(episode) {
from_json_into(json.at("BaseWeaponTypeProbTable"), this->base_weapon_type_prob_table);
from_json_into(json.at("SubtypeBaseTable"), this->subtype_base_table);
from_json_into(json.at("SubtypeAreaLengthTable"), this->subtype_area_length_table);
from_json_into(json.at("GrindProbTable"), this->grind_prob_table);
from_json_into(json.at("ArmorShieldTypeIndexProbTable"), this->armor_shield_type_index_prob_table);
from_json_into(json.at("ArmorSlotCountProbTable"), this->armor_slot_count_prob_table);
from_json_into(json.at("BoxMesetaRanges"), this->box_meseta_ranges);
this->has_rare_bonus_value_prob_table = json.at("HasRareBonusValueProbTable").as_bool();
from_json_into(json.at("BonusValueProbTable"), this->bonus_value_prob_table);
from_json_into(json.at("NonRareBonusProbSpec"), this->nonrare_bonus_prob_spec);
from_json_into(json.at("BonusTypeProbTable"), this->bonus_type_prob_table);
from_json_into(json.at("SpecialMult"), this->special_mult);
from_json_into(json.at("SpecialPercent"), this->special_percent);
from_json_into(json.at("ToolClassProbTable"), this->tool_class_prob_table);
from_json_into(json.at("TechniqueIndexProbTable"), this->technique_index_prob_table);
from_json_into(json.at("TechniqueLevelRanges"), this->technique_level_ranges);
this->armor_or_shield_type_bias = json.at("ArmorOrShieldTypeBias").as_int();
from_json_into(json.at("UnitMaxStarsTable"), this->unit_max_stars_table);
from_json_into(json.at("BoxItemClassProbTable"), this->box_item_class_prob_table);
const auto& enemy_meseta_ranges_json = json.at("EnemyMesetaRanges").as_dict();
const auto& enemy_type_drop_probs_json = json.at("EnemyTypeDropProbs").as_dict();
const auto& enemy_item_classes_json = json.at("EnemyItemClasses").as_dict();
for (size_t z = 0; z < 0x64; z++) {
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
for (Episode episode : episodes) {
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));
from_json_into(*enemy_meseta_ranges_json.at(name), this->enemy_meseta_ranges[z]);
this->enemy_type_drop_probs[z] = enemy_type_drop_probs_json.at(name)->as_int();
this->enemy_item_classes[z] = enemy_item_classes_json.at(name)->as_int();
}
}
}
}
static const char* name_for_common_item_class(uint8_t item_class) {
switch (item_class) {
case 0x00:
return "WEAPON ";
case 0x01:
return "ARMOR ";
case 0x02:
return "SHIELD ";
case 0x03:
return "UNIT ";
case 0x04:
return "TOOL ";
case 0x05:
return "MESETA ";
case 0x06:
return "NOTHING";
default:
return "UNKNOWN";
}
}
void CommonItemSet::Table::print(FILE* stream) const {
const auto& meseta_ranges = this->enemy_meseta_ranges;
const auto& drop_probs = this->enemy_type_drop_probs;
const auto& item_classes = this->enemy_item_classes;
fprintf(stream, "Enemy tables:\n");
fprintf(stream, " ## $LOW $HIGH DAR%% ITEM ENEMIES\n");
for (size_t z = 0; z < 0x64; z++) {
string enemies_str;
for (EnemyType enemy_type : enemy_types_for_rare_table_index(this->episode, z)) {
if (!enemies_str.empty()) {
enemies_str += ", ";
}
enemies_str += name_for_enum(enemy_type);
}
if (drop_probs[z]) {
fprintf(stream, " %02zX %5hu %5hu %3hhu%% %02hX:%s %s\n",
z, meseta_ranges[z].min, meseta_ranges[z].max, drop_probs[z], item_classes[z],
name_for_common_item_class(item_classes[z]), enemies_str.c_str());
} else {
fprintf(stream, " %02zX ----- ----- 0%% -- %s\n", z, enemies_str.c_str());
}
}
static const array<const char*, 12> base_weapon_type_names = {
"SABER ",
"SWORD ",
"DAGGER ",
"PARTISAN",
"SLICER ",
"HANDGUN ",
"RIFLE ",
"MECHGUN ",
"SHOT ",
"CANE ",
"ROD ",
"WAND ",
};
fprintf(stream, "Base weapon config:\n");
fprintf(stream, " TYPE PROB [SB AL] FLOORS\n");
for (size_t z = 0; z < 12; z++) {
uint8_t floor_to_class[10];
if (this->subtype_base_table[z] < 0) {
size_t start_floor = std::min<size_t>(-this->subtype_area_length_table[z], 10);
for (size_t x = 0; x < start_floor; x++) {
floor_to_class[x] = 0xFF;
}
for (size_t x = start_floor; x < 10; x++) {
floor_to_class[x] = (x - start_floor) / this->subtype_area_length_table[z];
}
} else {
for (size_t x = 0; x < 10; x++) {
floor_to_class[x] = this->subtype_base_table[z] + (x / this->subtype_area_length_table[z]);
}
}
fprintf(stream, " %02zX:%s %3hhu%% [%02hhX %02hhX] %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX\n",
z, base_weapon_type_names[z], this->base_weapon_type_prob_table[z],
this->subtype_base_table[z], this->subtype_area_length_table[z],
floor_to_class[0], floor_to_class[1], floor_to_class[2], floor_to_class[3], floor_to_class[4],
floor_to_class[5], floor_to_class[6], floor_to_class[7], floor_to_class[8], floor_to_class[9]);
}
fprintf(stream, "Box configuration:\n");
fprintf(stream, " AR $LOW $HIGH WEP%% ARM%% SHD%% UNI%% TL%% MST%% NO%%\n");
for (size_t z = 0; z < 10; z++) {
fprintf(stream, " %02zX %5hu %5hu %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%%\n",
z, this->box_meseta_ranges[z].min, this->box_meseta_ranges[z].max,
this->box_item_class_prob_table[0][z],
this->box_item_class_prob_table[1][z],
this->box_item_class_prob_table[2][z],
this->box_item_class_prob_table[3][z],
this->box_item_class_prob_table[4][z],
this->box_item_class_prob_table[5][z],
this->box_item_class_prob_table[6][z]);
}
fprintf(stream, "Weapon drops:\n");
fprintf(stream, " Grinds:\n");
fprintf(stream, " GD AR0%% AR1%% AR2%% AR3%%\n");
for (size_t z = 0; z < 9; z++) {
fprintf(stream, " +%zu %3hhd%% %3hhd%% %3hhd%% %3hhd%%\n", z,
this->grind_prob_table[z][0], this->grind_prob_table[z][1],
this->grind_prob_table[z][2], this->grind_prob_table[z][3]);
}
fprintf(stream, " Bonus value table:\n");
fprintf(stream, " ID");
for (int8_t v = -10; v <= 100; v += 5) {
fprintf(stream, " %5hhd%%", v);
}
fputc('\n', stream);
for (size_t z = 0; z < (this->has_rare_bonus_value_prob_table ? 6 : 5); z++) {
fprintf(stream, " %02zX", z);
for (size_t x = 0; x < 0x17; x++) {
fprintf(stream, " %5hu#", this->bonus_value_prob_table[x][z]);
}
fputc('\n', stream);
}
fprintf(stream, " Area config tables:\n");
fprintf(stream, " AR BONUS SP NO%% NTV%% AB%% MAC%% DRK%% HIT%% SM SPC%%\n");
for (size_t z = 0; z < 10; z++) {
fprintf(stream, " %02zX %02hhX %02hhX %02hhX %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %02hhX %3hhu%%\n",
z, this->nonrare_bonus_prob_spec[0][z], this->nonrare_bonus_prob_spec[1][z], this->nonrare_bonus_prob_spec[2][z],
this->bonus_type_prob_table[0][z], this->bonus_type_prob_table[1][z], this->bonus_type_prob_table[2][z],
this->bonus_type_prob_table[3][z], this->bonus_type_prob_table[4][z], this->bonus_type_prob_table[5][z],
this->special_mult[z], this->special_percent[z]);
}
fprintf(stream, " Tool class table:\n");
fprintf(stream, " CS A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
for (size_t tool_class = 0; tool_class < this->tool_class_prob_table.size(); tool_class++) {
fprintf(stream, " %02zX", tool_class);
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
fprintf(stream, " %5hu", this->tool_class_prob_table[tool_class][area_norm]);
}
fputc('\n', stream);
}
static const array<const char*, 19> technique_names = {
"FOIE ",
"GIFOIE ",
"RAFOIE ",
"BARTA ",
"GIBARTA ",
"RABARTA ",
"ZONDE ",
"GIZONDE ",
"RAZONDE ",
"GRANTS ",
"DEBAND ",
"JELLEN ",
"ZALURE ",
"SHIFTA ",
"RYUKER ",
"RESTA ",
"ANTI ",
"REVERSER",
"MEGID ",
};
fprintf(stream, " Technique table:\n");
fprintf(stream, " TECH A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
for (size_t tech_num = 0; tech_num < this->technique_index_prob_table.size(); tech_num++) {
fprintf(stream, " %02zX:%s", tech_num, technique_names[tech_num]);
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
uint16_t prob = this->technique_index_prob_table[tech_num][area_norm];
if (prob) {
const auto& level_range = this->technique_level_ranges[tech_num][area_norm];
size_t min_level = level_range.min + 1;
size_t max_level = level_range.max + 1;
fprintf(stream, " %5hu[%2zu-%2zu]", prob, min_level, max_level);
} else {
fprintf(stream, " 0[-----]");
}
}
fputc('\n', stream);
}
fprintf(stream, " Armor/shield type bias: %hhu\n", this->armor_or_shield_type_bias);
fprintf(stream, " Armor/shield type index table:\n");
fprintf(stream, " TY PROB\n");
for (size_t z = 0; z < 5; z++) {
fprintf(stream, " %02zX %3hhu%%\n", z, this->armor_shield_type_index_prob_table[z]);
}
fprintf(stream, " Armor/shield slot count table:\n");
fprintf(stream, " #S PROB\n");
for (size_t z = 0; z < 5; z++) {
fprintf(stream, " %02zX %3hhu%%\n", z, this->armor_slot_count_prob_table[z]);
}
fprintf(stream, " Unit maximum stars table:\n");
fprintf(stream, " AR #*\n");
for (size_t z = 0; z < 10; z++) {
fprintf(stream, " %02zX %3hhu\n", z, this->unit_max_stars_table[z]);
}
}
JSON CommonItemSet::Table::json() const { JSON CommonItemSet::Table::json() const {
JSON enemy_meseta_ranges_json = JSON::dict(); JSON enemy_meseta_ranges_json = JSON::dict();
JSON enemy_type_drop_probs_json = JSON::dict(); JSON enemy_type_drop_probs_json = JSON::dict();
@@ -111,7 +403,28 @@ JSON CommonItemSet::json() const {
return modes_dict; return modes_dict;
} }
CommonItemSet::Table::Table(const StringReader& r, bool is_big_endian, bool is_v3) { void CommonItemSet::print(FILE* stream) const {
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
for (const auto& mode : modes) {
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
for (const auto& episode : episodes) {
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
for (uint8_t section_id = 0; section_id < 10; section_id++) {
try {
auto table = this->get_table(episode, mode, difficulty, section_id);
fprintf(stream, "============ %s %s %s %s\n",
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
table->print(stream);
} catch (const runtime_error&) {
}
}
}
}
}
}
CommonItemSet::Table::Table(const StringReader& r, bool is_big_endian, bool is_v3, Episode episode)
: episode(episode) {
if (is_big_endian) { if (is_big_endian) {
this->parse_itempt_t<true>(r, is_v3); this->parse_itempt_t<true>(r, is_v3);
} else { } else {
@@ -179,41 +492,6 @@ void CommonItemSet::Table::parse_itempt_t(const StringReader& r, bool is_v3) {
this->box_item_class_prob_table = r.pget<parray<parray<uint8_t, 10>, 7>>(offsets.box_item_class_prob_table_offset); this->box_item_class_prob_table = r.pget<parray<parray<uint8_t, 10>, 7>>(offsets.box_item_class_prob_table_offset);
} }
void CommonItemSet::Table::print_enemy_table(FILE* stream) const {
const auto& meseta_ranges = this->enemy_meseta_ranges;
const auto& drop_probs = this->enemy_type_drop_probs;
const auto& item_classes = this->enemy_item_classes;
// const parray<Range<uint16_t>, 0x64>& enemy_meseta_ranges() const;
// const parray<uint8_t, 0x64>& enemy_type_drop_probs() const;
// const parray<uint8_t, 0x64>& enemy_item_classes() const;
fprintf(stream, "## $_LOW $_HIGH DAR ITEM\n");
for (size_t z = 0; z < 0x64; z++) {
const char* item_class_name = "__UNKNOWN__";
switch (item_classes[z]) {
case 0x00:
item_class_name = "WEAPON";
break;
case 0x01:
item_class_name = "ARMOR";
break;
case 0x02:
item_class_name = "SHIELD";
break;
case 0x03:
item_class_name = "UNIT";
break;
case 0x04:
item_class_name = "TOOL";
break;
case 0x05:
item_class_name = "MESETA";
break;
}
fprintf(stream, "%02zX %5hu %5hu %3hhu %02hX (%s)\n",
z, meseta_ranges[z].min, meseta_ranges[z].max, drop_probs[z], item_classes[z], item_class_name);
}
}
uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) { uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) {
// Bits: -----EEEMMDDSSSS // Bits: -----EEEMMDDSSSS
return (((static_cast<uint16_t>(episode) << 8) & 0x0700) | return (((static_cast<uint16_t>(episode) << 8) & 0x0700) |
@@ -241,7 +519,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
for (size_t section_id = 0; section_id < 10; section_id++) { for (size_t section_id = 0; section_id < 10; section_id++) {
auto entry = pt_afs.get(difficulty * 10 + section_id); auto entry = pt_afs.get(difficulty * 10 + section_id);
StringReader r(entry.first, entry.second); StringReader r(entry.first, entry.second);
auto table = make_shared<Table>(r, false, false); auto table = make_shared<Table>(r, false, false, Episode::EP1);
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::NORMAL, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::NORMAL, difficulty, section_id), table);
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::BATTLE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::BATTLE, difficulty, section_id), table);
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::SOLO, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::SOLO, difficulty, section_id), table);
@@ -253,7 +531,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
AFSArchive ct_afs(ct_afs_data); AFSArchive ct_afs(ct_afs_data);
for (size_t difficulty = 0; difficulty < 4; difficulty++) { for (size_t difficulty = 0; difficulty < 4; difficulty++) {
auto r = ct_afs.get_reader(difficulty * 10); auto r = ct_afs.get_reader(difficulty * 10);
auto table = make_shared<Table>(r, false, false); auto table = make_shared<Table>(r, false, false, Episode::EP1);
for (size_t section_id = 0; section_id < 10; section_id++) { for (size_t section_id = 0; section_id < 10; section_id++) {
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::CHALLENGE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::CHALLENGE, difficulty, section_id), table);
} }
@@ -305,7 +583,7 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
throw; throw;
} }
} }
auto table = make_shared<Table>(r, is_big_endian, true); auto table = make_shared<Table>(r, is_big_endian, true, episode);
this->tables.emplace(this->key_for_table(episode, GameMode::NORMAL, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::NORMAL, difficulty, section_id), table);
this->tables.emplace(this->key_for_table(episode, GameMode::BATTLE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::BATTLE, difficulty, section_id), table);
this->tables.emplace(this->key_for_table(episode, GameMode::SOLO, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::SOLO, difficulty, section_id), table);
@@ -315,7 +593,7 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
if (episode != Episode::EP4) { if (episode != Episode::EP4) {
for (size_t difficulty = 0; difficulty < 4; difficulty++) { for (size_t difficulty = 0; difficulty < 4; difficulty++) {
auto r = gsl.get_reader(filename_for_table(episode, difficulty, 0, true)); auto r = gsl.get_reader(filename_for_table(episode, difficulty, 0, true));
auto table = make_shared<Table>(r, is_big_endian, true); auto table = make_shared<Table>(r, is_big_endian, true, episode);
for (size_t section_id = 0; section_id < 10; section_id++) { for (size_t section_id = 0; section_id < 10; section_id++) {
this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table);
} }
@@ -324,6 +602,33 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
} }
} }
JSONCommonItemSet::JSONCommonItemSet(const JSON& json) {
for (const auto& mode_it : json.as_dict()) {
static const unordered_map<string, GameMode> mode_keys(
{{"Normal", GameMode::NORMAL}, {"Battle", GameMode::BATTLE}, {"Challenge", GameMode::CHALLENGE}, {"Solo", GameMode::SOLO}});
GameMode mode = mode_keys.at(mode_it.first);
for (const auto& episode_it : mode_it.second->as_dict()) {
static const unordered_map<string, Episode> episode_keys(
{{"Episode1", Episode::EP1}, {"Episode2", Episode::EP2}, {"Episode4", Episode::EP4}});
Episode episode = episode_keys.at(episode_it.first);
for (const auto& difficulty_it : episode_it.second->as_dict()) {
static const unordered_map<string, uint8_t> difficulty_keys(
{{"Normal", 0}, {"Hard", 1}, {"VeryHard", 2}, {"Ultimate", 3}});
uint8_t difficulty = difficulty_keys.at(difficulty_it.first);
for (const auto& section_id_it : difficulty_it.second->as_dict()) {
uint8_t section_id = section_id_for_name(section_id_it.first);
this->tables.emplace(
this->key_for_table(episode, mode, difficulty, section_id),
make_shared<Table>(*section_id_it.second, episode));
}
}
}
}
}
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data) RELFileSet::RELFileSet(std::shared_ptr<const std::string> data)
: data(data), : data(data),
r(*this->data) {} r(*this->data) {}
+10 -2
View File
@@ -14,7 +14,8 @@ public:
class Table { class Table {
public: public:
Table() = delete; Table() = delete;
Table(const StringReader& r, bool big_endian, bool is_v3); Table(const JSON& json, Episode episode);
Table(const StringReader& r, bool big_endian, bool is_v3, Episode episode);
template <typename IntT> template <typename IntT>
struct Range { struct Range {
@@ -22,6 +23,7 @@ public:
IntT max; IntT max;
} __packed__; } __packed__;
Episode episode;
parray<uint8_t, 0x0C> base_weapon_type_prob_table; parray<uint8_t, 0x0C> base_weapon_type_prob_table;
parray<int8_t, 0x0C> subtype_base_table; parray<int8_t, 0x0C> subtype_base_table;
parray<uint8_t, 0x0C> subtype_area_length_table; parray<uint8_t, 0x0C> subtype_area_length_table;
@@ -45,8 +47,8 @@ public:
parray<uint8_t, 0x0A> unit_max_stars_table; parray<uint8_t, 0x0A> unit_max_stars_table;
parray<parray<uint8_t, 10>, 7> box_item_class_prob_table; parray<parray<uint8_t, 10>, 7> box_item_class_prob_table;
void print_enemy_table(FILE* stream) const;
JSON json() const; JSON json() const;
void print(FILE* stream) const;
private: private:
template <bool IsBigEndian> template <bool IsBigEndian>
@@ -263,6 +265,7 @@ public:
std::shared_ptr<const Table> get_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const; std::shared_ptr<const Table> get_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const;
JSON json() const; JSON json() const;
void print(FILE* stream) const;
protected: protected:
CommonItemSet() = default; CommonItemSet() = default;
@@ -282,6 +285,11 @@ public:
GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gsl_data, bool is_big_endian); GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gsl_data, bool is_big_endian);
}; };
class JSONCommonItemSet : public CommonItemSet {
public:
explicit JSONCommonItemSet(const JSON& json);
};
// Note: There are clearly better ways of doing this, but this implementation // Note: There are clearly better ways of doing this, but this implementation
// closely follows what the original code in the client does. // closely follows what the original code in the client does.
template <typename ItemT, size_t MaxCount> template <typename ItemT, size_t MaxCount>
+23 -8
View File
@@ -12,7 +12,7 @@ namespace Episode3 {
void BattleRecord::PlayerEntry::print(FILE* stream) const { void BattleRecord::PlayerEntry::print(FILE* stream) const {
// TODO: Format this nicely somehow. Maybe factor out the functions in // TODO: Format this nicely somehow. Maybe factor out the functions in
// QuestScript that format some of these structures // QuestScript that format some of these structures
print_data(stream, this, sizeof(this)); print_data(stream, this, sizeof(*this), 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
} }
BattleRecord::Event::Event(StringReader& r) { BattleRecord::Event::Event(StringReader& r) {
@@ -96,29 +96,30 @@ void BattleRecord::Event::print(FILE* stream) const {
for (const auto& player : this->players) { for (const auto& player : this->players) {
fprintf(stream, " %02" PRIX32, player.lobby_data.client_id.load()); fprintf(stream, " %02" PRIX32, player.lobby_data.client_id.load());
} }
fputc('\n', stream);
for (const auto& player : this->players) { for (const auto& player : this->players) {
player.print(stream); player.print(stream);
} }
break; break;
case Type::BATTLE_COMMAND: case Type::BATTLE_COMMAND:
fprintf(stream, "BATTLE_COMMAND\n"); fprintf(stream, "BATTLE_COMMAND\n");
print_data(stream, this->data); print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
break; break;
case Type::GAME_COMMAND: case Type::GAME_COMMAND:
fprintf(stream, "GAME_COMMAND\n"); fprintf(stream, "GAME_COMMAND\n");
print_data(stream, this->data); print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
break; break;
case Type::EP3_GAME_COMMAND: case Type::EP3_GAME_COMMAND:
fprintf(stream, "EP3_GAME_COMMAND\n"); fprintf(stream, "EP3_GAME_COMMAND\n");
print_data(stream, this->data); print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
break; break;
case Type::CHAT_MESSAGE: case Type::CHAT_MESSAGE:
fprintf(stream, "CHAT_MESSAGE %08" PRIX32 "\n", this->guild_card_number); fprintf(stream, "CHAT_MESSAGE %08" PRIX32 "\n", this->guild_card_number);
print_data(stream, this->data); print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
break; break;
case Type::SERVER_DATA_COMMAND: case Type::SERVER_DATA_COMMAND:
fprintf(stream, "SERVER_DATA_COMMAND\n"); fprintf(stream, "SERVER_DATA_COMMAND\n");
print_data(stream, this->data); print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
break; break;
default: default:
throw runtime_error("unknown event type in battle record"); throw runtime_error("unknown event type in battle record");
@@ -255,6 +256,20 @@ void BattleRecord::add_random_data(const void* data, size_t size) {
this->random_stream.append(reinterpret_cast<const char*>(data), size); this->random_stream.append(reinterpret_cast<const char*>(data), size);
} }
vector<string> BattleRecord::get_all_server_data_commands() const {
vector<string> ret;
for (const auto& event : this->events) {
if (event.type == Event::Type::SERVER_DATA_COMMAND) {
ret.emplace_back(event.data);
}
}
return ret;
}
const string& BattleRecord::get_random_stream() const {
return this->random_stream;
}
bool BattleRecord::is_map_definition_event(const Event& ev) { bool BattleRecord::is_map_definition_event(const Event& ev) {
if (ev.type == Event::Type::BATTLE_COMMAND) { if (ev.type == Event::Type::BATTLE_COMMAND) {
auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF); auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF);
@@ -331,7 +346,7 @@ void BattleRecord::set_battle_start_timestamp() {
} }
} }
for (; it != this->events.end(); it++) { for (; it != this->events.end(); it++) {
if (it->type == Event::Type::BATTLE_COMMAND) { if ((it->type == Event::Type::BATTLE_COMMAND) || (it->type == Event::Type::SERVER_DATA_COMMAND)) {
new_events.emplace_back(std::move(*it)); new_events.emplace_back(std::move(*it));
} }
} }
@@ -373,7 +388,7 @@ shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
return this->record; return this->record;
} }
void BattleRecordPlayer::set_lobby(std::shared_ptr<Lobby> l) { void BattleRecordPlayer::set_lobby(shared_ptr<Lobby> l) {
this->lobby = l; this->lobby = l;
} }
+3
View File
@@ -86,6 +86,9 @@ public:
void print(FILE* stream) const; void print(FILE* stream) const;
std::vector<std::string> get_all_server_data_commands() const;
const std::string& get_random_stream() const;
private: private:
static constexpr uint64_t SIGNATURE_V1 = 0x14C946D56D1DAC50; static constexpr uint64_t SIGNATURE_V1 = 0x14C946D56D1DAC50;
static constexpr uint64_t SIGNATURE_V2 = 0xD01E5EC12853C377; static constexpr uint64_t SIGNATURE_V2 = 0xD01E5EC12853C377;
+20 -22
View File
@@ -396,8 +396,8 @@ int16_t Card::compute_defense_power_for_attacker_card(shared_ptr<const Card> att
} }
} }
s->card_special->apply_action_conditions(3, attacker_card, this->shared_from_this(), 0x08, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x08, nullptr);
s->card_special->apply_action_conditions(3, attacker_card, this->shared_from_this(), 0x10, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x10, nullptr);
return this->action_metadata.defense_power + this->action_metadata.defense_bonus; return this->action_metadata.defense_power + this->action_metadata.defense_bonus;
} }
@@ -982,7 +982,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
if (apply_action_conditions) { if (apply_action_conditions) {
auto this_sh = this->shared_from_this(); auto this_sh = this->shared_from_this();
s->card_special->apply_action_conditions(3, this_sh, this_sh, 1, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 1, nullptr);
log.debug("applied action conditions (1)"); log.debug("applied action conditions (1)");
} else { } else {
log.debug("skipped applying action conditions (1)"); log.debug("skipped applying action conditions (1)");
@@ -1120,7 +1120,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
if (apply_action_conditions) { if (apply_action_conditions) {
auto this_sh = this->shared_from_this(); auto this_sh = this->shared_from_this();
s->card_special->apply_action_conditions(0x03, this_sh, this_sh, 2, nullptr); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 2, nullptr);
log.debug("applied action conditions (2)"); log.debug("applied action conditions (2)");
if (!is_nte && this->action_chain.check_flag(0x100)) { if (!is_nte && this->action_chain.check_flag(0x100)) {
this->action_chain.chain.damage = min<int16_t>(this->action_chain.chain.damage + 5, 99); this->action_chain.chain.damage = min<int16_t>(this->action_chain.chain.damage + 5, 99);
@@ -1171,7 +1171,7 @@ void Card::unknown_80237F98(bool require_condition_20_or_21) {
for (ssize_t z = 8; z >= 0; z--) { for (ssize_t z = 8; z >= 0; z--) {
if (this->action_chain.conditions[z].type != ConditionType::NONE) { if (this->action_chain.conditions[z].type != ConditionType::NONE) {
if (!require_condition_20_or_21 || if (!require_condition_20_or_21 ||
s->card_special->condition_has_when_20_or_21(this->action_chain.conditions[z])) { s->card_special->condition_applies_on_sc_or_item_attack(this->action_chain.conditions[z])) {
ActionState as; ActionState as;
auto& cond = this->action_chain.conditions[z]; auto& cond = this->action_chain.conditions[z];
if (!s->card_special->is_card_targeted_by_condition(cond, as, this->shared_from_this())) { if (!s->card_special->is_card_targeted_by_condition(cond, as, this->shared_from_this())) {
@@ -1219,7 +1219,9 @@ void Card::move_phase_before() {
} }
void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as) { void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as) {
auto log = this->server()->log_stack(string_printf("unknown_80236374(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id())); auto s = this->server();
auto log = s->log_stack(string_printf("unknown_80236374(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id()));
auto check_card = [&](shared_ptr<Card> card) -> void { auto check_card = [&](shared_ptr<Card> card) -> void {
if (card) { if (card) {
if (!card->unknown_80236554(other_card, as)) { if (!card->unknown_80236554(other_card, as)) {
@@ -1231,21 +1233,18 @@ void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as)
}; };
for (size_t client_id = 0; client_id < 4; client_id++) { for (size_t client_id = 0; client_id < 4; client_id++) {
auto ps = this->server()->player_states[client_id]; auto ps = s->player_states[client_id];
if (ps) { if (ps && (s->get_current_team_turn2() != ps->get_team_id())) {
if (this->server()->get_current_team_turn2() != ps->get_team_id()) {
check_card(ps->get_sc_card()); check_card(ps->get_sc_card());
for (size_t set_index = 0; set_index < 8; set_index++) { for (size_t set_index = 0; set_index < 8; set_index++) {
check_card(ps->get_set_card(set_index)); check_card(ps->get_set_card(set_index));
} }
} }
} }
}
for (size_t client_id = 0; client_id < 4; client_id++) { for (size_t client_id = 0; client_id < 4; client_id++) {
auto ps = this->server()->player_states[client_id]; auto ps = s->player_states[client_id];
if (ps) { if (ps && (s->get_current_team_turn2() == ps->get_team_id())) {
if (this->server()->get_current_team_turn2() == ps->get_team_id()) {
check_card(ps->get_sc_card()); check_card(ps->get_sc_card());
for (size_t set_index = 0; set_index < 8; set_index++) { for (size_t set_index = 0; set_index < 8; set_index++) {
check_card(ps->get_set_card(set_index)); check_card(ps->get_set_card(set_index));
@@ -1253,7 +1252,6 @@ void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as)
} }
} }
} }
}
void Card::unknown_802379BC(uint16_t card_ref) { void Card::unknown_802379BC(uint16_t card_ref) {
this->action_chain.chain.unknown_card_ref_a3 = this->action_chain.chain.unknown_card_ref_a3 =
@@ -1404,8 +1402,8 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
log.debug("last attack damage stats cleared"); log.debug("last attack damage stats cleared");
if (other_card) { if (other_card) {
s->card_special->apply_action_conditions(0x03, other_card, this->shared_from_this(), 0x20, as); s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, other_card, this->shared_from_this(), 0x20, as);
s->card_special->apply_action_conditions(0x17, other_card, this->shared_from_this(), 0x40, as); s->card_special->apply_action_conditions(EffectWhen::BEFORE_THIS_CARD_ATTACKED, other_card, this->shared_from_this(), 0x40, as);
if (other_card->action_chain.check_flag(0x20000)) { if (other_card->action_chain.check_flag(0x20000)) {
this->action_metadata.attack_bonus = 0; this->action_metadata.attack_bonus = 0;
return ret; return ret;
@@ -1520,7 +1518,7 @@ void Card::apply_attack_result() {
this->compute_action_chain_results(true, false); this->compute_action_chain_results(true, false);
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
s->card_special->unknown_8024997C(this->shared_from_this()); s->card_special->apply_effects_before_attack(this->shared_from_this());
} }
this->compute_action_chain_results(true, false); this->compute_action_chain_results(true, false);
@@ -1560,21 +1558,21 @@ void Card::apply_attack_result() {
} }
} }
this->compute_action_chain_results(1, 0); this->compute_action_chain_results(true, false);
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
s->card_special->unknown_8024997C(this->shared_from_this()); s->card_special->apply_effects_before_attack(this->shared_from_this());
} }
if (!(this->card_flags & 2)) { if (!(this->card_flags & 2)) {
this->compute_action_chain_results(1, 0); this->compute_action_chain_results(true, false);
s->card_special->check_for_attack_interference(this->shared_from_this()); s->card_special->check_for_attack_interference(this->shared_from_this());
} }
this->compute_action_chain_results(1, 0); this->compute_action_chain_results(true, false);
this->unknown_80236374(this->shared_from_this(), nullptr); this->unknown_80236374(this->shared_from_this(), nullptr);
this->unknown_802362D8(this->shared_from_this()); this->unknown_802362D8(this->shared_from_this());
} }
if (!this->action_chain.check_flag(0x40)) { if (!this->action_chain.check_flag(0x40)) {
s->card_special->unknown_8024A394(this->shared_from_this()); s->card_special->apply_effects_after_attack(this->shared_from_this());
} }
ps->stats.num_attacks_given++; ps->stats.num_attacks_given++;
+115 -97
View File
@@ -79,7 +79,7 @@ void CardSpecial::AttackEnvStats::clear() {
this->target_attack_bonus = 0; this->target_attack_bonus = 0;
this->last_attack_preliminary_damage = 0; this->last_attack_preliminary_damage = 0;
this->last_attack_damage = 0; this->last_attack_damage = 0;
this->total_last_attack_damage = 0; this->final_last_attack_damage = 0;
this->last_attack_damage_count = 0; this->last_attack_damage_count = 0;
this->target_current_hp = 0; this->target_current_hp = 0;
} }
@@ -107,7 +107,7 @@ void CardSpecial::AttackEnvStats::print(FILE* stream) const {
fprintf(stream, "(ef) non_target_team_num_set_cards = %" PRIu32 "\n", this->non_target_team_num_set_cards); fprintf(stream, "(ef) non_target_team_num_set_cards = %" PRIu32 "\n", this->non_target_team_num_set_cards);
fprintf(stream, "(ehp) target_current_hp = %" PRIu32 "\n", this->target_current_hp); fprintf(stream, "(ehp) target_current_hp = %" PRIu32 "\n", this->target_current_hp);
fprintf(stream, "(f) num_set_cards = %" PRIu32 "\n", this->num_set_cards); fprintf(stream, "(f) num_set_cards = %" PRIu32 "\n", this->num_set_cards);
fprintf(stream, "(fdm) total_last_attack_damage = %" PRIu32 "\n", this->total_last_attack_damage); fprintf(stream, "(fdm) final_last_attack_damage = %" PRIu32 "\n", this->final_last_attack_damage);
fprintf(stream, "(ff) target_team_num_set_cards = %" PRIu32 "\n", this->target_team_num_set_cards); fprintf(stream, "(ff) target_team_num_set_cards = %" PRIu32 "\n", this->target_team_num_set_cards);
fprintf(stream, "(gn) num_gun_type_items = %" PRIu32 "\n", this->num_gun_type_items); fprintf(stream, "(gn) num_gun_type_items = %" PRIu32 "\n", this->num_gun_type_items);
fprintf(stream, "(hf) num_item_or_creature_cards_in_hand = %" PRIu32 "\n", this->num_item_or_creature_cards_in_hand); fprintf(stream, "(hf) num_item_or_creature_cards_in_hand = %" PRIu32 "\n", this->num_item_or_creature_cards_in_hand);
@@ -239,7 +239,7 @@ void CardSpecial::adjust_dice_boost_if_team_has_condition_52(
} }
void CardSpecial::apply_action_conditions( void CardSpecial::apply_action_conditions(
uint8_t when, EffectWhen when,
shared_ptr<const Card> attacker_card, shared_ptr<const Card> attacker_card,
shared_ptr<Card> defender_card, shared_ptr<Card> defender_card,
uint32_t flags, uint32_t flags,
@@ -252,8 +252,7 @@ void CardSpecial::apply_action_conditions(
temp_as = *as; temp_as = *as;
} }
} else { } else {
temp_as = this->create_defense_state_for_card_pair_action_chains( temp_as = this->create_defense_state_for_card_pair_action_chains(attacker_card, defender_card);
attacker_card, defender_card);
} }
this->apply_defense_conditions(temp_as, when, defender_card, flags); this->apply_defense_conditions(temp_as, when, defender_card, flags);
@@ -291,7 +290,7 @@ bool CardSpecial::apply_attribute_guard_if_possible(
} }
bool CardSpecial::apply_defense_condition( bool CardSpecial::apply_defense_condition(
uint8_t when, EffectWhen when,
Condition* defender_cond, Condition* defender_cond,
uint8_t cond_index, uint8_t cond_index,
const ActionState& defense_state, const ActionState& defense_state,
@@ -328,7 +327,7 @@ bool CardSpecial::apply_defense_condition(
return false; return false;
} }
if ((when == 0x02) && (defender_cond->type == ConditionType::GUOM) && (flags & 4)) { if ((when == EffectWhen::AFTER_ANY_CARD_ATTACK) && (defender_cond->type == ConditionType::GUOM) && (flags & 4)) {
CardShortStatus stat = defender_card->get_short_status(); CardShortStatus stat = defender_card->get_short_status();
if (stat.card_flags & 4) { if (stat.card_flags & 4) {
G_ApplyConditionEffect_Ep3_6xB4x06 cmd; G_ApplyConditionEffect_Ep3_6xB4x06 cmd;
@@ -347,7 +346,7 @@ bool CardSpecial::apply_defense_condition(
if (s->options.is_nte()) { if (s->options.is_nte()) {
auto defender_ps = defender_card->player_state(); auto defender_ps = defender_card->player_state();
if ((when == 0x0F) && (flags & 4) && (defender_cond->type == ConditionType::DROP) && defender_ps) { if ((when == EffectWhen::BEFORE_DRAW_PHASE) && (flags & 4) && (defender_cond->type == ConditionType::DROP) && defender_ps) {
auto defender_sc_card = defender_ps->get_sc_card(); auto defender_sc_card = defender_ps->get_sc_card();
uint8_t defender_team_id = defender_ps->get_team_id(); uint8_t defender_team_id = defender_ps->get_team_id();
if (defender_sc_card && s->team_exp[defender_team_id]) { if (defender_sc_card && s->team_exp[defender_team_id]) {
@@ -364,7 +363,7 @@ bool CardSpecial::apply_defense_condition(
} }
} }
if ((when == 0x04) && (flags & 4) && !defender_has_ability_trap && (defender_cond->type == ConditionType::ACID)) { if ((when == EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN) && (flags & 4) && !defender_has_ability_trap && (defender_cond->type == ConditionType::ACID)) {
int16_t hp = defender_card->get_current_hp(); int16_t hp = defender_card->get_current_hp();
if (hp > 0) { if (hp > 0) {
this->send_6xB4x06_for_stat_delta(defender_card, defender_cond->card_ref, 0x20, -1, 0, 1); this->send_6xB4x06_for_stat_delta(defender_card, defender_cond->card_ref, 0x20, -1, 0, 1);
@@ -418,12 +417,11 @@ bool CardSpecial::apply_defense_condition(
bool CardSpecial::apply_defense_conditions( bool CardSpecial::apply_defense_conditions(
const ActionState& as, const ActionState& as,
uint8_t when, EffectWhen when,
shared_ptr<Card> defender_card, shared_ptr<Card> defender_card,
uint32_t flags) { uint32_t flags) {
for (size_t z = 0; z < 9; z++) { for (size_t z = 0; z < 9; z++) {
this->apply_defense_condition( this->apply_defense_condition(when, &defender_card->action_chain.conditions[z], z, as, defender_card, flags, 0);
when, &defender_card->action_chain.conditions[z], z, as, defender_card, flags, 0);
} }
return true; return true;
} }
@@ -812,7 +810,7 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
int32_t total_last_attack_damage = 0; int32_t total_last_attack_damage = 0;
size_t last_attack_damage_count = 0; size_t last_attack_damage_count = 0;
this->sum_last_attack_damage(nullptr, &total_last_attack_damage, &last_attack_damage_count); this->sum_last_attack_damage(nullptr, &total_last_attack_damage, &last_attack_damage_count);
ast.total_last_attack_damage = total_last_attack_damage; ast.final_last_attack_damage = total_last_attack_damage;
ast.last_attack_damage_count = last_attack_damage_count; ast.last_attack_damage_count = last_attack_damage_count;
if (!target_card) { if (!target_card) {
@@ -1238,13 +1236,14 @@ void CardSpecial::compute_team_dice_bonus(uint8_t team_id) {
s->team_dice_bonus[team_id] = min<uint8_t>(value, 8); s->team_dice_bonus[team_id] = min<uint8_t>(value, 8);
} }
bool CardSpecial::condition_has_when_20_or_21(const Condition& cond) const { bool CardSpecial::condition_applies_on_sc_or_item_attack(const Condition& cond) const {
auto ce = this->server()->definition_for_card_ref(cond.card_ref); auto ce = this->server()->definition_for_card_ref(cond.card_ref);
if (!ce) { if (!ce) {
return false; return false;
} }
uint8_t when = ce->def.effects[cond.card_definition_effect_index].when; EffectWhen when = ce->def.effects[cond.card_definition_effect_index].when;
return ((when == 0x20) || (when == 0x21)); return ((when == EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK) ||
(when == EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK));
} }
size_t CardSpecial::count_action_cards_with_condition_for_all_current_attacks( size_t CardSpecial::count_action_cards_with_condition_for_all_current_attacks(
@@ -1410,7 +1409,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
uint16_t set_card_ref, uint16_t set_card_ref,
uint16_t sc_card_ref, uint16_t sc_card_ref,
uint8_t random_percent, uint8_t random_percent,
uint8_t when) const { EffectWhen when) const {
// Note: In the original code, as and dice_roll were optional pointers, but // Note: In the original code, as and dice_roll were optional pointers, but
// they are non-null at all callsites, so we've replaced them with references // they are non-null at all callsites, so we've replaced them with references
// (and eliminated the null checks within this function). // (and eliminated the null checks within this function).
@@ -1650,7 +1649,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
// or comment it appropriately. // or comment it appropriately.
if (is_nte) { if (is_nte) {
return (v < set_card->unknown_a9); return (v < set_card->unknown_a9);
} else if (when == 4) { } else if (when == EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN) {
uint32_t y = set_card->unknown_a9 & 0xFFFFFFFE; uint32_t y = set_card->unknown_a9 & 0xFFFFFFFE;
if ((set_card->unknown_a9 > 0) && if ((set_card->unknown_a9 > 0) &&
(y == (y / (v & 0xFFFFFFFE)) * (v & 0xFFFFFFFE))) { (y == (y / (v & 0xFFFFFFFE)) * (v & 0xFFFFFFFE))) {
@@ -3519,7 +3518,7 @@ void CardSpecial::on_card_set(shared_ptr<PlayerState> ps, uint16_t card_ref) {
uint16_t sc_card_ref = sc_card ? sc_card->get_card_ref() : 0xFFFF; uint16_t sc_card_ref = sc_card ? sc_card->get_card_ref() : 0xFFFF;
ActionState as; ActionState as;
this->evaluate_and_apply_effects(0x01, card_ref, as, sc_card_ref); this->evaluate_and_apply_effects(EffectWhen::CARD_SET, card_ref, as, sc_card_ref);
} }
const CardDefinition::Effect* CardSpecial::original_definition_for_condition(const Condition& cond) const { const CardDefinition::Effect* CardSpecial::original_definition_for_condition(const Condition& cond) const {
@@ -3827,7 +3826,7 @@ int16_t CardSpecial::max_all_attack_bonuses(size_t* out_count) const {
return max_attack_bonus; return max_attack_bonus;
} }
void CardSpecial::unknown_80244AA8(shared_ptr<Card> card) { void CardSpecial::apply_effects_after_card_move(shared_ptr<Card> card) {
ActionState as = this->create_attack_state_from_card_action_chain(card); ActionState as = this->create_attack_state_from_card_action_chain(card);
bool is_nte = this->server()->options.is_nte(); bool is_nte = this->server()->options.is_nte();
@@ -3847,12 +3846,12 @@ void CardSpecial::unknown_80244AA8(shared_ptr<Card> card) {
} }
} }
} }
this->apply_defense_conditions(as, 0x27, card, 0x04); this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card, 0x04);
this->evaluate_and_apply_effects(0x27, card->get_card_ref(), as, 0xFFFF); this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card->get_card_ref(), as, 0xFFFF);
} }
this->apply_defense_conditions(as, 0x13, card, is_nte ? 0x1F : 0x04); this->apply_defense_conditions(as, EffectWhen::AFTER_CARD_MOVE, card, is_nte ? 0x1F : 0x04);
this->evaluate_and_apply_effects(0x13, card->get_card_ref(), as, 0xFFFF); this->evaluate_and_apply_effects(EffectWhen::AFTER_CARD_MOVE, card->get_card_ref(), as, 0xFFFF);
} }
void CardSpecial::check_for_defense_interference( void CardSpecial::check_for_defense_interference(
@@ -3938,20 +3937,20 @@ void CardSpecial::check_for_defense_interference(
} }
void CardSpecial::evaluate_and_apply_effects( void CardSpecial::evaluate_and_apply_effects(
uint8_t when, EffectWhen when,
uint16_t set_card_ref, uint16_t set_card_ref,
const ActionState& as, const ActionState& as,
uint16_t sc_card_ref, uint16_t sc_card_ref,
bool apply_defense_condition_to_all_cards, bool apply_defense_condition_to_all_cards,
uint16_t apply_defense_condition_to_card_ref) { uint16_t apply_defense_condition_to_card_ref) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(string_printf("evaluate_and_apply_effects(%02hhX, @%04hX, @%04hX): ", when, set_card_ref, sc_card_ref)); auto log = s->log_stack(string_printf("evaluate_and_apply_effects(%s, @%04hX, @%04hX): ", name_for_enum(when), set_card_ref, sc_card_ref));
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
{ {
string as_str = as.str(s); string as_str = as.str(s);
log.debug("when=%02hhX, set_card_ref=@%04hX, as=%s, sc_card_ref=@%04hX, apply_defense_condition_to_all_cards=%s, apply_defense_condition_to_card_ref=@%04hX", log.debug("when=%s, set_card_ref=@%04hX, as=%s, sc_card_ref=@%04hX, apply_defense_condition_to_all_cards=%s, apply_defense_condition_to_card_ref=@%04hX",
when, set_card_ref, as_str.c_str(), sc_card_ref, apply_defense_condition_to_all_cards ? "true" : "false", apply_defense_condition_to_card_ref); name_for_enum(when), set_card_ref, as_str.c_str(), sc_card_ref, apply_defense_condition_to_all_cards ? "true" : "false", apply_defense_condition_to_card_ref);
} }
if (!is_nte) { if (!is_nte) {
@@ -4016,7 +4015,7 @@ void CardSpecial::evaluate_and_apply_effects(
string card_effect_str = card_effect.str(); string card_effect_str = card_effect.str();
effect_log.debug("effect: %s", card_effect_str.c_str()); effect_log.debug("effect: %s", card_effect_str.c_str());
if (card_effect.when != when) { if (card_effect.when != when) {
effect_log.debug("does not apply (effect.when=%02hhX, when=%02" PRIX32 ")", card_effect.when, when); effect_log.debug("does not apply (effect.when=%s, when=%s)", name_for_enum(card_effect.when), name_for_enum(when));
continue; continue;
} }
@@ -4428,10 +4427,10 @@ void CardSpecial::on_card_destroyed(
attacker_card, destroyed_card); attacker_card, destroyed_card);
uint16_t destroyed_card_ref = destroyed_card->get_card_ref(); uint16_t destroyed_card_ref = destroyed_card->get_card_ref();
this->evaluate_and_apply_effects(0x05, destroyed_card_ref, defense_as, 0xFFFF); this->evaluate_and_apply_effects(EffectWhen::CARD_DESTROYED, destroyed_card_ref, defense_as, 0xFFFF);
for (size_t z = 0; (z < 8) && (defense_as.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (defense_as.action_card_refs[z] != 0xFFFF); z++) {
this->evaluate_and_apply_effects( this->evaluate_and_apply_effects(
0x05, defense_as.action_card_refs[z], defense_as, destroyed_card->get_card_ref()); EffectWhen::CARD_DESTROYED, defense_as.action_card_refs[z], defense_as, destroyed_card->get_card_ref());
} }
if (attacker_card) { if (attacker_card) {
@@ -4673,9 +4672,9 @@ vector<shared_ptr<const Card>> CardSpecial::filter_cards_by_range(
return ret; return ret;
} }
void CardSpecial::unknown_8024AAB8(const ActionState& as) { void CardSpecial::apply_effects_after_attack_target_resolution(const ActionState& as) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack("unknown_8024AAB8: "); auto log = s->log_stack("apply_effects_after_attack_target_resolution: ");
string as_str = as.str(s); string as_str = as.str(s);
log.debug("as=%s", as_str.c_str()); log.debug("as=%s", as_str.c_str());
@@ -4687,31 +4686,37 @@ void CardSpecial::unknown_8024AAB8(const ActionState& as) {
if (this->send_6xB4x06_if_card_ref_invalid(as.original_attacker_card_ref, 0x1F) == 0xFFFF) { if (this->send_6xB4x06_if_card_ref_invalid(as.original_attacker_card_ref, 0x1F) == 0xFFFF) {
this->evaluate_and_apply_effects( this->evaluate_and_apply_effects(
0x01, as.action_card_refs[z], as, this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x21)); EffectWhen::CARD_SET,
as.action_card_refs[z],
as,
this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x21));
this->evaluate_and_apply_effects( this->evaluate_and_apply_effects(
0x0B, as.action_card_refs[z], as, this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x22)); EffectWhen::AFTER_ATTACK_TARGET_RESOLUTION,
as.action_card_refs[z],
as,
this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x22));
} else { } else {
uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.target_card_refs[0], 0x20); uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.target_card_refs[0], 0x20);
if (card_ref != 0xFFFF) { if (card_ref != 0xFFFF) {
this->evaluate_and_apply_effects(0x01, as.action_card_refs[z], as, card_ref); this->evaluate_and_apply_effects(EffectWhen::CARD_SET, as.action_card_refs[z], as, card_ref);
this->evaluate_and_apply_effects(0x15, as.action_card_refs[z], as, card_ref); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_15, as.action_card_refs[z], as, card_ref);
} }
} }
} }
if (as.original_attacker_card_ref == 0xffff) { if (as.original_attacker_card_ref == 0xFFFF) {
uint16_t card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x23); uint16_t card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x23);
uint16_t card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x25); uint16_t card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x25);
this->evaluate_and_apply_effects(0x33, card_ref2, as, card_ref1); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_33, card_ref2, as, card_ref1);
card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x24); card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x24);
card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x26); card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x26);
this->evaluate_and_apply_effects(0x34, card_ref2, as, card_ref1); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_34, card_ref2, as, card_ref1);
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.action_card_refs[z], 0x27); uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.action_card_refs[z], 0x27);
if (card_ref == 0xFFFF) { if (card_ref == 0xFFFF) {
break; break;
} }
this->evaluate_and_apply_effects(0x35, as.target_card_refs[z], as, as.attacker_card_ref); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_35, as.target_card_refs[z], as, as.attacker_card_ref);
} }
} }
} }
@@ -4719,11 +4724,11 @@ void CardSpecial::unknown_8024AAB8(const ActionState& as) {
void CardSpecial::move_phase_before_for_card(shared_ptr<Card> card) { void CardSpecial::move_phase_before_for_card(shared_ptr<Card> card) {
bool is_nte = this->server()->options.is_nte(); bool is_nte = this->server()->options.is_nte();
ActionState as = this->create_attack_state_from_card_action_chain(card); ActionState as = this->create_attack_state_from_card_action_chain(card);
this->apply_defense_conditions(as, 0x09, card, is_nte ? 0x1F : 0x04); this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE, card, is_nte ? 0x1F : 0x04);
this->evaluate_and_apply_effects(0x09, card->get_card_ref(), as, 0xFFFF); this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE, card->get_card_ref(), as, 0xFFFF);
if (!is_nte) { if (!is_nte) {
this->apply_defense_conditions(as, 0x27, card, 0x04); this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card, 0x04);
this->evaluate_and_apply_effects(0x27, card->get_card_ref(), as, 0xFFFF); this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card->get_card_ref(), as, 0xFFFF);
} }
} }
@@ -4750,19 +4755,19 @@ void CardSpecial::dice_phase_before_for_card(shared_ptr<Card> card) {
} }
if (!is_nte) { if (!is_nte) {
this->apply_defense_conditions(as, 0x46, card, 0x04); this->apply_defense_conditions(as, EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL, card, 0x04);
this->evaluate_and_apply_effects(0x46, card->get_card_ref(), as, sc_card_ref); this->evaluate_and_apply_effects(EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL, card->get_card_ref(), as, sc_card_ref);
} }
if (ps->is_team_turn()) { if (ps->is_team_turn()) {
this->apply_defense_conditions(as, 0x04, card, 0x04); this->apply_defense_conditions(as, EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN, card, 0x04);
this->evaluate_and_apply_effects(0x04, card->get_card_ref(), as, sc_card_ref); this->evaluate_and_apply_effects(EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN, card->get_card_ref(), as, sc_card_ref);
} }
} }
template <uint8_t When1, uint8_t When2> template <EffectWhen When1, EffectWhen When2>
void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, const ActionState* existing_as) { void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(string_printf("apply_effects_on_phase_change_t<%02hhX, %02hhX>(@%04hX #%04hX): ", When1, When2, unknown_p2->get_card_ref(), unknown_p2->get_card_id())); auto log = s->log_stack(string_printf("apply_effects_on_phase_change_t<%s, %s>(@%04hX #%04hX): ", name_for_enum(When1), name_for_enum(When2), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
bool is_nte = s->options.is_nte(); bool is_nte = s->options.is_nte();
ActionState as; ActionState as;
@@ -4799,17 +4804,17 @@ void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, c
} }
void CardSpecial::draw_phase_before_for_card(shared_ptr<Card> unknown_p2) { void CardSpecial::draw_phase_before_for_card(shared_ptr<Card> unknown_p2) {
this->apply_effects_on_phase_change_t<0x0F, 0x0A>(unknown_p2); this->apply_effects_on_phase_change_t<EffectWhen::BEFORE_DRAW_PHASE, EffectWhen::UNKNOWN_0A>(unknown_p2);
} }
void CardSpecial::action_phase_before_for_card(shared_ptr<Card> unknown_p2) { void CardSpecial::action_phase_before_for_card(shared_ptr<Card> unknown_p2) {
if (unknown_p2->player_state()->is_team_turn()) { if (unknown_p2->player_state()->is_team_turn()) {
this->apply_effects_on_phase_change_t<0x0E, 0x0A>(unknown_p2); this->apply_effects_on_phase_change_t<EffectWhen::BEFORE_ACT_PHASE, EffectWhen::UNKNOWN_0A>(unknown_p2);
} }
} }
void CardSpecial::unknown_8024945C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) { void CardSpecial::unknown_8024945C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
this->apply_effects_on_phase_change_t<0x0A, 0x0A>(unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as); this->apply_effects_on_phase_change_t<EffectWhen::UNKNOWN_0A, EffectWhen::UNKNOWN_0A>(unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as);
} }
void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) { void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
@@ -4828,38 +4833,38 @@ void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionStat
auto ce = unknown_p2->get_definition(); auto ce = unknown_p2->get_definition();
auto defender_card = (ce && (ce->def.type == CardType::ITEM) && card) ? card : unknown_p2; auto defender_card = (ce && (ce->def.type == CardType::ITEM) && card) ? card : unknown_p2;
this->apply_defense_conditions(as, 0x3D, unknown_p2, 4); this->apply_defense_conditions(as, EffectWhen::ATTACK_STAT_OVERRIDES, unknown_p2, 4);
this->apply_defense_conditions(as, 0x3E, unknown_p2, 4); this->apply_defense_conditions(as, EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, unknown_p2, 4);
if (defender_card) { if (defender_card) {
this->apply_defense_conditions(as, 0x22, defender_card, 4); this->apply_defense_conditions(as, EffectWhen::UNKNOWN_22, defender_card, 4);
} }
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
auto card = this->server()->card_for_set_card_ref(as.target_card_refs[z]); auto card = this->server()->card_for_set_card_ref(as.target_card_refs[z]);
if (card) { if (card) {
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card); ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
this->apply_defense_conditions(defense_as, 0x3D, card, 4); this->apply_defense_conditions(defense_as, EffectWhen::ATTACK_STAT_OVERRIDES, card, 4);
this->apply_defense_conditions(defense_as, 0x3F, card, 4); this->apply_defense_conditions(defense_as, EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card, 4);
} }
} }
this->evaluate_and_apply_effects(0x3D, unknown_p2->get_card_ref(), as, card_ref); this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, unknown_p2->get_card_ref(), as, card_ref);
this->evaluate_and_apply_effects(0x3E, unknown_p2->get_card_ref(), as, card_ref); this->evaluate_and_apply_effects(EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, unknown_p2->get_card_ref(), as, card_ref);
if (defender_card) { if (defender_card) {
this->evaluate_and_apply_effects(0x22, defender_card->get_card_ref(), as, card_ref); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_22, defender_card->get_card_ref(), as, card_ref);
} }
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
this->evaluate_and_apply_effects(0x3D, as.action_card_refs[z], as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, as.action_card_refs[z], as, unknown_p2->get_card_ref());
this->evaluate_and_apply_effects(0x3E, as.action_card_refs[z], as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, as.action_card_refs[z], as, unknown_p2->get_card_ref());
} }
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
card = this->server()->card_for_set_card_ref(as.target_card_refs[z]); card = this->server()->card_for_set_card_ref(as.target_card_refs[z]);
if (card) { if (card) {
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card); ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
this->evaluate_and_apply_effects(0x3D, card->get_card_ref(), defense_as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
this->evaluate_and_apply_effects(0x3F, card->get_card_ref(), defense_as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
} }
} }
} }
@@ -4873,11 +4878,11 @@ void CardSpecial::unknown_8024A9D8(const ActionState& pa, uint16_t action_card_r
for (size_t z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
if (this->server()->options.is_nte() || (action_card_ref == 0xFFFF) || (action_card_ref == pa.action_card_refs[z])) { if (this->server()->options.is_nte() || (action_card_ref == 0xFFFF) || (action_card_ref == pa.action_card_refs[z])) {
if (pa.original_attacker_card_ref == 0xFFFF) { if (pa.original_attacker_card_ref == 0xFFFF) {
this->evaluate_and_apply_effects(0x29, pa.action_card_refs[z], pa, pa.attacker_card_ref); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_29, pa.action_card_refs[z], pa, pa.attacker_card_ref);
this->evaluate_and_apply_effects(0x2A, pa.action_card_refs[z], pa, pa.attacker_card_ref); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_2A, pa.action_card_refs[z], pa, pa.attacker_card_ref);
} else { } else {
this->evaluate_and_apply_effects(0x29, pa.action_card_refs[z], pa, pa.target_card_refs[0]); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_29, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
this->evaluate_and_apply_effects(0x2B, pa.action_card_refs[z], pa, pa.target_card_refs[0]); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_2B, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
} }
} }
} }
@@ -4957,10 +4962,15 @@ void CardSpecial::check_for_attack_interference(shared_ptr<Card> unknown_p2) {
this->server()->send(cmd); this->server()->send(cmd);
} }
template <uint8_t When1, uint8_t When2, uint8_t When3, uint8_t When4> template <
void CardSpecial::unknown_t2(shared_ptr<Card> unknown_p2) { EffectWhen WhenAllCards,
EffectWhen WhenAttackerAndActionCards,
EffectWhen WhenAttackerOrHunterSCCard,
EffectWhen WhenTargetsAndActionCards>
void CardSpecial::apply_effects_before_or_after_attack(shared_ptr<Card> unknown_p2) {
auto s = this->server(); auto s = this->server();
auto log = s->log_stack(string_printf("unknown_t2<%02hhX, %02hhX, %02hhX, %02hhX>(@%04hX #%04hX): ", When1, When2, When3, When4, unknown_p2->get_card_ref(), unknown_p2->get_card_id())); auto log = s->log_stack(string_printf("apply_effects_before_or_after_attack<%s, %s, %s, %s>(@%04hX #%04hX): ",
name_for_enum(WhenAllCards), name_for_enum(WhenAttackerAndActionCards), name_for_enum(WhenAttackerOrHunterSCCard), name_for_enum(WhenTargetsAndActionCards), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
ActionState as = this->create_attack_state_from_card_action_chain(unknown_p2); ActionState as = this->create_attack_state_from_card_action_chain(unknown_p2);
@@ -4970,56 +4980,64 @@ void CardSpecial::unknown_t2(shared_ptr<Card> unknown_p2) {
sc_card_ref = sc_card->get_card_ref(); sc_card_ref = sc_card->get_card_ref();
} }
auto defender_card = unknown_p2; auto attacker_card = unknown_p2;
if (unknown_p2->get_definition() && (unknown_p2->get_definition()->def.type == CardType::ITEM) && sc_card) { if (unknown_p2->get_definition() && (unknown_p2->get_definition()->def.type == CardType::ITEM) && sc_card) {
defender_card = sc_card; attacker_card = sc_card;
} }
uint8_t apply_defense_conditions_flags = s->options.is_nte() ? 0x1F : 0x04; uint8_t apply_defense_conditions_flags = s->options.is_nte() ? 0x1F : 0x04;
this->apply_defense_conditions(as, When1, unknown_p2, apply_defense_conditions_flags); this->apply_defense_conditions(as, WhenAllCards, unknown_p2, apply_defense_conditions_flags);
this->apply_defense_conditions(as, When2, unknown_p2, apply_defense_conditions_flags); this->apply_defense_conditions(as, WhenAttackerAndActionCards, unknown_p2, apply_defense_conditions_flags);
if (defender_card) { if (attacker_card) {
this->apply_defense_conditions(as, When3, defender_card, apply_defense_conditions_flags); this->apply_defense_conditions(as, WhenAttackerOrHunterSCCard, attacker_card, apply_defense_conditions_flags);
} }
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]); auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]);
if (set_card) { if (set_card) {
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card); ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card);
this->apply_defense_conditions(target_as, When1, set_card, apply_defense_conditions_flags); this->apply_defense_conditions(target_as, WhenAllCards, set_card, apply_defense_conditions_flags);
this->apply_defense_conditions(target_as, When4, set_card, apply_defense_conditions_flags); this->apply_defense_conditions(target_as, WhenTargetsAndActionCards, set_card, apply_defense_conditions_flags);
} }
} }
this->evaluate_and_apply_effects(When1, unknown_p2->get_card_ref(), as, sc_card_ref); this->evaluate_and_apply_effects(WhenAllCards, unknown_p2->get_card_ref(), as, sc_card_ref);
this->evaluate_and_apply_effects(When2, unknown_p2->get_card_ref(), as, sc_card_ref); this->evaluate_and_apply_effects(WhenAttackerAndActionCards, unknown_p2->get_card_ref(), as, sc_card_ref);
if (defender_card) { if (attacker_card) {
this->evaluate_and_apply_effects(When3, defender_card->get_card_ref(), as, sc_card_ref); this->evaluate_and_apply_effects(WhenAttackerOrHunterSCCard, attacker_card->get_card_ref(), as, sc_card_ref);
} }
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
this->evaluate_and_apply_effects(When1, as.action_card_refs[z], as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(WhenAllCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
this->evaluate_and_apply_effects(When2, as.action_card_refs[z], as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(WhenAttackerAndActionCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
} }
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]); auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]);
if (set_card) { if (set_card) {
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card); ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card);
this->evaluate_and_apply_effects(When1, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(WhenAllCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
this->evaluate_and_apply_effects(When4, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref()); this->evaluate_and_apply_effects(WhenTargetsAndActionCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
for (size_t z = 0; (z < 8) && (target_as.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (target_as.action_card_refs[z] != 0xFFFF); z++) {
this->evaluate_and_apply_effects(When1, target_as.action_card_refs[z], target_as, set_card->get_card_ref()); this->evaluate_and_apply_effects(WhenAllCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
this->evaluate_and_apply_effects(When4, target_as.action_card_refs[z], target_as, set_card->get_card_ref()); this->evaluate_and_apply_effects(WhenTargetsAndActionCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
} }
} }
} }
} }
void CardSpecial::unknown_8024997C(shared_ptr<Card> card) { void CardSpecial::apply_effects_after_attack(shared_ptr<Card> card) {
return this->unknown_t2<0x03, 0x0D, 0x21, 0x17>(card); return this->apply_effects_before_or_after_attack<
EffectWhen::AFTER_ANY_CARD_ATTACK,
EffectWhen::AFTER_THIS_CARD_ATTACK,
EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK,
EffectWhen::AFTER_THIS_CARD_ATTACKED>(card);
} }
void CardSpecial::unknown_8024A394(shared_ptr<Card> card) { void CardSpecial::apply_effects_before_attack(shared_ptr<Card> card) {
return this->unknown_t2<0x02, 0x0C, 0x20, 0x16>(card); return this->apply_effects_before_or_after_attack<
EffectWhen::BEFORE_ANY_CARD_ATTACK,
EffectWhen::BEFORE_THIS_CARD_ATTACK,
EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK,
EffectWhen::BEFORE_THIS_CARD_ATTACKED>(card);
} }
bool CardSpecial::client_has_atk_dice_boost_condition(uint8_t client_id) { bool CardSpecial::client_has_atk_dice_boost_condition(uint8_t client_id) {
@@ -5056,8 +5074,8 @@ void CardSpecial::unknown_8024A6DC(shared_ptr<Card> unknown_p2, shared_ptr<Card>
ActionState as = this->create_defense_state_for_card_pair_action_chains( ActionState as = this->create_defense_state_for_card_pair_action_chains(
unknown_p2, unknown_p3); unknown_p2, unknown_p3);
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) { for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
this->evaluate_and_apply_effects(0x01, as.action_card_refs[z], as, unknown_p3->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::CARD_SET, as.action_card_refs[z], as, unknown_p3->get_card_ref());
this->evaluate_and_apply_effects(0x15, as.action_card_refs[z], as, unknown_p3->get_card_ref()); this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_15, as.action_card_refs[z], as, unknown_p3->get_card_ref());
} }
} }
+18 -14
View File
@@ -85,7 +85,7 @@ public:
/* 84 */ uint32_t target_attack_bonus; // "edm" in expr /* 84 */ uint32_t target_attack_bonus; // "edm" in expr
/* 88 */ uint32_t last_attack_preliminary_damage; // "ldm" in expr /* 88 */ uint32_t last_attack_preliminary_damage; // "ldm" in expr
/* 8C */ uint32_t last_attack_damage; // "rdm" in expr /* 8C */ uint32_t last_attack_damage; // "rdm" in expr
/* 90 */ uint32_t total_last_attack_damage; // "fdm" in expr /* 90 */ uint32_t final_last_attack_damage; // "fdm" in expr
/* 94 */ uint32_t last_attack_damage_count; // "ndm" in expr /* 94 */ uint32_t last_attack_damage_count; // "ndm" in expr
/* 98 */ uint32_t target_current_hp; // "ehp" in expr /* 98 */ uint32_t target_current_hp; // "ehp" in expr
/* 9C */ /* 9C */
@@ -106,7 +106,7 @@ public:
void adjust_dice_boost_if_team_has_condition_52( void adjust_dice_boost_if_team_has_condition_52(
uint8_t team_id, uint8_t* inout_dice_boost, std::shared_ptr<const Card> card); uint8_t team_id, uint8_t* inout_dice_boost, std::shared_ptr<const Card> card);
void apply_action_conditions( void apply_action_conditions(
uint8_t when, EffectWhen when,
std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> attacker_card,
std::shared_ptr<Card> defender_card, std::shared_ptr<Card> defender_card,
uint32_t flags, uint32_t flags,
@@ -118,7 +118,7 @@ public:
uint16_t condition_giver_card_ref, uint16_t condition_giver_card_ref,
uint16_t attacker_card_ref); uint16_t attacker_card_ref);
bool apply_defense_condition( bool apply_defense_condition(
uint8_t when, EffectWhen when,
Condition* defender_cond, Condition* defender_cond,
uint8_t cond_index, uint8_t cond_index,
const ActionState& defense_state, const ActionState& defense_state,
@@ -127,7 +127,7 @@ public:
bool unknown_p8); bool unknown_p8);
bool apply_defense_conditions( bool apply_defense_conditions(
const ActionState& as, const ActionState& as,
uint8_t when, EffectWhen when,
std::shared_ptr<Card> defender_card, std::shared_ptr<Card> defender_card,
uint32_t flags); uint32_t flags);
bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref( bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(
@@ -165,7 +165,7 @@ public:
uint16_t sc_card_ref); uint16_t sc_card_ref);
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const; StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
void compute_team_dice_bonus(uint8_t team_id); void compute_team_dice_bonus(uint8_t team_id);
bool condition_has_when_20_or_21(const Condition& cond) const; bool condition_applies_on_sc_or_item_attack(const Condition& cond) const;
size_t count_action_cards_with_condition_for_all_current_attacks( size_t count_action_cards_with_condition_for_all_current_attacks(
ConditionType cond_type, uint16_t card_ref) const; ConditionType cond_type, uint16_t card_ref) const;
size_t count_action_cards_with_condition_for_current_attack( size_t count_action_cards_with_condition_for_current_attack(
@@ -189,7 +189,7 @@ public:
uint16_t set_card_ref, uint16_t set_card_ref,
uint16_t sc_card_ref, uint16_t sc_card_ref,
uint8_t random_percent, uint8_t random_percent,
uint8_t when) const; EffectWhen when) const;
int32_t evaluate_effect_expr( int32_t evaluate_effect_expr(
const AttackEnvStats& ast, const AttackEnvStats& ast,
const char* expr, const char* expr,
@@ -276,13 +276,13 @@ public:
size_t* out_damage_count) const; size_t* out_damage_count) const;
void update_condition_orders(std::shared_ptr<Card> card); void update_condition_orders(std::shared_ptr<Card> card);
int16_t max_all_attack_bonuses(size_t* out_count) const; int16_t max_all_attack_bonuses(size_t* out_count) const;
void unknown_80244AA8(std::shared_ptr<Card> card); void apply_effects_after_card_move(std::shared_ptr<Card> card);
void check_for_defense_interference( void check_for_defense_interference(
std::shared_ptr<const Card> attacker_card, std::shared_ptr<const Card> attacker_card,
std::shared_ptr<Card> target_card, std::shared_ptr<Card> target_card,
int16_t* inout_unknown_p4); int16_t* inout_unknown_p4);
void evaluate_and_apply_effects( void evaluate_and_apply_effects(
uint8_t when, EffectWhen when,
uint16_t set_card_ref, uint16_t set_card_ref,
const ActionState& as, const ActionState& as,
uint16_t sc_card_ref, uint16_t sc_card_ref,
@@ -313,10 +313,10 @@ public:
std::shared_ptr<const Card> card1, std::shared_ptr<const Card> card1,
const Location& card1_loc, const Location& card1_loc,
std::shared_ptr<const Card> card2) const; std::shared_ptr<const Card> card2) const;
void unknown_8024AAB8(const ActionState& as); void apply_effects_after_attack_target_resolution(const ActionState& as);
void move_phase_before_for_card(std::shared_ptr<Card> unknown_p2); void move_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
void dice_phase_before_for_card(std::shared_ptr<Card> card); void dice_phase_before_for_card(std::shared_ptr<Card> card);
template <uint8_t When1, uint8_t When2> template <EffectWhen When1, EffectWhen When2>
void apply_effects_on_phase_change_t(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as = nullptr); 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 draw_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
void action_phase_before_for_card(std::shared_ptr<Card> unknown_p2); void action_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
@@ -325,10 +325,14 @@ public:
static std::shared_ptr<Card> sc_card_for_card(std::shared_ptr<Card> unknown_p2); 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); void unknown_8024A9D8(const ActionState& pa, uint16_t action_card_ref);
void check_for_attack_interference(std::shared_ptr<Card> unknown_p2); void check_for_attack_interference(std::shared_ptr<Card> unknown_p2);
template <uint8_t When1, uint8_t When2, uint8_t When3, uint8_t When4> template <
void unknown_t2(std::shared_ptr<Card> unknown_p2); EffectWhen WhenAllCards,
void unknown_8024997C(std::shared_ptr<Card> card); EffectWhen WhenAttackerAndActionCards,
void unknown_8024A394(std::shared_ptr<Card> card); EffectWhen WhenAttackerOrHunterSCCard,
EffectWhen WhenTargetsAndActionCards>
void apply_effects_before_or_after_attack(std::shared_ptr<Card> unknown_p2);
void apply_effects_before_attack(std::shared_ptr<Card> card);
void apply_effects_after_attack(std::shared_ptr<Card> card);
bool client_has_atk_dice_boost_condition(uint8_t client_id); bool client_has_atk_dice_boost_condition(uint8_t client_id);
void unknown_8024A6DC( void unknown_8024A6DC(
std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3); std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3);
+144 -16
View File
@@ -109,8 +109,8 @@ bool Location::operator!=(const Location& other) const {
} }
std::string Location::str() const { std::string Location::str() const {
return string_printf("Location[x=%hhu, y=%hhu, dir=%s, u=%hhu]", return string_printf("Location[x=%hhu, y=%hhu, dir=%hhu:%s, u=%hhu]",
this->x, this->y, name_for_enum(this->direction), this->unused); this->x, this->y, static_cast<uint8_t>(this->direction), name_for_enum(this->direction), this->unused);
} }
void Location::clear() { void Location::clear() {
@@ -517,7 +517,7 @@ bool CardDefinition::Effect::is_empty() const {
return (this->effect_num == 0 && return (this->effect_num == 0 &&
this->type == ConditionType::NONE && this->type == ConditionType::NONE &&
this->expr.empty() && this->expr.empty() &&
this->when == 0 && this->when == EffectWhen::NONE &&
this->arg1.empty() && this->arg1.empty() &&
this->arg2.empty() && this->arg2.empty() &&
this->arg3.empty() && this->arg3.empty() &&
@@ -603,7 +603,7 @@ string CardDefinition::Effect::str(const char* separator, const TextSet* text_ar
if (!this->expr.empty()) { if (!this->expr.empty()) {
tokens.emplace_back("expr=" + this->expr.decode()); tokens.emplace_back("expr=" + this->expr.decode());
} }
tokens.emplace_back(string_printf("when=%02hhX", this->when)); tokens.emplace_back(string_printf("when=%02hhX:%s", static_cast<uint8_t>(this->when), name_for_enum(this->when)));
tokens.emplace_back("arg1=" + this->str_for_arg(this->arg1.decode())); tokens.emplace_back("arg1=" + this->str_for_arg(this->arg1.decode()));
tokens.emplace_back("arg2=" + this->str_for_arg(this->arg2.decode())); tokens.emplace_back("arg2=" + this->str_for_arg(this->arg2.decode()));
tokens.emplace_back("arg3=" + this->str_for_arg(this->arg3.decode())); tokens.emplace_back("arg3=" + this->str_for_arg(this->arg3.decode()));
@@ -736,23 +736,23 @@ string name_for_rank(CardRank rank) {
} }
} }
string name_for_target_mode(TargetMode target_mode) { const char* name_for_target_mode(TargetMode target_mode) {
static const vector<const char*> names({ static const vector<const char*> names({
"NONE", "NONE",
"SINGLE", "SINGLE_RANGE",
"MULTI", "MULTI_RANGE",
"SELF", "SELF",
"TEAM", "TEAM",
"EVERYONE",
"MULTI_RANGE_ALLIES",
"ALL_ALLIES",
"ALL", "ALL",
"MULTI-ALLY", "OWN_FCS",
"ALL-ALLY",
"ALL-ATTACK",
"OWN-FCS",
}); });
try { try {
return names.at(static_cast<uint8_t>(target_mode)); return names.at(static_cast<uint8_t>(target_mode));
} catch (const out_of_range&) { } catch (const out_of_range&) {
return string_printf("(%02hhX)", static_cast<uint8_t>(target_mode)); return "__UNKNOWN__";
} }
} }
@@ -886,7 +886,7 @@ string CardDefinition::str(bool single_line, const TextSet* text_archive) const
string criterion_str = name_for_enum(this->usable_criterion); string criterion_str = name_for_enum(this->usable_criterion);
string card_class_str = name_for_enum(this->card_class()); string card_class_str = name_for_enum(this->card_class());
string rank_str = name_for_rank(this->rank); string rank_str = name_for_rank(this->rank);
string target_mode_str = name_for_target_mode(this->target_mode); const char* target_mode_str = name_for_target_mode(this->target_mode);
string assist_turns_str = string_for_assist_turns(this->assist_turns); string assist_turns_str = string_for_assist_turns(this->assist_turns);
string hp_str = this->hp.str(); string hp_str = this->hp.str();
string ap_str = this->ap.str(); string ap_str = this->ap.str();
@@ -937,7 +937,7 @@ string CardDefinition::str(bool single_line, const TextSet* text_archive) const
criterion_str.c_str(), criterion_str.c_str(),
rank_str.c_str(), rank_str.c_str(),
cost_str.c_str(), cost_str.c_str(),
target_mode_str.c_str(), target_mode_str,
range_str.c_str(), range_str.c_str(),
assist_turns_str.c_str(), assist_turns_str.c_str(),
this->cannot_move ? "true" : "false", this->cannot_move ? "true" : "false",
@@ -1004,7 +1004,7 @@ Card: %04" PRIX32 " \"%s\"\n\
criterion_str.c_str(), criterion_str.c_str(),
rank_str.c_str(), rank_str.c_str(),
cost_str.c_str(), cost_str.c_str(),
target_mode_str.c_str(), target_mode_str,
range_str.c_str(), range_str.c_str(),
assist_turns_str.c_str(), assist_turns_str.c_str(),
this->cannot_move ? "cannot" : "can", this->cannot_move ? "cannot" : "can",
@@ -1068,7 +1068,7 @@ JSON CardDefinition::Effect::json() const {
{"EffectNum", this->effect_num}, {"EffectNum", this->effect_num},
{"ConditionType", name_for_enum(this->type)}, {"ConditionType", name_for_enum(this->type)},
{"Expression", this->expr.decode()}, {"Expression", this->expr.decode()},
{"When", this->when}, {"When", name_for_enum(this->when)},
{"Arg1", this->arg1.decode()}, {"Arg1", this->arg1.decode()},
{"Arg2", this->arg2.decode()}, {"Arg2", this->arg2.decode()},
{"Arg3", this->arg3.decode()}, {"Arg3", this->arg3.decode()},
@@ -1158,6 +1158,62 @@ void PlayerConfig::encrypt(uint8_t basis) {
this->basis = basis; this->basis = basis;
} }
PlayerConfigNTE::PlayerConfigNTE(const PlayerConfig& config)
: rank_text(config.rank_text),
unknown_a1(config.unknown_a1),
tech_menu_shortcut_entries(config.tech_menu_shortcut_entries),
choice_search_config(config.choice_search_config),
scenario_progress(config.scenario_progress),
unused_offline_records(config.unused_offline_records),
unknown_a4(config.unknown_a4),
is_encrypted(config.is_encrypted),
basis(config.basis),
unused(config.unused),
card_counts(config.card_counts),
card_count_checksums(config.card_count_checksums),
rare_tokens(config.rare_tokens),
decks(config.decks),
unknown_a8(config.unknown_a8),
offline_clv_exp(config.offline_clv_exp),
online_clv_exp(config.online_clv_exp),
recent_human_opponents(config.recent_human_opponents),
unknown_a10(config.unknown_a10),
init_timestamp(config.init_timestamp),
last_online_battle_start_timestamp(config.last_online_battle_start_timestamp),
unknown_t3(config.unknown_t3),
unknown_a14(config.unknown_a14) {
// TODO: Do we need to recompute card_count_checksums? (Here or in operator
// PlayerConfig?)
}
PlayerConfigNTE::operator PlayerConfig() const {
PlayerConfig ret;
ret.rank_text = this->rank_text;
ret.unknown_a1 = this->unknown_a1;
ret.tech_menu_shortcut_entries = this->tech_menu_shortcut_entries;
ret.choice_search_config = this->choice_search_config;
ret.scenario_progress = this->scenario_progress;
ret.unused_offline_records = this->unused_offline_records;
ret.unknown_a4 = this->unknown_a4;
ret.is_encrypted = this->is_encrypted;
ret.basis = this->basis;
ret.unused = this->unused;
ret.card_counts = this->card_counts;
ret.card_count_checksums = this->card_count_checksums;
ret.rare_tokens = this->rare_tokens;
ret.decks = this->decks;
ret.unknown_a8 = this->unknown_a8;
ret.offline_clv_exp = this->offline_clv_exp;
ret.online_clv_exp = this->online_clv_exp;
ret.recent_human_opponents = this->recent_human_opponents;
ret.unknown_a10 = this->unknown_a10;
ret.init_timestamp = this->init_timestamp;
ret.last_online_battle_start_timestamp = this->last_online_battle_start_timestamp;
ret.unknown_t3 = this->unknown_t3;
ret.unknown_a14 = this->unknown_a14;
return ret;
}
Rules::Rules(const JSON& json) { Rules::Rules(const JSON& json) {
this->clear(); this->clear();
this->overall_time_limit = json.get_int("overall_time_limit", this->overall_time_limit); this->overall_time_limit = json.get_int("overall_time_limit", this->overall_time_limit);
@@ -3117,6 +3173,78 @@ const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_
} }
} }
template <>
const char* name_for_enum<Episode3::EffectWhen>(Episode3::EffectWhen when) {
switch (when) {
case Episode3::EffectWhen::NONE:
return "NONE";
case Episode3::EffectWhen::CARD_SET:
return "CARD_SET";
case Episode3::EffectWhen::AFTER_ANY_CARD_ATTACK:
return "AFTER_ANY_CARD_ATTACK";
case Episode3::EffectWhen::BEFORE_ANY_CARD_ATTACK:
return "BEFORE_ANY_CARD_ATTACK";
case Episode3::EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN:
return "BEFORE_DICE_PHASE_THIS_TEAM_TURN";
case Episode3::EffectWhen::CARD_DESTROYED:
return "CARD_DESTROYED";
case Episode3::EffectWhen::AFTER_SET_PHASE:
return "AFTER_SET_PHASE";
case Episode3::EffectWhen::BEFORE_MOVE_PHASE:
return "BEFORE_MOVE_PHASE";
case Episode3::EffectWhen::UNKNOWN_0A:
return "UNKNOWN_0A";
case Episode3::EffectWhen::AFTER_ATTACK_TARGET_RESOLUTION:
return "AFTER_ATTACK_TARGET_RESOLUTION";
case Episode3::EffectWhen::AFTER_THIS_CARD_ATTACK:
return "AFTER_THIS_CARD_ATTACK";
case Episode3::EffectWhen::BEFORE_THIS_CARD_ATTACK:
return "BEFORE_THIS_CARD_ATTACK";
case Episode3::EffectWhen::BEFORE_ACT_PHASE:
return "BEFORE_ACT_PHASE";
case Episode3::EffectWhen::BEFORE_DRAW_PHASE:
return "BEFORE_DRAW_PHASE";
case Episode3::EffectWhen::AFTER_CARD_MOVE:
return "AFTER_CARD_MOVE";
case Episode3::EffectWhen::UNKNOWN_15:
return "UNKNOWN_15";
case Episode3::EffectWhen::AFTER_THIS_CARD_ATTACKED:
return "AFTER_THIS_CARD_ATTACKED";
case Episode3::EffectWhen::BEFORE_THIS_CARD_ATTACKED:
return "BEFORE_THIS_CARD_ATTACKED";
case Episode3::EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK:
return "AFTER_CREATURE_OR_HUNTER_SC_ATTACK";
case Episode3::EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK:
return "BEFORE_CREATURE_OR_HUNTER_SC_ATTACK";
case Episode3::EffectWhen::UNKNOWN_22:
return "UNKNOWN_22";
case Episode3::EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL:
return "BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL";
case Episode3::EffectWhen::UNKNOWN_29:
return "UNKNOWN_29";
case Episode3::EffectWhen::UNKNOWN_2A:
return "UNKNOWN_2A";
case Episode3::EffectWhen::UNKNOWN_2B:
return "UNKNOWN_2B";
case Episode3::EffectWhen::UNKNOWN_33:
return "UNKNOWN_33";
case Episode3::EffectWhen::UNKNOWN_34:
return "UNKNOWN_34";
case Episode3::EffectWhen::UNKNOWN_35:
return "UNKNOWN_35";
case Episode3::EffectWhen::ATTACK_STAT_OVERRIDES:
return "ATTACK_STAT_OVERRIDES";
case Episode3::EffectWhen::ATTACK_DAMAGE_ADJUSTMENT:
return "ATTACK_DAMAGE_ADJUSTMENT";
case Episode3::EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT:
return "DEFENSE_DAMAGE_ADJUSTMENT";
case Episode3::EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL:
return "BEFORE_DICE_PHASE_ALL_TURNS_FINAL";
default:
return "__INVALID__";
}
}
template <> template <>
const char* name_for_enum<Episode3::Direction>(Episode3::Direction d) { const char* name_for_enum<Episode3::Direction>(Episode3::Direction d) {
switch (d) { switch (d) {
+77 -4
View File
@@ -173,6 +173,8 @@ enum class TargetMode : uint8_t {
OWN_FCS = 0x09, // e.g. Traitor OWN_FCS = 0x09, // e.g. Traitor
}; };
const char* name_for_target_mode(TargetMode target_mode);
enum class ConditionType : uint8_t { enum class ConditionType : uint8_t {
NONE = 0x00, NONE = 0x00,
AP_BOOST = 0x01, // Temporarily increase AP by N AP_BOOST = 0x01, // Temporarily increase AP by N
@@ -304,6 +306,41 @@ enum class ConditionType : uint8_t {
ANY_FF = 0xFF, // Used as a wildcard in some search functions ANY_FF = 0xFF, // Used as a wildcard in some search functions
}; };
enum class EffectWhen : uint8_t {
NONE = 0x00,
CARD_SET = 0x01, // Permanent effects like RAMPAGE/PIERCE on SCs, BIG_SWING, AERIAL, etc.; many AC effects also
AFTER_ANY_CARD_ATTACK = 0x02, // GIVE_DAMAGE, HEAL, A_H_SWAP_PERM
BEFORE_ANY_CARD_ATTACK = 0x03, // AP_LOSS, COMBO_TP
BEFORE_DICE_PHASE_THIS_TEAM_TURN = 0x04, // Many different effects
CARD_DESTROYED = 0x05, // RETURN_TO_HAND, RETURN, FILIAL, GIVE_OR_TAKE_EXP
AFTER_SET_PHASE = 0x06, // Unused
BEFORE_MOVE_PHASE = 0x09, // Unused
UNKNOWN_0A = 0x0A, // ANTI_ABNORMALITY_2 on Tollaw (non-SC version of another when?)
AFTER_ATTACK_TARGET_RESOLUTION = 0x0B, // ABILITY_TRAP via First Attack action card only
AFTER_THIS_CARD_ATTACK = 0x0C, // Many effects
BEFORE_THIS_CARD_ATTACK = 0x0D, // Conditions, AP_BOOST/TP_BOOST, AP_SILENCE, MULTI_STRIKE
BEFORE_ACT_PHASE = 0x0E, // Before act phase (ANTI_ABNORMALITY_2, FIXED_RANGE)
BEFORE_DRAW_PHASE = 0x0F, // Unused
AFTER_CARD_MOVE = 0x13, // Unused
UNKNOWN_15 = 0x15, // Unused
AFTER_THIS_CARD_ATTACKED = 0x16, // Conditions, DEATH_COMPANION, GIVE_DAMAGE, AP_GROWTH (Nidra)
BEFORE_THIS_CARD_ATTACKED = 0x17, // Defense damage adjustments
AFTER_CREATURE_OR_HUNTER_SC_ATTACK = 0x20, // RETURN_TO_HAND, A_T_SWAP_PERM, GIVE_OR_TAKE_EXP
BEFORE_CREATURE_OR_HUNTER_SC_ATTACK = 0x21, // Unused
UNKNOWN_22 = 0x22, // MISC_AP_BONUSES (SCs only?)
BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL = 0x27, // SET_MV
UNKNOWN_29 = 0x29, // MIGHTY_KNUCKLE
UNKNOWN_2A = 0x2A, // Unused
UNKNOWN_2B = 0x2B, // Unused
UNKNOWN_33 = 0x33, // DEF_DISABLE_BY_COST
UNKNOWN_34 = 0x34, // Unused
UNKNOWN_35 = 0x35, // Unused
ATTACK_STAT_OVERRIDES = 0x3D, // BONUS_FROM_LEADER, COPY, ABILITY_TRAP
ATTACK_DAMAGE_ADJUSTMENT = 0x3E, // AP_BOOST, SLAYERS_ASSASSINS, WEAK_SPOT_INFLUENCE, GROUP
DEFENSE_DAMAGE_ADJUSTMENT = 0x3F, // MOSTLY_HALFGUARDS, ACTION_DISRUPTER
BEFORE_DICE_PHASE_ALL_TURNS_FINAL = 0x46, // Pollux Timed Pierce
};
enum class AssistEffect : uint16_t { enum class AssistEffect : uint16_t {
NONE = 0x0000, NONE = 0x0000,
DICE_HALF = 0x0001, DICE_HALF = 0x0001,
@@ -486,7 +523,7 @@ struct CardDefinition {
/* 02 */ pstring<TextEncoding::ASCII, 0x0F> expr; /* 02 */ pstring<TextEncoding::ASCII, 0x0F> expr;
// when specifies in which phase the effect should activate. // when specifies in which phase the effect should activate.
// TODO: There are many values that can be used here; document them. // TODO: There are many values that can be used here; document them.
/* 11 */ uint8_t when; /* 11 */ EffectWhen when;
// arg1 generally specifies how long the effect activates for. // arg1 generally specifies how long the effect activates for.
/* 12 */ pstring<TextEncoding::ASCII, 4> arg1; /* 12 */ pstring<TextEncoding::ASCII, 4> arg1;
// arg2 generally specifies a condition for when the effect activates. // arg2 generally specifies a condition for when the effect activates.
@@ -870,12 +907,12 @@ struct PlayerConfig {
// card counts array is encrypted in memory most of the time, and they went // card counts array is encrypted in memory most of the time, and they went
// out of their way to ensure the game uses an area of memory that almost no // out of their way to ensure the game uses an area of memory that almost no
// other game uses, which is also used by the Action Replay.) // other game uses, which is also used by the Action Replay.)
/* 05A4:0450 */ parray<be_uint64_t, 0x1C2> rare_tokens; /* 05A4:0450 */ parray<be_uint64_t, 450> rare_tokens;
/* 13B4:1260 */ parray<uint8_t, 0x80> unknown_a7; /* 13B4:1260 */ parray<uint8_t, 0x80> unknown_a7;
/* 1434:12E0 */ parray<DeckDefinition, 25> decks; /* 1434:12E0 */ parray<DeckDefinition, 25> decks;
/* 2118:1FC4 */ parray<uint8_t, 0x08> unknown_a8; /* 2118:1FC4 */ parray<uint8_t, 0x08> unknown_a8;
/* 2120:1FCC */ be_uint32_t offline_clv_exp; // CLvOff = this / 100 /* 2120:1FCC */ be_uint32_t offline_clv_exp; // CLvOff = (this / 100) + 1
/* 2124:1FD0 */ be_uint32_t online_clv_exp; // CLvOn = this / 100 /* 2124:1FD0 */ be_uint32_t online_clv_exp; // CLvOn = (this / 100) + 1
struct PlayerReference { struct PlayerReference {
/* 00 */ be_uint32_t guild_card_number; /* 00 */ be_uint32_t guild_card_number;
/* 04 */ pstring<TextEncoding::MARKED, 0x18> name; /* 04 */ pstring<TextEncoding::MARKED, 0x18> name;
@@ -904,6 +941,40 @@ struct PlayerConfig {
void encrypt(uint8_t basis); void encrypt(uint8_t basis);
} __packed_ws__(PlayerConfig, 0x2350); } __packed_ws__(PlayerConfig, 0x2350);
struct PlayerConfigNTE {
/* 0000 */ pstring<TextEncoding::MARKED, 12> rank_text;
/* 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;
/* 0078 */ parray<be_uint32_t, 0x10> scenario_progress; // Final has 0x30 entries here
/* 00B8 */ PlayerRecordsBattleBE unused_offline_records;
/* 00D0 */ parray<uint8_t, 4> unknown_a4;
/* 00D4 */ uint8_t is_encrypted;
/* 00D5 */ uint8_t basis;
/* 00D6 */ parray<uint8_t, 2> unused;
/* 00D8 */ parray<uint8_t, 1000> card_counts;
/* 04C0 */ parray<be_uint16_t, 50> card_count_checksums;
/* 0524 */ parray<be_uint64_t, 300> rare_tokens;
/* 0E84 */ parray<DeckDefinition, 25> decks;
/* 1B68 */ parray<uint8_t, 0x08> unknown_a8;
/* 1B70 */ be_uint32_t offline_clv_exp;
/* 1B74 */ be_uint32_t online_clv_exp;
/* 1B78 */ parray<PlayerConfig::PlayerReference, 10> recent_human_opponents;
/* 1C90 */ parray<uint8_t, 0x28> unknown_a10;
/* 1CB8 */ be_uint32_t init_timestamp;
/* 1CBC */ be_uint32_t last_online_battle_start_timestamp;
/* 1CC0 */ be_uint32_t unknown_t3;
/* 1CC4 */ parray<uint8_t, 0x94> unknown_a14;
/* 1D58 */
PlayerConfigNTE() = default;
explicit PlayerConfigNTE(const PlayerConfig& config);
operator PlayerConfig() const;
void decrypt();
void encrypt(uint8_t basis);
} __packed_ws__(PlayerConfigNTE, 0x1D58);
enum class HPType : uint8_t { enum class HPType : uint8_t {
DEFEAT_PLAYER = 0, DEFEAT_PLAYER = 0,
DEFEAT_TEAM = 1, DEFEAT_TEAM = 1,
@@ -1575,4 +1646,6 @@ const char* name_for_enum<Episode3::CardClass>(Episode3::CardClass cc);
template <> template <>
const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_type); const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_type);
template <> template <>
const char* name_for_enum<Episode3::EffectWhen>(Episode3::EffectWhen when);
template <>
const char* name_for_enum<Episode3::Direction>(Episode3::Direction d); const char* name_for_enum<Episode3::Direction>(Episode3::Direction d);
+1 -1
View File
@@ -1003,7 +1003,7 @@ bool PlayerState::move_card_to_location_by_card_index(size_t card_index, const L
this->send_6xB4x04_if_needed(); this->send_6xB4x04_if_needed();
s->send_6xB4x05(); s->send_6xB4x05();
s->send_6xB4x39(); s->send_6xB4x39();
s->card_special->unknown_80244AA8(card); s->card_special->apply_effects_after_card_move(card);
return true; return true;
} }
+32 -4
View File
@@ -2,6 +2,7 @@
#include <optional> #include <optional>
#include "DataIndexes.hh"
#include "Server.hh" #include "Server.hh"
using namespace std; using namespace std;
@@ -1469,36 +1470,52 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
uint16_t* out_effective_card_id, uint16_t* out_effective_card_id,
TargetMode* out_effective_target_mode, TargetMode* out_effective_target_mode,
uint16_t* out_orig_card_ref) const { uint16_t* out_orig_card_ref) const {
auto s = this->server();
bool is_nte = s->options.is_nte();
auto log = s->log_stack("compute_effective_range_and_target_mode_for_attack: ");
size_t z; size_t z;
for (z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) { for (z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
} }
if (z >= 8) { if (z >= 8) {
log.debug("too many action card refs");
return false; return false;
} }
log.debug("%zu action card refs", z);
uint16_t card_ref = (z == 0) ? pa.attacker_card_ref : pa.action_card_refs[z - 1]; uint16_t card_ref = (z == 0) ? pa.attacker_card_ref : pa.action_card_refs[z - 1];
log.debug("base card ref = @%04hX", card_ref);
uint16_t card_id = this->card_id_for_card_ref(card_ref); uint16_t card_id = this->card_id_for_card_ref(card_ref);
if (card_id == 0xFFFF) { if (card_id == 0xFFFF) {
log.debug("card ref is broken");
return false; return false;
} }
auto ce = this->definition_for_card_id(card_id); auto ce = this->definition_for_card_id(card_id);
uint8_t client_id = client_id_for_card_ref(pa.attacker_card_ref); uint8_t client_id = client_id_for_card_ref(pa.attacker_card_ref);
if ((client_id == 0xFF) || !ce) { if ((client_id == 0xFF) || !ce) {
log.debug("card ref is broken or definition is missing");
return false; return false;
} }
if (out_orig_card_ref) { if (out_orig_card_ref) {
log.debug("orig_card_ref = @%04hX", card_ref);
*out_orig_card_ref = card_ref; *out_orig_card_ref = card_ref;
} }
auto target_mode = ce->def.target_mode; auto target_mode = ce->def.target_mode;
if (this->card_ref_or_sc_has_fixed_range(pa.attacker_card_ref)) { if (this->card_ref_or_sc_has_fixed_range(pa.attacker_card_ref)) {
const char* target_mode_name = name_for_target_mode(target_mode);
log.debug("attacker card ref @%04hX has fixed range; target mode is %s (%hhu)",
pa.attacker_card_ref.load(), target_mode_name, static_cast<uint8_t>(target_mode));
card_id = this->card_id_for_card_ref(pa.attacker_card_ref); card_id = this->card_id_for_card_ref(pa.attacker_card_ref);
if (!this->server()->options.is_nte()) { if (!is_nte) {
auto sc_ce = this->definition_for_card_id(card_id); auto sc_ce = this->definition_for_card_id(card_id);
if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) { if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) {
target_mode = sc_ce->def.target_mode; target_mode = sc_ce->def.target_mode;
const char* target_mode_name = name_for_target_mode(target_mode);
log.debug("sc_ce overrides target mode with %s (%hhu)",
target_mode_name, static_cast<uint8_t>(target_mode));
} }
} }
} }
@@ -1508,8 +1525,10 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
auto assist_effect = this->assist_server->get_active_assist_by_index(z); auto assist_effect = this->assist_server->get_active_assist_by_index(z);
if (assist_effect == AssistEffect::SIMPLE) { if (assist_effect == AssistEffect::SIMPLE) {
card_id = this->card_id_for_card_ref(pa.attacker_card_ref); card_id = this->card_id_for_card_ref(pa.attacker_card_ref);
log.debug("SIMPLE assist overrides card id with #%04hX", card_id);
} else if (assist_effect == AssistEffect::HEAVY_FOG) { } else if (assist_effect == AssistEffect::HEAVY_FOG) {
card_id = 0xFFFE; card_id = 0xFFFE;
log.debug("HEAVY_FOG assist overrides card id with #%04hX", card_id);
} }
} }
@@ -2040,21 +2059,27 @@ shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_id(uint3
uint32_t RulerServer::get_card_id_with_effective_range( uint32_t RulerServer::get_card_id_with_effective_range(
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const { uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const {
auto log = this->server()->log_stack(string_printf("get_card_id_with_effective_range(@%04hX, #%04hX): ", card_ref, card_id_override));
uint16_t card_id = (card_id_override == 0xFFFF) uint16_t card_id = (card_id_override == 0xFFFF)
? this->card_id_for_card_ref(card_ref) ? this->card_id_for_card_ref(card_ref)
: card_id_override; : card_id_override;
log.debug("card_id=#%04hX", card_id);
if (card_id != 0xFFFF) { if (card_id != 0xFFFF) {
auto ce = this->definition_for_card_id(card_id); auto ce = this->definition_for_card_id(card_id);
uint8_t client_id = client_id_for_card_ref(card_ref); uint8_t client_id = client_id_for_card_ref(card_ref);
if ((client_id != 0xFF) && ce) { if ((client_id != 0xFF) && ce) {
TargetMode effective_target_mode = ce->def.target_mode; TargetMode effective_target_mode = ce->def.target_mode;
log.debug("ce valid for #%04hX with effective target mode %s", card_id, name_for_target_mode(effective_target_mode));
if (this->card_ref_or_sc_has_fixed_range(card_ref)) { if (this->card_ref_or_sc_has_fixed_range(card_ref)) {
// Undo the override that may have been passed in // Undo the override that may have been passed in
auto ce = this->definition_for_card_id(this->card_id_for_card_ref(card_ref)); log.debug("@%04hX has FIXED_RANGE", card_ref);
if (ce && (static_cast<uint8_t>(effective_target_mode) < 6)) { auto orig_ce = this->definition_for_card_id(this->card_id_for_card_ref(card_ref));
effective_target_mode = ce->def.target_mode; if (orig_ce && (static_cast<uint8_t>(effective_target_mode) < 6)) {
log.debug("ce valid for #%04hX with effective target mode %s; overriding to %s", card_id, name_for_target_mode(effective_target_mode), name_for_target_mode(orig_ce->def.target_mode));
effective_target_mode = orig_ce->def.target_mode;
} }
} }
@@ -2063,14 +2088,17 @@ uint32_t RulerServer::get_card_id_with_effective_range(
auto eff = this->assist_server->get_active_assist_by_index(z); auto eff = this->assist_server->get_active_assist_by_index(z);
if (eff == AssistEffect::SIMPLE) { if (eff == AssistEffect::SIMPLE) {
card_id = this->card_id_for_card_ref(card_ref); card_id = this->card_id_for_card_ref(card_ref);
log.debug("SIMPLE assist effect is active; using #%04hX for range", card_id);
} else if (eff == AssistEffect::HEAVY_FOG) { } else if (eff == AssistEffect::HEAVY_FOG) {
card_id = 0xFFFE; card_id = 0xFFFE;
log.debug("HEAVY_FOG assist effect is active; limiting range to one tile in front");
} }
} }
if (out_target_mode) { if (out_target_mode) {
*out_target_mode = effective_target_mode; *out_target_mode = effective_target_mode;
} }
log.debug("results: card_id=#%04hX, target_mode=%s", card_id, name_for_target_mode(effective_target_mode));
} }
} }
+12 -6
View File
@@ -30,7 +30,7 @@ void Server::PresenceEntry::clear() {
Server::Server(shared_ptr<Lobby> lobby, Options&& options) Server::Server(shared_ptr<Lobby> lobby, Options&& options)
: lobby(lobby), : lobby(lobby),
battle_record(lobby->battle_record), battle_record(lobby ? lobby->battle_record : nullptr),
has_lobby(lobby != nullptr), has_lobby(lobby != nullptr),
options(std::move(options)), options(std::move(options)),
last_chosen_map(this->options.tournament ? this->options.tournament->get_map() : nullptr), last_chosen_map(this->options.tournament ? this->options.tournament->get_map() : nullptr),
@@ -260,7 +260,7 @@ void Server::send(const void* data, size_t size, uint8_t command, bool enable_ma
} else if ((this->options.behavior_flags & BehaviorFlag::LOG_COMMANDS_IF_LOBBY_MISSING) && } else if ((this->options.behavior_flags & BehaviorFlag::LOG_COMMANDS_IF_LOBBY_MISSING) &&
this->log().info("Generated command")) { this->log().info("Generated command")) {
print_data(stderr, data, size); print_data(stderr, data, size, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
} }
} }
@@ -1075,7 +1075,13 @@ shared_ptr<const PlayerState> Server::get_player_state(uint8_t client_id) const
} }
uint32_t Server::get_random_raw() { uint32_t Server::get_random_raw() {
le_uint32_t ret = random_from_optional_crypt(this->options.opt_rand_crypt); le_uint32_t ret;
if (this->options.opt_rand_stream) {
this->options.opt_rand_stream->readx(&ret, sizeof(ret));
} else {
ret = random_from_optional_crypt(this->options.opt_rand_crypt);
}
if (this->battle_record && this->battle_record->writable()) { if (this->battle_record && this->battle_record->writable()) {
this->battle_record->add_random_data(&ret, sizeof(ret)); this->battle_record->add_random_data(&ret, sizeof(ret));
} }
@@ -1456,12 +1462,12 @@ void Server::set_phase_after() {
if (ps) { if (ps) {
auto card = ps->get_sc_card(); auto card = ps->get_sc_card();
if (card) { if (card) {
this->card_special->apply_action_conditions(0x06, nullptr, card, is_nte ? 0x1F : 0x04, nullptr); this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
} }
for (size_t set_index = 0; set_index < 8; set_index++) { for (size_t set_index = 0; set_index < 8; set_index++) {
auto card = ps->get_set_card(set_index); auto card = ps->get_set_card(set_index);
if (card) { if (card) {
this->card_special->apply_action_conditions(0x06, nullptr, card, is_nte ? 0x1F : 0x04, nullptr); this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
} }
} }
} }
@@ -2863,7 +2869,7 @@ void Server::unknown_8023EEF4() {
ActionState as = cmd.state; ActionState as = cmd.state;
this->send(cmd); this->send(cmd);
this->card_special->unknown_8024AAB8(as); this->card_special->apply_effects_after_attack_target_resolution(as);
if (!is_nte) { if (!is_nte) {
this->attack_cards[this->unknown_a14]->compute_action_chain_results(1, 0); this->attack_cards[this->unknown_a14]->compute_action_chain_results(1, 0);
+1
View File
@@ -72,6 +72,7 @@ public:
std::shared_ptr<const CardIndex> card_index; std::shared_ptr<const CardIndex> card_index;
std::shared_ptr<const MapIndex> map_index; std::shared_ptr<const MapIndex> map_index;
uint32_t behavior_flags; uint32_t behavior_flags;
std::shared_ptr<StringReader> opt_rand_stream;
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt; std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
std::shared_ptr<const Tournament> tournament; std::shared_ptr<const Tournament> tournament;
std::array<std::vector<uint16_t>, 5> trap_card_ids; std::array<std::vector<uint16_t>, 5> trap_card_ids;
+4
View File
@@ -9,8 +9,12 @@
#include <optional> #include <optional>
#include <stdexcept> #include <stdexcept>
// Calls a function on the given base's event thread. This function returns
// when the call has been enqueued, not necessarily after it returns.
void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn); void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn);
// Calls a function on the given base's event thread and waits for it to
// return. Returns the value returned on that thread.
template <typename T> template <typename T>
T call_on_event_thread(std::shared_ptr<struct event_base> base, std::function<T()>&& compute) { T call_on_event_thread(std::shared_ptr<struct event_base> base, std::function<T()>&& compute) {
std::optional<T> ret; std::optional<T> ret;
+11 -6
View File
@@ -50,7 +50,8 @@ const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
template <typename FooterT> template <typename FooterT>
string CompiledFunctionCode::generate_client_command_t( string CompiledFunctionCode::generate_client_command_t(
const unordered_map<string, uint32_t>& label_writes, const unordered_map<string, uint32_t>& label_writes,
const string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const { uint32_t override_relocations_offset) const {
FooterT footer; FooterT footer;
footer.num_relocations = this->relocation_deltas.size(); footer.num_relocations = this->relocation_deltas.size();
@@ -72,7 +73,9 @@ string CompiledFunctionCode::generate_client_command_t(
} else { } else {
w.write(this->code); w.write(this->code);
} }
w.write(suffix); if (suffix_size) {
w.write(suffix_data, suffix_size);
}
while (w.size() & 3) { while (w.size() & 3) {
w.put_u8(0); w.put_u8(0);
} }
@@ -101,14 +104,15 @@ string CompiledFunctionCode::generate_client_command_t(
string CompiledFunctionCode::generate_client_command( string CompiledFunctionCode::generate_client_command(
const unordered_map<string, uint32_t>& label_writes, const unordered_map<string, uint32_t>& label_writes,
const string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t override_relocations_offset) const { uint32_t override_relocations_offset) const {
if (this->arch == Architecture::POWERPC) { if (this->arch == Architecture::POWERPC) {
return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2>( return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2>(
label_writes, suffix, override_relocations_offset); label_writes, suffix_data, suffix_size, override_relocations_offset);
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) { } else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2>( return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2>(
label_writes, suffix, override_relocations_offset); label_writes, suffix_data, suffix_size, override_relocations_offset);
} else { } else {
throw logic_error("invalid architecture"); throw logic_error("invalid architecture");
} }
@@ -388,8 +392,9 @@ shared_ptr<const Menu> FunctionCodeIndex::patch_switches_menu(
} }
bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const { bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
uint32_t mask = specific_version_is_indeterminate(specific_version) ? 0xFF000000 : 0xFFFFFFFF;
for (const auto& it : this->menu_item_id_and_specific_version_to_patch_function) { for (const auto& it : this->menu_item_id_and_specific_version_to_patch_function) {
if ((it.first & 0xFF000000) == (specific_version & 0xFF000000)) { if ((it.first & mask) == (specific_version & mask)) {
return false; return false;
} }
} }
+4 -2
View File
@@ -43,11 +43,13 @@ struct CompiledFunctionCode {
template <typename FooterT> template <typename FooterT>
std::string generate_client_command_t( std::string generate_client_command_t(
const std::unordered_map<std::string, uint32_t>& label_writes, const std::unordered_map<std::string, uint32_t>& label_writes,
const std::string& suffix, const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const; uint32_t override_relocations_offset = 0) const;
std::string generate_client_command( std::string generate_client_command(
const std::unordered_map<std::string, uint32_t>& label_writes = {}, const std::unordered_map<std::string, uint32_t>& label_writes = {},
const std::string& suffix = "", const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t override_relocations_offset = 0) const; uint32_t override_relocations_offset = 0) const;
}; };
+249 -3
View File
@@ -132,8 +132,7 @@ unordered_multimap<string, string> HTTPServer::parse_url_params(const string& qu
} }
value.resize(write_offset); value.resize(write_offset);
params.emplace(piecewise_construct, forward_as_tuple(it, 0, first_equals), params.emplace(piecewise_construct, forward_as_tuple(it, 0, first_equals), forward_as_tuple(value));
forward_as_tuple(value));
} else { } else {
params.emplace(it, ""); params.emplace(it, "");
} }
@@ -204,6 +203,233 @@ void HTTPServer::wait_for_stop() {
this->th.join(); this->th.join();
} }
HTTPServer::WebsocketClient::WebsocketClient(struct evhttp_connection* conn)
: conn(conn),
bev(evhttp_connection_get_bufferevent(this->conn)),
pending_opcode(0xFF),
last_communication_time(now()) {}
HTTPServer::WebsocketClient::~WebsocketClient() {
evhttp_connection_free(this->conn);
}
void HTTPServer::WebsocketClient::reset_pending_frame() {
this->pending_opcode = 0xFF;
this->pending_data.clear();
}
shared_ptr<HTTPServer::WebsocketClient> HTTPServer::enable_websockets(struct evhttp_request* req) {
if (evhttp_request_get_command(req) != EVHTTP_REQ_GET) {
return nullptr;
}
struct evkeyvalq* in_headers = evhttp_request_get_input_headers(req);
const char* connection_header = evhttp_find_header(in_headers, "Connection");
if (!connection_header || strcasecmp(connection_header, "upgrade")) {
return nullptr;
}
const char* upgrade_header = evhttp_find_header(in_headers, "Upgrade");
if (!upgrade_header || strcasecmp(upgrade_header, "websocket")) {
return nullptr;
}
const char* sec_websocket_key_header = evhttp_find_header(in_headers, "Sec-WebSocket-Key");
if (!sec_websocket_key_header) {
return nullptr;
}
// Note: it's important that we make a copy of this header's value since
// we're about to free the original
string sec_websocket_key = sec_websocket_key_header;
string sec_websocket_accept_data = sec_websocket_key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
string sec_websocket_accept = base64_encode(sha1(sec_websocket_accept_data));
// Hijack the bufferevent since it's no longer handling HTTP at all
struct evhttp_connection* conn = evhttp_request_get_connection(req);
struct bufferevent* bev = evhttp_connection_get_bufferevent(conn);
bufferevent_setcb(bev, &this->dispatch_on_websocket_read, NULL, &this->dispatch_on_websocket_error, this);
bufferevent_enable(bev, EV_READ | EV_WRITE);
// Send the HTTP reply, which enables websockets
struct evbuffer* out_buf = bufferevent_get_output(bev);
evbuffer_add_printf(out_buf, "HTTP/1.1 101 Switching Protocols\r\n\
Upgrade: websocket\r\n\
Connection: upgrade\r\n\
Sec-WebSocket-Accept: %s\r\n\
\r\n",
sec_websocket_accept.c_str());
return this->bev_to_websocket_client.emplace(bev, new WebsocketClient(conn)).first->second;
}
void HTTPServer::dispatch_on_websocket_read(struct bufferevent* bev, void* ctx) {
reinterpret_cast<HTTPServer*>(ctx)->on_websocket_read(bev);
}
void HTTPServer::dispatch_on_websocket_error(struct bufferevent* bev, short events, void* ctx) {
reinterpret_cast<HTTPServer*>(ctx)->on_websocket_error(bev, events);
}
void HTTPServer::on_websocket_read(struct bufferevent* bev) {
struct evbuffer* in_buf = bufferevent_get_input(bev);
for (;;) {
// We need at most 10 bytes to determine if there's a valid frame, or as
// little as 2
string header_data(10, '\0');
ssize_t bytes_read = evbuffer_copyout(in_buf, const_cast<char*>(header_data.data()), header_data.size());
if (bytes_read < 2) {
break; // Full header not yet available
}
// Get the payload size
bool has_mask = header_data[1] & 0x80;
size_t header_size = 2;
size_t payload_size = header_data[1] & 0x7F;
if (payload_size == 0x7F) {
if (bytes_read < 10) {
break; // Full 64-bit header not yet available
}
payload_size = bswap64(*reinterpret_cast<const uint64_t*>(&header_data[2]));
header_size = 10;
} else if (payload_size == 0x7E) {
if (bytes_read < 4) {
break; // Full 16-bit size header not yet available
}
payload_size = bswap16(*reinterpret_cast<const uint16_t*>(&header_data[2]));
header_size = 4;
}
if (evbuffer_get_length(in_buf) < header_size + payload_size) {
break; // Full message not yet available
}
// Full message is available; skip the header bytes (we already read them)
// and read the masking key if needed
evbuffer_drain(in_buf, header_size);
uint8_t mask_key[4];
if (has_mask) {
evbuffer_remove(in_buf, mask_key, 4);
}
shared_ptr<WebsocketClient> c = this->bev_to_websocket_client.at(bev);
c->last_communication_time = now();
// Read and unmask message data
string payload(payload_size, '\0');
evbuffer_remove(in_buf, const_cast<char*>(payload.data()), payload_size);
if (has_mask) {
for (size_t x = 0; x < payload_size; x++) {
payload[x] ^= mask_key[x & 3];
}
}
// If the current message is a control message, respond appropriately
// (these can be sent in the middle of fragmented messages)
uint8_t opcode = header_data[0] & 0x0F;
if (opcode & 0x08) {
if (opcode == 0x0A) {
// Ping response; ignore it
} else if (opcode == 0x08) {
// Close message
this->send_websocket_message(bev, payload, 0x08);
this->disconnect_websocket_client(bev);
} else if (opcode == 0x09) {
// Ping message
this->send_websocket_message(bev, payload, 0x0A);
} else {
// Unknown control message type
this->disconnect_websocket_client(bev);
}
break;
}
// If there's an existing pending message, the current message's opcode
// should be zero; if there's no pending message, it must not be zero
if ((c->pending_opcode != 0xFF) == (opcode != 0)) {
this->disconnect_websocket_client(bev);
break;
}
// At this point, we have read a full message; we must not break out of
// this loop in case there are further messages available.
// Save the message opcode, if present, and append the frame data
if (opcode) {
c->pending_opcode = opcode;
}
c->pending_data += payload;
// If the FIN bit is set, then the frame is complete - append the payload
// to any pending payloads and call the message handler. If the FIN bit
// isn't set, we need to receive at least one continuation frame to
// complete the message.
if (header_data[0] & 0x80) {
this->handle_websocket_message(c, c->pending_opcode, c->pending_data);
c->reset_pending_frame();
}
}
}
void HTTPServer::on_websocket_error(struct bufferevent* bev, short events) {
if (events & (BEV_EVENT_ERROR | BEV_EVENT_EOF)) {
this->disconnect_websocket_client(bev);
}
}
void HTTPServer::disconnect_websocket_client(struct bufferevent* bev) {
auto it = this->bev_to_websocket_client.find(bev);
this->handle_websocket_disconnect(it->second);
this->bev_to_websocket_client.erase(it);
}
void HTTPServer::send_websocket_message(struct bufferevent* bev,
const string& message, uint8_t opcode) {
string header;
header.push_back(0x80 | (opcode & 0x0F));
if (message.size() > 65535) {
header.push_back(0x7F);
header.resize(10);
*reinterpret_cast<uint64_t*>(const_cast<char*>(header.data() + 2)) = bswap64(message.size());
} else if (message.size() > 0x7D) {
header.push_back(0x7E);
header.resize(4);
*reinterpret_cast<uint16_t*>(const_cast<char*>(header.data() + 2)) = bswap16(message.size());
} else {
header.push_back(message.size());
}
struct evbuffer* out_buf = bufferevent_get_output(bev);
evbuffer_add(out_buf, header.data(), header.size());
evbuffer_add(out_buf, message.data(), message.size());
}
void HTTPServer::send_websocket_message(shared_ptr<WebsocketClient> c, const string& message, uint8_t opcode) {
this->send_websocket_message(c->bev, message, opcode);
}
void HTTPServer::handle_websocket_message(shared_ptr<WebsocketClient>, uint8_t, const string&) {
// Currently we just ignore any messages from the client
}
void HTTPServer::handle_websocket_disconnect(shared_ptr<WebsocketClient> c) {
this->rare_drop_subscribers.erase(c);
}
void HTTPServer::send_rare_drop_notification(shared_ptr<const JSON> message) {
forward_to_event_thread(this->base, [this, message]() -> void {
if (this->rare_drop_subscribers.empty()) {
return;
}
string serialized = message->serialize();
for (const auto& c : this->rare_drop_subscribers) {
this->send_websocket_message(c, serialized);
}
});
}
void HTTPServer::dispatch_handle_request(struct evhttp_request* req, void* ctx) { void HTTPServer::dispatch_handle_request(struct evhttp_request* req, void* ctx) {
reinterpret_cast<HTTPServer*>(ctx)->handle_request(req); reinterpret_cast<HTTPServer*>(ctx)->handle_request(req);
} }
@@ -220,6 +446,7 @@ JSON HTTPServer::generate_quest_json_st(shared_ptr<const Quest> q) {
{"Number", q->quest_number}, {"Number", q->quest_number},
{"Episode", name_for_episode(q->episode)}, {"Episode", name_for_episode(q->episode)},
{"Joinable", q->joinable}, {"Joinable", q->joinable},
{"LockStatusRegister", (q->lock_status_register >= 0) ? q->lock_status_register : JSON(nullptr)},
{"Name", q->name}, {"Name", q->name},
{"BattleRules", std::move(battle_rules_json)}, {"BattleRules", std::move(battle_rules_json)},
{"ChallengeTemplateIndex", std::move(challenge_template_index_json)}, {"ChallengeTemplateIndex", std::move(challenge_template_index_json)},
@@ -566,6 +793,7 @@ JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared_ptr<co
ret.emplace("Name", l->name); ret.emplace("Name", l->name);
ret.emplace("RandomSeed", l->random_seed); ret.emplace("RandomSeed", l->random_seed);
if (l->episode != Episode::EP3) { if (l->episode != Episode::EP3) {
ret.emplace("QuestSelectionInProgress", l->check_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS));
ret.emplace("QuestInProgress", l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS)); ret.emplace("QuestInProgress", l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS));
ret.emplace("JoinableQuestInProgress", l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS)); ret.emplace("JoinableQuestInProgress", l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS));
auto variations_json = JSON::list(); auto variations_json = JSON::list();
@@ -577,6 +805,7 @@ JSON HTTPServer::generate_lobby_json_st(shared_ptr<const Lobby> l, shared_ptr<co
ret.emplace("Mode", name_for_mode(l->mode)); ret.emplace("Mode", name_for_mode(l->mode));
ret.emplace("Difficulty", name_for_difficulty(l->difficulty)); ret.emplace("Difficulty", name_for_difficulty(l->difficulty));
ret.emplace("BaseEXPMultiplier", l->base_exp_multiplier); ret.emplace("BaseEXPMultiplier", l->base_exp_multiplier);
ret.emplace("EXPShareMultiplier", l->exp_share_multiplier);
ret.emplace("AllowedDropModes", l->allowed_drop_modes); ret.emplace("AllowedDropModes", l->allowed_drop_modes);
switch (l->drop_mode) { switch (l->drop_mode) {
case Lobby::DropMode::DISABLED: case Lobby::DropMode::DISABLED:
@@ -748,9 +977,11 @@ JSON HTTPServer::generate_game_server_clients_json() const {
JSON HTTPServer::generate_proxy_server_clients_json() const { JSON HTTPServer::generate_proxy_server_clients_json() const {
return call_on_event_thread<JSON>(this->state->base, [&]() { return call_on_event_thread<JSON>(this->state->base, [&]() {
JSON res = JSON::list(); JSON res = JSON::list();
if (this->state->proxy_server) {
for (const auto& it : this->state->proxy_server->all_sessions()) { for (const auto& it : this->state->proxy_server->all_sessions()) {
res.emplace_back(this->generate_proxy_client_json_st(it.second)); res.emplace_back(this->generate_proxy_client_json_st(it.second));
} }
}
return res; return res;
}); });
} }
@@ -775,7 +1006,7 @@ JSON HTTPServer::generate_server_info_json() const {
{"LobbyCount", lobby_count}, {"LobbyCount", lobby_count},
{"GameCount", game_count}, {"GameCount", game_count},
{"ClientCount", this->state->channel_to_client.size()}, {"ClientCount", this->state->channel_to_client.size()},
{"ProxySessionCount", this->state->proxy_server->num_sessions()}, {"ProxySessionCount", this->state->proxy_server ? this->state->proxy_server->num_sessions() : 0},
{"ServerName", this->state->name}, {"ServerName", this->state->name},
}); });
}); });
@@ -812,6 +1043,7 @@ JSON HTTPServer::generate_summary_json() const {
} }
auto proxy_clients_json = JSON::list(); auto proxy_clients_json = JSON::list();
if (this->state->proxy_server) {
for (const auto& it : this->state->proxy_server->all_sessions()) { for (const auto& it : this->state->proxy_server->all_sessions()) {
proxy_clients_json.emplace_back(JSON::dict({ proxy_clients_json.emplace_back(JSON::dict({
{"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)}, {"AccountID", it.second->login ? it.second->login->account->account_id : JSON(nullptr)},
@@ -820,6 +1052,7 @@ JSON HTTPServer::generate_summary_json() const {
{"Language", name_for_language_code(it.second->language())}, {"Language", name_for_language_code(it.second->language())},
})); }));
} }
}
auto games_json = JSON::list(); auto games_json = JSON::list();
for (const auto& it : this->state->id_to_lobby) { for (const auto& it : this->state->id_to_lobby) {
@@ -841,6 +1074,7 @@ JSON HTTPServer::generate_summary_json() const {
game_json.emplace("MapNumber", (ep3s && ep3s->last_chosen_map) ? ep3s->last_chosen_map->map_number : JSON(nullptr)); game_json.emplace("MapNumber", (ep3s && ep3s->last_chosen_map) ? ep3s->last_chosen_map->map_number : JSON(nullptr));
game_json.emplace("Rules", (ep3s && ep3s->map_and_rules) ? ep3s->map_and_rules->rules.json() : nullptr); game_json.emplace("Rules", (ep3s && ep3s->map_and_rules) ? ep3s->map_and_rules->rules.json() : nullptr);
} else { } else {
game_json.emplace("QuestSelectionInProgress", l->check_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS));
game_json.emplace("QuestInProgress", l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS)); game_json.emplace("QuestInProgress", l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS));
game_json.emplace("JoinableQuestInProgress", l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS)); game_json.emplace("JoinableQuestInProgress", l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS));
game_json.emplace("SectionID", name_for_section_id(l->effective_section_id())); game_json.emplace("SectionID", name_for_section_id(l->effective_section_id()));
@@ -952,11 +1186,23 @@ void HTTPServer::handle_request(struct evhttp_request* req) {
"/y/proxy-clients", "/y/proxy-clients",
"/y/lobbies", "/y/lobbies",
"/y/server", "/y/server",
"/y/rare-drops/stream",
"/y/summary", "/y/summary",
"/y/all", "/y/all",
}); });
ret = make_shared<JSON>(JSON::dict({{"endpoints", std::move(endpoints_json)}})); ret = make_shared<JSON>(JSON::dict({{"endpoints", std::move(endpoints_json)}}));
} else if (uri == "/y/rare-drops/stream") {
auto c = this->enable_websockets(req);
if (!c) {
throw http_error(400, "this path requires a websocket connection");
} else {
this->rare_drop_subscribers.emplace(c);
auto version_message = JSON::dict({{"ServerType", "newserv"}});
this->send_websocket_message(c, version_message.serialize());
return;
}
} else if (uri == "/y/data/ep3-cards") { } else if (uri == "/y/data/ep3-cards") {
ret = make_shared<JSON>(this->generate_ep3_cards_json(false)); ret = make_shared<JSON>(this->generate_ep3_cards_json(false));
} else if (uri == "/y/data/ep3-cards-trial") { } else if (uri == "/y/data/ep3-cards-trial") {
+38
View File
@@ -28,6 +28,8 @@ public:
void schedule_stop(); void schedule_stop();
void wait_for_stop(); void wait_for_stop();
void send_rare_drop_notification(std::shared_ptr<const JSON> message);
protected: protected:
class http_error : public std::runtime_error { class http_error : public std::runtime_error {
public: public:
@@ -35,11 +37,47 @@ protected:
int code; int code;
}; };
struct WebsocketClient {
struct evhttp_connection* conn;
struct bufferevent* bev;
uint8_t pending_opcode;
std::string pending_data;
uint64_t last_communication_time;
void* context;
WebsocketClient(struct evhttp_connection* conn);
~WebsocketClient();
void reset_pending_frame();
};
std::shared_ptr<ServerState> state; std::shared_ptr<ServerState> state;
std::shared_ptr<struct event_base> base; std::shared_ptr<struct event_base> base;
std::shared_ptr<struct evhttp> http; std::shared_ptr<struct evhttp> http;
std::thread th; std::thread th;
std::unordered_set<std::shared_ptr<WebsocketClient>> rare_drop_subscribers;
std::unordered_map<struct bufferevent*, std::shared_ptr<WebsocketClient>> bev_to_websocket_client;
std::shared_ptr<WebsocketClient> enable_websockets(struct evhttp_request* req);
static void dispatch_on_websocket_read(struct bufferevent* bev, void* ctx);
static void dispatch_on_websocket_error(struct bufferevent* bev, short events, void* ctx);
void on_websocket_read(struct bufferevent* bev);
void on_websocket_error(struct bufferevent* bev, short events);
void disconnect_websocket_client(struct bufferevent* bev);
void send_websocket_message(struct bufferevent* bev, const std::string& message, uint8_t opcode = 0x01);
void send_websocket_message(std::shared_ptr<WebsocketClient> c, const std::string& message, uint8_t opcode = 0x01);
virtual void handle_websocket_message(std::shared_ptr<WebsocketClient> c, uint8_t opcode, const std::string& message);
virtual void handle_websocket_disconnect(std::shared_ptr<WebsocketClient> c);
void thread_fn(); void thread_fn();
static void dispatch_handle_request(struct evhttp_request* req, void* ctx); static void dispatch_handle_request(struct evhttp_request* req, void* ctx);
+21 -21
View File
@@ -337,31 +337,19 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
throw runtime_error("invalid expression"); throw runtime_error("invalid expression");
} }
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for binary operators at the root level // Check for binary operators at the root level
using BinType = BinaryOperatorNode::Type; using BinType = BinaryOperatorNode::Type;
static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = { static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = {
{{make_pair("*", BinType::MULTIPLY)}, {make_pair("/", BinType::DIVIDE)}, {make_pair("%", BinType::MODULUS)}},
{{make_pair("+", BinType::ADD)}, {make_pair("-", BinType::SUBTRACT)}},
{{make_pair("<<", BinType::LEFT_SHIFT)}, {make_pair(">>", BinType::RIGHT_SHIFT)}},
{{make_pair("<=", BinType::LESS_OR_EQUAL)}, {make_pair(">=", BinType::GREATER_OR_EQUAL)}, {make_pair("<", BinType::LESS_THAN)}, {make_pair(">", BinType::GREATER_THAN)}},
{{make_pair("==", BinType::EQUAL)}, {make_pair("!=", BinType::NOT_EQUAL)}},
{{make_pair("&", BinType::BITWISE_AND)}},
{{make_pair("^", BinType::BITWISE_XOR)}},
{{make_pair("|", BinType::BITWISE_OR)}},
{{make_pair("&&", BinType::LOGICAL_AND)}},
{{make_pair("||", BinType::LOGICAL_OR)}}, {{make_pair("||", BinType::LOGICAL_OR)}},
{{make_pair("&&", BinType::LOGICAL_AND)}},
{{make_pair("|", BinType::BITWISE_OR)}},
{{make_pair("^", BinType::BITWISE_XOR)}},
{{make_pair("&", BinType::BITWISE_AND)}},
{{make_pair("==", BinType::EQUAL)}, {make_pair("!=", BinType::NOT_EQUAL)}},
{{make_pair("<=", BinType::LESS_OR_EQUAL)}, {make_pair(">=", BinType::GREATER_OR_EQUAL)}, {make_pair("<", BinType::LESS_THAN)}, {make_pair(">", BinType::GREATER_THAN)}},
{{make_pair("<<", BinType::LEFT_SHIFT)}, {make_pair(">>", BinType::RIGHT_SHIFT)}},
{{make_pair("+", BinType::ADD)}, {make_pair("-", BinType::SUBTRACT)}},
{{make_pair("*", BinType::MULTIPLY)}, {make_pair("/", BinType::DIVIDE)}, {make_pair("%", BinType::MODULUS)}},
}; };
for (const auto& operators : binary_operator_levels) { for (const auto& operators : binary_operator_levels) {
size_t paren_level = 0; size_t paren_level = 0;
@@ -392,6 +380,18 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
} }
} }
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for env lookups // Check for env lookups
if (text.starts_with("F_")) { if (text.starts_with("F_")) {
char* endptr = nullptr; char* endptr = nullptr;
+86 -77
View File
@@ -7,6 +7,17 @@
using namespace std; using namespace std;
// The favored weapon type table is hardcoded in the game client. The table is:
// Viridia shots
// Greennill rifles
// Skyly swords
// Bluefull partisans
// Purplenum mechguns
// Pinkal canes
// Redria (none)
// Oran daggers
// Yellowboze (none)
// Whitill slicers
static const array<uint8_t, 10> favored_weapon_by_section_id = { static const array<uint8_t, 10> favored_weapon_by_section_id = {
0x09, 0x07, 0x02, 0x04, 0x08, 0x0A, 0xFF, 0x03, 0xFF, 0x05}; 0x09, 0x07, 0x02, 0x04, 0x08, 0x0A, 0xFF, 0x03, 0xFF, 0x05};
@@ -472,7 +483,7 @@ void ItemCreator::deduplicate_weapon_bonuses(ItemData& item) const {
void ItemCreator::set_item_kill_count_if_unsealable(ItemData& item) const { void ItemCreator::set_item_kill_count_if_unsealable(ItemData& item) const {
if (this->item_parameter_table->is_unsealable_item(item)) { if (this->item_parameter_table->is_unsealable_item(item)) {
this->log.info("Item is unsealable; setting kill count to zero"); this->log.info("Item is unsealable; setting kill count to zero");
item.set_sealed_item_kill_count(0); item.set_kill_count(0);
} }
} }
@@ -1439,78 +1450,78 @@ vector<ItemData> ItemCreator::generate_weapon_shop_contents(size_t player_level)
} else { } else {
static const vector<pair<uint8_t, uint8_t>> defs({ static const vector<pair<uint8_t, uint8_t>> defs({
{0x01, 0x00}, /* 00 */ {0x01, 0x00},
{0x01, 0x01}, /* 01 */ {0x01, 0x01},
{0x01, 0x02}, /* 02 */ {0x01, 0x02},
{0x01, 0x03}, /* 03 */ {0x01, 0x03},
{0x01, 0x04}, /* 04 */ {0x01, 0x04},
{0x03, 0x00}, /* 05 */ {0x03, 0x00},
{0x03, 0x01}, /* 06 */ {0x03, 0x01},
{0x03, 0x02}, /* 07 */ {0x03, 0x02},
{0x03, 0x03}, /* 08 */ {0x03, 0x03},
{0x03, 0x04}, /* 09 */ {0x03, 0x04},
{0x02, 0x00}, /* 0A */ {0x02, 0x00},
{0x02, 0x01}, /* 0B */ {0x02, 0x01},
{0x02, 0x02}, /* 0C */ {0x02, 0x02},
{0x02, 0x03}, /* 0D */ {0x02, 0x03},
{0x02, 0x04}, /* 0E */ {0x02, 0x04},
{0x05, 0x00}, /* 0F */ {0x05, 0x00},
{0x05, 0x01}, /* 10 */ {0x05, 0x01},
{0x05, 0x02}, /* 11 */ {0x05, 0x02},
{0x05, 0x03}, /* 12 */ {0x05, 0x03},
{0x05, 0x04}, /* 13 */ {0x05, 0x04},
{0x04, 0x00}, /* 14 */ {0x04, 0x00},
{0x04, 0x01}, /* 15 */ {0x04, 0x01},
{0x04, 0x02}, /* 16 */ {0x04, 0x02},
{0x04, 0x03}, /* 17 */ {0x04, 0x03},
{0x04, 0x04}, /* 18 */ {0x04, 0x04},
{0x06, 0x00}, /* 19 */ {0x06, 0x00},
{0x06, 0x01}, /* 1A */ {0x06, 0x01},
{0x06, 0x02}, /* 1B */ {0x06, 0x02},
{0x06, 0x03}, /* 1C */ {0x06, 0x03},
{0x06, 0x04}, /* 1D */ {0x06, 0x04},
{0x07, 0x00}, /* 1E */ {0x07, 0x00},
{0x07, 0x01}, /* 1F */ {0x07, 0x01},
{0x07, 0x02}, /* 20 */ {0x07, 0x02},
{0x07, 0x03}, /* 21 */ {0x07, 0x03},
{0x07, 0x04}, /* 22 */ {0x07, 0x04},
{0x08, 0x00}, /* 23 */ {0x08, 0x00},
{0x08, 0x01}, /* 24 */ {0x08, 0x01},
{0x08, 0x02}, /* 25 */ {0x08, 0x02},
{0x08, 0x03}, /* 26 */ {0x08, 0x03},
{0x08, 0x04}, /* 27 */ {0x08, 0x04},
{0x09, 0x00}, /* 28 */ {0x09, 0x00},
{0x09, 0x01}, /* 29 */ {0x09, 0x01},
{0x09, 0x02}, /* 2A */ {0x09, 0x02},
{0x09, 0x03}, /* 2B */ {0x09, 0x03},
{0x09, 0x04}, /* 2C */ {0x09, 0x04},
{0x0A, 0x00}, /* 2D */ {0x0A, 0x00},
{0x0A, 0x01}, /* 2E */ {0x0A, 0x01},
{0x0A, 0x02}, /* 2F */ {0x0A, 0x02},
{0x0A, 0x03}, /* 30 */ {0x0A, 0x03},
{0x0B, 0x00}, /* 31 */ {0x0B, 0x00},
{0x0B, 0x01}, /* 32 */ {0x0B, 0x01},
{0x0B, 0x02}, /* 33 */ {0x0B, 0x02},
{0x0B, 0x03}, /* 34 */ {0x0B, 0x03},
{0x0C, 0x00}, /* 35 */ {0x0C, 0x00},
{0x0C, 0x01}, /* 36 */ {0x0C, 0x01},
{0x0C, 0x02}, /* 37 */ {0x0C, 0x02},
{0x0C, 0x03}, /* 38 */ {0x0C, 0x03},
{0xFF, 0xFF}, /* 39 */ {0xFF, 0xFF}, // Special-cased above
{0xFF, 0xFF}, /* 3A */ {0xFF, 0xFF}, // Special-cased above
{0x01, 0x05}, /* 3B */ {0x01, 0x05},
{0x02, 0x05}, /* 3C */ {0x02, 0x05},
{0x06, 0x05}, /* 3D */ {0x06, 0x05},
{0x08, 0x05}, /* 3E */ {0x08, 0x05},
{0x0A, 0x04}, /* 3F */ {0x0A, 0x04},
{0x0C, 0x04}, /* 40 */ {0x0C, 0x04},
{0x0B, 0x04}, /* 41 */ {0x0B, 0x04},
{0x01, 0x06}, /* 42 */ {0x01, 0x06},
{0x03, 0x05}, /* 43 */ {0x03, 0x05},
{0x07, 0x05}, /* 44 */ {0x07, 0x05},
{0x0A, 0x05}, /* 45 */ {0x0A, 0x05},
{0x0C, 0x05}, /* 46 */ {0x0C, 0x05},
{0x0B, 0x05}, /* 47 */ {0x0B, 0x05},
}); });
const auto& def = defs.at(which); const auto& def = defs.at(which);
item.data1[0] = 0; item.data1[0] = 0;
@@ -1556,10 +1567,8 @@ void ItemCreator::generate_weapon_shop_item_grind(ItemData& item, size_t player_
? this->weapon_random_set->get_favored_grind_range(table_index) ? this->weapon_random_set->get_favored_grind_range(table_index)
: this->weapon_random_set->get_standard_grind_range(table_index); : this->weapon_random_set->get_standard_grind_range(table_index);
const auto& weapon_def = this->item_parameter_table->get_weapon( const auto& weapon_def = this->item_parameter_table->get_weapon(item.data1[1], item.data1[2]);
item.data1[1], item.data1[2]); item.data1[3] = clamp<uint8_t>(this->rand_int(range->max + 1), range->min, weapon_def.max_grind);
item.data1[3] = clamp<uint8_t>(
this->rand_int(range->max + 1), range->min, weapon_def.max_grind);
} }
void ItemCreator::generate_weapon_shop_item_special(ItemData& item, size_t player_level) { void ItemCreator::generate_weapon_shop_item_special(ItemData& item, size_t player_level) {
+18
View File
@@ -83,6 +83,24 @@ private:
// Note: The original implementation uses 17 different random states for some // Note: The original implementation uses 17 different random states for some
// reason. We forego that and use only one for simplicity. // reason. We forego that and use only one for simplicity.
// Originally, the 17 random states were used for:
// [0x00] - drop-anything rate check
// [0x01] - common item class check
// [0x02] - get_rand_from_weighted_tables16 determinants
// [0x03] - get_rand_from_weighted_tables8 determinants
// [0x04] - tech disk levels
// [0x05] - meseta amounts
// [0x06] - rare drop rate check
// [0x07] - rare weapon special table index
// [0x08] - apparently unused
// [0x09] - whether to generate a common weapon special
// [0x0A] - number of stars for common weapon special
// [0x0B] - unit modifiers
// [0x0C] - common armor DFP bonuses
// [0x0D] - common armor EVP bonuses
// [0x0E] - apparently unused
// [0x0F] - which common weapon special to generate
// [0x10] - apparently unused
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt; std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
bool are_rare_drops_allowed() const; bool are_rare_drops_allowed() const;
+13 -4
View File
@@ -431,7 +431,10 @@ void ItemData::decode_for_version(Version from_version) {
} }
void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParameterTable> item_parameter_table) { 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)) && (to_version != Version::GC_NTE) && !this->has_encoded_v2_data(); bool should_encode_v2_data = item_parameter_table &&
(is_v1(to_version) || is_v2(to_version)) &&
(to_version != Version::GC_NTE) &&
!this->has_encoded_v2_data();
switch (this->data1[0]) { switch (this->data1[0]) {
case 0x00: case 0x00:
@@ -534,11 +537,16 @@ bool ItemData::has_encoded_v2_data() const {
: (this->get_encoded_v2_data() != 0); : (this->get_encoded_v2_data() != 0);
} }
uint16_t ItemData::get_sealed_item_kill_count() const { bool ItemData::has_kill_count() const {
return ((this->data1[10] << 8) | this->data1[11]) & 0x7FFF; return !this->is_s_rank_weapon() && (this->data1[10] & 0x80);
} }
void ItemData::set_sealed_item_kill_count(uint16_t v) { uint16_t ItemData::get_kill_count() const {
return this->has_kill_count() ? (((this->data1[10] << 8) | this->data1[11]) & 0x7FFF) : 0;
}
void ItemData::set_kill_count(uint16_t v) {
if (!this->is_s_rank_weapon()) {
if (v > 0x7FFF) { if (v > 0x7FFF) {
this->data1w[5] = 0xFFFF; this->data1w[5] = 0xFFFF;
} else { } else {
@@ -546,6 +554,7 @@ void ItemData::set_sealed_item_kill_count(uint16_t v) {
this->data1[11] = v; this->data1[11] = v;
} }
} }
}
uint8_t ItemData::get_tool_item_amount(const StackLimits& limits) const { uint8_t ItemData::get_tool_item_amount(const StackLimits& limits) const {
return this->is_stackable(limits) ? this->data1[5] : 1; return this->is_stackable(limits) ? this->data1[5] : 1;
+4 -2
View File
@@ -84,6 +84,7 @@ struct ItemData {
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV // Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
// Tool: 03ZZZZFF 00CC0000 00000000 00000000 // Tool: 03ZZZZFF 00CC0000 00000000 00000000
// Meseta: 04000000 00000000 00000000 MMMMMMMM // Meseta: 04000000 00000000 00000000 MMMMMMMM
// 01034D00 00000000 204E0000
// A = attribute type (for S-ranks, custom name) // A = attribute type (for S-ranks, custom name)
// B = attribute amount (for S-ranks, custom name) // B = attribute amount (for S-ranks, custom name)
// C = stack size (for tools) // C = stack size (for tools)
@@ -173,8 +174,9 @@ struct ItemData {
uint8_t get_encoded_v2_data() const; uint8_t get_encoded_v2_data() const;
bool has_encoded_v2_data() const; bool has_encoded_v2_data() const;
uint16_t get_sealed_item_kill_count() const; bool has_kill_count() const;
void set_sealed_item_kill_count(uint16_t v); uint16_t get_kill_count() const;
void set_kill_count(uint16_t v);
uint8_t get_tool_item_amount(const StackLimits& limits) const; uint8_t get_tool_item_amount(const StackLimits& limits) const;
void set_tool_item_amount(const StackLimits& limits, uint8_t amount); void set_tool_item_amount(const StackLimits& limits, uint8_t amount);
int16_t get_armor_or_shield_defense_bonus() const; int16_t get_armor_or_shield_defense_bonus() const;
+11 -7
View File
@@ -208,7 +208,10 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
if (which == 0) { if (which == 0) {
continue; continue;
} }
if (which > 5) { if (which & 0x80) {
uint16_t kill_count = ((which << 8) & 0x7F00) | (value & 0xFF);
ret_tokens.emplace_back(string_printf("K:%hu", kill_count));
} else if (which > 5) {
ret_tokens.emplace_back(string_printf("!PC:%02hhX%02hhX", which, value)); ret_tokens.emplace_back(string_printf("!PC:%02hhX%02hhX", which, value));
} else { } else {
bonuses[which - 1] = value; bonuses[which - 1] = value;
@@ -217,13 +220,14 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
if (!bonuses.is_filled_with(0)) { if (!bonuses.is_filled_with(0)) {
bool should_include_hit = (bonuses[4] != 0); bool should_include_hit = (bonuses[4] != 0);
bool should_highlight_hit = include_color_escapes && (bonuses[4] > 0); bool should_highlight_hit = include_color_escapes && (bonuses[4] > 0);
const char* color_prefix = include_color_escapes ? "$C7" : "";
if (should_include_hit) { if (should_include_hit) {
ret_tokens.emplace_back(string_printf("%hhd/%hhd/%hhd/%hhd/%s%hhd", ret_tokens.emplace_back(string_printf("%s%hhd/%hhd/%hhd/%hhd/%s%hhd",
bonuses[0], bonuses[1], bonuses[2], bonuses[3], color_prefix, bonuses[0], bonuses[1], bonuses[2], bonuses[3],
(should_highlight_hit ? "$CG" : ""), bonuses[4])); (should_highlight_hit ? "$C6" : ""), bonuses[4]));
} else { } else {
ret_tokens.emplace_back(string_printf("%hhd/%hhd/%hhd/%hhd", ret_tokens.emplace_back(string_printf("%s%hhd/%hhd/%hhd/%hhd",
bonuses[0], bonuses[1], bonuses[2], bonuses[3])); color_prefix, bonuses[0], bonuses[1], bonuses[2], bonuses[3]));
} }
} }
} }
@@ -848,7 +852,7 @@ void ItemNameIndex::print_table(FILE* stream) const {
t.amount.load(), t.amount.load(),
t.tech.load(), t.tech.load(),
t.cost.load(), t.cost.load(),
t.item_flag.load(), t.item_flags.load(),
stars, stars,
divisor_str.c_str(), divisor_str.c_str(),
name.c_str()); name.c_str());
+3 -3
View File
@@ -397,7 +397,7 @@ ItemParameterTable::ToolV4 ItemParameterTable::ToolV1V2::to_v4() const {
ret.amount = this->amount; ret.amount = this->amount;
ret.tech = this->tech; ret.tech = this->tech;
ret.cost = this->cost; ret.cost = this->cost;
ret.item_flag = this->item_flag; ret.item_flags = this->item_flags;
return ret; return ret;
} }
@@ -410,7 +410,7 @@ ItemParameterTable::ToolV4 ItemParameterTable::ToolV3T<IsBigEndian>::to_v4() con
ret.amount = this->amount.load(); ret.amount = this->amount.load();
ret.tech = this->tech.load(); ret.tech = this->tech.load();
ret.cost = this->cost.load(); ret.cost = this->cost.load();
ret.item_flag = this->item_flag.load(); ret.item_flags = this->item_flags.load();
return ret; return ret;
} }
@@ -1008,7 +1008,7 @@ uint8_t ItemParameterTable::get_item_base_stars(const ItemData& item) const {
const auto& def = (item.data1[1] == 2) const auto& def = (item.data1[1] == 2)
? this->get_tool(2, item.data1[4]) ? this->get_tool(2, item.data1[4])
: this->get_tool(item.data1[1], item.data1[2]); : this->get_tool(item.data1[1], item.data1[2]);
return (def.item_flag & 0x80) ? 12 : 0; return (def.item_flags & 0x80) ? 12 : 0;
} else { } else {
return 0; return 0;
} }
+10 -1
View File
@@ -341,7 +341,16 @@ public:
/* 04 */ U16T amount = 0; /* 04 */ U16T amount = 0;
/* 06 */ U16T tech = 0; /* 06 */ U16T tech = 0;
/* 08 */ S32T cost = 0; /* 08 */ S32T cost = 0;
/* 0C */ U32T item_flag = 0; // Bits in item_flags:
// 00000001 - ever usable by player ("Use" appears in inventory menu)
// 00000002 - unknown
// 00000004 - unknown
// 00000008 - usable by android characters
// 00000010 - usable in Pioneer 2 / Lab
// 00000020 - usable in boss arenas
// 00000040 - usable in Challenge mode
// 00000080 - is rare (renders as red box; V3+)
/* 0C */ U32T item_flags = 0;
/* 10 */ /* 10 */
} __packed__; } __packed__;
+15 -12
View File
@@ -12,7 +12,8 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
// On PC (and presumably DC), the client sends a 6x29 after this to delete the // On PC (and presumably DC), the client sends a 6x29 after this to delete the
// used item. On GC and later versions, this does not happen, so we should // used item. On GC and later versions, this does not happen, so we should
// delete the item here. // delete the item here.
bool is_v3_or_later = is_v3(c->version()) || is_v4(c->version()); bool is_v4 = ::is_v4(c->version());
bool is_v3_or_later = is_v3(c->version()) || is_v4;
bool should_delete_item = is_v3_or_later; bool should_delete_item = is_v3_or_later;
auto player = c->character(); auto player = c->character();
@@ -36,20 +37,14 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
} }
auto& weapon = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::WEAPON)]; auto& weapon = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::WEAPON)];
// Don't enforce the weapon's grind limit on V1 and V2. This is necessary // Only enforce grind limits on BB, since the server doesn't have direct
// because the V2 client replaces its inventory items on the fly with items // control over players' inventories on other versions
// compatible with V1 when sending the 61 and 98 commands. There appears to
// be no way to disable this behavior, so there's no way for the server to
// get an accurate picture of what's actually in the player's inventory, so
// there's no way to know if we would be enforcing the correct grind limit.
if (is_v3_or_later) {
auto item_parameter_table = s->item_parameter_table(c->version()); auto item_parameter_table = s->item_parameter_table(c->version());
auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]); auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]);
if (weapon.data.data1[3] >= weapon_def.max_grind) { if (is_v4 && (weapon.data.data1[3] >= weapon_def.max_grind)) {
throw runtime_error("weapon already at maximum grind"); throw runtime_error("weapon already at maximum grind");
} }
} weapon.data.data1[3] = min<uint8_t>(weapon.data.data1[3] + item.data.data1[2] + 1, weapon_def.max_grind);
weapon.data.data1[3] += (item.data.data1[2] + 1);
} else if ((primary_identifier & 0xFFFF0000) == 0x030B0000) { // Material } else if ((primary_identifier & 0xFFFF0000) == 0x030B0000) { // Material
auto p = c->character(); auto p = c->character();
@@ -119,21 +114,25 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
} else if (primary_identifier == 0x00330000) { } else if (primary_identifier == 0x00330000) {
// Unseal Sealed J-Sword => Tsumikiri J-Sword // Unseal Sealed J-Sword => Tsumikiri J-Sword
item.data.data1[1] = 0x32; item.data.data1[1] = 0x32;
item.flags &= (~8); // Unequip it
should_delete_item = false; should_delete_item = false;
} else if (primary_identifier == 0x00AB0000) { } else if (primary_identifier == 0x00AB0000) {
// Unseal Lame d'Argent => Excalibur // Unseal Lame d'Argent => Excalibur
item.data.data1[1] = 0xAC; item.data.data1[1] = 0xAC;
item.flags &= (~8); // Unequip it
should_delete_item = false; should_delete_item = false;
} else if (primary_identifier == 0x01034D00) { } else if (primary_identifier == 0x01034D00) {
// Unseal Limiter => Adept // Unseal Limiter => Adept
item.data.data1[2] = 0x4E; item.data.data1[2] = 0x4E;
item.flags &= (~8); // Unequip it
should_delete_item = false; should_delete_item = false;
} else if (primary_identifier == 0x01034F00) { } else if (primary_identifier == 0x01034F00) {
// Unseal Swordsman Lore => Proof of Sword-Saint // Unseal Swordsman Lore => Proof of Sword-Saint
item.data.data1[2] = 0x50; item.data.data1[2] = 0x50;
item.flags &= (~8); // Unequip it
should_delete_item = false; should_delete_item = false;
} else if (primary_identifier == 0x030C0000) { } else if (primary_identifier == 0x030C0000) {
@@ -239,9 +238,13 @@ void player_use_item(shared_ptr<Client> c, size_t item_index, shared_ptr<PSOLFGE
inv_item.data.data1[0] = combo.result_item[0]; inv_item.data.data1[0] = combo.result_item[0];
inv_item.data.data1[1] = combo.result_item[1]; inv_item.data.data1[1] = combo.result_item[1];
// For mags, don't reset level + PBs + stats
if (inv_item.data.data1[0] != 0x02) {
inv_item.data.data1[2] = combo.result_item[2]; inv_item.data.data1[2] = combo.result_item[2];
inv_item.data.data1[3] = 0; // Grind inv_item.data.data1[3] = 0; // Grind
inv_item.data.data1[4] = 0; // Flags + special inv_item.data.data1[4] = 0; // Flags + special
}
inv_item.flags &= (~8); // Unequip it
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
} }
@@ -343,7 +346,7 @@ void apply_mag_feed_result(
if (evolution_number < 2) { if (evolution_number < 2) {
uint16_t flags = mag_item.compute_mag_strength_flags(); uint16_t flags = mag_item.compute_mag_strength_flags();
if (mag_number == 0x0D) { if (mag_number == 0x0D) {
if ((flags & 0x110) == 0) { if (flags & 0x110) {
mag_item.data1[1] = 0x02; mag_item.data1[1] = 0x02;
} else if (flags & 8) { } else if (flags & 8) {
mag_item.data1[1] = 0x03; mag_item.data1[1] = 0x03;
+14 -2
View File
@@ -149,6 +149,7 @@ Lobby::Lobby(shared_ptr<ServerState> s, uint32_t id, bool is_game)
mode(GameMode::NORMAL), mode(GameMode::NORMAL),
difficulty(0), difficulty(0),
base_exp_multiplier(1), base_exp_multiplier(1),
exp_share_multiplier(0.5),
challenge_exp_multiplier(1.0f), challenge_exp_multiplier(1.0f),
random_seed(random_object<uint32_t>()), random_seed(random_object<uint32_t>()),
drop_mode(DropMode::CLIENT), drop_mode(DropMode::CLIENT),
@@ -504,6 +505,7 @@ void Lobby::create_ep3_server() {
.card_index = is_nte ? s->ep3_card_index_trial : s->ep3_card_index, .card_index = is_nte ? s->ep3_card_index_trial : s->ep3_card_index,
.map_index = s->ep3_map_index, .map_index = s->ep3_map_index,
.behavior_flags = s->ep3_behavior_flags, .behavior_flags = s->ep3_behavior_flags,
.opt_rand_stream = nullptr,
.opt_rand_crypt = this->opt_rand_crypt, .opt_rand_crypt = this->opt_rand_crypt,
.tournament = tourn, .tournament = tourn,
.trap_card_ids = s->ep3_trap_card_ids, .trap_card_ids = s->ep3_trap_card_ids,
@@ -792,10 +794,14 @@ Lobby::JoinError Lobby::join_error_for_client(std::shared_ptr<Client> c, const s
if (this->count_clients() >= this->max_clients) { if (this->count_clients() >= this->max_clients) {
return JoinError::FULL; return JoinError::FULL;
} }
if (!this->version_is_allowed(c->version()) && !c->config.check_flag(Client::Flag::DEBUG_ENABLED)) { bool debug_enabled = c->config.check_flag(Client::Flag::DEBUG_ENABLED);
if (!this->version_is_allowed(c->version()) && !debug_enabled) {
return JoinError::VERSION_CONFLICT; return JoinError::VERSION_CONFLICT;
} }
if (this->is_game()) { if (this->is_game()) {
if (this->check_flag(Flag::QUEST_SELECTION_IN_PROGRESS)) {
return JoinError::QUEST_SELECTION_IN_PROGRESS;
}
if (this->check_flag(Flag::QUEST_IN_PROGRESS)) { if (this->check_flag(Flag::QUEST_IN_PROGRESS)) {
return JoinError::QUEST_IN_PROGRESS; return JoinError::QUEST_IN_PROGRESS;
} }
@@ -805,6 +811,10 @@ Lobby::JoinError Lobby::join_error_for_client(std::shared_ptr<Client> c, const s
if (this->mode == GameMode::SOLO) { if (this->mode == GameMode::SOLO) {
return JoinError::SOLO; return JoinError::SOLO;
} }
if (!debug_enabled &&
(this->check_flag(Flag::IS_CLIENT_CUSTOMIZATION) != c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION))) {
return JoinError::VERSION_CONFLICT;
}
if (!c->login->account->check_flag(Account::Flag::FREE_JOIN_GAMES)) { if (!c->login->account->check_flag(Account::Flag::FREE_JOIN_GAMES)) {
if (password && !this->password.empty() && (*password != this->password)) { if (password && !this->password.empty() && (*password != this->password)) {
return JoinError::INCORRECT_PASSWORD; return JoinError::INCORRECT_PASSWORD;
@@ -967,7 +977,9 @@ bool Lobby::compare_shared(const shared_ptr<const Lobby>& a, const shared_ptr<co
// 5. Difficulty: Normal < Hard < Very Hard < Ultimate // 5. Difficulty: Normal < Hard < Very Hard < Ultimate
// 6. Game name // 6. Game name
static auto get_priority = +[](const shared_ptr<const Lobby>& l) -> size_t { static auto get_priority = +[](const shared_ptr<const Lobby>& l) -> size_t {
if (l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS) || l->check_flag(Lobby::Flag::BATTLE_IN_PROGRESS)) { if (l->check_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS) ||
l->check_flag(Lobby::Flag::QUEST_IN_PROGRESS) ||
l->check_flag(Lobby::Flag::BATTLE_IN_PROGRESS)) {
return 4; return 4;
} }
size_t num_clients = l->count_clients(); size_t num_clients = l->count_clients();
+13 -10
View File
@@ -67,14 +67,16 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
PERSISTENT = 0x00000002, PERSISTENT = 0x00000002,
// Flags used only for games // Flags used only for games
CHEATS_ENABLED = 0x00000100, CHEATS_ENABLED = 0x00000100,
QUEST_IN_PROGRESS = 0x00000200, QUEST_SELECTION_IN_PROGRESS = 0x00000200,
BATTLE_IN_PROGRESS = 0x00000400, QUEST_IN_PROGRESS = 0x00000400,
JOINABLE_QUEST_IN_PROGRESS = 0x00000800, BATTLE_IN_PROGRESS = 0x00000800,
IS_SPECTATOR_TEAM = 0x00002000, // episode must be EP3 also JOINABLE_QUEST_IN_PROGRESS = 0x00001000,
SPECTATORS_FORBIDDEN = 0x00004000, IS_CLIENT_CUSTOMIZATION = 0x00002000,
START_BATTLE_PLAYER_IMMEDIATELY = 0x00008000, IS_SPECTATOR_TEAM = 0x00004000, // .episode must be EP3 also
CANNOT_CHANGE_CHEAT_MODE = 0x00010000, SPECTATORS_FORBIDDEN = 0x00008000,
USE_CREATOR_SECTION_ID = 0x00020000, START_BATTLE_PLAYER_IMMEDIATELY = 0x00010000,
CANNOT_CHANGE_CHEAT_MODE = 0x00020000,
USE_CREATOR_SECTION_ID = 0x00040000,
// Flags used only for lobbies // Flags used only for lobbies
PUBLIC = 0x01000000, PUBLIC = 0x01000000,
DEFAULT = 0x02000000, DEFAULT = 0x02000000,
@@ -89,8 +91,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
SERVER_DUPLICATE = 4, SERVER_DUPLICATE = 4,
}; };
std::weak_ptr<ServerState> std::weak_ptr<ServerState> server_state;
server_state;
PrefixedLogger log; PrefixedLogger log;
uint32_t lobby_id; uint32_t lobby_id;
@@ -121,6 +122,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
GameMode mode; GameMode mode;
uint8_t difficulty; // 0-3 uint8_t difficulty; // 0-3
uint16_t base_exp_multiplier; uint16_t base_exp_multiplier;
float exp_share_multiplier;
float challenge_exp_multiplier; float challenge_exp_multiplier;
std::string password; std::string password;
std::string name; std::string name;
@@ -281,6 +283,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
ALLOWED = 0, ALLOWED = 0,
FULL, FULL,
VERSION_CONFLICT, VERSION_CONFLICT,
QUEST_SELECTION_IN_PROGRESS,
QUEST_IN_PROGRESS, QUEST_IN_PROGRESS,
BATTLE_IN_PROGRESS, BATTLE_IN_PROGRESS,
LOADING, LOADING,
+109 -34
View File
@@ -17,9 +17,9 @@
#include <unordered_map> #include <unordered_map>
#ifdef HAVE_RESOURCE_FILE #ifdef HAVE_RESOURCE_FILE
#include "ARCodeTranslator.hh" #include "AddressTranslator.hh"
#else #else
#include "ARCodeTranslator-Stub.hh" #include "AddressTranslator-Stub.hh"
#endif #endif
#include "BMLArchive.hh" #include "BMLArchive.hh"
#include "CatSession.hh" #include "CatSession.hh"
@@ -681,8 +681,8 @@ static void a_encrypt_decrypt_pc_save_fn(Arguments& args) {
for (size_t z = 0; z < charfile->entries.size(); z++) { for (size_t z = 0; z < charfile->entries.size(); z++) {
if (charfile->entries[z].present) { if (charfile->entries[z].present) {
try { try {
charfile->entries[z].character = decrypt_fixed_size_data_section_t<PSOPCCharacterFile::CharacterEntry::Character, false>( charfile->entries[z].encrypted = decrypt_fixed_size_data_section_t<PSOPCCharacterFile::CharacterEntry::EncryptedSection, false>(
&charfile->entries[z].character, sizeof(charfile->entries[z].character), round1_seed, skip_checksum, override_round2_seed); &charfile->entries[z].encrypted, sizeof(charfile->entries[z].encrypted), round1_seed, skip_checksum, override_round2_seed);
} catch (const exception& e) { } catch (const exception& e) {
fprintf(stderr, "warning: cannot decrypt character %zu: %s\n", z, e.what()); fprintf(stderr, "warning: cannot decrypt character %zu: %s\n", z, e.what());
} }
@@ -691,12 +691,12 @@ static void a_encrypt_decrypt_pc_save_fn(Arguments& args) {
} else { } else {
for (size_t z = 0; z < charfile->entries.size(); z++) { for (size_t z = 0; z < charfile->entries.size(); z++) {
if (charfile->entries[z].present) { if (charfile->entries[z].present) {
string encrypted = encrypt_fixed_size_data_section_t<PSOPCCharacterFile::CharacterEntry::Character, false>( string encrypted = encrypt_fixed_size_data_section_t<PSOPCCharacterFile::CharacterEntry::EncryptedSection, false>(
charfile->entries[z].character, round1_seed); charfile->entries[z].encrypted, round1_seed);
if (encrypted.size() != sizeof(PSOPCCharacterFile::CharacterEntry::Character)) { if (encrypted.size() != sizeof(PSOPCCharacterFile::CharacterEntry::EncryptedSection)) {
throw logic_error("incorrect encrypted result size"); throw logic_error("incorrect encrypted result size");
} }
charfile->entries[z].character = *reinterpret_cast<const PSOPCCharacterFile::CharacterEntry::Character*>(encrypted.data()); charfile->entries[z].encrypted = *reinterpret_cast<const PSOPCCharacterFile::CharacterEntry::EncryptedSection*>(encrypted.data());
} }
} }
} }
@@ -765,7 +765,7 @@ Action a_decrypt_dcv2_executable(
If --simple is given, uses the simpler encryption method used in some\n\ If --simple is given, uses the simpler encryption method used in some\n\
community modifications of the game. In this case, --seed is not required;\n\ community modifications of the game. In this case, --seed is not required;\n\
if not given, finds the seed automatically, and prints it to stderr so you\n\ if not given, finds the seed automatically, and prints it to stderr so you\n\
will be able to use it when re-encrypting.", will be able to use it when re-encrypting.\n",
+[](Arguments& args) { +[](Arguments& args) {
string executable_filename = args.get<string>("executable", true); string executable_filename = args.get<string>("executable", true);
string executable_data = load_file(executable_filename); string executable_data = load_file(executable_filename);
@@ -785,14 +785,14 @@ Action a_decrypt_dcv2_executable(
}); });
Action a_encrypt_dcv2_executable( Action a_encrypt_dcv2_executable(
"encrypt-dcv2-executable", "\ "encrypt-dcv2-executable", "\
decrypt-dcv2-executable --executable=EXEC --indexes=INDEXES\n\ encrypt-dcv2-executable --executable=EXEC --indexes=INDEXES\n\
decrypt-dcv2-executable --executable=EXEC --simple --seed=SEED\n\ encrypt-dcv2-executable --executable=EXEC --simple --seed=SEED\n\
Encrypt a PSO DC v2 executable file. EXEC should be the path to the\n\ Encrypt a PSO DC v2 executable file. EXEC should be the path to the\n\
executable (DP_ADDRESS.JPN) and INDEXES should be the path to the index\n\ executable (DP_ADDRESS.JPN) and INDEXES should be the path to the index\n\
fixup table (KATSUO.SEA). The output is written to EXEC.enc and\n\ fixup table (KATSUO.SEA). The output is written to EXEC.enc and\n\
INDEXES.enc.\n\ INDEXES.enc.\n\
If --simple is given, uses the simpler encryption method used in some\n\ If --simple is given, uses the simpler encryption method used in some\n\
community modifications of the game. In this case, --seed is required.", community modifications of the game. In this case, --seed is required.\n",
+[](Arguments& args) { +[](Arguments& args) {
string executable_filename = args.get<string>("executable", true); string executable_filename = args.get<string>("executable", true);
string executable_data = load_file(executable_filename); string executable_data = load_file(executable_filename);
@@ -1163,9 +1163,9 @@ Action a_disassemble_quest_script(
if (!args.get<bool>("decompressed")) { if (!args.get<bool>("decompressed")) {
data = prs_decompress(data); data = prs_decompress(data);
} }
uint8_t language = args.get<bool>("japanese") ? 0 : 1; uint8_t override_language = args.get<uint8_t>("language", 0xFF);
bool reassembly_mode = args.get<bool>("reassembly"); bool reassembly_mode = args.get<bool>("reassembly");
string result = disassemble_quest_script(data.data(), data.size(), version, language, reassembly_mode); string result = disassemble_quest_script(data.data(), data.size(), version, override_language, reassembly_mode);
write_output_data(args, result.data(), result.size(), "txt"); write_output_data(args, result.data(), result.size(), "txt");
}); });
Action a_disassemble_quest_map( Action a_disassemble_quest_map(
@@ -1237,7 +1237,13 @@ Action a_assemble_quest_script(
uncompressed .bind file instead.\n", uncompressed .bind file instead.\n",
+[](Arguments& args) { +[](Arguments& args) {
string text = read_input_data(args); string text = read_input_data(args);
string result = assemble_quest_script(text);
const string& input_filename = args.get<string>(1, false);
string include_dir = (!input_filename.empty() && (input_filename != "-"))
? dirname(input_filename)
: ".";
string result = assemble_quest_script(text, include_dir);
bool compress = !args.get<bool>("decompressed"); bool compress = !args.get<bool>("decompressed");
if (compress) { if (compress) {
result = prs_compress_optimal(result); result = prs_compress_optimal(result);
@@ -1261,7 +1267,8 @@ Action a_assemble_all_patches(
uint32_t override_start_addr) -> void { uint32_t override_start_addr) -> void {
for (uint8_t encrypted = 0; encrypted < 2; encrypted++) { for (uint8_t encrypted = 0; encrypted < 2; encrypted++) {
StringWriter w; StringWriter w;
string data = prepare_send_function_call_data(code, {}, "", checksum_addr, checksum_size, override_start_addr, encrypted); string data = prepare_send_function_call_data(
code, {}, nullptr, 0, checksum_addr, checksum_size, override_start_addr, encrypted);
w.put(PSOCommandHeaderDCV3{.command = 0xB2, .flag = code->index, .size = data.size() + 4}); w.put(PSOCommandHeaderDCV3{.command = 0xB2, .flag = code->index, .size = data.size() + 4});
w.write(data); w.write(data);
string out_path = code->source_path + (encrypted ? ".enc.bin" : ".std.bin"); string out_path = code->source_path + (encrypted ? ".enc.bin" : ".std.bin");
@@ -1603,6 +1610,42 @@ Action a_convert_rare_item_set(
throw runtime_error("cannot determine output format; use a filename ending with .json, .gsl, .gslb, or .afs"); throw runtime_error("cannot determine output format; use a filename ending with .json, .gsl, .gslb, or .afs");
} }
}); });
Action a_convert_common_item_set(
"convert-common-item-set", "\
convert-common-item-set INPUT-FILENAME [OUTPUT-FILENAME]\n\
Convert the input rare item set to a JSON representation and write it to\n\
OUTPUT-FILENAME or stdout. The input filename must end in one of the\n\
following extensions:\n\
.json (newserv JSON common item table)\n\
.gsl (PSO BB little-endian GSL archive)\n\
.gslb (PSO GC big-endian GSL archive)\n",
+[](Arguments& args) {
string input_filename = args.get<string>(1, false);
if (input_filename.empty() || (input_filename == "-")) {
throw runtime_error("input filename must be given");
}
auto data = make_shared<string>(read_input_data(args));
shared_ptr<CommonItemSet> cs;
if (ends_with(input_filename, ".json")) {
cs = make_shared<JSONCommonItemSet>(JSON::parse(*data));
} else if (ends_with(input_filename, ".gsl")) {
cs = make_shared<GSLV3V4CommonItemSet>(data, args.get<bool>("big-endian"));
} else if (ends_with(input_filename, ".gslb")) {
cs = make_shared<GSLV3V4CommonItemSet>(data, true);
} else {
throw runtime_error("cannot determine input format; use a filename ending with .json, .gsl, .gslb, or .afs");
}
const string& output_filename = args.get<string>(2, false);
if (output_filename.empty()) {
cs->print(stdout);
} else {
auto json = cs->json();
string json_data = json.serialize(JSON::SerializeOption::FORMAT | JSON::SerializeOption::HEX_INTEGERS | JSON::SerializeOption::SORT_DICT_KEYS);
write_output_data(args, json_data.data(), json_data.size(), "json");
}
});
Action a_describe_item( Action a_describe_item(
"describe-item", "\ "describe-item", "\
@@ -2333,21 +2376,13 @@ Action a_dc_serial_number_speed_test(
} }
}); });
Action a_ar_code_translator( Action a_address_translator(
"ar-code-translator", nullptr, +[](Arguments& args) { "address-translator", nullptr, +[](Arguments& args) {
const string& dir = args.get<string>(1, false); const string& dir = args.get<string>(1, false);
if (dir.empty() || (dir == "-")) { if (dir.empty() || (dir == "-")) {
throw invalid_argument("a directory name is required"); throw invalid_argument("a directory name is required");
} }
run_ar_code_translator(dir, args.get<string>(2, false), args.get<string>(3, false)); run_address_translator(dir, args.get<string>(2, false), args.get<string>(3, false));
});
Action a_xbe_patch_translator(
"xbe-patch-translator", nullptr, +[](Arguments& args) {
const string& dir = args.get<string>(1, false);
if (dir.empty() || (dir == "-")) {
throw invalid_argument("a directory name is required");
}
run_xbe_patch_translator(dir, args.get<string>(2, false), args.get<string>(3, false));
}); });
Action a_diff_dol_files( Action a_diff_dol_files(
@@ -2400,6 +2435,7 @@ Action a_replay_ep3_battle_commands(
.card_index = s->ep3_card_index, .card_index = s->ep3_card_index,
.map_index = s->ep3_map_index, .map_index = s->ep3_map_index,
.behavior_flags = 0x0092, .behavior_flags = 0x0092,
.opt_rand_stream = nullptr,
.opt_rand_crypt = (seed >= 0) ? make_shared<PSOV2Encryption>(seed) : nullptr, .opt_rand_crypt = (seed >= 0) ? make_shared<PSOV2Encryption>(seed) : nullptr,
.tournament = nullptr, .tournament = nullptr,
.trap_card_ids = {}, .trap_card_ids = {},
@@ -2426,6 +2462,46 @@ Action a_replay_ep3_battle_commands(
} }
}); });
Action a_replay_ep3_battle_record(
"replay-ep3-battle-record", nullptr, +[](Arguments& args) {
auto rec = make_shared<Episode3::BattleRecord>(read_input_data(args));
auto s = make_shared<ServerState>(get_config_filename(args));
s->load_ep3_cards(false);
s->load_ep3_maps(false);
bool is_trial = (get_cli_version(args, Version::GC_EP3) == Version::GC_EP3_NTE);
Episode3::Server::Options options = {
.card_index = s->ep3_card_index,
.map_index = s->ep3_map_index,
.behavior_flags = (Episode3::BehaviorFlag::IGNORE_CARD_COUNTS |
Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES |
Episode3::BehaviorFlag::DISABLE_MASKING |
Episode3::BehaviorFlag::LOG_COMMANDS_IF_LOBBY_MISSING),
.opt_rand_stream = make_shared<StringReader>(rec->get_random_stream()),
.opt_rand_crypt = nullptr,
.tournament = nullptr,
.trap_card_ids = {},
};
if (is_trial) {
options.behavior_flags |= Episode3::BehaviorFlag::IS_TRIAL_EDITION;
}
options.behavior_flags |= Episode3::BehaviorFlag::LOG_COMMANDS_IF_LOBBY_MISSING;
auto server = make_shared<Episode3::Server>(nullptr, std::move(options));
server->init();
for (const auto& command : rec->get_all_server_data_commands()) {
log_info("Server data command");
print_data(stderr, command, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
server->on_server_data_input(nullptr, command);
}
});
Action a_disassemble_ep3_battle_record(
"disassemble-ep3-battle-record", nullptr, +[](Arguments& args) {
Episode3::BattleRecord(read_input_data(args)).print(stdout);
});
Action a_run_server_replay_log( Action a_run_server_replay_log(
"", nullptr, +[](Arguments& args) { "", nullptr, +[](Arguments& args) {
{ {
@@ -2473,7 +2549,6 @@ Action a_run_server_replay_log(
shared_ptr<ServerShell> shell; shared_ptr<ServerShell> shell;
shared_ptr<ReplaySession> replay_session; shared_ptr<ReplaySession> replay_session;
shared_ptr<HTTPServer> http_server;
if (is_replay) { if (is_replay) {
config_log.info("Starting proxy server"); config_log.info("Starting proxy server");
state->proxy_server = make_shared<ProxyServer>(base, state); state->proxy_server = make_shared<ProxyServer>(base, state);
@@ -2583,10 +2658,10 @@ Action a_run_server_replay_log(
if (!state->http_addresses.empty() || !state->http_addresses.empty()) { if (!state->http_addresses.empty() || !state->http_addresses.empty()) {
config_log.info("Starting HTTP server"); config_log.info("Starting HTTP server");
http_server = make_shared<HTTPServer>(state); state->http_server = make_shared<HTTPServer>(state);
for (const auto& it : state->http_addresses) { for (const auto& it : state->http_addresses) {
auto netloc = parse_netloc(it); auto netloc = parse_netloc(it);
http_server->listen(netloc.first, netloc.second); state->http_server->listen(netloc.first, netloc.second);
} }
} }
} }
@@ -2630,8 +2705,8 @@ Action a_run_server_replay_log(
if (state->bb_patch_server) { if (state->bb_patch_server) {
state->bb_patch_server->schedule_stop(); state->bb_patch_server->schedule_stop();
} }
if (http_server) { if (state->http_server) {
http_server->schedule_stop(); state->http_server->schedule_stop();
} }
if (state->pc_patch_server) { if (state->pc_patch_server) {
config_log.info("Waiting for PC_V2 patch server to stop"); config_log.info("Waiting for PC_V2 patch server to stop");
@@ -2641,9 +2716,9 @@ Action a_run_server_replay_log(
config_log.info("Waiting for BB_V4 patch server to stop"); config_log.info("Waiting for BB_V4 patch server to stop");
state->bb_patch_server->wait_for_stop(); state->bb_patch_server->wait_for_stop();
} }
if (http_server) { if (state->http_server) {
config_log.info("Waiting for HTTP server to stop"); config_log.info("Waiting for HTTP server to stop");
http_server->wait_for_stop(); state->http_server->wait_for_stop();
} }
state->proxy_server.reset(); // Break reference cycle state->proxy_server.reset(); // Break reference cycle
}); });
+3 -3
View File
@@ -678,10 +678,10 @@ Map::Enemy::Enemy(
wave_number(wave_number), wave_number(wave_number),
type(type), type(type),
floor(floor), floor(floor),
state_flags(0) {} server_flags(0) {}
string Map::Enemy::str() const { string Map::Enemy::str() const {
return string_printf("[Map::Enemy E-%hX source %zX %s%s floor=%02hhX section=%04hX wave_number=%04hX flags=%02hhX]", return string_printf("[Map::Enemy E-%hX source %zX %s%s floor=%02hhX section=%04hX wave_number=%04hX server_flags=%02hhX]",
this->enemy_id, this->enemy_id,
this->source_index, this->source_index,
name_for_enum(this->type), name_for_enum(this->type),
@@ -689,7 +689,7 @@ string Map::Enemy::str() const {
this->floor, this->floor,
this->section, this->section,
this->wave_number, this->wave_number,
this->state_flags); this->server_flags);
} }
string Map::Event::str() const { string Map::Event::str() const {
+16 -6
View File
@@ -233,11 +233,11 @@ struct Map {
struct Enemy { struct Enemy {
enum Flag { enum Flag {
EXP_REQUESTED_BY_PLAYER0 = 0x01, LAST_HIT_MASK = 0x03,
EXP_REQUESTED_BY_PLAYER1 = 0x02, EXP_GIVEN = 0x04,
EXP_REQUESTED_BY_PLAYER2 = 0x04, ITEM_DROPPED = 0x08,
EXP_REQUESTED_BY_PLAYER3 = 0x08, ALL_HITS_MASK_FIRST = 0x10,
ITEM_DROPPED = 0x10, ALL_HITS_MASK = 0xF0,
}; };
size_t source_index; size_t source_index;
size_t set_index; size_t set_index;
@@ -248,7 +248,7 @@ struct Map {
uint16_t wave_number; uint16_t wave_number;
EnemyType type; EnemyType type;
uint8_t floor; uint8_t floor;
uint8_t state_flags; uint8_t server_flags;
Enemy( Enemy(
uint16_t enemy_id, uint16_t enemy_id,
@@ -260,6 +260,16 @@ struct Map {
EnemyType type); EnemyType type);
std::string str() const; std::string str() const;
inline bool ever_hit_by_client_id(uint8_t client_id) const {
return this->server_flags & (Flag::ALL_HITS_MASK_FIRST << client_id);
}
inline bool last_hit_by_client_id(uint8_t client_id) const {
return (this->server_flags & Flag::LAST_HIT_MASK) == client_id;
}
inline void set_last_hit_by_client_id(uint8_t client_id) {
this->server_flags = (this->server_flags & (~Flag::LAST_HIT_MASK)) | (Flag::ALL_HITS_MASK_FIRST << client_id) | (client_id & 3);
}
}; };
struct Event { struct Event {
+12 -8
View File
@@ -20,7 +20,10 @@ constexpr uint32_t LOBBY = 0x33000033;
constexpr uint32_t GAME = 0x44000044; constexpr uint32_t GAME = 0x44000044;
constexpr uint32_t QUEST_EP1 = 0x55010155; constexpr uint32_t QUEST_EP1 = 0x55010155;
constexpr uint32_t QUEST_EP2 = 0x55020255; constexpr uint32_t QUEST_EP2 = 0x55020255;
constexpr uint32_t QUEST_CATEGORIES = 0x66010166; // See the decsription of the A2 command in CommandFormats.hh for why these
// menu IDs don't fit the rest of the pattern.
constexpr uint32_t QUEST_CATEGORIES_EP1 = 0x01000001;
constexpr uint32_t QUEST_CATEGORIES_EP2 = 0x02000002;
constexpr uint32_t PROXY_DESTINATIONS = 0x77000077; constexpr uint32_t PROXY_DESTINATIONS = 0x77000077;
constexpr uint32_t PROGRAMS = 0x88000088; constexpr uint32_t PROGRAMS = 0x88000088;
constexpr uint32_t PATCHES = 0x99000099; constexpr uint32_t PATCHES = 0x99000099;
@@ -77,13 +80,14 @@ constexpr uint32_t SWITCH_ASSIST = 0xAA0707AA;
constexpr uint32_t BLOCK_EVENTS = 0xAA0808AA; constexpr uint32_t BLOCK_EVENTS = 0xAA0808AA;
constexpr uint32_t BLOCK_PATCHES = 0xAA0909AA; constexpr uint32_t BLOCK_PATCHES = 0xAA0909AA;
constexpr uint32_t SAVE_FILES = 0xAA0A0AAA; constexpr uint32_t SAVE_FILES = 0xAA0A0AAA;
constexpr uint32_t RED_NAME = 0xAA0B0BAA; constexpr uint32_t VIRTUAL_CLIENT = 0xAA0B0BAA;
constexpr uint32_t BLANK_NAME = 0xAA0C0CAA; constexpr uint32_t RED_NAME = 0xAA0C0CAA;
constexpr uint32_t SUPPRESS_LOGIN = 0xAA0D0DAA; constexpr uint32_t BLANK_NAME = 0xAA0D0DAA;
constexpr uint32_t SKIP_CARD = 0xAA0E0EAA; constexpr uint32_t SUPPRESS_LOGIN = 0xAA0E0EAA;
constexpr uint32_t EP3_INFINITE_MESETA = 0xAA0F0FAA; constexpr uint32_t SKIP_CARD = 0xAA0F0FAA;
constexpr uint32_t EP3_INFINITE_TIME = 0xAA1010AA; constexpr uint32_t EP3_INFINITE_MESETA = 0xAA1010AA;
constexpr uint32_t EP3_UNMASK_WHISPERS = 0xAA1111AA; constexpr uint32_t EP3_INFINITE_TIME = 0xAA1111AA;
constexpr uint32_t EP3_UNMASK_WHISPERS = 0xAA1212AA;
} // namespace ProxyOptionsMenuItemID } // namespace ProxyOptionsMenuItemID
namespace TeamRewardMenuItemID { namespace TeamRewardMenuItemID {
+2 -2
View File
@@ -66,7 +66,7 @@ std::shared_ptr<PSOBBGuildCardFile> PlayerFilesManager::get_guild_card(const std
} }
} }
std::shared_ptr<PlayerBank> PlayerFilesManager::get_bank(const std::string& filename) { std::shared_ptr<PlayerBank200> PlayerFilesManager::get_bank(const std::string& filename) {
try { try {
return this->loaded_bank_files.at(filename); return this->loaded_bank_files.at(filename);
} catch (const out_of_range&) { } catch (const out_of_range&) {
@@ -92,7 +92,7 @@ void PlayerFilesManager::set_guild_card(const std::string& filename, std::shared
} }
} }
void PlayerFilesManager::set_bank(const std::string& filename, std::shared_ptr<PlayerBank> file) { void PlayerFilesManager::set_bank(const std::string& filename, std::shared_ptr<PlayerBank200> file) {
if (!this->loaded_bank_files.emplace(filename, file).second) { if (!this->loaded_bank_files.emplace(filename, file).second) {
throw runtime_error("bank file already loaded: " + filename); throw runtime_error("bank file already loaded: " + filename);
} }
+3 -3
View File
@@ -27,12 +27,12 @@ public:
std::shared_ptr<PSOBBBaseSystemFile> get_system(const std::string& filename); std::shared_ptr<PSOBBBaseSystemFile> get_system(const std::string& filename);
std::shared_ptr<PSOBBCharacterFile> get_character(const std::string& filename); std::shared_ptr<PSOBBCharacterFile> get_character(const std::string& filename);
std::shared_ptr<PSOBBGuildCardFile> get_guild_card(const std::string& filename); std::shared_ptr<PSOBBGuildCardFile> get_guild_card(const std::string& filename);
std::shared_ptr<PlayerBank> get_bank(const std::string& filename); std::shared_ptr<PlayerBank200> get_bank(const std::string& filename);
void set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file); void set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file);
void set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file); void set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file);
void set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file); void set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file);
void set_bank(const std::string& filename, std::shared_ptr<PlayerBank> file); void set_bank(const std::string& filename, std::shared_ptr<PlayerBank200> file);
private: private:
std::shared_ptr<struct event_base> base; std::shared_ptr<struct event_base> base;
@@ -41,7 +41,7 @@ private:
std::unordered_map<std::string, std::shared_ptr<PSOBBBaseSystemFile>> loaded_system_files; std::unordered_map<std::string, std::shared_ptr<PSOBBBaseSystemFile>> loaded_system_files;
std::unordered_map<std::string, std::shared_ptr<PSOBBCharacterFile>> loaded_character_files; std::unordered_map<std::string, std::shared_ptr<PSOBBCharacterFile>> loaded_character_files;
std::unordered_map<std::string, std::shared_ptr<PSOBBGuildCardFile>> loaded_guild_card_files; std::unordered_map<std::string, std::shared_ptr<PSOBBGuildCardFile>> loaded_guild_card_files;
std::unordered_map<std::string, std::shared_ptr<PlayerBank>> loaded_bank_files; std::unordered_map<std::string, std::shared_ptr<PlayerBank200>> loaded_bank_files;
static void clear_expired_files(evutil_socket_t fd, short events, void* ctx); static void clear_expired_files(evutil_socket_t fd, short events, void* ctx);
}; };
+33 -13
View File
@@ -3,6 +3,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include <array> #include <array>
#include <phosg/Encoding.hh> #include <phosg/Encoding.hh>
#include <phosg/JSON.hh> #include <phosg/JSON.hh>
@@ -46,12 +47,14 @@ class ItemParameterTable;
template <bool IsBigEndian> template <bool IsBigEndian>
struct PlayerInventoryItemT { struct PlayerInventoryItemT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
/* 00 */ uint8_t present = 0; /* 00 */ uint8_t present = 0;
/* 01 */ uint8_t unknown_a1 = 0; /* 01 */ uint8_t unknown_a1 = 0;
// See note above about these fields // See note above about these fields
/* 02 */ uint8_t extension_data1 = 0; /* 02 */ uint8_t extension_data1 = 0;
/* 03 */ uint8_t extension_data2 = 0; /* 03 */ uint8_t extension_data2 = 0;
/* 04 */ le_uint32_t flags = 0; // 8 = equipped /* 04 */ U32T flags = 0; // 8 = equipped
/* 08 */ ItemData data; /* 08 */ ItemData data;
/* 1C */ /* 1C */
@@ -73,6 +76,7 @@ struct PlayerInventoryItemT {
ret.extension_data2 = this->extension_data2; ret.extension_data2 = this->extension_data2;
ret.flags = this->flags.load(); ret.flags = this->flags.load();
ret.data = this->data; ret.data = this->data;
ret.data.id.store_raw(bswap32(ret.data.id.load_raw()));
return ret; return ret;
} }
} __packed__; } __packed__;
@@ -230,6 +234,7 @@ struct PlayerInventoryT {
} }
size_t remove_all_items_of_type(uint8_t data1_0, int16_t data1_1 = -1) { size_t remove_all_items_of_type(uint8_t data1_0, int16_t data1_1 = -1) {
size_t write_offset = 0; size_t write_offset = 0;
for (size_t read_offset = 0; read_offset < this->num_items; read_offset++) { for (size_t read_offset = 0; read_offset < this->num_items; read_offset++) {
bool should_delete = ((this->items[read_offset].data.data1[0] == data1_0) && bool should_delete = ((this->items[read_offset].data.data1[0] == data1_0) &&
@@ -297,14 +302,14 @@ using PlayerInventoryBE = PlayerInventoryT<true>;
check_struct_size(PlayerInventory, 0x34C); check_struct_size(PlayerInventory, 0x34C);
check_struct_size(PlayerInventoryBE, 0x34C); check_struct_size(PlayerInventoryBE, 0x34C);
template <bool IsBigEndian> template <size_t SlotCount, bool IsBigEndian>
struct PlayerBankT { struct PlayerBankT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type; using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
/* 0000 */ U32T num_items = 0; /* 0000 */ U32T num_items = 0;
/* 0004 */ U32T meseta = 0; /* 0004 */ U32T meseta = 0;
/* 0008 */ parray<PlayerBankItemT<IsBigEndian>, 200> items; /* 0008 */ parray<PlayerBankItemT<IsBigEndian>, SlotCount> items;
/* 12C8 */ /* 05A8 for 60 items (v1/v2), 12C8 for 200 items (v3/v4) */
void add_item(const ItemData& item, const ItemData::StackLimits& limits) { void add_item(const ItemData& item, const ItemData::StackLimits& limits) {
uint32_t primary_identifier = item.primary_identifier(); uint32_t primary_identifier = item.primary_identifier();
@@ -337,7 +342,7 @@ struct PlayerBankT {
} }
} }
if (this->num_items >= 200) { if (this->num_items >= SlotCount) {
throw std::runtime_error("no free space in bank"); throw std::runtime_error("no free space in bank");
} }
auto& last_item = this->items[this->num_items]; auto& last_item = this->items[this->num_items];
@@ -391,17 +396,32 @@ struct PlayerBankT {
} }
} }
operator PlayerBankT<!IsBigEndian>() const { void decode_from_client(Version v) {
PlayerBankT<!IsBigEndian> ret;
ret.num_items = this->num_items.load();
ret.meseta = this->meseta.load();
for (size_t z = 0; z < this->items.size(); z++) { for (size_t z = 0; z < this->items.size(); z++) {
this->items[z].data.decode_for_version(v);
}
}
void encode_for_client(Version v) {
for (size_t z = 0; z < this->items.size(); z++) {
this->items[z].data.encode_for_version(v, nullptr);
}
}
template <size_t DestSlotCount, bool DestIsBigEndian>
operator PlayerBankT<DestSlotCount, DestIsBigEndian>() const {
PlayerBankT<DestSlotCount, DestIsBigEndian> ret;
ret.num_items = std::min<size_t>(ret.items.size(), this->num_items.load());
ret.meseta = this->meseta.load();
for (size_t z = 0; z < std::min<size_t>(ret.items.size(), this->items.size()); z++) {
ret.items[z] = this->items[z]; ret.items[z] = this->items[z];
} }
return ret; return ret;
} }
} __packed__; } __packed__;
using PlayerBank = PlayerBankT<false>; using PlayerBank60 = PlayerBankT<60, false>;
using PlayerBankBE = PlayerBankT<true>; using PlayerBank200 = PlayerBankT<200, false>;
check_struct_size(PlayerBank, 0x12C8); using PlayerBank200BE = PlayerBankT<200, true>;
check_struct_size(PlayerBankBE, 0x12C8); check_struct_size(PlayerBank60, 0x05A8);
check_struct_size(PlayerBank200, 0x12C8);
check_struct_size(PlayerBank200BE, 0x12C8);
+2 -2
View File
@@ -176,8 +176,8 @@ void XBNetworkLocation::clear() {
this->external_ipv4_address = 0; this->external_ipv4_address = 0;
this->port = 0; this->port = 0;
this->mac_address.clear(0); this->mac_address.clear(0);
this->unknown_a1 = 0; this->sg_ip_address = 0;
this->unknown_a2 = 0; this->spi = 0;
this->account_id = 0; this->account_id = 0;
this->unknown_a3.clear(0); this->unknown_a3.clear(0);
} }
+36 -19
View File
@@ -359,24 +359,41 @@ struct GuildCardPC {
operator GuildCardBB() const; operator GuildCardBB() const;
} __packed_ws__(GuildCardPC, 0xF0); } __packed_ws__(GuildCardPC, 0xF0);
template <bool IsBigEndian> // 0000 | 62 00 AC 00 06 2A 00 00 00 00 01 00 90 96 66 8C | b * f
// 0010 | 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 | 1111
// 0020 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0030 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0080 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 0090 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
// 00A0 | 00 00 00 00 00 00 00 00 01 00 06 00 |
template <bool IsBigEndian, size_t DescriptionLength>
struct GuildCardGCT { struct GuildCardGCT {
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type; using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
/* 00 */ U32T player_tag = 0x00010000; /* NTE:Final */
/* 04 */ U32T guild_card_number = 0; /* 00:00 */ U32T player_tag = 0x00010000;
/* 08 */ pstring<TextEncoding::ASCII, 0x18> name; /* 04:04 */ U32T guild_card_number = 0;
/* 20 */ pstring<TextEncoding::MARKED, 0x6C> description; /* 08:08 */ pstring<TextEncoding::ASCII, 0x18> name;
/* 8C */ uint8_t present = 0; /* 20:20 */ pstring<TextEncoding::MARKED, DescriptionLength> description;
/* 8D */ uint8_t language = 0; /* 8C:8C */ uint8_t present = 0;
/* 8E */ uint8_t section_id = 0; /* 8D:8D */ uint8_t language = 0;
/* 8F */ uint8_t char_class = 0; /* 8E:8E */ uint8_t section_id = 0;
/* 90 */ /* 8F:8F */ uint8_t char_class = 0;
/* 90:90 */
operator GuildCardBB() const; operator GuildCardBB() const;
} __packed__; } __packed__;
using GuildCardGC = GuildCardGCT<false>; using GuildCardGCNTE = GuildCardGCT<false, 0x80>;
using GuildCardGCBE = GuildCardGCT<true>; using GuildCardGCNTEBE = GuildCardGCT<true, 0x80>;
using GuildCardGC = GuildCardGCT<false, 0x6C>;
using GuildCardGCBE = GuildCardGCT<true, 0x6C>;
check_struct_size(GuildCardGCNTE, 0xA4);
check_struct_size(GuildCardGCNTEBE, 0xA4);
check_struct_size(GuildCardGC, 0x90); check_struct_size(GuildCardGC, 0x90);
check_struct_size(GuildCardGCBE, 0x90); check_struct_size(GuildCardGCBE, 0x90);
@@ -412,9 +429,9 @@ struct GuildCardBB {
operator GuildCardDCNTE() const; operator GuildCardDCNTE() const;
operator GuildCardDC() const; operator GuildCardDC() const;
operator GuildCardPC() const; operator GuildCardPC() const;
template <bool IsBigEndian> template <bool IsBigEndian, size_t DescriptionLength>
operator GuildCardGCT<IsBigEndian>() const { operator GuildCardGCT<IsBigEndian, DescriptionLength>() const {
GuildCardGCT<IsBigEndian> ret; GuildCardGCT<IsBigEndian, DescriptionLength> ret;
ret.player_tag = 0x00010000; ret.player_tag = 0x00010000;
ret.guild_card_number = this->guild_card_number.load(); ret.guild_card_number = this->guild_card_number.load();
ret.name.encode(this->name.decode(this->language), this->language); ret.name.encode(this->name.decode(this->language), this->language);
@@ -428,8 +445,8 @@ struct GuildCardBB {
operator GuildCardXB() const; operator GuildCardXB() const;
} __packed_ws__(GuildCardBB, 0x108); } __packed_ws__(GuildCardBB, 0x108);
template <bool IsBigEndian> template <bool IsBigEndian, size_t DescriptionLength>
GuildCardGCT<IsBigEndian>::operator GuildCardBB() const { GuildCardGCT<IsBigEndian, DescriptionLength>::operator GuildCardBB() const {
GuildCardBB ret; GuildCardBB ret;
ret.guild_card_number = this->guild_card_number.load(); ret.guild_card_number = this->guild_card_number.load();
ret.name.encode(this->name.decode(this->language), this->language); ret.name.encode(this->name.decode(this->language), this->language);
@@ -471,8 +488,8 @@ struct XBNetworkLocation {
/* 04 */ le_uint32_t external_ipv4_address = 0x23232323; /* 04 */ le_uint32_t external_ipv4_address = 0x23232323;
/* 08 */ le_uint16_t port = 9500; /* 08 */ le_uint16_t port = 9500;
/* 0A */ parray<uint8_t, 6> mac_address = 0x77; /* 0A */ parray<uint8_t, 6> mac_address = 0x77;
/* 10 */ le_uint32_t unknown_a1; /* 10 */ le_uint32_t sg_ip_address = 0x0B0B0B0B;
/* 14 */ le_uint32_t unknown_a2; /* 14 */ le_uint32_t spi = 0xCCCCCCCC;
/* 18 */ le_uint64_t account_id = 0xFFFFFFFFFFFFFFFF; /* 18 */ le_uint64_t account_id = 0xFFFFFFFFFFFFFFFF;
/* 20 */ parray<le_uint32_t, 4> unknown_a3; /* 20 */ parray<le_uint32_t, 4> unknown_a3;
/* 30 */ /* 30 */
+16 -17
View File
@@ -169,7 +169,7 @@ static HandlerResult S_G_9A(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t
} }
cmd.unused1 = 0; cmd.unused1 = 0;
cmd.unused2 = 0; cmd.unused2 = 0;
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0; cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0;
cmd.language = ses->language(); cmd.language = ses->language();
cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id)); cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id));
@@ -275,7 +275,7 @@ static HandlerResult S_V123P_02_17(
} }
cmd.unknown_a1 = 0; cmd.unknown_a1 = 0;
cmd.unknown_a2 = 0; cmd.unknown_a2 = 0;
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0; cmd.is_extended = 0;
cmd.language = ses->language(); cmd.language = ses->language();
cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id)); cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id));
@@ -313,7 +313,7 @@ static HandlerResult S_V123P_02_17(
cmd.player_tag = 0x00010000; cmd.player_tag = 0x00010000;
cmd.guild_card_number = ses->remote_guild_card_number; cmd.guild_card_number = ses->remote_guild_card_number;
} }
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id)); cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id));
cmd.access_key.encode(*access_key); cmd.access_key.encode(*access_key);
if (ses->version() != Version::GC_NTE) { if (ses->version() != Version::GC_NTE) {
@@ -337,7 +337,7 @@ static HandlerResult S_V123P_02_17(
} }
cmd.unused1 = 0; cmd.unused1 = 0;
cmd.unused2 = 0; cmd.unused2 = 0;
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0; cmd.is_extended = 0;
cmd.language = ses->language(); cmd.language = ses->language();
cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id)); cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id));
@@ -367,7 +367,7 @@ static HandlerResult S_V123P_02_17(
C_VerifyAccount_V3_DB cmd; C_VerifyAccount_V3_DB cmd;
cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id)); cmd.serial_number.encode(string_printf("%08" PRIX32 "", ses->login->account->account_id));
cmd.access_key.encode(ses->login->gc_license->access_key); cmd.access_key.encode(ses->login->gc_license->access_key);
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.serial_number2 = cmd.serial_number; cmd.serial_number2 = cmd.serial_number;
cmd.access_key2 = cmd.access_key; cmd.access_key2 = cmd.access_key;
cmd.password.encode(ses->login->gc_license->password); cmd.password.encode(ses->login->gc_license->password);
@@ -396,7 +396,7 @@ static HandlerResult S_V123P_02_17(
cmd.guild_card_number = guild_card_number; cmd.guild_card_number = guild_card_number;
cmd.unused1 = 0; cmd.unused1 = 0;
cmd.unused2 = 0; cmd.unused2 = 0;
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = 0; cmd.is_extended = 0;
cmd.language = ses->language(); cmd.language = ses->language();
cmd.serial_number.encode(string_printf("%08" PRIX32, fake_serial_number)); cmd.serial_number.encode(string_printf("%08" PRIX32, fake_serial_number));
@@ -432,7 +432,7 @@ static HandlerResult S_V123P_02_17(
} }
cmd.unused1 = 0; cmd.unused1 = 0;
cmd.unused2 = 0; cmd.unused2 = 0;
cmd.sub_version = ses->sub_version; cmd.sub_version = ses->effective_sub_version();
cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0; cmd.is_extended = (ses->remote_guild_card_number < 0) ? 1 : 0;
cmd.language = ses->language(); cmd.language = ses->language();
cmd.serial_number.encode(ses->login->xb_license->gamertag); cmd.serial_number.encode(ses->login->xb_license->gamertag);
@@ -1122,8 +1122,7 @@ static HandlerResult S_6x(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
const auto& cmd = check_size_t<G_AttackFinished_6x46>(data, const auto& cmd = check_size_t<G_AttackFinished_6x46>(data,
offsetof(G_AttackFinished_6x46, targets), offsetof(G_AttackFinished_6x46, targets),
sizeof(G_AttackFinished_6x46)); sizeof(G_AttackFinished_6x46));
size_t allowed_count = min<size_t>(cmd.header.size - 2, 11); if (cmd.count > min<size_t>(cmd.header.size - 2, cmd.targets.size())) {
if (cmd.count > allowed_count) {
ses->log.warning("Blocking subcommand 6x46 with invalid count"); ses->log.warning("Blocking subcommand 6x46 with invalid count");
return HandlerResult::Type::SUPPRESS; return HandlerResult::Type::SUPPRESS;
} }
@@ -1131,24 +1130,24 @@ static HandlerResult S_6x(shared_ptr<ProxyServer::LinkedSession> ses, uint16_t,
const auto& cmd = check_size_t<G_CastTechnique_6x47>(data, const auto& cmd = check_size_t<G_CastTechnique_6x47>(data,
offsetof(G_CastTechnique_6x47, targets), offsetof(G_CastTechnique_6x47, targets),
sizeof(G_CastTechnique_6x47)); sizeof(G_CastTechnique_6x47));
size_t allowed_count = min<size_t>(cmd.header.size - 2, 10); if (cmd.target_count > min<size_t>(cmd.header.size - 2, cmd.targets.size())) {
if (cmd.target_count > allowed_count) {
ses->log.warning("Blocking subcommand 6x47 with invalid count"); ses->log.warning("Blocking subcommand 6x47 with invalid count");
return HandlerResult::Type::SUPPRESS; return HandlerResult::Type::SUPPRESS;
} }
} else if (data[0] == 0x49) { } else if (data[0] == 0x49) {
const auto& cmd = check_size_t<G_SubtractPBEnergy_6x49>(data, const auto& cmd = check_size_t<G_ExecutePhotonBlast_6x49>(data,
offsetof(G_SubtractPBEnergy_6x49, entries), offsetof(G_ExecutePhotonBlast_6x49, targets),
sizeof(G_SubtractPBEnergy_6x49)); sizeof(G_ExecutePhotonBlast_6x49));
size_t allowed_count = min<size_t>(cmd.header.size - 3, 14); if (cmd.target_count > min<size_t>(cmd.header.size - 3, cmd.targets.size())) {
if (cmd.entry_count > allowed_count) {
ses->log.warning("Blocking subcommand 6x49 with invalid count"); ses->log.warning("Blocking subcommand 6x49 with invalid count");
return HandlerResult::Type::SUPPRESS; return HandlerResult::Type::SUPPRESS;
} }
} else if (data[0] == 0x5F) { } else if (data[0] == 0x5F) {
const auto& cmd = check_size_t<G_DropItem_DC_6x5F>(data, sizeof(G_DropItem_PC_V3_BB_6x5F)); const auto& cmd = check_size_t<G_DropItem_DC_6x5F>(data, sizeof(G_DropItem_PC_V3_BB_6x5F));
send_item_notification_if_needed(ses->require_server_state(), ses->client_channel, ses->config, cmd.item.item, true); ItemData item = cmd.item.item;
item.decode_for_version(ses->version());
send_item_notification_if_needed(ses->require_server_state(), ses->client_channel, ses->config, item, true);
} else if ((data[0] == 0x60) || (static_cast<uint8_t>(data[0]) == 0xA2)) { } else if ((data[0] == 0x60) || (static_cast<uint8_t>(data[0]) == 0xA2)) {
return SC_6x60_6xA2(ses, data); return SC_6x60_6xA2(ses, data);
+5
View File
@@ -160,6 +160,11 @@ public:
inline uint8_t language() const { inline uint8_t language() const {
return this->client_channel.language; return this->client_channel.language;
} }
inline uint32_t effective_sub_version() const {
return this->config.check_flag(Client::Flag::PROXY_VIRTUAL_CLIENT)
? default_sub_version_for_version(this->version())
: this->sub_version;
}
void set_version(Version v); void set_version(Version v);
void resume( void resume(
+55 -13
View File
@@ -204,12 +204,18 @@ VersionedQuest::VersionedQuest(
std::shared_ptr<const std::string> pvr_contents, std::shared_ptr<const std::string> pvr_contents,
std::shared_ptr<const BattleRules> battle_rules, std::shared_ptr<const BattleRules> battle_rules,
ssize_t challenge_template_index, ssize_t challenge_template_index,
uint8_t description_flag,
std::shared_ptr<const IntegralExpression> available_expression, std::shared_ptr<const IntegralExpression> available_expression,
std::shared_ptr<const IntegralExpression> enabled_expression) std::shared_ptr<const IntegralExpression> enabled_expression,
bool allow_start_from_chat_command,
bool force_joinable,
int16_t lock_status_register)
: quest_number(quest_number), : quest_number(quest_number),
category_id(category_id), category_id(category_id),
episode(Episode::NONE), episode(Episode::NONE),
joinable(false), allow_start_from_chat_command(allow_start_from_chat_command),
joinable(force_joinable),
lock_status_register(lock_status_register),
version(version), version(version),
language(language), language(language),
is_dlq_encoded(false), is_dlq_encoded(false),
@@ -218,6 +224,7 @@ VersionedQuest::VersionedQuest(
pvr_contents(pvr_contents), pvr_contents(pvr_contents),
battle_rules(battle_rules), battle_rules(battle_rules),
challenge_template_index(challenge_template_index), challenge_template_index(challenge_template_index),
description_flag(description_flag),
available_expression(available_expression), available_expression(available_expression),
enabled_expression(enabled_expression) { enabled_expression(enabled_expression) {
@@ -233,7 +240,6 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is too small for header"); throw invalid_argument("file is too small for header");
} }
auto* header = reinterpret_cast<const PSOQuestHeaderDCNTE*>(bin_decompressed.data()); auto* header = reinterpret_cast<const PSOQuestHeaderDCNTE*>(bin_decompressed.data());
this->joinable = false;
this->episode = Episode::EP1; this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = fnv1a32(header, sizeof(header)) & 0xFFFF; this->quest_number = fnv1a32(header, sizeof(header)) & 0xFFFF;
@@ -249,7 +255,6 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is too small for header"); throw invalid_argument("file is too small for header");
} }
auto* header = reinterpret_cast<const PSOQuestHeaderDC*>(bin_decompressed.data()); auto* header = reinterpret_cast<const PSOQuestHeaderDC*>(bin_decompressed.data());
this->joinable = false;
this->episode = Episode::EP1; this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number; this->quest_number = header->quest_number;
@@ -266,7 +271,6 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is too small for header"); throw invalid_argument("file is too small for header");
} }
auto* header = reinterpret_cast<const PSOQuestHeaderPC*>(bin_decompressed.data()); auto* header = reinterpret_cast<const PSOQuestHeaderPC*>(bin_decompressed.data());
this->joinable = false;
this->episode = Episode::EP1; this->episode = Episode::EP1;
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number; this->quest_number = header->quest_number;
@@ -289,7 +293,6 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is incorrect size"); throw invalid_argument("file is incorrect size");
} }
auto* map = reinterpret_cast<const Episode3::MapDefinition*>(bin_decompressed.data()); auto* map = reinterpret_cast<const Episode3::MapDefinition*>(bin_decompressed.data());
this->joinable = false;
this->episode = Episode::EP3; this->episode = Episode::EP3;
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = map->map_number; this->quest_number = map->map_number;
@@ -307,7 +310,6 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is too small for header"); throw invalid_argument("file is too small for header");
} }
auto* header = reinterpret_cast<const PSOQuestHeaderGC*>(bin_decompressed.data()); auto* header = reinterpret_cast<const PSOQuestHeaderGC*>(bin_decompressed.data());
this->joinable = false;
this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version); this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version);
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number; this->quest_number = header->quest_number;
@@ -323,7 +325,7 @@ VersionedQuest::VersionedQuest(
throw invalid_argument("file is too small for header"); throw invalid_argument("file is too small for header");
} }
auto* header = reinterpret_cast<const PSOQuestHeaderBB*>(bin_decompressed.data()); auto* header = reinterpret_cast<const PSOQuestHeaderBB*>(bin_decompressed.data());
this->joinable = header->joinable; this->joinable |= header->joinable;
this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version); this->episode = find_quest_episode_from_script(bin_decompressed.data(), bin_decompressed.size(), this->version);
if (this->quest_number == 0xFFFFFFFF) { if (this->quest_number == 0xFFFFFFFF) {
this->quest_number = header->quest_number; this->quest_number = header->quest_number;
@@ -386,10 +388,13 @@ Quest::Quest(shared_ptr<const VersionedQuest> initial_version)
: quest_number(initial_version->quest_number), : quest_number(initial_version->quest_number),
category_id(initial_version->category_id), category_id(initial_version->category_id),
episode(initial_version->episode), episode(initial_version->episode),
allow_start_from_chat_command(initial_version->allow_start_from_chat_command),
joinable(initial_version->joinable), joinable(initial_version->joinable),
lock_status_register(initial_version->lock_status_register),
name(initial_version->name), name(initial_version->name),
battle_rules(initial_version->battle_rules), battle_rules(initial_version->battle_rules),
challenge_template_index(initial_version->challenge_template_index), challenge_template_index(initial_version->challenge_template_index),
description_flag(initial_version->description_flag),
available_expression(initial_version->available_expression), available_expression(initial_version->available_expression),
enabled_expression(initial_version->enabled_expression) { enabled_expression(initial_version->enabled_expression) {
this->versions.emplace(this->versions_key(initial_version->version, initial_version->language), initial_version); this->versions.emplace(this->versions_key(initial_version->version, initial_version->language), initial_version);
@@ -409,9 +414,15 @@ void Quest::add_version(shared_ptr<const VersionedQuest> vq) {
if (this->episode != vq->episode) { if (this->episode != vq->episode) {
throw runtime_error("quest version is in a different episode"); throw runtime_error("quest version is in a different episode");
} }
if (this->allow_start_from_chat_command != vq->allow_start_from_chat_command) {
throw runtime_error("quest version has a different allow_start_from_chat_command state");
}
if (this->joinable != vq->joinable) { if (this->joinable != vq->joinable) {
throw runtime_error("quest version has a different joinability state"); throw runtime_error("quest version has a different joinability state");
} }
if (this->lock_status_register != vq->lock_status_register) {
throw runtime_error("quest version has a different lock status register");
}
if (!this->battle_rules != !vq->battle_rules) { if (!this->battle_rules != !vq->battle_rules) {
throw runtime_error("quest version has a different battle rules presence state"); throw runtime_error("quest version has a different battle rules presence state");
} }
@@ -421,6 +432,9 @@ void Quest::add_version(shared_ptr<const VersionedQuest> vq) {
if (this->challenge_template_index != vq->challenge_template_index) { if (this->challenge_template_index != vq->challenge_template_index) {
throw runtime_error("quest version has different challenge template index"); throw runtime_error("quest version has different challenge template index");
} }
if (this->description_flag != vq->description_flag) {
throw runtime_error("quest version has different description flag");
}
if (!this->available_expression != !vq->available_expression) { if (!this->available_expression != !vq->available_expression) {
throw runtime_error("quest version has available expression but root quest does not, or vice versa"); throw runtime_error("quest version has available expression but root quest does not, or vice versa");
} }
@@ -447,17 +461,22 @@ bool Quest::has_version_any_language(Version v) const {
return ((it != this->versions.end()) && ((it->first & 0xFF00) == k)); return ((it != this->versions.end()) && ((it->first & 0xFF00) == k));
} }
shared_ptr<const VersionedQuest> Quest::version(Version v, uint8_t language) const { shared_ptr<const VersionedQuest> Quest::version(Version v, uint8_t language, bool allow_language_fallback) const {
// Return the requested version, if it exists // Return the requested version, if it exists
try { try {
return this->versions.at(this->versions_key(v, language)); return this->versions.at(this->versions_key(v, language));
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
if (!allow_language_fallback) {
return nullptr;
}
// Return the English version, if it exists // Return the English version, if it exists
try { try {
return this->versions.at(this->versions_key(v, 1)); return this->versions.at(this->versions_key(v, 1));
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
// Return the first language, if it exists // Return the first language, if it exists
auto it = this->versions.lower_bound(this->versions_key(v, 0)); auto it = this->versions.lower_bound(this->versions_key(v, 0));
if ((it == this->versions.end()) || ((it->first & 0xFF00) != this->versions_key(v, 0))) { if ((it == this->versions.end()) || ((it->first & 0xFF00) != this->versions_key(v, 0))) {
@@ -529,7 +548,8 @@ QuestIndex::QuestIndex(
file_data = decode_dlq_data(load_file(file_path)); file_data = decode_dlq_data(load_file(file_path));
filename.resize(filename.size() - 4); filename.resize(filename.size() - 4);
} else if (ends_with(filename, ".txt")) { } else if (ends_with(filename, ".txt")) {
file_data = assemble_quest_script(load_file(file_path)); string include_dir = dirname(file_path);
file_data = assemble_quest_script(load_file(file_path), include_dir);
filename.resize(filename.size() - 4); filename.resize(filename.size() - 4);
if (ends_with(filename, ".bin")) { if (ends_with(filename, ".bin")) {
filename.push_back('d'); filename.push_back('d');
@@ -573,8 +593,6 @@ QuestIndex::QuestIndex(
throw runtime_error("qst file contains unsupported file type: " + it.first); throw runtime_error("qst file contains unsupported file type: " + it.first);
} }
} }
} else {
static_game_data_log.warning("(%s) Skipping file (unsupported format)", filename.c_str());
} }
} catch (const exception& e) { } catch (const exception& e) {
@@ -672,8 +690,12 @@ QuestIndex::QuestIndex(
const FileData* json_filedata = nullptr; const FileData* json_filedata = nullptr;
shared_ptr<BattleRules> battle_rules; shared_ptr<BattleRules> battle_rules;
ssize_t challenge_template_index = -1; ssize_t challenge_template_index = -1;
uint8_t description_flag = 0;
shared_ptr<const IntegralExpression> available_expression; shared_ptr<const IntegralExpression> available_expression;
shared_ptr<const IntegralExpression> enabled_expression; shared_ptr<const IntegralExpression> enabled_expression;
bool allow_start_from_chat_command = false;
bool force_joinable = false;
int16_t lock_status_register = -1;
try { try {
json_filedata = &json_files.at(basename); json_filedata = &json_files.at(basename);
} catch (const out_of_range&) { } catch (const out_of_range&) {
@@ -696,6 +718,10 @@ QuestIndex::QuestIndex(
challenge_template_index = metadata_json.at("ChallengeTemplateIndex").as_int(); challenge_template_index = metadata_json.at("ChallengeTemplateIndex").as_int();
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
try {
description_flag = metadata_json.at("DescriptionFlag").as_int();
} catch (const out_of_range&) {
}
try { try {
available_expression = make_shared<IntegralExpression>(metadata_json.get_string("AvailableIf")); available_expression = make_shared<IntegralExpression>(metadata_json.get_string("AvailableIf"));
} catch (const out_of_range&) { } catch (const out_of_range&) {
@@ -704,6 +730,18 @@ QuestIndex::QuestIndex(
enabled_expression = make_shared<IntegralExpression>(metadata_json.get_string("EnabledIf")); enabled_expression = make_shared<IntegralExpression>(metadata_json.get_string("EnabledIf"));
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
try {
allow_start_from_chat_command = metadata_json.get_bool("AllowStartFromChatCommand");
} catch (const out_of_range&) {
}
try {
force_joinable = metadata_json.get_bool("Joinable");
} catch (const out_of_range&) {
}
try {
lock_status_register = metadata_json.get_bool("LockStatusRegister");
} catch (const out_of_range&) {
}
} }
auto vq = make_shared<VersionedQuest>( auto vq = make_shared<VersionedQuest>(
@@ -716,8 +754,12 @@ QuestIndex::QuestIndex(
pvr_filedata ? pvr_filedata->data : nullptr, pvr_filedata ? pvr_filedata->data : nullptr,
battle_rules, battle_rules,
challenge_template_index, challenge_template_index,
description_flag,
available_expression, available_expression,
enabled_expression); enabled_expression,
allow_start_from_chat_command,
force_joinable,
lock_status_register);
auto category_name = this->category_index->at(vq->category_id)->name; auto category_name = this->category_index->at(vq->category_id)->name;
string filenames_str = bin_filedata->filename; string filenames_str = bin_filedata->filename;
+17 -4
View File
@@ -37,7 +37,7 @@ enum class QuestMenuType {
struct QuestCategoryIndex { struct QuestCategoryIndex {
struct Category { struct Category {
uint32_t category_id; uint32_t category_id;
uint8_t enabled_flags; uint16_t enabled_flags;
std::string directory_name; std::string directory_name;
std::string name; std::string name;
std::string description; std::string description;
@@ -48,7 +48,10 @@ struct QuestCategoryIndex {
return this->enabled_flags & (1 << static_cast<uint8_t>(menu_type)); return this->enabled_flags & (1 << static_cast<uint8_t>(menu_type));
} }
[[nodiscard]] inline bool enable_episode_filter() const { [[nodiscard]] inline bool enable_episode_filter() const {
return this->enabled_flags & 0x80; return this->enabled_flags & 0x080;
}
[[nodiscard]] inline bool use_ep2_icon() const {
return this->enabled_flags & 0x100;
} }
}; };
@@ -63,7 +66,9 @@ struct VersionedQuest {
uint32_t quest_number; uint32_t quest_number;
uint32_t category_id; uint32_t category_id;
Episode episode; Episode episode;
bool allow_start_from_chat_command;
bool joinable; bool joinable;
int16_t lock_status_register;
std::string name; std::string name;
Version version; Version version;
uint8_t language; uint8_t language;
@@ -76,6 +81,7 @@ struct VersionedQuest {
std::shared_ptr<const std::string> pvr_contents; std::shared_ptr<const std::string> pvr_contents;
std::shared_ptr<const BattleRules> battle_rules; std::shared_ptr<const BattleRules> battle_rules;
ssize_t challenge_template_index; ssize_t challenge_template_index;
uint8_t description_flag;
std::shared_ptr<const IntegralExpression> available_expression; std::shared_ptr<const IntegralExpression> available_expression;
std::shared_ptr<const IntegralExpression> enabled_expression; std::shared_ptr<const IntegralExpression> enabled_expression;
@@ -89,8 +95,12 @@ struct VersionedQuest {
std::shared_ptr<const std::string> pvr_contents, std::shared_ptr<const std::string> pvr_contents,
std::shared_ptr<const BattleRules> battle_rules = nullptr, std::shared_ptr<const BattleRules> battle_rules = nullptr,
ssize_t challenge_template_index = -1, ssize_t challenge_template_index = -1,
uint8_t description_flag = 0,
std::shared_ptr<const IntegralExpression> available_expression = nullptr, std::shared_ptr<const IntegralExpression> available_expression = nullptr,
std::shared_ptr<const IntegralExpression> enabled_expression = nullptr); std::shared_ptr<const IntegralExpression> enabled_expression = nullptr,
bool allow_start_from_chat_command = false,
bool force_joinable = false,
int16_t lock_status_register = -1);
std::string bin_filename() const; std::string bin_filename() const;
std::string dat_filename() const; std::string dat_filename() const;
@@ -113,17 +123,20 @@ public:
void add_version(std::shared_ptr<const VersionedQuest> vq); void add_version(std::shared_ptr<const VersionedQuest> vq);
bool has_version(Version v, uint8_t language) const; bool has_version(Version v, uint8_t language) const;
bool has_version_any_language(Version v) const; bool has_version_any_language(Version v) const;
std::shared_ptr<const VersionedQuest> version(Version v, uint8_t language) const; std::shared_ptr<const VersionedQuest> version(Version v, uint8_t language, bool allow_language_fallback = true) const;
static uint32_t versions_key(Version v, uint8_t language); static uint32_t versions_key(Version v, uint8_t language);
uint32_t quest_number; uint32_t quest_number;
uint32_t category_id; uint32_t category_id;
Episode episode; Episode episode;
bool allow_start_from_chat_command;
bool joinable; bool joinable;
int16_t lock_status_register;
std::string name; std::string name;
std::shared_ptr<const BattleRules> battle_rules; std::shared_ptr<const BattleRules> battle_rules;
ssize_t challenge_template_index; ssize_t challenge_template_index;
uint8_t description_flag;
std::shared_ptr<const IntegralExpression> available_expression; std::shared_ptr<const IntegralExpression> available_expression;
std::shared_ptr<const IntegralExpression> enabled_expression; std::shared_ptr<const IntegralExpression> enabled_expression;
std::map<uint32_t, std::shared_ptr<const VersionedQuest>> versions; std::map<uint32_t, std::shared_ptr<const VersionedQuest>> versions;
+378 -58
View File
@@ -12,6 +12,12 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#ifdef HAVE_RESOURCE_FILE
#include <resource_file/Emulators/PPC32Emulator.hh>
#include <resource_file/Emulators/SH4Emulator.hh>
#include <resource_file/Emulators/X86Emulator.hh>
#endif
#include "BattleParamsIndex.hh" #include "BattleParamsIndex.hh"
#include "CommandFormats.hh" #include "CommandFormats.hh"
#include "Compression.hh" #include "Compression.hh"
@@ -36,7 +42,11 @@ ToT as_type(const FromT& v) {
static const char* name_for_header_episode_number(uint8_t episode) { static const char* name_for_header_episode_number(uint8_t episode) {
static const array<const char*, 3> names = {"Episode1", "Episode2", "Episode4"}; static const array<const char*, 3> names = {"Episode1", "Episode2", "Episode4"};
try {
return names.at(episode); return names.at(episode);
} catch (const out_of_range&) {
return "Episode1 # invalid value in header";
}
} }
static TextEncoding encoding_for_language(uint8_t language) { static TextEncoding encoding_for_language(uint8_t language) {
@@ -276,7 +286,7 @@ static const QuestScriptOpcodeDefinition opcode_defs[] = {
{0x000A, "letb", {REG, INT8}, F_V3_V4}, // Sets register to a fixed value (int8) {0x000A, "letb", {REG, INT8}, F_V3_V4}, // Sets register to a fixed value (int8)
{0x000B, "letw", {REG, INT16}, F_V3_V4}, // Sets register to a fixed value (int16) {0x000B, "letw", {REG, INT16}, F_V3_V4}, // Sets register to a fixed value (int16)
{0x000C, "leta", {REG, REG}, F_V3_V4}, // Sets regA to the memory address of regB {0x000C, "leta", {REG, REG}, F_V3_V4}, // Sets regA to the memory address of regB
{0x000D, "leto", {REG, SCRIPT16}, F_V3_V4}, // Sets register to the offset (NOT memory address) of a function {0x000D, "leto", {REG, SCRIPT16}, F_V3_V4}, // Sets register to the address of an entry in the quest function table
{0x0010, "set", {REG}, F_V0_V4}, // Sets a register to 1 {0x0010, "set", {REG}, F_V0_V4}, // Sets a register to 1
{0x0011, "clear", {REG}, F_V0_V4}, // Sets a register to 0 {0x0011, "clear", {REG}, F_V0_V4}, // Sets a register to 0
{0x0012, "rev", {REG}, F_V0_V4}, // Sets a register to 0 if it's nonzero and vice versa {0x0012, "rev", {REG}, F_V0_V4}, // Sets a register to 0 if it's nonzero and vice versa
@@ -681,7 +691,7 @@ static const QuestScriptOpcodeDefinition opcode_defs[] = {
{0xF8B4, "write2", {INT32, INT32}, F_V3_V4 | F_ARGS}, {0xF8B4, "write2", {INT32, INT32}, F_V3_V4 | F_ARGS},
{0xF8B5, "write4", {REG, REG}, F_V2}, {0xF8B5, "write4", {REG, REG}, F_V2},
{0xF8B5, "write4", {INT32, INT32}, F_V3_V4 | F_ARGS}, {0xF8B5, "write4", {INT32, INT32}, F_V3_V4 | F_ARGS},
{0xF8B6, "check_for_hacking", {REG}, F_V2}, // Returns a bitmask of 5 different types of detectable hacking. But it only works on DCv2 - it crashes on all other versions. {0xF8B6, "check_for_hacking", {REG}, F_V2_V4}, // Returns a bitmask of 5 different types of detectable hacking. But it only works on DCv2 - it crashes on all other versions.
{0xF8B7, "unknown_F8B7", {REG}, F_V2_V4}, // TODO (DX) - Challenge mode. Appears to be timing-related; regA is expected to be in [60, 3600]. Encodes the value with encrypt_challenge_time even though it's never sent over the network and is only decrypted locally. {0xF8B7, "unknown_F8B7", {REG}, F_V2_V4}, // TODO (DX) - Challenge mode. Appears to be timing-related; regA is expected to be in [60, 3600]. Encodes the value with encrypt_challenge_time even though it's never sent over the network and is only decrypted locally.
{0xF8B8, "disable_retry_menu", {}, F_V2_V4}, {0xF8B8, "disable_retry_menu", {}, F_V2_V4},
{0xF8B9, "chl_recovery", {}, F_V2_V4}, {0xF8B9, "chl_recovery", {}, F_V2_V4},
@@ -826,6 +836,7 @@ static const QuestScriptOpcodeDefinition opcode_defs[] = {
{0xF94A, "olga_flow_is_dead", {REG}, F_V3_V4}, {0xF94A, "olga_flow_is_dead", {REG}, F_V3_V4},
{0xF94B, "particle_effect_nc", {{REG_SET_FIXED, 4}}, F_V3_V4}, {0xF94B, "particle_effect_nc", {{REG_SET_FIXED, 4}}, F_V3_V4},
{0xF94C, "player_effect_nc", {{REG_SET_FIXED, 4}}, F_V3_V4}, {0xF94C, "player_effect_nc", {{REG_SET_FIXED, 4}}, F_V3_V4},
{0xF94D, "has_ep3_save_file", {REG}, F_GC_V3 | F_ARGS}, // (PSO Plus only) Returns 1 if a file named PSO3_CHARACTER is present on either memory card
{0xF94D, "give_or_take_card", {{REG_SET_FIXED, 2}}, F_GC_EP3}, // regsA[0] is card_id; card is given if regsA[1] >= 0, otherwise it's taken {0xF94D, "give_or_take_card", {{REG_SET_FIXED, 2}}, F_GC_EP3}, // regsA[0] is card_id; card is given if regsA[1] >= 0, otherwise it's taken
{0xF94D, "unknown_F94D", {INT32, REG}, F_XB_V3 | F_ARGS}, // Related to voice chat. argA is a client ID; a value is read from that player's TVoiceChatClient object and (!!value) is placed in regB. This value is set by the 6xB3 command; TODO: figure out what that value represents and name this opcode appropriately {0xF94D, "unknown_F94D", {INT32, REG}, F_XB_V3 | F_ARGS}, // Related to voice chat. argA is a client ID; a value is read from that player's TVoiceChatClient object and (!!value) is placed in regB. This value is set by the 6xB3 command; TODO: figure out what that value represents and name this opcode appropriately
{0xF94D, "nop_F94D", {}, F_V4}, {0xF94D, "nop_F94D", {}, F_V4},
@@ -900,7 +911,7 @@ opcodes_by_name_for_version(Version v) {
return index; return index;
} }
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t language, bool reassembly_mode) { std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t override_language, bool reassembly_mode) {
StringReader r(data, size); StringReader r(data, size);
deque<string> lines; deque<string> lines;
lines.emplace_back(string_printf(".version %s", name_for_enum(version))); lines.emplace_back(string_printf(".version %s", name_for_enum(version)));
@@ -908,6 +919,7 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
bool use_wstrs = false; bool use_wstrs = false;
size_t code_offset = 0; size_t code_offset = 0;
size_t function_table_offset = 0; size_t function_table_offset = 0;
uint8_t language;
switch (version) { switch (version) {
case Version::DC_NTE: { case Version::DC_NTE: {
const auto& header = r.get<PSOQuestHeaderDCNTE>(); const auto& header = r.get<PSOQuestHeaderDCNTE>();
@@ -923,8 +935,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
const auto& header = r.get<PSOQuestHeaderDC>(); const auto& header = r.get<PSOQuestHeaderDC>();
code_offset = header.code_offset; code_offset = header.code_offset;
function_table_offset = header.function_table_offset; function_table_offset = header.function_table_offset;
if (header.language < 5) { if (override_language != 0xFF) {
language = override_language;
} else if (header.language < 5) {
language = header.language; language = header.language;
} else {
language = 1;
} }
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load())); lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
lines.emplace_back(string_printf(".language %hhu", header.language)); lines.emplace_back(string_printf(".language %hhu", header.language));
@@ -939,8 +955,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
const auto& header = r.get<PSOQuestHeaderPC>(); const auto& header = r.get<PSOQuestHeaderPC>();
code_offset = header.code_offset; code_offset = header.code_offset;
function_table_offset = header.function_table_offset; function_table_offset = header.function_table_offset;
if (header.language < 8) { if (override_language != 0xFF) {
language = override_language;
} else if (header.language < 8) {
language = header.language; language = header.language;
} else {
language = 1;
} }
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load())); lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
lines.emplace_back(string_printf(".language %hhu", header.language)); lines.emplace_back(string_printf(".language %hhu", header.language));
@@ -957,8 +977,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
const auto& header = r.get<PSOQuestHeaderGC>(); const auto& header = r.get<PSOQuestHeaderGC>();
code_offset = header.code_offset; code_offset = header.code_offset;
function_table_offset = header.function_table_offset; function_table_offset = header.function_table_offset;
if (header.language < 5) { if (override_language != 0xFF) {
language = override_language;
} else if (header.language < 5) {
language = header.language; language = header.language;
} else {
language = 1;
} }
lines.emplace_back(string_printf(".quest_num %hhu", header.quest_number)); lines.emplace_back(string_printf(".quest_num %hhu", header.quest_number));
lines.emplace_back(string_printf(".language %hhu", header.language)); lines.emplace_back(string_printf(".language %hhu", header.language));
@@ -973,9 +997,14 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
const auto& header = r.get<PSOQuestHeaderBB>(); const auto& header = r.get<PSOQuestHeaderBB>();
code_offset = header.code_offset; code_offset = header.code_offset;
function_table_offset = header.function_table_offset; function_table_offset = header.function_table_offset;
if (override_language != 0xFF) {
language = override_language;
} else {
language = 1;
}
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load())); lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
lines.emplace_back(string_printf(".episode %s", name_for_header_episode_number(header.episode))); lines.emplace_back(string_printf(".episode %s", name_for_header_episode_number(header.episode)));
lines.emplace_back(string_printf(".max_players %hhu", header.episode)); lines.emplace_back(string_printf(".max_players %hhu", header.max_players ? header.max_players : 4));
if (header.joinable) { if (header.joinable) {
lines.emplace_back(".joinable"); lines.emplace_back(".joinable");
} }
@@ -1111,10 +1140,14 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
arg_stack_values.emplace_back(ArgStackValue::Type::LABEL, label_id); arg_stack_values.emplace_back(ArgStackValue::Type::LABEL, label_id);
} }
if (label_id >= function_table.size()) { if (label_id >= function_table.size()) {
dasm_arg = string_printf("label%04" PRIX32 " /* invalid */", label_id); dasm_arg = string_printf("label%04" PRIX32, label_id);
} else { } else {
auto& l = function_table.at(label_id); auto& l = function_table.at(label_id);
if (reassembly_mode) {
dasm_arg = string_printf("label%04" PRIX32, label_id);
} else {
dasm_arg = string_printf("label%04" PRIX32 " /* %04" PRIX32 " */", label_id, l->offset); dasm_arg = string_printf("label%04" PRIX32 " /* %04" PRIX32 " */", label_id, l->offset);
}
l->references.emplace(opcode_start_offset); l->references.emplace(opcode_start_offset);
l->add_data_type(arg.data_type); l->add_data_type(arg.data_type);
if (arg.data_type == Arg::DataType::SCRIPT) { if (arg.data_type == Arg::DataType::SCRIPT) {
@@ -1132,10 +1165,14 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
dasm_arg += (dasm_arg.empty() ? "[" : ", "); dasm_arg += (dasm_arg.empty() ? "[" : ", ");
uint32_t label_id = cmd_r.get_u16l(); uint32_t label_id = cmd_r.get_u16l();
if (label_id >= function_table.size()) { if (label_id >= function_table.size()) {
dasm_arg += string_printf("function%04" PRIX32 " /* invalid */", label_id); dasm_arg += string_printf("label%04" PRIX32, label_id);
} else { } else {
auto& l = function_table.at(label_id); auto& l = function_table.at(label_id);
if (reassembly_mode) {
dasm_arg += string_printf("label%04" PRIX32, label_id);
} else {
dasm_arg += string_printf("label%04" PRIX32 " /* %04" PRIX32 " */", label_id, l->offset); dasm_arg += string_printf("label%04" PRIX32 " /* %04" PRIX32 " */", label_id, l->offset);
}
l->references.emplace(opcode_start_offset); l->references.emplace(opcode_start_offset);
l->add_data_type(arg.data_type); l->add_data_type(arg.data_type);
if (arg.data_type == Arg::DataType::SCRIPT) { if (arg.data_type == Arg::DataType::SCRIPT) {
@@ -1638,9 +1675,10 @@ Episode find_quest_episode_from_script(const void* data, size_t size, Version ve
throw logic_error("invalid quest version"); throw logic_error("invalid quest version");
} }
const auto& opcodes = opcodes_for_version(version);
unordered_set<Episode> found_episodes; unordered_set<Episode> found_episodes;
try {
const auto& opcodes = opcodes_for_version(version);
// The set_episode opcode should always be in the first function (0) // The set_episode opcode should always be in the first function (0)
StringReader cmd_r = r.sub(code_offset + r.pget_u32l(function_table_offset)); StringReader cmd_r = r.sub(code_offset + r.pget_u32l(function_table_offset));
@@ -1733,6 +1771,9 @@ Episode find_quest_episode_from_script(const void* data, size_t size, Version ve
} }
} }
} }
} catch (const exception& e) {
log_warning("Cannot determine episode from quest script (%s)", e.what());
}
if (found_episodes.size() > 1) { if (found_episodes.size() > 1) {
throw runtime_error("multiple episodes found"); throw runtime_error("multiple episodes found");
@@ -1757,7 +1798,191 @@ Episode episode_for_quest_episode_number(uint8_t episode_number) {
} }
} }
std::string assemble_quest_script(const std::string& text) { struct RegisterAssigner {
struct Register {
string name;
int16_t number = -1; // -1 = unassigned (any number)
shared_ptr<Register> prev;
shared_ptr<Register> next;
unordered_set<size_t> offsets;
std::string str() const {
return string_printf("Register(%p, name=\"%s\", number=%hd)", this, this->name.c_str(), this->number);
}
};
~RegisterAssigner() {
for (auto& it : this->named_regs) {
it.second->prev.reset();
it.second->next.reset();
}
for (auto& reg : this->numbered_regs) {
if (reg) {
reg->prev.reset();
reg->next.reset();
}
}
}
shared_ptr<Register> get_or_create(const string& name, int16_t number) {
if ((number < -1) || (number >= 0x100)) {
throw runtime_error("invalid register number");
}
shared_ptr<Register> reg;
if (!name.empty()) {
try {
reg = this->named_regs.at(name);
} catch (const out_of_range&) {
}
}
if (!reg && number >= 0) {
reg = this->numbered_regs.at(number);
}
if (!reg) {
reg = make_shared<Register>();
}
if (number >= 0) {
if (reg->number < 0) {
reg->number = number;
auto& numbered_reg = this->numbered_regs.at(reg->number);
if (numbered_reg) {
throw runtime_error(reg->str() + " cannot be assigned due to conflict with " + numbered_reg->str());
}
this->numbered_regs.at(reg->number) = reg;
} else if (reg->number != number) {
throw runtime_error(string_printf("register %s is assigned multiple numbers", reg->name.c_str()));
}
}
if (!name.empty()) {
if (reg->name.empty()) {
reg->name = name;
if (!this->named_regs.emplace(reg->name, reg).second) {
throw runtime_error(string_printf("name %s is already assigned to a different register", reg->name.c_str()));
}
} else if (reg->name != name) {
throw runtime_error(string_printf("register %hd is assigned multiple names", reg->number));
}
}
return reg;
}
void assign_number(shared_ptr<Register> reg, uint8_t number) {
if (reg->number < 0) {
reg->number = number;
if (this->numbered_regs.at(reg->number)) {
throw logic_error(string_printf("register number %hd assigned multiple times", reg->number));
}
this->numbered_regs.at(reg->number) = reg;
} else if (reg->number != static_cast<int16_t>(number)) {
throw runtime_error(string_printf("assigning different register number %hhu over existing register number %hd", number, reg->number));
}
}
void constrain(shared_ptr<Register> first_reg, shared_ptr<Register> second_reg) {
if (!first_reg->next) {
first_reg->next = second_reg;
} else if (first_reg->next != second_reg) {
throw runtime_error(string_printf("register %s must come after %s, but is already constrained to another register", second_reg->name.c_str(), first_reg->name.c_str()));
}
if (!second_reg->prev) {
second_reg->prev = first_reg;
} else if (second_reg->prev != first_reg) {
throw runtime_error(string_printf("register %s must come before %s, but is already constrained to another register", first_reg->name.c_str(), second_reg->name.c_str()));
}
if ((first_reg->number >= 0) && (second_reg->number >= 0) && (first_reg->number != ((second_reg->number - 1) & 0xFF))) {
throw runtime_error(string_printf("register %s must come before %s, but both registers already have non-consecutive numbers", first_reg->name.c_str(), second_reg->name.c_str()));
}
}
void assign_all() {
// TODO: Technically, we should assign the biggest blocks first to minimize
// fragmentation. I am lazy and haven't implemented this yet.
vector<shared_ptr<Register>> unassigned;
for (auto it : this->named_regs) {
if (it.second->number < 0) {
unassigned.emplace_back(it.second);
}
}
for (auto reg : unassigned) {
// If this register is already assigned, skip it
if (reg->number >= 0) {
continue;
}
// If any next register is assigned, assign this register
size_t next_delta = 1;
for (auto next_reg = reg->next; next_reg; next_reg = next_reg->next, next_delta++) {
if (next_reg->number >= 0) {
this->assign_number(reg, (next_reg->number - next_delta) & 0xFF);
break;
}
}
if (reg->number >= 0) {
continue;
}
// If any prev register is assigned, assign this register
size_t prev_delta = 1;
for (auto prev_reg = reg->prev; prev_reg; prev_reg = prev_reg->prev, prev_delta++) {
if (prev_reg->number >= 0) {
this->assign_number(reg, (prev_reg->number + prev_delta) & 0xFF);
break;
}
}
if (reg->number >= 0) {
continue;
}
// No prev or next register is assigned; find an interval in the register
// number space that fits this block of registers. The total number of
// register numbers needed is (prev_delta - 1) + (next_delta - 1) + 1.
size_t num_regs = prev_delta + next_delta - 1;
this->assign_number(reg, (this->find_register_number_space(num_regs) + (prev_delta - 1)) & 0xFF);
// We don't need to assign the prev and next registers; they should also
// be in the unassigned set and will be assigned by the above logic
}
// At this point, all registers should be assigned
for (const auto& it : this->named_regs) {
if (it.second->number < 0) {
throw logic_error(string_printf("register %s was not assigned", it.second->name.c_str()));
}
}
for (size_t z = 0; z < 0x100; z++) {
auto reg = this->numbered_regs[z];
if (reg && (reg->number != static_cast<int16_t>(z))) {
throw logic_error(string_printf("register %zu has incorrect number %hd", z, reg->number));
}
}
}
uint8_t find_register_number_space(size_t num_regs) const {
for (size_t candidate = 0; candidate < 0x100; candidate++) {
size_t z;
for (z = 0; z < num_regs; z++) {
if (this->numbered_regs[candidate + z]) {
break;
}
}
if (z == num_regs) {
return candidate;
}
}
throw runtime_error("not enough space to assign registers");
}
map<string, shared_ptr<Register>> named_regs;
array<shared_ptr<Register>, 0x100> numbered_regs;
};
std::string assemble_quest_script(const std::string& text, const std::string& include_directory) {
auto lines = split(text, '\n'); auto lines = split(text, '\n');
// Strip comments and whitespace // Strip comments and whitespace
@@ -1832,7 +2057,7 @@ std::string assemble_quest_script(const std::string& text) {
ssize_t index = -1; ssize_t index = -1;
ssize_t offset = -1; ssize_t offset = -1;
}; };
unordered_map<string, shared_ptr<Label>> labels_by_name; map<string, shared_ptr<Label>> labels_by_name;
map<ssize_t, shared_ptr<Label>> labels_by_index; map<ssize_t, shared_ptr<Label>> labels_by_index;
for (size_t line_num = 1; line_num <= lines.size(); line_num++) { for (size_t line_num = 1; line_num <= lines.size(); line_num++) {
const auto& line = lines[line_num - 1]; const auto& line = lines[line_num - 1];
@@ -1883,6 +2108,88 @@ std::string assemble_quest_script(const std::string& text) {
} }
} }
// Prepare to collect named registers
RegisterAssigner reg_assigner;
auto parse_reg = [&reg_assigner](const string& arg, bool allow_unnumbered = true) -> shared_ptr<RegisterAssigner::Register> {
if (arg.size() < 2) {
throw runtime_error("register argument is too short");
}
if ((arg[0] != 'r') && (arg[0] != 'f')) {
throw runtime_error("a register is required");
}
string name;
ssize_t number = -1;
if (arg[1] == ':') {
auto tokens = split(arg.substr(2), '@');
if (tokens.size() == 1) {
name = std::move(tokens[0]);
} else if (tokens.size() == 2) {
name = std::move(tokens[0]);
number = stoull(tokens[1], nullptr, 0);
} else {
throw runtime_error("invalid register specification");
}
} else {
number = stoull(arg.substr(1), nullptr, 0);
}
if (!allow_unnumbered && (number < 0)) {
throw runtime_error("a numbered register is required");
}
if (number > 0xFF) {
throw runtime_error("invalid register number");
}
return reg_assigner.get_or_create(name, number);
};
auto parse_reg_set_fixed = [&reg_assigner, &parse_reg](const string& name, size_t expected_count) -> vector<shared_ptr<RegisterAssigner::Register>> {
if (expected_count == 0) {
throw logic_error("REG_SET_FIXED argument expects no registers");
}
if (name.empty()) {
throw runtime_error("no register specified for REG_SET_FIXED argument");
}
vector<shared_ptr<RegisterAssigner::Register>> regs;
if ((name[0] == '(') && (name.back() == ')')) {
auto tokens = split(name.substr(1, name.size() - 2), ',');
if (tokens.size() != expected_count) {
throw runtime_error("incorrect number of registers in REG_SET_FIXED");
}
for (auto& token : tokens) {
strip_trailing_whitespace(token);
strip_leading_whitespace(token);
regs.emplace_back(parse_reg(token));
if (regs.size() > 1) {
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
}
}
} else {
auto tokens = split(name, '-');
if (tokens.size() == 1) {
regs.emplace_back(parse_reg(tokens[0], false));
while (regs.size() < expected_count) {
regs.emplace_back(parse_reg("", (regs.back()->number + 1) & 0xFF));
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
}
} else if (tokens.size() == 2) {
regs.emplace_back(parse_reg(tokens[0], false));
while (regs.size() < expected_count - 1) {
regs.emplace_back(reg_assigner.get_or_create("", (regs.back()->number + 1) & 0xFF));
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
}
regs.emplace_back(parse_reg(tokens[1], false));
if (static_cast<size_t>(regs.back()->number - regs.front()->number + 1) != expected_count) {
throw runtime_error("incorrect number of registers used");
}
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
} else {
throw runtime_error("invalid fixed register set syntax");
}
}
if (regs.empty() || regs.size() != expected_count) {
throw logic_error("incorrect register count in REG_SET_FIXED after parsing");
}
return regs;
};
// Assemble code segment // Assemble code segment
bool version_has_args = F_HAS_ARGS & v_flag(quest_version); bool version_has_args = F_HAS_ARGS & v_flag(quest_version);
const auto& opcodes = opcodes_by_name_for_version(quest_version); const auto& opcodes = opcodes_by_name_for_version(quest_version);
@@ -1907,6 +2214,29 @@ std::string assemble_quest_script(const std::string& text) {
} else if (starts_with(line, ".zero ")) { } else if (starts_with(line, ".zero ")) {
size_t size = stoull(line.substr(6), nullptr, 0); size_t size = stoull(line.substr(6), nullptr, 0);
code_w.extend_by(size, 0x00); code_w.extend_by(size, 0x00);
} else if (starts_with(line, ".include_bin ")) {
string filename = line.substr(13);
strip_whitespace(filename);
code_w.write(load_file(include_directory + "/" + filename));
} else if (starts_with(line, ".include_native ")) {
#ifdef HAVE_RESOURCE_FILE
string filename = line.substr(16);
strip_whitespace(filename);
string native_text = load_file(include_directory + "/" + filename);
string code;
if (is_ppc(quest_version)) {
code = std::move(PPC32Emulator::assemble(native_text).code);
} else if (is_x86(quest_version)) {
code = std::move(X86Emulator::assemble(native_text).code);
} else if (is_sh4(quest_version)) {
code = std::move(SH4Emulator::assemble(native_text).code);
} else {
throw runtime_error("unknown architecture");
}
code_w.write(code);
#else
throw runtime_error("native code cannot be compiled; rebuild newserv with libresource_file");
#endif
} }
continue; continue;
} }
@@ -1956,16 +2286,6 @@ std::string assemble_quest_script(const std::string& text) {
strip_leading_whitespace(arg); strip_leading_whitespace(arg);
try { try {
auto parse_reg = +[](const string& name) -> uint8_t {
if ((name[0] != 'r') && (name[0] != 'f')) {
throw runtime_error("a register is required");
}
size_t reg_num = stoull(name.substr(1), nullptr, 0);
if (reg_num > 0xFF) {
throw runtime_error("invalid register number");
}
return reg_num;
};
auto add_cstr = [&](const string& text) -> void { auto add_cstr = [&](const string& text) -> void {
switch (quest_version) { switch (quest_version) {
case Version::DC_NTE: case Version::DC_NTE:
@@ -2001,37 +2321,33 @@ std::string assemble_quest_script(const std::string& text) {
} else if (label_it != labels_by_name.end()) { } else if (label_it != labels_by_name.end()) {
code_w.put_u8(0x4B); // arg_pushw code_w.put_u8(0x4B); // arg_pushw
code_w.put_u16l(label_it->second->index); code_w.put_u16l(label_it->second->index);
} else if ((arg[0] == 'r') || (arg[0] == 'f')) { } else if ((arg[0] == 'r') || (arg[0] == 'f') || ((arg[0] == '(') && (arg.back() == ')'))) {
// If the corresponding argument is a REG or REG_SET_FIXED, push // If the corresponding argument is a REG or REG_SET_FIXED, push
// the register number, not the register's value, since it's an // the register number, not the register's value, since it's an
// out-param // out-param
if ((arg_def.type == Type::REG) || (arg_def.type == Type::REG32)) { if ((arg_def.type == Type::REG) || (arg_def.type == Type::REG32)) {
code_w.put_u8(0x4A); // arg_pushb code_w.put_u8(0x4A); // arg_pushb
code_w.put_u8(parse_reg(arg)); auto reg = parse_reg(arg);
reg->offsets.emplace(code_w.size());
code_w.put_u8(reg->number);
} else if ( } else if (
(arg_def.type == Type::REG_SET_FIXED) || (arg_def.type == Type::REG_SET_FIXED) ||
(arg_def.type == Type::REG32_SET_FIXED)) { (arg_def.type == Type::REG32_SET_FIXED)) {
auto tokens = split(arg, '-'); auto regs = parse_reg_set_fixed(arg, arg_def.count);
uint8_t start_reg;
if (tokens.size() == 1) {
start_reg = parse_reg(tokens[0]);
} else if (tokens.size() == 2) {
start_reg = parse_reg(tokens[0]);
if (static_cast<size_t>(parse_reg(tokens[1]) - start_reg + 1) != arg_def.count) {
throw runtime_error("incorrect number of registers used");
}
} else {
throw runtime_error("invalid fixed register set syntax");
}
code_w.put_u8(0x4A); // arg_pushb code_w.put_u8(0x4A); // arg_pushb
code_w.put_u8(start_reg); regs[0]->offsets.emplace(code_w.size());
code_w.put_u8(regs[0]->number);
} else { } else {
code_w.put_u8(0x48); // arg_pushr code_w.put_u8(0x48); // arg_pushr
code_w.put_u8(parse_reg(arg)); auto reg = parse_reg(arg);
reg->offsets.emplace(code_w.size());
code_w.put_u8(reg->number);
} }
} else if ((arg[0] == '@') && ((arg[1] == 'r') || (arg[1] == 'f'))) { } else if ((arg[0] == '@') && ((arg[1] == 'r') || (arg[1] == 'f'))) {
code_w.put_u8(0x4C); // arg_pusha code_w.put_u8(0x4C); // arg_pusha
code_w.put_u8(parse_reg(arg.substr(1))); auto reg = parse_reg(arg.substr(1));
reg->offsets.emplace(code_w.size());
code_w.put_u8(reg->number);
} else if ((arg[0] == '@') && labels_by_name.count(arg.substr(1))) { } else if ((arg[0] == '@') && labels_by_name.count(arg.substr(1))) {
code_w.put_u8(0x4D); // arg_pusho code_w.put_u8(0x4D); // arg_pusho
code_w.put_u16(labels_by_name.at(arg.substr(1))->index); code_w.put_u16(labels_by_name.at(arg.substr(1))->index);
@@ -2076,11 +2392,12 @@ std::string assemble_quest_script(const std::string& text) {
code_w.put_u16(labels_by_name.at(name)->index); code_w.put_u16(labels_by_name.at(name)->index);
} }
}; };
auto add_reg = [&](const string& name, bool is32) -> void { auto add_reg = [&](shared_ptr<RegisterAssigner::Register> reg, bool is32) -> void {
reg->offsets.emplace(code_w.size());
if (is32) { if (is32) {
code_w.put_u32l(parse_reg(name)); code_w.put_u32l(reg->number & 0xFF);
} else { } else {
code_w.put_u8(parse_reg(name)); code_w.put_u8(reg->number);
} }
}; };
@@ -2112,30 +2429,21 @@ std::string assemble_quest_script(const std::string& text) {
} }
case Type::REG: case Type::REG:
case Type::REG32: case Type::REG32:
add_reg(arg, arg_def.type == Type::REG32); add_reg(parse_reg(arg), arg_def.type == Type::REG32);
break; break;
case Type::REG_SET_FIXED: case Type::REG_SET_FIXED:
case Type::REG32_SET_FIXED: { case Type::REG32_SET_FIXED: {
auto tokens = split(arg, '-'); auto regs = parse_reg_set_fixed(arg, arg_def.count);
if (tokens.size() == 1) { add_reg(regs[0], arg_def.type == Type::REG32_SET_FIXED);
add_reg(tokens[0], arg_def.type == Type::REG32_SET_FIXED);
} else if (tokens.size() == 2) {
if (static_cast<size_t>(parse_reg(tokens[1]) - parse_reg(tokens[0]) + 1) != arg_def.count) {
throw runtime_error("incorrect number of registers used");
}
add_reg(tokens[0], arg_def.type == Type::REG32_SET_FIXED);
} else {
throw runtime_error("invalid fixed register set syntax");
}
break; break;
} }
case Type::REG_SET: { case Type::REG_SET: {
auto regs = split_set(arg); auto regs = split_set(arg);
code_w.put_u8(regs.size()); code_w.put_u8(regs.size());
for (auto reg : regs) { for (auto reg_arg : regs) {
strip_trailing_whitespace(reg); strip_trailing_whitespace(reg_arg);
strip_leading_whitespace(reg); strip_leading_whitespace(reg_arg);
add_reg(reg, false); add_reg(parse_reg(reg_arg), false);
} }
break; break;
} }
@@ -2180,6 +2488,18 @@ std::string assemble_quest_script(const std::string& text) {
code_w.put_u8(0); code_w.put_u8(0);
} }
// Assign all register numbers and patch the code section if needed
reg_assigner.assign_all();
for (size_t z = 0; z < 0x100; z++) {
auto reg = reg_assigner.numbered_regs[z];
if (!reg) {
continue;
}
for (size_t offset : reg->offsets) {
code_w.pput_u8(offset, reg->number);
}
}
// Generate function table // Generate function table
ssize_t function_table_size = labels_by_index.rbegin()->first + 1; ssize_t function_table_size = labels_by_index.rbegin()->first + 1;
vector<le_uint32_t> function_table; vector<le_uint32_t> function_table;
+2 -2
View File
@@ -82,7 +82,7 @@ struct PSOQuestHeaderBB {
Episode episode_for_quest_episode_number(uint8_t episode_number); Episode episode_for_quest_episode_number(uint8_t episode_number);
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t language, bool reassembly_mode); std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t override_language = 0xFF, bool reassembly_mode = false);
std::string assemble_quest_script(const std::string& text); std::string assemble_quest_script(const std::string& text, const std::string& include_directory);
Episode find_quest_episode_from_script(const void* data, size_t size, Version version); Episode find_quest_episode_from_script(const void* data, size_t size, Version version);
+358 -168
View File
@@ -103,6 +103,8 @@ static shared_ptr<const Menu> proxy_options_menu_for_client(shared_ptr<const Cli
"Save files", "Save local copies of\nfiles from the\nremote server\n(quests, etc.)"); "Save files", "Save local copies of\nfiles from the\nremote server\n(quests, etc.)");
} }
if (s->proxy_enable_login_options) { if (s->proxy_enable_login_options) {
add_flag_option(ProxyOptionsMenuItemID::VIRTUAL_CLIENT, Client::Flag::PROXY_VIRTUAL_CLIENT,
"Virtual client", "");
add_flag_option(ProxyOptionsMenuItemID::RED_NAME, Client::Flag::PROXY_RED_NAME_ENABLED, add_flag_option(ProxyOptionsMenuItemID::RED_NAME, Client::Flag::PROXY_RED_NAME_ENABLED,
"Red name", "Set the colors\nof your name and\nChallenge Mode\nrank to red"); "Red name", "Set the colors\nof your name and\nChallenge Mode\nrank to red");
add_flag_option(ProxyOptionsMenuItemID::BLANK_NAME, Client::Flag::PROXY_BLANK_NAME_ENABLED, add_flag_option(ProxyOptionsMenuItemID::BLANK_NAME, Client::Flag::PROXY_BLANK_NAME_ENABLED,
@@ -128,7 +130,7 @@ void send_first_pre_lobby_commands(shared_ptr<Client> c, std::function<void()> o
if (function_compiler_available() && if (function_compiler_available() &&
!c->config.check_flag(Client::Flag::HAS_AUTO_PATCHES) && !c->config.check_flag(Client::Flag::HAS_AUTO_PATCHES) &&
!c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
prepare_client_for_patches(c, [wc = weak_ptr<Client>(c), on_complete = std::move(on_complete)]() -> void { prepare_client_for_patches(c, [wc = weak_ptr<Client>(c), on_complete = std::move(on_complete)]() -> void {
auto c = wc.lock(); auto c = wc.lock();
if (!c) { if (!c) {
@@ -226,6 +228,10 @@ void send_client_to_proxy_server(shared_ptr<Client> c) {
if (ses->config.check_flag(Client::Flag::PROXY_ZERO_REMOTE_GUILD_CARD)) { if (ses->config.check_flag(Client::Flag::PROXY_ZERO_REMOTE_GUILD_CARD)) {
ses->remote_guild_card_number = 0; ses->remote_guild_card_number = 0;
} }
if (c->version() == Version::GC_EP3) {
send_ep3_media_update(c, 4, 0, "");
ses->config.clear_flag(Client::Flag::HAS_EP3_MEDIA_UPDATES);
}
send_reconnect(c, s->connect_address_for_client(c), local_port); send_reconnect(c, s->connect_address_for_client(c), local_port);
}); });
@@ -236,26 +242,16 @@ static void send_proxy_destinations_menu(shared_ptr<Client> c) {
send_menu(c, s->proxy_destinations_menu(c->version())); send_menu(c, s->proxy_destinations_menu(c->version()));
} }
static bool send_enable_send_function_call_if_applicable(shared_ptr<Client> c) {
auto s = c->require_server_state();
if (function_compiler_available() && c->config.check_flag(Client::Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL)) {
if (s->ep3_send_function_call_enabled) {
send_quest_buffer_overflow(c);
} else {
c->config.set_flag(Client::Flag::NO_SEND_FUNCTION_CALL);
}
c->config.clear_flag(Client::Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL);
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void on_connect(std::shared_ptr<Client> c) { void on_connect(std::shared_ptr<Client> c) {
auto s = c->require_server_state();
if (s->default_switch_assist_enabled) {
c->config.set_flag(Client::Flag::SWITCH_ASSIST_ENABLED);
}
switch (c->server_behavior) { switch (c->server_behavior) {
case ServerBehavior::PC_CONSOLE_DETECT: { case ServerBehavior::PC_CONSOLE_DETECT: {
auto s = c->require_server_state();
uint16_t pc_port = s->name_to_port_config.at("pc-login")->port; uint16_t pc_port = s->name_to_port_config.at("pc-login")->port;
uint16_t console_port = s->name_to_port_config.at("console-login")->port; uint16_t console_port = s->name_to_port_config.at("console-login")->port;
send_pc_console_split_reconnect(c, s->connect_address_for_client(c), pc_port, console_port); send_pc_console_split_reconnect(c, s->connect_address_for_client(c), pc_port, console_port);
@@ -359,13 +355,7 @@ static void send_main_menu(shared_ptr<Client> c) {
send_menu(c, main_menu); send_menu(c, main_menu);
} }
void on_login_complete(shared_ptr<Client> c) { void on_login_server_login_complete(shared_ptr<Client> c) {
c->convert_account_to_temporary_if_nte();
// On BB, this function is called when the data server phase is done (and we
// should send the ship select menu), so we don't need to check for it here.
switch (c->server_behavior) {
case ServerBehavior::LOGIN_SERVER: {
auto s = c->require_server_state(); auto s = c->require_server_state();
if (s->pre_lobby_event && (!is_ep3(c->version()) || s->ep3_menu_song < 0)) { if (s->pre_lobby_event && (!is_ep3(c->version()) || s->ep3_menu_song < 0)) {
@@ -381,12 +371,66 @@ void on_login_complete(shared_ptr<Client> c) {
c->config.check_flag(Client::Flag::NO_D6) || c->config.check_flag(Client::Flag::NO_D6) ||
!c->config.check_flag(Client::Flag::AT_WELCOME_MESSAGE)) { !c->config.check_flag(Client::Flag::AT_WELCOME_MESSAGE)) {
c->config.clear_flag(Client::Flag::AT_WELCOME_MESSAGE); c->config.clear_flag(Client::Flag::AT_WELCOME_MESSAGE);
send_enable_send_function_call_if_applicable(c);
send_update_client_config(c, false); send_update_client_config(c, false);
send_main_menu(c); send_main_menu(c);
} else { } else {
send_message_box(c, s->welcome_message.c_str()); send_message_box(c, s->welcome_message.c_str());
} }
}
void on_login_complete(shared_ptr<Client> c) {
c->convert_account_to_temporary_if_nte();
// On BB, this function is called when the data server phase is done (and we
// should send the ship select menu), so we don't need to check for it here.
switch (c->server_behavior) {
case ServerBehavior::LOGIN_SERVER: {
auto s = c->require_server_state();
if (c->config.check_flag(Client::Flag::CAN_RECEIVE_ENABLE_B2_QUEST) &&
!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL) &&
(s->enable_send_function_call_quest_num >= 0)) {
auto q = s->default_quest_index->get(s->enable_send_function_call_quest_num);
if (q) {
uint8_t q_language;
switch (c->sub_version) {
case 0x39:
q_language = 0; // Japanese (JP Plus v1.5)
break;
case 0x42:
case 0x43:
q_language = 2; // German (EU Ep3)
break;
case 0x41:
q_language = 4; // Spanish (US Ep3)
break;
case 0x36:
case 0x3A:
default:
q_language = 1; // English (US Plus v1.2 + customizations)
}
auto vq = q->version(is_ep3(c->version()) ? Version::GC_V3 : c->version(), q_language, false);
if (vq) {
c->config.set_flag(Client::Flag::HAS_SEND_FUNCTION_CALL);
c->config.set_flag(Client::Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH);
c->config.set_flag(Client::Flag::AWAITING_ENABLE_B2_QUEST);
send_update_client_config(c, false);
c->log.info("Sending %c version of quest \"%s\"", char_for_language_code(vq->language), vq->name.c_str());
string bin_filename = vq->bin_filename();
string dat_filename = vq->dat_filename();
string xb_filename = vq->xb_filename();
send_open_quest_file(c, bin_filename, bin_filename, xb_filename, vq->quest_number, QuestFileType::ONLINE, vq->bin_contents);
send_open_quest_file(c, dat_filename, dat_filename, xb_filename, vq->quest_number, QuestFileType::ONLINE, vq->dat_contents);
send_command(c, 0xAC, 0x00);
}
}
}
if (!c->config.check_flag(Client::Flag::AWAITING_ENABLE_B2_QUEST)) {
on_login_server_login_complete(c);
}
break; break;
} }
@@ -465,6 +509,20 @@ static void on_1D(shared_ptr<Client> c, uint16_t, uint32_t, string&) {
c->config.clear_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_FLAG_STATE); c->config.clear_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_FLAG_STATE);
send_game_flag_state(c); // 6x6F send_game_flag_state(c); // 6x6F
} }
if (c->config.check_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_PLAYER_STATES)) {
c->config.clear_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_PLAYER_STATES);
auto l = c->require_lobby();
if (l->is_game()) {
for (auto lc : l->clients) {
// If we haven't received a 6x70 from this client, maybe they're VERY
// far behind and wil lstll send it, or maybe they'll time out and be
// disconnected soon - either way, we shouldn't fail if it's missing.
if (lc && (lc != c) && lc->last_reported_6x70) {
send_game_player_state(c, lc, true); // 6x70
}
}
}
}
} }
static void on_05_XB(shared_ptr<Client> c, uint16_t, uint32_t, string&) { static void on_05_XB(shared_ptr<Client> c, uint16_t, uint32_t, string&) {
@@ -858,18 +916,6 @@ static void on_9D_9E(shared_ptr<Client> c, uint16_t command, uint32_t, string& d
c->channel.language = base_cmd->language; c->channel.language = base_cmd->language;
set_console_client_flags(c, base_cmd->sub_version); set_console_client_flags(c, base_cmd->sub_version);
// See system/client-functions/Episode3USAQuestBufferOverflow.ppc.s for where
// this value gets set. We use this to determine if the client has already run
// the code or not; sending it again when the client has already run it will
// likely cause the client to crash.
if (base_cmd->unused1 == 0x5F5CA297) {
c->config.clear_flag(Client::Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL);
c->config.clear_flag(Client::Flag::NO_SEND_FUNCTION_CALL);
} else if (!s->ep3_send_function_call_enabled && c->config.check_flag(Client::Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL)) {
c->config.clear_flag(Client::Flag::USE_OVERFLOW_FOR_SEND_FUNCTION_CALL);
c->config.set_flag(Client::Flag::NO_SEND_FUNCTION_CALL);
}
try { try {
switch (c->version()) { switch (c->version()) {
case Version::DC_V2: { case Version::DC_V2: {
@@ -987,37 +1033,6 @@ static void on_9E_XB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} }
} }
static void scramble_bb_security_data(parray<uint8_t, 0x28>& data, uint8_t which, bool reverse) {
static const uint8_t forward_orders[8][5] = {
{2, 0, 1, 4, 3},
{3, 4, 0, 1, 2},
{2, 3, 4, 0, 1},
{2, 3, 0, 1, 4},
{0, 2, 3, 4, 1},
{1, 4, 2, 3, 0},
{2, 0, 1, 4, 3},
{1, 0, 3, 4, 2},
};
static const uint8_t reverse_orders[8][5] = {
{1, 2, 0, 4, 3},
{2, 3, 4, 0, 1},
{3, 4, 0, 1, 2},
{2, 3, 0, 1, 4},
{0, 4, 1, 2, 3},
{4, 0, 2, 3, 1},
{1, 2, 0, 4, 3},
{1, 0, 4, 2, 3},
};
const auto& order = reverse ? reverse_orders[which & 7] : forward_orders[which & 7];
parray<uint8_t, 0x28> scrambled_data;
for (size_t z = 0; z < 5; z++) {
for (size_t x = 0; x < 8; x++) {
scrambled_data[(z * 8) + x] = data[(order[z] * 8) + x];
}
}
data = scrambled_data;
}
static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) { static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
const auto& base_cmd = check_size_t<C_LoginBase_BB_93>(data, 0xFFFF); const auto& base_cmd = check_size_t<C_LoginBase_BB_93>(data, 0xFFFF);
auto s = c->require_server_state(); auto s = c->require_server_state();
@@ -1026,12 +1041,6 @@ static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
? check_size_t<C_LoginWithoutHardwareInfo_BB_93>(data).client_config ? check_size_t<C_LoginWithoutHardwareInfo_BB_93>(data).client_config
: check_size_t<C_LoginWithHardwareInfo_BB_93>(data).client_config; : check_size_t<C_LoginWithHardwareInfo_BB_93>(data).client_config;
// If security_token is zero, the game scrambles the client config data based
// on the first character in the username. We undo the scramble here.
if (base_cmd.security_token == 0) {
scramble_bb_security_data(config_data, base_cmd.username.at(0), true);
}
c->config.set_flags_for_version(c->version(), base_cmd.sub_version); c->config.set_flags_for_version(c->version(), base_cmd.sub_version);
c->channel.language = base_cmd.language; c->channel.language = base_cmd.language;
string username = base_cmd.username.decode(); string username = base_cmd.username.decode();
@@ -1057,6 +1066,48 @@ static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} else { } else {
string version_string = config_data.as_string(); string version_string = config_data.as_string();
strip_trailing_zeroes(version_string); strip_trailing_zeroes(version_string);
// If the version string starts with "Ver.", assume it's Sega and apply the
// normal version encoding logic. Otherwise, assume it's a community mod,
// almost all of which are based on TethVer12513, so assume that version
// otherwise.
if (starts_with(version_string, "Ver.")) {
// Basic algorithm: take all numeric characters from the version string
// and ignore everything else. Treat that as a decimal integer, then
// base36-encode it into the low 3 bytes of specific_version.
uint64_t version = 0;
for (char ch : version_string) {
if (isdigit(ch)) {
version = (version * 10) + (ch - '0');
}
}
uint8_t shift = 0;
uint32_t specific_version = 0;
while (version) {
if (shift > 16) {
throw runtime_error("invalid version string");
}
uint8_t ch = (version % 36) + '0';
version /= 36;
if (ch > '9') {
ch += 7;
}
specific_version |= (ch << shift);
shift += 8;
}
if (!(specific_version & 0x00FF0000)) {
specific_version |= 0x00300000;
}
if (!(specific_version & 0x0000FF00)) {
specific_version |= 0x00003000;
}
if (!(specific_version & 0x000000FF)) {
specific_version |= 0x00000030;
}
c->config.specific_version = 0x35000000 | specific_version;
} else {
c->config.specific_version = 0x35394E4C; // 59NL
// Note: Tethealla PSOBB is actually Japanese PSOBB, but with most of the // Note: Tethealla PSOBB is actually Japanese PSOBB, but with most of the
// files replaced with English text/graphics/etc. For this reason, it still // files replaced with English text/graphics/etc. For this reason, it still
// reports its language as Japanese, so we have to account for that // reports its language as Japanese, so we have to account for that
@@ -1066,6 +1117,7 @@ static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->config.set_flag(Client::Flag::FORCE_ENGLISH_LANGUAGE_BB); c->config.set_flag(Client::Flag::FORCE_ENGLISH_LANGUAGE_BB);
} }
} }
}
c->channel.language = c->config.check_flag(Client::Flag::FORCE_ENGLISH_LANGUAGE_BB) ? 1 : base_cmd.language; c->channel.language = c->config.check_flag(Client::Flag::FORCE_ENGLISH_LANGUAGE_BB) ? 1 : base_cmd.language;
c->bb_connection_phase = base_cmd.connection_phase; c->bb_connection_phase = base_cmd.connection_phase;
c->bb_character_index = base_cmd.character_slot; c->bb_character_index = base_cmd.character_slot;
@@ -1229,6 +1281,7 @@ static bool add_next_game_client(shared_ptr<Lobby> l) {
s->change_client_lobby(c, l, true, target_client_id); s->change_client_lobby(c, l, true, target_client_id);
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
if (tourn) { if (tourn) {
c->config.set_flag(Client::Flag::LOADING_TOURNAMENT); c->config.set_flag(Client::Flag::LOADING_TOURNAMENT);
} }
@@ -1572,7 +1625,22 @@ static void on_CA_Ep3(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} }
bool battle_finished_before = l->ep3_server->battle_finished; bool battle_finished_before = l->ep3_server->battle_finished;
if (s->catch_handler_exceptions) {
try {
l->ep3_server->on_server_data_input(c, data); l->ep3_server->on_server_data_input(c, data);
} catch (const exception& e) {
c->log.error("Episode 3 engine returned an error: %s", e.what());
if (l->battle_record) {
string filename = string_printf("system/ep3/battle-records/exc.%" PRIu64 ".mzrd", now());
save_file(filename, l->battle_record->serialize());
c->log.error("Saved partial battle record as %s", filename.c_str());
}
throw;
}
} else {
l->ep3_server->on_server_data_input(c, data);
}
// If the battle has finished, finalize the recording and link it to all // If the battle has finished, finalize the recording and link it to all
// participating players and spectators // participating players and spectators
@@ -1703,7 +1771,6 @@ static void on_D6_V3(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
send_menu(c, s->information_menu(c->version())); send_menu(c, s->information_menu(c->version()));
} else if (c->config.check_flag(Client::Flag::AT_WELCOME_MESSAGE)) { } else if (c->config.check_flag(Client::Flag::AT_WELCOME_MESSAGE)) {
c->config.clear_flag(Client::Flag::AT_WELCOME_MESSAGE); c->config.clear_flag(Client::Flag::AT_WELCOME_MESSAGE);
send_enable_send_function_call_if_applicable(c);
send_update_client_config(c, false); send_update_client_config(c, false);
send_main_menu(c); send_main_menu(c);
} }
@@ -1714,7 +1781,8 @@ static void on_09(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
auto s = c->require_server_state(); auto s = c->require_server_state();
switch (cmd.menu_id) { switch (cmd.menu_id) {
case MenuID::QUEST_CATEGORIES: case MenuID::QUEST_CATEGORIES_EP1:
case MenuID::QUEST_CATEGORIES_EP2:
// Don't send anything here. The quest filter menu already has short // Don't send anything here. The quest filter menu already has short
// descriptions included with the entries, which the client shows in the // descriptions included with the entries, which the client shows in the
// usual location on the screen. // usual location on the screen.
@@ -1724,17 +1792,17 @@ static void on_09(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
bool is_download_quest = !c->lobby.lock(); bool is_download_quest = !c->lobby.lock();
auto quest_index = s->quest_index(c->version()); auto quest_index = s->quest_index(c->version());
if (!quest_index) { if (!quest_index) {
send_quest_info(c, "$C7Quests are not available.", is_download_quest); send_quest_info(c, "$C7Quests are not available.", 0x00, is_download_quest);
} else { } else {
auto q = quest_index->get(cmd.item_id); auto q = quest_index->get(cmd.item_id);
if (!q) { if (!q) {
send_quest_info(c, "$C4Quest does not\nexist.", is_download_quest); send_quest_info(c, "$C4Quest does not\nexist.", 0x00, is_download_quest);
} else { } else {
auto vq = q->version(c->version(), c->language()); auto vq = q->version(c->version(), c->language());
if (!vq) { if (!vq) {
send_quest_info(c, "$C4Quest does not\nexist for this game\nversion.", is_download_quest); send_quest_info(c, "$C4Quest does not\nexist for this game\nversion.", 0x00, is_download_quest);
} else { } else {
send_quest_info(c, vq->long_description, is_download_quest); send_quest_info(c, vq->long_description, vq->description_flag, is_download_quest);
} }
} }
} }
@@ -1803,6 +1871,8 @@ static void on_09(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
info += "$C6Quest in progress\n"; info += "$C6Quest in progress\n";
} else if (game->check_flag(Lobby::Flag::QUEST_IN_PROGRESS)) { } else if (game->check_flag(Lobby::Flag::QUEST_IN_PROGRESS)) {
info += "$C4Quest in progress\n"; info += "$C4Quest in progress\n";
} else if (game->check_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS)) {
info += "$C4Selecting quest\n";
} }
switch (game->drop_mode) { switch (game->drop_mode) {
@@ -1952,11 +2022,11 @@ static void on_quest_loaded(shared_ptr<Lobby> l) {
lc->delete_overlay(); lc->delete_overlay();
if (l->quest->battle_rules) { if (l->quest->battle_rules) {
lc->use_default_bank(); lc->use_default_bank();
lc->create_battle_overlay(l->quest->battle_rules, s->level_table); lc->create_battle_overlay(l->quest->battle_rules, s->level_table(lc->version()));
lc->log.info("Created battle overlay"); lc->log.info("Created battle overlay");
} else if (l->quest->challenge_template_index >= 0) { } else if (l->quest->challenge_template_index >= 0) {
lc->use_default_bank(); lc->use_default_bank();
lc->create_challenge_overlay(lc->version(), l->quest->challenge_template_index, s->level_table); lc->create_challenge_overlay(lc->version(), l->quest->challenge_template_index, s->level_table(lc->version()));
lc->log.info("Created challenge overlay"); lc->log.info("Created challenge overlay");
l->assign_inventory_and_bank_item_ids(lc, true); l->assign_inventory_and_bank_item_ids(lc, true);
} }
@@ -1972,6 +2042,14 @@ void set_lobby_quest(shared_ptr<Lobby> l, shared_ptr<const Quest> q, bool substi
throw runtime_error("lobby already has an assigned quest"); throw runtime_error("lobby already has an assigned quest");
} }
// Only allow loading battle/challenge quests if the game mode is correct
if ((q->challenge_template_index >= 0) != (l->mode == GameMode::CHALLENGE)) {
throw runtime_error("incorrect game mode");
}
if ((q->battle_rules != nullptr) != (l->mode == GameMode::BATTLE)) {
throw runtime_error("incorrect game mode");
}
auto s = l->require_server_state(); auto s = l->require_server_state();
if (q->joinable) { if (q->joinable) {
@@ -1979,6 +2057,7 @@ void set_lobby_quest(shared_ptr<Lobby> l, shared_ptr<const Quest> q, bool substi
} else { } else {
l->set_flag(Lobby::Flag::QUEST_IN_PROGRESS); l->set_flag(Lobby::Flag::QUEST_IN_PROGRESS);
} }
l->clear_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS);
l->clear_flag(Lobby::Flag::PERSISTENT); l->clear_flag(Lobby::Flag::PERSISTENT);
l->quest = q; l->quest = q;
@@ -2025,6 +2104,7 @@ void set_lobby_quest(shared_ptr<Lobby> l, shared_ptr<const Quest> q, bool substi
lc->should_disconnect = true; lc->should_disconnect = true;
break; break;
} }
lc->log.info("Sending %c version of quest \"%s\"", char_for_language_code(vq->language), vq->name.c_str());
string bin_filename = vq->bin_filename(); string bin_filename = vq->bin_filename();
string dat_filename = vq->dat_filename(); string dat_filename = vq->dat_filename();
@@ -2034,6 +2114,7 @@ void set_lobby_quest(shared_ptr<Lobby> l, shared_ptr<const Quest> q, bool substi
if (use_loading_flag) { if (use_loading_flag) {
lc->config.set_flag(Client::Flag::LOADING_QUEST); lc->config.set_flag(Client::Flag::LOADING_QUEST);
lc->log.info("LOADING_QUEST flag set");
lc->disconnect_hooks.emplace(QUEST_BARRIER_DISCONNECT_HOOK_NAME, [l]() -> void { lc->disconnect_hooks.emplace(QUEST_BARRIER_DISCONNECT_HOOK_NAME, [l]() -> void {
send_quest_barrier_if_all_clients_ready(l); send_quest_barrier_if_all_clients_ready(l);
}); });
@@ -2141,7 +2222,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (!function_compiler_available()) { if (!function_compiler_available()) {
throw runtime_error("function compiler not available"); throw runtime_error("function compiler not available");
} }
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
prepare_client_for_patches(c, [c]() -> void { prepare_client_for_patches(c, [c]() -> void {
@@ -2153,7 +2234,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (!function_compiler_available()) { if (!function_compiler_available()) {
throw runtime_error("function compiler not available"); throw runtime_error("function compiler not available");
} }
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
// We have to prepare the client for patches here, even though we // We have to prepare the client for patches here, even though we
@@ -2168,7 +2249,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (!function_compiler_available()) { if (!function_compiler_available()) {
throw runtime_error("function compiler not available"); throw runtime_error("function compiler not available");
} }
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
prepare_client_for_patches(c, [c]() -> void { prepare_client_for_patches(c, [c]() -> void {
@@ -2296,6 +2377,9 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
case ProxyOptionsMenuItemID::SAVE_FILES: case ProxyOptionsMenuItemID::SAVE_FILES:
c->config.toggle_flag(Client::Flag::PROXY_SAVE_FILES); c->config.toggle_flag(Client::Flag::PROXY_SAVE_FILES);
goto resend_proxy_options_menu; goto resend_proxy_options_menu;
case ProxyOptionsMenuItemID::VIRTUAL_CLIENT:
c->config.toggle_flag(Client::Flag::PROXY_VIRTUAL_CLIENT);
goto resend_proxy_options_menu;
case ProxyOptionsMenuItemID::RED_NAME: case ProxyOptionsMenuItemID::RED_NAME:
c->config.toggle_flag(Client::Flag::PROXY_RED_NAME_ENABLED); c->config.toggle_flag(Client::Flag::PROXY_RED_NAME_ENABLED);
goto resend_proxy_options_menu; goto resend_proxy_options_menu;
@@ -2374,6 +2458,8 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} }
if (game->is_game()) { if (game->is_game()) {
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
// If no one was in the game before, then there's no leader to send // If no one was in the game before, then there's no leader to send
// the game state - send it to the joining player (who is now the // the game state - send it to the joining player (who is now the
// leader) // leader)
@@ -2391,6 +2477,9 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
case Lobby::JoinError::VERSION_CONFLICT: case Lobby::JoinError::VERSION_CONFLICT:
send_lobby_message_box(c, "$C7You cannot join this\ngame because it is\nfor a different\nversion of PSO."); send_lobby_message_box(c, "$C7You cannot join this\ngame because it is\nfor a different\nversion of PSO.");
break; break;
case Lobby::JoinError::QUEST_SELECTION_IN_PROGRESS:
send_lobby_message_box(c, "$C7You cannot join this\ngame because the\nplayers are currently\nchoosing a quest.");
break;
case Lobby::JoinError::QUEST_IN_PROGRESS: case Lobby::JoinError::QUEST_IN_PROGRESS:
send_lobby_message_box(c, "$C7You cannot join this\ngame because a\nquest is already\nin progress."); send_lobby_message_box(c, "$C7You cannot join this\ngame because a\nquest is already\nin progress.");
break; break;
@@ -2428,7 +2517,8 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
break; break;
} }
case MenuID::QUEST_CATEGORIES: { case MenuID::QUEST_CATEGORIES_EP1:
case MenuID::QUEST_CATEGORIES_EP2: {
auto s = c->require_server_state(); auto s = c->require_server_state();
auto quest_index = s->quest_index(c->version()); auto quest_index = s->quest_index(c->version());
if (!quest_index) { if (!quest_index) {
@@ -2517,7 +2607,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
send_main_menu(c); send_main_menu(c);
} else { } else {
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
@@ -2535,7 +2625,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
send_main_menu(c); send_main_menu(c);
} else { } else {
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
@@ -2555,7 +2645,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
send_main_menu(c); send_main_menu(c);
} else { } else {
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw runtime_error("client does not support send_function_call"); throw runtime_error("client does not support send_function_call");
} }
@@ -2640,6 +2730,13 @@ static void on_84(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
const auto& cmd = check_size_t<C_LobbySelection_84>(data); const auto& cmd = check_size_t<C_LobbySelection_84>(data);
auto s = c->require_server_state(); auto s = c->require_server_state();
if ((c->server_behavior == ServerBehavior::LOGIN_SERVER) &&
c->config.check_flag(Client::Flag::AWAITING_ENABLE_B2_QUEST)) {
on_login_server_login_complete(c);
c->config.clear_flag(Client::Flag::AWAITING_ENABLE_B2_QUEST);
return;
}
if (cmd.menu_id != MenuID::LOBBY) { if (cmd.menu_id != MenuID::LOBBY) {
send_message_box(c, "Incorrect menu ID"); send_message_box(c, "Incorrect menu ID");
return; return;
@@ -2745,7 +2842,7 @@ static void send_dol_file_chunk(shared_ptr<Client> c, uint32_t start_addr) {
auto fn = s->function_code_index->name_to_function.at("WriteMemory"); auto fn = s->function_code_index->name_to_function.at("WriteMemory");
unordered_map<string, uint32_t> label_writes( unordered_map<string, uint32_t> label_writes(
{{"dest_addr", start_addr}, {"size", bytes_to_send}}); {{"dest_addr", start_addr}, {"size", bytes_to_send}});
send_function_call(c, fn, label_writes, data_to_send); send_function_call(c, fn, label_writes, data_to_send.data(), data_to_send.size());
size_t progress_percent = ((offset + bytes_to_send) * 100) / c->loading_dol_file->data.size(); size_t progress_percent = ((offset + bytes_to_send) * 100) / c->loading_dol_file->data.size();
send_ship_info(c, string_printf("%zu%%%%", progress_percent)); send_ship_info(c, string_printf("%zu%%%%", progress_percent));
@@ -2793,11 +2890,11 @@ static void on_A2(shared_ptr<Client> c, uint16_t, uint32_t flag, string& data) {
return; return;
} }
// In Episode 3, there are no quest categories, so skip directly to the quest
// filter menu.
if (is_ep3(c->version())) { if (is_ep3(c->version())) {
send_lobby_message_box(c, "$C7Episode 3 does not\nprovide online quests\nvia this interface."); send_lobby_message_box(c, "$C7Episode 3 does not\nprovide online quests\nvia this interface.");
} else { return;
}
QuestMenuType menu_type; QuestMenuType menu_type;
if ((c->version() == Version::BB_V4) && flag) { if ((c->version() == Version::BB_V4) && flag) {
menu_type = QuestMenuType::GOVERNMENT; menu_type = QuestMenuType::GOVERNMENT;
@@ -2819,34 +2916,61 @@ static void on_A2(shared_ptr<Client> c, uint16_t, uint32_t flag, string& data) {
throw logic_error("invalid game mode"); throw logic_error("invalid game mode");
} }
} }
send_quest_categories_menu(c, s->quest_index(c->version()), menu_type, l->episode); send_quest_categories_menu(c, s->quest_index(c->version()), menu_type, l->episode);
l->set_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS);
}
static void on_A9(shared_ptr<Client> c, uint16_t, uint32_t, string&) {
auto l = c->require_lobby();
if (l->is_game() && (c->lobby_client_id == l->leader_id)) {
l->clear_flag(Lobby::Flag::QUEST_SELECTION_IN_PROGRESS);
}
}
static void on_joinable_quest_loaded(shared_ptr<Client> c) {
auto l = c->require_lobby();
if (!l->is_game() || !l->quest) {
throw runtime_error("joinable quest load completed in non-game");
}
auto leader_c = l->clients.at(l->leader_id);
if (!leader_c) {
throw logic_error("lobby leader is missing");
}
// On BB, ask the leader to send the quest state to the joining player (and
// we'll need to use the game join command queue to avoid any item ID races).
// On other versions, the server will have to generate the state commands;
// this happens when the response to the ping (1D) is received, so we don't
// need the game join command queue in that case.
if (leader_c->version() == Version::BB_V4) {
send_command(leader_c, 0xDD, c->lobby_client_id);
c->log.info("Creating game join command queue");
c->game_join_command_queue = make_unique<deque<Client::JoinCommand>>();
} else {
c->config.set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_ITEM_STATE);
c->config.set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE);
c->config.set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_OBJECT_STATE);
c->config.set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_FLAG_STATE);
c->config.set_flag(Client::Flag::SHOULD_SEND_ARTIFICIAL_PLAYER_STATES);
}
send_command(c, 0x1D, 0x00);
if (!is_v1_or_v2(c->version())) {
send_command(c, 0xAC, 0x00);
} }
} }
static void on_AC_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) { static void on_AC_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
check_size_v(data.size(), 0); check_size_v(data.size(), 0);
auto l = c->require_lobby();
if (c->config.check_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST)) { if (c->config.check_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST)) {
if (l->base_version != Version::BB_V4) { on_joinable_quest_loaded(c);
throw logic_error("joinable quest started on non-BB version");
}
auto leader_c = l->clients.at(l->leader_id);
if (!leader_c) {
throw logic_error("lobby leader is missing");
}
send_command(leader_c, 0xDD, c->lobby_client_id);
send_command(c, 0xAC, 0x00);
c->log.info("Creating game join command queue");
c->game_join_command_queue = make_unique<deque<Client::JoinCommand>>();
send_command(c, 0x1D, 0x00);
} else if (c->config.check_flag(Client::Flag::LOADING_QUEST)) { } else if (c->config.check_flag(Client::Flag::LOADING_QUEST)) {
c->config.clear_flag(Client::Flag::LOADING_QUEST); c->config.clear_flag(Client::Flag::LOADING_QUEST);
c->log.info("LOADING_QUEST flag cleared");
auto l = c->require_lobby();
if (l->quest && send_quest_barrier_if_all_clients_ready(l)) { if (l->quest && send_quest_barrier_if_all_clients_ready(l)) {
on_quest_loaded(l); on_quest_loaded(l);
} }
@@ -2887,41 +3011,44 @@ static void on_D7_GC(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} }
} }
static void send_file_chunk( static void on_13_A7_GC(shared_ptr<Client> c, uint16_t command, uint32_t flag, string& data) {
shared_ptr<Client> c, // See comment in send_open_quest_file about why we only have logic here for
const string& filename, // GC clients, and ignore this command on all other versions
size_t chunk_index, const auto& cmd = check_size_t<C_WriteFileConfirmation_V3_BB_13_A7>(data);
bool is_download_quest) { bool is_download_quest = (command == 0xA7);
shared_ptr<const string> data; string filename = cmd.filename.decode();
size_t chunk_to_send = flag + GC_QUEST_LOAD_MAX_CHUNKS_IN_FLIGHT;
shared_ptr<const string> file_data;
try { try {
data = c->sending_files.at(filename); file_data = c->sending_files.at(filename);
} catch (const out_of_range&) { } catch (const out_of_range&) {
return; return;
} }
size_t chunk_offset = chunk_index * 0x400; size_t chunk_offset = chunk_to_send * 0x400;
if (chunk_offset >= data->size()) { if (chunk_offset >= file_data->size()) {
c->log.info("Done sending file %s", filename.c_str()); c->log.info("Done sending file %s", filename.c_str());
c->sending_files.erase(filename); c->sending_files.erase(filename);
} else { } else {
const void* chunk_data = data->data() + (chunk_index * 0x400); const void* chunk_data = file_data->data() + (chunk_to_send * 0x400);
size_t chunk_size = min<size_t>(data->size() - chunk_offset, 0x400); size_t chunk_size = min<size_t>(file_data->size() - chunk_offset, 0x400);
send_quest_file_chunk(c, filename, chunk_index, chunk_data, chunk_size, is_download_quest); send_quest_file_chunk(c, filename, chunk_to_send, chunk_data, chunk_size, is_download_quest);
} }
} }
static void on_44_A6_V3_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& data) {
const auto& cmd = check_size_t<C_OpenFileConfirmation_44_A6>(data);
send_file_chunk(c, cmd.filename.decode(), 0, (command == 0xA6));
}
static void on_13_A7_V3_BB(shared_ptr<Client> c, uint16_t command, uint32_t flag, string& data) {
const auto& cmd = check_size_t<C_WriteFileConfirmation_V3_BB_13_A7>(data);
send_file_chunk(c, cmd.filename.decode(), flag + 1, (command == 0xA7));
}
static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, string& data) { static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, string& data) {
auto s = c->require_server_state(); auto s = c->require_server_state();
// 98 should only be sent when leaving a game, and we should leave the client
// in no lobby (they will send an 84 soon afterward to choose a lobby).
if (command == 0x98) {
// If the client had an overlay (for battle/challenge modes), delete it
c->delete_overlay();
c->telepipe_lobby_id = 0;
s->remove_client_from_lobby(c);
}
auto player = c->character(); auto player = c->character();
switch (c->version()) { switch (c->version()) {
@@ -3116,15 +3243,13 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
c->update_channel_name(); c->update_channel_name();
// 98 should only be sent when leaving a game, and we should leave the client // If the player is BB and has just left a game, sync their save file to the
// in no lobby (they will send an 84 soon afterward to choose a lobby). // client to make sure it's up to date
if (command == 0x98) { if ((c->version() == Version::BB_V4) && (command == 0x98)) {
// If the client had an overlay (for battle/challenge modes), delete it send_complete_player_bb(c);
c->delete_overlay(); }
s->remove_client_from_lobby(c); if (command == 0x61) {
} else if (command == 0x61) {
if (c->pending_character_export) { if (c->pending_character_export) {
unique_ptr<Client::PendingCharacterExport> pending_export = std::move(c->pending_character_export); unique_ptr<Client::PendingCharacterExport> pending_export = std::move(c->pending_character_export);
c->pending_character_export.reset(); c->pending_character_export.reset();
@@ -3135,7 +3260,7 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
pending_export->dest_bb_license->username, pending_export->character_index); pending_export->dest_bb_license->username, pending_export->character_index);
} else { } else {
filename = Client::backup_character_filename( filename = Client::backup_character_filename(
pending_export->dest_account->account_id, pending_export->character_index); pending_export->dest_account->account_id, pending_export->character_index, is_ep3(c->version()));
} }
if (s->player_files_manager->get_character(filename)) { if (s->player_files_manager->get_character(filename)) {
@@ -3147,17 +3272,19 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
c->language(), c->language(),
player->disp.visual, player->disp.visual,
player->disp.name.decode(c->language()), player->disp.name.decode(c->language()),
s->level_table); s->level_table(c->version()));
bb_player->disp.visual.version = 4; bb_player->disp.visual.version = 4;
bb_player->disp.visual.name_color_checksum = 0x00000000; bb_player->disp.visual.name_color_checksum = 0x00000000;
bb_player->inventory = player->inventory; bb_player->inventory = player->inventory;
// Before V3, player stats can't be correctly computed from other fields // Before V3, player stats can't be correctly computed from other fields
// because material usage isn't stored anywhere. For these versions, we // because material usage isn't stored anywhere. For these versions, we
// have to trust the stats field from the player's data. // have to trust the stats field from the player's data.
auto level_table = s->level_table(c->version());
if (is_v1_or_v2(c->version())) { if (is_v1_or_v2(c->version())) {
bb_player->disp.stats = player->disp.stats; bb_player->disp.stats = player->disp.stats;
bb_player->import_tethealla_material_usage(level_table);
} else { } else {
s->level_table->advance_to_level(bb_player->disp.stats, player->disp.stats.level, bb_player->disp.visual.char_class); level_table->advance_to_level(bb_player->disp.stats, player->disp.stats.level, bb_player->disp.visual.char_class);
bb_player->disp.stats.char_stats.atp += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::POWER) * 2; bb_player->disp.stats.char_stats.atp += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::POWER) * 2;
bb_player->disp.stats.char_stats.mst += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::MIND) * 2; bb_player->disp.stats.char_stats.mst += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::MIND) * 2;
bb_player->disp.stats.char_stats.evp += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::EVADE) * 2; bb_player->disp.stats.char_stats.evp += bb_player->get_material_usage(PSOBBCharacterFile::MaterialType::EVADE) * 2;
@@ -3206,7 +3333,8 @@ static void on_30(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} else { } else {
filename = Client::backup_character_filename( filename = Client::backup_character_filename(
pending_export->dest_account->account_id, pending_export->dest_account->account_id,
pending_export->character_index); pending_export->character_index,
is_ep3(c->version()));
} }
auto s = c->require_server_state(); auto s = c->require_server_state();
@@ -3215,23 +3343,43 @@ static void on_30(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
return; return;
} }
if (is_ep3(c->version())) {
try {
if (c->version() == Version::GC_EP3_NTE) {
PSOGCEp3CharacterFile::Character ch(check_size_t<PSOGCEp3NTECharacter>(data));
Client::save_ep3_character_file(filename, ch);
} else {
Client::save_ep3_character_file(filename, check_size_t<PSOGCEp3CharacterFile::Character>(data));
}
send_text_message(c, "$C7Character data saved\n(full save file)");
} catch (const exception& e) {
send_text_message_printf(c, "$C6Character data could\nnot be saved:\n%s", e.what());
}
return;
}
shared_ptr<PSOBBCharacterFile> bb_char; shared_ptr<PSOBBCharacterFile> bb_char;
switch (c->version()) { switch (c->version()) {
case Version::GC_V3: { case Version::DC_V2:
auto gc_char = check_size_t<PSOGCCharacterFile::Character>(data); bb_char = PSOBBCharacterFile::create_from_dc_v2(check_size_t<PSODCV2CharacterFile>(data));
bb_char = PSOBBCharacterFile::create_from_gc(gc_char);
break; break;
} case Version::GC_NTE:
bb_char = PSOBBCharacterFile::create_from_gc_nte(check_size_t<PSOGCNTECharacterFileCharacter>(data));
break;
case Version::GC_V3:
bb_char = PSOBBCharacterFile::create_from_gc(check_size_t<PSOGCCharacterFile::Character>(data));
break;
case Version::XB_V3:
bb_char = PSOBBCharacterFile::create_from_xb(check_size_t<PSOXBCharacterFileCharacter>(data));
break;
case Version::GC_EP3_NTE:
case Version::GC_EP3:
throw logic_error("Episode 3 case not handled correctly");
case Version::DC_NTE: case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE: case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1: case Version::DC_V1:
case Version::DC_V2:
case Version::PC_NTE: case Version::PC_NTE:
case Version::PC_V2: case Version::PC_V2:
case Version::GC_NTE:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
case Version::XB_V3:
case Version::BB_V4: case Version::BB_V4:
default: default:
throw logic_error("extended player data command not implemented for version"); throw logic_error("extended player data command not implemented for version");
@@ -3433,6 +3581,10 @@ static void on_E8_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& d
should_save = true; should_save = true;
} }
} }
if (c->login && new_gc.guild_card_number == c->login->account->account_id) {
c->character(true, false)->guild_card.description = new_gc.description;
c->log.info("Updated character's guild card");
}
break; break;
} }
case 0x07E8: { // Add blocked user case 0x07E8: { // Add blocked user
@@ -3570,7 +3722,7 @@ static void on_E5_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} else { } else {
try { try {
auto s = c->require_server_state(); auto s = c->require_server_state();
c->create_character_file(c->login->account->account_id, c->language(), cmd.preview, s->level_table); c->create_character_file(c->login->account->account_id, c->language(), cmd.preview, s->level_table(c->version()));
} catch (const exception& e) { } catch (const exception& e) {
send_message_box(c, string_printf("$C6New character could not be created:\n%s", e.what())); send_message_box(c, string_printf("$C6New character could not be created:\n%s", e.what()));
return; return;
@@ -3581,22 +3733,21 @@ static void on_E5_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} }
static void on_ED_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& data) { static void on_ED_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& data) {
auto p = c->character(true, false);
auto sys = c->system_file(); auto sys = c->system_file();
switch (command) { switch (command) {
case 0x01ED: { case 0x01ED: {
const auto& cmd = check_size_t<C_UpdateOptionFlags_BB_01ED>(data); const auto& cmd = check_size_t<C_UpdateOptionFlags_BB_01ED>(data);
p->option_flags = cmd.option_flags; c->character(true, false)->option_flags = cmd.option_flags;
break; break;
} }
case 0x02ED: { case 0x02ED: {
const auto& cmd = check_size_t<C_UpdateSymbolChats_BB_02ED>(data); const auto& cmd = check_size_t<C_UpdateSymbolChats_BB_02ED>(data);
p->symbol_chats = cmd.symbol_chats; c->character(true, false)->symbol_chats = cmd.symbol_chats;
break; break;
} }
case 0x03ED: { case 0x03ED: {
const auto& cmd = check_size_t<C_UpdateChatShortcuts_BB_03ED>(data); const auto& cmd = check_size_t<C_UpdateChatShortcuts_BB_03ED>(data);
p->shortcuts = cmd.chat_shortcuts; c->character(true, false)->shortcuts = cmd.chat_shortcuts;
break; break;
} }
case 0x04ED: { case 0x04ED: {
@@ -3613,17 +3764,17 @@ static void on_ED_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& d
} }
case 0x06ED: { case 0x06ED: {
const auto& cmd = check_size_t<C_UpdateTechMenu_BB_06ED>(data); const auto& cmd = check_size_t<C_UpdateTechMenu_BB_06ED>(data);
p->tech_menu_shortcut_entries = cmd.tech_menu; c->character(true, false)->tech_menu_shortcut_entries = cmd.tech_menu;
break; break;
} }
case 0x07ED: { case 0x07ED: {
const auto& cmd = check_size_t<C_UpdateCustomizeMenu_BB_07ED>(data); const auto& cmd = check_size_t<C_UpdateCustomizeMenu_BB_07ED>(data);
p->disp.config = cmd.customize; c->character()->disp.config = cmd.customize;
break; break;
} }
case 0x08ED: { case 0x08ED: {
const auto& cmd = check_size_t<C_UpdateChallengeRecords_BB_08ED>(data); const auto& cmd = check_size_t<C_UpdateChallengeRecords_BB_08ED>(data);
p->challenge_records = cmd.records; c->character(true, false)->challenge_records = cmd.records;
break; break;
} }
default: default:
@@ -3690,7 +3841,7 @@ static void on_DF_BB(shared_ptr<Client> c, uint16_t command, uint32_t, string& d
for (auto lc : l->clients) { for (auto lc : l->clients) {
if (lc) { if (lc) {
lc->use_default_bank(); lc->use_default_bank();
lc->create_challenge_overlay(lc->version(), l->quest->challenge_template_index, s->level_table); lc->create_challenge_overlay(lc->version(), l->quest->challenge_template_index, s->level_table(lc->version()));
lc->log.info("Created challenge overlay"); lc->log.info("Created challenge overlay");
l->assign_inventory_and_bank_item_ids(lc, true); l->assign_inventory_and_bank_item_ids(lc, true);
} }
@@ -4138,6 +4289,9 @@ shared_ptr<Lobby> create_game_generic(
default: default:
throw logic_error("invalid quest script version"); throw logic_error("invalid quest script version");
} }
if (c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION)) {
game->set_flag(Lobby::Flag::IS_CLIENT_CUSTOMIZATION);
}
while (game->floor_item_managers.size() < 0x12) { while (game->floor_item_managers.size() < 0x12) {
game->floor_item_managers.emplace_back(game->lobby_id, game->floor_item_managers.size()); game->floor_item_managers.emplace_back(game->lobby_id, game->floor_item_managers.size());
@@ -4173,9 +4327,8 @@ shared_ptr<Lobby> create_game_generic(
game->battle_player = battle_player; game->battle_player = battle_player;
battle_player->set_lobby(game); battle_player->set_lobby(game);
} }
if (game->base_version == Version::BB_V4) {
game->base_exp_multiplier = s->bb_global_exp_multiplier; game->base_exp_multiplier = s->bb_global_exp_multiplier;
} game->exp_share_multiplier = s->exp_share_multiplier;
const unordered_map<uint16_t, IntegralExpression>* quest_flag_rewrites; const unordered_map<uint16_t, IntegralExpression>* quest_flag_rewrites;
switch (game->base_version) { switch (game->base_version) {
@@ -4329,6 +4482,7 @@ static void on_C1_PC(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (game) { if (game) {
s->change_client_lobby(c, game); s->change_client_lobby(c, game);
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
} }
} }
@@ -4401,6 +4555,7 @@ static void on_0C_C1_E7_EC(shared_ptr<Client> c, uint16_t command, uint32_t, str
if (game) { if (game) {
s->change_client_lobby(c, game); s->change_client_lobby(c, game);
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
// There is a bug in DC NTE and 11/2000 that causes them to assign item IDs // There is a bug in DC NTE and 11/2000 that causes them to assign item IDs
// twice when joining a game. If there are other players in the game, this // twice when joining a game. If there are other players in the game, this
@@ -4458,6 +4613,7 @@ static void on_C1_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (game) { if (game) {
s->change_client_lobby(c, game); s->change_client_lobby(c, game);
c->config.set_flag(Client::Flag::LOADING); c->config.set_flag(Client::Flag::LOADING);
c->log.info("LOADING flag set");
} }
} }
@@ -4487,6 +4643,7 @@ static void on_6F(shared_ptr<Client> c, uint16_t command, uint32_t, string& data
// don't matter for Ep3) // don't matter for Ep3)
if (c->config.check_flag(Client::Flag::LOADING)) { if (c->config.check_flag(Client::Flag::LOADING)) {
c->config.clear_flag(Client::Flag::LOADING); c->config.clear_flag(Client::Flag::LOADING);
c->log.info("LOADING flag cleared");
// The client sends 6F when it has created its TObjPlayer and assigned its // The client sends 6F when it has created its TObjPlayer and assigned its
// item IDs. For the leader, however, this happens before any inbound commands // item IDs. For the leader, however, this happens before any inbound commands
@@ -4519,6 +4676,9 @@ static void on_6F(shared_ptr<Client> c, uint16_t command, uint32_t, string& data
send_update_team_reward_flags(c); send_update_team_reward_flags(c);
send_all_nearby_team_metadatas_to_client(c, false); send_all_nearby_team_metadatas_to_client(c, false);
// On BB, send the joinable quest file as soon as the client is ready (6F).
// On other versions, we send joinable quests in the 99 handler instead,
// since we need to wait for the client's save to complete.
// BB sends 016F when the client is done loading a quest. In that case, we // BB sends 016F when the client is done loading a quest. In that case, we
// shouldn't send the quest to them again! // shouldn't send the quest to them again!
if ((command == 0x006F) && l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS)) { if ((command == 0x006F) && l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS)) {
@@ -4535,10 +4695,12 @@ static void on_6F(shared_ptr<Client> c, uint16_t command, uint32_t, string& data
send_open_quest_file(c, bin_filename, bin_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->bin_contents); send_open_quest_file(c, bin_filename, bin_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->bin_contents);
send_open_quest_file(c, dat_filename, dat_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->dat_contents); send_open_quest_file(c, dat_filename, dat_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->dat_contents);
c->config.set_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST); c->config.set_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST);
c->log.info("LOADING_RUNNING_JOINABLE_QUEST flag set");
should_resume_game = false; should_resume_game = false;
} else if ((command == 0x016F) && c->config.check_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST)) { } else if ((command == 0x016F) && c->config.check_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST)) {
c->config.clear_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST); c->config.clear_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST);
c->log.info("LOADING_RUNNING_JOINABLE_QUEST flag cleared");
} }
if (l->map) { if (l->map) {
send_rare_enemy_index_list(c, l->map->rare_enemy_indexes); send_rare_enemy_index_list(c, l->map->rare_enemy_indexes);
@@ -4602,6 +4764,34 @@ static void on_99(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
} else if (c->should_send_to_proxy_server) { } else if (c->should_send_to_proxy_server) {
send_client_to_proxy_server(c); send_client_to_proxy_server(c);
} }
// See the comment in on_6F about why we do this here, but only for non-BB
// versions.
if (l && l->check_flag(Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS) && (c->version() != Version::BB_V4)) {
if (!l->quest) {
throw runtime_error("JOINABLE_QUEST_IN_PROGRESS is set, but lobby has no quest");
}
auto vq = l->quest->version(c->version(), c->language());
if (!vq) {
throw runtime_error("JOINABLE_QUEST_IN_PROGRESS is set, but lobby has no quest for client version");
}
string bin_filename = vq->bin_filename();
string dat_filename = vq->dat_filename();
send_open_quest_file(c, bin_filename, bin_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->bin_contents);
send_open_quest_file(c, dat_filename, dat_filename, "", vq->quest_number, QuestFileType::ONLINE, vq->dat_contents);
c->config.set_flag(Client::Flag::LOADING_RUNNING_JOINABLE_QUEST);
c->log.info("LOADING_RUNNING_JOINABLE_QUEST flag set");
// On v1 and v2, there is no confirmation when the client is done
// downloading the quest file, so just set the in-quest state immediately.
// On v3 and later, we do this when we receive the AC command.
// TODO: This might not work for GC NTE, since we wait for file chunk
// confirmations (13 commands) but there is no AC command.
if (is_v1_or_v2(c->version())) {
on_joinable_quest_loaded(c);
}
}
} }
static void on_D0_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) { static void on_D0_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
@@ -5193,7 +5383,7 @@ static on_command_t handlers[0x100][NUM_NON_PATCH_VERSIONS] = {
/* 10 */ {on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10}, /* 10 */ {on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10, on_10},
/* 11 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 11 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 12 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 12 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 13 */ {on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB}, /* 13 */ {on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_13_A7_GC, on_13_A7_GC, on_13_A7_GC, on_13_A7_GC, on_ignored, on_ignored},
/* 14 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 14 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 15 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 15 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 16 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 16 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
@@ -5245,7 +5435,7 @@ static on_command_t handlers[0x100][NUM_NON_PATCH_VERSIONS] = {
/* 41 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 41 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 42 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 42 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 43 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 43 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 44 */ {on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB}, /* 44 */ {on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored},
/* 45 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 45 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 46 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 46 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 47 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* 47 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
@@ -5349,10 +5539,10 @@ static on_command_t handlers[0x100][NUM_NON_PATCH_VERSIONS] = {
/* A3 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* A3 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* A4 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* A4 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* A5 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* A5 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* A6 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, on_44_A6_V3_BB, nullptr}, /* A6 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, nullptr},
/* A7 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, on_13_A7_V3_BB, nullptr}, /* A7 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_13_A7_GC, on_13_A7_GC, on_13_A7_GC, on_13_A7_GC, on_ignored, nullptr},
/* A8 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* A8 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* A9 */ {on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored}, /* A9 */ {on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9, on_A9},
/* AA */ {nullptr, nullptr, nullptr, nullptr, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA}, /* AA */ {nullptr, nullptr, nullptr, nullptr, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA, on_AA},
/* AB */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, /* AB */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* AC */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB}, /* AC */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB, on_AC_V3_BB},
+464 -267
View File
File diff suppressed because it is too large Load Diff
+86
View File
@@ -36,3 +36,89 @@ DropReconcileResult reconcile_drop_request_with_map(
const Client::Config& config, const Client::Config& config,
std::shared_ptr<Map> map, std::shared_ptr<Map> map,
bool mark_drop); bool mark_drop);
class Parsed6x70Data {
public:
Version from_version;
bool from_client_customization;
Version item_version;
G_SyncPlayerDispAndInventory_BaseDCNTE base;
uint32_t unknown_a5_nte = 0;
uint32_t unknown_a6_nte = 0;
uint16_t bonus_hp_from_materials = 0;
uint16_t bonus_tp_from_materials = 0;
parray<uint8_t, 0x10> unknown_a5_112000;
parray<G_Unknown_6x70_SubA2, 5> unknown_a4_final;
uint32_t language = 0;
uint32_t player_tag = 0;
uint32_t guild_card_number = 0;
uint32_t unknown_a6 = 0;
uint32_t battle_team_number = 0;
Telepipe6x70 telepipe;
uint32_t unknown_a8 = 0;
parray<uint8_t, 0x10> unknown_a9_nte_112000;
G_Unknown_6x70_SubA1 unknown_a9_final;
uint32_t area = 0;
uint32_t flags2 = 0;
parray<uint8_t, 0x14> technique_levels_v1 = 0xFF;
PlayerVisualConfig visual;
std::string name;
PlayerStats stats;
uint32_t num_items = 0;
parray<PlayerInventoryItem, 0x1E> items;
uint32_t floor = 0;
uint64_t xb_user_id = 0;
uint32_t xb_unknown_a16 = 0;
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_DCNTE_6x70& cmd,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_DC112000_6x70& cmd,
uint32_t guild_card_number,
uint8_t language,
Version from_version,
bool from_client_customization);
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_DC_PC_6x70& cmd,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_GC_6x70& cmd,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_XB_6x70& cmd,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_BB_6x70& cmd,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
G_SyncPlayerDispAndInventory_DCNTE_6x70 as_dc_nte(std::shared_ptr<ServerState> s) const;
G_SyncPlayerDispAndInventory_DC112000_6x70 as_dc_112000(std::shared_ptr<ServerState> s) const;
G_SyncPlayerDispAndInventory_DC_PC_6x70 as_dc_pc(std::shared_ptr<ServerState> s, Version to_version) const;
G_SyncPlayerDispAndInventory_GC_6x70 as_gc_gcnte(std::shared_ptr<ServerState> s, Version to_version) const;
G_SyncPlayerDispAndInventory_XB_6x70 as_xb(std::shared_ptr<ServerState> s) const;
G_SyncPlayerDispAndInventory_BB_6x70 as_bb(std::shared_ptr<ServerState> s, uint8_t language) const;
uint64_t default_xb_user_id() const;
void clear_v1_unused_item_fields();
void clear_dc_protos_unused_item_fields();
protected:
Parsed6x70Data(
const G_SyncPlayerDispAndInventory_BaseV1& base,
uint32_t guild_card_number,
Version from_version,
bool from_client_customization);
G_SyncPlayerDispAndInventory_BaseV1 base_v1() const;
};
+452 -64
View File
@@ -4,13 +4,79 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include "LevelTable.hh"
#include "PSOProtocol.hh" #include "PSOProtocol.hh"
using namespace std; using namespace std;
// Originally there was going to be a language-based header, but then I decided struct DefaultSymbolChatEntry {
// against it. This string was already in use for that parser, so I didn't array<const char*, 8> language_to_name;
// bother changing it. uint32_t spec;
array<uint16_t, 4> corner_objects;
array<SymbolChatFacePart, 12> face_parts;
SaveFileSymbolChatEntryBB to_entry(uint8_t language) const {
SaveFileSymbolChatEntryBB ret;
ret.present = 1;
ret.name.encode(this->language_to_name.at(language), language);
ret.spec.spec = this->spec;
for (size_t z = 0; z < 4; z++) {
ret.spec.corner_objects[z] = this->corner_objects[z];
}
for (size_t z = 0; z < 12; z++) {
ret.spec.face_parts[z] = this->face_parts[z];
}
return ret;
}
};
static const array<DefaultSymbolChatEntry, 6> DEFAULT_SYMBOL_CHATS = {
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF", "\tEHello", "\tEHallo", "\tESalut", "\tEHola", "\tB\xE4\xBD\xA0\xE5\xA5\xBD", "\tT\xE4\xBD\xA0\xE5\xA5\xBD", "\tK\xEC\x95\x88\xEB\x85\x95"}, 0x28, {0xFFFF, 0x000D, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x05, 0x18, 0x1D, 0x00}, {0x05, 0x28, 0x1D, 0x01}, {0x36, 0x20, 0x2A, 0x00}, {0x3C, 0x00, 0x32, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x95\xE3\x82\x88\xE3\x81\x86\xE3\x81\xAA\xE3\x82\x89", "\tEGood-bye", "\tETschus", "\tEAu revoir", "\tEAdios", "\tB\xE5\x86\x8D\xE8\xA7\x81", "\tT\xE5\x86\x8D\xE8\xA6\x8B", "\tK\xEC\x9E\x98\xEA\xB0\x80"}, 0x74, {0x0476, 0x000C, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x06, 0x15, 0x14, 0x00}, {0x06, 0x2B, 0x14, 0x01}, {0x05, 0x18, 0x1F, 0x00}, {0x05, 0x28, 0x1F, 0x01}, {0x36, 0x20, 0x2A, 0x00}, {0x3C, 0x00, 0x32, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
DefaultSymbolChatEntry{{"\tJ\xE3\x81\xB0\xE3\x82\x93\xE3\x81\x96\xE3\x83\xBC\xE3\x81\x84", "\tEHurrah!", "\tEHurra!", "\tEHourra !", "\tEHurra", "\tB\xE4\xB8\x87\xE5\xB2\x81", "\tT\xE8\x90\xAC\xE6\xAD\xB2", "\tK\xEB\xA7\x8C\xEC\x84\xB8"}, 0x28, {0x0362, 0x0362, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x09, 0x16, 0x1B, 0x00}, {0x09, 0x2B, 0x1B, 0x01}, {0x37, 0x20, 0x2C, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x86\xE3\x81\x87\xEF\xBD\x9E\xE3\x82\x93", "\tECrying", "\tEIch bin sauer!", "\tEJe suis triste", "\tELlanto", "\tB\xE5\x96\x82\xEF\xBD\x9E", "\tT\xE5\x96\x82\xEF\xBD\x9E", "\tK\xEC\x9D\x91~"}, 0x74, {0x074F, 0xFFFF, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x06, 0x15, 0x14, 0x00}, {0x06, 0x2B, 0x14, 0x01}, {0x05, 0x18, 0x1F, 0x00}, {0x05, 0x28, 0x1F, 0x01}, {0x21, 0x20, 0x2E, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x8A\xE3\x81\x93\xE3\x81\xA3\xE3\x81\x9F\xEF\xBC\x81", "\tEI'm angry!", "\tEWeinen", "\tEJe suis en colere !", "\tEEnfado", "\tB\xE7\x94\x9F\xE6\xB0\x94\xE4\xBA\x86\xEF\xBC\x81", "\tT\xE7\x94\x9F\xE6\xB0\xA3\xE4\xBA\x86\xEF\xBC\x81", "\tK\xEB\x82\x98\xEC\x99\x94\xEB\x8B\xA4\xEF\xBC\x81"}, 0x5C, {0x0116, 0x0001, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x0B, 0x18, 0x1B, 0x01}, {0x0B, 0x28, 0x1B, 0x00}, {0x33, 0x20, 0x2A, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x9F\xE3\x81\x99\xE3\x81\x91\xE3\x81\xA6\xEF\xBC\x81", "\tEHelp me!", "\tEHilf mir!", "\tEAide-moi !", "\tEAyuda", "\tB\xE6\x95\x91\xE5\x91\xBD\xE5\x95\x8A\xEF\xBC\x81", "\tT\xE6\x95\x91\xE5\x91\xBD\xE5\x95\x8A\xEF\xBC\x81", "\tK\xEB\x8F\x84\xEC\x99\x80\xEC\xA4\x98\xEF\xBC\x81"}, 0xEC, {0x065E, 0x0138, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x02, 0x17, 0x1B, 0x01}, {0x02, 0x2A, 0x1B, 0x00}, {0x31, 0x20, 0x2C, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}},
};
static const array<uint16_t, 20> DEFAULT_TECH_MENU_CONFIG = {
0x0000, 0x0006, 0x0003, 0x0001, 0x0007, 0x0004, 0x0002, 0x0008, 0x0005, 0x0009,
0x0012, 0x000F, 0x0010, 0x0011, 0x000D, 0x000A, 0x000B, 0x000C, 0x000E, 0x0000};
static const array<uint8_t, 0x016C> DEFAULT_KEY_CONFIG = {
0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4B, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
static const array<uint8_t, 0x0038> DEFAULT_JOYSTICK_CONFIG = {
0x00, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
// Originally there was going to be a language-based header for .nsc files, but
// then I decided against it. This string was already in use for that parser,
// so I didn't bother changing it.
const char* LegacySavedAccountDataBB::SIGNATURE = "newserv account file format; 7 sections present; sequential;"; const char* LegacySavedAccountDataBB::SIGNATURE = "newserv account file format; 7 sections present; sequential;";
ShuffleTables::ShuffleTables(PSOV2Encryption& crypt) { ShuffleTables::ShuffleTables(PSOV2Encryption& crypt) {
@@ -191,6 +257,65 @@ Image PSOGCSnapshotFile::decode_image() const {
return ret; return ret;
} }
PSOGCEp3CharacterFile::Character::Character(const PSOGCEp3NTECharacter& nte)
: inventory(nte.inventory),
disp(nte.disp),
flags(nte.flags),
creation_timestamp(nte.creation_timestamp),
signature(nte.signature),
play_time_seconds(nte.play_time_seconds),
option_flags(nte.option_flags),
save_count(nte.save_count),
ppp_username(nte.ppp_username),
ppp_password(nte.ppp_password),
seq_vars(nte.seq_vars),
death_count(nte.death_count),
bank(nte.bank),
guild_card(nte.guild_card),
symbol_chats(nte.symbol_chats),
chat_shortcuts(nte.chat_shortcuts),
auto_reply(nte.auto_reply),
info_board(nte.info_board),
battle_records(nte.battle_records),
unknown_a10(nte.unknown_a10),
challenge_record_stats(nte.challenge_record_stats),
ep3_config(nte.ep3_config),
unknown_a11(nte.unknown_a11),
unknown_a12(nte.unknown_a12),
unknown_a13(nte.unknown_a13) {
this->ep3_config.backup_visual = this->disp.visual;
}
PSOGCEp3CharacterFile::Character::operator PSOGCEp3NTECharacter() const {
PSOGCEp3NTECharacter ret;
ret.inventory = this->inventory;
ret.disp = this->disp;
ret.flags = this->flags;
ret.creation_timestamp = this->creation_timestamp;
ret.signature = this->signature;
ret.play_time_seconds = this->play_time_seconds;
ret.option_flags = this->option_flags;
ret.save_count = this->save_count;
ret.ppp_username = this->ppp_username;
ret.ppp_password = this->ppp_password;
ret.seq_vars = this->seq_vars;
ret.death_count = this->death_count;
ret.bank = this->bank;
ret.guild_card = this->guild_card;
ret.symbol_chats = this->symbol_chats;
ret.chat_shortcuts = this->chat_shortcuts;
ret.auto_reply = this->auto_reply;
ret.info_board = this->info_board;
ret.battle_records = this->battle_records;
ret.unknown_a10 = this->unknown_a10;
ret.challenge_record_stats = this->challenge_record_stats;
ret.ep3_config = Episode3::PlayerConfigNTE(this->ep3_config);
ret.unknown_a11 = this->unknown_a11;
ret.unknown_a12 = this->unknown_a12;
ret.unknown_a13 = this->unknown_a13;
return ret;
}
void PSOBBGuildCardFile::Entry::clear() { void PSOBBGuildCardFile::Entry::clear() {
this->data.clear(); this->data.clear();
this->unknown_a1.clear(0); this->unknown_a1.clear(0);
@@ -203,11 +328,11 @@ uint32_t PSOBBGuildCardFile::checksum() const {
PSOBBBaseSystemFile::PSOBBBaseSystemFile() { PSOBBBaseSystemFile::PSOBBBaseSystemFile() {
// This field is based on 1/1/2000, not 1/1/1970, so adjust appropriately // This field is based on 1/1/2000, not 1/1/1970, so adjust appropriately
this->base.creation_timestamp = (now() - 946684800000000ULL) / 1000000; this->base.creation_timestamp = (now() - 946684800000000ULL) / 1000000;
for (size_t z = 0; z < PSOBBBaseSystemFile::DEFAULT_KEY_CONFIG.size(); z++) { for (size_t z = 0; z < DEFAULT_KEY_CONFIG.size(); z++) {
this->key_config[z] = PSOBBBaseSystemFile::DEFAULT_KEY_CONFIG[z]; this->key_config[z] = DEFAULT_KEY_CONFIG[z];
} }
for (size_t z = 0; z < PSOBBBaseSystemFile::DEFAULT_JOYSTICK_CONFIG.size(); z++) { for (size_t z = 0; z < DEFAULT_JOYSTICK_CONFIG.size(); z++) {
this->joystick_config[z] = PSOBBBaseSystemFile::DEFAULT_JOYSTICK_CONFIG[z]; this->joystick_config[z] = DEFAULT_JOYSTICK_CONFIG[z];
} }
} }
@@ -400,11 +525,11 @@ shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_config(
ret->guild_card.language = ret->inventory.language; ret->guild_card.language = ret->inventory.language;
ret->guild_card.section_id = ret->disp.visual.section_id; ret->guild_card.section_id = ret->disp.visual.section_id;
ret->guild_card.char_class = ret->disp.visual.char_class; ret->guild_card.char_class = ret->disp.visual.char_class;
for (size_t z = 0; z < PSOBBCharacterFile::DEFAULT_SYMBOL_CHATS.size(); z++) { for (size_t z = 0; z < DEFAULT_SYMBOL_CHATS.size(); z++) {
ret->symbol_chats[z] = PSOBBCharacterFile::DEFAULT_SYMBOL_CHATS[z].to_entry(language); ret->symbol_chats[z] = DEFAULT_SYMBOL_CHATS[z].to_entry(language);
} }
for (size_t z = 0; z < PSOBBCharacterFile::DEFAULT_TECH_MENU_CONFIG.size(); z++) { for (size_t z = 0; z < DEFAULT_TECH_MENU_CONFIG.size(); z++) {
ret->tech_menu_shortcut_entries[z] = PSOBBCharacterFile::DEFAULT_TECH_MENU_CONFIG[z]; ret->tech_menu_shortcut_entries[z] = DEFAULT_TECH_MENU_CONFIG[z];
} }
return ret; return ret;
} }
@@ -418,9 +543,82 @@ shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_preview(
guild_card_number, language, preview.visual, preview.name.decode(language), level_table); guild_card_number, language, preview.visual, preview.name.decode(language), level_table);
} }
shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_dc_v2(const PSODCV2CharacterFile& dc) {
auto ret = make_shared<PSOBBCharacterFile>();
ret->inventory = dc.inventory;
ret->inventory.decode_from_client(Version::DC_V2);
uint8_t language = ret->inventory.language;
ret->disp = dc.disp.to_bb(language, language);
ret->creation_timestamp = dc.creation_timestamp;
ret->play_time_seconds = dc.play_time_seconds;
ret->option_flags = dc.option_flags;
ret->save_count = dc.save_count;
ret->quest_flags = dc.quest_flags;
ret->bank = dc.bank;
ret->bank.decode_from_client(Version::DC_V2);
ret->guild_card = dc.guild_card;
for (size_t z = 0; z < std::min<size_t>(ret->symbol_chats.size(), dc.symbol_chats.size()); z++) {
auto& ret_sc = ret->symbol_chats[z];
const auto& dc_sc = dc.symbol_chats[z];
ret_sc.present = dc_sc.present.load();
ret_sc.name.encode(dc_sc.name.decode(language), language);
ret_sc.spec = dc_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), dc.shortcuts.size()); z++) {
ret->shortcuts[z] = dc.shortcuts[z].convert<false, TextEncoding::UTF16, 0x50>(language);
}
ret->battle_records = dc.battle_records;
ret->challenge_records = dc.challenge_records;
ret->tech_menu_shortcut_entries = dc.tech_menu_shortcut_entries;
for (size_t z = 0; z < 5; z++) {
ret->choice_search_config.entries[z].parent_choice_id = dc.choice_search_config[z * 2].load();
ret->choice_search_config.entries[z].choice_id = dc.choice_search_config[z * 2 + 1].load();
}
return ret;
}
shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_gc_nte(const PSOGCNTECharacterFileCharacter& gc_nte) {
auto ret = make_shared<PSOBBCharacterFile>();
ret->inventory = gc_nte.inventory;
// Note: We intentionally do not call ret->inventory.decode_from_client here.
// This is because the GC client byteswaps data2 in each item before sending
// it to the server in the 61 and 98 commands, but GetExtendedPlayerInfo does
// not do this, so the data2 fields are already in the correct order here.
uint8_t language = ret->inventory.language;
ret->disp = gc_nte.disp.to_bb(language, language);
ret->creation_timestamp = gc_nte.creation_timestamp.load();
ret->play_time_seconds = gc_nte.play_time_seconds.load();
ret->option_flags = gc_nte.option_flags.load();
ret->save_count = gc_nte.save_count.load();
ret->quest_flags = gc_nte.quest_flags;
ret->bank = gc_nte.bank;
ret->guild_card = gc_nte.guild_card;
for (size_t z = 0; z < std::min<size_t>(ret->symbol_chats.size(), gc_nte.symbol_chats.size()); z++) {
auto& ret_sc = ret->symbol_chats[z];
const auto& gc_sc = gc_nte.symbol_chats[z];
ret_sc.present = gc_sc.present.load();
ret_sc.name.encode(gc_sc.name.decode(language), language);
ret_sc.spec = gc_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), gc_nte.shortcuts.size()); z++) {
ret->shortcuts[z] = gc_nte.shortcuts[z].convert<false, TextEncoding::UTF16, 0x50>(language);
}
ret->battle_records = gc_nte.battle_records;
ret->unknown_a4 = gc_nte.unknown_a4;
ret->challenge_records = gc_nte.challenge_records;
for (size_t z = 0; z < std::min<size_t>(ret->tech_menu_shortcut_entries.size(), gc_nte.tech_menu_shortcut_entries.size()); z++) {
ret->tech_menu_shortcut_entries[z] = gc_nte.tech_menu_shortcut_entries[z].load();
}
return ret;
}
shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_gc(const PSOGCCharacterFile::Character& gc) { shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_gc(const PSOGCCharacterFile::Character& gc) {
auto ret = make_shared<PSOBBCharacterFile>(); auto ret = make_shared<PSOBBCharacterFile>();
ret->inventory = gc.inventory; ret->inventory = gc.inventory;
// Note: We intentionally do not call ret->inventory.decode_from_client here.
// This is because the GC client byteswaps data2 in each item before sending
// it to the server in the 61 and 98 commands, but GetExtendedPlayerInfo does
// not do this, so the data2 fields are already in the correct order here.
uint8_t language = ret->inventory.language; uint8_t language = ret->inventory.language;
ret->disp = gc.disp.to_bb(language, language); ret->disp = gc.disp.to_bb(language, language);
ret->creation_timestamp = gc.creation_timestamp.load(); ret->creation_timestamp = gc.creation_timestamp.load();
@@ -439,7 +637,7 @@ shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_gc(const PSOGCCha
ret_sc.spec = gc_sc.spec; ret_sc.spec = gc_sc.spec;
} }
for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), gc.shortcuts.size()); z++) { for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), gc.shortcuts.size()); z++) {
ret->shortcuts[z] = gc.shortcuts[z].convert<false, TextEncoding::UTF16>(language); ret->shortcuts[z] = gc.shortcuts[z].convert<false, TextEncoding::UTF16, 0x50>(language);
} }
ret->auto_reply.encode(gc.auto_reply.decode(language), language); ret->auto_reply.encode(gc.auto_reply.decode(language), language);
ret->info_board.encode(gc.info_board.decode(language), language); ret->info_board.encode(gc.info_board.decode(language), language);
@@ -459,12 +657,179 @@ shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_gc(const PSOGCCha
return ret; return ret;
} }
shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_ep3(const PSOGCEp3CharacterFile::Character& ep3) {
auto ret = make_shared<PSOBBCharacterFile>();
ret->inventory = ep3.inventory;
uint8_t language = ret->inventory.language;
ret->disp = ep3.disp.to_bb(language, language);
ret->creation_timestamp = ep3.creation_timestamp.load();
ret->play_time_seconds = ep3.play_time_seconds.load();
ret->option_flags = ep3.option_flags.load();
ret->save_count = ep3.save_count.load();
ret->death_count = ep3.death_count.load();
ret->bank = ep3.bank;
ret->guild_card = ep3.guild_card;
for (size_t z = 0; z < std::min<size_t>(ret->symbol_chats.size(), ep3.symbol_chats.size()); z++) {
auto& ret_sc = ret->symbol_chats[z];
const auto& gc_sc = ep3.symbol_chats[z];
ret_sc.present = gc_sc.present.load();
ret_sc.name.encode(gc_sc.name.decode(language), language);
ret_sc.spec = gc_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), ep3.chat_shortcuts.size()); z++) {
ret->shortcuts[z] = ep3.chat_shortcuts[z].convert<false, TextEncoding::UTF16, 0x50>(language);
}
ret->auto_reply.encode(ep3.auto_reply.decode(language), language);
ret->info_board.encode(ep3.info_board.decode(language), language);
ret->battle_records = ep3.battle_records;
ret->unknown_a4 = ep3.ep3_config.unknown_a4;
ret->challenge_records.rank_title.encode(ep3.ep3_config.rank_text.decode(language), language);
for (size_t z = 0; z < std::min<size_t>(ret->tech_menu_shortcut_entries.size(), ep3.ep3_config.tech_menu_shortcut_entries.size()); z++) {
ret->tech_menu_shortcut_entries[z] = ep3.ep3_config.tech_menu_shortcut_entries[z].load();
}
ret->choice_search_config.disabled = !!(ret->option_flags & 0x00040000);
for (size_t z = 0; z < 5; z++) {
ret->choice_search_config.entries[z].parent_choice_id = ep3.ep3_config.choice_search_config[z * 2].load();
ret->choice_search_config.entries[z].choice_id = ep3.ep3_config.choice_search_config[z * 2 + 1].load();
}
for (size_t z = 0; z < std::min<size_t>(ret->quest_counters.size(), ep3.ep3_config.scenario_progress.size()); z++) {
ret->quest_counters[z] = ep3.ep3_config.scenario_progress[z].load();
}
ret->offline_battle_records = ep3.ep3_config.unused_offline_records;
return ret;
}
shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_xb(const PSOXBCharacterFileCharacter& xb) {
auto ret = make_shared<PSOBBCharacterFile>();
ret->inventory = xb.inventory;
ret->inventory.decode_from_client(Version::XB_V3);
uint8_t language = ret->inventory.language;
ret->disp = xb.disp.to_bb(language, language);
ret->creation_timestamp = xb.creation_timestamp.load();
ret->play_time_seconds = xb.play_time_seconds.load();
ret->option_flags = xb.option_flags.load();
ret->save_count = xb.save_count.load();
ret->quest_flags = xb.quest_flags;
ret->death_count = xb.death_count.load();
ret->bank = xb.bank;
ret->bank.decode_from_client(Version::XB_V3);
ret->guild_card = xb.guild_card;
for (size_t z = 0; z < std::min<size_t>(ret->symbol_chats.size(), xb.symbol_chats.size()); z++) {
auto& ret_sc = ret->symbol_chats[z];
const auto& xb_sc = xb.symbol_chats[z];
ret_sc.present = xb_sc.present.load();
ret_sc.name.encode(xb_sc.name.decode(language), language);
ret_sc.spec = xb_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret->shortcuts.size(), xb.shortcuts.size()); z++) {
ret->shortcuts[z] = xb.shortcuts[z].convert<false, TextEncoding::UTF16, 0x50>(language);
}
ret->auto_reply.encode(xb.auto_reply.decode(language), language);
ret->info_board.encode(xb.info_board.decode(language), language);
ret->battle_records = xb.battle_records;
ret->unknown_a4 = xb.unknown_a4;
ret->challenge_records = xb.challenge_records;
for (size_t z = 0; z < std::min<size_t>(ret->tech_menu_shortcut_entries.size(), xb.tech_menu_shortcut_entries.size()); z++) {
ret->tech_menu_shortcut_entries[z] = xb.tech_menu_shortcut_entries[z].load();
}
ret->choice_search_config = xb.choice_search_config;
ret->unknown_a6 = xb.unknown_a6;
for (size_t z = 0; z < std::min<size_t>(ret->quest_counters.size(), xb.quest_counters.size()); z++) {
ret->quest_counters[z] = xb.quest_counters[z].load();
}
ret->offline_battle_records = xb.offline_battle_records;
ret->unknown_a7 = xb.unknown_a7;
return ret;
}
PSODCV2CharacterFile PSOBBCharacterFile::to_dc_v2() const {
uint8_t language = this->inventory.language;
PSODCV2CharacterFile ret;
ret.inventory = this->inventory;
// We don't need to do the v1-compatible encoding (hence it is OK to pass
// nullptr here) but we do need to encode mag stats in the v2 format
ret.inventory.encode_for_client(Version::DC_V2, nullptr);
ret.disp = this->disp.to_dcpcv3<false>(language, language);
ret.disp.visual.enforce_lobby_join_limits_for_version(Version::DC_V2);
ret.creation_timestamp = this->creation_timestamp.load();
ret.play_time_seconds = this->play_time_seconds.load();
ret.option_flags = this->option_flags.load();
ret.save_count = this->save_count.load();
ret.quest_flags = this->quest_flags;
ret.bank = this->bank;
ret.bank.encode_for_client(Version::DC_V2);
ret.guild_card = this->guild_card;
for (size_t z = 0; z < std::min<size_t>(ret.symbol_chats.size(), this->symbol_chats.size()); z++) {
auto& ret_sc = ret.symbol_chats[z];
const auto& gc_sc = this->symbol_chats[z];
ret_sc.present = gc_sc.present.load();
ret_sc.name.encode(gc_sc.name.decode(language), language);
ret_sc.spec = gc_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret.shortcuts.size(), this->shortcuts.size()); z++) {
ret.shortcuts[z] = this->shortcuts[z].convert<false, TextEncoding::MARKED, 0x3C>(language);
}
ret.battle_records = this->battle_records;
ret.challenge_records = this->challenge_records;
for (size_t z = 0; z < std::min<size_t>(ret.tech_menu_shortcut_entries.size(), this->tech_menu_shortcut_entries.size()); z++) {
ret.tech_menu_shortcut_entries[z] = this->tech_menu_shortcut_entries[z].load();
}
for (size_t z = 0; z < 5; z++) {
ret.choice_search_config[z * 2] = this->choice_search_config.entries[z].parent_choice_id.load();
ret.choice_search_config[z * 2 + 1] = this->choice_search_config.entries[z].choice_id.load();
}
return ret;
}
PSOGCNTECharacterFileCharacter PSOBBCharacterFile::to_gc_nte() const {
uint8_t language = this->inventory.language;
PSOGCNTECharacterFileCharacter ret;
ret.inventory = this->inventory;
// Note: We intentionally do not call ret.inventory.encode_for_client here.
// This is because the GC client byteswaps data2 in each item before sending
// it to the server in the 61 and 98 commands, but GetExtendedPlayerInfo does
// not do this, so the data2 fields are already in the correct order here.
ret.disp = this->disp.to_dcpcv3<true>(language, language);
ret.disp.visual.enforce_lobby_join_limits_for_version(Version::GC_V3);
ret.creation_timestamp = this->creation_timestamp.load();
ret.play_time_seconds = this->play_time_seconds.load();
ret.option_flags = this->option_flags.load();
ret.save_count = this->save_count.load();
ret.quest_flags = this->quest_flags;
ret.bank = this->bank;
ret.guild_card = this->guild_card;
for (size_t z = 0; z < std::min<size_t>(ret.symbol_chats.size(), this->symbol_chats.size()); z++) {
auto& ret_sc = ret.symbol_chats[z];
const auto& gc_sc = this->symbol_chats[z];
ret_sc.present = gc_sc.present.load();
ret_sc.name.encode(gc_sc.name.decode(language), language);
ret_sc.spec = gc_sc.spec;
}
for (size_t z = 0; z < std::min<size_t>(ret.shortcuts.size(), this->shortcuts.size()); z++) {
ret.shortcuts[z] = this->shortcuts[z].convert<true, TextEncoding::MARKED, 0x50>(language);
}
ret.battle_records = this->battle_records;
ret.unknown_a4 = this->unknown_a4;
ret.challenge_records = this->challenge_records;
for (size_t z = 0; z < std::min<size_t>(ret.tech_menu_shortcut_entries.size(), this->tech_menu_shortcut_entries.size()); z++) {
ret.tech_menu_shortcut_entries[z] = this->tech_menu_shortcut_entries[z].load();
}
return ret;
}
PSOGCCharacterFile::Character PSOBBCharacterFile::to_gc() const { PSOGCCharacterFile::Character PSOBBCharacterFile::to_gc() const {
uint8_t language = this->inventory.language; uint8_t language = this->inventory.language;
PSOGCCharacterFile::Character ret; PSOGCCharacterFile::Character ret;
ret.inventory = this->inventory; ret.inventory = this->inventory;
// Note: We intentionally do not call ret.inventory.encode_for_client here.
// This is because the GC client byteswaps data2 in each item before sending
// it to the server in the 61 and 98 commands, but GetExtendedPlayerInfo does
// not do this, so the data2 fields are already in the correct order here.
ret.disp = this->disp.to_dcpcv3<true>(language, language); ret.disp = this->disp.to_dcpcv3<true>(language, language);
ret.disp.visual.enforce_lobby_join_limits_for_version(Version::GC_V3);
ret.creation_timestamp = this->creation_timestamp.load(); ret.creation_timestamp = this->creation_timestamp.load();
ret.play_time_seconds = this->play_time_seconds.load(); ret.play_time_seconds = this->play_time_seconds.load();
ret.option_flags = this->option_flags.load(); ret.option_flags = this->option_flags.load();
@@ -481,7 +846,7 @@ PSOGCCharacterFile::Character PSOBBCharacterFile::to_gc() const {
ret_sc.spec = gc_sc.spec; ret_sc.spec = gc_sc.spec;
} }
for (size_t z = 0; z < std::min<size_t>(ret.shortcuts.size(), this->shortcuts.size()); z++) { for (size_t z = 0; z < std::min<size_t>(ret.shortcuts.size(), this->shortcuts.size()); z++) {
ret.shortcuts[z] = this->shortcuts[z].convert<true, TextEncoding::MARKED>(language); ret.shortcuts[z] = this->shortcuts[z].convert<true, TextEncoding::MARKED, 0x50>(language);
} }
ret.auto_reply.encode(this->auto_reply.decode(language), language); ret.auto_reply.encode(this->auto_reply.decode(language), language);
ret.info_board.encode(this->info_board.decode(language), language); ret.info_board.encode(this->info_board.decode(language), language);
@@ -501,22 +866,55 @@ PSOGCCharacterFile::Character PSOBBCharacterFile::to_gc() const {
return ret; return ret;
} }
SaveFileSymbolChatEntryBB PSOBBCharacterFile::DefaultSymbolChatEntry::to_entry(uint8_t language) const { PSOXBCharacterFileCharacter PSOBBCharacterFile::to_xb(uint64_t xb_user_id) const {
SaveFileSymbolChatEntryBB ret; uint8_t language = this->inventory.language;
ret.present = 1;
ret.name.encode(this->language_to_name.at(language), language); PSOXBCharacterFileCharacter ret;
ret.spec.spec = this->spec; ret.inventory = this->inventory;
for (size_t z = 0; z < 4; z++) { ret.inventory.encode_for_client(Version::XB_V3, nullptr);
ret.spec.corner_objects[z] = this->corner_objects[z]; ret.disp = this->disp.to_dcpcv3<false>(language, language);
ret.disp.visual.enforce_lobby_join_limits_for_version(Version::XB_V3);
ret.creation_timestamp = this->creation_timestamp.load();
ret.play_time_seconds = this->play_time_seconds.load();
ret.option_flags = this->option_flags.load();
ret.save_count = this->save_count.load();
ret.quest_flags = this->quest_flags;
ret.death_count = this->death_count.load();
ret.bank = this->bank;
ret.bank.encode_for_client(Version::XB_V3);
ret.guild_card = this->guild_card;
ret.guild_card.xb_user_id_high = (xb_user_id >> 32) & 0xFFFFFFFF;
ret.guild_card.xb_user_id_low = xb_user_id & 0xFFFFFFFF;
for (size_t z = 0; z < std::min<size_t>(ret.symbol_chats.size(), this->symbol_chats.size()); z++) {
auto& ret_sc = ret.symbol_chats[z];
const auto& gc_sc = this->symbol_chats[z];
ret_sc.present = gc_sc.present.load();
ret_sc.name.encode(gc_sc.name.decode(language), language);
ret_sc.spec = gc_sc.spec;
} }
for (size_t z = 0; z < 12; z++) { for (size_t z = 0; z < std::min<size_t>(ret.shortcuts.size(), this->shortcuts.size()); z++) {
ret.spec.face_parts[z] = this->face_parts[z]; ret.shortcuts[z] = this->shortcuts[z].convert<false, TextEncoding::MARKED, 0x50>(language);
} }
ret.auto_reply.encode(this->auto_reply.decode(language), language);
ret.info_board.encode(this->info_board.decode(language), language);
ret.battle_records = this->battle_records;
ret.unknown_a4 = this->unknown_a4;
ret.challenge_records = this->challenge_records;
for (size_t z = 0; z < std::min<size_t>(ret.tech_menu_shortcut_entries.size(), this->tech_menu_shortcut_entries.size()); z++) {
ret.tech_menu_shortcut_entries[z] = this->tech_menu_shortcut_entries[z].load();
}
ret.choice_search_config = this->choice_search_config;
ret.unknown_a6 = this->unknown_a6;
for (size_t z = 0; z < std::min<size_t>(ret.quest_counters.size(), this->quest_counters.size()); z++) {
ret.quest_counters[z] = this->quest_counters[z].load();
}
ret.offline_battle_records = this->offline_battle_records;
ret.unknown_a7 = this->unknown_a7;
return ret; return ret;
} }
// TODO: Eliminate duplication between this function and the parallel function // TODO: Eliminate duplication between this function and the parallel function
// in PlayerBank // in PlayerBankT
void PSOBBCharacterFile::add_item(const ItemData& item, const ItemData::StackLimits& limits) { void PSOBBCharacterFile::add_item(const ItemData& item, const ItemData::StackLimits& limits) {
uint32_t primary_identifier = item.primary_identifier(); uint32_t primary_identifier = item.primary_identifier();
@@ -564,7 +962,7 @@ void PSOBBCharacterFile::add_item(const ItemData& item, const ItemData::StackLim
} }
// TODO: Eliminate code duplication between this function and the parallel // TODO: Eliminate code duplication between this function and the parallel
// function in PlayerBank // function in PlayerBankT
ItemData PSOBBCharacterFile::remove_item(uint32_t item_id, uint32_t amount, const ItemData::StackLimits& limits) { ItemData PSOBBCharacterFile::remove_item(uint32_t item_id, uint32_t amount, const ItemData::StackLimits& limits) {
ItemData ret; ItemData ret;
@@ -699,49 +1097,39 @@ void PSOBBCharacterFile::clear_all_material_usage() {
} }
} }
const array<PSOBBCharacterFile::DefaultSymbolChatEntry, 6> PSOBBCharacterFile::DEFAULT_SYMBOL_CHATS = { void PSOBBCharacterFile::import_tethealla_material_usage(std::shared_ptr<const LevelTable> level_table) {
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF", "\tEHello", "\tEHallo", "\tESalut", "\tEHola", "\tB\xE4\xBD\xA0\xE5\xA5\xBD", "\tT\xE4\xBD\xA0\xE5\xA5\xBD", "\tK\xEC\x95\x88\xEB\x85\x95"}, 0x28, {0xFFFF, 0x000D, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x05, 0x18, 0x1D, 0x00}, {0x05, 0x28, 0x1D, 0x01}, {0x36, 0x20, 0x2A, 0x00}, {0x3C, 0x00, 0x32, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, // Tethealla (Ephinea) doesn't store material counts anywhere in the file,
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x95\xE3\x82\x88\xE3\x81\x86\xE3\x81\xAA\xE3\x82\x89", "\tEGood-bye", "\tETschus", "\tEAu revoir", "\tEAdios", "\tB\xE5\x86\x8D\xE8\xA7\x81", "\tT\xE5\x86\x8D\xE8\xA6\x8B", "\tK\xEC\x9E\x98\xEA\xB0\x80"}, 0x74, {0x0476, 0x000C, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x06, 0x15, 0x14, 0x00}, {0x06, 0x2B, 0x14, 0x01}, {0x05, 0x18, 0x1F, 0x00}, {0x05, 0x28, 0x1F, 0x01}, {0x36, 0x20, 0x2A, 0x00}, {0x3C, 0x00, 0x32, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, // so if the material counts in the inventory extension data are all zero,
DefaultSymbolChatEntry{{"\tJ\xE3\x81\xB0\xE3\x82\x93\xE3\x81\x96\xE3\x83\xBC\xE3\x81\x84", "\tEHurrah!", "\tEHurra!", "\tEHourra !", "\tEHurra", "\tB\xE4\xB8\x87\xE5\xB2\x81", "\tT\xE8\x90\xAC\xE6\xAD\xB2", "\tK\xEB\xA7\x8C\xEC\x84\xB8"}, 0x28, {0x0362, 0x0362, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x09, 0x16, 0x1B, 0x00}, {0x09, 0x2B, 0x1B, 0x01}, {0x37, 0x20, 0x2C, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, // check the current stats against the expected stats for the character's
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x86\xE3\x81\x87\xEF\xBD\x9E\xE3\x82\x93", "\tECrying", "\tEIch bin sauer!", "\tEJe suis triste", "\tELlanto", "\tB\xE5\x96\x82\xEF\xBD\x9E", "\tT\xE5\x96\x82\xEF\xBD\x9E", "\tK\xEC\x9D\x91~"}, 0x74, {0x074F, 0xFFFF, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x06, 0x15, 0x14, 0x00}, {0x06, 0x2B, 0x14, 0x01}, {0x05, 0x18, 0x1F, 0x00}, {0x05, 0x28, 0x1F, 0x01}, {0x21, 0x20, 0x2E, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, // current level and set the material counts if they make sense.
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x8A\xE3\x81\x93\xE3\x81\xA3\xE3\x81\x9F\xEF\xBC\x81", "\tEI'm angry!", "\tEWeinen", "\tEJe suis en colere !", "\tEEnfado", "\tB\xE7\x94\x9F\xE6\xB0\x94\xE4\xBA\x86\xEF\xBC\x81", "\tT\xE7\x94\x9F\xE6\xB0\xA3\xE4\xBA\x86\xEF\xBC\x81", "\tK\xEB\x82\x98\xEC\x99\x94\xEB\x8B\xA4\xEF\xBC\x81"}, 0x5C, {0x0116, 0x0001, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x0B, 0x18, 0x1B, 0x01}, {0x0B, 0x28, 0x1B, 0x00}, {0x33, 0x20, 0x2A, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, if (this->get_material_usage(PSOBBCharacterFile::MaterialType::POWER) |
DefaultSymbolChatEntry{{"\tJ\xE3\x81\x9F\xE3\x81\x99\xE3\x81\x91\xE3\x81\xA6\xEF\xBC\x81", "\tEHelp me!", "\tEHilf mir!", "\tEAide-moi !", "\tEAyuda", "\tB\xE6\x95\x91\xE5\x91\xBD\xE5\x95\x8A\xEF\xBC\x81", "\tT\xE6\x95\x91\xE5\x91\xBD\xE5\x95\x8A\xEF\xBC\x81", "\tK\xEB\x8F\x84\xEC\x99\x80\xEC\xA4\x98\xEF\xBC\x81"}, 0xEC, {0x065E, 0x0138, 0xFFFF, 0xFFFF}, {SymbolChatFacePart{0x02, 0x17, 0x1B, 0x01}, {0x02, 0x2A, 0x1B, 0x00}, {0x31, 0x20, 0x2C, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x00}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}, {0xFF, 0x00, 0x00, 0x02}}}, this->get_material_usage(PSOBBCharacterFile::MaterialType::MIND) |
}; this->get_material_usage(PSOBBCharacterFile::MaterialType::EVADE) |
this->get_material_usage(PSOBBCharacterFile::MaterialType::DEF) |
this->get_material_usage(PSOBBCharacterFile::MaterialType::LUCK)) {
return;
}
const array<uint16_t, 20> PSOBBCharacterFile::DEFAULT_TECH_MENU_CONFIG = { PlayerStats level_base_stats = this->disp.stats;
0x0000, 0x0006, 0x0003, 0x0001, 0x0007, 0x0004, 0x0002, 0x0008, 0x0005, 0x0009, level_table->reset_to_base(level_base_stats, this->disp.visual.char_class);
0x0012, 0x000F, 0x0010, 0x0011, 0x000D, 0x000A, 0x000B, 0x000C, 0x000E, 0x0000}; level_table->advance_to_level(level_base_stats, this->disp.stats.level, this->disp.visual.char_class);
const array<uint8_t, 0x016C> PSOBBBaseSystemFile::DEFAULT_KEY_CONFIG = { uint64_t pow = (this->disp.stats.char_stats.atp - level_base_stats.char_stats.atp) / 2;
0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, uint64_t mind = (this->disp.stats.char_stats.mst - level_base_stats.char_stats.mst) / 2;
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, uint64_t evade = (this->disp.stats.char_stats.evp - level_base_stats.char_stats.evp) / 2;
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, uint64_t def = (this->disp.stats.char_stats.dfp - level_base_stats.char_stats.dfp) / 2;
0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, uint64_t luck = (this->disp.stats.char_stats.lck - level_base_stats.char_stats.lck) / 2;
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4B, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
const array<uint8_t, 0x0038> PSOBBBaseSystemFile::DEFAULT_JOYSTICK_CONFIG = { // We intentionally do not check any limits here. This is because on pre-v3,
0x00, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, // there are no limits, and we don't want to reject legitimate characters
0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // that have used more than 250 materials.
0x08, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; this->set_material_usage(PSOBBCharacterFile::MaterialType::POWER, pow);
this->set_material_usage(PSOBBCharacterFile::MaterialType::MIND, mind);
this->set_material_usage(PSOBBCharacterFile::MaterialType::EVADE, evade);
this->set_material_usage(PSOBBCharacterFile::MaterialType::DEF, def);
this->set_material_usage(PSOBBCharacterFile::MaterialType::LUCK, luck);
}
static uint16_t crc16(const void* data, size_t size) { static uint16_t crc16(const void* data, size_t size) {
static const uint16_t table[0x100] = { static const uint16_t table[0x100] = {
+626 -405
View File
File diff suppressed because it is too large Load Diff
+224 -67
View File
@@ -19,6 +19,7 @@
#include "FileContentsCache.hh" #include "FileContentsCache.hh"
#include "PSOProtocol.hh" #include "PSOProtocol.hh"
#include "ProxyServer.hh" #include "ProxyServer.hh"
#include "ReceiveSubcommands.hh"
#include "StaticGameData.hh" #include "StaticGameData.hh"
#include "Text.hh" #include "Text.hh"
@@ -346,8 +347,7 @@ void prepare_client_for_patches(shared_ptr<Client> c, function<void()> on_comple
} else if (c->version() == Version::XB_V3) { } else if (c->version() == Version::XB_V3) {
version_detect_name = "VersionDetectXB"; version_detect_name = "VersionDetectXB";
} }
if (version_detect_name && if (version_detect_name && specific_version_is_indeterminate(c->config.specific_version)) {
c->config.specific_version == default_specific_version_for_version(c->version(), -1)) {
send_function_call(c, s->function_code_index->name_to_function.at(version_detect_name)); send_function_call(c, s->function_code_index->name_to_function.at(version_detect_name));
c->function_call_response_queue.emplace_back([wc = weak_ptr<Client>(c), on_complete](uint32_t specific_version, uint32_t) -> void { c->function_call_response_queue.emplace_back([wc = weak_ptr<Client>(c), on_complete](uint32_t specific_version, uint32_t) -> void {
auto c = wc.lock(); auto c = wc.lock();
@@ -364,7 +364,8 @@ void prepare_client_for_patches(shared_ptr<Client> c, function<void()> on_comple
}; };
if (!c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH)) { if (!c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH)) {
send_function_call(c, s->function_code_index->name_to_function.at("CacheClearFix-Phase1"), {}, "", 0x80000000, 8, 0x7F2734EC); auto fn = s->function_code_index->name_to_function.at("CacheClearFix-Phase1");
send_function_call(c, fn, {}, nullptr, 0, 0x80000000, 8, 0x7F2734EC);
c->function_call_response_queue.emplace_back([s, wc = weak_ptr<Client>(c), send_version_detect](uint32_t, uint32_t header_checksum) -> void { c->function_call_response_queue.emplace_back([s, wc = weak_ptr<Client>(c), send_version_detect](uint32_t, uint32_t header_checksum) -> void {
auto c = wc.lock(); auto c = wc.lock();
if (!c) { if (!c) {
@@ -396,14 +397,15 @@ void prepare_client_for_patches(shared_ptr<Client> c, function<void()> on_comple
string prepare_send_function_call_data( string prepare_send_function_call_data(
shared_ptr<const CompiledFunctionCode> code, shared_ptr<const CompiledFunctionCode> code,
const unordered_map<string, uint32_t>& label_writes, const unordered_map<string, uint32_t>& label_writes,
const string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t checksum_addr, uint32_t checksum_addr,
uint32_t checksum_size, uint32_t checksum_size,
uint32_t override_relocations_offset, uint32_t override_relocations_offset,
bool use_encrypted_format) { bool use_encrypted_format) {
string data; string data;
if (code.get()) { if (code.get()) {
data = code->generate_client_command(label_writes, suffix, override_relocations_offset); data = code->generate_client_command(label_writes, suffix_data, suffix_size, override_relocations_offset);
if (use_encrypted_format) { if (use_encrypted_format) {
uint32_t key = random_object<uint32_t>(); uint32_t key = random_object<uint32_t>();
@@ -445,7 +447,8 @@ void send_function_call(
shared_ptr<Client> c, shared_ptr<Client> c,
shared_ptr<const CompiledFunctionCode> code, shared_ptr<const CompiledFunctionCode> code,
const unordered_map<string, uint32_t>& label_writes, const unordered_map<string, uint32_t>& label_writes,
const string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t checksum_addr, uint32_t checksum_addr,
uint32_t checksum_size, uint32_t checksum_size,
uint32_t override_relocations_offset) { uint32_t override_relocations_offset) {
@@ -454,7 +457,8 @@ void send_function_call(
c->config, c->config,
code, code,
label_writes, label_writes,
suffix, suffix_data,
suffix_size,
checksum_addr, checksum_addr,
checksum_size, checksum_size,
override_relocations_offset); override_relocations_offset);
@@ -465,11 +469,12 @@ void send_function_call(
const Client::Config& client_config, const Client::Config& client_config,
shared_ptr<const CompiledFunctionCode> code, shared_ptr<const CompiledFunctionCode> code,
const unordered_map<string, uint32_t>& label_writes, const unordered_map<string, uint32_t>& label_writes,
const string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t checksum_addr, uint32_t checksum_addr,
uint32_t checksum_size, uint32_t checksum_size,
uint32_t override_relocations_offset) { uint32_t override_relocations_offset) {
if (client_config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL)) { if (!client_config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
throw logic_error("client does not support function calls"); throw logic_error("client does not support function calls");
} }
if (code.get() && client_config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) { if (code.get() && client_config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) {
@@ -477,7 +482,7 @@ void send_function_call(
} }
string data = prepare_send_function_call_data( string data = prepare_send_function_call_data(
code, label_writes, suffix, checksum_addr, checksum_size, override_relocations_offset, code, label_writes, suffix_data, suffix_size, checksum_addr, checksum_size, override_relocations_offset,
client_config.check_flag(Client::Flag::ENCRYPTED_SEND_FUNCTION_CALL)); client_config.check_flag(Client::Flag::ENCRYPTED_SEND_FUNCTION_CALL));
ch.send(0xB2, code ? code->index : 0x00, data); ch.send(0xB2, code ? code->index : 0x00, data);
@@ -502,10 +507,11 @@ bool send_protected_command(std::shared_ptr<Client> c, const void* data, size_t
case Version::GC_V3: case Version::GC_V3:
case Version::XB_V3: case Version::XB_V3:
case Version::GC_EP3_NTE: case Version::GC_EP3_NTE:
case Version::GC_EP3: { case Version::GC_EP3:
case Version::BB_V4: {
auto s = c->require_server_state(); auto s = c->require_server_state();
if (!s->enable_v3_v4_protected_subcommands || if (!s->enable_v3_v4_protected_subcommands ||
c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL) || !c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL) ||
c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) { c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) {
return false; return false;
} }
@@ -519,7 +525,7 @@ bool send_protected_command(std::shared_ptr<Client> c, const void* data, size_t
auto s = c->require_server_state(); auto s = c->require_server_state();
auto fn = s->function_code_index->get_patch("CallProtectedHandler", c->config.specific_version); auto fn = s->function_code_index->get_patch("CallProtectedHandler", c->config.specific_version);
uint32_t size_label_value = is_big_endian(c->version()) ? data.size() : bswap32(data.size()); uint32_t size_label_value = is_big_endian(c->version()) ? data.size() : bswap32(data.size());
send_function_call(c, fn, {{"size", size_label_value}}, data); send_function_call(c, fn, {{"size", size_label_value}}, data.data(), data.size());
c->function_call_response_queue.emplace_back(empty_function_call_response_handler); c->function_call_response_queue.emplace_back(empty_function_call_response_handler);
if (echo_to_lobby) { if (echo_to_lobby) {
auto l = c->lobby.lock(); auto l = c->lobby.lock();
@@ -557,6 +563,37 @@ void send_pc_console_split_reconnect(shared_ptr<Client> c, uint32_t address,
send_command_t(c, 0x19, 0x00, cmd); send_command_t(c, 0x19, 0x00, cmd);
} }
static void scramble_bb_security_data(parray<uint8_t, 0x28>& data, uint8_t which, bool reverse) {
static const uint8_t forward_orders[8][5] = {
{2, 0, 1, 4, 3},
{3, 4, 0, 1, 2},
{2, 3, 4, 0, 1},
{2, 3, 0, 1, 4},
{0, 2, 3, 4, 1},
{1, 4, 2, 3, 0},
{2, 0, 1, 4, 3},
{1, 0, 3, 4, 2},
};
static const uint8_t reverse_orders[8][5] = {
{1, 2, 0, 4, 3},
{2, 3, 4, 0, 1},
{3, 4, 0, 1, 2},
{2, 3, 0, 1, 4},
{0, 4, 1, 2, 3},
{4, 0, 2, 3, 1},
{1, 2, 0, 4, 3},
{1, 0, 4, 2, 3},
};
const auto& order = reverse ? reverse_orders[which & 7] : forward_orders[which & 7];
parray<uint8_t, 0x28> scrambled_data;
for (size_t z = 0; z < 5; z++) {
for (size_t x = 0; x < 8; x++) {
scrambled_data[(z * 8) + x] = data[(order[z] * 8) + x];
}
}
data = scrambled_data;
}
void send_client_init_bb(shared_ptr<Client> c, uint32_t error_code) { void send_client_init_bb(shared_ptr<Client> c, uint32_t error_code) {
auto team = c->team(); auto team = c->team();
S_ClientInit_BB_00E6 cmd; S_ClientInit_BB_00E6 cmd;
@@ -567,6 +604,15 @@ void send_client_init_bb(shared_ptr<Client> c, uint32_t error_code) {
c->config.serialize_into(cmd.client_config); c->config.serialize_into(cmd.client_config);
cmd.can_create_team = 1; cmd.can_create_team = 1;
cmd.episode_4_unlocked = 1; cmd.episode_4_unlocked = 1;
// If security_token is zero, the game scrambles the client config data based
// on the first character in the username. We undo the scramble here, so when
// the client scrambles the data upon receipt, it will be correct when it next
// is sent back to the server.
if (cmd.security_token == 0 && c->login && c->login->bb_license) {
scramble_bb_security_data(cmd.client_config, c->login->bb_license->username.at(0), true);
}
send_command_t(c, 0x00E6, 0x00000000, cmd); send_command_t(c, 0x00E6, 0x00000000, cmd);
} }
@@ -733,6 +779,7 @@ static void send_text(
Channel& ch, Channel& ch,
StringWriter& w, StringWriter& w,
uint16_t command, uint16_t command,
uint32_t flag,
const string& text, const string& text,
ColorMode color_mode) { ColorMode color_mode) {
bool is_w = uses_utf16(ch.version); bool is_w = uses_utf16(ch.version);
@@ -766,18 +813,18 @@ static void send_text(
while (w.str().size() & 3) { while (w.str().size() & 3) {
w.put_u8(0); w.put_u8(0);
} }
ch.send(command, 0x00, w.str()); ch.send(command, flag, w.str());
} }
static void send_text(Channel& ch, uint16_t command, const string& text, ColorMode color_mode) { static void send_text(Channel& ch, uint16_t command, uint32_t flag, const string& text, ColorMode color_mode) {
StringWriter w; StringWriter w;
send_text(ch, w, command, text, color_mode); send_text(ch, w, command, flag, text, color_mode);
} }
static void send_header_text(Channel& ch, uint16_t command, uint32_t guild_card_number, const string& text, ColorMode color_mode) { static void send_header_text(Channel& ch, uint16_t command, uint32_t guild_card_number, const string& text, ColorMode color_mode) {
StringWriter w; StringWriter w;
w.put(SC_TextHeader_01_06_11_B0_EE({0, guild_card_number})); w.put(SC_TextHeader_01_06_11_B0_EE({0, guild_card_number}));
send_text(ch, w, command, text, color_mode); send_text(ch, w, command, 0x00, text, color_mode);
} }
void send_message_box(shared_ptr<Client> c, const string& text) { void send_message_box(shared_ptr<Client> c, const string& text) {
@@ -806,7 +853,7 @@ void send_message_box(shared_ptr<Client> c, const string& text) {
default: default:
throw logic_error("invalid game version"); throw logic_error("invalid game version");
} }
send_text(c->channel, command, text, ColorMode::ADD); send_text(c->channel, command, 0x00, text, ColorMode::ADD);
} }
void send_ep3_timed_message_box(Channel& ch, uint32_t frames, const string& message) { void send_ep3_timed_message_box(Channel& ch, uint32_t frames, const string& message) {
@@ -828,11 +875,11 @@ void send_ep3_timed_message_box(Channel& ch, uint32_t frames, const string& mess
} }
void send_lobby_name(shared_ptr<Client> c, const string& text) { void send_lobby_name(shared_ptr<Client> c, const string& text) {
send_text(c->channel, 0x8A, text, ColorMode::NONE); send_text(c->channel, 0x8A, 0x00, text, ColorMode::NONE);
} }
void send_quest_info(shared_ptr<Client> c, const string& text, bool is_download_quest) { void send_quest_info(shared_ptr<Client> c, const string& text, uint8_t description_flag, bool is_download_quest) {
send_text(c->channel, is_download_quest ? 0xA5 : 0xA3, text, ColorMode::ADD); send_text(c->channel, is_download_quest ? 0xA5 : 0xA3, description_flag, text, ColorMode::ADD);
} }
void send_lobby_message_box(shared_ptr<Client> c, const string& text, bool left_side_on_bb) { void send_lobby_message_box(shared_ptr<Client> c, const string& text, bool left_side_on_bb) {
@@ -1382,7 +1429,7 @@ void send_menu_t(shared_ptr<Client> c, shared_ptr<const Menu> menu, bool is_info
is_visible &= !c->config.check_flag(Client::Flag::NO_D6); is_visible &= !c->config.check_flag(Client::Flag::NO_D6);
} }
if (item.flags & MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL) { if (item.flags & MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL) {
is_visible &= !c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL); is_visible &= c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL);
} }
if (item.flags & MenuItem::Flag::REQUIRES_SAVE_DISABLED) { if (item.flags & MenuItem::Flag::REQUIRES_SAVE_DISABLED) {
is_visible &= !c->config.check_flag(Client::Flag::SAVE_ENABLED); is_visible &= !c->config.check_flag(Client::Flag::SAVE_ENABLED);
@@ -1436,6 +1483,7 @@ void send_game_menu_t(
for (shared_ptr<Lobby> l : s->all_lobbies()) { for (shared_ptr<Lobby> l : s->all_lobbies()) {
if (l->is_game() && if (l->is_game() &&
(client_has_debug || l->version_is_allowed(c->version())) && (client_has_debug || l->version_is_allowed(c->version())) &&
(client_has_debug || (l->check_flag(Lobby::Flag::IS_CLIENT_CUSTOMIZATION) == c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION))) &&
(l->check_flag(Lobby::Flag::IS_SPECTATOR_TEAM) == is_spectator_team_list) && (l->check_flag(Lobby::Flag::IS_SPECTATOR_TEAM) == is_spectator_team_list) &&
(!show_tournaments_only || l->tournament_match)) { (!show_tournaments_only || l->tournament_match)) {
games.emplace(l); games.emplace(l);
@@ -1538,7 +1586,7 @@ void send_quest_menu_t(
} }
auto& e = entries.emplace_back(); auto& e = entries.emplace_back();
e.menu_id = (it.second->episode == Episode::EP2) ? MenuID::QUEST_EP2 : MenuID::QUEST_EP1; e.menu_id = (it.second->episode == Episode::EP1) ? MenuID::QUEST_EP1 : MenuID::QUEST_EP2;
e.item_id = it.second->quest_number; e.item_id = it.second->quest_number;
e.name.encode(vq->name, c->language()); e.name.encode(vq->name, c->language());
e.short_description.encode(add_color(vq->short_description), c->language()); e.short_description.encode(add_color(vq->short_description), c->language());
@@ -1559,7 +1607,7 @@ void send_quest_menu_bb(
} }
auto& e = entries.emplace_back(); auto& e = entries.emplace_back();
e.menu_id = MenuID::QUEST_EP1; e.menu_id = (it.second->episode == Episode::EP1) ? MenuID::QUEST_EP1 : MenuID::QUEST_EP2;
e.item_id = it.second->quest_number; e.item_id = it.second->quest_number;
e.name.encode(vq->name, c->language()); e.name.encode(vq->name, c->language());
e.short_description.encode(add_color(vq->short_description), c->language()); e.short_description.encode(add_color(vq->short_description), c->language());
@@ -1583,7 +1631,7 @@ void send_quest_categories_menu_t(
vector<EntryT> entries; vector<EntryT> entries;
for (const auto& cat : quest_index->categories(menu_type, episode, c->version(), include_condition)) { for (const auto& cat : quest_index->categories(menu_type, episode, c->version(), include_condition)) {
auto& e = entries.emplace_back(); auto& e = entries.emplace_back();
e.menu_id = MenuID::QUEST_CATEGORIES; e.menu_id = cat->use_ep2_icon() ? MenuID::QUEST_CATEGORIES_EP2 : MenuID::QUEST_CATEGORIES_EP1;
e.item_id = cat->category_id; e.item_id = cat->category_id;
e.name.encode(cat->name, c->language()); e.name.encode(cat->name, c->language());
e.short_description.encode(add_color(cat->description), c->language()); e.short_description.encode(add_color(cat->description), c->language());
@@ -1794,9 +1842,10 @@ static void send_join_spectator_team(shared_ptr<Client> c, shared_ptr<Lobby> l)
: wc_p->disp.stats.level.load(); : wc_p->disp.stats.level.load();
e.name_color = wc_p->disp.visual.name_color; e.name_color = wc_p->disp.visual.name_color;
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(wc);
p.disp.visual.name_color = s->name_color_for_version(wc->version()); if (name_color) {
e.name_color = p.disp.visual.name_color; p.disp.visual.name_color = name_color;
e.name_color = name_color;
} }
player_count++; player_count++;
@@ -1862,9 +1911,10 @@ static void send_join_spectator_team(shared_ptr<Client> c, shared_ptr<Lobby> l)
: other_p->disp.stats.level.load(); : other_p->disp.stats.level.load();
cmd_e.name_color = other_p->disp.visual.name_color; cmd_e.name_color = other_p->disp.visual.name_color;
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(other_c);
cmd_p.disp.visual.name_color = s->name_color_for_version(other_c->version()); if (name_color) {
cmd_e.name_color = cmd_p.disp.visual.name_color; cmd_p.disp.visual.name_color = name_color;
cmd_e.name_color = name_color;
} }
player_count++; player_count++;
@@ -1966,15 +2016,17 @@ void send_join_game(shared_ptr<Client> c, shared_ptr<Lobby> l) {
size_t player_count = populate_v3_cmd(cmd); size_t player_count = populate_v3_cmd(cmd);
auto s = c->require_server_state(); auto s = c->require_server_state();
for (size_t x = 0; x < 4; x++) { for (size_t x = 0; x < 4; x++) {
if (l->clients[x]) { auto lc = l->clients[x];
auto other_p = l->clients[x]->character(); if (lc) {
auto other_p = lc->character();
auto& cmd_p = cmd.players_ep3[x]; auto& cmd_p = cmd.players_ep3[x];
cmd_p.inventory = other_p->inventory; cmd_p.inventory = other_p->inventory;
cmd_p.inventory.encode_for_client(c->version(), s->item_parameter_table_for_encode(c->version())); cmd_p.inventory.encode_for_client(c->version(), s->item_parameter_table_for_encode(c->version()));
cmd_p.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(other_p->disp, c->language(), other_p->inventory.language); cmd_p.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(other_p->disp, c->language(), other_p->inventory.language);
cmd_p.disp.enforce_lobby_join_limits_for_version(c->version()); cmd_p.disp.enforce_lobby_join_limits_for_version(c->version());
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(lc);
cmd_p.disp.visual.name_color = s->name_color_for_version(l->clients[x]->version()); if (name_color) {
cmd_p.disp.visual.name_color = name_color;
} }
} }
} }
@@ -2092,8 +2144,9 @@ void send_join_lobby_t(shared_ptr<Client> c, shared_ptr<Lobby> l, shared_ptr<Cli
} else { } else {
e.disp = convert_player_disp_data<DispDataT>(lp->disp, c->language(), lp->inventory.language); e.disp = convert_player_disp_data<DispDataT>(lp->disp, c->language(), lp->inventory.language);
e.disp.enforce_lobby_join_limits_for_version(c->version()); e.disp.enforce_lobby_join_limits_for_version(c->version());
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(lc);
e.disp.visual.name_color = s->name_color_for_version(lc->version()); if (name_color) {
e.disp.visual.name_color = name_color;
if (is_v1_or_v2(c->version())) { if (is_v1_or_v2(c->version())) {
e.disp.visual.compute_name_color_checksum(); e.disp.visual.compute_name_color_checksum();
} }
@@ -2164,8 +2217,9 @@ void send_join_lobby_xb(shared_ptr<Client> c, shared_ptr<Lobby> l, shared_ptr<Cl
e.inventory.encode_for_client(c->version(), s->item_parameter_table_for_encode(c->version())); e.inventory.encode_for_client(c->version(), s->item_parameter_table_for_encode(c->version()));
e.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(lp->disp, c->language(), lp->inventory.language); e.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(lp->disp, c->language(), lp->inventory.language);
e.disp.enforce_lobby_join_limits_for_version(c->version()); e.disp.enforce_lobby_join_limits_for_version(c->version());
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(lc);
e.disp.visual.name_color = s->name_color_for_version(lc->version()); if (name_color) {
e.disp.visual.name_color = name_color;
} }
} }
@@ -2215,8 +2269,9 @@ void send_join_lobby_dc_nte(shared_ptr<Client> c, shared_ptr<Lobby> l,
} else { } else {
e.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(lp->disp, c->language(), lp->inventory.language); e.disp = convert_player_disp_data<PlayerDispDataDCPCV3>(lp->disp, c->language(), lp->inventory.language);
e.disp.enforce_lobby_join_limits_for_version(c->version()); e.disp.enforce_lobby_join_limits_for_version(c->version());
if (s->version_name_colors) { uint32_t name_color = s->name_color_for_client(lc);
e.disp.visual.name_color = s->name_color_for_version(lc->version()); if (name_color) {
e.disp.visual.name_color = name_color;
e.disp.visual.compute_name_color_checksum(); e.disp.visual.compute_name_color_checksum();
} }
} }
@@ -2329,17 +2384,31 @@ void send_self_leave_notification(shared_ptr<Client> c) {
send_command_t(c, 0x69, c->lobby_client_id, cmd); send_command_t(c, 0x69, c->lobby_client_id, cmd);
} }
static bool send_get_extended_player_info(shared_ptr<Client> c) { void send_get_player_info(shared_ptr<Client> c, bool request_extended) {
// TODO: Support extended player info on other versions. switch (c->version()) {
if (c->version() != Version::GC_V3) { case Version::DC_NTE:
return false; case Version::DC_V1_11_2000_PROTOTYPE:
} case Version::DC_V1:
auto s = c->require_server_state(); case Version::PC_NTE:
if (c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL) || case Version::PC_V2:
c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) { case Version::BB_V4:
return false; request_extended = false;
break;
case Version::DC_V2:
case Version::GC_NTE:
case Version::GC_V3:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
case Version::XB_V3:
break;
default:
throw logic_error("invalid version");
} }
if (request_extended &&
c->config.check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL) &&
!c->config.check_flag(Client::Flag::SEND_FUNCTION_CALL_CHECKSUM_ONLY)) {
auto s = c->require_server_state();
prepare_client_for_patches(c, [wc = weak_ptr<Client>(c)]() { prepare_client_for_patches(c, [wc = weak_ptr<Client>(c)]() {
auto c = wc.lock(); auto c = wc.lock();
if (!c) { if (!c) {
@@ -2355,11 +2424,7 @@ static bool send_get_extended_player_info(shared_ptr<Client> c) {
send_get_player_info(c, false); send_get_player_info(c, false);
} }
}); });
return true; } else {
}
void send_get_player_info(shared_ptr<Client> c, bool request_extended) {
if (!request_extended || !send_get_extended_player_info(c)) {
send_command(c, (c->version() == Version::DC_NTE) ? 0x8D : 0x95, 0x00); send_command(c, (c->version() == Version::DC_NTE) ? 0x8D : 0x95, 0x00);
} }
} }
@@ -2435,7 +2500,13 @@ void send_arrow_update(shared_ptr<Lobby> l) {
} }
} }
// tells the player that the joining player is done joining, and the game can resume void send_unblock_join(shared_ptr<Client> c) {
if (!is_pre_v1(c->version())) {
static const be_uint32_t data = 0x71010000;
send_command(c, 0x60, 0x00, &data, sizeof(be_uint32_t));
}
}
void send_resume_game(shared_ptr<Lobby> l, shared_ptr<Client> ready_client) { void send_resume_game(shared_ptr<Lobby> l, shared_ptr<Client> ready_client) {
for (auto lc : l->clients) { for (auto lc : l->clients) {
if (lc && (lc != ready_client) && !is_pre_v1(lc->version())) { if (lc && (lc != ready_client) && !is_pre_v1(lc->version())) {
@@ -2483,9 +2554,7 @@ void send_remove_conditions(shared_ptr<Client> c) {
cmd.unknown_a1 = z; cmd.unknown_a1 = z;
cmd.unknown_a2 = 0; cmd.unknown_a2 = 0;
} }
if (send_protected_command(c, &cmds, sizeof(cmds), true)) { send_protected_command(c, &cmds, sizeof(cmds), true);
send_command_excluding_client(c->require_lobby(), c, 0x60, 0x00, &cmds, sizeof(cmds));
}
} }
void send_remove_conditions(Channel& ch, uint16_t client_id) { void send_remove_conditions(Channel& ch, uint16_t client_id) {
@@ -2566,7 +2635,7 @@ void send_game_join_sync_command_compressed(
} }
if (c->game_join_command_queue) { if (c->game_join_command_queue) {
c->log.info("Client not ready to receive join commands; adding to queue"); c->log.info("Client not ready to receive game commands; adding to queue");
auto& cmd = c->game_join_command_queue->emplace_back(); auto& cmd = c->game_join_command_queue->emplace_back();
cmd.command = 0x6D; cmd.command = 0x6D;
cmd.flag = c->lobby_client_id; cmd.flag = c->lobby_client_id;
@@ -2640,7 +2709,7 @@ void send_game_enemy_state(shared_ptr<Client> c) {
const auto& enemy = l->map->enemies[z]; const auto& enemy = l->map->enemies[z];
auto& entry = entries.emplace_back(); auto& entry = entries.emplace_back();
entry.flags = enemy.game_flags; entry.flags = enemy.game_flags;
entry.item_drop_id = (enemy.state_flags & Map::Enemy::Flag::ITEM_DROPPED) ? 0xFFFF : (0xCA0 + z); entry.item_drop_id = (enemy.server_flags & Map::Enemy::Flag::ITEM_DROPPED) ? 0xFFFF : (0xCA0 + z);
entry.total_damage = enemy.total_damage; entry.total_damage = enemy.total_damage;
} }
@@ -2788,6 +2857,85 @@ void send_game_flag_state(shared_ptr<Client> c) {
} }
} }
void send_game_player_state(shared_ptr<Client> to_c, shared_ptr<Client> from_c, bool apply_overrides) {
if (!from_c->last_reported_6x70) {
throw runtime_error("source client did not send a 6x70 command");
}
if (!from_c->login) {
throw logic_error("source client is not logged in");
}
auto s = to_c->require_server_state();
Parsed6x70Data to_send = *from_c->last_reported_6x70;
to_send.base.client_id = from_c->lobby_client_id;
to_send.player_tag = 0x00010000;
to_send.guild_card_number = from_c->login->account->account_id;
auto to_l = to_c->lobby.lock();
if (to_l && (from_c->telepipe_lobby_id == to_l->lobby_id)) {
to_send.telepipe.owner_client_id = from_c->telepipe_state.client_id2;
to_send.telepipe.floor = from_c->telepipe_state.floor;
to_send.telepipe.unknown_a1 = from_c->telepipe_state.unknown_b3;
to_send.telepipe.x = from_c->telepipe_state.x;
to_send.telepipe.y = from_c->telepipe_state.y;
to_send.telepipe.z = from_c->telepipe_state.z;
to_send.telepipe.unknown_a3 = from_c->telepipe_state.unknown_a3;
}
if (apply_overrides) {
auto from_p = from_c->character();
to_send.base.x = from_c->x;
to_send.base.z = from_c->z;
to_send.bonus_hp_from_materials = from_p->inventory.hp_from_materials;
to_send.bonus_tp_from_materials = from_p->inventory.tp_from_materials;
to_send.language = from_c->language();
// TODO: Deal with telepipes. Probably we should track their state via the
// subcommands sent when they're created/destroyed, but currently we don't.
to_send.area = from_c->floor;
to_send.technique_levels_v1 = from_p->disp.technique_levels_v1;
to_send.visual = from_p->disp.visual;
to_send.name = from_p->disp.name.decode(from_c->language());
if (to_c->version() != Version::BB_V4) {
to_send.visual.name.encode(to_send.name, to_c->language());
}
to_send.stats = from_p->disp.stats;
to_send.num_items = from_p->inventory.num_items;
to_send.items = from_p->inventory.items;
to_send.item_version = Version::BB_V4; // Server-side items are stored in BB encoding
to_send.floor = from_c->floor;
}
switch (to_c->version()) {
case Version::DC_NTE:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_dc_nte(s));
break;
case Version::DC_V1_11_2000_PROTOTYPE:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_dc_112000(s));
break;
case Version::DC_V1:
case Version::DC_V2:
case Version::PC_NTE:
case Version::PC_V2:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_dc_pc(s, to_c->version()));
break;
case Version::GC_NTE:
case Version::GC_V3:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_gc_gcnte(s, to_c->version()));
break;
case Version::XB_V3:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_xb(s));
break;
case Version::BB_V4:
send_or_enqueue_command(to_c, 0x6D, to_c->lobby_client_id, to_send.as_bb(s, to_c->language()));
break;
default:
throw logic_error("attempting to send 6x70 command to unknown game version");
}
}
void send_drop_item_to_channel(shared_ptr<ServerState> s, Channel& ch, const ItemData& item, void send_drop_item_to_channel(shared_ptr<ServerState> s, Channel& ch, const ItemData& item,
bool from_enemy, uint8_t floor, float x, float z, uint16_t entity_id) { bool from_enemy, uint8_t floor, float x, float z, uint16_t entity_id) {
uint8_t subcommand = get_pre_v1_subcommand(ch.version, 0x51, 0x58, 0x5F); uint8_t subcommand = get_pre_v1_subcommand(ch.version, 0x51, 0x58, 0x5F);
@@ -2976,7 +3124,7 @@ void send_set_exp_multiplier(shared_ptr<Lobby> l) {
G_SetEXPMultiplier_BB_6xDD cmd = {{0xDD, sizeof(G_SetEXPMultiplier_BB_6xDD) / 4, (l->mode == GameMode::CHALLENGE) ? 1 : l->base_exp_multiplier}}; G_SetEXPMultiplier_BB_6xDD cmd = {{0xDD, sizeof(G_SetEXPMultiplier_BB_6xDD) / 4, (l->mode == GameMode::CHALLENGE) ? 1 : l->base_exp_multiplier}};
for (auto lc : l->clients) { for (auto lc : l->clients) {
if (lc && (lc->version() == Version::BB_V4)) { if (lc && (lc->version() == Version::BB_V4)) {
send_command_t(l, 0x60, 0x00, cmd); send_command_t(lc, 0x60, 0x00, cmd);
} }
} }
} }
@@ -3710,10 +3858,16 @@ void send_open_quest_file(
throw logic_error("cannot send quest files to this version of client"); throw logic_error("cannot send quest files to this version of client");
} }
// For GC/XB/BB, we wait for acknowledgement commands before sending each // On most versions, we can trust the TCP stack to do the right thing when we
// chunk. For DC/PC, we send the entire quest all at once. // send a lot of data at once, but on GC, the client will crash if too much
if (is_v1_or_v2(c->version()) && (c->version() != Version::GC_NTE)) { // quest data is sent at once. This is likely a bug in the TCP stack, since
for (size_t offset = 0; offset < contents->size(); offset += 0x400) { // the client should apply backpressure to avoid bad situations, but we have
// to deal with it here instead.
size_t total_chunks = (contents->size() + 0x3FF) / 0x400;
size_t chunks_to_send = is_gc(c->version()) ? min<size_t>(GC_QUEST_LOAD_MAX_CHUNKS_IN_FLIGHT, total_chunks) : total_chunks;
for (size_t z = 0; z < chunks_to_send; z++) {
size_t offset = z * 0x400;
size_t chunk_bytes = contents->size() - offset; size_t chunk_bytes = contents->size() - offset;
if (chunk_bytes > 0x400) { if (chunk_bytes > 0x400) {
chunk_bytes = 0x400; chunk_bytes = 0x400;
@@ -3721,7 +3875,10 @@ void send_open_quest_file(
send_quest_file_chunk(c, filename.c_str(), offset / 0x400, send_quest_file_chunk(c, filename.c_str(), offset / 0x400,
contents->data() + offset, chunk_bytes, (type != QuestFileType::ONLINE)); contents->data() + offset, chunk_bytes, (type != QuestFileType::ONLINE));
} }
} else {
// If there are still chunks to send, track the file so the chunk
// acknowledgement handler (13 or A7) cna know what to send next
if (chunks_to_send < total_chunks) {
c->sending_files.emplace(filename, contents); c->sending_files.emplace(filename, contents);
c->log.info("Opened file %s", filename.c_str()); c->log.info("Opened file %s", filename.c_str());
} }
+26 -5
View File
@@ -21,6 +21,8 @@ extern const std::unordered_set<uint32_t> v2_crypt_initial_client_commands;
extern const std::unordered_set<uint32_t> v3_crypt_initial_client_commands; extern const std::unordered_set<uint32_t> v3_crypt_initial_client_commands;
extern const std::unordered_set<std::string> bb_crypt_initial_client_commands; extern const std::unordered_set<std::string> bb_crypt_initial_client_commands;
constexpr size_t GC_QUEST_LOAD_MAX_CHUNKS_IN_FLIGHT = 4;
// TODO: Many of these functions should take a Channel& instead of a // TODO: Many of these functions should take a Channel& instead of a
// shared_ptr<Client>. Refactor functions appropriately. // shared_ptr<Client>. Refactor functions appropriately.
@@ -32,6 +34,21 @@ extern const std::unordered_set<std::string> bb_crypt_initial_client_commands;
// pointer is given but size is accidentally not given (e.g. if the type of // pointer is given but size is accidentally not given (e.g. if the type of
// data in the calling function is changed from string to void*). // data in the calling function is changed from string to void*).
template <typename CmdT>
void send_or_enqueue_command(std::shared_ptr<Client> c, uint16_t command, uint32_t flag, const CmdT& cmd) {
if (c->game_join_command_queue) {
c->log.info("Client not ready to receive game commands; adding to queue");
auto& q_cmd = c->game_join_command_queue->emplace_back();
q_cmd.command = command;
q_cmd.flag = flag;
// TODO: It'd be nice to avoid this copy. Maybe take in a pointer to cmd
// and move it into q_cmd somehow, so q_cmd can free it when needed?
q_cmd.data.assign(reinterpret_cast<const char*>(&cmd), sizeof(cmd));
} else {
send_command(c, command, flag, &cmd, sizeof(cmd));
}
}
void send_command(std::shared_ptr<Client> c, uint16_t command, void send_command(std::shared_ptr<Client> c, uint16_t command,
uint32_t flag, const std::vector<std::pair<const void*, size_t>>& blocks); uint32_t flag, const std::vector<std::pair<const void*, size_t>>& blocks);
@@ -137,7 +154,8 @@ void prepare_client_for_patches(std::shared_ptr<Client> c, std::function<void()>
std::string prepare_send_function_call_data( std::string prepare_send_function_call_data(
std::shared_ptr<const CompiledFunctionCode> code, std::shared_ptr<const CompiledFunctionCode> code,
const std::unordered_map<std::string, uint32_t>& label_writes, const std::unordered_map<std::string, uint32_t>& label_writes,
const std::string& suffix, const void* suffix_data,
size_t suffix_size,
uint32_t checksum_addr, uint32_t checksum_addr,
uint32_t checksum_size, uint32_t checksum_size,
uint32_t override_relocations_offset, uint32_t override_relocations_offset,
@@ -147,7 +165,8 @@ void send_function_call(
const Client::Config& client_config, const Client::Config& client_config,
std::shared_ptr<const CompiledFunctionCode> code, std::shared_ptr<const CompiledFunctionCode> code,
const std::unordered_map<std::string, uint32_t>& label_writes = {}, const std::unordered_map<std::string, uint32_t>& label_writes = {},
const std::string& suffix = "", const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t checksum_addr = 0, uint32_t checksum_addr = 0,
uint32_t checksum_size = 0, uint32_t checksum_size = 0,
uint32_t override_relocations_offset = 0); uint32_t override_relocations_offset = 0);
@@ -155,7 +174,8 @@ void send_function_call(
std::shared_ptr<Client> c, std::shared_ptr<Client> c,
std::shared_ptr<const CompiledFunctionCode> code, std::shared_ptr<const CompiledFunctionCode> code,
const std::unordered_map<std::string, uint32_t>& label_writes = {}, const std::unordered_map<std::string, uint32_t>& label_writes = {},
const std::string& suffix = "", const void* suffix_data = nullptr,
size_t suffix_size = 0,
uint32_t checksum_addr = 0, uint32_t checksum_addr = 0,
uint32_t checksum_size = 0, uint32_t checksum_size = 0,
uint32_t override_relocations_offset = 0); uint32_t override_relocations_offset = 0);
@@ -182,8 +202,7 @@ void send_complete_player_bb(std::shared_ptr<Client> c);
void send_message_box(std::shared_ptr<Client> c, const std::string& text); void send_message_box(std::shared_ptr<Client> c, const std::string& text);
void send_ep3_timed_message_box(Channel& ch, uint32_t frames, const std::string& text); void send_ep3_timed_message_box(Channel& ch, uint32_t frames, const std::string& text);
void send_lobby_name(std::shared_ptr<Client> c, const std::string& text); void send_lobby_name(std::shared_ptr<Client> c, const std::string& text);
void send_quest_info(std::shared_ptr<Client> c, const std::string& text, void send_quest_info(std::shared_ptr<Client> c, const std::string& text, uint8_t flag, bool is_download_quest);
bool is_download_quest);
void send_lobby_message_box(std::shared_ptr<Client> c, const std::string& text, bool left_side_on_bb = false); void send_lobby_message_box(std::shared_ptr<Client> c, const std::string& text, bool left_side_on_bb = false);
void send_ship_info(std::shared_ptr<Client> c, const std::string& text); void send_ship_info(std::shared_ptr<Client> c, const std::string& text);
void send_ship_info(Channel& ch, const std::string& text); void send_ship_info(Channel& ch, const std::string& text);
@@ -293,6 +312,7 @@ void send_execute_item_trade(std::shared_ptr<Client> c, const std::vector<ItemDa
void send_execute_card_trade(std::shared_ptr<Client> c, const std::vector<std::pair<uint32_t, uint32_t>>& card_to_count); void send_execute_card_trade(std::shared_ptr<Client> c, const std::vector<std::pair<uint32_t, uint32_t>>& card_to_count);
void send_arrow_update(std::shared_ptr<Lobby> l); void send_arrow_update(std::shared_ptr<Lobby> l);
void send_unblock_join(std::shared_ptr<Client> c);
void send_resume_game(std::shared_ptr<Lobby> l, std::shared_ptr<Client> ready_client); void send_resume_game(std::shared_ptr<Lobby> l, std::shared_ptr<Client> ready_client);
enum PlayerStatsChange { enum PlayerStatsChange {
@@ -331,6 +351,7 @@ void send_game_enemy_state(std::shared_ptr<Client> c);
void send_game_object_state(std::shared_ptr<Client> c); void send_game_object_state(std::shared_ptr<Client> c);
void send_game_set_state(std::shared_ptr<Client> c); void send_game_set_state(std::shared_ptr<Client> c);
void send_game_flag_state(std::shared_ptr<Client> c); void send_game_flag_state(std::shared_ptr<Client> c);
void send_game_player_state(std::shared_ptr<Client> to_c, std::shared_ptr<Client> from_c, bool apply_overrides);
void send_drop_item_to_channel(std::shared_ptr<ServerState> s, Channel& ch, const ItemData& item, void send_drop_item_to_channel(std::shared_ptr<ServerState> s, Channel& ch, const ItemData& item,
bool from_enemy, uint8_t floor, float x, float z, uint16_t request_id); bool from_enemy, uint8_t floor, float x, float z, uint16_t request_id);
void send_drop_item_to_lobby(std::shared_ptr<Lobby> l, const ItemData& item, void send_drop_item_to_lobby(std::shared_ptr<Lobby> l, const ItemData& item,
+18 -4
View File
@@ -82,7 +82,21 @@ void ServerShell::thread_fn() {
for (;;) { for (;;) {
fprintf(stdout, "newserv> "); fprintf(stdout, "newserv> ");
fflush(stdout); fflush(stdout);
string command = fgets(stdin); string command;
uint64_t read_start_usecs = now();
try {
command = fgets(stdin);
} catch (const io_error& e) {
// Cygwin sometimes causes fgets() to fail with errno -1 when the
// terminal window is resized. We ignore these events unless the read
// failed immediately (which probably means it would fail again if we
// retried immediately).
if (now() - read_start_usecs < 1000000 || e.error != -1) {
throw;
}
log_warning("I/O error reading from terminal: %s (%d)", e.what(), e.error);
continue;
}
// If command is empty (not even a \n), it's probably EOF // If command is empty (not even a \n), it's probably EOF
if (command.empty()) { if (command.empty()) {
@@ -209,7 +223,7 @@ CommandDefinition c_reload(
functions - recompile all client-side patches and functions\n\ functions - recompile all client-side patches and functions\n\
item-definitions - reload item definitions files\n\ item-definitions - reload item definitions files\n\
item-name-index - regenerate item name list\n\ item-name-index - regenerate item name list\n\
level-table - reload the level-up tables\n\ level-tables - reload the player stats tables\n\
patch-files - reindex the PC and BB patch directories\n\ patch-files - reindex the PC and BB patch directories\n\
quests - reindex all quests (including Episode3 download quests)\n\ quests - reindex all quests (including Episode3 download quests)\n\
set-tables - reload set data tables\n\ set-tables - reload set data tables\n\
@@ -246,8 +260,8 @@ CommandDefinition c_reload(
args.s->load_set_data_tables(true); args.s->load_set_data_tables(true);
} else if (type == "battle-params") { } else if (type == "battle-params") {
args.s->load_battle_params(true); args.s->load_battle_params(true);
} else if (type == "level-table") { } else if (type == "level-tables") {
args.s->load_level_table(true); args.s->load_level_tables(true);
} else if (type == "text-index") { } else if (type == "text-index") {
args.s->load_text_index(true); args.s->load_text_index(true);
} else if (type == "word-select") { } else if (type == "word-select") {
+83 -9
View File
@@ -26,7 +26,11 @@ ServerState::QuestF960Result::QuestF960Result(const JSON& json, std::shared_ptr<
this->probability_upgrade = json.get_int("ProbabilityUpgrade", 0); this->probability_upgrade = json.get_int("ProbabilityUpgrade", 0);
for (size_t day = 0; day < 7; day++) { for (size_t day = 0; day < 7; day++) {
for (const auto& item_it : json.get_list(day_names[day])) { for (const auto& item_it : json.get_list(day_names[day])) {
try {
this->results[day].emplace_back(name_index->parse_item_description(item_it->as_string())); this->results[day].emplace_back(name_index->parse_item_description(item_it->as_string()));
} catch (const exception& e) {
config_log.warning("Cannot parse item description \"%s\": %s (skipping entry)", item_it->as_string().c_str(), e.what());
}
} }
} }
} }
@@ -61,7 +65,7 @@ void ServerState::add_client_to_available_lobby(shared_ptr<Client> c) {
} }
if (!added_to_lobby.get()) { if (!added_to_lobby.get()) {
for (const auto& lobby_id : this->public_lobby_search_order(c->version())) { for (const auto& lobby_id : this->public_lobby_search_order(c)) {
try { try {
auto l = this->find_lobby(lobby_id); auto l = this->find_lobby(lobby_id);
if (l && if (l &&
@@ -317,8 +321,11 @@ const vector<pair<string, uint16_t>>& ServerState::proxy_destinations(Version ve
} }
} }
const vector<uint32_t> ServerState::public_lobby_search_order(Version version) const { const vector<uint32_t>& ServerState::public_lobby_search_order(Version version, bool is_client_customization) const {
static_assert(NUM_VERSIONS == 14, "Don\'t forget to update the public lobby search orders in config.json"); static_assert(NUM_VERSIONS == 14, "Don\'t forget to update the public lobby search orders in config.json");
if (is_client_customization && !this->client_customization_public_lobby_search_order.empty()) {
return this->client_customization_public_lobby_search_order;
}
return this->public_lobby_search_orders.at(static_cast<size_t>(version)); return this->public_lobby_search_orders.at(static_cast<size_t>(version));
} }
@@ -372,6 +379,28 @@ shared_ptr<const SetDataTableBase> ServerState::set_data_table(
return ret; return ret;
} }
shared_ptr<const LevelTable> ServerState::level_table(Version version) const {
switch (version) {
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1:
case Version::DC_V2:
case Version::PC_NTE:
case Version::PC_V2:
case Version::GC_NTE: // TODO: Does NTE use the v2 table, the v3 table, or neither?
return this->level_table_v1_v2;
case Version::GC_V3:
case Version::GC_EP3_NTE:
case Version::GC_EP3:
case Version::XB_V3:
return this->level_table_v3;
case Version::BB_V4:
return this->level_table_v4;
default:
throw logic_error("level table not available for version");
}
}
shared_ptr<const ItemParameterTable> ServerState::item_parameter_table(Version version) const { shared_ptr<const ItemParameterTable> ServerState::item_parameter_table(Version version) const {
auto ret = this->item_parameter_tables.at(static_cast<size_t>(version)); auto ret = this->item_parameter_tables.at(static_cast<size_t>(version));
if (ret == nullptr) { if (ret == nullptr) {
@@ -747,14 +776,24 @@ void ServerState::load_config_early() {
this->quest_flag_rewrites_v3 = parse_quest_flag_rewrites("QuestFlagRewritesV3"); this->quest_flag_rewrites_v3 = parse_quest_flag_rewrites("QuestFlagRewritesV3");
this->quest_flag_rewrites_v4 = parse_quest_flag_rewrites("QuestFlagRewritesV4"); this->quest_flag_rewrites_v4 = parse_quest_flag_rewrites("QuestFlagRewritesV4");
this->quest_counter_fields.clear();
try {
for (const auto& it : this->config_json->get_dict("QuestCounterFields")) {
const auto& def = it.second->as_list();
this->quest_counter_fields.emplace(it.first, make_pair(def.at(0)->as_int(), def.at(1)->as_int()));
}
} catch (const out_of_range&) {
}
this->persistent_game_idle_timeout_usecs = this->config_json->get_int("PersistentGameIdleTimeout", 0); this->persistent_game_idle_timeout_usecs = this->config_json->get_int("PersistentGameIdleTimeout", 0);
this->cheat_mode_behavior = parse_behavior_switch("CheatModeBehavior", BehaviorSwitch::OFF_BY_DEFAULT); this->cheat_mode_behavior = parse_behavior_switch("CheatModeBehavior", BehaviorSwitch::OFF_BY_DEFAULT);
this->default_switch_assist_enabled = this->config_json->get_bool("EnableSwitchAssistByDefault", false);
this->use_game_creator_section_id = this->config_json->get_bool("UseGameCreatorSectionID", false); this->use_game_creator_section_id = this->config_json->get_bool("UseGameCreatorSectionID", false);
this->default_rare_notifs_enabled_v1_v2 = this->config_json->get_bool("RareNotificationsEnabledByDefault", false); this->default_rare_notifs_enabled_v1_v2 = this->config_json->get_bool("RareNotificationsEnabledByDefault", false);
this->default_rare_notifs_enabled_v3_v4 = this->default_rare_notifs_enabled_v1_v2; this->default_rare_notifs_enabled_v3_v4 = this->default_rare_notifs_enabled_v1_v2;
this->default_rare_notifs_enabled_v1_v2 = this->config_json->get_bool("RareNotificationsEnabledByDefaultV1V2", this->default_rare_notifs_enabled_v1_v2); this->default_rare_notifs_enabled_v1_v2 = this->config_json->get_bool("RareNotificationsEnabledByDefaultV1V2", this->default_rare_notifs_enabled_v1_v2);
this->default_rare_notifs_enabled_v3_v4 = this->config_json->get_bool("RareNotificationsEnabledByDefaultV3V4", this->default_rare_notifs_enabled_v3_v4); this->default_rare_notifs_enabled_v3_v4 = this->config_json->get_bool("RareNotificationsEnabledByDefaultV3V4", this->default_rare_notifs_enabled_v3_v4);
this->ep3_send_function_call_enabled = this->config_json->get_bool("EnableEpisode3SendFunctionCall", false); this->enable_send_function_call_quest_num = this->config_json->get_int("EnableSendFunctionCallQuestNumber", -1);
this->enable_v3_v4_protected_subcommands = this->config_json->get_bool("EnableV3V4ProtectedSubcommands", false); this->enable_v3_v4_protected_subcommands = this->config_json->get_bool("EnableV3V4ProtectedSubcommands", false);
this->catch_handler_exceptions = this->config_json->get_bool("CatchHandlerExceptions", true); this->catch_handler_exceptions = this->config_json->get_bool("CatchHandlerExceptions", true);
@@ -904,6 +943,7 @@ void ServerState::load_config_early() {
} }
this->bb_global_exp_multiplier = this->config_json->get_int("BBGlobalEXPMultiplier", 1); this->bb_global_exp_multiplier = this->config_json->get_int("BBGlobalEXPMultiplier", 1);
this->exp_share_multiplier = this->config_json->get_float("BBEXPShareMultiplier", 0.5);
this->server_global_drop_rate_multiplier = this->config_json->get_float("ServerGlobalDropRateMultiplier", 1); this->server_global_drop_rate_multiplier = this->config_json->get_float("ServerGlobalDropRateMultiplier", 1);
set_log_levels_from_json(this->config_json->get("LogLevels", JSON::dict())); set_log_levels_from_json(this->config_json->get("LogLevels", JSON::dict()));
@@ -920,6 +960,7 @@ void ServerState::load_config_early() {
this->enable_chat_commands = this->config_json->get_bool("EnableChatCommands", true); this->enable_chat_commands = this->config_json->get_bool("EnableChatCommands", true);
this->version_name_colors.reset(); this->version_name_colors.reset();
this->client_customization_name_color = 0;
try { try {
const auto& colors_json = this->config_json->get_list("VersionNameColors"); const auto& colors_json = this->config_json->get_list("VersionNameColors");
if (colors_json.size() != NUM_NON_PATCH_VERSIONS) { if (colors_json.size() != NUM_NON_PATCH_VERSIONS) {
@@ -932,10 +973,15 @@ void ServerState::load_config_early() {
this->version_name_colors = std::move(new_colors); this->version_name_colors = std::move(new_colors);
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
try {
this->client_customization_name_color = this->config_json->get_int("ClientCustomizationNameColor");
} catch (const out_of_range&) {
}
for (auto& order : this->public_lobby_search_orders) { for (auto& order : this->public_lobby_search_orders) {
order.clear(); order.clear();
} }
this->client_customization_public_lobby_search_order.clear();
try { try {
const auto& orders_json = this->config_json->get_list("LobbySearchOrders"); const auto& orders_json = this->config_json->get_list("LobbySearchOrders");
for (size_t v_s = 0; v_s < orders_json.size(); v_s++) { for (size_t v_s = 0; v_s < orders_json.size(); v_s++) {
@@ -947,6 +993,14 @@ void ServerState::load_config_early() {
} }
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
try {
const auto& order_json = this->config_json->get_list("ClientCustomizationLobbySearchOrder");
auto& order = this->client_customization_public_lobby_search_order;
for (const auto& it : order_json) {
order.emplace_back(it->as_int());
}
} catch (const out_of_range&) {
}
this->pre_lobby_event = 0; this->pre_lobby_event = 0;
try { try {
@@ -1201,7 +1255,11 @@ void ServerState::load_config_late() {
for (const auto& difficulty_it : type_it->as_list()) { for (const auto& difficulty_it : type_it->as_list()) {
auto& difficulty_res = type_res.emplace_back(); auto& difficulty_res = type_res.emplace_back();
for (const auto& item_it : difficulty_it->as_list()) { for (const auto& item_it : difficulty_it->as_list()) {
try {
difficulty_res.emplace_back(this->parse_item_description(Version::BB_V4, item_it->as_string())); difficulty_res.emplace_back(this->parse_item_description(Version::BB_V4, item_it->as_string()));
} catch (const exception& e) {
config_log.warning("Cannot parse item description \"%s\": %s (skipping entry)", item_it->as_string().c_str(), e.what());
}
} }
} }
} }
@@ -1211,7 +1269,11 @@ void ServerState::load_config_late() {
for (const auto& it : this->config_json->get_list("QuestF95FResultItems")) { for (const auto& it : this->config_json->get_list("QuestF95FResultItems")) {
auto& list = it->as_list(); auto& list = it->as_list();
size_t price = list.at(0)->as_int(); size_t price = list.at(0)->as_int();
try {
this->quest_F95F_results.emplace_back(make_pair(price, this->parse_item_description(Version::BB_V4, list.at(1)->as_string()))); this->quest_F95F_results.emplace_back(make_pair(price, this->parse_item_description(Version::BB_V4, list.at(1)->as_string())));
} catch (const exception& e) {
config_log.warning("Cannot parse item description \"%s\": %s (skipping entry)", list.at(1)->as_string().c_str(), e.what());
}
} }
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
@@ -1224,7 +1286,11 @@ void ServerState::load_config_late() {
} }
try { try {
for (const auto& it : this->config_json->get_list("SecretLotteryResultItems")) { for (const auto& it : this->config_json->get_list("SecretLotteryResultItems")) {
try {
this->secret_lottery_results.emplace_back(this->parse_item_description(Version::BB_V4, it->as_string())); this->secret_lottery_results.emplace_back(this->parse_item_description(Version::BB_V4, it->as_string()));
} catch (const exception& e) {
config_log.warning("Cannot parse item description \"%s\": %s (skipping entry)", it->as_string().c_str(), e.what());
}
} }
} catch (const out_of_range&) { } catch (const out_of_range&) {
} }
@@ -1236,8 +1302,12 @@ void ServerState::load_config_late() {
if (pi_json->is_int()) { if (pi_json->is_int()) {
ret.emplace(pi_json->as_int()); ret.emplace(pi_json->as_int());
} else { } else {
try {
auto item = this->parse_item_description(base_version, pi_json->as_string()); auto item = this->parse_item_description(base_version, pi_json->as_string());
ret.emplace(item.primary_identifier()); ret.emplace(item.primary_identifier());
} catch (const exception& e) {
config_log.warning("Cannot parse item description \"%s\": %s (skipping entry)", pi_json->as_string().c_str(), e.what());
}
} }
} }
} catch (const out_of_range&) { } catch (const out_of_range&) {
@@ -1407,12 +1477,16 @@ void ServerState::load_battle_params(bool from_non_event_thread) {
this->forward_or_call(from_non_event_thread, std::move(set)); this->forward_or_call(from_non_event_thread, std::move(set));
} }
void ServerState::load_level_table(bool from_non_event_thread) { void ServerState::load_level_tables(bool from_non_event_thread) {
config_log.info("Loading level table"); config_log.info("Loading level tables");
auto new_table = make_shared<LevelTableV4>(*this->load_bb_file("PlyLevelTbl.prs"), true); auto new_table_v1_v2 = make_shared<LevelTableV2>(load_file("system/level-tables/PlayerTable-pc-v2.prs"), true);
auto new_table_v3 = make_shared<LevelTableV3BE>(load_file("system/level-tables/PlyLevelTbl-gc-v3.cpt"), true);
auto new_table_v4 = make_shared<LevelTableV4>(*this->load_bb_file("PlyLevelTbl.prs"), true);
auto set = [s = this->shared_from_this(), new_table = std::move(new_table)]() { auto set = [s = this->shared_from_this(), new_table_v1_v2 = std::move(new_table_v1_v2), new_table_v3 = std::move(new_table_v3), new_table_v4 = std::move(new_table_v4)]() {
s->level_table = std::move(new_table); s->level_table_v1_v2 = std::move(new_table_v1_v2);
s->level_table_v3 = std::move(new_table_v3);
s->level_table_v4 = std::move(new_table_v4);
}; };
this->forward_or_call(from_non_event_thread, std::move(set)); this->forward_or_call(from_non_event_thread, std::move(set));
} }
@@ -1834,7 +1908,7 @@ void ServerState::load_all() {
this->create_default_lobbies(); this->create_default_lobbies();
this->load_set_data_tables(false); this->load_set_data_tables(false);
this->load_battle_params(false); this->load_battle_params(false);
this->load_level_table(false); this->load_level_tables(false);
this->load_text_index(false); this->load_text_index(false);
this->load_word_select_table(false); this->load_word_select_table(false);
this->load_item_definitions(false); this->load_item_definitions(false);
+24 -5
View File
@@ -36,6 +36,7 @@
class ProxyServer; class ProxyServer;
class Server; class Server;
class IPStackSimulator; class IPStackSimulator;
class HTTPServer;
struct PortConfiguration { struct PortConfiguration {
std::string name; std::string name;
@@ -95,6 +96,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
bool allow_gc_xb_games = true; bool allow_gc_xb_games = true;
bool enable_chat_commands = true; bool enable_chat_commands = true;
std::unique_ptr<std::array<uint32_t, NUM_NON_PATCH_VERSIONS>> version_name_colors; std::unique_ptr<std::array<uint32_t, NUM_NON_PATCH_VERSIONS>> version_name_colors;
uint32_t client_customization_name_color = 0x00000000;
uint8_t allowed_drop_modes_v1_v2_normal = 0x1F; uint8_t allowed_drop_modes_v1_v2_normal = 0x1F;
uint8_t allowed_drop_modes_v1_v2_battle = 0x07; uint8_t allowed_drop_modes_v1_v2_battle = 0x07;
uint8_t allowed_drop_modes_v1_v2_challenge = 0x07; uint8_t allowed_drop_modes_v1_v2_challenge = 0x07;
@@ -116,8 +118,9 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v1_v2; std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v1_v2;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v3; std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v3;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v4; std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v4;
std::unordered_map<std::string, std::pair<uint8_t, uint32_t>> quest_counter_fields; // For $qfread command
uint64_t persistent_game_idle_timeout_usecs = 0; uint64_t persistent_game_idle_timeout_usecs = 0;
bool ep3_send_function_call_enabled = false; int64_t enable_send_function_call_quest_num = -1;
bool enable_v3_v4_protected_subcommands = false; bool enable_v3_v4_protected_subcommands = false;
bool catch_handler_exceptions = true; bool catch_handler_exceptions = true;
bool ep3_infinite_meseta = false; bool ep3_infinite_meseta = false;
@@ -129,6 +132,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
bool hide_download_commands = true; bool hide_download_commands = true;
RunShellBehavior run_shell_behavior = RunShellBehavior::DEFAULT; RunShellBehavior run_shell_behavior = RunShellBehavior::DEFAULT;
BehaviorSwitch cheat_mode_behavior = BehaviorSwitch::OFF_BY_DEFAULT; BehaviorSwitch cheat_mode_behavior = BehaviorSwitch::OFF_BY_DEFAULT;
bool default_switch_assist_enabled = false;
bool use_game_creator_section_id = false; bool use_game_creator_section_id = false;
bool default_rare_notifs_enabled_v1_v2 = false; bool default_rare_notifs_enabled_v1_v2 = false;
bool default_rare_notifs_enabled_v3_v4 = false; bool default_rare_notifs_enabled_v3_v4 = false;
@@ -155,7 +159,9 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::shared_ptr<const QuestCategoryIndex> quest_category_index; std::shared_ptr<const QuestCategoryIndex> quest_category_index;
std::shared_ptr<const QuestIndex> default_quest_index; std::shared_ptr<const QuestIndex> default_quest_index;
std::shared_ptr<const QuestIndex> ep3_download_quest_index; std::shared_ptr<const QuestIndex> ep3_download_quest_index;
std::shared_ptr<const LevelTable> level_table; std::shared_ptr<const LevelTable> level_table_v1_v2;
std::shared_ptr<const LevelTable> level_table_v3;
std::shared_ptr<const LevelTable> level_table_v4;
std::shared_ptr<const BattleParamsIndex> battle_params; std::shared_ptr<const BattleParamsIndex> battle_params;
std::shared_ptr<const GSLArchive> bb_data_gsl; std::shared_ptr<const GSLArchive> bb_data_gsl;
std::unordered_map<std::string, std::shared_ptr<const RareItemSet>> rare_item_sets; std::unordered_map<std::string, std::shared_ptr<const RareItemSet>> rare_item_sets;
@@ -196,6 +202,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
QuestF960Result quest_F960_failure_results; QuestF960Result quest_F960_failure_results;
std::vector<ItemData> secret_lottery_results; std::vector<ItemData> secret_lottery_results;
uint16_t bb_global_exp_multiplier = 1; uint16_t bb_global_exp_multiplier = 1;
float exp_share_multiplier = 0.5;
double server_global_drop_rate_multiplier = 1.0; double server_global_drop_rate_multiplier = 1.0;
std::shared_ptr<Episode3::TournamentIndex> ep3_tournament_index; std::shared_ptr<Episode3::TournamentIndex> ep3_tournament_index;
@@ -246,6 +253,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::unordered_set<std::shared_ptr<Lobby>> lobbies_to_destroy; std::unordered_set<std::shared_ptr<Lobby>> lobbies_to_destroy;
std::shared_ptr<struct event> destroy_lobbies_event; std::shared_ptr<struct event> destroy_lobbies_event;
std::array<std::vector<uint32_t>, NUM_VERSIONS> public_lobby_search_orders; std::array<std::vector<uint32_t>, NUM_VERSIONS> public_lobby_search_orders;
std::vector<uint32_t> client_customization_public_lobby_search_order;
std::atomic<int32_t> next_lobby_id = 1; std::atomic<int32_t> next_lobby_id = 1;
uint8_t pre_lobby_event = 0; uint8_t pre_lobby_event = 0;
int32_t ep3_menu_song = -1; int32_t ep3_menu_song = -1;
@@ -263,6 +271,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::shared_ptr<Server> game_server; std::shared_ptr<Server> game_server;
std::shared_ptr<PatchServer> pc_patch_server; std::shared_ptr<PatchServer> pc_patch_server;
std::shared_ptr<PatchServer> bb_patch_server; std::shared_ptr<PatchServer> bb_patch_server;
std::shared_ptr<HTTPServer> http_server;
explicit ServerState(const std::string& config_filename = ""); explicit ServerState(const std::string& config_filename = "");
ServerState(std::shared_ptr<struct event_base> base, const std::string& config_filename, bool is_replay); ServerState(std::shared_ptr<struct event_base> base, const std::string& config_filename, bool is_replay);
@@ -302,6 +311,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::shared_ptr<const SetDataTableBase> set_data_table(Version version, Episode episode, GameMode mode, uint8_t difficulty) const; std::shared_ptr<const SetDataTableBase> set_data_table(Version version, Episode episode, GameMode mode, uint8_t difficulty) const;
std::shared_ptr<const LevelTable> level_table(Version version) const;
std::shared_ptr<const ItemParameterTable> item_parameter_table(Version version) const; std::shared_ptr<const ItemParameterTable> item_parameter_table(Version version) const;
std::shared_ptr<const ItemParameterTable> item_parameter_table_for_encode(Version version) const; std::shared_ptr<const ItemParameterTable> item_parameter_table_for_encode(Version version) const;
std::shared_ptr<const ItemData::StackLimits> item_stack_limits(Version version) const; std::shared_ptr<const ItemData::StackLimits> item_stack_limits(Version version) const;
@@ -310,11 +320,20 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::string describe_item(Version version, const ItemData& item, bool include_color_codes) const; std::string describe_item(Version version, const ItemData& item, bool include_color_codes) const;
ItemData parse_item_description(Version version, const std::string& description) const; ItemData parse_item_description(Version version, const std::string& description) const;
const std::vector<uint32_t> public_lobby_search_order(Version version) const; const std::vector<uint32_t>& public_lobby_search_order(Version version, bool is_client_customization) const;
inline const std::vector<uint32_t>& public_lobby_search_order(std::shared_ptr<const Client> c) const {
return this->public_lobby_search_order(c->version(), c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION));
}
inline uint32_t name_color_for_version(Version v) const { inline uint32_t name_color_for_client(Version v, bool is_client_customization) const {
if (is_client_customization && this->client_customization_name_color) {
return this->client_customization_name_color;
}
return this->version_name_colors ? this->version_name_colors->at(static_cast<size_t>(v) - NUM_PATCH_VERSIONS) : 0; return this->version_name_colors ? this->version_name_colors->at(static_cast<size_t>(v) - NUM_PATCH_VERSIONS) : 0;
} }
inline uint32_t name_color_for_client(std::shared_ptr<const Client> c) const {
return this->name_color_for_client(c->version(), c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION));
}
std::shared_ptr<const std::vector<std::string>> information_contents_for_client(std::shared_ptr<const Client> c) const; std::shared_ptr<const std::vector<std::string>> information_contents_for_client(std::shared_ptr<const Client> c) const;
std::shared_ptr<const QuestIndex> quest_index(Version version) const; std::shared_ptr<const QuestIndex> quest_index(Version version) const;
@@ -364,7 +383,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
void load_patch_indexes(bool from_non_event_thread); void load_patch_indexes(bool from_non_event_thread);
void clear_map_file_caches(); void clear_map_file_caches();
void load_battle_params(bool from_non_event_thread); void load_battle_params(bool from_non_event_thread);
void load_level_table(bool from_non_event_thread); void load_level_tables(bool from_non_event_thread);
void load_text_index(bool from_non_event_thread); void load_text_index(bool from_non_event_thread);
std::shared_ptr<ItemNameIndex> create_item_name_index_for_version( std::shared_ptr<ItemNameIndex> create_item_name_index_for_version(
std::shared_ptr<const ItemParameterTable> pmt, std::shared_ptr<const ItemParameterTable> pmt,
+22
View File
@@ -749,6 +749,15 @@ static const array<const char*, 0x0B> ep4_floor_names = {
"Purgatory", "Purgatory",
}; };
static const array<const char*, 0x12> ep1_floor_names_short = {
"P2", "F1", "F2", "C1", "C2", "C3", "M1", "M2", "R1", "R2", "R3", "Dgn", "DRL", "VO", "DF", "Lby", "B1", "B2"};
static const array<const char*, 0x12> ep2_floor_names_short = {
"Lab", "VRTA", "VRTB", "VRSA", "VRSB", "CCA", "JN", "JE", "Mtn", "SS", "SU", "SL", "GG", "OF", "BR", "GD", "SSN", "Twr"};
static const array<const char*, 0x0B> ep4_floor_names_short = {
"P2", "CE", "CW", "CS", "CN", "CI", "D1", "D2", "D3", "SM", "Pg"};
size_t floor_limit_for_episode(Episode ep) { size_t floor_limit_for_episode(Episode ep) {
switch (ep) { switch (ep) {
case Episode::EP1: case Episode::EP1:
@@ -775,6 +784,19 @@ const char* name_for_floor(Episode episode, uint8_t floor) {
} }
} }
const char* short_name_for_floor(Episode episode, uint8_t floor) {
switch (episode) {
case Episode::EP1:
return ep1_floor_names_short.at(floor);
case Episode::EP2:
return ep2_floor_names_short.at(floor);
case Episode::EP4:
return ep4_floor_names_short.at(floor);
default:
throw logic_error("invalid episode for floor");
}
}
bool floor_is_boss_arena(Episode episode, uint8_t floor) { bool floor_is_boss_arena(Episode episode, uint8_t floor) {
switch (episode) { switch (episode) {
case Episode::EP1: case Episode::EP1:
+1
View File
@@ -76,6 +76,7 @@ extern const std::unordered_map<std::string, uint8_t> mag_color_for_name;
size_t floor_limit_for_episode(Episode ep); size_t floor_limit_for_episode(Episode ep);
uint8_t floor_for_name(const std::string& name); uint8_t floor_for_name(const std::string& name);
const char* name_for_floor(Episode episode, uint8_t floor); const char* name_for_floor(Episode episode, uint8_t floor);
const char* short_name_for_floor(Episode episode, uint8_t floor);
bool floor_is_boss_arena(Episode episode, uint8_t floor); bool floor_is_boss_arena(Episode episode, uint8_t floor);
uint32_t class_flags_for_class(uint8_t char_class); uint32_t class_flags_for_class(uint8_t char_class);
+1 -1
View File
@@ -113,7 +113,7 @@ void TeamIndex::Team::save_flag() const {
if (!this->flag_data) { if (!this->flag_data) {
return; return;
} }
Image img(32, 32, false); Image img(32, 32, true);
for (size_t y = 0; y < 32; y++) { for (size_t y = 0; y < 32; y++) {
for (size_t x = 0; x < 32; x++) { for (size_t x = 0; x < 32; x++) {
img.write_pixel(x, y, decode_argb1555_to_rgba8888(this->flag_data->at(y * 0x20 + x))); img.write_pixel(x, y, decode_argb1555_to_rgba8888(this->flag_data->at(y * 0x20 + x)));
+41 -14
View File
@@ -199,6 +199,34 @@ ServerBehavior enum_for_name<ServerBehavior>(const char* name) {
} }
} }
uint32_t default_sub_version_for_version(Version version) {
switch (version) {
case Version::DC_NTE:
return 0x20;
case Version::DC_V1_11_2000_PROTOTYPE:
return 0x21;
case Version::DC_V1:
return 0x21;
case Version::DC_V2:
return 0x26;
case Version::PC_NTE:
return 0x28;
case Version::PC_V2:
return 0x29;
case Version::GC_NTE:
case Version::GC_V3:
case Version::XB_V3:
return 0x30;
case Version::GC_EP3_NTE:
case Version::GC_EP3:
return 0x40;
case Version::BB_V4:
return 0x41;
default:
return 0x00;
}
}
uint32_t default_specific_version_for_version(Version version, int64_t sub_version) { uint32_t default_specific_version_for_version(Version version, int64_t sub_version) {
// For versions that don't support send_function_call by default, we need // For versions that don't support send_function_call by default, we need
// to set the specific_version based on sub_version. Fortunately, all // to set the specific_version based on sub_version. Fortunately, all
@@ -207,15 +235,15 @@ uint32_t default_specific_version_for_version(Version version, int64_t sub_versi
// VersionDetectDC, VersionDetectGC, or VersionDetectXB call. // VersionDetectDC, VersionDetectGC, or VersionDetectXB call.
switch (version) { switch (version) {
case Version::DC_NTE: case Version::DC_NTE:
return SPECIFIC_VERSION_DC_NTE; return SPECIFIC_VERSION_DC_NTE; // 1OJ1
case Version::DC_V1_11_2000_PROTOTYPE: case Version::DC_V1_11_2000_PROTOTYPE:
return SPECIFIC_VERSION_DC_11_2000_PROTOTYPE; return SPECIFIC_VERSION_DC_11_2000_PROTOTYPE; // 1OJ2
case Version::DC_V1: case Version::DC_V1:
return SPECIFIC_VERSION_DC_V1_INDETERMINATE; // Need to send VersionDetectDC (but can't on V1; rip) return SPECIFIC_VERSION_DC_V1_INDETERMINATE; // 1___; need to send VersionDetectDC (but can't on V1; rip)
case Version::DC_V2: case Version::DC_V2:
return SPECIFIC_VERSION_DC_V2_INDETERMINATE; // Need to send VersionDetectDC return SPECIFIC_VERSION_DC_V2_INDETERMINATE; // 2___; need to send VersionDetectDC
case Version::PC_V2: case Version::PC_V2:
return SPECIFIC_VERSION_PC_V2; return SPECIFIC_VERSION_PC_V2; // 2OJW
case Version::GC_NTE: case Version::GC_NTE:
return SPECIFIC_VERSION_GC_NTE; // 3OJT return SPECIFIC_VERSION_GC_NTE; // 3OJT
case Version::GC_V3: case Version::GC_V3:
@@ -224,6 +252,7 @@ uint32_t default_specific_version_for_version(Version version, int64_t sub_versi
case 0x33: // GC Ep1&2 EU 60Hz case 0x33: // GC Ep1&2 EU 60Hz
return SPECIFIC_VERSION_GC_V3_EU; // 3OP0 return SPECIFIC_VERSION_GC_V3_EU; // 3OP0
case 0x36: // GC Ep1&2 US v1.2 (Plus) case 0x36: // GC Ep1&2 US v1.2 (Plus)
case 0x3A: // GC Ep1&2 US v1.2 (Plus) GMK edition
return SPECIFIC_VERSION_GC_V3_US_12; // 3OE2 return SPECIFIC_VERSION_GC_V3_US_12; // 3OE2
case 0x34: // GC Ep1&2 JP v1.3 case 0x34: // GC Ep1&2 JP v1.3
return SPECIFIC_VERSION_GC_V3_JP_13; // 3OJ3 return SPECIFIC_VERSION_GC_V3_JP_13; // 3OJ3
@@ -235,7 +264,7 @@ uint32_t default_specific_version_for_version(Version version, int64_t sub_versi
case 0x30: // GC Ep1&2 GameJam demo, GC Ep1&2 Trial Edition, GC Ep1&2 JP v1.2, at least one version of PSO XB case 0x30: // GC Ep1&2 GameJam demo, GC Ep1&2 Trial Edition, GC Ep1&2 JP v1.2, at least one version of PSO XB
case 0x31: // GC Ep1&2 US v1.0, GC US v1.1, XB US case 0x31: // GC Ep1&2 US v1.0, GC US v1.1, XB US
default: default:
return SPECIFIC_VERSION_GC_V3_INDETERMINATE; // Need to send VersionDetectGC return SPECIFIC_VERSION_GC_V3_INDETERMINATE; // 3O__; need to send VersionDetectGC
} }
throw logic_error("this should be impossible"); throw logic_error("this should be impossible");
case Version::GC_EP3_NTE: case Version::GC_EP3_NTE:
@@ -250,12 +279,12 @@ uint32_t default_specific_version_for_version(Version version, int64_t sub_versi
case -1: // Initial check (before sub_version recognition) case -1: // Initial check (before sub_version recognition)
case 0x40: // GC Ep3 trial and GC Ep3 JP case 0x40: // GC Ep3 trial and GC Ep3 JP
default: default:
return SPECIFIC_VERSION_GC_EP3_INDETERMINATE; // Need to send VersionDetectGC return SPECIFIC_VERSION_GC_EP3_INDETERMINATE; // 3SJ_; need to send VersionDetectGC
} }
case Version::XB_V3: case Version::XB_V3:
return SPECIFIC_VERSION_XB_V3_INDETERMINATE; return SPECIFIC_VERSION_XB_V3_INDETERMINATE; // 4O__; need to send VersionDetectXB
case Version::BB_V4: case Version::BB_V4:
return SPECIFIC_VERSION_BB_V4_INDETERMINATE; return SPECIFIC_VERSION_BB_V4_INDETERMINATE; // 5___; we should be able to determine version from initial login
default: default:
return SPECIFIC_VERSION_INDETERMINATE; return SPECIFIC_VERSION_INDETERMINATE;
} }
@@ -275,7 +304,7 @@ bool specific_version_is_dc(uint32_t specific_version) {
} }
bool specific_version_is_gc(uint32_t specific_version) { bool specific_version_is_gc(uint32_t specific_version) {
// GC specific_versions are 3GRV, where G is [OE], R is [JEP], V is [0-9T] // GC specific_versions are 3GRV, where G is [OS], R is [JEP], V is [0-9T]
if ((specific_version & 0xFF000000) != 0x33000000) { if ((specific_version & 0xFF000000) != 0x33000000) {
return false; return false;
} }
@@ -305,10 +334,8 @@ bool specific_version_is_xb(uint32_t specific_version) {
} }
bool specific_version_is_bb(uint32_t specific_version) { bool specific_version_is_bb(uint32_t specific_version) {
// TODO: We should actually find a way to determine BB specific_versions, but // BB specific_versions are 5XXX, where X is an encoding of the revision number
// there are so many mods out there, and there's a patch server anyway, so it return (specific_version & 0xFF000000) == 0x35000000;
// seems not worth the effort
return specific_version == 0x35303030;
} }
const char* file_path_token_for_version(Version version) { const char* file_path_token_for_version(Version version) {
+1
View File
@@ -161,6 +161,7 @@ constexpr uint32_t SPECIFIC_VERSION_XB_V3_INDETERMINATE = 0x344F0000; // 4O__
constexpr uint32_t SPECIFIC_VERSION_BB_V4_INDETERMINATE = 0x35000000; // 5___ constexpr uint32_t SPECIFIC_VERSION_BB_V4_INDETERMINATE = 0x35000000; // 5___
constexpr uint32_t SPECIFIC_VERSION_INDETERMINATE = 0x00000000; // ____ constexpr uint32_t SPECIFIC_VERSION_INDETERMINATE = 0x00000000; // ____
uint32_t default_sub_version_for_version(Version version);
uint32_t default_specific_version_for_version(Version version, int64_t sub_version); uint32_t default_specific_version_for_version(Version version, int64_t sub_version);
bool specific_version_is_indeterminate(uint32_t specific_version); bool specific_version_is_indeterminate(uint32_t specific_version);
bool specific_version_is_dc(uint32_t specific_version); bool specific_version_is_dc(uint32_t specific_version);
@@ -7,8 +7,8 @@ reloc0:
.offsetof start .offsetof start
start: start:
.include CallProtectedHandlerXB .include CallProtectedHandlerXB
.data 0x007237E8 .data 0x007237E8 # should_allow_protected_commands
.data 0x002DE000 .data 0x002DE000 # handle_6x(void* data @ ecx, uint32_t size @ eax)
size: size:
.data 0x00000000 .data 0x00000000
data: data:
@@ -0,0 +1,36 @@
.meta hide_from_patches_menu
.meta name="CallProtectedHandler"
.meta description=""
entry_ptr:
reloc0:
.offsetof start
start:
jmp get_data_addr
resume:
xchg ebx, [esp]
mov edx, [ebx]
mov dword [edx], 1
mov edx, [ebx + 4]
push dword [ebx + 8]
lea ecx, [ebx + 0x0C]
push ecx
call edx # RcvPsoData2(data, size)
add esp, 8
mov edx, [ebx]
mov dword [edx], 0
pop ebx
ret
get_data_addr:
call resume
.data 0x00AAECF0 # should_allow_protected_commands
.data 0x00800860 # RcvPsoData2(void* data @ stack, uint32_t size @ stack)
size:
.data 0x00000000
data:
@@ -1,5 +1,5 @@
start: start:
mov eax, 0x88888888 # eax = &player_compute_implied_stats mov eax, 0x88888888 # eax = &player_compute_implied_stats (the value is overwritten by the including patch)
lea edx, [ecx + 0x78] lea edx, [ecx + 0x78]
cmp byte [edx + 0x76], 11 # this->data1[2] (item+0xEE) ?= 0x0B cmp byte [edx + 0x76], 11 # this->data1[2] (item+0xEE) ?= 0x0B
jne skip_all jne skip_all
@@ -0,0 +1,17 @@
.meta name="Disable idle DC"
.meta description="Disable idle\ndisconnect timeout"
entry_ptr:
reloc0:
.offsetof start
start:
.include WriteCodeBlocksDC
.align 4
.data 0x8C01A6C8
.data 0x00000002
mov r0, 0
.align 4
.data 0x00000000
.data 0x00000000
@@ -0,0 +1,17 @@
.meta name="Disable idle DC"
.meta description="Disable idle\ndisconnect timeout"
entry_ptr:
reloc0:
.offsetof start
start:
.include WriteCodeBlocksDC
.align 4
.data 0x8C01A454
.data 0x00000002
mov r0, 0
.align 4
.data 0x00000000
.data 0x00000000
@@ -0,0 +1,17 @@
.meta name="Disable idle DC"
.meta description="Disable idle\ndisconnect timeout"
entry_ptr:
reloc0:
.offsetof start
start:
.include WriteCodeBlocksDC
.align 4
.data 0x8C01A6D0
.data 0x00000002
mov r0, 0
.align 4
.data 0x00000000
.data 0x00000000
@@ -0,0 +1,17 @@
.meta name="Disable idle DC"
.meta description="Disable idle\ndisconnect timeout"
entry_ptr:
reloc0:
.offsetof start
start:
.include WriteCodeBlocksDC
.align 4
.data 0x8C01A414
.data 0x00000002
mov r0, 0
.align 4
.data 0x00000000
.data 0x00000000

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